solution
stringlengths
52
181k
difficulty
int64
0
6
#include <vector> #include <iostream> #include <algorithm> #include <functional> using namespace std; const int mod = 1000000009; int main() { int N, M; cin >> N >> M; int lim = max(N, 3); vector<int> fact(3 * lim + 1), inv(3 * lim + 1), factinv(3 * lim + 1), val(N + 1); fact[0] = 1; inv[1] = 1; factinv[0] = 1; f...
0
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e5 + 6; const int inf = (int)1e9 * 2; const int mod = (int)1e9 + 7; int n, m, t[maxn * 2]; int maxi = -inf, mini = inf, cnt, sum, qwe; int b, c; string s, str, save, prov, save2; int a[100]; char alf[10] = {'a', 'e', 'i', 'o', 'u', 'y'}; bool ok; int ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; const int MAXM = 3010; int n; int xL[MAXN], xR[MAXN], yL[MAXN], yR[MAXN]; int L[MAXM][MAXM], D[MAXM][MAXM], F[MAXM][MAXM]; int id[MAXN]; pair<int, pair<int, int> > s[MAXN * 2]; bool cmp(int a, int b) { return yR[a] < yR[b] || yR[a] == yR[b] && xR[...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { string a; cin >> a; reverse(a.begin(), a.end()); string d; for (int i = 0; i < a.size(); i++) { d += a[i]; if (d == "op") { ...
1
#include <bits/stdc++.h> struct SegmentTree { static const int mxn = 1 << 18; int tag[mxn << 1]; int mx[mxn << 1], mxu[mxn << 1]; inline void push(int x, int v) { tag[x] += v; mx[x] += v; } inline void pushdown(int x) { if (tag[x]) { push(x << 1, tag[x]); push(x << 1 | 1, tag[x]); ...
5
#include<bits/stdc++.h> using namespace std; #define ll long long int #define INF 1e18 ll MOD = 1e9+7; ll a[403]; ll n,K; ll dp[100000000]; //dp[i] - in which rows i have done and ways to make it happen int main(){ cin>>n; memset(dp,0,sizeof dp); ll a[n][n]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>a[i...
0
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> typedef long long ll ; #define rep(i, a, b) for (int i = a; i <= b; ++ i) const int N = 200005, M = N << 1, inf = 1e9 + 7 ; using namespace std ; int e, n, ter[M], nxt[M], lnk[N], v[N], f[N][3], g[N][3] ; char s[N] ; ll a...
0
#include <bits/stdc++.h> using namespace std; bool dv(int n, int r) { return n % r; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, s; cin >> n >> m >> s; long long ioi = 0; for (int x = 1; x <= n; x += 2) for (int y = 1; y <= m; y += 2) { int a = (x >> 1), b = (y >> 1); ...
3
#include <bits/stdc++.h> using namespace std; const int N = 101; int n, m, a, i, mx, cnt[N]; vector<int> vec; bool check(int days) { int rem = n; for (int i = 0; i < vec.size(); ++i) { rem -= (vec[i] / days); } return (rem <= 0); } int main() { cin >> n >> m; for (i = 0; i < m; ++i) { cin >> a; ...
2
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5+100; vector<int> g[N]; int d[N],mx[N],fa[N],n,a,t; void dfs1(int u,int f){ fa[u]=f; mx[u]=d[u]=d[f]+1; for(auto v:g[u]){ if(v==f) continue; dfs1(v,u); mx[u]=max(mx[u],mx[v]); } } int ans=0; int main(){ ...
0
#include <bits/stdc++.h> using namespace std; int main() { int x, r = 12; bool b; string s; cin >> x >> s >> s; b = s == "month"; if (b) { switch (x) { case 30: r = 11; break; case 31: r = 7; break; default: r = 12; } } else { if (x == ...
1
#include <bits/stdc++.h> using namespace std; template <typename T> T sqr(T x) { return x * x; } template <typename T> T abs(T x) { return x > 0 ? x : -x; } int gcd(int x, int y) { while (x != 0 && y != 0) { if (x > y) { x %= y; } else { y %= x; } } return x + y; } int main() { ios_b...
6
#include <bits/stdc++.h> using namespace std; using lint = long long int; template <class T = int> using V = vector<T>; template <class T = int> using VV = V<V<T> >; template <class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); } template <class T, class... Args> void assign(V<T>& v, int n, const...
1
#include<bits/stdc++.h> using namespace std; int g[101][101]; int main(void){ int n; cin>>n; for(int i=0;i<n;i++){ int u,k; cin>>u>>k; for(int j=0;j<k;j++){ int v; cin>>v; g[u][v]=1; } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cout<<g[i][j]<<" \n"[j==n]; }...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long int t; cin >> t; while (t--) { long long r, g, b, w; cin >> r >> g >> b >> w; if ((((r % 2) + (g % 2) + (b % 2) + (w % 2)) <= 1) || (r && g && b && ((r...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b, c, d, tms, ans = 1; cin >> n >> a >> b >> c >> d; tms = a + b + c + d; for (int i = 1; i < n; i++) { cin >> a >> b >> c >> d; if (tms < a + b + c + d) { ans++; } } cout << ans; }
1
#include <bits/stdc++.h> using namespace std; long long x[4]; void solve(int tc) { for (int i = 0; i < 4; i++) scanf("%lld", x + i); if (x[0] == 0 && x[1] == 0 && x[2] == 0 && x[3] == 0) { puts("0"); return; } if (x[0] == 1 && x[1] == 0 && x[2] == 0 && x[3] == 0) { puts("00"); return; } if (...
2
#include <bits/stdc++.h> using namespace std; const int N = 200000; int a[N + 5], p[N + 5], sp[10], cnt[10]; int main() { int n; scanf("%d", &n); scanf("%d %d %d", p + 1, p + 2, p + 3); for (int i = 1; i <= n; ++i) scanf("%d", a + i); sort(p + 1, p + 4); sp[1] = p[1]; sp[2] = p[2]; sp[3] = p[3]; sp[4]...
5
#include <iostream> #include <algorithm> using namespace std; const int Z = 1e9+7; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int c[n]; for (int i = 0; i < n; i++) { cin >> c[i]; } sort(c, c+n); int ans = 0; for (int i = 0; i < n; i++) ...
0
#include <bits/stdc++.h> using namespace std; bool poss(long long int x, long long int y, long long int x1, long long int y1, long long int t) { long long int d = (x - x1) * (x - x1) + (y - y1) * (y - y1); if (d <= t * t) return true; return false; } int main() { long long int n, x, y, t; double p; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int r; r = n / 2; int u; int counter = 0; for (int i = 1; i <= r; i++) { u = n - i; if (u % i == 0) { counter++; } } cout << counter; }
1
#include<cstdio> #include<iostream> using namespace std; int main() { int n,x,ans=0; cin>>n; while(n--){ cin>>x; ans+=x-1; } cout<<ans; }
0
#include <iostream> #include <fstream> #include <algorithm> using namespace std; ifstream fin("date.in"); ofstream fout("date.out"); long long v[200005], sum[200005], cnt[200005], w[200005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; for(int j=1; j<=t; j++) { int...
6
#include <bits/stdc++.h> using namespace std; int main() { string s; int i, a = 0, b = 0, c = 0; getline(cin, s); if (s.length() < 5) { cout << "Too weak"; return 0; } for (i = 0; i < s.length(); i++) { if (s[i] >= '0' && s[i] <= '9') a = 1; if (s[i] >= 'A' && s[i] <= 'Z') b = 1; if (s[i...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int a[N], b[N], s[N]; int st[N], tp; int xx; bool f; bool vis[N]; double ans[N]; struct edge { int v, w; edge(int x, int y) { v = x, w = y; } }; vector<edge> e[N]; void dfs(int u) { st[++tp] = u; vis[u] = 1; for (auto x : e[u]) { int v ...
1
#include <bits/stdc++.h> using namespace std; unordered_map<long long, long long> cor; long long n; long long x[1000005], y[1000005]; long long perechi[1000005], unu[1000005]; void reeducare() { for (long long i = 1; i <= n; i++) y[i] = x[i]; sort(y + 1, y + n + 1); for (long long i = 1; i <= n; i++) { if (y[...
5
#include <bits/stdc++.h> using namespace std; struct Point { long long x, y; }; bool operator<(Point A, Point B) { return make_pair(A.x, A.y) < make_pair(B.x, B.y); } bool operator==(Point A, Point B) { return make_pair(A.x, A.y) == make_pair(B.x, B.y); } struct Vector { long long x, y; Vector(Point A, Point ...
5
#include <bits/stdc++.h> using namespace std; int n, m, b, mod; long long dp[550][550]; int a[550]; int main() { scanf("%d%d%d%d", &n, &m, &b, &mod); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { for (int k = a[i]; k <= b; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n >> s; int a[n], b[n]; bool c1, c2, c3; c1 = c3 = c2 = false; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } if (a[0] == 1) c1 = true; for (int j = (s - 1); j < n; j++) {...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int n, mx = 100000000000, a, b, i, p, q, x, y, flag = 0; cin >> n; a = 4; b = 7; for (i = 0; i * a <= n; i++) { if ((n - (i * a)) % b == 0) { p = i; q = (n - (i * a)) / b; if (p + q < mx) { mx = p + q; x...
3
#include <bits/stdc++.h> int main() { int sum = 0, count = 0, n, m; scanf("%d%d", &n, &m); int arr[n], i; for (i = 0; i < n; i++) scanf("%d", &arr[i]); std::sort(arr, arr + n); for (i = 0; i < n; i++) { if (arr[i] < 0 && count < m) { sum += arr[i]; count++; } else break; } prin...
2
#include <bits/stdc++.h> using namespace std; static const long long COUNTER_CLOCKWISE = 1; static const long long CLOCKWISE = -1; static const long long ONLINE_BACK = 2; static const long long ONLINE_FRONT = -2; static const long long ON_SEGMENT = 0; struct Point { double x, y; Point() {} Point(double x, double ...
3
#include<iostream> using namespace std; int main(){ int a, b; char op; for(;;){ cin >> a >> op >> b; if(op == '+'){cout << a + b << endl;} else if(op == '-') {cout << a - b << endl;} else if(op == '*') {cout << a * b << endl;} else if(op == '/') {cout << a / b << endl;} else break; } }
0
#include <iostream> using int64 = long long; int main() { int64 n, d; std::cin >> n >> d; n--; int64 N = n - d + 1; std::cout << (d == 1 ? n * (n + 1) / 2 : d + (N + 3) * N / 2 - 2) << std::endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { long long n; int m; scanf("%lld %d", &n, &m); long long sum = 0; vector<int> vec; priority_queue<int> pq, pq2; for (int i = 0; i < m; i++) { int x; scanf("%d", &x); pq.pus...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, c; long long int s, a, d, b; cin >> n >> d; long long int ara[n]; for (i = 0; i < n; i++) { cin >> ara[i]; } c = 2; for (i = 0; i < n - 1; i++) { a = ara[i + 1] - ara[i]; if (a > 2 * d) c += 2; else if (a == 2 ...
1
#include <bits/stdc++.h> int main() { int n, m, k, p = 1; scanf("%d", &n); m = n; while (m != 0) { if (m % 10 == 1) { m = m / 10; continue; } if (m % 100 == 14) { m = m / 100; continue; } if (m % 1000 == 144) { m = m / 1000; continue; } p = 0; ...
1
#include<iostream> int main(){ int arr[1000001] = {0, 1, 1, 1, 1, 1}; for(int i=6;i<=1000000;i++){ if((i%2 == 0 && arr[i/2]) || (i%3 == 0 && arr[i/3]) || (i%5 == 0 && arr[i/5])){ arr[i] = 1; }else{ arr[i] = 0; } } int m, n; while(std::cin >> m >> n, m){ int res = 0; while(m <= n){ if(a...
0
#include <bits/stdc++.h> using namespace std; long long kq = 0; long long a, b; int main() { cin >> a >> b; for (int k = 1; k <= a; k++) { long long x = (1ll * k * b + 1) % 1000000007; long long y = (1ll * (b - 1) * b / 2) % 1000000007; kq = (kq + (x * y) % 1000000007) % 1000000007; } cout << kq % 1...
1
#include <bits/stdc++.h> using namespace std; int n; int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 72, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int feet = n / 36, inch; n = n % 36; inch = n / 3; n = n % 3; if (n == 2) inch++; if (inch >= 12) { feet = feet + inch / 12; inch = inch % 12; } printf("%d %d", feet, inch); return 0; }
1
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int arr[n], i, sum = 0, j, k, flag = 0; for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } for (i = 0; i < n; i++) { sum = arr[i]; for (j = 0; j < n; j++) { for (k = j + 1; k < n; k++) { if (sum == arr[j] + arr[k] && i !=...
1
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline T1 max(T1 a, T2 b) { return a < b ? b : a; } template <typename T1, typename T2> inline T1 min(T1 a, T2 b) { return a < b ? a : b; } const char lf = '\n'; namespace ae86 { const int bufl = 1 << 15; char buf[bufl], *s = buf, *t ...
6
#include <bits/stdc++.h> using namespace std; long long stoll(string target) { stringstream s; s << target; long long w; s >> w; return w; } int stoi(string target) { stringstream s; s << target; int w; s >> w; return w; } string itos(int i) { stringstream s; s << i; return s.str(); } string l...
2
#include <bits/stdc++.h> using namespace std; mt19937 mt_rand( chrono::high_resolution_clock::now().time_since_epoch().count()); const int N = 2e5 + 5, HS = 3, K = 10; int n, m, k; vector<pair<int, int> > g[N]; int mod[HS]; struct hash_number { int a[HS]; hash_number() { fill(a, a + HS, 0); } hash_number(long...
2
#include <bits/stdc++.h> using namespace std; const int maxN = 2e3; int n, arr[maxN]; map<int, vector<pair<int, int> > > seg; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0), cout.precision(15); cin >> n; for (int i = int(0); i < int(n); i++) cin >> arr[i]; for (int i = int(...
6
#include <iostream> #define MAX(a,b) ((a>b)?(a):(b)) using namespace std; int main(void){ int a,b; int n; int k[10]; int i; cin>>n; while(n--){ a=b=-1; for(i=0;i<10;i++) cin>>k[i]; for(i=0;i<10;i++){ if(a>k[i]&&b>k[i])break; if(k[i]>a&&k[i]>b){ if(a>b)a=k[i]; else b=k[i]; }else if(k[i]>a)a...
0
#include <bits/stdc++.h> using namespace std; int arr[256]; int main() { string s1, s2; getline(cin, s1); getline(cin, s2); bool bol = true; for (int i = 0; i < s1.size(); i++) arr[s1[i]]++; for (int i = 0; i < s2.size() && bol; i++) if (s2[i] != ' ') { if (!arr[s2[i]]--) bol = false; } if (...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0, curr_ans = 0, c = 0; cin >> n; int arr[n], i; for (i = 0; i < n; i++) cin >> arr[i]; int m, j; cin >> m; int arr2[m]; for (i = 0; i < m; i++) cin >> arr2[i]; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { if (arr...
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout << "square1001" << endl; }
0
#include "bits/stdc++.h" using namespace std; int main(){ int K; cin>>K; cout<<((K+1)/2)*(K/2)<<endl; }
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; typedef pair<ll,pll> plp; int main(){ ll inf=1000000000000000000; ll n,m,s,t;cin>>n>>m>>s>>t; ll u[m],v[m],a[m],b[m]; vector<plp> h[n+1]; for(ll i=0;i<m;i++){ cin>>u[i]>>v[i]>>a[i]>>b[i]; h[u[i]].push_back(make...
0
#include<bits/stdc++.h> using namespace std; char s[200000+7]; long long mp[200000+7]; int main(){ long long n,p; cin>>n>>p; cin>>s+1; if(p==2||p==5){ long long ans=0; for(long long i=n;i>=1;i--){ if((s[i]-'0')%p==0){ ans+=i; } } cout<<ans<<endl; return 0; } long long ans=0; long long t=...
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define DUMP(x) cout << #x << " = " << (x) << endl; #define FOR(i, m, n) for (ll i = m; i < n; i++) #define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define FO...
0
#include <bits/stdc++.h> using namespace std; int main() { int t, n, l, r; scanf("%d", &t); while (t--) { scanf("%d%d%d", &n, &l, &r); int k = n / l; if (1LL * r * k >= n) puts("Yes"); else puts("No"); } return 0; }
2
#include<iostream> #include<cstdio> #include<queue> #include<cstring> #include<cmath> #include<stack> #include<algorithm> #define rg register #define ll long long #define LDB long double #define ull unsigned long long #define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt) #define go(i,x,a) for(rg int i=a;i<x;i++) #defin...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int N = 1000005; const double PI = 4 * atan(1); const double eps = 1e-7; const long long oo = 1e18; long double a, b, x; int main() { cin >> a >> b; long double ans = 1e18; long long k = (long long)((a - b) / (2 * b)); if (k != 0) an...
1
#include <bits/stdc++.h> using namespace std; int main(void) { string a, b; while (cin >> a >> b) { if (a == b) { cout << a << endl; } else { cout << 1 << endl; } } return 0; }
1
#include <bits/stdc++.h> using namespace std; int a[100 + 10], b[100 + 10]; int main() { long long n, m, f; cin >> n; m = n; f = m; for (int i = 0; i <= 10; i++) { if (m % 10 == 0) break; m++; } f /= 10; f *= 10; if (n - f > m - n) cout << m; else cout << f; return 0; }
1
#include <bits/stdc++.h> using namespace std; void base() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void solve() { int n, n1, n2; cin >> n >> n1 >> n2; priority_queue<double> pq; for (int i = 0; i < n; ++i) { int x; cin >> x; pq.push(x); } if (n1 > n2) swap(n1, n2); doub...
2
#include <bits/stdc++.h> using namespace std; inline int max(const int &a, const int &b) { return a > b ? a : b; } const int N = 2e5 + 13; int n, q; char s[N]; struct SegTree { int l, r, apb, amb, dpc, dmc, lbc, rbc, res; } t[N << 2]; inline void refresh(int p) { if (t[p << 1].lbc < t[p << 1 | 1].rbc) t[p].lbc ...
3
#include <bits/stdc++.h> using namespace std; unordered_map<long long, long long> mp; int main() { long long n, p, k; cin >> n >> p >> k; for (int i = 1; i <= n; i++) { long long x; cin >> x; mp[(((x * x % p) * (x * x % p) - k * x % p) % p + p) % p]++; } long long ans = 0; for (auto it = mp.begi...
5
#include <bits/stdc++.h> int main() { long long A, B; scanf("%lld %lld", &A, &B); long long X = (A - B) / 2; long long Y = X + B; if (2 * X + B != A) printf("-1"); else printf("%lld %lld", X, Y); return 0; }
4
#include <bits/stdc++.h> using namespace std; template <class T> int size(const T &x) { return x.size(); } const int INF = ~(1 << 31); const double EPS = 1e-9; const double pi = acos(-1); template <class T> T smod(T a, T b) { return (a % b + b) % b; } int brute(vector<int> &perm) { int best = -1, bestval = -1; ...
3
#include <bits/stdc++.h> using namespace std; const int Maxn = 1005; const int Maxm = 200005; int n, m, q; int dist[Maxn][Maxn]; int a[Maxm], b[Maxm]; int l[Maxm], r[Maxm], s[Maxm], t[Maxm]; vector<int> has[Maxm]; bool res[Maxm]; int main() { scanf("%d %d %d", &n, &m, &q); for (int i = 1; i <= n; i++) for (int ...
5
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c; cin >> a >> b >> c; int ans = -1; int d = abs(a - b); int len = 2 * d; if (a == b or b == c or c == a) ans = -1; else if (a == b + 1 || b == a + 1) ans = -1; else { ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, q; int i, temp; cin >> n >> q; int a[n + 1]; int b[40] = {0}; int count; for (i = 0; i < n; i++) { cin >> a[i]; temp = a[i]; count = 0; while (temp != 0) { ...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; template <typename T> inline T SQR(T a) { return a * a; } template <typename T> struct InfP { operator T() const { return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() ...
5
#include <bits/stdc++.h> using namespace std; int main() { long long n, diff, taken, money, energy; cin >> n; int blocks[100020]; blocks[0] = 0; for (int i = 1; i <= n; i++) { cin >> blocks[i]; } money = energy = 0; for (int i = 0; i < n; i++) { if (blocks[i] >= blocks[i + 1]) energy += bl...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s = ""; for (int i = 1; i <= n; i++) { stringstream ss; ss << i; string s1 = ss.str(); s += s1; } cout << s[n - 1]; }
1
#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; long long l, r; long long lky[2048]; int ct; void rec(long long pv, long long tt) { if (pv > 1e9) return; lky[ct++] = tt + pv * 4; rec(pv * 10, lky[ct - 1]); lky[ct++] = tt + pv * 7; rec(pv * 10, lky[ct - 1]); } int main(int argc, char **argv) { cin.tie(NULL); ...
3
#include<cstdio> using namespace std; int N,A[200005],a[200005],l=1,r=200000,mid; bool check(int n) { int re=-1; for(int i=1;i<=N*2-1;i++) if(A[i]>=n) a[i]=1; else a[i]=0; for(int i=1;i<=N-1;i++) { if(a[N+i]==a[N+i-1]) { re=a[N+i]; break; } if(a[N-i]==a[N-i+1]) { re=a[N-i]; break; } } ...
0
#include <iostream> using namespace std; int main() { int N, X; cin >> N >> X; int n = 0, cnt = 1; for(int i = 0; i < N; i++) { int L; cin >> L; n += L; if(n <= X) cnt++; } cout << cnt << endl; }
0
#include <bits/stdc++.h> using namespace std; const int maxp = 1000100; const int mod = 1000000007; int v[maxp]; int main() { int p, k, res = 1; scanf("%d%d", &p, &k); if (k == 1) { for (int i = (0); i <= (int(p) - 1); ++i) res = 1LL * res * p % mod; printf("%d\n", res); return 0; } for (int i = (...
2
#include <bits/stdc++.h> using namespace std; int main(void) { int n; scanf("%d", &n); long a[n]; long long s = 0, ss = 0; for (int i = 0; i < n; i++) { scanf("%ld", &a[i]); s += a[i]; } if (s % 3 != 0) { printf("0\n"); return 0; } s = s / 3; vector<int> sum1; vector<int> sum2; f...
3
#include <bits/stdc++.h> const long long N = 20005; const long long NN = 105; const long long INF = 1000000000000000000; const long long MOD = 1000000007; const long long M0D = 998244353; const long double PI = acos((long double)-1); const long long P = 53; using namespace std; void ma1n() { string s; cin >> s; i...
2
#include <cstdio> using namespace std; const int N=2010; const int INF=1e9; int n; int p[2][N]; int preSum[2][N][N*2]; inline void updateMin(int &x,int y){ x=(y<x)?y:x; } void readData(){ scanf("%d",&n); static char str[5]; int x; for(int i=1;i<=n*2;i++){ scanf("%s%d",str,&x); p[str[0]=='W'][x]=i; } } void in...
0
// warm heart, wagging tail,and a smile just for you! // β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ // β–ˆβ–ˆβ–ˆβ•¬β•¬β•¬β•¬β•¬β•¬β•¬β•¬β•¬β•¬β–ˆβ–ˆβ–ˆ // β–ˆβ–ˆβ–ˆβ•¬β•¬β•¬β•¬β•¬β–ˆβ–ˆβ–ˆβ–ˆβ•¬β•¬β•¬β•¬β•¬β•¬β–ˆβ–ˆβ–ˆ // ...
0
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool checkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool checkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int MAXN = 100000 + 10; struct Node { int id; long long val; bool oper...
2
#include<bits/stdc++.h> using namespace std; bool isprime(long long int val) { if (val <= 1)return false; for (long long int i = 2; i*i <= val; i++) { if (val%i == 0LL)return false; } return true; } int main(){ ios::sync_with_stdio(false); cin.tie(0); vector<int> db; int n,p; ...
0
#include <bits/stdc++.h> using namespace std; int a[2]; int val[1000]; int main() { val['Q'] = 9; val['R'] = 5; val['B'] = 3; val['N'] = 3; val['P'] = 1; val['K'] = 0; for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) { char c; cin >> c; int k; if (c >= 'a') { k =...
1
#include <bits/stdc++.h> using namespace std; long long m, b; long long no_of_bananas_in_rectangle(long long x, long long y) { long long ans = (x * (x + 1) / 2) * (y + 1) + (y * (y + 1) / 2) * (x + 1); return ans; } int main() { long long max = 0; cin >> m >> b; for (long long i = 0; i <= b; i++) if (no_o...
2
#include <bits/stdc++.h> using namespace std; typedef long long arrv[600000 + 10]; typedef long long arre[800000 + 10]; long long i, j, k, p, n, m, tot, ans; arrv g, f, a; arre pt, nt, w; struct node { long long x, y; } q[600000 + 10]; void Link(long long x, long long y) { pt[++tot] = y, nt[tot] = g[x], g[x] = tot,...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int v[7]; string s1, s2, s3; long long int a1 = 0, a2 = 0, a3 = 0; s1 = "1 2 4\n"; s2 = "1 2 6\n"; s3 = "1 3 6\n"; for (int i = 0; i < 7; i++) v[i] = 0; long long int a; cin >> a; for (int i = 0; i < a; i++) { int x; cin >>...
1
#include<bits/stdc++.h> using namespace std; using ll=long long; int n; vector<ll> ans; int SIZE; ll calc(ll x,ll y,ll z,ll k){ ll res=0; auto sum=[&](ll a,ll b,ll l,ll r){ l=max(l,0LL); r=min(r,x+1); if(a==1) l=max(l,-b); if(a==-1) r=min(r,b+1); if(l>=r) return 0LL; ...
0
#include <bits/stdc++.h> using namespace std; const int Maxn = 600; int n, m, b, mod, a[Maxn]; long long d[3][Maxn][Maxn]; void input() { cin >> n >> m >> b >> mod; for (int i = 0; i < n; i++) cin >> a[i]; } void solve() { for (int k = 1; k < n + 1; k++) for (int g = 0; g < b + 1; g++) d[0][k][g] = 1 % mod; ...
3
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef complex<double> P; typedef pair<int,int> pii; #define REP(i,n) for(ll i=0;i<n;++i) #define REPR(i,n) for(ll i=1;i<n;++i) #define FOR(i,a,b) for(ll i=a;i<b;++i) #define DEBUG(x) cout<<#x<<": "<<x...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; long long ll[maxn], rr[maxn]; long long a[maxn << 2]; int w[maxn]; struct Seg { int sum[maxn << 4]; int lazy[maxn << 4]; int lazy_r[maxn << 4]; inline void pushup(int rt) { sum[rt] = sum[rt << 1 | 1] + sum[rt << 1]; } inline void pushdown...
6
#include<cstdio> #include<algorithm> using namespace std; const int MOD=1e9+7; int n,a=0,d=0,mmh=1; int main(){ register int i; scanf("%d",&n); for (i=1;i<=n;i++){ d=max(d,i-1-(a+1)/2); mmh=1LL*mmh*(i-d)%MOD; scanf("%d",&a); } printf("%d\n",mmh); }
0
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i) int main() { string s; cin >> s; int n = s.size(), u = 1, v = 1; bool b = false; rep(i, n / 2) if(s[i] != s[n - 2 - i]) b = true; if(b || s[0] != '1' || s[n - 1] != '0') { cout << -1 << endl;...
0
#include <cstdio> #define rep(i,n) for(int i=0; i<n; ++i) int n,m,l; int main(){ scanf("%d %d %d", &n,&m,&l); int a[n][m]; rep(i,n){ rep(j,m){ scanf("%d", &a[i][j]); } } int b[m][l]; rep(i,m){ rep(j,l){ scanf("%d", &b[i][j]); } } int long long c[n][l]; rep(i,n){ rep(j,l){ int long l...
0
#include<bits/stdc++.h> using namespace std; #define LL long long #define N 3000 #define INF 0x3f3f3f3f3f3f3f3fLL LL n,tot,ans,head[N],iter[N],level[N],q[N],a[N]; struct edge{LL v,cap,nxt;}e[N]; void add(LL x,LL y,LL z){ e[++tot].v=y; e[tot].cap=z; e[tot].nxt=head[x]; head[x]=tot; e[++tot].v=x; e[tot].cap=0; e[to...
0
#include <bits/stdc++.h> using namespace std; bool isprime(int k){ for(int i=2;i*i<=k;i++){ if(k%i==0)return false; } return true; } int main() { long long x; cin >> x; for(int j=x;j<10000000;j++){ if(isprime(j)){cout <<j; break;} } }
0
#include <bits/stdc++.h> using namespace std; template <class X, class Y> void amax(X& x, const Y& y) { if (x < y) x = y; } template <class X, class Y> void amin(X& x, const Y& y) { if (x > y) x = y; } const int INF = 1e9 + 10; const long long INFL = 1e18 + 10; const int MAX = 110; const int BASE = 1e9 + 7; int n, ...
3
#include "bits/stdc++.h" using namespace std; int main() { long long A, B; cin >> A >> B; cout << (A ^ B) << endl; }
0
#include <bits/stdc++.h> using namespace std; char s[1000002]; char actual[1000002]; struct node { int mini, maxi, lazy; node() : mini(0), maxi(0), lazy(0) {} node operator+(const node &p) const { node ret; ret.mini = min(mini, p.mini); ret.maxi = max(maxi, p.maxi); ret.lazy = 0; return ret; ...
5
#include <bits/stdc++.h> using namespace std; int n; int arr[100000]; void solve() { cin >> n; int total = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; total += arr[i]; } int cur = 0, res = 0; for (int i = 0; i < n - 1; i++) { cur += arr[i]; if (2 * cur == total) res++; } cout << res ...
3
#include <bits/stdc++.h> using namespace std; stack<time_t> time_stack; void startTimer() { time_stack.push(clock()); } double stopTimer() { double time = clock() - time_stack.top(); time_stack.pop(); return time / double(CLOCKS_PER_SEC); } int main() { startTimer(); ios::sync_with_stdio(false); int n; ci...
1
#include <bits/stdc++.h> using namespace std; long long n, k; int a[124], ans; int dp[124][100024], maxN = 100024; long long get(long long nn, int ind) { if (!nn) { return 0; } if (ind == k) { return nn; } if (nn < maxN && dp[ind][nn] >= 0) { return dp[ind][nn]; } long long crr = get(nn, ind +...
5