func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; long long int a[n], b[n], c[n], d[n]; bool f = false; for (long long int i = 0; i < n; i = i + 1) { cin >> a[i] >> b[i] >> c[i] >> d[i]; if (b[...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7; int ans[N]; int he[N]; int res[N]; vector<int> g[N]; vector<int> a[N]; vector<int> lul[N]; void dfs(int v, int pr, int h) { he[v] = h; for (auto to : g[v]) { if (to != pr) { dfs(to, v, h + 1); } } } ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 5; const int MOD = 1e9 + 7; int dr[4] = {0, 0, 1, -1}; int dc[4] = {1, -1, 0, 0}; int ddr[8] = {0, 0, 1, -1, 1, -1, 1, -1}; int ddc[8] = {1, -1, 0, 0, 1, -1, -1, 1}; bool isPrime(int n) { if (n <= 1) return false; for (int i = 2...
#include <bits/stdc++.h> using namespace std; long long solve(long long n, long long x, long long y) { if (y == 0) return 0; if (y == x / 2 + 1) return n / 2 + (n % 2); long long res = 0; if (y > x / 2 + 1) { res += n / 2; res += n % 2; res += solve(n / 2, x / 2, y - x / 2 - 1); ...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; struct DSU { int n; vector<int> link, sz; DSU(int n) : n(n), link(n), sz(n) { for (int i = 0; i < n; i++) { link[i] = i; sz[i] = 1; } } int first(int x) { return (x == link[x] ? x : link[x] = f...
#include <bits/stdc++.h> using namespace std; int n, d, m, a[100001], id; long long sum[100001]; int main() { scanf( %d%d%d , &n, &d, &m); for (int i = 1; i <= n; ++i) scanf( %d , a + i); sort(a + 1, a + 1 + n); id = upper_bound(a + 1, a + 1 + n, m) - a; for (int i = 1; i <= n; ++i) sum[i] =...
#include <bits/stdc++.h> using namespace std; class TwoSat { static const int ME = 1000010; static const int MV = 2010; struct G { struct E { int u, v, next; } e[ME]; int le, head[MV]; void init() { le = 0; memset(head, -1, sizeof(head)); } voi...
#include <bits/stdc++.h> using namespace std; using int64 = long long; using ld = double; const int MAXN = 1e5 + 1; vector<int> G[MAXN], comp[MAXN], suf_freq[MAXN]; vector<int64> suf_sum[MAXN]; int comp_cnt, comp_ind[MAXN], p[MAXN], dp1[MAXN], dp2[MAXN], dp[MAXN], diameter[MAXN]; void max_self(int...
#include <bits/stdc++.h> using namespace std; const int N = 300010; const long long inf = 4e18; int n, k, x1[N], var[N], x2[N], y2[N], x[N], y[N]; pair<pair<int, int>, int> px[N], py[N], py1[N]; long long ans; long long solve(pair<pair<int, int>, int> *p, int n, int k, int w) { int j = n - k; long...
#include <bits/stdc++.h> using namespace std; string s; string str[] = { 012345 , 041235 , 034125 , 023415 , 104523 , 120453 , 152043 , 145203 , 215304 , 201534 , 230154 , 253014 }; bool solve(string x, string y) { for (int i = 0; i < 12; i++) { string t1; for (int j...
#include <bits/stdc++.h> using namespace std; int n, t; int dp[22][7][7][12][12]; int main() { cin >> n >> t; if (n <= 2) { cout << 0 << endl; return 0; } for (int i = 1; i <= 4; i++) for (int j = 1; j <= 4; j++) if (i != j) dp[2][i][j][0][0] = 1; for (int i = 2; i ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; map<pair<int, int>, int> rel; vector<int> x, y, color[4]; int pos[N], block[N]; char s[N]; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; ch < 0 || ch > 9 ; ch = getchar()) if (ch == - ) f = -1; ...
#include <bits/stdc++.h> using namespace std; int f(int a, int b) { int ans = 1; for (int i = 0; i < b; i++) ans *= a; return ans; } int main() { int a, b, sgn, n, ans = 1999; scanf( %d %d %d , &a, &b, &n); sgn = (a < 0) ^ (b < 0); a = abs(a); b = abs(b); if (sgn == 1 && n % ...
#include <bits/stdc++.h> using namespace std; int mod; struct EDGE { int to, nxt; } box[101000 * 2]; int h[101000], top, f1[101000], f2[101000]; void add(int u, int v) { box[top].to = v; box[top].nxt = h[u]; h[u] = top++; } int dp[610][610]; int dfs(int a, int b) { if (dp[a][b] + 1...
#include <bits/stdc++.h> using namespace std; vector<int> adj[100], kk; int n, m, c1, c2, vb[100], cc, ff; void dfs(int x) { c1++; vb[x] = 1; c2 += adj[x].size(); for (int u : adj[x]) { if (!vb[u]) dfs(u); } return; } bool cmp(int u, int v) { memset(vb, 0, sizeof(vb)); ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, a = 0; cin >> n >> m; for (int i = 0; i < n; i++) { long long int t = 100000000000; for (int j = 0; j < m; j++) { long long int r; cin >> r; t = min(t, r); } a = max(t, a); ...
#include <bits/stdc++.h> using namespace std; long long x[9999999]; int a = 0, b, c, n; int bbb(int iw, int zw, long long t) { if (t > x[zw] || t < x[iw]) return 0; while (zw >= iw) { int qccc = (iw + zw) >> 1; if (t < x[qccc]) zw = qccc - 1; else if (x[qccc] < t) iw = ...
#include<bits/stdc++.h> using namespace std; namespace program { const int N = 100005; struct edge { int to, nxt; edge() {} edge(int to_, int nxt_): to(to_), nxt(nxt_) {} } e[N << 1]; int hd[N], cnt, fir[N], end[N]; vector<pair<int, int> > del, ins; void adde(int u, int v) {...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; double power(double x, int n) { if (n <= 1) return n ? x : 1; double t = power(x, n / 2); if (n % 2) return t * t * x; else return t * t; } double p[maxn]; int main() { int m, n; scanf( %d%d , &m,...
#include <bits/stdc++.h> using namespace std; pair<int, int> dir[4]; int ans = 0; int n, m; char maz[55][55]; char op[105]; void bfs() { int x, y; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { if (maz[i][j] == S ) { x = i, y = j; } } } ...
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1); const int n_ = 1e5 + 5; int n; long long a[n_], b[n_], dp[n_]; vector<int> st; vector<long double> p; long double getIntersect(int i, int j) { return (dp[j] - dp[i]) / (long double)(b[i] - b[j]); } int main() { sc...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m, flag = 0; cin >> n >> m; long long int a[n][m], b[n][m]; for (long long int(i) = 0; (i) < (n); ++(i)) { for (long long int(j) = 0; (j) < (m); ++(j)) { ...
#include <bits/stdc++.h> using namespace std; char s[100500]; char c[200100]; int l[100100][26], r[100100][26]; int last[26]; int main() { long long res; int tmp; int n, k, ll, l1, i, j; cin >> n >> k; scanf( %s , s); ll = strlen(s); memset(last, -1, sizeof(last)); for (i = 0...
#include <bits/stdc++.h> using namespace std; const int N = 2020; int Arr[N][N]; int Pre[N][N]; int Add[N][N]; bool Col[N]; bool Row[N]; int getSum(int x1, int y1, int x2, int y2) { return Pre[x2][y2] - Pre[x1 - 1][y2] - Pre[x2][y1 - 1] + Pre[x1 - 1][y1 - 1]; } int main() { ios::sync_with_st...
#include <bits/stdc++.h> using namespace std; const int X = 100; char s[X][1000], a[15]; int main() { int i = 0, j = 0, c = 0, x; memset(s, . , sizeof(s)); for (x = 0; x < X; x++) s[x][999] = 0; scanf( %s , a); for (x = 0; a[x]; x++) { for (;;) { if (c == a[x]) { s[+...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.clear(); fflush(stdin); int n; cin >> n; while (n--) { string s; cin >> s; int year = stoi(s.substr(4, s.size() - 4)), p = 1, x = 1989; for (i...
#include <bits/stdc++.h> using namespace std; struct __s { __s() { if (1) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s() { if (!1) fprintf(stderr, Execution time: %.3lf s. n , (double)clock() / CLOCKS_PER_SEC); ...
#include <bits/stdc++.h> char s[1000010]; int max_pos_by_allowed_and_len[1 << 20][21]; constexpr int full = (1 << 20) - 1; template <typename T> void mx(T& x, T y) { x = (x > y ? x : y); } void update(const int* __restrict__ a, int* __restrict__ b) { for (int i = 0; i < 21; i += 7) { mx(b[i ...
#include <bits/stdc++.h> using namespace std; void qSort(long long **a, int first, int last) { long long i = first, j = last, x = a[(first + last) / 2][0]; do { while (a[i][0] < x) i++; while (a[j][0] > x) j--; if (i <= j) { if (i < j) { long long tmp0, tmp1; tm...
#include <bits/stdc++.h> using namespace std; int main() { int x1 = 0, y1 = 0, x2 = 0, y2 = 0; int n = 0; cin >> x1 >> y1 >> x2 >> y2 >> n; int count = 0; for (int i = 0; i < n; ++i) { int a = 0, b = 0, c = 0; cin >> a >> b >> c; int d1 = (a * 1LL * x1 + b * 1LL * y1 + c < 0 ? ...
#include <bits/stdc++.h> using namespace std; #define fr first #define sc second #define pb push_back const int INF = 1e9 + 1; const int mod = 1e9+9; const int base = 1e9; int main() { //freopen( input.txt , r , stdin); ios_base::sync_with_stdio(false); cin.tie(0); cout.ti...
#include <bits/stdc++.h> using namespace std; int N, K; bool good[1050]; int main() { scanf( %d , &N); for (int i = 2; i <= N; i++) { bool isp = true; for (int j = 2; j < i; j++) if (i % j == 0) { isp = false; int x = i; while (x % j == 0) x /= j; ...
#include <bits/stdc++.h> using namespace std; void solve() { long long a, b; cin >> a >> b; if ((a + b) % 3 != 0) { cout << NO << endl; return; } long long mi = min(a, b); long long mx = max(a, b); long long d = mx - mi; if (mx > 2 * mi) { cout << NO << endl; ...
#include <bits/stdc++.h> using namespace std; string t[100000]; char mm[100000]; int check[26]; int ans() { int m = 0, c = 0; for (int i = 0; i < 26; ++i) m = max(m, check[i]); for (int i = 0; i < 26; ++i) { if (check[i] == m) ++c; if (c > 1) return 0; } return 1; } int mai...
#include <bits/stdc++.h> using namespace std; const int inf = 1E7; int a[2][200], u, v, c[200], n; bool check() { for (int i = 0; i <= n; i++) if (c[i] > 1 || c[i] < -1) return 0; return 1; } void dfs(int x) { if (x > n) { cout << n << endl; for (int i = 0; i <= n; i++) printf(...
#include <bits/stdc++.h> using namespace std; int main() { long long n, arr[100], k; set<int> todo; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> arr[i]; k += arr[i]; for (long long x = 1; x * x <= arr[i]; x++) { todo.insert(x); todo.insert(arr[i] / x); ...
#include <bits/stdc++.h> using namespace std; string s[100001]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> s[i]; } long double x = 0; long long ans = 0; for (int i = n; i >= 1; i--) { if (s[i] == halfplus ) { x += 0.5; } ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-8; const int INF = 1E9; const int MAXN = 11111; int n, maxc; int l[MAXN], r[MAXN], b[MAXN]; int _less[MAXN]; int id[MAXN], mx; double ans, dp[11][MAXN], sum[11][MAXN]; double p[11]; int main() { ...
#include <bits/stdc++.h> using namespace std; signed main() { long long n; cin >> n; long long a[n]; long long sum = 0; for (long long i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } long long req = ceil(4.5 * n) - sum; vector<long long> b(n); for (long long i = 0; i...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 4e5 + 47, mod = 1e9 + 7, inf = 1e9 + 7; long long n, m; vector<long long> val; void read() { cin >> n; val.resize(n); for (long long i = 0; i < n; ++i) cin >> val[i]; } vector<long long> fenw(MAXN, 0); void update(long long...
#include <bits/stdc++.h> using namespace std; struct node { int v, w; node() {} node(int V, int W) { v = V; w = W; } }; vector<node> G[105]; int n, m; int dp[105][105][30]; int dfs(int first, int second, int s) { if (dp[first][second][s] != -1) return dp[first][second][s]; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, i, c = 0, b; cin >> n; char name[15]; for (i = 0; i < n; i++) { cin >> name; cin >> b >> a; if (b >= 2400 && a > b) c = 1; } if (c == 1) cout << YES << endl; else cout << NO << endl; ...
#include <bits/stdc++.h> using namespace std; const int N = 1000001; int main() { ios::sync_with_stdio(false); int n; string s; cin >> n >> s; sort(s.begin(), s.end()); cout << s; return 0; }
#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 = 100000; const int MAXCAP = 300000; typedef struct R { int w, c; } R; bool operator<(const R &a, const R &b) { return (long long)a.c * b.w > (long long)b.c *...
#include <bits/stdc++.h> using namespace std; void print(long long a[], int n) { cout << endl; for (int i = 0; i < n; i++) cout << a[i] << ; cout << endl; } const int N = 1111; int db[2][N]; int main() { int n, k, x; scanf( %d%d%d , &n, &k, &x); int minn = 1 << 30; int maxx = ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2222, mod = 998244353; int add(int x, int y) { x += y; return x >= mod ? x - mod : x; } int mul(int x, int y) { return 1ll * x * y % mod; } int qpow(int a, int b) { int ans = 1; while (b) { if (b & 1) ans = mul(ans, a); ...
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> g[100005]; int siz[100005]; bool era[100005]; long long rans; int col[100005]; int calc(int v, int p) { int cnt = 1; for (int i = 0; i < (int)g[v].size(); i++) { int to = g[v][i]; if (to == p || era[to]) continue; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; long long ans = 0; f...
#include <bits/stdc++.h> using namespace std; int tree[4 * 200005], cs[200005], ar[200005]; struct dt { int b, e, h, id, res; } st[100005]; bool cmp1(dt x, dt y) { return x.b < y.b; } bool cmp2(dt x, dt y) { return x.id < y.id; } void update(int nd, int b, int e, int x, int v) { if (b > x || e < x...
#include <bits/stdc++.h> using namespace std; long long modpow(long long a, long long n, long long temp) { long long res = 1, y = a; while (n > 0) { if (n & 1) res = (res * y) % temp; y = (y * y) % temp; n /= 2; } return res % temp; } long long ison(long long mask, long long po...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; struct post { int pos[3]; int st[3]; int mv; }; inline int code(const post& p) { int q = p.mv; for (int _n((3) - 1), i(0); i <= _n; i++) q = q * 44 + p.pos[i]; for (int _n((3) - 1), i(0); i <= _n; ...
#include <bits/stdc++.h> using namespace std; int n, m; char arr[55][55]; int dp[55][55][55][55]; int f(int ind, int let, int dig, int sim) { if (ind == n) { if (let && dig && sim) return 0; else return 1e9; } if (dp[ind][let][dig][sim] != -1) return dp[ind][let][dig][s...
#include <bits/stdc++.h> using namespace std; long long a[500005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, i, j, k, l, m; long long t; cin >> t; long long pret = t; while (t--) { cin >> n >> k; for (i = 1; i <= n; i++) cin >> a[i]; i...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int maxt = (1 << 19) + 20; vector<pair<pair<int, int>, int> > ad[maxn]; vector<pair<pair<int, int>, int> > qs[maxn]; set<pair<int, int> > st; set<pair<int, int> >::iterator it1, it2, it3; int n, q; long long val[maxt], taga...
#include <bits/stdc++.h> using namespace std; const int MAXN = 110000; const double EPS = 1E-7; struct pt { int x, y; }; int n; pt p[MAXN]; int l[MAXN], r[MAXN]; long long r_sums[MAXN]; inline long long vec(pt a, pt b, pt c) { return (b.x - a.x) * 1ll * (c.y - a.y) - (b.y - a.y) * 1ll * (c.x...
#include <bits/stdc++.h> const int maxn = 1e3 + 10; using namespace std; int n, x[110], y[110], cnt1, cnt2, sum1, sum2; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; if (x[i] % 2 == 1) { cnt1++; } if (y[i] % 2 == 1) { cnt2++; } ...
#include <bits/stdc++.h> using namespace std; template <class X, class Y> bool minimize(X &x, const Y &y) { X eps = 1e-9; if (x > y + eps) { x = y; return true; } else return false; } template <class X, class Y> bool maximize(X &x, const Y &y) { X eps = 1e-9; if (x + ep...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long i, j, k, r, c, c1, c2, cnt, ans, x, y, p, t; vector<vector<long long>> v, a, b; unordered_map<long long, set<pair<long long, long long>>> m; vector<long long> re, q; cin ...
#include <bits/stdc++.h> using namespace std; int a[10]; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; string b; cin >> b; for (int i = 0; i < n; i++) { a[b[i] - 0 ] = 1; } bool flag = (((a[1] || a[2] || a[3]) && (a[0])) || ((a[1] || a[2] || a[...
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); } template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); } template <cl...
#include <bits/stdc++.h> using namespace std; bool check(long long x, long long y, long long x1, long long y1) { if (x != 0 && y != 0 && x1 % x == 0 && y1 % y == 0 && x1 / x >= 0 && y1 / y >= 0 && x1 / x == y1 / y) return 1; if (x == 0 && y == 0 && y1 == 0 && x1 == 0) return 1; if (x == 0 ...
#include <iostream> #include <algorithm> #include <vector> #include <cmath> using namespace std; int main() { int t = 0; cin>>t; for(int i = 0; i < t; i++) { int n = 0; cin>>n; int v[100] = {0}; for(int j = 0; j < n; j++) cin>>v[j];...
#include <bits/stdc++.h> template <typename T> inline void read(T &x) { bool b = 0; char c; while (!isdigit(c = getchar()) && c != - ) ; if (c == - ) c = getchar(), b = 1; x = c - 48; while (isdigit(c = getchar())) x = x * 10 + c - 48; if (b) x = -x; } void reads(std ::string...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 7; const long long mod = 998244353; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, s, d; unsigned long long ok[N]; unsigned long long d1[(1 << 20)], d2[(1 << 10)], a[N]; unordered_map<unsigned long long, in...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 20; int n, x, y, a[maxn], o = 0; int main() { cin >> n >> x >> y; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { for (int j = max(0, i + x - 1); j < i; j++) { if (a[j] < a[i]) { o = 1...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return (a.first > b.first); } bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } long long int power(long ...
#include <bits/stdc++.h> using namespace std; const int N = 2e3; int n, h, aa[N + 2], vis[2][N + 1][N + 1][2]; double p, dp[2][N + 1][N + 1][2]; double dfs(int s1, int lo, int hi, int s2) { if (vis[s1][lo][hi][s2]) return dp[s1][lo][hi][s2]; vis[s1][lo][hi][s2] = 1; if (lo > hi) return 0; doub...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int n1, n2, n3 = 0; bool flagm = true, flagr = true; while (n--) { cin >> n1 >> n2; if (n3 < n2 && n3 != 0) flagm = false; if (n1 != n2) flagr = false; n3 = n2; } if (!flagr) cout <<...
#include <bits/stdc++.h> using namespace std; int k[3], t[3]; int n; long long a[100000]; long long was[100000]; int main() { scanf( %d %d %d , &k[0], &k[1], &k[2]); scanf( %d %d %d , &t[0], &t[1], &t[2]); scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %I64d , &a[i]); was[...
#include <bits/stdc++.h> using namespace std; int n, h; int cnt; int main() { cin >> n >> h; for (int e = 0; e < n; e++) { int in; cin >> in; if (in > h) { cnt += 2; } else { cnt++; } } cout << cnt; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = ...
#include <bits/stdc++.h> using namespace std; using LL = long long; using VI = vector<int>; const int inf = 2e9; LL calc(set<int>& st, int L, int R) { VI a; for (int i = L;;) { a.push_back(i); if (i == R) break; if (st.upper_bound(i) != st.end() && *st.upper_bound(i) < R) i =...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 1e6 + 10; const int mod = 998244353; int m, n, k = 0, flag = 0, cnt = 0; int a[N], ans[N]; long long pow2[N]; bool did[N]; int main() { ios::sync_with_stdio(false); cin >> n >> k; ; for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; const int N = 100; int cost[N][2], timee, tmm, num, clr, n; char ha, arr[25]; string tm1, tm2; int main() { scanf( %s , &arr); tm1 = arr; scanf( %s%d , &arr, &n); tm2 = arr; while (n--) { scanf( %d %c%d %c , &timee, &tmm, &num, &clr);...
#include <bits/stdc++.h> using namespace std; set<string> setao; string s; const int N = 10010; int pd[N][4], n; char solve(int k, int last) { if (k == n) return 1; if (n - k == 1 or k > n) return 0; if (pd[k][last] != -1) return pd[k][last]; string ant; for (int i = last; i >= 1; i--) {...
#include <bits/stdc++.h> using namespace std; long long int ara[1000000]; int wow[7 * 22000]; void make_wow(int x) { int xx; int l; int k = 1; stack<int> s; for (int i = 1; i <= x; i++) { xx = i; while (xx != 0) { l = xx % 10; xx /= 10; s.push(l); } ...
#include <bits/stdc++.h> using namespace std; map<long long, vector<long long>> M; bool res[100010]; int main() { long long n; long long k; cin >> n >> k; long long S = 0; for (long long i = 1; i <= n; i++) { long long a; cin >> a; M[a].push_back(i); S += a; } ...
#include <bits/stdc++.h> using namespace std; int indeg[510], vis[510], indeg1[510], vis1[510]; int n, m; vector<vector<int> > adj(510); int check(int x) { int i, c, p; queue<int> q; for (i = 0; i < n; i++) { vis1[i] = vis[i]; indeg1[i] = indeg[i]; } indeg1[x]--; q.push(x);...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } template <typename t1> t1 gcd(t1 a, t1 b) { return b == 0 ? a : gcd(b, a % b); } template <typename t1> t1 lcm(t1 a, t1 b) { return a * (b / gcd(a...
#include <bits/stdc++.h> using namespace std; mt19937 dadi(chrono::high_resolution_clock::now().time_since_epoch().count()); const int N = 100 + 5, K = 1e3 + 5; int n, m, k, w[N], p[K], cnt[N][K]; struct game { int u, v, t; } a[K]; inline int add(int u, int v) { shuffle(p, p + k, dadi); int mx...
#include <bits/stdc++.h> using namespace std; int k, m = 1e9, a, b, n, i; int main() { scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d%d , &a, &b); m = min(m, b); k += m * a; } printf( %d n , k); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i=a; i<=b; i++) #define repd(i, a, b) for(int i=a; i>=b; i--) #define vi vector<int> #define vll vector<long long> #define pii pair<int,int> #define pll pair<long long,long long> #define pb push_back #define fr first #define ...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long a[1000005], b[1000005]; long long nine[100], t[100]; int main() { int n, k; t[0] = 1LL; for (int i = (1); i <= (10); i++) t[i] = (t[i - 1] * 10LL) % mod; nine[1] = 9LL; for (int i = (2); i <= (10); i++) nine[i...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, x1, y1, x2, y2, j, k, sum = 0; int a[101][101]; memset(a, 0, sizeof(a)); scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d%d%d%d , &x1, &y1, &x2, &y2); for (k = x1; k <= x2; k++) for (j = y1; j <= y2; j++...
#include <bits/stdc++.h> using namespace std; int spend(int x) { int b, total, cash_back, left; cash_back = x / 10; b = cash_back * 10; left = x - b + cash_back; if (cash_back < 1) { return left; } return b + spend(left); } int main() { int testcase; cin >> testcase; ...
#include <bits/stdc++.h> using namespace std; long long n, q; string s; int main() { cin >> n >> q; while (q--) { vector<pair<long long, long long> > v; long long x, l = 1, r = n, cur = n / 2 + 1; cin >> x >> s; while (cur != x) { v.push_back({l, r}); if (x < cur)...
#include <bits/stdc++.h> using namespace std; void solve(void); int main() { { ios_base::sync_with_stdio(false); cin.tie(NULL); { solve(); } } return 0; } void solve() { long long int n, i; cin >> n; vector<long long int> v; for (i = 1; i * i <= n; i++) { if...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2, typename T3> T2 x_pow_y(T1 x, T3 y, T2 mod) { T2 ans = 1; long long a = x % mod; while (y) { if (y & 1) ans = (ans * a) % mod; a = (a * a) % mod; y >>= 1; } return ans; } template <typename ...
#include <bits/stdc++.h> using namespace std; enum { UP, DOWN, LEFT, RIGHT }; const int MAX = 15500; struct Node { int dir; Node* pt[4]; } node[MAX], *cur, *row[MAX], *col[MAX], *st[MAX]; char s[MAX]; int r, c, top; int getDir(char c) { switch (c) { case U : return UP; c...
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, ans = 1, val[256], v; string s, p; cin >> s; char a; for (a = 0 ; a <= 9 ; a++) { p.push_back(a); } for (a = A ; a <= Z ; a++) { p.push_back(a); } for (a = a ; a <= z ; a++) { p...
#include <bits/stdc++.h> using namespace std; void readi(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) f = -1; else v = v * 10 + c - 0 ; while (isdigit(c = getchar())) v = v * 10 + c - 0 ; x = v * f; } void ...
#include <bits/stdc++.h> using namespace std; using ii = pair<int, int>; int z[][2] = {{-1, 0}, {1, 0}}; vector<ii> solve(int x, int y) { if (x < y) swap(x, y); vector<ii> a; x -= y - 1; for (int k = 0; k < 2 * y - 1; ++k) { a.push_back({2, 3 + k}); if (~k & 1) for (int j = 0...
#include <bits/stdc++.h> using namespace std; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } signed main() { ci...
#include <bits/stdc++.h> int main() { int ans = 1, n, mod = 1000003; scanf( %d , &n); for (int i = 0; i < n - 1; i++) { ans *= 3; ans %= mod; } printf( %d n , ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0; string s; cin >> n >> s; for (int i = 0; i < n; i++) sum += s[i] - 0 ; for (int i = 2; i <= n; i++) { if (sum % i == 0) { int cur = 0; bool flag = 1; for (int j = 0; j < n; j++) { ...
#include <bits/stdc++.h> using namespace std; int n, x; long long f[200010]; vector<pair<int, long long> > ke[200010]; struct te { int l, r; long long s; } a[200010]; bool cmp(te i, te j) { return ((i.l < j.l) || (i.l == j.l && i.r < j.r)); } int main() { if (fopen( a.txt , r )) { fre...
#include <bits/stdc++.h> using namespace std; constexpr long double m_pi = 3.1415926535897932L; constexpr long long MOD = 1000000007; constexpr long long INF = 1LL << 61; constexpr long double EPS = 1e-10; template <typename T> using vector2 = vector<vector<T>>; template <typename T> using vector3 = v...
#include <bits/stdc++.h> using namespace std; void fastio() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed; } int main() { fastio(); int n; cin >> n; long long int a[n]; long long int totsum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using i3 = pair<int, ii>; using li = pair<ll, int>; using lii = pair<ll, ii>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vii = vector<ii>; using vli = vector<li>; us...
#include <bits/stdc++.h> const int maxn = 2e5 + 50; using namespace std; int n; long long a[maxn], dp[maxn], he[maxn]; vector<int> maps[maxn]; void dfs(int u, int fa) { he[u] = 0; for (int i = 0, len = maps[u].size(); i < len; i++) { int v = maps[u][i]; if (v != fa) { dfs(v, u); ...