func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); for (int a = 0; a < t; a++) { int n; scanf( %d , &n); string attack, prepend; cin >> attack; while (!attack.empty() and attack.back() == attack.front()) { prepend += attack.back(); ...
#include <bits/stdc++.h> using namespace std; inline void read(int& x) { char c = getchar(); x = 0; while (c < 0 || c > 9 ) c = getchar(); while (c <= 9 && c >= 0 ) x = x * 10 + c - 48, c = getchar(); return; } inline void write(int x) { if (!x) { putchar( 0 ); putchar(...
#include <bits/stdc++.h> using namespace std; const long long maxN = 3e2 + 2, N = 1e5 + 7, MOD = 1e9 + 7, Mod = 1e9 + 6, INF = 1LL << 56; long long n, m, k, x, y, z, dp[maxN][maxN], ans[maxN][maxN]; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cin >> n >> ...
#include <bits/stdc++.h> using namespace std; void RD(int &x) { scanf( %d , &x); } void RD(long long &x) { scanf( %I64d , &x); } void RD(double &x) { scanf( %lf , &x); } void RD(int &x, int &y) { scanf( %d%d , &x, &y); } void RD(long long &x, long long &y) { scanf( %I64d%I64d , &x, &y); } void RD(double &...
#include <algorithm> #include <iostream> #include <climits> #include <iomanip> #include <cstring> #include <string> #include <vector> #include <queue> #include <cmath> #include <set> #include <map> using namespace std; template <typename T> istream &operator>> (istream &is, vector<T> &ve...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; void solve() { long long v, c, vv, cc; cin >> v >> c >> vv >> cc; long long f = 0; if (cc > min(v, c)) { cout << NO n ; return; } v += c; vv += cc; if (vv > v) { cout << NO n ; retu...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, c = 0, p = 0; cin >> n; long long int s = (n / 2); for (int i = 1; i <= s; i++) { p += 8; c += (p * i); } cout << c << endl; } }
#include <bits/stdc++.h> namespace imzzy { class fastin { private: int _ch, _f; public: inline fastin &operator>>(char &c) { c = getchar(); return *this; } template <typename _Tp> inline fastin &operator>>(_Tp &_x) { _x = 0; while (!isdigit(_ch)) _f |= (_ch == 45...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; if (a <= b) cout << Second ; else if (a > b) cout << First ; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, f; char x; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { cin >> x; if (x != B && x != W && x != G ) f = 1; ...
#include <bits/stdc++.h> using namespace std; struct Edge { int u, v, w; Edge() {} Edge(int tu, int tv, int tw) : u(tu), v(tv), w(tw) {} int operator<(const Edge e1) const { return w > e1.w; } } p[100007]; int n, m; struct uset { int p[100007], sz[100007]; uset() {} uset(int n) { ...
#include <bits/stdc++.h> const int MOD = 1e9 + 7; using namespace std; signed main() { long long t, n; cin >> t >> n; long long a[n]; set<long long> s; long long c = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n - 1; i++) { c += t - a[i]; } ...
#include <bits/stdc++.h> using namespace std; const int N = 200100; const int M = 1000100; const long long mod = 998244353; int main() { ios::sync_with_stdio(false); int q; cin >> q; while (q--) { string s; cin >> s; int l = 0, r = 0, u = 0, d = 0; for (int i = 0; i < s...
#include <bits/stdc++.h> using namespace std; int main() { int t = 1; while (t--) { long long n, min, cnt = 0, x; cin >> n; vector<long long> v(n); for (int i = 0; i < n; ++i) cin >> v[i]; min = *min_element(v.begin(), v.end()); for (int i = 0; i < n; ++i) { if (m...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { string a, b, c; cin >> a >> b >> c; bool ok = true; for (int i = 0; i < a.size(); i++) { ok &= a[i] == c[i] || b[i] == c[i]; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 5; int fa[maxn]; int m, n, q, i, x, y; int getfa(int x) { if (x == fa[x]) return x; return fa[x] = getfa(fa[x]); } int main() { scanf( %d%d%d , &n, &m, &q); for (i = 1; i <= m + n; i++) fa[i] = i; for (i = 1; i <= q; ...
#include <bits/stdc++.h> using namespace std; int n, m; int arr[300001]; bool check(int val) { if (val < 0) return false; if (val >= m - 1) return true; int prev = 0; for (int i = int(1); i <= int(n); i++) { if (arr[i] + val < prev) return false; int r = (arr[i] + val) % m; if ...
#include <bits/stdc++.h> using namespace std; const int Maxn = 100100; const int INF = 0x7f7f7f7f; const double eps = 1e-8; const double pi = 3.1415926535897932384626433832795; int main() { int n; ios::sync_with_stdio(0); cin >> n; cout << n * n / 4 << endl; for (int i = 1; i <= n / 2; i...
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << , ; err(++it, args...); } namespace fastIO { bool IOerror = 0; ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:60000000 ) using namespace std; const long double eps = 1e-9; const int inf = (1 << 30) - 1; const long long inf64 = ((long long)1 << 62) - 1; const long double pi = 3.1415926535897932384626433832795; template <class T> T sqr(T x) { return x *...
#include <bits/stdc++.h> inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } inline void sub(long long &a, long long b) { a -= b; if (a < 0) a += 1000000007; } inline void add(long long &a, long long b) { a += b; if (a >= 1000000007) a -= 1000000007; } template <...
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 10; int mod = 1e9 + 7; long long power(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; } long long INV(long long a) { return ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( inline , fast-math , unroll-loops , no-stack-protector ) #pragma GCC target( popcnt,tune=native ) using namespace std; namespace io { const int SIZE = (1 << 21) + 1; char ibuf[SIZE], *iS, *iT, obuf[SIZE...
#include <bits/stdc++.h> using namespace std; int main() { double t, y, j, n; cin >> t; while (t--) { cin >> n; j = n * n; j = j - 4 * n; if (j >= 0) { double x = sqrt(j); if ((-n - x) > 0) cout << N ; else { x = (n - x) / 2; ...
#include <bits/stdc++.h> using namespace std; constexpr long long INF = 2e18; constexpr long long MOD = 1e9 + 7; constexpr long long MAXN = 2e5 + 3; void solve() { long long n; cin >> n; map<long long, long long> m; long long ans = 0; for (long long i = 1; i <= n; ++i) { long long x;...
#include <bits/stdc++.h> using namespace std; float S, a, b, c; int main() { ios ::sync_with_stdio(false); cin >> S >> a >> b >> c; float sum = a + b + c; if (sum == 0) cout << 0 0 0 ; else printf( %.12f %.12f %.12f , a * S / sum, b * S / sum, c * S / sum); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 20; const long long mod = 1e9 + 7; int w[(maxn * 4) << 2], n; vector<pair<int, int> > col[(maxn * 4) << 2]; int query(int L, int R, int l, int r, int rt); void pushup(int rt) { w[rt] = w[rt << 1] + w[rt << 1 | 1]; } void pushdown(int r...
#include <bits/stdc++.h> using namespace std; const int MM = 120000; vector<int> G[MM], T[MM]; int P[MM], L[MM]; void dfs(int u, int par) { P[u] = par; if (par != -1) L[u] = L[par] + 1; for (auto v : G[u]) { if (v != par) { dfs(v, u); } } } int N, K; bool rip = 0; v...
#include <bits/stdc++.h> using namespace std; int get(int x) { int cnt = 0; while (x >= 10) { int sum = 0; while (x) { sum += x % 10; x /= 10; } cnt++; x = sum; } return cnt; } int main() { string s; cin >> s; if (s.size() == 1) cou...
#include <bits/stdc++.h> using namespace std; void ga(int N, int *A) { for (int i(0); i < N; i++) scanf( %d , A + i); } long long pw(long long n, long long k, long long MOD) { long long r(1); while (k) { if (k & 1) r = r * n >= MOD ? r * n % MOD + MOD : r * n; n = n * n >= MOD ? n * n % ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long ans = 1; ans += (3 * n * (n + 1)); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, k; cin >> n >> k; long long int ans = k / n; long long int t1 = ans * n; if (t1 < k) ans++; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(move(x)); return move(v); } void err(vector<string>::iterator it) {} template <typename T, typename... Args> ...
#include <bits/stdc++.h> using namespace std; int a[1000005], dp[1000005]; int main() { int n, i, j; while (~scanf( %d , &n)) { memset(dp, 0, sizeof(dp)); for (i = 0; i < n; i++) { scanf( %d , &a[i]); } for (i = 0; i < n; i++) { dp[a[i]] = max(dp[a[i]], 1); ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { int n; long long m; cin >> n >> m; m -= 1; vector<int> xs; for (int i = 0; i < n; i++) { xs.push_back(-1); } int i = 0; int u = 0; int v = n - 1; while (u <= v) { long long h = (1L...
#include <bits/stdc++.h> using namespace std; long long p[222222]; long long sum[222222]; long long max1[222222]; long long max2[222222]; long long get(long long l, long long r) { long long t = sum[r]; if (l >= 1) { t -= sum[l - 1]; } return t; } int main() { long long n, k; ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 9223000000000000000; struct DATA { long long v; long long c; long double p; }; long long n, l; DATA data[31]; bool cmp(DATA x, DATA y) { return x.p < y.p; } void init() { scanf( %lld%lld , &n, &l); for (int i = 1; i...
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ld = long double; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T1, typename T2> ostream &operator<<(ostream &out, const pair<T1, T2> &item) {...
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); while (t--) { int n; scanf( %d , &n); long long a[100001]; long long y = 0; long long thissum = 0, maxsum = 0; int count = 1; for (int i = 0; i < n; i++) { scanf( %lld , &...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { long long x, y; cin >> x >> y; if (x == y + 1) { cout << NO n ; } else { cout << YES n ; } } return 0; ...
#include <bits/stdc++.h> using namespace std; long long int recpow(long long int base, long long int exp) { long long int result = 1; while (exp > 0) { if (exp & 1) result = ((long long int)result * base) % 1000000007; base = ((long long int)(base % 1000000007) * (base % 1000000007)) %...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int N; vector<int> adj[MAXN]; map<int, int> dp[MAXN]; int cid; map<vector<int>, int> idmp; int getid(vector<int> v) { if (idmp.count(v)) { return idmp[v]; } return idmp[v] = cid++; } int dfs(int x, int p); v...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int t = 1; while (t--) { int n; cin >> n; map<int, vector<int>> m; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; m[v[i]...
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; Point() {} Point(double x, double y) : x(x), y(y) {} Point operator+(const Point& other) const { return {x + other.x, y + other.y}; } Point operator-(const Point& other) const { return {x - other.x, y - oth...
#include <bits/stdc++.h> using namespace std; int n, t0 = 0, t1 = 0, a[200009], h = 100000, mx = 0; string s; void f(char x) { if (x == 0 ) t0++; else t1++; } int main() { cin >> n >> s; for (int i = 0; i < n; i++) { f(s[i]); a[100000 + t1 - t0] = i; if (t0 == ...
#include <bits/stdc++.h> using namespace std; namespace Flandre_Scarlet { long long mod; class Matrix { private: long long a[5][5]; public: long long n; Matrix() { memset(a, 0, sizeof(a)); n = 0; } Matrix(long long _n) { memset(a, 0, sizeof(a)); n = _n; }...
#include <bits/stdc++.h> using namespace std; int grid[201][201]{0}; int main() { string s; cin >> s; int x = 100; int y = 100; grid[x][y] = true; for (auto& it : s) { switch (it) { case L : x--; break; case R : x++; break; ...
#include <bits/stdc++.h> using namespace std; int n, _m, ans = 0; map<string, int> m; string s[1010], u[1010], v[1010]; int main() { cin >> n >> _m; for (int i = 1; i <= n; i++) cin >> s[i]; sort(s + 1, s + n + 1); for (int i = 1; i <= n; i++) m[s[i]] = i - 1; for (int i = 1; i <= _m; i++)...
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) using namespace std; const int N = 1e5 + 1; vector<int> co[N]; long long ans = 0; void dfs(int x, int p) { ans += (int)co[x].size() * ((int)co[x].size() - 1) / 2; for (auto y : co[x]) { if (y == p) continue; dfs(y, x); } } int m...
#include <bits/stdc++.h> using namespace std; int n; vector<double> first, second; double eps = 0.0000001; double ai; int main() { std::ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { cin >> ai; first.push_back(ai); } for (int i = 0; i < n; i++) { c...
#include <bits/stdc++.h> using namespace std; int n, c[8005][8005], fal[8005], dp[8005], len[8005]; char s[8005]; void Init(char *s, int n, int *c) { fal[1] = 0, fal[2] = 1; for (int i = 2; i <= n; i++) { int j = fal[i]; while (j && s[i] != s[j]) j = fal[j]; fal[i + 1] = j + 1; } ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const long long MOD = 1e9 + 7; long long h[26][N], p[N]; int a[30], b[30]; char s[N + 10]; long long get(int i, int l, int r) { return (h[i][r] - h[i][l - 1] * p[r - l + 1]) % MOD; } int main() { int n, m, x, y, len; whi...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, q[5000]; cin >> n >> a >> b; for (int i = 0; i < n; i++) cin >> q[i]; sort(q, q + n); cout << q[b] - q[b - 1]; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX_NM = 1000 * 1000; int dl; char S[MAX_NM]; void dodaj(char l, int x) { while (x--) { dl++; S[dl] = l; } } int main() { int n, m, k; cin >> n >> m >> k; if (k > 4 * n * m - 2 * n - 2 * m) { cout << NO n ; ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,unroll-loops ) #pragma GCC target( avx,avx2,fma ) using namespace std; const long long mod1 = 998244353; const long long mod = 1e9 + 7; long long mod_mul(long long a, long long b) { a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mo...
#include <bits/stdc++.h> using namespace std; int n, m, f[50010]; struct node { int f[12], g[12], size; } a[50010]; struct cmp { bool operator()(node a, node b) { for (int i = 1; i <= m; i++) if (a.f[i] > b.g[i]) return 0; return 1; } }; multiset<node, cmp> q; inline void...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } struct State { int delta; map<int, int> pos; map<int, int> neg; set<pair<int, pair<int, int>>> matches; void init() { delta = 0; pos.clear(); neg.clear(); matches....
#include <bits/stdc++.h> using namespace std; int main() { string x, t; getline(cin, x); string temp = ; int index = -1; for (int i = 0; i < x.size(); ++i) { if (x[i] == = ) index = i; } index += 2; for (int i = index; i < x.size(); ++i) temp.push_back(x[i]); int n = sto...
#include <bits/stdc++.h> using namespace std; void setIO(string NAME) {} inline long long gI() { char c = getchar(); while ((c < 0 || c > 9 ) && c != - ) c = getchar(); long long flag = 1, p = 0; if (c == - ) flag = -1, c = getchar(); while (c >= 0 && c <= 9 ) p = p * 10 + (c - 0 ), c...
#include <bits/stdc++.h> const int dx[] = {0, -1, 0, 1, -1, 1, 1, -1, -2, -2, 2, 2, -1, -1, 1, 1}; const int dy[] = {-1, 0, 1, 0, 1, 1, -1, -1, -1, 1, -1, 1, -2, 2, -2, 2}; using namespace std; int main(int argc, char const *argv[]) { int n, m; scanf( %d %d , &n, &m); while (n) { printf( 0 ); ...
#include <bits/stdc++.h> using namespace std; struct ACfixed { static const int ASZ = 10; struct node { array<int, ASZ> to; int link = -1; int tlink = -1; int id = -1; }; vector<node> d = {{}}; int add(string s, int id) { int v = 0; for (auto C : s) { ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 5; const int INF = 0x7fffffff; bool p(long long a) { for (long long i = 2; i <= sqrt(a); i++) { if (a % i == 0) return 0; } return 1; } int main() { int n; cin >> n; int c = n; while (!p(c)) { ...
#include <bits/stdc++.h> using namespace std; int f[35][1005][5]; void preprocess() { int i, j, k, l; for (i = 0; i <= 1000; i++) f[0][i][0] = f[0][i][1] = f[0][i][2] = f[0][i][3] = 0; i = 0; f[0][i][0] = f[0][i][1] = f[0][i][2] = f[0][i][3] = 1; for (i = 1; i < 31; i++) { f[i][0][...
#include <bits/stdc++.h> using namespace std; const int N = 200005; const int G = N; set<pair<int, int> > S; set<int> a[N]; int ans[N]; bool was[N]; vector<int> C[G + G]; int n, m; bool solve() { while (!S.empty()) { int idx = S.begin()->second; if (a[idx].empty()) { cerr << ...
#include <bits/stdc++.h> using namespace std; int n, m; char an[505]; vector<int> b, other[5]; int A[505][505], visited[505], ans[5]; int dfs(int node, int flag) { int sz = 1; visited[node] = flag; other[flag].push_back(node); for (int i = 0; i < n; ++i) if (!visited[i] and A[node][i])...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; int dx[] = {-1, 1, 0, 0, -1, 1, -1, 1}; int dy[] = {0, 0, 1, -1, 1, -1, -1, 1}; void fast() { ios_base::sync_with_stdio(0); cin.tie(0); } long long gcd(long long x, long long y) { if (!y) return x; return gcd(y, x % y);...
#include <bits/stdc++.h> using namespace std; template <typename Tp> inline void outarr(Tp _begin, Tp _end, const char* _delim = ) { for (Tp current = _begin; current != _end; ++current) { std::cout << *current << _delim; } std::cout << n ; } using ll = int64_t; using pii = std::pair<...
#include <bits/stdc++.h> using namespace std; long long n; const long long mod = 1000000007LL; long long dp[35][35][2]; void init() { int tmp; scanf( %d , &tmp); n = tmp; } void process() { dp[32][0][0] = 1; for (int i = 32; i > 0; i--) { for (int j = 0; j <= 32 - i; j++) { ...
#include <bits/stdc++.h> using namespace std; const int L = 1e5 + 1; long long sofar[L], out[L]; struct node { long long l, r, q; }; long long ans = 0, counter[3000002], k; bool comp(node x, node y) { return x.r < y.r; } void add(long long val) { ans += counter[val ^ k]; counter[val]++; ...
#include<bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define endl n typedef long long LL; const int maxn = 2e5 + 5; int cnt, id, a[maxn], hea[maxn], siz[maxn], dfsid[maxn], sum[maxn]; map<int, int> exist, tol; struct node{ int v...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } template <class T1, class T2> struct cmpf { bool rev; inline bool operator()(const pair<T1, T2>& a, const pair<T1, T2>& b) const { return (a.first < b.first) ^ rev; } cmp...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int sq = sqrt(n); if (n % sq == 0) { cout << sq << << n / sq; } else { int i = 0; while (++i) { if (n % (sq - i) == 0) { cout << sq - i << << n / (sq - i); break; ...
#include <bits/stdc++.h> using namespace std; const int p = 1e9 + 7; long long binpow(long long a, long long b, long long mod) { long long res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res % mod; } const int dx[] = {1, -1, 0, 0}; ...
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f3f3f3f3f; struct port { int id; int x, y; }; void solve() { int n, m, sx, sy, dx, dy; cin >> n >> m >> sx >> sy >> dx >> dy; vector<port> p; for (int i = 0, x, y; i < m; ++i) { cin >> x >> y; p.pu...
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = RDLU ; long long ln, lk, lm; void etp(bool f = 0) { puts(f ? Yes : No ); exit(0); } void addmod(int &x, int y, int mod = 1000000007) { assert(y >=...
#include <bits/stdc++.h> using namespace std; int dp[5002][5002][2]; vector<vector<int> > adj(12345); int subtree[5004], c[5003], d[5003], dp1[5003], dp2[5003]; int dfs(int u) { int i, j, k, sumi = 1; subtree[u] = 1; for (i = 0; i < adj[u].size(); i++) { dfs(adj[u][i]); subtree[u] += s...
#include <bits/stdc++.h> using namespace std; bool s[100005]; int main() { int n; cin >> n; n *= 2; int ans = 0, rst = 0; ; while (n--) { int tmp; cin >> tmp; if (s[tmp]) ans -= 1; else s[tmp] = 1, ans++; rst = max(rst, ans); } cout << ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; vector<bool> vt(100005); vector<int> side(100005, 0b111); set<int> G[100005]; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; G[a].insert(b); G[b].insert(a); } bool firs...
#include <bits/stdc++.h> using namespace std; template <class T> inline int size(const T& c) { return c.size(); } using namespace std; const int maxn = 100000 + 10; struct student { int a; int b; int cs; } a[maxn]; int n, p, k, k2; long long f[maxn]; long long sumgrey, sumplease, r...
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; long long gcd(long long a, long long b) { while (b > 0) { long long p = a % b; a = b; b = p; } return a; } long long bexp(long long a, int b) { long long res = 1; while (b > 0) { if (b & 1) res = r...
#include <bits/stdc++.h> using namespace std; const int maxn = 1.1e5; queue<int> Q[2]; vector<int> E[maxn]; int n, m, cnt, in[maxn], f[maxn]; signed main() { scanf( %d%d , &n, &m); for (int i = 0; i < n; ++i) scanf( %d , f + i); for (int i = 1, x, y; i <= m; ++i) scanf( %d%d , &x, &y), ++i...
#include <bits/stdc++.h> using namespace std; struct Seller { long long first, second, diff; } a[200005]; bool cmp(Seller p, Seller q) { return (p.diff > q.diff); } int main() { long long n, m, i, j, ans = 0; cin >> n >> m; for (i = 0; i < n; i++) cin >> a[i].first; for (i = 0; i < n; i++)...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c, d; scanf( %d %d %d %d %d , &n, &a, &b, &c, &d); long long ans = 0; for (int i = 1; i <= n; i++) { int sum = a + b + i; if (sum - a - c <= 0 || sum - a - c > n) continue; if (sum - b - d <= 0 || sum - b - d >...
#include <bits/stdc++.h> using namespace std; int N, uz[1005], kay; char ar[1005][1005], k[1005]; int kontrol(int a, int say) { for (int i = 1; i <= uz[a] - say + 1; i++) { if (ar[a][i] == k[1]) { int m = 1, j, k1; for (j = i + 1, k1 = 2; j <= uz[a] && k1 <= say && m; j++, k1++) ...
#include <bits/stdc++.h> using namespace std; char ch[100001]; int N, n, m; long long a[1 << 20], b[1 << 20]; int g[21][100001]; void FWT(long long p[], int flag) { int temp = N; for (int i = 2; i <= temp; i *= 2) { int t = i / 2; for (int j = 0; j < temp; j += i) { for (int k = ...
#include <bits/stdc++.h> using namespace std; int main() { vector<pair<long long int, long long int> > v; long long int n, x, c = 0; cin >> n; for (int i = 0; i < n; i++) { long long int a, b; cin >> a >> b; v.push_back(make_pair(a, b)); } sort(v.begin(), v.end()); long...
#include <bits/stdc++.h> using namespace std; const int N = 157; int f[N][N]; int main() { int n; scanf( %d , &n); f[0][0] = 1; f[1][0] = 0; f[1][1] = 1; for (int i = 2; i <= n; i++) { for (int j = 0; j <= i - 2; j++) f[i][j] = f[i - 2][j]; for (int j = 0; j <= i - 1; j++) { ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:64000000 ) int n; pair<int, int> a[1 << 10]; int b[1 << 10]; int ans[1 << 10][1 << 10]; int len[1 << 10]; void answer(string s) { puts(s.c_str()); if (s == NO ) exit(0); for (int i = 0; i < n; ++i) { for (in...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MAX = 2e6 + 5; int ftree[MAX] = {0}; int sum[MAX] = {0}; int query(int node) { int sum = 0; while (node > 0) { sum += ftree[node]; node -= (node & -node); } ...
#include <bits/stdc++.h> using namespace std; const int Maxn = 1000000; const int Inf = 0x3f3f3f3f; int n, m, k; pair<int, int> edge[Maxn + 5]; int a[Maxn + 5]; map<pair<int, int>, int> mp; int deg[Maxn + 5], sz[Maxn + 5], st[Maxn + 5], col[Maxn + 5]; vector<pair<int, int> > g[Maxn + 5]; int ans[Max...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > vertices; vector<pair<int, int> > edges; int main() { int v; cin >> v; int a, b; queue<int> q; for (int i = 0; i < v; i++) { cin >> a >> b; vertices.push_back(make_pair(a, b)); if (a == 1) { q.pus...
#include <bits/stdc++.h> using std::max; const int N = 3e5 + 5; template <typename T> void read(T &x) { bool neg = false; unsigned char c = getchar(); for (; (c ^ 48) > 9; c = getchar()) if (c == - ) neg = true; for (x = 0; (c ^ 48) < 10; c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);...
#include <bits/stdc++.h> using namespace std; string s[6] = { 170 , 020 , 200 , 110 , 050 , 080 }; int main() { int n; cin >> n; if (n < 3) cout << -1; else if (n == 3) cout << 210; else { cout << 1; for (int i = 0; i < n - 4; i++) cout << 0; cout << s[n % 6]...
#include <bits/stdc++.h> using namespace std; string s1[10], s2[10], score[10]; map<string, int> mp; string name[10]; int a[10][10]; bool better(int x, int y) { int n; int sx = 0, px = 0, mx = 0, sy = 0, py = 0, my = 0; for (n = 0; n < 4; n++) if (n != x) { if (a[x][n] > a[n][x]) ...
#include <bits/stdc++.h> using namespace ::std; const long double PI = acos(-1); const long long MOD = 1000000000 + 7; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long add(long long a, long long b, long long m = MOD) { if (a >= m) a %= m; if (b >= m) b %= m; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, f = 0; cin >> n; for (int i = 1; i < 50; i++) { if ((i * (i + 1)) / 2 == n) { f = 1; break; } if (i > n) break; } if (f) cout << YES << endl; else cout << NO << endl; retur...
#include <bits/stdc++.h> using namespace std; template <class T> inline T sqr(const T &x) { return x * x; } inline long long sqr(int x) { return sqr<long long>(x); } template <class T> T binpow(const T &a, long long n) { return n == 0 ? 1 : sqr(binpow(a, n / 2)) * (n % 2 ? a : 1); } long long ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long MAXN = 1e5 + 3; const long long inf = 2e9; long long max(long long a, long long b) { if (a > b) return a; else return b; } long long min(long long a, long long b) { if (a < b) return ...
#include <bits/stdc++.h> using namespace std; const int N = 100010; struct node { int c, h, i; friend bool operator<(const node &a, const node &b) { if (a.c != b.c) return a.c < b.c; return a.h > b.h; } } t[N]; struct node2 { int s, t, i, size; friend bool operator<(const node2...
#include <bits/stdc++.h> using namespace std; struct congressman { int votes; int last_vote; int nr_of_order; bool operator<(const congressman &other) const { if (votes == other.votes) return last_vote > other.last_vote; return votes < other.votes; }; } v[105]; int n, k, m, a, po...