func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; vector<int> solve(vector<int> a) { int n = (int)a.size(); vector<int> dp(n + 1, 1e9); dp[0] = -1e9; vector<int> ret(n); for (int i = 0; i < n; i++) { int x = (int)(upper_bound(dp.begin(), dp.end(), a[i]) - dp.begin()); ret[i] = x; d...
#include <bits/stdc++.h> using namespace std; long long N = 1e9 + 7; void solve() { long long n; cin >> n; vector<long long> v(n); for (int i = 0; i < n; i++) cin >> v[i]; long long b[n]; long long sum = 0; for (int i = 0; i < n; i++) sum += v[i]; long long x = (n * (n + 1)) / 2; ...
#include <bits/stdc++.h> using namespace std; void solve() { map<char, long long> m; for (long long i = 0; i < 26; i++) { char ch; cin >> ch; m[ch] = i; } string str; cin >> str; long long ans = 0, sum = 0; for (long long i = 0; i < str.length() - 1; i++) { sum = ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 3; char ch; bool flag = 0; void read(int &x) { for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == - )) || 1); ch = getchar()) ; for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar()) ; ...
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; long long mod = 1000000007LL; long long mod2 = 998244353LL; int n; int t, q; long long a[100005], b[100005]; long long pre[100005]; struct node { int l, r; long long mx, mn; } tree[100005 << 2]; void build(int id, in...
#include <bits/stdc++.h> using namespace std; long long x, y; vector<long long> cnt; vector<char> sol; bool ok; void solve(long long x, long long y) { if (!x) { if (y == 1) ok = 1; return; } if (!y) { if (x == 1) ok = 1; return; } if (x == y) { if (x == 1) o...
#include <bits/stdc++.h> using namespace std; char c[100003], b[100003]; int ggg[100003]; string a; long long d, e, f, g, ming, oo, ksa, lxy; bool nn, o; int main() { gets(c); c[strlen(c)] = ; a = c; for (int i = 0; i <= a.length(); i++) { if (a.substr(i, 1) == ) { if (...
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; }; Point points[100000]; int gcd(int a, int b) { if (b) return gcd(b, a % b); return a; } int main() { int n; while (scanf( %d , &n) != EOF) { long double A = 0.0; long double b = 0.0; for (int ...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const long long MAX = 6e6 + 10; int w[1000]; int a[1000]; void solve() { int n; cin >> n; memset(a, 0, sizeof(a)); for (int i = 0; i < n; i++) { cin >> w[i]; a[w[i]]++; } int ans = 0; for (...
#include <bits/stdc++.h> using namespace std; int n, x, i, a[200], s1, s2, j = 2; string can = YES ; int main() { cin >> n; cin >> x; x = 7 - x; for (i = 0; i < n * 2; i++) { cin >> a[i]; } for (i = 1; i < n; i++) { s1 = a[j]; s2 = a[j + 1]; if (x == s1 || x == s...
#include <bits/stdc++.h> using namespace std; const int maxN = 502; long long c[maxN][maxN]; long long a[maxN]; int n, m, b, md; int main() { cin >> n >> m >> b >> md; for (int i = 1; i <= n; i++) cin >> a[i]; c[0][0] = 1; for (int i = 1; i <= n; i++) for (int j = 0; j < m; j++) ...
#include <bits/stdc++.h> using namespace std; void print(vector<long long> v) { long long n = v.size(); for (long long i = 0; i < n; i++) { cout << v[i] << ; } } long long power(long long a, long long b) { long long res = 1; while (b != 0) { if (b & 1) { res *= a; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; long long x, d; int cntDist = 0; string inp; cin >> n >> x; getline(cin, inp); for (int i = 0; i < n; i++) { getline(cin, inp); stringstream ss(inp.substr(2)); ss >> d; if (inp[0] == + ) { ...
#include <bits/stdc++.h> using namespace std; int a, b, c, d[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> a >> b >> c; a = a % b; d[a]++; int t; for (int i = 1; i <= 100005; ++i) { t = a * 10 / b; if (t == c) { cout << i; ...
#include <bits/stdc++.h> using namespace std; void _fill_int(int* p, int val, int rep) { int i; for (i = 0; i < rep; i++) p[i] = val; } signed long long GETi() { signed long long i; scanf( %lld , &i); return i; } int N; map<vector<int>, double> M[64]; int st[64], num[64]; double do...
#include <bits/stdc++.h> using namespace std; long long n, m, r, k, tot; int dx[] = {0, -1, 0, 1}; int dy[] = {-1, 0, 1, 0}; struct Cell { long long c, x, y; bool operator<(const Cell &oth) const { return c < oth.c; } }; class Map { private: set<long long> vis; public: bool isVisi...
#include <bits/stdc++.h> using namespace std; int pw(int a, int b) { if (b == 0) return 1; if (b == 1) return a; long long rep = pw(a, b / 2), M = 1e9 + 7; if (b % 2 == 0) return (rep * rep) % M; return (((rep * rep) % M) * a) % M; } int main() { int n, k, m; cin >> n >> m >> k; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j; string ss; cin >> n >> m >> ss; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { if (ss[j] == B && ss[j + 1] == G ) { ss[j] = G ; ss[j + 1] = B ; j++; } } ...
#include <bits/stdc++.h> using namespace std; const int Maxn = 4010; double num1[Maxn]; int num2[Maxn]; double dif[Maxn]; int main() { int n = 0, N = 0; int cnt = 0, cnt1 = 0, cnt2 = 0; double sum = 0; double ans = 100000000.0; scanf( %d , &n); N = 2 * n; for (int i = 0; i < N; i...
/* Author:- Neel_Patel */ #include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(c) (c).begin(),(c).end() #define vi vector<int> #define pii pair<int,int> #define pll pair<long long,long long> #define vll vector<long long> #define priq priority_queue #define...
#include <bits/stdc++.h> using namespace std; long long n, m; long long a[200010]; const long long inf_int = 1e9; pair<long long, long long> S[200010]; long long st[400010]; long long st_[400010]; long long lazy[400010]; void construct_st(int l = 1, int r = n, int i = 0) { if (l == r) { st[i...
#include <bits/stdc++.h> using namespace std; double res, a, b; int main() { int n, k; cin >> n >> k; vector<double> x(n), y(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; if (i) { a = x[i] - x[i - 1]; b = y[i] - y[i - 1]; res += sqrt((a * a) + (b * b));...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int mass[n]; for (int i = 0; i < n; i++) cin >> mass[i]; list<int> lis; int ans = 0; for (int i = 0; i < m; i++) { int temp; cin >> temp; temp--; if (lis.empty()) lis.push_...
#include <bits/stdc++.h> using namespace std; int sst(string g) { int f; stringstream ss; ss << g; ss >> f; return f; } int main() { string s, s1, s2, s3; cin >> s; int max = -1, h = 0; int t = s.size(), x, y, z; if (t < 3) { cout << -1 << endl; return 0; ...
#include <bits/stdc++.h> using namespace std; string binary(long long n) { string result; do result += 0 + (n & 1); while (n >>= 1); reverse(result.begin(), result.end()); return result; } int countSubstr(const string& str, const string& sub) { if (sub.length() == 0) return 0; int ...
#include <bits/stdc++.h> using namespace std; bool compare(const pair<int, int>& i, const pair<int, int>& j) { return i.first < j.first; } int ncr(int n, int k) { if (n < k) return 0; int C[n + 1][k + 1]; int i, j; for (i = 0; i <= n; i++) { for (j = 0; j <= min(i, k); j++) { i...
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 20; int a[maxn]; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int ans = 0; for (int i = n - 1; i >= 0; i -= k) { ans += 2 * (a[i] - 1); } co...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2000; int n, k; int a, b, c, d; int num[MAXN], num_cnt = 0; int rank[MAXN]; set<int> s; vector<int> v; int main() { cin >> n >> k; cin >> a >> b >> c >> d; if (k <= n) { cout << -1 << endl; } else { if (n >= 5) ...
#include <bits/stdc++.h> using namespace std; int a[1234]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , a + i); int mx = 0; for (int i = 0; i < n; i++) if (a[i] > mx) mx = a[i]; for (int u = 1; u <= mx; u++) { for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; int n, m; char mp[444][444]; struct node { int num[8]; } np[444][444]; int dy[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; int dx[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; long long ans; bool in(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; } void cal(in...
#include <bits/stdc++.h> using namespace std; const int MXN = 2e5 + 5; int x[MXN]; int y[MXN]; int d[MXN]; int xr[MXN]; int par[MXN]; int siz[MXN]; int sol[MXN]; int type[MXN]; int basis[30]; stack<pair<int *, int>> stk; vector<array<int, 3>> st[2 << 18]; void change(int &ref, int val) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int ans = 0; while (n--) { string t; cin >> t; int c = k; for (char x : t) if (x == 4 || x == 7 ) c--; if (c >= 0) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int x, neg, zero; cin >> x; int arr[x]; for (int i = 0; i < x; i++) cin >> arr[i]; sort(arr, arr + x); if (arr[x - 1] <= 0) { cout << 1 << << arr[0] << endl; cout << 2 << << arr[1] << ...
#include <bits/stdc++.h> using namespace std; const int N = 200005; const char c[3][4] = { RGB , GBR , BRG }; int sum[3][N]; char s[N]; int main() { int n, k, T; scanf( %d , &T); while (T--) { scanf( %d%d , &n, &k); sum[0][0] = sum[1][0] = sum[2][0] = 0; scanf( %s , s); ...
#include <bits/stdc++.h> using namespace std; const int N = 2005; char s[N]; int main() { int T; scanf( %d , &T); while (T--) { int n, k; scanf( %d%d , &n, &k); scanf( %s , s); getchar(); vector<int> cnt(27, 0); for (int i = 0; i < n; ++i) ++cnt[s[i] - a ]; ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const long long infLL = 90000000000000000; inline bool checkBit(long long n, int i) { return n & (1LL << i); } inline long long setBit(long long n, int i) { return n | (1LL <<...
#include <bits/stdc++.h> using namespace std; int n, m, i, x, y, res; vector<int> g[200200], o[200200]; bool u[3][200200], w[200200], ok = true; char r[200200]; void dfs(int i, int z) { u[z][i] = true; w[i] = true; for (int j = 0; j < g[i].size(); j++) { int k = g[i][j]; if (w[k]) ok...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, lim = 1e7 + 10, key = 1010; int v[lim], r[lim], d[lim]; int main() { int n, m, q; scanf( %d%d%d , &n, &m, &q); for (long long i = 1, _b = (n); i <= _b; i++) for (long long j = 1, _b = (m); j <= _b; j++) scanf( %d , v + key ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; int a, b, c, d, i, j, n, m, k, ans; char mas2[2001][2001]; bitset<2000> mas[2001], ver[2001]; int si[2001]; int main() { gets(mas2[0]); sscanf(mas2[0], %d , &n); for (int _n((n)-1), i(0); i <= _n; i++) ge...
#include <bits/stdc++.h> const int N = 200200; using namespace std; int n, k, s, t; int c[N]; int v[N]; vector<int> g; bool f(int x) { long long cnt = s + s; for (int i = 0; i + 1 < g.size(); i++) { if (g[i + 1] - g[i] > x) return false; int l = x - (g[i + 1] - g[i]); cnt -= min(...
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, t, k, ret; int a[N]; int sum[N]; int main() { scanf( %d%d%d , &n, &t, &k); int all = 0; sum[0] = 1; a[0] = 1; for (int i = 1; i <= t; i++) { scanf( %d , &a[i]); sum[i] = sum[i - 1] + a[i]; if (a[...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, m, r0; cin >> a >> b >> m >> r0; int step = 0; map<int, int> smap; smap[r0] = 0; while (true) { r0 = r0 * a + b; r0 %= m; step++; if (smap.find(r0) != smap.end()) { cout << step - smap[...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int maxn = 100000 + 10; struct Point { double x, y; Point() {} Point(double x, double y) : x(x), y(y) {} } inter; struct Line { int a, b, c, id; Line() {} Line(int a, int b, int c, int id) : a(a), b(b), c(c)...
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265389793238462643383279502884197169; const long long MOD = 1e9 + 7; const int MAXN = 1e6 + 5; const int oo = 1e9; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t, p; cin >> t; while ...
#include <bits/stdc++.h> using namespace std; const long double pi = 2 * acos(0.0); long long infinity = std::numeric_limits<long long>::max(); long long binary_search(long long dp[], long long n, long long p) { long long l, r, mid; l = 0; r = n - 1; sort(dp, dp + n); while (l <= r && l >= 0...
#include <bits/stdc++.h> using namespace std; int main() { double x, y, a, b, t; while (cin >> a >> b) { int n; cin >> n; double p = 1e18; for (int i = 0; i < n; i++) { cin >> x >> y >> t; p = min(p, hypot((x - a), (y - b)) / t); } printf( %.20lf , p); ...
#include <bits/stdc++.h> using namespace std; int n, m; long long a, b[100100], p[100100]; bool check(int num) { long long gongfei = 0LL; for (int i = n - num + 1; i <= n; i++) { int j = i - (n - num); if (b[i] < p[j]) { gongfei += p[j] - b[i]; } } if (gongfei > a) retu...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10, P = 1e9 + 7; int qpow(int a, int n) { int ans = 1; for (; n; a = a * (int64_t)a % P, n >>= 1) if (n & 1) ans = ans * (int64_t)a % P; return ans; } int fac[N], ifac[N], f[N]; int C(int n, int m) { if (m > n) return 0;...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { long long int n, m, x, y; cin >> n >> m >> x >> y; string s[n]; for (int a = 0; a < n; a++) cin >> s[a]; ...
#include <bits/stdc++.h> using namespace std; long long n; long long x[1005], y[1005]; set<pair<pair<long long, long long>, pair<long long, long long> > > S; map<pair<long long, long long>, long long> mp; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } int...
#include <bits/stdc++.h> const long double ACOSPI = (acosl(-1.0)); using namespace std; int main() { int n = 0; int i = 0; int x = 0; long long ans = 0; map<int, long long> m; int a = 0; cin >> n >> x; for (i = 0; i < n; i++) { cin >> a; ans += m[a]; m[x ^ a]++; ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); } int toInt(char xx) { return xx - 0 ; } char toChar(int xx) { return xx + 0 ; } int isDigit(char xx) { return ( 0 <= xx && xx <= 9 ); } bool isCharacter(char xx) { return (( a ...
#include <bits/stdc++.h> using namespace std; struct Dev { int p; int e; long double t; } d[100000]; int n, p; bool fun(long double midTime) { long double energy = 0, t; for (int i = 0; i < n; i++) { t = midTime - d[i].t; if (t > 0) energy += t * d[i].p; } return midTim...
#include <bits/stdc++.h> using namespace std; vector<int> build_z(const vector<int>& a) { int n = (int)(a).size(); vector<int> z(n); int l = 0, r = 0; for (int i = 1; i < n; i++) { z[i] = max(0, min(z[i - l], r - i)); while (i + z[i] < n && a[z[i]] == a[z[i] + i]) z[i]++; if (i + z...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int i, a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); i = 1; while (a[i] == a[0]) { i++; } if (i < n) cout << a[i]; else cout << NO ; return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 1e9 + 10; int n, D[2020][2020]; int add(int& x, int y) { return x = (x + y) % MOD; } int main() { scanf( %d , &n); int ans = 0; D[0][0] = 1; for (int i = 1; i <= 2 * n; i++) { for (int j = 0; j <= i;...
#include <bits/stdc++.h> using namespace std; class abio { static const unsigned BUF_SZ = 65536; FILE *istream, *ostream; char ibuf[BUF_SZ], obuf[BUF_SZ]; bool reached_eof; size_t ip, isz; size_t op, osz; inline void clear_ibuf(void) { ip = isz = 0u; } inline void clear_obuf(void) { ...
#include <bits/stdc++.h> using namespace std; int n, m; int f[300000]; int a[40]; int add(int a, int b) { return (a + b >= m) ? a + b - m : a + b; } void inc(int& a, int b) { a = (a + b >= m) ? a + b - m : a + b; } int main(void) { scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) scanf( %d , &a[...
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int q; cin >> q; for (int d = 0; d < q; d++) { string s, t; cin >> s >> t; int n = s.size(); int m = t.size(); n = n % 2; ...
#include <bits/stdc++.h> using namespace std; const int N = 110; int a[N], b[N]; int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 0; i <= n; i++) scanf( %d , &a[i]); for (int i = 0; i <= m; i++) scanf( %d , &b[i]); if (...
#include <bits/stdc++.h> template <class T> void read(T &a) { a = 0; char x = getchar(); bool f = 0; for (; x < 0 || x > 9 ; x = getchar()) f |= x == - ; for (; x >= 0 && x <= 9 ; x = getchar()) a = (a << 3) + (a << 1) + x - 0 ; if (f) a = -a; } template <class T, class... Args> ...
#include <bits/stdc++.h> using namespace std; long long mo = 998244353; long long bin_fun(long long chto, long long vkak) { if (vkak == 0) return 1; if (vkak == 1) return chto; if (vkak % 2 == 0) return bin_fun(chto * chto % mo, vkak / 2); else return (bin_fun(chto * chto % mo, vkak / ...
#include <bits/stdc++.h> using namespace std; int x, y, z, X, Y, Z, A, B, C, D, E, F; int main() { cin >> X >> Y >> Z >> x >> y >> z >> A >> B >> C >> D >> E >> F; cout << A * (Y < 0) + B * (Y > y) + C * (Z < 0) + D * (Z > z) + E * (X < 0) + F * (X > x) << n ; }
#include <bits/stdc++.h> using namespace std; inline char gc() { return getchar(); } template <class T> int read(T &ans) { ans = 0; char ch = gc(); T f = 1; while (!isdigit(ch)) { if (ch == EOF) return -1; if (ch == - ) f = -1; ch = gc(); } while (isdigit(ch)) ans = an...
#include <bits/stdc++.h> using namespace std; struct note { int a, b, x; } a[100005 * 2]; long long ansa, ansb; int n; int tot; bool cmp(note i, note j) { return i.x > j.x; } int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { long long a1, b, c, d; scanf( %I64d%I64d%I64...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 0) { cout << NO ; } else { cout << YES n ; int i = 1; int a[2 * n]; for (int j = 0; j < n; j++) { a[j] = i; if (j % 2 == 0) { a[j + n] = i + 1; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, ans = 0; cin >> n; pair<int, int> p[n]; int ab, be, le, ri; for (i = 0; i < n; i++) { int r, s; cin >> r >> s; p[i] = make_pair(r, s); } for (i = 0; i < n; i++) { ab = 0, be = 0, le = 0, ri = ...
#include <bits/stdc++.h> using namespace std; #define endl n #define ll long long #define fr(i,s,e) for(ll i=s;i<=e;i++) #define rfr(i,s,e) for(ll i=s;i>=e;i--) #define f(x,m) for(auto x : m) #define ff first #define ss second #define pb push_back #define pp pop_back #define pf push_fro...
#include <bits/stdc++.h> using namespace std; int N, i, j, r[55]; long long m, f[55]; void solve(int n, int p, long long m) { if (n == 0) return; for (int i = 1; i <= n && i <= 2; i++) { if (m <= f[n - i]) { solve(n - i, p + i, m); for (int j = p + i; j <= N; j++) r[j] += i; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = 1e9 + 7, N = 1e5 + 10; int32_t main() { ios::sync_with_stdio(false); cin.tie(NULL); ll a[3]; cin >> a[0] >> a[1] >> a[2]; cout << First << endl; vector<ll> b(3); iota(b.begin(), b.end(), 0); sort...
#include <bits/stdc++.h> const long long RXD = 1e9 + 7; const long long N = 1e5 + 1000; using namespace std; long long C[N][110], a[N], s[N][110], n, m, l, r, K; long long read() { long long x = 0, f = 1, c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); ...
#include <bits/stdc++.h> using namespace std; void readi(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) f = -1; else v = v * 10 + c - 0 ; while (isdigit(c = getchar())) v = v * 10 + c - 0 ; x = v * f; } void ...
#include <bits/stdc++.h> using namespace std; int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> string toString(T x) { ostringstream sout; sout << x; return sout.str(); } vector<string> form(string a, char s) { a += s; vector<st...
#include <bits/stdc++.h> template <class T> void setmax(T &a, T b) { if (a < b) a = b; } template <class T> void setmin(T &a, T b) { if (b < a) a = b; } using namespace std; void read(long long &x) { scanf( %lld , &x); } void read(long long &x, long long &y) { scanf( %lld %lld , &x, &y); } v...
#include <bits/stdc++.h> using namespace std; const int MAN = 110; const int MAM = 60; int dp[MAN][MAM][2]; int INF = -100000000; int main() { string str; int m; while (cin >> str >> m) { int len = str.size(); memset(dp, 0, sizeof(dp)); for (int i = 0; i <= len; ++i) { ...
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-6; const int INF = (int)(INT_MAX - 100); const long long mod = (int)(1e+9 + 7); const int N = (int)(1e5); int main() { int n, s; cin >> n >> s; char d; int p, k; map<int, int, greater<int> > C; map<int, int> V; ...
#include <bits/stdc++.h> using namespace std; int main() { vector<string> V; for (int i = 0; i < 4; ++i) { string s; cin >> s; V.push_back(s); } bool pos = false; for (int r = 0; r < 3; ++r) { for (int c = 0; c < 3; ++c) { int dots = 0, nums = 0; dots += (...
#include <bits/stdc++.h> using namespace std; pair<int, int> a[1010]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %d%d , &a[i].second, &a[i].first); if (a[i].first < a[i].second) swap(a[i].first, a[i].second); } sort(a, a + n); vector<int> ans; ...
#include <bits/stdc++.h> using namespace std; long long cd, w, a, b, kq = 0, mod = 1e9 + 7, fact[1000001], sf[1000001], p[1000001]; void inp() { cin >> cd >> w >> a >> b; } long long bigmod(long long hat, long long base) { if (hat == 0) return 1; long long k = bigmod(hat / 2, ba...
#include <bits/stdc++.h> const int N = 1e3 + 10; using namespace std; int a[N], b[N], c[N]; char str1[N], str2[N], str3[N]; int main() { int tc; cin >> tc; while (tc--) { long long n, k, sum{0}, suma{0}, sumb{0}; cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> a[i]; ...
#include <bits/stdc++.h> using namespace std; int a[3], b[3]; int main() { int n, m; ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; ++i) { int c; cin >> c; a[c % 2]++; } for (int j = 1; j <= m; ++j) { int c; cin >> c; ...
#include <bits/stdc++.h> using namespace std; int main() { int n1, n2, k1, k2; cin >> n1 >> n2 >> k1 >> k2; if (n1 > n2) { cout << First << endl; return 0; } if (n2 > n1) { cout << Second << endl; return 0; } if (k1 < k2) { cout << Second << endl; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005, maxl = 200005, maxsg = 60; int n, f, SG, cnt, maxx; int p[maxl], c[maxl], sg[maxl], A[maxn], B[maxn]; bitset<maxl> ok, have[maxsg]; void sieve(int n) { c[1] = 1; for (int i = 2; i <= n; i++) { if (c[i] == 0) p[++cnt] = i, o...
#include <bits/stdc++.h> using namespace std; void logf(istream_iterator<string> it) {} template <typename T, typename... Args> void logf(istream_iterator<string> it, T a, Args... args) { cout << *it << = << a << ; logf(++it, args...); } const double PI = acos(-1); void solve() { string s...
#include <bits/stdc++.h> using namespace std; int n, q; int m; int lastans; int a[1000][700]; int b[100100]; int sz[1000]; short int cnt[1000][100100]; void remake() { int pos = 0; for (int i = 0; i <= m; i++) { sz[i] = 0; for (int j = 0; j < 700; a[i][j] = 0, j++) { if (a[...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; const int INFINITE = 0x3f3f3f3f; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } template ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 998244353; int n, m, t[1 << 19]; struct segTree { struct { ll kk, bk, kb, bb; } a[1 << 20]; void upd(int p, int l, int r) { int mid = l + r >> 1, v = t[mid] == 1 ? 9 - t[mid + 1] : 0; a[p].kk = a[p...
#include <bits/stdc++.h> using namespace std; int n, m; int a[1111]; int b[1111]; int c[1111]; int vis[1111]; int pos[5]; int cntp; int main() { scanf( %d , &n); bool flag = 0; for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); vis[a[i]]++; } for (int i = 1; i <= n; ++i...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; struct hhh { long long x; long long y; long long v; } c[1000001]; bool operator<(hhh a, hhh b) { return (a.v != b.v ? a.v > b.v : (a.x != b.x ? a.x > b.x : a.y > b.y)); } vector<hhh> v; long long n, m, a, b, h[1...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); struct Aho { enum { ALPHA = 30 }; struct Node { int p = -1, link = -1, superLink = -1; int next[ALPHA], go[ALPHA]; bool leaf = false; vector<int> leaves; char ch...
#include <bits/stdc++.h> using namespace std; int main() { string s, s1; int m; cin >> s; cin >> m; int l, r, k, i, j, d, ind; while (m--) { cin >> l >> r >> k; --l; --r; d = r - l + 1; s1 = s.substr(l, d); for (i = l; i <= r; ++i) { ind = (i - l +...
#include <bits/stdc++.h> using namespace std; const long long maxn = 100005; const long long p = 1e9 + 7; long long a[maxn], n, x, sum; long long st[maxn], top; vector<long long> v; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == -...
#include <bits/stdc++.h> using namespace std; struct NODE { char name[102]; int to; }; struct TRIE { vector<NODE> fold, file; }; TRIE trie[5][10010]; int cnt[5]; int ans_file, ans_fold; int track(int index, int tar, int &layer) { int i, j, count = 0; if (trie[index][tar].fold.size(...
#include <bits/stdc++.h> using namespace std; int T[2 * 10010]; vector<int> G[6010]; vector<int> S[6010]; int P[6010]; int C[6010]; map<int, int> M; bool V[6010]; int mx; int n = 6010; void modify(int p, int value) { for (T[p += n] = value; p > 1; p >>= 1) T[p >> 1] = max(T[p], T[p ^ 1]); } ...
#include <bits/stdc++.h> using namespace std; int cnt[200001], n, par; vector<int> adj[200001]; vector<pair<int, int> > v; void count(int h, int p) { cnt[h]++; for (auto it : adj[h]) if (it ^ p) { count(it, h); cnt[h] += cnt[it]; } } int ct(int h, int p) { for (auto...
#include <bits/stdc++.h> using namespace std; bool f[10]; char s[100005]; int main() { int n, i, j; scanf( %d , &n); scanf( %s , s); for (i = 0; i < n; i++) { if (s[i] == L ) { for (j = 0; j < 10; j++) if (!f[j]) break; f[j] = 1; } else if (s[i] == R ) { ...
#include <bits/stdc++.h> using namespace std; vector<int> pr; bool isp[1001]; void p() { memset(isp, true, sizeof isp); isp[0] = isp[1] = false; for (int i = 2; i < 1001; ++i) { if (!isp[i]) continue; pr.push_back(i); for (int j = 2 * i; j < 1001; j += i) isp[j] = false; } } ...
#include <bits/stdc++.h> using namespace std; int t[6000020][2], tt; void ins(long long x) { int p = 0; for (int i = 40; i--;) { if (!t[p][x >> i & 1]) t[p][x >> i & 1] = ++tt; p = t[p][x >> i & 1]; } } long long qy(long long x) { long long z = 0; int p = 0; for (int i = 40...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; const int MAXN = 5e2 + 10; int n, m; long long adj[MAXN][MAXN]; long long adj_[MAXN][MAXN]; int ans[MAXN][MAXN]...
#include <bits/stdc++.h> using namespace std; int ask(int i, int j) { cout << ? << i << << j << endl; fflush(stdout); int val; cin >> val; return val; } int main() { int n; cin >> n; int a[n + 1]; int index = 1, i, x, y; for (int i = 2; i <= n; i++) { x = ask...