func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int _ = 1, tc = 1; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const int MAXN = 1e7 + 1; int spf[MAXN]; int d, x, y; void sieve() { for (int i = 1; i < MAXN; i++) spf[i] = i; for (int i = 4; i < MAXN; i += 2) spf[i] = 2; for (int i = 3; i...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 1000; int n; char s[MAXN + 1]; int solve() { int ret = n; for (int i = (0); i < (n); ++i) if (s[i] == 1 || s[n - i - 1] == 1 ) ret = max(ret, 2 * (n ...
#include <bits/stdc++.h> using namespace std; long long const mod = 1000000007; long long const md = 998244353; long long mypow(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } ret...
#include <bits/stdc++.h> using namespace std; long long resp, n, m, tt; int main() { cin >> n >> m; if (m % 2 == 0) { tt = m / 2; tt = tt * (tt + 1) - tt; } else { tt = m / 2; tt = tt * (tt + 1); } for (long long i = 2; i <= n; i += 2) { resp += tt * (n - i + 1); ...
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; int INF = 1e6; long long int n, m; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long int i, j, t, k, x, y, z, N; cin >> n; long long int a[n], b[n], c[n]; for (i = 0; i < n; i++) cin >...
#include <bits/stdc++.h> using namespace std; int arr[1000010]; char ch[1000010]; map<int, int> mp, mp1; vector<int> vec(1000010); int main() { int i, j, k, n, m, t, p, cas = 1; memset(arr, 0, sizeof arr); vec.clear(); mp.clear(); mp1.clear(); int cnt = 0, l = 0, r = 0; stack<int...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, flag = 0; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } sort(v.begin(), v.end()); if (v[0] == 0) { vector<int> v1(n); ...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, m, a, b, count = 0; ; cin >> n >> m; while (cin >> a >> b) { if (a == 1 || b == 1) { count++; } } cout << count; } signed main() { long long test = 1; while (test--) { solve(); ...
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0; cin >> n; bool* V = new bool[n]; bool Back = false; for (int i = 0; i < n; ++i) { cin >> V[i]; if (V[i]) { if (Back && c) c++; c++; Back = false; } else { Back = true; ...
#include <bits/stdc++.h> using namespace std; struct pt { long long x, y; pt operator-(pt b) const { return {x - b.x, y - b.y}; } bool operator==(pt b) const { return x == b.x && y == b.y; } bool operator<(pt b) const { if (x != b.x) return x < b.x; return y < b.y; } }; long long...
#include <bits/stdc++.h> using namespace std; long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p = 0, q = 0, r, s, t, u, v, w, x, y, z, temp = 0, ans = 0, t1, t2, sum = 0; vector<long long int> v1, v2, v3, v4, v5, v6; vector<string> vs1, vs2, vs3, vs4; double f1, f2 = 0, f3, f4; vector<doubl...
#include <bits/stdc++.h> using namespace std; bool vis[1000][1000]; bool lab[1000][1000]; vector<int> ans; int comp[1000][1000]; int cur_ans; int cur_comp = 0; int dfs(int x, int y) { if (!lab[x][y]) { ++cur_ans; return 0; } if (!vis[x][y]) { comp[x][y] = cur_comp; vi...
#include <bits/stdc++.h> using namespace std; inline long long readLL() { long long n = 0; int ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) n = n * 10 + ch - 0 , ch = getchar(); return n; } const int MAX_N = 500000 + 3, MAX_LOG_V = 61; int n; long long a[MAX_...
#include <bits/stdc++.h> long long A[100000]; using namespace std; int main() { long long n, s = 0, m = -100000, a = 0, p; cin >> n; for (int i = 0; i < n; i++) { cin >> A[i]; if (A[i] % 2 == 0 && A[i] > 0) s += A[i]; } std::sort(A, A + n); for (int i = n - 1; i >= 0; i--) { ...
#include <bits/stdc++.h> using namespace std; int i, n, k; string Yes_No, names[] = { a , b , c , d , e , f , g , h , i , j , k , l , m , n , o , p , q , r , s , t , u , v , w , x , y , z , aa , bb , cc , dd , ee , ff ,...
#include <bits/stdc++.h> using namespace std; string gd, str, ask; int q, n, t, ans, tmp, cnt, ara[1000]; int main() { cin >> gd >> str >> n; for (int i = 0; i < gd.size(); i++) ara[gd[i] - a ] = 1; while (n--) { cin >> ask; int in = -1, fin = -1; ans = 0; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; int t1, t2, x1, x2, t0, ans1 = 1000000000, ans2 = 1000000000; double best = 1e16; int main() { cin >> t1 >> t2 >> x1 >> x2 >> t0; if (t1 == t2 && t1 == t0) { cout << x1 << << x2 << n ; return 0; } if (t2 == t0) { cout << 0 ...
#include <bits/stdc++.h> using namespace std; const int MAXR = 1e6 + 1e3; int n; vector<int> b, dp, s; vector<pair<int, int> > v; int main() { ios_base::sync_with_stdio(false); cin.tie(0); while (cin >> n) { b = vector<int>(MAXR, 0); s = vector<int>(MAXR, 0); dp = vector<int>(M...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, i; cin >> n; int la, ra; int cnt00 = 0, cnt01 = 0, cnt10 = 0, cnt11 = 0; for (i = 0; i < n; i++) { cin >> la >> ra; if (la == 1) { if (ra == 0) ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 1e9; const long long LINF = INF * (long long)INF; const double EPS = 1e-7; const int MAX = 20 * 1000 + 47; const int MAS = 2 * 1e5 + 10; const int MOD = 998244353; long long haves, haveb, havec; long long pri...
#include <bits/stdc++.h> using namespace std; struct pii { char C; int fi; int se; }; char A[1000][1000]; void p(int L) { cout << L << endl; for (int i = 1; i <= L; ++i) { for (int j = 1; j <= L; ++j) { cout << A[i][j]; } cout << endl; } } void prin1(pii a...
#include <bits/stdc++.h> using namespace std; int hc(int a, int b) { if (b == 0) return a; return hc(b, a % b); } int main() { int n, a[10010], i, sum = 0; cin >> n; int k = n; for (i = 2; i < n; i++) { a[i] = i; } for (i = 2; i < n; i++) { while (n != 0) { su...
#include <bits/stdc++.h> #pragma GCC optimize( -O3 ) using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } template <typename T> int gaussianElimination(vector<vector<T>> &A, int var = -1) { int N = A.size(), M = A[0].size(); if (var < 0) v...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; template <typename T> void debug(vector<T> x) { for (auto e : x) { cout << e << ; } cout << n ; } void solve() { long long n; cin >> n; long long x = n / 4; long long y = n % 4; if (y % 4 == ...
#include <bits/stdc++.h> using namespace std; int n, m, cur; int fa[1005]; set<int> s1, s2; struct edge { int from, to; char color[2]; } e[100005]; int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } void init() { for (int i = 1; i <= n; i++) { fa[i] = i; } cur = n...
#include <bits/stdc++.h> namespace FastIO { const int SIZE = (1 << 21) + 1; char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int qr; inline void flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; } inline void putc(ch...
#include <bits/stdc++.h> using namespace std; const int N = 5005; const long long MOD = 998244353ll; enum RESULT { OK, WIN }; int n, v[N], nxt[N], prv[N]; long long dp[N][2], acc[N], inv[N]; long long expr(long long e, long long n) { if (n == 0) return 1ll; long long tp = expr(e, n / 2ll); tp ...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, m, i, j; cin >> n >> m; int x, y; vector<vector<int> > adj(n); vector<int> ncon(n, 0); for (i = (0); i < (m); i++) { cin >> x >> y; adj[x - 1].push_back(y - 1); adj[y - 1].push_back(x - 1); ncon...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; const int M = 1e4 + 5; int n, m, w, vis[N], l[N], r[N]; long long a[N], ans[N], s; int main() { cin >> n >> s; long long sum = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } if (sum < s) { ...
#include <bits/stdc++.h> using namespace std; int S, C, Ha, Hb, Wa, Wb; long long Ans; int main() { scanf( %d%d%d%d%d , &C, &Ha, &Hb, &Wa, &Wb); S = sqrt(C); if (Wa > Wb) swap(Ha, Hb), swap(Wa, Wb); if (Wb > S) for (int i = 0; 1LL * i * Wb <= C; i++) Ans = max(Ans, 1LL * i * Hb + 1...
#include <bits/stdc++.h> using namespace std; int n, m; char a[109][109], b[109][109]; void add(int x, int y) { if (a[x][y] == * ) return; if (b[x][y] == 0 ) b[x][y] = 1 ; else ++b[x][y]; } void fill(int x, int y) { if (x > 0 && y > 0) add(x - 1, y - 1); if (x > 0) { ...
#include <bits/stdc++.h> using namespace std; using ui32 = unsigned int; using i64 = long long; using f64 = long double; using ui64 = unsigned long long; void read(int& x) { scanf( %d , &x); } void read(int n, vector<int>& a) { for (int i = 0; i < n; i++) read(a[i]); } void read(int n, int* a) { ...
#include <bits/stdc++.h> using namespace std; int isprime(int n) { int i; for (i = 2; i * i <= n; i++) { if (n % i == 0) return 0; } return 1; } int main() { long long int n, k = 0, i = 0, m, x = 0, y, q, r, s, l, t, a, v0, v1, c, b, j = 0, d = 0, ct = 0, sum = 0, ...
#include <bits/stdc++.h> using namespace std; void GO() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); } const long long INF = 1e9; const long long mod = (1e9) + 7; const int maxn = (int)100; const long double PI = acos(-1.0); const long double eps = 0.000000001; mt19937 rnd(time(0))...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; int n, nn, m; int a[N], b[N], c[N]; int f[N]; inline void add(int i, int v) { for (; i <= n; i += i & -i) f[i] += v; } inline int find(int v) { int i = 0; for (int k = 20; k >= 0; k--) { if (i + (1 << k) <= n && f[i +...
#include <bits/stdc++.h> using namespace std; int main(void) { int m; cin >> m; int C[m]; for (int i = 0; i < m; ++i) cin >> C[i]; int x, y; cin >> x >> y; int sum_1, sum_2; sum_1 = sum_2 = 0; int now = 0; for (int i = 0; i < m; ++i) sum_2 += C[i]; while (sum_1 < x || sum...
#include <bits/stdc++.h> using namespace std; const long long mxN = 52; vector<long long> adj[mxN]; signed main() { long long n; cin >> n; long long x = (n * (n - 1)) / 2; long long a[x - 1][2]; for (long long i = 0; i < x - 1; i++) { cin >> a[i][0] >> a[i][1]; adj[a[i][0]].push_...
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; int n; int dp[maxn][256], a[maxn], cur[8]; vector<int> pos[maxn]; int ok(int len) { int ans = -1; memset(dp, -1, sizeof(dp)); memset(cur, 0, sizeof(cur)); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0...
#pragma GCC optimize( O3 , Ofast , unroll-loops , omit-frame-pointer , inline ) //Optimization flags #pragma GCC option( arch=native , tune=native , no-zero-upper ) //Enable AVX // #pragma GCC target( avx2 ) //Enable AVX #include <bits/stdc++.h> #define int long long using namespace std; #ifdef ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; int a[n]; vector<int> c; for (int i = 0; i < n; i++) a[i] = 0; for (int i = 0; i < n; i++) { int k; cin >> k; c.push_back(k); ...
#include <bits/stdc++.h> using namespace std; long long t, a, b, c, d; long long divide(long long x, long long y) { return (x + y - 1) / y; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> t; while (t--) { cin >> a >> b >> c >> d; if (b >= a) ...
#include <bits/stdc++.h> using namespace std; int main() { int sum = 0, sum1 = 0, c = 0; int n, x, y, d; cin >> n; d = n; while (n--) { cin >> x; sum = sum + x; cin >> y; sum1 = sum1 + y; if (x % 2 == 0 && y % 2 == 1 || (y % 2 == 0 && x % 2 == 1)) c++; } cou...
#include <bits/stdc++.h> using namespace std; const long long inf = ~0ULL >> 1; const int maxV = 3e5 + 10; const int maxE = 6e5 + 10; struct EDGE { int v, nxt; long long w; EDGE() {} EDGE(int vv, int xx, long long ww) { v = vv, nxt = xx, w = ww; } }; EDGE edg[maxE]; int EH[maxV], etot; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 58, SQ = 500; int LE[maxn], LO[maxn], par[maxn], a[maxn], root[maxn], lazy[maxn], m; inline void make(int j) { int lase = -1, laso = -1; int l = j * SQ; for (int i = l; i - l < SQ; i++) { a[i] ^= lazy[j]; if (a[i]) ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; cout << n << endl; while (n--) { cout << 1 ; } }
#include <bits/stdc++.h> using namespace std; int main() { long long n, s, p, k, m, t, x, y, ans, res; cin >> t; while (t--) { cin >> n; long long a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } ans = 0; m = INT_MAX; for (int i = n; i >= 1; i--) ...
#include <bits/stdc++.h> using namespace std; long long max(long long x, long long y) { return x > y ? x : y; } long long min(long long x, long long y) { return x < y ? x : y; } long long gcd(long long p, long long q) { if (q == 0) return p; return gcd(q, p % q); } bool check(long long b, long long ...
#include <bits/stdc++.h> using namespace std; inline long long fexp(long long b, long long e) { long long x = 1; for (; e; e >>= 1, b = (b * b) % (1000000007)) if (e & 1) x = (x * b) % (1000000007); return x; } long long n, k, ok, i, j, x; set<long long> S; signed main() { ios_base::sy...
#include <bits/stdc++.h> using namespace std; int main() { int i = 0; string s; cin >> s; if (s[0] >= a && s[0] <= z ) s[0] = char(s[0] - 32); cout << s << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const static int INF = 1000000000; int t; string input; map<string, string> apa; int main() { scanf( %d , &t); string a, b; string v = void ; apa[v] = void ; while (t--) { cin >> input; if (input == typedef ) { cin >> a...
#include <bits/stdc++.h> using namespace std; int main() { long pos = 0; long long distance; int n, flag = 1; char dir[20]; cin >> n; for (int j = 0; j < n; j++) { cin >> distance >> dir; if (pos == 0 && strcmp(dir, South ) != 0) { flag = 0; } else if (pos == 20000...
#include <bits/stdc++.h> #pragma GCC optimize Ofast #pragma GCC optimize unroll-loops #pragma GCC target sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native using namespace std; class Debugger { public: Debugger(const std::string& _separator = - ) : first(true), separator(_separator) {} ...
#include <bits/stdc++.h> using namespace std; int main() { long long(n), (k); scanf( %lld%lld , &(n), &(k)); ; long long n2 = n; vector<long long> vec; while (n) { vec.push_back(n); if (n - 1 > 0) vec.push_back(n - 1); if (n - 2 > 0) vec.push_back(n - 2); if (n - 3 > ...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; const long long int inf = 0x3f3f3f3f3f3f3f3fLL; const double eps = 1e-9; const double PI = acos(-1); long long int i, j, k; void solve(void); inline bool equal(double a, double b) { return fabs(a - b) < eps; } int main...
#include <bits/stdc++.h> using namespace std; char str[100010]; long long n, l[100010], r[100010], ofs, stk[100010], sa[100010], rk[100010], tmp[100010], hei[100010]; vector<long long> ll[100010], rr[100010]; void build_sa(char *str, long long sa[]); void build_hei(char *str, long long sa[], long long...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, A = 5e5 + 5; vector<vector<long long>> v; long long n, m, val; long long ans[A]; bool vis[A], vis2[A]; void DFS(long long node) { if (vis[node]) return; vis[node] = 1; for (auto child : v[node]) { if (vis[child]) cont...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<set<int> > v(n); vector<set<int> > w(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; if (a > b) v[a].insert(b); else v[b].insert(a);...
#include <bits/stdc++.h> using namespace std; long long cnt(long long a, long long b, long long c) { if (a > b || b > c) return 0LL; if (a == b && b == c) return 1LL; if (a == b && b < c) return 3LL; if (a < b && b == c) return 3LL; if (a < b && b < c) return 6LL; } int main() { long lon...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6; const int md = 1000000009; int n; long long two[maxn + 5], f[maxn + 5], ans; int main() { two[0] = 1; for (int i = 1; i <= maxn; ++i) two[i] = two[i - 1] * 2 % md; scanf( %d , &n); f[n] = 2; for (int i = n - 1; i >= 2; -...
#include <bits/stdc++.h> using namespace std; long long gcd1(long long a, long long b) { if (a == 0) return b; return gcd1(b % a, a); } long long modx(long long base, long long ex) { long long ans = 1LL, val = base; while (ex > 0LL) { if (ex & 1LL) ans = (ans * val) % 998244353LL; va...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int base = sqrt(n); if (base * base == n) { cout << base << << 1 << endl; return; } n = n - base * base; if (n <= base + 1) { cout << n << << base + 1 << endl; } else cout <<...
#include <bits/stdc++.h> using namespace std; int main() { string a, s; cin >> a >> s; sort(s.begin(), s.end()); reverse(s.begin(), s.end()); int k = 0; for (int i = 0; i < a.size() && i < s.size(); i++) { bool found = false; for (int j = k; j < a.size(); j++) { if (s[i] ...
#include <bits/stdc++.h> using namespace std; bool sort_d(long long x, long long y) { return x > y; } int gcd(long long x, long long y) { if (!y) return x; else return gcd(y, x % y); } int lcm(long long x, long long y) { return (x * y) / gcd(x, y); } int main() { int n, m, a, b; ...
#include <bits/stdc++.h> using namespace std; inline int ni() { int a; scanf( %d , &a); return a; } inline double nf() { double a; scanf( %lf , &a); return a; } template <class T> void out(T a, T b) { bool first = true; for (T i = a; i != b; i++) { if (!first) printf(...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; int solve(); void precomp(); int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t = 1; if (0) cin >> t; precomp(); for (int tc = 1; tc <= t; tc++) { if (0 && 0) cout << Case # << tc ...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long a, b, c; cin >> a >> b >> c; cout << a + b + c - 1 << endl; } return 0; }
#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; double __begin; template <typename T1, typename T2, typename T3> struct triple { T1 a; T2 b; T3 c; triple(){}; triple(T1 _a, T2 _b, T3 _c) : a(_a), b(_b), c(_c) {} }; template <typename T1, typename T2, typename T3> bool operator<(const tri...
#include <bits/stdc++.h> using namespace std; int a, n, d, t, v; double ans[100001]; double gets_ans() { double t1 = v * 1.0 / a; if (0.5 * a * t1 * t1 <= d) return t + t1 + (d - 0.5 * a * t1 * t1) / v; return sqrt(2.0 * d / a) + t; } int main() { cin >> n >> a >> d; for (int i = 0; i < ...
#include <bits/stdc++.h> using namespace std; struct dsu { vector<int> p; vector<int> q; vector<int> pre; vector<int> nxt; vector<int> sz; int n; dsu(int _n) : n(_n) { p.resize(n); iota(p.begin(), p.end(), 0); q = p; sz.assign(n, 1); pre.assign(n, -1); ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000000000 ) using namespace std; long long n, cnt[5], fct[1000001]; pair<long long, long long> dp[1000001]; string st; map<char, int> mp; long long pw(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a; long lon...
#include <bits/stdc++.h> using namespace std; const int Nmax = 2005; int n, k; pair<double, double> mij[Nmax * Nmax]; pair<int, int> a[Nmax]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second; for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) ...
#include <bits/stdc++.h> using namespace std; bool vis[500005]; int low[500005], d[500005], par[500005], rnk[500005], lev[500005], timer; vector<int> adj[500005], tree[500005]; vector<pair<int, int>> edges; map<int, map<int, int>> ed, br; int get(int x) { return (par[x] == x ? x : par[x] = get(par[x])); }...
#include <bits/stdc++.h> using namespace std; int n, m, i; int main() { scanf( %d , &n); n -= 10; int a[20]; a[0] = 0; a[1] = 4; a[2] = 4; a[3] = 4; a[4] = 4; a[5] = 4; a[6] = 4; a[7] = 4; a[8] = 4; a[9] = 4; a[10] = 15; a[11] = 4; printf( %d n , (n ...
#include <bits/stdc++.h> const long double eps = 1e-9; const long double pi = fabsl(atan2(0.0, -1.0)); const int INF = 0x7f7f7f7f; const long long LINF = 1ll << 60; const long double LDINF = 1e42; using namespace std; int n, k; string s; int a[110]; int res[110]; int p[110]; void Load() { ci...
#include <bits/stdc++.h> using namespace std; const int maxN = 2 * 300000 + 1000; int block[maxN], start[maxN], fin[maxN]; int main() { ios::sync_with_stdio(0); ; int n, m; cin >> n >> m; string s; cin >> s; set<int> st; st.insert(-1); st.insert(n); for (int i = 0; i < n;...
#include <bits/stdc++.h> using namespace std; int n; struct pt { int ai; int wz; }; int cmp(pt a, pt b) { return a.ai > b.ai; } pt cun[1005]; int ans; int ans1[1005]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &cun[i].ai); cun[i].wz = i; } ...
#include <bits/stdc++.h> using namespace std; int n, k, sum1, sum2; string a; int f[300011]; void solve() { scanf( %d%d , &n, &k); cin >> a; memset(f, -1, sizeof(f)); for (int i = 0; i < n; i++) { if (a[i] != ? ) { if (f[i % k] == -1) f[i % k] = a[i] - 0 ; els...
#include <bits/stdc++.h> using namespace std; struct tree { int maxv[650001]; void set(int x, int d, int o, int l, int r) { if (l == r) { maxv[o] = d; return; } int m = (l + r) / 2; if (x <= m) set(x, d, o * 2, l, m); else set(x, d, o * 2 + 1, m ...
#include <bits/stdc++.h> using namespace std; void solve() { int n, d = 0; long long x, amount; char sign; int quantity; cin >> n >> amount; for (int i = 0; i < n; i++) { cin >> sign >> quantity; if (sign == + ) amount += quantity; else if (amount < quantity) ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool cmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool cmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } int inp() { int x = 0, f = 1; char ch; for (ch = getchar()...
#include <bits/stdc++.h> using namespace std; long long mod = (long long)1000000007; int M, K; int par[100000 + 5]; vector<int> adj[100000 + 5]; long long dp[100000 + 5][11][3]; struct bin_tree_type { int le; int ri; }; bin_tree_type tree[100000 + 5]; long long exp(long long ret, int pow) { ...
#include <bits/stdc++.h> using namespace std; const int dir[8][2] = {{1, 0}, {0, 1}, {1, 1}, {1, -1}, {-1, 0}, {0, -1}, {-1, -1}, {-1, 1}}; int n, m, cnt[1000 + 5][1000 + 5]; char a[1000 + 5][1000 + 5]; void work(int x, int y) { bool flag = true; for (int i = 0; i < 8; i++...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) f = -1; else v = (c & 15); while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15); x = v * f;...
#include <bits/stdc++.h> using namespace std; struct node { int t, o, c; }; char s[4000010]; int n, o[4000010], c[4000010], t[4000010]; void build(int id, int l, int r) { if (r - l < 1) { if (s[r] == ( ) o[id] = 1; else c[id] = 1; return; } int mid = (l + r...
#include <bits/stdc++.h> using namespace std; int main() { stack<char> s; int n, count = 0; char c; cin >> n; for (int i = 0; i < n; i++) { cin >> c; if (s.empty()) s.push(c); else if (s.top() == c) { s.pop(); s.push(c); count++; } else ...
#include <bits/stdc++.h> using namespace std; int i, j; int main() { string str; int b = 0, e = 0, a = 0, r = 0, s = 0; cin >> str; if (str.size() >= 4) for (i = 0; i < str.size() - 3; i++) { for (j = i; j < str.size(); j++) { if (str[j] == b && str[j + 1] == e && str[j...
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; bool debug = 1; const int N = 1e5 + 10; bool vis[N]; int g[N]; int dfs(int i) { vis[i] = 1; if (!vis[g[i]]) { return 1 + dfs(g[i]); } return 1; } int main() { int n, x; scanf( %d , &n); for (int i ...
#include <bits/stdc++.h> using namespace std; inline long long in() { int32_t x; scanf( %d , &x); return x; } inline long long lin() { long long x; scanf( %lld , &x); return x; } inline string get() { char ch[2000010]; scanf( %s , ch); return ch; } inline void read(lo...
#include <bits/stdc++.h> using namespace std; FILE *outt, *inn; const int N = 3e5 + 10; int n, a[N], res[N], ans, c, l, r; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } ans = -1; for (int i = 0; i < n; i++) { l = r = i; while (l > 0 && ...
#include <bits/stdc++.h> using namespace std; int main() { long long int test, i, j, count, flag = 0, n, o1 = 0, o2 = 0, b1, x, y, m, l, z, max1, x1, y1, x2, y2, z1, k, sum, f, r, ans1, min1; cin >> n; long long int a[n]; if (...
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, h, p[N], q[N], bit[N]; void update(int x, int v) { for (; x < n; x += (x + 1) & -(x + 1)) bit[x] += v; } int sum(int x) { int res = 0; for (; x >= 0; x -= (x + 1) & -(x + 1)) res += bit[x]; return res; } void solv...
#include <bits/stdc++.h> using namespace std; long long ara[400005], csum1[400005], csum2[400005]; int main() { int n; scanf( %d , &n); long long sum = 0; for (int i = 0; i < n; i++) scanf( %lld , &ara[i]), sum += ara[i], csum1[ara[i]] += ara[i], csum2[ara[i]]++; for (int i = 1...
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; int mod = 1000000007; db pie = 3.1415926535; int spf[5000005]; int mm = 5000000; int pre[5000005]; void help() { int i; for (i = 1; i <= mm; i++) { spf[i] = i; } for (i = 2; i <= mm; i += 2) { ...
#include <bits/stdc++.h> using namespace std; struct Query { int left; int right; int index; bool operator<(const Query &other) const { return right < other.right; } }; const int N = 1e6 + 100; int a[N]; int xorSum[N]; Query q[N]; int ans[N]; struct FenwickTree { FenwickTree() { fi...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } long long expr(long long n, long long e) { if (e == 0) return 1; if (e & 1) { return n * expr(n, e ^ 1); } else return expr(n, e ...
#include <bits/stdc++.h> using namespace std; const int N = 100009; const long long MOD = 1e9 + 7; int dX[] = {0, 0, 1, -1}; int dY[] = {1, -1, 0, 0}; long long GCD(long long num, long long ones) { return !ones ? num : GCD(ones, num % ones); } string s; map<int, int> mp; long long ans, sum; in...
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef pair<int, int> P; ll gcd(ll a, ll b){return b? gcd(b, a % b): a;} ll quickpow(ll a, ll b){ll res = 1; while(b){if (b & 1) res = res * a; a = a * a; b >>= 1;} return res;} // head const int N = 2e3 + 5, inf = 1e1...
#include <bits/stdc++.h> using namespace std; const int BUFFER_SIZE = 1 << 20; char rb[BUFFER_SIZE], *rp = rb, *rt = rb; inline char read_char() { return rp == rt ? (rt = rb + fread(rb, 1, BUFFER_SIZE, stdin), rp = rb, *rp++) : *rp++; } inline int read_int() { int x = 0; char...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { string s; cin >> s; int x = -1, y = -1; for (int i = 0; i < s.size(); ++i) { for (int j = 0; j < i; ++j) { if (s[i] == s[j]) { x = j, y = i; } } } if (abs(y - x) == 1) { ...