func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 + 10; int n; ll d, m; ll a[N], sum[N]; int main() { cin >> n >> d >> m; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); ll tmp = 0; int ptr = -1; for (int i = 0; i < n; i++) { if (a...
#include <bits/stdc++.h> using namespace std; int main() { vector<int> vec; double ans = 0; int n; cin >> n; vec.resize(n); for (int i = 0; i < n; cin >> vec[i++]) ; sort(vec.rbegin(), vec.rend()); for (int i = 0; i < n; i += 2) ans += vec[i] * vec[i]; for (int i = 1; i < n...
#include <bits/stdc++.h> using namespace std; long long n, i, j, ans, k; int main() { scanf( %I64d%I64d , &n, &k); ans = 1; for (i = 2; i <= n; i++) { if (i == 1) ans = (ans * (k - 1)) % 1000000007; else if (i <= k) ans = (ans * (k)) % 1000000007; else ans = (...
#include <bits/stdc++.h> using namespace std; const long long mxn = 1e6 + 7; const long long mod = 1e9 + 7; const long long inf = 1e18 + 7; int dx[] = {+1, -1, 0, 0}; int dy[] = {0, 0, -1, +1}; pair<int, int> p[mxn]; map<long long, long long> f, s; int n; int a[mxn], ls[mxn]; long long ans; void...
#include <bits/stdc++.h> const int mod = 1000000007; const int gmod = 3; const int inf = 1039074182; const double eps = 1e-9; const long long llinf = 2LL * inf * inf; template <typename T1, typename T2> inline void chmin(T1 &x, T2 b) { if (b < x) x = b; } template <typename T1, typename T2> inli...
#include <bits/stdc++.h> using namespace std; void warp() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); } long long get(vector<long long> &a, vector<long long> &b) { long long ans = 0; long long all = 0; long long n = a.size(); for (long long i = 0; i < n; i++) all += ...
#include <bits/stdc++.h> using namespace std; struct Person { int num; string n1, n2; string final; Person(int num = -1) { this->num = num; } void read(int num = -1) { this->num = num; cin >> n1 >> n2; } }; const int N = 200000; Person b[N], a[N]; int p[N]; int n; boo...
#include <bits/stdc++.h> int main() { int n, i, j, temp; scanf( %d , &n); char s[n]; scanf( %s , &s); for (i = 0; i < n; i++) { if (s[i] > s[i + 1] && i + 1 < n) { printf( YES n ); printf( %d %d , i + 1, i + 2); return 0; } } printf( NO ); return 0; ...
#include <bits/stdc++.h> using namespace std; template <typename T> void pr(vector<T> &v) { for (int i = 0; i < (int)(v).size(); i++) cout << v[i] << ; cout << n ; ; } template <typename T> void pr(vector<vector<T>> &v) { for (int i = 0; i < (int)(v).size(); i++) { pr(v[i]); }...
#include <bits/stdc++.h> using namespace std; int s[10000], g[10000]; set<int> v; int main() { int k, n; cin >> k >> n; for (int i = 0; i < n; i++) { cin >> s[i] >> g[i]; } for (int i = 1; i <= 100; i++) { bool f = 1; for (int j = 0; j < n; j++) { if ((s[j] + i - 1)...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n1 = 0; int n2 = 0; int n4 = 0; int n8 = 0; int n16 = 0; int n32 = 0; int n64 = 0; int n128 = 0; int n256 = 0; int n512 = 0; int n1024 = 0; ...
#include <bits/stdc++.h> using namespace std; int n, a; int A[6]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &A[i]); } sort(A, A + n); printf( %d , A[n / 2]); return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9 + 7; class Compare { public: bool operator()(const string &s, const string &t) const { if (s.size() != t.size()) return (s.size() < t.size()); for (int i = 0, _n = (s.size()); i < _n; i = i + 1) { if (s[i] < t[i]) re...
#include <bits/stdc++.h> using namespace std; int c[200010]; int v[200010]; set<int> not_full; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, q, p, x, k; cin >> n; for (int i = 1; i <= n; ++i) { cin >> c[i]; not_full.insert(i); } cin >> m; while (m-...
#include <bits/stdc++.h> #define taskname #define pb push_back #define eb emplace_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define for0(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> p(n, 0); for (int i = 0; i < n; i++) { int aux; cin >> aux; p[i] = aux - 1; } vector<long long int> dp(n + 1, 0); for (int i = 1; i < n + 1; i++) { dp[i] = (long long int)(dp[i...
#include <bits/stdc++.h> using namespace std; pair<int, int> V[300300][30]; int Lar[300300]; vector<int> Map[300300]; struct tree { tree *L[27]; tree() { for (int i = 0; i < 27; i++) L[i] = NULL; } } root, *point, *point2; int mm[300300], C[300300], depht[300300]; int MAX = 1; tree *...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e5 + 1; const long long LOG = 20; vector<pair<long long, long long> > edg[MAXN]; long long sz[MAXN]; long long link[MAXN]; long long ans[MAXN]; bool used[MAXN]; vector<pair<long long, long long> > ost[MAXN]; long long dp[MAXN][LOG...
#include <bits/stdc++.h> using namespace std; map<string, int> mp; int sum[1111], cnt, po[1111], Sum[1111]; char s[1111][1111], ss[1111][1111]; int a[1111]; int find(char *s) { if (mp[s]) return mp[s]; mp[s] = ++cnt; strcpy(ss[cnt], s); return cnt; } int main() { int n; while (sc...
#include <bits/stdc++.h> using namespace std; const int limit = 320; int v[100000]; int dp[limit][100000]; int n; static int bruteforce(int p, int k) { int cnt = 0; while (p < n) { cnt++; p = p + v[p] + k; } return cnt; } int main() { cin >> n; for (int i = 0; i < n; ...
#include <bits/stdc++.h> const int inf = 0x3f3f3f; const long long INF = 1ll << 61; using namespace std; int n, x; typedef struct Node { int t, h, m; }; Node aa[2000 + 55], bb[2000 + 55]; void init() { memset(aa, 0, sizeof(aa)); memset(bb, 0, sizeof(bb)); } int cnt1, cnt2; bool input()...
#include <bits/stdc++.h> using namespace std; int main() { map<long long int, long long int> m; long long int a, x, n, o, i, j; long long int sum = 0; cin >> n; for (i = 0; i < n; i++) { cin >> a >> x; m[a] = max(m[a], x); } cin >> o; for (i = 0; i < o; i++) { cin >...
#include <bits/stdc++.h> using namespace std; const int PI = 3.141592653589793; const int inf = 1000111222; const int mod = 1000000007; const int N = 200007; bool comp(const pair<int, int> &a, const pair<int, int> &b) { int len = a.second - a.first + 1; int len2 = b.second - b.first + 1; if (len...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int cnt = 1, T[N * 31][2], n; long long t, a[N * 31]; void insert(long long x) { int u = 0; for (int i = 30; i >= 0; i--) { int v = (x >> i) & 1; if (!T[u][v]) { memset(T[cnt], 0, sizeof(T[cnt])); a[cnt] =...
#include <bits/stdc++.h> long long gcdfun(long long x, long long y) { if (y == 0) return x; else return gcdfun(y, x % y); } using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n, k = 1, flag = 0, ans ...
#include <bits/stdc++.h> using namespace std; double tick() { static clock_t oldt, newt = clock(); double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC; oldt = newt; return diff; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long a[4][4] = {0}; long long k; ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { string d; cin >> d; bool f = true; for (int i = 0; i < d.size(); i++) { if (d[i] == 0 ) { d.erase(i, 1); f = false; break; } } if (f) { d.erase(0, 1); } cout <<...
#include <bits/stdc++.h> using namespace std; struct node { int x, y; } p[111]; int g[1111][1111]; int vis[1111]; int n; void dfs(int u) { vis[u] = 1; int i; for (i = 0; i < n; i++) { if (g[u][i] && !vis[i]) { dfs(i); } } } int main() { cin >> n; int i, ...
#include <bits/stdc++.h> using namespace std; long long n, R, RP[70]; int T, nm = 1, o; int GCD(int a, int b) { return !a ? b : GCD(b % a, a); } void BT(int a) { if (a == 62) { if (o == 0) return; if (o % 2 == 0) RP[nm]--; else RP[nm]++; return; } BT(a + 1);...
#include <bits/stdc++.h> #pragma GCC optimize( 03 ) using namespace std; int n, m, q, x[200100], y[200100], dad[400100]; bool viz[400100]; int find(int p) { if (dad[p] == p) return p; return dad[p] = find(dad[p]); } void join(int a, int b) { dad[find(a)] = find(b); } int main() { ios_base::s...
#include <bits/stdc++.h> using namespace std; int main() { int a[110], n, sum = 0, i; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (i = 0; i < n - 1; i++) { if (a[i] == a[i + 1]) { sum++; i++; } } printf( %d n , sum / 2); return 0; ...
#include <bits/stdc++.h> const int N = 1e3 + 5; int n, m, q, sum[N][N]; int opt(int x, int y) { return (__builtin_popcount(x) + __builtin_popcount(y)) & 1; } int calc(int x, int y, int opt) { return opt == 0 ? sum[x][y] : x * y - sum[x][y]; } long long I(int x, int y, int r, int c) { long long...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int c = 0, r, d, a, s; a = n; while (n) { if (n >= 10) { r = n / 10; n -= r * 10; n += r; c += r * 10; } else {...
#include <bits/stdc++.h> using namespace std; string tolower(string str) { for (int i = 0; i < str.size(); i++) str[i] = tolower(str[i]); return str; } int main() { int n; cin >> n; vector<string> store; for (int i = 0; i < n; i++) { string str; cin >> str; store.push_b...
#include <bits/stdc++.h> int inp() { char c = getchar(); while (c < 0 || c > 9 ) c = getchar(); int sum = 0; while (c >= 0 && c <= 9 ) { sum = sum * 10 + c - 0 ; c = getchar(); } return sum; } int x[200010], s1, s2, n; bool check(int lim) { int l = -2147483647; ...
#include <bits/stdc++.h> using namespace std; int dp[55][35555], n, m, a[35555], las[35555], pre[35555], now; struct LT { int mx, lazy; } tr[517171]; void U(int x) { tr[x].mx = max(tr[x << 1].mx, tr[x << 1 | 1].mx); } void D(int x) { tr[x << 1].lazy += tr[x].lazy; tr[x << 1].mx += tr[x].lazy; ...
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 1, ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) x = (x << 1) + (x << 3) + ch - 0 , ch = getchar(); return f * x; } ...
// zukonit14 - Kunal Raut #include<bits/stdc++.h> using namespace std; // #include ext/pb_ds/assoc_container.hpp // #include ext/pb_ds/tree_policy.hpp // using namespace __gnu_pbds; // template<class T> // using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_updat...
#include <bits/stdc++.h> using namespace std; string s; map<string, bool> vis; void ReadCube(string cube) { int _4D[4][6] = {{0, 1, 2, 3, 4, 5}, {0, 3, 2, 1, 5, 4}, {0, 5, 2, 4, 1, 3}, {0, 4, 2, 5, 3, 1}}; for (int i = 0; i < 4; ++i) { ...
#include <bits/stdc++.h> using namespace std; #define MAXN (int)(1e5 + 5) #define MAXL 20 #define F first #define S second #define endl n #define MOD (lli)(1e9 + 9) #define MOD2 (lli)(1e9 + 7) #define lli long long int #define sz(a) int(a.size()) #define DEBUG if (0) cout << aqui << endl;...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; const int mod = 1e9 + 7; const int N = 1e6 + 10; const long long INF = 1e18; long long power(long long x, long long y) { long long t = 1; while (y > 0) { if (y % 2) y -= 1, t = t * x % mod; else y /= 2...
#include <bits/stdc++.h> using namespace std; int main() { long long x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; int n; cin >> n; vector<long long> l(n + 1), t(n + 1); l[0] = 0; t[0] = 0; for (int i = 1; i <= n; i++) { char c; cin >> c; l[i] = l[i - 1]; t[i] ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const int N = 1200031; int n, ar[N], w[N]; int gcd(int a, int b) { while (a && b) a > b ? a %= b : b %= a; return a + b; } vector<pair<int, int> > edges; vector<int> entries[N]; int sz[N]; long long ANS[N]; vector<int...
#include <bits/stdc++.h> int a, n; int main() { scanf( %d %d , &n, &a); int res = 0; if (a % 2 == 1) printf( %d n , a / 2 + a % 2); else printf( %d n , n / 2 - a / 2 + 1); return 0; }
#include <bits/stdc++.h> using namespace std; int compare(const void* a, const void* b) { return (*(int*)a - *(int*)b); } int main() { int n; long long k, sum2, sum3; int a[100005], c[100005]; long long b[100005]; int i, j, count; cin >> n; cin >> k; for (i = 0; i < n; i++) scanf( ...
#include <bits/stdc++.h> using namespace std; long long x, y, z, t1, t2, t3; int main() { scanf( %lld%lld%lld%lld%lld%lld , &x, &y, &z, &t1, &t2, &t3); puts(abs(x - y) * t1 >= abs(x - y) * t2 + abs(x - z) * t2 + 3 * t3 ? YES : NO );...
#include <bits/stdc++.h> using namespace std; long long n, l, r, k, c, i; string s; int main() { ios_base::sync_with_stdio(0); cin >> n; if (n == 0) { cout << a << n ; return 0; } while (n > 0) { l = 1; r = 100000; k++; while (l < r) { ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long MAX = 100005; const long double PI = 3.14159265359; const long double G = 9.807; const long long INF = 1e18; const long double EPS = 1e-6; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T smin(T &a, const T &b) { return a > b ? a = b : a; } template <typename T> inline T smax(T &a, const T &b) { return a < b ? a = b : a; } inline void add(long long &l, const long long &r) { l = (l + r) % (long long)1...
#include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); ; string s; getline(cin, s); long long int ans = 0, cur = 0; int sg = +1; for (int i = (0); i < (int((s).size())); i += (1))...
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 5; int mark[2][M]; int h[2][M]; int32_t main() { ios_base::sync_with_stdio(false); ; int n, k; cin >> n >> k; for (int i = 0; i < 2; i++) { string s; cin >> s; for (int j = 0; j < n; j++) if (s[j] =...
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; int n; vector<int> a[200]; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed; cin >> n; int k = (1 + sqrt(1 + 8 * n)) / 2, x = 1; cout << k << endl; for (int i = 1; i <= k; i++) { for (in...
#include <bits/stdc++.h> using namespace std; vector<int> adj[100000]; vector<int> hs; bool possible(int wantvalue, int maxcost) { const int nhs = hs.size(); long long cost = 0; int i = 0; for (int j = 0; j <= nhs; j++) { while (j - i > wantvalue) { cost -= (hs[j - 1] - hs[i]); ...
#include <bits/stdc++.h> using namespace std; long double Ax, Ay, Bx, By, Cx, Cy, a11, a12, a21, a22, det; bool flag; void f(double x, double y) { double tx, ty; tx = a11 * x + a12 * y; ty = a21 * x + a22 * y; cerr << tx << << ty << n ; tx = fabs(tx); ty = fabs(ty); tx += 1e-11...
#include <bits/stdc++.h> using namespace std; vector<int> a, b, d1, d2; int main() { int n, l; cin >> n >> l; a.resize(n); b.resize(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < n; ++i) { cin >> b[i]; } a.push_back(l + a[0]); b.push_back(l...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long dp[11][2][1010][1010]; string s, t; long long bt(int K, bool f, int a, int b) { if (K == 0) return 0; long long& ref = dp[K][f][a][b]; if (ref != -1) return ref; ref = INT_MIN; if (f) { ref = bt...
#include <bits/stdc++.h> using namespace std; void model(vector<int>& a, const vector<pair<int, int> >& v) { for (pair<int, int> p : v) swap(a[p.first], a[p.second]); } bool check(int n, const vector<pair<int, int> >& v) { vector<int> a(n); for (int i = 0; i < n; ++i) a[i] = i; model(a, v); ...
#include <bits/stdc++.h> using namespace std; int t; long long x, y; int main() { cin >> t; while (t--) { cin >> x >> y; if (x == y) cout << x << endl; else if (x > y) cout << x + y << endl; else cout << y - y % x / 2 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long long int q; cin >> q; for (long long int l = 0; l < q; l++) { long long int n; cin >> n; long long int ans = 0; while (n != 1) { long long int track = ans; while (n % 2 == 0) { n = n / 2; ...
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n, i, j; cin >> t; while (t--) { cin >> n; if (n % 2 == 0) { cout << n / 2 << << n / 2; } else { for (i = 3, j = 0; i * i <= n; i++) { if (n % i == 0) { cout << n / i <...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2E5 + 10; const int P = 1E9 + 7; int n, q; struct node { int l, r, id; } qu[MAXN]; int a[MAXN], pri[1100], cnt; int num[1000001]; long long ans[MAXN]; long long bin[MAXN]; vector<int> dir[1000001]; vector<int> rec[MAXN]; int po...
#include <bits/stdc++.h> using namespace std; int main() { int i; string a[3]; cin >> a[0] >> a[1] >> a[2]; for (i = 0; i < 3; i++) { if ((a[i] == rock ) && (a[(i + 1) % 3] == scissors ) && (a[(i + 2) % 3] == scissors )) { break; } if ((a[i] == scissors ) && (...
#include <bits/stdc++.h> using namespace std; int main() { int n, pos, lo, hi; while (cin >> n >> pos >> lo >> hi) { int cnt = 0; if (lo == 1 && hi == n) { cout << 0 << endl; continue; } int xlo = abs(pos - lo); int xhi = abs(pos - hi); if (lo - 1 >= 1 &...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int M = 1e5 + 5; int main() { ios_base::sync_with_stdio(false); int tt; cin >> tt; while (tt--) { int n, i, j; cin >> n; vector<long long> v[N]; for (i = 0; i < n; i++) { int m; lon...
#include <bits/stdc++.h> using namespace std; const int N = 300010; const int MOD = 1000000007; int n, m; int a[N], b[N]; char mm[10010]; vector<int> f[N]; long long w[2010]; int RM(int a) { if (!m) return 0; int t; for (int i = m - 1; i >= 0; i--) { t = w[i] % a; w[i] /= a; ...
#include <bits/stdc++.h> using namespace std; char s[500005], t[500005]; long long ans; int n, k, now, tmp; int main() { scanf( %d %d n , &n, &k); fread(s + 1, 1, n, stdin); getchar(); fread(t + 1, 1, n, stdin); s[n + 1] = # ; if (k == 1) return printf( %d n , n), 0; for (now = 1;...
#include <bits/stdc++.h> using namespace std; template <typename TF> void write_debug_output(ostream &out, TF const &f) { out << f << std::endl; } template <typename TF, typename... TR> void write_debug_output(ostream &out, TF const &f, TR const &...rest) { out << f << ; write_debug_output(ou...
#include <bits/stdc++.h> using namespace std; const int N = 1000007, M = 5000007; const long long INF = 1e14; inline void read(int &first) { char c = getchar(); while ((c < 48) || (c > 57)) c = getchar(); first = c ^ 48; c = getchar(); while ((c >= 48) && (c <= 57)) { first = first * 1...
#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; int ara[200010]; string res; string str; void func(int le, int ri, int chk, int past) { if (res.size() < str.size()) { res = str; } if (le > ri) { return; } if (chk == 0) { if ((past < ara[le]) && (ara[le] < ara[ri]))...
#include <bits/stdc++.h> const int N = 300300; using namespace std; struct edge { int ul, ur, dl, dr, a, al, ar; long long xl, xr; }; edge comb(edge a, edge b, int sa, int sb) { edge g; g.a = max(a.a, b.a); g.al = a.al; g.xl = a.xl; g.ul = a.ul; g.dl = a.dl; g.ar = b.ar; ...
#include <bits/stdc++.h> using namespace std; int c[100010]; long long ans; int main() { int n, x; scanf( %d%d , &n, &x); for (int i = 1; i <= n; i++) scanf( %d , &c[i]); sort(c + 1, c + n + 1); if (n < x) { ans = 0; for (int i = 1; i <= n; i++) ans += (long long)c[i] * (x - i + ...
#include <bits/stdc++.h> using namespace std; #define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define INP(arr,n) for(int a=0;a<n;a++)cin>>arr[a] #define OTP(arr,n) for(int a=0;a<n;a++)cout<<arr[a]<< #define ll long long int #define pb(v,a) v.push_back(a) int main() { IOS;int t = 0;cin...
#include <bits/stdc++.h> using namespace std; string p[3][2] = {{ lios , liala }, { etr , etra }, { initis , inites }}, s; pair<int, int> kind(string q) { int l = q.length(); if (l >= 4 && q.substr(l - 4, 4) == p[0][0]) return pair<int, int>(0, 0); if (l >= 5 && q.substr(l - 5, 5) == p[0][1]) retur...
#include <bits/stdc++.h> using namespace std; long long n, sb, a[4], data1[100001], num[100001]; void merge(int l, int r) { int mid = (l + r) / 2; int i = l, j = mid + 1, k = 0; while (i <= mid && j <= r) { if (data1[i] < data1[j]) num[k++] = data1[i++]; else num[k++] = dat...
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) #pragma comment(linker, /STACK:336777216 ) const int sqrtn = 300; const int inf = 987654321; const int sz = 1e5 + 5; const int mod = 1e9 + 7; int n, vis[sz]; string str; int main() { scanf( %d , &n); cin >> str; ...
#include <bits/stdc++.h> using namespace std; namespace IO { const int maxn(1 << 21 | 1); char *iS, *iT, ibuf[maxn], obuf[maxn], *oS = obuf, *oT = obuf + maxn - 1, c, st[20]; int f, tp, len; inline char getc() { return iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1...
#include <bits/stdc++.h> using namespace std; int ly1[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int ly2[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, ...
#include <bits/stdc++.h> using namespace std; struct Query { int p, s, id; bool operator<(const Query &b) const { return (s < b.s); } }; int main() { int n; scanf( %d , &n); vector<int> a(n); for (int i = 0; i < n; ++i) scanf( %d , &a[i]); int m; scanf( %d , &m); vector<Query...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int mod = 1e9 + 7; const int N = 4e5 + 10; const int inf = 1e9; int n, k, m; map<pair<int, int>, int> vis; int mx[N << 2], tag[N << 2]; int a[N]; void pd(int p, int k) { mx[p << 1] += k; tag[p << 1] += k; mx[p <...
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const long long linf = (long long)1e18; const double eps = (double)1e-8; const int mod = (int)1e9 + 7; const int maxn = (int)1e5 + 5; const int MX = (int)1e5; const int PRIME = 31; string s, t; int n, m, first; long long hs[ma...
#include <bits/stdc++.h> using namespace std; long long int a[123456], b[123456]; vector<long long int> v1, v2, v3; map<long long int, long long int> mp; map<string, long long int> mps; map<char, long long int> mpc; int main() { long long int f = 0, x = 0, l = 0, r = 0, n, i; cin >> n; for (i ...
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); int main() { ios::sync_with_stdio(0); cin.tie(0); map<string, vector<int> > mda; int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { string s; cin >> s...
#include <bits/stdc++.h> using namespace std; int main() { long long tc, n, arr1[100005], m, arr2[100005], count = 0, even = 0, even2 = 0, odd = 0, odd2 = 0; cin >> tc; while (tc--) { cin >> n; for (int i = 0; i < n; i++) { cin >> a...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; bool adj[4005][4005]; int edges[4005]; int main() { int n, m, res = INF; cin >> n >> m; while (m--) { int a, b; cin >> a >> b; adj[a][b] = adj[b][a] = 1; edges[a]++; edges[b]++; } for (int i = ...
#include <bits/stdc++.h> using namespace std; long long maxn = -1e18; long long minn = 1e18; long long mod = 1000000007; long long ans = 0; long long cur = 0; long long tong = 0, tong2 = 0; long long cnt = 0; long long k, l; string s; long long n, m, x, y; long long b[100005]; long long was[20...
#include <bits/stdc++.h> using namespace std; namespace scanfuck { const int L = (1 << 21) + 1; struct io { char ibuf[L], *iS, *iT, obuf[L], *oS, *oT, c, st[55]; int f, tp; void flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; } void putc(char x) { *oS++ = x; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000006; char s[maxn]; int ans[8] = {1869, 8196, 1986, 8691, 6198, 1689, 1968}; int main() { while (scanf( %s , s) != EOF) { int len = strlen(s); int A[10] = {0}; for (int i = 0; i < len; i++) { A[s[i] - 0 ]++; ...
#include <bits/stdc++.h> using namespace std; template <typename T> vector<T>& operator--(vector<T>& v) { for (auto& i : v) --i; return v; } template <typename T> vector<T>& operator++(vector<T>& v) { for (auto& i : v) ++i; return v; } template <typename T> istream& operator>>(istream&...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double inf = 1e20; const double pi = acos(-1.0); const int maxp = 10001; int dcmp(double d) { if (fabs(d) < eps) return 0; return d > eps ? 1 : -1; } inline double sqr(double x) { return x * x; } struct point { do...
#include <bits/stdc++.h> const int a[250] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1, 52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-9; int n, m, k; long long dp[35][35][100]; long long dfs(int l, int r, int t) { if (l * r < t) return 999999999; if (l > r) swap(l, r); if (dp[l][r][t] != -1) return dp[l][r][t]; if (t == 0) { ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-8; int main() { ios_base::sync_with_stdio(0); map<long long, bool> mapa; long long in[200009]; long long n, len, x, y; cin >> n >> len >> x >> y; for (int i = 0; i < n; i++) { cin >> i...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); long long l, r; long long g(long long x) { long long t = 1; while (t <= x) t *= 10; return (t - 1 - x) * x; } int n, m; const char let[] = ACGT ; char buf[1600]; int len[16]; int a[16][16]; vector<int> st; s...
#include <bits/stdc++.h> using namespace std; long long int mul(long long int a, long long int b) { return ((a % int(1e9 + 7)) * (b % int(1e9 + 7))) % int(1e9 + 7); } long long int add(long long int a, long long int b) { return ((a % int(1e9 + 7)) + (b % int(1e9 + 7))) % int(1e9 + 7); } long long in...
#include <bits/stdc++.h> using namespace std; long long read() { long long 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 * 10 + c - 0 ; c = getchar(); } return x * F; }...
#include <bits/stdc++.h> using namespace std; const int maxn = 300005; int N, K, val[maxn], prime[30000], cnt, limit, ans; bool del[maxn]; void pre() { for (int i = 2; i <= N; i++) { if (!val[i]) prime[++cnt] = i; val[i]++; for (int j = i + i; j <= N; j += i) val[j]++; } } int ma...
#include <bits/stdc++.h> using namespace std; int get(int l, int n) { int v1, v2; cout << ? << l << endl; fflush(stdout); cin >> v1; cout << ? << (l + n / 2 - 1) % n + 1 << endl; fflush(stdout); cin >> v2; return v2 - v1; } int main() { int n; cin >> n; int l, r...
#include <bits/stdc++.h> using namespace std; int dp[2010][2010]; int main() { int n, h, i; scanf( %d%d , &n, &h); dp[0][0] = 1; for (i = 1; i <= n; i++) { int x; scanf( %d , &x); x = h - x; if (x < 0) { printf( 0 n ); return 0; } if (x >= 1) { ...
#include <bits/stdc++.h> using namespace std; unordered_map<char, long long> s, p; bool check() { long long any = s[ ? ]; long long sub = 0; for (auto it = p.begin(); it != p.end(); it++) { if (s[it->first] > p[it->first]) return false; else if (s[it->first] < p[it->first]) ...