func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; template <typename tp> inline void read(tp& x) { x = 0; char tmp; bool key = 0; for (tmp = getchar(); !isdigit(tmp); tmp = getchar()) key = (tmp == - ); for (; isdigit(tmp); tmp = getchar()) x = (x << 3) + (x << 1) + (tmp ^ 0 ); if (key) x = ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 3; struct tree { long long sum; int tag; int lc; int rc; } a[N << 1]; long long s[N]; int n, m, t = 1; long long ans; long long win; vector<pair<long long, long long> > other, change; inline int read() { int v = 0,...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) const double PI = acos(-1); template <class A, class B> std::ostream& operator<<(std::ostream& st, const std::pair<A, B> p) { st << ( << p.first << , << p.second << ) ; return st; } using namespace std; const int mod = 998244353; int add(...
#include <bits/stdc++.h> const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; const long long MOD = 1000000009; const int MAXM = 100010; int m; long long pow_mod[MAXM]; int X[MAXM], Y[MAXM]; map<pair<int, int>, int> ma; set<int> S; set<int> up[MAXM], down[MAXM]; v...
#include <bits/stdc++.h> using namespace std; const int N = 5 * 10000; const long long mod = 1000000007; void solve() { int n; cin >> n; vector<int> a(n), b(n), c(n), d(n), e(n); string str; for (int i = 0; i < n; i++) { cin >> str; int qtd[] = {0, 0, 0, 0, 0}; for (char c ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using ld = long double; struct Node { vi to; int lk; ll w; Node() : to(14), lk(0), w(0) {} }; vector<Node> au(1); int sz = 1; void add(...
#include <bits/stdc++.h> using namespace std; int main() { char ch1, ch2, ch; int i, j, k, tc, res, total, temp, mx, num, num1, num2; int n, a, b; { scanf( %d %d %d , &n, &a, &b); if (b == 0) printf( %d n , a); else if (b > 0) { while (b--) { if (a == n) ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, aa, bb; cin >> a >> b; a += 100; b += 100; cin >> aa >> bb; aa += 100; bb += 100; if (aa != a && bb != b) { int tmp = (abs(a - aa)); int tmp2 = (abs(b - bb)); cout << 2 * abs(tmp2 + tmp) + 4; }...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); vector<int> a(n); for (auto &i : a) scanf( %d , &i); map<int, int> dp; int ans = 0; int last = 0; for (int i = 0; i < n; i++) { int x = a[i]; dp[x] = dp[x - 1] + 1; if (ans < dp[x]) {...
#include <bits/stdc++.h> using namespace std; int id = 0; vector<int> group(2e5 + 5, -1); 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]; string S; cin >> S; for (int i = 0; i < N; i++) { if (...
#include <bits/stdc++.h> using namespace std; char s[200005]; int alph[26]; int main() { scanf( %s , &s); for (int i = 0; s[i]; i++) alph[s[i] - a ]++; for (int i = 0; i < 26; i++) for (int j = 26 - 1; j > i; j--) if (alph[i] & 1) if (alph[j] & 1) alph[i]++, alph[j]--; i...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using db = double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<db, db>; using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>; using vd = vecto...
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n >> t; if (n == 1 && t == 10) cout << -1 << endl; else { cout << t; if (t == 10) n--; for (int i = 0; i < n - 1; i++) cout << 0; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; char tbl[209][209]; int vid[209][209]; int hid[209][209]; int n, m; vector<int> G[100009]; int pr[100009]; int was[100009]; int wcnt; bool vert(int x, int y) { return vid[x][y] > 0; } bool improve(int x) { was[x] = wcnt; for (int nb : G[x]) { ...
#include <bits/stdc++.h> using namespace std; const unsigned int MOD = 1000000007; void solve() { string s; cin >> s; string t; cin >> t; vector<char> v; bool check1 = false; bool check2 = false; bool check3 = false; for (int i = 0; i < s.length(); i++) { if (s[i] == a )...
#include <bits/stdc++.h> using namespace std; const int maxn = 220, maxm = 220 * 220; struct edge { int s, t, next; } e[maxm]; struct vtx { int dfn, low, belong, leave; bool instack; } ver[maxn]; int hd[maxn], cnt, ind, sta[maxn], top, bcnt; void insert(int a, int b) { e[cnt].next = hd[a...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using vi = vector<int>; using ii = pair<int, int>; using vii = vector<pair<int, int>>; void solve() { int n; cin >> n; int r = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; +...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; void solve() { int n; cin >> n; vector<set<int>> v(n + 1); for (int i = 0; i < n - 2; i++) { int x, y, z; cin >> x >> y >> z; v[x].insert(y); v[x].insert(z); v[y].insert(x); v[y].insert...
#include <bits/stdc++.h> using namespace std; typedef const char* cstr; const int oo = (~0u) >> 1; const long long int ooll = (~0ull) >> 1; const double inf = 1e+20; const double eps = 1e-8; const double pi = acos(-1.0); const int MOD = 1000000007; template <typename type> inline bool cmax(type& a, ...
#include <bits/stdc++.h> using namespace std; const int _ = 5e5 + 7; int n, m, a[_], b[_]; bool check(int mid) { memset(b, -1, sizeof(b)); b[0] = 0; for (int i = 1; i <= n; ++i) { int L = a[i], R = (a[i] + mid) % m; if (L <= R) { if (b[i - 1] <= R) b[i] = max(b[i - 1], ...
#include <bits/stdc++.h> using namespace std; int main(){ //freopen( input.inp , r ,stdin); //freopen( output.out , w ,stdout); ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--){ int a,b; cin >> a >> b; int ans = 0; ...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; int x1[48] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, ...
#include <bits/stdc++.h> using namespace std; const long long N = 100005; char en = n ; long long inf = 1e16; long long mod = 1e9 + 7; long long power(long long x, long long n, long long mod) { long long res = 1; x %= mod; while (n) { if (n & 1) res = (res * x) % mod; x = (x * x) %...
#include <bits/stdc++.h> using namespace std; const int maxn = 9000020; const int K = 60; const int MOd = 1e9 + 7; int a, b; int nex[maxn][2]; int ar[3020], st[maxn]; int dn[maxn], N; int ans; int add(int a, int b) { a += b; a %= MOd; if (a < 0) return a + MOd; return a; } void d...
#include <bits/stdc++.h> using namespace std; const int MaxN = 500 + 5; int n, m, mod, h[MaxN], tmp, tot[3]; long long f[MaxN << 1][MaxN]; char ch; void read(int &num) { ch = 0; while (ch < 0 || ch > 9 ) ch = getchar(); num = ch - 0 ; } int main() { scanf( %d%d%d , &n, &m, &mod); ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const int N = 1e6 + 10; struct UFS { stack<pair<int *, int>> stk; int fa[N], rnk[N]; inline void init(int n) { for (int i = 0; i <= n; ++i) fa[i] = i, rnk[i] = 0; } inline int Find(int x) ...
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n >> t; int edge_n = 2 * n; double edges[edge_n]; double currX, currA; for (int i = 0; i < n; i++) { cin >> currX >> currA; edges[2 * i] = currX - currA / 2; edges[2 * i + 1] = currX + currA / 2; ...
#include <bits/stdc++.h> using namespace std; int bs(int a[], int l, int u, int x) { int m, p = -1; while (l <= u) { m = (l + u) / 2; if (a[m] == x || (a[m] < x && m + 1 <= u && a[m + 1] >= x)) return m; else if (a[m] < x) { p = m; l = m + 1; } else { ...
#include <bits/stdc++.h> using namespace std; const int maxint = -1u >> 1; int n; long long x[100010]; bool v[100010]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %I64d , &x[i]); sort(x, x + n); long long a = -1, b = -1; long long ret = 0; for (int i = n - 2; i >...
#include <bits/stdc++.h> using namespace std; int main() { long long n, count = 0, ans; cin >> n; string s; cin >> s; long long r = 0, b = 0; for (long long i = 0; i < n; i++) if (s[i] == r ) r++; else if (s[i] == b ) b++; for (long long i = 0; i < n; i++) ...
#include <bits/stdc++.h> int main() { int a, b, s = 0, t = 0, r = 0, i, c, d; scanf( %d %d , &a, &b); for (i = 1; i <= 6; i++) { c = abs(a - i); d = abs(b - i); if (c < d) s++; else if (c > d) t++; else r++; } printf( %d %d %d n , s, r, t); ...
#include <bits/stdc++.h> using namespace std; struct node { int v; long long w; node(){}; node(int v, long long w) : v(v), w(w) {} }; vector<vector<node> > G; int b[102550]; long long solve(int s) { long long ans = 10000000000000000; int len = G[s].size(); for (int i = 0; i < len...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, s, ans = 0, counter = 0; cin >> n >> s; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); while (ans < s) { counter++; ans += a[n - counter]...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:60777216 ) using namespace std; int main() { int tc; cin >> tc; for (int TC = (0); TC < (tc); TC++) { int n, k; string s; cin >> n >> k >> s; k--; string res = ; for (int i = (0); i < (n / 2 - k); i++) res.p...
#include <bits/stdc++.h> using namespace std; const int maxn = 500 + 4; const int maxlog = 22; const int mod = 1e9 + 7; const int sq = 350; int n, m; int ans[maxn][maxn][2]; pair<int, int> par[maxn][maxn][2]; queue<pair<pair<int, int>, bool> > q; vector<int> edge[maxn]; void solve() { while (!...
#include <bits/stdc++.h> int main() { int n, m; char c[12][13]; scanf( %d %d , &n, &m); for (int i = 1; i <= n; ++i) scanf( %s , &c[i][1]); int eaten(0); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { if (c[i][j] == W ) { if (c[i - 1][j] == P || c[i + ...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { int arr[100005]; for (int i = 1; i <= n; i++) { cin >> arr[i]; } long long cnt = 0; for (int i = 1; i < n; i++) { long long x = log2(n - i); arr[i + (1 << x)] += arr[i];...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = ...
#include <bits/stdc++.h> using namespace std; int n; long long s[10000] = {0}; long long c[10000] = {0}; long long dp[2][10000] = {0}; int main() { for (int i = 0; i < 10000; i++) { dp[0][i] = 100000000000000; dp[1][i] = 100000000000000; } cin >> n; for (int i = 0; i < n; i++) ci...
#include <bits/stdc++.h> using namespace std; int a[100100] = {}, b[100100] = {}, c[100100] = {}; int main() { int n, x, y; cin >> n >> x >> y; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); b[i] = a[i]; } sort(a + 1, a + n + 1); if (x < y) { int t = x, z = a[y + 1]; ...
#include <bits/stdc++.h> using namespace std; string flip1(string st) { swap(st[0], st[1]); swap(st[1], st[2]); swap(st[2], st[3]); return st; } string flip2(string st) { swap(st[0], st[4]); swap(st[4], st[2]); swap(st[2], st[5]); return st; } string fun(string x) { strin...
#include <bits/stdc++.h> using namespace std; int a, b; int main() { while (cin >> a >> b) { int min = 0; int temp = a; while (temp) { if (min < temp % 10) min = temp % 10; temp /= 10; } temp = b; while (temp) { if (min < temp % 10) min = temp % 10; ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:20000000 ) string problem_name = a ; void init() { freopen((problem_name + .in ).c_str(), rt , stdin); } struct tpoint { int x, y; }; long long vp(tpoint a, tpoint b, tpoint c) { tpoint f, s; f.x = b.x - a.x; ...
#include <bits/stdc++.h> using namespace std; const int N = 9e5 + 7; const long long INF = 1e9 + 7; int main() { cout << 2000 << endl; for (int i = 1; i <= 1000; i++) cout << i << 1 << i << 2 n ; for (int i = 1000; i >= 1; i--) cout << i << 1 << i << 2 n ; return 0; }
#include <bits/stdc++.h> using namespace std; long long inf = 2147483647; const long long ll = 9223372036854775807, ninf = 1000000000; const double eps = 1e-6; const long long nll = 1000000000000000000; class MulticoreProcessingEasy { public: int fastestTime(int jobLength, int corePenalty, vector<int...
#include <bits/stdc++.h> using namespace std; long long powm(long long base, long long exp, long long mod = 1000000007) { long long ans = 1; while (exp) { if (exp & 1) ans = (ans * base) % mod; exp >>= 1, base = (base * base) % mod; } return ans; } long long ctl(char x, char an = a ...
#include<bits/stdc++.h> using namespace std; #define w(t) int t; cin>>t; while(t--) #define int long long int #define I int32_t #define asc(i,a,n) for(int i=a;i<n;i++) #define dsc(i,n,a) for(int i=n;i>=a;i--) #define vi vector<int> #define pi pair<int,int> #define PB push_back #define MP make_pair ...
#include <bits/stdc++.h> using namespace std; struct team { string nam; int pt, diff, get; } T[55]; int n; void gao(string s, int pt, int diff, int get) { for (int i = 0; i < n; i++) { if (s == T[i].nam) { T[i].pt += pt; T[i].diff += diff; T[i].get += get; bre...
#include <bits/stdc++.h> using namespace std; char s[200005], t[200005]; vector<int> pos[200005]; int main() { int T; scanf( %d , &T); while (T--) { for (int i = 0; i <= 30; i++) pos[i].clear(); scanf( %s%s , s, t); int l1 = strlen(s), l2 = strlen(t); int now = -1, ans = 0; ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long f = 1, x = 0; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 0 ; ch = getchar(); } return x * f; } ...
#include <bits/stdc++.h> using namespace std; struct node { long long A, B; }; bool func(node s1, node s2) { return s1.A < s2.A; } int main() { long long n; cin >> n; std::vector<node> b(n); vector<long long> a(n); ; for (long long i = 0; i <= n - 1; i++) { cin >> a[i]; }...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, f = 0, a; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &a); if (a == 1) f = 1; } if (f) printf( %d , -1); else printf( %d , 1); return 0; }
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) int32_t main() { ios::sync_with_stdio(false); cin.tie(0); long long a, b; cin >> a >> b; lon...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); for (int i = 0; i < (n / 2); i++) printf( 01 ); if (n % 2) printf( 0 ); printf( n ); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t, tc; cin >> t; for (tc = 0; tc < t; tc++) { int n, i; cin >> n; vector<int> v(n), mx(n + 1, 0), mn(n + 1, n + 5); for (i = 0; i < n; i++) { cin >> v[i]; mx[v[i]] = i; mn[v[i]] = i; } ...
#include <bits/stdc++.h> using namespace std; long long lower, upper, res; char num1[65536], num2[65536], num[65536]; void DFS(int depth, bool lower_flag, bool upper_flag) { if (depth == 10) { long long a = 0, b = 0; bool flag = false; for (int i = 0; i < 10; i++) { if (num[i] != ...
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { long long int ans = 1; while (b) { if (b & 1) { ans = ((ans % 1000000007) * (a % 1000000007)) % 1000000007; } a = ((a % 1000000007) * (a % 1000000007)) % 1000000007; b = b >>...
#include <bits/stdc++.h> using namespace std; vector<int> v(7); int main() { int n; string s; cin >> n; for (int j = 0; j < n; j++) { auto a = 0; cin >> s; for (auto &c : s) { int r = c - 48; v.at(a) += r; a++; } } auto result = *max_element(...
#include <bits/stdc++.h> using namespace std; const long long int N = 200010; const long long int MOD = 998244353; long long int mod(long long int n) { return (n % MOD + MOD) % MOD; } void solve() { long long int n; cin >> n; long long int a[n]; long long int sum = 0; for (long long int i ...
#include <bits/stdc++.h> using namespace std; struct node { long long int cur; long long int lr; long long int e; long long int f; long long int rl; node() {} node(long long int cur, long long int lr, long long int e, long long int f, long long int rl) : cur(cur), lr(lr)...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2e5 + 1; int main() { int N, Q; cin >> N >> Q; set<int> all; multiset<int> gaps; for (int i = 0; i < N; ++i) { int x; cin >> x; all.insert(x); } for (auto iter = all.begin(); iter != all.end(); ++iter) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<vector<long long> > PRE(32, vector<long long>(n + 2, 0)), ZEROS(32, vector<long long>(n + 2, 0)); vector<long long> L(m), R(m), Q(m); for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; int toNumber(string s) { int Number; if (!(istringstream(s) >> Number)) Number = 0; return Number; } string toString(int number) { ostringstream ostr; ostr << number; return ostr.str(); } int main() { int n, m, k; while (cin >> n ...
#include <bits/stdc++.h> using namespace std; int main() { int x = 0, y = 0; int n; char a[205] = { 0 }; scanf( %d , &n); scanf( %s , a + 1); for (int i = 1; i <= n; i++) { if (a[i] == 0 ) x++; else y++; } if (x == y) { printf( 2 n ); printf(...
#include <bits/stdc++.h> using namespace std; struct node { int x, y, id; }; node A[1000100]; int ans[1000100]; vector<int> P[1200]; int cmp1(node a, node b) { return a.x < b.x; } int cmp2(int a, int b) { return A[a].y < A[b].y; } const int Base = 1000; int main() { int n; scanf( %d , &n...
#include <bits/stdc++.h> using namespace std; const int N = 5e3; vector<int> od; vector<int> ev; void manachar(string s) { string x = @# ; for (auto c : s) x.push_back(c), x.push_back( # ); x.push_back( $ ); s = x; int n = s.size(); int l = 0, r = 0; vector<int> pp(n); for (in...
#include <bits/stdc++.h> using namespace std; const int MX = 400500; int u_mask = (1 << 30) + ((1 << 30) - 1); int a[MX]; int n; namespace tree { const int delta = 1 << 18; int val[2 * delta]; int rev[2 * delta]; void init() { val[delta] = rev[delta] = u_mask; for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long mod2 = 998244353; long long inf = 1000000000000000000; double pi = 2 * acos(0); int dh[4] = {1, -1, 0, 0}; int dw[4] = {0, 0, 1, -1}; int ddh[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; int ddw[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; ...
#include <bits/stdc++.h> using namespace std; int n; int query(string s) { cout << ? << << s << endl; cout.flush(); int ans; cin >> ans; ans = n - ans; return ans; } string str(int k) { string s; s.resize(n); for (int i = 0; i < k; i++) s[i] = 0 ; for (i...
#include <bits/stdc++.h> int n; long long x, y, z = 2; int main() { scanf( %d , &n); for (long long k = 1; k <= n; k++) { y += 2; x += y; double a = x; double b = z; a = (double)(a / k); b = (double)(b / k); a = (double)a * x; printf( %.0lf n , (double)a - b...
#include <bits/stdc++.h> using namespace std; const int L = 2000; const int AB = 26; int cnt[AB]; char s1[L + 2], s2[L + 2]; int n; char tmp[L + 2]; vector<int> ans; void shift(int); int main() { scanf( %d , &n); scanf( %s%s , s1 + 1, s2 + 1); for (int i = 1; i <= n; ++i) { ++cnt[s...
#include <bits/stdc++.h> using namespace std; ifstream fin( input ); void init() { cin.tie(NULL); ios_base::sync_with_stdio(false); } struct operation { int i, j, x; }; int n; vector<int> v; vector<int> cpy; vector<operation> ops; void simul() { for (operation x : ops) { cpy[...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) using namespace std; using ll = long long int; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vpii = vector<pii>; using vpll = vector<pll>; using ...
#include <bits/stdc++.h> using namespace std; bool one(string s); bool two(string s); void c(string s); void c2(string s); int main() { string str; int i; cin >> str; if (one(str)) { c(str); } else if (two(str)) { c2(str); } else { cout << str << endl; } ret...
#include <bits/stdc++.h> using namespace std; template <class T> inline int SIZE(T& n) { return n.size(); } template <class T> void OUT(const T& n) { for (unsigned int i = 0; i < n.size(); ++i) { cout << n[i] << ; } cout << endl; } int toInt(string s) { int r = 0; string...
#include <bits/stdc++.h> using namespace std; long long mp[2010][2010]; long long sum1[2010][2010], sum2[2010][2010]; int n; int check(int x, int y, int xx, int yy) { int remy = abs(yy - y); int remx = abs(xx - x); if (remy == remx) return 0; return 1; } long long getsum(int i, int j) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, j = 0, i, s, t; cin >> n; int a[n + 1]; for (i = 1; i <= n; i++) cin >> a[i]; s = a[1] + 2 * n - 1; for (i = 1; i < n; i++) s += abs(a[i] - a[i + 1]); cout << s; return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int n; int main() { cin >> n; for (int i = 2; i * i <= n; i++) { if (n % i != 0) continue; int m1 = i; for (int z1 = 1; z1 < m1; z1++) { int val = n - 1 - z1 * (n / i); if (val > 0 && val % m1 ...
#include <bits/stdc++.h> using namespace std; long long add(int a, int b) { return (a % 1000000007 + b % 1000000007 + ((8000000000000000064LL) / 1000000007) * 1000000007) % 1000000007; } long long sub(long long a, long long b) { return (a % 1000000007 - b % 1000000007 + ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1.e9 + 7; const int MAXN = 1000000; int fact[MAXN + 5], inv[MAXN + 5]; int lgput(int a, int b) { int ans = 1; for (; b; b >>= 1) { if (b & 1) ans = 1LL * ans * a % MOD; a = 1LL * a * a % MOD; } return ans; } void pre...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) using namespace std; const int MOD = 1000000007; bool ispalindrome(string &s) { for (int i = 0; i < (int)s.size() / 2; i++) { if (s[i] == s[(s.size() - i - 1)]) continue; else return false...
#include <bits/stdc++.h> using namespace std; long long dp[1020][600], mod = (1000000007); long long solve(int n, int m, int k) { if (n < 2 * k - 1 or m < 2 * k - 1) return 0; if (n <= 0 or m <= 0) return !k; if (!k) return 1; if (n == 2 * k - 1) { if (dp[m][k] != -1) return dp[m][k]; ...
#include <bits/stdc++.h> const int MAX = 1e5 + 10; using namespace std; char x[MAX], y[MAX]; int func[MAX][26], f[MAX], xlen, ylen; int dp[2][MAX]; int main() { scanf( %s %s , x, y); xlen = strlen(x); ylen = strlen(y); int k = 0; f[0] = 0; if (xlen < ylen) { printf( 0 n ); ...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; for (int t = 0; t < T; t++) { int n; cin >> n; int a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } int differe...
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, res = pow(10, 18); cin >> n; vector<long long int> v(n); for (long long int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); for (long long int i = 0; i < n / 2; i++) res = min(res, v[i + n / 2] - v[i]); ...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, , ); ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int N; char S[1010][20202]; int len[1010]; int cmp[20202]; int tmp[20202]; int D[2][20202]; int main() { scanf( %d , &N); for (int i = 1; i <= N; i++) { scanf( %s , S[i] + 1); len[i] = strlen(S[i] + 1); }...
#include <bits/stdc++.h> using namespace std; int dp[2005][2005] = {0}; long long int n, t, m, h, l, r; int check(int v) { return v >= l && v <= r; } void solve() { cin >> n >> h >> l >> r; vector<int> v; for (int i = 0; i < n; i++) { cin >> t; v.push_back(t); } for (int i = 0;...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string s; cin >> s; queue<string> q; set<string> st; int ans = 0; q.push(s); st.insert(s); while (!q.empty() && int(st.size()) < k) { string v = q.front(); q.pop(); for (int ...
#include <bits/stdc++.h> const int MAXN = 1e5 + 5; std::unordered_map<int, int> cnt; int a[MAXN]{}; int m = 1e9, n; int main() { scanf( %d , &n); cnt.reserve(n); for (int i = 0; i < n; ++i) { scanf( %d , &a[i]); ++cnt[a[i]]; } std::sort(a, a + n); int bank = cnt.at(a[0]), r...
#include <bits/stdc++.h> using namespace std; int ans[4000], n; string s; int main() { cin >> n; cin >> s; for (int i = 1; i <= n; i++) ans[i] = 1; for (int i = 0; i < n - 1; i++) { if (s[i] == = ) { ans[i + 2] = ans[i + 1]; } if (s[i] == R ) ans[i + 2] = ans[i + 1] +...
#include <bits/stdc++.h> using namespace std; long long n, a[100100]; bool vis[100100]; vector<long long> v; int main() { long long n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); if (a[n - 1] >= a[n - 2] + a[n - 3]) { cout << NO << endl; return 0; }...
#include <bits/stdc++.h> using namespace std; vector<long long> g; long long from, to; void recurse(long long n) { if (n > to) return; if (n >= from && n <= to) { g.push_back(n); } recurse(n * 10 + 4); recurse(n * 10 + 7); } long long get(long long f, long long t, long long ff, lon...
#include <bits/stdc++.h> using namespace std; int main(void) { int n, k, count, x, y, sum; cin >> n >> k; count = 2; x = (n - 1) / k; y = (n - 1) % k; if (y == 0) { sum = 2 * x; } else if (y == 1) { sum = 2 * x + 1; } else { sum = 2 * (x + 1); } cout << sum ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t, n, k; cin >> t; while (t--) { cin >> n >> k; if (k % 2) { if (n % 2) { n -= k - 1; if (n > 0) { cout << YES n ; for ...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int M = 3600 + 10; int w, h, mx, n, r[M], c[M], cntx, cnty; long long int fac[M], inv[M], g[M][M], f[M][M], ans; long long int qpow(long long int a, long long int b) { long long int y = 1; for (; b; a = a * a % mod, b >>=...
#include <bits/stdc++.h> using namespace std; int MAX = 1000000; int MIN = -1000000; int INF = 1000000000; int x4[4] = {0, 1, 0, -1}; int y4[4] = {1, 0, -1, 0}; int x8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; int y8[8] = {1, 1, 0, -1, -1, -1, 0, 1}; int i, j, k; int main() { string str; cin >> str;...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2 ) #pragma GCC optimize( unroll-loops ) #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define req(i,a,b) for(int i=(a);i>=(b);--i) #define rep_(i,a,b) for(int i=(a);i<(b).size();++i) #define ...
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e9 + 7; const long long int mod = 998244353; long long int mini(long long int a, long long int b) { if (a >= b) return b; return a; } long long int maxi(long long int a, long long int b) { if (a >= b) return a; return b...