func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> int len; int big; int Dgt[30]; int N; int ans; void tochar(int); int main() { while (scanf( %d , &N) != EOF) { memset(Dgt, 0, sizeof(Dgt)); ans = 0; while (N) { big = -1; tochar(N); for (int i = 0; i < len; i++) { if (Dgt[i] ...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; long long a[3], b[3]; cin >> a[0] >> a[1] >> a[2]; cin >> b[0] >> b[1] >> b[2]; cout << max(0ll, a[0] - b[0] - b[2]) + max(0ll, a[1] - b[1] - b[0]) + max(0ll, a[2] - b[2] - b[1]) << ; ...
#include <bits/stdc++.h> using namespace std; bool equal(string s) { int n = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == a ) n++; } if (n * 2 != s.length()) return false; return true; } string s, s1, sex; int n, d, k; int main() { cin >> k; cin >> s; n = s.le...
#include <bits/stdc++.h> using namespace std; int a[105][2]; int main() { int n, sum = 0, b = 0; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i][0]); sum += a[i][0]; } n /= 2; sum = sum / n; for (int j = 1; j <= n; j++) { for (int i = 1; i <= 2 * n; ...
#include <bits/stdc++.h> using namespace std; long long SG[1110000] = {0, 1, 2, 1, 4, 3, 2, 1, 5, 6, 2, 1, 8, 7, 5, 9, 8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, 11, 12, 14, 13}; long long n, Ans, vis[1110000]; set<long long> Hehe; int main() { scanf( %I64d , &n); long long Or...
#include <bits/stdc++.h> using namespace std; int n, m, cnt; bool vis[1000005]; vector<int> G[1000005]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= m; i++) { int u, v; scanf( %d%d , &u, &v); G[u].push_back(v); } for (int u = 1; u <= n; u++) { if (vis[u]) co...
#include <bits/stdc++.h> using namespace std; const int N = 2013; char p[1 << 20], s[205]; int k, n, m; int main() { gets(p); gets(s); cin >> k; n = strlen(p); m = strlen(s); string minLex; for (int i = 1; i <= k + 1; ++i) minLex += 1 ; int rboud = min(m, k), cntIn = n / k, R ...
#include <bits/stdc++.h> using namespace std; struct node { int x, y, z; } a[10]; int flag; long long v[5]; long long dist(int i, int j) { long long x = a[i].x - a[j].x; long long y = a[i].y - a[j].y; long long z = a[i].z - a[j].z; return x * x + y * y + z * z; } int ok() { int c...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1024; int n, m; bool b[MAXN][MAXN]; int main() { cin >> n >> m; for (register int l = (1); l < (int)(m + 1); ++l) { int x, y; cin >> x >> y; x--; y--; b[x][y] = true; for (register int xx = (x - 2); xx <...
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const long long LLINF = 9223372036854775807LL; template <int MOD> struct Num { int x; Num() : x(0) {} explicit Num(int x, bool skip_check = false) { if (skip_check) this->x = x; else { if (x >= 0 ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e6 + 66; vector<int> g[N], f[N]; int used[N]; vector<int> topsort; void dfs(int v) { used[v] = 1; for (int to : g[v]) if (used[to] != 1) dfs(to); topsort.emplace_back(v); } int c[N]; void color(int v...
#include <bits/stdc++.h> using namespace std; void read_file(bool outToFile = true) {} int n, K; const int MAXN = 200000 + 99; int A[MAXN]; set<int> X; int vis[MAXN]; bool check() { memset(vis, 0, sizeof vis); stack<int> s; int idx = 0; int cur = 1; while (true) { while (s.empt...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, t, tt, i; long long t1, t2, t3, t4; while (~scanf( %lld %lld , &a, &b)) { t = b - a; t1 = a % 10; t2 = b % 10; t3 = (a / 10) % 10; t4 = (b / 10) % 10; if (t >= 10 || (t4 != t3)) { print...
#include <bits/stdc++.h> using namespace std; const int maxN = 100050, mod = 1000000007; ; int n, ans, k; int fa[maxN], c[maxN]; int getfa(int u) { if (fa[u] == u) return u; int t = fa[u]; fa[u] = getfa(fa[u]); while (c[u] < 0) c[u] += mod; while (c[t] < 0) c[t] += mod; c[u] = (c[u] ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:5000000000 ) const long long mod = 1000000007; long long Inf = (long long)2e9; long long LINF = (long long)1e18 + 1e17; using namespace std; int main() { ios::sync_with_stdio(false); int n; cin >> n; vector<long long> a(n); vector<...
#include <bits/stdc++.h> using namespace std; const int inf = (1 << 30); const int N = 100005; int n, k; int g[105][105]; int main() { int i, j, t, cas = 0; memset(g, 0, sizeof(g)); scanf( %d , &k); for (n = 3; n <= 100; n++) { if ((n) * (n - 1) * (n - 2) / 6 > k) break; } n--;...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; long long int mod = 1e9 + 7; long long int mod1 = 998244351; long long int power(long long int a, long long ...
#include <bits/stdc++.h> using namespace std; int n, numone, numtwo, sum, tmp; char nlong; string nameone, nametwo; string read; struct node { string name; int goal, moregoal, score; int q; } wxy[100]; bool check(int t) { for (int i = 0; i < tmp; i++) if (wxy[t].name[i] != nameone[...
#include <bits/stdc++.h> using namespace std; int f[26]; char s[100005]; int dp[100005][26]; int main(void) { int n; scanf( %s , s + 1); scanf( %d , &n); for (int i = 0; i < 26; i++) f[i] = -1; for (int i = 0; i < n; i++) { char x[10]; scanf( %s , x); f[x[0] - a ] = x[1]...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int a, b; cin >> a >> b; int x = abs(a - b); int ans = x / 5; x %= 5; ans += x / 2; x %= 2; ans += x; cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int a, b, c, s; vector<double> x, y11, z; double rx, ry, rz, mn = -1000000000; double mln(double x) { return log(x); } void upd(double nx, double ny, double nz) { if (nx + ny + nz > (s + 1e-7)) return; double cur = 0; if (a) cur += a * mln(nx); i...
#include <bits/stdc++.h> using namespace std; struct Pnt { int x, y; Pnt() {} Pnt(int _x, int _y) { x = _x; y = _y; } bool operator<(const Pnt& o) const { if (x != o.x) return x < o.x; return y < o.y; } void show() { printf( Pnt %d %d n , x, y); } }; const int...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); const int INF = 1000000000; const int dx[4] = {0, 0, 1, -1}; const int dy[4] = {1, -1, 0, 0}; const int N = 100001; int n, a[N]; int ans; int main() { ios_base::sync_with_stdio(0); cin >> n; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int inf = 1e9; char aa[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; vector<int> G[14]; int dp[1 << 14], dp2[14][14][1 << 14]; vector<int> re[1 << 14]; pair<int, int> last_pair[1 << 14]; int pre[1 << 14]; int last[14][14][1 << 14]; bool v[1 << 14]; int main() { int n, m, x, y; scanf( %d%d , &n, &m); for (int i =...
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << endl; err(++it, args...); } void faster() { ios::sync_with_stdio(false); cin....
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, k; vector<pair<int, int> > g[maxn]; int d[maxn], par[maxn]; void dfs1(int u, int fa) { par[u] = fa; for (auto p : g[u]) { int v = p.first; if (v == fa) continue; d[v] = d[u] + p.second; dfs1(v, u);...
#include <bits/stdc++.h> int main() { static char cc[100000 + 1]; int n, k, a, i; scanf( %d%d , &n, &k); a = (n - k) / 2; for (i = 0; i < n; i++) cc[i] = 0 + (i % (a + 1) == a); printf( %s n , cc); return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, l, r, ar[110], ubah; int main() { cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> l >> r; ar[l]++; ar[r + 1]--; } for (int i = 1; i <= n; i++) { ubah += ar[i]; if (ubah != 1) { cout << i << << ub...
#include <bits/stdc++.h> using namespace std; unsigned long long lvl_len(int lvl) { static long long len[64] = {0}; if (len[lvl]) return len[lvl]; else { len[1] = 1; for (int i = 2; i < 64; ++i) len[i] = len[i - 1] * 2 + 1; } return len[lvl]; } void rec(int lvl, unsigned lo...
#include<bits/stdc++.h> using namespace std ; #define ll long long #define pb push_back #define all(v) v.begin(),v.end() #define sz(a) (ll)a.size() #define F first #define S second #define INF 2000000000000000000 ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<vector<int> > A(n, vector<int>(n)); int counter = 0; int sum = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < k - 1; j++) { A[i][j] = ++counter; } } for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ff first #define ss second #define pb push_back #define mp make_pair #define deb(x) cout<< #x << << x << n ; #define MAX 9223372036854775807 #define MIN -9223372036854775807 #define setbits(n) __builtin_popcountll(n...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<string, string> mp; set<string> s; for (int i = 0; i < n; i++) { string old, edg; cin >> old >> edg; mp[old] = edg; s.insert(edg); } map<string, string>::iterator p; p = mp.begin()...
#include <bits/stdc++.h> using namespace std; long long add(long long x, long long y) { x += y; while (x >= 998244353) x -= 998244353; while (x < 0) x += 998244353; return x; } long long mul(long long x, long long y) { return (x * 1ll * y) % 998244353; } long long binpow(long long x, long long...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; long long T[N]; long long sum[5]; multiset<long long, greater<long long>> ms[5]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k, b, c; cin >> n >> k >> b >> c; for (int i = 1; i <= n; i++) { cin >> T[i...
#include <bits/stdc++.h> long long int mod = 1000000007; using namespace std; void solve() { long long int n, k; cin >> n >> k; char ans[4][n]; int nval = n - 2; for (int i = 0; i < 4; i++) { for (int j = 0; j < n; j++) { ans[i][j] = . ; } } int mid = nval / 2; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 300005; const long long mod = 998244353; long long fac[maxn], invfac[maxn]; int a[maxn]; long long qp(long long x, long long p, long long MOD) { long long res = 1; while (p) { if (p & 1) res = res * x % MOD; x = x * x % MOD; ...
#include <bits/stdc++.h> using namespace std; int f3(int n) { return n * (n - 1) * (n - 2) / 6; } int main() { int K; cin >> K; int N = 3; while (f3(N + 1) <= K) N++; int MN = N * (N - 1) / 2; int TN = 100; vector<string> E(TN, string(TN, 0 )); for (int i = 0; i < N; i++) { ...
#include <bits/stdc++.h> using namespace std; const int up = 1e6 + 6; int n, m, k, pos; int cost[up], p[up], last[up]; int main() { scanf( %d , &n); scanf( %d , &m); scanf( %d , &k); for (int i = 1; i <= m; i++) { scanf( %d , &pos); p[pos] = 1; } if (p[0]) { printf( %...
#include <bits/stdc++.h> using namespace std; mt19937_64 rang( chrono::high_resolution_clock::now().time_since_epoch().count()); int rng(int lim) { uniform_int_distribution<int> uid(0, lim - 1); return uid(rang); } void solution() { int y; cin >> y; while (true) { y = y + 1; ...
#include <bits/stdc++.h> using namespace std; map<char, char> q; int main() { char a[30], b[30]; scanf( %s , a); scanf( %s , b); q.clear(); for (int i = 0; i < 26; i++) { q[a[i]] = b[i]; q[a[i] - 32] = b[i] - 32; } char aim[2000]; scanf( %s , aim); for (int i = 0; a...
#include <bits/stdc++.h> const double EPS = 1e-7; const double PI = 3.1415926535897932384626; const int MAXN = 100001; int n, a[MAXN]; int main() { std::cin >> n; for (int i = 1; i <= n; i++) { std::cin >> a[i]; } long long answer = 0; for (int i = 1; i <= n; i++) { answer += a...
#include <bits/stdc++.h> int n; int degree[100010]; int main() { scanf( %d , &n); for (int i = 1; i <= n - 1; i++) { int r1, r2; scanf( %d%d , &r1, &r2); degree[r1]++; degree[r2]++; } for (int i = 1; i <= n; i++) { if (degree[i] == 2) { printf( NO ); r...
#include <bits/stdc++.h> using namespace std; int n; long long int cost = 0; vector<int> a, b, c; vector<vector<int>> g; pair<int, int> dfs(int cur, int par, int mn_before) { pair<int, int> ap = {0, 0}; int mn_cur = min(a[cur], mn_before); if (b[cur] != c[cur]) { if (b[cur] == 1) { ...
#include <bits/stdc++.h> using namespace std; int num, rt[200010], n; struct data { int l, r, v; } tr[200010 * 20]; void insert(int p, int l, int r, int n, int &x) { x = ++num; tr[x] = tr[n]; if (l == r) { tr[x].v++; return; } int mid = l + r >> 1; if (p <= mid) i...
#include <bits/stdc++.h> using namespace std; const long long INF = 10000; const long long MAXN = 1000; int n, a[MAXN], sum, cnt, ans; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } sort(a, a + n + 1); for (int i = n; i >= 1; i--) { cnt ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int l = 0; l < t; l++) { long long n, s, k; cin >> n >> s >> k; unordered_set<long long> tilos; for (int i = 0; i < k; ++i) { long long x; cin >> x; tilos.insert(x); } ...
#include <bits/stdc++.h> using namespace std; int d[200100], a[200100]; long long ans; int main() { int n, m, i, tmp, s, x; bool f = false, flag = true; scanf( %d , &n); for (i = 1; i <= n; ++i) scanf( %d , d + i); scanf( %d , &m); if (m % ((n - 1) << 1) == 0) f = true; s = (m / ((n ...
#include <bits/stdc++.h> using namespace std; long long abs2(long long a) { return a >= 0 ? a : -a; } long long calc(long long k, long long a) { if (k >= 0) return k / a; return (k - (a - 1)) / a; } long long calc2(long long a1, long long b1, long long a2, long long b2) { long long x = abs2(a1 - a...
#include <bits/stdc++.h> using namespace std; using lld = signed long long int; lld solve() { lld n, m, k; cin >> n >> m >> k; lld x = n / k; if (m <= x) return m; if (m <= x + (k - 1)) return x - 1; return x - ceil((m - x) / (k - 1.0)); } int main() { ios_base::sync_with_stdio(fal...
#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 maxn = 100000 + 10; int a[maxn], b[maxn]; int main() { int n; scanf( %d , &n); long long ans = 0; int cnt1 = 0, cnt2 = 0, cnt0 = 0; for (int i = 1; i <= n; i++) { scanf( %d , a + i); if (a[i] <= -1) { ans += -1 - a[i...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000005; int T, n, m, las = 1, ndnum = 1, ans; char s[maxn]; struct node { int ch[26], len, fa; } d[maxn << 1]; int siz[maxn << 1], vis[maxn << 1], timer; int head[maxn << 1], tot; struct edge { int nxt, to; } e[maxn << 1]; voi...
#include <bits/stdc++.h> using namespace std; const int OO = (int)2e9; const double PI = 2 * acos(0.0); const double EPS = 1e-9; int dcmp(double a, double b) { return fabs(a - b) <= EPS ? 0 : a > b ? 1 : 2; } int DI[] = {-1, 0, 1, 0, 1, -1, -1, 1}; int DJ[] = {0, 1, 0, -1, 1, -1, 1, -1}; void clc1(strin...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 300; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; const double eps = 1e-6; string s; int gx[] = {0, 0, 1, -1}; int gy[] = {1, -1, 0, 0}; bool used[MAX_N][MAX_N]; bool check(int x, int y) { int cnt = 0; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; namespace kotespace { template <class T> class duplet { private: public: T x, y; duplet(){}; duplet(T a, T b) : x(a), y(b){}; bool operator<(const duplet P) const { return (x < P.x || (x == P.x && y < P.y)); } bool operator>(const...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:102400000,102400000 ) template <class T> void chkmax(T &a, T b) { if (a < b) a = b; } template <class T> void chkmin(T &a, T b) { if (a > b) a = b; } const int inf = 0x3f3f3f3f; const long long linf = 2e18 + 100; ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.); const int MX = 500500; int t, n, i, j, z[MX]; char s[MX]; vector<complex<double> > a, b; vector<int> r, ans; void fft(vector<complex<double> >& a, bool inv) { int n = a.size(); if (n == 1) return; for (int i = 1, rv =...
#include <bits/stdc++.h> using namespace std; const int N = 1000005; int a[N], L[N], tot, R[N], Stack[N], n, m; long long Ans[N]; struct Ask { int l, r, from; } A[N]; inline int cmp1(Ask x, Ask y) { return x.l > y.l; } inline int cmp2(Ask x, Ask y) { return x.r < y.r; } struct segTree { struct...
#include <bits/stdc++.h> using namespace std; int maxn = (1 << 18) - 1; int main() { int k; scanf( %d , &k); int b = maxn, cnt = 0; for (int i = 0; i <= 20; ++i) { if ((k >> i) & 1) { b ^= (1 << i); } } int cc = maxn >> 1; printf( %d %d n , 3, 3); printf( %d %d ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; bool lava[2][n]; for (int i = 0; i < 2; i++) { for (int j = 0; j < n; j++) lava[i][j] = false; } set<int> blocked1; set<int> blocked2; for ...
#include <bits/stdc++.h> const long long maxn = 8e9 + 5; long long v[10000000]; long long k[10000000]; long long n, sum; int judge(long long m) { long long i, sum1 = sum; for (i = 0; i < n; i++) { if (m * v[i] > k[i]) { if (k[i] + sum1 < m * v[i]) break; else if (k[i] +...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> g(n + 1); for (int i = 0; i < n; i++) { int u; cin >> u; g[i + 1] = u; } for (int i = 1; i <= n; i++) { if (g[g[g[i]]] == i) { cout << YES ; return 0; } ...
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const double eps = 1e-9; const int maxn = 100010; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; double l, v1, v2; cin >> n >> l >> v1 >> v2 >> k; int t = (n + k - 1) / k; if (t == 1) { ...
#include <bits/stdc++.h> using namespace std; long long MOD(string s, long long c) { long long ans = 0, p = 1; for (int i = (((int)s.size()) - 1); i >= (0); i--) { ans = (ans + (s[i] - 0 ) * p) % c; p *= 10; p %= c; } return ans; } long long mod(long long a, long long b, long ...
#include <bits/stdc++.h> using namespace std; const double INF = 1e18; const int MAX_N = 100100; const int IT = 100; const double PI = acos(-1.0); int x[MAX_N]; int y[MAX_N]; long long dist(int a, int b) { long long dx = x[a] - x[b]; long long dy = y[a] - y[b]; return dx * dx + dy * dy; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); vector<int> a(n); for (int i = 0; i < n; i++) scanf( %d , &a[i]); sort(a.begin(), a.end()); for (auto i : a) { if (i != a[0]) { printf( %d , i); return 0; } } printf( NO ); ...
#include <bits/stdc++.h> using namespace std; long long a[20]; long long b[20][10][10]; long long c[20][10][10]; long long dp(long long n, int p) { long long n0 = n; long long ans = 0; while (n >= 10) { long long m = n; long long e = 0; while ((m + 10) % (a[e] * 10) < 10) e++; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int dp[maxn], ans; const int inf = 1e9; int a1, a2, adfds, fd; vector<int> edge[maxn]; int n, m, d, num[maxn], fuck; void dfs1(int u, int fa) { int i; for (i = 0; i < (int)edge[u].size(); i++) { int v = edge[u][i]; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const double eps = 1e-9; int n, t; char A[N], B[N]; int main() { scanf( %d %d n , &n, &t); gets(A); gets(B); int sameCnt = 0; for (int i = 0; i < n; ++i) { if (A[i] == B[i]) ++sameCnt; } int dif = n - sam...
#include <bits/stdc++.h> using namespace std; const int c=200002, k=20; int n, q, p[c], szint[c], fel[c][k], f[c], db[c]; long long aa[c], bb[c], dist[c], val[c], sum; bool v[c]; set<int> s; int lca(int a, int b) { if (szint[a]<szint[b]) { swap(a, b); } for (int i=k-1; i>=0;...
#include <bits/stdc++.h> int main(void) { static unsigned char mas[125 * 1000000], mas1[125 * 1000000]; int n, m, mas2[200000], x, rez = 0, last1 = 0, last2 = 1; scanf( %d %d , &n, &m); for (int i = 0; i < ceil(m / 8.0); i++) { mas[i] = 0; mas1[i] = 0; } int samechet = 0, sameneche...
#include <bits/stdc++.h> using namespace std; const int N = 400005; map<int, int> H; int n, m, p, l, r, s, tot, T, a[N], b[N], c[N], ans[N]; int get() { int v; scanf( %d , &v); if (!H[v]) H[v] = ++tot; return H[v]; } void add(int x) { if (c[x]++ < 0) --s; else ++s; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e9; struct comparator { bool operator()(const pair<int, int> &a, const pair<int, int> &b) { return a.first > b.first; } } cmp; int main() { char in; vector<pair<int, int> > white, black; int board[8][8]; for (int i =...
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, k, n; string s, s1, b; cin >> n >> k >> s; b = s; for (i = k; i < n; i++) b[i] = b[i - k]; if (b >= s) cout << n << endl << b << endl; else { for (i = k - 1; i >= 0; i--) { if (b[i] == 9 ) ...
#include <bits/stdc++.h> using namespace std; bool cmp(int u, int y) { return u > y; } int main() { int i, j; int n, m, x; int a[100009], b[100009]; int cnt; while (scanf( %d %d , &n, &x) != EOF) { for (i = 0; i < n; i++) scanf( %d , &a[i]); sort(a, a + n, cmp); for (i = 0; i...
#include <bits/stdc++.h> using namespace std; int find(string s, string sub, int begin, int end) { for (int i = begin; i < end - 1; i++) if (s[i] == sub[0] && s[i + 1] == sub[1]) return i; return -1; } int main() { string s, sub; cin >> s; int size = s.size(); int index1, index2, i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); std::ios::sync_with_stdio(false); string a; cin >> a; for (int i = 0; i < a.size(); i++) { if (((int)(a[i]) >= 48 && (int)(a[i]) <= 57) || ((int)(a[i]) >= 97 ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int M = 1e9 + 7; void madd(int& a, int b) { a += b; if (a >= M) a -= M; } int mult(int a, int b) { return (1LL * a * b) % M; } int modexp(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = mult(res, ...
#include <bits/stdc++.h> using namespace std; int main() { long long int x, d, nxt = 1, arr[10001] = {0}, pos = 0; cin >> x >> d; for (int j = 30; j >= 0; j--) if (x >= (((long long int)1 << j))) { x -= ((long long int)1 << j); for (int i = 1; i <= j; i++) arr[pos++] = nxt; ...
#include <bits/stdc++.h> using namespace std; struct Edge { int v, f; Edge *next, *rest; }; int n, m, b, x[100], k[100], p[100]; long long dp[1048576]; long long ans = 0x3FFFFFFFFFFFFFFFLL; int main() { scanf( %d%d%d , &n, &m, &b); for (int i = 0, len; i < n; i++) { scanf( %d%d%d , &...
#include <bits/stdc++.h> using namespace std; int n; int a[300005] = {0}; int c1 = 0, c2 = 0, p1 = 0, p2 = 0; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; int maxn = -1; for (int i = 1; i <= n; i++) { if (c1 == 0) { p1 = i; c1 = a[i]; } else if (...
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a % b) : a); } template <class T> T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); } template <class T> inline bool read(T &x) { int c = getchar(); int sgn = 1; while (~c &...
#include <bits/stdc++.h> using namespace std; int n, m, k; vector<int> E[200020], V; int dis[2][200020]; void solve() { scanf( %d%d%d , &n, &m, &k); for (int i = 1; i <= k; i++) { int x; scanf( %d , &x); V.push_back(x); } for (int i = 0; i < (m); i++) { int x, y; ...
#include <bits/stdc++.h> using namespace std; inline bool isPowerOfTwo(int x) { return (x != 0 && (x & (x - 1)) == 0); } double pi = 3.141592653589793238462643; int month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int n; int b[MAXN]; set<pair<int, int>, greater<pair<int, int> > > s; int ans[MAXN]; int main() { scanf( %d , &n); for (auto i = 0; i != n; i++) scanf( %d , &b[i]); for (auto i = 0; i != n; i++) { int j = (i + 1) % n...
#include <bits/stdc++.h> using namespace std; int main() { int N = 0; cin >> N; for (int i = 0; i < N; i++) { int length, height; cin >> length >> height; int pixL, pixH; cin >> pixL >> pixH; int ans = max(max(height - pixH - 1, pixH) * length, max(lengt...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > p, pt; int n, m; void getanswer(int l, int r) { if (l >= r) return; getanswer(l, (l + r) / 2); getanswer(1 + ((l + r) / 2), r); for (int i = int(l); i <= int(r); ++i) { m++; pt.push_back(make_pair(p[(l + r) / 2].fi...
#include <bits/stdc++.h> const int maxn = 8005; const int inf = 0x3f3f3f3f; const long long mod = 998244353; using namespace std; long long vis[111]; int main() { long long x = 1ll, y; int n, q; scanf( %d %d , &n, &q); for (int i = 1; i <= n; ++i) { scanf( %lld , &y); for (int j ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); char sym[] = { A , O , M , H , I , o , T , V , W , U , X , Y , x , w , v }; map<char, char> mp; mp[ b ] = d ; mp[ d ] = b ; mp[ p ] ...
#include <bits/stdc++.h> using namespace std; int main() { int a[100] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1, 52, 2, 5, 1, 5,...
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9 + 7; const pair<int, int> pinf = pair<int, int>(inf, inf); int up(int n) { int ret = 1; while (ret < n) ret <<= 1; return ret; } template <class T> class segtree { vector<T> arr; T min(int l, int r, int cl, int cr, ...
#include <bits/stdc++.h> bool V[11][11]; int T[11][11]; int R = 0, C = 0, N = 0, K = 0, t1 = 0, t2 = 0; int W = 0; int main() { scanf( %d%d%d%d , &R, &C, &N, &K); for (int i = 1; i <= N; i++) { scanf( %d%d , &t1, &t2); V[t1][t2] = true; } for (int i = 1; i <= R; i++) for (int...
#include <bits/stdc++.h> using namespace std; int n; int da[550]; int dp[550][1050]; int dp2[550][550]; struct kutija { int in, out, w, s, v; } K[505]; bool cmp(const kutija &a, const kutija &b) { if (a.in != b.in) return a.in < b.in; if (a.out != b.out) return a.out > b.out; return a.s ...
#include <bits/stdc++.h> using namespace std; int n, a[5][8]; int vis[123124]; struct Mp { int a[30]; Mp() { memset(a, 0, sizeof(a)); } bool operator<(const Mp &x) const { for (int i = 0; i < 25; ++i) if (x.a[i] != a[i]) return a[i] < x.a[i]; return 0; } void swap(int &a,...
#include <bits/stdc++.h> using namespace std; const int N = 1011; int n, m; char a[N][N]; int b[N][N], ts; const int dx[] = {-1, -1, 0, 0, 1, 1}; const int dy[] = {1, -1, 2, -2, 1, -1}; void output() { for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { int x = i, y = j; ...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; long long a[n], b[n], c[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } for (long long i = 0; i < n; i++) cin ...
#include <bits/stdc++.h> const int oo = 2139063143; const int N = 101000; const int P = 1000000007; using namespace std; inline void sc(int &x) { x = 0; static int p; p = 1; static char c; c = getchar(); while (!isdigit(c)) { if (c == - ) p = -1; c = getchar(); } w...
#include <bits/stdc++.h> using namespace std; int n, V; pair<int, int> a[111111]; int x[111111], t[111111], b[111111], f[111111]; int ans1, ans2; int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d%d , &x[i], &t[i]); cin >> V; for (int i = 1; i <= n; ++i) t[i] *= V, a[...