func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); long long int a, b; cin >> a >> b; vector<long long int> m; vector<long long int> n; set<long long int> s; m.push_back(1); n.push_back(1); if (a == 1) s.insert(1);...
#include <bits/stdc++.h> using namespace std; void rd(int &x) { x = 0; int f = 1; char ch = (getchar()); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = (getchar()); } while (isdigit(ch)) x = x * 10 + ch - 0 , ch = (getchar()); x *= f; } const int N = 5e5 + 5; int n...
#include <bits/stdc++.h> using namespace std; int n, A[105], B[105], w, ans, tmp; int main() { scanf( %d , &n); n *= 2; for (int i = (0); i < (n); i++) scanf( %d , &A[i]); sort(A, A + n); ans = 123412345; for (int i = (0); i < (n); i++) for (int j = (i + 1); j < (n); j++) { w...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; vector<int> g[maxn]; int father[maxn]; int a[maxn]; int findfather(int x) { int a = x; while (x != father[x]) x = father[x]; while (a != father[a]) { int z = a; a = father[a]; father[z] = x; } ret...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5, INF = 0x3f3f3f3f; int a[maxn]; int last[maxn]; int main() { int n; while (cin >> n) { memset(last, INF, sizeof(last)); for (int i = 0; i < n; i++) { cin >> a[i]; last[a[i]] = i; } sort(last,...
#include <bits/stdc++.h> using namespace std; char seat[10][1005]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int mark = 2000; int flag; for (int i = 0; i < n; i++) { cin >> seat[0][i] >> seat[1][i] >> seat[2][i] >> seat[3][i] >> seat[4][i]; if (...
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> dp[2001][26]; int q[2000]; pair<int, int> ans[2001][2001]; int nxt[2001][26]; pair<int, int> jump(pair<int, int> p, char c) { if (p.first < m) { p.second = dp[q[p.first]][c - a ][p.second]; if (p.second == -1) { p...
#include <bits/stdc++.h> using namespace std; long long n, k, a, ans, i, b[10000000]; string s, s1; int main() { cin >> n >> s; s1 = 0 ; s1 += s; s1 += 0 ; s = s1; a = s.find( 11 ); if (a < 10000) return cout << No , 0; a = s.find( 000 ); if (a < 10000) return cout << No ...
#include <bits/stdc++.h> const long double eps = 1e-9; const double pi = acos(-1.0); const long long inf = 1e18; using namespace std; int a[33], b[33], p[33], k[33], n, r, u, tt[33], z[33], back[33]; int cnt = 0; long long ans = -inf; void update(int step) { int left = (u - step) % 2; long long ...
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; using namespace std; void file(bool opt) { if (opt && fopen( in.txt , r )) freopen( in.txt , r , stdin), freopen( out.txt , w , stdout); } struct node { double x, y; } point[100000 + 5], tu[100000 + 5]; int tot = 0; int n; double mu...
#include <bits/stdc++.h> using namespace std; namespace Work { const int kMaxN = 100010; multiset<int> set; int n; int a[kMaxN], b[kMaxN]; int pos[kMaxN]; void solve(FILE* fin, FILE* fout) { fscanf(fin, %d , &n); for (int i = 1; i <= n; i++) { fscanf(fin, %d , a + i); pos[a[i]] = i...
#include <bits/stdc++.h> using namespace std; int main() { string x, y; cin >> x >> y; int sum = atoi(x.c_str()) + atoi(y.c_str()); int p = 0, now = 1; for (; sum; sum /= 10) { if (sum % 10 != 0) { p += (sum % 10) * now; now *= 10; } } x.erase(remove(x.begin()...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<int, int> > vec(n); vector<int> x(n); vector<int> y(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; vec[i].first = x[i]; vec[i].second = y[i]; } long long ans = 0; sor...
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; int ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { int a; cin >> a; if (i == j || i + j == n - 1 || i == n / 2 || j == n / 2) ans += a; } cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) cout << -1 << n ; else cout << n << << n + 1 << << n * 1LL * (n + 1) << n ; }
#include <bits/stdc++.h> using namespace std; vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.emplace_back(x); return move(v); } void err(vector<string>::iterator it) {} template <typename T, typename... Args> vo...
#include <bits/stdc++.h> using namespace std; const long long oo = 1e16; template <class P> P gcd(P a, P b) { return b ? gcd(b, a % b) : a; }; long long read() { char c = getchar(); long long d = 0, f = 1; for (; c < 0 || c > 9 ; c = getchar()) if (c == - ) f = -1; for (; c >= ...
#include <bits/stdc++.h> using namespace std; const int maxRounds = 200000; double p[110], ans, pw[110][maxRounds + 10]; int times[110], n; int main() { cin >> n; if (n == 1) { cout << 1; return 0; } for (int i = 1; i <= n; ++i) { int first; cin >> first; p[i] = f...
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, maxx = 2, s = 1, k = 1; cin >> n; vector<int> a(n); for (i = 0; i < n; i++) cin >> a[i]; a.push_back(0); for (i = 0; i < n; i++) { if (i > 0 && s > 1 && a[i] == 1 && a[i - 1] == 2) s = 1; if (i > 0 && k > ...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, f, k; scanf( %lld %lld %lld %lld , &a, &b, &f, &k); long long ans = 0; long long cfuel = b; for (int i = 0; i < k - 1; i++) { if (i % 2 == 0) { if (cfuel >= 2 * a - f) { cfuel -= a; } else ...
#include <bits/stdc++.h> using namespace std; void rs(int &x) { scanf( %d , &x); } void rsl(long long &x) { scanf( %I64d , &x); } void rsd(double &x) { scanf( %lf , &x); } void rss(char *str) { scanf( %s , str); } void ws(int &x) { printf( %d , x); } void wsl(long long &x) { printf( %I64d , x); } void...
#include <bits/stdc++.h> using namespace std; int generateb(int a, long int nos[], long int noa[], long int nob[]) { int i, minb = 100002; for (i = 0; i < 26; i++) { nos[i] = nos[i] - (noa[i] * a); } for (i = 0; i < 26; i++) { if (nob[i] != 0) { if (nos[i] / nob[i] < minb) { ...
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define rep(i, a, b) for(int i = a; i < (b); ++i) #define per(i, a, b) for(int i = b-1; i>=a ; i--) #define trav(a, x) for(auto& a : x) #define allin(a , x) for(auto a : x) #define all(x) begin(x), end(x) #define sz(x) (int...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; const int maxn = 100086; const double PI = atan(1.0) * 4.0; const double eps = 1e-9; const long long mod = 1000000007; const int maxe = 10086 * 2; long long quick_pow(long long a, long long n) { long ...
#include <bits/stdc++.h> using namespace std; const int mo = 1e9 + 7; struct node { int mat[210][210]; } qwq; int n, k, m; inline int ha(int x, int y) { return x * (1 << m) + y; } node ksm(int l) { if (l == 1) return qwq; node op = ksm(l / 2), op2; memset(op2.mat, 0, sizeof(op2.mat)); ...
#include <bits/stdc++.h> using namespace std; const int MN = 2011; int n, a[MN]; vector<int> ls[MN]; void solve1(int u) { cout << YES << endl; for (int turn = 0, _a = (3); turn < _a; turn++) { for (int i = (1), _b = (2000); i <= _b; i++) { if (i != u) { for (int x = 0, _a = (...
#include <bits/stdc++.h> using namespace std; const int N = 1e5; const int sqrtN = 320; int countA[sqrtN], countP[sqrtN]; map<int, int> dm[sqrtN]; void recomp(int ind) { int a, p; a = p = 0; for (auto& x : dm[ind]) { if (x.second != -1) { if (p != 0) p--; else ...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) int ah = 911382323; int bh = 972663749; template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << ( << p.first << , << p.second << ) ; } template <typename T> ostream &ope...
#include <bits/stdc++.h> using namespace std; const int N = 2e6; int cost[N], n, a, b, T; string s; long long l[N], r[N]; bool check(int d) { --d; long long bst = min(l[d], r[d]); for (int i = 1; i < d; ++i) { bst = min(bst, l[i] + r[d - i] + a * i); bst = min(bst, r[i] + l[d - i] + ...
#include <bits/stdc++.h> using namespace std; int a, s, d, f, g, h, j, k, l, i, n, m; string x[2], z[2]; char c; int dfs(int i1, int i2, int tri) { if (x[0] == z[0] && x[1] == z[1]) { return 1; } if (tri < 0) return 0; int ret = 0; if (i1 < 1) { c = x[i1][i2]; x[i1][i2] =...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; long long a(-1), b(-1), ans(INT_MAX), tempA, tempB; for (int i = 0;; i++) { if (i * 7 > n) { break; } if ((n - i * 7) % 4 == 0) { tempA = (n - i * 7) / 4; tempB = i; ...
#include <bits/stdc++.h> using namespace std; long long ans; int n, a, b; vector<pair<int, int> > v; int main() { ans = 0; scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %d %d , &a, &b); v.push_back(make_pair(b, a)); } sort(v.begin(), v.end()); for (int i = 0, j = 0;...
#include <bits/stdc++.h> using namespace std; using cd = complex<double>; const double PI = acos(-1); int reverse(int num, int lg_n) { int res = 0; for (int i = 0; i < lg_n; i++) { if (num & (1 << i)) res |= 1 << (lg_n - 1 - i); } return res; } void fft(vector<cd> &a, bool invert) { ...
#include <bits/stdc++.h> using namespace std; struct segtree { int n; vector<long long> tree; void init(int s) { n = s; tree.resize(4 * s); } long long qry(int i, int j) { return qry(i, j, 1, 0, n - 1); } void upd(int i, long long v) { upd(i, v, 1, 0, n - 1); } long long qry(...
#include <bits/stdc++.h> using namespace std; int N, K; vector<int> arr; struct Query { int l, r, p, q; }; vector<Query> query, tmp; vector<vector<long long> > dp; vector<int> cnt; int lpos, rpos; long long cost; void solve(int k) { query.push_back({0, N - 1, 0, N - 1}); while (query.s...
#include <bits/stdc++.h> using namespace std; int main() { double d, h, v, e; while (~scanf( %lf%lf%lf%lf , &d, &h, &v, &e)) { double v1, v2; v1 = (d / 2) * (d / 2) * 3.1415927 * e; v2 = (d / 2) * (d / 2) * 3.1415927 * h; if (v1 >= v) printf( NO n ); else { doub...
#include <bits/stdc++.h> using namespace std; int n, m; int tot = 1; int b[200005], e[200005], h[200005], p[200005], u[200005]; vector<int> ans[200005]; void add(int x, int y) { b[++tot] = y; e[tot] = h[x]; h[x] = tot; } void dfs(int k, int fa_edge) { p[k] = 1; for (int go = h[k]; go...
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int n; int neg = 0; string s[N + 5]; inline long long pars(int x) { long long ret = 0LL; for (int i = 0; i < s[x].size(); i++) { if (s[x][i] == - ) continue; if (s[x][i] == . ) break; ret *= 10; ret += s[x][i]...
#include <bits/stdc++.h> using namespace std; int n; int sum; int l, r; int ans = 360; int a[360]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; while (r < n) { sum += a[r]; while (sum >= 180) { ans = min(ans, 2 * abs(180 - sum)); sum -= a[l]; ...
#include <bits/stdc++.h> using namespace std; int n, f, d; int main() { cin >> n; if (n % 3 != 2) d = n / 3; else d = n / 3 + 1; f = d / 12; d %= 12; cout << f << << d; return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 1000000001; const long long int LLINF = 1000000000000000001LL; struct ITree { vector<long long int> T; int p = 1; ITree(int n) { while (p < n) p *= 2; T.resize(2 * p - 1, 0); } int par(int...
#include <bits/stdc++.h> using namespace std; using LL = long long; constexpr int N = 1e5 + 5; void solve() { int a, b; cin >> a >> b; if (a * 2 <= b) cout << a << << a * 2 << n ; else cout << -1 -1 n ; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int S = 40; const unsigned long long mod = 998244353; struct poly { int a[S + 10]; inline int& operator[](const int& x) { return a[x]; } poly() { for (int i = 0; i < S; i++) a[i] = 0; } friend poly operator*(...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, k, m, x, ans = 0; cin >> n >> k >> m; vector<pair<long long, long long> > v; for (int i = 0; i < n; i++) { cin >> x; if (v.empty() || (v.back().first != x)) { ...
#include <bits/stdc++.h> #pragma optimize( avx ) #pragma optimize( no-stack-protector ) namespace io { inline char gnc() { return (char)getchar(); } template <typename T> inline void gi(T &dx) { dx = 0; int yc = gnc(); bool nega = false; while (yc < 0 || yc > 9 ) { nega = (yc == - ...
#include <bits/stdc++.h> using namespace std; const long long A = 100000000000000LL, N = 300005; long long p, d, limit; long long cal(long long p) { int x = 0; if (p % 10 != 9) return 0; while (p % 10 == 9) { x++; p /= 10; } return x; } int main() { cin >> p >> d; lim...
#include <bits/stdc++.h> using namespace std; int main() { int data[100]; int n, x, y; cin >> n >> x >> y; int c = 0; for (int i = 0; i < n; i++) { cin >> data[i]; if (data[i] <= x) c++; } if (x > y) { cout << n; } else { if (c % 2 == 0) { cout << c / ...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long int n, c[100005], dp[100005][2], i, j; cin >> n; string s[100005], rs[100005]; for (i = 1; i <= n; i++) cin >> c[i]; ...
#include <bits/stdc++.h> using namespace std; map<pair<long long unsigned, long long unsigned>, pair<long long unsigned, long long unsigned> > dp; long long unsigned n; void read() { cin >> n; return; } pair<long long unsigned, long long unsigned> find(long long unsigned s, ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 10001001; int min_div[MAXN]; vector<long long> primes; void criba() { for (int i = (int)0; i < (int)MAXN; i++) min_div[i] = i; for (int i = (int)2; i < (int)MAXN; i++) { if (min_div[i] != i) continue; primes.push_back(i); ...
#include <bits/stdc++.h> const int N = 1e5 + 5; int n; char c[N]; int main() { int T = 1; scanf( %d , &T); while (T--) { scanf( %s , c + 1); n = strlen(c + 1); printf( %d n , 4); printf( L 2 n ); printf( L 2 n ); printf( R 2 n ); n += 2; n += n - 2; ...
#include <bits/stdc++.h> using namespace std; char grid[1005][1005]; int lewo[1005][1005], prawo[1005][1005], gora[1005][1005], dol[1005][1005]; bool odwiedzony[1005][1005]; vector<pair<int, int> > przedzialy_x[1005], przedzialy_y[1005]; vector<pair<pair<int, int>, int> > wynik; int main() { ios_base:...
#include <bits/stdc++.h> using std::bitset; using std::cin; using std::cout; using std::endl; using std::make_pair; using std::map; using std::pair; using std::priority_queue; using std::queue; using std::set; using std::string; using std::stringstream; using std::vector; class MyTimer { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; void qr(int &x) { scanf( %d , &x); } int n, sz[N], f[N], root, c[N]; long long k, mn, mx; struct edge { int y, next; } a[N * 2]; int len, last[N]; void ins(int x, int y) { a[++len] = (edge){y, last[x]}; last[x] = len; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 111111; const int INF = 0x3f3f3f3f; int vis[maxn]; bool selected[maxn]; int n, m; vector<int> adj[maxn]; bool test[maxn]; double elapsed() { return clock() / (double)CLOCKS_PER_SEC; } bool dfs(int v) { if (selected[v] == true) return...
#include <bits/stdc++.h> using namespace std; inline int gi() { char c; int num = 0, flg = 1; while ((c = getchar()) < 0 || c > 9 ) if (c == - ) flg = -1; while (c >= 0 && c <= 9 ) { num = num * 10 + c - 48; c = getchar(); } return num * flg; } int n, m; int fi...
#include <bits/stdc++.h> using namespace std; long long a[212345], sumi, wow, i; int main() { std::ios::sync_with_stdio(false); int n; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; sumi += a[i]; } wow = 0; for (i = 0; i < n; i++) { wow += a[i]; if (2 * wow >=...
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9, maxn = (int)1e5 + 1; const double eps = (double)1e-8; const int mod = (int)1000000009; int n, a[1001], x, y, xx, yy, z, my, mx; vector<pair<int, bool> > b[3000]; string c, st; int main() { my = 1500; z = 1500; cin >> n; ...
#include <bits/stdc++.h> using namespace std; int H, M, N; set<int> a[200005]; int p[200005], seq[200005], r = 0; int u[200005]; map<int, pair<int, int> > history; void release(pair<int, int> P) { a[P.first].insert(P.second); } int main(void) { scanf( %d%d%d , &H, &M, &N); for (int i = 0; i < H;...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { int n; cin >> n; int graph[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { graph[i][j] = INF; } } for (int i = 0; i < n - 1; i++) { int a, b, c; cin >> a >> b ...
#include <bits/stdc++.h> using namespace std; const int max_n = 300333, inf = 1011111111; int n, m, a[max_n], used[max_n], pos, lb[max_n]; vector<int> g2[max_n], num2[max_n], g[max_n], num[max_n], k, ans; void dfs(int v) { used[v] = 1; for (int i = 0; i < g2[v].size(); ++i) { if (used[g2[v][i]] ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; int ans; scanf( %d%d%d , &a, &b, &c); ans = (a - b) * c; if (!(ans % b)) ans /= b; else { ans /= b; ans += 1; } printf( %d n , ans); return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 100005, INF = 1e18; void solve() { long long n, ans = 0, max = 0; cin >> n; ans = n / 2; cout << ans << n ; for (long long i = (long long)0; i < ans - 1; i++) { cout << 2 ; } if (n % 2 == 0) cout << 2 << ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010, maxp = 1000010; int x[maxn], dp[maxp][20], can[maxp], f[maxp]; int n, a, b; inline void chkmax(int& a, int b) { if (a < b) a = b; } inline void chkmin(int& a, int b) { if (a > b) a = b; } int getmin(int l, int r) { int ...
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> g[100000]; vector<int> rev_g[100000]; vector<int> post_order; vector<bool> visited; vector<int> scc; void dfs1(int x) { if (visited[x]) return; visited[x] = true; for (auto y : g[x]) dfs1(y); post_order.push_back(x); }...
#include <bits/stdc++.h> using namespace std; int n, k; int query(int x, int y) { cout << 1 << x << << y << endl; string ans; cin >> ans; if (ans == TAK ) return 1; return 0; } int find(int l, int r) { if (l > r) return -1; int L = l; int R = r; while (L < R) { ...
#include <bits/stdc++.h> using namespace std; int i, j, k, s, t; int read() { int x = 0; char ch = getchar(); while (ch < 0 || ch > 9 ) ch = getchar(); while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } return x; } int n1, n2, n3, p1, p2, p3, m1, m...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const int mod = 1e9 + 7; struct edge { int u, v, t, c, id; } e[N]; int n, m; vector<edge> s[N]; bool cmp(edge a, edge b) { return a.c < b.c; } struct TwoSat { static const int N = ::N << 1; int dfn[N], low[N], id[N], st[N...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; const long long MOD = 1000000007; long long n, k; long long pre[MAXN], suf[MAXN], fac[MAXN], ifac[MAXN]; inline long long quick_pow(long long x, long long k) { long long res = 1; while (k) { if (k & 1) (res *= x) %= MOD; ...
#include <bits/stdc++.h> using namespace std; string st; double ans = 0.0, curr = 0.0; int flag = 0; int main() { cin >> st; for (int i = 0; i < st.size(); i++) { if ( a <= st[i] && st[i] <= z ) { ans += curr; curr = 0.0; continue; } if (st[i] == . ) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10, MAXM = 1e6 + 10; const int INF = INT_MAX, SINF = 0x3f3f3f3f; const long long llINF = LLONG_MAX; const int MOD = 1e9 + 7, mod = 998244353; const int inv2 = 5e8 + 4; long double x, y, z; long double a[MAXN]; string s[MAXN]; int m...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int sum(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; } int sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; } int mul(int a, int b) { return (1LL * a * b) % MOD; } const int MAXN = 1e6 + 7; int shuru[MAXN], she...
#include <bits/stdc++.h> using namespace std; const int N = 5E4 + 5; const int M = N * 17 * 17; int n, m, q, x, y, son[N], dep[N], fa[N], g[N], l[N], tot, f[N], mark[M], to[N], ch[M][2], sum, c[N], a[N], k, b[N]; long long ans[N], tr[M], C; vector<int> G[N]; int dfs(int x) { int y; son[x] = ...
#include <bits/stdc++.h> using namespace std; const int NN = 50010; const int INF = 0x3f3f3f3f; const int MOD = 100000, STA = 8000010; const long long LNF = 1LL << 60; const double EPS = 1e-8; const double OO = 1e15; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, 1, 0, -1}; const int day[13]...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); ; int n, k; cin >> n >> k; while (n > 0 && k > 0) { k--; if (n % 10 == 0) n = n / 10; else n--; } cout << n << n ; return 0; }
#include <bits/stdc++.h> using namespace std; long long A[200005], tree[200005]; void update(int pos, long long v) { for (; pos < 200005; pos += pos & -pos) tree[pos] += v; } long long read(int pos) { long long ret = 0; for (; pos; pos -= pos & -pos) ret += tree[pos]; return ret; } int mai...
#include <bits/stdc++.h> using namespace std; map<int, int> sg; map<int, bool> us; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { int x, d; cin >> x >> d; sg[x] = x + d; us[x] = true; if (us[x + d] && sg[x + d] == x && sg[x] == x + d) { cout << YE...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int v = 0; map<int, int> s; for (int i = 19; s.size() < 10010; i += 9) { int kk = i; int c = 0; while (kk > 0) { c += kk % 10; kk /= 10; } if (c == 10) s[v++] = i; } ...
#include <bits/stdc++.h> using namespace std; struct data { int le, ri, cnt; data(int le_ = 0, int ri_ = 0, int cnt_ = 0) { le = le_; ri = ri_; cnt = cnt_; } }; const int N = 1e6 + 10; int seg[4 * N + 10]; int brk[5][4 * N + 10]; int n; void add(int idx, bool b, int L = 0, ...
#include <bits/stdc++.h> using namespace std; long long f[1 << 10], M = 1000000; long long l, r, k; class Matrix { public: long long a[3][3]; Matrix(int fib = 0) { memset(a, 0, sizeof(a)); if (fib) a[1][2] = a[2][1] = a[2][2] = 1; } Matrix operator*(const Matrix &v) { Matrix...
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { return (a > b ? a : b); } long long min(long long a, long long b) { return (a < b ? a : b); } void algo() { string s1, s2; char c; cin >> s1 >> s2; long long j = 0, len = s1.size(); for (long long i = 0; ...
#include <bits/stdc++.h> using namespace std; double const EPS = 1.0E-9; int const MOD = (int)1e9 + 7; inline void read(char* s) { scanf( %s , s); } inline void read(int& x) { scanf( %d , &(x)); } inline void read(long long& x) { scanf( %lld , &x); } inline void read(double& x) { scanf( %lf , &x); } inl...
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; const int MAX_LENGTH = 100000 + 8; const ull B = 100000007ULL; char s[3][MAX_LENGTH]; ull H[3][MAX_LENGTH], B_to[MAX_LENGTH] = {1ULL}; int id[3] = {0, 1, 2}, len[3]; void init_hash() { for (int i = 0; i < 3; ++i) { f...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (a < b) swap(a, b); if (b == 0) return a; while (b) { long long int re = a % b; a = b; b = re; } return a; } vector<int> a[1000 + 10], b[1000 + 10]; vector<int> c1(1000 ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int val[maxn]; int sito[maxn]; int main() { ios::sync_with_stdio(false); for (int i = 0; i < maxn; i++) { sito[i] = true; } vector<int> v; sito[0] = sito[1] = false; for (int i = 2; i < maxn; i++) { if (...
#include <bits/stdc++.h> using namespace std; long long sqr(long long x) { return x * x; } bool done = false; int p[8][3]; bool same(double x, double y) { return abs(x - y) < 1e-9; } int cnt = 0; void backtr(int idx) { if (done) return; if (idx == 7) { cnt++; map<long long, int> ck; ...
#include <bits/stdc++.h> using namespace std; const long long N = 30; bool vis[N]; int id1 = -1, id2 = -1; char ch; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int n = 27; for (int i = 0; i < 27; i++) { if (vis[s[i] - A ]) { id2 = i; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 4; void solve() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; float min = 4.5 * n; int mn = (int)min; if (min - mn > 0) mn++; int sum = 0; for (int i = 0; i < n; i++) sum += arr[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i; scanf( %d%d , &n, &k); char s[n]; scanf( %s , s); for (i = 0; i < n; ++i) { if (s[i] == G ) { for (int j = i + k; j < n; j += k) { if (s[j] == # ) { printf( NO n ); return 0;...
#include <bits/stdc++.h> using namespace std; const int N = 100010; const int S = 550; int n, q, a[N]; struct Block { int lid, rid; deque<int> que; int mp[N]; Block() {} void init() { lid = rid = 0; que.clear(); memset(mp, 0, sizeof mp); } void addf(int x) { ...
#include <bits/stdc++.h> using namespace std; int n, f, r[4]; char names[4][16] = { Gryffindor , Hufflepuff , Ravenclaw , Slytherin }; int main() { scanf( %d , &n); vector<vector<int> > v; v.push_back(vector<int>(4)); for (int k = 0; k < (int)(n); k++) { char op; scanf( %c , &op)...
#include <bits/stdc++.h> using namespace std; int i, L; char s[100005]; int main() { scanf( %s , &s); L = strlen(s); for (i = 0; i < L; i++) printf( %c , s[i]); for (i = L - 1; i >= 0; i--) printf( %c , s[i]); }
#include <bits/stdc++.h> using namespace std; int N; vector<int> adj[200005]; int dfs(int cur, int prv, bool valid) { int cnt = valid; for (int nxt : adj[cur]) if (nxt != prv) cnt += dfs(nxt, cur, !valid); return cnt; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie...
#include <bits/stdc++.h> using namespace std; map<string, string> m; int main() { long long int n, mm, i; string s, b, s1, b1; cin >> n >> mm; for (i = 0; i < n; i++) { cin >> s >> b; m[b] = s; } char c; for (i = 0; i < mm; i++) { cin >> s1 >> b1; int l = b1.len...
#include <bits/stdc++.h> using namespace std; const int N = 2000010; long long n, m, s, l; vector<pair<long long, long long> > Adj[N]; long long Dis[N], Ans; set<pair<long long, long long> > Res; vector<pair<long long, pair<long long, long long> > > Edges; void Dik() { for (int i = 0; i <= n; i++) D...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, k, x, y; cin >> n >> k; if (n > k) { x = k * (k + 1); x = x / 2; cout << x << endl; } else { y = n - 1; x = y * (y + 1); ...
#include <bits/stdc++.h> using namespace std; const double EPSILON = 1e-9; const double PI = acos(0.0) * 2; const int MOD = 1000000007; const int INF = 0x3c3c3c3c; const long long INFL = 0x3c3c3c3c3c3c3c3c; const int MAX_N = 102; long long S, X; long long solve(long long sum, int pos) { if (sum > ...
#include <bits/stdc++.h> using namespace std; int main() { int n = 0; long long q, p = 1; cin >> q; for (int i = 0; i < 2; i++) { for (long long s = 2; s * s <= q; s++) { if (q % s == 0) { n++; p *= s; q /= s; break; } } } i...
#include <bits/stdc++.h> using namespace std; const int N = 212345; int seg[4 * N], v[N], tin[N], tout[N], ans[N]; int a, b, n, q; void init(int r, int i, int j) { if (i == j) { seg[r] = v[i]; } else { init(2 * r, i, (i + j) / 2); init(2 * r + 1, (i + j) / 2 + 1, j); seg[r] = m...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int th = 0; for (int i = 1; i < n; i++) { th += i; th %= n; cout << (th + 1) << ; } return 0; }