solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long n, ctr = 0; long long r[N], h[N], a[N], bit[N]; map<long long, long long> m, rm; void update(long long idx, long long k) { while (idx <= n) { bit[idx] = max(bit[idx], k); idx += idx & -idx; } } long long pref(long long idx)...
4
#include <bits/stdc++.h> using namespace std; struct edge { int to, nxt; }; int head[100010], cnt; int ans; edge e[200010]; int dfn[100010], low[100010], ind; int stk[200010], top; int col[100010], num; int deg[100010]; bool ok[100010]; int n, m; void addedge(int a, int b) { e[cnt].to = b; e[cnt].nxt = head[a]; ...
6
#include <bits/stdc++.h> using namespace std; const int NMAX = 50007; int n, a[NMAX], _id[NMAX], ans[NMAX]; int id(int i) { return i % n; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) _id[i] = i; sort(_id, _id + n, [](int i, int j) { return a[i] + a[id(i + ...
3
#include <bits/stdc++.h> #define ALL(a) (a).begin(), (a).end() #define ll long long using namespace std; vector<string> split(string s){ vector<string> ret; int idx = 0; for(int i = 0; i < s.size(); i++){ if(s[i] == ':' || s[i] == ',' || s[i] == '.'){ ret.push_back(s.substr(idx, i-idx)); idx = i+1; } }...
0
#include <bits/stdc++.h> #pragma GCC optimize("O3,inline,unroll-loops") using namespace std; class Point { public: double x; double y; Point(double _x = 0, double _y = 0) : x(_x), y(_y) { return; } Point operator+(Point that) { return Point(this->x + that.x, this->y + that.y); } Point operator-(Point t...
5
#include <bits/stdc++.h> using namespace std; int main() { long long int cases = 1; while (cases--) { long long int n; cin >> n; string s; cin >> s; long long int l = 0; for (long long int i = 1; i <= n / 2; i++) { string t1 = s.substr(0, i); string t2 = s.substr(i, i); if ...
2
#include <bits/stdc++.h> const double pi = acos(-1.0); double GetDis(double x1, double y1, double x2, double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } int main() { double xx, yy, dis, EPS; double x[2], y[2], r[2], R[2]; scanf("%lf%lf%lf%lf", &x[0], &y[0], &r[0], &R[0]); scanf("%lf%lf...
2
#include <bits/stdc++.h> using namespace std; struct g { int f, b; } a[110000]; int q[110000], b[110000], cp[110000], cb[110000]; bool cmp(g &x, g &y) { return x.f < y.f; } bool cmp2(g &x, g &y) { return x.b < y.b || x.b == y.b && x.f < y.f; } int main() { int h, l, r, i, flag = 0, j, h1, n, ans = 10000000; scanf...
4
#include <bits/stdc++.h> using namespace std; namespace IO { void setIn(string s) { freopen(s.c_str(), "r", stdin); } void setOut(string s) { freopen(s.c_str(), "w", stdout); } void setIO(string s = "") { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (s.size()) { setIn(s + ".inp"); setOu...
3
#include<bits/stdc++.h> using namespace std; #define M 100005 char s[M],t[M]; int sk[26][M],r[26]; int main(){ scanf("%s%s",s+1,t+1); int n=strlen(s+1),m=strlen(t+1); for(int i=1;i<=n;++i)sk[s[i]-'a'][++r[s[i]-'a']]=i; long long ans=0; for(int i=1,st=0;i<=m;++i){ int p=t[i]-'a'; if(!r[p]){ puts("-1"); re...
0
#include <bits/stdc++.h> using namespace std; long long arr[100005]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> arr[i]; } int t; long long val = 0; for (int i = 0; i < m; ++i) { cin >> t; if (t == 3) { int q; cin >> q; cout << arr[q - 1] + val ...
2
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { int c; while (a != 0) { c = a; a = b % a; b = c; } return b; } int main() { ios_base::sync_with_stdio(0); int n, m, b = 0; cin >> n >> m; vector<vector<int> > arr(n, vector<int>(4, 0)); for (int i = 0; i < n; i++) { ...
2
#include <bits/stdc++.h> using namespace std; int p[500000]; int otv[500000]; bool mb = true; void f(int a, int b, int x, int y) { int r; vector<int> posl; if (a <= b && mb) { int t = a, index = 0; while (t <= b) { if (p[t] == -2) p[t] = b + 1; posl.push_back(t); t = p[t]; index++;...
3
#include <bits/stdc++.h> using namespace std; int sa, sg; char arr[1000100]; int narr; int n; int main() { scanf("%d", &n); scanf("%s", arr); narr = strlen(arr); int rs = 0; for (int i = 0; i < narr; i += n) { if (i >= 4 && arr[i - 1] == arr[i - 2] && arr[i - 2] == arr[i - 3]) rs++; } printf("%d\n", r...
1
#include<bits/stdc++.h> using namespace std; int main() { int n; string s; cin>>n>>s; cout<<(n<3200?"red":s); }
0
#include <bits/stdc++.h> using namespace std; long long z, o, i, j, n, m, p = 20000001, e; vector<long long> v[200005]; map<char, char> mp, mp1; string s; char c, d; int main() { cin >> n >> m; cin >> s; for (i = 'a'; i <= 'z'; i++) { c = i; mp[c] = c; } for (i = 1; i <= m; i++) { cin >> c >> d; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 200100; int n, m, k, sa, sb, ans = 2e9 + 10000, calc, x, ty, sz1, res[N], tim; struct item { int t, a, b; } a[N]; vector<pair<int, int> > b[4]; priority_queue<pair<int, int> > s, t; bool cmp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; } i...
5
#include <bits/stdc++.h> #define N 400500 #define int long long using namespace std; int Ans, mx[3][3][N << 2], X, Y, m, n, num[N], cnt; struct Data{int c, l, r;}d[N]; bool cmpl(Data a, Data b){return a.l < b.l;} void pushup(int rt, int c){ for(int i = 0; i < 3; i++) mx[c][i][rt] = max(mx[c][i][rt << 1], mx[c][i][rt...
0
#include <bits/stdc++.h> using namespace std; void solve(); mt19937 rnd(2007); signed main() { mt19937 rrnd( std::chrono::high_resolution_clock::now().time_since_epoch().count()); swap(rrnd, rnd); ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); solve(); } void solve() { string...
1
#include <bits/stdc++.h> using namespace std; const long long MXN = 2e5 + 10; long long q, n, a, b; long long Val[MXN], C[MXN], dp[MXN]; bool vis[MXN]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q; for (int i = 1; i <= n; i++) cin >> Val[i]; for (int i = 1; i <= n; i++) cin >...
3
#include <bits/stdc++.h> using namespace std; string s, t; map<char, bool> good; int main() { cin >> s; for (char x : s) good[x] = true; cin >> s; int n, m = s.length(), pos = -29102001; for (int i = 0; i < m; ++i) if (s[i] == '*') { pos = i; break; } cin >> n; while (n--) { bool o...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int a[MAXN]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) scanf("%d", a + i); if (a[n - 1] == 1) { puts("NO"); } else if ((n >= 2 && a[n - 2] == 1) || (n == 1 && a[n - 1] == 0)) { puts("YES"); for (int i = 0; i <...
5
#include <bits/stdc++.h> using namespace std; struct Struct { long long X; long long Y; long long Z; }; Struct Data[501]; long long Dp[501]; int main(void) { register int i, j; register long long Total; cin >> Total; for (i = 1; i <= Total; i++) { cin >> Data[i].X >> Data[i].Y >> Data[i].Z; } sort...
6
#include <bits/stdc++.h> using namespace std; const int ooU = 2147483647; const long long ooT = 9223372036854775807; template <class _TYPE_> _TYPE_ smin(_TYPE_ &a, _TYPE_ b) { return a = min(a, b); } template <class _TYPE_> _TYPE_ smax(_TYPE_ &a, _TYPE_ b) { return a = max(a, b); } long long gcd(long long a, long l...
5
#include <bits/stdc++.h> using namespace std; int ans[50][50]; int main() { int n; scanf("%d", &n); for (int i = 1, cur = 1; i <= n; i++) for (int j = n / 2 + 1 - min(i, n - i + 1) + 1; j <= n / 2 + 1 + min(i, n - i + 1) - 1; j++) { ans[i][j] = cur; cur += 2; } for (int i = 1, cur =...
3
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { if (a < 0) return gcd(-a, b); if (b < 0) return gcd(a, -b); return (b == 0) ? a : gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { if (a < 0) return lcm(-a, b); if (b < 0) return lcm(a, -b); return a * (b /...
2
#include <bits/stdc++.h> using namespace std; int main() { vector<long long> v(2 * 1e5 + 5, 0); vector<bool> check(2 * 1e5 + 5, 0); long long q; cin >> q; char c; long long l = 0, r = 0, n; while (q--) { cin >> c >> n; if (c == 'L') { l++; v[n] = l; } else if (c == 'R') { r++...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int l[n], r[n]; for (int i = 0; i < n; i++) cin >> l[i] >> r[i]; int lsum = 0, rsum = 0; for (int i = 0; i < n; i++) { lsum += l[i]; rsum += r[i]; } int maxdiff = abs(lsum - rsum), maxdiffindex = 0; bool ispossible = f...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int MOD = 1000000007; const int INF = 10000000; const int MAX = 100000; const ld PI = (acos(-1)); template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template ...
3
#include<bits/stdc++.h> #define lb long double #define N 110 #define eps 1e-10 using namespace std; struct Po{lb x,y;}a[N],p1,p2; vector<Po> no; int n,q; void get(Po &x){scanf("%Lf %Lf",&x.x,&x.y);} Po operator -(Po x,Po y){return (Po){x.x-y.x,x.y-y.y};} lb operator *(Po x,Po y){return x.x*y.y-x.y*y.x;} Po operator *(...
0
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 10; struct ope { int x, y, z; ope() {} ope(int a, int b, int c) : x(a), y(b), z(c) {} void out() { printf("%d %d %d\n", x, y, z); } } ans[M], op[101]; int top, bit[M]; int n, A[M], ls[M]; void add(int a, int b, int c) { ans[++top] = ope(a, b, c);...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int ar[5]; int sum = 0; for (char i = 1; i < 5; i++) { cin >> ar[i]; } string s; cin >> s; for (int i = 0; i < s.length(); i++) { sum = sum + ar[s[i] - '0']; } cout << su...
1
#include <bits/stdc++.h> using namespace std; int main() { long long time; cin >> time; while (time--) { long long n, m, i, j, k; cin >> n >> m; vector<vector<long long>> a(n, vector<long long>(m)); for (i = 0; i < n; i++) for (j = 0; j < m; j++) cin >> a[i][j]; vector<long long> v(n); ...
2
#include <iostream> #include <algorithm> using namespace std; const int N = 100005; int a[N], cnt[N * 2]; long long id[N * 2]; int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; long long init = 0; for (int i = 1; i < n; i++) { int l = a[i], r = a[i +...
0
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") template <typename T> bool mmax(T &m, const T q) { if (m < q) { m = q; retu...
5
#include <bits/stdc++.h> using namespace std; const long long N = (long long)1e5; long long n, sp, s[N + 1], a[N + 1], b[N + 1]; long long a_total = 0, b_total = 0, total = 0, ans = 0; vector<pair<long long, long long> > h1, h2; int main() { ios::sync_with_stdio(false); cin >> n >> sp; for (long long i = 0; i < n...
2
#include<cstdio> #include<queue> using namespace std; typedef pair<int, int> PII; int x, N; int d[15], c[15]; int INF = 1001001001; int ans[200001]; int main() { for(int i = 0; i <= 200000; i++) { ans[i] = INF; } scanf("%d%d", &N, &x); for(int i = 0; i < N; i++) { scanf("%d%d", &d[i], &c[i]); } prior...
0
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : (-x); } template <class T> T sqr(T x) { return x * x; } long long get(long long l, long long r) { return max(0LL, r - l + 1); } long long cross(long long x1, long long y1, long long x2, long long y2) { return max(0LL,...
2
#include <bits/stdc++.h> using namespace std; void zanj0() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } vector<vector<long long int> > trap; const long long int N = 2e5 + 5; vector<long long int> arr; bool cmp(vector<long long int>& a, vector<long long int>& b) { return a.back() == b.back() ? (a[0...
4
#include <bits/stdc++.h> bool u[1000001]; int pr[500001]; int l; int n; long long a[8]; int f[7000]; int thr[10]; int b[8]; int inf = 10000; int g[8]; int cal(long long x) { int i; int ret = 0; for (i = 1; i <= l && pr[i] <= x / pr[i]; i++) { while (x % pr[i] == 0) { x = x / pr[i]; ret++; } ...
3
#include <bits/stdc++.h> using namespace std; int main() { int b[100000], c = 0, d, e, f; int a; cin >> a; f = a; for (int i = 0; i < a; ++i) { cin >> b[i]; if (i == b[i]) c = c + 1; } for (int i = 0; i < a; ++i) { if (i != b[i]) { if (b[b[i]] == i) { c = c + 2; cout << c...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1000; int n, m, ans[9], x[N], y[N]; vector<int> hor[N], vert[N], Rdiag[N + N], Ldiag[N + N]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d%d", x + i, y + i); hor[x[i]].push_back(y[i]); vert[y[i]].push_back(x[...
5
#include <bits/stdc++.h> using namespace std; const long long max_ = 3000 + 7; const int mod = 1e9 + 7; const int inf = 1e9; const long long INF = 1e18; int read() { int s = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <=...
4
#include <bits/stdc++.h> using namespace std; int a, b, m, r[1000005], n, i, j, k, l; pair<int, int> o[1000005]; int main() { cin >> a >> b >> m >> r[0]; i = 1; while (i != 0) { r[i] = (a * r[i - 1] + b) % m; if (o[r[i]].first < 1) { o[r[i]].first++; o[r[i]].second = i; } else { l = ...
2
#include<bits/stdc++.h> using namespace std; int main() { double R; cin>>R; cout<<((2*3.14)*R)<<endl; }
0
#include <bits/stdc++.h> const int maxn = 100005; using namespace std; inline int rd() { 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; } ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; cin >> n; while (n--) { string a, b; cin >> a >> b; long long k = 0, f = 1; if (a.size() > b.size()) { cout << "NO" << endl; continue; } for (long...
2
#include <bits/stdc++.h> using namespace std; bool vowel(char a) { a = toupper(a); if ((a == 'A') || (a == 'E') || (a == 'I') || (a == 'O') || (a == 'U')) return 1; return 0; } long long int n, m, q, a, b, c, sum = 0, cnt = 0; long long int arr[300005]; map<long long int, bool> mp; string s; int setBit(long l...
4
#include<iostream> using namespace std; #define MAX 101 int w,h; char map[MAX][MAX]; int DX[] = {0,1,0,-1}; int DY[] = {-1,0,1,0}; int rec(int y,int x,char c){ if(map[y][x] == '.')return 0; map[y][x] = '.'; for(int i= 0;i < 4;i++){ int nx = x + DX[i]; int ny = y + DY[i]; if(nx < 0 || nx >= w)continue; if(ny ...
0
#include <iostream> #include <cmath> #include <iomanip> #include <algorithm> using namespace std; int main(){ while(1){ int d,e; cin >> d >> e; if(d==0) break; double minimum=1e9; for(int i=0; i<d; i++){ int j=d-i; double diff = fabs(e- sqrt(i*i+j*j)); minimum = min(diff, minim...
0
#include<bits/stdc++.h> using namespace std; struct I{I(){ios::sync_with_stdio(false);cin.tie(0);}}init; typedef long long LL; typedef vector<LL> V; typedef vector<V> VV; const LL MOD=1e9+7; LL p[500][500]; struct CWW{CWW(){ for(int i=1;i<500;i++){ p[i][0]=1; for(int j=1;j<500;j++) ...
0
#include <iostream> #include <vector> constexpr int INF = 1 << 30; void solve() { int n, m; std::cin >> n >> m; std::vector<int> ds(n), cs(m); for (auto& d : ds) std::cin >> d; for (auto& c : cs) std::cin >> c; std::vector<int> ans(n + 1, INF); ans[0] = 0; for (auto c : cs) { ...
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; inline int read() { int s = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar(); return s; } const int N = 5005; int n, q; int l[N], r[N], a[N], b[N]; int main() { n...
3
#include <bits/stdc++.h> using namespace std; bool p[5000007]; long long dp1[5000007], dp2[5000007]; void calcSieve() { p[0] = 1; p[1] = 1; for (int i = 2; i < 5000007; i++) { if (!p[i]) { for (int j = 2; j * i < 5000007; j++) { p[i * j] = 1; } } } for (int i = 1; i < 5000007; i++)...
1
#include <cstdio> #include <bits/stdc++.h> using namespace std; long long int items[3005][3005]; long long int dp[3005][3005][4]; int main() { int r, c, k; scanf("%d%d%d", &r, &c, &k); for (int l = 0; l < k; l ++) { int i, j, v; scanf("%d%d%d", &i, &j, &v); items[i][j] = v; } for (int i = 1; i <...
0
#include <bits/stdc++.h> using namespace std; int main() { int e, i, c = 0, d = 0, f = 0; string a; cin >> a; e = a.size(); for (i = 0; i < e; i++) { if (a[i] == 'a') c++; } d = e - c; if (c > d) { cout << c + d; } else { cout << (2 * c - 1); } }
1
#include <bits/stdc++.h> template <class T> inline void read(T &x) { x = 0; register char c = getchar(); register bool f = 0; while (!isdigit(c)) f ^= c == '-', c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); if (f) x = -x; } template <class T> inline void print(T x) { if (x < 0) pu...
3
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int main() { int n; string s, ss; cin >> s >> n; vector<pair<int, string> > v(n + 1); v[0] = make_pair(0, s); char next; while (cin.get(next)) if (next == '\n') break; for (int i = 1; i <= n; ++i) { getline(cin, ss); if (...
3
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 2; const int nmlog = 22; int nxt[MAX][23]; int color[MAX]; int dp[MAX]; int dp_new[MAX]; int robots[MAX], black[MAX]; void solve() { int n, m; vector<char> a; cin >> n >> m; a.resize(n * m); for (int i = 0; i < n; i++) { string s; cin...
6
#include <bits/stdc++.h> using namespace std; long long const mod = 1e9 + 7; long long const inf = 2e18; inline long long add(long long a, long long b) { return (a % mod + b % mod + mod) % mod; } inline long long mul(long long a, long long b) { return (a % mod * b % mod + mod) % mod; } inline long long sub(long lon...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e2 + 10; const int mod = 1e9 + 7; int n, b, k, x; int dp[2][maxn]; void muldp(int *dest, int *src, long long fac) { static int tmp[maxn]; memset(tmp, 0, sizeof tmp); for (int i = 0; i < x; ++i) { for (int j = 0; j < x; ++j) { int c = (i * f...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> f(n); vector<int> a(m); vector<int> b(m); vector<int> x(n + 1); vector<bool> am(n + 1); fill(x.begin(), x.end(), -1); for (int i = 0; i < n; i++) { cin >> f[i]; if (x[f[i]] == -1) { x[f[i]] = ...
2
#include <bits/stdc++.h> using namespace std; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; const int mod = (int)1e9 + 7; const long long INF64 = 3e18; void smxl(long long &a, long long b) { if (a < b) a = b; } void smnl(long long &a, long long b) { if (a > b) a = b; } void adsl(long long &a, long long b) {...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int x = 0; for (int i = 0; i < n; i++) { arr[i] += x; x = max(arr[i], x); cout << arr[i] << ' '; } cout << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; int a[120], n, b[120]; char c; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> c, a[i] = c - '0'; for (int i = 1; i <= n; i++) cin >> c, b[i] = c - '0'; sort(a + 1, a + n + 1); sort(b + 1, b + n + 1); if (a[1] < b[1]) { for (int i = 2; i <= n; i++...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; cout << fixed << setprecision(9) << cos(3.14159265358979323846 / (4 * n)) / sin(3.14159265358979323846 / (2 * n)) << ...
3
#include <bits/stdc++.h> using namespace std; template <typename T> inline T qmin(const T &a, const T &b) { return a < b ? a : b; } template <typename T> inline T qmax(const T &a, const T &b) { return a > b ? a : b; } template <typename T> inline void getmin(T &a, const T &b) { if (a > b) a = b; } template <typen...
5
#include <bits/stdc++.h> using namespace std; int binomialCoeff(int n, int k) { int res = 1; if (k > n - k) k = n - k; for (int i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; s...
2
#include <bits/stdc++.h> 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) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int res = 0; wh...
4
#include<iostream> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; ll L, R; ll memo[60][2][2][2]; ll dfs(int pos, int flagX, int flagY, int flagZ) { if (pos == -1) return 1; if (memo[pos][flagX][flagY][flagZ] != -1) { return memo[pos][flagX][flagY][flagZ]; } ll ret = 0; ...
0
#include <iostream> using namespace std; typedef long long ll; int main(){ ll n,r=0;cin>>n; ll m=n,ans=0,a[1000000]; fill(a,a+1000000,0); for(ll i=2;i*i<=n;i++){ if(m%i==0){ while(m%i==0){ a[r]++; m=m/i; } r++; } } ll j=1; for(int i=0;i<r;i++){ while(a[i]-j>=0...
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma,sse2") #pragma GCC optimization("unroll-loops") using namespace std; int64_t t, n, l, r, a[1000005]; string s; bool prime(int x) { for (int i = 2; i * i <= x; i++) { if (x % i == 0) return 0; } return 1; } void solve() { ...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; int a[n], vis[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; vis[i] = 0; } sort(a, a + n); int ans = 0; for (int i = 0;...
1
#include <bits/stdc++.h> using namespace std; int const N = 11000; char s[N]; int pos; using P = pair<int, int>; vector<P> expr(); int number() { return s[pos++] - '0'; } vector<P> factor() { if (s[pos] == '(') { pos++; auto res = expr(); assert(s[pos] == ')'); pos++; return res; } else { in...
5
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target("popcnt,abm,mmx,avx2") using namespace std; using Long = long long; using Double = double; using vi = vector<int>; template <class U, class V> istream& operator>>(istream& is, pair<U, V>& p) { is >> p.first >> p.second; ret...
4
#include <bits/stdc++.h> using namespace std; long long a[200005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } long long ans = a[n]; for (int i = n - 1; i >= 1; i--) { if (a[i] < a[i + 1]) ans += a[i]; els...
2
#include <bits/stdc++.h> using namespace std; char w[120]; char q[120]; int b, d, wlen, qlen; int matched[120]; int main() { scanf("%d %d", &b, &d); scanf("%s", w); scanf("%s", q); wlen = strlen(w); qlen = strlen(q); for (int i = (0); i < (qlen); ++i) { bool ok = false; for (int j = (0); j < (wlen);...
2
#include<iostream> #include<string> #include<vector> #include<cstdio> #include<sstream> #include<algorithm> #include<cmath> #include<map> #include<functional> #include<queue> #include<stack> #include<set> using namespace std; int ta[100][100]; const int BAN=10; int main(){ char ttmp; int y,x,s,cnt=0,ma=0; while(...
0
#include <bits/stdc++.h> using namespace std; #define ll long long map<pair<int,int>,int> m; int main(void){ int H,W,N; cin >> H >> W >> N; for(int i=0;i<N;i++){ int x,y; cin >> x >> y; for(int a=0;a<3;a++){ for(int b=0;b<3;b++){ int nx = x-a; int ny = y-b; if(nx<1||ny<1||nx>H-2||ny>W-2)contin...
0
#include <bits/stdc++.h> using namespace std; vector<string> path; void add(string s) { s += "/"; string tmp = ""; int ssize = s.size(); for (int i = 0; i < ssize; i++) { if (s[i] == '/') { if (tmp == "..") { path.pop_back(); } else { path.push_back(tmp); } tmp = ""; ...
3
#include <bits/stdc++.h> using int64 = long long; namespace oct { inline void ios(bool enable = false, std::string s = "") { if (enable) { std::string t; freopen((t = s + ".in").data(), "r", stdin); freopen((t = s + ".out").data(), "w", stdout); } std::ios::sync_with_stdio(0); std::cin.tie(0), std::...
4
#include <bits/stdc++.h> using namespace std; vector<int> v[100000]; int p[100000]; int s = 1; int f(int i, int l) { for (int j = 0; j < v[i].size(); j++) { if (p[v[i][j]] == l) { s = 0; return 0; } else { if (p[v[i][j]] == -1) { p[v[i][j]] = 1 - l; f(v[i][j], 1 - l); }...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 200; int mp[maxn]; char s[100100]; int num[100100]; int id = 0; int cnt[maxn]; int n; void solve() { int s = 0, t = 0; int res = n; memset(cnt, 0, sizeof(cnt)); int get = 0; while (true) { while (t < n && get < id) { int lx = num[t++]; ...
3
#include<stdio.h> int main(void) { int n, i, sum = 0, x; char a[100], b[100], c[100]; char k; scanf("%d %s %s %s", &n, a, b, c); for (i = 0; i < n; i++) { x = 0; if (b[i] == c[i] && a[i] == b[i]); else if(a[i]==b[i]||b[i]==c[i]||a[i]==c[i])x++; else x += 2; sum += x; } printf("%d\n", sum); }
0
#include <bits/stdc++.h> using namespace std; int main() { string s; stack<int> st; for (; cin >> s;) { if (s == "+" || s == "-" || s == "*") { int a = st.top(); st.pop(); int b = st.top(); st.pop(); if (s == "+") st.push(b + a); if (s == "-") st.pus...
0
#include <bits/stdc++.h> using namespace std; int n; pair<int,int> a[100001]; int l; int main(){ cin.tie(0); ios_base::sync_with_stdio(0); cin>>n; int i; for(i=1 ; i<=n ; i++){ int x,l; cin>>x>>l; a[i]={x+l,x-l}; } sort(a+1,a+n+1); int k=-2e9; int ans=0; f...
0
#include<bits/stdc++.h> using namespace std; #define ll long long map<ll,ll>m; ll a[222222]; ll n,k; int main(){ cin>>n>>k; for(int i=1;i<=n;i++)cin>>a[i]; for(int i=1;i<=n;i++)a[i]=(a[i-1]+a[i]-1)%k; ll ans=0; m[0]++; for(int l=0,r=1;r<=n;r++){ if(r-l==k)m[a[l++]]--; ans+=m[a[r]]; m[a[r]]++; }cout<<ans<<e...
0
#include <bits/stdc++.h> using namespace std; string str, tmp, ans[3]; int n; int main() { srand(time(NULL)); cin >> n >> str; do { tmp = str; for (int i(0), num(0), x(0); i < 3; i++, tmp = to_string(x), x = 0) { ans[i] = ""; for (size_t j(0); j < tmp.size(); j++) { num = num * 10 + tm...
1
#include<iostream> int main(){ std::string l[9]={"',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ"},s,a; for(int i,c,t;std::cin>>s;std::cout<<a<<"\n"){ for(s+=1,a="",c=i=0;++i<s.size();c++) if(s[i-1]-s[i]){ if(s[i-1]-48){ t=s[i-1]-49; a+=l[t][c%l[t].size()]; } c=-1...
0
#include <bits/stdc++.h> using namespace std; const int N = 1000; const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; int n, m, res; char a[N][N]; char command[N]; bool inside(int x, int y) { return (0 < x && x <= n && 0 < y && y <= m && a[x][y] != '#'); } int main() { ios_base::sync_with_stdio(false)...
2
#include<iostream> #include<algorithm> #include<vector> #include<stack> #include<map> #include<set> #include<queue> #include<cstdio> #include<climits> #include<cmath> #include<cstring> #include<string> #include<sstream> #define f first #define s second #define mp make_pair #define REP(i,n) for(int i=0; i<(int)(n); i+...
0
#include <bits/stdc++.h> using namespace std; int a[105]; int main() { char ch[1005]; int cnt = 0; int jia = 0, jian = 0; gets(ch); int len = strlen(ch); int num = 0; for (int i = 0; i < len; i++) { if (ch[i] != '?') { if (ch[i] == '+') { jia++; a[cnt] = 1; cnt++; }...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; template <class T> inline bool setmin(T &a, T b) { if (a > b) return a = b, 1; return 0; } templat...
1
#include <bits/stdc++.h> using namespace std; long long g[20], temp[20]; int main() { for (int i = 0; i < 14; i++) cin >> temp[i]; long long maxx = 0; for (int i = 0; i < 14; i++) { if (temp[i] == 0) continue; for (int j = 0; j < 14; j++) g[j] = temp[j]; long long ans = 0; long long a = g[i] / 14,...
2
#include <iostream> #include <algorithm> #include <vector> #include <iomanip> #include <map> #include <queue> #include <cmath> static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using namespace std; template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; int main()...
0
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; int main() { int n, m, k; cin >> n >> m >> k; vector<int> c(n); vector<vector<int>> A(n); for (int i = 0; i < n; i++) { cin >> c[i]; A[i].resize(c[i]); for (int j = 0; j < c[i]; j++) { cin >> A[i][j]; A[i][j...
6
#include <bits/stdc++.h> using namespace std; const int N = 500 + 7; int n, m, us[N][N], u, v; pair<int, int> pre[N][N]; vector<int> vc[N]; int main() { cin >> n >> m; for (int i = 0; i < m; i++) { cin >> v >> u; vc[v].push_back(u); vc[u].push_back(v); } for (int i = 0; i < N; i++) { for (int j ...
5
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 1, -1, 0, 1, -1, 1, -1}; int dy[] = {1, 0, 0, -1, -1, 1, 1, -1}; int main() { ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; map<int, int> idx; int st = -1, en = -1; for (int i = 0; i < (int)s.size(); i++) { if...
3
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { long long people, ice, num, dist = 0; char ch; cin >> people >> ice; while (people--) { cin >> ch >> num; if (ch == '+') { ice += num; } else if (ch == '-') { if (ice < num) { dist++; } e...
1
#include <bits/stdc++.h> using namespace std; const int fx[] = {+1, -1, +0, +0}; const int fy[] = {+0, +0, +1, -1}; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } lon...
3