func_code_string
stringlengths
59
71.4k
#include<bits/stdc++.h> using namespace std; long long q,n,c[400005],z,ans,mn=1e14,d,x; map<long long,long long>las,ll; vector<long long>v; struct am{ long long va,ind; }; am a[400005]; bool cmp(am zz,am y){ return zz.ind<y.ind; } set<long long>st; int main(){ ios::sync_with_stdio(NULL); c...
#include <bits/stdc++.h> using namespace std; const int N = 200009; int n, a[N], cnt[N], mode, fsm[N], tmp[N], ans; void larg(int x) { int sm = 0, res = 0; memset(fsm, 0, sizeof(fsm)); for (int i = 1; i <= n; i++) { if (a[i] == mode) sm++; else if (a[i] == x) sm--; ...
#include <bits/stdc++.h> using namespace std; const int N = 300; map<int, int> m; int main() { ios_base::sync_with_stdio(false); int i, j, n; cin >> n; int p = 0; int k = 0; for (i = 1; i <= n; ++i) { cin >> j; if (m[j] == 0) ++k; else m[j]--; m[i]...
#include <bits/stdc++.h> using namespace std; int N, R; int result = INT_MAX; char opt[] = TB ; int turns; int sLast; char rChar[1000001]; int main() { int x, y; cin >> N >> R; if (N == 1 && R == 1) { cout << 0 << endl << T << endl; return 0; } for (int i = 1; i < R; i...
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long PRIME = 999727999; long long PRIME2 = 999999937; long long INF = LLONG_MAX / 4; template <class F1, class F2> ostream& operator<<(ostream& os, const pair<F1, F2>& p) { return os << p.first << << p.second; } templa...
#include <bits/stdc++.h> using namespace std; const int N = 100002; int n, m, ok[N], a, b, c, l[N], nr[N]; vector<pair<int, int>> G[N]; int p[20][N]; void parentDFS(int x, int par) { p[0][x] = par; l[x] = l[par] + 1; for (auto it : G[x]) if (it.first != par) parentDFS(it.first, x); } i...
#include <bits/stdc++.h> using namespace std; int dp[6][6][220][220], aa[50], bb[50]; void init() { memset(dp, -1, sizeof(dp)); dp[0][0][0][0] = 0; for (int s1 = 0; s1 < 3; ++s1) for (int s2 = 0; s2 < 3; ++s2) for (int j = 0; j < 220; ++j) for (int k = 0; k < 220; ++k) ...
#include <bits/stdc++.h> using namespace std; string A[4][102]; string M[202]; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; for (int p = 0; p < 4; p++) { for (int i = 0; i < n; i++) { cin >> A[p][i]; } } vector<int> T; for (int i = 0; i < 4; i++...
#include <bits/stdc++.h> int gi() { int x = 0; char ch = getchar(); while (!isdigit(ch)) { if (ch == ? ) return -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return x; } bool eq(int a, int b) { if (b == -1) return 1; return a == b; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { string s, t; cin >> s >> t; std::map<char, bool> ms, mt; for (int i = 0; i < s.size(); i++) { ms[s[i]] = true; mt[t[i]] = true; } for (char x = a ; x <= z ; x++...
#include<bits/stdc++.h> using namespace std; #define ll long long #define endl n #define pb push_back const ll INF=1e18+10; void solve() { ll n,m; cin>>n>>m; string s; cin>>s; string p=s; while(m--) { s=p; for(ll i=0;i<n;i++) { ...
#include <bits/stdc++.h> using namespace std; const int MX = 200005; const int MD = 998244353; void add(int& a, int b) { a += b; if (a >= MD) a -= MD; } void sub(int& a, int b) { a -= b; if (a < 0) a += MD; } int mod_sum(int a, int b) { a += b; if (a >= MD) a -= MD; return a;...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200100; const long long INF = 0x3f3f3f3f3f3f3f3f; long long d[MAXN], h[MAXN]; long long sd[MAXN]; struct str { long long pfx, sfx, rnode, l, r; }; struct st { st *fe, *fd; long long l, r, meio, pfx, sfx, rnode; st(long long x...
#include <bits/stdc++.h> using namespace std; int n; map<int, int, greater<int> > g; int a; int gcd(int a, int b) { while (b != 0) { a %= b; swap(a, b); } return a; } int main() { ios::sync_with_stdio(0); cin.tie(0); ; cin >> n; for (int(i) = (0); (i) < int(n * ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > ans; int a[305], b[305], n; int cur[305]; map<int, vector<int> > m; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; for (int i = 0;...
#include <bits/stdc++.h> using namespace std; long long a, b; long long remove(long long a) { long long temp = 0L; int tens = 1; while (a) { if (a % 10) { temp += tens * (a % 10); tens *= 10; } a /= 10; } return temp; } int main() { cin >> a >> b; ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int lens = s.length(); s = + s; s = s + ; int minn = -1; int a[10000] = {0}; a[0] = 0; int p = 1; for (int i = 0; i <= lens + 1; i++) { if (s[i] == A || s[i] == E || s[i] == I ||...
#include <bits/stdc++.h> using namespace std; namespace std { template <> struct hash<pair<int, int> > { size_t operator()(const pair<int, int>& x) const { long long P = 38923, Q = 109797901; return (size_t)((x.first * P + x.second) % Q); } }; }; // namespace std template <class T> ...
#include <bits/stdc++.h> int main() { std::string first, last, create = fffffffffffff ; int let = 1; std::cin >> first >> last; create[0] = first[0]; int size = first.size(); for (int i = 1; i < size; i++) { if (first[i] < last[0]) { create[let] = first[i]; let++; ...
#include <bits/stdc++.h> using namespace std; int n, x, y, z, a[200005], o, X, Y, Z, XY, XZ, YZ; bool ok(int t) { X = Y = Z = XY = XZ = YZ = 0; for (int i = o; i; i--) { if (X + XY + XZ < t && a[i] <= x) X++; else if (Y + XY + YZ < t && a[i] <= y) Y++; else if (Z + XZ + Y...
#include <bits/stdc++.h> using namespace std; const int N = 1510; int n, arr[N], m; int main() { scanf( %d , &n); int ans = 0; for (int i = 0; i < n; i++) { scanf( %d , &arr[i]); for (int j = 0; j < i; j++) { if (arr[i] < arr[j]) ans ^= 1; } } scanf( %d , &m); w...
#include bits/stdc++.h using namespace std; #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(),(x).end() #define uniq(v) (v).erase(unique(all(v)),(v).end()) #def...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, t; cin >> n >> t; vector<int> arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] == 0 || arr[i] == t) continue; arr[i] %= t; } set<int...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long i, T, n; cin >> T; while (T--) { double h, c, t, ans; cin >> h >> c >> t; double res = h, freq = 1.0, diff = fabs(((h + c) / 2) - t); if (h == t) { ...
#include <bits/stdc++.h> using namespace std; int compare(const void* a, const void* b) { return ((*(pair<long long, long long>*)a).first - (*(pair<long long, long long>*)b).first); } string alfabet = abcdefghijklmnopqrstuvwxyz ; int main() { long long n, x1, x2, k, b; cin >> n; c...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( unroll-loops ) using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (...
#include <bits/stdc++.h> using namespace std; struct BIT { int bit[200005]; void init() { memset(bit, 0, sizeof(bit)); } void add(int k, int x) { k++; while (k < 200005) { bit[k] += x; k += k & -k; } } int get(int k) { k++; int ret = 0; while (...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 5; struct edge { int to, w, next; } G[maxn * maxn]; struct node { int x1, y1, x2, y2, id; } nd[maxn]; long long bit[maxn][maxn], ans[maxn]; int n, m, k, q, head[maxn], tot; vector<int> vec[maxn]; char s[10]; void init(int...
#include <bits/stdc++.h> using namespace std; void boost() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main(void) { boost(); long long n; cin >> n; vector<long long> v(n); for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); i += 1...
#include <bits/stdc++.h> using namespace std; char s[200005], c; int a[200005]; int ans[26]; int main() { int n, k; int maxn = 0; cin >> n >> k; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i < n; i++) { if (s[i] == s[i - 1]) a[i] = a[i - 1] + 1; else ...
#include <bits/stdc++.h> typedef struct { int u, v, w; } Edge; int n; int e; Edge edges[100 * 99]; int d[100]; void bf(int s) { int i, j; for (i = 0; i < n; ++i) d[i] = 1000000000; d[s] = 0; for (i = 0; i < n - 1; ++i) for (j = 0; j < e; ++j) if (d[edges[j].u] + edges[j]....
#include <bits/stdc++.h> using namespace std; int main() { int t, s, q, rel_dist, time; cin >> t >> s >> q; int starts = 1; rel_dist = s; while (rel_dist * q < t) { rel_dist = rel_dist * q; starts++; } cout << starts << endl; return 0; }
#include <bits/stdc++.h> const int inf = INT_MAX; const int MAX = 1e5 + 8; const long long MOD = 1e9 + 7; const int TOT_PRIMES = 1e6 + 9; const int MAX_A = 71; const int LN = 20; using namespace std; bool prime[MAX]; void precompute() { memset(prime, false, sizeof(prime)); for (int i = 2; i < ...
#include <bits/stdc++.h> char str[100010], out[100010], visited[100010]; int n, m, len, ar[100010], counter[256], tree[100010]; void update(int p, int v) { p++; while (p <= n) { tree[p] += v; p += (p & (-p)); } } int query(int p) { int res = 0; while (p) { res += tree[p];...
#include <bits/stdc++.h> using namespace std; vector<int> g[201010]; int tin[201010], tout[201010]; int n, a[201010], m, timer; int is[201010], lvl[201010]; void dfs(int v) { tin[v] = ++timer; for (auto to : g[v]) if (!tin[to]) { lvl[to] = lvl[v] ^ 1; dfs(to); } tout[...
#include <bits/stdc++.h> int d[1005], vis[1005]; int main() { int flag = 0; int n; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &d[i]); vis[d[i]]++; } int ans = 0; for (int i = 1; i <= 100; i++) { if (vis[i] == 1) { ans++; } if (vis[i] ...
#include <bits/stdc++.h> using namespace std; const int len = 6020; int SIZE; const int inf = (int)1e9; int n; vector<int> in; vector<vector<int>> g; int flow[len][len], cost[len][len], pot[len]; int get_p(int u, int v) { return cost[u][v] + pot[u] - pot[v]; } int add_path(int from, int to) { ve...
#include <bits/stdc++.h> using namespace std; int t[111]; int main() { int n, k, m; cin >> n >> k >> m; int sum = 0; for (int i = 0; i < k; i++) { cin >> t[i]; sum += t[i]; } sort(t, t + k); int ans = 0; for (int i = 0; i <= n; i++) { int time = m - sum * i; ...
#include bits/stdc++.h using namespace std; const int MAXN = 3e5+10; int cores[MAXN]; int pos[51]; int n, m; int solve(int cor){ int ans = pos[cor]; for(int i = 1; i <= 50; i++){ if(pos[i] < pos[cor] && pos[i]) pos[i]++; } pos[cor] = 1; return ans; } ...
#include <bits/stdc++.h> using namespace std; string s1, s2; int k, ans; double eps = 0.01; bool ok(int l) { if (s1.compare(0, l, s2, 0, l) != 0) { return false; } for (int i = 0; i < s1.size(); i += l) { if (s1.compare(0, l, s1, i, l) != 0) { return false; } } fo...
#include <bits/stdc++.h> using namespace std; const int maxn = 15; int dis[maxn][maxn]; char str[2000100]; void cal(int p, int q) { memset(dis, 0x3f3f3f3f, sizeof dis); for (int i = 0; i <= 9; i++) { dis[i][(i + p) % 10] = min(dis[i][(i + p) % 10], 1); dis[i][(i + q) % 10] = min(dis[i][(i ...
#include <bits/stdc++.h> using namespace std; bool isprime(long long int n) { if (n < 2) return false; for (long long int i = 2; i <= sqrt(n); i++) if (n % i == 0) return false; return true; } long long gcd(long long int a, long long int b) { if (a == 0 || b == 0) return a + b; e...
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __prin...
#include <bits/stdc++.h> using namespace std; int n, m; int L[36000], R[36000]; int D[36000], U[36000]; int C[36000]; int S[185], H[185], mark[36000], OK[185], tans[36000]; int ak, size; void Link(int r, int c) { S[c]++; C[size] = c; U[size] = U[c]; D[U[c]] = size; D[size] = c; U...
#include <bits/stdc++.h> using namespace std; int main(void) { unsigned long num_bottles = 0; cin >> num_bottles; map<unsigned long, pair<unsigned long, unsigned long> > links; map<unsigned long, unsigned long> counts; for (unsigned long n = 0; n < num_bottles; n++) { unsigned long a = 0, ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> arr(n); int neg = 0; int pos = 0; for (long long i = 0; i < ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr[n]; map<long long, int> mp; vector<long long> summer(n); for (int i = 0; i < n; i++) { int m; cin >> m; int tmp; long long sum = 0; for (int j = 0; j < m; j++) { ...
#include <bits/stdc++.h> using namespace std; vector<int> f[100005]; int n, m, temp, flag = 0; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> temp; f[temp].push_back(i + 1); } int j = 0, ans[100005]; for (int i = 0; i < m; i++) { cin >> temp; if (f[t...
#include <bits/stdc++.h> using namespace std; int get_set(int v, vector<int>& parent) { if (v != parent[v]) { parent[v] = get_set(parent[v], parent); } return parent[v]; } void union_set(int a, int b, vector<int>& parent, vector<int>& rang) { a = get_set(a, parent); b = get_set(b, pare...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, tmp; bool b; cin >> n >> m; vector<int> t(n, -1); while (m--) { cin >> tmp; t[tmp - 1]++; } m = 1000; for (int i = 0; i < n; i++) { m = min(m, t[i]); } cout << m + 1; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T1> void print_list(const T1& a) { cerr << a << endl; } template <typename T1, typename T2> void print_list(const T1& a, const T2& b) { cerr << a << << b << endl; } template <typename T1, typename T2, typename T3> void print_...
#include <bits/stdc++.h> using namespace std; const int maxn = 200009; const long long MOD = 119 << 23 | 1; class { public: struct N { N(int a, int b, int c, int d) { sta[0] = a; sta[1] = b; sta[2] = c; sta[3] = d; } int sta[4]; }; int f[1 << 18];...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long t; cin >> t; for (long long q = 0; q < t; q++) { long long a, b, k; cin >> a >> b >> k; vector<long long> x(a * b); for (long long i = 0; i < a * b; i++) { x[i] = (i % a % b != i % b % a); } ...
#include <bits/stdc++.h> using namespace std; struct zfc { char a[101]; int la; } a[101]; bool cmp(zfc a, zfc b) { return a.la < b.la; } bool cha(zfc a, zfc b) { int flag; for (int i = 0; i <= b.la - a.la; i++) { flag = 0; for (int j = 0; j < a.la; j++) if (a.a[j] != b.a[j ...
#include <bits/stdc++.h> using namespace std; int winner[300005]; int ans[300005]; int range[300005]; int find_winner(int v) { if (v == winner[v]) return v; return winner[v] = find_winner(winner[v]); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long tbnnnnn = n - 2; cout << tbnnnnn * tbnnnnn; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m; const int sz = 1 << 13; vector<int> gos[5001]; int rev[5001]; template <class T> class Dinic { struct _edge { int x, y; T c, rc; _edge(int x, int y, T c, T rc) : x(x), y(y), c(c), rc(rc) {} }; int s, e; int n; ve...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; const double PI = acos(-1.0); const long long EPS = (1e-10); const long long N = 1e5 * 2 + 10; const long long inf = 1e9 * 2 + 10; const ll INF = 1e18 * 2 + 10; const long long...
#include <bits/stdc++.h> using namespace std; long long mult(long long a, long long b, long long p = 1000000007) { long long ans = ((a % p) * (b % p)) % p; return (ans + p) % p; } long long add(long long a, long long b, long long p = 1000000007) { long long ans = (a % p + b % p) % p; return (ans...
#include <bits/stdc++.h> using namespace std; int tree[2000004]; int A[500002]; long long modular_pow(long long base, long long exponent, long long modulus) { long long result = 1; while (exponent > 0) { if (exponent % 2 == 1) result = (result * base) % modulus; exponent = exponent >> 1; ...
#include <bits/stdc++.h> int main() { long n(0); scanf( %ld , &n); std::map<long, long> solutions; bool possible(1); for (int k = 0; k < n; k++) { long number(0), participant(0); scanf( %ld %ld , &number, &participant); if (solutions.find(participant) != solutions.end()) { ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; struct node { int x, p; } a[N]; int d, n, m, top, xx, nexttttt[N], last, q[N]; long long ans; bool cmp(node a, node b) { return a.x < b.x; } int main() { scanf( %d%d%d , &d, &n, &m); for (int i = 1; i <= m; i++) scanf( %d%...
#include <bits/stdc++.h> using namespace std; int n, i, a[3][30], half; long long ans, ans1, ans2; struct node { long long x, y, z; bool operator<(const node& T) const { if (x != T.x) return x < T.x; else if (y != T.y) return y < T.y; else return z < T.z; } ...
#include <bits/stdc++.h> using namespace std; int m, n, i; double o; int main() { cin >> m >> n; for (i = 1; i <= m; i++) o += i * (pow((double)i / m, n) - pow((double)(i - 1) / m, n)); cout << o << endl; return 0; }
#include <bits/stdc++.h> using namespace std; stack<int> s1; char a[200005]; int flag[200005]; int main() { int n, k; scanf( %d%d , &n, &k); memset(flag, 0, sizeof(flag)); scanf( %s , a); int l = 0; for (int i = 0; i < n; i++) { if (l == k) break; if (a[i] == ( ) { ...
#include <bits/stdc++.h> using namespace std; int mult(int a, int b) { long long res = ((long long)a * b) % 1000000007; return res; } int binaryPow(int n, int p) { int acc = 1; while (p) { if (p & 1) acc = mult(acc, n); n = mult(n, n); p /= 2; } return acc; } int mo...
#include <bits/stdc++.h> using namespace std; int getint() { int s = 0, o = 1; char c; for (c = getchar(); c < 0 || c > 9 ; c = getchar()) if (c == - ) o = -1; for (; c >= 0 && c <= 9 ; c = getchar()) s *= 10, s += c - 0 ; return s * o; } const int mod = (int)1e9 + 7; struct ...
#include <bits/stdc++.h> using namespace std; map<int, int> values; map<int, bool> reverseVisited; map<int, vector<int> > rev; stack<int> lastVisited; map<int, bool> visited; map<int, vector<int> > cities; void dfs(int init) { visited[init] = true; for (int i = 0; i < cities[init].size(); i++) {...
#include <bits/stdc++.h> using namespace std; int const N = 100000 + 10; int ans[N], sum, a[N], c[N]; int n, m, block, root, id[N], size[N]; int ne[N << 1], to[N << 1], first[N], tot; int num[N], tim[N]; void add(int u, int v) { ne[tot] = first[u]; to[tot] = v; first[u] = tot++; } struct N...
#include <bits/stdc++.h> int main() { int l, r, a, count; scanf( %d%d%d , &l, &r, &a); count = 0; while (count < a) { if (l > (r + a)) { r = r + a; goto x; } if (r > (l + a)) { l = l + a; goto x; } if (l < r) { l++; count++;...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5, M = 35; int n, m, x; int g[M][M], tot, v[1000][2]; int main() { int T; cin >> T; while (T--) { cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf( %d , &g[i][j]); ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, h, g; vector<int> home, guest; cin >> n; while (n--) { cin >> h >> g; home.push_back(h); guest.push_back(g); } n = home.size(); h = 0; for (int...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n; cin >> n; vector<int> bit(n); for (int i = 0; i < n; i++) { cin >> bit[i]; } bit.push_back(bit[n - 1]); int bit_before = bit[0]; int bit_start = bit[0]; int start = 0; int...
#include <bits/stdc++.h> using namespace std; const int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; int n, m, c[2005][2005]; char s[2005][2005]; bool vis[2005][2005]; bool judge(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m && s[x][y] == . ; } queue<pair<int, int> > q; void bfs(int ...
#include <bits/stdc++.h> using namespace std; int n; bool isPrime(int x) { for (int i = 2; i * i <= x; i++) if (x % i == 0) return false; return true; } int main() { cin >> n; for (int i = (1); i <= (1000); i++) if (!isPrime(n * i + 1)) { cout << i; return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, k; cin >> n >> k; string s; cin >> s; int g, t; for (i = 0; i < n; i++) { if (s[i] == G ) { g = i; } else if (s[i] == T ) t = i; } if (g == t) { cout << YES ; return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { string str, ch[103]; int n; cin >> str >> n; for (int i = 1; i <= n; i++) cin >> ch[i]; sort(ch + 1, ch + 1 + n); for (int i = 1; i <= n; i++) { int len = str.length(); string t = ch[i].substr(0, len); if (t == str)...
#include <bits/stdc++.h> using namespace std; const int MAXV = 210; const int MAXE = 40010; const int inf = 1e9; struct Edge { int u, v, cap, flow, next; } grana[MAXE]; int n, m, E; vector<int> odd, even, sol[MAXV], g[MAXV]; int head[MAXV], dist[MAXV]; int src, snk, k; bool mark[MAXV]; int v...
#include <bits/stdc++.h> using namespace std; struct node { long long c, f, l; }; bool operator<(node a, node b) { return a.f < b.f; } long long n, dx, fx, bn, tot, i, tf, fn, first, xn, sum, xx; node a[100004], b[100004]; bool can; int main() { cin >> n >> dx >> fx; bn = -1; tot = 0; ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const long long MODSQ = 1LL * MOD * MOD; int W[8]; int dp[1 << 7][1 << 7][8][2]; struct matrix { int sz; int data[1 << 7][1 << 7]; }; matrix multiply(matrix& a, matrix& b) { matrix c; c.sz = a.sz; for (int i = ...
#include <bits/stdc++.h> int main() { long long n; while (scanf( %lld , &n) != EOF) { printf( %lld n , n - n / 2 - n / 3 - n / 5 - n / 7 + n / 6 + n / 10 + n / 14 + n / 15 + n / 21 + n / 35 - n / 30 - n / 42 - n / 70 - n / 105 + n / 210); } r...
#include <bits/stdc++.h> using namespace std; const int MAX = 303; const int MOD = 1e9 + 7; long long ncr[MAX][MAX]; map<int, int> cnt; int tot[MAX]; long long dp[MAX][MAX]; vector<int> fin; int get(int a) { int ans = 1; for (int i = 2; (i * i) <= a; i++) { int k = 0; while ((a % i...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7, MAX = 1e5 + 5; long long powN(long long a, long long p) { if (p == 0) return 1; long long z = powN(a, p / 2); z = (z * z) % MOD; if (p % 2) z = (z * a) % MOD; return z; } vector<bool> is_prime(MAX + 1, true); void Sie...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const long long INFLL = 1e18 + 7; const long double EPS = 1e-9; const int MAXN = 1e5 + 17; mt19937 myRand(1337); mt19937_64 myRand64(1337); signed main(void) { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int k; cin ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int n; string s; vector<string> precalced = { !x&x , !(x|y|z) , !x&!y&z , !x&!y , !x&!z&y , ...
#include <bits/stdc++.h> using namespace std; int n, p, cnt, r[1010]; pair<int, int> c[1010]; bool check[1010]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> c[i].second >> c[i].first; if (c[i].second > c[i].first) swap(c[i].second, c[i].first); } sort(c, c + n); ...
#include <bits/stdc++.h> using namespace std; int n, m, u, v, vk = 0, vv = 0; long long res = 0, se = 0; int visited[1000000], selfE[1000000]; vector<vector<int> > G(1000000, vector<int>()); void dfs(int i) { if (visited[i]) return; visited[i] = 1; vk++; for (int u : G[i]) { dfs(u); ...
#include <bits/stdc++.h> using namespace std; int n; double p[1001]; double getp(unsigned long long a, unsigned long long b) { unsigned long long st = 1, ed = 1; double ret; while (st < a) st = st * 10; while (ed < b) ed = ed * 10; if (ed > b) ed = ed / 10; if (st > a) st = st / 10; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, a[5] = {0}; cin >> n; for (int i = 0; i < n; i++) { cin >> x; a[x]++; } int res = a[4]; res += a[2] / 2; a[2] = a[2] % 2; if (a[2] == 1) { res++; a[1] -= 2; } res += a[3]; if (a[1...
#include <bits/stdc++.h> using namespace std; int main() { int n, c; c = 0; string s; cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i] == 8 ) { c += 1; } } cout << min(n / 11, c); }
#include <bits/stdc++.h> using namespace std; inline void init() { ios::sync_with_stdio(false); cin.tie(0); } const int N = 100005; vector<int> adj[N]; bool reach[N][2]; int prv[N][2]; void dfs(int u, int k) { reach[u][k] = true; for (int v : adj[u]) { if (!reach[v][k ^ 1]) { ...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<long long int> v[2]; const long long int N = 3e5 + 5; long long int x[N]; char ch[N]; signed main() { ios ::sync_with_stdio(0), cin.tie(0), cou...
#include <bits/stdc++.h> namespace FASTIO { char buf[1 << 21]; char *p1, *p2; template <typename T> inline void wt(T x, char c = n ) { if (x < 0) { x = -x; putchar( - ); } static char sta[sizeof(T) * 8]; T top = 0; do { sta[top++] = x % 10; x /= 10; } while (x...
#include <bits/stdc++.h> int main() { int N, A, B, C; char Error = 0; scanf( %d , &N); while (N) { A = N % 10; B = N % 100; C = N % 1000; if (A == 1) { N /= 10; } else if (B == 14) { N /= 100; } else if (C == 144) { N /= 1000; } else { ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1; const int M = 1e9 + 7; int n; vector<int> d; vector<pair<int, int> > construct(int cur, vector<int> d) { if (((int)d.size()) == 0) return vector<pair<int, int> >(); vector<pair<int, int> > tmp; for (int i = 0; i < (d[0]); i++) ...
#include <bits/stdc++.h> using namespace std; int n, m, a[110], s[110][110]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); for (int j = 1; j <= a[i]; j++) s[i][j % m + 1]++; } for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; char s[maxn]; int un[maxn], ln[maxn]; int main() { int i, j, k; int ans = INT_MAX, tmp; scanf( %s , s + 1); un[0] = ln[0] = 0; for (i = 1; s[i]; ++i) { if (islower(s[i])) { ln[i] = ln[i - 1] + 1; ...
#include <bits/stdc++.h> int sg[100010], f[100010], pre[100010]; int used[100010]; int n; int cal(int n) { for (int m = 2;; m++) { int tot = m * (m - 1) / 2; if (tot > n) break; tot = n - tot; if (tot % m) continue; int s = tot / m; int t = s + m - 1; int v = sg[t] ...
#include <bits/stdc++.h> using namespace std; int n, j; string a, b; int main() { cin >> n; cin >> a >> b; sort(a.begin(), a.end()); sort(b.begin(), b.end()); j = n - 1; for (int i = n - 1; i >= 0; i--) { if (a[i] <= b[j]) j--; } cout << j + 1 << n ; j = 0; for (i...
#include <bits/stdc++.h> using namespace std; ifstream fin( A.in ); ofstream fout( A.out ); int n, m, i, j, a, b, y, minv = 1000000000, t = 0, ok, nr; char cor[256], s[1001][1001]; int wh[1001][1001]; int viz[1001 * 1001], pred[1001 * 1001], best[1001 * 1001], good[1001 * 1001], st[1001 * 1001]; q...