func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; string s[10100]; string sep; bool u[10100] = {false}; vector<string> str; string make(pair<string, string> p) { return ((p.first + sep + p.second) < (p.second + sep + p.first)) ? (p.first + sep + p.second) : (p.second + sep + p....
#include <bits/stdc++.h> using namespace std; template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; int n, m, k; int arr[70][70]; int dp[71][71][36][71]; int func(int s, int e, int cnd, int rem) { if (cnd >= m / 2) { return -1e9; } if (s == n) { if (rem == 0...
#include <bits/stdc++.h> using namespace std; int x, y; char a[1001][1001]; int n, c[1000000], ni[5001][5001]; bool vis[1001][1001], b[1000000]; int e[] = {1, -1, 0, 0}; int r[] = {0, 0, -1, 1}; void dfs(int i, int j, int n) { vis[i][j] = true; ni[i][j] = n; c[n]++; for (int g = 0; g < 4...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } return f == -...
#include <bits/stdc++.h> using namespace std; const int N = 10; const int inf = 2000000000; int f(int first, int second, int t[N]) { int a[N], b[N]; for (int i = 0; i < N; i++) { a[i] = b[i] = t[i]; } a[first]--; b[second]--; if (a[first] < 0 || b[second] < 0) { return -1; ...
#include <bits/stdc++.h> using namespace std; const string nameFile = test ; ifstream in(nameFile + .in ); ofstream out(nameFile + .out ); const int nmax = 4e3; int n, nrGond; char ch; int a[nmax + 2][nmax + 2]; int dp[802][nmax + 2]; char buffer[10000]; inline int getCost(int i, int j) { r...
#include <bits/stdc++.h> using namespace std; int n, ta; long double x[1005][1005], tb, tc, td; vector<int> y; vector<long double> z; bool used[1005]; int main() { scanf( %d , &n); for (int a = 0; a < n; a++) for (int b = 0; b < n; b++) { scanf( %d , &ta); x[a][b] = ta; ...
#include <bits/stdc++.h> using namespace std; int i, j, n, m, a, b, tmp; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { cin >> n >> m >> a >> b; tmp = n * m / gcd(n, m); cout << b / tmp - (a - 1) / tmp; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 10005; vector<int> gr[N]; int ans = 0; void dfs(int v, int p = -1) { for (int to : gr[v]) if (to != p) { dfs(to, v); ans += (gr[to].size() - 1); } ans += ((gr[v].size() - (v != 1)) * (gr[v].size() - 1 - (v != 1))) ...
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using u64 = uint64_t; using u32 = uint32_t; struct Node { int idx; Node *left = nullptr, *right = nullptr; }; int depth(Node* v) { if (!v) return 0; return max(depth(v->left), depth(v->right)) + 1; } int main() { ios...
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int main() { fastIO int t; cin>>t; while(t--) { int x,y; cin>>x>>y; if (x==y) cout<<x+y<< ...
#include <bits/stdc++.h> using namespace std; const int M = 500005; int n, m, q; struct Edge { Edge() {} Edge(int u_, int v_) : u(u_), v(v_) {} int u, v; bool operator<(const Edge &a) const { if (v != a.v) return v < a.v; return u > a.u; } } edge[M << 1]; int fa[M]; int get...
#include <bits/stdc++.h> using namespace std; inline void print(char pt) { printf( %c n , pt); } inline void print(int pt) { printf( %d n , pt); } inline void print(long long pt) { printf( %I64d n , pt); } inline void print(double pt) { printf( %.20f n , pt); } inline void print(char pt[]) { printf( %s n , ...
#include <bits/stdc++.h> using namespace std; int T, n, m; int x[15]; char s[15][10005]; int v[10005], cnt[25], tmp[25]; int P[10005]; int ans; void dfs(int p, int sum) { if (p == n + 1) { int cur = m, res = sum; for (int i = 20; i >= 0; i--) { res += (i - 10) * (cur * 2 - cnt[i]...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; struct edge { int v, nxt; } g[N]; int tot = 0, head[N]; inline void add(int u, int v) { g[++tot] = edge{v, head[u]}; head[u] = tot; } int n, m, fa[N], sz[N], son[N], top[N], dfn[N], tpos[N], dep[N], cnt = 0; inline void ...
#include <bits/stdc++.h> using namespace std; const int N = 2005; string s, ans; bool f, at; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> s; int n = s.size(); f = at = false; for (int i = 0; i < n; i++) { if (i < n - 3 && s[i] == d && s[i + 1] == o && ...
#include <bits/stdc++.h> using namespace std; const int M = 3e5 + 10; const long long inf = 1e18 + 10; const long long mod = 1e1; long long a[M], p[M], dp[3][M]; int main() { int t; scanf( %d , &t); while (t--) { int n; scanf( %d , &n); for (int i = 0; i <= n; i++) dp[0][i] = d...
#include <bits/stdc++.h> using namespace std; const int Nmax = 2e5 + 5; int A[Nmax], start[Nmax]; long long cnt[Nmax]; bool cycle[Nmax]; int go[Nmax], where[Nmax], visited[Nmax]; vector<int> active[Nmax], when[Nmax]; int zz[Nmax], ans[Nmax]; int nrcomp, n, q, Nr; vector<int> cyc[Nmax]; vector<int>...
#include<bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int,int>; #define ff first #define se second #define pb push_back #define all(x) (x).begin(),(x).end() const int mod = 1e9+7; const int inf = 1e9; const int mx = 1e6+5; #define exitYes {cout<< Yes n ; retu...
#include <bits/stdc++.h> using namespace std; struct pr { int type; int k; char dir; }; struct point { long long first; long long second; }; bool cmp(const point &a, const point &b) { return sqrt(a.first * a.first + a.second * a.second) < sqrt(b.first * b.first + b.second ...
#include<iostream> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int a; cin >> a; cout << 2-a*a; return 0; }
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - 0 ; c = getchar(); } x *= f; } const int N = ...
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > points; vector<pair<long long, pair<long long, long long> > > areas; map<long long, vector<long long> > pm; int main() { int n, m, k; scanf( %i%i%i , &n, &m, &k); for (int i = 0; i < n; i++) { int x, y; s...
#include <bits/stdc++.h> using namespace std; int arr[5010], n; int solve(int l, int r, int h) { int i, j, k; if (l > r) return 0; int ans = 0, val = 1000000007; for (i = l; i <= r; i++) val = min(val, arr[i]); int pos = l - 1; ans = val - h; for (i = l; i <= r; i++) { if (arr[i]...
#include <bits/stdc++.h> using namespace std; int n, u, r; vector<int> a, b, k, p; long long s, current; int lastChoice; void input(); void solve(); void go(int k); int main() { input(); solve(); } void input() { cin >> n >> u >> r; a.resize(n); b.resize(n); k.resize(n); ...
#include <bits/stdc++.h> using namespace std; int ans[3][1010], dp[3][1010][55][55]; int n, p, k, r, s, x; int teto(int a, int b) { return (a + b - 1) / b; } int main() { while (scanf( %d %d %d , &n, &p, &k) != EOF) { memset(ans, 0, sizeof(ans)); scanf( %d , &r); for (int i = 0; i < r; i...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n; int a[maxn]; long long dp[maxn][3][3]; int main(void) { scanf( %d , &n); for (int i = 0; i < n - 1; i++) scanf( %d , &a[i]); for (int i = 1; i < n; i++) { if (a[i - 1] == 0) continue; int b = a[i - 1]; ...
#include <bits/stdc++.h> const int N = 25, Mod = 1e6 + 3; const int n = 11; int y[N], k, inv[Mod + 2]; int fm[] = {404910, 950915, 220896, 410947, 30845, 962989, 30845, 410947, 220896, 950915, 404910}; inline int po(int x, int y) { int r = 1; while (y) { if (y & 1) r = 1ll * r * x...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) #pragma warning(disable : 4996 4018) using namespace std; long long n, k, p; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> n >> k >> p; if ((n & 1) && k) { n--; k--; } while (p--) { l...
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e5 + 5; long long n, q, a[maxn], c[maxn]; long long read() { long long res = 0, f = 1; char ch; do { ch = getchar(); if (ch == - ) f = -1; } while (!isdigit(ch)); do { res = res * 10 + ch - 0 ; ch...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 * 100 * 2 + 152; long long n, m, x, y, z, q, mark[maxn], k = 1, par1[maxn], sum[maxn], h[maxn]; pair<long long, long long> par[17][maxn]; vector<pair<long long, long long> > v[maxn]; pair<long long, pair<long long, long long> > edg[maxn]; ...
#include <bits/stdc++.h> using namespace std; const int N = 5e4 + 5, inf = 0x3f3f3f3f; int n, front, x, ans = -inf, nxt; vector<int> interact(int _) { printf( ? %d n , _); fflush(stdout); int a, b; scanf( %d%d , &a, &b); return vector<int>({a, b}); } void give(int _) { printf( ! %d n...
#include <bits/stdc++.h> using namespace std; bool cmp(pair<int, int> p1, pair<int, int> p2) { return p2.second < p1.second; } vector<pair<int, int> > k; vector<pair<int, int> > c; vector<pair<int, int> > ans; int main() { int n, v; int t, p; cin >> n >> v; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5 + 5; const long long mod = 10000000000000007; const long long nary = 9; long long a; int ans[100], n; int main() { while (scanf( %d%I64d , &n, &a) != EOF) { n = 0; while (a > 0) { int d = (int)(a % 10); a /=...
#include <bits/stdc++.h> using namespace std; bool square(long long g) { long long k = sqrt(g); return k * k == g; } int main() { int i, q, k; long long l, r, val; set<long long> s; for (i = 2; i <= 1000000; i++) { int op = 18.0 / log10(i); val = 1LL * i * i; for (k = 3...
#include <bits/stdc++.h> using namespace std; int a[5001], n; int dfs(int l, int r) { int Min = a[l], ans = 0; for (int i = l + 1; i <= r; i++) Min = min(Min, a[i]); ans = Min; for (int i = l; i <= r; i++) a[i] -= Min; for (int i = l; i <= r; i++) if (a[i]) { int tmp = i + 1; ...
#include <bits/stdc++.h> using namespace std; int N; double A[100001]; double dp[100001]; int main() { scanf( %d , &N); for (int i = 1; i <= N; i++) scanf( %lf , A + i); double ans = 0.0; for (int i = 1; i <= N; i++) ans += A[i] + 2 * (dp[i] = (dp[i - 1] + A[i - 1]) * A[i]); printf( ...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 10, M = 2e5 + 10; struct upd { int r, s, t, id; } t; vector<upd> v[M]; struct edge { int x, y; } e[M]; int ans[M], n, m, qi, f[N][N]; signed main() { int x; scanf( %d %d %d , &n, &m, &qi); for (register int i = (1); ...
#include <bits/stdc++.h> using uint = unsigned int; using cat = long long; using dbl = long double; constexpr dbl pi = 3.14159265358979323846; using namespace std; cat pw(cat a, cat e, cat mod) { if (e <= 0) return 1; cat x = pw(a, e / 2, mod); x = x * x % mod; return (e & 1) ? x * a % mod :...
#include <bits/stdc++.h> using namespace std; template <typename T> void print(vector<T>& v) { for (int i = 0; i < v.size(); i++) { cout << v[i] << ; } cout << n ; } vector<int> z_function(string s) { int n = (int)s.length(); vector<int> z(n); for (int i = 1, l = 0, r = 0; i...
#include <bits/stdc++.h> using namespace std; const long long MAX = 100010; const long long MOD = 1000000007; const long long INF = (long long)1e9; const long long LLINF = 0x3f3f3f3f3f3f3f3f; const long double EPS = 1e-7; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.t...
#include <bits/stdc++.h> using namespace std; using ll = long long; struct cmp { bool operator()(const pair<ll, ll>& a, const pair<ll, ll>& b) { return abs(a.first - a.second) > abs(b.first - b.second); } }; int main() { ll n; cin >> n; vector<pair<ll, ll>> v(n); multiset<pair<ll...
#include <bits/stdc++.h> using namespace std; const int maxn = 404; int n, m; vector<int> g[maxn]; vector<int> q, G; int dis[maxn][maxn]; long double p[maxn], P; pair<long double, int> mxp[maxn]; long double ans; void bfs(int s) { dis[s][s] = 0; q.resize(0); q.push_back(s); for (int ...
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 5; const int inf = 6969696; int dp[N][N]; int a[N]; int e[N]; int n, k; int go(int pos, int left) { if (left < 0) return -inf; if (pos == n) return 0; int &cur = dp[pos][left]; if (cur != -1) return cur; cur = go(pos +...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s = abcd ; string ans = ; int m = n / 4; for (int i = 0; i < m; i++) { ans += s; } int z = n % 4; for (int i = 0; i < z; i++) { ans += s[i]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int INF = (1LL << 30) - 1; const long long int LINF = (1LL << 62) - 1; const int NMAX = (1e5) + 5; int N, M; int pile[NMAX]; bool check(long long int time) { int i, k; long long int curr; int P[NMAX]; memcpy(P, pile, sizeof(pile)); fo...
#include <bits/stdc++.h> using namespace std; int n, ar[200001], f[10001], g[21][21], f1[10001]; int main() { ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); cin >> n; for (int i = 0; i < n * n; i++) { cin >> ar[i]; f[ar[i]]++; f1[ar[i]]++; } if (n & 1) { int wh...
#include <bits/stdc++.h> using namespace std; long long lis(long long arr[], long long n) { long long lis[n]; lis[0] = 1; for (long long i = 1; i < n; i++) { lis[i] = 1; for (long long j = 0; j < i; j++) if (arr[i] >= arr[j] && lis[i] < lis[j] + 1) lis[i] = lis[j] + 1; } retu...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, i, j, ma; cin >> n; int arr[n], b[n]; for (i = 0; i < n; i++) { cin >> arr[i]; } ma = arr[n - 1]; b[n - 1] = 0; for (i = n - 2; i >= 0; i--) { if (arr[i] <= ma) { b[i] = (ma - arr[i]) + 1; ...
#include <bits/stdc++.h> using namespace std; constexpr int kN = int(1E7 + 10); vector<long long int> prime; int l[kN], mu[kN], s[kN]; long long int n; void pre() { mu[1] = 1; for (int i = 2; i <= n; i++) { if (l[i] == 0) { mu[i] = -1; prime.push_back(l[i] = i); } f...
#include <bits/stdc++.h> using namespace std; int main() { int x, mx = -1, n; cin >> n; while (n--) { cin >> x; mx = max(x, mx); } if (mx <= 25) cout << 0 n ; else cout << mx - 25 << n ; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxVal = 200005; int arr[maxVal]; int tree[4 * maxVal]; void build(int node, int start, int endd, int k) { if (start == endd) { if (arr[start] >= k) tree[node] = 1; else tree[node] = 0; } else { int mid = (start ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; const long long p = 1e9 + 7; int par[MAXN][2], size[MAXN][2], dist[MAXN][2], val[MAXN][2]; int groups, n, k; pair<int, int> find(int e, int x) { if (par[x][e] == x) { return pair<int, int>(x, 0); } pair<int, int> t = f...
#include <bits/stdc++.h> const double eps = (1e-5); using namespace std; int dcmp(long double a, long double b) { return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1; } long long getBit(long long num, int idx) { return ((num >> idx) & 1ll) == 1; } int setBit1(int num, int idx) { return num | (1 << idx); }...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; const long long INF = 1e18; struct node { long long d, f, t, c; } a[N]; long long b[N]; long long dp[1000006], dp1[1000005]; bool cmp(node p, node q) { return p.d < q.d; } int main() { int n, m, k; long long x = 1000000...
#include <bits/stdc++.h> using namespace std; long long sum[4]; int main(void) { long long n, a, b, c, d, min_value = 1e14, max_value = 0, flag = 0; scanf( %lld %lld %lld %lld %lld , &n, &a, &b, &c, &d); sum[0] = a + b; sum[1] = b + d; sum[2] = c + d; sum[3] = a + c; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; const long long md = 1e9 + 7; const long long MX = 2e5 + 5; const long long INF = 1e18; const long double PI = 4 * atan((long double)1); long long power(long long a, long long n) { long long res = 1; while (n) { if (n % 2) res *= a; a *= a; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 710; int n; struct Tbig { static const int bit = 10000; int n, a[30]; Tbig(int x = 0) { memset(a, 0, sizeof a); for (n = 0; x; x /= bit) a[n++] = x % bit; !n ? n = 1 : 0; } Tbig operator*(const Tbig &b) const { ...
#include <bits/stdc++.h> using namespace std; int main() { int size1; string s; vector<int> v; int arr[200]; cin >> size1 >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == * ) v.push_back(i + 1); } for (int i = 0; i < v.size(); i++) { for (int count1 = 1; count1 <= ...
#include <bits/stdc++.h> using namespace std; const long long int N = 1e5; long long int t[N]; string s; long long int n, k; bool chek(long long int x) { for (long long int i = 0; i < n; i++) { if (!(s[i] - 0 )) { long long int en = i + x; long long int st = i - x; en = mi...
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, n, m; string s, v; int main() { cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a >> b; } for (int i = 1; i <= n; i++) { if (i % 2 == 1) { cout << 1; } else { cout << 0; } } }
#include <bits/stdc++.h> using namespace std; int n, i, j, k, x, y, w, m, Q, used[100500], start; pair<pair<int, int>, int> a[100500]; vector<pair<int, int> > g[100500]; vector<int> f[100500]; long long d[100500]; long long hea[200500]; int new_w[100500], new_d[100500]; int hea2[200500]; int st[1005...
#include <bits/stdc++.h> using namespace std; int n, arr[100010], mn = 1000000000, st, ans = 1000000000; bool b; int main() { cin >> n; for (int i = 0; i < n; ++i) { cin >> arr[i]; mn = min(mn, arr[i]); } for (int i = 0; i < n; ++i) { if (arr[i] == mn && !b) { st = i; ...
#include <bits/stdc++.h> using namespace std; int i, j; string a[110]; int f[110]; int g[110]; int h1[110]; int h2[110]; int s1[110]; int s2[110]; int rem; void del(int k) { rem--; s1[f[k]] -= k; s2[g[k]] -= k; h1[f[k]]--; h2[g[k]]--; if (h1[f[k]] == 1 && (1 << f[k] & i)) d...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[n]; for (int i = 0; i < n; i++) a[i] = i + 1; int cnt = (n / 2) * (n / 2); if (n % 2 == 0) cnt -= n / 2; if (cnt < m) { cout << -1; return 0; } int idx = n - 1; while (m < cn...
#include <bits/stdc++.h> using namespace std; int n, nn[5], ma; string s; long long ans = 1; int main() { cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i] == A ) nn[0]++; if (s[i] == C ) nn[1]++; if (s[i] == G ) nn[2]++; if (s[i] == T ) nn[3]++; } for (int i = ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; long long t, n, a[maxn]; int main() { scanf( %d , &t); while (t--) { long long maxx = -1e18, ans = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] > maxx) maxx = a[i]; } ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; char s[MAXN]; int main() { int m; scanf( %d , &m); scanf( %s , s); int n = strlen(s); priority_queue<int, vector<int>, greater<int> > Q; for (int k = 0; k < 26; k++) { while (!Q.empty()) Q.pop(); bool fla...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const double PI = acos(-1); long long power(long long x, long long y) { if (y == 0) return 1; else if (y == 1) return x; long long r = power(x, y / 2); if (y % 2 == 0) return (r * r); else re...
#include <bits/stdc++.h> using namespace std; const int N = 205; int n, siz[N], s[N][N], ori[N][N], tot[N], pos[N]; vector<int> ans; int read() { int x = 0, f = 1; char s; while ((s = getchar()) > 9 || s < 0 ) if (s == - ) f = -1; while (s >= 0 && s <= 9 ) x = (x << 1) + (x ...
#include <bits/stdc++.h> inline void DoNothing() {} template <typename T> inline T Abs(const T a) { return a < 0 ? -a : a; } template <typename T> inline T Min(const T a, const T b) { return a < b ? a : b; } template <typename T> inline T Max(const T a, const T b) { return a > b ? a : b; ...
#include <bits/stdc++.h> using namespace std; int sumb[64]; int xorb[64]; long long s, r; int maxx = 0; void bits() { int i = 0; long long bf = s; while (bf) { sumb[i] = bf % 2; ++i; bf /= 2; } maxx = i; bf = r; i = 0; while (bf) { xorb[i] = bf % 2; ...
#include <bits/stdc++.h> using namespace std; inline long long add(long long a, long long b) { return ((a % 1000000007LL) + (b % 1000000007LL)) % 1000000007LL; } inline long long mul(long long a, long long b) { return ((a % 1000000007LL) * (b % 1000000007LL)) % 1000000007LL; } inline long long sub(l...
#include <bits/stdc++.h> using namespace std; const int N = 1000007; int v[N]; vector<int> pos[N]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> v[i]; pos[v[i]].push_back(i); } for (int i = 0; i < N; ++i) { reverse(pos[i].begin(), pos[i].end()); }...
#include <bits/stdc++.h> using namespace std; int main(void) { int n, m; cin >> n >> m; vector<string> xs(n); for (int i = 0; i < n; i++) cin >> xs[i]; int cur = 0; int curB = 0; set<int> ans; for (int i = 0; i < xs.size() - 1; i++) { int j = 0; while (j < xs[i].size()) {...
#include <bits/stdc++.h> using namespace std; const int num = 200001; long long a[401]; int main() { int t, n; cin >> t; int str, cur; int fl = 0; while (t--) { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) a[n + i] = a[i]; cur = 2 * n...
#include <bits/stdc++.h> using namespace std; const int pw = 1 << 17; const int maxn = 1e5 + 20; int ans[maxn]; void work() { int n, x; cin >> n >> x; if (n == 1) { printf( YES n ); cout << x << endl; return; } else if (n == 2 && x == 0) { printf( NO n ); return; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; set<int> st; int x; int sz = 0; for (int i = 0; i < n; i++) { cin >> x; if (sz > 3) continue; if (st.find(x) == st.end()) { sz++; st.insert(x); } } if (sz > 3) co...
#include <bits/stdc++.h> using namespace std; char a[105]; char temp[105]; int main() { int n; scanf( %d%*c , &n); while (n--) { int cnt = 0; bool flag = false; bool first = false; gets(a); int len = strlen(a); for (int i = len - 5; i <= len; i++) temp[cnt++] = a[...
#include <bits/stdc++.h> using namespace std; const int X = 100000 + 5; long long C[1005][1005]; long long n, m; long long iis, ii, jjs, jj, cc; void calc() { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cc += C[i][j]; } } for (int i = 0; i < n; i++) { fo...
#include <bits/stdc++.h> using namespace std; int a[2000], b[2000]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i] >> b[i]; } int k = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; j++) { if (j != i) { if (a[i] == b[j]) { ...
#include <bits/stdc++.h> using namespace std; int n, q, adj[4][200123]; int vis[4][200123]; void show() { for (int i = 1; i <= 2; ++i) { for (int j = 1; j <= n; ++j) { cout << adj[i][j] << ; } cout << endl; } } int dfs(int i, int j, char v) { if (i == 2 and (j == (n ...
#include <bits/stdc++.h> using namespace std; typedef struct edge { int a; int b; int c; }; int n, m; edge roads[10000]; vector<int> out[200]; double matrix[200][200]; double const eps = 1e-10; double val[200]; bool isZero(double r) { return r < eps && r > -eps; } void flip(int r1, int...
#include <bits/stdc++.h> using namespace std; long long a[1000005]; int main() { int n; cin >> n; multiset<long long> s; for (int i = 1; i <= n; i++) { cin >> a[i]; s.insert(a[i]); } long long ans = 1e9; for (int i = 1; i <= n; i++) { s.erase(s.find(a[i])); long...
#include <bits/stdc++.h> #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( O8 ) #pragma GCC optimization( unroll-loops ) using namespace std; const long long int N = 60 + 5, mod = 1e9 + 7, inf = 1e12, maxq = 5e5 + 30, maxm = 1e3 + 30; const long double eps = 0.0000001; lon...
#include <bits/stdc++.h> using namespace std; int main() { int n, odd, up, down; odd = up = down = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] % 2 != 0) odd++; } for (int i = 0; i < n; i++) { if (a[i] % 2 == 0) cout << a[i] / 2 << ...
#include <bits/stdc++.h> using namespace std; const int N = 500005; int n, K, a[N]; long long checkl(int x) { long long sum = 0; for (int i = 0; i < n; ++i) { sum += max(0, x - a[i]); } return sum; } long long checkr(int x) { long long sum = 0; for (int i = 0; i < n; ++i) { ...
#include <bits/stdc++.h> using namespace std; int prior(string a) { if (a == rat ) { return 0; } else if (a == woman || a == child ) { return 1; } else if (a == man ) { return 2; } else return 3; } int main() { int n, i, j; int k[4] = {0}; string b[4][100...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k1, k2; cin >> n >> m >> k1 >> k2; if (n > m) { cout << First << endl; } else { cout << Second << endl; } }
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n; cin >> n; getchar(); string s; cin >> s; int ans = 1000000; string cnt = ; for (int i = 0; i < n; ++i) { cnt += s[i]; string s1 = cnt; string s2 = s.substr(i + 1, i + 1);...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } long long ans = 0; for (int rep = 0; rep < 2; rep++) { for (int r = 2; r < n; r++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n; cin>>n; int a[n],b[n],sum=0,sum2=0; vector<int>v1; vector<int>v2; for(int i=0;i<n;i++) { cin>>a[i]; ...
#include <bits/stdc++.h> using namespace std; long long ans, p, s; int N; struct node { int a[2]; node *L, *R; node() { a[0] = a[1] = 0; L = R = NULL; } void add() { if (L == NULL) L = new node(); if (R == NULL) R = new node(); } }; void update(node *no, long ...
#include <bits/stdc++.h> using namespace std; long long fn(long long x) { long long ret = (x * (x + 1)) / 2; if (x < 0) ret = 0; return ret; } long long fn(long long R, long long K1, long long K2) { long long ret = 0; K1 = min(K1, R - 1); K2 = min(K2, R); if (R - K1 >= K2) return ((K...
#include <bits/stdc++.h> using namespace std; const int maxN(2e5 + 10); typedef int i_N[maxN]; int N, K; namespace graph { i_N A, P, is_us, Cus, deg; pair<int, int> edge[maxN]; vector<int> adj[maxN], node[maxN]; void link(const int u, const int v) { adj[u].push_back(v); } void dfs(const int u) { ...
#include <bits/stdc++.h> using namespace std; int n, m; int inf = (int)1e9; int c[4]; string t[4]; vector<vector<long long> > dp; const int hhh = 21; string z[hhh] = { 000100010001 , 100010001000 , 000000010001 , 000010001000 , 001100111111 , 001000111111 , 000100111111 , 00000...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e18 + 7; void solve() { int n, k; cin >> n >> k; string s; cin >> s; for (int i = 0; i < k; i++) { int z = 0, one = 0, j = i + k; for (j; j < n; j += k) { if (s[j] == 1 ) one++;...
#include <bits/stdc++.h> using namespace std; const int N = 520; long long gi() { long long x = 0, o = 1; char ch = getchar(); while (!isdigit(ch) && ch != - ) ch = getchar(); if (ch == - ) o = -1, ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return x * o; ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0; bool f = false; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = true; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x << 3) + (x << 1) + (c ^ 0 ); c = g...
#include <bits/stdc++.h> using namespace std; int pointer; vector<long long> M; vector<long long> B; bool bad(int l1, int l2, int l3) { double x_12 = double(B[l2] - B[l1]) / double(M[l1] - M[l2]); double x_13 = double(B[l3] - B[l1]) / double(M[l1] - M[l3]); return x_13 < x_12; } void add(long ...