func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed; cout << setprecision(12); long long n1, n2; cin >> n1 >> n2; long long a[n1], b[n2], cnt1[10] = {0}, cnt2[10] = {0}; for (long long i = 0; i < n1; i++) { cin >> a[i]; ...
#include <bits/stdc++.h> using namespace std; long long N; long long x, y, x2, y2; pair<int, int> v[100010]; bool Can(long long n) { long long Rem = n % N; long long Count = n / N; long long X = v[Rem].first + (v[N].first * Count); long long Y = v[Rem].second + (v[N].second * Count); retur...
#include <bits/stdc++.h> using namespace std; const int MAXN = 500; bool vis[3][MAXN]; char g[3][MAXN]; pair<int, int> que[MAXN * 3]; int n, k; inline void init() { memset(g, 0, sizeof(g)); memset(vis, false, sizeof(vis)); scanf( %d%d , &n, &k); for (int i = 0; i < 3; i++) scanf( %s , g[i]...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t = 1; while (t--) { long long int i, j, k = 0, n, m; cin >> n >> m; vector<long long int> a(n); for (i = 0; i < n; i++) { long long int x, y; ...
#include <bits/stdc++.h> using namespace std; long long f(long long x) { long long res; res = x * x; return res; } void solve() { long long a[3]; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); long long d; d = (long long)(sqrt(f(a[2]) + f(a[1] - a[0]))); d = d + 1; cout << ...
#include <bits/stdc++.h> using namespace std; #define Int long long const int mxN = 2e5 + 5; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; cin >> t; while(t--){ Int n; cin >> n; while(n % 11 != 0 && n > 10)n -= 111; ...
#include <bits/stdc++.h> using namespace std; long long exp(long long a, long long b, long long p) { if (b == 0) return 1; if (b % 2) return a * exp(a, b - 1, p) % p; return exp(a * a % p, b / 2, p); } long long inv[1000009], E[1000009]; int main() { long long a, b, p, x; cin >> a >> b >> ...
#include <bits/stdc++.h> using namespace std; const int inf = 1000000; int f[35][35][55]; int gao(int x, int y, int z) { if (f[x][y][z] > 0) return f[x][y][z]; if (z == 0) return f[x][y][z] = 0; if (x * y < z) return f[x][y][z] = inf; if (x * y == z) return f[x][y][z] = 0; int now = inf; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; int m; cin >> n >> m; bool ans[m + 1]; for (int i = 0; i <= m; i++) { ans[i] = false; } int a[n]; vector<pair<int, int> > v; for (int i = 0; i < n; i++) { int a; int b; cin >> a; cin >...
#include <bits/stdc++.h> using namespace std; const double pi = 3.1415926535897932384626433832795028841971; long long fb[100100], fa[100100]; long long k[100100], a[100100], b[100100]; int main() { ios::sync_with_stdio(0); cin.tie(); cout.tie(); long long n, s, sum = 0, ans = 0, ka = 0, kb = 0...
#include <bits/stdc++.h> using namespace std; char buf[2000]; int dx[4] = {0, 0, -1, 1}; int dy[4] = {-1, 1, 0, 0}; int n, m; pair<int, int> tbl1[1 << 23]; pair<int, int> tbl2[1 << 23]; const int Prime1 = 262139, Prime2 = 40999999; const int Prime3 = 100003, Prime4 = 40999799; const pair<int, int> Z...
#include <bits/stdc++.h> using namespace std; int main() { long long int a; cin >> a; while (1) { long long int t = a; long long int su = 0; while (t > 0) { su += t % 10; t /= 10; } if (su % 4 == 0) { cout << a; return 0; } a++; ...
#include <bits/stdc++.h> using namespace std; struct MinTreeNode { int min; int count; }; int n; MinTreeNode tmin[200000]; int tgcd[200000]; int gcd(int a, int b) { if (a == 0) { return b; } if (b == 0) { return a; } if (a == 1 || b == 1) { return 1; } ...
#include <bits/stdc++.h> using namespace std; vector<long long int> v; vector<long long int> v1; vector<long long int> v2; const long long int inf = 100000000000005; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; for (int i = 1; i < n; ...
#include <bits/stdc++.h> using namespace std; int p[] = {0, 5, 7, 5}; int main() { for (int k = 1; k <= 3; k++) { string s; getline(cin, s); int tot = 0; for (int i = 0; i < s.size(); i++) if (s[i] == a || s[i] == e || s[i] == i || s[i] == o || s[i] == u ) ...
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; int nxt[4][100001] = {0}; bool ok[4]; void getnext(int m, char s2[], int t) { int j = 0; for (int i = 2; i <= m; i++) { while (j != 0 && s2[j + 1] != s2[i]) j = nxt[t][j]; if (s2[j + 1] == s2[i]) j++; nxt[t][i]...
#include <bits/stdc++.h> using namespace std; void file(string s) { freopen((s + .in ).c_str(), r , stdin); freopen((s + .out ).c_str(), w , stdout); } template <typename Tp> void read(Tp &x) { long long fh = 1; char c = getchar(); x = 0; while (c > 9 || c < 0 ) { if (c ==...
#include <bits/stdc++.h> using namespace std; int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}; vector<int> next(vector<int>& a, int p, int k) { vector<int> result; for (long long mul = 1; mul <= (long long)k; mul *= p) { for (int i = 0; i < a.size(); ++i) { long long newN = (long long...
#include <bits/stdc++.h> int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } using namespace ::std; const int maxn = 5300; const int inf = 1e9 + 800; const int mod = 1e9 + 7; bool ro[maxn][maxn]; bool cu[maxn][maxn]; bool mosro[maxn]; bool moscu[maxn]; int main() { ios_base::sync_with_s...
#include <bits/stdc++.h> using namespace std; int n, m; int p[100010]; const int md = 1000000009; int an = 1; int sz[100010]; void make_set(int v) { p[v] = v; sz[v] = 1; } int find_set(int v) { if (p[v] == v) return v; return p[v] = find_set(p[v]); } void union_sets(int a, int b) {...
#include <bits/stdc++.h> using namespace std; int dp[100][100]; struct point { public: long long x, y; point(long long a, long long b) { x = a; y = b; } point() {} void setPoint(long long a, long long b) { x = a; y = b; } double dist(point p) { return sqrt(po...
#include <bits/stdc++.h> using namespace std; string s; int n; int main() { cin >> n; cin >> s; for (int i = 0; i < n; i++) { if (i + 2 < n && s[i] == o && s[i + 1] == g && s[i + 2] == o ) { while (i + 2 < n && s[i + 1] == g && s[i + 2] == o ) i += 2; cout << *** ; ...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); int n; cin >> n; vector<string> arr; for (int i = 0; i < n; i++) { string x; cin >> x; arr.push_back(x); } int chocolate = 0; for (int...
#include <bits/stdc++.h> using namespace std; vector<pair<pair<int, int>, int> > a; int main() { int L, b, f, n, m, cmd, x; cin >> L >> b >> f; cin >> n; for (int cs = (1); cs <= (n); ++cs) { sort((a).begin(), (a).end()); cin >> cmd >> x; if (cmd == 1) { if ((a.empty() &&...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 2e6 + 7; char str[maxn]; int ans[10][10], used[10]; int mp[10][10][10][10]; struct NODE { int num, step; }; int bfs(int numa, int numb, int a, int b) { queue<NODE> que; memset(used, 0, sizeof(used));...
#include <bits/stdc++.h> using namespace std; int main() { string st; cin >> st; for (int i = 0; i < st.size(); i++) { if (st[i] == 0 || st[i] == 8 ) { cout << YES n ; cout << st[i] << endl; return 0; } for (int j = i + 1; j < st.size(); j++) { int n...
#include <bits/stdc++.h> using namespace std; map<char, long long> mp; map<pair<char, long long>, long long> cnt; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); for (char c = a ; c <= z ; c++) cin >> mp[c]; string s; cin >> s; long long n = s.length(); long long sum = m...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; map<int, int> mp; long long ans = 0, mx = 1e6; for (int i = 0; i < n; i++) { int first; scanf( %d , &first); int second = 1; long long yy = 1; for (int j = 2; j * j <= first; j++) ...
#include <bits/stdc++.h> int R, C; int ER, EC; int SR, SC; char field[1010][1010]; int dist[1010][1010]; int Q[1010 * 1010], Qb, Qe; int dr[4] = {-1, +1, 0, 0}; int dc[4] = {0, 0, -1, +1}; int main(void) { scanf( %d %d , &R, &C); for (int r = 0; r < R; ++r) { scanf( %s , field[r]); ...
#include <bits/stdc++.h> using namespace std; long long n, M; vector<long long> cards; map<int, vector<int>> m; int sodd = 1, seven = 2; int oddbalance; int nextOdd() { for (int i = sodd;; i += 2) { if (m[i].empty()) { sodd = i + 2; if (i > M) { cout << -1 << endl; ...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize -O3 bool prime(long long int n) { if (n == 1) return false; if (n == 2 || n == 3) return true; long long int k = sqrt(n) + 1; for (long long int i = 2; i < k; i++) { if (n % i == 0) return false; } return true; } ...
#include <bits/stdc++.h> using namespace std; int n, s, inp; int c[10]; int best = -1; int b3, b4, b5; struct bezout { long long d, a, b; }; bezout extgcd(long long x, long long y) { if (y == 0) return (bezout){x, 1, 0}; bezout s = extgcd(y, x % y); return (bezout){s.d, s.b, s.a - x / y ...
#include <bits/stdc++.h> using namespace std; int res; int a[100], ins[100]; int IsLucky(int x) { for (; x; x /= 10) if (x % 10 != 4 && x % 10 != 7) return 0; return 1; } void Dfs(int now, int lim) { res++; if ((long long)now * 10 + 4 <= lim) Dfs(now * 10 + 4, lim); if ((long long)...
#include <bits/stdc++.h> using namespace std; const long long N = 100007; long long n, x[N], y[N]; pair<long long, long long> mid(long long a, long long b) { long long xx = (x[a] + x[b]) / 2; long long yy = (y[a] + y[b]) / 2; return {xx, yy}; } int32_t main() { ios_base::sync_with_stdio(fals...
#include <bits/stdc++.h> using namespace std; int main() { int tt; cin >> tt; while (tt--) { int c, m, x; cin >> c >> m >> x; cout << min(c, min(m, ((c + m + x) / 3))) << endl; } }
#include <bits/stdc++.h> using namespace std; long long n; int main() { int T; scanf( %d , &T); while (T--) { scanf( %I64d , &n); for (long long i = n;; i += i) if (i * (n + 1) % (4 * n) == 0) { printf( %I64d n , i + 1); break; } } return 0; } ...
#include <bits/stdc++.h> using namespace std; const long long N = 550, mod = 998244353, inv2 = 499122177, g = 3; long long mul[N], inv[N]; long long ksm(long long f, long long x) { long long tot = 1; while (x) { if (x & 1ll) tot = tot * f % mod; f = f * f % mod; x >>= 1ll; } re...
#include <bits/stdc++.h> using namespace std; char s[100005]; int cnt[30]; int main() { int k, i; scanf( %s , s); scanf( %d , &k); for (i = 0; s[i]; i++) cnt[s[i] - a ]++; if (k >= i) { puts( 0 n ); return 0; } while (1) { int minx = 1 << 30, mini; for (i = 0...
#include <bits/stdc++.h> using namespace std; int n, p; vector<int> adj[100005]; vector<int> ans; vector<int> vis; int dfs(int s) { if (s >= n) return 0; vis[s] = 1; int flag = 0; for (int i = 0; i < adj[s].size(); i++) { if (!vis[adj[s][i]]) { flag = 1; ans[s] += dfs(a...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; vector<int> ind; int num = 0, add = 0; for (int i = 0; i < n; ++i) { if (a[i] == i) ++num; else if (a[a[i]] == i) add = 2; ...
#include <bits/stdc++.h> using namespace std; template <typename... Args> void read(Args &...args) { ((cin >> args), ...); } template <typename... Args> void show(Args... args) { ((cout << args << ), ...); } void solve() { int n; read(n); vector<int> v(n); for (auto &it : v) c...
#include <bits/stdc++.h> using namespace std; int a[100005]; int cmp(int x, int y) { int x1 = 10 - x % 10; int y1 = 10 - y % 10; return x1 < y1; } int main() { int i, n, m; cin >> n >> m; for (i = 1; i <= n; i++) { scanf( %d , &a[i]); } sort(a + 1, a + 1 + n, cmp); fo...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9 + 10; const int MOD = (int)1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, a, b, c, t; cin >> n >> a >> b >> c >> t; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; if...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const int N = 510000, M = N << 1; int n, hd[N], to[M], nxt[M], noedg = 1, size[N]; long long buc[N], f[N], ans = inf; vector<int> app[N]; template <class T> inline void read(T &x) { x = 0; char ch = getchar(), w = 0; w...
#include <bits/stdc++.h> #pragma optimization_level 3 #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx ) using namespace std; const long long N = 5e5 + 3; const long long mod = 998244353; const long long INF = 0x7f7f...
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)1e9 + 999999; const long long Mod = (long long)1e9 + 7; const long long MaXN = (long long)1e18; const int N = (int)1e6 + 7; const int MaXI = (int)1e9; const int Mass = (int)2e5; int main() { ios_base::sync_with_stdio(0); ...
#include <bits/stdc++.h> using namespace std; ostream &operator<<(ostream &out, vector<long long> &a) { for (auto i : a) out << i << ; return out; } istream &operator>>(istream &in, vector<long long> &a) { for (auto &i : a) in >> i; return in; } int main() { cin.tie(0); cout.tie(0...
#include <bits/stdc++.h> using namespace std; int main() { int n, q; char c; vector<int> a(10); cin >> n; for (int i = 0; i < n; i++) { cin >> c; if (c == L ) { q = 0; while (a[q] == 1) { q++; } a[q] = 1; } else if (c == R ) { ...
#include <bits/stdc++.h> using namespace std; int bits[32]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<long long> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } for (int i = 0; i < m; i++) { int x; cin >> x; ...
#include <bits/stdc++.h> using namespace std; const int Maxn = 1009; pair<int, pair<int, int> > sr[Maxn * Maxn]; int n, m; int check(int k) { bitset<Maxn> row[Maxn]; for (int i = 0; i <= k; i++) { int x = sr[i].second.first, y = sr[i].second.second; row[x].set(y); } for (int i = 0;...
#include <bits/stdc++.h> using namespace std; double dp[128][128]; int x[128], y[128]; int N, K, x_0, y_0; double eps; double dist(double x1, double y1) { return sqrt((x_0 - x1) * (x_0 - x1) + (y_0 - y1) * (y_0 - y1)); } double hit(double R, double D) { return (D <= R) ? 1. : exp(1 - D * D / R /...
#include <bits/stdc++.h> using namespace std; long long inf; const double eps = 1e-8; const double pi = acos(-1.0); template <class T> long long chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; } template <class T> long long chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; } template <clas...
#include <bits/stdc++.h> using namespace std; int n, m; int main() { int i, j; scanf( %d%d , &n, &m); for (i = 1; i <= n / 2; i++) { for (j = 1; j <= m; j++) { printf( %d %d n , i, j); printf( %d %d n , n - i + 1, m + 1 - j); } } if (n % 2 == 1) { for (j = 1; ...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int a, b; cin >> a >> b; if (a % b == 0) { cout << 0 << n ; } else { long long int g = a / b; long long int ans = (b * (g + 1) - a); cou...
#include <iostream> #include <cstdio> #include <cassert> #include <cstring> #include <cmath> #include <functional> #include <algorithm> #include <utility> #include <vector> #include <string> #include <map> #include <set> using namespace std; using ll = long long; using PII = pair<int,int>; ...
#include <bits/stdc++.h> using namespace std; long long n, ans; vector<long long> a; int main() { cin >> n; a.resize(n); long long min_A = 1 << 31 - 1; long long max_A = -1; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] > max_A) { max_A = a[i]; } if (a[i...
#include <bits/stdc++.h> using namespace std; long long sol[200000]; long long solve(int in, vector<int> v[], int visited[], int a[]) { if (sol[in] != -2e16) { return sol[in]; } long long ans = a[in]; visited[in] = 1; for (int i = 0; i < v[in].size(); i++) { if (visited[v[in][i]] =...
#include <bits/stdc++.h> using namespace std; long long G[500][500], d[500][500]; long long x[500], n, m; void floyd(long long k) { for (long long i = 0; i < n; i++) if (i != k) { for (long long j = 0; j < n; j++) if (i != j && j != k) if (G[i][j] > G[i][k] + G[k][j]) { ...
#include <bits/stdc++.h> using namespace std; char inp[200005]; int main() { bool ok; queue<int> zeroes, ones; vector<int> vec[200005]; int n_vec = 0, n_z = 0, n_o = 0, tam; scanf( %s , inp); tam = strlen(inp); if (inp[0] == 1 ) cout << -1 << endl; else { vec[n_vec++]....
#include <bits/stdc++.h> using namespace std; int x1[200010]; int x2[200010]; int yz1[200010]; int yz2[200010]; int n; pair<pair<int, int>, pair<int, int> > pp[200010]; pair<pair<int, int>, pair<int, int> > qq[200010]; bool isValid(int x1, int y1, int x2, int y2) { if (x1 <= x2 && y1 <= y2) { ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7, siz = 1e6 + 5; long long t, n, m, k, a[siz], inp[siz], cnt, co[siz], less_right[siz], less_left[siz], tree[siz][2]; pair<long long, long long> p[siz]; long long get(long long ind, long long id) { long long ret = 0; for ...
#include <bits/stdc++.h> using namespace std; int n, k; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; if (n < 2 * k + 1) { cout << -1 << endl; return 0; } cout << n * k << endl; for (int i = 0; i < n; i++) for (int j = 1; j <= k...
#include <bits/stdc++.h> using namespace std; const int N = 310; int r[N]; char g[N][N]; int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; int main() { int n, m, k; scanf( %d %d %d , &n, &m, &k); for (int i = 0; i < n; i++) scanf( %s , g[i]); int cnt = 0; for (int x = 1; x < 150; x++) ...
#include <bits/stdc++.h> using namespace std; const int maxn = INT_MAX; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; if (n > m) { swap(n, m); } if (n == 1) { if (m % 6 == 0) { cout << n * m; } else if (...
#include <bits/stdc++.h> using namespace std; int vp, vd, time_s, time_b, dist; int main() { scanf( %d%d%d%d%d , &vp, &vd, &time_s, &time_b, &dist); if (vd <= vp) { puts( 0 ); return 0; } int ans = 0; double now = 1.0 * vp * time_s; while (now < dist) { double Overtake = ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 106; int g[MAX_N][MAX_N]; int h[MAX_N][MAX_N]; bool not_empty_row[MAX_N]; bool not_empty_col[MAX_N]; bool used_row[MAX_N]; bool used_col[MAX_N]; void coppy(int n, int m) { for (int i = 1; n >= i; i++) { for (int j = 1; m >= j; j...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int nax = 3e5 + 10; long long w[nax]; long long dp[nax], ans; vector<pair<int, long long> > v[nax]; void dfs(int id, int par) { vector<long long> temp; for (auto i : v[id]) { if (i.first == par) continue; ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } template <class T> inline T sqr(T x) { ...
#include <bits/stdc++.h> using namespace std; vector<int> tree[2 * 100000 + 4]; long long dp[2 * 100000 + 3][2]; int value[2 * 100000 + 4]; void dfs(int x) { dp[x][0] = 0; dp[x][1] = -200000000005; for (int i = 0, sz = tree[x].size(); i < sz; i++) { int v = tree[x][i]; dfs(v); lo...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; void makedata() { freopen( input.txt , w , stdout); fclose(stdout); } long long a[250000]; int n, q; template <typename T> class SegmentTree { private: T *data, *lazy; int type; vo...
#define _CRT_SECURE_NO_WARNINGS #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target_tbl( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) //#include stdafx.h #include iostream #include fstream #include algorithm #include iomanip #inc...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; long long t[N], dp[N]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %lld , &t[i]); } dp[0] = 0; long long sum = 0; for (int i = 1; i <= n; i++) { dp[i] = dp[i - 1] + 20; ...
#include <bits/stdc++.h> using namespace std; long long GCD(long long a, long long b) { return (a % b) == 0 ? b : GCD(b, a % b); } long long mod(long long x) { return ((x % 998244353 + 998244353) % 998244353); } bool cmp(const pair<int, int> &left, const pair<int, int> &right) { return left.first > ri...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const long long M = (long long)1e9 + 7; int Int() { int x; scanf( %d , &x); return x; } long long Long() { long long x; scanf( %lld , &x); return x; } void Char(char *ch) { scanf( %s , ch); } template <typenam...
#include <bits/stdc++.h> using namespace std; template <class T> void read(T &x) { x = 0; char c = getchar(); int flag = 0; while (c < 0 || c > 9 ) flag |= (c == - ), c = getchar(); while (c >= 0 && c <= 9 ) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); if (flag) x = -x; ...
#include <bits/stdc++.h> using namespace std; int n; vector<int> vans; set<int> s; int main() { scanf( %d , &n); int start = 1; for (int i = 1; i <= n; ++i) { int x; scanf( %d , &x); if (s.count(x)) { vans.push_back(start); vans.push_back(i); start = i + 1...
#include <bits/stdc++.h> using namespace std; long long N = 1e7 + 5; std::vector<long long> v(N, 0); std::vector<long long> p; void sieve() { for (long long i = 2; i < N; i++) { if (v[i] != 0) continue; p.push_back(i); for (long long j = 2 * i; j < N; j += i) v[j] = 1; } } int ma...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using PII = pair<ll, ll>; using piii = pair<pii, pii>; using Pi = pair<int, pii>; using Graph = vector<vector<int>>; const int dx[4] = {0, -1, 1, 0}; const int dy[4] = {-1, 0, 0, 1}; bool check(int x, int...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 4; set<int> ts[N]; map<int, int> tmp; int n, k, a[N]; void add(int v) { auto it1 = tmp.find(v); if (it1 == tmp.end()) { tmp.emplace(v, 1); ts[1].insert(v); } else { ts[it1->second].erase(v); it1->second++; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; bool issafe(int i, int j, int n, int m) { return i >= 0 && j >= 0 && i < n && j < m; } char s[] = { D , L , R , U }; int dx[] = {+1, 0, 0, -1}; int dy[] = {0, -1, +1, 0}; void solve() { int n, m, k; cin >> n >> m >> k;...
#include <bits/stdc++.h> using namespace std; const int N = 4005; int n; struct child { long long v, d, p; int idx; child(long long v, long long d, long long p, int idx) : v(v), d(d), p(p), idx(idx) {} }; long long v, d, p; vector<child *> ve; int main() { ios::sync_with_stdio(fa...
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<string> st(N); vector<char> max(M, 0 ); for (int i = 0; i < N; i++) { cin >> st[i]; for (int j = 0; j < M; j++) if (st[i][j] > max[j]) max[j] = st[i][j]; } int sum = 0; for...
#include <bits/stdc++.h> char s[1005]; int a[25], mark[6071], dp[1005][6071], ch[6071][12], link[6071], tl, ans = 1e9, x, n; void insert(int len) { int rt = 0; for (int i = 1; i <= len; ++i) { if (!ch[rt][a[i]]) ch[rt][a[i]] = ++...
#include <bits/stdc++.h> using namespace std; struct Tree { int ch[10]; int len; int fail; } T[100010]; int tot; void insert(char* str, int len) { int now = 0; for (int i = 0; i < len; i++) { if (!T[now].ch[str[i] - 0 ]) { T[now].ch[str[i] - 0 ] = ++tot; T[tot].len ...
#include <bits/stdc++.h> using namespace std; void prepare() { ios_base::sync_with_stdio(0); cin.tie(0); freopen( input.txt , r , stdin); freopen( output.txt , w , stdout); } int main() { long double d, l, v1, v2; cin >> d >> l >> v1 >> v2; long double ans = (l - d) / (v1 + v2); ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read() { T x = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == - ) f = -f; c = getchar(); } while (isdigit(c)) { x = (x << 3) + (x << 1) + (c - 48); c = getchar(); } retur...
#include <bits/stdc++.h> using namespace std; int t, a, b, c; int main() { cin >> t; while (t--) { cin >> a >> b >> c; int res = 0; if (c & 1) res = 3; if (res) { if (b & 1) res = 1; if (a & 1) res = 0; else res = 1; } else { ...
#include <bits/stdc++.h> using namespace std; template <class T> T inline sqr(T x) { return x * x; } template <class T> inline void relaxMin(T &a, T b) { a = min(a, b); } template <class T> inline void relaxMax(T &a, T b) { a = max(a, b); } template <class T> inline T sign(T x) { ...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const int INF = (int)1e9 + 7; int parent[(int)1e5 + 2]; int deep[(int)1e5 + 2]; long long setSum[(int)1e5 + 2]; int a[(int)1e5 + 2]; inline void input() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(N...
#include <bits/stdc++.h> using namespace std; long long int a[100005]; long long int n, len, k; class data { public: set<pair<long long int, long long int> > mx, mn; long long int sum1, ksum; data() { ksum = 0, sum1 = 0; } void ins(long long int v, long long int index) { sum1 += v; ...
#include <bits/stdc++.h> using namespace std; long long f[20]; vector<long long> lu; void go(int x, int y, long long p) { if (x == y) return; lu.push_back(p * 10 + 4); lu.push_back(p * 10 + 7); go(x, y + 1, p * 10 + 4); go(x, y + 1, p * 10 + 7); } bool ok(long long x) { if (!x) retur...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool cmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool cmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } template <typename L, typename R> ostream &operator<<(ostream &out, ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long n = s.size(), i, j; long long displaced_left[n], displaced_right[n], minimum = INT_MAX; for (i = 0, j = s.size() - 1; i < n; i++, j--) { if (i == 0) { displaced_left[i] = 0, displaced_right[j] ...
#include <bits/stdc++.h> using namespace std; int main() { int n, ch; cin >> n; if (n == 0) cout << O-|-OOOO n ; else while (n != 0) { ch = n % 10; string s; switch (ch) { case 0: s = O-|-OOOO ; break; case 1: ...
#include <bits/stdc++.h> using namespace std; void solve() { int n, q, m; cin >> n >> q >> m; vector<int> b(n + 1), a(m + 1); for (int i = 1; i <= n; i++) cin >> b[i]; int t[q], l[q], r[q]; for (int i = 0; i < q; i++) cin >> t[i] >> l[i] >> r[i]; for (int i = 1; i <= m; i++) { cin ...
#include <complex> #include <queue> #include <set> #include <unordered_set> #include <list> #include <chrono> #include <random> #include <iostream> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <map> #include <unordered_map> #include <stack> #include <...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<pair<int, int>> v; int row[1010] = {0}, col[1010] = {0}; char g[1010][1010]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { cin >> g[i][j]; if (g[i][j] == * ) row[i]++...
#include <bits/stdc++.h> using namespace std; int main() { char s[110]; while (scanf( %s , s) != EOF) { int l = strlen(s); int ans = 0; for (int i = 0; i < l; i++) { if (s[i] == Q ) { for (int j = i + 1; j < l; j++) { if (s[j] == A ) { for (int...
#include <bits/stdc++.h> int main() { unsigned int m = 0, n = 0, s; scanf( %d%d , &m, &n); s = (m * n) / 2; printf( %d , s); return 0; }
#include <bits/stdc++.h> #pragma comment(linker, /STACK:2560000000000 ) using namespace std; map<int, int> sell; map<int, int> buy; int main() { int n, s; cin >> n >> s; for (int i = 1; i <= n; i++) { int p, d; char c; cin >> c >> p >> d; if (c == S ) { sell[p] +=...