solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 28; const long long INF = 1LL << 60; template <class T> inline void Rd(T &res) { res = 0; char c; while (c = getchar(), !isdigit(c)) ; do res = (res << 1) + (res << 3) + (c ^ 48); while (c = getchar(), isdigit(c)); } template <class T> voi...
5
#include <bits/stdc++.h> using namespace std; int main(){ int N,X,Y; cin >> N >> X >> Y; int count[2850]; for(int i=1; i<=N-1; i++){ for(int j=i+1; j<=N; j++){ count[min(j-i,abs(X-i)+1+abs(Y-j))]++; } } for(int k=1; k<=N-1; k++) cout << count[k] << endl; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) //const ll mod = 1000000007; int PAIR[6050]; string dp[6050]; int main() { //cout.precision(10); int N; string S; cin >> N >> S; S = "#" + S; queue<int> a, b; for(...
0
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int maxn = 2e5+100; struct SECTION { ll l,r; SECTION() {} SECTION(ll l,ll r):l(l),r(r) {} bool operator<(const SECTION& oth) const { if(l==oth.l) return r < oth.r; return l < oth.l; } bool operator==(const SECTION& oth) const { re...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000") using namespace std; template <class T> void out(map<char, T> &a, string s = "(%3c ->%3d)") { for (auto(it) = (a).begin(); (it) != (a).end(); ++(it)) printf(s.c_str(), it->first, it->second); printf("\n"); } template <class T> void out(vector<...
4
#include <bits/stdc++.h> using namespace std; unsigned long long power(unsigned long long x, int y, int p) { unsigned long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } bool cmp(pair<string, int> &a, pair<string, int> &b) { ...
3
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; void solve() { int n; cin >> n; int ar[n], lock[n]; for (int i = 0; i < n; i++) cin >> ar[i]; vector<int> temp, res; bool flag = false; for (int i = 0; i < n - 1; i++) { if (ar[i] > ar[i + 1]) { flag = true; } } if (f...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; int N; char res[102]; vector<string> g[102]; int cnt[102][26]; int r[26]; int tmp[26]; int q[51][2]; int m; int a[100000]; int b[100000]; int v1[100000]; int v2[100000]; int f[51][2]; int lf[51][2]; int rg[51][2]; void query(int a, int b) { i...
3
#include <bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; int n, m, v[200002]; int bg[200002], sm[200002]; map<int, int> mp; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; int posm = 0; for (int i = 1; i <= n; ++i) { cin >> v[i]; if (v[i] ...
5
#include<bits/stdc++.h> using namespace std; int main(){ int x; cin>>x; cout<<3*x*x; return 0; }
0
#include <bits/stdc++.h> char a[25], b[25]; int main() { int i, A = 0, B = 0; scanf("%s%s", a, b); for (i = 0; i < strlen(a); i = i + 2) { if (a[i] == '8' && b[i] == '[') A++; if (a[i] == '[' && b[i] == '8') B++; if (a[i] == '[' && b[i] == '(') A++; if (a[i] == '(' && b[i] == '[') B++; if (a[i...
1
#include <bits/stdc++.h> using namespace std; int hed[600010], nxt[600010], to[600010], cnt; inline void addedge(int u, int v) { nxt[++cnt] = hed[u]; hed[u] = cnt; to[cnt] = v; } int siz[300010], root[300010], ans[300010]; int mx[300010]; int id[6000010], son[6000010][2], tot; int n, q; int merge(int x, int y) { ...
2
#include <iostream> using namespace std; string s; int i; int main() { cin>>s; for(i=1; i<=s.size(); i++) cout<<"x"; }
0
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long INFL = LLONG_MAX; const long double pi = acos(-1); long long N; int s(long long x) { int tot = 0; while (x) { tot += x % 10; x /= 10; } return tot; } int main() { ios_base::sync_with_stdio(0); cout.precision(15); ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, i = 0; cin >> n; int a[n]; int sumi = 0, sumo = 0, sum = 0; for (i = 0; i < n; i++) { cin >> a[i]; sum = sum + a[i]; } if (sum != 0) { cout << "YES"; cout << endl << "1" << endl << "1 " << n; exit(0); } int j = 0, fl...
1
#include <bits/stdc++.h> using namespace std; int n, h; long long dp[40][40][40]; long long calc(int l, int r, int d) { if (dp[l][r][d] != -1) return dp[l][r][d]; if (l > r && d == 0) return dp[l][r][d] = 1; else if (l > r) return dp[l][r][d] = 0; if (l == r && d == 1) return dp[l][r][d] = 1; else...
4
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(nam...
3
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long f[2001][2001]; long long ans; long long n, m; int main() { cin >> n; cin >> m; for (int i = 2; i <= m; i++) f[1][i] = 1; for (int i = 2; i <= n; i++) { f[i][1] = 1; for (int j = 2, s = 0; j <= m; j++) { s += f[i...
4
#include <bits/stdc++.h> using namespace std; const int INF = 1001001001; const long long LINF = 1e16; const double pi = 3.1415926535897932; const string endstr = "\n"; template <typename T> T gcd(T a, T b) { return (a == 0) ? b : gcd(b % a, a); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long s = n * (n + 1) / 2; if (s % 2 == 0) { cout << "0"; } else { cout << "1"; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, dt; int main() { double d, l, v1, v2, a, b, c; while (scanf("%lf %lf %lf %lf", &d, &l, &v1, &v2) == 4) { a = (l - d) / 2; b = (v1 + v2) / 2; c = a / b; printf("%.6lf\n", c); } return 0; }
1
#include <bits/stdc++.h> using namespace std; const long long MAX = 1e6; const long long mod = 1e9 + 7; const long long inf = 1e18 + 12; long long arr[MAX]; map<long long, long long> mm; int main() { ios_base::sync_with_stdio(false); cout.tie(NULL); cout.tie(NULL); ; long long tt; cin >> tt; while (tt--) ...
3
#include <bits/stdc++.h> using namespace std; long long pow(long long a, long long b) { if (b == 1) { return a; } if (b % 2 == 1) { return pow(a, b - 1) * a; } else { long long x = pow(a, b / 2); return x * x; } } long long powm(long long a, long long b, long long m) { if (b == 1) { retu...
1
#include <bits/stdc++.h> using namespace std; int main() { int row, col, temp, cntp, x, y, x1, y1, i, j, dif, dif2; int a[5][5]; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { cin >> a[i][j]; } } for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) { if (a[i][j] == 1) { ...
1
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int h = 0, g = 0, f = 0; while (h < s.size()) { g = 0; while (h < s.size() && s[h] == s[h + 1]) { g++; h++; } if (g % 2 == 1) f++; h++; } cout << f; }
1
#include <bits/stdc++.h> using namespace std; int main(){ int r,c; cin>>r>>c; int a[r][c],b[r],d[c],e=0; for(int s=0;s<c;s++){ d[s]=0; } for(int i=0;i<r;i++){ b[i]=0; for(int j=0;j<c;j++){ cin>>a[i][j]; b[i]+=a[i][j]; d[j]+=a[i][j]; } } for(int k=0;k<r;k++){ for(int l=0;l<c;l++){...
0
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007LL; int n, m; vector<pair<pair<int, int>, int>> g; vector<pair<int, int>> v[200009], u[200009]; bool ok; int w[200009]; bool chk[200009]; vector<int> q; void Dfs2(int u, int f) { chk[u] = 1; for (auto i : v[u]) if (chk[i.first] == 0 &...
4
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const double PI = acos(-1.0); const double EPS = 1e-10; inline int readint() { int sum = 0; char c = getchar(); bool f = 0; while (c < '0' || c > '9') { if (c == '-') f = 1; c = getchar(); } while (c >= '0' && c <= '9') { ...
4
#include <bits/stdc++.h> using namespace std; clock_t time_p = clock(); void Time() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n"; } const int INF = 1e9 + 7; long double pi = 3.1415926535897932; const long long INF64 = 9e18; const long long mod = 1e9 + 7; const int...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, l, m, n, a, b, c, d, x, y, z, p, q; while (cin >> n) { long long int sum = 0; for (x = 1; x <= n; x++) { cin >> a; sum += a; } long long int ans = 0; n++; for (i = 1; i <= 5; i++) { sum++; ...
1
#include <bits/stdc++.h> using namespace std; vector<int> a[120005]; int n, m, father[120005], l[120005], deep[120005], num[120005], q[120005][30], r, o, x, y, s1, s2, lca, ll, t, d, u[30]; int build(int k, int pre) { father[k] = pre; deep[k] = deep[pre] + 1; num[k] = 1; q[k][1] = father[k]; r = 1; o = ...
5
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9, maxn = (int)1e5 + 1; const double eps = (double)1e-8; const int mod = (int)1000000009; int main() { long long n, m, c, d, k, q, o = 0, kol = 0; cin >> c >> d >> n >> m >> k; q = n; n = n * m - k; m = q; kol = 0; while (o < n) { if...
1
#include<iostream> using namespace std; int h,n,a[100009],sum; int main(){ cin>>h>>n; for(int i=0;i<n;i++){ cin>>a[i]; sum+=a[i]; } cout<<((sum>=h)?"Yes":"No")<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; int n, l, i, same = 0; bool ch; cin >> n >> s; for (l = 1; l <= n / 2; l++) { ch = 1; for (i = 0; i < l; i++) { if (s[i] != s[i + l]) { ch = 0; break; ...
2
#include <bits/stdc++.h> using namespace std; long long int dp[35][35][55], n, m, k; inline long long int call(long long int x, long long int y, long long int rem) { if (rem == 0) return 0; if (rem == (x * y)) return 0; if (dp[x][y][rem] != -1) return dp[x][y][rem]; long long int ans = 1e18; for (long long in...
5
#include <bits/stdc++.h> using namespace std; struct node { long long l, r; }; bool cmp(node a, node b) { if (a.l != b.l) return a.l < b.l; return a.r < b.r; } long long T, N, S; node a[200005]; bool can(long long x) { long long cnt = 0; long long money = 0; for (long long i = N; i >= 1; i--) { if (a[i]...
4
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 9; int main() { ios_base::sync_with_stdio(0); long long n, k; cin >> n >> k; vector<long long> a(n); long long ex = 0, ans = 0; for (int i = 0; i < n; i++) { cin >> a[i]; a[i] = max(0LL, a[i] - ex); long long need = (a[i] + ...
4
#include <bits/stdc++.h> using namespace std; int t(int n, int k) { int x = 1; int p = k; while (p <= n) { p = k; p = p + x; x = x * 2; } p = p - x / 2 + x / 4; return p; } int main() { unsigned int a; cin >> a; unsigned int b[a + 1]; unsigned int i = 1; for (i = 1; i <= a; i++) { ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long a[n], b[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(b, b + n); long long min = b[0]; long long start = 0; for (long long i = 0; i < n; i++) { if (a[i] == min) { st...
1
#include <bits/stdc++.h> using namespace std; bool isprime[1000100]; int main() { vector<long long> primes; primes.push_back(2); for (int i = 0; i <= 1000000; i++) isprime[i] = 1; isprime[0] = isprime[1] = 0; for (long long i = 3; i <= 1000000; i += 2) { if (isprime[i]) { for (long long j = i * i; j...
2
#include <stdio.h> #include <math.h> #include <vector> #include <iostream> using namespace std; int main(void) { vector<double> r; int n; while (true) { cin >> n; if (n==-1){break;} double x=1,y=0,s=0,c=0; for (int i=1; i<n; i++) { if(x!=0) { s = y/(sqrt(x*x+y*y)); c = x/(sqrt(x*x+y*y)); ...
0
#include <bits/stdc++.h> using namespace std; template <typename T> T rd() { T nmb = 0; int sgn = 0; char chr = getchar(); while (!isdigit(chr)) { if (chr == '-') sgn = 1; chr = getchar(); } while (isdigit(chr)) { nmb = (nmb << 3) + (nmb << 1) + chr - '0'; chr = getchar(); } return sgn ?...
6
#include <bits/stdc++.h> using namespace std; const int N = 5005 + 5; int t, n, m, l, r, sum[N], dep[N]; bool solve() { fill(dep + 1, dep + n + 1, 1); m = n * (n - 1) / 2 - m; for (l = 2, r = n; l < r; --r) { while (l < r && (m - r + l < 0 || dep[l] == dep[l - 1] * 2)) l++; if (l >= r) break; m -= r, ...
5
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)n;i++) #define all(c) (c).begin(),(c).end() #define pb push_back #define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0); using namespace std; namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(cons...
0
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, seed = 131, MAXN = 0; int main() { cin.tie(0)->sync_with_stdio(0); int t; cin >> t; while (t--) { int n; cin >> n; string a, b; cin >> a >> b; a = " " + a; b = " " + b; vector<int> ans; int uwu1 = 1, uwu2 = n;...
1
#include<bits/stdc++.h> using namespace std; int dp[3001][3001]; int a[3000], b[3000]; int N, T, S; int rec(int idx, int time){ if(idx == N || time == T) return(0); if(~dp[idx][time]) return(dp[idx][time]); int ret = max( rec( idx + 1, time), rec( idx, time + 1)); if((time + b[idx] <= S || time >= S) && tim...
0
#include <bits/stdc++.h> const int N = 1e5; const int inf = 1e9 + 10; using namespace std; void yes() { cout << "YES" << endl; } void no() { cout << "NO" << endl; } map<long long int, long long int> cnt; void prime_factorization(long long int n) { for (long long int i = 2; i * i <= n; i++) { while (n % i == 0) { ...
3
#include <bits/stdc++.h> const int maxn = 1000010; int n, r[maxn * 4], ans[maxn]; char s[maxn], S[maxn * 4]; int min(int a, int b) { return a < b ? a : b; } int main() { scanf("%d%s", &n, s); S[0] = 2; for (int i = 0; i < n * 2; i++) { S[i * 2 + 1] = 1; S[i * 2 + 2] = s[i % 2 ? n - i / 2 - 1 : i / 2]; }...
6
#include <bits/stdc++.h> #define LL long long using namespace std; const int N=2e5+10; const int B=316; 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; } void print(LL x){ if(x>9) print(x...
0
#include <bits/stdc++.h> using namespace std; void f(); int main() { int t; cin >> t; while (t--) { f(); } return 0; } void f() { int a, b, c, d; cin >> a >> b >> c >> d; cout << max((a + b), (c + d)) << endl; }
2
#include <iostream> using namespace std; int main() { int a,b[100010]={0},c[110],ans =0; cin >> a ; for(int i=1;i<=a;i++) cin >> b[i]; for(int i=0;i<=a+1;i++){ ans += abs(b[i]-b[i+1]); } for(int i=1;i<=a;i++){ cout << ans + abs(b[i-1]-b[i+1]) -abs(b[i-1]-b[i]) -abs(b[i]-b[i+1])...
0
#include <bits/stdc++.h> using namespace std; int ships = 0, n, k, a, m; set<pair<int, int> > xs; int cal(int l, int r) { return (r - l + 2) / (a + 1); } int main() { cin >> n >> k >> a >> m; xs.insert({n, 1}); ships = cal(1, n); for (int i = 1; i <= m; i++) { int x; int newa = 0, newb = 0; cin >> x...
4
#include <algorithm> #include <cstdio> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { int a, b; while (scanf("%d%d", &a, &b) == 2) { if (a < b) swap(a, b); printf("%d\n", gcd(a, b)); } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int N,K; cin >>N>>K; if((N+1)/2 >= K)cout<<"YES"; else cout <<"NO"; }
0
#include <bits/stdc++.h> using namespace std; const int MAX = 100; const int MM = 100 * 1000; const int INF = 1 << 29; const long long D = 1000 * 1000 * 1000 + 7; int p[MAX + 10]; bool adj[MAX + 10][MAX + 10]; int cnt = 0; int k; int main() { ios::sync_with_stdio(false); for (int i = 3; i < MAX; i++) p[i] = i * (i ...
3
#include <bits/stdc++.h> using namespace std; inline int nextint() { int temporary; scanf("%d", &temporary); return temporary; } inline long long nextll() { long long temporary; scanf("%lld", &temporary); return temporary; } inline double nextdouble() { double temporary; scanf("%lf", &temporary); retu...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 8, lim = 4 * maxn; int segtree[lim]; int len[maxn]; vector<int> tlist[maxn]; int ptr; map<int, int> m; int mapper(int num) { int val = m[num]; if (val != 0) return val; m[num] = ++ptr; return ptr; } int query(int cur, int l, int r, int ql, int...
5
#include <bits/stdc++.h> using namespace std; long long fpow(long long n, long long k, long long p = 1000000007) { long long r = 1; for (; k; k >>= 1) { if (k & 1) r = r * n % p; n = n * n % p; } return r; } long long inv(long long a, long long p = 1000000007) { return fpow(a, p - 2, p); } int main() ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n, i, f = 0, A, B, C; cin >> n; vector<long long> a(n); for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { A = a[i]; B = a[A - 1]; C = a[B - 1...
1
#include <bits/stdc++.h> using namespace std; long long a, b, l[3001][3001], dp[3001][3001], mod = 1000000007; char cc; long long find(long long aa, long long bb, long long qq, long long ww) { if (l[aa][bb] == 2) return 0; memset(dp, 0, sizeof(dp)); dp[aa][bb] = 1; for (int i = aa; i <= qq; i++) { for (int ...
4
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, n, m; int main() { cin >> n; long long arr[n]; map<long long, long long> mp, mp1; map<long long, long long>::iterator it, itr, ptr; for (int i = 1; i <= 2 * n; i++) { cin >> a; it = mp.find(a); if (it != mp.end()) { mp1[a] =...
2
#include <iostream> #include <algorithm> #include <vector> #include <cstring> #include <cstdio> using namespace std; int n,m; int bs[20]; int as[20]; int dp[1<<14]; int combSum[1<<14]; const int INF=1000000000; int main(){ int tmp[20]; while(scanf("%d %d",&n,&m)&&(n|m)){ memset(combSum,0,sizeof(combSum)); ...
0
#include <bits/stdc++.h> using namespace std; int n; int a[100]; bool check(int x, int r) { int st = 0; for (int i = 0; i < n; i++){ if (a[i] > x) return false; if (st + a[i] > x){ --r; st = 0; } st += a[i]; } return r > 0; } int main() { int m; while (scanf("%d %d", &m, &n), n){ for (int i =...
0
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1 >> s2; for (int i = 0; i < s1.length(); i++) { if (s1[i] == s2[i]) cout << "0"; else cout << "1"; } cout << "\n"; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(0); int t; cin >> t; while (t--) { string s; cin >> s; int x = 0, y = 0, m = 0; set<tuple<int, int, int> > e; for (char c : s) { int temp; int x2 = x, y2 = y; if (c == 'N') temp = ...
3
#include <iostream> using namespace std; long long n, k, j = 0, t = 0; long long a[200000], b[200000], c[200000]; int main() { cin >> n >> k; fill(c, c + n + 1, -1); for (long long i = 0; i < n; i++) cin >> a[i]; while (c[j] < 0) { c[j] = t; b[t] = j; t++; j = a[j] - 1; } if(k < t) cout << b[k]...
0
#include <bits/stdc++.h> using namespace std; inline int read() { int c = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { c = c * 10 + ch - '0'; ch = getchar(); } return c * f; } const int inf = 0x3f3f3...
3
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; typedef pair<int, int> P; int main() { int a, b; cin >> a >> b; cout << abs(a-b) << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int frinds[n]; for (int i = 0; i < n; i++) { cin >> frinds[i]; } int x[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i + 1 == frinds[j]) x[i] = j + 1; } } for (int i = 0; i < n; i++) cou...
1
#include<bits/stdc++.h> using namespace std; int d; bool isprime(int x){ for(int i=2;i<=sqrt(x);i++) if(x%i == 0) return false; return true; } int main(){ int T,ans1,ans2; cin>>T; while(T--){ cin>>d; for(int i=d+1;;i++){ if(isprime(i)){ ans1 = i; break; } } for(int i=ans1+d;;i++){ if(i...
2
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; const int maxn = 4000000; struct point { long long x, y; point() {} point(long long a, long long b) : x(a), y(b) {} long long len2() const { return x * x + y * y...
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; const int DIM = 110 * 1000; int n; vector<int> e[DIM]; int top; int mi[DIM], ma[DIM]; int key[DIM]; int q; pair<int, int> a[DIM]; int rs[DIM], ls[DIM]; vector<pair<pair<int, int>, int> > pp; long long aa[DIM], bb[DIM]; int ras[DIM]...
3
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZER...
0
#include <bits/stdc++.h> using namespace std; int a[110]; int b[2], cnt; int t; int main() { cin >> t; while (t--) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); int flag = 0; int idx; for (int i = 0; i < n; i++) { if (a[i] % 2 == 0) { idx = i; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n; cin >> n; if (n == 1) cout << "FastestFinger" << endl; else if (n == 2) cout << "Ashishgup" << endl; else if (n % 2) cout << "Ashishgup" << endl; else { set<int> s...
3
#include <iostream> #include <utility> #include <string> #include <vector> int main(int, char**) { int n, K; std::string s; std::cin >> n >> K >> s; std::vector<int> is; char pre{}; for(int i{}; i < n; ++i) { if(pre != s[i]) is.push_back(i); pre = s[i]; } int ans{-1}; size_t r{is.size()}; ...
0
#include <bits/stdc++.h> using namespace std; priority_queue<pair<int, int> > q; vector<vector<int> > v; int n, dp[200001]; int main() { scanf("%d", &n); v.resize(n + 1); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); if (i == 1) v[i].push_back(x), v[i].push_back(i + 1); else if (i =...
2
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template <class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vl...
2
#include <bits/stdc++.h> using namespace std; bool sort_pair(const pair<int, int> &a, const pair<int, int> &b) { return a.first < b.first; } int main() { int n; cin >> n; vector<pair<int, int>> shots(n); for (int i = 0; i < n; ++i) { int a; cin >> a; shots[i] = {a, i}; } sort(shots.rbegin(), s...
2
#include <bits/stdc++.h> using namespace std; char a[500005]; int sa[500005], height[500005], cnt[500005], x[500005], tmp1[500005], Rank[500005], st[500005][21], lg[500005], maxn[2000005], dp[500005], n, m; void MakeSuffixArray() { m = 127; for (int i = 1; i <= n; ++i) ++cnt[x[i] = a[i]]; for (int i = 2; i <=...
6
#include <bits/stdc++.h> using namespace std; using INT = long long; using pii = pair<int, int>; char s[500100]; vector<int> vec[500100], id[500100]; int mx[500100][2], mn[500100][2]; int MX[500100], MN[500100]; int main() { int n; cin >> n; int N = 0, nn = 0; for (int i = 1; i <= n; i++) { scanf("%s", s); ...
3
#include <bits/stdc++.h> const int INF = 2147483647; const int MOD = 1000000007; const long long INF64 = 9223372036854775807; using namespace std; int main() { cout << "2000\n"; for (int i = 1; i <= 1000; i++) cout << i << " 1 " << i << " 2\n"; for (int i = 1000; i >= 1; i--) cout << i << " 1 " << i << " 2\n"; ...
4
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e6 + 1; const int MOD = 1e9 + 7; const int INF = 1e9; const long long int LINF = 1e18; const long long int N = 100001; void snake_bite() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed; } bool containsDigit(long long int number, ...
2
#include <bits/stdc++.h> using namespace std; #define ll long long const int N=1005; const int M=20005; ll dp[2][M]; int c,p=1; int v[N],w[N],s[N],id[N]; bool comp(int i, int j){ return w[i]+s[i]<w[j]+s[j];} int main() { int n,i,j,k; scanf("%i",&n); for(i=1;i<=n;i++) scanf("%i %i %i",&w[i],&s[i],&v[i]),id[i]=i; sor...
0
#include <bits/stdc++.h> using namespace std; int main() { int N, M, ans = 0; cin >> N; for (int i = 0; i < N; i++) { int cnt = 0; for (int j = 0; j < 3; j++) { cin >> M; if (M == 1) cnt++; } if (cnt >= 2) ans++; } cout << ans; return 0; }
1
#include <bits/stdc++.h> using namespace std; int a[8][3]; void input() { for (int i = 0; i < 8; i++) for (int j = 0; j < 3; j++) cin >> a[i][j]; } long long d(int a1[], int a2[]) { long long n1 = 1; return n1 * (a1[0] - a2[0]) * (a1[0] - a2[0]) + n1 * (a1[1] - a2[1]) * (a1[1] - a2[1]) + n1 ...
2
#include <bits/stdc++.h> using namespace std; int main(){ int N, M; cin >> N >> M; vector<set<int>> E(N); for(int ii=0; ii<M; ii++){ int a, b; cin >> a >> b; a--; b--; E[a].insert(b); E[b].insert(a); } vector<int> ans(N, -1); queue<int> Q; Q.push(0); ans[0] = 0; while(Q.siz...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b; cin >> n; vector<pair<long long, long long> > v; for (int i = 0; i < n; i++) { cin >> a >> b; v.push_back(make_pair(b, a)); } sort(v.begin(), v.end()); vector<pair<long long, long long> >::iterator it; long long count ...
2
#include <bits/stdc++.h> using namespace std; int n; int tim[100010], ans[100010]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> tim[i]; for (int i = 1; i <= n; i++) { ans[i] = ans[i - 1] + 20; int pos = upper_bound(tim + 1, tim + 1 + i, tim[i] - 90) - tim - 1; ans[i] = min(ans[i], ans[po...
2
#include <bits/stdc++.h> using namespace std; const int nmax = 10001; const int mmax = 10001; const int kmax = 101; const long long oo = 1000000000000; struct kcanh { int u, v, l, r, vtu, vtv; }; ifstream fi("HACK.INP"); ofstream fo("HACK.OUT"); vector<pair<long long, int> > adj[nmax]; kcanh canh[kmax]; int s[2]; lon...
5
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; int inp; vector<vector<int>> gr(n + m - 1, {0, 0}); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> inp; if (inp) { gr[i + j][1]...
3
#include <bits/stdc++.h> using namespace std; const double pi = 3.1415926535; void FAST() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } long long int gas[300001]; long long int dp[300001][2]; long long int path[300001]; vector<pair<long long int, long long int>> adj[300001]; void Traveller(long long int i...
1
#include <stdio.h> const int INF=(1<<30); int main(){ int n,s,a[100010],back=0,ans=INF; long long int now=0; scanf("%d%d",&n,&s); for(int i=0;i<n;i++){ scanf("%d",&a[i]); now+=a[i]; while(now>=s){ if(i-back+1<ans)ans=i-back+1; now-=a[back]; bac...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, t, i, s, p; cin >> t; for (i = 0; i < t; i++) { cin >> a >> b; s = a - b; s = abs(s); if (s % 5 == 0) { cout << s / 5 << endl; } else if (s % 5 != 0) { p = s / 5; s = s % 5; if (s % 2 == 0) {...
1
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { long long n; cin >> n; if (n < 1 || n > 100000) { cout << 0; return 0; } vector<long long> piles(n); vector<long long> cost(n); for (long long i = 0; i < n; i++) { cin >> piles[i]; } sort(piles.begin(), piles.e...
2
#include<bits/stdc++.h> #define ll long long #define ull unsigned ll #define uint unsigned #define pii pair<int,int> #define pll pair<ll,ll> #define PB push_back #define fi first #define se second #define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++) #define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--) #define CLR...
0
#include <bits/stdc++.h> using namespace std; const int MN = 100 * 100 * 100; int n, k, nest[MN], ans, ff; int main() { cin >> n >> k; for (int i = 0; i < k; i++) { int mi; cin >> mi; int x = -1, f, flag = 0, t = 1; cin >> f; ans += mi - 1; if (f == 1) { flag = 1; } for (int j ...
1
/* please pass my code use a kruskal's idea every edge should be between adjacent connected components (no idea why this is the case, it just seems to work) */ #include <stdio.h> #include <set> #include <utility> long long minn(long long a,long long b){return a<=b?a:b;} int n; long long d; int a[200005]; // segm...
0
#include <bits/stdc++.h> using namespace std; struct sort_pred { bool operator()(const pair<int, int>& left, const pair<int, int>& right) { return left.second < right.second; } }; struct convert { void operator()(char& c) { c = toupper((unsigned char)c); } }; struct convertd { void operator()(char& c) { c =...
1
//11 #include<iostream> #include<algorithm> using namespace std; int main(){ for(int n,k;cin>>n>>k,n|k;){ int f[101][101]; fill_n(f[0],101*101,-1); while(k--){ int l; cin>>l; if(l){ int c,d,e; cin>>c>>d>>e; f[c][d]=f[d][c]=(f[d][c]==-1)?e:min(e,f[d][c]); }else{ int a,b; cin>...
0