func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); double n, m; char ch; cin >> n >> ch >> m; if (n >= 12) n -= 12; double ans1, ans2; ans2 = 6 * m; ans1 = n * 30 + 0.5 * m; cout << ans1 << << ans2 << endl; }
#include <bits/stdc++.h> using namespace std; long long getInt() { long long ret; char tmpc; bool sign = 0; while (tmpc = getchar(), !isdigit(tmpc)) sign = (tmpc == - ); ret = tmpc - 0 ; while (tmpc = getchar(), isdigit(tmpc)) ret = ret * 10 + tmpc - 0 ; if (sign) ret *= -1; retur...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, f, a, b; vector<pair<long long int, long long int> > v; cin >> n >> f; int i; for (i = 0; i < n; i++) { cin >> a >> b; v.push_back(make_pair(a, b)); } long long int ans = 0; vector<long long int> ...
#include <bits/stdc++.h> using ll = long long; int n, a, v[10005]; ll d[1000005], ans; char s[10005]; int main() { scanf( %d , &a); scanf( %s , s + 1); n = std::strlen(s + 1); int lim = n * 10; for (int i = 1; i <= n; ++i) v[i] = v[i - 1] + s[i] - 0 ; for (int l = 1; l <= n; ++l) ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const long long int MOD = 1e9 + 7; const long long int INV2 = 500000004; int A[N][4]; int main(int argc, char const *argv[]) { cin.sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; int v = 1; for (int i = 1; ...
#include <bits/stdc++.h> using namespace std; vector<string> split(const string& s, const string& delim = ) { vector<string> res; string t; for (int i = 0; i != s.size(); i++) { if (delim.find(s[i]) != string::npos) { if (!t.empty()) { res.push_back(t); t = ; ...
#include <bits/stdc++.h> using namespace std; long double s, a, b, c; int main() { cin >> s >> a >> b >> c; if (a + b + c == 0) { cout << 0 << << 0 << << 0 << endl; return 0; } long double x = s * a / (a + b + c); long double y = s * b / (a + b + c); long double z = s *...
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; typedef long double ld; typedef vector<ll> vl; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<vector<ll>> vvl; typedef vector<ll, vector<ll>> vll; #define ln n #define mp make_pair #defin...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int v[maxn], b[maxn]; int n, k; long long base, sum; int cmp(const int &i, const int &j) { return i > j; } int main() { while (scanf( %d %d , &n, &k) != EOF) { scanf( %I64d , &base); sum = 0; for (int i = 0; i < n...
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { int i, z; while (y != 0) { z = x % y; x = y; y = z; } return x; } int a[110]; int b[110]; int main() { int n, m, i, j, k, count = 0, s = 0; scanf( %d%d , &n, &m); for (i = 0; i <= n; i++) scan...
#include <bits/stdc++.h> using namespace std; long long pw(long long base, long long e) { return e ? pw(base * base, e / 2) * (e % 2 ? base : 1) : 1; } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long to_int(string s) { long long ret = 0; for (int i = 0; i <= s.s...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const long long mod = 1e9 + 7; const long long N = 2e5 + 5, K = 105; const int si = (1 << 20); const long long add = 1e4; const long long M = 100 + 5; const double INFdb = 1e10; int t; int n; vector<int> a[N]; priority_que...
#include <bits/stdc++.h> using namespace std; int n, m; int l[100500]; int r[100500]; int val[100500]; int t[400500]; int t2[400500]; int mas[100500]; int INF = 0; void build(int v, int tl, int tr) { if (tl == tr) t[v] = 0; else { int mid = (tl + tr) >> 1; build(v << 1, tl,...
#include <bits/stdc++.h> using namespace std; int main() { long long n, d, f; cin >> n; if (n % 3 == 2) d = n / 3 + 1; else d = n / 3; f = d / 12; d = d % 12; cout << f << << d << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { x = 0; char c = getchar(), f = 0; for (; c < 0 || c > 9 ; c = getchar()) if (c == - ) f = 1; for (; c >= 0 && c <= 9 ; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -...
#include <bits/stdc++.h> const int M = 1000005; long long f[M]; int A[M]; int n; int Min(int a, int b) { return a < b ? a : b; } int Max(int a, int b) { return a < b ? b : a; } int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d , A + i); long long ans = 0; A[0] = 1; f...
#include <bits/stdc++.h> using namespace std; const int N = 2000; vector<array<int, 2>> que; int degree[N][N], n, m; string grid[N]; bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m && grid[i][j] == . ; } void update(int i, int j) { if (i >= 0 && i < n && j >= 0 && j < m) { ...
#include <bits/stdc++.h> using namespace std; set<string> st; set<string>::iterator it1; vector<int> dp2(20000, 0), dp3(20000, 0); void solve(string s, int i, string prev) { if (i < 1) return; if (i == 1) { string a = s.substr(i - 1, 2); if (a != prev) st.insert(a); else ...
#include <bits/stdc++.h> using namespace std; int n, i, X[200005], poz, nr0; long long A[200005], B[200005], val, t; int main() { ios::sync_with_stdio(false); cin >> n >> t; for (i = 1; i <= n; i++) cin >> A[i]; for (i = 1; i <= n; i++) { cin >> X[i]; if (X[i] < X[i - 1]) { c...
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e5 + 22; vector<vector<int> > cr; int N, M; vector<vector<int> > qq; int A[MAXN], prv[MAXN], nxt[MAXN], lst[MAXN]; struct Fenwick { int n; vector<long long> t, w; void init(int _n) { n = _n; t.resize(n, 0); ...
#include <bits/stdc++.h> using namespace std; int N, A; vector<int> X; int main(void) { cin.sync_with_stdio(0); cin >> N; int Curr = 0, __Cnt = 0; for (int i = 0; i < N; i++) { cin >> A; if (A < 0) { if (__Cnt == 2) { __Cnt = 0; X.push_back(Curr); ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, p, q, count = 0; cin >> n; vector<int> v; vector<int>::iterator it; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } for (int i = 0; i < n; i++) { p = i; for (int j = i + 1; j < n; j++) ...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > g(7); vector<int> vis(7); int cycles = 0; int nds = 0; bool allvis() { for (int i = 1; i <= 5; i++) if (!vis[i]) return false; return true; } bool dfs(int node, int par, int cnt) { if (vis[node]) { cycles++; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; while (TESTS--) { vector<pair<int, int>> v; int i, a, b, index = 0, dp[1000005] = {0}, ans = INT_MIN, n; cin >> n; for (long long int i = 0...
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX / 2, NINF = INT_MIN / 2; const long double PI = acos(-1.0); void prepareIO() { if (strlen( ) != 0) { freopen( .in , r , stdin); freopen( .out , w , stdout)...
#include <bits/stdc++.h> using namespace std; namespace output { void __(short x) { cout << x; } void __(unsigned x) { cout << x; } void __(int x) { cout << x; } void __(long long x) { cout << x; } void __(unsigned long long x) { cout << x; } void __(double x) { cout << x; } void __(long double x) { c...
#include <bits/stdc++.h> int main() { int a, i, b, k, temp; while (~scanf( %d , &a) && a >= 0) { temp = 0; while (a) { b = a; k = 0; while (b > 0) { if (k < b % 10) k = b % 10; b = b / 10; } a -= k; temp++; } printf( %...
#include <bits/stdc++.h> using namespace std; int delta[1000000], cnt[1000000]; int main() { int n, m, dx, dy; cin >> n >> m >> dx >> dy; int x = 0, y = 0; delta[0] = 0; for (int i = 1; i < n; ++i) { x = (x + dx) % n; y = (y + dy) % n; delta[x] = y; } for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000009; const double PI = acos(-1.0); const double eps = 1e-8; const int MAXN = 0; const int MAXM = 0; long long n, k, t, b, z; int main() { z = 1; int ans = 0; cin >> k >> b >> n >> t; while (z <= t) { ans++; ...
#include <bits/stdc++.h> using namespace std; int main() { long long l, i = 0, n, d, t; cin >> d >> n; if (d != 1 && n == 0) { cout << No solution n ; return 0; } cout << n; for (t = 1; t <= d - 1; t++) cout << 0; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b, c, d; int n; cin >> a >> b >> c >> d >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } cout << YES n ; int row = max(b, d); ...
#include <bits/stdc++.h> using namespace std; int a[100100], q[1000000], ql, qr, m[100100][2]; bool edge(int i, int j) { return m[i][0] == j || m[i][1] == j; } void add(int i, int j) { if (m[i][0] == -1) m[i][0] = j; else m[i][1] = j; } int main() { int i, j, k, n, l, L, t, x = 1; ...
#include <bits/stdc++.h> using namespace std; double dp[110][110][110] = {0}; double c[110][110] = {0}; int a[110], n, m; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= m; ++i) scanf( %d , &a[i]); for (int i = 0; i <= n + m; ++i) c[i][0] = 1; for (int i = 1; i <= n + m; ++i) fo...
#pragma GCC target ( avx2 ) #pragma GCC optimize ( O3 ) #pragma GCC optimize ( unroll-loops ) #include<bits/stdc++.h> using namespace std; // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // int rnd(int x, int y) {return (rng() % (y-x +1)) + x;}; #define ll long long #def...
#include <bits/stdc++.h> const double eps = (1e-9); using namespace std; int dcmp(long double a, long double b) { return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1; } int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; } int setBit1(int num, int idx) { return num | (1 << idx); } long long s...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long f[705][705][2][2], digit[705], num, ans; long long quick_pow(long long a, long long x) { long long ans = 1; while (x) { if (x & 1) ans = ans * a % MOD; a = a * a % MOD; x >>= 1; } return ans;...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; pair<long long, long long> ps[300010]; long long x; int main() { cin >> x; if (x == 1) { puts( 1 n1 1 ); return 0; } ps[0].first = 1, ps[0].second = x; bool f1 = 0; long long c = 2, f2 = 0; int t = 1...
#include <bits/stdc++.h> using namespace std; int n, l, k, i, p[256], a[256], j, w; double f[201][512][201], aa; int main() { scanf( %d%d%d , &n, &l, &k); k = min(k, n); for (i = 0; i < n; ++i) scanf( %d , p + i); for (i = 0; i < n; ++i) scanf( %d , a + i); f[0][k + 256][0] = 1; for (i =...
#include <bits/stdc++.h> using namespace std; long long a[20]; long long b[20]; int getbit(long long x) { int ret = 0; while (x) { x /= 10; ++ret; } return ret; } int main() { a[1] = 9; b[1] = 9; for (int i = 2; i <= 18; ++i) b[i] = b[i - 1] * 10 + 9; for (int i =...
#include <bits/stdc++.h> using namespace std; const int MAX = 514; int mat[MAX][MAX]; int aib[MAX][MAX]; int n, m; int dx[] = {1, 0}; int dy[] = {0, 1}; inline int inside(int x, int y) { return x <= n and y <= m and x >= 1 and y >= 1; } int jos[MAX][MAX]; int dreapta[MAX][MAX]; int main() { ...
#include <bits/stdc++.h> using namespace std; vector<long long> adj[205]; bool vis[205]; long long dp[205]; void dfs(long long v) { vis[v] = true; for (long long first : adj[v]) { if (!vis[first]) { dfs(first); dp[v] = max(dp[first] + 1, dp[v]); } } } signed main() ...
#include <bits/stdc++.h> int main() { long long a, b; scanf( %I64d %I64d , &a, &b); printf( %I64d n , (6LL * a - 1LL) * b); for (long long i = 1; i <= a; i++) { printf( %I64d %I64d %I64d %I64d n , (6LL * i - 5LL) * b, (6LL * i - 4LL) * b, (6LL * i - 3LL) * b, (6LL * i - 1LL) * b); ...
#include <bits/stdc++.h> using namespace std; int main() { int n; double x, r1 = 0, p1 = 0, p2 = 999999999999, a, b; cin >> n; while (n--) { cin >> x; r1 = max(r1, x); } cin >> n; while (n--) { cin >> x; p1 = max(p1, x); } cin >> n; while (n--) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { printf( %d , i); for (int j = 1; j < n; j++) { int tmp = (i + j) % n; if (tmp == 0) tmp = n; printf( %d , j * n + tmp); } printf( n ); }...
#include <bits/stdc++.h> using namespace std; struct caca { long long a, b; }; caca v[7005]; bool ok[7005]; bool cmp(caca a, caca b) { return a.a < b.a; } int main() { cin.tie(0)->sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; for (int i = 1; i <= n; i++) c...
#include <bits/stdc++.h> using namespace std; const int N = 100 + 10; int n, m; int SG[N << 1]; int main() { int T; for(scanf( %d , &T); T--; ) { scanf( %d%d , &n, &m); memset(SG, 0, (n + m) << 2); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j+...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); string s; cin >> s; long long int n = s.length(), i; stack<char> a; for (i = 0; i < n; i++) { if (a.empty()) a.push(s[i]); else { if (a.top() == s[i]) a.pop(); el...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int N = 122231; int n, k; vector<int> g[N]; int used[N]; int done[150][150][150]; int memo[150][150][150]; vector<int> sons[N]; int max_dep[N]; void dfs(int v) { used[v] = 1; max_dep[v] = 0; for (int i = 0; i < g[...
#include <bits/stdc++.h> const int INF = 1 << 29; using namespace std; void put(int i) { cout << (i == 0 ? 0 : i); exit(0); } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); ; int n, x, y; cin >> n; vector<int> v(n), sum(n); for (int i = 0; i < n; ++...
#include <bits/stdc++.h> using namespace std; const int N = 200010, M = 400010, mod = 1e9 + 7; int n, m, k; int h[N], e[M], ne[M], idx; int a[N], b[N], ans[N]; int ind[N], oud[N], cnt; bool stn[N], stm[M]; struct Edge { int a, b; } edge[M]; void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[...
#include <bits/stdc++.h> using namespace std; vector<int> g[200009]; int c[200009]; set<int> col[200009]; int main() { int n, m; scanf( %d , &n); scanf( %d , &m); int fans = 1e6; for (int i = 1; i <= n; i++) { scanf( %d , &c[i]); fans = min(fans, c[i]); } for (int i = 0...
#include <bits/stdc++.h> using namespace std; int n, k; int main() { cin >> n >> k; n = n % 6; if (n == 0) { cout << k; return 0; } if (k == 0) { if ((n == 1) || (n == 2)) { cout << 1; } if ((n == 3) || (n == 4)) { cout << 2; } if ((n =...
#include <bits/stdc++.h> using namespace std; using lli = long long int; using pii = pair<int, int>; using vi = vector<int>; using vb = vector<bool>; using vvi = vector<vector<int>>; using vlli = vector<long long int>; using vpii = vector<pair<int, int>>; const int N = 500005; mt19937 rng(chrono::st...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = pi / 180.0; int main() { int t; cin >> t; while (t--) { double n; cin >> n; double angle = 180.0 / n; double first = 1.0 / 2.0 / sin(angle / 2.0 * eps); double a1 = 180.0 / n ...
#include <bits/stdc++.h> using namespace std; int main() { set<char> c; int mul = 0; long long ans = 1; bool f = false; string s; cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == ? ) ans *= 10; else if (s[i] >= 65 && s[i] <= 74) c.insert(s[i]); ...
#include <bits/stdc++.h> using namespace std; bool f[1005]; vector<int> x[1005]; vector<int> y[1005]; int dx[4] = {1, 1, -1, -1}; int dy[4] = {1, -1, 1, -1}; int main() { for (int i = 1; i <= 1000; i++) { for (int j = 1; j <= 1000; j++) { int p = i * i + j * j; int u = (int)(sqrt...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int m, k, n, s; cin >> m >> k >> n >> s; int len = m - k * (n - 1); vector<int> a(m); for (auto& i : a) { cin >> i; } int bad = 0; vector<int> cnt(5e5 + 1); for (int...
#include <bits/stdc++.h> const int maxn = 5e5 + 5; const int logn = 21; const int lim = 2e1; const int maxq = 5e5 + 5; struct w { int l, r, id; friend bool operator<(w now, w oth) { return now.r < oth.r; } } qu[maxq]; int b[logn], p[logn]; void insert(int gave, int id) { for (int i = lim; i ...
#include <queue> #include <vector> #include <stdio.h> #include <stdlib.h> #define DEBUG printf( Passing [%s] in Line %d n , __FUNCTION__ , __LINE__) ; const int MAX_N = (1 << 11) + 10 , MAX_M = 10 + 5 , MAX_E = (1 << 22) + 10 , INF = 0x3f3f3f3f ; struct Link { int num , cap , cost ; Link *ne...
#include <bits/stdc++.h> using namespace std; template <class t> t mag(t a) { return a > 0 ? a : -a; } template <class T> T cdiv(T num, T den) { return (num / den) + (num % den > 0); } std::ifstream term( /dev/tty ); std::string tempstring; using ll = int_fast64_t; using ii = pair<ll, ll>;...
#include <bits/stdc++.h> using namespace std; char ch, B[1 << 20], *S = B, *T = B; long long aa, bb; long long rd() { while (ch = (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T) ? 0 : *S++), !(ch >= 0 && ch <= 9 ) && ch != - ) ; ...
#include <bits/stdc++.h> using namespace std; template <class T> void splitstr(const string &s, vector<T> &out) { istringstream in(s); out.clear(); copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out)); } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; ...
#include <bits/stdc++.h> int main() { int n, i, sum1, sum2, sum3; scanf( %d , &n); sum1 = 0; for (i = 0; i < n; i++) { int a; scanf( %d , &a); sum1 ^= a; } sum2 = 0; for (i = 0; i < n - 1; i++) { int b; scanf( %d , &b); sum2 ^= b; } sum3 = 0; ...
#include <bits/stdc++.h> using namespace std; const int inf = ~0U >> 1; const long long INF = ~0ULL >> 1; template <class T> inline void read(T &n) { char c; int flag = 1; for (c = getchar(); !(c >= 0 && c <= 9 || c == - ); c = getchar()) ; if (c == - ) flag = -1, n = 0; ...
#include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s; s = + s; int dem = 0; for (int i = 1; i <= s.size() - 1; i++) { if (s[i] < 97 && (s[i] - 0 ) % 2 != 0) dem++; else if (s[i] == a || s[i] == e || s[i] == i || s[i] == o || ...
#include <bits/stdc++.h> using namespace std; long long n, m, i, j, k, l; long long p[10004], ans; int main() { cin >> n >> m >> k; for (int i_ = 0; i_ < n; ++i_) cin >> p[i_]; ; ans = 0; if (n & 1) { if (m >= n / 2 + 1) { int mn = 2e9; for (i = 0; i < n; i += 2) mn = (...
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (x) return (gcd(y % x, x)); else return y; } int main() { int a, b, n; cin >> a >> b >> n; for (int i = 0; i < 1000; i++) { int x = gcd(a, n); if (x <= n) n -= x; else { cou...
#include <bits/stdc++.h> using namespace std; const int maxn = 1001010; int a[maxn]; void solve() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } int cnt = 0; for (int i = 0; i < n and a[i] >= i; ++i, ++cnt) { } for (int i = n - 1; i >= 0 and a[i] >= n - 1 -...
#include <bits/stdc++.h> using namespace std; int mark[201000 << 2]; int A[201000], n, m; struct ST { int val[2], las, len; void update(ST a, ST b) { b.val[1] -= a.las; b.val[0] += a.las; if (b.len & 1) b.las -= a.las; else b.las += a.las; val[0] = min(a.val...
#include <bits/stdc++.h> using namespace std; int main() { int n, a[101]; bool f = 1; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) f = 0; } if (f) puts( EASY ); else puts( HARD ); }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; const int inf = INT_MAX; const long long inff = 1e18; const long long mod = 1e9 + 7; long long n, p, k; long long a[maxn]; set<long long> s; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >>...
#include <bits/stdc++.h> using namespace std; long long mod = 1000 * 1000 * 1000 + 7; struct suffix_array { vector<int> sa; vector<int> lcp; vector<vector<int>> st; vector<int> log2; vector<int> c; string str; int n; void sort_pairs(vector<pair<pair<int, int>, int>>& a) { vec...
#include <bits/stdc++.h> typedef struct { int dollar; int cent; } money; money q[110]; int w[110]; int main() { int i, j, n, m, k = 0, l = 0; scanf( %d%d , &n, &m); for (i = 1; i <= n; i++) scanf( %d%d , &q[i].dollar, &q[i].cent); for (i = 1; i <= n; i++) { if (q[i].dollar < m ||...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int a[maxn]; set<int> S; long long qpow(long long a, long long b, long long mod) { long long ret = 1LL; while (b) { if (b & 1) ret = ret * a % mod; a = a * a % mod; b >>= 1; } return ret; } long long...
#include <bits/stdc++.h> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; int t = x * y / z; t = (int)sqrt(t); x = x / t; z = y / t; y = t; cout << 4 * x + 4 * z + 4 * y << n ; return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e17; const long long MOD = 1000000007; const long long MAX = 4000001; const long double eps = 1E-14; long long max(long long a, long long b) { if (a > b) { return a; } return b; } long long min(long long a, long long ...
#include <bits/stdc++.h> using namespace std; int main() { map<char, long long> mp1, mp2; mp1[ v ] = 1; mp1[ < ] = 2; mp1[ ^ ] = 3; mp1[ > ] = 4; mp2[ v ] = 1; mp2[ > ] = 2; mp2[ ^ ] = 3; mp2[ < ] = 4; char a, b; long long n; cin >> a >> b; cin >> n; n = n % 4...
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 10; int inf = (int)3e15; int mod = (int)1e9 + 7; int sz = 500, timer = 0; vector<int> gr[MAX]; int n, q, odd[MAX], even[MAX], h[MAX], tin[MAX], tout[MAX], mus[MAX], o[MAX]; vector<pair<int, int>> tmp; void calc(int v, int p) { tin...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream &operator>>(istream &is, vector<pair<T1, T2>> &v) { for (pair<T1, T2> &t : v) is >> t.first >> t.second; return is; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is...
#include <bits/stdc++.h> using namespace std; using ll = long long int; const int N = 2e5 + 10; int n, k, a[N], b[N], idx[N], kp = -1; char lc = a - 1, res[N]; int main() { ios_base::sync_with_stdio(false), cout.tie(nullptr), cin.tie(nullptr); cin >> n >> k; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; int k, n, root, par[100005]; vector<int> v[100005]; bool vis[100005], fr; void findroot(int u, int l) { int i; if (v[u].size() == 1 && l == 2 * k) { fr = true; root = u; } for (i = 0; i < v[u].size(); i++) { if (fr) break; i...
#include <bits/stdc++.h> using namespace std; inline int Gcd(int X, int Y) { return Y ? Gcd(Y, X % Y) : X; } int n; int inp[100001], p[100001], pc, g[100001], h[100001]; void init() { inp[0] = inp[1] = 1; g[1] = 1; for (int i = 2; i <= (100000); ++i) { if (!inp[i]) p[++pc] = i, g[i] = 2, h[i...
#include <bits/stdc++.h> using namespace std; struct T { int lz, sz; int v[2], t[2], f1[2], f2[2]; T(int x = 1) { lz = 0, sz = x; for (int i = 0; i < 2; i++) { v[i] = f1[i] = x; t[i] = f2[i] = 0; } } void upd() { for (int i = 0; i < 2; i++) t[i] ^= 1; ...
#include <bits/stdc++.h> using namespace std; int N, M, Q, Sum, op[100005], X[100005], Y[100005], Ans[100005], Mp[1005][1005], Lh[1005], Ln[1005]; int lnk[100005], nxt[100005], son[100005], tot; bool vis[100005], Num[1005]; inline int read() { int N = 0; char ch = getchar(); while (ch > 9 ...
#include <bits/stdc++.h> using namespace std; int K; long long p[21], a[21], aLeft[21]; long long N, Nq3; long long minArea = 3000000000000000000LL; long long ansA, ansB, ansC; long long curA; long long leftMul[21]; long long BCq, BC, nowBest; void dfs2(int cur, long long carry) { if (carry * le...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; string bus[7]; bus[0] = +------------------------+ ; bus[1] = |#.#.#.#.#.#.#.#.#.#.#.|D|) ; bus[2] = |#.#.#.#.#.#.#.#.#.#.#.|.| ; bus[3] = |#.......................| ; ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, string> > vc[100010]; vector<string> vc1[100010]; bool comp(pair<int, string> a, pair<int, string> b) { return a.first > b.first; } int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { string s; int a, ...
#include <bits/stdc++.h> using namespace std; const long long int maxn = 1e6 + 1; const long long int modn = 1e9 + 7; long long int T, len, num, gav, ver, x, maxi, sum, fir, sec, out, th; vector<long long int> vec[maxn]; bool is_use[maxn]; long long int all[maxn]; void dfs(long long int x) { is_use[...
#include <bits/stdc++.h> using namespace std; char a[10][10], b[10][10]; int n, ok[8]; struct matrix { char m[10][10]; } v[7]; int main() { cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> a[i][j]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) ci...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x = 0, y = 0; cin >> n >> m; x = max(m, n); for (int a = 0; a <= x; a++) { for (int b = 0; b <= x; b++) { if ((a * a) + b == n && (b * b) + a == m) { y++; } } } cout << y << endl; } ...
#include <bits/stdc++.h> using namespace std; long long POW(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a; if (b & 1) return (a * POW(a, b - 1)) % 1000000007; long long t = POW(a, b / 2); return (t * t) % 1000000007; } long long gcd(long long a, long long b) { return...
#include <bits/stdc++.h> #pragma GCC optimize O3,no-stack-protector using namespace std; const int MAXN = 1e5 + 7; vector<int> G[MAXN]; bool blo[MAXN]; short odw[MAXN]; bool tried[MAXN]; int n, m; bool dfs(int v) { if (blo[v] == true) return false; odw[v] = 1; for (auto w : G[v]) { ...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const int mod = 1e9 + 7; long long power(int a, long long b) { if (b == 0LL) return 1LL; long long tmp = power(a, b / 2); if (b & 1LL) return (tmp * tmp % mod) * a % mod; return tmp * tmp % mod; } int main() { ios:...
#include <bits/stdc++.h> using namespace std; vector<int> E[101000]; vector<long long> L[101000]; int n, Count[101000], Num[101000], cnt, par[101000], pp[18][101000]; long long Mod = 1000000007, D[101000], D2[101000], T[101000], T2[101000], pL[101000], DL[101000]; int Dep[101000]; void DFS(int...
#include <bits/stdc++.h> struct M { int p, b; }; struct F { const int p, i; int r, c; F(int p, int t, int i) : p(p), i(i), r(p + t), c(0) {} int t() { return r - p; } }; void solve(std::vector<F> &fs, std::vector<M> &ms) { std::multimap<int, int> ms_landed; std::map<int, F *> fs_ac...
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rnf(2106); const int N = 1000006, INF = 1000000009; int n; int a[N]; int dp[N][2]; int p[N][2]; void minh(int& x, int& px, int y, int u) { if (y < x) { x = y; px =...
#include <bits/stdc++.h> using namespace std; string text; map<int, int> cache; string to_bin(int v) { string res = ; for (int i = 128; i >= 1; i /= 2) { if (v - i >= 0) { res += 1 ; v -= i; } else { res += 0 ; } } return move(res); } int reverse...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, i, j, k, p, c, x, m, a, b, d, y, t; cin >> t; while (t--) { cin >> n >> a >> b >> c >> d; x = (a - b) * n; y = (a + b) * n; if ((y < (c - d)) || (x...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ] #pragma GCC optimize( Ofast ] #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ] using namespace std; long long int n, k; map<vector<pair<long long int, long long int>>, long long int> mp; vector<pair<long long...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > g; bool flag[100003]; int down[100003]; int max1[100003]; int max2[100003]; int up[100003]; void dfs(int x) { flag[x] = true; int i; for (i = 0; i < g[x].size(); i++) { if (!flag[g[x][i]]) { dfs(g[x][i]); ...