func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; long long arr[500005]; map<long long, int> mm; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %lld , &arr[i]); for (int i = 1; i <= n - 1; i++) arr[i] += arr[i - 1]; for (int i = 0; i < n; i++) mm[arr[i]]++; int mx = ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100007; long long i, j, k, n, m, t, x, y, ans; long long pw2[32]; long long a[MAXN]; void calPowerTwo() { long long i, j, k; pw2[0] = 1; for (i = 1; i < 32; i++) { pw2[i] = pw2[i - 1] * 2; } } int main() { calPowerT...
#include <bits/stdc++.h> using namespace std; int dadsadasda; const int INF = 0x3f3f3f3f; const long long LLINF = 1e18; const int MAXN = 3e5; int n; int a[MAXN]; int ans[MAXN]; priority_queue<pair<int, int> > pq; int father[MAXN], siz[MAXN], cnt[MAXN]; void makeSet(int nn, int m) { for (int i ...
#include <bits/stdc++.h> double const MOD = 1000000007; double const N = 1000005; double const LN = 20; double const inf = 1e18 + 5; using namespace std; double a, b; void mirror(double &x, double &z) { if (x < 0) { x = -x; return; } if (z < 0) { z = -z; return; } ...
#include <bits/stdc++.h> using namespace std; long long ara[100010]; int segtree[20][100010 * 4]; int lazy[20][100010 * 4]; void build(int node, int l, int r, int po) { if (l == r) { segtree[po][node] = 0; if ((ara[l] & (1 << po))) { segtree[po][node] = 1; } return; } ...
#include <bits/stdc++.h> using namespace std; int main() { int t, a; cin >> t; while (t--) { cin >> a; cout << a / 2 << endl; } }
#include <bits/stdc++.h> using namespace std; struct road { int x, next; double dis; } r[305 * 305 * 2]; int N, M; int st[305], w; int vis[305]; double P[305]; double l1 = -1, r1 = 0, mid; double dis[305]; void add(int x, int y, double dis) { r[++w].x = y, r[w].next = st[x]; r[w].dis...
#include <bits/stdc++.h> char map[1005][1005]; int main() { int n, m; scanf( %d %d , &n, &m); for (int r = 0; r < n; r++) scanf( %s , map[r]); int row[1005] = {0}; int col[1005] = {0}; for (int r = 0; r < n; r++) { int count = 0; for (int c = 0; c < m; c++) if (map[r][c] ...
#include <bits/stdc++.h> using namespace std; const int N = 20; const int mod = 1e9 + 7; long double a[N]; int n, k; long double dp[1 << N], out[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k; int zeros = 0; for (int i = 0; i < n; i++) cin >> a[i], zeros +...
#include <bits/stdc++.h> const long long N = 1000000; using namespace std; long long n, k, l, i = 0, j, mn, mx = N, ans = 0, als, r1, r2, r3, t, q, v, m, ii, r4; string d1, d3, d2, s; char kl, km, mk, lk; double fg; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);...
#include <bits/stdc++.h> using namespace std; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; long long r1, r2, r3, d; cin >> n >> r1 >> r2 >> r3 >> d; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<vector<long long>> dp(n, vector<long long...
#include <bits/stdc++.h> using namespace std; using namespace std; const long long MOD = 1000000007; vector<vector<long long> > matrix_mul(vector<vector<long long> > a, vector<vector<long long> > b) { vector<vector<long long> > c(a.size(), vector<long long>(b[0].size(...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; const double eps = 1e-6; vector<int> g[maxn]; vector<int> tree[maxn]; int deep[maxn], son[maxn]; int cnt, mx; void dfs(int x, int y) { int sz = g[x].size(); deep...
#include <bits/stdc++.h> using namespace std; int N; int main() { cin >> N; int dec[2 * N]; int all_round_down = 0; int z = 0; for (int i = 0; i < 2 * N; i++) { double x; cin >> x; dec[i] = int((x + 0.0005 - int(x + 0.0005)) * 1000); all_round_down += dec[i]; if (...
#include <bits/stdc++.h> using namespace std; int n; vector<int> edge[(1 << 18)]; int degree[(1 << 18)]; int DelNode; int DFS(int iDeep, int iNode, int iParent) { int iSons = edge[iNode].size(); if (iParent) iSons--; if (iDeep > n) return -1; if (iSons > 3) return -1; if (iSons == 0) ret...
#include <bits/stdc++.h> using namespace std; long long n, sz, i, ans, j, a[200001], t[531172], op; void upd(int x) { for (j = x / 2; j >= 1; j /= 2) t[j] = max(t[j * 2], t[j * 2 + 1]); } long long finds(int l, int r) { long long sum = -1; while (l <= r) { if (l % 2 == 1) sum = max(sum, t[l]...
#include <bits/stdc++.h> using namespace std; int read() { register 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 = 10 * x + ch - 0 ; ch = getchar(); } return x * ...
#include <bits/stdc++.h> using namespace std; long long c[55]; struct cmp { bool operator()(long long a, long long b) { return c[a] < c[b]; } }; int main() { long long n, m, k; long long a[55], b[55], ind[55]; long long dp[55][55][105][3]; cin >> n >> m >> k; for (long long i = 0; i < ...
#include <bits/stdc++.h> using namespace std; long long a[1010]; long long b[1010]; long long c[2020]; long long d[1010]; long long mex(long long m) { sort(b, b + m); long long j = 0; long long k = 0; long long ans = m; while (j < m) { if (b[k] > j) { ans = j; break...
#include <bits/stdc++.h> using namespace std; template <class A> ostream& operator<<(ostream& out, const vector<A>& v) { for (long long i = 0; i < v.size(); i++) { if (i) out << ; out << v[i]; } return out << n ; } const long long mod = 1000000007; inline long long add(long long...
#include <bits/stdc++.h> using namespace std; string in_name = sample.in ; string out_name = sample.out ; ifstream in; ofstream out; vector<int> v[1001]; int N; int main() { cin >> N; int k, x; for (int i = 0; i < N; i++) { cin >> k; for (int j = 0; j < k; j++) { cin >>...
#include <bits/stdc++.h> using namespace std; int firstt(int* a, int n) { long long l, r, s; for (int i = 0; i <= n - 1; ++i) { l = 0; r = 10000000000; while (l < r - 1) { s = (-l + r) / 2 + l; if (s * n >= a[i] - i) { r = s; } else { l = s; ...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > V(7); vector<vector<string> > S(7); set<string> SS; int n, m; void DFS(int node, string T) { if (T.length() == n) { SS.insert(T); return; } for (int i = 0; i < S[node].size(); i++) { string R = S[node][i]; ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 5e5 + 5; struct Node { long long t, h, m; } a[MAXN]; bool cmp(Node x, Node y) { return x.m > y.m; } long long n, x; long long vis[MAXN]; long long solve(long long now) { memset(vis, 0, sizeof(vis)); long long ans = 0; l...
#include <bits/stdc++.h> using namespace std; int main() { int n, perm[305], m[305][305]; char s[305]; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &perm[i]); } memset(m, 0, sizeof(m)); for (int i = 0; i < n; i++) { scanf( %s , s); for (int j = 0; j < n; j...
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair #define deb(x) cout<< #x << << x << n ; #define MAX 9223372036854775807 #define MIN -9223372036854775807 #define PI 3.141592653589 #define setbits(n) __builtin_popcountll(n) #define...
#include <bits/stdc++.h> using namespace std; int q; int n; int nav[200005], pos[200005]; int main() { scanf( %d , &q); while (q--) { int men = 999999, lar = 999999; scanf( %d , &n); int a; for (int i = 0; i < n; i++) { scanf( %d , &a); if (nav[a] == 0) nav[a] =...
#include <bits/stdc++.h> using namespace std; const int N = 1e3; int main() { int n; cin >> n; for (int i = 1; i < N; i++) if (i * (i + 1) <= 2 * n && (i + 2) * (i + 1) > 2 * n) { cout << i << endl; for (int j = 1; j < i; j++) cout << j << ; cout << n - (i - 1) * i / 2...
#include <bits/stdc++.h> using namespace std; int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; int ans[505][505]; int col = 1, n, coz = 0; int main() { std::ios::sync_with_stdio(false); scanf( %d , &n); if (n < 3) { printf( -1 ); return 0; } int now_ = 0, cot = n; int x ...
#include <bits/stdc++.h> using namespace std; int main() { int n, tf = 0, f = 0, hun = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 25) tf++; else if (a[i] == 50) { f++; tf--; } else { hun++; if (f >= 1)...
#include <bits/stdc++.h> using namespace std; long long n, y; int main() { cin >> n; n--; for (int i = 1; i <= sqrt(n); i++) if (n % i == 0) { y = n / i - 1 - i; if ((y % 2 == 0) && (y > 0)) { cout << i << << y / 2; return 0; } } cout << ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[n]; int b[m]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; int flag = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i] =...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int power(int a, int b, int p) { int ans = 1 % p; for (; b; b >>= 1) { if (b & 1) ans = (long long)ans * a % p; a = (long long)a * a % p; } return ans; } int a, b, c, d; int...
#include <bits/stdc++.h> using namespace std; const int MAXINT = 1000001; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n), b(n); vector<bool> used(MAXINT); set<int> dif; ...
#include <bits/stdc++.h> using namespace std; int dp[100001]; int tmp, n, b[100001]; vector<pair<int, int> > a; int main() { int tt, ss; cin >> n; for (int i = (0); i <= (n - 1); i++) { cin >> tt >> ss; a.push_back(make_pair(tt, ss)); } sort(a.begin(), a.end()); tmp = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { long long b, deocoai, g, n, p, q, i, a[300], t, tong, z, a1, a2, k2, k1; cin >> b >> g >> n; if (min(b, g) >= n) { cout << n + 1; return 0; } if (max(b, g) >= n && min(b, g) <= n) { cout << min(b, g) + 1; return 0...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); long long ans = 0; vector<pair<int, int> > v; vector<int> all; for (int i = 1; i <= n; ++i) { int a, b, c, d; scanf( %d%d%d%d , &a, &b, &c, &d); if (a + b < c + d) { if (a > d) v.push...
#include <bits/stdc++.h> using namespace std; const long long max_sz = 1e5 + 1; const long long mod = 1e9 + 7; const long long MAXN = 4e18 + 1; char flip(char k) { if (k == 0 ) return 1 ; return 0 ; } long long sum_digit(long long n) { long long a = 0, i; for (i = n; i > 0; i = i / 10) ...
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; const double PI = acos(-1.0); const double EPS = 1e-8; using namespace std; int main() { int n; while (cin >> n) { if (n <= 2) puts( -1 ); else { if (n % 2) cout << 2 * ((long long)(n / 2) * (n / 2) + n / 2) << ...
#include <bits/stdc++.h> using namespace std; double across(int n, int num_sides) { double ang = M_PI * ((double)num_sides / n) / 2; return 0.5 / sin(M_PI / (2 * n)) * sin(ang) * 2; } int main() { cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; double arg = ...
#include <bits/stdc++.h> using namespace std; int main() { int t, a, i, j, ans, k, n, m; scanf( %d , &t); while (t--) { ans = 0; set<int> a; a.clear(); scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %d , &k); if (k % 2 == 0) a.insert(k); } wh...
#include <bits/stdc++.h> using namespace std; inline pair<long long int, long long int> compute_pos( pair<long long int, long long int> prev, char ch) { int flag = 1; pair<long long int, long long int> dest; dest = prev; if (ch == U ) dest.second += flag; if (ch == D ) dest.second -= fla...
#include <bits/stdc++.h> using namespace std; int d[101], t, m, c, b, i, j, k, l; string s; int main() { cin >> t >> m; for (k = 0; k < t; k++) { cin >> s; if (s[0] == a ) { cin >> c; for (i = 0, j = -1; i < m; i++) if (i - j == c && !d[i]) break; ...
#include <bits/stdc++.h> using namespace std; char ch, s[22][22]; int n, m, N, sg[22][22][22][22], op[22][22]; bool ok, bo[100000]; void read(int &x) { for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == - ) ok = 1; for (x = 0; isdigit(ch); x = x * 10 + ch - 0 , ch = getchar()...
#include <bits/stdc++.h> using namespace std; int num[100010]; int l[100010], r[100010]; int tree[100010 << 2]; int lazy[100010 << 2]; vector<int> v[100010]; void build(int l, int r, int rt) { if (l == r) { tree[rt] = num[l]; lazy[rt] = 0; return; } int m = l + r >> 1; bu...
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { fast(); long long int t; t = 1; while (t--) { int n; cin >> n; long long arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, ...
#include <bits/stdc++.h> using namespace std; int cnt(vector<vector<pair<int, int>>>& graph, int cur, int parent, int val) { int ans = 1; for (auto p : graph[cur]) { if (p.first == parent) continue; if (p.second == val) ans += cnt(graph, p.first, cur, val); } return ans; } void fill(...
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; void pr_init() {} void solve() { string str[2]; cin >> str[0] >> str[1]; long long ss = (long long)str[0].size(); long long dp[2][ss + 1]; for (long long i = 0; i < 2; i++) { for (long long j = 0; j < ss; j++) {...
#include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == - , c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5, Lim = 18; int tr[maxn * 19][2], nowxor, cnt = 1, siz[maxn * 19], n, m; template <typename T> inline void read(T &x) { char c; int f = 1; while (!isdigit(c = getchar())) (c == - ) && (f = -1); x = c ^ 48; while (isdigi...
#include <bits/stdc++.h> long long vx[200010], vy[200010]; std::map<long long, long long> mp, gg; int main() { int n; long long a, b; scanf( %d%lld%lld , &n, &a, &b); long long ans = 0; for (int k = 1; k <= n; k++) { long long t; scanf( %lld%lld%lld , &t, &vx[k], &vy[k]); lon...
#include <bits/stdc++.h> using namespace std; const int mmmm = 1111; int n; char s[mmmm]; int a[mmmm], f[mmmm]; void qwe() { a[0] = 1989; f[0] = 1; for (int i = 1; i <= 9; i++) { f[i] = f[i - 1] * 10; a[i] = a[i - 1] + f[i]; } } int main() { qwe(); while (scanf( %d , ...
#include <bits/stdc++.h> const double PI = 3.141592653589793238463; using namespace std; inline long long add(long long a, long long b) { a += b; if (a >= 1000000007) a -= 1000000007; return a; } inline long long sub(long long a, long long b) { a -= b; if (a < 0) a += 1000000007; retur...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000000 + 7; const int N = 10000001; long long dp[N]; int main() { dp[1] = 0; dp[2] = 3; for (int i = 3; i < N; i++) dp[i] = (dp[i - 2] * 3 + dp[i - 1] * 2) % mod; int n; while (scanf( %d , &n) != EOF) printf( %lld n , ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int maxn = 1e4 + 5; int n, b, q; int a[maxn], c[maxn]; inline int f(int x, int j) { return (x / 5) + (x % 5 >= j); } inline int calc(int j, int l, int r) { return f(r, j) - f(l - 1, j); } int main() { scanf( %d%d%d , &n, &b...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e7; int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } int main() { int n, ans = INT_MAX, count = 0; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; count += (v[i] == 1)...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; pair<int, int> p[10][10]; int nom[4]; bool cmp(int a, int b) { if (p[a][0] != p[b][0]) return (p[a][0] < p[b][0]); else return (p[a][1] < p[b][1]); } int main() { for (int i = (0); i < (4); i++...
#include <bits/stdc++.h> using namespace std; int A[200000]; int cost[200001]; int sub() { int n, p, k; cin >> n >> p >> k; for (int i = 0; i < n; i++) { cin >> A[i]; } sort(A, A + n); for (int i = 0; i < n; i++) { if (i < k - 1) { cost[i + 1] = cost[i] + A[i]; ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:102400000,102400000 ) const long long INF = 1e18 + 1LL; const double Pi = acos(-1.0); const int N = 5e5 + 10, M = 1e3 + 20, mod = 1e9 + 7, inf = 2e9; vector<int> G[N]; long long dp[N][10], fs[N][10]; long long ans = 0; int n...
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; reverse(s.begin(), s.end()); reverse(t.begin(), t.end()); int i = 0; while (i < s.length() && i < t.length() && s[i] == t[i]) { i++; } cout << s.length() + t.length() - 2 * i; }
#include <bits/stdc++.h> int main() { int n, s; scanf( %d%d , &n, &s); s *= 100; int max = 0; bool tr = false; for (int i = 1; i <= n; i++) { int d, c; scanf( %d%d , &d, &c); int money = d * 100 + c; if (money <= s) { tr = true; int sweet = (s - money) %...
#include <bits/stdc++.h> using namespace std; int n, k, m; int times[45]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k >> m; for (int i = 0; i < k; i++) cin >> times[i]; int s = 0; for (int i = 0; i < k; i++) s += times[i]; sort(begin(times), begin(times) + k); ...
#include <bits/stdc++.h> using namespace std; template <typename T, typename V> void bugp(const pair<T, V> &x) { cerr << { << x.first << , << x.second << } << endl; } template <typename T, typename U, typename V> void bugpp(const pair<T, pair<U, V> > &x) { cerr << { << x.first << , { << x...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int oo = 0x3f3f3f3f; const long long OO = 0x3f3f3f3f3f3f3f...
#include <bits/stdc++.h> using namespace std; int n, m, i, x, y, ans = 0, t; bool p1[1010], p2[1010]; int main() { scanf( %d%d , &n, &m); for (i = 1; i <= n; i++) p1[i] = p2[i] = 1; p1[1] = p2[1] = p1[n] = p2[n] = 0; for (i = 1; i <= m; i++) { scanf( %d%d , &x, &y); p1[x] = p2[y] = 0...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); if (n % 2) printf( black n ); else printf( white n1 2 n ); }
#include <bits/stdc++.h> using namespace std; namespace fastIO { bool IOerror = 0; inline char nc() { static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000; if (p1 == pend) { p1 = buf; pend = buf + fread(buf, 1, 100000, stdin); if (pend == p1) { IOerror = 1; ...
#include <iostream> #include <string.h> #include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while(t--) { int x; cin >> x; bool isPossible = false; for (int i = 0; i < 11; i++) { if (111*i <= x && (x - 111*i)%11 == 0)...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000005; int a[maxn], ra[maxn]; int main() { int n, m, k; while (~scanf( %d%d%d , &n, &m, &k)) { for (int i = 0; i < n; i++) { scanf( %d , &a[i]); ra[a[i]] = i; } int t; long long cnt = 0; for (i...
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; unsigned long long n, k, x; unsigned long long a[300000]; unsigned long long dpL[300000]; unsigned long long dpR[300000]; int main() { int i, j; cin >> n >> k >> x; unsigned long long s = 0, MAX = 0; for (i = 0; i < n; ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int64_t n, m; cin >> n >> m; pair<char, int64_t> a[n][m]; for (int64_t i = 0; i < n; ++i) { for (int64_t j = 0; j < m; ++j) { cin >> a[i][j].first; a[i][j].secon...
#include <bits/stdc++.h> using namespace std; int l, s, cnt, last, b[100005]; char a[100005]; int main() { int i, j; scanf( %s , a); l = strlen(a); for (i = 0; i < strlen(a); i++) { if (a[i] == ( ) s++; else if (a[i] == ) ) s--; else if (a[i] == # ) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, first, last, ans, flag; cin >> n; if (n <= 2) { cout << 0 << endl; return 0; } ans = flag = 0; first = 1; last = n; for (int i = 1; i < n; i++) { ans += (first + last) % (n + 1); if (!flag) { ...
#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() { long long n; scanf( %I64d , &n)...
#include <bits/stdc++.h> using namespace std; int main() { float n; cin >> n; cout << ceil(n / 5); return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; void solve(){ ll n, i; cin >> n; ll u, r, d, l; ll u1=0, r1=0, d1=0, l1=0; cin >> u >> r >> d >> l; if(u==n) r1++,l1++; if(d==n) r1++,l1++; if(r==n) u1++,d1++; if(l==n) u1++,d1++; ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int x; cin >> x; cin.ignore(); string input; getline(cin, input); int len = input.length(); int cnt[3] = {0}; for (int i = 0; i < len; i++) { if (input[i] == 0 ) cnt[0]++; else...
#include <bits/stdc++.h> using namespace std; int n, m; int a[120], b[120], c[120], d[120]; map<int, int> mp; vector<int> ans; int main() { memset(b, -1, sizeof(b)); scanf( %d %d , &n, &m); for (int i = 1; i <= m; i++) { int x, y; scanf( %d %d , &x, &y); b[x] = y; mp[x] =...
#include <bits/stdc++.h> using namespace std; const int maxN = 5; long double x[maxN], y[maxN], r[maxN], val[maxN]; long double f(long double xx, long double yy) { for (int i = 0; i < 3; ++i) { val[i] = sqrt((x[i] - xx) * (x[i] - xx) + (y[i] - yy) * (y[i] - yy)) / r[i]; } val[3] = val[0]; ...
#include <bits/stdc++.h> const double eps = 1e-9; const double PI = acos(-1.0); const long long int mod = 1e9 + 7; const int MAXN = 2e3 + 5; using namespace std; vector<vector<int>> adj(MAXN); int mxd; void dfs(int u, int d) { mxd = max(mxd, d); for (int v : adj[u]) dfs(v, d + 1); } void cp(...
#include <bits/stdc++.h> using namespace std; int power(long long int x, long long int y) { long long int temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else return x * temp * temp; } bool prime_check(long long int n) { long long int i...
#include <bits/stdc++.h> using namespace std; inline char nchar() { static const int bufl = 1 << 20; static char buf[bufl], *a = NULL, *b = NULL; return a == b && (b = (a = buf) + fread(buf, 1, bufl, stdin), a == b) ? EOF : *a++; ...
#include <bits/stdc++.h> using namespace std; const long long int INF = 9223372036854775807LL; #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroint-loops ) long long int power(long long int a, long long int b, long long int m) { long long int res = 1; wh...
#include <bits/stdc++.h> using namespace std; int c[10000] = {0}, d[10000] = {0}; int main() { int n, m, i; scanf( %d%d , &n, &m); for (i = 0; i < m; i++) { int x, y; scanf( %d%d , &x, &y); c[x]++; d[y]++; } int ans = 0, j, kc = 0, kd = 0; for (i = 2; i <= n - 1; i+...
#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]; int x = a[0], j = 0; vector<int> pol(n, 0); pol[0] = 1; for (int i = 1; i < n; i++) { if (a[i] == x) pol[j]++; else { j++; ...
#include <bits/stdc++.h> using namespace std; int n, m; int visited[200001]; int colour[200001]; vector<int> adj_list[200001]; int* graph[1000001]; int* finalcolour[1000001]; int size[1000001]; int check; int count1 = 0; int k[9]; int l[9]; int dp[9][1001]; int A[9][11]; int c[9][10]; bo...
#include <bits/stdc++.h> using namespace std; long long inf = 4e18, mod = 1e9 + 7; vector<pair<pair<long long, long long>, pair<long long, long long>>> v; int segt[4 * 6000000 + 5], lazy[4 * 6000000 + 5]; void push(int v, int l, int r) { segt[v] += lazy[v]; if (l != r) { lazy[2 * v] += lazy[v]; ...
#include <bits/stdc++.h> using namespace std; bool m[1001][1001]; bool ff[1001][1001]; int n, num; int ans; int main() { cin >> n >> num; for (int i = 1; i <= n; i++) for (int j = i + 1; j <= i + num; j++) if (!m[i][(j - 1) % n + 1]) { m[i][(j - 1) % n + 1] = true; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 0) { cout << n / 2 - 1; } else { cout << (n + 1) / 2 - 1; } }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int a[N]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t, i, j, n, m, l, r; cin >> n; for (i = 0; i < n; i++) { cin >> l; a[l] = 1; } l = r = 0; if (a[1] == 1) l++;...
#include <bits/stdc++.h> using namespace std; int AbsDifference(int a, int b) { if (a >= b) return a - b; return b - a; } long long AbsDifference(long long a, long long b) { if (a >= b) return a - b; return b - a; } const int mod = 1000000007; const int mod2 = 1000000009; const int inf =...
#include <bits/stdc++.h> int t[10000]; int main() { int n, m, k; std::cin >> n >> m >> k; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { std::cin >> t[100 * i + j]; } } int ans = 1000000; if (n > k) { for (int j = 0; j < n; j++) { int dc = 0; ...
#include <bits/stdc++.h> using namespace std; char c[101]; int n, ans; int check(int k) { int cnt = 0, sum = 0; for (int i = 0; i < n; i++) { sum += c[i] - 0 ; if (sum > k) return 0; if (sum == k) sum = 0, cnt++; } return (sum == 0 && cnt > 1) ? 1 : 0; } int main() { s...
#include <bits/stdc++.h> int main() { long long t, i, l, k, j, b[23132], s, n; char ch[1000000]; while (gets(ch)) { l = strlen(ch); for (k = 0; k < 124; k++) b[k] = 0; for (k = 0; k < l; k++) { b[ch[k] - 48]++; } s = 0; for (j = 0; j < 124; j++) { if (0 ...
#include <bits/stdc++.h> using namespace std; long long w, m, k; int main() { scanf( %I64d%I64d%I64d , &w, &m, &k); w /= k; if (!w) { puts( 0 ); return 0; } long long cnt = 0; long long tmp = m; while (tmp) { cnt++; tmp /= 10; } tmp = 1; for (int i =...
#include <bits/stdc++.h> using namespace std; long long INF = (1e19); int n, m; int a[105]; bool cmp(int a, int b) { return a > b; } bool check(int d) { int i = 1, k = 0, ans = 0; while (a[i] - k > 0 && i <= n) { ans += (a[i] - k); if (i % d == 0) { k++; } if (ans >= ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<long long> a(n); map<long long, long long> mp; long long ans = 0; for (long long i = 0; i < n; i++) { cin >> a[i]; if (mp[a[...
#include <bits/stdc++.h> using namespace std; using namespace std; const int MAXN = 1005; vector<int> child[200000]; int ceng[200000]; void dfs(int v, int ii) { ceng[ii]++; for (int i = 0; i < child[v].size(); i++) { dfs(child[v][i], ii + 1); } } int main() { int n; scanf( %d ,...
#include <bits/stdc++.h> using namespace std; const long long N = 309, mod = 1e9 + 7; inline long long read() { register long long x = 0, f = 1; register char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x =...
#include <bits/stdc++.h> using namespace std; int poww(int a, int b) { for (int i = 0; i < b; i++) a *= a; return a; } int main() { int n, t; cin >> n; if (n < 10) { cout << n << endl; return 0; } long long i = 2; long long sum = 9; long long x = 10, v[] = {999999...