func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int N = 105, M = N * N * N; int n, pos, l, r, i, j, k, f[N][N][N], h, t, q[M][3], ans; inline void ext(int x, int y, int z, int d) { if (y > z) return; if (y > l || z < r) return; if (x < y || x > z) return; if (~f[x][y][z]) return; f[x][y]...
#include <bits/stdc++.h> int32_t gcd(int32_t a, int32_t b) { if (b == 0) return a; return gcd(b, a % b); } int32_t mpf(int32_t n, std::vector<int32_t>& primes) { for (int32_t i = 0; i < primes.size(); i++) if (n % primes[i] == 0) return primes[i]; return 1; } int main() { int32_t num...
#include <bits/stdc++.h> inline int read() { register int s = 0, f = 1; char c; for (c = getchar(); c < 0 || c > 9 ; c = getchar()) if (c == - ) f = -1; while (c >= 0 && c <= 9 ) s = (s * 10 + (c ^ 0 )), c = getchar(); return s * f; } inline void print(register int x) { if (x...
#include <bits/stdc++.h> using namespace std; const int Max = 2e5 + 10; const int LOG = 30; const int INF = 1e9 + 10; struct Trie { int l[Max * LOG], r[Max * LOG]; int cnt[Max * LOG]; int sz = 1; int index[Max * LOG]; int dp[Max * LOG][2]; void insert(int x, int ind) { int p = 1;...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > diffs; long long int su[100500]; int n, s; long long int kek(long long int res) { long long int ans = res; su[n - 1] = 1ll * diffs.back().first * diffs.back().second; for (int i = n - 2; i >= 0; i--) { su[i] = su[i + 1] + ...
#include <bits/stdc++.h> const int MAXN = 1000 + 5; char str[MAXN]; int n; inline std::vector<int> query(std::vector<int> d) { std::vector<int> ans; printf( ? ); for (auto x : d) printf( %d , x); puts( ); std::fflush(stdout); scanf( %s , str + 1); for (int i = 1; i <= n; ++i) ans....
#include <bits/stdc++.h> using namespace std; int main() { // your code goes here int t; cin>>t; int len=pow(10,9)+7; while(t--) { int n,k; cin>>n>>k; long long int ans=1; for(int i=0;i<k;i++) { ans=(ans*n)% len; } cout<<ans<<endl; ...
#include <bits/stdc++.h> using namespace std; inline void read(long long &x) { char ch; bool flag = false; for (ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == - ) flag = true; for (x = 0; isdigit(ch); x = x * 10 + ch - 0 , ch = getchar()) ; x = flag ? -x : x; } inline ...
#include <bits/stdc++.h> int main() { char a[200100], b[200100]; while (~scanf( %s%s , a, b)) { int c[1000]; memset(c, 0, sizeof(c)); int n = 0; for (int i = 0; a[i]; ++i) ++c[a[i]]; int ya = 0; for (int i = 0; b[i]; ++i) if (c[b[i]]) --c[b[i]], ++ya, b[i] = -1; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { long long n, m; cin >> n >> m; vector<pair<long long, long long>> ar(m); for (int i = 0; i < m; ++i) { cin >> ar[i].first ...
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; long long mod = 1000000007LL; long long mod2 = 998244353LL; long long t, l, r; long long dp[5000005]; long long prm[5000005]; long long pw[5000005]; long long dfs(int x) { if (dp[x] >= 0) return dp[x]; if (x == 1) return...
#include <bits/stdc++.h> using namespace std; const int maxn = 100086; const int inf = 2.1e9; const long long Inf = 999999999999999999; const int mod = 1000000007; const double eps = 1e-6; const double pi = acos(-1); int n, s, t; int nums[206]; int vis[maxn], num[maxn]; int prime[maxn], cur; boo...
#include <bits/stdc++.h> using namespace std; char oda[3500]; int y; void PuLe(int x) { int j; j = x; while (oda[j - 1] == . ) { oda[j - 1] = @ ; j--; } if (oda[j - 1] == R ) { if ((x - j) % 2 != 0) oda[x - ((x - j) / 2 + 1)] = . ; } } void PuRi(int x) { int...
#include <bits/stdc++.h> using namespace std; long long int binarySearch(long long int* arr, long long int l, long long int r, long long int x) { if (r >= l) { long long int mid = l + (r - l) / 2; if (arr[mid] == x) return mid; if (arr[mid] > x) return binarySearch...
#include <bits/stdc++.h> using namespace std; bool cmp(int x, int y) { return x > y; } int main() { double sum; int n, r[110]; while (~scanf( %d , &n)) { sum = 0; for (int i = 0; i < n; i++) scanf( %d , &r[i]); sort(r, r + n, cmp); int tmp = 1; for (int i = 0; i < n; i++)...
#include <bits/stdc++.h> using namespace std; int n, m, a[5005], b[5005], c[5005], dp[5005][5005][2], size[5005]; vector<int> G[5005]; void DP(int u) { size[u] = 1; dp[u][0][0] = 0; dp[u][1][0] = a[u]; dp[u][1][1] = a[u] - b[u]; for (int i = 0; i < G[u].size(); i++) { int v = G[u][i]; ...
#include <bits/stdc++.h> using namespace std; struct line { long long m, b; int id; }; long long floordiv(long long a, long long b) { return a / b - (a % b && ((a < 0) ^ (b < 0))); } long long intersect(line a, line b) { return floordiv(b.b - a.b, a.m - b.m); } pair<int, int> org[262192 >> 1];...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); const int inf = 0x3f3f3f3f; const long long oo = 1LL << 60; const int N = 10010; const int E = 200010; class Graph { public: int pnt[E], nxt[E], id[E]; int head[N], nv, ne; void init(const...
#include <bits/stdc++.h> using namespace std; using LL = long long; namespace _buff { const size_t BUFF = 1 << 19; char buff[BUFF], *begin = buff, *end = buff; char getc() { if (begin == end) { begin = buff; end = buff + fread(buff, 1, BUFF, stdin); } return begin == end ? -1 : *begi...
#include <bits/stdc++.h> using namespace std; int n, i; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n >> s; for (i = 1; i <= n; i++) { if (n % i == 0) { reverse(s.begin(), s.begin() + i); } } cout << s; }
#include <bits/stdc++.h> #pragma GCC target( avx ) #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize( Ofast ) #pragma GCC optimize( inline ) #pragma GCC optimize( -fgcse ) #pragma GCC optimize( -fgcse-lm ) #pragma GCC optimize( -fipa-sra ) #pragma GCC optimize( -ftree-pre ) #pragm...
#include <bits/stdc++.h> using namespace std; int n, m; long long a, b; int main() { scanf( %d %d , &n, &m); a = 0, b = 1; for (int i = (1); i <= (n); i++) { long long c, d; d = 2 * m * b - a; a = m * b + (m - 1) * a; b = d; a %= 1000000007; b %= 1000000007; }...
#include <bits/stdc++.h> using namespace std; int n, ans, k, d, cnt1, cnt2, l, r; int a[200050]; struct node { int x, b; }; node s[200050]; int main() { k = 1; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); } l = 1, r = n, s[0].x = 0; d = 0; while...
#include <bits/stdc++.h> using namespace std; int n, s, a[200100], cnt[200100], ans, kol; set<int> st; int main() { cin >> n >> s; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= n; ++i) { if (i == s) { if (a[i] != 0) { a[i] = 0; ans++; ...
#include <bits/stdc++.h> using namespace std; const int N = 505; int cnt[N * N], par[N][N], sum[N][N], sz[N * N]; char grid[N][N]; int n, k; int cur = 0; void change(int id, int add) { if (id == 0) return; if (cnt[id]) cur -= sz[id]; cnt[id] += add; if (cnt[id]) cur += sz[id]; } void p...
#include <bits/stdc++.h> using namespace std; template <class T> bool setmax(T &_a, T _b) { if (_b > _a) { _a = _b; return true; } return false; } template <class T> bool setmin(T &_a, T _b) { if (_b < _a) { _a = _b; return true; } return false; } template...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; while (TESTS--) { int n, e; set<int> v; map<int, int> m; cin >> n; for (long long int i = 0; i < n; i++) { cin >> e; ...
#include <bits/stdc++.h> using namespace std; set<pair<long long, long long> > S; set<pair<long long, long long> >::iterator it; set<pair<long long, long long> >::iterator it2; pair<long long, long long> temp; void intersect_yes(long long s, long long e) { if (S.empty()) return; for (it = S.begin();...
#include<stdio.h> #include<bits/stdc++.h> typedef long long ll; using namespace std; int main() { ll deva; cin>>deva; for(ll ol=0;ol<deva;ol++) { int n; cin>>n; string s; cin>>s; int a[26]={0}; int flag=1; ...
#include <bits/stdc++.h> using namespace std; int a[100500]; int sp[2005]; int f[100500], l[100500]; int n, m; int ns[2 * 100500]; int ps[2 * 100500]; int used[2 * 100500]; int lp[100500]; int rp[100500]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; ++i) { scanf( %d , ...
#include <bits/stdc++.h> using namespace std; int INF = 1000000007; string FILENAME = input ; string FILEINPUT = FILENAME; void writeln(int a) { printf( %d n , a); } void writeln(int a, int b) { printf( %d %d n , a, b); } void writeln(int a, int b, int c) { printf( %d %d %d n , a, b, c); } void writeln...
#include <bits/stdc++.h> using namespace std; int a[110]; int r; void solve(int x) { r = 0; while (x) { a[r++] = x % 3; x /= 3; } } int main() { int t; scanf( %d , &t); while (t--) { memset(a, 0, sizeof a); int n; scanf( %d , &n); solve(n); a...
#include <bits/stdc++.h> int main() { int n, m1, m2, m3, min1, min2, min3, max1, max2, max3; scanf( %d%d%d%d%d%d%d , &n, &min1, &max1, &min2, &max2, &min3, &max3); m1 = n - min2 - min3; if (m1 <= max1) printf( %6d %6d %6d , m1, min2, min3); else { m2 = min2 + m1 - max1; if (m2 < ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( avx2 ) using namespace std; const long long MAX = -1000000000000000000; const long long MIN = 1000000000000000000; const long long inf = 1000000000; const long long K...
#include <bits/stdc++.h> using namespace std; const long long MXN = 1e6 + 1; const long long MNN = 1e3 + 1; const long long MOD = 1e9 + 7; const long long INF = 1e18; const long long MAGIC = 1000; const long double EPS = 1e-9; const long double PI = 3.1415926536; const string TIME = rovno_ushten_push...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, ns, ne, v, i; cin >> n >> m >> ns >> ne >> v; vector<long long int> s(ns), e(ne); for (i = 0; i < ns; i++) cin >> s[i]; for (i = 0; i < ne; i++) cin >> e[i]; long long int q; cin >> q; while (q--) { ...
#include <bits/stdc++.h> using namespace std; map<pair<long long, long long>, long long> mp; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; for (long long i = 0; i < m; i++) { long long a, b; cin >> a >> b; a--; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long getres(long long n) { if (n == 0) { return 0; } vector<long long> now; for (long long i = 0;; i++) { long long t = pow(2, i); if (t <= n) { n -= t; now.push_back(t); if ...
#include <bits/stdc++.h> using namespace std; struct zero { int nxt, to; } edge[200000 << 1]; int head[200000], tot = 0; void add_edge(int a, int b) { edge[++tot] = (zero){head[a], b}; head[a] = tot; } int n, m, plk, poi, d1, d2, dep[200000], kl[200000], d[200000], op[200000], h[200000];...
#include <bits/stdc++.h> using namespace std; vector<int> fibton; void Fib(int n) { int x = 0, y = 1, z = 0; fibton.push_back(0); for (int i = 0; i <= n; i++) { z = x + y; fibton.push_back(z); if (fibton[fibton.size() - 1] >= n) { break; } x = y; y = z; ...
#include <iostream> #include <iomanip> #include <cstdio> #include <vector> #include <algorithm> #include <cmath> #include <cstring> #include <cassert> #include <string> #include <set> #include <map> #include <random> #include <bitset> #include <string> #include <unordered_set> #include <un...
#include <bits/stdc++.h> using namespace std; int lim; char c[1000]; int g[1000][1000]; int f[1000][1000], pre[1000][1000]; void back(int v, int k) { int p = pre[v][k]; if (p) { back(p, k - 1); printf( + ); } int i1 = p + 1; int j1 = v; for (; i1 < j1; i1++, j1--) i...
#include <bits/stdc++.h> using namespace std; const int mm = 500050; int n, ss, tt, kk, m; int c[1001001], v[1001001]; int g[1001001]; int xx[1001001], yy[1001001], minvv = 0, initi = 0; long long sum[500500], ti[500500]; vector<int> num[500500]; inline void solve() { int i = 0; while (i <= m)...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000005; int n, k; struct edge { int v; edge *nxt; } g[maxn << 1], *he[maxn]; int cnt; void add_edge(int a, int b) { edge *e = g + (++cnt); e->v = b, e->nxt = he[a]; he[a] = e; } bool in[maxn]; int mxs[maxn], dep[maxn...
#include <bits/stdc++.h> using namespace std; const int N = 1e6; int t, tot, type[N]; long long r, f[N]; vector<int> son[N]; template <class T> inline void read(T &x) { x = 0; char ch = getchar(), w = 0; while (!isdigit(ch)) w = ch == - , ch = getchar(); while (isdigit(ch)) x = (x << 1) +...
#include <bits/stdc++.h> using namespace std; struct node { int a, b; bool operator<(const node& r) const { return r.b < b; } } e[105]; int dp[10005][105]; int main() { int n, sum = 0, num = 0, sum2 = 0; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &e[i].a); sum +...
#include <bits/stdc++.h> using ll = long long; using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); int t; cin >> t; for (ll _ = 0, _Len = (t); _ < _Len; ++_) { ll n; cin >> n; vector<ll> a(n); vector<pa...
#include <bits/stdc++.h> using namespace std; const double EPS = 10e-11; class VagueDouble { public: double vd; VagueDouble() { vd = nan( ); } VagueDouble(const double d) { vd = d; } inline VagueDouble operator-() const { return VagueDouble(-vd); } inline VagueDouble operator+(const VagueD...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T first, T second) { while (second > 0) { first %= second; swap(first, second); } return first; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <class _T> inline _T sqr(con...
#include <bits/stdc++.h> using namespace std; const int inv = 1000000000; const int minv = -inv; const int max_n = 100010; const int max_m = 100010; const int max_k = 110; const int modref = 1000000007; int n, m; int a[max_n]; int b[max_n][max_k + 1] = {0}; int c[max_k + 1] = {0}; int bin[max_n ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,inline,unroll-loops,fast-math ) using namespace std; int f[5020][5020]; inline int Mod(int x) { return x + ((x >> 31) & 998244353); } int Power(int x, int y) { int o; for (o = 1; y; y >>= 1) { if (y & 1) o = (long long)o * x % 998244353; ...
#include <bits/stdc++.h> using namespace std; const long INF = 1000 * 1000 * 1000; const long long int mod = 1000000007; int dp[100050]; int main() { std::ios::sync_with_stdio(false); int t; cin >> t; while (t--) { long double d; cin >> d; long double a, b, x, y; x = d ...
#include <bits/stdc++.h> using namespace std; int m[120], n, k = 0; int main() { cin >> n; char a, b; getchar(); for (int i = 1; i < n; i++) { a = getchar(); b = getchar(); m[a - a ]++; if (m[b - A ] > 0) { m[b - A ]--; } else { k++; } } ...
#define _CRT_SECURE_NO_WARNINGS #include <vector> #include <string> #include <map> #include <queue> #include <unordered_map> #include <unordered_set> #include <cassert> #include <complex> #include <cstdio> #include <iostream> #include <iomanip> #include <cmath> #include <functional> #include...
#include <bits/stdc++.h> const long long N = 5e5 + 5; const int MOD = 1e9 + 7; using namespace std; int n; int a[N]; long long b[N], c[N]; multiset<long long> s; void xuly() { cin >> n; for (int i = (1); i <= (n); ++i) cin >> a[i]; sort(a + 1, a + 1 + n); cout << (n - 1) / 2 << n ; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; struct gg { int a, b, num; } g[maxn], out[maxn]; bool cmp(gg g1, gg g2) { return g1.a < g2.a || (g1.a == g2.a && g1.b > g2.b); } int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { cin >> g[i].a >>...
#include <bits/stdc++.h> using namespace std; template <typename T> void printArray(T arr, int l) { for (int i = 0; i < l; i++) cout << arr[i] << ; cout << endl; } int main(void) { int n, k; cin >> n >> k; vector<int> floors; for (int i = 0; i < n; i++) { int temp; cin >...
#include <bits/stdc++.h> using namespace std; int a[105]; int t, n, m; bool check() { int flag = 1; for (int i = 1; i < n; i++) { if (a[i] > a[i + 1]) return 0; } return 1; } int main() { cin >> t; while (t--) { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i...
#include <bits/stdc++.h> using namespace std; template <typename T> void rd(T& x) { int f = 0, c; while (!isdigit(c = getchar())) f ^= !(c ^ 45); x = (c & 15); while (isdigit(c = getchar())) x = x * 10 + (c & 15); if (f) x = -x; } template <typename T> void pt(T x, int c = -1) { if (...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int ans[6]; cout << ? 1 2 << n ; cout.flush(); double a; cin >> a; cout << ? 2 3 << n ; cout.flush(); double b; cin >> b; map<double, bool...
#include <bits/stdc++.h> using namespace std; long long dp[3505][305]; int a[305], b[305]; const int mod = 1e9 + 7; int main() { int n, l; cin >> n >> l; for (int i = 0; i < n; i++) { scanf( %d%d , &a[i], &b[i]); dp[a[i]][i]++; if (a[i] != b[i]) { a[i + n] = b[i]; ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; using mseti = multiset<int>; using mmapii = multimap<int, int>; inline int int_max() { return numeric_limits<int>::max(); } inline int int_min() { return numeric_limits<int>::min(); } inline ll ll_max() { return numeric_limits<ll>::max();...
#include <bits/stdc++.h> using namespace std; int a[300007]; int main() { int n, k; scanf( %d%d , &n, &k); string s; cin >> s; int sum = 1; a[0] = 1; for (int i = (1); i <= (n - 1); ++i) { if (sum && s[i] == . ) a[i] = 1; sum += a[i]; if (i >= k) sum -= a[i - k]; ...
#include <bits/stdc++.h> using namespace std; int l, n, a[55], b[55], c[55], d[55]; int main() { cin >> n >> l; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; for (int i = 1; i < n; i++) c[i] = a[i] - a[i - 1]; c[0] = a[0] + l - a[n - 1]; for (int i = 1; ...
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 1, 0, -1, -1, -1, 1, 1}; int dy[] = {1, 0, -1, 0, 1, -1, 1, -1}; int main() { ios::sync_with_stdio(false); long long n, k; cin >> n >> k; if (n == 1) cout << 0; else if (n <= k) cout << 1; else { n--; lo...
#include <bits/stdc++.h> using namespace std; int n, m, f[1000010], a[1000010]; char s[1000010]; bool vis[1000010]; long long Pow(int x) { if (x < 0) return 0; if (x == 0) return 1; long long ans = Pow(x >> 1); ans = ans * ans % 1000000007ll; if (x & 1) ans = (ans * 26ll) % 1000000007ll; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 511111; int num[maxn]; int q[maxn]; int main() { int i, j, n, m, k; scanf( %d%d , &n, &m); memset(num, 0, sizeof(num)); num[0] = 1; for (i = 1; i <= n; i++) { scanf( %d , &k); for (j = 500000; j >= k; j--) { ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:134217728 ) using namespace std; int main() { int p[4], a, b; for (int i(0); i <= (4 - 1); ++i) scanf( %d , &p[i]); scanf( %d%d , &a, &b); int res(0); for (int i = a; i <= b; ++i) { int perm[] = {0, 1, 2, 3}; int k(0); ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 105; const long long MOD = 1e9 + 7; long long dp[MAXN][MAXN], tmp[MAXN][MAXN]; void fillTmp() { for (int i = 0; i < MAXN; i++) fill(tmp[i], tmp[i] + MAXN, 0); return; } void fillDp() { for (int i = 0; i < MAXN; i++) for (int ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 1e4 + 10; int T, n; int id[N], cnt[10], ans[10]; char s[N]; inline int check(int id) { int mini = inf; for (int i = 1; i <= 4; i++) mini = min(mini, cnt[i]); if (cnt[id] == mini) return 1; return 0; }...
#include <bits/stdc++.h> using namespace std; int n, m, sum = 0, a = 101; int main() { cin >> n; while (n--) { cin >> m; sum += m; if (m & 1 && m < a) a = m; } if (sum & 1) cout << sum << endl; else { if (a == 101) cout << 0 << endl; else cou...
#include <bits/stdc++.h> using namespace std; const bool debug = false; const int inf = 1000 * 1000 * 1000; const int MAKSN = 1000 + 13; const long long MOD = 123456789LL; int n, m, k, l, x, y, a, b, p; string s; vector<int> v; void readIn() { cin >> n >> m >> p; x = 0; for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; char str[200], pat[20][200]; map<pair<int, int>, int> H[20]; set<pair<int, int> > st; int a[20], b[20]; int N; int main() { int i, j, k, h, len, ans, cnt; scanf( %s , str); scanf( %d , &N); for (i = 0; i < N; i++) scanf( %s%d%d , &pat[i], &a[i]...
#include <bits/stdc++.h> using namespace std; const int lim = 1e6 + 1; int criba[lim]; void fun_criba(int n) { for (int i = 2; i <= 2; i++) { if (criba[i] == 0) for (int j = i + i; j <= n; j += i) { criba[j] = i; } } for (int i = 3; i <= n; i += 2) { if (criba[i...
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; cout << 3 * (N - 2) - 2 + (N - 4) * (N - 3) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; char c; int n, m, cnt, f[3600][3]; bool a[60][60], flag, heng[51][51][51], shu[51][51][51]; bool go(int x1, int y1, int x2, int y2) { if (heng[x1][min(y1, y2)][max(y1, y2)] && shu[y2][min(x1, x2)][max(x1, x2)]) return true; if (heng[x2][min(y1, y2)][...
#include <bits/stdc++.h> using namespace std; const int MX = (int)1e3 + 6; int n, ax, ay, cx, cy, bx, by; int dirx8[] = {0, 0, 1, -1, 1, -1, 1, -1}; int diry8[] = {1, -1, 0, 0, 1, -1, -1, 1}; bool vis[MX][MX]; void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } bool vail...
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using vi = vector<int>; using ll = long long; vi prefix_function(string &s) { int n = int((s).size()), j = 0; vi pre(n); for (int i = int(1); i < int(n); i++) { while (j > 0 && s[i] != s[j]) j = pre[j - 1]; pre[i...
#include <bits/stdc++.h> using namespace std; namespace io { const int l = 1 << 19; char buf[l], *s, *t, c; char gc() { if (s == t) { t = (s = buf) + fread(buf, 1, l, stdin); return s == t ? EOF : *s++; } return *s++; } template <class I> void gi(I &x) { x = 0; c = gc(); ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1; int n, m, d; pair<long long, long long> a[N]; deque<pair<long long, long long> > D; int res; int ans[N]; void Input() { cin >> n >> m >> d; for (int i = 1; i <= (int)n; i++) { cin >> a[i].first; a[i].second = i; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int maxn5 = 3e5 + 10; const int maxn3 = 1e3 + 10; const long long mod = 1e9 + 7; const long long inf = 2e18; int a[maxn5], righ[24][maxn5], lef[24][maxn5]; int mn[18][maxn5], mx[18][maxn5], n, ans[maxn5], l[maxn5], r[maxn5]; ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > vvx; vector<pair<int, int> > vvz; bool contained(int a, int b, int c, int d) { if (c <= b && d >= a) return true; else return false; } int main() { int p, q, l, r; cin >> p >> q >> l >> r; vvx.resize(p + 1)...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pint = pair<int, int>; using pll = pair<ll, ll>; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; vector<ll> a(n); for (ll i = 0; i < (ll)n; i++) cin >> a[i]...
#include <bits/stdc++.h> using std::abs; using std::array; using std::cerr; using std::cin; using std::cout; using std::generate; using std::make_pair; using std::map; using std::max; using std::max_element; using std::min; using std::min_element; using std::pair; using std::reverse; using...
#include <bits/stdc++.h> using namespace std; long long n, k; long long phi(long long x) { long long ret = 1; for (long long i = 2; i * i <= x; i++) { if (x % i == 0) { ret *= i - 1; x /= i; while (x % i == 0) x /= i, ret *= i; } } if (x > 1) ret *= x - 1; r...
#include <bits/stdc++.h> using namespace std; long long spf[2]; long long fac[2]; void sieve() { spf[1] = 1; for (long long i = 2; i < 2; i++) spf[i] = i; for (long long i = 4; i < 2; i += 2) spf[i] = 2; for (long long i = 3; i * i < 2; i++) { if (spf[i] == i) { for (long long j = ...
#include <bits/stdc++.h> using namespace std; const int cap = 1e5 + 10; int main() { long long a[cap]; a[1] = 0; long long n, m; long long Max, Min; cin >> n >> m; if (m == 0) Max = n; else { for (int i = 2; i <= n; i++) { a[i] = a[i - 1] + i - 1; if (a[i] >...
#include <bits/stdc++.h> using namespace std; const int INF = 2e9 + 10; const int MOD = 1e9 + 7; const int N = 1e6 + 10; int n, m, b; vector<int> st; int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); cin >> n; int cnt = 0; int ans = 0; for (int i = 1; i <= 2 *...
#include <bits/stdc++.h> using namespace std; const int mod = 1e6 + 3; int toint(string s) { int ans = 0; for (char x : s) ans = ans * 10 + (x - 0 ); return ans; } int lcs(string a, string b) { int n = a.size(), m = b.size(); int dp[2][m + 1]; for (int i = 0; i <= n; i++) { for ...
#include <bits/stdc++.h> using namespace std; unsigned long long get_idx(int p) { int idx = 1; while (idx < p) idx *= 2; return idx; } void update(vector<unsigned long long> &tree, unsigned long long idx, unsigned long long val) { tree[idx] = val; idx /= 2; while (idx) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, j, k = 0, x = 0, y = 0, i, c = 0; cin >> m; int a[500001] = {0}; int ans[1000][1000] = {0}; while (m--) { cin >> n >> x >> y; if (n == 1) { a[x] += y; for (i = 1; i < 1000; i++) ans[i][x % i] += y; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAX_N = 1e5 + 9; int ans[MAX_N]; void sieve(int n) { int nw = 1; for (int i = 2; i <= n; i++) ans[i] = INT_MAX; for (ll i = 2; i <= n; i++) { if (ans[i] != INT_MAX) continue; for (ll j = i; j <= n; j += i) an...
#include <bits/stdc++.h> using namespace std; int m[1000][1000]; int main() { m[0][0] = 1; m[0][1] = 2; m[1][0] = 2; m[1][1] = 3; m[2][0] = 3; m[2][1] = 1; int n; scanf( %d , &n); int g = 4; int d = 2; int cur = 0; while (g <= n) { m[cur][d] = g; ++g; ...
#include <bits/stdc++.h> using namespace std; map<string, string> mp; int main() { string a, b; int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a >> b; mp[b] = a; } for (int i = 0; i < m; i++) { cin >> a >> b; b.pop_back(); cout << a << << b ...
#include <bits/stdc++.h> using namespace std; stack<int> s[100005]; int n, m, k, from, to, d[100005], f[100005], t[100005], c[100005], before[100005], cnt = 0; bool vis[100005] = {false}; void swap(int &a, int &b) { int t = a; a = b; b = t; } void qsort(int l, int r) { int i = l, j =...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2002; int n, k; long long a[MAXN]; int dp[MAXN]; int abs1(int a) { return a >= 0 ? a : -a; } int min1(int a, int b) { return a > b ? b : a; } bool find(long long mid) { for (int i = 1; i <= n + 1; i++) dp[i] = i - 1; dp[1] = 0; f...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tc; cin >> tc; int z; for (int t = 1; t <= tc; t++) { cin >> z; int a, s, d = 0; s = 0; a = 0; int x; for (int q = 1; q <= z...
#include <bits/stdc++.h> using namespace std; int N[5]; int K; int getChoice(int choice) { if (N[choice]) return choice; for (int i = 1; true; i++) { if (choice + i < 5 && N[choice + i]) return choice + i; if (choice - i >= 0 && N[choice - i]) return choice - i; } } int main() { ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, s1, s2, s3, s4; cin >> a >> b >> c; s1 = a + c + b; s2 = a + a + b + b; s3 = a + c + c + a; s4 = b + c + c + b; cout << min(s1, (min(s2, min(s3, s4)))); }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; vector<long long> v(n); for (int i = 0; i < n; i++) { string s; cin >> s; long long a =...