func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { long n, m, val, i, j = 0, sum = 0, k = 0; vector<long> toys; vector<long> selected; cin >> n >> m; for (i = 0; i < n; i++) { cin >> val; toys.push_back(val); } sort(toys.begin(), toys.end()); for (i = 0; i < 10000...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; const long long inf = 0x3f3f3f3f3f3f3f3f; int n, m, q, u[N], v[N], w[N]; long long d[2][N]; bool vis[N]; vector<pair<long long, int> > g[N]; pair<long long, int> pre[N]; void dij(int s, long long d[]) { for (int i = (1); i < (n +...
#include <bits/stdc++.h> using namespace std; vector<int> graph[200002]; int visited[200002], sub[200002]; int subsize(int root) { visited[root] = 1; for (int child : graph[root]) { if (!visited[child]) sub[root] += subsize(child); } return sub[root]; } void destroy(int root, int par) ...
#include <bits/stdc++.h> using namespace std; long long n, crush[100005], ans = -1; bool exi[100005]; long long ms(int o, int x, int p) { if (p > 2 * n) return -1; if (crush[x] == x) return p ? -1 : 0; if ((x == o) && p) return 0; int t = ms(o, crush[x], p + 1); return (t < 0 ? t : t + 1); ...
#include <bits/stdc++.h> using namespace std; int Array[100005], Left[100005]; int Right[100005]; int main() { int N, i; scanf( %d , &N); for (i = 1; i <= N; ++i) { scanf( %d , Array + i); Left[i] = min(Left[i - 1] + 1, Array[i]); } for (i = N; i >= 1; --i) Right[i] = min(Right[i...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > di = {{2, 1}, {1, 2}, {-1, 2}, {-2, 1}, {-2, -1}, {-1, -2}, {1, -2}, {2, -1}}; int n, m; int X1, Y1, X2, Y2; queue<pair<int, int> > q1, q2; bool isValid(pair<int, int> cell) { return (1 <= cell.firs...
#include <bits/stdc++.h> using namespace std; int n, t; int dp[21][5][11][11][2]; int solve(int pos, int h, int mn, int mx, bool w) { if (mn > t - 1 || mx > t) return 0; if (pos == n) return mx == t && mn == t - 1; int &ref = dp[pos][h][mn][mx][w]; if (ref != -1) return ref; ref = 0; for...
#include <bits/stdc++.h> using namespace std; using uint = unsigned; using ll = long long; using ull = unsigned 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 vs = vector<string>; ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; using ii = pair<int, int>; using ll = long long; const int mod = 1e9 + 7; const int N = 1e6 + 5; const int M = 29; int ans[N]; int dp[3][N]; struct suffixAutomaton { struct state { int len...
#include <bits/stdc++.h> using namespace std; namespace IO { char buf[1 << 22], *p1 = buf, *p2 = buf; template <typename T> inline void read(T &x) { x = 0; register char ch = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++); ...
#include <bits/stdc++.h> using namespace std; int n, ini_pos; vector<int> v[2020]; int a[2020], MAX; map<int, int> mp; int dist(int a, int b) { if (a < b) swap(a, b); return min(a - b, n - a + b); } void input() { scanf( %d %d , &n, &ini_pos); for (int i = 1; i <= n; i++) scanf( %d , a +...
#include <bits/stdc++.h> using namespace std; long long a[201000]; long long vis[201000]; int main() { int t; cin >> t; while (t--) { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %lld , &a[i]), vis[i] = 0; int m; scanf( %d , &m); for (int i = 1; i <...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int k; cin >> k; if (k == 0) return cout << + n , 0; vector<string> ats = { ++ , +* }; while (ats.size() < (1 << k)) { auto cp = ats; for (auto& s : cp) for (auto& ch : s...
#include <bits/stdc++.h> using namespace std; int n, m; int t[107][107]; int mini; int a; int maxi; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { mini = 1000000009; for (int j = 1; j <= m; j++) { scanf( %d , &a); if (a < mini) { mini = a; ...
#include <bits/stdc++.h> using namespace std; using LL = long long; const int N = 100005; struct Node { char c; int pos; Node() {} Node(char _c, int _pos) : c(_c), pos(_pos) {} bool operator<(const Node& rhs) const { if (c != rhs.c) return c < rhs.c; return pos < rhs.pos; } ...
#include <bits/stdc++.h> using namespace std; long long x, maxi = 0, sum = 0; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(NULL); int x; cin >> x; int one = 0, zero = 0; string s; cin >> s; for (int i = 0; i < x; i++) { if (s[i] - 0 == 1) one++...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long a; cin >> a; long long m = 0; vector<long long> c; long long b[a]; for (int i = 0; i < a; i++) { cin >> b[i]; } for (int y = 0; y < ...
#include <bits/stdc++.h> using namespace std; int n, k; struct node { int mx[11], mn[11], num; friend bool operator<(const node &A, const node &B) { int ok = 1; for (int i = 1; i <= k; i++) ok &= A.mx[i] < B.mn[i]; return ok; } friend node operator+(const node &A, const node &B) ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n; string s; int finish_x, finish_y; cin >> n >> s >> finish_x >> finish_y; if (n < abs(finish_x) + abs(finish_y) || n % 2 != (abs(finish_x) + abs(finish_y)) % 2) { cout << -1; ret...
#include <bits/stdc++.h> using namespace std; long double eps = (long double)1 / 1e9; long long inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353; long long sqr(long long a) { return a * a; } long long qb(long long a) { return a * a * a; } long long gcd(long long a, long long b) { return !a ? b : gcd(b % a,...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long infLL = 0x3f3f3f3f3f3f3f3fLL; const int hash_mod = 1000037; const double eps = 1e-10; const double pi = acos(-1); const int maxn = 5000 + 5; int n, m; char s[maxn]; int f[maxn][maxn], g[maxn]; int main() { ...
#include <bits/stdc++.h> using namespace std; set<long long> s; void dfs(int a, int b, long long sum, int d, int& n) { if (d >= 0) { if (sum <= n && sum > 0) { s.insert(sum); } } if (d == 0) { return; } dfs(a, b, sum * 10 + a, d - 1, n); dfs(a, b, sum * 10 + b, d ...
#include <bits/stdc++.h> using namespace std; const int N = 53e4, mod = 998244353; int n, nn, L, A, B, ans, fac[N], inv[N], a[N], b[N], c[N], R[N]; int C(int a, int b) { return 1ll * fac[a] * inv[b] % mod * inv[a - b] % mod; } int qpow(int a, int b) { int ret = 1; while (b) { if (b & 1) ret = 1l...
#include <bits/stdc++.h> using namespace std; int n, c[25], coin[25]; int ans = 0; bool can; int p_b; bool good() { int cnt = 0; for (int i = 0; i < 25; i++) cnt += coin[i]; return cnt == 1; } void rec(int s, int r, int p) { if (r == 1) { if (c[p] > 1) coin[c[p]]++; p++; ...
#include <bits/stdc++.h> using namespace std; int main() { int a[1002], l, n; scanf( %d %d , &n, &l); for (int i = 0; i < n; i++) scanf( %d , a + i); sort(a, a + n); double d = max(a[0] - 0, l - a[n - 1]); for (int i = n - 1; i > 0; i--) d = max(d, double(a[i] - a[i - 1]) / 2); printf( %...
#include <bits/stdc++.h> using namespace std; int main() { double m, n; double i; cin >> m >> n; double ans = 0; for (i = 1; i <= m; i++) { ans = ans + i * (pow((i / m), n) - pow(((i - 1) / m), n)); } printf( %.9lf , ans); return 0; }
#include <bits/stdc++.h> using namespace std; int pre[5005][5005]; int main() { int n, k; bool flag = true; scanf( %d%d , &n, &k); map<int, int> m; for (int i = 1; i <= n; i++) { int yy; scanf( %d , &yy); m[yy]++; pre[yy][m[yy]] = i; if (m[yy] > k) flag = false; ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long double PI = 4 * atan((long double)1); const long long int INF = 1e18; const long long int NINF = -1e18; long long int get_hash(string s) { long long int N = 1000001; long long int base[N], A = 11, MD = 1110111110111; ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { int n; cin >> n; int arr[n + 1]; for (int i = 1; i <= n; i++) cin >> arr[i]; int long long ans = 0; for (int mx = 0; mx < 31; mx++) { int long long cur = 0; int long long best = 0; for (int i ...
#include <bits/stdc++.h> using namespace std; int main() { int aux; string a; cin >> a; cout << (a.size() * 25) + 26 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, k, x, y, sum, cnt, ans; int main() { printf( red n ); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T, class U> T &ctmax(T &x, const U &y) { return x = max<T>(x, y); } template <class T, class U> T &ctmin(T &x, const U &y) { return x = min<T>(x, y); } int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ...
#include <bits/stdc++.h> using namespace std; int main() { int kl[5] = {0}, n, ans = 0, x; cin >> n; for (int i = 1; i <= n; i++) { cin >> x; kl[x]++; } x = min(kl[1], kl[2]); ans += x; kl[1] -= x; kl[2] -= x; kl[3] += x; if (kl[1] != 0) { ans += kl[1] / 3 *...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, c = 0, a[101]; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n - 1; i++) { if (a[i] == 0) { if (a[i + 1] == 1 && a[i - 1] == 1) { c++; a[i + 1] = 0, a[i - 1] = 0; } }...
#include <bits/stdc++.h> using namespace std; const double pi = 3.141592653589793238; int main() { int t, a, b; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (long long int i = 0; i < n; i++) cin >> a[i]; int ct = 0, ct1 = 0, ct2 = 0; sort(a, a + n); ...
#include <bits/stdc++.h> using namespace std; vector<int> a[1111]; queue<int> p; int ji[1111], f = 1, b[1111], c[1111]; void dfs(int p) { ji[p]++; for (int i = 0; i < a[p].size(); i++) { if (ji[a[p][i]] >= 3) { f = 0; return; } dfs(a[p][i]); } } int main() { ...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > adj; bool vis[100100]; int mx = 0; int far = -1; void dfs(int cur, int len) { if (vis[cur]++) return; if (len > mx) { mx = len; far = cur; } for (int x : adj[cur]) dfs(x, len + 1); } int main() { int n, m;...
#include <bits/stdc++.h> using namespace std; using ll = long long; ll mod = 1e9 + 7; ll bpow(ll a, ll b, ll m) { a %= m; ll res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } bool cmp(vector<ll> v1, vector<ll> v2) { return v1...
#include <bits/stdc++.h> using namespace std; int main(void) { int n; vector<string> v; cin >> n; for (int i = 0; i < int(n); i++) { string s; cin >> s; v.push_back(s); } for (int i = 0; i < int(10); i++) { cout << ?? << i << >> << i << ?? << endl; } cou...
#include <bits/stdc++.h> using namespace std; vector<int> G[500005]; void solve() { int n, m, i, a, b; cin >> n >> m; vector<pair<int, int>> topics(n + 1); vector<int> assigned(n + 1, 1); vector<bool> done(n + 1, 0); for (i = 0; i < m; ++i) { cin >> a >> b; G[a].push_back(b); ...
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, e, i, j, n; int main() { map<string, long long> m, m1; cin >> a >> b; string s; for (i = 1; i <= a; i++) { cin >> s; m[s]++; } d = b; for (i = 1; i <= b; i++) { cin >> s; if (m[s] > 0) { ...
#include <bits/stdc++.h> using namespace std; int main() { int y1, m1, d1, y2, m2, d2; scanf( %d:%d:%d n%d:%d:%d , &y1, &m1, &d1, &y2, &m2, &d2); if (m1 < 3) y1--, m1 += 12; long long ans1 = 365 * y1 + y1 / 4 - y1 / 100 + y1 / 400 + (153 * m1 - 457) / 5 + d1 - 306; if (m2 < 3) y2--, m2 +...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const double PI = 4 * atan(1); const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = 1e9 + 7; const int MAX_N = 2e6 + 10; int n; int a[MAX_N], b[MAX_N], p[MAX_N]; void solve() ...
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const long long mod = 95542721; const double eps = 1e-9; const double pi = 3.1415926535897932384626; const int DX[] = {1, 0, -1, 0}, DY[] = {0, 1, 0, -1}; long long powmod(long long a, long long b) { long long res = 1; a %= mod...
#include <bits/stdc++.h> using namespace std; const int MOD = 100 * 1000 * 1000; int n1, n2, k1, k2; long long dp[2][101][101]; int solve(int a, int b, int c) { if (b == 0 || c == 0) { if (a == 0) { dp[a][b][c] = (b <= k1); return dp[a][b][c]; } dp[a][b][c] = (c <= k2); ...
#include <bits/stdc++.h> using namespace std; typedef int (*uniopi)(int); typedef long long (*uniopl)(long long); typedef int (*binopi)(int, int); typedef long long (*binopl)(long long, long long); typedef int (*tupopi)(int, int, int); typedef long long (*tupopl)(long long, long long, long long); const ...
#include <bits/stdc++.h> using namespace std; struct BIT { vector<pair<int, int> > f; void init() { f.push_back(make_pair(-1e9, 0)); f.push_back(make_pair(0, 0)); f.push_back(make_pair(1e9, 0)); sort(f.begin(), f.end()); } void update(int i, int val, bool fake = 0) { if...
#include <bits/stdc++.h> using namespace std; int t, n, k, d, a[200010]; int num[1000010]; bool check(int mid) { int l = 1, r = 1, nl = 1, nr = 1, cnt = 1; num[a[1]]++; while (nr < n) { nr++; num[a[nr]]++; if (num[a[nr]] == 1) { cnt++; } while (cnt > mid) { ...
#include <bits/stdc++.h> using namespace std; int a, b, c, d, e, z[509], x[509], pi, g, s; vector<int> v[509]; bool m, rr; pair<int, int> p[509]; void dfs(int w) { if (m == 1) return; z[w] = 1; for (vector<int>::iterator it = v[w].begin(); it != v[w].end(); it++) { if (x[(*it)] == c) { ...
#include <bits/stdc++.h> using namespace std; int arr[101]; vector<int> vec; int main(void) { int n; long long k; long long sum; scanf( %d %lld , &n, &k); sum = k; vec.push_back(1); for (int i = 0; i < n; i++) { scanf( %d , &arr[i]); sum += arr[i]; vec.push_back(arr...
#include <bits/stdc++.h> using namespace std; int m[200]; int n; int S, E; bool is_ok(int lim) { int s = 0, e = 0; for (int i = 0; i < lim; ++i) s += m[i]; for (int j = lim; j <= n; ++j) e += m[j]; return s <= E && e <= E && s >= S && e >= S; } int main() { cin >> n; for (int i = 1...
#include <bits/stdc++.h> using namespace std; const int maxn = 105; map<string, int> H1[maxn], H2[maxn]; vector<char> ans; char getA(string a, string b) { int c[30]; for (int i = 0; i < 26; i++) c[i] = 0; for (int i = 0; i < a.size(); i++) c[a[i] - a ]++; for (int i = 0; i < b.size(); i++) c[...
#include <bits/stdc++.h> using namespace std; int C[50][50]; int main() { C[0][0] = 1; for (int i = 1; i <= 30; i++) { C[i][0] = C[i][i] = 1; for (int j = 1; j <= 30; j++) { C[i][j] = C[i - 1][j] + C[i - 1][j - 1]; } } string p = aaaaaaaaab ; int pSize = (int)p.size(...
#include <bits/stdc++.h> using namespace std; long long b[1510100], n, x; long long Mod, C; long long power(long long a, long long n, long long mod) { if (n == 0) return 1; long long y; y = power(a, n / 2, mod); if (n & 1) { return (((y * y) % mod) * a) % mod; } else { return (y ...
#include <bits/stdc++.h> using namespace std; const int Max = 3e5 + 10; const int E = Max * 2; int son[Max], maxson[Max], fa[Max], zx[Max]; int head[Max], nex[E], pnt[E], edge; int vis[Max]; void Init() { edge = 0; memset(son, 0, sizeof(son)); memset(maxson, 0, sizeof(maxson)); memset(fa, ...
#include <bits/stdc++.h> using namespace std; long long n, m; int main() { cin >> n >> m; if (n > m) swap(n, m); if (n == 1) { cout << 6 * (m / 6) + 2 * max(m % 6 - 3, (long long)0); return 0; } if (n == 2) { if (m == 2) { cout << 0; return 0; } if...
#include <bits/stdc++.h> clock_t t = clock(); namespace my_std { using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> inline T rnd(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } template <typename T> inline bool chkmax(T& x, ...
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template <class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } int main() { int n; cin >> n; static long long dp[100][100][...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cout.tie(0); iostream::sync_with_stdio(false); long long n, m; cin >> n >> m; set<int> taken_lines, taken_cols; long long base = n * n; for (int i = 0; i < m; ++i) { int x, y; cin >> x >> y; bool...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int l = 0; int r = n - 1; while (l < n - 1 && a[l] < a[l + 1]) l++; while (r > 0 && a[r] < a[r - 1]) r--; for (int i = l + 1; i <= r; i++) { if (a[...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 10; int a[maxn], b[maxn]; int dp[2][maxn][55][55]; inline int ip(int k) { return k > 0 ? k : 0; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, p, k; cin >> n >> p >> k; int r, s; cin >> r; for (i...
#include <bits/stdc++.h> using namespace std; int Left[1000010]; int mini[1000010]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; string S; cin >> S; for (int i = 0; i < S.length(); i++) { if (S[i] == ( ) Left[i + 1] = Left[i] + 1; el...
#include <bits/stdc++.h> using namespace std; const int maxn = 1111; int a[maxn], b[maxn]; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; int maxim = 0, num = -1; for (int i = 1; i <= n; i++) { b[i] = a[i]; for (int j = 1; j <= n; j++) b[j] = a[i]...
#include <bits/stdc++.h> using namespace std; int n, m, S[2005]; bool mark[2005][2005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); char c; cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { cin >> c; mark[i][j] = c - 0 ; if (...
#include <bits/stdc++.h> using namespace std; const int N = 400500; long long A[N]; long long B[N]; inline long long mymod2(long long x) { if (x % 2 == 0) return 0; else return 1; } inline long long mydiv2(long long x) { if (x >= 0) return x / 2; else { if (x % 2 ==...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long int n; cin >> n; vector<long long int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); if (n == 1) { ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; char tt = a ; int k = s.size(), c = 0; for (int i = 0; i < k; i++) { int x = int(tt); int y = int(s[i]); int a = abs(x - y); int b = 26 - a; b = min(b, a); c += b; tt = s[i];...
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << , ; err(++it, args...); } namespace fastIO { bool IOerror = 0; ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } int N, K; char cs[100002]; int main() { scanf( %d%d , &N, &K); for (int i = (0); i < (int)(N...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2025; const int MOD = 998244353; int n, k; namespace Task1 { int ans; int f[MAXN][MAXN]; int sum[MAXN][MAXN]; void solve() { f[0][n] = 1; for (int i = n; i >= 1; i--) sum[0][i] = 1; for (int i = 1; i <= n; i++) for (int j...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int inf = 0x3f3f3f3f; int n; vector<int> vec[N]; int dis(int s, int t) { if (t >= s) return t - s; return t - s + n; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int m; cin >> n >> m; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; vector<int> silver, gold; int g = 0, mxg = -1; ; for (int i = 0; i < s.size(); i++) { if (s[i] == S ) { gold.push_back(g); if (g > mxg) mxg = g; g = 0; ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e5 + 10; const long long MAXL = 20; long long n, m; long long v[MAXN], s[MAXN]; long long rmq[MAXL][MAXN]; long long resp[MAXN]; long long best[MAXN]; void buildRMQ() { for (long long k = 0; k < n; k++) rmq[0][k] = s[k]; for...
#include <bits/stdc++.h> using namespace std; const long long N = 201; const long long K = 201; const long long X = 201; long long dp[N][X]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n, k, x; cin >> n >> k >> x; vector<long long> picBeaut...
#include <bits/stdc++.h> using namespace std; struct Q { int l, r, id; bool operator<(const Q a) const { if (l == a.l) return r < a.r; return l < a.l; } } q[400003]; int a[400003], b[400003]; int pos[400003]; int m, sum[400003]; int lb(int k) { return k & -k; } void add(int k, in...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; string w; for (int i = 0; i <= 2 * n - 2; i = i + 2) { w = w + s[i]; } cout << w << endl; } }
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > p; int main() { int tc; cin >> tc; while (tc--) { p.clear(); int n, a, b; cin >> n; bool value = true; for (int i = 0; i < n; ++i) { cin >> a >> b; if (a < b) value = false; if (...
#include <bits/stdc++.h> using namespace std; const long long N = 2e3 + 5; const long long MOD = 1e9 + 7; long long nCr[N][N]; void precompute() { nCr[0][0] = 1; for (long long i = 1; i < N; i++) { nCr[i][0] = 1; for (long long j = 1; j <= i; j++) { nCr[i][j] = nCr[i - 1][j - 1] + ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a[110][110], i, j, maxi, f, maxid[110], c = 0, poi; scanf( %d%d , &n, &m); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) scanf( %d , &a[i][j]); } for (i = 0; i < m; i++) { maxi = a[i][0]; maxid[i] = 0; ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; template <class T> T sqr(const T &x) { return x * x; } template <class T> T lowbit(const T &x) { return (x ^ (x - 1)) & x; } inline long long mlog2(long long n) { long long c = 0; c ...
#include <bits/stdc++.h> using namespace std; string st; long ans, tans, n, ttl, qpos; int main() { ios_base::sync_with_stdio(0); cin >> n; cin >> st; for (int i = 0; i < st.size(); i++) if (st[i] == H ) ++ttl; ans = 1000000; for (int stp = 0; stp < n; stp++) { tans = 0; ...
#include <bits/stdc++.h> const int N = 60; const int M = 11; const int MOD = 1e9 + 7; int binom[N + 1][N + 1], n, a[N], parent[N], inDegree[N], v0[N], v1[N], msk1[N], dp[N + 1][1 << M]; int findRoot(int u) { if (parent[u] != u) { parent[u] = findRoot(parent[u]); } return parent[u]; }...
#include <bits/stdc++.h> using namespace std; const long long maxn = 2010; const long long mod = 998244353; long long pw(long long a, long long b) { if (b == 0) return 1; long long k = pw(a, b / 2); k = (k * k) % mod; if (b & 1) k = (k * a) % mod; return k; } long long n, m; long long ...
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e5 + 10; const int MaxL = 18; const int INF = 1e9; const int MOD = 1e9 + 7; int up[MaxN][MaxL], ds[MaxN]; vector<int> graph[MaxN]; int n, m, sz[MaxN]; long long sum[MaxN], ups[MaxN]; void dfsLca(int v, int p) { up[v][0] = p; for...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> len(n); vector<string> s(n); for (int i = 0; i < n; i++) { cin >> s[i]; len[i] = s[i].length(); } const int all = n - 1 + accumulate(len.begin(), len.end(), 0); vector<vector<bool>> eq...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; long long max(long long a, long long b) { if (a > b) { return a; } else { return b; } } long long min(long long a, long long b) { if (a < b) { return a; } else { return b; } } long l...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10, N = 2000; long long m, n, shroo, I[maxn], tmm, id[maxn], J[maxn], W[maxn], Su[maxn], dp1[maxn], dp2[maxn]; vector<pair<long long, long long> > hel1; vector<int> tmp, in[maxn], out[maxn]; bool amx(int i, int j) { return id[I[i]] >...
#include <bits/stdc++.h> using namespace std; const int maxn = 100500; struct matrix { long double a[3][3]; void clear() { memset(a, 0, sizeof(a)); } matrix operator*(const matrix &y) { matrix ans; ans.clear(); for (int i = (0), iend = (2); i <= iend; i++) for (int j = (0), j...
#include <bits/stdc++.h> using namespace std; const int mn = 101000; vector<int> e[mn]; int c[mn], s[mn], sc[mn], sv[mn]; int R[mn], vis[mn]; int n, m, i, j, k, nc, tt; long long ans; bool cmpc(int i, int j) { return c[i] > c[j]; } bool cmps(int i, int j) { return s[i] < s[j]; } void add(int i, int ...
#include <bits/stdc++.h> using namespace std; const long long MX = 2e5 + 3; long long n, k, arr[MX], sum; multiset<long long> st; string s; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (long long i = 0; i < n; i++) cin >> arr[i]; cin >> s; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, root; vector<int> adj[N]; int dp[N][2], deg[N]; bool mark[N]; void dfs(int u, int pre) { for (int v : adj[u]) { if (v == pre) continue; dfs(v, u); } for (int p = 0, _n = (2); p < _n; p++) { int d = (d...
#include <bits/stdc++.h> using namespace std; int main() { double weight = 0; long n, m; cin >> n >> m; long long a[n]; long long b[n]; bool flag = 0; for (long i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) { flag = 1; } } for (long i = 0; i < n; i++)...
#include <bits/stdc++.h> using namespace std; const int maxn = 10050; const int inf = 0x7fffffff; string str; int buf[maxn]; vector<int> sans[10]; int save[300] = {}; string ansstr; string bk; int bK; int main(void) { int n, K; cin >> n >> K >> str; int ans = inf; for (int k = ( 0 ...
#include <bits/stdc++.h> int n, m, a, b, mna = 101, mnb = 101, mxa, mxb; void No() { printf( -1 ); } void Yes(int n) { printf( %d , n); } int main() { scanf( %d%d , &n, &m); for (int i = 0; i < n; i++, scanf( %d , &a), mna = std::min(mna, a), mxa = std::max(mxa, a)) ; for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long int ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return...
#include <bits/stdc++.h> using namespace std; set<pair<int, pair<int, int> > > l, u; set<pair<int, pair<int, int> > >::iterator itu, itl; const int INF = 1000 * 1000 * 1000LL + 10; int main() { int n, q, a, b, ll, lm, lt, uu, um, ut; char c; long long ans; cin >> n >> q; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; const int MAX = 4040; map<int, int> cnt1; map<int, int> cnt2; pair<int, int> a[200020]; int main() { int ans = 0; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; cnt1[a[i].first + a[i].second]++; ...
#include <bits/stdc++.h> using namespace std; int a[2000]; int n; inline bool check() { int c = 0; for (int i = 0; i < n; ++i) if (a[i] + 1 == a[i + 1]) ++c; if (c == n) return true; else return false; } inline void push() { for (int i = 0; i <= n; ++i) { if (i % ...
#include <bits/stdc++.h> using namespace std; const int maxn = 55; int n, l; int a[maxn], b[maxn]; bool check(int d, int x, int y) { int i = x + 1, j = y + 1; i %= n; j %= n; while (i != x && j != y) { if ((a[i] - b[j] + l) % l == d) { i++; i %= n; j++; j ...
#include <bits/stdc++.h> using namespace std; const int maxN = 100000 + 10; int main() { long long n, a[maxN], c = 0, min = 1000000001, index; cin >> n; for (long long i = 0; i < n; i++) { cin >> a[i]; if (a[i] < min) { min = a[i]; c = 0; index = i; } else if ...