solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int p1[100005], p2[100005]; int ans[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; while (cin >> n) { for (int i = 1; i <= n; i++) cin >> p1[i]; for (int i = 1; i <= n; i++) cin >> p2[i]; for (int i = 1; i <= n; i++) { ans[p...
4
#include <bits/stdc++.h> using namespace std; int n, m, k; unsigned long long c[500001]; int S[500001], T[500001]; unsigned long long X[500001], P[500001]; bool cmp(int i, int j) { return X[i] < X[j]; } int f[500001]; int ff(int x) { return f[x] ? f[x] = ff(f[x]) : x; } int Ans; int qPow(int b, int e) { int a = 1; ...
14
#include <bits/stdc++.h> using namespace std; long long lcm[3000], f[20][3000][55], num[55]; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long asd(long long now, long long mod, long long gbs, long long jud) { if (now < 0) { if (mod % gbs == 0) return 1; ...
17
#include <bits/stdc++.h> using namespace std; template <class T> inline void check_min(T &a, T b) { if (b < a) a = b; } template <class T> inline void check_max(T &a, T b) { if (a < b) a = b; } const int MAX_N = 3e5 + 5; inline int madd(int a, long long b, int m) { a = (a + b) % m; if (a < 0) a += m; return a...
20
#include <bits/stdc++.h> using namespace std; void fst() { printf("Ann\n"); } void sec() { printf("Mike\n"); } char s[500010]; int mn[500010]; int main() { cin >> (s + 1); int n = strlen(s + 1); mn[0] = 30; for (int i = 1; i <= n; i++) { mn[i] = min(mn[i - 1], s[i] - 'a'); } for (int i = 1; i <= n; i++)...
5
#include <bits/stdc++.h> using namespace std; int main() { long t; cin >> t; for (long i = 0; i < t; i++) { unsigned long long n; cin >> n; if (n == 1) { cout << 0 << endl; } else { int f = 0; long a = 0; long b = 0; long c = 0; while (f == 0) { if (n % ...
0
#include <bits/stdc++.h> using namespace std; deque<int> que[30]; string str; int main() { cin >> str; int n = str.length(); vector<long long> counter; counter.push_back(0); for (int i = 0; i < n; i++) { que[str[i] - 'a'].push_back(i); } for (int i = 0; i < n; i++) { vector<int> pos; for (int ...
12
#include <bits/stdc++.h> using namespace std; const int Max = 1e5 + 10; int main() { int n, j; cin >> n; int x = floor(sqrt(n)); for (int i = n; i >= 1; i -= x) { if (i - x + 1 <= 0) j = 1; else j = i - x + 1; for (; j <= i; j++) cout << j << " "; } cout << endl; return 0; }
8
#include <bits/stdc++.h> using namespace std; int main() { int n, i; int A[100001]; int sum = 0, max = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &A[i]); sum += A[i]; if (max < A[i]) max = A[i]; } sum = sum - max; int ans = max - sum + 1; printf("%d", ans); return 0; }
3
#include <bits/stdc++.h> using namespace std; const int MAXn = 2e5 + 10; int ar[MAXn], n; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; if (n % 2 == 0) return cout << "NO", 0; int ind = 0; bool flag = false; while (ind < n) { if (flag) { ar[ind] = (2 * ind + 2); ar...
4
#include <bits/stdc++.h> using namespace std; string che[101] = { "", "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", ...
14
#include <bits/stdc++.h> using namespace std; int main() { int ans = 0; int len; cin >> len; vector<int> cln; for (int l = 0; l < len; l++) { int val; cin >> val; cln.push_back(val); } int s, t; cin >> s >> t; if (s < t) { int x = 0; int y = 0; for (int l = s - 1; l < t - 1; l+...
0
#include <bits/stdc++.h> using namespace std; int main() { char n; bool ok = true; int cnt = 2; while (cin >> n) { if (n == '1') cnt = 0; else if (n == '4') { if (cnt == 2) ok = false; cnt++; } else ok = false; } puts(ok ? "YES" : "NO"); return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, m; int* c; queue<int> a; int br = 0; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); scanf("%d%d", &n, &m); c = new int[n]; for (int i = 0; i < n; i++) scanf("%d", &c[i]); for (int i = 0; i < m; i++) { int tmp; scan...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; template <class T> typename T::value_type arr_sum(const T& v, int n) { typename T::value_type sum = 0; for (int i = (0); i < (n); ++i) sum += v[i]; return sum; } struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_wit...
12
#include <bits/stdc++.h> using namespace std; const long long N = 2e6 + 7; vector<long long> adj[N]; long long a[N], sz[N], del[N], f[N], ans[N], dp[N], c; void dfs(long long u, long long p) { sz[u] = 1; for (long long v : adj[u]) if ((v ^ p) && !del[v]) { dfs(v, u); sz[u] += sz[v]; } } long lon...
16
#include <bits/stdc++.h> template <typename T> inline void mini(T &a, T b) { if (b < a) a = b; } template <typename T> inline void maxi(T &a, T b) { if (a < b) a = b; } struct Union { void init(int n) { P.resize(n); for (int i = 0; i < (n); ++i) P[i] = i; } int find(int i) { return P[i] == i ? i : (P[...
20
#include <bits/stdc++.h> int main() { char cmd[5]; int q, x = 0; scanf("%d", &q); while (q--) { scanf(" %s", cmd); if (q <= 0) return printf("%d\n", x + (cmd[1] == '+' ? 1 : -1)), 0; x += (cmd[1] == '+' ? 1 : -1); } return 0; }
0
#include <bits/stdc++.h> using namespace std; long long inf = 1e9; long long power(long long x, long long n, long long mod) { long long res = 1; x %= mod; while (n) { if (n & 1) res = (res * x) % mod; x = (x * x) % mod; n >>= 1; } return res % 1000000007; } long long dir[4][2] = {{1, 0}, {-1, 0}, ...
4
#include <bits/stdc++.h> #pragma GCC optimize("O3,inline,unroll-loops") using namespace std; int a[2020], b[2020]; char s[2020]; int f[2020][2020], g[2020][2020]; inline int Mod(int x) { return x + ((x >> 31) & 1000000007); } void Modadd(int &x, int y) { x = Mod(x + y - 1000000007); return; } int main(void) { int...
17
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { vector<long long> v1; long long n, k; cin >> n >> k; for (long long i = 1; i <= n; i++) { long long x; cin >> x; v1.push_back(x); } sort(v1.begin(), v1.end()); long long an...
8
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define all(vr) vr.begin(),vr.end() #define vi vector<int> #define vll vector<ll> const int N=2e5+10; ...
15
#include <bits/stdc++.h> using namespace std; int ri() { int x; if (scanf(" %d", &x) == EOF) return -1; return x; } long long int rl() { long long int x; if (cin >> x) return x; return -1; } string rs() { string s; if (cin >> s) return s; return ""; } const long long int mod = 998244353; struct Single...
10
#include <bits/stdc++.h> using namespace std; const int md = 1e9 + 7; int k, n, c[1005][1005]; int main() { c[0][0] = 1; for (int i = 1; i < 1005; i++) { c[i][0] = 1; for (int j = 1; j < 1005; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % md; } scanf("%d", &k); long long ans = 1; while (k--...
7
#include <bits/stdc++.h> using namespace std; const int dx[] = {-1, 0, 0, 1}; const int dy[] = {0, -1, 1, 0}; int n; int st; int a[300000 + 5]; int b[300000 + 5]; int c[300000 + 5]; int ans[300000 + 5]; bool cmp(int u, int v) { return a[u] < a[v]; } int main() { cin >> n; for (int i = (1), _b = (n); i <= _b; i++) c...
6
#include <bits/stdc++.h> using namespace std; int main() { int w, h, k, d = 0, ans; cin >> w >> h >> k; for (int i = 0; i < k; i++) { d += i; } ans = (2 * w + 2 * h - 4) * k - 16 * d; cout << ans; return 0; }
0
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; bool cmp(const pair<int, int> &p1, const pair<int, int> &p2) { if (p1.first > p2.first) return 1; if (p1.first == p2.first) return (p1.second < p2.second); return 0; } int main(int ab_ohab, char const *abohab[]) { ios::sync_with_stdio...
3
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int mod = 998244353; const int UP = 31500; const double PI = acos(-1.0); const double eps = -1e8; struct node { int val; int idx; bool operator<(const node& B) const { ...
9
#include <bits/stdc++.h> using namespace std; int head[2000050], nxt[2000050], to[2000050], cnt = 1, n, flow[2000050]; int dep[1050], Q[1050], a[1050]; int vis[2000050], pri[2000050], pri_cnt, ch[1050][2]; int vec[1050][1050], vsize[1050], inv[1050]; void sieve() { int i, j, lim = 15000; for (i = 2; i <= lim; i++) ...
15
#include <bits/stdc++.h> using namespace std; const long long P[6][3] = {{1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1}}; const long long BASE = 571; const long long INF = 0x7f7f7f7f; long long len[4], p[1000005]; long long ans = INF; long long hs[4][1000005]; char s[4][1000...
14
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; vector<int> dp(1 << 20); for (int i = 0; i < s.size(); ++i) { vector<bool> done(21); int mask = 0; for (int j = 0; i + j < s.size(); ++j) { int t = s[i + j] - ...
14
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3fll; const long long M = 1e9 + 7; const long long maxn = 100007; const double eps = 0.00000001; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } template <typename T> inline T abs(T...
15
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { if (!b) return a; return gcd(b, a % b); } int main() { int n; printf("YES\n"); scanf("%d", &n); for (int i = 0; i < n; i++) { int x1, y1, x2, y2; scanf("%d %d %d %d", &x1, &y1, &x2, &y2); printf("%d\n", ((4 + 2 * ...
13
#include <bits/stdc++.h> using namespace std; vector<int> c[11]; int main() { int n, k; scanf("%d%d", &n, &k); int a[n + 5]; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); c[a[i] % 10].push_back(i); } for (int i = 9; i >= 1; i--) { if (c[i].size()) { int x = 10 - i; for (int j = 0...
6
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int a[N]; int pt[N]; int num; bool check(int x, int k) { if (x == 0) return 1; int cnt = 0; for (int i = 0; i < N; i++) { cnt += a[i] / x; } return cnt >= k; } int main() { int n, k, x; cin >> n >> k; for (int i = 0; i < n; i++) { ...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; char c; string str; int n, m, var, st, en, dp[26][1505], ans[26][1505]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> str; for (int i = 0; i < 26; ++i) { for (int j = 0; j < n; ++j) { int cng = 0; for (in...
8
#include <bits/stdc++.h> using namespace std; long long n, m, k; long long read() { long long s = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar(); } return s * f; }...
9
#include <bits/stdc++.h> using namespace std; vector<tuple<int, int, int, int, int> > points; vector<double> length[1000]; double absolute(tuple<int, int, int, int, int> x) { return sqrt(get<0>(x) * get<0>(x) + get<1>(x) * get<1>(x) + get<2>(x) * get<2>(x) + get<3>(x) * get<3>(x) + get<4>(...
9
#include <bits/stdc++.h> using namespace std; double toRad(double deg) { return deg / 360. * 2. * (double)M_PI; } pair<int, int> rot(pair<int, int> origin, pair<int, int> init, int times) { int x = init.first - origin.first; int y = init.second - origin.second; for (int i = 0; i < times; i++) { int newx = -y;...
12
#include <bits/stdc++.h> using namespace std; long long dp[1000010][4]; int a[1000010]; int n, t1, t2, t3, d; void mind(long long &a, long long val) { a = min(a, val); } int main() { scanf("%d%d%d%d%d", &n, &t1, &t2, &t3, &d); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); memset(dp, 0x3f, sizeof(dp)); dp[1][...
15
#include <iostream> using namespace std; int main() { int t; cin>>t; for (int z = 0; z < t; z++) { int n; cin>>n; int m = 1; int l = 0; int lc = 0; for (int i = 1; i <= n; i++) { int x; cin>>x; if (x == l) { ...
0
#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--){ string s; cin>>s; int len; len=s.size(); int d=0,i; for(i=1;i<len;i++){ if(s[i]>s[0]) break; else{ if(s[i]<s[0]){ d...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f; int price = 0, waste = 0; if (e > f) { waste = min(a, d); price += (waste * e); d -= waste; waste = min(d, min(b, c)); p...
0
#include <bits/stdc++.h> using namespace std; const string bad = "Bad", yes = "Yes", no = "No"; long long N; int K; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); bool guess(long long l, long long r) { cout << l << " " << r << endl; string s; cin >> s; if (s == bad) assert(0); if (l == r...
13
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") int dp[10][10][10][2]; int id[10][10][10][2], cnt; const int INF = 0x3f3f3f3f; struct Node { int i, j, k, l; Node() {} Node(int _i, int _j, int _k, int _l) { i = _i, j = _j, k = _k, l = _l; } } trfrom[10][10][10][2]; inline int& f(const N...
16
#include <bits/stdc++.h> using namespace std; void solve() { long long n, m, k; cin >> n >> m >> k; vector<long long int> a(n + 1); long long b[n + 1][m + 1]; for (long long i = 1; i <= n; i++) cin >> a[i]; for (long long i = 1; i <= n; i++) for (long long j = 1; j <= m; j++) cin >> b[i][j]; long long...
9
#include <bits/stdc++.h> long long a[10]; char b[4], tmp[10]; int main(void) { while (~scanf("%lld %lld %lld %lld\n", &a[0], &a[1], &a[2], &a[3])) { gets(tmp); b[0] = tmp[0]; b[1] = tmp[2]; b[2] = tmp[4]; int i, j, k, q, m; long long ans = -1; for (i = 0; i < 4; i++) for (j = i + 1; ...
8
#include <bits/stdc++.h> using namespace std; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } const int INF = 1 << 29; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n >> b) & 1; } inline void set_bit(int &n, int b) { n |= two(b); } inline void unset_bit(int &n, int b...
6
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") using namespace std; clock_t timeStart, timeFinish; void timeBegin() { timeStart = clock(); } void timeEnd() { timeFinish = clock(); } void timeDuration() { timeEnd(); double time_taken = doub...
8
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; bitset<30> b(n); int ans = 1; for (int i = 0; i < 31; i++) { if (n & (1 << i)) ans *= 2; } cout << ans << endl; } }
4
#include <bits/stdc++.h> using namespace std; int main() { double a, b, c; cin >> a >> b >> c; if (a == 0) { if (b == 0) { if (c == 0) cout << -1 << endl; else cout << 0 << endl; } else { cout << 1 << endl; printf("%.9lf\n", -c / b); } } else { if (b * b -...
12
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); int T; T = 1; while (T--) { int n, a, b, i, j, l, r, mid, ans, x, y, ct; cin >> n >> a >> b; l = 1, r = (a + b); ans = -1; while (l <= r) { mid = (l + r) / 2; x = a, y = b; ct = 0; ...
4
#include <bits/stdc++.h> using namespace std; long long n, a, b, T, toL[500010], toR[500010]; string orient; bool can(int x) { if (x == 0) return true; long long first = 1, goBack = 0; if (orient[0] == 'w') first += b; if (x == 1) return first <= T; if (toL[x - 2] + first <= T) return true; if (toR[x - 2] +...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, k, x = 0; char ch; cin >> n >> k; for (int i = 0; i < n; i++) { ch = 'a' + x; cout << ch; x++; x = x % k; } return 0; }
0
#include <bits/stdc++.h> using namespace std; set<int> s[100005]; int m[100005]; set<int> t, v; int cnt[100005]; int n, k; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; cin >> n >> k; int x, y; for (int i = 1; i < n; i++) { cin >> x >> y; s[x].insert(y); s[y].insert(x); m[x...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1 || n % 2 == 0) { cout << -1 << endl; } else { vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } int ans = 0; for (int i = n - 1; i >= 2; i -= 2) { int idx = i + 1, idx_1 = i, i...
9
#include <bits/stdc++.h> using namespace std; const int N = 3e4 + 11; int n, jav; string s[N]; int main() { bool c = 0; cin >> n; for (int i = 0; i < n; i++) cin >> s[i]; int m = s[0].size(); for (int j = 0; j < m; j++) { for (int i = 0; i < n; i++) if (s[i][j] != s[0][j]) { jav = j; ...
0
#include <bits/stdc++.h> using namespace std; long long ch[300005], q[300005], dis[300005][2], deep[300005][2], siz[300005], n, m, tot, target[600005], pre[600005], last[300005], w[600005]; bool type[300005]; void add(long long x, long long y, long long z) { target[++tot] = y; pre[tot] = last[x]; last[x] = to...
18
#include <bits/stdc++.h> using namespace std; const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342; pair<double, double> t[100010]; bool done[100010]; map<pair<pair<int, int>, pair<int, int> >, long long> dp; vector<pair<double, vector<int> > > x, y; long...
15
#include <bits/stdc++.h> using namespace std; bool mark[1000 * 10]; vector<pair<long long, long long> > v; int main() { long long x1, y1, x8, y8; cin >> x1 >> y1 >> x8 >> y8; if (x1 > x8) swap(x1, x8); if (y1 > y8) swap(y1, y8); for (long long i = y1; i <= y8; i++) { v.push_back(make_pair(x1, i)); v.p...
5
#include <bits/stdc++.h> using namespace std; int n; pair<int, int> ar[400003]; int pos0[400003]; int pos1[400003]; int tree[4 * 400003]; vector<pair<pair<int, int>, int> > v; void update(int cx, int cy, int q, int val, int pos) { if (cy < q || q < cx) return; tree[pos] = max(tree[pos], val); if (cx == cy) return...
10
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; int dr[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; const int maxn = 505; char place[maxn][maxn]; int n, m; int k; bool flag; stack<pair<int, int> > s; void dfs(int x, int y) { if (flag) flag = false; else s.p...
11
#include <bits/stdc++.h> const long long N = 2e5 + 10; const long long mod = 1e9 + 7; const int Max_n = 1e6 + 10; using namespace std; map<string, int> hap; queue<string> q; stack<string> p; int main() { int n, m; cin >> n >> m; while (n--) { string s; cin >> s; hap[s]++; } int sum = 0; string o...
3
#include <bits/stdc++.h> using namespace std; void fast() { ios::sync_with_stdio(false), cin.tie(0); } const int S = 2e5 + 5; long long N1[S]; long long N2[S]; map<long long, int> V; int main() { fast(); int n, m; cin >> n; long long Q; for (int i = 0; i < n; i++) { cin >> Q; ++V[Q]; } cin >> m; ...
5
#include <bits/stdc++.h> using namespace std; long num[1010]; set<long> mp[1010]; long output(long l, long r) { long i, q; printf("? %ld", r - l + 1); for (i = l; i <= r; i++) printf(" %ld", i); printf("\n"); fflush(stdout); scanf("%ld", &q); return q; } int main() { long _ = 1, __ = 1, n, m, i, j, x, q...
16
#include <bits/stdc++.h> using namespace std; int main() { int Sz; cin >> Sz; int Cnt = (Sz - 11) / 2 + (Sz - 11) % 2; string S1; cin >> S1; for (int K = 0; Cnt > 0; K++) { if (S1[K] != '8' && Cnt > 0) { S1.erase(K, 1); Cnt = Cnt - 1; K = K - 1; } } int Cnt2 = 0; for (int K =...
4
#include <bits/stdc++.h> using namespace std; long long ar[200005], p[200005]; map<long long, long long> mp; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); ; long long n; cin >> n; ar[0] = p[0] = 0; for (int i = 0; i < n; i++) cin >> ar[i + 1], p[i + 1] = p[i] + ar[i + 1]; long long sum = 0...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int n, k; int fa[maxn]; int a[maxn]; int cnt; int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); } void merge(int x, int y) { int fx = gf(x); int fy = gf(y); if (fx != fy) { fa[fx] = fy; --cnt; } } int main() { scanf("%d%d"...
4
#include <bits/stdc++.h> using namespace std; int mu[300005], prime[300005], tot, n; int num[300005], ans[300005], f[300005], g[300005]; bool flag[300005]; void Prime(int N) { mu[1] = 1; for (int i = 2; i <= N; i++) { if (flag[i] == false) tot++, prime[tot] = i, mu[i] = -1; for (int j = 1; j <= tot; j++) { ...
17
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string str; cin >> str; int ans = 0; int countA = 0; for (int i = 0; i < n; i++) { if (str[i] == 'I') { ans++; } else if (str[i] == 'A') { countA++; } } if (ans == 0) { cout << countA; } else { ...
2
#include <bits/stdc++.h> int T, n, a[20], dp[20][33000][20], sum[33000], preu[20][33000][20], prep[20][33000][20]; int main() { scanf("%d", &T); for (; T; --T) { scanf("%d", &n); int L = 1 << n; for (int i = 0; i < n; ++i) scanf("%d", a + i); for (int i = 1; i < L; ++i) { sum[i] = 0; ...
22
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int i = 0, l = 0, count = 0; while (s[i] != '\0') { if (s[i] == '(') { l++; } else if (s[i] == ')') { if (l != 0) { l--; count++; } } i++; } cout << count * 2; }
6
#include <bits/stdc++.h> using namespace std; bool canMultiple(long long a, long long b) { return a <= LLONG_MAX / b; } long long gcd(long long a, long long b) { long long t; while (b != 0) t = b, b = a % b, a = t; return a; } void printFrac(long long a, long long b) { long long g = gcd(a, b); printf("%" PRId...
10
#include <bits/stdc++.h> using namespace std; const int N = 2e5; struct Tap { long long x; long long y; }; bool compare(Tap& t1, Tap& t2) { return t1.y < t2.y; } long long min(long long a, long long b) { return (a < b) ? a : b; } Tap taps[N + 10]; int main() { long long n, T; cin >> n >> T; double ans = 0; ...
12
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") using namespace std; using ll = long long...
18
#include <bits/stdc++.h> using namespace std; long long* reverse(long long* b, int n) { long long* b2 = new long long[n]; for (int i = 0; i < n; i++) b2[i] = b[n - 1 - i]; return b2; } void print(vector<char> v) { cout << "SMALL" << endl << v.size() << endl; string s; for (int i = v.size() - 1; i >= 0; i--)...
19
#include <bits/stdc++.h> using namespace std; int n, m; int ans0, ans1; vector<int> G[200010]; int hui[200010]; int vis[200010]; bool a[200010]; bool b[200010]; void bfs(int p) { memset(vis, -1, sizeof(vis)); memset(a, false, sizeof(a)); memset(b, false, sizeof(b)); queue<int> que; que.push(p); vis[p] = 0; ...
9
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } long long int binpow(long long int a, long long int n) { long long int res = 1; a %= 1000000007; while (n) if (n & 1) { res *= a; res %...
12
#include <bits/stdc++.h> using namespace std; struct SEG { long long cnt, sum; }; int n, m; long long t; vector<pair<int, int> > a; vector<SEG> seg; void insert(int o, int l, int r, int POS, int VAL) { if (r < POS || POS < l) return; if (l == r) { seg[o].cnt = 1; seg[o].sum = VAL; return; } int mi...
13
#include <bits/stdc++.h> using namespace std; int n, m; bool ok(int i, int j) { return i < n && j < m && i >= 0 && j >= 0; } int main() { ios::sync_with_stdio(false); cin.tie(0); int test; cin >> test; for (int cur_test = 1; cur_test <= test; cur_test++) { int k; cin >> n >> m >> k; string res[n];...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, l, a; cin >> n >> l >> a; int x = 0; int q, w; int ans = 0; for (int i = 0; i < n; ++i) { cin >> q >> w; ans += (q - x) / a; x = q + w; } ans += (l - x) / a; cout << ans << endl; }
2
#include <bits/stdc++.h> using namespace std; void fastIO() { std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } template <typename T, typename U> inline void mnze(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> inline void mxze(T &x, U y) { if (x < y) x = y; } void _scan(int &x)...
13
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e6 + 2; int prime[MaxN], vis[MaxN], cnt[MaxN]; int pri_cnt; void get_prime() { int m = (int)sqrt(1000000 + 1); pri_cnt = 0; memset(vis, 0, sizeof(vis)); vis[0] = 1; vis[1] = 1; for (int i = 2; i <= m; ++i) { if (!vis[i]) { prime[pri_c...
8
#include <bits/stdc++.h> using namespace std; const long long mx = (1e5) + 1; const long long mod = 1000000007; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> a(n); vector<int> f, s; long long sum = 0, sum1 = 0; for (int i = 0; i < n; i++) { ci...
6
#include <bits/stdc++.h> #pragma GCC optimize(3) #pragma GCC optimize(2) using namespace std; const int maxn = 510; const int inf32 = 1e9; const long long inf64 = 1e18; const int mod = 998244353; int mul(int first, int second) { return (long long)first * second % mod; } int add(int first, int second) { long long ret ...
17
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); } template <class T> inline T lcm(T a, T b) { return ((a) / gcd((a), (b)) * (b)); } template <class T> inline T BigMod(T Base, T power, T M = 1000000007) { if (power == 0) retur...
12
#include <bits/stdc++.h> using namespace std; int main() { long long int n, sum = 0, count = 0, i, k = 1, x; cin >> n; long long int a[100]; vector<long long int> v; for (i = 81; i >= 0; i--) { x = n - i; sum = 0; while (x != 0) { sum = sum + x % 10; x = x / 10; } if (sum == i)...
4
#include <bits/stdc++.h> using namespace std; int main() { int chas, minut; string time; cin >> time; chas = (((int)time[0] - 48) * 10 + ((int)time[1] - 48)) % 12; minut = ((int)time[3] - 48) * 10 + ((int)time[4] - 48); double ugol1, ugol2; ugol2 = 6 * minut; double ghf = (double)minut / 2; ugol1 = 30...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; for (i = 1; i <= n; i++) { if (i % 2 != 0) cout << "I hate" << " "; else cout << "I love" << " "; if (i == n) cout << "it" << " "; else cout << "that" ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int arr[4]; for (int i = 0; i < 4; i++) cin >> arr[i]; sort(arr, arr + 4); long long sum = arr[3]; long long int A, B, C; A = sum - arr[0]; B = sum - arr[1]; C = sum - arr[2]; cout << A << " " << B << " " << C << endl; return 0; }
0
#include <bits/stdc++.h> int A, H, W; double ax = 1e100; void exgcd(int a, int b, int& x, int& y) { if (!b) { x = 1, y = 0; } else { exgcd(b, a % b, y, x); y -= a / b * x; } } void solve(int x, int y) { int p = y / A, q = y - p * A; if (!p) return; int t = ((long long)H * p - q) % y, t2 = (A + H...
19
#include <bits/stdc++.h> using namespace std; const int MAXN = 50 + 5; int n, m; int sum[MAXN][MAXN]; int a, b; int main() { cin >> n >> m; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> sum[i][j]; } } cin >> a >> b; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m...
4
#include <bits/stdc++.h> using namespace std; int m[7] = {1869, 1968, 1689, 6198, 1698, 1986, 1896}; int main() { int d[10] = {0}, i, r = 0; string s; cin >> s; for (i = 0; i < s.size(); i++) d[s[i] - '0']++; d[1]--; d[6]--; d[8]--; d[9]--; for (i = 1; i <= 9; i++) while (d[i]--) { cout << i...
8
#include <bits/stdc++.h> using namespace std; int main() { // freopen("input.txt", "r", stdin); ios::sync_with_stdio(0); cin.tie(NULL); int n; cin >> n; vector<pair<int, int>> a, b; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if ((i + j) % 2 == 0)...
9
#include <bits/stdc++.h> using namespace std; template <typename T> vector<T>& operator--(vector<T>& v) { for (auto& i : v) --i; return v; } template <typename T> vector<T>& operator++(vector<T>& v) { for (auto& i : v) ++i; return v; } template <typename T> istream& operator>>(istream& is, vector<T>& v) { for...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; const int inf = (1 << 28) - 1; struct Ques { int w, kind, id; } A[maxn]; int fa[maxn]; struct node { int u, v; node(int a = 0, int b = 0) { u = a, v = b; } } S[maxn]; int cmp(Ques u, Ques v) { if (u.w == v.w) return u.kind > v.kind; return...
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int h, m; cin >> h >> m; int ans = (24 - h) * 60 - m; cout << ans << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; pair<int, int> app[15]; bitset<5005> in[200005]; int arr[15][100005]; int main() { int n, k, q; scanf("%d%d%d", &n, &k, &q); for (int i = 0; i < k; i++) { for (int j = 0; j < 1 << 12; j++) { if (j & (1 << i)) in[i].set(j); } for (int j = 0; j < n; j+...
21
#include <bits/stdc++.h> template <typename T> T in() { char ch; T n = 0; bool ng = false; while (1) { ch = getchar(); if (ch == '-') { ng = true; ch = getchar(); break; } if (ch >= '0' && ch <= '9') break; } while (1) { n = n * 10 + (ch - '0'); ch = getchar(); ...
15
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!(ch >= '0' && ch <= '9')) { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + (ch - '0'); ch = getchar(); } return x * f; } const int N = 20...
13