func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int ar[] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; int main() { int n, a, sum = 1; cin >> n; for (int i = 0; i < 2; i++) { a = n % 10; sum *= ar[a]; n /= 10; } cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { srand(time(NULL)); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.setf(ios::fixed); cout.precision(0); long long n; cin >> n; string s; char y = a ; while (n != 0) { s.push_back(y); int t = 1; ...
#include <bits/stdc++.h> using namespace std; inline int ckmax(int &a, int b) { return a < b ? a = b, 1 : 0; } inline int ckmin(int &a, int b) { return a > b ? a = b, 1 : 0; } char s[500100], t[500100]; int n, m, wt, p[500100], sta[500100], pre[500100], nex[500100], top; int main() { scanf( %d%d%d , &n,...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; map<int, int> mp; for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } int mx = 0, p = 0; for (auto it = mp.begin(); it...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; deque<int> dq; map<int, int> freq; for (int i = 0; i < n; i++) { int x; cin >> x; if (freq[x] == 0) { if ((int)dq.size() < k) dq.push_front(x); else { dq.push...
#include <bits/stdc++.h> using namespace std; using ll = unsigned long long; using pii = pair<int, int>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); } template <class T> void DBG(T...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e6 + 5; long long magic_const = 3e18; const int MAX_L = 3; class segment_tree { int n; vector<long long> val; vector<long long> pushes; int l, r; long long ans, adding_value; void push(int v, bool is_leaf) { val[v] ...
#include <bits/stdc++.h> using namespace std; const long long maxx = 1e6 + 7; const long long maxn = 1e6 + 7; const long long mod = 998244353; const long long maxs = 500000 + 7; const long long maxm = 400000 + 7; const long long maxk = 1008 + 7; const long long maxw = 100 + 7; const long long maxh = 1...
#include <bits/stdc++.h> const int mn = 10100, mm = 5010000; char st[mm], ans[mm]; int f[mm], s[mm], L[mn], R[mn]; int n, m, K, i, j, d, len, now; void del(int p) { for (; p <= m; p += p & (-p)) --s[p]; } int query(int v) { int i = 1, l = m >> 1; for (; l; l >>= 1) if (s[i + l - 1] < v) ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; const int INF = 1e8; void boost() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(NULL); } long long n, a[N], b[N], sum, sum2, ans, dp[N], t; string s; int main() { boost(); cin >> t; for (int l = 1; l <= t...
#include <bits/stdc++.h> using namespace std; const double PI = 3.1415926535897932384626433; int MOD = 0; int pl(int v1, int v2) { int res = v1 + v2; if (res < 0) res += MOD; else if (res >= MOD) res -= MOD; return res; } int mul(const int v1, const int v2) { return (int)((1LL * ...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; vector<int> get_sb(int num) { vector<int> res; while (num) { res.push_back(num % 10); num /= 10; } return res; } string get_a(vector<int> kol, string sub) { string reserve = 9 ; ++reserve[0]; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, k; cin >> n >> k; int t[n]; for (int i = 0; i < n; i++) cin >> t[i]; sort(t, t + n); if (k == n) cout << t[n - 1] << endl; else if (k == 0) { if (t[0] - 1 == 0) cout << ...
#include <bits/stdc++.h> using namespace std; int absol(int x); int main() { int n, C, left, right, top, bot; char c; int xy[10][2] = {{1, 3}, {0, 0}, {1, 0}, {2, 0}, {0, 1}, {1, 1}, {2, 1}, {0, 2}, {1, 2}, {2, 2}}; cin >> n; cin >> c; C = c; C -= 48; left = C;...
#include <bits/stdc++.h> int const MAX = 1e5 + 5; using namespace std; bool check(long long m, long long ai, long long di, long long hm, long long am, long long dm) { long long retval; if (hm % (ai - dm) == 0) retval = m - (((hm) / (ai - dm))) * (am - (di)); else retval = m - ...
#include <bits/stdc++.h> using namespace std; void solve(long long int input) { long long int n; cin >> n; double a[n], b[n]; for (long long int i = 0; i < n; i++) cin >> a[i]; for (long long int i = 0; i < n; i++) cin >> b[i]; map<long double, long long int> mp; long long int ans = 0; ...
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, a, b, k, pr[N], seq[N]; char s[200005]; int main() { scanf( %d%d%d%d , &n, &a, &b, &k); scanf( %s , s + 1); int len = strlen(s + 1), lst = 0, cur = 0; for (int i = 1; i <= len; ++i) { if (s[i] == 1 ) { cu...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; double a[maxn], st[maxn]; int len[maxn]; int main() { int n, x; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &x); a[i] = x; } int p = 0; for (int i = 1; i <= n; i++) { st[++p] = a[i...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long a, b; cin >> a >> b; double d = ((pow(b, 2)) - (pow(a, 2))) / (2 * a); cout << fixed << setprecision(12) << abs(d); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline T SQR(T x) { return x * x; } template <class T> inline string TOSTR(const T &x) { stringstream ss; ss << x; return ss.str(); } template <class T> void UPDATE_MIN(T &x, T y) { if (y < x) { x = y; } }...
#include <bits/stdc++.h> using namespace std; #define f first #define s second #define ll long long #define ld long double #define pii pair <int,int> #define pll pair <ll,ll> #define pil pair <int,ll> #define pli pair <ll,int> #define pss pair <short,short> #define ull unsigned long long #define...
#include <bits/stdc++.h> using namespace std; const int MX = 300005; long long n, m, k; struct node { int id; long long pos; long long dir; } no[MX]; int now[MX]; int ans[MX]; bool cmp(node a, node b) { if (a.pos < b.pos) return true; return false; } int main() { char ss[5]; ...
#include <bits/stdc++.h> using namespace std; int n; const int MAXN = 200010; int B[MAXN], C[MAXN], a[MAXN]; long long b[MAXN], c[MAXN]; struct Node { int b, c, id; bool operator<(const Node ano) const { return b + c < ano.b + ano.c; } } opt[MAXN]; int cnt[MAXN]; bool check(int x) { int no...
#include <bits/stdc++.h> using namespace std; const int N = (1 << 18); const double PI = acos(-1.0); char s[N]; int lA, lB; int a[N], b[N]; int inB[110][N]; int S, B; struct cpx { double x, y; cpx(double p = 0, double q = 0) : x(p), y(q) {} cpx operator+(cpx &o) { return cpx(x + o.x, y + o...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a, b; cin >> n >> k >> a >> b; bool impossible = false; string s; int curGroup = (a > b) ? 0 : 1; int groupSize = 0; for (int i = 0; i < n; ++i) { if (curGroup) { if (!b--) { impossible = true; ...
#include <bits/stdc++.h> using namespace std; int v[3 * 100001]; int main() { int n; long long s = 0; cin >> n; for (int i = 1; i <= n; ++i) { cin >> v[i]; } sort(v + 1, v + n + 1); for (int i = 1; i <= n / 2; ++i) { s += (v[i] + v[n - i + 1]) * (v[i] + v[n - i + 1]); }...
#include <bits/stdc++.h> #pragma GCC target( sse4,avx ) struct Solution { int n; std::vector<std::vector<int>> graph; std::vector<std::vector<int>> matrix; int counter; std::vector<int> dirtyFlags; std::vector<double> maxProbs; double checkFirst(int a) { double res = 0; for (...
#include <bits/stdc++.h> using namespace std; set<string> f; int main() { int n; cin >> n; int ans = 0; for (int i = 0; i < n; ++i) { string s = ; while (1) { char c; cin >> c; if (isdigit(c)) s += c; if (((int)(s).size()) == 4) break; } sw...
#include <bits/stdc++.h> #pragma GCC optimize( O3 , unroll-all-loops ) #pragma GCC target( sse4.2 ) using namespace std; const long long kk = 1000; const long long ml = kk * kk; const long long mod = ml * kk + 7; const long long inf = ml * ml * ml + 7; mt19937 rng(chrono::steady_clock::now().time_since...
#include <bits/stdc++.h> using namespace std; long long int n, m, k, w; vector<vector<vector<char>>> mp; struct dsu { vector<long long int> p, sz; dsu(long long int n) { p.resize(n); sz.resize(n, 1); for (long long int i = 0; i < n; i++) p[i] = i; } long long int getRoot(long l...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5000 + 10, MOD = 1000000007; vector<pair<int, int> > lis[MAXN * 2]; pair<int, int> p[MAXN]; int n, f[MAXN], cnt; bool b[MAXN]; int dis(const pair<int, int> &a, const pair<int, int> &b) { return abs(a.first - b.first) + abs(a.second - b.sec...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:102400000,102400000 ) const int N = 1e5 + 10, M = 1024; int a[N], cnt[N], n, k, x; int main() { scanf( %d %d %d , &n, &k, &x); int ai; for (int i = 1; i <= n; i++) { scanf( %d , &ai); a[ai]++; } for (...
#include <bits/stdc++.h> using namespace std; const int N = 333333; vector<pair<int, int> > graph[N]; int vis[N], d[N]; bool has[N]; int n, m; int dfs(int u) { vis[u] = true; int cnt = 0; for (auto e : graph[u]) { if (!vis[e.first]) { if (dfs(e.first)) { has[e.second] =...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } int sol = 0; for (int i = 1; i <= n; i++) { int cnt = 1; for (int j = i - 1; j >= 1; j--) { if (a[j] > a[j + 1]) ...
#include <bits/stdc++.h> using namespace std; int n, p[1000010], cur[1000010 * 2]; int main() { long long ans = 0, sum = 0; int l = 0, r = 0, temp = 0; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &p[i]); for (int i = 1; i <= n; i++) { sum += abs(p[i] - i); if (p[i] >=...
#include <bits/stdc++.h> using namespace std; int main() { int n, w, one = 0, two = 0, sum = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> w; if (w == 100) { one++; } else { two++; } sum += w; } if (two % 2 == 0) { if (one % 2 == 0) { ...
#include <bits/stdc++.h> using namespace std; const int INF = 2000 * 1000 * 1000; int calc(int sweet, string str) { int mx = -1; for (register int i = (0); i < (int)(((int)(str).size())); ++i) if (sweet > 0 && str[i] == H ) { mx = max(mx, i); str[i] = . ; sweet--; } ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e17; int n, s, e, nxt[5001]; long long x[5001], a[5001], b[5001], c[5001], d[5001]; long long dp[5001][5001]; inline long long dis(int s, int e) { return (s < e) ? d[s] + a[e] : c[s] + b[e]; } int main() { ios_base::sync_with_s...
#include <bits/stdc++.h> using namespace std; int N, M, P, Q; int A[101], B[101]; int w[202][202]; bool V[202]; vector<int> path; bool dfs(int n) { path.push_back(n); V[n] = 1; if (n == N + N + 1) return 1; for (int i = 0; i <= N + N + 1; i++) if (!V[i] && w[n][i]) { if (dfs(...
#include <bits/stdc++.h> using namespace std; const long double PI = 4 * atan(1); const int32_t MOD = 1e9 + 7; int power(int x, unsigned int y) { int temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp % MOD; else return x * temp % MOD * temp % ...
#include <bits/stdc++.h> using namespace std; const int N = 111111; vector<int> g[N]; bool s[N], f[N], used[N], foo[N], bar[N]; int q[N], qb, qe; int main() { int n; cin >> n; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); ...
#include <bits/stdc++.h> using namespace std; int n, m; int d[200], f[200][200]; int c[200]; int dis[200][200]; long long fa[200]; int ans[200]; void floyed() { for (int k = 1; k <= n; ++k) for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) dis[i][j] = min(dis[i][j], d...
#include <bits/stdc++.h> constexpr auto Inf = 0X3F3F3F3F; using namespace std; namespace IO { inline long long read() { long long o = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c > / && c < : ) { o = o * 10 + ...
#include <bits/stdc++.h> using namespace std; int read() { char ch = getchar(); int x = 0, fl = 1; for (; !isdigit(ch); ch = getchar()) if (ch == - ) fl = -1; for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch - 0 ); return x * fl; } const int N = 300005; const long ...
#include <bits/stdc++.h> using namespace std; void O_o() { ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); } int main() { O_o(); int x, y; bool flag; vector<int> vec; cin >> x; y = x; while (x != 0) { vec.push_back(x % 10); x = ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e6 + 100; const long long MAXL = 21; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long x, r, l; cin >> x >> l >> r; long long ans = 0; long long a = 1; while (2 * a <= x) a = 2 *...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) #pragma warning(disable : 4786) using namespace std; int MIN(int a, int b) { return a < b ? a : b; } int MAX(int a, int b) { return a > b ? a : b; } int GCD(int a, int b) { while (b) b ^= a ^= b ^= a %= b; return a; } int LCM(in...
#include <bits/stdc++.h> using namespace std; const int Mod = 1e9 + 7; const int N = 1e3 + 100; const int M = 3e4 + 100; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; inline long long dpow(long long a, long long b) { long long r = 1, t = a; while (b) { if (b & 1) r =...
#include <bits/stdc++.h> using namespace std; long long int n, p, k; long long int cost[200010]; long long int price() { long long int dp[200010] = {0}; sort(cost, cost + n); long long int ans = 0; for (long long int i = 0; i < n; i++) { if (i < k - 1) { dp[i] = cost[i] + (i == 0 ?...
#include <bits/stdc++.h> using namespace std; int ans; int visited[1001]; int cc = 0; vector<int> arr[1001]; void dfs(int node) { visited[node]++; if (visited[node] == 2) { ans = node; return; } for (auto child : arr[node]) { if (visited[node] < 2) dfs(child); } } i...
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long pow(long long x, long long v) { if (v == 0) return 1LL; if (v % 2) return (x % MOD) * pow(x % MOD, v - 1) % MOD; return pow((x * x) % MOD, v / 2) % MOD; } int main() { int n; long long x, sum = 0, v, mx = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int t, n; cin >> t; while (t--) { cin >> n; vector<int> numbers(n); vector<int> trayectoria(n + 1); for (int &i : numbers) cin >> i; if (numbers[0] == 1) { cout << n + 1 << ; for (int i = 1; i < n...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; while (cin >> a >> b) { if (a == 0 && b == 0) cout << NO << endl; else { c = abs(a - b); if (c == 0 || c == 1) cout << YES << endl; else cout << NO << endl; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; int n, m, k, t, mx, mi, x, y, dx, dy, idx, cnt, tot, sum, res, flag, st; vector<int> e[maxn]; void dfs(int u, int pre, int dep, int op) { if (dep > mx) { mx = dep; ...
#include <bits/stdc++.h> int n; int length; int num[1000]; int main() { scanf( %d , &n); while (n--) { int max = 0; int mark = 0; scanf( %d , &length); for (int i = 1; i <= length; i++) { scanf( %d , &num[i]); if (num[i] > (i + mark)) { mark += num[i] - ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; vector<pair<int, pair<int, int> > > ans; int v[4][n]; for (int i = 0; i < 4; ++i) { for (int j = 0; j < n; ++j) { cin >> v[i][j]; } } for (int i = 1; ...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = 1; for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); if (f) x = -x; } template <typename F> i...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s.size() == 1 && (s[0] == A || s[0] == I || s[0] == M || s[0] == O || s[0] == T || s[0] == U || s[0] == V || s[0] == W || s[0] == X || s[0] == Y || s[0] == H )) { cout ...
#include <bits/stdc++.h> struct MinCostFlow { const long long INF1 = 1000000000LL; const long long INF2 = 100000000LL; struct edge { long long u, v; long long cap, cost; edge* rev; edge(const long long& uu, const long long& vv, const long long& _cap, const long long& _co...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; int n, m; const int maxN = 42; vector<int> g[maxN]; int deg[maxN]; bool ed[maxN][maxN]; long long f() { return (1LL << n); } const int maxK = 20; bool bad[(1 << maxK) + 10]; int from[(1 << maxK) + 10]; bool other_bad[(1 << ...
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)3e18; struct data { long long x, flag, id; int operator<(const data& d) const { return x < d.x; } } d[200010 << 2]; long long dp[200010 << 2][2], c[200010 << 2], s[200010 << 2], v[200010 << 2], nw, ans; long long _s...
#include <bits/stdc++.h> using namespace std; const long long maxn = 500002; const long long mod = 1000000000; const long double eps = 1e-9; const long long inf = ((1ll << 31ll) - 1ll); const long long INF = 2000000000000000000ll; const long double pi = acos(-1); long long qpow(long long b, long long e)...
#include <bits/stdc++.h> using namespace std; inline long long read() { register char ch; while (!isdigit(ch = getchar())) ; register long long x = ch ^ 0 ; while (isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^ 0 ); return x; } vector<pair<long long, long long> > e[200005...
#include <bits/stdc++.h> const int t = 50; int f[t][t][t], g[t][t]; long long p[t]; int cnt; void mul(int c[t][t], int a[t][t], int b[t][t], int n) { int d[t][t]; memset(d, 0, sizeof d); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int k = 0; k < n; k++) d[i][k] ^= a[...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx ) using namespace std; namespace SimplexMethod { const long double EPS = 1.0E-12; vector<vector<long double>> a; vector<long double> b, c, res; vector<int> N, kt; int m; void pivot(int k, ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; int n; int main() { scanf( %d , &n); if (n <= 8) { int a = 2; int b = (n) / a; int c = (n) % a; for (int i = 1; i <= n;) { if (c > 0) { printf( %d , c); c--; i++; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n; int mxm[4 * maxn]; int get(int id, int L, int R, int l, int r, int x) { if (l >= r) return -1; if (L == l and R == r) { if (mxm[id] < x) return -1; if (L + 1 == R) return L; int mid = (L + R) >> 1; ...
#include <bits/stdc++.h> char ch; bool fs; void re(int& x) { while (ch = getchar(), ch < 33) ; if (ch == - ) fs = 1, x = 0; else fs = 0, x = ch - 48; while (ch = getchar(), ch > 33) x = x * 10 + ch - 48; if (fs) x = -x; } using namespace std; pair<int, int> d[62]; in...
#include <bits/stdc++.h> using namespace std; string a; int main() { cin >> a; cout << a; reverse(a.begin(), a.end()); cout << a << endl; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 + 7; int n, k; string second; string s2; string s1; int main() { cin >> n >> k; cin >> second; sort(second.begin(), second.end()); for (int i = 0; i < n; i++) { if (second[i] != second[i + 1]) { s2 += second[i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 207; int n, f[MAXN]; long long mmc_atual = 1; vector<int> folhas, Gr[MAXN]; bool in_cycle[MAXN], mrk[MAXN]; int marca_ciclo(int u) { if (in_cycle[u]) return 0; in_cycle[u] = true; return 1 + marca_ciclo(f[u]); } void dfsr(int u...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( unroll-loops ) using namespace std; using ll = long long; using db = long double; using ii = pair<int, int>; const int N = 1e5 + 5, LG = 17, MOD = 998244353; const int SQ = 225; const long double EPS = 1e-7; int n, m, a[N], b[...
#include <bits/stdc++.h> using namespace std; const int N = 200010, M = 7000010; int n, a[N], rt, tot; map<int, int> mp; int val[M]; vector<int> g[M]; int ans, ansx, ansy, S, T, cur, fa[M]; bool vis[M]; void dfs(int x, int fath, int dis, int *var) { vis[x] = true; if (x <= n && dis > cur) *var...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; while (n) { if (n % 10 != 1 && n % 100 != 14 && n % 1000 != 144) { cout << NO ; return 0; } n /= 10; } cout << YES ; return 0; }
#include <bits/stdc++.h> char s[200005]; int res[200005]; int ptr; int main() { int n, a, b, k; scanf( %d%d%d%d , &n, &a, &b, &k); scanf( %s , s); int cons = 0; int cnt = 0; for (int i = 0; i < n; i++) { if (s[i] == 0 ) cons++; if (s[i] == 1 ) { cnt += cons / b; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int prefix[N]; int main() { string s; int n, k; cin >> n >> k >> s; for (int i = int(1); i <= int(n); i++) prefix[i] = prefix[i - 1] + 1 - s[i - 1]; int ans = n + 1; for (int i = int(1); i <= int(n); i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, c = 0; cin >> n; int w = 1; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; if (n == 1) cout << First << endl; else { for (int i = 0; i < n; i++...
#include <bits/stdc++.h> using namespace std; const int sz = 1e3; int adjm[sz + 1][sz + 1]; vector<int> adjl[(int)(1e6 + 1)]; vector<bool> vis((int)1e6 + 1, 0); void init_adjm(int n) { for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) adjm[i][j] = 0; } } void bfs(int s, int n, in...
#include <bits/stdc++.h> using namespace std; int n, k, i, j, m, p, a[510]; double b[710000]; double calc(int x, int y, double a) { return (y - x) * a + x; } int main() { scanf( %d%d , &n, &k); m = 700000 / k; for (i = 1; i <= n; i++) { double ans = 0; for (j = 0; j <= k; j++) scanf( %...
#include <bits/stdc++.h> using namespace std; int x[100], y[100]; int l1, l2, l3, l4, s, f[10], n; int len(int g1, int g2) { int res = (((x[g1] - x[g2]) * (x[g1] - x[g2]) + (y[g1] - y[g2]) * (y[g1] - y[g2]))); return res; } bool prr(int kk1, int kk2, int kk3, int kk4) { int ii, jj = 0, a...
#include <bits/stdc++.h> using namespace std; int n, p; struct Node { int i, d; } d[100005]; vector<int> v[100005 << 1]; bool cmp(Node x, Node y) { return x.d > y.d; } int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &d[i].d); d[i].i = 2 * i; } sort(...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000000 + 7; const long long int N = 10000000 + 6; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int a, b; cin >> a >> b; vector<pair<int, int> > bb, aa; for (int i = 1; i < 1000; i++) { ...
#include <bits/stdc++.h> using namespace std; struct Info { int h, l, r; vector<int> A; Info(vector<int> _A, int _h, int _l, int _r) : A(_A), h(_h), l(_l), r(_r) {} }; int FindMaxGoodSleep(int idx, int time, vector<vector<int>>& memo, const Info& input) { if (idx >= input....
#include <bits/stdc++.h> using namespace std; vector<int> G[100009]; map<string, int> pr; struct comp { bool operator()(const pair<string, int>& l, const pair<string, int>& r) { return l.second > r.second; } }; int main() { pr[ captain ] = 1; pr[ man ] = 2; pr[ child ] = 3; pr[...
#include <bits/stdc++.h> using namespace std; vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.emplace_back(x); return move(v); } void err(vector<string>::iterator it) {} template <typename T, typename... Args> vo...
#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 type(string a) { if (a == S ) return 1; if (a == M ) return 2; if (a == L ) return 3; if (a == XL ) r...
#include <bits/stdc++.h> using namespace std; using ll = long long; int t, n, inp[3], cnt[100010]; map<pair<int, int>, vector<pair<int, int>>> el; int root; vector<int> qans; vector<int> neigh[100010]; void solve() { cin >> n; el.clear(); for (int i = 1; i <= n; ++i) cnt[i] = 0, neigh[i].cle...
#include <bits/stdc++.h> using namespace std; template <class T> inline T gcd(T a, T b) { if (a < 0) return gcd(-a, b); if (b < 0) return gcd(a, -b); return (b == 0) ? a : gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { if (a < 0) return lcm(-a, b); if (b < 0) return lcm(a, ...
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 1000 + 10; long long int a[N], mm[N], visited[N], anss[N], ans; int n; vector <int> e[N]; void dfs(int v){ visited[v] = 1; if (e[v].size() == 1 and v != 1){ anss[v] = 1; return; } vector <int> vec; for (auto u...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <typename T> T pow(T a, T b, long long m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; ...
#include <bits/stdc++.h> const int maxn = 1010; int n, m, K, N; int a[maxn][maxn]; char row[maxn][maxn], col[maxn][maxn]; void Read() { int i; scanf( %d%d%d , &n, &m, &K); for (i = 1; i <= 2 * n - 1; i++) if (i & 1) scanf( %s , row[i + 1 >> 1] + 1); else scanf( %s , col...
#include <bits/stdc++.h> using namespace std; int main() { long long H, L; scanf( %lld%lld , &H, &L); printf( %f , 0.5 * (L * L - H * H) / H); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n < k || (n > 1 && k == 1)) { cout << -1 << endl; return 0; } if (n <= 2) { n == 1 ? cout << a << endl : cout << ab << endl; return 0; } char *str = new char[n + 1]; st...
#include <bits/stdc++.h> using namespace std; int n, k, a, b, c, d, now, f[1001]; bool jud[1001]; int main() { cin.sync_with_stdio(false); cin >> n >> k; cin >> a >> b >> c >> d; if (k < n + 1 || n == 4) { cout << -1 << endl; return 0; } f[1] = a; f[2] = c; f[n - 1] =...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 50; const long long mod = 1e9 + 7; const long long INF = 1e18; long long dx[] = {-1, 0, 1, 0}; long long dy[] = {0, 1, 0, -1}; bool compare(const pair<long long, long long>& i, const pair<long long, long long>& j) { ...
#include <bits/stdc++.h> using namespace std; long long b, a, r; int k; int d0[360360 + 5], d1[360360 + 5]; void sim() { assert(a <= b); while (b > a) { long long w = b - 1; for (int i = 2, ThxDem = k + 1; i < ThxDem; ++i) if (b / i * i >= a) w = min(w, b / i * i); b = w; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int songs = n + m - 1; cout << songs << endl; for (int i = 1; i <= n; i++) { cout << i << << 1 << endl; } for (int i = 2; i <= m; i++) { cout << 1 << << i << endl; } return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); while (t--) { int a, b, c; int d, e, f; scanf( %d%d%d , &a, &b, &c); scanf( %d%d%d , &d, &e, &f); int sum = 0; sum = min(c, e) * 2; e = e - sum / 2; c = c - sum / 2; i...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int m = 0, c = 0; while (t--) { int a, b; cin >> a >> b; if (a > b) m++; else if (a < b) c++; else { m++; c++; } } if (m > c) cout << Mishka ...
#include <bits/stdc++.h> using namespace std; const int N = (int)6e4 + 2; int n; map<string, int> mp; vector<pair<string, int>> v; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; string str; for (int i = 0; i < n; ++i) { cin >> str; mp[str] = i; } ...