func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; long long nod(long long a, long long b) { while (a != 0 && b != 0) { if (a > b) a %= b; else b %= a; } return a + b; } int main() { long long n, a[100]; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const long long M = (long long)1e9 + 7; int Int() { int x; scanf( %d , &x); return x; } long long Long() { long long x; scanf( %lld , &x); return x; } void Char(char *ch) { scanf( %s , ch); } template <typenam...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; std::cin >> n >> m; getchar(); int a[n][m], nums[m]; for (int i = 0; i < m; i++) { nums[i] = 0; } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[i][j] = getchar() - 0 ; nums[j...
#include <bits/stdc++.h> using namespace std; struct point { long double x, y, s; point() {} point(int xx, int yy, point o) { x = (long double)xx, y = (long double)yy; s = atan2(y - o.y, x - o.x); } } o, p; bool operator<(point _1, point _2) { if (_1.s == _2.s) { return _1....
#include <bits/stdc++.h> using namespace std; int main() { double n, l, v1, v2, k; cin >> n >> l >> v1 >> v2 >> k; double m = ceil(n / k); double ans = l * v2 / (v1 * v2 - v2 * (v1 * v1 - v2 * v2) / (v1 + (2 * m - 1) * v2)); cout << fixed << setprecision(10) << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int ar[5000009]; long long j; int finder(vector<pair<long long, long long> > v, long long jump) { for (int i = 0; i < v.size(); i++) { if (v[i].first > jump) { return i; } } return v.size(); } long long count = 0; vector<pair<lo...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int f[1 << 6], ff[1 << 6], g[1 << 6], gg[1 << 6]; int b[N]; char s[N], w[100]; int n, m; bool check() { for (int i = 1; i < (1 << 6); i++) gg[i] = gg[i - (i & -i)] + g[i & -i]; for (int i = 1; i < (1 << 6) - 1; i++) if (gg...
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y) { long long int res = 1; x = x; while (y > 0) { if (y & 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } long long int logtwo(long long int n) { if (n == 1) r...
#include <bits/stdc++.h> using namespace std; int st[200011], disc = 0, mod, en[200011]; vector<int> adj[200011]; bitset<1003> m[1000011]; int flag[1000011], a[200011]; int p[2011], arr[200011]; vector<int> pr; bitset<1003> def; void dfs(int u, int p) { st[u] = disc; arr[disc] = u; disc++;...
#include <bits/stdc++.h> using namespace std; int main() { int z, n, m; while (cin >> n >> m) { if (m > n) z = -1; else { if (n % 2 == 0) z = n / 2; else z = (n / 2) + 1; while (z % m != 0) { z++; } } cout << z; ...
#include <bits/stdc++.h> using namespace std; int gcd(int p, int q) { return q == 0 ? p : gcd(q, p % q); } char s[100100]; long long res[2][2]; int main() { cin >> s; int len = strlen(s); memset(res, 0, sizeof(res)); long long a = 0, b = 0; for (int i = 0; i < len; i++) { int temp = ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m; cin >> n >> m; long long int a[m]; for (int i = 0; i < m; i++) { cin >> a[i]; } sort(a, a + m); int i = 0; while (i < m - 2) { if (a[i] + 1 == a[i + 1] && a[i + 1] + 1 == a[i + 2]) { co...
#include <bits/stdc++.h> using namespace std; const long double lim = 1e99; template <typename T> inline T read() { register T sum = 0; register char cc = getchar(); int sym = 1; while (cc != - && (cc > 9 || cc < 0 )) cc = getchar(); if (cc == - ) sym = -1, cc = getchar(); sum = su...
#include <bits/stdc++.h> using namespace std; const int Max_N(1050); int N; double P[Max_N][Max_N], F[Max_N], G[Max_N], V[Max_N]; bool done[Max_N]; int main() { scanf( %d , &N); for (int i = 1; i <= N; ++i) { V[i] = 1.0; for (int j = 1; j <= N; ++j) scanf( %lf , P[i] + j), P[i][j] /= 100...
#include <bits/stdc++.h> using namespace std; constexpr int MAX_N = 200000; int N, M, S, D; int X[MAX_N + 10]; int DP[MAX_N + 1] = {0}; stack<string> OPS; void run(int x) { if (x == 0) return; std::ostringstream os; os << RUN << x; OPS.push(os.str()); } void jump(int x) { assert...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long mpow(long long x, long long y) { if (y == 0) return 1; if (y % 2) return x * mpow(x, y - 1) % MOD; long long h = mpow(x, y / 2); return h * h % MOD; } long long arr[111111]; int main() { int k; sca...
#include <bits/stdc++.h> using namespace std; long long solve() { long long m, n, i, j; string a, b; cin >> m >> n >> a >> b; long long t[m + 1][n + 1]; memset(t, 0, sizeof(t)); long long sol = 0; for (i = 1; i <= m; i++) for (j = 1; j <= n; j++) { if (a[i - 1] == b[j - 1])...
#include <bits/stdc++.h> using namespace std; int read() { int nm = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()) nm = nm * 10 + c - 0 ; return nm * f; } long long cup[10001], flow[10001], to[10001], head[10001...
#include <bits/stdc++.h> using namespace std; const int N = 2036000; const long long INF = 199999999999LL; int n, m; long long a[N], b[N]; long long first, second, mod; long long w[N], t[N]; int nn; void AddA(int &i) { w[nn] = a[i++]; t[nn++] = 1; } void AddB(int &j) { w[nn] = b[j++]; ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; const int inf = 1e9 + 1; const long long OO = 1e18; long long p1, p2, c1, c2, w1, w2; long long solve() { long long a2, b1, b3, ans = 0; for (int i = 0; i <= min(p1 / w1, c1); i++) { long long a2 = min((p1 - i * w1) / w2, c...
#include <bits/stdc++.h> using namespace std; int main() { int n, lam, mx = 0, c = 0; cin >> n; vector<int> cand(n); for (int i = 0; i < n; i++) { cin >> cand[i]; if (mx < cand[i]) mx = cand[i]; } for (int i = 0; i < n; i++) if (mx == cand[i]) c++; int x = lam = cand[0]...
#include <bits/stdc++.h> using namespace std; int64_t *arry[3]; int main(void) { int64_t n, p, q, r; cin >> n >> p >> q >> r; for (int i = 0; i < 3; i++) { arry[i] = (int64_t *)malloc(sizeof(int64_t) * n); } for (int i = 0; i < n; i++) { int buf; cin >> buf; arry[0][i] ...
#include <bits/stdc++.h> int main() { int n, w = 0, k = 1, i = 0, t = 0; scanf( %d , &n); int a[n]; for (i = 0; i < n; i++) { scanf( %d , &a[i]); if (a[i] > t) t = a[i]; } for (i = 0; i < n; i++) { if ((a[i] == t) && (a[i + 1] == t)) k++; else if ((a[i] == t) &&...
#include <bits/stdc++.h> using namespace std; long long int func(long long int n) { long long int res = 0; while (n != 0) { n /= 10; res++; } return res; } int main() { long long int w, m, k; cin >> w >> m >> k; long long int n = func(m), tr = w / k, res = 0; while (t...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimization( O3 ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( avx,avx2,fma ) using namespace std; int main() { long double r, x1, y1, x2, y2; cin >> r >> x1 >> y1 >> x2 >> y2; long double x = sqrt((y1 - y2) * (y1 - ...
#include <bits/stdc++.h> using namespace std; void Rd(int &x) { static char c; x = 0; while ((c = getchar()) < 48) ; do x = (x << 3) + (x << 1) + (c ^ 48); while ((c = getchar()) > 47); } int n; int Next[200004 << 1], V[200004 << 1], W[200004], Head[200004], tot; void Add_Edge(int ...
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 998244353; #define rep(i,a,b) for(ll i=a;i<b;++i) #define pii pair<int,int> int main() { ios_base::sync_with_stdio(0); cin.tie(0); int tt=1; cin>>tt; while(tt--) { int n; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a[120], i, j, res; while (scanf( %d %d , &n, &m) == 2) { for (i = 1; i <= n; i++) { scanf( %d , &a[i]); } bool flag = true; int k = 0; while (flag) { for (i = 1; i <= n; i++) { if (a[...
#include <bits/stdc++.h> using namespace std; int main() { long long n; double r, v, si, fi; cin >> n >> r >> v; for (int i = 0; i < n; i++) { cin >> si >> fi; double dist = fi - si; double cir = 2 * 3.14159265358979323846 * r; double rev = dist / cir; rev = floor(rev);...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int n, Q, x; int fa[N], fv[N]; vector<int> c[N]; struct nod { int i, l, r; } b; vector<nod> a[N]; int pl, pr; long long px; long long t[N * 4], lz[N * 4]; void down(int i) { if (lz[i]) { t[i + i] += lz[i]; l...
#include <bits/stdc++.h> using namespace std; int main() { int NWarm, NChip; cin >> NWarm >> NChip; int temp = NWarm * (NWarm + 1) / 2; int ans = NChip % temp; int i; for (i = 1; i <= temp; i++) { ans = ans - i; if (ans < 0) break; } int ans1 = ans + i; cout << ans1 <...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> start(m); vector<int> ending(m); vector<int> time(m); vector<int> prize(m); int money = 0; for (int i = 0; i < m; i++) { cin >> start[i] >> ending[i] >> time[i] >> prize[i]; } ...
#include <bits/stdc++.h> using namespace std; const int Maxn = 200005; const int Maxd = 10; int bits[1 << Maxd]; int t; char str[Maxn]; int slen; int main() { for (int i = 1; i < 1 << Maxd; i++) bits[i] = 1 + bits[i - (i & -i)]; scanf( %d , &t); while (t--) { scanf( %s , str); sl...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int n; vector<int> v, lm, rm; class SegmentTreeMax { public: int n; vector<long long> vect; SegmentTreeMax(int _n) : n(_n) { vect.resize(2 * n); fill(vect.begin(), vect.end(), 0); } void modify(int p, lon...
#include <bits/stdc++.h> using namespace std; template <typename T> bool get_int(T &x) { char t = getchar(); bool neg = false; x = 0; for (; (t > 9 || t < 0 ) && t != - && t != EOF; t = getchar()) ; if (t == - ) neg = true, t = getchar(); if (t == EOF) return false; for (; ...
#include <bits/stdc++.h> using namespace std; int N, M; int A[104][104], B[104][104]; int main() { scanf( %d %d , &N, &M); for (int i = 1; i <= N; ++i) for (int j = 1; j <= M; ++j) { char c; scanf( %c , &c); if (c == * ) A[i][j] = 1; } int cnt = 0; for (int ...
#include <bits/stdc++.h> using namespace std; int main() { long long int k, n, w, t; cin >> k >> n >> w >> t; t = (w * (w + 1) / 2) * k; t = t - n; if (t < 0) cout << 0 ; else cout << t; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b; scanf( %d%d , &a, &b); if (b > a) printf( -1 n ); else { double ans, a1, a2; a1 = (a + b) / (2.0 * ((a + b) / (2 * b))); a2 = (a - b) / (2.0 * ((a - b) / (2 * b))); printf( %.12lf n , min(a1, a2)); ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[201]; for (int i = 1; i <= n; ++i) cin >> arr[i]; int brr[201] = {0}, count = 0; for (int i = 1; i <= n; ++i) { if (i == 1 && n >= 2) { if (arr[1] == 1 && arr[2] == 2) brr[i] = 1; } else {...
#include <bits/stdc++.h> using namespace std; double esp = 1e-11; const double PI = acos(-1.0); const long long int INF = 0x3f3f3f3f; const long long int MOD = 1e9 + 7; const int maxn = 200010; int main() { int a, b, c; scanf( %d%d%d , &a, &b, &c); long double x = (-b + sqrt((long double)b * b...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int NMAX = 300010; const double E = 1e-8; const double PI = acos(-1); int n, m, stest; int d; set<long long> St; long long st[NMAX], h[NMAX]; pair<int, int> Tree[4 * NMAX]; int dp[NMAX], trace[NMAX]; pair<int, int> c...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MXN = 3e5 + 5; const int MOD = 998244353; const int LOG = 19; int add(int x, int y) { return (x += y) < MOD ? x : x - MOD; } int sub(int x, int y) { return (x -= y) >= 00 ? x : x + MOD; } int mul(int x, int y) { return (ll)x *...
#include <bits/stdc++.h> using namespace std; int l[100000 + 9], r[100000 + 9]; int n, p; int main() { cin >> n >> p; for (int i = 0; i < n; i++) { cin >> l[i] >> r[i]; } double ans = 0; for (int i = 0; i < n; i++) { int j = (i + 1) % n; int div1 = r[i] / p - (l[i] - 1) / p...
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr); string s, t; cin >> s >> t; int ns = s.size() - 1; int nt = t.size() - 1; bool stop = true; while (stop && (ns >= 0 && nt >= 0)) { if (s[ns] != t[nt])...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long inf64 = 1e18; const int mod = inf + 7; inline int _sum(int a, int b) { return a + b < mod ? a + b : a + b - mod; } inline int _mul(int a, int b) { return (1ll * a * b) % mod; } inline int _sub(int a, int b) { return a >= b ...
#include <bits/stdc++.h> using namespace std; const long long maxm = 3e5 + 5; const long long mod = 998244353; long long fac[maxm], inv[maxm]; long long l[maxm], r[maxm]; pair<long long, long long> p[25]; long long sum[maxm][45]; long long num[maxm]; long long n, m; long long ppow(long long a, long ...
#include <bits/stdc++.h> using namespace std; const int N = 5, R = 1e4; int n, l[N], r[N]; long long cnt[R + 1]; double all; bool used[N]; long long f(int cur, int c, int mn, int x = N) { if (cur == n) { if (mn > 0) { return 0; } long long cnt = 1; for (int i = 0; i < n...
#include <bits/stdc++.h> using namespace std; int i, n, k, x, ans, c; pair<int, int> a[100005]; int main() { cin >> n >> k; for (i = 0; i < n; i++) { cin >> x; a[i].first = 10 - x % 10; a[i].second = x; } sort(a, a + n); for (i = 0; i < n; i++) { if (a[i].second < 100...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, h; cin >> n >> m >> h; int f[m]; int l[n]; int t[n][m]; int ans[n][m]; for (int i = 0; i < m; i++) cin >> f[i]; for (int i = 0; i < n; i++) cin >> l[i]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, now, t, mx, gcd, m, a[107]; scanf( %d , &n); for (i = 0; i ^ n; i++) { scanf( %d , a + i); } sort(a, a + n); mx = gcd = a[0]; m = 1; for (i = 1; i ^ n; i++) { if (a[i - 1] != a[i]) { mx = mx < a[...
#include <bits/stdc++.h> using namespace std; int a[100009]; int b[100009]; int main() { int n; cin >> n; map<int, int> mp; for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } for (int j = 0; j < n; j++) { cin >> b[j]; mp[b[j]]++; } int c = 0; for...
#include <bits/stdc++.h> using namespace std; signed main() { int n; cin >> n; int ar[n]; for (int i = 0; i < n; i++) cin >> ar[i]; int max_n = pow(2, n); bool ans = false; for (int i = 0; i < max_n; i++) { int temp = i; int val = 0; for (int j = 0; j < n; j++) { ...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int INF = 0x3f3f3f3f; const int GRAPH_SIZE = 20010; int pin[GRAPH_SIZE], dep[GRAPH_SIZE], s = 0, t = GRAPH_SIZE - 1; struct EDGE { int u, v, c; }; vector<EDGE> e; vector<int> each[GRAPH_SIZE]; bool bfs() { queue<int>...
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, j, x1, x2, y1, y2; cin >> n; vector<string> a(n); for (i = 0; i < n; i++) cin >> a[i]; x1 = 0; y1 = 0; while (a[x1][y1] == 0 && (x1 <= n - 1 || y1 < n - 1)) if (y1 == n - 1) { y1 = 0; x1++;...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int tt = 1; cin >> tt; for (int tc = 1; tc <= tt; tc++) { int a; cin >> a; if (360 % (180 - a)) cout << NO n ; else cout << YE...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long dp[57 + 7][57 + 7]; long long mdp[57 + 7][57 + 7]; bool vis[57 + 7][57 + 7]; int n, K; long long ncr[57 + 7][57 + 7]; int L, R; long long func(int l, int r, int i, int j, int k, int m) { long long ret = (ncr[...
#include <bits/stdc++.h> using namespace std; const int maxn = 410, MOD = 10007; char s[maxn]; int n, m, mat_s; typedef long long Mat[maxn][maxn]; void print(Mat A) { for (int i = 0; i < (mat_s); i++) { for (int j = 0; j < (mat_s); j++) { cout << A[i][j] << ; } cout << endl;...
#include <bits/stdc++.h> using namespace std; bool cmp(pair<long long int, long long int> pa1, pair<long long int, long long int> pa2) { return pa1.second < pa2.second; } int main() { long long int n, k, i, mn, cnt; cin >> n >> k; long long int a[5001]; for (i = 0; i < n; i++) cin...
#include <bits/stdc++.h> using namespace std; int f[150000]; int find(int x) { if (x == f[x]) return f[x]; else { return f[x] = find(f[x]); } } int a[150000]; int num[150000]; int main() { ios::sync_with_stdio(false); int n, m; while (cin >> n >> m) { memset(a, 0,...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; struct node { int tim, a, b, id; bool operator<(const node& aa) const { return tim < aa.tim; } } a[N]; deque<node> s[5], rt[5]; int vis[N]; vector<int> ad, de; int main() { int n, m, k; scanf( %d%d%d , &n, &m, &k); ...
#include <bits/stdc++.h> using namespace std; int n, c, a[100005], sign[100005]; bool sign_ch[100005]; int main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; sign[n] = 1; c = a[n]; for (int i = n - 1; i >= 1; i--) { if (c >= a[i]) { c -= a[i]; sign[i] = -1; ...
#include <bits/stdc++.h> using namespace std; int n, r[1010], c[1010], rc[1010], rr[1010], tr[1010], tc[1010], rtc[1010], rtr[1010]; class portal { public: int ix, iy, ox, oy; }; vector<portal> ans; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &r[i]); ...
#include <bits/stdc++.h> using namespace std; vector<int> row, col, A; vector<pair<pair<int, int>, int> > mat; int grid[111][111]; void shift_up(int c, int n, int m) { int i, temp; temp = grid[n][c]; for (i = n; i > 1; i--) grid[i][c] = grid[i - 1][c]; grid[1][c] = temp; } void shift_left(...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; if (n == 3) { cout << >vv << endl << ^<. << endl << ^.< << endl; cout << 1 << << 3; } if (n == 5) { cout << >...v << endl << v.<.. << endl << ..^.. << endl ...
#include <bits/stdc++.h> using namespace std; struct sir { int val, ind; }; sir sv[200005]; int n, m, k, v[200005], part[200005], t = 0; long long sum = 0; bool B[200005]; bool comp(sir X, sir Y) { return X.val > Y.val; } int main() { cin >> n >> m >> k; for (int i = 1; i <= n; ++i) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; ++i) { for (int x = 0; x < n; ++x) if (i == x) cout << k << ; else cout << 0 << ; cout << endl; } }
#include <bits/stdc++.h> using namespace std; long long h[100000]; int main() { int n; cin >> n; for (int j = 0; j < n; ++j) { cin >> h[j]; } long long max = h[n - 1]; long long answer[100000]; answer[n - 1] = 0; for (int i = n - 2; i >= 0; --i) { if (h[i] > max) { ...
#include <bits/stdc++.h> using namespace std; int n, m; vector<pair<int, int>> parent[1000001], hv[1000001], vv[1000001]; vector<vector<pair<int, int>>> edges[1000001]; vector<int> vals[1000001], done[1000001]; pair<int, int> get(pair<int, int> x) { pair<int, int> k = parent[x.first][x.second]; if (...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 1e6 + 10; string s[101]; string x; long long dp[101]; long long n; int m; int fail[N]; struct matrix { long long v[4][4]; matrix() { for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n; cin >> n; long long int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; long long int pre = 0; int counter = 0; while (counter < n && arr[coun...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using iii = tuple<int, int, int>; using vi = vector<int>; int main(void) { ios::sync_with_stdio(false), cin.tie(NULL); int n; cin >> n; vector<iii> a(n); int maxr = 0, i = 0; for (auto &[r,...
#include <bits/stdc++.h> using namespace std; int main() { size_t n, w, m; ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr), cin >> n >> w >> m; struct bottle_t { size_t amount, id; } bottle, poured; stack<bottle_t> bottles, non_empty; vector<bottle_t> cup[...
#include <bits/stdc++.h> using namespace std; int min(int s, int t) { if (s <= t) return s; return t; } int max(int s, int t) { if (s >= t) return s; return t; } int main(void) { int cases; int n, s, t, m, k; cin >> cases; while (cases--) { cin >> n >> s >> t; m =...
#include <bits/stdc++.h> using namespace std; int main() { int x; int a[2] = {0}; char c; while (scanf( %c , &c) != -1) { a[c - x ]++; } if (a[0] > a[1]) { x = a[0] - a[1]; for (int i = 0; i < x; i++) { printf( %c , x ); } printf( n ); } else { ...
#include <bits/stdc++.h> using namespace std; bool comp(int x, int y) { return x > y; } bool myComp(pair<int, int> x, pair<int, int> y) { if (x.first < y.first) return true; if (x.first > y.first) return false; return x.second > y.second; } int lucky[] = {4, 7, 44, 47, 74, 77, 444, 447, 474, 477, ...
#include <bits/stdc++.h> using namespace std; int main() { int it; int TUX; cin >> TUX; int FOO = 0, BAR = 0, BAZ = 0, QUZ = 1; for (int i = TUX; i != 0; i--) { int PUR; cin >> PUR; FOO += PUR; BAR++; it = ((max((FOO * QUZ), (BAR * BAZ))) == (FOO * QUZ)); if (...
#include <bits/stdc++.h> using namespace std; bool areParanthesisBalanced(string expr) { stack<char> s; char x; for (int i = 0; i < expr.length(); i++) { if (expr[i] == ( || expr[i] == [ || expr[i] == { ) { s.push(expr[i]); continue; } if (s.empty()) return false; ...
#include <bits/stdc++.h> int main() { int n, i, j, k = 0, z, x; scanf( %d , &n); for (i = 1; i < n; i++) { for (j = i; j < n; j++) { z = i * i + j * j; x = sqrt(z); if (x * x == z && x <= n) { k++; } } } printf( %d , k); return 0; }
#include <bits/stdc++.h> const int MAXN = 200005; int n, m, tot, a[MAXN], b[MAXN], pa[MAXN], pb[MAXN], tr[MAXN], ans[MAXN * 10]; bool tag[MAXN * 10], used[MAXN * 10]; template <typename T> inline void read(T &x) { int fl = 0, ch; while (ch = getchar(), ch < 48 || 57 < ch) fl ^= !(ch ^ 45); x = (ch...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000100; const long long MOD = 1e9 + 7; int N, M; string P; int y[MAXN], fail[MAXN]; bool good[MAXN]; int main() { ios_base::sync_with_stdio(0); cin >> N >> M >> P; for (int i = 0; i < M; i++) { cin >> y[i]; y[i]--; ...
#include <bits/stdc++.h> using namespace std; const int N = 100100; pair<long double, long double> a[N]; int n; bool f(long double mid) { long double l[n], r[n]; multiset<pair<long double, int>> xex; for (int i = 0; i < n; i++) { l[i] = 1.0 * a[i].first - a[i].second * mid; xex.insert(...
#include <bits/stdc++.h> using namespace std; int a[15]; inline int read() { char ch = getchar(); int x = 0, f = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) x = x * 10 + (ch ^ 48), ch = getchar(); return x * f; } ...
#include <bits/stdc++.h> using namespace std; int n; int a[200007]; void input() { scanf( %d , &n); int i; for (i = 1; i <= n; i++) { scanf( %d , &a[i]); } } void solve() { int i; for (i = 1; i <= n; i++) { if ((a[i] % 2) == 1) { if (i != n && (a[i + 1] != 0)) { ...
#include <bits/stdc++.h> using namespace std; char s[10010]; int main() { int n; cin >> n; while (n--) { string a; cin >> a; for (int i = 0; i < a.size(); i++) { s[i] = a[i]; } sort(s, s + a.size()); if (s[0] == s[a.size() - 1]) { cout << -1 << endl;...
#include <bits/stdc++.h> using namespace std; const int mara = (int)(1e6) + 5; vector<long long> a(mara), prime(mara), v(mara), luck; map<long long, bool> flag; long long bigmod(long long a, long long b, long long m) { long long res = 1; while (b) { if (b & 1) { res = (res * a) % m; ...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); n& n - 1 ? printf( NO ) : printf( YES ); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; vector<pair<long long, int> > c(n); vector<int> ans(n); for (int i = 0; i < n; ++i) { cin >> c[i].first; c[i].second = i; } set<pair<long long, int> > av;...
#include <bits/stdc++.h> using namespace std; const int maxn = 2005, maxv = 4e6 + 5; long long a, b, c, X1, X2, Y1, Y2; pair<long double, long double> va[6], vb[6]; void exgcd(long long a, long long b, long long &x, long long &y) { if (!b) { x = 1, y = 0; return; } exgcd(b, a % b, y, x...
#include <bits/stdc++.h> using namespace std; vector<int> edges[100006]; int given[100006] = {0}; int dfs(int i, int c) { if (given[i] != 0) { if ((given[i] == 1 && c == 2) || (given[i] == 2 && c == 1)) return 0; } if (edges[i].size() != 0) given[i] = c; int fl = 1; for (int j = 0; j <...
#include <bits/stdc++.h> using namespace std; struct Widget { string type, name; vector<Widget *> childs; long long h, w, s, b; Widget(string _name = , string _type = , long long _h = -1, long long _w = -1) { h = _h, w = _w; type = _type; name = _name; s = 0; ...
#include <bits/stdc++.h> using namespace std; int n, m, a[1000], l[1000], r[1000], mn, mx, ans, mx2, mn2, ansi = -1, ans2; string s; int main() { ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; if (i == 0) mn = a[i], mx = ...
#include <bits/stdc++.h> using namespace std; int main() { int n; int ans = 0; cin >> n; string arr[11] = { ABSINTH , BEER , BRANDY , CHAMPAGNE , GIN , RUM , SAKE , TEQUILA , VODKA , WHISKEY , WINE }; for (int i = 0; i < n; i++) { string a; ci...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int MOD = 1e9 + 7; const int N = 1e5 + 10; int n, p[N], h[N]; vector<int> g[N]; vector<pair<int, int> > ans; void build(int x, int y) { int m1 = g[x].size(); if (x == y) { for (auto i = 0; i < m1 - 1; i++) ans...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int pen = 0; for (int i = 0; i < n; i++) { if (pen) { if (a[i]) a[i]--; else { cout << NO ; return 0; ...
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __prin...
#include <bits/stdc++.h> using namespace std; long long calc(int n, int k) { int c = n / k; long long ans = c; ans += (long long)(n - k) * c / 2; return ans; } int main() { int n; cin >> n; vector<long long> a; for (int i = 1; i * i <= n; i++) if (n % i == 0) { a.pu...
#include <bits/stdc++.h> using namespace std; vector<pair<long long int, long long int> > dis(100005), edge; long long int cnt[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t = 0, n, e, x, y, z, i, j, k, g, q, ans = 0, sum = 0, c = 0, h; cin >> n >> t; ...
#include <bits/stdc++.h> using namespace std; int main(void) { int n, max = 0; string a[100]; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { int count = 0; for (int j = 0; j < n; j++) { if (i != j) { if (a[i].compare(a[j]) == 0) cou...
#include <bits/stdc++.h> using namespace std; int n, m, as = 0; template <class T> void read(T &x) { char ch; bool ok; for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == - ) ok = 1; for (x = 0; isdigit(ch); x = x * 10 + ch - 0 , ch = getchar()) ; if (ok) x = -...
/****************************** * * * author : rion_cse * * created: 11.07.2021 * * * ******************************/ /******************************************************* * ...