func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using std::cerr; using std::endl; const int N = 2005, INF = 1e9, P = 998244353; int n, G[N][N]; char str[N]; int deg[N]; inline int binom(int x) { return x * (x - 1) / 2; } inline bool check() { std::sort(deg + 1, deg + n + 1); int sum = 0; for (int i = 1; i < n; ++i...
#include <bits/stdc++.h> using namespace std; class TaskD { public: unsigned long long compute(vector<pair<int, int> >& a, const vector<unsigned long long>& tag) { vector<pair<int, int> > events; for (int i = 0; i < a.size(); ++i) { events.emplace_back(a[i]....
#include <bits/stdc++.h> using namespace std; long long n, m, res, t, k, o; long long a[1000100], b[1000100]; priority_queue<int, vector<int>, greater<int> > q; int main() { scanf( %lld %lld , &n, &k); for (long long i = 1; i <= n; i++) { scanf( %lld , &a[i]); } scanf( %lld , &m); fo...
#include <bits/stdc++.h> using namespace std; long long mod_v(long long num) { if (num >= 0) return (num % 1000000007); else return (num % 1000000007 + 1000000007) % 1000000007; } long long bigmod(long long b, long long p, long long m) { long long res = 1 % m, x = b % m; while (p) { ...
#include <bits/stdc++.h> using namespace std; long long n, a[3000], b[3000], w[500], pos[500][5000], ans; string second; int ispal(int x, int y) { int t = y; while (x != y) { if (second[x] != second[y]) return 0; if (y - x == 1 || y - x == 2) { b[t]++; return 1; } ...
#include <bits/stdc++.h> using namespace std; map<string, int> Id; char Name[107][15], Str[107][150]; int dp[107][107], last[107][107], record[107][107], vis[107]; void Show(int Step, int k) { if (Step - 1) Show(Step - 1, last[Step][k]); int pos = 0; while (Str[Step][pos] != : ) pos++; printf...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000 + 10; const int INF = 1000000000; const int MOD = (int)(1e9) + 7; int main() { int n; cin >> n; int m = (1 << (n + 1)) - 1; vector<int> a(m + 10, 0); for (int i = 2; i <= m; i++) cin >> a[i]; vector<int> s(m + 10, 0)...
#include <bits/stdc++.h> using namespace std; void test_case() { int n; long long k; cin >> n >> k; int l, r[2] = {-1, -1}; long long curr[2] = {k, k}, ans[2] = {0, 0}, monsters; for (int i = 0; i < n; i++) { int old_r[2] = {r[0], r[1]}, tmp_r; long long old_curr[2] = {curr[0], c...
#include <bits/stdc++.h> using namespace std; int r, c, n, k, x, y; int flag[101][101]; int main() { cin >> r >> c >> n >> k; for (int i = 0; i < n; i++) { cin >> x >> y; flag[x][y] = 1; } int cnt = 0; for (int i = 1; i <= r; i++) { for (int i1 = 1; i1 <= c; i1++) { ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAX = 1e5 + 55; const int INF = 1e9 + 77; const long long INFINF = 1e18 + 1e17; const double PI = acos(-1.0); long long power(long long x, long long y) { if (y == 0) return 1; long long s = power(x, y / 2); s *= s...
#include <bits/stdc++.h> using namespace std; int Int() { int x; scanf( %d , &x); return x; } long long Long() { long long x; scanf( %lld , &x); return x; } void err(istream_iterator<string> it) { cout << endl; } template <typename T, typename... Args> void err(istream_iterator<s...
#include <bits/stdc++.h> using namespace std; int n; string s, t; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> t; int ph = 0; pair<int, int> mh = {0, 0}; for (int i = 0; i < n; i++) { if (t[i] == ( ) ph++; else ph--; mh = min(mh,...
#include <bits/stdc++.h> using namespace std; string s; int main() { int t; cin >> t; while (t--) { cin >> s; int n = s.length(); if (s[n - 2] == p && s[n - 1] == o ) { cout << FILIPINO << endl; } else if (s[n - 1] == u && s[n - 2] == s && (s[n...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; const int INF = 1e9, MOD = INF - 1755647; int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); } int power(int a, int b) { return (!b ? 1 : power(a, b / 2) * power(a, b / 2) * (b % 2 ? a : 1)); } int mod(int a) { return (a ...
#include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin>>t; while(t--) { int n; cin>>n; string a; cin>>a; if(a[0]== 2 &&a[1]== 0 &&a[2]== 2 &&a[3]== 0 ) cout<< YES << n ; else if(a[...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000000 + 10; char b[maxn]; int a[maxn]; int ccc[20]; int main() { long long n; long long sum = 0; cin >> n; if (n % 2 == 0) sum = n / 2; else sum = (-n - 1) / 2; cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int x[3], y[3]; map<pair<int, int>, bool> cleaned; int cost(int cx, int cy) { int sum = 0; for (int i = 0; i < (3); i++) sum += ((cx - x[i]) > 0 ? (cx - x[i]) : -(cx - x[i])) + ((cy - y[i]) > 0 ? (cy - y[i]) : -(cy - y[i])); return sum...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-7; struct segtree { struct node { double sum; double mul, add; node() { sum = 0; mul = 1; add = 0; } void apply_mul(int l, int r, double v) { mul *= v; add *= v; su...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int mod = 1e9 + 7; int n, l[N], t[N]; long long r; int main() { scanf( %d%lld , &n, &r); for (int i = 0; i < n; i++) scanf( %d , l + i); for (int i = 0; i < n; i++) { scanf( %d , t + i); if (t[i] < l[i]) retur...
#include <bits/stdc++.h> using ul = std::uint32_t; using li = std::int32_t; using ull = std::uint64_t; using ll = std::int64_t; std::vector<ul> v; std::string s; int main() { std::getline(std::cin, s); std::stringstream ss(s); while (std::getline(ss, s, , )) { std::stringstream ss(s); ...
#include <bits/stdc++.h> using namespace std; const int N = (int)4e2; const int INF = (int)1e9; int n, m, a[N][N], p; int dyn[N][N], last[N]; vector<pair<int, int> > q[N * N]; int len[N][N]; int main() { cin >> n >> m >> p; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { ...
#include <bits/stdc++.h> using namespace std; long long mul(long long a, long long b) { return (a * b) % 1000000007; } long long add(long long a, long long b) { a += b; if (a >= 1000000007) a -= 1000000007; return a; } long long binary_expo(long long base, long long expo) { long long res = 1; ...
#include<bits/stdc++.h> using namespace std; long long t,n,k,pos; string s; bool mode; char best(int pos){ char c=s[pos]; return min({c,char((c- a +1)%k+ a ),char(((c- a -1)%k+k)%k+ a )}); } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>t; while(t--){ ...
#include <bits/stdc++.h> using namespace std; const int nMax = 2000005; int p[nMax]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { p[i] = i + 1; } int s = 0; for (int j = 2; j < n + 1; ++j) { int curr = p[s]; p[n + s] = p[n + s - n % j]; for (int i =...
#include <bits/stdc++.h> using namespace std; int n, m, k; bool debug = false; int dp[1005][1005]; char a[1005], b[1005]; int main() { scanf( %s%s , a + 1, b + 1); int n = strlen(a + 1); int m = strlen(b + 1); for (int i = 1; i <= n; i++) dp[i][0] = i; for (int i = 1; i <= m; i++) dp[0][...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; const long long MOD = 1e9 + 7; long long n, m, cnt = 0; long long a[N], comp[N], vis[N]; vector<long long> g[N], rg[N], v[N]; vector<long long> todo; void dfs(long long k) { vis[k] = 1; for (auto it : g[k]) { if (!v...
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) using namespace std; unsigned long long min(unsigned long long x, unsigned long long y) { if (x < y) return x; return y; } unsigned long long max(unsigned long long x, unsign...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; char a[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } int str1 = n; int str2 = -1; int st1 = m; int st2 = -1; for (int i = 0; i < n;...
#include <bits/stdc++.h> using namespace std; int main() { vector<long long> no; long long int n, m, s = 0, a[100000], l = 1, i; cin >> n >> m; for (i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n); for (i = 1; i <= m; i++) { if (a[l] == i) l++; else { s +=...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n, k; cin >> n >> k; long long total = n * k; std::vector<long long> v(total); for (long long i = 0; i < total;...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int a[n]; long long int sum = 0; for (long int i = 0; i < n; i++) scanf( %lld , &a[i]), sum += a[i]; long long int ans[n]; long long int l = 0, r = 1e12; long long int mid = 0; while (...
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; int n, k; int a[maxn], b[maxn]; map<int, bool> MAP; int main() { int ans = 0; scanf( %d%d , &k, &n); for (int i = 0; i < k; i++) { scanf( %d , &a[i]); } for (int i = 0; i < n; i++) { scanf( %d , &b[i]); ...
#include <bits/stdc++.h> using namespace std; int n; int a[15]; void f(int fg, int x) { if (fg == 1) { for (int i = 0; i <= 10; i++) { if (((x >> i) & 1) != 0) { a[i] = 1; } } } else if (fg == 2) { for (int i = 0; i <= 10; i++) { if (((x >> i) & 1) == ...
#include <bits/stdc++.h> using namespace std; const long long limita = 998244353; long long n, v[200], st, dr, mij, mul, ans, maxDegree; long long GCD(long long x, long long y) { if (y != 0) return GCD(y, x % y); else return x; } int main() { ios::sync_with_stdio(false); cin.tie(...
#include <bits/stdc++.h> using namespace std; int n, arr[200000 + 5], x[200000 + 5], ada[35]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &arr[i]); if (i > 0) x[i] = x[i - 1] ^ arr[i]; else x[i] = arr[i]; } if (x[n - 1] == 0) prin...
#include <bits/stdc++.h> using namespace std; int main() { long long int l, r, x, y, k; cin >> l >> r >> x >> y >> k; for (long long int i = x; i <= y; ++i) { if (k * i >= l && k * i <= r) { cout << YES << endl; exit(0); } } cout << NO << endl; }
#include <bits/stdc++.h> using namespace std; void solutionC(); int main() { solutionC(); return EXIT_SUCCESS; } int n, a[500002], b[500002]; bool check() { for (int i = 1; i < n - 1; ++i) { int s = a[i] + a[i - 1] + a[i + 1]; if (s == 2 && a[i] != 1) return false; if (s == 1 &...
#include <bits/stdc++.h> using namespace std; struct node { int hx, hy; int tx, ty; int dep; long dir; int zt[15]; }; queue<node> q; int n, m, len; int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; bool v[15][15][262144]; char c[30][30]; bool init(int a, int b) { if (a < 0 || a...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vb = vector<bool>; using vvb = vector<vb>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>; const ll...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ara[n]; int temp = n; int k = 0; while (n--) { cin >> ara[k++]; } sort(ara, ara + temp); queue<int> Q; for (int i = 0; i < temp; i++) { Q.push(ara[i]); } int i; for (i = 1;...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; long long eq(long long start, long long k) { long long num = k - (start - 1); return ((num * (start + k)) / 2) - (num - 1); } void solve() { long long n, k; cin >> n >> k; long long q = eq(2, k); if (n == 1) cou...
#include <bits/stdc++.h> using namespace std; const long long MOD = (1 << 30); const double Exp = 1e-8; const int maxm = 1e5 + 7; const int maxn = 1e5 + 7; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const double pi = 3.1415926535898; string s; int q, n, sum1, sum2, sum3; ...
#include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1e18 #define memset(a , b) memset((a) , (b) , sizeof(a)) #define mod 1000000007 #define rep(i , n) for((i) = 0 ; (i) < n ; (i)++) #define N ...
#include <bits/stdc++.h> using namespace std; int D, m, x, y; vector<vector<long double>> e; const long double oo = 1e13; vector<long double> mns(vector<long double> a, vector<long double> b) { vector<long double> ret; ret.resize(D); for (int i = 0; i < D; i++) ret[i] = a[i] - b[i]; return ret...
#include <bits/stdc++.h> using namespace std; const int N = 233333; int par[N][25], dep[N]; int u, v, ans; int n; inline int lca(int u, int v) { if (dep[u] < dep[v]) { u ^= v; v ^= u; u ^= v; } for (int i = 0; i < 25; i++) if (((dep[u] - dep[v]) >> i) & 1) u = par[u][i]; ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long llINF = 1e18; const int MAXN = 1e5 + 5; int n, Q; int a[MAXN]; namespace SegmentTree { struct Node { int lmax, rmax, lmin, rmin, maxl, maxr, minl, minr, sum, maxsum, minsum, maxposl, minposl, maxposr, m...
#include <bits/stdc++.h> unsigned long long mulmod(unsigned long long a, unsigned long long b, unsigned long long c) { unsigned long long x = 0, y = a % c; while (b > 0) { if (b % 2 == 1) { x = (x + y) % c; } y = (y * 2) % c; b /= 2; } return...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long s[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> s[i][j]; } } long long ans = sqrt((long long)((s[0][1] * s[0][2]) / s[1][2])); cout << ans; for (int i...
#include <bits/stdc++.h> using namespace std; string str(string s) { if (s.size() % 2) return s; string a = str(s.substr(0, s.size() / 2)); string b = str(s.substr(s.size() / 2, s.size() / 2)); if (a < b) return a + b; else return b + a; } int main() { ios_base::sync_with_std...
#include <bits/stdc++.h> long long mod = 1000000007; using namespace std; int n; long long powmod(long long a, long long b) { long long res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } int a[100005]; int main() { i...
#include <bits/stdc++.h> using namespace std; template <typename _T> inline void _DBG(const char *s, _T x) { cerr << s << = << x << n ; } template <typename _T, typename... args> void _DBG(const char *s, _T x, args... a) { while (*s != , ) cerr << *s++; cerr << = << x << , ; _DBG...
#include <bits/stdc++.h> using namespace std; int parent[200005], par[200005], root; int find(int i) { if (parent[i] != i) parent[i] = find(parent[i]); return parent[i]; } void merge(int x, int y) { int xroot = find(x); int yroot = find(y); if (xroot == yroot) { if (!root) root = xro...
#include <bits/stdc++.h> using namespace std; template <typename T> void pr(vector<T> &v) { for (int i = 0; i < (int)(v).size(); i++) cout << v[i] << ; cout << n ; ; } template <typename T> void pr(vector<vector<T>> &v) { for (int i = 0; i < (int)(v).size(); i++) { pr(v[i]); }...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 105; const int N = 200; int f[maxn][maxn][maxn]; int g[maxn][maxn][maxn]; bool usedf[maxn][maxn]; bool usedg[maxn][maxn]; int n, m, K, ans, c[N + 5][N + 5]; int main() { scanf( %d %d %d , &n, &m, &K); if ...
#include <bits/stdc++.h> using namespace std; long long mod(long long x) { return ((x % 1000000007 + 1000000007) % 1000000007); } long long add(long long a, long long b) { return mod(mod(a) + mod(b)); } long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); } template <class T> void pr...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; const long long int inf = 9e18; void __print(long long int x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { ce...
#include <bits/stdc++.h> using namespace std; int N; char S[100005]; int main() { scanf( %d , &N); scanf( %s , S); string ANS = ; int a = (N - 11) / 2, b = a; for (int i = 0; i < N; i++) { if (S[i] == 8 ) { if (a) --a; else ANS += S[i]; } el...
#include <bits/stdc++.h> using namespace std; template <class T> istream &operator>>(istream &in, vector<T> &arr) { for (T &i : arr) { in >> i; } return in; } template <class T> ostream &operator<<(ostream &in, vector<T> &arr) { for (T &i : arr) { in << i << ; } return...
#include <bits/stdc++.h> using namespace std; int n, m, ans, up, top; unsigned long long k; unsigned long long st[201], ed[201], sum[201], num[201]; int s[300010]; inline void init() { unsigned long long mi = 1; st[0] = 0; ed[0] = 0; for (int i = 1; i <= 64; i++) { st[i] = ed[i - 1] + ...
#include <bits/stdc++.h> using namespace std; char s[10][10]; int main() { int bl = 0, wh = 0; for (int i = 0; i < 8; i++) scanf( %s , s[i]); for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) { if (s[i][j] == Q ) wh += 9; else if (s[i][j] == R ) wh += ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5, maxm = 1e4 + 5, maxe = maxn * 4 + maxm, maxp = 4 * maxe; int n, m, b[maxe], id[maxe], tot, cnt, d; double p[maxp], ans; int read() { int ret = 0, f = 1; char ch = getchar(); while (ch > 9 || ch < 0 ) { if ...
#include <bits/stdc++.h> constexpr static int MAXD = 20000; using namespace std; bool check() { int n; cin >> n; int dist = 0; bool r = true; for (int i = 0; i < n; i++) { int t; string dir; cin >> t >> dir; if (dist == 0 && dir != South ) r = false; if (dist == ...
#include <bits/stdc++.h> using namespace std; int cmpint(const void *a, const void *b) { if (((int *)a)[0] == ((int *)b)[0]) return ((int *)a)[1] - ((int *)b)[1]; return ((int *)a)[0] - ((int *)b)[0]; } char s[100005]; int a[4] = {0}; int abs(int a) { if (a > 0) return a; return -a; } in...
/* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/priority_queue.hpp> using namespace __gnu_pbds; __gnu_pbds::priority_queue<int, less<int>> pq; gp_hash_table<int, int> mp; */ /** Begin fast allocation */ /* const int mx_MEM = 10 * 1e7; int mpos = 0; char mem[mx_MEM]; ...
#include <bits/stdc++.h> using namespace std; int L, R; int main() { int n, m, i, j, u, v; cin >> n >> m; int ans = 100001; for (i = 0; i < m; i++) { scanf( %d%d , &L, &R); ans = min(ans, R - L + 1); } cout << ans << endl; for (i = 1; i <= n; i++) cout << i % ans << ; ...
#include <bits/stdc++.h> using namespace std; const long long N = 100005, INF = 2000000000000000000; vector<long long> g[N]; long long power(long long a, long long b, long long p) { if (a == 0) return 0; long long res = 1; a %= p; while (b > 0) { if (b & 1) res = (res * a) % p; b >>=...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int num; bool flag = true; int* numbers = new int[n]; for (int i = 0; i < n; i++) { cin >> num; numbers[i] = num; if (i == n - 1) break; } for (int i = 0; i < n - 1; i++) for (int j = ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); if (n % 2 == 1) printf( black ); else printf( white n1 2 ); return 0; }
#include <bits/stdc++.h> using namespace std; int qa[100010] = {0}, qb[100010] = {0}, qla[100010] = {0}; int pa[100010] = {0}, pb[100010] = {0}, pla[100010] = {0}; char a[100010], b[100010]; int n, m; int la, lb, l1, r1, l2, r2; int main() { cin >> a >> b; cin >> n; la = strlen(a); lb = st...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline T1 max(T1 a, T2 b) { return b < a ? a : b; } template <typename T1, typename T2> inline T1 min(T1 a, T2 b) { return a < b ? a : b; } namespace ae86 { const int bufl = 1 << 15; char buf[bufl], *s = buf, *...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll N = 105, inf = 4e18 + 4, mod = 1e9 + 7; ll n, a2[N], num[N], ans, sum, dp[N][N * N], tmp[N][N * N], fac[N], inv[N]; bool mark[N]; ll pw(ll a, ll b) { if (b == 0) return 1; a %= mod; if (b % 2 == 1) return a * pw(a, (b -...
#include <bits/stdc++.h> using namespace std; int a[100001], n; int main() { int i, h; scanf( %d n , &n); for (i = 1; i <= n; ++i) scanf( %d n , &a[i]); h = a[1]; for (i = 2; i <= n; ++i) if (a[i - 1] < a[i]) h += a[i] - a[i - 1] + 1; else h += a[i - 1] - a[i] + 1; ...
#include <bits/stdc++.h> using namespace std; int cnt[15]; int s[15]; char c[1 << 20]; int need[15]; int digits(int first) { return !first ? 0 : 1 + digits(first / 10); } int main(void) { int n; string str; cin >> (c + 1) >> str; n = strlen(c + 1); for (auto it : str) ++need[it - 0 ];...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, p; string s; bool f = 0; cin >> n >> p >> s; s = + s; for (int i = n + 1; i > 1; i--) { for (char j = s[i] + 1; j < a + p; ...
#include <bits/stdc++.h> using namespace std; struct unionfind_t { vector<int> parent, rank; unionfind_t(int n) : parent(n), rank(n, 0) { iota(parent.begin(), parent.end(), 0); } int find(int v) { if (parent[v] == v) return v; return parent[v] = find(parent[v]); } int join(...
#include <bits/stdc++.h> using namespace std; struct edge { int v, nxt; } e[2050]; int ecnt; int n, m; int totdep; int pw[2050]; map<int, int> head; map<int, bool> has_fa; map<int, int> sz; map<int, bool> vis; void adde(int u, int v) { e[++ecnt].v = v; e[ecnt].nxt = head[u]; head...
#include <bits/stdc++.h> using namespace std; #define int long long int P = 1000000007; #define F first #define S second #define pb push_back #define mp make_pair void solve () { int n, c; cin >> n >> c; int a[n], b[n-1]; int mi=INT_MAX; for (int i=0; i<n; ++i) {cin >> a[i];} for (int i=0...
#include <bits/stdc++.h> using namespace std; string tostr(long long x) { stringstream ss; ss << x; return ss.str(); } long long toint(string &s) { stringstream ss; ss << s; long long x; ss >> x; return x; } int main() { long long a1, a2, tmp, arr[20], sum, j; string ...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; for (int P = 0; P < T; P++) { int n, k, d; cin >> n >> k >> d; vector<int> ar(n); map<int, int> s; int count = 0; for (int i = 0; i < n; i++) { int tmp = 0; cin >> tmp; ...
#include <iostream> #include <vector> #include <string> #include <cstring> #include <cmath> #include <climits> #include <algorithm> #include <map> #include <stack> #include <unordered_map> #include <set> #include <unordered_set> #include <utility> #include <iomanip> using namespace std; ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector ) #pragma GCC target( avx ) int V[100000]; float x; int main() { int n, m, l, r, A, T; scanf( %d%d , &n, &m); for (int i = 1; i <= n; ++i) scanf( %d , &V[i]); while (m--) { scanf( %d%d%d%f , &T, &l, &r, &x); if...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const long long N = 5e2 + 1; const long long M = 1e6 + 1; long long dp[2 * N][2 * N], min1[2 * N][2 * N], ar[2 * N], ar1[M]; bool check[2 * N][2 * N]; vector<long long> occur[N]; long long solve(long long l, long long r) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 11; string s; bool vis[maxn]; int n; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> s; n = s.length(); vector<pair<int, int> > vec, tmp; for (int i = 0; i < n; i++) { if (vec.empty() ||...
#include <bits/stdc++.h> int n, m, k; int main() { long long ans = 1; scanf( %d%d%d , &n, &m, &k); if (k == n) { int mid = k / 2 + (k & 1); for (int i = 0; i < mid; ++i) ans = (ans * m) % 1000000007; printf( %I64d , ans); } else if (!(k % 2) && k < n) printf( %d , m); els...
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; const int MM = 998244353; const long double PI = acos(-1); long long power(long long b, long long e, long long m) { if (e == 0) return 1; if (e & 1) return b * power(b * b % m, e / 2, m) % m; return power(b * b % m, e / 2, m);...
#include <bits/stdc++.h> using namespace std; int n, cnt[200200], mx = 0, val = 0, arr[200200], pr[200200], a[200200], ans; vector<int> lst, bd; void tryBuild(int i) { vector<int> lPos(400400, -1); lPos[200000] = 0; for (int i1 = 1; i1 <= n; i1++) { if (a[i1] == i) { arr[i1] = 1; ...
#include <bits/stdc++.h> using namespace std; using cat = long long; int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int W, N, M; cin >> W >> N >> M; vector<int> A(1 << W, 0); for (int i = 0; i < N; i++) { int a; cin >> a; A[a]++; ...
#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; } long long powmod(long long a, long long b, long long MOD) { long long ans = 1; while (b) { if (b % 2) ans = ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int main() { long double x1, y1, r1, x2, y2, r2; while (~scanf( %Lf%Lf%Lf%Lf%Lf%Lf , &x1, &y1, &r1, &x2, &y2, &r2)) { long double de = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); long double d = sqrt(de); if (...
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class t> using V = vector<t>; constexpr ll INF = 1e16; int n, m; ll dp[1502][1502]; int tab[1502][1502]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; ++i) for (int k = 1; k <= m; ++k) scanf( %d ,...
#include <bits/stdc++.h> using namespace std; bool alph[26] = {1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0}; bool check(string s) { for (int i = 0; i < s.length(); i++) if (!alph[s[i] - A ]) return false; return true; } int main() { string...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (n == 5) { cout << >...v << endl << v.<.. << endl << ..^.. << endl << >.... << endl << ..^.< << endl << 1 1 ; return 0; } if (n == ...
#include <bits/stdc++.h> using namespace std; int main() { long long tests, a, b, c; cin >> tests; while (tests--) { cin >> a >> b >> c; vector<long long> v; v.push_back(a); v.push_back(b); v.push_back(c); sort(v.begin(), v.end()); a = v[0]; b = v[1]; ...
#include <bits/stdc++.h> const int MAXN = 200000; using namespace std; inline int read() { int x = 0, w = 1; char c = ; while (c < 0 || c > 9 ) { c = getchar(); if (c == - ) w = -1; } while (c >= 0 && c <= 9 ) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n,m; int count=0; cin>>n>>m; map <int, int > ma; int a[n],b[m]; for(int i=0;i<n;i++) { cin>>a[i]; ma[a[i]]++...
#include <bits/stdc++.h> using namespace std; int n; struct Line { int k, b; } a[100100]; struct Fraction { int x, y; } b[100100]; int gcd(int x, int y) { if (x == 0) return y; else return gcd(y % x, x); } bool cmp(const Fraction &t1, const Fraction &t2) { if (t1.x != t...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; int n, a[N], b[N], c[N]; int Log[N]; int l[19][N], r[19][N]; struct rmq { int st[N][19], val[N]; int type; inline int Max(int x, int y) { return (val[x] < val[y]) ? y : x; } void build(int *b, int n, int _type) { typ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); char str[105]; scanf( %s , str); int l = 0, r = 0, u = 0, d = 0; for (int i = 0; i < n; i++) if (str[i] == L ) l++; else if (str[i] == R ) r++; else if (str[i] == U ) ...
#include <bits/stdc++.h> using namespace std; string a, b, c; long long n, x, y, z; pair<long long, long long> f[2000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> a >> b >> c; for (auto i : a) { f[i].first++; x = max(x, f[i].first); } ...
#include <bits/stdc++.h> using namespace std; namespace { int CC_; const double EPS = 1E-9; const double PI = 2 * acos(0.0); const long long MOD = 1000000007; template <class T> void DA(T i, T e) { while (i != e) { cout << Con>>( << ++CC_ << ) << *i++ << n ; } } template <clas...