func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int b[100]; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; b[a[i]]++; } int f = 0, h = -1; for (int i = 1; i <= 100; i++) { if (b[i] == 1) { f++; } else if (b[i] > 2) { ...
#include <bits/stdc++.h> using namespace std; long long a, b, mod1 = 998244353, mod2 = 1000000007, mod3 = 1222827239; string s1, s2; struct ha { long long q1, q2, q3; bool operator==(const ha &aa) const { return (q1 == aa.q1 && q2 == aa.q2 && q3 == aa.q3); } } has[500001], gg[500001], base[5...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; if (n % 4 != 0) { cout << NO n ; continue; } cout << YES n ; for (int i = 2; i <= n; i += 2) cout << i << ; for (int i = 1; i < n - 1;...
#include <bits/stdc++.h> using namespace std; template <typename T> vector<T> uniq(vector<T> v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); return v; } template <typename T> struct RMQ { using F = function<T(const T &, const T &)>; int n; vector<T> t; ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - 0 ; return x * f; } const long long MAXN = 100010; const lo...
#include <bits/stdc++.h> using namespace std; long long n, m; long long x, y, z; vector<pair<long long, long long> > v[200005]; long long dp[300]; bool used[2000005]; long long len[100005]; void dfs(long long x) { used[x] = true; for (long long i = 0; i < v[x].size(); ++i) { long long to =...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; char m = b ; int ans = 0; int k = 0, bm = 0, rm = 0; while (k < n) { if (s[k] == m) { if (m == b ) m = r ; else m = b ; k++; } e...
#include <bits/stdc++.h> using namespace std; char A[5010], B[5010]; int N, M; int f[5010][5010]; int main() { scanf( %d%d , &N, &M); scanf( %s , A + 1); scanf( %s , B + 1); int ans = 0; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) { f[i][j] = max(f[i - 1][j] -...
#include <bits/stdc++.h> using namespace std; vector<int> t; void upd(int v, int x) { for (int i = v; i < t.size(); i |= (i + 1)) { t[i] += x; } } int get(int v) { int sum = 0; for (int i = v; i >= 0; i = (i & (i + 1)) - 1) { sum += t[i]; } return sum; } int low_b(int s...
#include<bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ int n; cin>>n; int A[n],B[n]; vector<int>pos,neg; for(int i=0;i<n;++i){ cin>>A[i]; } int z=0; ...
#include <bits/stdc++.h> using namespace std; int arr[3]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; for (int i = 0; i < t; ++i) { int x; cin >> x; arr[i % 3] += x; } int count = 0; for (int i = 0; i < 3; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n + 1]; for (int i = 1; i <= n; i++) cin >> arr[i]; int x; cin >> x; int w, l; while (x--) { cin >> w >> l; if (w == 1) { arr[2] += arr[1] - l; arr[1] = 0; continue...
#include <bits/stdc++.h> using namespace std; inline int read() { register int X = 0; register char ch = 0; while (ch < 48 || ch > 57) ch = getchar(); while (ch >= 48 && ch <= 57) X = X * 10 + (ch ^ 48), ch = getchar(); return X; } long long powM(long long a, int t = 998244353 - 2) { lon...
#include <bits/stdc++.h> using namespace std; const long long mod = 20071027; const double pi = acos(1.0 * (-1)); int p[1001111]; long long fun(long long x) { long long dt = 1 + 8 * x; long long t = sqrt(dt * 1.0) + 0.0000001; if (t * t != dt) return -1; return (1 + t) / 2; } int main() { ...
#include <bits/stdc++.h> #pragma GCC optimize( unroll-loops ) using namespace std; int main() { int q; cin >> q; while (q--) { int n; cin >> n; long long a[n + 5], m = 0; vector<int> idx; for (int i = 0; i < n; i++) { cin >> a[i]; } long long ans = 0; ...
#include <bits/stdc++.h> using namespace std; const int MX = 300003; int h[4][4]; bool res[4][MX]; int len; int calc(int i) { if (h[0][i] <= h[0][1]) { int x = h[0][1] - h[0][i]; if ((h[1][i] < x) || (h[1][i] - x) % 2) return -1; int k = (h[1][i] - x) / 2; if (k > h[0][i]) return...
#include <bits/stdc++.h> using namespace std; int b, k, a[100005], sum, tmp; int main() { cin >> b >> k; for (int i = 1; i <= k; ++i) { scanf( %d , &a[i]); a[i] %= 2; } tmp = 1; for (int i = k; i >= 1; --i) { sum = (sum + tmp * a[i]) % 2; tmp = tmp * b % 2; } if...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d %d , &n, &m), ++n; long long ans = 0; for (int a = m + 1; a <= n / 2; ++a) { int tmp = 0; for (int b = m + 1, c = n - m - 1; b < n - m && c > m; ++b) { while (c > m && a * ((a << 1) + b - (n << 1) - c)...
#include <iostream> #include <iosfwd> #include <iomanip> #include <cstdio> #include <cstring> #include <cstdlib> #include <ctime> #include <cmath> #include <cassert> #include <cctype> #include <climits> #include <vector> #include <bitset> #include <set> #include <queue> #include <math.h> ...
#include <bits/stdc++.h> using namespace std; int c[1200000], save[5500]; bool flag[1200000]; int main() { int n, k; while (scanf( %d%d , &n, &k) != EOF) { for (int i = 1; i <= n; i++) scanf( %d , &save[i]); sort(save + 1, save + n + 1); memset(c, 0, sizeof(c)); for (int i = 1; i...
#include <bits/stdc++.h> using namespace std; using VI = vector<int>; using VI2 = vector<VI>; using UM = unordered_map<int, int>; using UM2 = unordered_map<int, UM>; using M = map<int, int>; using M2 = map<int, M>; using u64 = unsigned long long; using i64 = long long; using u32 = unsigned int; us...
#include <bits/stdc++.h> using namespace std; int n, m, tmp = 1; int sum(int a) { int res = 0; while (a) { res += a % 10; a /= 10; } return res; } int main() { cin >> n >> m; if (2 * n > 2220) { int nn = n / 2 + n % 2; for (int i = 1; i <= nn; ++i) { cou...
#include <bits/stdc++.h> using lli = long long int; using li = long int; using namespace std; const lli MOD{1000000007}; const lli INF{(false ? (INT_MAX - 1) / 2 : (lli)1e18 + 5)}; const lli N{200005}; int main() { cout << setprecision(15); cin.tie(nullptr)->sync_with_stdio(false); li T{1}; ...
#include <bits/stdc++.h> using namespace std; void fnc() { int n; cin >> n; cout << n << endl; for (int i = 0; i < n; i++) cout << i + 1 << ; cout << endl; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) fnc(); }
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; template <class T> inline void chkmin(T &a, T b) { if (a > b) a = b; } template <class T> inline void chkmax(T &a, T b) { if (a < b) a = b; } int main() { int n, m; cin >> n >> m; --n; int l = 1, r = ...
#include <bits/stdc++.h> int main() { int N, gre[101], res[100][101], n, i, j; scanf( %d , &N); for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { scanf( %d , &res[i][j]); } gre[i] = 1; } n = 0; for (i = 0; i < N; i++) { for (j = i; j < N; j++) { if (re...
#include <bits/stdc++.h> using namespace std; struct Fenwick { int n; long long tree[200002]; void init(int _n) { n = _n; fill(tree + 1, tree + n + 1, 0LL); } void upd(int x, long long val) { while (x <= n) { tree[x] += val; x += x & -x; } } long l...
#include <bits/stdc++.h> using namespace std; long long t[500005], mid; long long l[500005], r[500005], h[500005]; struct st { long long h, cnt; }; stack<st> q; int main() { cin.sync_with_stdio(0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> t[i]; q.push({-1, 1}); for ...
#include <bits/stdc++.h> using namespace std; int a, b, t; void read_input() { cin >> a >> b; } void solve() { int res = abs(a - b); int ans = res / 5; res = res % 5; ans += res / 2; res %= 2; ans += res; cout << ans << endl; } int main() { ios::sync_with_stdio(0), cin.tie(0)...
#include<bits/stdc++.h> using namespace std; long long a[1000010]; bool cmp(long long a,long long b) { return a>b; } int main() { long long m,n,i,j,x,y,suma=0,sumb=0; cin>>n; while(n--) { cin>>m; for(i=0;i<m;i++) cin>>a[i]; sort(a,a+m,cmp); for(i=0;i<m;) { if(a[...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int ar[n + 2], tr1[n + 2], tr2[n + 2], kl[k + 2][102]; memset(kl, 0, sizeof(kl)); vector<pair<int, int>> vec; for (int i = 0; i < n; i++) { cin >> ar[i]; tr1[i] = ar[i]; tr2[i] = ar[i]; ...
#include <bits/stdc++.h> using namespace std; void sol(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; long long ml = 1, ans = 0; vector<int> ls(n); map<long long, int> pre, mp; mp[0] = 1; vector<long long> an; while (ml < 1e15) { ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int n, bin[35], f[35][35][2]; void updata(int &x, int y) { x += y; x -= x >= MOD ? MOD : 0; } int main() { scanf( %d , &n); bin[0] = 1; for (int i = 1; i <= 30; i++) bin[i] = bin[i - 1] * 2; for (int i = 30; i ...
#include <bits/stdc++.h> using namespace std; void redondear(string &s, int pto, int idx) { if (idx == (int)(s.size())) { cout << s << endl; return; } s.resize(idx); bool unoAdelante = false; for (int i = (idx)-1; i >= (int)(0); i--) { if (i == pto) { continue; } ...
#include <bits/stdc++.h> using namespace std; int n; int l, r; void did(int &x, int y) { printf( ? %d n , y); fflush(stdout); scanf( %d , &x); } int main() { scanf( %d , &n); if ((n / 2) & 1) { printf( ! -1 ); fflush(stdout); return 0; } while (1) { printf...
#include <bits/stdc++.h> using namespace std; const int M = 3010; int n, x[M]; char d[M][6]; int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1}; vector<long long> X, Y; int g[M][M], fw1, fw2; queue<pair<int, int> > Q; const long long INF = 20000000005LL, MINF = -INF; struct point { long long lasx, l...
#include <bits/stdc++.h> using namespace std; const int maxn = 60; int n, l; char s[maxn][maxn], t[maxn]; bool eq(int x, int i, int j) { for (int k = 0; k < l; k++) { if (s[x][i] != t[j]) return false; i = (i + 1) % l; j = (j + 1) % l; } return true; } int dist(int x, int j) ...
#include <bits/stdc++.h> using namespace std; int n, k, p[1000001]; long long ans; int main() { scanf( %d%d , &n, &k); if (k == 1) { printf( 3 ); return 0; } for (int i = 1; i <= n; i++) p[i] = i; for (int i = 2; i <= n; i++) if (p[i] == i) for (int j = i; j <= n; j...
#include <bits/stdc++.h> using namespace std; int num[10010]; int dp[1 << 18]; int bad[1 << 18]; int g[100][100]; int tmp[1 << 18]; string s; int get(int l, int r) { int t = 0; for (int i = l; i <= r; ++i) { t |= 1 << (s[i] - a ); } return t; } int main() { int n, p; s...
#include <bits/stdc++.h> using namespace std; int main() { long long n; scanf( %lld , &n); if (n == 1 || n == 2) { puts( -1 ); return 0; } if (n & 1) { n -= 1; n /= 2; printf( %lld %lld n , 2 * n * n + 2 * n, 2 * n * n + 2 * n + 1); } else { n /= 2; ...
#include <bits/stdc++.h> using namespace std; int main() { int s, a, b, c; cin >> s >> a >> b >> c; double x = 0.0, y = 0.0, z = 0.0; if (a || b || c) { x = s * a / (double)(a + b + c); y = s * b / (double)(a + b + c); z = s * c / (double)(a + b + c); } printf( %.12f %.12f ...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0; int f = 1, ch = getchar(); for (; !isdigit(ch) && ch != EOF; ch = getchar()) if (ch == - ) f = -1; for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 0 ); return x * f; } const int N = 500005; in...
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a; cin >> b; int lena = a.length(), lenb = b.length(); if (lena != lenb) cout << NO ; else { int count = 0; char old1, old2; for (int i = 0; i < lena && count < 3; i++) { if (a[i] ...
#include<bits/stdc++.h> namespace my_std{ using namespace std; #define pii pair<int,int> #define fir first #define sec second #define MP make_pair #define rep(i,x,y) for (int i=(x);i<=(y);i++) #define drep(i,x,y) for (int i=(x);i>=(y);i--) #define go(x) for (int i=head[x];i;i=edge[i].nxt) #...
#include <bits/stdc++.h> using namespace std; string s; int ans; map<int, int> f; int main() { cin >> s; int n = s.length(); f[0] = 1; int cur = 0; for (int i = 1; i < n; i++) { if (s[i] == s[i - 1]) { f[cur]++; } else { f[i]++; cur = i; } } ...
#include <bits/stdc++.h> using namespace std; pair<long double, long double> a[100005]; long double isum = 0, min1 = 1000000000000, isum1, t[100005], min2 = 1000000000000, min3 = 1000000000000, min4 = 1000000000000, min5 = 1000000000000; int i, j; long long ax, ay, bx, by, tx, ty, ...
#include <bits/stdc++.h> using namespace std; const char nl = n ; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, v1, v2, t1, t2; cin >> n >> v1 >> v2 >> t1 >> t2; if (n * v1 + t1 * 2 < n * v2 + t2 * 2) cout << First << nl; else if (n * v1 + t1 * 2 > n * v2 + t2 * 2...
#include <bits/stdc++.h> using namespace std; void swap(long long &a, long long &b) { auto tm = a; a = b; b = tm; } const long long mod = 1000000009; const long long mod2 = 998244353; const long long INF = (1LL << 20) - 1; const long long N = 2e5 + 25; long long n, m, a, b; vector<long lon...
#include <bits/stdc++.h> void rd(int &x) { x = 0; int f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch <= 9 && ch >= 0 ) x = x * 10 + ch - 0 , ch = getchar(); x *= f; } void lrd(long long &x) { x = 0; ...
#include<bits/stdc++.h> using namespace std; #define lp(i,a,n) for(i=a;i<n;i++) #define ld(i,a,n) for(i=n-1;i>=a;i--) #define ll long long #define dd double #define mod 10000007 #define inf 1e18 #define inp(t) cin>>t; while(t--) int main(){ int t; ios::sync_with_stdio(false); inp(t){ ll n...
#include <bits/stdc++.h> using namespace std; int n; double V1; double V2[100005]; double L[100005]; double D[100005]; double X[100005]; bool check(double T) { bool ok1 = false; bool ok1b = false; bool ok2 = false; bool ok2b = false; double l = 0; double r = 1000000; vector<p...
#include <bits/stdc++.h> using namespace std; vector<int> pat[100000]; int main() { int num, way; scanf( %d%d , &num, &way); set<pair<int, int> > se; for (int i = 0; i < way; i++) { int za, zb; scanf( %d%d , &za, &zb); za--; zb--; pat[za].push_back(zb); pat[zb]....
#include <bits/stdc++.h> using namespace std; string s1, s2; int a, b; int nxt[205], cnt[205]; int main() { scanf( %d%d , &a, &b); cin >> s1 >> s2; for (int i = 0; i < s2.size(); i++) { int pos = i; for (int r = 0; r < s1.size(); r++) { if (s2[pos] == s1[r]) { pos++; ...
#include <bits/stdc++.h> using namespace std; const int MX = 500005; const int MC = 2; int get(char c) { if (c == ( ) return 0; return 1; } struct Node { int l, r, pardp; Node *par, *sLink; Node *chd[MC]; bool isLeaf; int st; Node() { l = r = pardp = 0; par = sLi...
#include <bits/stdc++.h> using namespace std; const int Maxn = 7005; const int Maxm = 1000006; int n, m; int a[Maxn], b[Maxn], c[Maxn], d[Maxn], e[Maxn]; int mn[Maxn], mx[Maxn]; bool has[Maxm]; vector<int> tk; int main() { scanf( %d %d , &n, &m); for (int i = 0; i < m; i++) { scanf( %d %...
#include <bits/stdc++.h> using namespace std; int n, m; struct Node { int pos, val, sit; } a[305]; bool cmp(Node x, Node y) { if (x.val == y.val) { return x.pos > y.pos; } return x.val < y.val; } bool cmp2(Node x, Node y) { return x.pos < y.pos; } int main() { int T; std::c...
#include <bits/stdc++.h> using namespace std; const int INTINF = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int MAXN = 55; const int MAXM = (1 << 20) + 1; long long dp[MAXM], C[MAXN][MAXN]; int n, m; char a[MAXN][MAXN]; double ans = 0; int count(long long x) { int res = 0; w...
#include <bits/stdc++.h> using namespace std; long long n, m, s, t, l, rest; long long d[1010], d2[1010], w[10010]; bool zeredg[10010]; pair<long long, long long> edg[10010]; vector<vector<long long> > edglist; void dijkstra(long long dist[], bool sec) { set<pair<long long, long long> > najbl; dis...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int a[200007]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &a[i]); sort(a, a + n); int c = n / 2 - 1; int l = 0, r = n - 1; int mn = 1e9 + 77; for (int i = 0; i <= c; i+...
#include <bits/stdc++.h> using namespace std; template <class _T> inline _T sqr(const _T &first) { return first * first; } template <class _T> inline string tostr(const _T &a) { ostringstream os( ); os << a; return os.str(); } const long double PI = 3.1415926535897932384626433832795L; ...
#include <bits/stdc++.h> using namespace std; const double long EPS = 1e-10; struct wor { double long x = 0, y = 0; }; double long dist(wor a, wor b) { double long answer = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); return answer; } pair<vector<double long>, vector<lo...
#include <bits/stdc++.h> using namespace std; struct edge { int target; int weight; int o; }; struct vertice { long long time; int city; int edge_ID; int edge_W; }; struct mysort { bool operator()(const vertice &l, const vertice &r) { if (l.time == r.time) retur...
#include <bits/stdc++.h> const int MAX_N = (int)3e5 + 123; const long long inf = (long long)1e18 + 123; using namespace std; char ans[2][30]; string second; pair<long long, long long> do_it(int l, int r) { int len = r - l; int last = 13 - (len + 1) / 2; pair<long long, long long> res = make_pair...
#include <bits/stdc++.h> using namespace std; inline long long min2(long long a, long long b) { return (a) < (b) ? (a) : (b); } inline long long max2(long long a, long long b) { return (a) > (b) ? (a) : (b); } inline long long max3(long long a, long long b, long long c) { return (a) > (b) ? ((a)...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int T; scanf( %d , &T); while (T--) { ll n, m, ans = 0; scanf( %lld%lld , &n, &m); for (ll k = 1; k <= n / k; k++) { ans += max(0ll, min(n / k - 1, m) - k); } printf( %lld n , ans); } ...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 1]; int sum = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; int G[n + 1][m + 1]; memset(G, 0, sizeof(G)); for (int l = 0; l < k; l++) { int i, j; cin >> i >> j; G[i][j] = 1; if ((i > 1 && j > 1 && G[i - 1][j] && G[i][j - 1] && G[i - 1][j - ...
#include <bits/stdc++.h> using namespace std; const int d[][2] = {{1, -1}, {1, 1}, {-1, -1}, {-1, 1}}; const char* ds[] = { DL , DR , UL , UR }; int gdi(const char* s) { int i = -1; while (++i < 4) { if (!strcmp(s, ds[i])) return i; } } bool sv[4] = {false}; int fdi(const int dr, cons...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long N = 1e6 + 1; long long pre[N], sub[N]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; string str; cin >> str; long long a = 0, b = 0, c = 0; for (long long i = 0; i ...
#include <bits/stdc++.h> using namespace std; struct node { int sum; int adj[6]; node() { sum = 0; memset(adj, -1, sizeof adj); } }; int n, m; vector<node> T; map<string, int> S; void add(string x) { int cur = 0; for (int i = 0; i < x.size(); i++) { int c = x[i] -...
#include <bits/stdc++.h> using namespace std; int arr[100009], mark[100009], vis[100009]; map<pair<int, int>, int> mp; map<pair<int, int>, int>::iterator ii; int main() { int n, i; scanf( %d , &n); for (i = 0; i < n; ++i) scanf( %d , &arr[i]); memset(mark, 0, sizeof mark); for (i = 0; i < ...
#include <bits/stdc++.h> using namespace std; template <typename... Args> void dbg(Args... args) { ((cout << args << ), ...); } const int N = 110; char t[N][N][N]; char f[N][N][N]; int main() { int n, m, k; cin >> n >> m >> k; for (int x = 1; x <= n; ++x) for (int y = 1; y <= m;...
#include <bits/stdc++.h> using namespace std; const int MX = (int)2e5 + 10; const int mod = (int)1e9 + 7; bool check(string& t) { bool ok = true; int n = t.size(); for (int j = 0; j < n / 2; ++j) { ok &= t[j] == t[n - j - 1]; } return ok; } int main(int argc, char* argv[]) { ci...
#include <bits/stdc++.h> using namespace std; using ll = long long; char change(char c) { if (c == B ) { return W ; } return B ; } int main() { int n, k; cin >> n >> k; string s; cin >> s; int good = -1; vector<int> start(n, -1); for (int i = 0; i != n; ++i) { ...
#include <bits/stdc++.h> void out(int x) { if (x) { std::cout << x << std::endl; } else { std::cout << Impossible << std::endl; } exit(0); } bool string_is_palindorome(const std::string& s) { for (int i = 0, j = s.size() - 1; i < j; i++, j--) if (s[i] != s[j]) return false;...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 300; const long long mod = 1e9 + 7; const long long NN = 20 + 1; vector<pair<long long, long long> > a[N]; long long p[N][NN], t[N], dp[N], dp2[N], sum[N], h[N], dp3[N], dp4[N], n; void dfs2(long long v, long long par = -1, long long ...
#include <bits/stdc++.h> const double PI = acos(-1.0); using namespace std; int t[100010]; void update(int x, int v) { for (; x < 100010; x += (x & -x)) t[x] += v; } int sum(int r) { int ans = 0; for (; r > 0; r -= (r & -r)) ans += t[r]; return ans; } int sum(int l, int r) { if (l > ...
#include <bits/stdc++.h> using namespace std; const int MX = 35; bitset<MX * MX> bs[MX * MX]; int n, a[MX][MX], m, sz, h, res; void impr() { for (int k = 0; k < m; k++) { cout << k << : << n ; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cout << bs[k][((i)*n + (j))] <...
#include <bits/stdc++.h> using namespace std; long long N, A[100]; int main(void) { cin >> N; for (long long i = ((long long)0); i < ((long long)N); i++) cin >> A[i]; bool ans = true; long long p1 = 1, p2 = 2, s = 3; for (long long i = ((long long)0); i < ((long long)N); i++) { if (A[i] ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n <= 2) { cout << -1; return 0; } if (n == 3) { cout << 210; return 0; } if ((n - 4) % 6 == 0) { cout << 1; for (int i = 0; i < n - 3; i++) cout << 0; cout << 50; ...
#include <bits/stdc++.h> using namespace std; int n, m, s[111]; int f[20][1 << 20]; int bitc[1 << 20]; int act[22]; int who[22]; int picks[22]; inline void upd_max(int i, int j, int val) { if (f[i][j] > 1000000000) f[i][j] = val; else f[i][j] = max(f[i][j], val); } inline void up...
#include <bits/stdc++.h> std::string a, b; std::string cal(std::string a) { if (a.length() % 2) return a; std::string s1 = cal(a.substr(0, a.length() / 2)); std::string s2 = cal(a.substr(a.length() / 2, a.length())); if (s1 < s2) return s1 + s2; return s2 + s1; } int main() { std::cin >>...
#include <bits/stdc++.h> using namespace std; int n, t1, t2, k; pair<int, int> res[100001]; bool cmp(pair<int, int> a, pair<int, int> b) { if (a.second == b.second) { return a.first < b.first; } return a.second > b.second; } int cal(int a, int b) { return a * t1 * (100 - k) + b * t2 * 100;...
#include <bits/stdc++.h> char a[200005], b[200005]; int cmp(char *p, char *q, int n) { if (!strncmp(p, q, n)) return 1; if (n % 2) return 0; int temp = n / 2; if (cmp(p, q, temp) && cmp(p + temp, q + temp, temp)) return 1; else if (cmp(p + temp, q, temp) && cmp(p, q + temp, temp)) re...
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int read() { int c = 0; char ch = getchar(); while (ch < 0 || 9 < ch) ch = getchar(); while ( 0 <= ch && ch <= 9 ) c = c * 10 + ch - 0 , ch = getchar(); return c; } int main() { int n = read(), P = read(), k = read(...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, inf = 2e9, mxn = 1e6 + 5; void solve() { int n, m, addx = 0, addy = 0, mnx = 0, mxx = 0, mny = 0, mxy = 0, x = 1, y = 1; cin >> n >> m; string second; cin >> second; for (auto i : second) { addx += (i ==...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; if (n / 36 + 1 == (n + 1) / 36) n++; cout << n / 36 << << round((n - (n / 36) * 36) * 1.0 / 3); return 0; }
#include <bits/stdc++.h> using namespace std; string sd(int n) { string s; stringstream ss; ss << n; ss >> s; return s; } int main() { long long int n, k, a[105], c = 0, san = 0; string s; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; s = sd(a[i]); ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int min1, min2, min3, max1, max2, max3; cin >> min1 >> max1 >> min2 >> max2 >> min3 >> max3; int c = n; int ans1 = min1, ans2 = min2, ans3 = min3; for (int i = min1; i < max1; i++) { if (ans1 + ans2 + ans3 ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long l, r; cin >> l >> r; string s_l = to_string(l), s_r = to_string(r); long long m = s_l.length(), n = s_r.length(); if (m == n) { long long num = ...
#include <bits/stdc++.h> using namespace std; int main() { int n; string str; cin >> n; cin >> str; int a = count(str.begin(), str.end(), A ); int d = n - a; if (a == d) { cout << Friendship n ; return 0; } a < d ? cout << Danik n : cout << Anton n ; return 0...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777222 ) using namespace std; const long long mod = (long long)1e9 + 7; const int inf = (int)2e9; const long long INF = (long long)1e18; const int base = 1000 * 1000 * 1000; const int maxn = 505; const long double pi = acosl(-1.0); const long ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; int ne[MAXN], l[MAXN]; int one[MAXN]; int n; int g[MAXN]; void D(int *a, int *b) { for (int i = 0; i < n; i++) g[i] = b[a[i]]; for (int i = 0; i < n; i++) a[i] = g[i]; } void Pow(int deg) { int new_deg = 0; int cn...
#include <bits/stdc++.h> const long double pi = acos(-1); using namespace std; char a[105][105], row[105], col[105]; bool vis[105]; int main() { int n, m; cin >> n >> m; bool b = false; if (n == 1) { cout << 0 n ; return 0; } for (int i = 0; i < n; i++) { for (int j ...
#include <bits/stdc++.h> using namespace std; const int N = 1005; bool vis[N]; vector<int> temp; int n, t, num; int ans[N], L[N], R[N]; void pr() { return; for (int i = 0; i < n; i++) printf( %d , ans[i]); puts( ); puts( ); } void pr2() { return; printf( %d n , temp.size());...
#include <bits/stdc++.h> using namespace std; void maximize(double &a, double b) { a = max(a, b); } struct point { long long int x, y; point() {} point(long long int x, long long int y) : x(x), y(y) {} }; long long int prodesc(point p1, point p2) { return p1.x * p2.x + p1.y * p2.y; } long long i...
#include <bits/stdc++.h> using namespace std; int arr[20]; int mem[20][20][20]; int n, a, b; int calc(int ind, int p, int c) { int x0 = arr[ind - 1] - p, x1 = arr[ind] - c, x2 = arr[ind + 1]; int& res = mem[ind][p][c]; if (res != -1) return res; if (ind == n - 2) { res = 0; while (...
#include <bits/stdc++.h> const int maxn = 1e5 + 5; int n, k; int a[maxn]; int main() { scanf( %d%d , &n, &k); int ans = 0; int l = 0; while (k--) { bool flag = false; int m; scanf( %d , &m); for (int i = 1; i <= m; i++) { scanf( %d , &a[i]); if (a[1] == 1)...
#include <bits/stdc++.h> using namespace std; const long long N = 3e4 + 10, M = 1e3 + 10; long long n, p[N], d, dp[N][M + 10]; long long solve(long long pos, long long L) { if (pos > 30000) return 0; long long wh = L - d + M / 2; if (dp[pos][wh] != -1) return dp[pos][wh]; long long ret = 0; ...
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& s, vector<T> const& v) { s << { ; for (int i = 0; i < int(v.size()); i++) s << (i ? , : ) << v[i]; return s << } ; } template <typename S, typename T> ostream& operator<<(ostream& s, pair<S, T>...