func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const double Pi = acos(-1.0); const int MAXN = 1e6 + 5; int n, m, t; int v[MAXN]; char s[MAXN]; int main() { cin >> t; while (t--) { cin >> n >> s + 1; int sum1 = 0, sum2 = 0, now = 0; for (int i = 1; i <= n * 2; i++) { if (s[...
#include <bits/stdc++.h> using namespace std; const int MAX = 300005; pair<int, int> seg[2 * MAX]; void update(int l, int r, int fight, int value) { for (l += MAX, r += MAX; l < r; l >>= 1, r >>= 1) { if (l & 1) seg[l++] = make_pair(fight, value); if (r & 1) seg[--r] = make_pair(fight, value); ...
#include <bits/stdc++.h> using namespace std; int *c; int main() { int a, b, t, f, n, m, d, g, sum = 0; int mas[4]; cin >> mas[0] >> mas[1] >> mas[2] >> mas[3] >> a >> b; c = min_element(mas, mas + 4); *c = min(*c, b + 1); if (*c - a >= 0) cout << *c - a; else cout << 0 ; ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int t, n, m, x = 0, y = 0, flag = 0, cnt = 0, sum = 0, sum1 = 0, sum0 = 0, flag1 = 0; int a1, a2, a3, b1, b2, b3; vector<int> d; cin >> t; int a[t]; for (int i = 0; i < t; i++) { cin...
#include <bits/stdc++.h> using namespace std; int n, k, tab[70], p; int main() { scanf( %d %d , &n, &k); for (int i = 0; i < n; i++) scanf( %d , &tab[i]); sort(tab, tab + n); if (k > n) { printf( -1 n ); return 0; } printf( %d %d n , tab[n - k], tab[n - k]); return 0; } ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = int(1e6) + 10; const int MAX_M = 21; int n, r, c; int a[MAX_N], b[MAX_N]; int f[MAX_N][MAX_M]; char buffer[MAX_N * 6]; int main() { scanf( %d%d%d n , &n, &r, &c); c++; gets(buffer); int m = strlen(buffer); buffer[m++] = ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int s[n + 1]; s[0] = 0; for (int i = 1; i <= n; i++) cin >> s[i]; int dp[n + 1][n + 1]; memset(dp, 0, sizeof(dp)); int ans = 0; for (int i = 1; i <= n; i++) { int prev = 0; for (int j = 0; j <...
#include <bits/stdc++.h> using namespace std; const int32_t MAX = 1000000 + 1; int64_t ans[MAX]; int main(int argc, char *argv[]) { ios_base::sync_with_stdio(false); ifstream in( input.txt ); ofstream out( output.txt ); int64_t n, q, k = 0, type, evenSh = 0, oddSh = 0, parity = 0, lastSh = 0; ...
#include <bits/stdc++.h> using namespace std; long long X[200200]; int Xi[200200], xi; int X2[200200], x2; int Xm[200200], xm; int a[200200], w[200200], x, n, q; inline void update(int u) { for (; u <= n; u += u & -u) { X[u] += x; Xi[u] = (Xi[u] + xi) % 1000000007; X2[u] = (X2[u] + x...
#include <bits/stdc++.h> using namespace std; const int N = 101010; int n, ans; int pa[N << 1], ns[N], nt[N], ma[N], pos[N]; vector<pair<int, int> > res; char s[N], sr[N]; void Manacher(char *s, int n, int *pa) { pa[0] = 1; for (int i = 1, j = 0; i < (n << 1) - 1; ++i) { int p = i >> 1, q = ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int a[maxn], b[maxn]; int main() { int n, i, j; cin >> n; for (i = 0; i < n; i++) cin >> j, a[j] = i; multiset<int> s; for (i = 0; i < n; i++) cin >> b[i], s.insert(i - a[b[i]]); for (int i = 0; i < n; i++) { mu...
#include <bits/stdc++.h> using namespace std; const int N = 100010; const int sq = 320; int n, q, p[N], r[N], dp[N]; int f(int x) { int y = x; for (int i = 0; i < sq; i++) x = p[x]; return dp[y] = x; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> q; fo...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, k; cin >> n >> k; map<char, long long> mp; for (long long i = 0; i < n; i++) { char x; cin >> x; mp[x]++; } vector<pair<lo...
#include <bits/stdc++.h> using namespace std; char s[] = GB ; int main() { int n, k, a, b; scanf( %d%d%d%d , &n, &k, &a, &b); if (a < b) { swap(a, b); swap(s[0], s[1]); } int num = (a - 1) / k + 1; if (b < num - 1) { puts( NO ); return 0; } while (num--) { ...
#include <bits/stdc++.h> using namespace std; int main() { int t, a, b; scanf( %d , &t); while (t--) { scanf( %d%d , &a, &b); double output; if (b == 0) { printf( 1 n ); continue; } else if (a == 0) { printf( 0.5 n ); continue; } if (a ...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n, kol = 0; vector<int> a, b; cin >> n; for (i = 0; i < n; i++) { cin >> j; a.push_back(j); b.push_back(j); } sort(b.begin(), b.end()); for (i = 0; i < n; i++) if (a[i] != b[i]) kol++; if (ko...
#include <bits/stdc++.h> const int MAXN = 200005; int nn; int x[MAXN]; long long tt; long long a[MAXN]; long long mi[MAXN], mx[MAXN]; long long ans[MAXN]; int tag[MAXN]; int main() { using namespace std; ios::sync_with_stdio(false); cin.tie(0); cin >> nn >> tt; for (int i = 1; i <=...
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_str...
#include <bits/stdc++.h> using namespace std; long long N; vector<int> E[100000]; bool visit[100000] = {0}; long long component[100000] = {0}; int cN = 0; stack<int> stk; void DFS(int s) { if (visit[s]) return; visit[s] = true; stk.push(s); while (!stk.empty()) { int v = stk.top();...
#include<bits/stdc++.h> using namespace std; const int MAXN = 1010; int vis[MAXN*2][MAXN*2],T,n,m,ans; /* void dfs(int x,int y,int step,int now){ if(step==n){ if(!vis[x+MAXN][y+MAXN]) ans++,vis[x+MAXN][y+MAXN] = 1; return; } if(now==1){ dfs(x+1,y,step+1,2); dfs(x-1,y,step+1,2); ...
#include <bits/stdc++.h> using namespace std; vector<int> q, s; int n, k; vector<int> apply(vector<int> &a, vector<int> q) { vector<int> res(n); for (int i = 0; i < n; i++) { res[i] = a[q[i]]; } return res; } vector<int> rev_apply(const vector<int> &a, vector<int> &q) { vector<int>...
#include <bits/stdc++.h> using namespace std; const long long sz = 3e5 + 10; long long ara[sz], pos[sz], other[sz], mn[sz]; int main() { long long n, m; cin >> n >> m; for (long long i = 1; i <= n; ++i) { scanf( %lld , &ara[i]); pos[ara[i]] = i; } for (long long i = 1; i <= n; ++...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int q; cin >> q; while (q--) { string s; cin >> s; vector<char> v[2]; for (int i = 0; i < s.size(); i++) v[s[i] % 2].push_back(s[i]); int p1, p2; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, temp; cin >> n >> k; int arr[n], sum[n]; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) { if (arr[i] == 0) sum[i] = 0; else sum[i] = sum[arr[i] - 1]; temp = i > k ? k : ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; pair<long long, char> s[MAXN], t[MAXN]; int nxt[MAXN]; void kmp(pair<long long, char> str[], int len) { memset(nxt, -1, sizeof(nxt)); for (int i = 0; i < len - 1; i++) { int p = nxt[i]; while (p != -1 && str[i + 1] != s...
#include <bits/stdc++.h> using namespace std; const unsigned long long p = 31; const unsigned long long m = 1e9 + 7; bool compare(string a, string b) { sort(a.begin(), a.end()); sort(b.begin(), b.end()); int n = a.length(); unsigned long long hash_a = 0, hash_b = 0; unsigned long long p_pow ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 10101; const int BIT = 30; int N; int arr[MAXN], brr[MAXN]; bool isb[MAXN]; vector<pair<int, int> > vans; void action(int a, int b) { arr[b] ^= arr[a]; vans.push_back(make_pair(b + 1, a + 1)); } void aswap(int a, int b) { if ...
#include <bits/stdc++.h> using namespace std; const int N = 100001, BAR = 500, MOD = 1000000007; int fac[N], inv[N]; int powMod(int a, int n) { int ret = 1; while (n) { if (n & 1) { ret = (long long)ret * a % MOD; } a = (long long)a * a % MOD; n >>= 1; } return re...
#include <bits/stdc++.h> int main() { int n, t, i; scanf( %d , &t); for (i = 0; i < t; i++) { scanf( %d , &n); printf( %d n , n / 2); } }
#include <bits/stdc++.h> using namespace std; const long double PI = 3.14159265359; const long long MOD = (long long)998244353ll; const long long MAXN = (long long)3e5 + 10; const long long INF = (long long)2242545357980376863; const long double EPS = (long double)1e-8; long long source[MAXN], d0[MAXN], d...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > adj[200001]; int totalIn, totalOut; int inEdges[200001]; int outEdges[200001]; void dfs(int u, int par, int in, int out) { inEdges[u] = in; outEdges[u] = out; for (pair<int, int> &p : adj[u]) { int v = p.first; int...
#include <bits/stdc++.h> using namespace std; long long n, arr[26], s, k, fuck[19], ans; vector<pair<long long, long long> > v1; map<pair<long long, long long>, long long> maph; void rek(long long x, long long r, long long z, long long o, bool p) { if (x >= r) { if (!p) v1.push_back({z, o});...
#include <bits/stdc++.h> int main() { int n, t, i, j, k, xi, ai, s, y; int x[1000], a[1000]; scanf( %d%d , &n, &t); for (i = 0; i < n; i++) { scanf( %d%d , &xi, &ai); j = 0; while ((j < i) && (x[j] < xi)) j++; for (k = i; k > j; k--) { x[k] = x[k - 1]; a[k] = a[...
#include <bits/stdc++.h> using namespace std; int n, cnt, pos, sz, mx, last, start; char s[2000005], ans[2000005]; int main() { scanf( %d , &n); memset(ans, 000 , sizeof(ans)); for (register int i = 1; i <= n; i++) { scanf( %s , s); scanf( %d , &cnt); sz = strlen(s); for (r...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { double n; cin >> n; double r = 1 / (2 * tan((360 / (4 * n)) * (3.1415926535 / 180))); cout << setprecision(15) << 2 * r << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int c = 0, m = 0, y = 0, w = 0, g = 0, b = 0, d, e; cin >> d >> e; char arr[d][e]; for (int i = 0; i < d; i++) { for (int j = 0; j < e; j++) { cin >> arr[i][j]; if (arr[i][j] == M ) { m++; } else if (...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000006; char s[maxn]; int ans[8] = {1869, 8196, 1986, 8691, 6198, 1689, 1968}; int main() { while (scanf( %s , s) != EOF) { int len = strlen(s); int A[10] = {0}; for (int i = 0; i < len; i++) { A[s[i] - 0 ]++; ...
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long t; cin >> t; for (int ti = (int)(0); ti < (int)(t); ti++) { unsigned long long n; cin >> n; if (n % 2) { unsigned long long tmp = (n + 1u) * n; unsigned long long res; if (tmp % (4u * ...
#include <bits/stdc++.h> using namespace std; const int M = 2e6 + 10; int a[M], b[M], c[M], d[M], e[M], f[M]; vector<int> T[M]; struct NTT { static const int G = 3, P = 998244353; int N, na, nb, w[2][M], rev[M]; long long kpow(long long a, int b) { long long c = 1; for (; b; b >>= 1, a...
#include <bits/stdc++.h> int a[105], stor[105]; int main() { int n; scanf( %d , &n); int i; for (i = 0; i < n; i++) scanf( %d , &a[i]); int j, k = 0, max; max = a[2] - a[0]; for (i = 1; i < n - 1; i++) { if (i == 1) { max = a[2] - a[0]; for (j = 2; j < n - 1; j++) {...
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() using ll=long long int; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; template<typenam...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 0x3f3f3f3f; const double eps = 1e-8; const long long mod = 10007; const int N = 110; int val[110]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++...
#include<bits/stdc++.h> #define ll long long #define ii pair<ll,ll> #define x first #define y second using namespace std; const long o=200005; ll n,it[2][4*o]; ii a[o]; vector<ii>p[2]; void build(long db,long x,long l,long r) { if(l==r) { it[db][x]=p[db][l].y; retur...
#include <bits/stdc++.h> using namespace std; int n; int v[200005]; void read(); int main() { read(); int k = n - 1; while (v[k] == v[k + 1]) --k; cout << k << n ; return 0; } void read() { cin >> n; for (int i = 1; i <= n; ++i) cin >> v[i]; }
#include <bits/stdc++.h> using namespace std; const long long inf = 2e9; const long long infll = 1e18; double eps = 0.0000001; ifstream in( input.txt ); ofstream out( output.txt ); ; long long n; vector<long long> c; vector<long long> t; void init() { cin >> n; c.resize(n); t.resize(n)...
#include <bits/stdc++.h> using namespace std; long long x, y, z, arr[100 * 100005], rearr[100 * 100005]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); ; cin >> x >> y; for (int i = 0; i < x; i++) { cin >> z; arr[z]++; } z = 0; for (int i = 1e7; i >= 1; i--)...
#include <bits/stdc++.h> int main() { int n, k, l, c, d, p, nl, np, x, y, z, a, i; scanf( %d%d%d%d%d%d%d%d , &n, &k, &l, &c, &d, &p, &nl, &np); x = (k * l) / nl; y = c * d; z = p / np; if (x < y && x < z) { a = x; } else if (y < x && y < z) { a = y; } else { a = z; ...
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 30) - 1; const long long mod = 1e9 + 9; map<pair<int, int>, int> mp; int m; int v[100010][2]; int vis[100010]; int ans[100010], anscnt; int up[100010][3]; int down[100010][3]; priority_queue<int> qmax; priority_queue<int, vector...
#include <bits/stdc++.h> #pragma optimization_level 3 #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) using namespace std; const long long N = 1e6 + 5; const long long mod = 1e+9 + 7; const long long INF = 0x7f7f7f7f7f7f7f7f; const int INFi = 0...
#include <bits/stdc++.h> using namespace std; const long long llInf = 1e18 + 1e17; const int Inf = 1e9 + 1e8, N = 1e5 + 10, Mod = 1e9 + 7; int dp[N], t[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; dp[0] = 0; for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; void __print(long long 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) { cerr << << x << ; } void __print(const char *x) { cerr << << x <<...
#include <bits/stdc++.h> using namespace std; const int N = 1e5; vector<long long> edges[N]; long long vdiv[N]; int alreadyPrinted = 0; void rec(int d, int k, int v, int m) { if (v == m || alreadyPrinted == N) { return; } if (v == 0) { cout << 1 << ; alreadyPrinted++; ...
#include <bits/stdc++.h> using namespace std; int a[102][102]; int main() { int n, m; cin >> n >> m; int sum = 0; for (int i = 0; i < m; i++) { int x, y, c; cin >> x >> y >> c; a[x - 1][y - 1] = c; sum += c; } for (int i = 0; i < n; i++) { for (int i = 0; i < ...
#include <bits/stdc++.h> using namespace std; int n; long long arr[200011]; long long sum[200011]; bool check(int k) { int i; for (i = 1; i <= n; i++) sum[i] = 0; for (i = n; i >= 3; i--) { if (sum[i] + arr[i] < k) return 0; long long d = (sum[i] + arr[i] - k) / 3; long long d3 =...
#include <bits/stdc++.h> using namespace std; const double PI = 2 * acos(0.0); void fastInOut(); int power(int z, int i) { int zz = 1; for (int k = 0; k < i; k++) { zz *= z; } return zz; } long long power(long long x, long long y) { long long z = 1; for (long long i = 0; i < y;...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long dp[1010][1010], sum[1010]; int main() { memset(dp, 0, sizeof(dp)); int n, m, r; cin >> n >> m >> r; for (int i = 0; i <= 1000; i++) dp[0][i] = 1; for (int i = 1; i <= r; i++) { memset(sum, 0, size...
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; char s[60]; int main() { cin >> s; set<string> A; int n = strlen(s); for (int i = 0; i < n; ++i) { string cur; for (int j = 0; j < n; ++j) { cur += s[(i + j) % n]; } A.insert(cur); } co...
#include <bits/stdc++.h> using namespace std; struct node { string st; int l; }; int n, k, cnt = 0, m; node a[1000]; bool cmp(const node &x, const node &y) { return (x.l < y.l); } bool substring(string s1, string s2) { for (int i = 0; i <= s2.length() - s1.length(); i++) { bool flag = 1;...
#include <bits/stdc++.h> using namespace std; template <class T> void show(const vector<T> &a) { for (T x : a) cout << x << ; cout << endl; } signed main() { long long tc; cin >> tc; while (tc--) { long long x, y, z; cin >> x >> y >> z; vector<long long> a(3); a[...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e, f; int g = 1000; cin >> a >> b >> c >> d >> e >> f; if ((b * d * f) > (a * c * e) || (c == 0 && d != 0) || (a == 0 && b != 0 && d != 0)) cout << Ron << endl; else cout << Hermione << endl; r...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native ) const int maxn = 2e5 + 5; const int minn = 65; const long long mod = 1e9 + 7; const long long mod1 = 998244353; const long double pi = acos(-...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long f[2000007]; void pre() { f[0] = 1; for (int i = 1; i <= 2000001; i++) { f[i] = i * f[i - 1] % mod; } } long long powmod(long long x, long long n) { long long res = 1; while (n) { if (n & 1)...
#include <bits/stdc++.h> using namespace std; int read() { int f = 1, x = 0; char c = getchar(); while (!isdigit(c)) { if (c == - ) f = -f; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + c - 0 ; c = getchar(); } return x * f; } const int N =...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long gcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long x1, y1; long long g = gcd(b, a % b, x1, y1); x = y1; y1 = x1 - y1 * (a / b)...
#include <bits/stdc++.h> using namespace std; unsigned long long mod = 1000000007; template <class T1> void deb(T1 e1) { cout << e1 << n ; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << << e2 << n ; } template <class T1, class T2, class T3> void deb(T1 e1, T2 ...
#include <bits/stdc++.h> using namespace std; const int maxn = (1 << 17); int a[maxn], pos[maxn], n, b[maxn]; struct num { int idx, val; bool operator<(const num &mtp) const { return val > mtp.val; } }; priority_queue<num> q1, q2; int out[maxn]; void read() { int i; scanf( %d , &n); ...
#include <bits/stdc++.h> using namespace std; int dp[1004]; long long ncr[1004][1004]; int ones(int n) { int cnt = 0; while (n) { if (n % 2 == 1) { cnt++; } n /= 2; } return cnt; } void calcncr() { for (int i = 0; i <= 1000; i++) { ncr[i][0] = 1; } ...
#include <bits/stdc++.h> using namespace std; long long q[1000001], a[100001]; int main() { long long n, x, cnt = 0; cin >> n >> x; for (int i = 1; i <= n; i++) { cin >> a[i]; q[a[i]]++; } int e = 0; if (!x) { e = 1; } for (int i = 1; i <= n; i++) { int w = ...
#include <bits/stdc++.h> using namespace std; const long double INF = 1e12, epsilon = 1e-8; long double Y_AXIS, res = INF; vector<pair<long double, bool> > forbid; inline long double sqr(long double x) { return x * x; } inline long double dist(long double x1, long double y1, long double x2 = 0, ...
#include <bits/stdc++.h> using namespace std; template <typename T> void MACRO_VAR_Scan(T& t) { cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First& first, Rest&... rest) { cin >> first; MACRO_VAR_Scan(rest...); } template <typename T> void MACRO_VEC_ROW_Init(...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimization( unroll-loops ) using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; int read_int() { bool minus = false; int result = 0; char ch; ch = getchar(); while (1) { if...
#include <bits/stdc++.h> using namespace std; long long k, b, n, t; int main() { cin >> k >> b >> n >> t; int temp = 0; long long acc = 1; while (acc <= t) { acc *= k; acc += b; temp++; } int ans = n - temp + 1; if (ans < 0) cout << 0 << endl; else cou...
#include <bits/stdc++.h> using namespace std; using LL = long long; int func(int a, int b) { if (a == 1 and b >= 1) return (b - a); if (a == b or b % a == 0 or a <= 0 or b <= 0) return INT_MAX; int ret = func(b % a, a); if (ret != INT_MAX) ret += b / a; return ret; } int main() { ios_b...
#include <bits/stdc++.h> using namespace std; bool vis[12][12][12]; int ans2(int x, int y, int z, char a[12][12][12], int k, int n, int m) { int cnt = 0; if (a[x][y][z] == # || vis[x][y][z]) return 0; cnt++; vis[x][y][z] = true; if (x > 1) cnt += ans2(x - 1, y, z, a, k, n, m); if (x < k)...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; long long A[50001]; long long total = 0; for (int i = 0; i < N; ++i) { cin >> A[i]; total += A[i]; } long long x = total / N; long long res = 0; long long bal = 0; for (int i = 0; i < N; +...
#include <bits/stdc++.h> using namespace std; string S; const int MAX_N = 5000; bool wyn[MAX_N + 3][MAX_N + 3]; int main() { ios::sync_with_stdio(0); cin >> S; int wynik = 0; int val = 0; int zap = 0; for (int l = 0; l < S.size(); l++) { val = 0; zap = 0; for (int r =...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, k, a[N]; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { scanf( %d %d , &n, &k); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } int g = a[0]; for (int i = 1; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; int num[200000]; long long cnt[200000] = {0}; long long dp[200000] = {0}; long long sum[200000] = {0}; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> num[i]; cnt[num[i]]++; } long long ans = 0; for (int i =...
#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}; long long ln, lk, lm; char s[100005]; void fmain() { scanf( %d%d%d , &n, &m, &k); scanf( %s , s + 1); for (int ty, l, r, x, i = 0; i < m + k; i++) { scanf( %d%d%d%...
#include <bits/stdc++.h> using namespace std; struct Arco { int v, next; Arco() {} Arco(int v, int next) : v(v), next(next) {} } edges[1]; int last[1], E; void add_edge(int v, int u) { edges[E] = Arco(u, last[v]); last[v] = E++; } int xf[8] = {-1, -1, -1, 0, 0, +1, +1, +1}; int xc[8]...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; cin >> s; long long l_occ_1 = -1, l_occ_2 = -1, l_occ_3 = -1; long long maxi = s.length() + 1, mini; for (long long i = 0; i < s.length(); i++) { if (s[i] == 1 ) l_o...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 5; const long long INF = 100000000000000; long long h[maxn], p[maxn]; long long l[maxn], r[maxn]; int n, m; bool ok(long long t) { for (int i = 0; i < n; i++) { l[i] = h[i]; r[i] = h[i]; } int k = 0; for (i...
#include <bits/stdc++.h> char s1[1000100], s2[1000100]; char s[1000100 * 2]; int i, j, n, m; inline char rev(char& a) { if (a == N ) return S ; if (a == W ) return E ; if (a == S ) return N ; if (a == E ) return W ; return 0; } int z[1000100 * 2]; inline void Z() { int L = ...
#include <bits/stdc++.h> using namespace std; int const N = 1e5 + 10; char s[N]; int f[N][3]; bool _ok(int x, int y, int z) { if (x == z && z == y) return true; if (x == z && y == z - 1) return true; if (y == z && y == x - 1) return true; return false; } bool ok(int x, int y, int z) { ...
#include <bits/stdc++.h> using namespace std; long long n, x, y, ans; struct Edge { long long to, next; } edge[2 * 300001]; long long head[300001], sze; long long fa[300001], Tsze[300001], deep[300001]; inline char gc() { static char now[1 << 20], *S, *T; if (T == S) { T = (S = now) + fr...
#include <bits/stdc++.h> using namespace std; long long i, n, r, a, q; void solve() { cin >> n; if (n == 4 || n == 1 || n == 2) { cout << -1 n ; return; } a = n / 3; r = n % 3; if (r == 1) { cout << n / 3 - 2 << 0 << 1 n ; return; } if (r ==...
#include<bits/stdc++.h> #define ll long long #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define sz(x) (int)(x).size() #define PB push_back #define PI 3.1415926535897932384626433832795 #define what(x) cout<<#x<< is <<x<<endl; using namespace std; #ifdef LOCAL//ONLINE_JUDG...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; 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; n /= 2; } return res; } string bits(long long int ...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; struct Matching { int n; vector<int> matchL, matchR, dist; vector<bool> seen; vector<vector<int>> ke; Matching(int n) : n(n), matchL(n + 1), matchR(n + 1), dist(n + 1), seen(n...
#include <bits/stdc++.h> using namespace std; struct st { int o; int e; } arr[101]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, b; cin >> n >> b; vector<long long> vec; int v; arr[0].o = 0; arr[0].e = 0; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long ans = 0, now, a[14], b[14]; for (int i = 0; i < 14; i++) cin >> a[i]; for (int i = 0; i < 14; i++) { if (a[i] != 0) { for (int j = 0; j < 14; j++) b[j] = a[j]; int r = b[i] % 14, q = b[i] / 14; b[i] = 0; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 9; const long long mod1 = 1000000; ostringstream convert; long long n, m, cur, dp[100][300]; long long res; long long nbb = 0, nss = 0, ncc = 0, wmin, wmax; long long nb, ns, nc, pb, ps, pc, mx = 0; string s, s2; string a[1000...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n + n - 1); int sum = 0; for (int i = 0; i < n + n - 1; i++) { cin >> a[i]; sum += a[i]; } sort(a.begin(), a.end()); for (int i = 0; i < n + n - 2; i += 2) { if (a[i] < 0 && a[...
#include <bits/stdc++.h> using namespace std; const double eps(1e-8); const double pi(3.14159265358979); const int K = 33, mod = 1000000007; struct matrix { long long a[K][K]; } t[K] = {}, ans = {{}}, pre[K] = {}, suf[K] = {}; long long n; int k; inline void multi(const matrix &m1, const matrix &m...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int b, g; cin >> b; int i; int B[n]; for (i = 0; i < n; i++) { B[i] = 0; } int bb[b]; for (i = 0; i < b; i++) { cin >> bb[i]; B[bb[i]] = 1; } cin >> g; int G[m]; ...
#include <bits/stdc++.h> using namespace std; struct point { int tp; string s1, s2; } a[200000]; struct node { int n, next; } b[200000]; int n, l, st[200000]; map<string, int> p; int main() { cin >> n; scanf( n ); int m = 0; for (int i = 0; i < n; i++) { string s; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 500; const int M = 1e6 + 500; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const int LOG = 20; const int OFF = (1 << 20); const double EPS = 1e-9; const double PI = 3.1415926535; set<int> st; int n, x, l, r; char s[10]; ...
#include <bits/stdc++.h> using namespace std; int cnt[2000006]; int main() { int n, i, w; long long ans; scanf( %d , &n); for (i = 1; i <= n; i++) scanf( %d , &w), cnt[w]++; for (i = 0; i < 2000005; i++) { cnt[i + 1] += cnt[i] / 2; cnt[i] %= 2; } ans = 0; for (i = 0; i ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + ch - 0 ; ch = getchar(); } return ...
#include <bits/stdc++.h> using namespace std; int main() { int a[105]; int b[105]; int t, flag, flag1, i, n, c, sum1, sum2; scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %d , &a[i]); b[a[i]] = 1; } int count = 0; int sum = 0; flag = 1; int d = -1; c = 0; ...