func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; unordered_map<long long, int> mpSt; unordered_map<long long, int> mpEnd; set<long long> AllPoints; long long K[200005]; int main() { int N; scanf( %d , &N); for (int i = 0; i < N; i++) { long long st, end; scanf( %lld %lld , &st, &end); ...
#include <bits/stdc++.h> int main() { int n, temp, count, i, len, len1, j; char c, a[200], b[40]; strcpy(b, qwertyuiopasdfghjkl;zxcvbnm,./ ); while (~scanf( %c , &c)) { getchar(); gets(a); len = strlen(a); len1 = strlen(b); if (c == R ) temp = -1; else ...
#include <bits/stdc++.h> int n, i, j, l, h, k[5500], f[5500], t[5500]; int main() { scanf( %d n , &n); for (i = 1; i <= n; i++) { scanf( %d , &h); k[i] = k[i - 1] + h; j = i - 1; while (t[j] > k[i] - k[j]) j--; f[i] = f[j] + i - 1 - j; t[i] = k[i] - k[j]; } printf...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, x = 0; char c[30][30] = {0}; scanf( %d n , &n); for (i = 1; i <= n; i++) { char temp[605] = ; cin.getline(temp, 605); int length = strlen(temp); for (j = 0; j < length; j++) { c[0][temp[j] - 96]...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; t = 1; while (t--) { double n; cin >> n; double a[200001], sum = 0; set<double> s; for (int i = 0; i < n; i++) { cin >> a[i]; ...
#include <bits/stdc++.h> namespace myland { using namespace std; namespace _abbr {} using namespace _abbr; namespace _constant { const double EPS(1e-8); const double PI(acos(-1.0)); const int INF(0x3f3f3f3f); const long long INFL(0x3f3f3f3f3f3f3f3fll); const int MOD(1e9 + 7); const int dx[] = {-1,...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const int N = 101; const int INF = 0x3f3f3f3f; const int mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mo...
#include <bits/stdc++.h> using namespace std; const int maxl = 60, w = 10000; struct Big { int s[maxl], l; Big() { memset(s, 0, sizeof(s)); l = 1; } inline void fix() { for (int i = 1; i < l; i++) { if (s[i] >= w) { s[i + 1] += s[i] / w; s[i] %= w; ...
#include <bits/stdc++.h> using namespace std; const int N = 105; template <typename T> inline void read(T &AKNOI) { T x = 0, flag = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) flag = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 0 ; ...
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 123; const long long INF = (long long)1e18 + 123; const int inf = (int)1e9 + 123; const int MOD = (int)1e9 + 7; int n; int main() { cin >> n; if (n % 2 == 0) { cout << white n ; cout << 1 2 ; } else cout...
#include <bits/stdc++.h> using namespace std; int n, a[300000 + 10], ans = 2e9; vector<int> lj[300000 + 10]; multiset<int> s; int main() { int i; scanf( %d , &n); for (i = 1; i <= n; ++i) scanf( %d , &a[i]), s.insert(a[i]); for (i = 1; i < n; ++i) { int u, v; scanf( %d%d , &u, &v);...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; cout << (n - 2) * (n - 2); return 0; }
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; for (int i = 1; n; i++) { if (i & 1) printf( %d 2 n , i), n--; else if (n == 1) printf( %d 1 n , i), n = 0; else printf( %d 1 n%d 3 n , i, i), n -= 2; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e4 + 42; int n, m, k; int d[55][maxn], dp[55][maxn], s[55][maxn]; int val[maxn << 2], tag[maxn << 2]; int g; void build(int day, int l, int r, int rt) { if (l == r) { val[rt] = dp[day][l] + s[day + 1][l + k - 1] - s[day + 1][l - 1];...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline void mine(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> inline void maxe(T1 &x, T2 y) { if (x < y) x = y; } ostream &operator<<(ostream &a, const vector<long long> &b) { for (aut...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long cnt = 0; for (long long i = 0; i < s.length(); i++) { if ((s[i] - 0 ) % 2 == 0) cnt++; } if (cnt == 0) cout << -1 << endl; else { vector<char> v; for (long long i = 0; i < s....
#include <bits/stdc++.h> using namespace std::chrono; using namespace std; const long long int mod = 998244353; const int inf = 1e9 + 7; long long int f(long long int x, long long int n) { long long int r = 1; while (n > 0) { if (n % 2 == 1) r = (r * x) % mod; x = (x * x) % mod; n /=...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); int main() { int s1, s2, s3, s4; int a[4]; cin >> a[0] >> a[1] >> a[2] >> a[3]; int i, j, k = 0; sort(a, a + 4); j = a[0]; for (i = 1; i < 4; ++i) { if (j == a[i]) { k++; } else j = ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e8; const int MN = 2e+7; int n, m, nn, mm; int i, j, k, x, y, z, p, u, v; int d[2000], tt; char ss[2000][2000]; void change() { int n = nn, m = mm; if (x == 1) { int tmp = u; u = v; v = n - tmp + 1; swap(n, m)...
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c, i, j, k = 10000000000000000, l, n, m; cin >> n; b = c = a = 1000000; vector<long long int> v1; vector<string> v2; vector<long long int> v3; vector<string> v4; for (i = 0; i < n; i++) { string s; ...
#include <bits/stdc++.h> using namespace std; vector<long long> z; const long long N = 5e3 + 7, M1 = 1e9 + 7, M2 = 1e9 + 9, b1 = 127, b2 = 239; long long maxi1[N], maxi2[N], maxx[N]; pair<long long, long long> h1[N], h2[N]; pair<long long, long long> poww[N]; string best; long long mod(long long x, long...
#include <bits/stdc++.h> using namespace std; template <class T> void chkmax(T& x, T y) { x = x > y ? x : y; } template <class T> void chkmin(T& x, T y) { x = x < y ? x : y; } int n, m; vector<string> s; int calc(int mask, int j) { int res = 0; for (int i = 0; i < n; ++i) if ((...
#include <bits/stdc++.h> using namespace std; const int inf = 987654321; const long long int INF = 123456789987654321; int N; vector<int> arr, chk, chk2; bool f(int l, int r) { for (int i = 0; i < min(l, N - r - 1); i++) { if (arr[i] != arr[N - i - 1]) return false; } chk = vector<int>(N, ...
#include <bits/stdc++.h> using namespace std; char s[200010]; int g[200010][30]; int main() { int i, j, k; int n, t, m; cin >> t; while (t--) { cin >> n >> m; cin >> s + 1; int ans[30] = {0}; for (i = 1; i <= n; i++) { for (j = 0; j < 26; j++) { g[i][j] ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr; int a = 0, b = 0, i, j, k; for (i = 0; i < n; i++) { cin >> arr; if (arr >= 0) { a += arr; } else { b += arr; } } cout << a - b << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, d; long long x; int a[100005], b[100005]; int a_index[100005], q[100005]; long long getNextX() { x = (x * 37 + 10007) % 1000000007; return x; } void initAB() { for (int i = 0; i < n; i = i + 1) { a[i] = i + 1; } for (int i = ...
#include <bits/stdc++.h> using namespace std; long long n, t, p[105], ans, x = 1, c; pair<long long, long long> a[105]; int cmp(pair<long long, long long> a, pair<long long, long long> b) { return a.first * a.second < b.first * b.second; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin ...
#include <bits/stdc++.h> using namespace std; bool solve() { char s[500]; if (scanf( %s , s) == EOF) return false; int in = 0, out = 0; for (int i = 0; s[i]; ++i) { if (s[i] == + ) { if (out) { out--; in++; } else { in++; } } else { ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define mems(p) memset(p,-1,sizeof(p)) #define pb push_back #define eb emplace_back #define nl n #define sz(x) (int)(x).size() #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() ...
#include <bits/stdc++.h> using namespace std; int dp[1010][1010][11][2]; int main() { ios_base::sync_with_stdio(0); int n, m, k; cin >> n >> m >> k; int kk = k; string a, b; cin >> a >> b; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { if (a[i - 1] == b[j -...
#include <bits/stdc++.h> using namespace std; int n, m; int a[300], ans[500][2], tot, v[300]; void sl(int p, int x) { if (p == x || x == 0) return; if (a[x] == 0 || a[x] == x) { ans[tot][0] = p, ans[tot][1] = x; a[x] = x; a[p] = 0; tot++; return; } if (v[x]) { ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; const double eps = 1e-6; const double pi = acos(-1.0); template <class Z> inline Z SQ(Z &a) { return a * a; } template <class Z> inline bool checkmax(Z &a, Z b) { if (a == -1 || a < b) { a...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 5; const int MOD = 1e9 + 7; void solve() { int n, m; cin >> n >> m; cout << (n % m ? NO n : YES n ); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int t = 1; cin >> ...
#include <bits/stdc++.h> using namespace std; int main() { string s; int n, m, f = 0; cin >> n >> m; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == # ) f++; else f = 0; if (f >= m) { cout << NO ; return 0; } } cout << YES ; ...
#include <bits/stdc++.h> using namespace std; void solve(); void YN(bool b) { if (b) { cout << YES << n ; ; } else { cout << NO << n ; ; } }; void yn(bool b) { if (b) { cout << Yes << n ; ; } else { cout...
#include <bits/stdc++.h> using namespace std; int i, j, k, n, m, a[110001], ans; bool cmp(int a, int b) { return a > b; } int main() { scanf( %d%d , &n, &m); for (i = 1; i <= m; i++) scanf( %d%d , &j, &a[i]); sort(a + 1, a + 1 + m, cmp); for (i = 1;; i++) { if (i == 1) k = 1; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, q; string a; cin >> n; map<string, int> m; map<string, string> ma; for (int i = 1; i <= n; i++) { cin >> a; int len = a.length(); for (int i = 0; i <= len; i++) { for (int j = 0; j + i <= len; j++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); n = (int)((double)n / 3 + 0.5); cout << n / 12 << << n % 12 << n ; }
#include <bits/stdc++.h> using namespace std; struct LinearBase { const int n = 30; vector<int> pivot = vector<int>(n); void Insert(int curr) { for (int bit = n - 1; bit >= 0 && curr != 0; --bit) { if ((curr & (1 << bit)) != 0) { curr ^= pivot[bit]; } } if (cu...
#include <bits/stdc++.h> using namespace std; long long n, dp[30][30]; string s; long long ten[30]; string ans[30][30]; int main() { cin >> n >> s; reverse(s.begin(), s.end()); ten[0] = 1; for (int i = 1; i <= 20; i++) ten[i] = ten[i - 1] * 10; dp[0][0] = 0; dp[1][0] = s[0] - 0 ; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; const int maxm = 1e9 + 7; int n; int a[maxn], b[maxn], c[maxn], ans[maxn]; map<int, int> mp; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); b[i] = a[i]; } queue<int> q; ...
#include <bits/stdc++.h> using namespace std; int main() { cin.sync_with_stdio(false); cin.tie(0); long int n; cin >> n; const long int N = n; char s[N]; int cnt0 = 0, cnt1 = 0; for (int i = 0; i < n; i++) { cin >> s[i]; if (s[i] == z ) { cnt0++; } if...
#include <bits/stdc++.h> using namespace std; const int N = 10005, M = 105; int n; char s[N]; int p, m; int lim; int dp[2][N][M]; int ch[N][2], tot = 1; int fa[N]; void dfs(int u) { if (!ch[u][0]) return; dfs(ch[u][0]); dfs(ch[u][1]); for (int i = 0; i <= lim; i++) for (int j =...
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 3; const int mod = 1e9 + 7; const int inf = 1e9 + 7; bool dp[N][N]; bool ok[N][10]; int cnt[N][10]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string t[10]; t[0] = 1110111 ; t[1] = 0010010 ; t[2] = 1...
#include <bits/stdc++.h> using namespace std; const int NMAX = 100007; int v[NMAX]; int n; int main() { cin >> n; for (int i = 1; i <= n; ++i) { cin >> v[i]; } sort(v + 1, v + n + 1); for (int i = 3; i <= n; ++i) { if (v[i - 2] + v[i - 1] > v[i]) { cout << YES ; ...
#include <bits/stdc++.h> using namespace std; int n, m; char s[100005]; vector<int> p, star; void input() { scanf( %s , s); p.clear(), star.clear(); int l = strlen(s); for (int i = 0; i < l; i++) { if (s[i] == P ) p.push_back(i); if (s[i] == * ) star.push_back(i); } n = p...
#include <bits/stdc++.h> #define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0); #define F first #define S second #define V vector #define PB push_back #define MP make_pair #define EB emplace_back #define ALL(v) (v).begin(), (v).end() #define debug(x) cerr << Line( << __LINE__ << ) -> << #x ...
#include <bits/stdc++.h> using namespace std; vector<int> a; int main() { string s; cin >> s; int cur = 0, mul = 1; for (int i = s.length() - 1; i >= 0; --i) { if (s[i] == , ) { a.push_back(cur); mul = 1; cur = 0; } else { cur += mul * (s[i] - 48); ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string str; cin >> str; set<string> visited; queue<string> s; s.push(str); visited.insert(str); int count = 0, x = 0; while (!s.empty() && count != k) { string temp = s.front(); x ...
#include <bits/stdc++.h> using namespace std; long long n, m; int main() { cin >> n >> m; if (n > m) { swap(n, m); } if (n % 2 == 0 && m % 2 == 0) { if (n == 2 && m == 2) cout << 0 << endl; else cout << n * m << endl; return 0; } if (n + m <= 4) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int mod = 1e9 + 7; char str[maxn]; long long qp(long long a, long long b) { long long ret = 1; while (b) { if (b & 1) ret = ret * a % mod; a = a * a % mod; b >>= 1; } return ret; } long long inv...
#include <bits/stdc++.h> using namespace std; long long int power_mod(long long int a, long long int x) { if (x == 0) return 1; long long int y = power_mod(a, x / 2); long long int ans = (y * y) % 1000000007; if (x % 2) ans = (ans * a) % 1000000007; return ans; } long long int inv(long long ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast , unroll-loops ) using namespace std; const int MOD = 1e9 + 7; const int MAXN = 1010; const double EPS = 0.000001; double A[MAXN], B[MAXN]; int n, m; bool can(double X) { for (int i = 0; i < n; i++) { double W_li = m + X; double TO = ...
#include <bits/stdc++.h> using namespace std; const int N = 1000008; int n, m, k, d, i, j, e; int tmp[N], pos[N], p[N], c[N]; char s[N]; int main() { scanf( %s %d , s, &m); n = strlen(s); while (m--) { scanf( %d%d , &k, &d); for (i = 0; i < n; i++) { c[i] = (i + 1) % n; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5; vector<int> G[MAXN]; int happiness[MAXN], f[MAXN], tmpAns = 0, ans = 0; void dfs(int u, int par) { int oldTmpAns = -1, oldF = -1, oldFPos = -1; if (~par && f[tmpAns] < happiness[u]) oldTmpAns = tmpAns, f[++tmpAns] = happiness[u]...
#include <bits/stdc++.h> using namespace std; int n, k, maxx, cmax; int t[100010]; long long int sum[100010]; int binary_search1(int st, int dr, int pos, int x) { int sol = 0; while (st <= dr) { int m = (st + dr) / 2; long long int lsum = sum[pos] - sum[m - 1]; lsum = 1LL * (pos - m ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int arr[n][2]; for (int i = 0; i < n; i++) { cin >> arr[i][0] >> arr[i][1]; } long long int x = max(arr[0][0], arr[0][1]); vector<int> v1; int fail = 0; for (int i = 1; i < n; i+...
#include <bits/stdc++.h> using namespace std; int cnt, dfn[800005], ed[800005], tot, head[800005], tr[800005 * 4], sum[800005 * 4], fuckljx, n, m, vis[800005], de[800005]; char c[800005]; vector<char> mp[800005]; struct edge { int to, next; } data[800005 * 2]; struct hh { long long x, a, b, ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, r; scanf( %d%d%d , &a, &b, &r); printf( %s n , a >= 2 * r && b >= 2 * r ? First : Second ); }
#include <bits/stdc++.h> using namespace std; int T; long long r, b, k, g; long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { scanf( %d , &T); while (T--) { scanf( %lld%lld%lld , &r, &b, &k); if (r > b) swap(r, b)...
#include <bits/stdc++.h> using namespace std; int main() { int month, day; int cheat[13] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; cin >> month >> day; int n = cheat[month] - 8 + day; int ans = 1 + (n / 7) + ((n % 7) > 0); cout << ans; return 0; }
#include <bits/stdc++.h> const int MaxN = 100000, inf = 0x3f3f3f3f; inline void read(int &ans) { ans = 0; char c = getchar(); while (c < 0 || c > 9 ) c = getchar(); while (c >= 0 && c <= 9 ) ans = ans * 10 + c - 48, c = getchar(); return; } int n, P; struct Node { int pos, t; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, z; cin >> n >> k; vector<pair<int, int>> h, res; h.reserve(n); h.resize(k); for (int i = 0; i < k; ++i) { cin >> h[i].first; h[i].second = i; } make_heap(begin(h), end(h)); res.reserve(n); int64_...
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int N_MAX = 50; int pwr(int a, int b) { if (b == 0) return 1; if (b & 1) return 1LL * pwr(a, (b ^ 1)) * a % MOD; int aux = pwr(a, (b >> 1)); return 1LL * aux * aux % MOD; } int n; int invf[N_MAX + 2]; struct T...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; const long long mod = 1e9 + 7; const long long inf = 1e9; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; sor...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; long long sum = 0; vector<long long> a(n); for (long long i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; } vector<long long> pr...
#include <bits/stdc++.h> using namespace std; int n; vector<long long> b; int main() { ios_base::sync_with_stdio(false); cin >> n; b.resize(n); for (int i = 0; i < n; ++i) cin >> b[i]; long long mi = *min_element(b.begin(), b.end()); long long ma = *max_element(b.begin(), b.end()); i...
#include <bits/stdc++.h> using namespace std; const int N = 1555; const int INF = 0x3f3f3f3f; int sx, sy; int n, m; char maze[N][N]; int dir[4][2] = {0, 1, 1, 0, -1, 0, 0, -1}; struct node { int x, y; } vis[N][N]; bool bfs(int x, int y) { queue<node> q; node now, next; now.x = x; ...
#include <bits/stdc++.h> using namespace std; int n, ar[1010]; bool b[1010]; int main() { cin >> n; for (int i = 1; i <= n; ++i) { cin >> ar[i]; } for (int i = 1; i <= n; ++i) { int yk = i; while (1) { if (b[yk]) break; b[yk] = 1; yk = ar[yk]; } ...
#include <bits/stdc++.h> using namespace std; int bs; int* cnt; int ans; class query { public: int l; int r; int index; }; bool cmp(const query a, const query b) { int s = a.l / bs; int e = b.l / bs; if (s == e) return a.r < b.r; return s < e; } void add(int x) { if ...
#include <bits/stdc++.h> using namespace std; const int MAXn = 1e5 + 10, MAXlg = 20; long long dp[MAXn][MAXlg], h[MAXn], dp2[MAXn], n, m, dp3[MAXn], dp4[MAXn]; vector<int> v[MAXn]; bool flag[MAXn], flag2[MAXn]; int make_tree(int a) { flag[a] = true; int ans = 1; h[a] = h[dp[a][0]] + 1; if (v...
#include <bits/stdc++.h> using namespace std; using ll = long long; using cd = complex<double>; ll base = 100; void fft(vector<cd>& a, bool inv) { int n = a.size(); int bits = __builtin_ctz(n); for (int i = 0; i < n; ++i) { int x = 0; for (int j = 0; j < bits; ++j) x = (x << 1) | (i >>...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) void print(vector<long long> vvv) { for (auto it : vvv) cout << it << ; cout << n ; } long long mod = 1e9 + 7; long long qpow(long long base, long long p) { if (p == 0) return 1; if (p == 1) return base % mod; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const long long inf = 1e18; int ntest; int n, m, k; string s; int cnt[55]; bool ok[maxn]; void read_input() { cin >> n >> m >> k; cin >> s; } void solve() { fill(cnt, cnt + 26, 0); for (int i = 0; i < k; ++i) +...
#include <bits/stdc++.h> using namespace std; mt19937 mt(time(0)); long long n, k; long long a[123456]; const long long inf = (int)(1e9); int cnt = 0; long long mas[123456]; long long solve() { long long md; for (int i = mt() % 123456 + (int)(1e9);; i++) { bool ok = false; for (int j...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, k; cin >> n >> k; string s, s1; cin >> s; long long int a[27] = {0}, c = 0, d = 0; for (long long int i = 0; i < n; i++) { if (a[s[i] - a ] ==...
#include <bits/stdc++.h> using namespace std; struct target { long double x; long double y; long long t; long double p; bool operator<(const target &b) const; }; bool target::operator<(const target &b) const { return t < b.t; } int main() { cout.precision(30); vector<target> v; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int x, n, m, temp = 0; cin >> x >> n >> m; for (int i = 0; i <= n; i++) { if (x <= 10 * m) { temp = 1; break; } else x = x / 2 + 10; } if ...
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-6; int ROUND(double x) { return (int)(x + 0.5); } bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; } bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); } double SQSUM(double ...
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { long long int res = 1; while (b) { if (b % 2 == 1) res = (res * a) % 1000000007; a = (a * a) % 1000000007; b /= 2; } return res; } bool comp(long long int a, long long int b) {...
#include <bits/stdc++.h> const long long INF = 2e18; const double EPS = 1e-9; using namespace std; void WEZaa() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } int main() { WEZaa(); unsigned long long n, k; cin >> n >> k; vector<unsigned long long> a(n), b(n...
#include <bits/stdc++.h> using namespace std; int n, ans1, ans2, nr, x; vector<int> v; int main() { cin >> n; for (int i = 1; i <= n; ++i) { cin >> nr; for (int j = 1; j <= nr; ++j) { cin >> x; if (nr % 2 == 1 && j == (nr + 1) / 2) { v.push_back(-x); conti...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, ans = INT_MAX; cin >> n >> k; for (long long int i = 0; i < n; i++) { long long int x; cin >> x; if (k % x == 0) { ans = min(ans, k / x); } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace ::std; template <class T> T SQR(T N) { return (T)N * N; } template <class T> double DIST(T a, T b) { return 1.0 * sqrt(SQR(double(a)) + SQR(double(b))); } template <class T> bool CROSS(pair<T, T> a, pair<T, T> b, pair<T, T> c) { return (b.first - a....
#include <bits/stdc++.h> using namespace std; long long derangements(long long n) { if (n == 0) return 1; if (n == 1) return 0; if (n == 2) return 1; return (n - 1) * (derangements(n - 1) + derangements(n - 2)); } long long nCr(long long n, long long r) { long long res = 1; if (r == 0) r...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class ...
#include <bits/stdc++.h> using namespace std; int main() { int N, K, X; cin >> N >> K >> X; vector<int> Balls[100]; for (int i = 0; i < N; i++) { int color; cin >> color; Balls[0].push_back(color); } for (int i = 1; i < 100; i++) { Balls[i] = Balls[0]; } int r...
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; if (a <= 4) cout << a % 3 + 1 << endl; else if (a == 5) cout << a - 4 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; inline long long read() { long long num = 0, neg = 1; char c = getchar(); while (!isdigit(c)) { if (c == - ) neg = -1; c = getchar(); } while (isdigit(c)) { num = (num << 3) + (num << 1) + c - 0 ; c = getchar(); } re...
#include <bits/stdc++.h> using namespace std; void solve() { long long int i, j, n, s = 0, c = 0, x, k, y, m, z, ans = 0; cin >> n >> m; cin >> x >> z >> y; vector<long long int> a(n), b(m); for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < m; i++) { cin >> b[i]; }...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, l, m, n, p, x, y; string s1, s2, s3, s4; cin >> s1 >> s2; cin >> n; cout << s1 << << s2; cout << endl; for (i = 0; i < n; i++) { cin >> s3 >> s4; if (s3 == s1) { s1 = s4; cout << s1 <<...
#include <bits/stdc++.h> using namespace std; typedef long double ld; typedef long long int int64; typedef unsigned long long int uint64; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<long long> VLL; typedef vector<PII> ...
#include <bits/stdc++.h> using namespace std; const long long P = 1e9 + 7; const int N = 2e5 + 5; const int inf = 0x3f3f3f3f; const double pi = acos(-1); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, x, y, a[2]; vector<int> g[N]; void dfs(int x, int fa, int grp) { a[g...
#include <bits/stdc++.h> using namespace std; int main() { int m, n, sum = 0, i = 1, k; cin >> n >> m; k = m; while (m >= i) { m -= i; i = (i % n) + 1; } cout << m << endl; return 0; }
#include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s; for (int i = 1; i < s.size(); i++) { if (s[i] == s[i - 1]) for (char j = a ; j <= z ; j++) if (s[i - 1] != j && s[i + 1] != j) { s[i] = j; break; } } cout << s...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int t[n]; for (int i = 0; i < n; i++) { cin >> t[i]; } if (n == 1) { cout << m - t[0]; return 0; } int ans = 0; for (int k = 0; k < n * n * n; k++) { set<int> st; for...
#include <bits/stdc++.h> using namespace std; struct node { int cnt; bool leaf; int nx[26]; node() { leaf = false; cnt = 0; memset(nx, -1, sizeof nx); } }; string s, d; node t[300100]; int ans, sz; vector<string> v; void add(string s) { int cur = 0; for (int...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<int>; int n, m, p, nm; vector<char> g; vector<bool> vis; vector<int> s, cnt; vector<queue<int>> ex; queue<int> q; bool isEmpty(int v) { if (v < 0) return false; int i = v / m, ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 3005; const double PI = acos(-1); struct Point { ll x, y; }; inline Point operator+(const Point &a, const Point &b) { return {a.x + b.x, a.y + b.y}; } inline Point operator-(const Point &a, const Point &b) { ...
#include <bits/stdc++.h> using namespace std; const int maxm = 1e5 + 5; const int maxn = 1e5 + 5; const int inf = 0x3f3f3f3f; int n, m; int a[maxn]; struct edge { int u, v, w, next; } e[maxm * 2]; int head[maxn]; bool vis[maxn]; int cnt; priority_queue<int, vector<int>, greater<int> > q; v...