solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; long long int summ(long long int n) { long long int res = n * (n + 1); res /= 2; res %= 1000000007; return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a; cin >> a; long long int i, j, n = a.size(); a = '$' + a; long l...
4
#include <bits/stdc++.h> using namespace std; int main() { int len = 0; char word[1000], word2[1000], temp[1000]; scanf("%s", word); for (int i = 0; word[i] != '\0'; i++) { len++; } for (int i = 0; i < len / 2; i++) { swap(word[i], word[len - 1 - i]); } scanf("%s", word2); for (int i = 0; i < ...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; cin >> s; int n = s.length(); int cnt = 0; for (int i = 0; i < n; i++) { if (s[i] == 'N') cnt++; } if (cnt == 1) cout << "NO" << endl; else cout << "YES" << endl; ...
0
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; map<long long int, long long int> m; vector<long long int> v, v1; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, x, y, t, k; string s; cin >> s; long long int sum = 0; for (long long int i ...
2
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; long long mx = 0, n = a.size(), m = b.size(); for (int i = m - 1; i >= 0; i--) { int cnt = 0; for (int j = 0; j < n && i + j < m; j++) if (a[j] == b[i + j]) cnt++; if (cnt > mx) mx = cnt; } for (int i = ...
4
#include <bits/stdc++.h> using namespace std; int a[300100], s[1000100], n, k; int main() { ios_base::sync_with_stdio(false); cin >> n >> k; for (int i = 0; i < 1000100; i++) { s[i] = 0; } for (int i = 0; i < n; i++) { cin >> a[i]; s[a[i]]++; } sort(a, a + n); for (int i = 1; i < 1000100; i+...
6
#include <bits/stdc++.h> #include <algorithm> #include <string.h> #include <math.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const ll mod = 1000000007; #define vi vector<int> #define vp vector<pair<int, int>> #define graph vector<vector<int>> #define vs vector<string> const int MAXN =...
4
#include <bits/stdc++.h> using namespace std; int main() { string s; vector<char> v; cin >> s; int l = s.size(), i; for (i = 0; i < l; i++) { if (s[i] == '1' || s[i] == '2' || s[i] == '3') v.push_back(s[i]); } sort(v.begin(), v.end()); cout << v[0]; for (i = 1; i < v.size(); i++) cout << "+" << v[...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long ans = 2 * 3; long long ans2 = 3 * 3 * (n - 3); for (int i = 0; i < n - 2; i++) ans *= 4; for (int i = 0; i < n - 3; i++) ans2 *= 4; cout << ans + ans2 << endl; }
4
#include <bits/stdc++.h> using namespace std; long long int sum[1505][1505]; long long int dp[1505][1505]; int main() { int n, m, i, j; long long int t, s, ans; while (~scanf("%d %d", &n, &m)) { for (i = 0; i < n; i++) { s = 0; for (j = 0; j < m; j++) { scanf("%I64d", &t); s += t; ...
5
#include <bits/stdc++.h> using namespace std; vector<long long> poli, head; long long n, m, pishte, zaman, t, l = -1, r = 2e6 + 5, t1, t2; string s; int main() { cin >> n; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == '*') poli.push_back(i); if (s[i] == 'P') head.push_back(i); } while (r - l > 1...
5
#include <bits/stdc++.h> using namespace std; vector<int> a; int main() { int n, i, j, m, s = 0, t = 0, k, d; scanf("%d", &n); a.resize(n + 1, 0); for (i = 1; i <= n; ++i) { scanf("%d", &a[i]); s += a[i]; } for (i = 3; i <= n; ++i) { if (n % i == 0) { d = n / i; for (j = 1; j <= d; +...
2
#include <bits/stdc++.h> using namespace std; const int N = 21; char s[N][1000]; int n, k, f[N][N], len[N], ans = 0, a[N]; void dfs(int now, int last, int sum) { if (now > k) { ans = max(ans, sum); return; } for (int i = last + 1; i <= n - (k - now); ++i) { int tmp = sum; a[now] = i; for (int ...
5
#include <bits/stdc++.h> using namespace std; long long int pow(long long int x, long long int y, long long int m) { long long int res = 1; x = x % m; while (y > 0) { if (y & 1) res = ((res % m) * (x % m)) % m; y = y >> 1; x = ((x % m) * (x % m)) % m; } return res % m; } template <typename Arg1> v...
3
#include <bits/stdc++.h> using namespace std; int a[10] = {'8', 'a', 'a', '3', '6', '9', '4', '7', '0', '5'}; int s[10] = {0, 0, 0, 1, 0, 0, 0, 1, 0, 0}; char ch[11]; int main() { scanf("%s", ch); int len = strlen(ch), i, j; for (i = 0, j = len - 1; i < j; i++, j--) if (a[ch[i] - '0'] != ch[j]) return puts("N...
5
#include <bits/stdc++.h> using namespace std; int read() { int tot = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') fh = -1; c = getchar(); } while (c >= '0' && c <= '9') { tot = tot * 10 + c - '0'; c = getchar(); } return tot * fh; } void getstr(char *a) { cha...
2
#include <bits/stdc++.h> using namespace std; int n; string s; int check1(string s) { int len = s.size(); if (s[len - 1] == '.' && s[len - 2] == 'a' && s[len - 3] == 'l' && s[len - 4] == 'a' && s[len - 5] == 'l') return 1; return 0; } int check2(string s) { int len = s.size(); if (s[0] == 'm' && s[1...
1
#include <bits/stdc++.h> const int MaxN = 1010; long long f[MaxN]; int main() { int a, b, c; scanf("%d%d%d", &a, &b, &c); f[0] = a, f[1] = b; for (int i = 2; i <= c; i++) f[i] = f[i - 1] + f[i - 2]; printf("%I64d\n", f[c]); return 0; }
4
#include <bits/stdc++.h> namespace fastIO { static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23; char buf[IN_BUF], *ps = buf, *pt = buf; inline char my_getchar() { return ps == pt && (pt = (ps = buf) + fread(buf, 1, IN_BUF, stdin), ps == pt) ? EOF : *ps++; } template <typename T> inline boo...
6
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:256000000") const int N = 200000; int n; int k = 0; int m[3] = {0, 1, 2}; vector<vector<int> > gr; int cou[N]; int ans[N]; int main() { scanf("%d", &n); gr.resize(n); for (int i = 0; i < n; ++i) { int t; scanf("%d", &t); gr[...
5
#include <bits/stdc++.h> using namespace std; const int nn = 258; const int MOD = 1e9 + 7; const int BASE = 257; char s[nn][nn]; int v[nn]; long long t[nn]; long long power[nn]; long long res; int n, m; void manacher(const vector<int> &k) { int p = k.size() * 2 - 1; vector<int> f(p, 0); vector<int> a(p, -8); fo...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 3001, mod = 1e9 + 7; const double eps = 1e-9; template <typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; } template <typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = ...
8
#include <bits/stdc++.h> using namespace std; const double PI = 2 * acos(0.0), EPS = 1e-9; const int INF = 1e9, NINF = -1e9, MOD = 1e9 + 7; void GO() { cout << fixed << setprecision(10); } int main() { GO(); int n, m, q, r, l, c, a[1001] = {}; string second, t; cin >> n >> m >> q >> second >> t; for (int i = ...
2
#include <bits/stdc++.h> const int INF = 1e9 + 7; const int MAXN = 3e5 + 10; using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; for (int i = a; i <= 2 * a; i++) { for (int j = b; j <= 2 * b; j++) { for (int k = c; k <= 2 * c; k++) { if (i > j && j > k && d <= i && d <= j ...
2
#include <bits/stdc++.h> using namespace std; int n, x, a[105], c, ans, t; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n); c = 350; for (int i = 1; i <= n; i++) if (a[i] <= c) { c -= a[i]; ans++; } else ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i; cin >> n >> k; int f[n], t[n]; int maxx = 0, count[n]; for (i = 0; i < n; i++) { cin >> f[i] >> t[i]; if (t[i] > k) { count[i] = f[i] - (t[i] - k); } else count[i] = f[i]; } cout << *max_element(count, count + ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a, x, b, y; cin >> n >> a >> x >> b >> y; bool check = false; while (1) { if (a == x || b == y) break; a = a + 1; b = b - 1; if (a > n) a = 1; if (b < 1) b = n; if (a == b) { check = true; break; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int x, y, i, j, yes; char a[55][55]; int xf, yf, xe, ye; while (cin >> x >> y) { xf = 0; yf = 0; xe = x - 1; ye = y - 1; memset(a, '0', sizeof(a)); for (i = 0; i < x; i++) { cin >> a[i]; } for (i = 0; i < x; i++) { ...
0
#include <bits/stdc++.h> using namespace std; int M[200050][25] = {0}; int A[200050]; int NO[200050][25] = {INT_MAX}; int B[200050]; int N; int minidx, maxidx; void process1() { int i, j; for (i = 0; i < N; i++) M[i][0] = i; for (j = 1; 1 << j <= N; j++) for (i = 0; i + (1 << j) - 1 < N; i++) if (A[M[i]...
6
#include <bits/stdc++.h> #pragma GCC optimize("O2,unroll-loops") using namespace std; const int MAXN = 600010; int n, m, k, u, v, x, y, t, a, b; int par[MAXN], col[MAXN]; long long s0[MAXN], s1[MAXN], ans; vector<int> vec[MAXN]; string S; pair<int, int> Getpar(int x) { if (par[x] == x) return {x, 0}; pair<int, int>...
8
#include <bits/stdc++.h> using namespace std; //#define int long long int get(int b, int i, int j) { cout << b << ' ' << i + 1 << ' ' << j + 1 << endl; int x; cin >> x; return x; } void solve() { int n; cin >> n; int b; cin >> b; vector<vector<int>> arr(n, vector<int>(n, -1)); int cnt = n * n; ...
4
#include <bits/stdc++.h> using namespace std; vector<int> ans; vector<int> ads[100005]; int p[100005]; int cl[100005]; void dfs(int n) { int x, y; if (cl[n] == 1) { for (x = 0; x < ads[n].size(); x++) { if (cl[ads[n][x]] == 0) break; } if (x == ads[n].size()) ans.push_back(n); } for (int i = 0...
3
#include <bits/stdc++.h> using namespace std; long long int total, mult, val[100010]; bool vis[100010]; stack<long long int> ss; vector<long long int> x; vector<long long int> adj[100010 * 3]; vector<long long int> adj2[100010 * 3]; void dfs(long long int s) { vis[s] = 1; for (int i : adj[s]) { if (!vis[i]) dfs...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 0, f1, f2, f3, f4, i, j; cin >> n; int x[n], y[n]; for (i = 0; i < n; i++) cin >> x[i] >> y[i]; for (i = 0; i < n; i++) { f1 = 0, f2 = 0, f3 = 0, f4 = 0; for (j = 0; j < n; j++) { if (x[j] < x[i] && y[i] == y[j]) f1 = 1; ...
1
#include <bits/stdc++.h> const int MaxN = 6e5 + 50; template <class t> inline void read(t &s) { s = 0; register int f = 1; register char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar(); s *= f; retur...
7
#include <bits/stdc++.h> using namespace std; bool comp(string a, string b) { return a.length() < b.length(); } int main() { int n, sec; cin >> n >> sec; vector<string> s; for (int i = 0; i < n; i++) { string str; cin >> str; s.push_back(str); } string pwd; cin >> pwd; sort(s.begin(), s.end(...
1
#include <bits/stdc++.h> using namespace std; int main() { long long l, p[11] = {0}, n[11] = {0}, k; cin >> l; for (int i = 0; i < l; i++) { cin >> k; if (k > 0) p[k]++; else if (k < 0) n[-k]++; else p[0]++; } long long int sum = 0; for (int i = 1; i <= 10; i++) { sum +...
2
#include <bits/stdc++.h> using namespace std; int a[500]; int used[500]; long long gcd(long long x, long long y) { if (y == 0) return x; else return gcd(y, x % y); } long long lcm(long long x, long long y) { return x / gcd(x, y) * y; } int main() { int i, n, j; long long ans, mini, tmp; scanf("%d", &n...
6
#include <bits/stdc++.h> using namespace std; const long long oo = 0x3f3f3f3f3f3f3f3fll; const double eps = 1e-9; int main() { ios_base::sync_with_stdio(false); long long n; cin >> n; long long result = 1; for (long long i = 2; i * i <= n; i++) { if (n % i) continue; result *= i; while (n % i == 0...
2
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); int n, k; cin >> n >> k; auto a = vector<int>(n); for (int i = 0; i < (n); ++i) cin >> a[i]; auto next_pos = vector<deque<int>>(n); for (int i = 0; i < (n); ++i) { aut...
5
#include <bits/stdc++.h> using namespace std; inline bool checkBit(long long n, long long i) { return n & ((long long)1 << i); } inline long long setBit(long long n, long long i) { return n | ((long long)1 << i); ; } inline long long resetBit(long long n, long long i) { return n & (~((long long)1 << i)); } inli...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long n; cin >> n; vector<long long> a(n + 1, 0); unordered_map<long long, long long> m; vector<char> ans(n + 1, 'A'); for (long long i = 1; i <= n; i++) { cin >> a[i]; m[a[i]] = i; } for (long lon...
4
#include <bits/stdc++.h> using namespace std; long long int dx[] = {1, 0, -1, 0}; long long int dy[] = {0, 1, 0, -1}; const long long int N = 1000 * 1000 + 5; const long long int size = 1000 * 100 * 2 + 5; const long long int mod = 1000 * 1000 * 1000 + 7; long long int gcd(long long int a, long long int b) { if (!b) ...
2
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const long long inf = 1000000000000000LL; struct Friend { int tax, gir, pic; string name; Friend() { tax = gir = pic = 0; } }; void calc(Friend& f, string n) { vector<long long> a; for (int i = 0; i < 3; ++i) { for (int j = 0; j...
3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, m[200000], n; cin >> n >> b >> a; int a1 = a, i; for (int i = 0; i < n; i++) cin >> m[i]; for (i = 0; i < n; i++) { if (m[i] == 0) { if (a != 0) a--; else if (a == 0 && b != 0) b--; else { cout <...
3
#include <bits/stdc++.h> using namespace std; long long Set(long long N, long long pos) { return N = N | (1 << pos); } long long reset(long long N, long long pos) { return N = N & ~(1 << pos); } bool check(long long N, long long pos) { return (bool)(N & (1 << pos)); } void CI(long long &_x) { scanf("%I64d", &_x); } voi...
5
#include <bits/stdc++.h> using namespace std; int main() { string n, m; cin >> n; cin >> m; int sheets[26], garland[26]; memset(sheets, 0, sizeof(sheets)); memset(garland, 0, sizeof(garland)); for (int i = 0; i < n.size(); i++) sheets[n[i] - 'a']++; for (int i = 0; i < m.size(); i++) garland[m[i] - 'a']...
2
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > a; bool vis[100100]; int main() { int n, i, j; scanf("%d", &n); for (i = 3; i * 2 <= n; i += 2) if (!vis[i]) { vector<int> b; b.clear(); for (j = i; j <= n; j += 2 * i) if (!vis[j]) { vis[j] = true; ...
8
#include <bits/stdc++.h> using namespace std; int step[3005][3005], N, M, a, b, res = -1, p[5], ans[5], rstep[3005][3005]; pair<int, int> MAX[3005][5], RMAX[3005][5]; vector<int> e[3005]; inline void bfs(int x) { queue<int> q; step[x][x] = 0; q.push(x); while (!q.empty()) { int ff = q.front(); q.pop(); ...
6
#include <bits/stdc++.h> using namespace std; enum class NodeState { UNVISITED, VISITED }; struct neighbour { int id; int cost; int edgeId; neighbour(int _id, int _cost, int _edgeId) { id = _id; cost = _cost; edgeId = _edgeId; } }; int N, M, A, B; vector<neighbour> nb[1005]; NodeState state[1005];...
9
#include <bits/stdc++.h> using namespace std; int n, k; int grundy(int x) { if (x < 2) return x; else if (x == 3) return (k % 2); else if (x % 2) return 0; else { int res = 0; set<int> st; st.insert(grundy(x - 1)); st.insert((k % 2) * grundy(x / 2)); while (st.count(res)) res++; ...
7
#include <bits/stdc++.h> using namespace std; long long t, a, b, c, d; int main() { cin >> t; while (t--) { cin >> a >> b >> c >> d; long long cd = c / d, abd = a / (b * d); if (c <= d && a <= b * c) { cout << a << endl; } else if (c <= d) { cout << "-1\n"; } else if (a > cd * b * d ...
6
#include <bits/stdc++.h> using namespace std; int A, B; char picture[50][50]; bool check(int first, int second) { for (int a1 = 0; a1 < A; a1 += first) for (int a2 = 0; a2 < A; a2 += first) for (int b1 = 0; b1 < B; b1 += second) for (int b2 = 0; b2 < B; b2 += second) { if (a1 == a2 && b1 =...
5
#include <bits/stdc++.h> using namespace std; int dp[2][510][510] = {1}, bug[510], n, m, b, mod, ans = 0; int main() { cin >> n >> m >> b >> mod; for (int i = 1; i <= n; i++) { cin >> bug[i]; } for (int i = 1; i <= n; i++) { for (int j = 0; j <= m; j++) { for (int k = 0; k <= b; k++) { if ...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; long long b[maxn]; int n; map<long long, long long> mapper; int main() { long long sum = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { cin >> b[i]; } for (int i = 0; i < n; i++) { mapper[b[i] - i] += b[i]; sum = max(sum, ma...
3
#include <bits/stdc++.h> using namespace std; vector<int> v; bool isGood(int x) { int o = 0, z = 0; int lastOne = -1; for (int i = 0; i <= 31; ++i) if ((x & (1 << i)) > 0) lastOne = i; for (int i = 0; i <= lastOne; ++i) { if ((x & (1 << i)) == 0 && o == 0) { ++z; } else if ((x & (1 << i)) > 1)...
1
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1005; int a[MAX_N]; int n, m, c; bool check(int pos) { if (pos < n) { return false; } for (int i = 1; i < n; i++) { if (a[i] > a[i + 1] || a[i] == 0) { return false; } } return true; } int main() { scanf("%d %d %d", &n, &m, &c...
6
#include <bits/stdc++.h> using namespace std; long long const mo = 1e9 + 7; long double const pi = 2.00 * asin(1.00); long long mod(long long k) { return (k + mo) % mo; } long long addmod(long long a, long long b) { return mod(mod(a) + mod(b)); } long long mulmod(long long a, long long b) { return mod(mod(a) * mod(b));...
3
#include <bits/stdc++.h> using namespace std; struct comparator { bool operator()(int i, int j) { return i > j; } }; int main() { ; ios_base::sync_with_stdio(false); cin.tie(NULL); ; int n; cin >> n; string second; int a; priority_queue<int, std::vector<int>, comparator> h; vector<pair<string, int...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d%d", &n, &m); int x[300], y[300]; for (int i = 0; i < m; ++i) { scanf("%d%d", &x[i], &y[i]); } map<int, int> best; for (int i = 0; i < m; ++i) for (int j = i + 1; j < m; ++j) { long long A = y[j] - y[i]; long...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; int arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; } int o = sizeof(arr) / sizeof(arr[0]); sort(arr, arr + o); for (i = 0; i < n; i++) { cout << arr[i] << endl; } }
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); string s; long long a[1005]; long long count = 0; cin >> s; for (long long i = 0; i < s.size(); i += 2) { a[count++] = s[i] - '0'; } sort(a, a + count); for (long long i = 0; i < count; i++) { cout << a[i];...
0
#include <bits/stdc++.h> using namespace std; int a[10], n; char s[120000]; int main() { scanf("%d", &n); scanf("%s", s); for (int i = 0; i < n; ++i) { if (s[i] == 'A') a[0]++; else if (s[i] == 'C') a[1]++; else if (s[i] == 'G') a[2]++; else a[3]++; } int ret = 0, k = 0...
3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long int n; int t; cin >> t; while (t--) { cin >> n; vector<long long int> v(n); for (auto &it : v) cin >> it; ; long long int sum = accumulate(v.begin(), v.end(), 0); if (sum == ...
0
#include <bits/stdc++.h> using namespace std; void in() { return; } template <typename T, typename... Types> void in(T &a, Types &...b) { cin >> (a); in(b...); } void o() { return; } template <typename T, typename... Types> void o(T a, Types... b) { cout << (a); cout << ' '; o(b...); } bool sortin(const pair<...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10, mod = 1e9 + 7; const long long inf = 1e18; unsigned int dp[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(); int n, cnt = 0; cin >> n; string s; cin >> s; if (n & 1) return cout << 0 << endl, 0; dp[0] ...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n; map<int, int> mp; for (int i = 0; i < n; i++) { cin >> x; mp[x]++; } if (mp[2] > 0) { cout << 2 << " "; mp[2]--; } if (mp[1] > 0) { cout << 1 << " "; mp[1]--; } for (int i = 0; i < mp[2]; i++) cout...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 5; int ar[MAXN]; int N; int v[MAXN]; bool f(long double k) { long double left = 1e27; bool ok = false; for (int(i) = (N); (i) >= (1); (i)--) { if (v[i] > 0) { if (left <= ar[i] + v[i] * k && ok) return true; } else { ok = tru...
7
#include <bits/stdc++.h> #pragma GCC optimize(2) const double esp = 1e-6; const double pi = acos(-1.0); const int INF = 0x3f3f3f3f; const int inf = 1e9; using namespace std; long long read() { char ch = getchar(); long long x = 0, f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar()...
4
#include <bits/stdc++.h> using namespace std; long long int menor = 0x3f3f3f3f; long long int resp = 0; long long int posi; long long int n; long long int v[100005]; int main() { ios_base::sync_with_stdio(false); ; cin >> n; for (int i = 0; i < n; i++) { cin >> v[i]; if (v[i] < menor) menor = v[i]; } ...
2
#include <bits/stdc++.h> using namespace std; int n, m, k, a[102][102][102], res, was; int change[3][3]; int main() { change[0][0] = 1; change[1][1] = 1; change[2][2] = 1; scanf("%d %d %d", &n, &m, &k); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) for (int q = 1; q <= k; q++) scanf("%1d...
5
#include <bits/stdc++.h> using namespace std; int n, p, t, ans, f[100010], g[100010]; inline void div(int a, int b, int &c, int &r) { c = a / b; r = a % b; } int main() { scanf("%*d%d%d%d", &n, &p, &t); g[0] = -t; for (int i = 1, k1 = 0, k2 = 0, mx = 0; i <= n; ++i) { int x, y, h, v; scanf("%d%d", &x,...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; int n, h[N], cnt, m, vis[N][2], st, len[N], f = 0, top; int chu[N], dfn[N], low[N], tim, inq[N], scc, Stack[N], t[N], mx; struct Edge { int to, next; } e[N << 1]; void add(int u, int v) { e[++cnt] = (Edge){v, h[u]}; h[u] = cnt; } void Tarjan(i...
6
#include <bits/stdc++.h> int a[1000010], st[1000010], top = 0; long long sum[1000010]; int main() { int n, i, j; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &a[i]); sum[i] = sum[i - 1] + a[i]; } for (i = 1; i <= n; i++) { while (top && (sum[i] - sum[st[top]]) * (i - st[top - 1]) <= ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int emp_c[n]; long long max_s[n]; memset(max_s, 0, sizeof(max_s)); long long globalMax = LONG_MIN; for (int i = 0; i < n; i++) { cin >> emp_c[i]; for (int j = 0; j < emp_c[i]; j++) { long long x; cin >> x; ...
2
#include <bits/stdc++.h> using namespace std; int z; int main() { int b; string a; cin >> b >> a; for (int i = 0; i < b; i++) { if (a[i] == '1') { z++; } else { cout << z; z = 0; } } cout << z << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 50; int t, n, a[N], b[N], p[N], f[N]; vector<int> v[N]; void change(int x, int k) { for (; x <= n; x += x & -x) f[x] = max(f[x], k); } int ask(int x) { int ret = 0; for (; x; x ^= x & -x) ret = max(ret, f[x]); return ret; } int main() { scanf("...
8
#include <bits/stdc++.h> typedef long long ll; const int MAX_SIZE = 5e3 + 1; ll persons[MAX_SIZE], chairs[MAX_SIZE]; ll dp[MAX_SIZE][MAX_SIZE]; int main() { ll n {0}, total_persons {0}, total_chairs {0}; ll occupied {1}, empty {0}, num; std::cin >> n; for (ll i = 0; i < n; i++) { std::cin >> ...
5
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int x, y, k; cin >> x >> y >> k; long long int coal = k; long long int s = coal * y; s += k; s--; long long int total = s / (x - 1); long long int other = s % (x - 1); if (other)...
1
#include <iostream> #include <algorithm> constexpr int N = 105; constexpr int p = 1000000007; int add(int x, int y) { return (x += y) >= p ? x - p : x; } int sub(int x, int y) { return (x -= y) < 0 ? x + p : x; } int n, q, k; int c[N], b[N]; int f[N][N * N]; int s[2][N * N]; int l[N]; int main() { std::ios::syn...
9
#include <bits/stdc++.h> using namespace std; mt19937 gen_rand; template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &a) { os << "("; os << a.first << ", "; os << a.second; os << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, vector<T> &a) { os << "{"; bo...
5
#include <bits/stdc++.h> using namespace std; long long a[40005], b[40005]; signed main() { long long n, m, k; cin >> n >> m >> k; long long cnt = 0; for (long long i = 1; i <= n; i++) { long long x; scanf("%lld", &x); if (x == 1) { cnt++; a[1]++; a[cnt + 1]--; } else { c...
3
#include <bits/stdc++.h> using namespace std; int n; int a[105]; int main() { ios_base::sync_with_stdio(0); ; cin >> n; int ans = 0; for (int i = 0; i < n; i++) { int temp; cin >> temp; ans += abs(temp); } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long maxn = 32; typedef long long myarray[maxn]; long long answer; long long now[maxn]; long long a[maxn]; long long k[maxn]; long long b[maxn]; long long r; long total, n; long p[maxn]; void solve(long ost, long inl) { if (ost % 2 == 0) ...
6
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<l...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; struct Point { long long x, y; } P[maxn]; int main() { int n; cin >> n; long long xmax = -0x3f3f3f3f, xmin = 0x3f3f3f3f, ymax = -0x3f3f3f3f, ymin = 0x3f3f3f3f; for (int i = 1; i <= n; i++) { cin >> P[i].x >> P[i].y; x...
6
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n, m, c = 0; string s = "qwertyuiopasdfghjkl;zxcvbnm,./ ", x, y; cin >> x >> y; string f = ""; for (i = 0; i != y.size(); i++) { for (j = 0; j < s.size(); j++) { if (x == "R" && s[j] == y[i]) f += s[j - 1]; if (x == "L" && s[...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 300005; const long long INF = (1LL << 60) - 1; long long a[MAXN], b[MAXN]; struct func { long long l, m, r; func() {} func(long long _l, long long _m, long long _r) : l(_l), m(_m), r(_r) {} func operator+(const func &t) const { return func(max(l...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 3005; const long long INF = 1e16; const int MOD = 998244353; long long b[MAXN], w[MAXN], size[MAXN]; pair<long long, long long> dp[MAXN][MAXN], tmp[MAXN]; int n, m, T; vector<int> e[MAXN]; void dfs(int u, int fa) { dp[u][0] = make_pair(0, b[u]); size[u]...
8
#include <bits/stdc++.h> int F[(1 << 20) + 5]; int sta, now; char s[1000005]; std::map<char, int> mp; int count(int x) { int num = 0; while (x) { if (x % 2) ++num; x /= 2; } return num; } int main() { int num = 0; scanf("%s", s + 1); int len = strlen(s + 1); for (int i = 1; i <= len; i++) { ...
7
#include <bits/stdc++.h> using namespace std; template <typename T> T load() { T r; cin >> r; return r; } template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; } struct Dummyf { template <typename... Ts> void operator()(Ts&&...) {} }; str...
4
#include <bits/stdc++.h> using namespace std; int n, d, modulo; int inv[99]; const int N(1111); int dp[N][N][15]; int f(int i, int j, int k) { if (dp[i][j][k] != -1) { return dp[i][j][k]; } else if (i == 0 && j == 0 && k == 0) { return 1; } else if (j == 0) { return 0; } else if (dp[i][j][k] != -1) ...
9
#include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; const int maxn = 50; vector<int> v1, v2; int n, mod, Size; int a[maxn]; int main() { scanf("%d %d", &n, &mod); int t = n / 2, sum, ans = 0, p; for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } for (int i = 0; i < (1 << t); ++i) { ...
5
#include <bits/stdc++.h> using namespace std; struct InputReader { char buf[1000001]; int p; inline InputReader() { p = 1000001; } inline void Flush() { p = 0; fread(buf, 1, 1000001, stdin); } inline char C() { if (p >= 1000001) Flush(); return buf[p++]; } inline char Readnum() { cha...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 50; struct node { long long a, b, cnt; } p[N]; bool cmp(node x, node y) { return x.a < y.a; } long long sum[N]; int vis[N]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &p[i].a); } for (int i = 1; i <=...
4
#include <bits/stdc++.h> using namespace std; int n, cnt; long long a, sum, ans[100010]; queue<long long> q[100010]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &a); for (int j = 60; j >= 0; j--) { if (a & (1LL << j)) { q[j].push(a); break; } } ...
7
#include <bits/stdc++.h> using namespace std; int len, ans; bool a[100010], b[100010]; char x[100010] = {}; void input() { scanf("%s", &x); len = strlen(x); for (int i = 1; i <= len; ++i) a[i] = x[i - 1] - '0'; scanf("%s", &x); for (int i = 1; i <= len; ++i) b[i] = x[i - 1] - '0'; } void work() { for (int i...
1
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; const int maxn = 200050; int a[maxn]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", a + i), a[i] ^= a[i - 1]; if (!a[n]) { puts("-1"); return 0; } for (int x = 1, y = 0; x <= n && y <= 31;)...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, count1 = 0, count2 = 0; string str; cin >> n; cin >> str; for (int i = 0; i < n; i++) { if (str[i] == 'S' && str[i + 1] == 'F') count1++; else if (str[i] == 'F' && str[i + 1] == 'S') count2++; } if (count1 > count2) ...
0
#include <bits/stdc++.h> using namespace std; vector<int> vec; int t[200010]; int main() { int n, k; cin >> n >> k; int tol = 0, ans = 0; int pre = -1, last = -1; for (int i = 1; i <= n; i++) { scanf("%d", &t[i]); if (t[i] < 0) { last = i; ans += 2; tol++; if (pre != -1) vec.pu...
5