func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma comment(linker, /STACK:666000000 ) using namespace std; const int inf = (1 << 30) - 1; const long double eps = 1e-9; const long double pi = fabs(atan2(0.0, -1.0)); void ML(const bool v) { if (v) return; int *ass; for (;;) { ...
#include <bits/stdc++.h> using namespace std; int a[1000005], b[1000005], ans[1000005]; int main() { int n; cin >> n; vector<int> v; int y = 1; while (y < n) { v.push_back(y); y *= 2; } int j = v.size() - 1, x; for (int i = 0; i < n; i++) { cin >> a[i]; if (...
#include <bits/stdc++.h> using namespace std; const long long PLUS = -1; const long long MULT = -2; string fo; vector<long long> tmp, whereMULT; long long i, nr, lo, hi, total, add, crt, j, p, ans; int main() { cin >> fo; fo = 1* + fo + *1 ; for (i = 0; i < fo.size();) { if (!( 0 <= ...
#include <bits/stdc++.h> using namespace std; int su(int n) { int r, sum = 0; while (n != 0) { r = n % 10; sum = sum + r; n = n / 10; } return sum; } int main() { int n; cin >> n; int k = n; int i = 0; while (i != 10) { int d = su(k + i); if (d %...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; t = 1; while (t--) { int n, m; cin >> n >> m; string s[n]; for (int i = 0; i < n; ++i) { cin >> s[i]; } int cnt = 0; ...
#include <bits/stdc++.h> using namespace std; long long res, d, e, k; int N; int h[2020]; long long dp[2020][2020]; long long pw(long long a, long long n) { long long ret = 1; while (n) { if (n % 2) ret *= a, ret %= 998244353; a *= a, a %= 998244353; n >>= 1; } return ret; ...
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, ans, maxi, mini, res; string s1, s2; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> x; if (x == 2) cout << 2; else cout <...
#include <bits/stdc++.h> using namespace std; int on[100005]; int prime[100005], cnt = 0; void ola() { for (int i = 2; i <= 100005; i++) { if (!on[i]) prime[cnt++] = i; for (int j = 0; j < cnt && i * prime[j] <= 100005; j++) { on[i * prime[j]] = 1; if (i % prime[j] == 0) break; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 400005; int n, q, a[maxn]; namespace SGT { int Min[maxn << 2]; void modify(int l, int r, int id, int x, int y) { if (l == r) { Min[id] = y; return; } int mid = (l + r) >> 1; if (x <= mid) modify(l, mid, id << 1,...
#include <bits/stdc++.h> using namespace std; const double EPS = 1E-9; const int INF = 1000000000; const long long INF64 = (long long)1E18; const double PI = 3.1415926535897932384626433832795; long long gcd(long long a, long long b) { if (a < b) return gcd(b, a); if (b == 0) return a; return gcd...
#include <bits/stdc++.h> using namespace std; long long n, k, T; long long doit(long long n, long long k) { if (n == 1) return k * (k + 1) / 2; long long tp = (n - 1) / k + 1, v1 = doit(tp, k), tp2 = (n - 1) % k + 1; long long f1 = (tp - 1) * (k * k + 1), f2 = v1 - f1; if (tp2 * k < f2) retu...
#include <bits/stdc++.h> using namespace std; int t, n, m, a[5][200], ans; vector<pair<int, int> > v, vec; int getidx(int i, int j) { return (i - 1) * m + j; } int geti(int idx) { return (idx - 1) / m; } int getj(int idx) { return (((idx - 1) % m) + 1); } int main() { ios_base::sync_with_stdio(0); ...
#include <bits/stdc++.h> const int INF = 2147483647; using namespace std; unsigned char like[7][7]; int fenzu[7]; int n, totjy[3]; int getnum(char l[50]) { switch (l[0]) { case A : return 0; case C : if (l[1] == h ) return 1; else return 2; ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e6 + 7; const long double maxx = 1e11; int tmp[MAXN]; int main() { int n, k; cin >> n >> k; string s; cin >> s; k--; if (k >= n / 2) k = n - k - 1; int ans = 0, l = 0, r = 0; for (int i = 0, j = n - 1; i < j;...
#include <bits/stdc++.h> using namespace std; int main() { int n, tmp, curr = 0; cin >> n; int v[n], res[n]; for (int i = 0; i < n; i++) { cin >> tmp; v[tmp] = i + 1; } for (int i = 0; i < n; i++) { cin >> tmp; if (v[tmp] > curr) { res[i] = v[tmp] - curr; ...
#include <bits/stdc++.h> using namespace std; int n, k; int Time = 0; string s; bool dp[2][(int)1e5 + 10]; struct Node { int nxt[26]; bool leaf; Node() { for (int i = 0; i < 26; i++) nxt[i] = -1; leaf = 1; } } trie[(int)1e5 + 10]; void dodaj(string s) { int niz[100010]; ...
#include <bits/stdc++.h> int main() { int n, t, i; scanf( %d%d , &n, &t); if (n == 1 && t == 10) printf( -1 ); else { if (t == 10) { printf( 1 ); for (i = 0; i < n - 1; i++) printf( 0 ); } else for (i = 0; i < n; i++) printf( %d , t); } return 0; } ...
#include <bits/stdc++.h> using namespace std; const int N = 52; int n, m, a[N][N], b[N][N], i, j; int main() { cin >> n >> m; for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) cin >> a[i][j]; } for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) cin >> b[i][j]; } for (i = 1...
#include <bits/stdc++.h> int n; char s[20]; int main() { scanf( %d , &n); getchar(); int ans = 0; for (int i = 1; i <= n; i++) { scanf( %s , s); if (s[0] == T ) { ans += 4; } else if (s[0] == C ) { ans += 6; } else if (s[0] == O ) { ans += 8; ...
#include <bits/stdc++.h> using namespace std; pair<int, int> get_pair(int a, int b) { if (a > b) swap(a, b); return {a, b}; } template <class Cap, class Cost> struct mcf_graph { private: int _n; struct _edge { int to, rev; Cap cap; Cost cost; }; vector<pair<int, in...
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; const long double PI = 3.141592653589793238462643383279502884197; long long fac[1] = {1}, inv[1] = {1}; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long mp(long long a, long long b) { ...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& a) { in >> a.first >> a.second; return in; } template <typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> a) { out << a.first << << a.second;...
#include <bits/stdc++.h> using namespace std; long long int ar[500009], br[500009], cr[500009], tr[500009]; long long int fx[] = {-1, 1, 0, 0}; long long int fy[] = {0, 0, 1, -1}; map<long long int, long long int> mp; vector<long long int> v; string s; struct evan { long long int l, r, pos; } st[5...
#include <bits/stdc++.h> using namespace std; int main() { int x1, x2, y1, y2, x, y; cin >> x1 >> y1 >> x2 >> y2 >> x >> y; int temp1 = abs(x1 - x2), temp2 = abs(y1 - y2); int temp3 = temp1 / x, temp4 = temp2 / y; if (temp1 % x == 0 && temp2 % y == 0 && temp3 % 2 == temp4 % 2) cout << YES...
#include <bits/stdc++.h> struct point { double x, y, z; point() {} point(double _x, double _y, double _z) : x(_x), y(_y), z(_z) {} }; const double eps = 1e-8; double vlen(point p) { return sqrt(p.x * p.x + p.y * p.y + p.z * p.z); } point xmult(point u, point v) { point ret; ret.x = u.y * v...
#include <bits/stdc++.h> using namespace std; long long h, w, n; pair<long long, long long> a[2005]; long long fact[200005]; long long ifact[200005]; long long dp[2005]; long long exp(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a; if (b % 2 == 0) { long long r = ...
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 2; int lis[N], where[N], length[N], link[N], a[N], b[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } a[n] = INT_MAX; int m...
#include <bits/stdc++.h> using namespace std; const int maxn = 100101; int pre[maxn], ind[maxn], cnt[maxn], f[maxn]; vector<int> g[maxn], q; int main() { int n; cin >> n; for (int i = 2; i <= n; ++i) { int l, r; scanf( %d%d , &l, &r); g[l].push_back(r); g[r].push_back(l); ...
#include <bits/stdc++.h> using namespace std; struct node { int next, to; } a[400001]; int st[200001], vis[200001], fa[200001], last, cnt = 0, ans = 0, huan; int roo[200001], roo2[200001]; void add(int x, int y) { a[++cnt].to = y; a[cnt].next = st[x]; st[x] = cnt; } void dfs(int x, int l...
#include <bits/stdc++.h> using namespace std; int main() { long long n, x; string d; int t, m = 0; cin >> n >> x; for (int i = 0; i < n; i++) { cin >> d >> t; if (d[0] == + ) x += t; if (d[0] == - ) { if (x >= t) x -= t; else m++; } ...
#include <bits/stdc++.h> using namespace std; int t, n, pl; string s; int main() { std::ios::sync_with_stdio(false); cin >> t; for (int qqw = 1; qqw <= t; qqw++) { cin >> n; cin >> s; pl = -1; for (int i = 1; i <= n; i++) if (s[i - 1] == 0 ) pl = i; if (pl > 0)...
#include <bits/stdc++.h> using namespace std; struct linearbasis { long long base[64], flag, cnt; bool add(long long x) { for (int i = 62; ~i; i--) { if (x >> i & 1) { if (!base[i]) { base[i] = x; return false; } x ^= base[i]; } ...
#include <bits/stdc++.h> using namespace std; std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count()); constexpr int MAXN = 1e9 + 7; constexpr int INF = 0x3f3f3f3f; constexpr long long INFLL = 0x3f3f3f3f3f3f3f3f; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullp...
// precompute lookup table for each digit? #include <iostream> #include <unordered_map> #include <utility> #include <algorithm> using namespace std; #define MP make_pair<int, int> int main() { unordered_map<int, int> lookup[10]; lookup[1].insert(MP(0, 1)); lookup[2].insert(MP...
#include <bits/stdc++.h> using namespace std; int main() { float h, l, ans; cin >> h >> l; ans = (l * l - h * h) / (2 * h); cout << setprecision(13) << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; const int mod = 1e9 + 7; const int inf = (1 << 30); vector<int> v[maxn][5], tpl; int ted[maxn], com[maxn], tmp = 1; bool visited[maxn]; bool dfs(int u, int d) { visited[u] = 1; bool rz = (ted[com[u]] == 1); if (d == 1) ...
#include <bits/stdc++.h> using namespace std; long long am[20]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<long long> a(n); for (int i = 0, ThxDem = n; i < ThxDem; ++i) { cin >> a[i]; for (int j = 0, ThxDem = 20; j < ThxDem; ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:400000000 ) int n, r; string ans; pair<int, int> f(int a, int b) { if (a == 1 && b == 0) return pair<int, int>(0, 0); if (a > 1 && b == 0) return pair<int, int>(1000000007LL, 1000000007LL); if (a == 1 && b == 1) return p...
#include <bits/stdc++.h> using namespace std; int n, m; int U[5005], V[5005]; struct emm { int a, b, x; } a[5005]; bool cmp(emm x, emm y) { return x.x < y.x; } struct Edge { int v; Edge *next; } pool[5005 << 1], *h[5005]; int fa[5005], dep[5005], ans[5005]; int tot; void addEdge(int u,...
#include <bits/stdc++.h> using namespace std; int main() { char a[1010]; cin >> a; int l = strlen(a), dot; for (int i = 0; i < l; i++) { if (a[i] == . ) { dot = i; } } if (a[dot - 1] == 9 ) { cout << GOTO Vasilisa. << endl; } else { if (a[dot + 1] >= ...
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 11; int use[N], a[N], b[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; use[a[i]] = 1; } for (int j = 1; j <= n; j++)...
#include <bits/stdc++.h> using namespace std; int n, r, s; long long F[10005] = {1}, I[10005]; long long inv(long long a) { long long ans = 1; for (int k = 998244353 - 2; k; k >>= 1) { if (k & 1) ans = (ans * a) % 998244353; a = a * a % 998244353; } return ans; } long long C(int ...
#include <bits/stdc++.h> using namespace std; int n, m; int xans[200005]; bool pos; vector<pair<int, int> > xoc[200005]; vector<pair<int, int> > V[200005]; int erased[200005]; queue<int> toErase; int sgn(int v) { return abs(v) / v; } vector<pair<int, int> > E[200005]; int vis[200005]; int cycleR...
#include <bits/stdc++.h> using namespace std; const int MX = 1234567; const double PI = acos(-1.0), EPS = 1e-9; long long N, arr[MX]; long long gcd(long long a, long long b) { while (a > 0 && b > 0) { if (a > b) a %= b; else b %= a; } return a + b; } int main() { ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; scanf( %d%d%d , &a, &b, &c); int ok = 0; if (a == 1 || b == 1 || c == 1) ok = 1; if (a == 3 && b == 3 && c == 3) ok = 1; if (a == 2 && b == 2) ok = 1; if (b == 2 && c == 2) ok = 1; if (a == 2 && c == 2) ok = 1; ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { f = ch == - ? -1 : 1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 0 , ch = getchar(); return x * f; } const int N ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; char arr[100][100]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> arr[i][j]; if (arr[i][j] == - ) { arr[i][j] = - ; } else { if (i % 2 == 0 && ...
#include <bits/stdc++.h> using namespace std; template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p) { out << ( << p.first << , << p.second << ) ; return out; } template <typename T> ostream& operator<<(ostream& out, vector<T> const& v) { int l = v.size();...
#include <bits/stdc++.h> using namespace std; int main() { double r, x, y, z, t; cin >> r >> x >> y >> z >> t; double d = (x - z) * (x - z) + (y - t) * (y - t); d = sqrt(d); double i; for (i = 0; i < 10000000; i++) { if ((i * r) >= d / 2) break; } cout << i << endl; }
#include <bits/stdc++.h> using namespace std; int w1, w2, h1, h2; int main() { scanf( %d%d%d%d , &w1, &h1, &w2, &h2); printf( %d n , (h1 + h2) * 2 + 4 + max(w1, w2) * 2); return 0; }
#include <bits/stdc++.h> #pragma GCC optimize( O500 ) #pragma comment(linker, /STACK:1677777216 ) #pragma warning(default : 4) using namespace std; const double eps = 1e-12; const int oo = 0x3F3F3F3F; const long long ooLL = 0x3F3F3F3F3F3F3F3FLL; const int MOD = 1000000007; template <typename T> T s...
#include <bits/stdc++.h> using namespace std; int ispalin(string a) { string b = a; reverse(b.begin(), b.end()); return a == b; } int main() { string str; cin >> str; int N = str.size(); for (int i = 0; i <= N; i++) { for (char xc = a ; xc <= z ; xc++) { string str1; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int h = n / 2; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i <= h) { if (j >= h - i && j <= h + i) { cout << D ; } else { cout << * ; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 51; long long ans[maxn], a[maxn]; long long poww(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = res * a; b /= 2; a = a * a; } return res; } void init() { ans[0] = 1; a[0] = 1...
#include <bits/stdc++.h> using namespace std; char a[1001][1001]; int d[1001][1001]; int n, m, ans; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; for (int i = n; i > 0; i--) for (int j = m; j > 0; j--) { int cur; d...
#include <bits/stdc++.h> using namespace std; int n, m, k, i, p; int main() { cin >> n; if (n < 3) { cout << -1; } else { for (i = n; i >= 1; i--) { cout << i << ; } } }
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 1e9 + 7; const int N = 2e5 + 5; int64_t mpow(int64_t b,int64_t e,int64_t m){ int64_t r = 1; while(e > 0){ if(e & 1){ r = (r*b)%m; } b = (b*b)%m; e >>= 1; } return r;...
#include <bits/stdc++.h> using namespace std; int nxt() { int x; cin >> x; return x; } int main() { int n = nxt(), k = nxt(); vector<int> a(n); generate(a.begin(), a.end(), nxt); int s = accumulate(a.begin(), a.end(), 0); int ans = 0; while ((s + k * ans) * 1.0 / (n + ans) < ...
#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 visited[100005] = {0}; vector<int> v[100005]; int color[100005]; int dfs(int s) { int result = 0; visited[s] = 1; for (int i = 0; i < v[s].size(); i++) { if (!visited[v[s][i]]) { if (color[v[s][i]] != color[s]) result += (1...
#include <bits/stdc++.h> using namespace std; void dfs(const vector<int> &next, vector<bool> &visited, vector<int> &end, int x) { visited[x] = true; int y = next[x]; if (!visited[y]) { dfs(next, visited, end, y); end[x] = end[y]; } else end[x] = x; } int main() { ...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int AL = 26; const int N = (int)1e6 + 9; int powr(int n, int k) { if (k == 0) return 1; int v = powr(n, k / 2); v = (v * 1ll * v) % MOD; if (k & 1) v = (v * 1ll * n) % MOD; return v; } int cnt[AL]; int ...
#include <bits/stdc++.h> using namespace std; void solution() { long long n, x, m = 0, ans = 0; cin >> n; ans += 2 * n - 1; while (n--) { cin >> x; ans += abs(x - m); m = x; } cout << ans << n ; } int main() { ios ::sync_with_stdio(0); cin.tie(0); long lon...
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; for (int i = 0; i < q; i++) { int n, r; cin >> n >> r; int arr[n]; for (int j = 0; j < n; j++) { cin >> arr[j]; } sort(arr, arr + n); int shots = 0, act[n], p = 0; act[0] =...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int ch = 0, nch = 0; int x; int b; if (n >= m) { b = m; } else { b = n; } for (int i = 0; i < n; i++) { cin >> x; if (x % 2 == 0) { ch++; } else { nch...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { for (; b; a %= b, swap(a, b)) ; return a; } int n; pair<int, int> board[1001][1001]; int ans[1001][1001]; int dx[5] = {0, 1, -1, 0, 0}; int dy[5] = {0, 0, 0, 1, -1}; bool isValid(int x, int y) { retur...
#include <bits/stdc++.h> using namespace std; const int N = 21, inf = 1e7; int n, k, a[1 << N], pre[1 << N], ns, cs[1 << N]; inline int cmax(int x, int y) { if (x == -1 || y == -1) return x == -1 ? y : x; return a[x] > a[y] ? x : y; } bool E[1 << N][N]; void UPD(int x) { cs[x] = -1; for (i...
#include <bits/stdc++.h> using namespace std; const int N = 100 * 1000 + 5; int l[N]; int w[N]; int getw(long long s, long long e) { if (e % 2) { if (s % 2) { return 2; } return 1; } if (s * 2 > e) { if (s % 2 == e % 2) { return 2; } return 1; ...
#include <bits/stdc++.h> using namespace std; const int M = 10 + 10; int minn0[M][M]; int minn[M][M]; int dig[M]; int dignum; int fac(int x) { int ans = 1; for (int i = 1; i <= x; i++) { ans = ans * i; } return ans; } int ex(int a, int x) { int ans = 1; for (int i = 1; i ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cout.tie(0); cin.tie(0); long long k; cin >> k; long long sum = 0; map<long long, long long> m; vector<long long> ssum(k, 0), g(5005 * k, -1); vector<vector<long long>> a(k); vector<pair<l...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, len; int i = 1; cin >> n; cin >> k; vector<int> a; while (n > 1) { if (n % (i + 1) == 0) { a.push_back(i + 1); n = n / (i + 1); i -= 1; } i += 1; } len = a.size() - k; i...
#include <bits/stdc++.h> using namespace std; long long ar[100010]; unordered_map<long long, long long> um; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t, n, x, ans, y, prev; scanf( %lld , &t); long long sm = 0; while (t--) { scanf( %lld , &n); ...
#include <bits/stdc++.h> using namespace std; constexpr long long INF = 2e18; constexpr long long MOD = 1e9 + 7; constexpr long long MAXN = 2e5 + 3; struct Matrix { static constexpr long long MOD = 1e9 + 7; static constexpr long long MAXN = 200, MAXM = 200; array<array<long long, MAXM>, MAXN> mat ...
#include <bits/stdc++.h> using namespace std; inline int Read() { int x(0); char c = getchar(); while (c < 0 || c > 9 ) c = getchar(); while (c >= 0 && c <= 9 ) x = (x << 3) + (x << 1) + c - 0 , c = getchar(); return x; } const int maxn = 1e5 + 9, mod = 998244353, maxm = 409; int n,...
#include <bits/stdc++.h> using namespace std; template <class T> void REV(T *a, int n) { reverse(a + 1, a + 1 + n); } template <class T> void SRT(T *a, int n) { sort(a + 1, a + 1 + n); } template <class T> int UNI(T *a, int n) { sort(a + 1, a + 1 + n); return unique(a + 1, a + 1 + n) -...
#include <bits/stdc++.h> using namespace std; int main() { long long int k; cin >> k; if (k > 36) cout << -1; else { for (int i = 0; i < k / 2; i++) cout << 8; if (k % 2) cout << 4; } }
#include <bits/stdc++.h> using namespace std; char N[(int)1e6 + 5], B[(int)1e6 + 5]; long long n, b, c; inline long long euler(long long n) { long long ans = n; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { ans = ans / i * (i - 1); while (n % i == 0) n /= i; } } ...
#include <bits/stdc++.h> double dp[100111], ans; int sz[100111], ds[100111]; std::list<int> edge[100111]; int i, j, n; void dfs(int now, int fa) { ds[now] = ds[fa] + 1; ans += 1 / (double)ds[now]; for (std::list<int>::const_iterator it(edge[now].begin()); it != edge[now].end(); ++it) ...
#include <bits/stdc++.h> using namespace std; int n, m, jj = 0; long long a[22], b[22]; long long dp[10000][1000]; long long memo(int idx, int cnt) { long long res = (long long)(1e18); if (idx == 2 * n - 1) { if (cnt == 1) res = b[((idx + jj) % n)]; return dp[idx][cnt] = res; } if ...
#include <bits/stdc++.h> using namespace std; vector<int> leftSub[1000005]; vector<int> rightSub[1000005]; int leftSon[1000005], rightSon[1000005]; int maxVal[1000005], minVal[1000005]; int leftMax[1000005]; bool vis[1000005]; bool possible; int n, c, a, b; string d; int cnt; void findDfs(int u)...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MOD = 998244353; void add(int& a, int b) { a += b; if (a >= MOD) a -= MOD; } int mul(int a, int b) { return ll(a) * b % MOD; } int modinv(int a, int m = MOD) { return a == 1 ? a : m - modinv(m % a, a) * ll(m) / a; ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ); using namespace std; const int MAX_ARRAY = 100005; string num2str(int i) { stringstream ss; ss << i; return ss.str(); } std::vector<std::string> split(std::string str, std::string pattern) { std::string::size_type pos; ...
#include <bits/stdc++.h> using namespace std; void start() {} int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long a, b; cin >> a >> b; if (a < b) swap(a, b); b = 2 * b; if (b >= a) cout << b * b ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string str; cin >> str; long long count = 0, count2 = 0; for (int i = 0; i < n; i++) { if (str[i] == < ) { count++; } else { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char a[n][7]; for (int i = 0; i < n; i++) { for (int j = 0; j < 7; j++) cin >> a[i][j]; } int ans = 0, ct = 0; for (int j = 0; j < 7; j++) { ct = 0; for (int i = 0; i < n; i++) { if (a[i...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; inline long long read() { long long x = 0, w = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) w = -1; c = getchar(); } while (c <= 9 && c >= 0 ) { x = (x << 1) + (x << 3) + c - 0 ; ...
#include <bits/stdc++.h> using namespace std; mt19937 rng(time(0)); uniform_int_distribution<int> uid(-1e9, 1e9); vector<int> g[100002]; int d[100002], u[100002], k; long long res, w[505], v[505]; int find(int x, int px, int sz) { for (auto& i : g[x]) if (i != px && !u[i] && d[i] > sz / 2) retur...
#include <bits/stdc++.h> using namespace std; int n, len, dp[200][100][2][2]; char x[200]; const int unDEF = 10000, INF = 1000000000; int solve(int idx, int left, int dir, int isM) { if (idx < 0) { if (left + dir == 0) { return 0; } if (isM) { return -INF; } r...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; unsigned int a[100000 + 5], b[100000 + 5], p; int f(int x) { return ~((x - 1) >> 31); } int main() { int n, t, l, r, k, i; long long ans = 0; for (scanf( %d , &n); n--;) { scanf( %d%d%d , &t...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << endl; err(++it, args...); } long long powm(long long a, long l...
#include <bits/stdc++.h> long long a[100001]; int main() { int n; scanf( %d , &n); int i, j, k; int m = n / 2; for (i = 1; i < n; i += 2) { scanf( %I64d , &a[i]); } long long cur = 100000000000001LL; for (i = n - 1; i >= 1; i -= 2) { bool ok = false; for (k = 2 - a[...
#include <bits/stdc++.h> const int N = 2001000; int a[N], l[N], r[N], c[N]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); int t1 = 0, t2 = -1; for (int i = 1; i <= n; i++) if (a[i] > t2) t2 = a[i], t1 = i; for (int i = 1; i < t1; i++) a[n + i] ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } return x * f;...
#include <bits/stdc++.h> using namespace std; inline int BITS(long long __a) { short int __c = 0; __a <<= 1; while (__a) __c += ((__a >>= 1) & 1); return __c; } inline bool prime(int n) { for (int i = 3; i * i <= n; i += 2) if (n % i == 0) return false; return true; } set<int> ...
#include <bits/stdc++.h> using namespace std; char s[100100]; char s1[111]; char s2[110]; int main() { scanf( %s%s%s , s, s1, s2); int flag1, flag2; int n = strlen(s); int n1 = strlen(s1); int n2 = strlen(s2); flag1 = flag2 = 0; int i, j; for (i = 0; i < n; i++) { for (j ...
#include <bits/stdc++.h> using namespace std; int main() { int n, d, sum = 0; cin >> n >> d; vector<pair<int, int> > ins(n); for (int i = 0; i < n; i++) { cin >> ins[i].first; ins[i].second = i + 1; } sort(ins.begin(), ins.end()); int i = 0; while (i < n and ((sum + ins[i...
#include <bits/stdc++.h> using namespace std; double dp[1050000]; int n, k; double p[25]; double ans[25]; int main() { memset(dp, 0, sizeof(dp)); memset(ans, 0, sizeof(ans)); scanf( %d%d , &n, &k); for (int i = 0; i < n; i++) scanf( %lf , p + i); dp[0] = 1; int st = (1 << n); for...
#include <bits/stdc++.h> using namespace std; set<string> st; const int N = 1e6 + 5; int a[3000]; int c1 = 0, c2; string s, c; int na, nb, m, ans = 0, mx = 0; int main() { int n, a, b; cin >> n; while (n--) { cin >> a >> b; if (a == 2) { cout << b / a << endl; con...
#include <bits/stdc++.h> using namespace std; set<long long> myset; int base; int N; long long A[100005]; map<long long, int> Map; int ANS[600000]; int T[1200000]; int Lo[300000]; int ql, qu; int P[300000]; void update(int ind) { ind += base; T[ind] = ind - base; while (1) { in...
#include <bits/stdc++.h> using namespace std; int main() { int n, x1, y1, x2, y2; long long int answ = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> x1 >> y1 >> x2 >> y2; answ += (x2 - x1 + 1) * (y2 - y1 + 1); } cout << answ; return 0; }