solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; long long modul(long long x) { return x * (x % 2 + (x + 1) % 2); } int main() { string s; cin >> s; long long z; for (int i = 0; i < s.size(); i++) { if (s[i] == '^') { z = i; break; } } long long l = 0, r = 0; for (int i = 0; i < z; i++) {...
1
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 6; int pos[MAX], id[MAX]; int mod(int x, int y) { int res = x % y; if (res < 0) res += y; return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q; pos[1] = 0, pos[2] = 1; for (int i =...
10
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e6 + 10; const long long INF = 1e18; const long long MOD = 1e9 + 7; long long poww(long long a, long long b, long long md) { return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2,...
11
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") #define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define int long lon...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; template <class _T> inline string tostr(const _T& a) { ostringstream os(""); os << a; return os.str(); } int a[200], b[200], n, V; long double c[200]; int main() { cout.flags(ios::fixed); cout.precision(8); cin >> n >> ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int x; cin >> x; while (x--) { string s, t, p; cin >> s >> t >> p; int i, j, ss = s.size(), st = t.size(), sp = p.size(); map<char, int> needs; for (i = 0, j = 0; i < ss && j < st; ++i, ++j)...
5
#include <bits/stdc++.h> using namespace std; const int nmax = 5010; char A[nmax][nmax]; int D[nmax][nmax]; vector<int> V[nmax]; vector<int> T[nmax]; int N, M, out; int main() { scanf("%d%d", &N, &M); for (int i = 1; i <= N; ++i) scanf("%s", (A[i] + 1)); int mx = 0; for (int i = 1; i <= N; ++i) for (int j =...
8
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; template <typename T> using v = vector<T>; const long long inf = 4611686018427387903; void read() {} template <typename Arg, typename... Args> void read(Arg& arg, Args&... args) { cin >> (arg); read(args...); } void print() {} template <typ...
9
#include <bits/stdc++.h> using namespace std; long long fpow(long long a, long long b) { long long ans = 1, t = a; while (b) { if (b & 1) ans = ans * t % 998244353; t = t * t % 998244353; b >>= 1; } return ans; } long long inv(long long a) { return fpow(a, 998244353 - 2); } inline void add(int& a, i...
18
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") const int MAXN = 2e5 + 100; const int SIZE = (1 << 19) + 50; struct Segment_tree { struct Node { int stdl, stdr, val; Node() : stdl(0), stdr(0), val(0) {} } tree[SIZE]; inline void buildtree(int root, int l, int r) { tree[root...
22
#include <bits/stdc++.h> using namespace std; int n; const int MAXN = 1e5 + 10; const long long INF = 100000000 + 10LL << 1; struct Point { long long x, y; bool operator<(const Point& cmp) const { if (x == cmp.x) return y < cmp.y; return x < cmp.x; } } p[MAXN]; long long pre_max[MAXN], pre_min[MAXN], suf_...
21
#include <bits/stdc++.h> using namespace std; int n, m; long long a[1011], f[1011][1011], x; map<long long, int> k; int main() { scanf("%d%d", &m, &n); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) scanf("%1lld", &x), a[j] |= (x << i); for (int i = 0; i < m; i++) k[a[i]]++; f[0][0] = 1; for (int...
17
#include <bits/stdc++.h> using namespace std; struct st1 { int id, day; }; st1 a[110]; int n, m, vt; bool dk(st1 t1, st1 t2) { if (t1.day < t2.day) return 1; return 0; } void solve() { int i; for (i = 0; i < n; i++) { a[i].id = i + 1; scanf("%d", &a[i].day); } sort(a, a + n, dk); vt = -1; whil...
2
#include <bits/stdc++.h> int n; int IT[262144][60]; void UDT(int a) { while (a != 1) { a >>= 1; for (int x = 0; x < 60; x++) { IT[a][x] = IT[a * 2][x] + IT[a * 2 + 1][(x + IT[a * 2][x]) % 60]; } } } void Do(int a, int b) { a += 131072; int i; for (i = 0; i < 60; i++) { if (i % b == 0) ...
16
#include <bits/stdc++.h> using namespace std; class segtree { public: struct node { long long sum = 0; int pos = -1; long long val = 0; void apply(int l, int r, long long v) { assert(l == r); val = v; sum = v; pos = r; } }; node unite(const node &a, const node &b) cons...
20
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; long long int o = 0, c = 0, arr[n + 1]; char ori[n + 1], temp; arr[0] = 0; for (__typeof(n + 1) i = (1) - ((1) > (n + 1)); i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) { cin >> ori[i]; arr...
17
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; if (n / k % 2 == 0) cout << "NO" << endl; else cout << "YES" << endl; }
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") using namespace std; void itval(istream_iterator<string> it) {} template <typename T, typename... Args> void itval(istream_iterator<string> it, T a, Args... args)...
11
#include <bits/stdc++.h> int main() { long long k, s = 0, i; scanf("%I64d", &k); for (i = 1; i <= 1e6; i++) { if ((k + i) % 3 == 0 && (3 * i * i + i) / 2 <= k) s++; } printf("%I64d", s); }
9
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string r, w; r = s.substr(0, 2); w = s.substr(3, 2); float a, b; istringstream(r) >> a; istringstream(w) >> b; float ans = (a / 12 * 360) + float(b / 2); float anss = b / 60 * 360; if (ans >= 360) { ans -= 360; } ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n1, n2, k1, k2; cin >> n1 >> n2 >> k1 >> k2; while (n1 > 0 && n2 > 0) { n1--; n2--; } if (n2 == 0 && n1 != 0) cout << "First" << endl; else cout << "Second" << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int s = 0, maxa = 0; for (int i = 0; i < n; i++) { int a; cin >> a; s += a; maxa = max(maxa, a); } cout << max(maxa, 2 * s / n + 1); }
0
#include <bits/stdc++.h> using namespace std; long long n, k; long double l, v1, v2; long double t; long double get(long double time_ft) { long long cur = k; t = time_ft; long double dist = time_ft * v1; long double aut = time_ft * v2; long double nxt = aut; while (1) { if (cur >= n) { t += (l - a...
11
#include <bits/stdc++.h> using namespace std; int seg[8 * 100010]; void add(int v, int f, int e, int x, int val) { if (e - f == 1) { seg[v] = val; return; } int mid = (f + e) / 2; if (x < mid) add(2 * v, f, mid, x, val); else add(2 * v + 1, mid, e, x, val); seg[v] = seg[2 * v] + seg[2 * v + ...
14
#include <bits/stdc++.h> const int mod = 1000000007; std::vector<int> g[1111111]; int c[1111111]; int d[1111111]; void dfs(int x) { int tt; int cc, dd; int t1, t2; int i; c[x] = 1; cc = 0; dd = 1; tt = 1; for (i = 0; i < g[x].size(); i++) { dfs(g[x][i]); t1 = c[x]; t2 = d[x]; (c[x] += ...
19
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; struct mod_int { int val; mod_int(long long v = 0) { if (v < 0) v = v % MOD + MOD; if (v >= MOD) v %= MOD; val = v; } static int mod_inv(int a, int m = MOD) { int g = m, r = a, x = 0, y = 1; while (r != 0) { int q...
25
#include <bits/stdc++.h> using namespace std; const int N = 100010; const int INF = 1e9 + 69; int n, m; set <int> out; map <int, int> seg; map <int, set <int>> lose; vector <pair <int, int>> pts; inline bool losing (int x, int y) { if (lose.find(x) != lose.end()) return lose[x].count(y); auto it = prev(seg.uppe...
23
#include <bits/stdc++.h> using namespace std; string s, t; double calc(string s) { int l = s.length(), p = 0, q = 0, cnt = 0, cur = 0; for (int i = 0; i < l; i++) { char ch = (q & 1) ? 'R' : 'L'; if (s[i] == 'X') q++; else if (s[i] == ch) { p++; q++; cur = 0; } else { p...
20
#include <bits/stdc++.h> using namespace std; int main() { int w, h; cin >> w >> h; char img[h][w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> img[i][j]; for (int i = 0; i < 2 * w; i++) { for (int j = 0; j < 2 * h; j++) cout << img[j / 2][i / 2]; cout << endl; } return 0; }...
4
#include <bits/stdc++.h> using namespace std; int x1, x2, a, b, chk; int main() { cin >> x1 >> x2 >> a >> b; if (a <= x2 - x1 && x2 - x1 <= b) { cout << "FIRST" << endl; cout << x2 << endl; return 0; } if (a + b < 0) { swap(x1, x2); swap(a, b); a = -a; b = -b; chk = 1; } int ...
16
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); std::ios::sync_with_stdio(false); int n; cin >> n; int used[n]; for (int i = 0; i < n; i++) { used[i] = 0; } string s; cin >> s; int i = 0; while (i < s.length()) { if (s[i...
8
#include <bits/stdc++.h> using namespace std; long long n, m, k, p; long long mod; long long a[1201000], b[1201000], c[1201000]; void fwt(long long* a) { for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) if (!(j >> i & 1)) { long long x = a[j], y = a[j | 1 << i]; a[j] = (x + y) % mod; ...
22
#include <bits/stdc++.h> using namespace std; int D, M, Y, d, m, y, f[3]; int day[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; bool check() { if (m < M) return true; else if (m == M) return d <= D; return false; } int main() { scanf("%d.%d.%d", &D, &M, &Y); scanf("%d.%d.%d", &f[0], &f[1], ...
9
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; const int N = 2e5; int n, a[N], c00, c01, c10, c11; long long P[N], inv[N]; char A[N], B[N]; long long exgcd(long long a, long long b, long long &x, long long &y) { long long d = a; if (b != 0) { d = exgcd(b, a % b, y, x); y -= (a / ...
16
#include <bits/stdc++.h> using namespace std; long long n, t, k; int main() { cin >> t; while (t--) { cin >> n; cin >> k; vector<long long> a(n); for (long long i = 0; i < n; i++) cin >> a[i]; sort((a).begin(), (a).end(), greater<long long>()); int sol = 0; int cmin; long long len = ...
6
#include <bits/stdc++.h> using namespace std; const int N = 35000; unsigned int n, m, s, A, B, C, D, ans, cnt; unsigned int a[N], b[N], c[N], d[N], w[N], g[N], p[N]; inline unsigned int s1(unsigned int x) { return 1LL * x * (x + 1) / 2; } inline unsigned int s2(unsigned int x) { unsigned int a = x, b = x + 1, c = x +...
17
// Licykoc yyds!!! &.*^*.& %:include"bits/stdc++.h" using namespace std; #define N (int)(4e5+10) vector<int>g1[N],g2[N],g3[N]; stack<int>s; queue<int>q; int T,n,m; int dp[N],len,color[N],ru[N],siz[N],f[N]; bool vis[N],b[N],c[N]; inline void dfs1(int u) { vis[u]=true; for(int i=0;i<g1[u].size();i++) { int v=g1[u][i...
13
#include <bits/stdc++.h> using namespace std; int n, m, x, y, vx, vy; int refx, refy; long long exgcd(long long a, long long b, long long &x, long long &y) { if (!b) { x = 1, y = 0; return a; } long long res = exgcd(b, a % b, y, x); y -= (a / b) * x; return res; } int main() { scanf("%d%d%d%d%d%d", ...
18
#include <bits/stdc++.h> using namespace std; int A, B, n; long long getTime(long long l, long long r, long long m) { long long val1 = (r - l + 1) * (A + B * (l - 1)); val1 += B * ((r - l + 1) * (r - l)) / 2; long long d = m; long long ans = (val1 + d - 1) / d; if (A + (r - 1) * B > ans) ans = A + (r - 1) * B...
11
#include <bits/stdc++.h> using namespace std; long long n, i, cnt(0), res(0), l, t(0); const long long mod = 1e9 + 7; string s; void Init() { cin >> s; l = s.length(); for (i = 0; i < l; i++) { if (s[i] == 'a') t = ((t + 1) * 2 - 1) % mod; else res = (res + t) % mod; } cout << res; } int m...
6
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; vector<vector<long long>> edges; long long par[N]; long long find(long long x) { return x == par[x] ? x : par[x] = find(par[x]); } void unite(long long x, long long y) { x = find(x); y = find(y); if (x != y) par[x] = y; } int main() { lo...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0, c2 = 0, c3 = 0; cin >> n; for (int i = 1; i <= n; i++) { c += i; c3 += c; if (c3 > n) { break; } c2++; } cout << c2; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt1 = 0, cnt2 = 0; cin >> n; int arr[1010]; for (int i = 0; i < n; ++i) cin >> arr[i]; int round = 1, i = 0, j = n - 1; while (round <= n) { if (round % 2 == 1) cnt1 += max(arr[i], arr[j]); else cnt2 += max(arr[i], arr[j]...
0
#include <bits/stdc++.h> using namespace std; long long arr[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, i; cin >> n; for (i = 0; i < n; i++) cin >> arr[i]; if (n == 1) { cout << "1 1\n" << arr[0] * (-1) << "\n"; cout << "1 1\n" << arr[0] << "\n"; cout << "1 1...
8
#include <bits/stdc++.h> using namespace std; long long int used[100005]; map<pair<int, int>, int> m; set<pair<int, pair<int, int> > > fre; int freek(int x, int y) { int ans = 0; if (m.count(make_pair(x, y)) == 0) return 1; else { ans = ans + m.count(make_pair(x, y - 1)); ans = ans + m.count(make_pair...
13
#include <bits/stdc++.h> using namespace std; struct boi { int cnt, poz, cand; } f[105]; bool mycmp(boi a, boi b) { if (a.cnt == b.cnt) return a.cand < b.cand; return a.cnt > b.cnt; } int viz[105]; int main() { int n, k, m, a, x; cin >> n >> k >> m >> a; for (int i = 1; i <= a; i++) { cin >> x; f[x]...
13
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using pill = pair<int, ll>; using vvi = vector<vi>; ll gcd(ll a, ll b) { ll t; while ((t = a % b) != 0) { a = ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int n, mod; cin >> n >> mod; vector<long long int> v(n + 1); v[0] = 1; for (int i = 1; i <= n; i++) { v[i] = ((v[i - 1] % mod) * (i % mod)) % mod; } long long int ans = 0; for (int len = 1; len <= n; len++) { ans += (((v[len] *...
8
#include <bits/stdc++.h> using namespace std; string s; int main() { int i, j, k; cin >> s; int n = (int)(s.size()); if (n & 1) { cout << -1 << endl; return 0; } int x = 0, y = 0; for (i = 0; s[i]; i++) { if (s[i] == 'U') y++; if (s[i] == 'D') y--; if (s[i] == 'R') x++; if (s[i] ==...
3
#include <bits/stdc++.h> using namespace std; int n; double mat[20][20]; double dp[1 << 20]; bool mark[1 << 20]; double mem(int mask) { if (mask == (1 << n) - 1) return 1.; if (mark[mask]) return dp[mask]; int k = 1; for (int i = 0; i < n; i++) if (mask & (1 << i)) k++; mark[mask] = 1; dp[mask] = 0; f...
11
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b, long long c) { return max((a), max((b), (c))); } long long read() { long long x = 0, p = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') p = -1; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (...
14
#include <bits/stdc++.h> #pragma comment(linker, "/stack:20000000") using namespace std; double __begin; template <typename T1, typename T2, typename T3> struct triple { T1 a; T2 b; T3 c; triple(){}; triple(T1 _a, T2 _b, T3 _c) : a(_a), b(_b), c(_c) {} }; template <typename T1, typename T2, typename T3> bool ...
15
#include <bits/stdc++.h> using namespace std; long long modpow(long long a, long long p, long long mod) { long long ret = 1; while (p) { if (p & 1) ret = (ret * a) % mod; a = (a * a) % mod; p /= 2; } return ret; } long long power(long long a, long long p) { long long ret = 1; while (p) { if ...
11
#include <bits/stdc++.h> using namespace std; static long long val(long long k) { return k * ((3 * k) + 2); } static long long value(long long n) { long long high = 577350269; long long low = 0; while (high - low > 1) { if (val((high + low) / 2) < n) low = (high + low) / 2; else high = (high +...
13
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 111; const int INF = 1e9; int tt, k; int a[7]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> tt; for (int t = 0; t < tt; ++t) { cin >> k; int sum = 0; for (int i = 0; i < 7; ++i) { cin >> a[i]; sum += a[i...
7
#include <bits/stdc++.h> using namespace std; int dp1[41][41]; int dp3[41][41][41][41]; int dp4[41][41][41][41]; int b[41][41][41][41]; int a[41][41]; int main() { int n, m, q; scanf("%d %d %d", &n, &m, &q); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { char ch = getchar(); while (...
11
#include <bits/stdc++.h> using namespace std; const long long maxinput = 100005; const long long inf = 1e9 + 7; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<long long> vec; for (long long i = 0; i < n; i++) { long long temp; cin >> temp; ...
1
#include <bits/stdc++.h> using namespace std; ifstream in("test.in"); ofstream out("test.out"); const int DIM = 1e3 + 5; string str; char ans[DIM]; bool dp[DIM][DIM << 1]; void solve(int n, int k) { if (n == 0) return; if (str[n - 1] != '?') { ans[n] = str[n - 1]; if (str[n - 1] == 'L') solve(n - 1, k + 1);...
12
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #define int long long int32_t main() { ios::sync_with_stdio(false); /* bool prime[100001]; memset(prime, true, sizeof(prime)); for (int p=2; p*p<=100001; p++) { if (p...
1
#include <bits/stdc++.h> using namespace std; int n, m; char g[120][120]; int cnt = 0; bool flag1; pair<int, int> start; int main() { cin.tie(0); cin.sync_with_stdio(0); cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> g[i][j]; if (g[i][j] == 'B') cnt++; ...
0
#include <bits/stdc++.h> int main() { int n, a, b, i, j; scanf("%d", &n); i = (n % 7 > 2) ? (2) : (n % 7); a = (n / 7) * 2 + i; j = ((n % 7) == 6) ? (1) : (0); b = ((n / 7) * 2) + j; printf("%d %d", b, a); return 0; }
1
#include <bits/stdc++.h> const long long mod = 100000007; const long long M = 100005; const double pi = acos(-1); using namespace std; int main() { ios_base::sync_with_stdio(false); int m; string second; cin >> m; cin >> second; second = '0' + second + '}'; int n = ((int)(second).size()), pos[n]; int cn...
11
/** In the name of Allah (SWT). * * author: Asif * created: 00.00.2021 00:00:00 **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typed...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, k, total; cin >> n >> k >> total; vector<int> vec(k, 0); int onePassSum = 0; for (int i = 0; i < k; i++) { cin >> vec[i]; onePassSum += vec[i]; } sort(vec.begin(), vec.end()); int mx = 0; for (int i = 0; i <= n; i++) { int t...
10
#include <bits/stdc++.h> using namespace std; template <class T> T power(T a, T b) { T x; if (b == 0) x = 1; else x = a; for (size_t i = 1; i < b; i++) x *= a; return x; } long long int gcd(long long int a, long long int b) { return b == 0 ? a : gcd(b, a % b); } long long int n, m, a, b, c, ab, ba, ...
3
#include <bits/stdc++.h> using namespace std; long long a[105], b[105], w[105][105], e[105][105]; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } void ok(int n, int m, long long k) { printf("YES\n%I64d\n", k); for (int i = 1; i <= n; i++) printf("%I64d%c", a[i] % k + k, " \n"[i == n]); f...
14
#include <bits/stdc++.h> using namespace std; bool deb_mode = 0; class debugger { vector<string> vars; public: template <typename T> debugger &operator,(const T v) { stringstream ss; ss << v, vars.push_back(ss.str()); return *this; } void printall() { int j = 0, l = vars.size(); for (int...
9
#include <bits/stdc++.h> using namespace std; struct state { vector<long long> keys, vals[11]; void insert(long long key) { keys.push_back(key); } void init(long long val = 0) { sort(keys.begin(), keys.end()); keys.erase(unique(keys.begin(), keys.end()), keys.end()); for (int i = 0; i < 10; i++) vals[...
24
#include <bits/stdc++.h> using namespace std; int g[1010][1010]; int i, j, k, n, m, x, y, f, u; int main() { scanf("%d%d", &n, &m); for (i = 1; i <= m; i++) { scanf("%d%d", &x, &y); g[x][y] = 1; g[y][x] = 1; } for (i = 1; i <= n; i++) { f = 0; for (j = 1; j <= n; j++) f |= g[i][j]; if (!...
5
#include <bits/stdc++.h> int e[410000], last[410000], ind[410000], t; void addE(int a, int b) { t++; e[t] = b; last[t] = ind[a]; ind[a] = t; } int di[410000], q[410000], fa[410000], son[410000], rank[410000]; bool nleaf[410000]; int i, j, n, m; void prepare() { int i = 1, tt = 1; q[1] = 1; di[1] = 1; wh...
14
#include <bits/stdc++.h> using namespace std; const long long sz = 105; long long dp[sz][sz][sz], len1, len2, len3; long long prefMatch[sz][26]; char s1[sz], s2[sz], s3[sz]; string ans; long long solve(long long pos1, long long pos2, long long pos3) { if (pos3 > len3) return -(1LL << 61); if (pos1 > len1 || pos2 > ...
12
#include <bits/stdc++.h> using namespace std; long long cum[200001], b[200001]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long n, i, j, ans = 0; cin >> n; map<long long, long long> m; long long cnt = 1, sum = 0; m[0] = 0; for (i = 1; i <= n; i++) { ci...
9
#include <bits/stdc++.h> using namespace std; template <class A, class B> A convert(B x) { stringstream s; s << x; A r; s >> r; return r; } char c[10]; int a[8][8]; int b[8][8]; int di[] = {-1, +1, 0, 0}; int dj[] = {0, 0, -1, +1}; bool Bounds(int r, int c) { return (r >= 0 && r < 8 && c >= 0 && c < 8); } int...
9
#include <bits/stdc++.h> using namespace std; const int N = 510; int n; long long a[N]; int main() { scanf("%d", &n); for (int i = (0); i < (n); ++i) scanf("%lld", a + i); long long ans = *max_element(a, a + n); for (int i = (0); i < (n); ++i) for (int j = (i + 1); j < (n); ++j) { ans = max(ans, a[i] ...
11
#include <bits/stdc++.h> using namespace std; long long n; long long u[200000]; long long nb1 = 0; long long nb2 = 0; long long nb3 = 0; long long nb = 0; long long cnt[200000]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (long long i = 1; i <= n; i++) cin >>...
7
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long n = 0, h = 0, m = 0; cin >> n >> h >> m; long long a[n + 1]; for (long long i = 1; i <= n; i++) { a[i] = h; } for (long long i = 0; i < m; i++) { long long x = 0, y = 0, z = 0; cin >> x ...
0
#include <bits/stdc++.h> using namespace std; int vis[3003][3003], n, m, u, v; vector<pair<int, int> > cost[3003], cost2[3003]; vector<int> g[3003]; void bfs(int ii, int s) { queue<int> q; q.push(s); vis[ii][s] = 0; while (!q.empty()) { s = q.front(); q.pop(); for (int i = 0; i < (int)g[s].size(); i...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; long long k; cin >> n >> k; vector<int> a(n + 1); int maxx; cin >> maxx; int temp; bool flag = 1; int ans; for (int i = 1; i <= n - 1; i++) { cin >> temp; ...
4
#include <bits/stdc++.h> using namespace std; const int N = 3001; set<long long int> f; int p[N][N], ans[N]; vector<int> adj[N]; queue<pair<pair<int, int>, int> > q; long long mask(int a, int b, int c) { return 1000LL * (a * 1000 + b) + c; } int main(void) { int a, b, c, depth = -1, k, m, n; scanf("%d %d %d", &n, &...
12
#include <bits/stdc++.h> using namespace std; mt19937 rnd(51); const int N = 2e5 + 10; vector<int> v(N); int f, x; void solve(int l, int r) { if (l > r) { return; } cout << "? " << l + 1 << " " << r + 1 << endl; cin >> x >> f; int fs = r - f + 1, st = l + f - 1; if (fs <= st) { for (int i = fs; i <=...
19
#include <bits/stdc++.h> using namespace std; map<int, pair<int, int>> Pri; vector<int> Ps = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 13...
12
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int m, n, a, b, t[52][52], x, sum, i, j, k; cin >> n >> m; for (i = 0; i <= n; i++) t[i][0] = 0; for (j = 0; j <= m; j++) t[0][j] = 0; for (i = 1; i <= n; i++) for (j = 1; j <= m; j++) cin >> t[i][j]; cin >> a >> b; x = a...
4
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int MAXN = 300005; const long long mod = 1e9 + 7; const int inf = 0x3f3f3f3f; vector<int> a[MAXN]; vector<int> b[MAXN]; int n; struct Node { int l, r; int val; int val1; } node[MAXN << 2]; int aa[MAXN]; int bb[MAXN]; int book[MAXN]; void...
16
#include <bits/stdc++.h> using namespace std; stack<int> s; vector<int> e[100005], sct[100005]; int dfn[100005], low[100005], tim, bel[100005], scc; bool vis[100005]; void tarjan(int u) { dfn[u] = low[u] = ++tim; vis[u] = 1; s.push(u); for (int v, i = 0; i < e[u].size(); ++i) if (!dfn[v = e[u][i]]) { ...
11
#include <bits/stdc++.h> using namespace std; const int N = 3005; int n, rt, p[N][N], s[N][N]; long long f[N][N], ans; vector<int> G[N]; void build(int u) { s[rt][u] = 1; for (int v : G[u]) if (v ^ p[rt][u]) { p[rt][v] = u; build(v); s[rt][u] += s[rt][v]; } } long long dp(int u, int v) { ...
15
#include <bits/stdc++.h> using namespace std; int re() { int ret = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) f = (ch == '-') ? -f : f, ch = getchar(); while (isdigit(ch)) ret = ret * 10 + ch - '0', ch = getchar(); return ret * f; } signed main() { int t = re(); while (t--) { int n = re(), su...
10
#include <bits/stdc++.h> inline int read() { char c, _c; int x; for (c = _c = getchar(); !isdigit(c); c = getchar()) { _c = c; } for (x = 0; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } return _c == '-' ? -x : x; } const int N = 2e5 + 5; int n, m; char s[N], t[N], str[N]; bool check() { int x = ...
8
#include <bits/stdc++.h> using namespace std; long long a[100], dis[100][50], l, r, num, ans, down, tot; long long dfs(long long book, long long go, bool to) { if (book == -1) { return 1; } if (to == 0 && dis[book][go] != -1) { return dis[book][go]; } long long down = to ? a[book] : 9; long long ans...
11
#include <bits/stdc++.h> using namespace std; int c[8][8]; int d[8][8]; int cnt, now, ans, kol; char ch; int main() { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { scanf("%c", &ch); if (ch == 'B') { cnt++; c[i][j] = 1; } } scanf("\n"); } if (cnt == 0) pr...
3
#include <bits/stdc++.h> using namespace std; long long int mul(long long int x, long long int y) { long long int ans = 1; while (y > 0) { if (y & 1) ans = (ans * x) % 1000000007; y /= 2; x = (x * x) % 1000000007; } return ans; }; vector<vector<pair<long long int, long long int> > > v(100005); long ...
16
#include <bits/stdc++.h> using namespace std; template <class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; } template <class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; } long long MAXN = 9223372036854775807, mod = 998244353; bool comp(pair<long long, pair<...
7
#include <bits/stdc++.h> using namespace std; const int N = 200010; int n, a[N], b[N], p[N], ans; int main() { int i, j; scanf("%d", &n); for (i = 1; i <= n; ++i) { scanf("%d", a + i); p[a[i]] = 0; } for (i = 1; i <= n; ++i) { scanf("%d", b + i); p[b[i]] = i; } if (p[1]) { for (i = 2; ...
10
#include <bits/stdc++.h> using namespace std; int n, i, j, x, y, z, a[55][55], d[55][55][55][55]; char c; int get(int f, int s, int l, int r) { return a[l][r] - a[l][s - 1] - a[f - 1][r] + a[f - 1][s - 1]; } int main() { cin >> n; for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) { cin >> c; a[i][...
15
#include <bits/stdc++.h> using namespace std; int n, m, k; int x, y; int w, e; int a[101]; int main() { cin >> n >> m >> k; for (int i = 0; i < n; i++) cin >> a[i]; if (m == 1) { for (int i = m; i < n; i++) if (a[i] <= k && a[i] != 0) { x = i + 1; break; } cout << 10 * abs(m - ...
0
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { if (b == 1) return a; long long int temp = 1; temp = power(a, b / 2) % 1000000007; temp = (temp * temp) % 1000000007; if (b & 1) { temp *= a; temp %= 1000000007; } return temp % 1000000007; } int ...
7
#include <bits/stdc++.h> using namespace std; long double ans[100001] = {0}; vector<long long int> arr[100001]; long long int dp[100001] = {0}; long long int DFS1(long long int st) { long long int q = 0; for (long long int y = 0; y < arr[st].size(); y++) q += DFS1(arr[st][y]); return (dp[st] = q + 1); } void DFS2...
9
#include <bits/stdc++.h> using namespace std; long long s[2000005], v[2000005]; int main() { long long n, t, i, a, x; cin >> n; long long m = 1; long long sum = 0; long long sub = 0; for (i = (1); i <= (n); i++) { cin >> t; if (t == 1) { cin >> a >> x; s[a] += x; sum += a * x; ...
8
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, n, x, m = 0; cin >> n >> x >> a >> b; cout << min(n - 1, abs(b - a) + x) << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int konst = 1e6; pair<int, long long> H[10][konst + 1]; int maxDigit(int number) { int ans = 0; for (int g = 1; g <= number; g *= 10) { int digit = (number % (g * 10)) / g; ans = max(ans, digit); } return ans; } pair<long long, int> h(int L, int R) { ...
16
#include <bits/stdc++.h> using namespace std; int main() { int n1, n2, k1, k2; cin >> n1 >> n2 >> k1 >> k2; if (n1 > n2) puts("First"); else puts("Second"); }
0