func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); int N; vector<int> V; cin >> N; int X; for (int i = 0; i < N; i++) { cin >> X; V.push_back(X); } int ans = 100100, t = 0; for (int i = 1; i <= 100; i++) { ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1 << 28; const long long LINF = 1ll << 61; const long long mod = 1e9 + 7; unsigned long long base = 1000000007; char a[2][2011], s[2011]; int n, m; unsigned long long hsl[2][2011], hsr[2][2011], hss[2011], pw[2011]; unsigned long long...
#include <bits/stdc++.h> using namespace std; int main() { int n; bool temp = false; cin >> n; string *arr = new string[n]; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) { if (arr[i][0] == O && arr[i][1] == O ) { temp = true; cout << YES <<...
#include <bits/stdc++.h> using namespace std; int n, a[500 + 5]; long long ans = 1LL << 60; void cal(int x) { if (!x) return; long long sum = 0; for (int i = 1; i <= n; ++i) { if (a[i] % x == 0 || (a[i] / x >= x - 1 - a[i] % x)) sum += a[i] / x + bool(a[i] % x); else retu...
#include <bits/stdc++.h> using namespace std; const int cap = int(1e5) + 1; vector<int> graph[cap]; vector<int> cnt(cap); void dfs(int i, int h) { cnt[h] ^= 1; for (int j : graph[i]) dfs(j, h + 1); } int main() { int n; cin >> n; int p; for (int i = 2; i <= n; ++i) { cin >> p...
#include <bits/stdc++.h> using namespace std; struct node { int days; int index; }; bool compare(node lhs, node rhs) { return (lhs.days < rhs.days); } int main() { int n, k; int sum = 0; scanf( %d%d , &n, &k); node a[n + 1]; for (int i = 1; i <= n; i++) { scanf( %d , &a[i].da...
#include <bits/stdc++.h> using namespace std; vector<set<int> > g; vector<int> ans; vector<bool> used; void dfs(int v, int p) { used[v] = true; ans.push_back(v); for (set<int>::iterator i = g[v].begin(); i != g[v].end(); i++) { if (!used[*i] && g[*i].count(p)) dfs(*i, v); } } int mai...
#include <bits/stdc++.h> using namespace std; int main() { double t, n, i, x, mx, mn, f, j, s, r, y, c, m, k = 0, W, H, x1, y1, w, h, w1, h1, l, u, d, sw, sh, X, Y, X1, X2, R; cin >> t; while (t--) { cin >> W >> H; cin >> x >> y >> x1 >> y1; cin >> w >> h; w1 = abs(x - x1...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; const int maxm = 2e1 + 7; int n, m; int ar[maxn]; char ch[maxn]; int main() { int k; scanf( %d%d , &n, &k); int d = (n - k) / 2; for (int i = 0; i < n; i++) { ch[i] = 0 + (i % (d + 1) == d); } printf( %...
#include <bits/stdc++.h> #pragma GCC diagnostic ignored -Wunused-result #pragma GCC diagnostic ignored -Wunused-function using namespace std; namespace { namespace shik { template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf( %d , &x); } void _R(int64_t &x) { scanf( % SCNd6...
#include <bits/stdc++.h> using namespace std; bool adj[110][110]; short color[110]; bool ok = true; int n, m; void dfs(int node, int ccolor) { color[node] = ccolor; for (int i = 0; i < m; i++) { if (adj[node][i]) { if (color[i] == 0) { dfs(i, ccolor * (-1)); } else if...
#include <bits/stdc++.h> using namespace std; using ll = long long int; using ld = long double; template <typename Arg1> void debug_out(const char* name, Arg1&& arg1) { cerr << name << = << arg1 << ] << n ; } template <typename Arg1, typename... Args> void debug_out(const char* nam...
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > v; vector<long long> q; int main() { long long n, d, a, b, xx, x, y, sum = 0; cin >> n >> d >> a >> b; for (long long i = 0; i < n; i++) { cin >> x >> y; xx = x * a + y * b; v.push_back(make_pair(xx, ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const long long INFL = 1e18 + 123; const double PI = atan2(0, -1); mt19937 tw(960172); long long rnd(long long x, long long y) { static uniform_int_distribution<long long> d; return d(tw) % (y - x + 1) + x; } const int MAXN =...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int row = -n; row <= n; ++row) { int top = n - abs(row); for (int i = 0; i < abs(row); i++) { cout << ; } for (int i = 0; i < top; i++) { cout << i << ; } for (int ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > adj[100005]; int m, n, a, b, w; long long D[100005]; int Tr[100005]; void dijk(int x) { Tr[x] = 0; D[x] = 0; set<pair<long long, int> > s; s.insert({0, x}); while (s.size() > 0) { long long d = (*s.begin()).first...
#include <bits/stdc++.h> using namespace std; inline void out(int a) { printf( %d n , a); } inline void out(int a, int b) { printf( %d %d n , a, b); } inline void outf(double a) { printf( %3.lf n , a); } inline void outf(double a, double b) { printf( %3.lf %3.lf n , a, b); } inline void base() { ios_bas...
#include <bits/stdc++.h> using namespace std; const int MAX = 173, MAX2 = 400; const int foo = INT_MIN; char s[MAX]; int slen, l, an[MAX]; int B[MAX][MAX], F[MAX][MAX], R[MAX][MAX][MAX]; bool hh[MAX][MAX]; inline bool good(int i, int j) { return i <= j; } int full(int i, int j); int best(int i, int ...
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; struct IO { char buf[(1 << 20)], *p1, *p2; char pbuf[(1 << 20)], *pp; IO() : p1(buf), p2(buf), pp(pbuf) {} ~IO() { fwrite(pbuf, 1, pp - pbuf, stdout); } inline char gc() { if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, ...
#include <bits/stdc++.h> using namespace ::std; const long long maxn = 5e5 + 500; long long seg[4 * maxn]; long long dp[maxn]; long long q[maxn]; long long houp[maxn]; long long a[maxn]; map<long long, long long> last; map<long long, vector<long long> > las; void bild() { fill(seg, seg + 4 * maxn, -...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; int m, n, nword, R[MAXN], len[MAXN]; map<string, int> M; string s[MAXN]; vector<int> adj[MAXN], adj2[MAXN]; int super[MAXN], nsuper, number[MAXN], low[MAXN], cnt; int best[MAXN], rep[MAXN]; bool inStack[MAXN]; int st[MAXN], nst; ...
#include <bits/stdc++.h> using namespace std; map<int, bool> mp; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int a; cin >> a; mp[a] = 1; } for (int i = 0; i < 1010; i++) { if (mp[i] && mp[i + 1] && mp[i + 2]) { cout << YES << endl; retu...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; char s[1010]; int a[1010], num[1010], b[30]; int prime[1010], notprime[1010]; priority_queue<pair<int, char> > pq; set<pair<int, int> > st; pair<int, int> c[1010]; int ans[1010]; int cnt; void init() { for (int i = 2; i ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; template <typename T> T gcd(T a, T b) { T c; while (b) { c = b; b = a % b; a = c; } return a; } template <typename T> T powmod(T a, T b) { T res = 1; a %= mod; while (b) { if (b...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; pair<long long, long long> res; long long a[N]; void dfs(long long cur, long long cnt, long long sum) { if (!cur) { res = max(res, {cnt, sum}); return; } else { int p = upper_bound(a + 1, a + N, cur) - a; --p;...
#include <bits/stdc++.h> int cmpfnc(const void* a, const void* b) { return (*(int*)a - *(int*)b); } int main() { int i, n; scanf( %d , &n); int arr[300005]; for (i = 0; i < n; i++) scanf( %d , &arr[i]); qsort(arr, n, sizeof(int), cmpfnc); long long int sum = arr[0]; long long int count =...
#include <bits/stdc++.h> using namespace std; int main() { string str, s1, s2 = < ; stack<char> delm; vector<string> re; getline(cin, str); for (int i = 0; i < str.size(); i++) { if (str[i] == && delm.empty()) { s1 = < ; delm.push(str[i]); } else if (!delm.empty...
#include <bits/stdc++.h> #pragma GCC optimize(3) inline void read(int &x) { scanf( %d , &x); } inline void read(long long &x) { scanf( %I64d , &x); } inline void read(double &x) { scanf( %lf , &x); } inline void read(long double &x) { double tmp; read(tmp); x = tmp; } template <class T> inli...
#include <bits/stdc++.h> using namespace std; int N; signed long long W[303030]; vector<pair<int, int>> E[303030]; signed long long best[303030]; signed long long ma; void dfs(int cur, int pre) { vector<signed long long> C; for (auto& e : E[cur]) if (e.first != pre) { dfs(e.first, cu...
#include <bits/stdc++.h> using namespace std; const long long INF = numeric_limits<long long>::max() / 4; struct Edge { long long from, to, cap, flow, index; Edge(long long from, long long to, long long cap, long long flow, long long index) : from(from), to(to), cap(cap), flow(flow), inde...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; int sum[maxn], t, n, q, l, r; char s[maxn]; set<int> v[4 * maxn + 10]; int main() { scanf( %d , &t); while (t--) { sum[0] = 0; scanf( %d%d%s , &n, &q, (s + 1)); for (int i = 1; i <= n; i++) { sum[i] = s...
#include <bits/stdc++.h> using namespace std; const int base = 1e9; const int maxn = 1e3; const int logn = 20; const int inf = 2e9; const int alpha = 26; const int my_hash = 29; const long long l_inf = 4e18; const long long mod = 1e9 + 7; const double pi = acos(-1.0); const double eps = 1e-9; in...
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) using namespace std; void fil() {} long long int ipow(long long int base, long long int k, long long int M) { base %= M; k = k % (M - 1); long long int total = 1; while...
#include <bits/stdc++.h> using namespace std; using LL = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; LL sum = 0; for (int i = 0; i < n; ++i) { LL a; cin >> a; sum += a; } LL base = 1LL * (1 + n) * n / 2; LL add = (sum - ba...
#include <bits/stdc++.h> using namespace std; int T; int N, X, Y, Ord[100005]; bool print; int A[100005], Freq[100005], Freq2[100005], F[100005]; vector<int> V; vector<int> Ap[100005]; set<pair<int, int> > S1, S2; int Res[100005]; void Read() { scanf( %d%d%d , &N, &X, &Y); for (int i = 1; i ...
#include <bits/stdc++.h> using namespace std; int i, j, k, n, m, t; long long l, r = 1e14, md, res = 1e18, a[200500], b[200500]; struct sb { long long x, y; double t; bool operator<(const sb a) const { return t > a.t; } } s; bool chk(long long sb) { priority_queue<struct sb> q; int i, j,...
#include <bits/stdc++.h> using namespace std; long long n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; if ((n % 2) == 0) cout << n / 2; else cout << n / 2 + 1; return 0; }
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long a = 0; long long b = 0; void dfs(vector<vector<int>> &g, vector<bool> was, int v, int lvl) { was[v] = true; if (lvl % 2 == 0) a++; else b++; for (int x : g[v]) { if (!was[x]) dfs(g, was, x, lvl +...
#include <bits/stdc++.h> using namespace std; char t[100][100]; int main(int argc, char* argv[]) { unsigned int n; cin >> n; for (unsigned int i = 0; i < n; ++i) for (unsigned int j = 0; j < n; ++j) cin >> t[i][j]; unsigned int r = 0; for (unsigned int i = 0; i < n; ++i) { for (uns...
#include <bits/stdc++.h> using namespace std; struct V { int x, y; }; bool conf(V left, V right) { if (left.x != right.x) return left.x < right.x; return left.y < right.y; } int main() { V arr[9]; for (int i = 0; i <= 7; i++) scanf( %d %d , &arr[i].x, &arr[i].y); sort(arr, arr + 8, c...
#include <bits/stdc++.h> using namespace std; const int inf = (int)2e9; const long long mod = 1000000007; int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; long long powmod(long long a, long long p) { long long ans = 1; a %= mod; while (p) { if (p & 1) ans *= a; p /= 2; a *= a; ...
#include <bits/stdc++.h> using namespace std; using namespace std; void transform(int input) { if (input) { transform((input - 1) / 26); putchar(65 + (input - 1) % 26); } } int main() { int n, x, y; string input; for (scanf( %d , &n); n--;) { cin >> input; if (ssca...
#include <bits/stdc++.h> using namespace std; const int MAX = 105; int main() { ios::sync_with_stdio(false); int n; cin >> n; int x; cin >> x; for (int i = 0; i < n; i++) { x = 7 - x; int a, b; cin >> a >> b; if (a == x || b == x || 7 - a == x || 7 - b == x) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); string s; cin >> s; char x = a ; int y; set<int> arr[26]; for (int i = 0; i < s.length(); i++) { y = s[i] - x; arr[y].insert(i); } int q; cin >> q; int n, ans = 0; for (in...
#include <bits/stdc++.h> using namespace std; int a[1000005]; int main() { int n, m; while (~scanf( %d%d , &n, &m)) { if (n == 1) { printf( YES n%d n , m); } else if (n == 2) { if (m == 0) { printf( NO n ); } else { printf( YES n0 %d n , m); ...
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; long long int expo(long long int base, long long int exponent, long long int mod) { long long int ans = 1; while (exponent > 0) { if (exponent % 2 == 1) { ans *= base; ans %= mod; } ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); double fRand(double fMin, double fMax) { double f = (double)rand() / RAND_MAX; return fMin + f * (fMax - fMin); } template <class T> T min(T a, T b, T c) { return min(a, min(b, c)); } template <class T> T max(T a, ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1001000; int f[maxn], rx[maxn], ry[maxn], ans[maxn], pre_rx[maxn], pre_ry[maxn]; struct node { int num, x, y; } mp[maxn]; int find(int x) { while (x != f[x]) x = f[x] = f[f[x]]; return f[x]; } void merge(int x, int y) { int x...
#include <bits/stdc++.h> using namespace std; struct vec { long double x, y; bool operator==(const vec &a) const { return x == a.x && y == a.y; } bool operator<(const vec &a) const { if (a.x != x) return x < a.x; return y < a.y; } vec operator+(const vec &a) const { return {x + a.x, ...
#include <bits/stdc++.h> const double PI = acos(-1.0); using namespace std; char p[102][102]; int main() { int n; scanf( %d n , &n); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) p[i][j] = getchar(); getchar(); } bool foo = true; for (int i = 1; i <= n; ++i) { ...
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1 >> s2; int n = s1.length(), p = 0, a = 0, p2 = 0; for (int i = 0; i < n; i++) if (s1[i] == + ) p++; int m = n - p; for (int i = 0; i < n; i++) { if (s2[i] == ? ) a++; else if (s2[i...
#include <bits/stdc++.h> using namespace std; void printopt(int p) { for (int i = p / 2; i; i--) printf( 4 ); for (int i = p / 2; i; i--) printf( 7 ); } char s[100000 + 2]; char s47[100000 + 2]; int n; bool fopt(int i, int ddif47) { if (abs(ddif47) > n - i) return 0; int j = i; for (; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using pii = pair<int, int>; constexpr int N = 300001; struct Ed { int u, v; bool s; }; vector<pii> g[N], t[N]; int d[N], low[N], biconn[N]; bool scored[N], vis[N]; ...
#include <bits/stdc++.h> using namespace std; int search(long long int *array, int start_idx, int end_idx, long long int search_val) { if (start_idx == end_idx) return array[start_idx] <= search_val ? start_idx : -1; int mid_idx = start_idx + (end_idx - start_idx) / 2; if (search_val ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 1e5 + 10; const int mod = 998244353; const int N = 2e5 + 6; int pk = 30; int a[N]; struct Trie { static const int N = 15101000, M = 2; int ne[N][M], rt, L, sum[N], ans[N]; void ini() { fill_n(sum...
#include <bits/stdc++.h> using namespace std; template <class T> inline bool fs(T &x) { int c = getchar(); int sgn = 1; while (~c && c < 0 || c > 9 ) { if (c == - ) sgn = -1; c = getchar(); } for (x = 0; ~c && 0 <= c && c <= 9 ; c = getchar()) x = x * 10 + c - 0 ; x *= ...
#include <bits/stdc++.h> using namespace std; bool mark[100]; vector<pair<int, int> > coors; void DFS(int ver) { mark[ver] = true; for (int i = 0; i < coors.size(); i++) if ((coors[ver].first == coors[i].first || coors[ver].second == coors[i].second) && !mark[i]) DFS(i...
#include <bits/stdc++.h> using namespace std; const int PMAX = 61; long long shift[PMAX]; inline int logbin(long long x) { return 63 - __builtin_clzll(x); } inline void modif(int p, long long k) { shift[p] += k; shift[p] %= (1ll << p); } int main() { int q; scanf( %d , &q); for (int i ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return a % b ? gcd(b, a % b) : b; } int lcm(int a, int b) { return a * b / gcd(a, b); } int prime(long long n) { if (n < 2) return 0; if (n == 2 || n == 3) return 1; if (n % 6 != 1 && n % 6 != 5) return 0; for (long long i = 5...
#include <bits/stdc++.h> using namespace std; class myistream { static const int maxsize = 1000007, tmpsize = 50; char *s, *tmp; char *cur, *upperbound; FILE *fp; bool last_read; bool end_of_file; bool to_return; void upd() { int num = fread(s, sizeof(char), maxsize, fp); ...
#include <bits/stdc++.h> using namespace std; int main() { int R = 0; int d = 0; int n = 0; cin >> R; cin >> d; cin >> n; int x; int y; int r; int counter = 0; double low = 0; double high = 0; for (int i = 0; i < n; i++) { cin >> x; cin >> y; cin...
#include <bits/stdc++.h> using namespace std; bool checktwo(long long int n){if(n==0){return false;}else{return (ceil(log2(n)) == floor(log2(n)));}} long long int powerof2lte(long long int n){int p = (long long int)log2(n);return (long long int)pow(2, p);} long long int numdigits(long long int n){return...
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[131072], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 131072, stdin), p1 == p2) ? EOF : *p1++; } inline void read(int& x) { x = 0; char c = gc(); while ...
#include<bits/stdc++.h> using namespace std; const int maxn=1e4+10; int vis[maxn]; int a[maxn]; int main() { int T; scanf( %d ,&T); while(T--){ int n,d; scanf( %d%d ,&n,&d); for(int i=1;i<=n;i++){ scanf( %d ,&a[i]); } for(int ...
#include <bits/stdc++.h> using namespace std; char to_da(char c) { if (c >= A && c <= Z ) return c; else return c - 32; } char to_xiao(char c) { if (c >= A && c <= Z ) return c + 32; else return c; } int main() { string s; int a; while (cin >> s >> a...
#include <bits/stdc++.h> using namespace std; int main() { set<string> S; long n; string a; cin >> n; for (long i = 0; i < n; i++) { cin >> a; string s = ; long j = 0; while (j < a.size()) { if (a[j] == k ) { long k = j; while (a[k] == k ) ...
#include <bits/stdc++.h> using namespace std; int read() { int nm = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()) nm = nm * 10 + c - 0 ; return nm * f; } long long n, x, y; char s[300010]; int main() { ...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int pre[N]; int find(int x) { if (!pre[x]) return x; return pre[x] = find(pre[x]); } int d[510][510]; struct point { int x, y, z; void read() { scanf( %d%d%d , &x, &y, &z); } } a[N]; int type[N]; int main() { int...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, n, x, y; cin >> a >> b >> c >> d >> n; if (c < d) swap(a, b), swap(c, d); cout << max(0, n - (c - 1) * a - (d - 1) * b) << ; if (b * d >= n) { cout << n / d; return 0; } cout << b + (n - b * d) / c;...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int lim = sqrt(n) + 1; if (!(n & 1)) { cout << n / 2 << endl; return 0; } for (long long int i = 3; i <= lim + 1; i++) { if (n % i == 0) { cout << (n - i) / 2 + 1 << endl...
#include <bits/stdc++.h> using namespace std; char g[10][10]; int ax[10 * 10], n; bool use[10 * 10]; int q[2][100], ct[2], vst[8][8]; int dx[9] = {0, 0, 0, 1, -1, 1, 1, -1, -1}; int dy[9] = {0, 1, -1, 0, 0, -1, 1, -1, 1}; bool check(int x, int y) { if (x < 0 || y < 0 || x >= 8 || y >= 8) return 0; ...
#include <bits/stdc++.h> using namespace std; int N, M; bool conn[8][8]; int a, b; int v[8]; int cur; bool used[8][8]; int best, cur2, cur3, cur4, ans; int main() { cin >> N >> M; for (int i = 0; i < M; i++) { cin >> a >> b; conn[a][b] = conn[b][a] = true; } for (int i = 0;...
#include <bits/stdc++.h> using namespace std; long long int lar(long long int a, long long int b) { return ((a >= b) ? a : b); } long long int les(long long int a, long long int b) { return ((a <= b) ? a : b); } int main() { string s; cin >> s; vector<string> v; long long int a = 0, ...
#include <bits/stdc++.h> using namespace std; long long arr[200005]; bool can(long long val, long long n, long long k) { int m = (n + 1) / 2; long long sum = 0; for (int i = m; i <= n; i++) { if (val > arr[i]) sum += val - arr[i]; else break; } if (sum <= k) r...
#include <bits/stdc++.h> const int oo = 0x3f3f3f3f; template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; } template <typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; } template <typename T> T read(T &first) { int f = 1; ...
#include <bits/stdc++.h> using namespace std; int main() { int num = 0; int n; cin >> n; int d; int sh[n]; cin >> d; for (int i = 0; i < n; i++) cin >> sh[i]; for (int i = 0; i < n; i++) { for (int k = i + 1; k < n; k++) { if (abs(sh[i] - sh[k]) <= d) num += 2; } ...
#include <bits/stdc++.h> using namespace std; map<int, int> Map; int n, m, i, j; long long ans; string s; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> s; m = s.size(); bool cnt[30]; for (j = 0; j < 26; j++) cnt[j] = 0; for (j = 0; j < m; j++) cnt[s[j] - a ]...
#include <bits/stdc++.h> int main() { long long int n; scanf( %lld , &n); printf( %lld n , n / 2 + 1); long long int count1 = 0; long long int count2 = 1; for (int i = 1; i <= n; i++) { if (i % 2 == 0) { count2++; } else { count1++; } printf( %lld %lld n...
#include <bits/stdc++.h> const double eps = 1e-4, pi = acos(-1.0); const int maxS = 1e3 + 13; const int maxT = 20; const long long MOD = 1e9 + 7; using namespace std; struct point { int x, y; }; struct rs { int x, y, z; }; int n, m, i, j, k, x, y, z, S, T, ii, s, t, l, r, pos, len; int tot...
#include <bits/stdc++.h> #define int long long using namespace std; const int MAX = 505; int n, MOD, fact[MAX], C[MAX][MAX], f[2][MAX * MAX]; int getMaxInv(int x) { return (x - 1) * x / 2; } int32_t main() { #ifdef ACM freopen( input , r , stdin); #endif cin >> n >> MOD;...
#include <bits/stdc++.h> using namespace std; pair<int, int> s[300005]; int main() { int n, a, b, c, d, start, len; scanf( %d %d %d %d %d %d %d , &n, &a, &b, &c, &d, &start, &len); for (int i = 0; i < n; i++) scanf( %d %d , &s[i].first, &s[i].second); long long sum = 0, res = 0, ans = start; i...
#include <bits/stdc++.h> using namespace std; int main(void) { int x1, y1, x2, y2; scanf( %d%d%d%d , &x1, &y1, &x2, &y2); int res = abs(x1 - x2) + 1 + (x1 == x2); res += abs(y1 - y2) + 1 + (y1 == y2); printf( %d n , res * 2); }
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; long long int tc, cnt = 0, number, many, total = 0, query, require; int rmove[8] = {1, 0, -1, 0, -1, 1, -1, 1}; int cmove[8] = {0, 1, 0, -1, 1, -1, -1, 1}; long long int modpow(long long int x, long long int y, long long int...
#include <bits/stdc++.h> using namespace std; int n, s, k; int arr[51]; char color[51]; int mem[51][2501]; int solve(int i, char last, int num, int sum) { if (sum >= k) { return 0; } if (~mem[i][sum]) return mem[i][sum]; int ch1 = 1e9; for (int j = 0; j < n; j++) { if (arr[j]...
#include <bits/stdc++.h> using namespace std; int calc(int n) { for (int i = 1; i <= 10; ++i) { int tmp = n - i, cnt = 0; for (; tmp; ++cnt, tmp /= 10) ; if (cnt == i) return n - i; } } char s[1000050], ss[1000050]; int ans[1000050], a[1000050], n, m; char f[4][1000050], re...
#include <bits/stdc++.h> using std::cin; using std::cout; const long long N = 1e6 + 17, mo = 1e9 + 7; long long f[N][2], n, h[N]; inline long long min(long long x, long long y) { return x > y ? y : x; } inline long long quickmod(long long x) { return x >= mo ? x - mo : x; } signed main() { std::ios::s...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int head[444444], to[444444], cap[444444], dist[444444], nxt[444444], cur[444444], tnode[444444], mx, ans, tp, cnp, L[444444], R[444444]; int n, m, s, t, cnt, x, y, z; bool used[444444]; void addedge(int s, int t, int cps, int cpt) { ...
#include <bits/stdc++.h> using namespace std; vector<set<int> > arr; long long res = 0; void dfs(int vertex, int prev, int level) { for (int v : arr[vertex]) { if (v == prev) { continue; } if (level == 2) { res++; continue; } else { dfs(v, vertex, leve...
#include <bits/stdc++.h> using namespace std; const long long M = 51123987; long long C[151][151]; int dp[2][3][51][51][51] = {}; int main() { int n; string s; cin >> n >> s; auto cur = dp[0]; auto nex = dp[1]; int u = (n - 1) / 3 + 1; int t[3] = {}; for (int i = 0; i < n; i++)...
#include <bits/stdc++.h> int main() { int arr[1001] = {0}; int n, i, others, temp; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &temp); arr[temp]++; } for (i = 0; i < 1001; i++) { if (!arr[i]) continue; others = n - arr[i]; if (arr[i] - others > 1) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, k, ans = 1, p, temp; cin >> n >> k; if (n == k) { cout << 1; return 0; } if (k == 1) { cout << n; return 0; } long long s, e, m; s ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimization( unroll-loops, no-stack-protector ) #pragma GCC target( avx,avx2,fma ) using namespace std; const int INF = int(1e9) + 99; int main() { ios::sync_with_stdio(false), cin.tie(0); cout.tie(0); int n; string s; c...
#include <bits/stdc++.h> int main() { int x, y, z, i, j, k, a, b, c, n, m, t, mat[210210]; scanf( %d , &t); long long w, sum; while (t--) { scanf( %d %lld , &n, &w); j = -1; sum = 0; c = 0; for (x = 0; x < n; x++) { scanf( %d , &mat[x]); if (mat[x] >= (w +...
#include <bits/stdc++.h> int main() { int num; std::cin >> num; int arr1[num], arr2[num], sum1 = 0, sum2 = 0; for (int i = 0; i < num; i++) { std::cin >> arr1[i]; sum1 |= arr1[i]; } for (int i = 0; i < num; i++) { std::cin >> arr2[i]; sum2 |= arr2[i]; } std::cou...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 37; const long long INF = 1LL << 61; int n, u, r; long long sum; int a[MAX_N], b[MAX_N], k[MAX_N], p[MAX_N]; void dfs(int dep, bool f) { if ((u - dep) % 2 == 0) { long long s = 0; for (int i = 1; i <= n; ++i) { s += (l...
#include <bits/stdc++.h> using namespace std; long long n, k, A[100005], B[100005], C[100005], sum, val; pair<long long, long long> E[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> A[i]; C[A[i]]++;...
#include <bits/stdc++.h> using namespace std; long long T, n, s, sum; inline int read() { char ch = getchar(); int x = 0, f = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while ( 0 <= ch && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(...
#include <bits/stdc++.h> using namespace std; int dp[1000005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int a[n + 1]; for (int i = 0; i < n; i++) cin >> a[i]; dp[0] = 1; for (int i = 0; i < n; i++) { set<int> s; for (int j = 1;...
#include <bits/stdc++.h> long long p = 1e9 + 7, x; using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> x; while (cin >> x) cout << ((((x + 4) / 4) % p) * (((x + 6) / 4) % p)) % p << n ; }
#include <bits/stdc++.h> using namespace std; const long long int maxn = 200005, mod = pow(10, 9) + 7; void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void create_array(vector<long long int>& a) { for (long long int i = 1;; i++) { if (i % 3 != 0 and i % 10 != 3) { ...