func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-9; template <typename T> T sqr(T x) { return x * x; } double sind(double x) { return sin(x * PI / 180); } double cosd(double x) { return cos(x * PI / 180); } double tand(double x) { return tan(x * PI / ...
#include <bits/stdc++.h> using namespace std; class Graph { long long int v; list<pair<long long int, long long int>> *adj; public: Graph(long long int v) : v(v) { adj = new list<pair<long long int, long long int>>[v]; } void addEdge(long long int u, long long int v, long long int w,...
#include <bits/stdc++.h> using namespace std; using Long = int64_t; constexpr Long Z = 0; bool fire(Long N, Long M, int K, const vector<Long>& X, const vector<Long>& Y, Long t) { map<Long, int> xs; map<Long, int> ys; xs[0] = 0; xs[N] = 0; ys[0] = 0; ys[M] = 0; for (int i ...
#include <bits/stdc++.h> using namespace std; constexpr long long INF = 2e18; constexpr long long MOD = 1e9 + 7; constexpr long long MAXN = 2e5 + 3; void solve() { long long n; cin >> n; long long k; cin >> k; vector<long long> arr(n); for (long long i = 0; i < n; ++i) { long lon...
#include <bits/stdc++.h> using namespace std; int n, m, a[100010], s[100010], sp, cnt; long long tot, sum, pj; int main() { cin >> n >> m; for (register int i = 1; i <= n; i++) cin >> a[i], tot += a[i]; if (tot % m != 0) { cout << No << endl; return 0; } pj = tot / m; for (...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int fre[26] = {0}; for (int i = 0; i < n; i++) { fre[s[i] - a ] = fre[s[i] - a ] + 1; } string ans = ; for (int i = 0; i < 26; i++) { for (int j = 0; j < fre[i]; j++) {...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:64000000 ) struct arc { int f, s, prev; } arr[300000]; int q[100005]; int beg[100005]; int kol = 0; void add_arc(int f, int s) { f--; s--; arr[kol].f = f; arr[kol].s = s; arr[kol].prev = beg[f]; beg...
#include <bits/stdc++.h> using namespace std; const int MAX = 100100; const long long oo = 1e18; int N; long long P[MAX], D[MAX]; int L[MAX], R[MAX]; void init_L() { stack<int> S; for (int i = 0; i <= N + 1; ++i) { while (S.size() >= 2) { int x = S.top(); S.pop(); if ...
#include <bits/stdc++.h> using namespace std; const int N = 1000010; int t, sp[N]; map<int, int> n, m, s; vector<pair<int, int> > _n, _m, _s; long long n_val, m_val, s_val; void sieve(void) { for (int i = 2; i * i < N; ++i) { if (sp[i]) continue; sp[i] = i; for (int j = i * i; j < N;...
#include <bits/stdc++.h> using namespace std; const int MX = 25; int main(int argc, char *argv[]) { int n, k; cin >> n >> k; string a[n]; for (int i = (0), _b = (n); i < (_b); ++i) cin >> a[i]; uint8_t g[4]; uint32_t b[n]; for (int i = (0), _b = (n); i < (_b); ++i) { uint8_t x = ...
#include <bits/stdc++.h> using namespace std; map<int, vector<string> > mp; string s; int n, pos = 0; ; void dfs(int lvl) { int j = pos; while (s[j] != , ) j++; mp[lvl].push_back(s.substr(pos, j - pos)); pos = j + 1; j++; while (s[j] != , ) j++; int ct = stoi(s.substr(pos, j - ...
#include <bits/stdc++.h> using namespace std; int main() { double n, m, a; cin >> n >> m >> a; cout << (long long)(ceil(n / a) * ceil(m / a)); return 0; }
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000 ) using namespace std; long long x[3], y[3]; int main() { for (int i = 0; i < 3; i++) cin >> x[i] >> y[i]; if (x[0] == x[1] && x[0] == x[2] || y[0] == y[1] && y[0] == y[2]) { printf( 1 n ); return 0; } int perm[3] = {...
#include <bits/stdc++.h> using namespace std; const int mod = int(1e9 + 7); const double PI = acos(-1.0); const int N = 200000; long long n, a; long long p[N], b[N]; bool check(int x) { long long i, m; m = a; for (i = 0; i < x; i++) if (b[n - x + i] < p[i]) m -= p[i] - b[n - x + i]; ...
#include <bits/stdc++.h> using namespace std; string a[2005]; char s[2005]; int f[2005 * 2][2005], h[2005], n, m, k; void dp(int l, int r, int x) { if (l >= r) return; int L = ++m, R = ++m, mid = l; for (int i = l; i < r; i++) if (h[i] < h[mid]) mid = i; dp(l, mid, L), dp(mid + 1, r, R);...
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __prin...
#include <bits/stdc++.h> using namespace std; map<string, string> a; map<string, int> b; string s, g, p; int main() { int n, q; cin >> n; for (int i = 0; i < n; i++) { cin >> s; int l = s.length(); for (int j = 0; j < l; j++) { for (int k = 1; j + k <= l; k++) { ...
#include <bits/stdc++.h> using namespace std; int n, s = 19, i, sum, j, l; int main() { cin >> n; for (i = 1; i < n; i++) { s += 9; l = s; while (l) { sum += (l % 10); l /= 10; } if (sum != 10) i--; sum = 0; } cout << s; }
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = long long; using llu = long long unsigned; using ld = long double; const ld EPS = 1e-9; inline int cmp(ld first, ld second = 0, ld tol = EPS) { return (first <= second + tol) ? (first + tol < second) ? -1 : 0 : 1; }...
#include <bits/stdc++.h> using namespace std; const int MAXV = 600, MAXE = 70000, inf = 1000000000; int N, Count; int G[MAXV], Queue[MAXV], Dist[MAXV], Pre[MAXV], Last[MAXV]; int Data[MAXE], Weight[MAXE], Cost[MAXE], Next[MAXE]; bool Flag[MAXV]; int Calc(int X) { if (!X) return 0; return Calc(X / ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 0) { cout << O-|-OOOO << endl; return 0; } while (n != 0) { int k = n % 10; if (k >= 5) { cout << -O| ; k -= 5; } else cout << O-| ; int i = 0; ...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(); int n; cin >> n; int x; cin >> x; int a[n]; int pp[100005] = {0}; for (int i = 0; i < n; i++) { cin >> a[i]; pp[a[i]]++; } long l...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; int a[t + 10]; for (int i = 0; i < t; i++) { long int b, p, f, c, h, c1 = 0, c2 = 0; cin >> b >> p >> f; cin >> h >> c; b = b / 2; if (b ...
#include <bits/stdc++.h> using namespace std; int b[600][600], n, m, q, row[600]; int main() { ios::sync_with_stdio(false); scanf( %d%d%d , &n, &m, &q); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { int x; scanf( %d , &x); b[i][j] = x; } int ans = ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100500; int a[maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; long long k; cin >> n >> k; long long sm = 0; priority_queue<pair<int, int> > pq; for (int i = 0; i < n; ++i) { cin ...
#include <bits/stdc++.h> using namespace std; double tt, anstt; long long ansp, answ, tod[2000000], x1, x2, t1, t2, t0, ps; int main() { cin >> t1 >> t2 >> x1 >> x2 >> t0; if (t1 == t2 && t1 == t0) cout << x1 << << x2 << endl; else { tod[0] = x2; ps = 0; for (int i = 1; i...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { ...
#include <bits/stdc++.h> using namespace std; struct node { int a, b; node(int a = 0, int b = (int)1e9) : a(a), b(b) {} int get(int x) { return a * x + b; } }; struct Zwei { vector<node> st; vector<int> a; int n; void add(int pos) { a.push_back(pos); } void update() { sort(...
#include<bits/stdc++.h> #define int long long using namespace std; const int N=1e5+5; #define pb push_back int n,m,t; int i,j,k; int a[N]; int b[N],c[N]; vector<int> ans; vector<int>v[N]; int vis[N]; signed main() { int t; cin>>t; while(t--){ int n; cin>>n; ...
#include <bits/stdc++.h> const int MAXA = 5005; const int MAXN = 2016; int array[MAXN]{}; long long diffr[MAXA]{}; long long suffx[MAXA]{}; long double total; long long Ans = 0; int N; int main() { scanf( %d , &N); for (int i = 0; i < N; ++i) scanf( %d , &array[i]); total = N * (N - 1) >> ...
#include <bits/stdc++.h> using namespace std; int main() { const long long MOD = 1000000009; int n, m; cin >> n >> m; long long ret = 1; long long x = 1; for (int i = 0; i < (int)(m); i++) x = x * 2 % MOD; x = (x - 1 + MOD) % MOD; for (int i = 0; i < (int)(n); i++) { ret = ret ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<long long, long long>; const long long INF = 2e18; template <class A, class B> ostream &operator<<(ostream &os, const pair<A, B> &p) { os << ( << p.first << , << p.second << ) ; return os; } template <clas...
#include <bits/stdc++.h> std::mt19937 rng( (int)std::chrono::steady_clock::now().time_since_epoch().count()); using namespace std; long long mod = (998244353LL); inline long long Mod(long long a, long long b) { return (a % b); } inline long long poww(long long a, long long b) { long long res = 1; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; vector<int> v[maxn]; int vos[maxn]; int ans; void dfs(int now, int pre) { if (vos[now]) { ans = 0; return; } vos[now] = 1; for (int i = 0; i < v[now].size(); i++) { if (v[now][i] != pre) { dfs(v...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007LL; int n, k; string s; long long A[30]; long long ans, aux; int last[30]; int main() { cin >> n >> k >> s; memset(last, -1, sizeof(last)); int m = s.length(); ans = 1LL; for (int i = 0; i < m; i++) { ...
#include <bits/stdc++.h> using namespace std; char x[1500001]; int k, i, starti, fini; bool start, finish, found[500001]; int main() { while (cin.getline(x, 1500001)) { k++; found[k] = false; int a = strlen(x); for (i = 0; i < a; i++) { if (x[i] != && x[i] != # && !fo...
#include <bits/stdc++.h> const int inf = 0xfffffff; const long long INF = 1ll << 61; using namespace std; int num[1000000 + 5]; int b[1000000 + 5]; int c[1000000 + 5]; int n; int ans; void init() { memset(num, 0, sizeof(num)); memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c)); ans = 0; ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const int N = 100000 + 5; long long q; long long tree[4000005], lazy[4000005]; long long ti[1000005], di[1000005]; void lazify(long long s, long long e, long long i) { if (lazy[i]) { tree[i] += lazy[i]; if (s != e) {...
#include <bits/stdc++.h> using namespace std; bitset<4096> f[100020]; int a[13][100005], b[100005][13], now; bool cmp(int x, int y) { return a[x][now] == a[y][now] ? x > y : a[x][now] > a[y][now]; } int main() { int n, q, k, cnt, op, x, y; scanf( %d%d%d , &n, &k, &q); cnt = k; for (int i...
#include <bits/stdc++.h> using namespace std; const int N = 1E6 + 5, INF = 1E9 + 7; int m, n, ans = INF; mt19937 mt(133769420); int ask(int u, int v) { cout << ? << u << << v << endl; int ret; cin >> ret; return ret; } int rand(int l, int r) { uniform_int_distribution<int> uni(l...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); long long t, n, x; cin >> t; for (int i = 0; i < t; i++) { cin >> n >> x; cout << x * 2 << endl; } }
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x << 3) + (x << 1) + c - 0 ; c = getchar(); } return x ...
#include <bits/stdc++.h> using namespace std; double table[2][1005]; int main() { int N, K; cin >> N >> K; for (int t = 1; t <= N; t++) { for (int l = 1; l < 1000; l++) { double good = ((l + table[(t - 1) & 1][l + 1]) + l * ((l + 1) / 2.0 + table[(t - 1) & 1][l])) ...
#include <bits/stdc++.h> using namespace std; int n, k, tot, len[(int)(3e3 + 4)]; pair<int, int> bound[(int)(3e3 + 4)]; string s; vector<int> poz, ans[3000004]; void fail(); int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> k; cin >> s; for (int i = s.size() -...
#include <bits/stdc++.h> using namespace std; int SquareRoot(int n) { int l = 1, r = n + 1; while (l < r) { int mid = (l + r) / 2; if (n / mid < mid) { r = mid; } else { l = mid + 1; } } --l; if (l * l == n) { return l; } return -1; } int...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3fLL; const int MAXN = 1e6 + 5; int arr[MAXN], n; ll fun(ll x) { if (x == 1) return INF; ll sum = 0, y = 0; for (int i = 0; i < n; i++) { y += arr[i]; y %=...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; using LL = int64_t; using pii = pair<int, int>; const double PI = 2 * asin(1); int g_n; string g_s; vector<int> vi_in; vector<LL> vll_sum; void pretreat() {} void input() { vi_in.clear(), vi_in.resize(g_n + 1); v...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; template <class T, class U> inline void Max(T &a, U b) { if (a < b) a = b; } template <class T, class U> inline void Min(T &a, U b) { if (a > b) a = b; } inline void add(int &a, int b) { a +...
#include <bits/stdc++.h> using namespace std; vector<long long> v; int main() { long long n, res = 0, i; cin >> n; long long ans = (n * (n + 1)) / 2; if (ans % 2 == 0) cout << 0 << endl; else cout << 1 << endl; ans = ans / 2; for (i = n; i >= 1; i--) { res += i; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; int a[maxn]; int n; int vis[maxn]; vector<int> ans; int main() { memset(vis, 0, sizeof(vis)); ans.clear(); scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } int cnt = 0; int ma = 0...
#include <bits/stdc++.h> using namespace std; int n, s, x, v, t, y, i, nr1, nr2, v1[100004], v2[100004], c[1000004], d[1000004]; long long st, dr, m, Min, Min1, x1, x2, a[100004], b[100004]; double nr; bool ok; int main() { scanf( %d %d , &n, &s); for (i = 1; i <= n; i++) { scanf( %d %d ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; long long x, a, b, i, f = 1, pa, push_back; vector<pair<long long, long long> > v(n); vector<long long> ch; cin >> x; cin >> a >> b; pa ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); ; int n, m; cin >> n >> m; int dem = 0; if (m % n != 0) { cout << -1; return 0; } int sum = m / n; while (sum % 2 == 0) { sum /= 2; dem++; } while (sum % 3 == 0...
#include <bits/stdc++.h> using namespace std; void dfs(long long a, vector<long long>& d, vector<vector<long long>>& adj, vector<long long>& vis, long long dist) { d[a] = dist; vis[a]++; for (auto b : adj[a]) { if (!vis[b]) { dfs(b, d, adj, vis, dist + 1); } } } in...
#include <bits/stdc++.h> int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; using namespace std; vector<long long int> v, v2, v3; vector<long long int>::iterator it1, it2; int ar[200]; int main() { long long int tcase = 1; while (tcase--) { long long int n, k, a, ans = 0; scanf( %lld ...
#include <bits/stdc++.h> template <typename T> inline void read(T& x) { T res = 0, flag = 1; char ch; ch = getchar(); while (!isdigit(ch)) { if (ch == - ) flag = -1; ch = getchar(); } while (isdigit(ch)) { res = res * 10 + ch - 48; ch = getchar(); } x = res *...
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[1 << 16], *S, *T; if (S == T) { T = (S = buf) + fread(buf, 1, 1 << 16, stdin); if (T == S) return EOF; } return *S++; } inline int read() { int x = 0, f = 1; char ch = gc(); while (ch < 0 |...
#include <bits/stdc++.h> using namespace std; bool check(long long y) { for (long long x = 2; x * x <= y; x++) { if (y % x == 0) return 0; } return 1; } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); long long n, x, y; cin >> n; for (int i = 0; i < n; i++) ...
#include <bits/stdc++.h> int f[1200000], g[30][30], h[30][30], o[30], p[30], q[30][30]; char c[30][30]; int i, j, k, l, m, n, t, u, v; int main() { scanf( %d%d , &n, &m); for (i = 1; i <= n; i++) scanf( %s , c[i] + 1); for (i = 1; i <= n; i++) for (j = 1; j <= m; j++) c[i][j] = c[i][j] - 96; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int a[N], b[N], seg[4 * N], lazy[4 * N], n, diff[N]; void update(int sq, int eq, int val, int id = 1, int s = 1, int e = n) { if (lazy[id] != 0) { seg[id] = lazy[id]; if (s != e) lazy[id * 2] = lazy[id * 2 + 1] = lazy[id]; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5; int c[4][11][11][maxn + 5]; char s[maxn + 50]; char t[15]; int n; int getnum(char c) { if (c == A ) return 0; if (c == T ) return 1; if (c == G ) return 2; if (c == C ) return 3; } int lowbit(int x) { return x & (-...
#include <bits/stdc++.h> using namespace std; struct laptop { long long p, b, ind; laptop() {} laptop(long long a, long long b, long long c) : p(a), b(b), ind(c) {} bool operator<(const laptop& o) const { return ((long double)o.b * p > (long double)b * o.p); } }; int n, k; vector<lap...
#include <bits/stdc++.h> using namespace std; long long m, n, a, b, c, ans, ar[1000001], k, paths[200010], visit[200010], ans1, dp[400010], t, er[200110]; bool boo; bool compare(long long a, long long b) { if (a >= b) return 1; return 0; } int main() { string s; std::ios_base::sync_wit...
#include <bits/stdc++.h> using namespace std; int a[100005]; int themax(int b[], int k) { int sum = b[0]; for (int z = 1; z < k; z++) { sum += (b[z] + 1); } return sum; } int main() { int n, x, max = 0, min = 0; cin >> n >> x; for (int i = 0; i < n; i++) { cin >> a[i]; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 10; const int maxk = 2e4 + 10; const int inf = 0x3f3f3f3f; int n, m, k; bool g[maxn][maxn]; struct Block { int l, r, b, t; }; Block b[maxk]; int bnum; bool vis[maxk]; int d[maxk]; int res; int start, stop; void bfs() ...
#include <bits/stdc++.h> using namespace std; int a, s, d[10004][2], f, g, h, j, k, l, i, n, m; string x, z; set<string> q; bool chk(int idx, int dis) { for (int i = idx; i < idx + dis; i++) { if (x[i] != x[i + dis]) return true; } return false; } int main() { cin >> x; n = x.siz...
#include <bits/stdc++.h> using namespace std; bool IsPrime(int x) { for (int i = 2; i * i <= x; i++) if (x % i == 0) return false; return true; } int modpow(int w, int p, int m) { if (p == 0) return 1; int x = modpow(w, p / 2, m); x = 1LL * x * x % m; if (p & 1) x = 1LL * x * w % m...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long n, a[100009], m = 0; cin >> n; for (long i = long(0); i < long(n); i++) { cin >> a[i]; m = max(m, a[i]); } long c = 0, q = 0; for (long i = long(0); i < l...
#include <bits/stdc++.h> using namespace std; struct dat { int L, R, V; } a[100005]; int N, M; bool cmp(dat a, dat b) { if (a.L != b.L) return a.L < b.L; if (a.R != b.R) return a.R < b.R; return a.V < b.V; } int ans[100005], s[100005]; void build(int k) { int last = 0; for (int i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long int a, b; cin >> a >> b; long long int sumo = 0, sume = 0; for (int i = 1;; i++) { sumo = i * i; if (sumo > a) { cout << Vladik << endl; break; } sume ...
#include <bits/stdc++.h> using namespace std; const int N = 155; int n; int a[N], b[N], A, B; int main() { scanf( %d , &n); a[0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= A; j++) b[j + 1] = (b[j + 1] + a[j]) % 2; B = max(B, A + 1); swap(A, B); for (int j = 0;...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 1E6 + 7; int n; int id[N], x[N], y[N]; bool cmp(int a, int b) { if (x[a] < x[b]) return true; if (x[a] > x[b]) return false; if (x[a] % 2 == 1) return y[a] < y[b]; else return y[a] > y[b]; }...
#include <bits/stdc++.h> using namespace std; template <typename Arg, typename... Args> inline void input(Arg& arg, Args&... args) { cin >> arg; (void)(int[]){0, (void(cin >> args), 0)...}; } template <typename Arg, typename... Args> inline void printErr(Arg&& arg, Args&&... args) { cerr << arg;...
#include <bits/stdc++.h> using namespace std; const int maxn = 500002; long long a[maxn]; int n, k, d; void enter() { cin >> n >> k >> d; for (int i = (1), _b = (n + 1); i < _b; ++i) cin >> a[i]; } int seg[4 * maxn]; void update(int l, int r, int st, int q) { if (l == r) seg[st] = 1; ...
#include <bits/stdc++.h> using namespace std; char s[200005]; char x[26]; int n, m; char a, b; int main() { while (scanf( %d%d , &n, &m) != EOF) { for (int i = 0; i < 26; i++) x[i] = i + a ; getchar(); scanf( %s , s); getchar(); for (int i = 0; i < m; i++) { scanf(...
#include <bits/stdc++.h> using namespace std; int main() { string ch, t; int n, s, i; bool ok1 = 0, ok2 = 0; scanf( %d %d , &n, &s); if (9 * n >= s) { if (n == 1 && s == 0) { cout << 0 << << 0 << endl; } else if (s == 0) { cout << -1 << << -1 << endl; } ...
#include <bits/stdc++.h> using namespace std; const long long M = 1000000007; long long n, k; long long a[100050]; long long cnt[100050]; map<long long, long long> dict; long long f[100050]; long long fac[100000 + 50], ifac[100000 + 50]; long long pwk[100050]; long long ksm(long long a, long long x ...
#include <bits/stdc++.h> using namespace std; deque<char> D; int main() { int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) if (D.size() % 2 == 0 || D.back() != s[i]) D.push_back(s[i]); if (D.size() % 2 == 1) D.pop_back(); cout << n - D.size() << endl; for (int...
#include <bits/stdc++.h> int const MAX = 1e5 + 5; int a[MAX], need[MAX]; bool has[MAX], pos[MAX]; int main() { int n, num = 0; scanf( %d , &n); memset(has, false, sizeof(has)); memset(pos, false, sizeof(pos)); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); if (!has[a[i]] && a[...
#include <bits/stdc++.h> using namespace std; const int maxn = 100003; pair<int, int> t[4 * maxn]; int psh[maxn]; void update(int v, int l, int r, int q) { if (l == r) return void(t[v] = psh[q] ? make_pair(1, 0) : make_pair(0, 1)); int m = (l + r) / 2; if (q <= m) update(v * 2, l, m, q); if (q...
#include <bits/stdc++.h> using namespace std; int n; vector<int> tree[3005]; int p[3005][3005]; long long sz[3005][3005]; long long dfs(int root, int cur) { sz[root][cur] = 1; for (int nxt : tree[cur]) { if (!sz[root][nxt]) { sz[root][cur] += dfs(root, nxt); p[root][nxt] = cur;...
#include <bits/stdc++.h> using namespace std; int d1, d2, d3; int r; int main() { cin >> d1 >> d2 >> d3; r = d1 + d2 + d3; r = min(r, d1 + d1 + d2 + d2); r = min(r, d1 + d3 + d1 + d3); r = min(r, d2 + d3 + d2 + d3); cout << r << n ; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, m; cin >> n >> m; long long int s = 0, x, y, i, j; vector<long long int> a, b; for (i = 0; i < n; i++) { cin >> x; if (x < 0) a.push_back(x);...
#include <bits/stdc++.h> int main() { int i, j, count, n, a[5001], flag[5001]; scanf( %d , &n); count = 0; memset(flag, 0, sizeof(int) * 5001); for (i = 0; i < n; i++) { scanf( %d , &a[i]); if (a[i] > n) count++; else if (flag[a[i]] == 1) count++; else ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int n; cin >> n; vector<int> v(n); int mx = 0; for (int i = 0; i < n; i++) { cin >> v[i]; mx = max(mx, v[i]); } int count = 1, l = 0; fo...
#include <bits/stdc++.h> using namespace std; multiset<int> a, b; int c[300010], d[300010]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> c[i] >> d[i]; a.insert(c[i]); b.insert(d[i]); } int ans = 0; for (int i = 1; i <= n; i++) { a.erase(a.fi...
#include <bits/stdc++.h> using namespace std; int n, k, sx, ex; char s[1010]; int main() { scanf( %d%d%s , &n, &k, s); for (int i = 0; i < n; i++) { if (s[i] == G ) sx = i; if (s[i] == T ) ex = i; } if (sx > ex) swap(sx, ex); if ((ex - sx) % k != 0) printf( NO n ); el...
#include <bits/stdc++.h> using namespace std; signed main() { ios ::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n, k; cin >> n >> k; string s; cin >> s; vector<long long> cnt(26); for (auto u : s) ++cnt[u - ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long s = 0, w = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) s = s * 10 + ch - 0 , ch = getchar(); return s * w; } v...
#include <bits/stdc++.h> using namespace std; void solve() { long long a, b, c; cin >> a >> b; c = a + b; string s = to_string(a); string x = to_string(b); string y = to_string(c); string e = , f = , g = ; for (int i = 0; i < s.size(); i++) { if (s[i] != 0 ) { e ...
#include <bits/stdc++.h> using namespace std; set<int> Tmp, Trans; int dp[(500 + 5)][(500 + 5)], n, m, A[(500 + 5)], B[(500 + 5)]; int from[(500 + 5)][(500 + 5)][2], rkA[(500 + 5)], rkB[(500 + 5)]; int trans[(500 + 5)][(500 + 5)]; int getrk(int x) { int TP = 0; for (set<int>::iterator i = Trans.begi...
#include <bits/stdc++.h> using namespace std; const int mn = 2005; vector<int> g[mn], G[mn]; int dfn[mn], low[mn], times; int stk[mn], top, bel[mn], cnt, siz[mn], fa[mn]; int rt, maxs; bool ins[mn], vis[mn][mn], flg[mn], chn[mn], tmp[mn], leav[mn]; void dfs1(int s, int f) { dfn[s] = low[s] = ++times...
#include <bits/stdc++.h> using namespace std; const int N = 101; int a[N]; int n; int main() { int i, t; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); t = a[0]; a[0] = a[n - 1]; a[n - 1] = t; for (i = 0; i < n; i++) cout << a[i] << ; cout << endl; re...
#include <bits/stdc++.h> #pragma GCC_OPTIMAZE( ofast ) using namespace std; signed main() { long long n; cin >> n; vector<long long> arr(n); for (long long i = 0; i < n; i++) { cin >> arr[i]; arr[i]--; } long long cnt = 0, pos = 0; while (pos < n) { cnt++; long ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<vector<int> > T(n); for (int i = 0; i < n - 1; ++i) { int a, b; cin >> a >> b; --a; --b; T[a].push_back(b); T[b].push_back(a); } vector<boo...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { a = abs(a), b = abs(b); if (a < b) swap(a, b); return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } long long fast_pow(long long x, long long exp, long long mod)...
#include <bits/stdc++.h> const int MAX = 20; const double PI = std::acos(-1.0); struct comp { double real, imag; explicit comp(double real = 0, double imag = 0) : real(real), imag(imag) {} comp operator+(const comp &c) const { return comp(real + c.real, imag + c.imag); } comp operator-(c...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long a[n], b[n]; long long i; for (i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(a, a + n); long long count = 0; for (i = 0; i < n; i++) { if (a[i] != b[i]) { ...
#include <bits/stdc++.h> using namespace std; struct Arc { int f, s, prev; } arr[400005]; Arc nbr[400005]; Arc br[400005]; int beg[400005]; int kol = 0; void add_arc(int f, int s) { arr[kol].f = f; arr[kol].s = s; arr[kol].prev = beg[f]; beg[f] = kol++; arr[kol].f = s; arr[ko...
#include <bits/stdc++.h> using namespace std; using namespace std; map<long long, long long> f; int main() { int q; scanf( %d , &q); while (q--) { long long u, v; int t, w; scanf( %d %lld %lld , &t, &u, &v); if (t == 1) { scanf( %d , &w); while (u != v) { ...