func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; const int CNTV = 105; const int LENSUFF = 11; const int K = 4; const int MOD = 1e9 + 9; struct node { int go[K], suff, p, pch, lev, cr; node() { memset(go, -1, sizeof go); suff = p = pch = cr = -1; lev = 0; ...
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; vector<int> d(n), bal(n + 2); vector<long long> pref(n + 1); for (int i = 0; i < n; i++) scanf( %d , &d[i]); sort(d.begin(), d.end()); for (int i = 0; i < n; i++) pref[i + 1] = pref[i] + d[i]; int j = 0; fo...
#include <bits/stdc++.h> using namespace std; using LL = long long; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<LL>; using VVL = vector<VL>; using VD = vector<double>; using VVD = vector<VD>; using PII = pair<int, int>; using PDD = pair<double, double>; using PLL = pair<LL, L...
#include <bits/stdc++.h> using namespace std; int main() { int n, x(0); cin >> n; string s; while (n--) { cin >> s; if (s[1] == + ) ++x; else --x; } cout << x << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int i; string s; cin >> s; int right = s.size() - 1; int left = 0; vector<int> ans; ans.resize(s.size()); for ((i) = (0); (i) < (int)(s.size()); (i)++) { if (s[i] == l ) { ans[right] = i + 1; right--; ...
#include <bits/stdc++.h> using namespace std; const int N = (int)2e6 + 7; char c[N]; struct super_hash { vector<int> h[2], p[2]; int m[2], b[2]; super_hash(string s, int m1, int m2, int b1, int b2) { m[0] = m1, m[1] = m2; b[0] = b1, b[2] = b2; int n = s.size(); for (int t = 0...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, five = 0, zero = 0; cin >> n; while (n--) { cin >> k; if (k == 5) five += 1; else zero += 1; } if (five >= 9 && zero > 0) { for (size_t i = 0; i < five / 9; i++) cout << 555555555 ; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, y; cin >> n >> m; vector<int> deg(n, 0), uf(n), uf_cnt(n, 1); for (int i = 0; i < n; ++i) uf[i] = i; for (int i = 0; i < m; ++i) { cin >> x >> y; deg[--x]++; deg[--y]++; while (x != uf[x]) x = uf[x]; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; vector<int> vec[111111]; int num1[N], num2[N], pos[N]; int main() { int n, i, j; cin >> n; for (i = 1; i <= n; i++) { scanf( %d , &num1[i]); num2[i] = num1[i]; } sort(num2 + 1, num2 + n + 1); map<int, int...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, c = 0; n = 4; m = 14; string arr[n][m]; cin >> k; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (j == 0) arr[i][j] = |# ; else { if (j == m - 3 && i == 0 || j =...
#include <bits/stdc++.h> int main() { int a, b, c, i, l; scanf( %d%d%d , &a, &b, &c); if (a > b) { for (i = a; i > 0; i++) { if (i % a == 0 && i % b == 0) { l = i; break; } else { continue; } } } else if (b > a) { for (i = b; i > ...
#include <bits/stdc++.h> using namespace std; long double typedef ld; unsigned int typedef ui; long long int typedef li; pair<int, int> typedef pii; pair<li, li> typedef pli; vector<vector<int>> typedef graph; unsigned long long int typedef ull; const ld PI = 3.14159265359; const int mod = 100000000...
#include <bits/stdc++.h> using namespace std; double a[200000 + 100], sum[200000 + 100]; int main() { int n, k; double ans = 0; scanf( %d%d , &n, &k); for (int i = 0; i < n; i++) { double s; scanf( %lf , &a[i]); } sum[0] = 0; for (int i = 0; i < k; i++) sum[0] += a[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); vector<long long> a(n); for (long long &i : a) cin >> i; cout << *max_element(a.begin(), a.end()) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { vector<long long> num(1, 0); vector<long long> arr(1, 0); for (int i = 1; i <= 1e5; i++) { num.push_back(num.back() + 1 + floor(log10(i))); arr.push_back(arr.back() + num.back()); } int q; cin >> q; while (q--) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; n--; string str[] = { Sheldon , Leonard , Penny , Rajesh , Howard }; while (n >= 5) { n = n - 5; n = n / 2; } cout << str[n] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a[505][505], b[505][505], num[250005], c[505]; int read() { int A; bool K; char C; C = A = K = 0; while (C < 0 || C > 9 ) K |= C == - , C = getchar(); while (C > / && C < : ) A = (A << 3) + (A << 1) + (C ^ 48), C = getchar(); ret...
#include <bits/stdc++.h> using namespace std; const int maxk = 101, maxn = 100000 + 10; long long n, k, a[maxk], dp[maxk][maxn]; long long f(int x, long long num) { if (num == 0) return 0; if (x == k + 1) return num; if (num < maxn && dp[x][num] != -1) return dp[x][num]; long long p = f(x + 1, n...
#include <bits/stdc++.h> using namespace std; const int inf = (int)(2e9); const long long INF = (long long)(5e18); const int N = 305; set<pair<int, int> > st; int n, m; int bl[N * N], a[N][N], vis[N][N]; int ans[N][N]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) for ...
#include <bits/stdc++.h> using namespace std; int n, k; string s; int f[2222][2222][2]; const int mod = 1000000007; int sum[2222][2222]; inline void add(int i, int j, int k, int val) { f[i][j][k] += val; if (f[i][j][k] >= mod) f[i][j][k] -= mod; } int solve() { int ans = 0; for (int po...
#include <bits/stdc++.h> using namespace std; int T, c, d; int Abs(int x) { return x >= 0 ? x : -x; } int main() { scanf( %d , &T); while (T--) { scanf( %d%d , &c, &d); if (c == d) { if (c) printf( 1 n ); else printf( 0 n ); } else { if (Abs(...
#include <bits/stdc++.h> using namespace std; char s[111111]; int m, l, r, n, pos[111111], nxt[111111][28], pre[111111][28], pr[111111][28], nx[111111][28], cur[28], a[111111]; int prefix[111111]; int solve(int l, int r); int getsuf(int pos, int k) { if (~nx[pos][k]) return nx[pos][k]; return ...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000001; const double EPS = 10e-9; const int SIZE = 20; char number[SIZE]; vector<int> dig[SIZE]; inline void mySwap(int i, int j) { char tmp = number[j]; for (typeof(j) k = (j); k >= (i + 1); --k) number[k] = number[k - 1]; numb...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; int arr[maxn]; map<int, int> mp; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; vector<int> v; for (int i = n - 1; i >= 0; i--) { if (mp[arr[i]] == 0) { mp[arr[i]] = 1; v...
#include <bits/stdc++.h> int pow(int a) { int o = 1; for (int i = 0; i < a; i++) { o = (o * 2) % 998244353; } return o; } int main(void) { int n, m; scanf( %d%d , &n, &m); printf( %d , pow(n + m)); }
#include <bits/stdc++.h> const int MAX_N = 1e5 + 5; int n, m; char str[MAX_N], nxt[256]; bool chk[256], vis[256], not_root[256], flag; std::vector<char> ans; void dfs(char c) { if (!vis[c]) { vis[c] = true; ans.push_back(c); if (nxt[c]) dfs(nxt[c]); } else flag = true; } ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; int n; vector<int> vec[MAXN]; map<int, pair<int, int> > mp; int main() { cin >> n; cin.tie(0); for (int i = 0; i < n; i++) { int t; cin >> t; vec[i].resize(t); int sm = 0; for (int j = 0; j < t...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << : << arg1 << n ; } 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 main(int argc, char* argv[]) { char dt[1002]; memset(dt, 0, sizeof(dt)); char gr[1002]; memset(gr, 0, sizeof(gr)); cin >> dt >> gr; int n = strlen(dt); int m = strlen(gr); map<char, int> dtc; map<char, int> gtc; for (int i = 0...
#include <bits/stdc++.h> #define ALL(x) x.begin(), x.end() #define pb push_back #define db1(x) cout << #x << = << x << endl #define db2(x, y) cout << #x << = << x << , << #y << = << y << endl using namespace std; void localFileInput() { #ifndef ONLINE_JUDGE freopen( input.txt , r ...
#include <bits/stdc++.h> using namespace std; int main() { long int n, a, b, i = 0, cnt = 0, y; cin >> n >> a >> b; while (n >= 0) { if (i == 0) { n = n; } else { n = n - a; } if (n % b == 0 && n >= 0) { y = n / b; cnt++; break; } ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 7; long long n, q; long long a[maxn]; long long m; map<long long, long long> ma; long long Mod(long long x, long long mod) { if (x < mod) return x; return x % mod + mod; } long long fp(long long a, long long b, long lon...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10, N = 1e3 + 10; int tp[maxn], x[maxn], y[maxn]; vector<int> edge; char ch[2]; int rt[N], V, E, i, k; int root(int u) { if (rt[u] < 0) return u; else return rt[u] = root(rt[u]); } void init(int _V) { for (i =...
#include <bits/stdc++.h> using namespace std; int n, c; int a[1 << 20], b[1 << 20]; char tp[1 << 20]; int hs[128][128]; int ne[128][128]; int li[128]; bool getDP(int l, int r) { if (hs[l][r] != -1) return hs[l][r]; if (l >= r) { return (hs[l][r] = 1); } hs[l][r] = 0; for (int k...
#include <bits/stdc++.h> using namespace std; class PriorityQueue { private: vector<pair<int, int> > d1, d2; int l1 = 0, l2 = 0, r1 = 0, r2 = 0; inline bool takeFirst() { return l1 != r1 && (l2 == r2 || d1[l1] < d2[l2]); } public: inline void prepare() { swap(d1, d2); swap(l1, l...
#include <bits/stdc++.h> using namespace std; void debug(int* a, int n, bool flag = false) { if (!flag) printf( array ); for (int i = 1; i <= n; i++) printf( %d , a[i]); printf( n ); } void debug(vector<int>& E, bool flag = false) { if (!flag) printf( vector ); for (auto it : E) printf( ...
#include <bits/stdc++.h> using namespace std; struct lr { long long left, right; lr() : left(-1), right(1e7) {} lr(long long _l, long long _r) : left(_l), right(_r) {} }; int main() { long long n; scanf( %lld , &n); vector<long long> arr(n); for (int i = 0; i < n; i++) scanf( %lld , ...
#include <iostream> #include <bits/stdc++.h> #include <stdio.h> #include <cstdlib> #include<algorithm> #include<string.h> #include<map> #include<math.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n,k; cin>>n>>k;int count =0; vector <int> v,a(n);int max=n;...
#include <bits/stdc++.h> using namespace std; const long long maxM = 22, maxN = ((1LL << 20) + 1); long long M, mod, T, N; int bc[maxM][maxM]; int dp[maxN][2][maxM]; int arr[maxN], b[maxM], p2[maxM]; struct Matrix { long long n, m; long long val[maxM][maxM]; Matrix() { for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; long double n, l, k, v1, v2; int main() { cout << fixed << setprecision(10); cin >> n >> l >> v1 >> v2 >> k; if (v2 <= v1) { cout << l / (v1 * 1.0) << endl; return 0; } if (n <= k) { cout << l / (v2 * 1.0) << endl; return 0;...
#include <bits/stdc++.h> using namespace std; int start[200010], finish[200010], cnt, n, m, a[200010], dis[200010]; long long tree[2][8 * 200010]; vector<int> adj[200010], nodes[2], starts[2]; void update(int v, int vl, int vr, int l, int r, int val, int k) { int mid = (vl + vr) / 2; if (l <= vl && vr...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 7; const long long INF = 1e18 + 7; int n, a[MAXN], d[MAXN] = {}, k, l = 1, r = 0; long long f[MAXN], g[MAXN], ans = 0; void add(long long &a, const long long &b) { a += b; if (a > INF) a = INF; } long long sum(long long a, long...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long mx = 2e6 + 10; int posx[] = {1, -1, 0, 0}; int posy[] = {0, 0, 1, -1}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t = 1, n, k, m, a, b, c, d, h; cin >> t; w...
#include <bits/stdc++.h> long long dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; long long dy[8] = {1, 0, -1, 0, -1, 1, 1, -1}; using namespace std; class pa3 { public: long long x; long long y, z; pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {} bool operator<(const pa3 &p...
#include <bits/stdc++.h> using namespace std; template <typename _T> inline void read(_T &f) { f = 0; _T fu = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) fu = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { f = (f << 3) + (f << 1) + (c & 15); ...
#include <bits/stdc++.h> using namespace std; void optimise() { ios_base::sync_with_stdio(false); cin.tie(NULL); } long long int mod = 1e9 + 7; void normalize(long long int &a) { a = (a + mod) % mod; } long long int modmul(long long int a, long long int b) { a = a % mod; b = b % mod; nor...
#include <bits/stdc++.h> using namespace std; struct point { int x, y; inline bool operator<(const point &a) const { return x < a.x; } } arr[100005]; struct query_tp { int col, l, r, delta; query_tp() {} query_tp(int _col, int _l, int _r, int _delta) { col = _col; l = _l; r...
#include <bits/stdc++.h> using namespace std; const int lim = 200005; long long int n; vector<vector<long long int> > ans; vector<long long int> ed; void solve(int test) { cin >> n; for (int(i) = 0; (i) < n; (i)++) { long long int v; cin >> v; vector<long long int>::iterator ind = ...
#include <bits/stdc++.h> using namespace std; long long nxt(long long x) { long long mn = 10; long long mx = 0; long long xx = x; while (x > 0) { mn = min(mn, x % 10); mx = max(mx, x % 10); x /= 10; } return xx + mn * mx; } signed main() { long long t; cin >> t;...
#include <bits/stdc++.h> const int MAX = 2000010, mod = 1000000007; int n, m, mp[MAX], c[MAX], d[MAX], ds[MAX]; bool ty[MAX]; void upd(int i, int x) { x > d[i] ? d[i] = x, ds[i] = 1 : x == d[i] ? ds[i]++ : 0; } int main() { scanf( %d , &n); for (int p; n--;) scanf( %d , &p), c[p > m ? m = p : p]...
#include <bits/stdc++.h> using namespace std; const int maxn = 10e5; int minc, maxk = 0; long long int a[maxn], c[maxn]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(30); int n, s; cin >> n >> s; for (int i = 0; i < n; i++) cin >> a[i]; int l = 0,...
#include <bits/stdc++.h> using namespace std; const int NMax = 100005; vector<int> G[NMax]; long double Array[NMax]; int DP[NMax], N; void Read() { cin >> N; for (int i = 1; i < N; i++) { int x; cin >> x; G[x].push_back(i + 1); } } void buildDP(int node) { DP[node] = 1;...
#include <bits/stdc++.h> using namespace std; void no() { cout << IMPOSSIBLE << endl; exit(0); } int main() { cin.sync_with_stdio(false); int n, m; cin >> n >> m; int answer = 0; int last_day = 0, last_h = 0; for (int i = 0; i < m; i++) { int cur, h; cin >> cur >> h...
#include <bits/stdc++.h> using namespace std; set<pair<long long, long long> > s[17]; long long a[100002]; long long g[100002]; signed main() { ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long n, m; cin >> n >> m; for (long long i = 0; i <= n; i++) g[i] = (i * (i + 1)) / 2LL; l...
#include <bits/stdc++.h> using namespace std; long long aa[33]; long long a[33], b[33], k[33], p[33]; long long n, u, r; long long ans = -1e10; void dfs(long long d, long long pre) { if ((u - d) % 2 == 0) { long long t = 0; for (int i = 1; i <= n; i++) t = t + a[i] * k[i]; ans = max(an...
#include <bits/stdc++.h> using namespace std; vector<int> e[300020]; int f[300020][3]; inline int Mod(int x) { return x + ((x >> 31) & 998244353); } void DFS(int x, int p) { int i, v; f[x][0] = 1; f[x][1] = 1; f[x][2] = 1; for (i = 0; i < (signed)e[x].size(); i++) if ((v = e[x][i]) !...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int a[n]; map<int, int> mp; for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } long long ans = 0; for (int i = 0; i < n; i++) { fo...
#include <bits/stdc++.h> int main() { int n, m; scanf( %d %d , &n, &m); int msg1[n]; int msg2[m]; for (int i = 0; i < n; i++) { scanf( %d , &msg1[i]); } for (int i = 0; i < m; i++) { scanf( %d , &msg2[i]); } for (int i = 1; i < n; i++) { msg1[i] = msg1[i] + msg1[i...
#include <bits/stdc++.h> using namespace std; const double pi = 3.141592653589793238462; int n, m, r, w[70][70][70], d[70][70][2000], a, b, c; const int inf = 2000000000; void deb(int q) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) printf( %d , d[i][j][q]); printf( n ); ...
#include<bits/stdc++.h> using namespace std; const int N = 2000 + 10; int n; bool flag[N]; bool Query(int l1, int r1, int l2, int r2) { printf( ? %d %d n , r1 - l1 + 1, r2 - l2 + 1); for (int i = l1; i <= r1; i++) printf( %d%c , i, n [i == r1]); for (int i = l2; i <= r2; i++) printf( %...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; int m = 0; int block[5005]; long long f[5005]; int main() { int n, tmp; int num_of_for = 0; cin >> n; tmp = n; while (tmp--) { char c; cin >> c; if (c == s ) { block[m] = num_of_for; ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007LL; long long N; vector<long long> E[100000]; long long dp[100000][2]; long long ans = 0; long long mod_inv(long long n) { long long t = MOD - 2, p = 1, q = n; while (t > 0) { if (t % 2 == 1) p = (p * q) % MOD; ...
#include <bits/stdc++.h> using namespace std; long long int Lpow(long long int a, long long int b) { long long int ans = 1; while (b > 0) { if (b % 2) ans = (ans * a); a = (a * a); b = b / 2; } return ans; } long long int Lpow(long long int a, long long int b, long long int M) ...
#include <bits/stdc++.h> const int MAX_N = 102; using namespace std; string s; int dp[52][11]; long long numberOfways(int i, int digit) { if (i == s.length()) return 1; if (dp[i][digit] != -1) return dp[i][digit]; dp[i][digit] = 0; int curDigit = s[i] - 0 ; int newDigit = curDigit + digit...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> w(n); for (int i = 0; i < n; i++) cin >> w[i]; int x = 0; vector<int> ord(n); vector<int> rd(m); vector<bool> put(n, false); for (int i = 0; i < m; i++) { cin >> rd[i]; rd[...
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int rows[5] = {3, 4, 5, 4, 3}; bool dp[1 << 19], seen[1 << 19]; pii int_to_pair(int c) { pii res = {0, 0}; while (rows[res.first] <= c) { c -= rows[res.first]; res.first++; } res.second = c; return ...
#include <bits/stdc++.h> int n, u[1001], v[1001], dem[1001], ans = 0; using namespace std; void input() { cin >> n; for (int i = 1; i < n; i++) { cin >> u[i] >> v[i]; } } void output() { cout << ans << endl; } void solve() { for (int i = 1; i <= n; i++) { for (int j = 1; j < n; j...
#include <bits/stdc++.h> using namespace std; char s1[200005], s2[200005]; int len; bool judge(int p, char *s1, char *s2) { for (int i = 0; i < p; i++) { if (s1[i] != s2[i]) return 0; } return 1; } int check(int p, char *s1, char *s2) { if (p == 1) { if (s1[0] != s2[0]) return 0;...
#include <bits/stdc++.h> using namespace std; vector<int> a; int main() { int n, x, ans; cin >> n >> x; ans = x; a.resize(n); for (int i = 0; i < (int)(n); i++) { cin >> a[i]; } for (int i = 0; i < (int)(n); i++) { for (int j = i; j < n; j++) { ans = max(ans, (x / a...
#include <bits/stdc++.h> using namespace std; bool check(const pair<long long, long long> &a, const pair<long long, long long> &b) { if (a.first > b.first) return true; else if (a.first < b.first) return false; else { if (a.second < b.second) return true; els...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( no-stack-protector ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native ) #pragma GCC optimize( fast-math ) #pragma warning(disable : 4996) using namespace std; const in...
#include <bits/stdc++.h> using namespace std; const long double PI = acos((long double)-1); namespace fft { template <class T> class comp { public: T real, img; comp(T a = (T)0, T b = (T)0) : real(a), img(b) {} comp conj() { return comp(this->real, -(this->img)); } comp operator=(const comp...
#include <bits/stdc++.h> using namespace std; const int nax = 5005; const int mod = 1e9 + 7; const int inf = 1e9 + 120; int t[nax]; char sl[nax]; int pref[nax][nax]; int nxt[nax][nax]; int cmp(int i, int j) { if (t[i] < t[j]) return -1; if (t[i] > t[j]) return 1; return 0; } int dp(int...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; string to_string(string s) { return + s + ; } string to_string(const char* s) { return to_string((string)s); } string to_string(bool b) { return (b ? true : false ); } template <typename A, typename B> string to_string(pair...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; int main(void) { int n, q, a, b; scanf( %d%d%d%d , &n, &q, &a, &b); vector<int> x(n); for (int i = 0; i < n; ++i) { scanf( %d , &x[i]); } vector<double> y(n); vector<int> from(n, -1); y[0] = x[0]; for ...
#include <bits/stdc++.h> bool IsCircular(const std::string &s, const int n) { bool isCircular = true; for (int i = 0; i < n; i++) { int j = (i + 1) % n; isCircular &= ((s[i] == > || s[i] == - ) && (s[j] == > || s[j] == - )); } if (isCircular) return true; isCircular = t...
#include <bits/stdc++.h> using namespace std; const int N = (1 << 18) + 10; int n, m; long long tree[N], add[N]; int same[N]; int col[N]; void build(int x, int l, int r) { tree[x] = same[x] = col[x] = add[x] = 0; if (l == r) { same[x] = 1; col[x] = l + 1; return; } int s ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; string s; cin >> s; for (long long i = 0; i < s.size(); i++) { if (s[i] == * && i + 4 <= s.size()) { for (long long j = 1; j < s.size(); j++) { if (i + 4 * j <= s.size()) { if ...
#include <bits/stdc++.h> using namespace std; const int N = 1E6 + 50; const long long p = 1E9 + 7; int n, k; long long ans, sum, f[N], s[N], fac[N], inv[N]; inline void upd(long long &a, long long b) { a += b; if (a >= p) a -= p; } inline void sub(long long &a, long long b) { a -= b; if ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); int n, res = 0, t, b; cin >> n; while (n) { res++; t = n; b = -1; while (t) { b = max(b, t % 10); t...
#include <bits/stdc++.h> using namespace std; int N, a[55], P; double dp[55][55][55]; double fac(int n) { double ans = 1; for (int i = 0; i < (n); i++) ans *= (i + 1); return ans; } int main(int argc, char *argv[]) { scanf( %d , &N); for (int i = 0; i < (N); i++) scanf( %d , a + i); ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; const int LG = 27; const int INF = 1e9 + 7; pair<int, int> seg[LG][N]; int mx[LG][N]; int r[N], a[N], sol[N]; pair<int, int> p[N]; int n, k; void build(int l = 0, int r = n, int d = 0) { if (r - l == 1) { seg[d][l] = make...
#include <bits/stdc++.h> using namespace std; template <typename t> inline void read(t &x) { x = 0; char c = getchar(), f = 0; for (; c < 0 || c > 9 ; c = getchar()) if (c == - ) f = 1; for (; c >= 0 && c <= 9 ; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -...
#include <bits/stdc++.h> using namespace std; int main() { int x, v, arr[1000], c = 0; cin >> x >> v; for (int i = 0; i < x - 1; i++) { cin >> arr[i]; } while (1) { sort(arr, arr + x - 1); if (v > arr[x - 2]) break; arr[x - 2]--; v++; c++; } cout << c;...
#include <bits/stdc++.h> using namespace std; int f(char c) { return c - 48; } void soroban(int n, char *ans) { if (n < 5) { ans[0] = O ; ans[1] = - ; ans[2] = | ; for (int i = 3; i <= 7; i++) { if (i == n + 3) { ans[i] = - ; } else { ans[i] = O...
#include <bits/stdc++.h> using namespace std; int A[5005], n, k, L[5005][5005], S[5005], E[5005]; void doc() { scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) { scanf( %d , &A[i]); } } void xuly() { sort(A + 1, A + n + 1); for (int i = 1; i <= n; i++) { S[i] = 1; E[i]...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const long long mod = 998244353; const int maxn = 3005; int dp[maxn][maxn]; int dp2[maxn][maxn]; long long add(long long a, long long b) { return (a + b) % mod; } long long mul(long long a, long long b) { return (a * b) % mod; } lo...
#include <bits/stdc++.h> using namespace std; int oo = (1e9) + 7; int main() { long long n; cin >> n; vector<long long> b(n / 2 + 5, 0); for (int i = 1; i <= n / 2; i++) { scanf( %lld , &b[i]); } vector<long long> out(n + 5, 0); long long l = 0; long long r = 0; for (int ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T sqr(const T& a) { return a * a; } template <typename T> inline int sign(const T& a) { return a < 0 ? -1 : a > 0; } void task(); int main() { task(); return 0; } vector<int> z_function(string s) { int n...
#include <bits/stdc++.h> using namespace std; ifstream fi( easy .inp ); ofstream fo( easy .out ); int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<string> s; for (int i = 0; i < n; i++) { string x; ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 300000 + 10; long long n; long long ans[maxn], tot, vis[maxn], last; int main() { while (scanf( %lld , &n) != EOF) { memset(vis, 0, sizeof(vis)); memset(ans, 0, sizeof(ans)); for (int i = 0; i < n; i++) scanf( %lld , &a...
#include <bits/stdc++.h> #pragma GCC target( sse4,avx ) int getNimb(int c, int64_t forbidden_mask, std::map<std::pair<int, int64_t>, int>& map) { auto it = map.find(std::pair<int, int64_t>{c, forbidden_mask}); if (it != map.end()) { return it->second; } if (c == 0) { return...
#include <bits/stdc++.h> using namespace std; int z[100001]; int main() { string s; int T, a, b; cin >> s; for (a = 1; a < s.size(); a++) { z[a] = z[a - 1] + (s[a] == s[a - 1]); } for (cin >> T; T--; cout << z[b - 1] - z[a - 1] << endl) cin >> a >> b; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; bool taken[n + 1]; for (int i = 0; i < n + 1; i++) taken[i] = 0; int cc = 0; for (int i = 1; i < n + 1; i++) { for (int j = 1; j <= n; j++) { int a; cin >> a; ...
#include <bits/stdc++.h> using namespace std; const long long MXN = 100 + 10; const long long Mod = 1e9 + 7; void mkay(long long &x) { if (x >= Mod) x -= Mod; } long long n, k; long long sub[MXN], DP[MXN]; long long dp[MXN][MXN][2], pd[MXN][2]; vector<long long> adj[MXN]; vector<pair<long long, ...
#include <bits/stdc++.h> using namespace std; long long t, n, p[200100], c[200100], ans = 100100; bool hamin[200100]; vector<vector<long long> > cycle; bool same_color(long long ind, long long start, long long dist) { long long asdf = (start + dist) % cycle[ind].size(); while (asdf != start) { i...
#include <bits/stdc++.h> using namespace std; bool comprobarNum(vector<int> aux, int num) { for (int i = 0; i < aux.size(); i++) { if (aux[i] == num) { return true; } } return false; } int main() { int n, aux; cin >> n; vector<int> s; vector<int> numR; int con...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); double n, R, r; cin >> n >> R >> r; if (r > R) return cout << NO , 0; if (2 * r == R) { if (n <= 2) return cout << YES , 0; ...
#include <bits/stdc++.h> using namespace std; int i, j, m, n, rev_dig[25], cnt, non_zero, anscnt; long long x, ans1[100005], ans2[100005], ans3[100005]; long long getinv(long long a, long long p) { if (a == 1) return 1; long long k = a - getinv(p % a, a); return (k * p + 1) / a; } void answer(lo...
#include <bits/stdc++.h> using namespace std; int ROW[] = {+1, -1, +0, +0}; int COL[] = {+0, +0, +1, -1}; int X[] = {+0, +0, +1, -1, -1, +1, -1, +1}; int Y[] = {-1, +1, +0, +0, +1, +1, -1, -1}; int KX[] = {-2, -2, -1, -1, 1, 1, 2, 2}; int KY[] = {-1, 1, -2, 2, -2, 2, -1, 1}; int basePrime[] = {1009, 101...