func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> int main(void) { unsigned int const max_skill_level = 100; unsigned int number_of_boys; unsigned int number_of_girls; unsigned int number_of_pairs = 0; std::vector<unsigned int> number_of_boys_with_each_skill_level( max_skill_level + 1, 0); std::vector<unsigned...
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) using namespace std; void pre() {} void solve() { long long k, b, n; cin >> k >> b >> n; long long arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; map<long long,...
#include <bits/stdc++.h> using namespace std; int n, adj[166][166]; bool h[166]; vector<char> V[166], r; string a[105]; void dfs(char x) { h[x] = true; for (typeof(V[x].begin()) it = V[x].begin(); it != V[x].end(); it++) if (!h[*it]) dfs(*it); r.push_back(x); } int main() { cin >> ...
#include <bits/stdc++.h> using namespace std; const int N = 300010; int total[N]; vector<pair<pair<int, int>, int> > e[N]; int dir[N], from[N], to[N]; int visit[N]; int n, m; int main() { scanf( %d%d , &n, &m); memset(total, 0, sizeof(total)); for (int i = 1; i <= m; i++) { int u, v, w...
#include <bits/stdc++.h> using namespace std; inline int read(void) { int sum = 0, sign = 1; char ch = getchar(); while (ch > 9 || ch < 0 ) { if (ch == - ) sign = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { sum = ...
#include <bits/stdc++.h> using namespace std; const int SZ = 104; const double EPS = 1e-7; int a, b, c; void read() { cin >> a >> b >> c; } void solve() { a -= a / b * b; for (int i = 0; i < 1e5; ++i) { a *= 10; if (c == a / b) { cout << i + 1; return; } a -= ...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5; int a[maxn], b[maxn], c[maxn]; int n, K, i, j, x, y, bl, la; int main() { scanf( %d%d , &n, &K); x = K; for (i = 2; i <= x; i++) if (x % i == 0) { a[++la] = i; while (x % i == 0) { b[la]++; ...
#include <bits/stdc++.h> using namespace std; char st[8][20] = { err , monday , tuesday , wednesday , thursday , friday , saturday , sunday }; int main() { char s1[20], s2[20]; scanf( %s %s , s1, s2); int t1 = 0, t2 = 0; for (int i = 1; i <= 7; i++) if (strc...
#include <bits/stdc++.h> using namespace std; int main() { long long tc, n, x, cnt1, cnt2, i, max_; scanf( %lld , &tc); while (tc--) { scanf( %lld , &n); vector<long long> v; vector<long long> v1; for (i = 0; i < n; i++) { scanf( %lld , &x); v.push_back(x); ...
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma comment(linker, /STACK:336777216 ) using namespace std; int IT_MAX = 1 << 17; long long MOD = 1000000007; const int INF = 0x3f3f3f3f; const long long LL_INF = 0x3f3f3f3f3f3f3f3f; const double PI = acos(-1); const double ERR = 1e-10; s...
#include <bits/stdc++.h> using namespace std; int h, w, k, Q; int V; int a[1005][1005]; vector<int> G[1100005]; short d[1100005]; short dist[45][1000005]; vector<int> vec[45]; bool used[45]; int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; void bfs(int c, short dist[]) { queue<int> Q; for (...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; const int maxn = 3010; vector<int> g[maxn]; int vis[maxn], dis[maxn][maxn]; void bfs(int s) { memset(vis, 0, sizeof(vis)); queue<int> que; que.push(s); vis[s] = 1; while (!que.empty()) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, max1 = 0; cin >> n; long long int a[n]; long long int b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } b[n - 1] = 0; max1 = a[n - 1]; for (int i = n - 2; i >= 0; i--) { if (a[i] > max1) { ...
#include <bits/stdc++.h> using namespace std; int n, m; vector<pair<pair<int, int>, pair<int, int> > > ans; bool invert; void print(vector<vector<string> > &mat) { for (auto vs : mat) { for (string s : vs) { printf( |%6s| , s.c_str()); } cout << endl; } } void move(int s...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b); int main() { long long t, w, b; cin >> t >> w >> b; long long tie = 0; long long total = t; bool overflow = false; long long gcdValue = gcd(w, b); if (LLONG_MAX / double(w) < double(b) / gcdValue) ov...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, x, rev; cin >> n; while (n % 10 == 0) n = n / 10; rev = 0; x = n; while (x > 0) { rev = rev * 10 + x % 10; x = x / 10; } if (rev == n) cout << YES ; else cout << NO ; }
#include <bits/stdc++.h> using namespace std; void solve(void); int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); int t = 1; while (t--) solve(); return 0; } long long int power(long long int x, long long int y) { long long int temp; if (y == 0) return 1; temp = powe...
#include <bits/stdc++.h> using namespace std; int n, m, a[100010], pos[100010], f[100010], b; int main() { bool yes = true; cin >> n >> m; for (int i = 1; i < n + 1; i++) { cin >> f[i]; if (pos[f[i]]) { pos[f[i]] = -1; } else { pos[f[i]] = i; } } for (in...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); int s, x1, x2; cin >> s >> x1 >> x2; int t1, t2; cin >> t1 >> t2; int p, d; cin >> p >> d; int ans = abs(x1 - x2) * t2; if (x1 < x2) { if (p <= x1) { ...
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; const long long N = (long long)1e5 * 4; const long long INF = (long long)1e18; const double eps = (double)1e-6; string s; vector<long long> v; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); ...
#include <bits/stdc++.h> using namespace std; int main() { int x; scanf( %d , &x); printf( %d , x + 1 >> 1); }
#include <bits/stdc++.h> using namespace std; int a, b, c, n, t, f, ans; vector<int> v; queue<int> q; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n >> a >> b >> c >> t; for (int i = 0; i < n; i++) { cin >> f; v.push_back(f); } sort(v.begin...
#include <bits/stdc++.h> using namespace std; template <typename T, typename S> ostream &operator<<(ostream &os, const pair<T, S> &p) { return os << ( << p.first << , << p.second << ) ; } template <typename T, size_t N> ostream &operator<<(ostream &os, const array<T, N> &a) { os << ( ; fo...
#include <bits/stdc++.h> void rd(int &x) { x = 0; int f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch <= 9 && ch >= 0 ) x = x * 10 + ch - 0 , ch = getchar(); x *= f; } void lrd(long long &x) { x = 0; ...
#include <bits/stdc++.h> using namespace std; const int N = 1001; const int M = 300000; int n, m, a[N], b[N]; vector<bool> g[M]; pair<int, int> p[N]; priority_queue<pair<int, int> > q; bool solve(int x) { if (x == 0) return true; for (int i = 1; i <= n; i++) b[i] = a[i] - x; int sum = 0; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 5e3 + 10; int dp[maxn][maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; string a, b; cin >> a >> b; int ans = 0; for (int i = 1; i <= n; i++) { for (in...
#include <bits/stdc++.h> using namespace std; const int N = 1005; char a[N], b[N]; int lcp[N][N]; int f[N][N][12]; int main() { int l1, l2, n; scanf( %d%d%d , &l1, &l2, &n); scanf( %s%s , a + 1, b + 1); for (int i = (1); i <= (l1); i++) { for (int j = (1); j <= (l2); j++) { if ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000 * 100 + 10; vector<int> vec[MAXN]; int c[MAXN]; long long dp[2][MAXN]; void dfs(int v) { vector<int> temp; long long all = 1; for (int i = 0; i < (int)vec[v].size(); i++) { int u = vec[v][i]; dfs(u); temp.push_...
#include <bits/stdc++.h> using namespace std; namespace Base { const int inf = 0x3f3f3f3f, INF = 0x7fffffff; const long long infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll; template <typename T> void read(T &x) { x = 0; int fh = 1; double num = 1.0; char ch = getchar(); while...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000000; int sum[maxn]; int a[maxn]; int sum2[maxn]; int main() { int n; char s[maxn]; while (cin >> n) { memset(sum, 0, sizeof(sum)); for (int i = 1; i <= n; ++i) { scanf( %d , a + i); sum[i] = sum[i - 1]...
#include <bits/stdc++.h> using namespace std; pair<int, int> arr[5005]; vector<int> primes; int ans[5005]; int u[5005]; int n; void pre() { vector<char> bad(10005); for (int i = 2; i <= 10000; ++i) { if (!bad[i]) { primes.push_back(i); for (int j = i * i; j <= 10000; j += i) ...
#include <bits/stdc++.h> using namespace std; int main() { int n, tri = 0; scanf( %d , &n); long long trilist[n + 5]; for (int i = 0; i < n; i++) { scanf( %ld , &trilist[i]); } sort(trilist, trilist + n); for (int i = 0; i < n - 2; i++) { if (trilist[i] + trilist[i + 1] > tri...
#include <bits/stdc++.h> using namespace std; long long int visited1[200005], visited2[200005], step1[200005], step2[200005], ar[200005]; long long int n; void fill_array(long long int ar[], long long int value, long long int size) { for (long long int i = 0; i < size; i++) ar[i] = value; } long l...
#include <bits/stdc++.h> using namespace std; int n; struct pos { long long int x; long long int h; int indx; int sum; } p[100005]; bool cmp(pos a, pos b) { return a.x < b.x; } bool cmp2(pos a, pos b) { return a.indx < b.indx; } int bs(long long int key) { int l = 0; int r = n; ...
#include <bits/stdc++.h> using namespace std; long long n, m, p, prt[100005], num[100005], ans = 1, cnt, u, v; inline int getfather(int u) { if (u == prt[u]) return prt[u]; prt[u] = getfather(prt[u]); return prt[u]; } int main() { scanf( %lld%lld%lld , &n, &m, &p); for (register int i = 1;...
#include <bits/stdc++.h> using namespace std; const int N = 52; const int INF = 1e9; int mat[N][N]; int n, k; struct edge { int from, to, cap, cost, flow; edge(int from, int to, int cap, int cost) : from(from), to(to), cap(cap), cost(cost) { flow = 0; } }; vector<edge> e; vec...
#include <bits/stdc++.h> using namespace std; char ss[100002]; int main() { int N, K, k = 0; scanf( %d %d , &N, &K); scanf( %s , ss); string S = ss; for (int i = 0; i < N - 1 && k < K; i++) { if (S[i] == 4 && S[i + 1] == 7 ) { int x = i + 1; if (x % 2) { if (...
#include <bits/stdc++.h> using namespace std; int ns, k, n, m; char s[1000010], t[1000010], p[1000010]; vector<int> vet; int fail[1000010]; void buildFail(char *p) { int j = fail[0] = -1; for (int i = 1; i <= m; i++) { while (j >= 0 && p[j] != p[i - 1]) j = fail[j]; fail[i] = ++j; } ...
#include <bits/stdc++.h> using namespace std; const int MX = 400010; struct ST { int st[4 * MX], p[MX]; ST() { build(1, MX - 1, 1); } void build(int i, int j, int pos) { st[pos] = 0; if (i == j) { p[i] = pos; return; } int m = (i + j) / 2; build(i, m, pos ...
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; int n, m, t; long long dp[61][31][31]; int arr[61]; long long solve(int ind, int x, int y) { if (x > 3 && y > 0 && x + y == t) return 1; if (ind == n + m + 1) return 0; long long &ret = dp[ind][x][y]; if (ret != -1) retu...
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; int f[105][105][105], len[105], n, m; char s[105]; int qpow(int x, int y) { int res = 1; while (y) { if (y % 2) res = 1ll * res * x % mod; x = 1ll * x * x % mod; y /= 2; } return res; } int dfs(int x, int l,...
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define FOR(i, a, b) for(int i = (a); i < (b); i++) const int N = 1 << 10; int p[N][N]; int main() { int m, n; cin >> m >> n; FOR(i, 0, n) FOR(j, 0, m) cin >> p[i][j]; int sum = 0; FOR(j, 0, m) sum += p[n - 1]...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f2f1f0f; const long long LINF = 1ll * INF * INF; const int MAX_N = 2e5 + 100; int N; long long C; int Nr[MAX_N * 2]; long long SumNr[MAX_N * 2]; long long Ans[MAX_N]; long long SumAns[MAX_N]; long long getSum(long long val[], int a, ...
#include <bits/stdc++.h> using namespace std; long long f[3], x, y, z, k; int main() { long long a, b, c; long long r; cin >> f[0] >> f[1] >> f[2] >> k; sort(f, f + 3); k += 3; k = min(k, f[0] + f[1] + f[2]); a = f[0] * 3 <= k ? f[0] : k / 3; r = k - a; b = f[1] * 2 <= r ? f[1]...
#include <bits/stdc++.h> using namespace std; const int N = (int)1e6 + 9; int n, d[N]; int digit(int x) { int s = 0; while (x > 0) { s += x % 10; x /= 10; } return s; } vector<int> b[10]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 300001; const int logn = 20; bool s[maxn][logn]; int nxt[maxn][logn]; int f[maxn][logn]; int a[maxn]; int tmp[maxn]; int n, q; int main() { scanf( %d%d , &n, &q); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } ...
#include <bits/stdc++.h> using namespace std; struct Bug { int a, id; } B[100005]; struct Stu { int b, c, id; bool operator<(const Stu &A) const { return c > A.c; } } S[100005]; int n, m, s; int ans[100005]; int ans1[100005]; bool cmp(Bug A, Bug B) { return A.a > B.a; } bool cmp1(Stu A, ...
#include<bits/stdc++.h> using namespace std; #define ll long long int #define rep(i,a,b) for(int i=a;i<b;i++) #define arrr int n;cin>>n;int a[n];for(int i=0;i<n;i++){cin>>a[i];} const int N = 1e6; // bool prime[1000001]={true}; // void sieve(){ // memset(prime,1,sizeof(prime)); // prime[0]=pr...
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; long long power(long long x, long long n, long long mod) { if (n == 0) { return 0; } long long temp = power(x, n / 2, mod); if (n % 2 == 1) { return (x * temp * temp) % mod; } else { return (temp * temp...
#include <bits/stdc++.h> using namespace std; int main() { int n, s; int ans = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> s; ans += s * i; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; char s[200222]; int main() { while (scanf( %s , s) > 0) { int n = strlen(s); int a, b, c; a = b = c = 0; for (int i = 0; i < n; i++) { if (s[i] == 0 ) a++; else if (s[i] == 1 ) b++; } int fs...
#include <bits/stdc++.h> using namespace std; int ans = 0, visited[200005] = {0}; vector<int> edges[200005]; void dfs(int x) { visited[x] = 1; if (visited[edges[x][0]] == 1) ans++; else dfs(edges[x][0]); } int main() { int n, i, x, count = 0; cin >> n; for (i = 1; i <= n;...
#include <bits/stdc++.h> using namespace std; const int Maxn = 200 * 1000 + 10; int n, arr[Maxn], ind[Maxn], ans; int main() { cin >> n; for (int i = 0; i < n; i++) scanf( %d , &arr[i]); int a; for (int i = 0; i < n; i++) { scanf( %d , &a); ind[a] = i; } int prev = 0; for...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int a[maxn], vis[maxn]; int main() { int n, p, flag = 0, mark = 0, tot = 0, Min = 1e9 + 7, cur, Max = -1e9 - 7, Maxcur; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); if (a[i] == 0...
#include <bits/stdc++.h> using namespace std; long long a1, b1, a2, b2; int main() { cin >> a1 >> b1 >> a2 >> b2; long long t1, t2, t3, t4; t1 = a1 * b1; t2 = a2 * b2; int c12, c13; int c22, c23; c12 = c13 = c22 = c23 = 0; while (t1 % 2LL == 0LL) { c12++; t1 /= 2LL; ...
#include <bits/stdc++.h> using namespace std; const int N = 1000000; int cnt[N + 1]; int check[N + 1]; set<pair<int, int> > s; int main() { int n, A; scanf( %d %d , &n, &A); for (int i = 1; i <= N; i++) { cnt[i] = 0; s.insert({cnt[i], i}); } for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; long long int l, r, sum = 0, tempVariable, doneTillHereInArrayOfNumbers = 3; long long int arrayOfNumbers[100000]; long long int createNextLuckyNumber() { if (doneTillHereInArrayOfNumbers % 2 == 0) { arrayOfNumbers[doneTillHereInArrayOfNumbers] = ...
#include <bits/stdc++.h> const int INF = 1000000009; using namespace std; int main() { int n, i, l = 0, r = 0; string s; cin >> n >> s; s = . + s; for (i = 1; i < s.size(); i++) if (s[i] == L ) l = 1; else if (s[i] == R ) r = 1; if (r && l) cout << s.f...
#include <bits/stdc++.h> using namespace std; const int INF = 0x7FFFFFFF; struct prioritycom { bool operator()(const int& l, const int& r) { return l < r; } }; template <typename T> T lcm(T a, T b) { return a / __gcd(a, b) * b; } template <class T> T bigmod(T n, T p, T m) { if (p == 0) ret...
#include <bits/stdc++.h> using namespace std; int const N = 1e5 + 10; vector<int> e[N], b[N], d[N]; bool v[N], in[N]; void dfs(int root, int parent, int depth) { v[root] = true, in[root] = true; d[depth].push_back(root); for (auto child : e[root]) { if (in[child]) b[root].push_back(child); ...
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const long long ooo = 9223372036854775807ll; const int _cnt = 1000 * 1000 + 7; const int _p = 1000 * 1000 * 1000 + 7; const int N = 100005; const double PI = acos(-1.0); const double eps = 1e-9; int o(int x) { return x % _p; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d %d , &n, &m); vector<string> grid; int start_x, start_y; for (int i = 0; i < n; i++) { string s; cin >> s; grid.push_back(s); for (int j = 0; j < s.size(); j++) { if (s[j] == S ) { ...
#include <bits/stdc++.h> using namespace std; const int N = 100000; const double pi = acos(-1.0); int n, q, a[100100], seg[1700000], rev[1700000], tag[1700000]; char s[10]; int read() { int x = 0, f = 1; char ch = getchar(); while ((ch < 0 ) || (ch > 9 )) { if (ch == - ) f = -1; c...
#include <bits/stdc++.h> using namespace std; const int maxn = 3000 + 10; int sum, d[maxn], dp[maxn][2]; vector<pair<int, int> > edge[maxn]; int min(int a, int b) { return a < b ? a : b; } void dfs(int u, int f, int w) { if (f == -1) { sum = 0; d[u] = 0; dp[u][0] = dp[u][1] = 0; } ...
#include <bits/stdc++.h> const long double eps = 1e-9; using namespace std; template <class T> inline T MAX(const T &_a, const T &_b) { return ((_a > _b) ? _a : _b); } template <class T> inline T MIN(const T &_a, const T &_b) { return ((_a < _b) ? _a : _b); } template <class T> inline T MAX3...
#include <bits/stdc++.h> using namespace std; string s; int stx, sty, i; int f[2000][2000]; int main() { cin >> s; stx = 100; sty = 100; f[stx][sty] = 1; for (i = 0; i < s.size(); i++) { if (s[i] == U ) stx--; if (s[i] == D ) stx++; if (s[i] == L ) sty--; if (s[i...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void run() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int32_t main() { run(); vector<long long> dp((long long)(3e6), 0); dp[3] = 4; for (long long i = ...
#include <bits/stdc++.h> using namespace std; int n, m, dfs_low[100100], dfs_num[100100], cont; int vis[100100]; vector<int> AdjList[100100]; long long int v[100100]; long long int sum = 0, numWay = 1; vector<int> S; void tarjan(int u) { dfs_low[u] = dfs_num[u] = cont++; vis[u] = 1; S.push_b...
#include <bits/stdc++.h> using namespace std; char a[1005]; int f[1005], flag[1005], prime[1005], g[1005]; int n, num, ok[1005], k, i, id, ans, cnt, j; int main() { scanf( %s , a + 1); n = strlen(a + 1); num = 1; ok[1] = 1; for (i = 1; a[i]; i++) g[a[i] - a ]++; for (i = 2; i <= n; i+...
#include <bits/stdc++.h> using namespace std; double PI = acos(-1); double EPS = 1e-7; int INF = 1000000000; int MOD = 1000000007; int MAXINT = 2147483647; long long INFLL = 1000000000000000000LL; long long MAXLL = 9223372036854775807LL; int mx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}; int my[8] = {0, 0, -1...
#include <bits/stdc++.h> using namespace std; vector<long long> pa, pb; struct fenw { vector<long long> fw; long long n; void ini(long long pn) { n = pn; fw.clear(); fw.resize(n, 0); } void ad(long long l, long long x) { while (l < n) { fw[l] += x; l |= ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007LL; const int N = 10; char str[N][N]; int n = 8, ans, way[4][2] = {2, 2, 2, -2, -2, 2, -2, -2}; int flag[N][N][N][N]; void dfs(int x, int y, int u, int v) { flag[x][y][u][v] = 1; if (x == u && v == y && str[x][y] != # )...
#include <bits/stdc++.h> using namespace std; double maxx(double a, double b) { return a > b ? a : b; } int minn(int a, int b) { return a < b ? a : b; } int abss(int a) { return a < 0 ? (-a) : a; } const double eps = 1e-8, PI = 3.141592653589, INF = 1e7; int N; double L, R; double inpt[30][3]; double ...
#include <bits/stdc++.h> using namespace std; string c; int main() { int i, j, k, n, m, l; scanf( %d%d , &n, &k); if (n * (n - 1) / 2 <= k) { puts( no solution ); return 0; } for (i = 1; i <= n; i++) printf( %d %d n , 0, i); return 0; }
#include <bits/stdc++.h> using namespace std; int t, n, m; long long now, ans; char ch[1000039]; int main() { scanf( %d , &t); while (t--) { scanf( %d %s , &m, ch + 1); n = ans = strlen(ch + 1), now = n - 1; for (int a = 1; a <= m; a++) { for (int b = 1, c = n; b < ch[a] - 0...
#include <bits/stdc++.h> using namespace std; int n, m; int q; int in[100005], out[100005]; vector<int> g[100005]; long long ans; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= m; i++) { int u, v; scanf( %d%d , &u, &v); if (u < v) swap(u, v); out[u]++; in[v]...
#include <bits/stdc++.h> using namespace std; void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int32_t main() { c_p_c(); string str; getline(cin, str); vector<long long> vec; long long z = 1; for (long long i = 0; i < str.length(); i++) { if (str[...
#include <bits/stdc++.h> int arr[500005], st[500005][25], fa[500005][25], bit[500005]; inline int calc(int x, int y) { if (arr[x] <= arr[y]) return x; return y; } inline int query(int l, int r) { if (l < 0 || l > r) return 0; int len = bit[r - l + 1]; return calc(st[l][len], st[r - (1 << len...
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1); struct point { long double x, y; point(long double x = 0, long double y = 0) : x(x), y(y) {} point operator+(const point &o) const { return point(x + o.x, y + o.y); } point operator-(const point &o) const { return point...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch <= 9 && ch >= 0 ) { x = 10 * x + ch - 0 ; ch = getchar(); } return x * f;...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int N = 1e6; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; if (n % 2 == 0) { cout << white n1 2 ; } else { cout << black n ; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, flag = 0, i, j; cin >> a >> b >> c; for (i = 0; i <= c; i++) { for (j = 0; j <= c; j++) { if (a * i + b * j == c) { flag = 1; break; } } if (flag == 1) break; } if (flag ...
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y) { long long int res = 1; while (y) { if (y % 2) { res = (res * x) % 1000000007; } y = y >> 1; x = (x * x) % 1000000007; } return res; } void solve() { long long...
#include <bits/stdc++.h> using namespace std; struct node { int val, num; } q[1000005]; char str[1000005]; int len; void update() { int len1 = len; len = 0; for (int i = 1; i <= len1; i++) if (q[i].num > 0) { if (q[i].val == q[len].val) q[len].num += q[i].num; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; while (scanf( %d%d , &n, &m) == 2) { map<int, vector<int>> s; for (int i = 0; i < n; ++i) { int x; scanf( %d , &x); s[x].push_back(i); } int flag = 1; vector<int> ans(m); for (int...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m; vector<pair<long long, int> > v; vector<int> u[N]; int vis[N]; void dfs(int s) { if (!vis[s]) { vis[s] = true; for (int i = 0; i < u[s].size(); i++) { dfs(u[s][i]); } } } int main() { i...
#include <bits/stdc++.h> using namespace std; template <class T> T max(T a, T b, T c) { return max(a, max(b, c)); } template <class T> T min(T a, T b, T c) { return min(a, min(b, c)); } const double PI = 2.0 * acos(0.0); const int mx[] = {0, 1, 0, -1}; const int my[] = {-1, 0, 1, 0}; int n...
#include <bits/stdc++.h> int64_t f(int64_t a, int64_t b, int64_t c, int64_t l) { int64_t total = 0; for (int64_t la = 0ll; la <= l; ++la) { int64_t x = std::min(a - b - c + la, l - la); if (x >= 0) total += (x + 1) * (x + 2) / 2ll; } return total; } int main() { int64_t a, b, c, l;...
#include <bits/stdc++.h> const int MAXN = 1001; using namespace std; char s[MAXN + 1], heidi[MAXN + 1]; int main() { int n, i, poz; scanf( %s , &s); n = strlen(s); i = 0; poz = 0; heidi[0] = h ; heidi[1] = e ; heidi[2] = i ; heidi[3] = d ; heidi[4] = i ; while (i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int cases; cin >> cases; for (int i = 0; i < cases; i++) { int a, b; cin >> a >> b; if (a > b) swap(a, b); int dis = b - a; if (dis == 0) ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } int main() { int k; cin >> k; long long a; while (k--) { cin >> a; long long g = gcd(a + 1, a * 4); long long l = (a + 1) * a * 4 / g; ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n, m, xa = 55, xb = -1, ya = 55, yb = -1; char g[50][50]; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> g[i][j]; if (g[i][j] == * ) { xa = m...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int i, j; int k, n, s, p; cin >> k >> n >> s >> p; cout << int(ceil((ceil(n / (s * 1.0)) * k) / (p * 1.0))); return 0; }
#include <bits/stdc++.h> using namespace std; int n, m; char c[3001][3001]; int d[3001][3001]; long long dp(int sx, int sy, int ex, int ey) { memset(d, 0, sizeof(d)); if (c[sx][sy] != # ) d[sx][sy] = 1; for (int i = sx; i < n; i++) { for (int j = sy; j < m; j++) { if (d[i][j] > 0) {...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, ans = 0; long long sum_a = 0, sum_b = 0; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; sum_a += a[i]; } cin >> m; vector<int> b(m); for (int i = 0; i < m; ++i) { cin >>...
#include <bits/stdc++.h> using namespace std; int ar[10000]; int main() { int n, m, i, j, x = 0; cin >> n >> m; char a[n][2 * m]; for (i = 0; i < n; i++) { for (j = 0; j < 2 * m; j++) cin >> a[i][j]; } for (i = 0; i < n; i++) { for (j = 0; j < 2 * m; j = j + 2) { if (a[...
#include <bits/stdc++.h> using namespace std; void solve() {} int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s, q; cin >> s >> q; int index = 1; for (int i = 0; i < q.size(); i++) { if (s[index - 1] == q[i]) index++; } cout << index << n ; ret...
#include <bits/stdc++.h> using namespace std; int n, m, s, C[1001][2001]; int main() { for (int i = 0; i <= 1000; i++) { C[i][0] = C[i][i] = 1; for (int j = 1; j < i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007; } scanf( %d%d%d , &n, &m, &s); printf( %d n , int(...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; long long a[maxn], b[maxn]; int n; long long ans; inline long long read() { long long ans = 0; char ch = getchar(); while (ch < 0 || ch > 9 ) ch = getchar(); while (ch >= 0 && ch <= 9 ) { ans = ans * 10 + ch ...
#include <bits/stdc++.h> using namespace std; vector<long long> prime(long long N) { bool isPrime[N + 1]; vector<long long> c; for (long long i = 0; i <= N; ++i) { isPrime[i] = true; } isPrime[0] = false; isPrime[1] = false; for (long long i = 2; i * i <= N; ++i) { if (isPrim...