solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; const int mxx = 300005; vector<pair<int, int> > v[2 * mxx]; unordered_map<int, int> mp; long long int Max[mxx]; long long int tree[8 * mxx][2]; void update(int l, int r, int L, int R, int n, long long int val) { if (l > R || r < L) ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, a[100], b[100], sa = 0, sb = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; if (a[i] % 2 != 0) sa++; if (b[i] % 2 != 0) sb++; } if (sa % 2 == 0 && sb % 2 == 0) { cout << "0"; exit(0); } else if (sa % 2 != ...
1
#include <bits/stdc++.h> using namespace std; int m, n; char c[50 + 5][50 + 5]; int ans = 0; int main() { cin >> m >> n; for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) cin >> c[i][j]; for (int i = 0; i < m - 1; i++) for (int j = 0; j < n - 1; j++) { string s = ""; for (int k = i; k <=...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, b, cnt = 0, i, j; cin >> n >> m; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { cin >> a >> b; if (a == 1 || b == 1) cnt++; } } cout << cnt << endl; return 0; }
1
#include <bits/stdc++.h> #define N 101 using namespace std; int h,w,A; string mp[101]; int dx[]={0,0,1,-1};//V^>< int dy[]={1,-1,0,0}; int ans=1e9,used[101][101][10][10][4]; void dfs(int x,int y,int p,int q,int dir){ int &u=used[x][y][p][q][dir]; if(ans<=2*A-(p+q)||(u!=-1&&u<=2*A-(p+q)))return; u=2*A-(p+q); ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, root; cin >> n; vector<vector<int> > f(n + 1, vector<int>(20, 0)); vector<vector<int> > adj(n + 1), g(n); vector<int> d(n + 1, 0); for (int i = 1, x; i <= n; i++) { cin >> x; if (!x) ...
5
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; string arr[] = {"00", "01", "10", "11"}; vector<string> ab, ba, revab, revba; vector<int> abidx, baidx; bool check(string x) { if (x.empty()) return false; for (int i = 2; i < ((int)((x).size())); i += 2) if (x[i] != x[i - 1]) return false...
4
#include <bits/stdc++.h> using namespace std; struct Point { int x, y; inline Point() {} inline Point(int _x, int _y) { x = _x; y = _y; } } po[6000]; int n, r; inline int sqr(int x) { return x * x; } int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; inline bool ok(int x, int y) { int a = sqr(x), b = sqr...
5
#include <bits/stdc++.h> using namespace std; long long setBitNumber(long long n) { if (n == 0) return 0; long long msb = 0; n = n / 2; while (n != 0) { n = n / 2; msb++; } return (1 << msb); } void solve() { long long n; cin >> n; long long arr[n]; for (long long i = 0; i < n; i++) cin >> a...
2
#include <bits/stdc++.h> using namespace std; void FAST_IO(string filein = "", string fileout = "", string fileerr = "") { if (fopen(filein.c_str(), "r")) { freopen(filein.c_str(), "r", stdin); freopen(fileout.c_str(), "w", stdout); } cin.tie(0), cout.tie(0)->sync_with_stdio(0); } void Hollwo_Pelw(); sign...
5
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { string S, T, P; cin >> S >> T >> P; bool W[T.size() + 5]; for (int j = 0; j < T.size(); j++) W[j] = 0; int c = 0, i; bool ans = 1; for (i = 0; i < S.size() and c < T.size(); i++) { while (T[...
3
#include <bits/stdc++.h> using namespace std; struct QUERY { int query, time, number; }; vector<map<int, int> > tree; void update(int v, int tl, int tr, int pos, int query, int value) { int tm = (tl + tr) / 2; if (query == 1) { if (tl == tr) return; tree[v][value]++; } else if (query == 2) { if (tl ...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; int n; struct P { int num; int pos; }; P in[maxn]; bool cmp(P a, P b) { if (a.num == b.num) { return a.pos < b.pos; } return a.num > b.num; } int main() { while (~scanf("%d", &n)) { for (int i = 1; i <= n; i++) { scanf("%d", ...
2
#include <bits/stdc++.h> using namespace std; struct t { char c; int a, b; t(char c, int a, int b) : c(c), a(a), b(b) {} t() {} }; int n; vector<t> e; double temp; double t0 = 1000; double gen_rand() { int x = rand() + 1, y = rand() + 1; x %= y; return x / (double)y; } int get_ans() { int r = 0, b = 0; ...
5
#include <bits/stdc++.h> using namespace std; int main() { long long int c, d, x, y, a, b; cin >> a >> b >> x >> y >> c >> d; if (c == 0 and d == 0) { if ((a == x and b == y) or (a == -x and b == -y) or (a == y and b == -x) or (a == -y and b == x)) cout << "YES" << endl; else cout << "...
5
#include <bits/stdc++.h> int main() { int n, a, t = 0, p, s[1000]; scanf("%d", &n); scanf("%d", &p); while (--n) { scanf("%d", &a); if (a <= p) { s[t] = p; ++t; } p = a; } s[t] = p; ++t; printf("%d\n", t); for (n = 0; n < t; ++n) { printf("%d ", s[n]); } return 0; }...
1
#include <bits/stdc++.h> using namespace std; const int Inf = 999999; int n, m, s, e, ans; int num[100002]; vector<int> V[100002]; int dp[100002][301]; int main() { scanf("%d%d%d%d", &n, &m, &s, &e); for (int i = 1; i <= n; i++) scanf("%d", &num[i]); for (int i = 1; i <= m; i++) { int b; scanf("%d", &b); ...
3
#include <iostream> #include <string.h> using namespace std; long a[100000]; int main() { memset(a, 0, sizeof(a)); int n, j = 0; cin >> n >> a[0]; for (int i = 1; i < n; i++) { long k; cin >> k; if (k > a[j]) { a[j + 1] = k; j++; } } for (int i = 0; i < j; i++) { cout << a[i] << " "; } cou...
0
#include <bits/stdc++.h> namespace lyc { using namespace std; template <typename T> inline void read(T& res) { 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 << 1) + (x << 3) + (ch ^ 48); ch...
5
#include <bits/stdc++.h> using namespace std; signed main() { int t, n, len; cin >> t; while (t--) { cin >> n >> len; std::vector<int> a(n + 2, 0), s(n + 2, 1), sb(n + 2, 1); std::vector<double> tt(n + 2, 0), tb(n + 2, 0); a[n + 1] = len; for (int i = 0; i < n; i++) cin >> a[i + 1]; for (i...
3
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; int main() { int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f; int ans_ws = 100*a, ans_s = 0; rep(i, 31){ rep(j, 31){ int w = 100*a*i + 100*b*j; if(w == 0) continue; ...
0
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); int dblcmp(double d) { if (fabs(d) < eps) return 0; return d > eps ? 1 : -1; } inline double sqr(double x) { return x * x; } struct point { double x, y; point() {} point(double _x, double _y) : x(_x), y(_y){};...
3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, a; cin >> n; queue<int> q; vector<int> flag, kle; flag.resize(n + 5, 0); for (int i = 0; i < n; i++) { cin >> a; q.push(a); ++flag[a]; } for (int i = 1; i <= n; i++) { if (flag[...
4
#include <bits/stdc++.h> using namespace std; vector<int> ori(1), A, B; int idx[19], V[19]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ((void)0); ((void)0); ((void)0); int N, ans = 0, p = 0; for (int i = 1; i < 18; i++) { vector<int> temp(1, i); idx[i] = -1; for...
5
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); long long n, k; int main() { ios::sync_with_stdio(false); cin >> n >> k; cout << (6LL * (n - 1) + 5) * k << endl; for (int i = (0); i < (n); i++) { long long i6 = 6LL * i; cout << (i6 + 1) * k << " " << (i6 + 2) * k << " " << (i...
2
#include <bits/stdc++.h> using namespace std; int matrix[2001][2001], sum[2001] = {0}; int main() { int m, n; char ch; cin >> n >> m; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) { cin >> ch; matrix[i][j] = ch - '0'; sum[j] += matrix[i][j]; } int flag; for (int i = 1; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; for (int i = s.length() - 1; i > 0; i--) { if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y') { if (s[i - 1] == 'a' || s[i - 1] == 'e' || s[i - 1] == 'i' |...
1
#include <bits/stdc++.h> using namespace std; int grandy[890000]; int dp[890000][5]; vector<int> temp(5); void build() { for (int i = 0; i < 890000; i++) grandy[i] = 0; for (int i = 0; i < 890000; i++) for (int j = 0; j < 5; j++) dp[i][j] = 0; dp[0][0] = 1; dp[1][0] = 2; dp[2][0] = 3; for (int i = 3; i ...
3
#include <bits/stdc++.h> using namespace std; inline int rd() { int x = 0; char c = getchar(); bool f = 0; while (c < '0' && c != '-') c = getchar(); if (c == '-') f = 1, c = getchar(); while (c >= '0') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); return f ? -x : x; } const int SIZE = 2e5 + 100; con...
6
#include<cstdio> #include<algorithm> using namespace std; #define MAX 100 int p[MAX+1] = {0}; int m[MAX+1][MAX+1] = {0}; int main() { int n; int a,b; scanf("%d" ,&n); for(int i=0; i<n; i++) { scanf("%d%d", &a, &b); if(i == 0) p[0] = a; p[i+1] = b; } for(int l = 2; l <= n; l++) { for(int i=1; i <= n-l+...
0
#include <bits/stdc++.h> using namespace std; int const MAXn = 2e5 + 2; int p1[MAXn]; int p2[MAXn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> num; for (int i = 1; i <= n; i++) { int x; cin >> x; if (x == 0) continue; num.push_back(x); ...
2
#include<bits/stdc++.h> using namespace std; int main(){ int x; cin>>x; cout<<!x<<endl; }
0
/*Swati1411*/ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; cin>>t; while(t--) { int n; cin>>n; int a[n];int f[101]={0}; for(...
1
#include <bits/stdc++.h> using namespace std; long long ans, s, f[2][210][3]; int n, a[100010]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); if (a[1] == -1) for (int i = 1; i <= 200; i++) f[1][i][0] = 1; else f[1][a[1]][0] = 1; for (int i = 2; i <= n; i++) { s = 0...
1
#include <bits/stdc++.h> int power(int x, int y) { int i; int num = 1; for (i = 0; i < y; i++) { num = num * x; } return num; } int main() { int t; scanf("%d", &t); int n, i, j, k, l; int b[10]; for (i = 0; i < t; i++) { l = 0; scanf("%d", &n); for (j = 0; j < 10; j++) { if (n ...
1
#include <bits/stdc++.h> using namespace std; int n, m, f[100021][20], Max[100021][20], Min[100021][20]; int ff[100021], ans[1000021], h[100021], id[100021]; int find(int x) { return ff[x] == x ? x : ff[x] = find(ff[x]); } struct edge { int a, b, c, id, fg; bool operator<(const edge& z) const { return c < z.c; } } ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, t; bool c = false; cin >> n >> t; int a[n]; int x = 1; for (int y = 1; y < n; y++) { cin >> a[y]; a[y] += y; } while (x < n) { x = a[x]; if (x == t) { c = true; break; } } if (c == true) cout << "YE...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int mxn = 5e3 + 10; const int mod = 998244353; const int inf = 1e9; ll dp[mxn][mxn]; ll calc(ll a, ll b) { if (dp[a][b] != -1) return dp[a][b]; if (a == 1) return dp[a][b] = b + 1; if (b == 1) return dp[a][b] = a + 1...
3
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ '0'); if (f) return x; return -x; } const int N = 1e5; struct Edge { i...
6
#include <bits/stdc++.h> using namespace std; vector<int> v[100010]; long long int done, toadd, ind, cnt; int main() { int n, a; cin >> n; for (int i = 1; i <= n; i++) { cin >> a; v[a].push_back(i); } for (int i = 0; i < 100010 - 5; i++) { if (v[i].empty()) continue; if ((*(v[i].rbegin())) < i...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (int i = 1; i <= n; i++) cin >> a[i]; if (a[2] + a[1] > a[n]) cout << -1 << endl; else cout << 1 << " " << 2 << " " << n << endl; } }
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 20, mod = 998244353; long long n, a[maxn], part[maxn], Inv[maxn], fact[maxn], b[maxn / 10], A[maxn / 10], Sum, Ans, seg[maxn]; pair<int, int> lz[maxn]; vector<int> su; void upd(int i, int j, int x, int a1, int q) { seg[x] += (j - i) * (a1 + a1 +...
5
#include <iostream> using namespace std; typedef long long ll; const ll MOD = (1e+9) + 7; int n; int t[100000], a[100000]; int main() { cin >> n; for(int i = 0; i < n; i++){ cin >> t[i]; } for(int i = 0; i < n; i++){ cin >> a[i]; } ll ans = 1; if(t[n-1] != a[0]) ans = 0; for(int i = 1; i ...
0
#include <bits/stdc++.h> using namespace std; bool good(pair<int, int> a, pair<pair<int, int>, int> b) { if (a.second <= b.first.first) return true; return false; } long long f(pair<int, int> a, pair<pair<int, int>, int> b) { long long len = (b.first.first / a.second); long long pol = a.first / b.first.second +...
2
#include <bits/stdc++.h> using namespace std; const int N = 100000; const int INF = 1e9; int n, s, l; int a[N]; int Min[4 * N]; int Max[4 * N]; void buildMin(int v, int tl, int tr) { if (tl == tr) Min[v] = a[tl]; else { int tm = (tl + tr) / 2; buildMin(v * 2, tl, tm); buildMin(v * 2 + 1, tm + 1, tr)...
2
#include <bits/stdc++.h> using namespace std; int n, m; int arr[300005]; int Cache[1000005]; pair<long long, int> segTree[1200005]; int Divisors(int n) { int cnt = 0; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) cnt++; else cnt = cnt + 2; } } return ...
6
#include <bits/stdc++.h> using namespace std; int main() { char a[100]; int n, i, s = 0, f = 0; cin >> n; cin >> a; for (i = 1; i <= n; i++) { if (a[i] == 'F' && a[i - 1] == 'S') f++; else if (a[i] == 'S' && a[i - 1] == 'F') s++; } if (f > s) cout << "YES\n"; else cout << "NO...
1
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& os, vector<T> V) { os << "[ "; for (auto v : V) os << v << " "; return os << "]"; } template <class L, class R> ostream& operator<<(ostream& os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } ...
4
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 7; const int mod = 998244353; int c[N], cc[N]; vector<int> a[N], b[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) a[i].push_back(0); for (int i = 1; i <= n; i++) for (int j = 1;...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long INF = 4e18; const int inf = 2e9; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a * b / gcd(a, b); } int a[3005], pos[3005]; int main(void) { int n, i, j, naik = 0; scanf("%d", &n); ...
4
#include <bits/stdc++.h> using namespace std; void print_d(int n) { if (n < 0) { n = -n; putchar('-'); } int i = 10; char output_buffer[10]; do { output_buffer[--i] = (n % 10) + '0'; n /= 10; } while (n); do { putchar(output_buffer[i]); } while (++i < 10); } void print_ld(long n) { ...
4
#include <bits/stdc++.h> using namespace std; bool is(int arr[], int n, int m, int ans) { int prev = 0; int ok = 1; for (int i = 0; i < n; i++) { int l = arr[i], r = arr[i] + ans; if ((l <= prev && prev <= r) || (l <= prev + m && r >= prev + m)) continue; if (prev > l) { ok = 0; break; ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; int x = 1, y = n, i = 1, j = m; int cnt = 2 * m; while (x < y) { if (cnt % 2 == 0) { cout << x << " " << i++ << '\n'; } else cout << y << " " << j-- << '...
4
#include <bits/stdc++.h> using namespace std; long long n, k; int main() { cin >> n; if (n < 13) { k = pow(2, n); } else { k = 8092 * pow(2, n - 13); } cout << k; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int maxn = 3005; const long long mod = 1e9 + 7; int n; long long dp[maxn][maxn], D; vector<int> G[maxn]; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } long long int t = floor(log2(n - 1)); long long int shifter = pow(2, t); long long int moves = 0; for (int i = 0; i < n - 1; i++) { moves += a[...
1
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; void solve() { string s, r; cin >> s >> r; int n = s.size(); int m = r.size(); vector<int> v[26]; for (int i = 0; i < n; i++) { v[s[i] - 'a'].push_back(i); } int rc[26]; memset(rc, 0, sizeof rc); for (int i = 0; i < m; i++...
3
#include <bits/stdc++.h> using namespace std; long long qu1(long long n, long long x); long long qu2(long long n, long long x); long long qu1(long long n, long long x) { if (x & 1) return (x / 2) + 1; if (n & 1) return qu2(n / 2, x / 2) + n / 2 + 1; return qu1(n / 2, x / 2) + n / 2; } long long qu2(long long n, l...
2
#include <bits/stdc++.h> using namespace std; int x[] = {0, -1, 0, 1}; int y[] = {-1, 0, 1, 0}; int n, m; char mtx[12][12]; bool chk[12][12]; bool valid(int x, int y) { if (x < 0 || x > n - 1 || y < 0 || y > m - 1) return 0; else return 1; } int main() { int ans = 0; cin >> n >> m; for (int i = 0; i <...
2
#include <bits/stdc++.h> using namespace std; const int N = 2005, M = 55, mod = 998244353; int n, m, b[N], fac[N], ifac[N], dp[2][N][N * 2], sum[2][N][N * 2]; int L[N], R[N]; int fpow(int x, int y) { int res = 1; while (y) { if (y & 1) res = 1ll * res * x % mod; x = 1ll * x * x % mod, y >>= 1; } return ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long counter = 0; while (n != 0) { long long x = n; int b = -1; while (x != 0) { if (x % 10 > b) b = x % 10; x /= 10; } n -= b; counter++; } cout << counter << endl; }
3
#include <bits/stdc++.h> using namespace std; const int N = 150005; int n, i, x, a[N], ia[N]; long long ans; struct atom { int m0, m1, c; }; inline atom operator+(atom A, atom B) { if (A.m0 < B.m0) swap(A, B); return A.m0 == B.m0 ? (atom){A.m0, max(A.m1, B.m1), A.c + B.c} : (atom){A.m0, max(...
5
#include <bits/stdc++.h> using namespace std; long long s[110000], a[110000], b[110000], acb[110000], bca[110000]; int main() { int N, S; long long A = 0, B = 0, E = 0, aA = 0, aB = 0, Sum, Es = 0; memset(acb, 0, sizeof(acb)); memset(bca, 0, sizeof(bca)); ios::sync_with_stdio(false); cin >> N >> S; for (i...
2
#include <bits/stdc++.h> using namespace std; double dl[100], dr[100]; int l[100], r[100]; double prob[100][11234]; inline double f(double a, double b, double c, double d) { return (max(double(0), min(d, b) - max(a, c) + 1)) / (b - a + 1); } int main() { int m, i, j, k, n; double ans = 0, e; scanf("%d", &n); ...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC optimize("unroll-loops") using namespace std; void my_file_in_out() { freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout); } inline void OK(string t = "") { cerr << "OK " << t << '\n'; } inline long double time() { ret...
6
#include <bits/stdc++.h> using namespace std; template <class T> inline bool read(T &x) { int c = getchar(); int sgn = 1; while (~c && c<'0' | c> '9') { if (c == '-') sgn = -1; c = getchar(); } for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sgn; return ~c; } cons...
4
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int mod = 1000000007; const double eps = 1e-12; double maxx, minn; int maxi, mini; int cases = 0; int f[200010]; int s[200010]; int ss[200010]; int a[200010]; int b[200010]; int n, w; void getfill(int *s) { memset(f, 0, sizeof(f)); fo...
4
#include <bits/stdc++.h> using namespace std; template <typename _A, typename _B> using _p = pair<_A, _B>; template <typename _A> using _v = vector<_A>; template <typename _A> using _q = queue<_A>; template <typename _A> using _s = set<_A>; template <typename _A> using _st = stack<_A>; template <typename _A> using _d =...
5
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > p, A, B; bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } int binSearch(int s, int e, int v) { if (s > e) return -1; int md = (s + e) / 2; if (p[md].second == v) return md; else if (p[md].second < v) return...
2
#include <bits/stdc++.h> using namespace std; struct p { int x; int y; int i; }; vector<p> sp[300000], sn[400000]; int flagsp[300000], flagsn[400000]; long long int val[1000000]; int yd = 200000; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; for (int i = 0; i < k; i+...
3
#include <bits/stdc++.h> using namespace std; int n, p, upsAndDowns, poslednja, prva; short howMuch[100002], df[100002]; char c[100002]; int diff(char c1, char c2) { int x, y; x = c1 - c2; y = 26 + c2 - c1; if (x > y) x = y; return x; } int manji(int x, int y) { if (x > y) x = y; return x; } int main() { ...
3
#include <bits/stdc++.h> using namespace std; #define REP(i,m) for(int i=0; i<m; i++) #define FOR(i,n,m) for(int i=n; i<m; i++) #define INF 1000000007 #define INFL (1LL << 60) #define MOD 998244353 #define ALL(v) v.begin(),v.end() #define pb push_back #define ll long long int #define P pair<ll, ll> int main() { int ...
0
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <typename T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), (c > '9' ||...
4
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} template<class T> inline T sqr(T x) {return x*x;} typedef vector<int> vi; typedef vector<vi> vvi; typed...
0
#include<bits/stdc++.h> using namespace std; int main(){ //freopen("/home/byte001/Code/Input/1.txt","r",stdin); vector<int >a(9,0); for(int i=0;i<9;i++) cin>>a[i]; int n; cin>>n; bool isTrue = false; vector<int >b(9,0); while(n--){ int x; cin>>x; for(int i=0;i<9;i++) if(a[i]==x) b[i]=1; } if( (b[0]==1&&...
0
#include <bits/stdc++.h> using namespace std; using cd = complex<double>; const long long INF = 1e9; const long long mod = 1e9 + 7; const double Pi = acos(-1); void Fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int h, w, n; long long Fact[200005], iFact[200005], dp[2005]; vector<pair<int...
3
#include <iostream> #include <string> using namespace std; int main() { string s; int n; while (getline(cin, s)) { n = s.size(); for (int i = 1; i < 27; i++) { for (int j = 0; j < n; j++) { if (s[j] == ' ' || s[j] == '.') { continue; } if (s[j] == 'z') { s[j] = 'a'; c...
0
#include <bits/stdc++.h> using namespace std; string s; int hal(int o, int q) { string temp = ""; char holder = ' '; while (o != 0) { holder = o % 2 + '0'; temp = holder + temp; o /= 2; } reverse(temp.begin(), temp.end()); while (temp.size() < 8) temp += "0"; reverse(temp.begin(), temp.end());...
1
#include <bits/stdc++.h> using namespace std; #pragma GCC diagnostic ignored "-Wmissing-declarations" long long const inf = 1e18; long long solve(int a, int t, int p, int t0, int needtime, int x) { if (t >= t0) return needtime / t0 >= x ? 0 : inf; int l = -1; int r = needtime / t + 1; while (r - l > 1) { in...
3
#include <bits/stdc++.h> using namespace std; long long n, m, k; unordered_map<int, vector<pair<int, int> > > l[2]; unordered_map<int, int> ccnt[2]; int getXor(int t, int lenL, int cnt) { int ret = 0, ccut = 0; for (auto it = l[t].begin(); it != l[t].end(); it++) { sort(it->second.begin(), it->second.end()); ...
5
#include <bits/stdc++.h> using namespace std; vector<long long> arr; vector<long long> st; vector<long long> maxTillYet; int main() { int N; cin >> N; arr.resize(N); for (int i = 0; i < N; i++) cin >> arr[i]; sort(arr.begin(), arr.end()); st.assign(N, 0); maxTillYet.assign(N, 0); long long ans = 0; fo...
1
#include <bits/stdc++.h> using namespace std; long long int INF = 1e18, n, m, k, p[100100], sum, a[300100], b[300100], c[300100], d[100100], f[10], s, x, y, z, mx = -INF, mn = INF, ans, dlans[110], ind; bool marked[1010][1010]; double PI = 3.1415926535897932384626433832795; char ch[10][10], ...
1
#include <bits/stdc++.h> using namespace std; long long in[100010]; long long n; int main() { long long x, y; while (~scanf("%lld", &n)) { memset(in, 0, sizeof(in)); for (long long i = 1; i < n; i++) { scanf("%lld%lld", &x, &y); in[x]++; in[y]++; } if (n == 2) { printf("Yes\n...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 1003; int N, M, Q, a[maxn][maxn], up[maxn][maxn], dn[maxn][maxn], le[maxn][maxn], ri[maxn][maxn]; inline void maintainup(int x, int y) { for (int i = 1; i <= N; ++i) { up[i][y] = a[i][y] == 0 ? 0 : up[i - 1][y] + 1; } } inline void maintaindn(in...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; priority_queue<int> x; cin >> n; int s; for (int i = 0; i < n; ++i) { cin >> s; x.push(s); } int ans = x.top() - 25; if (ans < 0) { cout << 0 << endl; } else { cout << ans << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef tuple<int, int> duo; #define TT template<typename T> #define TTF template<typename T, typename F> #define ET(T) typename T::value_type TT inline T sq(T x){return x*x;} TT inline T In(){T x;cin>>x;return x;} TT inline ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; string s, ss; map<char, string> mp; mp['0'] = ""; mp['1'] = ""; mp['2'] = "2"; mp['3'] = "3"; mp['4'] = "223"; mp['5'] = "5"; mp['6'] = "35"; mp['7'] = "7"; mp['8'] = "2227"; mp['9'] = "2337"; cin >> n >> s; for (int i = 0; ...
3
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; void min_self(long long &a, long long b) { a = min(a, b); } void max_self(long long &a, long long b) { a = max(a, b); } long long add(long long x, long long y) { return (x + y) % MOD; } long long sub(long long x, long long y) { return add(x, M...
3
#include <bits/stdc++.h> using namespace std; const int M = 1000000009; long long power(long long b, long long e) { if (e < 0) return 0; if (!e) return 1; long long z = power(b, e >> 1) % M; z *= z; z %= M; if (e & 1) z *= b; z %= M; return z; } int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k);...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 40; int n; string s; int vec[MAXN]; int main() { cin >> n >> s; vec[0] = 1; for (int i = 1; i < n; i++) { char ch = s[i - 1]; if (ch == '=') vec[i] = vec[i - 1]; else if (ch == 'R') vec[i] = vec[i - 1] + 1; else { ...
1
#include <bits/stdc++.h> using namespace std; int i, i0, n, m, ans, a[50005][6]; long long dp[6][50005]; int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) for (int i0 = 1; i0 <= m; i0++) scanf("%d", &a[i][i0]); for (int i = 1; i <= m; i++) { for (int i0 = 1; i0 <= n; i0++) { dp[i][i0...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string a[n]; long long ans = 1; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { map<char, int> ma; for (int j = 0; j < n; j++) { ma[a[j][i]]++; } ans = ans * ma.size() %...
3
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 1000; int n; int target[MAXN]; char g[MAXN][MAXN + 1]; int targetedby[MAXN]; bool done[MAXN]; int solve() { for (int x = (0); x < (n); ++x) { for (int y = (0); y < (n); ++y...
5
#include <bits/stdc++.h> using namespace std; inline int rd() { int x = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) x = x * 10 + c - 48, c = getchar(); return x; } const int N = 8005; int n, nn, ql, qr, e[N][N], d[N], q[N], o[N], c[N]; char s[N]; long long ans; int main() { ...
5
#include <bits/stdc++.h> using namespace std; struct CNT { int v, t; } tz[20]; struct ANS { int c; string str; } p[20]; inline bool cmp(const CNT& a, const CNT& b) { return a.t > b.t || (a.t == b.t && a.v < b.v); } inline bool cmp2(const ANS& a, const ANS& b) { return a.c < b.c || (a.c == b.c && a.str < b.str...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 3005, MOD = 1000000007; int n, D; vector<int> G[MAXN]; int f[MAXN][MAXN]; void dfs(int u) { for (int i = 1; i <= n + 1; i++) f[u][i] = 1; for (auto v : G[u]) { dfs(v); for (int i = 1; i <= n + 1; i++) f[u][i] = 1ll * f[u][i] * f[v][i] % MOD; }...
6
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const long long inf = 1e18 + 10; const int maxc = 1e6 + 10; const long long mod = 1e9 + 7; int a[maxc]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(6); long long n, p; cin >> n >> p;...
3
#include <bits/stdc++.h> using namespace std; int n, len; string s, t, ans; void iget(int o) { int i, k = (10 - s[o] + '0') % 10; t = ""; for (i = o; i < len; i++) t = t + (char)((s[i] - '0' + k) % 10 + '0'); for (i = 0; i < o; i++) t = t + (char)((s[i] - '0' + k) % 10 + '0'); } void iWork() { cin >> n >> s; ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 105; int a[maxn]; int main() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); reverse(a + 1, a + 1 + n); for (int i = 1; i <= n; i++) printf("%d%c", a[i], i == n ? '\n...
1
#include<bits/stdc++.h> using namespace std; int main() { int N; cin>>N; N/=200; cout<<10-N<<endl; return 0; }
0