func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; struct edge { long long a, b, w, ind; }; const int LEN = 100100; const long long INF = 100000000000000; int n, m, s, t, use[LEN], use1[LEN], ans[LEN], timer, tin[LEN], fup[LEN]; vector<edge> ar[LEN], ar1[LEN], ar2[LEN]; edge ed[LEN]; long long dist[LEN...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long INF = 1e18; const int md = 1e9 + 7; const int N = 2e5 + 1; vector<int> g[N]; int p[N], s[N], mx[N], mn[N]; bool did[N]; void make(int v) { p[v] = v, s[v] = 1, mx[v] = v, mn[v] = v; } int fin(int v) { if (p[v] == v...
#include <bits/stdc++.h> using namespace std; int n, m, nxt[402][26]; string s, t; int dp[401][401]; bool solve2(string t1, string t2) { dp[0][0] = -1; for (int i = 0; i <= t1.size(); ++i) { for (int j = 0; j <= t2.size(); ++j) { if (!i && !j) continue; dp[i][j] = n; if (...
#include <bits/stdc++.h> using namespace std; const long long inf = 1000000000ll; const long long inf64 = inf * inf; const long long base = inf + 7; const double pi = acos(-1.0); long long Abs(long long x) { return (x >= 0 ? x : -x); } int n; string s; int par[62 * 62], size[62 * 62], in[62 * 62], out...
#include <bits/stdc++.h> using namespace std; int main() { char alfabetGainuse[] = -abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRQSTUVWXYZ0123456789 ; int T; cin >> T; for (int t = 1; t <= T; t++) { int r, c, k; cin >> r >> c >> k; char harta[r + 1][c + 1]; cin.get(); ...
#include <bits/stdc++.h> using namespace std; vector<long long> temp(3001, 0); vector<vector<long long> > dp(3001, temp); void solve() { long long n; cin >> n; vector<long long> v(n); long long i, j, k, l; for (i = 0; i < n; i++) cin >> v[i]; for (i = 0; i < 3001; i++) { for (j = 0...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, max = 0, count = 0; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; if (v[i - 1] != v[i]) count++; else if (count > max) { max = count; count = 1; } else ...
#include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 1; bool vis[mx]; vector<int> adj[mx]; int n; bool star() { bool ans; int count1 = 0; int other = 0; for (int i = 1; i <= n; i++) { if (adj[i].size() == 1) { count1++; } else if (adj[i].size() == n - 1) { ...
#include <bits/stdc++.h> using namespace std; long long a[2000005]; long long sum[2000005]; int main() { long long m, n, i, j, k, ans = 0; cin >> m; for (i = 1; i <= m; i++) scanf( %lld , &a[i]); sort(a + 1, a + 1 + m); for (i = m; i >= 1; i--) sum[i] = sum[i + 1] + a[i]; for (i = 1; i <...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 1; const int N = 5003; vector<int> adj[N]; vector<pair<int, int> > stores[N]; bool done[N]; int dist[N]; void clear(int n) { for (int i = 1; i <= n; ++i) done[i] = 0; } void modify(multiset<pair<int, int> >& tiendas, const int& ...
#include <bits/stdc++.h> using namespace std; const int maxn = 220; bool vis[maxn]; vector<int> G[maxn]; int ans; int dfs(int v, int x) { int sum = 0; int max1 = 0, max2 = 0; for (int i = 0; i < G[v].size(); i++) { if (G[v][i] != x) { sum = max(sum, dfs(G[v][i], v)); if (an...
#include <bits/stdc++.h> using namespace std; int main() { int d1, d2, d3, i; cin >> d1 >> d2 >> d3; int k[4] = {(d1 + d2 + d3), (2 * d1 + 2 * d2), (2 * d2 + 2 * d3), (2 * d1 + 2 * d3)}; int min = 1e9; for (i = 0; i < 4; i++) { if (k[i] < min) min = k[i]; } cout << ...
#include <bits/stdc++.h> using namespace std; template <typename T> T in() { char ch; T n = 0; bool ng = false; while (1) { ch = getchar(); if (ch == - ) { ng = true; ch = getchar(); break; } if (ch >= 0 && ch <= 9 ) break; } while (1) { ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); const int inf = 0x3f3f3f3f; const int N = 100010; int n, q; int a[N], b[N], c[N]; struct node { int low, high; vector<pair<int, int> > v; } tree[N << 2]; void build(int p, int low, int high, ...
#include <bits/stdc++.h> using namespace std; long long a, b; map<long long, bool> mp; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); for (long long i = 1; i <= 1000; i++) mp[i * i] = 1; cin >> a >> b; for (long long i = -1; i > -a; i--) { if (mp[a * a - i * i]...
#include <bits/stdc++.h> int main() { int a, b, c, d; scanf( %d%d%d%d , &a, &b, &c, &d); a > b ? printf( First ) : printf( Second ); return 0; }
#include <bits/stdc++.h> using namespace std; const int Nmax = 1e6 + 7; int n; string s; int dp[Nmax]; vector<int> v; int ans, ans1, ans2; inline int get(string s) { int cnt = 0; int mx = 4 * n; ans = 0; for (int i = 0; i < n; i++) { if (s[i] == ) ) cnt--; else ...
#include <bits/stdc++.h> using namespace std; long long n, k, a, b; vector<long long> v; long long rec(long long l, long long r) { long long i = lower_bound(v.begin(), v.end(), l) - v.begin(); long long j = upper_bound(v.begin(), v.end(), r) - v.begin(); j--; long long na = j - i + 1; long l...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int* results = new int[N]; for (int i = 0; i < N; i++) { int num, pos; cin >> num >> pos; results[i] = pos * 2; } for (int i = 0; i < N; i++) cout << results[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; pair<int, int> v[100000 + 1]; vector<int> sol[100000 + 1]; int is[100000 + 1]; int pos[100000 + 1]; int main() { int i, j, first, N, res = 0; scanf( %d , &N); for (i = 1; i <= N; ++i) { scanf( %d , &first); v[i] = {first, i}; } so...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; using ll = long long; using ull = unsigned long long; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; int k; cin >> n >> k; ll s = n * (n - 1) / 2; s %= n; ll t = 0; ll cnt...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, q; cin >> n >> m >> q; int a[n][m]; struct a { int o; int p; } arr[q]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } int fo[n]; for (int i = 0; i...
#include <bits/stdc++.h> const long long int maxn = 2e7 + 5; const long long mod = 1e9 + 7; using namespace std; long long int power(long long int a, long long int b) { long long int res = 1; while (b > 0) { if (b % 2 == 1) res = res * a; a = a * a; b = b / 2; } return res; }...
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0, i, aa = 0, bb = 0; cin >> n; int a[n], b[n]; for (i = 0; i < n; i++) { cin >> a[i] >> b[i]; aa = aa + a[i]; bb = bb + b[i]; } if (aa % 2 == 1 && bb % 2 == 1) { for (i = 0; i < n; i++) { i...
#include <bits/stdc++.h> using namespace std; inline bool SR(int &x) { return scanf( %d , &x) == 1; } inline bool SR(long long &x) { return scanf( %lld , &x) == 1; } inline bool SR(double &x) { return scanf( %lf , &x) == 1; } inline bool SR(char *s) { return scanf( %s , s) == 1; } inline bool RI() { return ...
#include <bits/stdc++.h> using namespace std; const int N = 1000100; const int MOD = 1000000007; vector<long long> al[N], sum[N]; vector<pair<int, int> > adj[N]; pair<int, int> p[N]; int cnt(int u, long long ls) { return upper_bound(al[u].begin(), al[u].end(), ls) - al[u].begin(); } long long hp(i...
#include <bits/stdc++.h> using namespace std; const long long maxn = 300100, maxv = 100, mod = 1e9 + 7, maxa = 1005, maxs = 820, maxb = 20, base = 737, base2 = 3079, mod3 = 998244353, delt = 10513; const long long inf = 2e16; const long long infint = 1e9 + 11; long long max...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 123; int a[N]; vector<int> g[N]; int n, node, stdist = 0; void dfs(int k, int par, int dist) { if (dist > stdist) { node = k; stdist = dist; } for (auto it : g[k]) { if (it == par) continu...
#include <bits/stdc++.h> using namespace std; const int N = 510; const long long INF = 1e18; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch -...
#include <bits/stdc++.h> using namespace std; vector<long long> v[200010]; vector<long long> traversal; long long cnt; long long color[200010]; long long start[200010]; long long enddd[200010]; void dfs(long long curr) { start[curr] = cnt; traversal.push_back(curr); cnt++; for (int i = 0...
#include <bits/stdc++.h> using namespace std; map<int, int> M; long long posSum[300001]; int A[300001]; int main() { int N; cin >> N; for (int i = 1; i <= N; i++) cin >> A[i]; posSum[0] = 0; for (int i = 1; i <= N; i++) { if (A[i] < 0) posSum[i] = posSum[i - 1]; else ...
#include <bits/stdc++.h> using namespace std; const long long A = 100000000000000LL, N = 10000, M = 1000001; long long i, j, n, m, a, t[M * 4]; void modi(long long v, long long l, long long r, long long g, long long h) { if (l == r) { t[v] = h % 1000000007; return; } long long mid = (l +...
#include <bits/stdc++.h> using namespace std; int p[300002], pi; bool tag[300002]; int main() { int n, x; long long cnt; while (scanf( %d , &n) != EOF) { memset(tag, false, sizeof(tag)); pi = 0; for (int i = 0; i < n; i++) { scanf( %d , &x); if (x < 1 || x > n || ta...
#include <bits/stdc++.h> using namespace std; char a[514][514]; int n, m; int ID[514][514]; int RID[20005]; int idt[20005]; int g[20005]; int FIND(int x) { return g[x] == x ? x : (g[x] = FIND(g[x])); } void UNION(int x, int y) { x = FIND(x); y = FIND(y); g[x] = y; } int edge(int x, int...
#include <bits/stdc++.h> using namespace std; const int N = 410000; char ch[N]; int a[N]; int n, t; int main() { scanf( %d%d , &n, &t); scanf( %s , ch + 1); if (t == 0) { printf( %s , ch + 1); return 0; } int s = 0; for (int i = 1; i <= n; i++) { if (ch[i] == . ) ...
#include <bits/stdc++.h> using namespace std; using ll = long long; int const N = 222; int const M = 1e9 + 7; int n; ll f[N][N]; struct point { ll x, y; point(ll _x = 0, ll _y = 0) : x(_x), y(_y) {} ll operator*(const point &rhs) const { return x * rhs.y - y * rhs.x; } point operator-(cons...
#include <bits/stdc++.h> using namespace std; void think() { long long n, m; cin >> n >> m; vector<long long> v(n); for (long long i = 0; i < n; i++) { cin >> v[i]; } long long ans = 0; for (long long i = 0; i < m; i++) { long long x, y; cin >> x >> y; ans += min(...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long k = (n + 1) / 2; k = k - 1; long long ans = 0; for (long long i = 1; i <= k; ++i) { ans += 8 * i * i; } cout << ans << ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e4 + 5; int n, q; bool possible[MAXN]; vector<int> seg[4 * MAXN]; void update(int u, int l, int r, int tl, int tr, int x) { if (l > tr || r < tl) return; else if (l <= tl && tr <= r) { seg[u].push_back(x); } else { ...
#include <bits/stdc++.h> using namespace std; int f[100010], g[100010]; int _Max(int x, int y) { return x > y ? x : y; } void upd(int x, int ans, int k) { if (f[x] < ans) f[x] = ans, g[x] = k; else if (f[x] == ans && k < g[x]) g[x] = k; } int main() { int n, L, p, t, i, j, l = 1, r =...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; template <class T> double sqrt(T x) { return sqrt((double)x); } template <class T> T sqr(T x) { return x * x; } const double PI = acos(-1.0); const int INF = 1000000000; const int MOD = 1000000007; ...
#include <bits/stdc++.h> using namespace std; const long long M = 998244353; const long long inf = 4e18; const long long N = 3e5; long long fac[N + 1]; long long power(long long x, long long y) { if (y < 0) return power(x, M - 2) * power(x, y + 1) % M; y %= (M - 1); long long res = 1; while ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; vector<long long int> cost(n); for (long long int i = 0; i < n; i++) { cin >> cost[i]; } sort(cost.begin(), cost.end()); long long int m; cin >> m; vector<long long int> coup(m); for (...
#include <bits/stdc++.h> using namespace std; bool chk[5000050]; int ara[5000050], sum[5000050]; void sieve() { int i, j, k, x, y, z; for (i = 2; i <= 5000000; i++) if (!chk[i]) { for (j = i; j <= 5000000; j += i) { x = 0; k = j; while (k % i == 0) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100100; string S; int N; int Z[MAXN]; int len[MAXN]; void Zalg() { int L = 0, R = 0; for (int i = 1; i < N; i++) { if (i > R) { L = R = i; while (R < N && S[R] == S[R - L]) R++; Z[i] = R - L; R--; ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } return f...
#include <bits/stdc++.h> using namespace std; int x[4]; int y[4]; int ii[4] = {1, -1, 0, 0}; int jj[4] = {0, 0, -1, 1}; int main() { ios_base::sync_with_stdio(0); int x1, x2, x3, y1, y2, y3; for (int i = 1; i <= 3; i++) { cin >> x[i] >> y[i]; } set<pair<int, int>> s; long long ...
#include <bits/stdc++.h> using namespace std; int N, M; int Candidates[100]; int main() { cin >> N >> M; for (int i = 0; i < M; i++) { int MaxVotesNum = -1; int idx = -1; for (int j = 0; j < N; j++) { int Temp; cin >> Temp; if (MaxVotesNum < Temp) { Ma...
#include <bits/stdc++.h> using namespace std; int arr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; void solve() { int d, x; int a, b; cin >> a >> b; int ans = 0; for (int i = a; i <= b; i++) { x = i; while (x) { d = x % 10; x = x / 10; ans += arr[d]; } } ...
#include <bits/stdc++.h> using namespace std; int lss[2000][2000] = {}; int main() { string s; cin >> s; int n = s.length(); if (n == 1) { cout << 0 << endl; return 0; } for (int i = 0; i < n; i++) { lss[i][i] = 1; int temp = s[i]; int zero = 0; if (s[i]...
#include <bits/stdc++.h> using namespace std; const bool OJ = true; const long long inf = 1LL << 60; template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { for (long long i = 0; i < (((long long)((v).size()))); i++) os << v[i] << ; return os; } template <class T> istream& o...
#include <bits/stdc++.h> template <class C, class E> inline bool contains(const C& container, const E& element) { return container.find(element) != container.end(); } 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) { ...
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& x) { clog << x << ; return *this; } } dbg; auto ____ = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return nullptr; }(); int main(int argc, ...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { int res[100]; memset(res, 0, sizeof(res)); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { int r; cin >> r; if (i < j) continue; switch (r) { ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T BM(T p, T e, T M) { long long int ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; ...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << std::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; int n; map<string, int> m; string s; string pr[109]; int darab[109][26]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; cout << ? << 1 << << n << endl; for (int i = 1; i <= (n * (n + 1)) / 2; i++) { cin >> s; ...
#include <bits/stdc++.h> using namespace std; long long solve() { long long a, b; cin >> a >> b; long long m = b / 2 + 1; if (m > a) return b % m; else return b % a; } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); ; long long t; cin...
#include <bits/stdc++.h> using namespace std; int n, m, mr; vector<string> v; string s, s2, tmp, res; vector<pair<int, int> > e; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> s; v.push_back(s); } sort(v.begin(), v.end()); for (int i = 0; i < m; i++) { ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long int INF = 9e18 + 2e17; const int inf = 2e9; const int N = 1e5 + 22; const double eps = 1e-10; bool cmp(pair<int, int> A, pair<int, int> B) { if (A.first != B.first) return A.first < B.first; return A.second > B....
#include <bits/stdc++.h> using namespace std; int n, m, cnt; vector<int> a[150004]; int num[150004], sl[150004]; int d[150004]; void DFS(int u) { num[u] = cnt; for (int i = 0; i < a[u].size(); i++) if (num[a[u][i]] == 0) DFS(a[u][i]); } int main() { ios::sync_with_stdio(0); cin >> ...
#include <bits/stdc++.h> using namespace std; bool arng(pair<long long, long long> p, pair<long long, long long> q) { if (p.first > q.first) return true; if (p.first == q.first) { return (p.second < q.second); } return false; } void solve() { long long n, m; cin >> n; long long...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; int arr[n + 1]; for (int i = 1; i <= n; i++) cin >> arr[i]; sort(arr + 1, arr + n + 1); ...
#include <bits/stdc++.h> const int N = 1e6 + 5; using namespace std; int n, k, a[N], cnt[N], Min = N; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; Min = min(Min, a[i]); cnt[a[i]]++; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; int ans = 1e9; for (long long i = 0; i < n; i++) { int j = max(n - i - 1, i); int k; if (i - j < 0) k = min(a[n - 1], a[i]); el...
#include <bits/stdc++.h> using namespace std; int main() { { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }; int n, cnt = 0; cin >> n; while (n) { if (n >= 100) { cnt += n / 100; n %= 100; } if (n >= 20) { cnt += n / 20; n %= 20; } ...
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; string blank = ; const int N = 2e5 + 10; vector<double> arr(N); int n; vector<double> can(double mid) { vector<double> ans; vector<double>::iterator i = arr.begin(); ans.push_back(min(arr[n - ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const long long INF = 2e18; void print(int a[], int n) { for (int i = 0; i < n; i++) cout << a[i] << ; cout << n ; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; jump: ...
#include <bits/stdc++.h> using namespace std; const long long int N = 10e18; map<long long, long long> mp; int main() { int t; cin >> t; long long int type, u, v, w; while (t--) { scanf( %lld , &type); if (type == 1) { scanf( %lld%lld%lld , &u, &v, &w); while (u != v)...
#include <bits/stdc++.h> using namespace std; struct triplet { int first, second, third; } per[1005]; pair<int, int> pr[1005 / 2][1005], s[1005 / 2]; int n, a[1005], dp[1005], k, l, ind[1005 / 2][1005], indice, minim = 1 << 30, pas; int main...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000005; const int MD = 1000 * 1000 * 1000 + 7; vector<int> g[maxn]; long long dp[maxn][2], mult[maxn][2], ans, cnt[maxn]; bool visited[maxn]; int binPow(int a, int b) { if (!b) return 1; if (b & 1) { return (1LL * binPow(a, b - ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int m = 1e9; for (int i = 0; i < n; i++) if (s[i] == R && s[i + 1] == L ) m = min(m, (a[i + 1] - a[i]) / 2); if (m == 1e9) ...
#include <bits/stdc++.h> using namespace std; string f0 = What are you doing at the end of the world? Are you busy? Will you save us? ; string fi1 = What are you doing while sending ; string fi2 = ? Are you busy? Will you send ; string fi3 = ? ; string ff = What are you doing...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( -O3 ) int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int a1, a2, k1, k2, n; cin >> a1 >> a2 >> k1 >> k2 >> n; if (k1 > k2) { swap(a1, a2); swap(k1, k2); } if (n <= a1 ...
#include <bits/stdc++.h> using namespace std; long long t, a, b, c, d; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> t; while (t--) { cin >> a >> b >> c >> d; long long l = 0, r = (c + d - 1) / d; while (l < r) { long long mid = l + r + 1 >> 1; l...
#include <bits/stdc++.h> using namespace std; void show() {} template <typename T, typename... V> void show(T t, V... v) { cerr << t; if (sizeof...(v)) cerr << , ; show(v...); } template <class X> bool mini(X& a, const X& b) { if (a > b) { a = b; return true; } return...
#include <bits/stdc++.h> using namespace std; vector<long long int> adj[101]; set<pair<long long int, long long int>> color[101]; long long int visited[101]; long long int x; void bfs(long long int a, long long int b, long long int c) { queue<long long int> q; q.push(a); while (!q.empty()) { ...
#include <bits/stdc++.h> using namespace std; int n, k, g; int a[100010]; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } bool used[100010]; int main() { scanf( %d%d , &n, &k); g = 0; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); a[i] %= k; ...
#include <bits/stdc++.h> using namespace std; int a[109]; int main() { int n, m; while (cin >> n >> m) { for (int i = 0; i < n; i++) cin >> a[i]; int p = 0; sort(a, a + n); for (int i = 0; i < n; i++) { int flag = 0; while (a[i]) { if (a[i] % 10 == 4 || a[...
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; for (int i = 0; i < a; i++) { int c = 0; int j; cin >> j; int f = j % 10; if (j > 1) f = (f - 1) * 10; if (j > 1000) { f = f + 10; } else if (j > 100) { f = f + 6; ...
#include<bits/stdc++.h> using namespace std; #define size(v) (int)v.size() #define all(v) (v).begin(),(v).end() using lint = long long; using fint = long double; const int INF = 1e9 + 9; const int MOD = 998244353; int n, a[200000]; int solve(){ int ret = 0; // pp...p cc...c ...
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n; long long A[N]; map<long long, long long> MP; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %lld , &A[i]); MP.insert({A[1] - 1, 0}); for (int i = 2; i <= n; i++) { long long B = -1; whi...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; long long a[n + 2]; a[0] = 0; long long sum = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] > a[i - 1]) su...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int num[maxn]; int F[1010]; int fnd(int t) { if (F[t] == t) return t; return F[t] = fnd(F[t]); } void join(int a, int b) { int t1 = fnd(a); int t2 = fnd(b); if (t1 != t2) F[t1] = t2; } int main() { int n, ...
#include <bits/stdc++.h> using namespace std; const int maxN = 1000005; int n, a[maxN], p[230], b[230]; bool bo[1 << 22]; void Init() { scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d , a + i); } void Work() { int ans = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= 2...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T; cin >> T; while (T-- > 0) { long long n, k; cin >> n >> k; int m; for (m = 2; m <= n; m++) { if (n % m == 0) break; } ...
#include <bits/stdc++.h> using namespace std; void read_file(bool outToFile = true) {} struct point; struct vec; struct line; struct circle; struct triangle; double to_rad(double theta); double to_deg(double theta); double dist(point p, point q); point middle(point p, point q); point translate(p...
#include <bits/stdc++.h> using namespace std; void readi(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) f = -1; else v = v * 10 + c - 0 ; while (isdigit(c = getchar())) v = v * 10 + c - 0 ; x = v * f; } void ...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 3; const long long linf = (long long)inf * inf + 2; int N, K; struct TrieNode { TrieNode *children[26]; bool canWin, canLose; TrieNode() { canWin = canLose = false; for (int i = 0; i < 26; ++i) children[i] = nullptr; ...
#include <bits/stdc++.h> const long long mod = 1000000007; using namespace std; int main() { long long ax, ay, bx, by, tx, ty; scanf( %I64d , &(ax)); scanf( %I64d , &(ay)); scanf( %I64d , &(bx)); scanf( %I64d , &(by)); scanf( %I64d , &(tx)); scanf( %I64d , &(ty)); long long n; ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5; const long long M = 1e4; const long long mod = 1e9 + 7; const long long inf = 1e9; long long read() { long long s = 0; register bool neg = 0; register char c = getchar(); for (; c < 0 || c > 9 ; c = getchar()) neg |= (...
#include <bits/stdc++.h> int main() { int n, p, i, j, k, l; double sum = 0; int a[50]; long long b[51][51]; scanf( %d , &n); for (i = 0; i < n; i++) scanf( %d , &a[i]); scanf( %d , &p); for (i = 0; i < n; i++) { double tmp = 0; for (j = 0; j <= n; j++) { for (k = 0;...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; const int MAX = 1e6 + 1; int n, f[MAX], dep[MAX]; int u[MAX], pr[MAX]; int stk[2][N], q[N << 1]; bool mk[MAX], cmp[N]; vector<int> a, adj[MAX], dv[MAX]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ...
#include <bits/stdc++.h> using namespace std; const int N = 105; set<string> name; map<string, int> id; string pos[N]; string s, st, o; int n, a[N], cnt; void add(string x) { if (name.find(x) != name.end()) return; name.insert(x); cnt++; id[x] = cnt; pos[cnt] = x; } signed main()...
#include <bits/stdc++.h> using namespace std; const int N = 3002; int dfn[N], low[N], c; bool ipt[N]; pair<int, int> edge[N]; vector<pair<int, int> > p[N]; void tarjan(int x, int pre) { dfn[x] = low[x] = ++c; for (__typeof(p[x].begin()) it = p[x].begin(); it != p[x].end(); ++it) { if (pre ==...
#include <bits/stdc++.h> using namespace std; int dir; int n, m, k; int go(int pos) { if (pos == 1) { dir = 1; return pos + 1; } if (pos == n) { dir = 0; return pos - 1; } if (dir) return pos + 1; return pos - 1; } int main() { cin >> n >> m >> k; stri...
#include <bits/stdc++.h> using namespace std; bool palindrome(string s) { int n = s.length(); for (int i = 0; i < n; i++) { if (s[i] != s[n - i - 1]) return 0; } return 1; } int main() { int n; cin >> n; string s; cin >> s; sort(s.begin(), s.end()); cout << s << end...
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); for (int i = 0; i < t; i++) { int x, y, n, cnt = 0, chk = 0, tmp, pos = -1, pos2 = -1, res; map<pair<int, int>, int> mp, Tmp, Imp; map<int, string> mp2; string s = , s2 = , s3 = ; scanf...
#include <bits/stdc++.h> using namespace std; int n, m, k; int arr[600][600] = {}; int visited[600][600] = {}; void dfs(int, int); int main() { cin >> n >> m >> k; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { char t; cin >> t; if (t == . ) { ar...
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long arr[200005]; pair<long long, long long> pt[200005]; int main() { long long n, x, y, newX, newY, cnt = 0, ansX, ansY, val = 0; map<pair<long long, long long>, long long> mp1; cin >> n >> x >> y; for (int i = 0; i <...