func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; double eps = 1e-7; int n, m, A, B, a[6010]; int cmp(double x) { if (x > eps) return 1; if (x < -eps) return -1; return 0; } struct line { double k, b; line(double _k, double _b) { k = _k, b = _b; } line(double __x) { k = 2, b = -2 * __x; ...
#include <bits/stdc++.h> using namespace std; const int N(1e5 + 5), M(1e5 + 5); struct edge { int u, v, nt, type, flag; } E[M << 1]; int head[N]; int d[N]; queue<int> que; void bfs(int s, int *d) { memset(d, -1, sizeof(int[N])); que.push(s), d[s] = 0; while (!que.empty()) { int u =...
#include <bits/stdc++.h> using namespace std; char s1[200100], s2[200100]; vector<int> pos[26]; long long sum1[27][200100]; long long sum2[27][200100]; int main() { int n; scanf( %d , &n); long long res2 = 0; for (int i = (1); i < (n + 1); ++i) res2 += (n - i + 1) * 1ll * (n - i + 1); sc...
#include <bits/stdc++.h> using namespace std; int n, i, j; pair<pair<int, int>, int> a[100002]; bool lav(int i) { int x1, u1, x2, u2, x3, u3; x1 = a[i].first.first; u1 = a[i].first.second; x2 = a[i + 1].first.first; u2 = a[i + 1].first.second; x3 = a[i + 2].first.first; u3 = a[i + 2]...
#include <bits/stdc++.h> using namespace std; template <typename T> void print1d(vector<T> &a) { for (long long int i = 0; i < a.size(); i++) { cout << a[i] << ; } cout << endl; } vector<long long int> divisor(long long int n) { vector<long long int> a; for (long long int i = 1; i...
#include <bits/stdc++.h> const int N = 1010; int sit[N], a[N]; int n, m, c; void ask(int x, int pos) { printf( %d n , pos); a[pos] = x; fflush(stdout); bool flag = true; for (int i = 1; i <= n; ++i) { if (!a[i]) { flag = false; break; } } for (int i = 1; i...
#include <bits/stdc++.h> inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } inline void sub(long long &a, long long b) { a -= b; if (a < 0) a += 1000000007; } inline void add(long long &a, long long b) { a += b; if (a >= 1000000007) a -= 1000000007; } template <...
#include <bits/stdc++.h> using namespace std; int main() { long long int x, y, z; cin >> x >> y >> z; cout << (x + y) / z << ; if (x / z + y / z < (x + y) / z) { cout << min(z - (x % z), z - (y % z)); } else { cout << 0 ; } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long t, n, m, s, a, b, w, c; cin >> t; while (t--) { cin >> n >> s; vector<vector<pair<long long, pair<long long, long long>>>> ady(n + 1); for (int i = 1; i < n; ++i) { ...
#include <bits/stdc++.h> using namespace std; double e[1010][510]; double c[510], b[510]; int main() { int n, m, in, im; scanf( %d%d%d%d , &n, &m, &in, &im); if (m == 1) { e[n][1] = 0.0; for (int i = n - 1; i >= in; --i) { e[i][1] = 2 + e[i + 1][1]; } printf( %.9lf n ...
#include <bits/stdc++.h> using namespace std; const int N = 105; const int mod = 1e9 + 7; long long n, m, x; long long dp[2][320][320][2]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); if (fopen( A.inp , r )) { freopen( test.inp , r , stdin); freopen( test.out , w , s...
#include <bits/stdc++.h> using namespace std; typedef long double real; string Pair[26][26]; int cost[26][26][501], dp[26][26][501]; pair<int, int> parent[26][26][501]; int n, m; char flag[501][501]; pair<int, pair<int, int> > buffer[26 * 26]; bool used[26][26]; int main() { ios_base::sync_with_...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long a[300010], cnt[300010]; long long n, k, maxx; int main() { ios_base::sync_with_stdio(false); cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; maxx = max(maxx, a[i]); } int pos = 1, ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; bool t = false; char ch = getchar(); while ((ch < 0 || ch > 9 ) && ch != - ) ch = getchar(); if (ch == - ) t = true, ch = getchar(); while (ch <= 9 && ch >= 0 ) x = x * 10 + ch - 48, ch = getchar(); retu...
#include <bits/stdc++.h> using namespace std; int n; pair<int, int> a[1000]; double findarea(pair<int, int> a, pair<int, int> b, pair<int, int> c) { return ((double)a.first * (b.second - c.second) + (double)b.first * (c.second - a.second) + (double)c.first * (a.second - b.second)) / ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 100000 + 5; const long long inf = 9e17; long long ans = inf, l, r, mid1, mid2; vector<long long> g[maxn], v; long long n, m; inline long long cost(long long mid) { long long cnt = mid - g[0].size(), tmp = 0; v.clear(); for (i...
#include <bits/stdc++.h> using namespace std; string s, a, b, c; long long f[120001], n, i, q, x, y, l, r, nom; bool abcde; int main() { ios::sync_with_stdio(0); cin.tie(0); s = What are you doing at the end of the world? Are you busy? Will you save us? ; a = What are you doing wh...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; int sg[N]; int main() { int T, n, k; scanf( %d , &T); while (T--) { scanf( %d %d , &n, &k); bool flag = true; if (k % 3 == 0) { int t = (k / 3 - 1) * 3 + 4; int s = n % t; if (s == t - 4) ...
#include <bits/stdc++.h> using namespace std; struct TreeNode { int val; TreeNode* left; TreeNode* right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; struct ListNode { int val; ListNode* next; ListNode(int x) : val(x), next(NULL) {} }; int nxt() { int x; cin >...
#include <bits/stdc++.h> using namespace std; class Solver { public: void solve() { cin >> n; long long sign = 1; long long C = n; long long three_to_i = 1; for (long long i = 1; i <= n; i++) { long long term = 2LL * (sign < 0 ? sign + mod : sign) * C; term %= mo...
#include <bits/stdc++.h> using namespace std; const int N = 300000 + 10; const int mod = 1e9 + 7; int n, q; char s[N]; long long sum[N]; long long pw[N], fibo[N], pw2[N], pw3[N]; int main() { scanf( %d%d , &n, &q); scanf( %s , s + 1); for (int i = 1; i <= n; ++i) { sum[i] = sum[i - 1] ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long long int INF = 1e12; long long int mod(long long int a) { if (a >= 0) return a; else return (-1 * a); } void swap(long long int a, long long int b) { long long int temp = a; a = b; b = temp; }...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > data; vector<vector<int> > sticks; vector<int> h; int dfs(int vertex, int last) { int longest = 0; for (int i = 0; i < data[vertex].size(); ++i) { int to = data[vertex][i]; if (to == last) continue; int len = dfs(to, ...
#include <bits/stdc++.h> const int MAXN = 3e5 + 10; const double eps = 1e-8; using namespace std; struct edge { int t, v; edge *next; } e[MAXN << 1], *h[MAXN], *o = e; void add(int x, int y, int vul) { o->t = y; o->v = vul; o->next = h[x]; h[x] = o++; } long long read() { lon...
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { string s; cin >> s; set<int> ans; for (int i = 1; i < s.size() - 1; i++) { if (s[i] == w && s[i - 1] == t && s[i + 1] == o ) { if (i + 3 < s.size() && s[i + 2] == n ...
#include <bits/stdc++.h> int adjL[201][210]; int visited[201]; int broken[201][201]; int edge[200][2]; int R[200][2]; int fine[201]; int dfs(int v, int c) { int i; int a; visited[v] = c; for (i = 1; i <= adjL[v][0]; i++) { a = adjL[v][i]; if (visited[a] != 0 || broken[v][a]) co...
#include <bits/stdc++.h> using namespace std; char s[300100]; int main() { int n, m; while (~scanf( %d %d n , &n, &m)) { gets(s); int len = strlen(s); int ans = 0; for (int i = 1; i < len; i++) { if (s[i] == . && s[i - 1] == . ) ans++; } char op[3]; int...
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { vector<vector<int> > grid; int h, w; cin >> h >> w; grid.assign(h, vector<int>(w, 0)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { scanf( %d , &grid[i...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; vector<int> fa; int n, m, q, g[300][300], x, y, c; int id(int x, int y) { return x * m + y; } int in(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; } int find(int x) { return fa[x] == x ? x : (fa[x] = find(fa[x])); } i...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string inst; cin >> inst; int total = 0; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { int ct_u = 0; int ct_l = 0; for (int k = i; k <= j; k++) { if (inst[k] ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e6 + 7; struct Data { long long min, max, resl, resr; }; struct TNode { long long L, R; TNode *left, *right; Data d; long long val; }; TNode *new_node(long long L, long long R) { return new TNode({L, R, nullptr, n...
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 1000 + 20; const int N5 = 300 * 1000 + 10; const int N3 = 3000 + 20; const long long mod = 1000 * 1000 * 1000 + 9; const long long inf = LLONG_MAX / 2; long long dp[2][N], par[N], rnk[N]; long long __pow(long long x, int y) { if (y =...
#include <bits/stdc++.h> using namespace std; int main() { string a, b, c; cin >> a >> b >> c; if (a[0] == c[2] && a[1] == c[1] && a[2] == c[0] && b[0] == b[2]) cout << YES << endl; else cout << NO << endl; }
#include <bits/stdc++.h> using namespace std; const long long I1 = 1e9; const long long I2 = 1e18; const int32_t M1 = 1e9 + 7; const int32_t M2 = 998244353; template <typename T, typename T1> T maxn(T &a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T minn(T &a, T...
#include <bits/stdc++.h> const long long MOD = 1000 * 1000 * 1000 + 7; const long long MOD1 = 998244353; const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7; using namespace std; long long power(long long x, long long y) { long long res = 1; while (y > 0) { if (y & 1) res = (...
#include <bits/stdc++.h> using namespace std; template <typename T, typename TT> ostream& operator<<(ostream& out, pair<T, TT> t) { return out << ( << t.first << , << t.second << ) ; } template <typename T> ostream& operator<<(ostream& out, vector<T> t) { for (int i = 0; i < ((int)(t).size()); ...
#include <bits/stdc++.h> using namespace std; const int p = 1e9 + 7, len = 1 << 16; char ch[100012]; int n, m, dp[502][100012], js, s[100012], tot, f[100012], val[100012]; inline void fwt_or(int x[], int mde) { for (int i = 2; i <= len; i <<= 1) for (int j = 0, stp = i >> 1; j < len; j += i) ...
#include <bits/stdc++.h> using namespace std; int func(int n) { int sum = 1; if (n == 3) return 4; if (n == 2) return 2; if (n == 1) return 1; if (n % 2 == 0) { sum += 2 * (n / 2 - 1) + 1 + func(n - 2); } else { sum += 2 * (n - 1) / 2 + func(n - 2); } return sum; } in...
#include <bits/stdc++.h> using namespace std; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> s; long long n = s.size(); long long a = 0, b = 0; for (auto f : s) { a += (f == 1 ); b += (f == 0 ); } long long z = n - a - b; if (a < b + z...
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 5; int a[N], n; int dp[N][N / 2][2][2]; int solve(int idx, int lft, bool b4, bool b44) { if (lft < 0) return 1e9; if (idx == n) { if (lft) return 1e9; return 0; } int &ret = dp[idx][lft][b4][b44]; if (~ret) retur...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mod = 1e9 + 7; const int sz = 1e5 + 10; int main() { int n, x; set<int> ans, st, ha; while (cin >> n) { ans.clear(); st.clear(); for (int i = 0; i < n; i++) { ha.clear(); cin >> x; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr(n + 1, -1); for (int i = 1; i <= n; i++) { int temp; cin >> temp; arr[i] = temp; } int ans = 0; vector<int> mini(n + 1, -1); vector<int> maxi(n + 1, -1); vector<int> equa...
#include <bits/stdc++.h> using namespace std; const long long mod = 51123987; string s; int n; long long d[50 + 10][50 + 10][150 + 10][3]; int NEXT[150 + 10][5]; inline int nex(int MIN, int c) { return NEXT[MIN][c]; } int main() { ios_base::sync_with_stdio(false); cin >> n >> s; for (int i =...
#include <bits/stdc++.h> using namespace std; struct node { int val, l, r; } a[100010]; int rt, n; bool to[100010]; map<int, bool> ma; vector<int> v; void dfs(int u, int maxx, int minn) { if (u == -1) return; if (a[u].val > maxx && a[u].val < minn) ma[a[u].val] = true; dfs(a[u].l, maxx, ...
#include <bits/stdc++.h> using namespace std; int n; struct node { int sig; int bz; char s[11]; int get() { int len = strlen(s); int x = 0; if (s[0] == 0 ) return 0; for (int i = 0; i < len; i++) if (s[i] < 0 || s[i] > 9 ) return 0; else ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; bool used[n]; for (int i = 0; i <= n - 1; i++) used[i] = false; int a = 0, b = n - 1; for (int i = 0; i <= k - 1; i++) { if (i & 1)...
#include <bits/stdc++.h> using namespace std; int a[26]; char s[100001]; int gcd(int a, int b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } int main() { int n, ans, sum = 0, c = 0, i, j, k, l; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d ...
#include <bits/stdc++.h> using namespace std; int main() { int d, n, a, s = 0, k; scanf( %d , &d); scanf( %d , &n); scanf( %d , &a); for (k = 1; k < n; k++) { s += d - a; scanf( %d , &a); } printf( %d n , s); return 0; }
#include <bits/stdc++.h> int main(void) { int n, m; scanf( %d %d , &n, &m); long long a[1000 + 1]; long long t[1000 + 1 + 1][1000 + 1]; for (int i = 1; i <= n; i++) { scanf( %lld , &a[i]); } for (int j = 0; j <= n; j++) t[n + 1][j] = 0; for (int i = n; i >= 1; i--) { for (i...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18 + 7; long long f[53], fac[53]; long long add(long long a, long long b) { return min(INF, a + b); } long long mul(long long a, long long b) { if (INF / a < b) return INF; return a * b; } const int N = 50; long long g(int n) ...
#include <bits/stdc++.h> using namespace std; int n; bitset<100005> m[70], tmp, tmpp; int f[100], ftop = 60; int ans[100010]; void swap(int x, int y) { tmp = m[x]; m[x] = m[y]; m[y] = tmp; } int main() { int i, j, k, d = 60; long long x, s = 0; scanf( %d , &n); for (i = 1; i ...
#include <bits/stdc++.h> using namespace std; const int max_n = 300011, log_n = 32, max_m = 111, mod = 1000000007, inf = 1011111111; const long double eps = 1e-7; struct bor { stack<pair<int, int> > st; int t[max_n][27], res[max_n], sz[max_n], n; bor() { for (int i = 0; i < max_n; ...
#include <bits/stdc++.h> using namespace std; int main() { double a, b, c, d; cin >> a >> b >> c >> d; double mx; mx = (a / b) * (1 / (1 - (1 - a / b) * (1 - c / d))); std::cout << std::setprecision(9) << mx << n ; }
#include <bits/stdc++.h> using namespace std; template <class T> inline void Read(T &x) { int f = 1; char t = getchar(); while (t < 0 || t > 9 ) { if (t == - ) f = -1; t = getchar(); } x = 0; while (t >= 0 && t <= 9 ) { x = x * 10 + t - 0 ; t = getchar(); ...
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) #pragma GCC optimize( unroll-loops ) using namespace std; long long power(long long a, long long b, long long md) { return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md))...
#include <bits/stdc++.h> using namespace std; const int MAX = 109; int a[MAX], n, k, t = 1e9, s; int main() { cin >> n; for (int i = 0; i < 2 * n - 1; i++) { cin >> a[i], s += abs(a[i]), t = min(t, abs(a[i])); if (a[i] < 0) k++; } if (k % 2 && n % 2 == 0) s -= 2 * t; cout << s; ...
#include <bits/stdc++.h> using namespace std; int nor[200100 * 2], n, t, m, a[200100], b[200100], sola, solb, sol, pcta, pctb; int main() { cin >> n; nor[++t] = 0; for (int i = 1; i <= n; ++i) { cin >> a[i]; nor[++t] = a[i]; } cin >> m; for (int i = 1; i <= m; ++i) { cin ...
#include <bits/stdc++.h> using namespace std; std::vector<int> Edge[510]; std::vector<int> Current[510]; int Right[510]; int Left[510]; int Vis[510]; int N, M; bool dfs(int idx) { if (Vis[idx]) return false; Vis[idx] = 1; for (int i = 0; i < Current[idx].size(); i++) { int v = Current[...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cin.sync_with_stdio(0); int n, t1, t2; double k; cin >> n >> t1 >> t2 >> k; k /= 100; k = 1 - k; double c[n + 1]; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; int tema = a; i...
#include <bits/stdc++.h> using namespace std; const int N = 100 * 1000 + 10; vector<int> u[N], v[N], v2[N]; vector<pair<int, int> > q[N]; int t, st[N], fi[N], di[N], g[N], par[N]; int root(int u) { return (par[u] == u) ? u : par[u] = root(par[u]); } void merge1(int x, int y) { int dx = root(x), dy = r...
#include <bits/stdc++.h> using namespace std; int main() { int a; int b; cin >> a >> b; cout.precision(13); if (b > a) { cout << -1; } else if ((a % b == 0) && ((a / b) % 2 == 1)) { cout << b; } else { int k = a / b; if (k % 2 == 0) { k--; } in...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long maxn = 3e6; const long long mod = 1e9 + 7; const long double PI = acos((long double)-1); long long pw(long long a, long long b, long long md = mod) { long long res = 1; ...
#include <bits/stdc++.h> using namespace std; int main() { puts( INTERCAL ); }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, sy, sx; cin >> n >> m >> sy >> sx; int up = sy; int down = sy + 1; int l = sx; int r = sx + 1; int k = 2; while (up >= 1) { while (l >= 1) { cout << up << << l << endl; l--; } w...
#include <bits/stdc++.h> using namespace std; int n, m; vector<pair<int, int> > a_sent; vector<pair<int, int> > b_sent; set<pair<int, int> > a_possible; set<pair<int, int> > b_possible; int vis[10]; bool certain(pair<int, int> a, vector<pair<int, int> > sent) { bool can_x = false; bool can_y = f...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, x, y, z, e, s, max1, max2, max3, max4; cin >> a >> b >> c; x = a + b * c; y = a * (b + c); z = a * b * c; e = (a + b) * c; s = a + b + c; max1 = (x + y + abs(x - y)) / 2; max2 = (max1 + z + abs(max1 - z)) / 2...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 10; const int SZ = 2e5 + 10; const int mod = 1e9 + 7; long long read() { long long n = 0; char a = getchar(); bool flag = 0; while (a > 9 || a < 0 ) { if (a == - ) flag = 1; a = getchar(); } while (a <=...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while(t--){ int n; cin >> n; if((n / 2020 > 0) && ((n % 2020) <= (n / 2020))){ cout << YES n ; }else{ cout << NO n ; } } }
#include <bits/stdc++.h> using namespace std; const int N = 100; long long f[N + 5][N + 5][N + 5]; long long fac[N + 5], C[N + 5][N + 5]; long long mod; long long dfs(int n, int m, int k) { if (n == 0) return k == 0; if (m == 1) return k == 1 ? fac[n] : 0; if (n == 1) return k == 0; if (2 * ...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; int P[N], I[N]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &P[i]); } int id = 1; for (int i = 1; i <= n; i++) { int cur = i; while (I[cur] != id) { I[cur] =...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long maxu = 200005; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long i, j, k = 0, n, t = 1, m, l = 0; cin >> t; while (t--) { cin >> n; long long a[n...
#include <bits/stdc++.h> using namespace std; int main() { int x, k, op, val1, val2; while (cin >> x >> k) { int mini = 0, maxi = 0; maxi = x - 1; vector<int> T(4005); for (int i = 0; i < k; ++i) { cin >> op; if (op == 2) { cin >> val1; T[val1] = 1...
#include <bits/stdc++.h> using namespace std; void file() {} using lli = long long int; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; void solve() { string s; cin >> s; string res = ; int z = 0, ones = 0, two = s.size(); for (int i = 0; i < s.size(); i++...
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, ans, m, j, k; string s; cin >> n >> s; ans = 0; char ch; for (i = 25; i >= 0; i--) { ch = i + a ; for (j = 1; j < (long long)s.size(); j++) { if (s[j] == ch and s[j - 1] + 1 == ch) { s.e...
#include <bits/stdc++.h> using namespace std; int main() { long long ara[20], ara1[20]; for (long long i = 1; i <= 14; i++) { scanf( %I64d , &ara[i]); } long long maxi = 0; long long sum, c; for (long long i = 1; i <= 14; i++) { if (ara[i] == 0) { continue; } ...
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int main() { vector<int> v, v1; long long a, b, c, d, e; cin >> a >> b >> c; for (int i = 0; i < b; i++) { cin >> d; v.push_back(d); } for (int i = 0; i < c; i++) { cin >> e; v1.push_back(e); } ...
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; const long long INF = 4e17; const int mod = 1e9 + 7; const double eps = 1e-9; const int N = 2e5 + 10; long long n, arr[N], tree[N << 2], lazy[N << 2]; void build(int node = 1, int L = 1, int R = n) { if (L == R) { tree[node] = ...
#include <bits/stdc++.h> using namespace std; string strA, strB, strAux; char aux; int main() { cin >> strA; cin >> strAux; aux = strAux[1]; strAux[1] = strAux[0]; strAux[0] = aux; strA += strAux; cin >> strB; cin >> strAux; aux = strAux[1]; strAux[1] = strAux[0]; str...
#include <bits/stdc++.h> using namespace std; constexpr static int MAXN = 1e6; int main() { int k, a, b; cin >> k >> a >> b; if (a > b) swap(a, b); int x = a / k; int y = b / k; if (x == 0 && y == 0) { cout << -1 << endl; return 0; } if (x == 0 && b % k > 0) { cou...
#include <bits/stdc++.h> using namespace std; int t; long long l, r; inline void solve() { cin >> t; while (t--) { cin >> l >> r; long long ans = l; for (int i = 0; i <= 62; ++i) { if (ans + (1ll << i) <= r && (ans & (1ll << i)) == 0) { ans += (1ll << i); } ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); set<int> a; int n, t; cin >> n; while (n--) { cin >> t; a.insert(t); } cout << ((a.count(0) == 1) ? a.size() - 1 : a.size()); return 0; } ...
#include <bits/stdc++.h> using namespace std; long long n; long long a[1005]; long long fac[1000005]; long long ppow(long long a, long long b) { long long c = 1; while (b) { if (b & 1) c = c * a % 1000000007; a = a * a % 1000000007; b >>= 1; } return c; } long long work(l...
#include <bits/stdc++.h> using namespace std; struct city { int x, y, p; double dis; } t[1010]; int cmp(city a, city b) { return a.dis < b.dis; } int main() { int s, n, i; while (scanf( %d%d , &n, &s) > 0) { for (i = 0; i < n; i++) { scanf( %d%d%d , &t[i].x, &t[i].y, &t[i].p); ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007LL; int n, m; int a[100005]; int main() { unordered_map<int, long long> cnt1; unordered_map<int, long long> cnt2; cnt1.clear(); cnt2.clear(); cin >> n >> m; bool isone = false; for (int i = 1; i <= m; ++i...
#include <bits/stdc++.h> using namespace std; int main() { long long n, x, y; cin >> n; cin >> x >> y; if (x + y <= n + 1) { cout << white ; } else { cout << black ; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string Decod, s; cin >> n >> s; int i = 0; while (n) { if (n % 2 != 0) { Decod += s[i]; } else { Decod = s[i] + Decod; } n = n - 1; i++; } cout << Decod << endl; }
#include <bits/stdc++.h> using namespace std; void rwFile() { freopen( INP.inp , r , stdin); freopen( OUT.out , w , stdout); } void solveB_MakeThemOdd() { int t; cin >> t; while (t--) { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; so...
#include <bits/stdc++.h> using namespace std; template <typename F, typename S> ostream& operator<<(ostream& os, const pair<F, S>& p) { return os << ( << p.first << , << p.second << ) ; } template <class T> ostream& operator<<(ostream& os, vector<T> const& x) { os << { ; for (auto& y : x...
#include <bits/stdc++.h> using namespace std; int c[100001], l[100001], r[100001], vis[100001], a[100001]; int f(int o, int ll, int rr) { if (!~o) return rr - ll + 1; int x = lower_bound(a + ll, a + rr + 1, c[o]) - a, y = x - 1; while (y < rr && a[y + 1] == c[o]) y++; return f(l[o], ll, x - 1) + f...
#include <bits/stdc++.h> using namespace std; pair<int, int> A[105]; vector<int> ans; int main() { int n, days; cin >> n >> days; for (int i = 0; i < n; i++) scanf( %d , &A[i].first), A[i].second = i; sort(A, A + n); for (int i = 0; i < n; i++) { if (days < A[i].first) break; ans...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 200000; int ans[MAX_N + 5]; int main() { int tc; cin >> tc; while (tc--) { int n, i, j; string s; cin >> n >> s; int num = n, last = 0; for (i = 0; i < n; i++) { if (i == n - 1 || s[i] == > ) { ...
#include <bits/stdc++.h> using namespace std; int ar[50][50]; int n; int check(int r, int c) { int v = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (ar[r][i] + ar[j][c] == ar[r][c]) { return 1; } } } return 0; } int main() { cin ...
#include <bits/stdc++.h> using namespace std; int A[110]; int main() { int n, k, x; cin >> n >> k >> x; for (int i = 0; i < n; i++) { cin >> A[i]; } int ans = 0; for (int i = 0; i < n - k; i++) { ans += A[i]; } ans += (k * x); cout << ans << endl; return 0; } ...
#include <bits/stdc++.h> using namespace std; const long long N = 5005; long long n, m, dp[N]; char s[N]; inline long long read() { long long ret = 0, f = 0; char c = getchar(); while (!isdigit(c)) { if (c == - ) f = 1; c = getchar(); } while (isdigit(c)) { ret = ret * 1...
#include <bits/stdc++.h> using namespace std; bool comp(long long x, long long y) { if (x >= y) return true; return false; } bool compare(const pair<long long, long long> &i, const pair<long long, long long> &j) { return i.first <= j.first; } bool compare1(const pair<long long, lo...
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; vector<int> sosedi[maxn]; int parent[maxn], shagi[maxn], start[maxn], finish[maxn], n; void dfs(int v, int predok) { parent[v] = predok; shagi[v] = shagi[predok] + 1; for (auto p : sosedi[v]) if (p != predok) dfs(p, v); ...
#include <bits/stdc++.h> using namespace std; bool home = 1; signed realMain(); signed main() { home = 0; if (home) { freopen( tony_stark , r , stdin); } else { ios::sync_with_stdio(0); cin.tie(0); } realMain(); } const int N = 100000 + 7; int n, k; long long sol[N...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << std::e...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { char c; bool nega = 0; while ((!isdigit(c = getchar())) && (c != - )) ; if (c == - ) { nega = 1; c = getchar(); } x = c - 48; while (isdigit(c = getchar())) x = x * 10 + c -...
#include <bits/stdc++.h> using namespace std; bool options(long a, long b) { return a > b; } int main() { long n, i, *arr, *arrSort, *index; map<long, long> res; cin >> n; arr = new long[n]; arrSort = new long[n]; index = new long[n]; for (i = 0; i < n; i++) { cin >> arr[i]; ...