func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double PI = acos(-1.0); int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); const int N = 1e2 + 10; int n, m; int v[N][2 * N]; cin >> n >> m; for (int i = 0; i < n; i++) { fo...
#include <bits/stdc++.h> using namespace std; int dp[105][105][2], a[105]; int n; void printdp() { int cnt = 0; for (int i = 0; i < n + 1; i++) { for (int j = 0; j < n + 1; j++) { for (int k = 0; k < 2; k++) { cnt++; cout << index << i << << j << << k << ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, s; cin >> n >> s; long long int min = INT_MAX; unsigned long long int sum = 0; long long int i; long long int arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; if (arr[i] < min) mi...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100030; const long long MODD = 1000000009; void do_case() { int a, b, c, d, x, y; cin >> x >> y >> a >> b >> c >> d; if (x > y) swap(x, y); pair<int, int> T[4] = {{a + c, max(b, d)}, {a + d, max(b, c)}, ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 500; int a[maxn]; int main(void) { int n, m; cin >> n >> m; int ans = 0; for (int i = 1; i <= m; i++) { int num; scanf( %d , &num); int x, temp; int flag = 0; scanf( %d , &x); temp = x; ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; ch < 0 || ch > 9 ; ch = getchar()) if (ch == - ) f = -1; for (; ch >= 0 && ch <= 9 ; ch = getchar()) x = x * 10 + ch - 0 ; return x * f; } int n, m; int dp[45][1 <<...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); } bool des(int i, int j) { return i > j; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; if (n == 5) cout << 1; else cout <...
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T; cin >> T; while(T--){ int X[210] = {}; int N, M; cin >> N >> M; for(int i = 0; i < N; i++){ for(int j = 0; j < M; j++){ int a; cin >> a; X[i+j] ^= a; ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void chkmax(T &x, T y) { if (x < y) x = y; } template <class T> inline void chkmin(T &x, T y) { if (x > y) x = y; } int t, n, m, k, cnt[26]; bool vis[200020]; char s[200020]; int solve() { int ans = 1000000007; ...
#include <bits/stdc++.h> using namespace std; pair<pair<int, int>, int> a[100010]; vector<pair<long long, int> > pre[100010]; long long maxx = 0; int maxi, maxj; int c = 0; long long s = 0; long long val1, val2; void eval(int i, int j, int k, bool f) { val2 = pre[j][k].first; if (val1 + val2 >...
#include <bits/stdc++.h> using namespace std; long long dp[100001]; bool seen[100001]; int n, q; vector<int> v, c; long long cal() { long long a, b; cin >> a >> b; for (int i = 0; i < 100001; i++) seen[i] = false; int c1, c2; c1 = c2 = -1; for (int i = 0; i < n; i++) { long lon...
#include <bits/stdc++.h> using namespace std; typedef const int &ci; inline int read() { int x = 0; char c = getchar(); while (c < 0 || c > 9 ) c = getchar(); while ( 0 <= c && c <= 9 ) x = 10 * x + c - 0 , c = getchar(); return x; } inline void Max(int &x, ci y) { if (x < y) x =...
#include <bits/stdc++.h> using namespace std; int n; long long sum; struct myS { int index; long long v; myS(){}; myS(int index, long long v) : index(index), v(v){}; bool operator<(const myS& right) const { return v < right.v; } } a[200001]; bool dd[1000001]; vector<int> res; int mai...
#include <bits/stdc++.h> using namespace std; template <class T1> void deb(T1 e1) { cout << e1 << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << << e2 << endl; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3) { cout << e1 << << e...
#include <bits/stdc++.h> using namespace std; long long len[1000006]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, q, t, x, s, m, p, d, l; cin >> n >> m >> l; for (int i = 0; i < n; i++) { cin >> len[i]; } long long co = 0; long long pre; if ...
#include <bits/stdc++.h> using namespace std; const int www = 9; const int Size = 10000; char buffer[Size]; int dr[] = {-1, 0, 1, 0}; int dc[] = {0, 1, 0, -1}; const int inf = 0x0fffffff; const int size = 52; long long dp[size][10]; int ar[size]; struct Point { int x, y, z; Point(int x = 0...
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf( %d , &x); } void _R(long long &x) { scanf( %lld , &x); } void _R(double &x) { scanf( %lf , &x); } void _R(char &x) { scanf( %c , &x); } void _R(char *x) { scanf( %s , x); } void...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e6 + 1e3, mod = 1e9 + 7, inf = 1e9; long long n, m, x1, d, z, t, sum, x, y, maxi, mini, a[MAXN], dp[4][MAXN], b[MAXN], ans; string s[MAXN]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n == k) { cout << -1; return 0; } int q = n - k; int a[n]; for (int i = 0; i < n; i++) a[i] = i + 1; if (!(q % 2)) { swap(a[0], a[n - 1]); q--; } for (int i = 1; i ...
#include <bits/stdc++.h> using namespace std; int n, m; struct AA { int p, s; } c[110]; int st[110]; bool cmp1(AA a, AA b) { if (a.p == b.p) return a.s < b.s; return a.p < b.p; } bool vis[110]; int work1() { int ret = 0; sort(c, c + n, cmp1); sort(st, st + m); for (int i = ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n, k; cin >> n >> k; long long n1 = n - (k - 1); if (n1 > 0 && n1 % 2 == 1) { cout << YES n ; for (l...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int main() { int n, K; cin >> n >> K; if (K == 1 || n <= 3) { puts( -1 ); } else if (K >= n) { puts( -1 ); } else if (n == 4) { if (K == 3) { puts( 3 n1 2 n2 3 n3 4 ); } else { puts( -1...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int N; char s[105]; int dp[105][2605]; void pre() { dp[0][0] = 1; for (int i = 1; i <= 100; i++) for (int j = 0; j <= 25 * i; j++) for (int c = 0; c < 26; c++) if (j - c >= 0) (dp[i][j] += dp[i - 1][j - c]...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:200000000 ) using namespace std; long long step(long long a, long long n) { if (n == 0) return 1; else if (n % 2 == 0) return step(a * a, n / 2); else return a * step(a, n - 1); } int main() { ios_base::sync_with_stdio(...
#include <bits/stdc++.h> using namespace std; int n; int a[200005]; int mv; int main() { scanf( %d , &n); mv = n / 2; if (n % 2 == 0) mv--; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } sort(a + 1, a + n + 1); int ret = 2000000000; for (int i = 0; i <= mv; i++) { ...
#include <bits/stdc++.h> using namespace std; int n, m, b, mod; int a[505]; int dp[505][505]; int main() { scanf( %d%d%d%d , &n, &m, &b, &mod); for (int i = 1; i <= n; ++i) scanf( %d , a + i); dp[0][0] = 1; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { for (int k ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100050, maxm = 5050; int n, m, K, p, h[maxn], a[maxn]; long long hh[maxn], ans; long long tim[maxn]; int cnt[maxm]; bool judg(long long x) { int i, j; long long tis = 0; for (i = 0; i < m; i++) cnt[i] = 0; for (i = 0; i < n; i+...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int n, num[100], cnt[N]; long long a[N]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { long long temp = a[i]; while (temp && temp % 2 == 0) { cnt[i]++; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000000 + 2; const long long MOD = 1e9 + 7; int N, p[MAXN]; long long s[MAXN], c[MAXN], f[MAXN], Ans; long long gcd(long long a, long long b) { if (a < b) swap(a, b); return b ? gcd(b, a % b) : a; } int main() { cin >> N; for...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.push_back(x); } sort(a.begin(), a.end()); int l = 0; int r = n - 1; for (int i = 0; i < n; i++) { if (i % 2) { ...
#include <bits/stdc++.h> using namespace std; int cnt[125]; char sa[5005]; int main() { bool ok, whh; int lens, lent; string s, t, my; cin >> s >> t; memset(cnt, 0, sizeof cnt); lens = s.length(); for (int i = 0; i < lens; i++) cnt[s[i]]++; ok = true; whh = false; my = s;...
#include <bits/stdc++.h> using namespace std; long long qpow(long long a, long long n) { long long res = 1; while (n) { if (n % 2) { res = (res * a) % 100000007; n--; } else { n = n / 2; a = (a * a) % 100000007; } } return res; } void solve() { ...
#include <bits/stdc++.h> using namespace std; string A[15]; long long nr[100]; int N, K; long long mn = 1000000000; int main() { scanf( %d %d n , &N, &K); for (int i = 1; i <= N; i++) cin >> A[i]; vector<int> v; for (int i = 1; i <= K; i++) v.push_back(i); do { for (int i = 1; i <=...
#include <bits/stdc++.h> using namespace std; int main() { int n, f = 0, s = 0; char pass[3], x[2]; cin >> pass[0] >> pass[1]; cin >> n; for (int i = 0; i < n; i++) { cin >> x[0] >> x[1]; if (x[0] == pass[0] && x[1] == pass[1]) { cout << YES ; return 0; } ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long a, b, x, y, n; cin >> a >> b >> x >> y >> n; long long p = a - x, q = b - y; long long pp = min(p, n), qq = min(q, n); long long aa = a - pp, bb = b - qq; long long tt ...
#include <bits/stdc++.h> using namespace std; const int N = 110; int n; char s[N][30]; char ss[30]; int p; int len[N]; int in[30]; int nxt[30]; int bf[30][30], ind[30]; void go(int i) { ss[p++] = char(i + a ); if (nxt[i] >= 0) go(nxt[i]); } int main() { scanf( %d , &n); memset...
#include <bits/stdc++.h> using namespace std; string st[30] = { zero , one , two , three , four , five , six , seven , eight , nine , ten , eleven , twelve , thirteen , fourteen , fifteen , sixteen , seve...
#include <bits/stdc++.h> using namespace std; long long int dpmax[200005][20]; long long int dpmin[200005][20]; long long int a[200005], b[200005]; int n; void ST() { for (int i = 1; i <= n; i++) { dpmax[i][0] = a[i]; dpmin[i][0] = b[i]; } for (int j = 1; (1 << j) <= n; j++) { ...
#include <bits/stdc++.h> const int maxn = 1e6 + 20; const int maxm = 1e5 + 10; const long long int mod = 998244353; const long long int INF = 1e18 + 100; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-8; using namespace std; int a[50][50]; int num[200], c[200]; int...
#include <bits/stdc++.h> using namespace std; long long a, b, x, y, t; int main() { cin >> t; while (t--) { cin >> a >> b >> x >> y; if (a > b) swap(a, b); cout << abs(a - b) * x + min(y, x * 2) * a << endl; } }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 5; const int MOD = 998244353; int main() { int n; while (cin >> n) { int p; long long x = 0, y = 0; for (int i = 1; i <= n; i++) { cin >> p; x += p / 2; y += p / 2; if (p % 2) { ...
#include <bits/stdc++.h> using namespace std; int main(void) { int i; char n[100010], m; stack<char> s; scanf( %s , n); for (i = 0; n[i] != 0; i++) { if (s.empty()) { s.push(n[i]); } else { m = s.top(); if (m == n[i]) s.pop(); else ...
#include <bits/stdc++.h> int NEXT_FREE_ID = 0; std::unordered_map<std::string, int> stringId; namespace persistentid { int NEXT_FREE_INDEX = 1; int s[10000000], L[10000000], R[10000000]; int root[100005]; int n = 1 << 30; int upd(int p, int v, int id, int l = 0, int r = n) { int ID = NEXT_FREE_INDEX...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<pair<int, pair<int, int> > > E(m); { int cnt = 0; for (int i = 0; i < m; i++) { cin >> E[i].first >> E[i].second.first; E[i].second.second = i; if (E[i].second.first == 1) c...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; const int M = 1e9 + 100; long long a[N]; int main() { int n, m; long long x, y; while (~scanf( %d %d , &n, &m)) { x = -M; y = M; for (int i = 0; i < n; i++) { scanf( %lld , &a[i]); x = max(a[i]...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int t; cin >> t; while (t--) { int n, m, k; cin >> n >> m >> k; vector<int> deg(n); vector<vector<int>> adj(n); for (int i = 0, u, v; i < m; ++i) { cin >> u >> v...
#include <bits/stdc++.h> using namespace std; int mas[1001][1001]; char chars[1000][1001]; int n, m; int st = 0; vector<int> woi; int p = 0; void dfs(int x, int y) { st++; mas[x][y] = p; if (x != 0) { if (mas[x - 1][y] == 0 && chars[x - 1][y] == . ) { dfs(x - 1, y); } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, A[100000], count0 = 0, max = 0; scanf( %i , &n); for (int i = 0; i < n; i++) { scanf( %i , A + i); if (A[i] < 0) A[i] = -A[i] - 1; if (!A[i]) count0++; if (A[i] > max) max = A[i]; } if (count0 == n) { ...
#include <bits/stdc++.h> const int S = 1 << 21; char ibuf[S], *iS, *iT, obuf[S], *oS = obuf, *oT = oS + S - 1; struct Flusher_ { ~Flusher_() { (fwrite(obuf, 1, oS - obuf, stdout), oS = obuf, void()); } } flusher_; template <class T> inline void read(T &x) { x = 0; register char c = (iS == iT ? (...
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) #pragma GCC optimize( unroll-loops ) using namespace std; const long double eps = 1e-7; const int inf = 1000000010; const long long INF = 10000000000000010LL; const int mod = 1000000007; const int MAXN = 100010, LOG = 20; int n, m, k, u, v, x, y, t, ...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { register T c = getchar(); x = 0; int t = 0; if (c == - ) t = 1, c = getchar(); for (; (c < 48 || c > 57); c = getchar()) ; for (; c > 47 && c < 58; c = getchar()) { x = (x << 1) + (x << 3) + ...
#include <bits/stdc++.h> const int INF = 1e9; using namespace std; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; bool vis[1005][1005], cvis[50]; vector<pair<int, int> > cc[50]; int m, n, k, a[1005][1005], D[45][1005][1005]; void DFS(int c) { memset(vis, 0, sizeof(vis)); memset(cvis, 0, siz...
#include <bits/stdc++.h> char in[4][4]; int oc = 0, xc = 0; int whowin() { int i, j; int ret = 0; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { if (in[i][j] != in[i][0]) break; } if (j == 3 && in[i][0] != . ) { if (in[i][0] == 0 ) ret |= 2; e...
#include <bits/stdc++.h> using namespace std; const long double EPS = (long double)1e-7; const long double PI = acos(0) * 2; bool isZero(const long double& x) { return abs(x) <= EPS; } int sign(const long double& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); } long long gcd(long long a, long long b) { f...
#include <bits/stdc++.h> const int INT_INF = 0x3f3f3f3f; const int INT_M_INF = 0x7f7f7f7f; const long long LL_INF = 0x3f3f3f3f3f3f3f3f; const long long LL_M_INF = 0x7f7f7f7f7f7f7f7f; const double pi = acos(-1.0); using namespace std; inline void debug(char ch) { for (int __ii = 0; __ii < 20; ++__ii) p...
#include <bits/stdc++.h> using namespace std; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, -1, 1}; int tt[1016][1016]; int hh[1016][1016]; int n, m; int ex, ey; queue<int> q; queue<int> p; void bfs() { while (!p.empty()) { int x = p.front(); int y = q.front(); p.pop(); q.p...
#include <bits/stdc++.h> using namespace std; struct Node { map<int, Node *> go; int l, r; Node *p, *link; Node(int _l, int _r, Node *_p) : l(_l), r(_r), p(_p), link(0) {} }; const int MAXN = 100 * 1000 + 5, S = 1000; string s[MAXN]; int c[MAXN], rr[MAXN], nn, curSuf; long long ans = 0; ...
#include <bits/stdc++.h> using namespace std; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i); } template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); } template <class T> int cntbit(T s...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); bool flag = true; for (int i = 0; i < n; i++) { if (i == 0) { int l = a[1]; int r = a[2]; if (a[i] >= l + r) flag =...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int c1 = 0, c2 = 0, c3 = 0; for (int i = 0; i < n; i++) { int x, y, z; cin >> x >> y >> z; c1 += x, c2 += y, c3 += z; } if (c1 == 0 && c2 == 0 && c3 == 0) cout << YES ; else cout <<...
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int Maxn = 1000005; const int mod = 1000000007; int fac[Maxn], inv[Maxn]; int n; int res; int toPower(int a, int p) { int res = 1; while (p) { if (p & 1) res = ll(res) * a % mod; p >>= 1; a = ll(a) * a ...
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 5; vector<long long> f; vector<long long> s; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long a, b; cin >> a >> b; while (a > 0) { long long rem = a % 10; a /= 10; f.p...
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& os, vector<T> V) { for (auto v : V) os << v << ; return cout << ; } template <class T> ostream& operator<<(ostream& os, set<T> S) { for (auto s : S) os << s << ; return cout << ; } tem...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( no-stack-protector ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( unroll-loops ) using namespace std; void seriy() { cin.tie(0); cout.tie(0); } signed main() { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int a = 0, b = 0; int n, d, t; cin >> n >> d; int sol = 0; for (int i = 0; i < n; ++i) { cin >> t; if (t == 0) { if (b + t < 0) { a = 0; b =...
#include <bits/stdc++.h> using namespace std; long long t, m, n, a, u, v; void printAnswer(vector<int> ans) { sort(ans.begin(), ans.end()); cout << ans.size() << endl; for (int i = 0; i < ans.size(); i++) { cout << ans[i] << ; } cout << endl; } int main() { cin >> t; for (...
#include <bits/stdc++.h> using namespace std; int len, a, b, c; string s; int main() { cin >> s; len = s.length(); for (int i = 0; i < len; i++) { if (s[i] == a ) a++, c++; else b++; a = max(a, b); b = max(b, c); } cout << a; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 11; const int Inf = 1e9; vector<int> dx[3] = { {-1, 0, 0, 1}, {-1, -1, 1, 1}, {-1, 1, 2, 2, 1, -1, -2, -2}}; vector<int> dy[3] = { {0, -1, 1, 0}, {-1, 1, -1, 1}, {-2, -2, -1, 1, 2, 2, -1, 1}}; int n; pair<int, int> g[3][3][N][N][N][N]...
#include <bits/stdc++.h> using namespace std; const long long int INF = LONG_LONG_MAX; const long long int NINF = LONG_LONG_MIN; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); long long int n, l, k; cin >> n >> l >> k; string s; cin >> s; sort((s).begin(), (s).end()); ...
#include <bits/stdc++.h> using namespace std; vector<long long> dan, ans; vector<pair<long long, long long> > check; long long calc(long long st) { multiset<long long> otr; long long otv = 0; for (long long i = 0; i < dan.size(); i++) { st += dan[i]; if (dan[i] < 0) otr.insert(dan[i]); ...
#include <bits/stdc++.h> using namespace std; const int maxn = 500; int d[maxn * maxn]; map<int, int> id; int idcnt; map<pair<int, int>, int> id2; int id2cnt; pair<int, int> status[maxn * maxn]; int ans[maxn * maxn]; int first[maxn * maxn], nxt[1750000], des[1750000], tot; int W[6]; int T, f; ...
#include <bits/stdc++.h> using namespace std; string s; int n, cnt[60], have, r = 1; int main() { ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); cin >> s; n = s.size(); s = + s; for (int i = (1); i <= (n); ++i) { while (r <= n && have < 26) { if (s[r] == ? ) ...
#include <bits/stdc++.h> using namespace std; vector<int> months = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const int MAX = 1e5 + 55; const int inf = 1e9 + 77; const int MOD = 1e9 + 7; const double PI = acos(-1.0); const double eps = 1e-7; int main() { int n, k; scanf( %d , &n); ...
#include <bits/stdc++.h> using namespace std; long long spf[1000005]; vector<long long> primes, prev[1000005], next[1000005]; void sieve() { for (long long i = 2; i < 1000005; ++i) { if (spf[i] == 0) { spf[i] = i; for (long long j = 2 * i; j <= 1000005; j += i) { if (spf[j] =...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; vector<long long int> graph[100007]; long long int vis[100007]; long long int mxm; void dfs(long long int u, long long int p, long long int d) { vis[u] = 1; mxm = max(mxm, d); for (long long int v : graph[u]) { df...
#include <bits/stdc++.h> using namespace std; const int NMAX = 31400; struct point { int x, y; }; int n; pair<point, point> p[5]; bool used[5]; bool func() { long long s = 0; point MIN, MAX; MIN.x = MIN.y = NMAX; MAX.x = MAX.y = 0; for (int i = 0; i < n; i++) { s += (p[i].s...
#include <bits/stdc++.h> using namespace std; unsigned long long int power(unsigned long long int n, unsigned long long int m) { if (n == 0LL) return 1LL % m; else if (n & 1LL) return ((power(n / 2, m) % m) * (power(n / 2, m) % m) * (3LL % m)) % m; else r...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const long long mod = 1000000007; int A[N], rmq[N][25], getL[N]; void go(int n) { for (int i = 0; i < n; i++) rmq[i][0] = i; for (int i = 1; i < N; i++) getL[i] = log2(i); for (int j = 1; (1 << j) <= n; j++) { for (int i =...
#include <bits/stdc++.h> using namespace std; const int N = 1005; struct edge { int to, next; } e[N * 2]; int head[N], tot, n; int sz[N], mxv, mxrt; void add(int x, int y) { e[++tot] = (edge){y, head[x]}; head[x] = tot; } void dfs(int x, int fa, int n) { int mx = 0; sz[x] = 1; ...
#include <bits/stdc++.h> using namespace std; struct Node { vector<int> children; int value, bit; Node(int b) { children.assign(2, -1); value = 0; bit = b; } }; vector<Node> tree; void add(int id, int amt, int n) { tree[n].value += amt; if (tree[n].bit == 0) return; ...
#include <bits/stdc++.h> using namespace std; double PI = 3.14159; int dX[] = {1, -1, 0, 0}; int dY[] = {0, 0, 1, -1}; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); double h, m, angle_h = 0, angle_m = 0; char c; cin >> h >> c >> m; h = fmod(h, 12); angle_h = (h...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, pos, cnt = 0; cin >> n >> a >> b; for (int pos = 1; pos <= n; pos++) { if (n - pos <= b && pos - 1 >= a) cnt++; } cout << cnt; return 0; }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, q; cin >> n >> q; while (q--) { long long a, b; cin >> a >> b; if ((a + b) % 2 == 0) { long long ans = 0; ans += (a) / 2 * ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, c, ans = 0; string s; cin >> s; bool sol = 1; for (int i = 0; i < s.length(); i++) { if (s[i] == 1 && s[i + 1] == 4 && s[i + 2] == 4 ) { i += 2; continue; } if (s[i] == 1 || (s[i] == ...
#include <bits/stdc++.h> using namespace std; const int max_n = 100; int a[max_n], tmp[max_n]; bool vis[max_n]; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } int main() { int n; cin >> n; for (int i = 0; i < (n); i++) { cin >> a[i]; a[i]--; tmp[i] = ...
#include <bits/stdc++.h> using namespace std; int n; long long p; long long a[1000005]; long long fastpow(long long a, int x) { if (x < 0) return 1; if (x == 0) return 1; if (x == 1) return a; long long tmp = fastpow(a, x >> 1); tmp = (tmp * tmp) % 1000000007ll; if (x & 1) { tmp ...
#include <bits/stdc++.h> using namespace std; template <class T> bool remin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <class T> bool remax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } int nxt(...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int mod = 1000000007; const long long linf = 0x3f3f3f3f3f3f3f3f; char c[200100]; int qnt[200100][26]; int main() { int t; scanf( %d , &t); while (t--) { int n, k; scanf( %d%d , &n, &k); scanf( %s...
#include <bits/stdc++.h> using namespace std; int main() { bool x = false; string s; cin >> s; string b; for (int i = 0; i < s.size(); i++) { if (s[i] == d && s[i + 1] == o && s[i + 2] == t && i != 0 && i + 2 < s.size() - 1) { b += . ; s[i + 1] = ; ...
#include <bits/stdc++.h> long long dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; long long dy[8] = {1, 0, -1, 0, -1, 1, 1, -1}; using namespace std; class pa3 { public: long long x; long long y, z; pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {} bool operator<(const pa3 &p...
#include <bits/stdc++.h> using namespace std; const int mx = 1e3 + 100, M = 1e9 + 7; long long int n, m, d[mx][mx]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; d[0][0] = 1; for (int i = 1; i < mx; i++) { d[i][0] = 1; for (int j = 1; j < i + 1...
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> int upmin(T1 &x, T2 v) { if (x <= v) { return 0; } x = v; return 1; } template <class T1, class T2> int upmax(T1 &x, T2 v) { if (x >= v) { return 0; } x = v; return 1; } const int INF ...
#include <bits/stdc++.h> int abs(int x) { return x > 0 ? x : -x; } int max(int x, int y) { return x > y ? x : y; } int min(int x, int y) { return x < y ? x : y; } long long read() { long long ans = 0; char ch = getchar(), t = ch; while (ch < 0 || ch > 9 ) { t = ch; ch = getchar(); ...
#include <bits/stdc++.h> using namespace std; map<long long, long long> C; long long B[1100000], pre[1100000], suf[1100000], A[1100000], tot, i, n, c[1100000], ans; void add(long long x) { for (; x <= n; x += (x & (-x))) c[x]++; } long long getsum(long long x) { long long sum = 0; for (; x...
#include <bits/stdc++.h> using namespace std; char st[100000]; int n, t, a[26], minn, maxx; int main() { scanf( %d%d , &n, &t); scanf( %s , st); minn = 25; maxx = 0; for (int i = 0; i < n; i++) { if (st[i] - 97 < minn) minn = st[i] - 97; if (st[i] - 97 > maxx) maxx = st[i] - 97; ...
#include <bits/stdc++.h> using namespace std; const int NMAX = 100; void breakGame(int a, int b) { int n, j, k, dk; if (a > b) swap(a, b); dk = 2 * a; k = a + 1; n = b - a; if (n & 1) k *= 2; cout << k << n ; if (n % 2 == 0) { for (j = 0; j <= dk; j += 2) cout << n / 2 + j ...
#include <bits/stdc++.h> using namespace std; const int M = 100000 + 5; map<long long int, int> mp; queue<int> Q; int vis[M]; long long int dk[M]; vector<long long int> step; long long int a[M]; int rch[M]; struct TREE { int lc; int rc; long long int l; long long int r; long long...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 113; const long long maxn = 5000 + 113; bool used[maxn]; int main() { srand(time(NULL)); ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<pair<pair<int, int>, int>> we; for (int i = 0;...
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; void add(int &a, int b) { a += b; if (a >= M) a -= M; } int mypow(int x, int t) { int ans = 1, res = x; while (t) { if (t & 1) ans = (long long)ans * res % M; res = (long long)res * res % M, t >>= 1; } ret...
#include <bits/stdc++.h> using namespace std; const int N = 251, N2 = N * N, M = 1e9 + 7; long long kc[N2], k1c[N2], ans, n, k, n2, C[N][N]; int main() { cin >> n >> k; kc[0] = k1c[0] = 1; for (int i = 1; i < N2; i++) { kc[i] = kc[i - 1] * k % M; k1c[i] = k1c[i - 1] * (k - 1) % M; } ...