func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int oo = 0x3f3f3f3f; const int maxn = 100000, maxlog = 12;...
#include <bits/stdc++.h> using namespace std; int main() { long s, n; cin >> n >> s; if (n >= s) cout << 1 n ; else { int div = s / n; (s % n == 0) ? cout << div << endl : cout << (div + 1) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; const int mod = 1e7 + 9; const int oo = (1 << 31) - 1; template <class T> inline void readInt(T &n) { n = 0; T ch = getchar(); int sign = 1; while (ch < 0 || ch > 9 ) { if (ch == ...
#include <bits/stdc++.h> namespace fdd { int n, m1, m2; std::priority_queue<int> q[1010]; std::vector<int> v1, v2; void solve() { std::cin >> n; for (int i = 3; i < n; i++) { scanf( %d%d , &m1, &m2); if (m1 > m2) std::swap(m1, m2); q[m1].push(m2); } for (int i = 2; i <= n; i+...
#include <bits/stdc++.h> #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native ) #pragma GCC optimize( Ofast,O3,unroll-loops ) using namespace std; struct cplx { long double a, b; cplx(long double a = 0, long double b = 0) : a(a), b(b) {} const cplx operator+(c...
#include <bits/stdc++.h> using namespace std; long long ans[60]; int main() { long long t, a, n, m, b, v, xmin, xmax, act, sum, i, vmi; cin >> t; while (t--) { cin >> a >> b >> m; if (a == b) { cout << 1 << a << n ; continue; } for (n = 2; n <= 50; n++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 110; int n, m, k, ans, a; vector<int> adj[N], lan[N]; bool mark[N]; void input() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> k; if (k == 0) a++; while (k--) { int v; cin >> v; lan[v].push...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:167177216 ) using namespace std; const int MAXN = 9; int main() { long long n, A; scanf( %I64d %I64d , &n, &A); long long sum = 0; vector<int> d(n); for (int i = 0; i < n; i++) { scanf( %d , &d[i]); sum += d[i]; } f...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double EPS = 1e-6; const int MOD = 1e9 + 7; const int MAXN = 110; const double PI = acos(-1.0); int ipt[MAXN][MAXN]; int main() { int n, m, k; while (~scanf( %d%d%d , &n, &m, &k)) { int ans = INF, all = 1 << m;...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int t, n; int cnt, num, maxx; int a[maxn]; int vis[maxn]; int m1[maxn]; int m2[maxn]; void init() { num = 0; maxx = 0; memset(vis, 0, sizeof(vis)); } int main() { scanf( %d , &t); while (t--) { cnt =...
#include <bits/stdc++.h> using namespace std; const int N = 100, M = 10000; int n, m, a[N + 9], ca; double x, ans; void into() { scanf( %d%lf , &n, &x); int p = 0; for (int i = 1; i <= n; ++i) { int t; scanf( %d , &t); t << 1 <= x ? ans += t : m += a[++ca] = t; } x /= 2; ...
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 30); const int MAXN = 100000; struct node { int le, ri; set<int> Set; int mx, mn; } tree[24 * MAXN + 5]; bool tag[MAXN + 5]; void pushup(int x) { if (tree[x].le == tree[x].ri) tree[x].mx = tree[x].mn = *tree[x].Set.r...
#include <bits/stdc++.h> using namespace std; using PII = pair<int, int>; using PLL = pair<long long, long long>; using VLL = vector<long long>; using VI = vector<int>; inline void fastio() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } const int INF = 0x3f3f3f3f; const long lon...
#include <bits/stdc++.h> using namespace std; bool prime[100000 + 5]; int ans[100000 + 5]; int main() { long long int n; cin >> n; for (int i = 0; i <= n; i++) prime[i] = true; long long int k = 1; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { ans[p] = k; f...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; string s; cin >> n >> k; cin >> s; int isThere[26]; for (int i = 0; i < 26; i++) isThere[i] = 0; bool ok = true; for (int i = 0; i < n; i++) { isThere[s[i] - a ]++; if (isThere[s[i] - a ] > k) { ...
#include <bits/stdc++.h> using namespace std; const int MAXD = 60 + 5; const int MAXN = 2e3 * 60 + 5; const int mod = 1e9 + 7; inline long long pw(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res...
#include <bits/stdc++.h> using namespace std; vector<string> ans; bool check(string s, int L, int R) { if (s[L] == 0 ) { if (R == L + 1) { return true; } return false; } int n = 0; for (int i = L; i < R; i++) { n *= 10; n += s[i] - 0 ; } return (n >=...
#include <bits/stdc++.h> using namespace std; struct node { long long int a; long long int b; }; node p[100005]; bool comp(node x, node y) { if (x.b < y.b) return true; return false; } int main() { long long int n, r, avg; cin >> n >> r >> avg; long long int s = 0; for (int...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int columns[n + 1]; memset(columns, 0, sizeof(columns)); for (int i = 0; i < m; i++) { int tmp; cin >> tmp; columns[tmp]++; } int ans = 1001; for (int i = 1; i <= n; i++) { ans...
#include <bits/stdc++.h> using namespace std; int head[100005]; struct edge { int vet, next; } E[200005]; int i, j, k, n, m, s, t, tot, L; int top[100005]; int fa[100005]; int dep[100005]; int a[100005]; int dist[3005][3005]; double ans; int X, Y, all; int cyc[100005]; int getf(int x) { ...
#include <bits/stdc++.h> using namespace std; int x[4], y[4], a[4], b[4]; vector<int> v[2]; void yes() { puts( YES ); exit(0); } void add(bool is, int at, int to) { if (is) v[is].push_back(y[at]), v[is].push_back(y[to]); else v[is].push_back(x[at]), v[is].push_back(x[to]); } ...
#include <bits/stdc++.h> using namespace std; double pi = 2 * acos(0.0); template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << { ; for (const auto &x : v) os << << x; return os << } ; } void solve() { long long int l, r, m; cin >> l >> r >> m; long ...
#include <bits/stdc++.h> long long mod = 1e9 + 7, mod2 = 998244353; using namespace std; long long fac[10000000]; long long gcd(long long x, long long y) { if (y == 0) return x; return gcd(y, x % y); } long long fexp(long long a, long long b, long long m) { long long ans = 1; while (b) { ...
#include <bits/stdc++.h> using namespace std; int n, m; map<int, int> mp; int a[11], aa[11]; int b[11]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> b[i]; if (a[b[i]] == 0) { a[b[i]]++; mp[b[i]]++; } } for (int i = 0; i < m; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y, a = 0, b = 0; cin >> n; vector<pair<int, int>> v; while (n--) { cin >> x >> y; a += x; b += y; v.push_back(make_pair(x, y)); } bool ok = 0; if (a % 2 == 0 && b % 2 == 0) { cout << 0; ...
#include <bits/stdc++.h> const int MAXN = 3000 + 1000; int n, sum; int in[MAXN], out[MAXN]; struct Union_Find_Set { int f[MAXN]; void Init(int N) { for (int i = 1, _ = N; i <= _; i++) f[i] = i; } int Find(int x) { return x == f[x] ? x : f[x] = Find(f[x]); } bool Union(int x, int y) { ...
#include <bits/stdc++.h> using namespace std; using LL = long long; namespace _buff { const size_t BUFF = 1 << 19; char buff[BUFF], *begin = buff, *end = buff; char getc() { if (begin == end) { begin = buff; end = buff + fread(buff, 1, BUFF, stdin); } return begin == end ? -1 : *begi...
#include <bits/stdc++.h> using namespace std; void func(void) { freopen( input.c , r , stdin); freopen( output.c , w , stdout); } void print(vector<long long> &v) { cout << v.size() << endl; for (int i = 0; i < v.size(); i++) { printf( %lld , v[i]); } printf( n ); } void pr...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e9; const int MAXN = 20010; const int MAXK = 110; int N, K; int A[MAXN]; int ord[MAXN]; int lo[MAXN], hi[MAXN]; struct line { int k, b; line() {} line(int k_, int b_) : k(k_), b(b_) {} int eval(int x...
#include <bits/stdc++.h> using namespace std; const int kMaxN = 1000005; int aib[2 * kMaxN]; int x[kMaxN], poz[kMaxN]; int el[2 * kMaxN]; bool first[kMaxN]; void aib_update(int ind, int val) { while (ind < 2 * kMaxN) { aib[ind] += val; ind += ind & (-ind); } return; } int aib_s...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); unsigned long long t; cin >> t; while (t--) { unsigned long long x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; if (x1 == x2 || y1 == y2) { cout << 1 ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int p[N], used[N]; void solve() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i]; } for (int i = 1; i <= n; i++) { if (p[i] == i) { cout << YES n ; for (int j = 1; j <= n; j++) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m, i, j; cin >> n >> m; char a[200][200]; for (i = 1; i <= n; i++) for (j = 1; j <= m; j++) cin >> a[i][j]; vector<vector<long long> > b(200, vector<lo...
#include <bits/stdc++.h> using namespace std; const int N = 111; vector<pair<int, int> > g[N]; void printAns(int id, int v, int u, double x) { if (x >= 1) { swap(v, u); x -= 1; } x = 1 - x; printf( 1 %d %d %d %.12lf n , id, u, v, x); } void dfs(int v, int par, double x) { for...
#include <bits/stdc++.h> using namespace std; const int N = 5 * 100005; int sum[N]; char str[5 * 100005]; int costf[5 * 100005]; int costb[5 * 100005]; int n, a, b, t; int main() { scanf( %d , &n); scanf( %d , &a); scanf( %d , &b); scanf( %d , &t); cin >> str; if (str[0] == h ) ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T BM(T p, T e, T M) { long long int ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.precision(1); cout << fixed; double n, x, y; cin >> n >> x >> y; double s = (y * n) / 100; int p = ceil(s) - x; if (p >= 0) cout << p; else cout...
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; int a, b; int s1 = 0; int s2 = 0; int flag = 0; while (n--) { cin >> a >> b; if ((a & 1) != (b & 1)) flag = 1; s1 += a; s2 += b; } cerr << s1 << << s2 << endl; int ans ...
#include <bits/stdc++.h> using namespace std; int main() { int m, n; int i; cin >> m >> n; double p[m]; double pre[m]; p[0] = pow(1.0 / m, n); pre[0] = p[0]; for (i = 1; i < m; i++) { p[i] = pow(double(i + 1) / m, n) - pre[i - 1]; pre[i] = pre[i - 1] + p[i]; } dou...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int arr[200] = {}, i, j, k, w, ans = 0; for (i = 0; i < n; i++) cin >> arr[i]; cin >> w; sort(arr, arr + n); for (i = 0; i < n; i++) { int c = 1; for (j = i + 1; j < n; j++) { if (arr[j...
#include <bits/stdc++.h> using namespace std; const int nmax = 200001; long long n, k; int main() { cin >> n >> k; int p = (n / k) % 2; cout << (p % 2 == 1 ? YES : NO ) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2010; const int INF = (int)1e9; char ch[N][N]; int n, m, k; int CountSpider(int x, int y, int time) { int ans = 0; if (x - time >= 1 && ch[y][x - time] == R ) ans++; if (x + time <= m && ch[y][x + time] == L ) ans++; if (y - time ...
#include <bits/stdc++.h> using namespace std; int main() { int N, F, M; cin >> N >> F >> M; int FR[200], MO[200]; vector<int> V; int mi = 10000; for (int i = 0; i < F; ++i) cin >> FR[i]; for (int j = 0; j < M; ++j) cin >> MO[j]; for (int i = 0; i < F; ++i) { int cnt = 0; ...
#include <bits/stdc++.h> using namespace std; void solve(){ int n; scanf( %d , &n); if (n == 2){ printf( 1 n2 1 n1 n2 1 n ); } else if (n == 3){ printf( 5 n2 3 1 n2 n1 3 n2 3 n ); } else { long long t = 0; vector<int> ans; v...
#include <bits/stdc++.h> using namespace std; long long n, k; long long bmm(long long x, long long y) { if (y) return bmm(y, x % y); return x; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; long long d = k; for (long long i = 0; i < n; i++) { long long...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 2e5 + 4; int main() { string s; int n; scanf( %d , &n); cin >> s; int pre[n], suf[n], minm = 0, bal = 0; for (int i = 0; i < n; i++) { if (s[i] == ( ) { pre[i] = 1; suf[i] = ...
#include <bits/stdc++.h> using namespace std; int main() { int n, o = 0, x = 0; cin >> n; for (int i = 0; i < n; i++) { int a; cin >> a; if (a) x++; else o++; } int s = x / 9; if (s && o) { for (int i = 0; i < 9 * s; i++) { cout << 5; ...
#include <bits/stdc++.h> char a[200005], b[200005], c[200005]; int v[200005], n, m; bool verif(int poz) { int i, j; for (i = 1; i <= n; i++) c[i] = a[i]; for (i = 1; i <= poz; i++) c[v[i]] = 0; for (i = 1, j = 1; i <= n && j <= m; i++) if (c[i] == b[j]) j++; if (j == m + 1) return true; ...
#include <bits/stdc++.h> using namespace std; long long n, a, b, c, ans; int main() { cin >> n >> a >> b >> c; if (n >= b) ans = (n - ((n - b) / (b - c) + 1) * (b - c)) / a + (n - b) / (b - c) + 1; cout << max(n / a, ans); }
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native ) using namespace std; int a1, b1, c1, a2, b2, c2; int d1, d2, d3, d4, d5, d6, d7; int f1, f2, f3, f4, f5, f6, f7; bool check() { return f1 <= d1 && f2 <=...
#include <bits/stdc++.h> using namespace std; inline string to_string(char c) { string s; s.push_back(c); return s; } struct Node { bool can_delete_all = true; char first_cant = 0; bool more = false; string first = ; string last = ; int ans_len = 0; Node(bool can_dele...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; int a[MAXN], ans[MAXN]; pair<int, int> tab[MAXN]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { cin...
#include <bits/stdc++.h> using namespace std; int n, m, k; int a[15][123]; int b[15][123]; int c[15][123]; vector<int> v; bool cmp(int x, int y) { return x > y; } int main() { cin >> n >> m >> k; for (int i = 0; i < n; i++) { string s; cin >> s; for (int j = 0; j < m; j++) cin ...
#include <bits/stdc++.h> using namespace std; int const inf = 1000 * 1000 * 1000; long long const inf64 = 1ll * inf * inf; struct Fenwick { int n; vector<long long> fen; Fenwick() { n = 0; } Fenwick(int nn) { n = nn; fen.resize(n + 1); } void put(int pos, int val) { for...
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> id; vector<int> a[100005]; int main() { int i, j, k, n; cin >> n; cout << n - 1 << endl; int idd = 1; for (k = (1); k <= (n - 1); k++) { cin >> i >> j; a[i].push_back(j); a[j].push_back(i); id[make...
#include <bits/stdc++.h> using namespace std; int t; char a[30]; int main() { cin >> t; while (t--) { string s; cin >> s; int len = s.size(), id = 0; for (int i = 0; i < len; i++) { int temp = 1; while (s[i + 1] == s[i]) { i++; temp++; ...
#include <bits/stdc++.h> using namespace std; void swap(long long &a, long long &b) { long long t = a; a = b; b = t; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n, k; cin >> n >> k; ...
#include <bits/stdc++.h> using namespace std; const int N = 19; int a[1 << N]; int main() { int n, q; cin >> n >> q; long long sum = 0; for (int i = 0; i < (1 << n); i++) cin >> a[i], sum += a[i]; cout << setprecision(10) << 1.0 * sum / (1 << n) << n ; for (int i = 0; i < q; i++) { ...
#include <bits/stdc++.h> using namespace std; int p(string s) { string a = s; s += # ; reverse(a.begin(), a.end()); s += a; int n = s.size(); vector<int> pi(n); pi[0] = 0; int j = 0; for (int i = 1; i < n; i++) { j = pi[i - 1]; while (j > 0 && s[i] != s[j]) j = pi[j ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; deque<char> vec; cin >> s; for (int i = 0; i < s.size(); ++i) vec.push_back(s[i]); int cnt = 0, i; while (vec.size() > 1) { if (vec[vec.size() - 1] == 0 ) { ++...
#include <bits/stdc++.h> using namespace std; const int N = 2005, M = 998244353; int read(int x = 0, int f = 1, char c = getchar()) { for (; c < 0 || c > 9 ; c = getchar()) if (c == - ) f = -1; for (; c >= 0 && c <= 9 ; c = getchar()) x = x * 10 + c - 0 ; return x * f; } int n, a[N][...
#include <bits/stdc++.h> using namespace std; int n, m, k; vector<long long> v; vector<pair<pair<long long, long long>, long long> > vv; vector<long long> ary; void update(int pos, long long val, int mx) { while (pos <= mx) { ary[pos] += val; pos += pos & -pos; } } long long get(int ...
#include <bits/stdc++.h> using namespace std; int n; int X, t[10000], h[10000], m[10000], v[10000]; int f(int x) { int ht = X; memset(v, 0, sizeof(v)); for (int i = (0); i < (n); i++) { int tmp = -1; for (int j = (0); j < (n); j++) { if (v[j] || t[j] != ((i + x) & 1) || h[j] > ht...
#include <bits/stdc++.h> using namespace std; int n; string s; set<string> aux; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { cin >> s; string ns = ; for (int j = 0; j < s.size(); j++) { if (s[j] == u ) ns += oo ; else if (s[j] == h ) { ...
#include<bits/stdc++.h> using namespace std; #define ll long long int #define inf 1e18 #define F first #define S second #define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define pb push_back #define pll pair<ll,ll> #define vl vector<ll> #define all(x) (x).begin(),(x).end() #...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j, k, l; cin >> n >> m; k = (n - m) / 2; j = 1; while (j <= n) { if (j % (k + 1) == 0) { cout << 1 ; } else { cout << 0 ; } j++; } }
#include <bits/stdc++.h> using namespace std; const long long maxS = 2e5 + 5; long long N, M; long long A[201], B[201]; long long DP[201][515]; long long go(long long pos, long long prev) { if (pos == N + 1) return 0; if (DP[pos][prev] != -1) return DP[pos][prev]; long long ans = INT_MAX; fo...
#include <bits/stdc++.h> using namespace std; const int maxn = 5000000 + 10; const int mod = 51123987; int n; long long p[maxn], sum; char s1[maxn], s[maxn]; long long min(int a, int b) { return a < b ? a : b; } inline void init() { s[0] = $ ; for (int i = 1; i <= n; ++i) s[2 * i] = s1[i], s[2 ...
#include <bits/stdc++.h> char ar[10][10]; int q[10 * 10 * 10 * 10][3]; bool forb[10][10][10 * 10]; bool used[10][10][10 * 10]; int dir[9][2] = {{1, 1}, {1, 0}, {1, -1}, {0, 1}, {0, 0}, {0, -1}, {-1, 1}, {-1, 0}, {-1, -1}}; void BFS(void) { int x = 8, y = 1; q[1][0] = x; q[1...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; constexpr int MOD = 998244353; int sum(int a, int b, int mod = MOD) { int c = a + b; if (c >= mod) { c -= mod; } return c; } inline int ...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; long long l = -1, r = -1; for (long long i = 0; i < s.length(); i++) { if (s[i] == [ ) { l = i; break; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, car[101][101]; bool t[101] = {0}; vector<int> ans; ans.clear(); scanf( %d , &n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf( %d , &car[i][j]); if (car[i][j] == 2) { t[j] =...
#include <bits/stdc++.h> using namespace std; const int N = 4003; int t[N][N]; int a; string s; map<long long, long long> mp; long long acc[N]; int main() { cin >> a >> s; int n = s.size(); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) t[i][j] = (s[i] - 0 ) * (s[j] - 0 ); ...
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T X) { return X * X; } const int maxn = 110; const double zero = 1e-8; int n, K; double omiga; struct COO { double x, y; } ob[maxn], nuclear; double p[maxn], f[maxn][maxn]; double numb; double ans; void init() { ...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const int nax = 1e3 + 20; const int mod = 1e9 + 7; int fact[nax]; int binpow(int a, int e) { int ans = 1; while (e > 1) { if (e & 1) { ans = (1LL * ans * a) % mod; --e; } a = (1LL * a * a) % m...
#include <bits/stdc++.h> using namespace std; template <class X, class Y> void amax(X& x, const Y& y) { if (x < y) x = y; } template <class X, class Y> void amin(X& x, const Y& y) { if (x > y) x = y; } const int INF = 1e9 + 10; const long long INFL = (long long)1e18 + 10; const int MAX = 2e5...
#include <bits/stdc++.h> int main() { long long int m, n, a; scanf( %lld %lld %lld , &m, &n, &a); if (m % a == 0 && n % a == 0) { printf( %lld , m * n / a / a); } if (m % a != 0 && n % a == 0) { printf( %lld , ((m + a) / a) * (n / a)); } if (m % a != 0 && n % a != 0) { pr...
#include <bits/stdc++.h> using namespace std; vector<int> e[200000 + 5]; int main() { int T, n; int m, p; scanf( %d , &T); for (int t = 1; t <= T; ++t) { scanf( %d , &n); for (int i = 0; i <= n; ++i) e[i].clear(); for (int i = 1; i <= n; ++i) { scanf( %d%d , &m, &p); ...
#include <bits/stdc++.h> using namespace std; vector<int> v[200009]; set<int> ss; pair<int, int> help[200009]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int a, b; scanf( %d %d , &a, &b); v[a].push_back(b); } for (int i = 1; i <= n; i++) sort(v[i].begin()...
#include <bits/stdc++.h> using namespace std; char a[100010]; int c[100010]; const int mod = 1000000007; long long Pow(long long a, long long b, long long c) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % c; b >>= 1; a = a * a % c; } return ans; } int main() ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, ans = 0, xs, ys, xe, ye; char q[105][105]; cin >> n >> m; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> q[i][j]; if (q[i][j] == S ) { xs = i; ys = j; } ...
#include <bits/stdc++.h> using namespace std; const double TOLL = 1e-9; int N, L, K; int a[210]; double p[210]; const int maxn = 400; double dp[201][401][maxn + 2]; double rec(int ind, int l, int cap) { if (cap < -202) cap = -200; if (cap > 202) cap = 200; if (ind == N) { if (l <= 0 &&...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math ) using namespace std; const int N = 2e5 + 100, sq = 1002, nsq = 200; int cnt[nsq][N], b[nsq][N / 2]; int a[N]; map<int, int> mp, nmp; vector<pair<int, pair<int, int> > > q; void add(int id, int val) { whi...
#include <bits/stdc++.h> using namespace std; template <typename T> T getint() { T x = 0, p = 1; char ch; do { ch = getchar(); } while (ch <= ); if (ch == - ) p = -1, ch = getchar(); while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 0 , ch = getchar(); return x * p; } tem...
#include <bits/stdc++.h> using namespace std; mt19937 rnd; const int N = 1e5 + 10; long long a[N], pref[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, d, m; cin >> n >> d >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); for (i...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<pair<long long, long long>> vp; long long p, a, l = 0, r = 0, ss = 0; for (int i = 0; i < n; i++) { cin >> p >> a; if (p < 0) { ++l; } else { ++r; } ss += a; v...
#include <bits/stdc++.h> using namespace std; double work(int x) { if (x == 0) return 1; double n = 1.000000011; double ans = 1; while (x > 0) { if ((x & 1) == 1) ans *= n; n *= n; x /= 2; } return ans; } int main() { int n, t; cin >> n >> t; printf( %0.20lf...
//Template Made By: Ojassvi Kumar #include<bits/stdc++.h> using namespace std; #define ios ios_base::sync_with_stdio(false);cin.tie(NULL); #define ll long long int #define fo(i,a,b) for(long long int i=a; i<b; i++) #define endl n #define max3(a,b,c) max(max((a),(b)),(c)) #define max4(a,b,c,d) max...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } double PI = 3.1415926536; const int inf = 1e9 + 7; long long MAX(long long a, long long b) { return a > b ? a : b; } ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; string a[2 * n], b[2 * m]; for (int i = 0; i < 2 * n; i += 2) { cin >> a[i] >> a[i + 1]; } for (int i = 0; i < 2 * m; i += 2) { cin >> b[i] >> b[i + 1]...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; double n; cin >> t; while (t--) { cin >> n; if (n * n - 4 * n < 0) { cout << N << endl; continue; } if (n == 0) { double ...
#include <bits/stdc++.h> struct three_t { int x, y, z; inline three_t(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {} }; std::vector<int> next[100010]; std::vector<three_t> to[100010]; int n, q, t[100010], v[100010], spc[100010], clr[100010], tag[100010], col[100010], tmp[100010]; void ...
#include <bits/stdc++.h> using namespace std; void bktk(int i, char *s, int val, int &ans, vector<int> &cnt) { if (!s[i]) { ans += cnt[val]; return; } val *= 3; if (s[i] == A ) { bktk(i + 1, s, val, ans, cnt); bktk(i + 1, s, val + 1, ans, cnt); } if (s[i] == a ) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, w, x, sum = 0, mmax = 0, us = 0; cin >> n >> w; for (int i = 1; i <= n; ++i) { scanf( %d , &x); sum += x; us = min(us, sum); mmax = max(mmax, sum); } if (us < 0) us = -us; else us = 0; p...
#include <bits/stdc++.h> int MOD = 1000000007; long long inf = 1e18; using namespace std; vector<int> A, B, C; int as, bs, cs; int a, b, c; int k, n1, n2, n3, t1, t2, t3; bool ok(int t) { if (a == n1) return false; int cntb = 0; for (int i = bs; i < B.size(); i++) { if (t + t1 < B[i] +...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN = (int)5e5 + 5; int n; struct node { int x, y; } a[MAXN]; struct BIT { long long sum[MAXN]; int n; void init(int _n) { n = _n; memset(sum, 0, sizeof(sum)); ; } int lowbit(int ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; scanf( %d%d , &a, &b); if (b > a) { printf( -1 n ); } else if (a == b) { printf( %d.000000000 n , a); } else { int k((a - b) / b); if (k & 1) { k--; } double ans1(1. * (a - b) / k); ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, m, k, i, j, a[200002], sum = 0; vector<long long int> v; set<pair<long long int, long long int>> s; cin >> n >> m >> k; for (i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0; char zf = 1; char ch = getchar(); while (ch != - && !isdigit(ch)) ch = getchar(); if (ch == - ) zf = -1, ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return x * zf; ...
#include <bits/stdc++.h> using namespace std; int main() { int x0, y0, x, y; cin >> x0 >> y0 >> x >> y; if (x0 != x && y != y0 && abs(x - x0) != abs(y - y0)) { cout << -1 << endl; return 0; } int dx = abs(y - y0); int dy = abs(x0 - x); if (x0 == x) cout << x0 + dx << ...