func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int x, y; while (scanf( %d %d , &x, &y) != EOF) { while (x >= 0 && y >= 0) { if (x >= 2 && y >= 2) { x -= 2; y -= 2; } else if (x == 1 && y >= 12) { x -= 1; y -= 12; } else if (x ...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10, LEN = 5e3 + 10, S = 51, INF = 1e18; long long f[N], l[N], r[N], sum[N]; long long lq[S], rq[S], sq[S], mq[S]; long long a[LEN], sx[LEN], mx[LEN]; int n, m; int main() { scanf( %d%d , &n, &m); memset(mq, -0x3f, sizeof mq); fo...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; cin >> a >> b; long long ships = 0; while (a != 0 && b != 0) { if (b > a) { ships += b / a; b = b % a; } else { ships += a / b; a = a % b; } } cout << ships << endl; ...
#include <bits/stdc++.h> using namespace std; int getsum(string st) { int rest = 0; for (int i = 0; i < st.size(); i++) { rest += st[i] - 0 ; } return rest; } string streverse(string st) { for (int i = 0; i < st.size() / 2; i++) { char tmp = st[i]; st[i] = st[st.size() - 1...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 10, N = 2e5 + 10, mod = 998244353, lg = 20, sq = 450; long long t, n, k, first[N], ans; inline long long power(long long x, long long y) { long long ret = 1; x %= mod; while (y) { if (y & 1) ret = (ret ...
#include <bits/stdc++.h> using namespace std; long long Deci(int arr[], int base, int n) { long long power = 1; long long num = 0; for (int i = n - 1; i >= 0; i--) { num += arr[i] * power; power = power * base; } return num; } int main() { int n, m, x, y; cin >> n >> x; ...
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long m) { if (y == 0) return 1; long long p = power(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } long long gcd(long long a, long long b) { if (a > b) swap(a, b); if...
#include <bits/stdc++.h> using namespace std; vector<string> v; int a[26] = {0}; int main() { int n, i, j, co = 0, F = -1; string s, s2; cin >> s; for (i = 0; i < s.size(); i++) { a[s[i] - a ] = 1; } cin >> s2 >> n; while (n--) { cin >> s; v.push_back(s); } ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, ans = 0, res = 0; cin >> n >> m; vector<pair<long long, long long>> v; set<pair<long long, long long>> s; for (int i = 0; i < n; i++) { long long p, q; cin >> p >> q; v.push_back(make_pair(q, p)); } ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long double E = 1e-9; char ccc; bool _minus = false; inline void read(int &n) { n = 0; _minus = false; while (true) { ccc = getchar(); if (ccc == || ccc == n ) break; if (ccc == - ) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; map<int, int> m; bool f = true; vector<int> v; while (n--) { int a; cin >> a; v.push_back(a)...
#include <bits/stdc++.h> using namespace std; struct data { int x, y; } v[300005]; inline bool cmp(data d1, data d2) { if (d1.x != d2.x) return d1.x < d2.x; return d1.y < d2.y; } inline bool cmp2(data d1, data d2) { return d1.y < d2.y; } int n; int main() { scanf( %d , &n); for (int ...
#include <bits/stdc++.h> using namespace std; using VI = vector<int>; using PII = pair<int, int>; using ll = long long; const int M = 1e9 + 7; const int N = 2010; VI d{1110111, 10010, 1011101, 1011011, 111010, 1101011, 1101111, 1010010, 1111111, 1111011}; int GetDiff(int x, int y) { return ...
#include <bits/stdc++.h> using namespace std; int n, m, s1, s2, t1, t2, l1, l2; vector<int> adj[3333]; int dist[3333][3333]; void bfs(int index) { queue<int> q; q.push(index); dist[index][index] = 0; while (!q.empty()) { int cur = q.front(); q.pop(); for (int to : adj[cur]) {...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const double INF = 1e20; const int N = 102; const int M = 1010; const int K = 10; int n; double C, T; const double Y = 1. / 0.9; pair<int, int> a[N]; double dp[N][M]; void read() { ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const long long N = 2e5 + 10; ; long long n, p[N], t[N], a[N], b[N], Ma[N], Mi[N], T; long long check(double m) { double M = 0.0; for (long long i = 1, j = 1; i <= n; i++) { while (j <= n && p[b[j]] < p[b[i]]) M = ...
#include <bits/stdc++.h> using namespace std; string A; bool isPalindrome(int left, int right) { while (left < right) { if (A[left] != A[right]) return false; left++, right--; } return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin...
#include <bits/stdc++.h> using namespace std; const long o = 1e6 + 5; long n, i, j, h, k, sl, g, kq = 0; long a[o], b[o], c[o], A, B; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; i = 0, j = 0, h = 0, k = 0; for (long p = 1; p <= n; p++) { ...
#include <bits/stdc++.h> using namespace std; long long ans; struct arr { int n; int v; } a[200001], b[200001]; int n, m, i, j; bool cmp(arr a, arr b) { return a.n < b.n; } int main() { cin >> n; for (i = 1; i <= n; i++) cin >> a[i].n >> a[i].v; cin >> m; for (i = 1; i <= m; i++) c...
#include <bits/stdc++.h> using namespace std; void fft(vector<complex<double> > &a, bool invert) { int n = a.size(), lg = 0; while (1 << lg < n) ++lg; assert(1 << lg == n); for (int i = 0; i < n; ++i) { int rev = 0; for (int j = 0; j < lg; ++j) if ((i & 1 << j) != 0) rev |= 1 << ...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e15; long long q[300005]; long long d[300005]; long long dd[300005]; struct st { long long x, w, id; }; vector<st> v[300005]; st t; vector<long long> ans; long long sum; long long n, m; long long x, y, z; inline void di...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(), cout.tie(); int n; cin >> n; int temp = 1; int a[] = {4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777}; for (int i = 0; i < 14; i++) { if (n % a[i] == 0) { cout <...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; const int INF = 0x3f3f3f3f; int dis[MAXN + 10], pos[MAXN + 10], f[MAXN + 10], Max, m, n; bool check(const int& x) { if (x >= dis[1] - 1) return true; if (2 * x < dis[1] - 1) return false; f[1] = 0; for (int i = 2; i <= n; i...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<pair<long long, long long> > v(n); for (int i = 0; i < n; i++) { int a; cin >> a; v[i] = {a, 0}; } if (n == 1) { cout << T n ; return; } while (1) { sort(v.begin(...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int n; cin >> n; string a, b; a += M , b += M ; string tmp1, tmp2; cin >> tmp1 >> tmp2; a += tmp1, b += tmp2; for (int i = (1); i <...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c, d; cin >> a >> b >> c >> d; cout << b << << c << << c << n ; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, l, r, c(0), d(0); scanf( %d%d , &n, &m); while (n--) { scanf( %d , &a); if (a == 1) { c += 1; } else { d += 1; } } int up = min(c, d) * 2; while (m--) { scanf( %d%d , &l, &r)...
#include <bits/stdc++.h> using namespace std; int maxx(int a[2][102], int n, int t) { int m = 0; for (int i = 0; i <= n; i++) if (a[t][i] > m) m = a[t][i]; return m; } int main() { char s[102]; ifstream in( input.txt ); long long int x, y; cin >> x >> y; if (x == 999999999)...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0); ; long long n, k, i; cin >> n >> k; long long a[n], pr[n + 1]; map<long long, long long> f; for (i = 0; i < n; i++) { cin >> a[i]; f[a[i]]++; } int fl = 0; for (aut...
#include <bits/stdc++.h> using namespace std; const int N = 105, M = N * N; int n; int a[N]; int f[N][M]; vector<pair<int, int> > b; int main() { scanf( %d , &n); int sum = 0; for (int i = 1; i <= n; i++) { scanf( %d , a + i); sum += a[i]; } sort(a + 1, a + n + 1); b.pu...
#include <bits/stdc++.h> using namespace std; const int MAX = 5048; vector<int> adj[MAX]; bool used[MAX]; int dist[MAX][MAX]; void solve(const int test_num) { (void)test_num; int v, e; cin >> v >> e; for (int ee = 0, a, b; ee < e; ++ee) { cin >> a >> b; adj[a].push_back(b); }...
#include <bits/stdc++.h> using namespace std; int ans = 1e9; int f[1000010]; int main() { int n, i, j; scanf( %d , &n); for (i = 2; i <= n; i++) { if (!f[i]) { for (j = 2 * i; j <= n; j += i) { f[j] = i; } } f[i] = i - f[i] + 1; } for (i = f[n]; i ...
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, m; cin >> n >> m; long long int st = n / 2; if (n & 1) st++; for (long long int i = (st); i < n + 1; i++) { if (i % m == 0) { cout << i; return; } } cout << -1; } signed main() {...
#include <bits/stdc++.h> using namespace std; long long func(long long arr[], long long n) { long long ans = 0; for (long long i = 2; i < n; i++) { if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) { ans++; } else if (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]) { ans++; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int available[1000000]; int aux; int aux2; for (int i = 0; i < 1000000; ++i) { available[i] = -2; } for (int i = 0; i < n; ++i) { int k = 0; cin >> aux; cin >> aux2; if (!(aux % ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const int N = 1e6 + 10, M = 1e7 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f, ha = 137; int n, q; int mx[N], a[N]; int s[M], ls[M], rs[M]; int rt[N]; int cnt; int update(int loc, int pre, int l, int r) { int now = ++cnt; s[now]...
#include <bits/stdc++.h> using namespace std; const int maxN = 200005; int P[maxN]; int color[maxN]; int cycle_count = 0; void dfs(int s) { color[s] = 1; if (color[P[s]] == 0) dfs(P[s]); else if (color[P[s]] == 1) ++cycle_count; color[s] = 2; } int main() { int n; cin...
#include <bits/stdc++.h> using namespace std; const int oo = ~0u >> 2, mo = (int)1e9 + 7; const int mn = 52, mp = ((mn) * (mn)), me = mp * 4; const int fx[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; struct EDGE { int y, l; } E[me]; int g[mp], d[mp], h[mn][mn], Q[mp]; bool a[mn][mn]; int n, m, tt(0...
#include <bits/stdc++.h> using namespace std; const double PI = atan(1.0) * 4.0; int in_c() { int c; while ((c = getchar()) <= ) { if (!~c) throw ~0; } return c; } int in() { int x = 0, c; while ((unsigned int)((c = getchar()) - 0 ) >= 10) { if (c == - ) return -in(); ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long maxi = LLONG_MIN; for (long long i = 1LL; i <= n; i++) { long long x, y; cin >> x >> y; maxi = max(maxi, x + y); } cout << maxi << endl; }
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; int *arr = (int *)malloc(sizeof(int) * n); for (int i = 0; i < n; ++i) cin >> arr[i]; int curr = arr[0], ans = 1, temp = 1; for (int i = 1; i < n; ++i) { ans = max(ans, temp); if (arr[i] >= curr) { ...
#include <bits/stdc++.h> using namespace std; long long nChooseR(int n, int k); long long gcd(long long a, long long b); vector<string> split(string target, char c); bool isPrime(long long g); long long n, m, t, a[] = {0, 0, 1, 2, 3, 4, 5}, k, x, y, z; long long ans; map<pair<int, int>, int> mp; vecto...
//IaMaNanBord// #include <bits/stdc++.h> using namespace std; //Macro Shorthands #define F first #define S second #define f(i,n) for(ll i=0;i<=n;i++) #define rf(i,n) for(ll i=n;i>=0;i--) #define Cf(i,a,b) fo...
#include <bits/stdc++.h> using namespace std; const long long int is_query = LLONG_MIN; struct Line { long long int m, b; mutable function<const Line*()> succ; bool operator<(const Line& rhs) const { if (rhs.b != is_query) return m < rhs.m; const Line* s = succ(); if (!s) return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int m, n; cin >> n >> m; int c[n]; for (int i = 0; i < n; i++) cin >> c[i]; int a[m]; for (int i = 0; i < m; i++) cin >> a[i]; int d = 0, j = 0; for (int i = 0; i < n; i++) { if (a[j] >= c[i]) { d++; j++...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int max = 2000000001, min = -2000000001; long long int x, y; string question; char answer; int i; for (i = 0; i < n; i++) { int tmp; cin >> question; cin >> x >> answer; cin....
#include <bits/stdc++.h> using namespace std; double x[2], y[2], r[2], R[2]; void solve() { double dx = x[0] - x[1]; double dy = y[0] - y[1]; double d = sqrt(dx * dx + dy * dy); int ans = 0; if (r[0] + R[1] <= d || d + r[0] <= r[1] || d + R[1] <= r[0]) ans++; if (R[0] + R[1] <= d || d + R[...
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; int *arr = new int[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int res = 0; for (int i = 0; i < n - 1; i++) { int k1 = arr[i] + arr[i + 1]; if (k1 < k) { arr[i + 1] += k - k1; ...
#include <bits/stdc++.h> using namespace std; void solve(int* arr, int n) { int max_sum = 0; int answer = 0; for (int i = 1; i <= 30; i++) { int current = 0; max_sum = 0; for (int j = 0; j < n; j++) { if (arr[j] > i) { current = 0; continue; } ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:1024000000,1024000000 ) int _MAX(int a, int b) { return a > b ? a : b; } int _MIN(int a, int b) { return a > b ? b : a; } int Scan() { int res = 0, flag = 0; char ch; if ((ch = getchar()) == - ) flag = 1; else...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; while (scanf( %d%d , &n, &x) != EOF) { int a[100000], b[100000]; for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } for (int i = 0; i < n; i++) { scanf( %d , &b[i]); } int a1[200001], b1...
#include <bits/stdc++.h> using namespace std; long long n, m, x, y, a, b, times, red, t3; long long k; void work3() { long long t1, t2; if (red == 0) { times--; red = m * 2 * (n - 1); } if (x != 1 && x != n) t3 = 2 * times; else t3 = times; if (red > n * m) { ...
#include <bits/stdc++.h> using namespace std; const int max_n = 1500555, inf = 1000111222; struct tree { long long a[4 * max_n], f[4 * max_n]; void clr() { memset(a, 0, sizeof(a)); memset(f, 0, sizeof(f)); } void push(int v, int l, int r) { if (f[v] != 0) { f[2 * v] += f[...
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int a, b, c; cin >> a >> b >> c; int s = 0; int min = a < b ? a : b; int max = a > b ? a : b; s += min; if (c > (max + min)) s += (max + min); else s += c...
#include <bits/stdc++.h> const long long kot = LLONG_MAX; using kk = long double; const long long int alpha = 1e18; using namespace std; int gcd(long long int a, long long int b) { if (a == 0) return b; if (b == 0) return a; if (a == b) return a; if (a > b) return gcd(a - b, b); return gcd...
#include <bits/stdc++.h> using namespace std; int d[1005][1005], sum, res, s, n; int main() { scanf( %d , &n); for (int res = 3; res <= 100; res++) { memset(d, 0, sizeof(d)), sum = 0; for (int i = 1; i <= res; i++) { for (int j = 1; j < i; j++) { if (sum <= n) { i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 5; int main() { ios::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while (T--) { int n, m; cin >> n >> m; if (n % m == 0) cout << YES n ; else cout << NO n ; } }
#include <bits/stdc++.h> using namespace std; void past_code(); void file() {} long long gcd(long long x, long long y) { if (y == 0) return x; return gcd(y, x % y); } long long todic(string z) { long long sum = 0; long long j = 1; for (long long i = 0; i < z.length(); i++) { sum +=...
#include <bits/stdc++.h> using namespace std; template <typename T> void print(const T& t) { cout << t << n ; } template <typename T, typename U, typename... ARGS> void print(const T& t, const U& u, const ARGS&... args) { cout << t << ; print(u, args...); } signed main() { ios_base:...
#include<bits/stdc++.h> using namespace std; #define l1 long long void solve() { int n; cin>>n; vector<int> v(n); for(auto &i:v) cin>>i; l1 sum = 0; l1 need = 0; for(int i=0;i<n;i++) { sum+=v[i]; need+=i; if(sum<need) {cout<< NO <<endl; return;} ...
#include <bits/stdc++.h> using namespace std; const int N = 500005; const int mod = 1e9 + 7; int n, m, l[N], r[N], f[N], sum[N]; vector<int> g[N]; vector<int> cmp; int main() { scanf( %d %d , &n, &m); for (int i = 0; i < m; ++i) { scanf( %d %d , l + i, r + i); cmp.push_back(r[i]); ...
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 100 + 10, mod = 100000007; int a[N]; int n; int main() { ios::sync_with_stdio(false); cin.tie(0); ; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; vector<int> ans; for (int i = 0; i < n; i++) { int val = a...
#include <bits/stdc++.h> using namespace std; const int64_t Nmax = 2e5 + 10; const int64_t mod = 1000000007; vector<int64_t> prime; int64_t is_power_of_two(int64_t a) { return a && (!(a & (a - 1))); } int64_t isperfectsquare(int64_t a) { double b = sqrt(a); return (b - ceil(b) == 0); } int64_t p...
#include <bits/stdc++.h> using namespace std; const int Maxn = 1e5 + 2; const int Nn = 251; char s[Maxn]; int a[Maxn][26], f[Nn][Nn][Nn], length[3], i, j, k, l, Min, n, m, id, p; char ss[3][Nn], op, c, sss[Nn]; void done() { for (int i = 0; i < 26; i++) { a[n][i] = n + 1; a[n + 1][i] = n +...
#include <bits/stdc++.h> using namespace std; vector<int> graph[100001]; int color[100001]; vector<int> b, w; void bfs(int v) { queue<int> q; q.push(v); color[v] = 1; b.push_back(v); while (!q.empty()) { int v = q.front(); q.pop(); for (int u : graph[v]) { if (col...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using ii = pair<int, int>; double x[60000], v[60000]; int n; bool f(double t) { vector<tuple<double, int> > a; for (int i = 0; i < n; ++i) { a.emplace_back(x[i] - v[i] * t, 0...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int count = 0; for (int i = n - 1; i > 0; i--) { if (n % i == 0) count++; } cout << count; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; vector<int> a; vector<int> b; vector<int> c; vector<vector<int> > g; int n, m, k; int dp[5005][5005]; int solve(int at, int homens) { if (at == n) { return 0; } if...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << n ; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, , ); ...
#include <bits/stdc++.h> int main() { int n; while (std::cin >> n) { if (n % 2 == 0) { std::cout << -1 << std::endl; continue; } std::vector<int> a(n), b(n), c(n), was(n); for (int i = 0; i < n; ++i) { a[i] = i; b[i] = (i + 1) % n; c[i] = (a[i] +...
#include <bits/stdc++.h> using namespace std; const int pr[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; const int m = 16; const int INF = 1e9; int n, d[110], por[110], vv[110], opr[110]; int f[110][65560], to[110][65560], pi[110][65560]; void init() { scanf( %d , &n); for (int...
#include <bits/stdc++.h> using namespace std; const int gridSize = 1000; long long getPairs(int n) { long long result = 0; for (int i = 1; i < n; i++) result += n - i; return result; } int main() { std::cout.sync_with_stdio(false); int n, i, x, y, j; cin >> n; bool a[gridSize + 1][...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> vt; for (int i = 0; i < n; i++) { int v; cin >> v; vt.push_back(v); } sort(vt.begin(), vt.end()); int ans = 0; int prev = vt[0]; for (int i = 1; i < n; i++) { int cur =...
#include <bits/stdc++.h> using namespace std; int main() { static int n; static int a[300010], b[300010]; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d%d , &a[i], &b[i]); int cnt[2] = {}; for (int i = 1; i <= n; i++) { if (a[i] < b[i]) cnt[0]++; else cnt...
#include <bits/stdc++.h> using namespace std; char s[10000]; int num[100]; int main() { int T, t, i, j, k, n, m = 0, len; scanf( %s , &s); len = strlen(s); for (i = 0; i < len; i++) { k = s[i] - a + 1; num[k]++; } for (i = 1; i <= 26; i++) if (num[i] % 2 == 1) m++; ...
#include <bits/stdc++.h> const double EPS = 1e-7, pi = 3.141592653589793; struct unit { double x, y; unit(double _x = 0, double _y = 0) : x(_x), y(_y) {} double cross(const unit &A) const { return x * A.y - y * A.x; } inline double len() const { return sqrt(x * x + y * y); } double operator*(con...
#include <bits/stdc++.h> using namespace std; int n, a, b; int main() { cin >> n >> a >> b; n -= a; b++; cout << (n > b ? b : n); return 0; }
#include <bits/stdc++.h> using namespace std; bool ask(long long l, long long r) { cout << l << << r << n ; cout.flush(); string res; cin >> res; return res == Yes ; } int main() { srand(time(NULL)); ios_base::sync_with_stdio(false); long long n, k; cin >> n >> k; ...
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long LINF = LLONG_MAX; const unsigned long long ULINF = ULLONG_MAX; const double EPS = 0.000001; char v[150][150], v_new[150][150]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int w, h; cin >> w >>...
#include <bits/stdc++.h> using namespace std; struct { int begin, end; } P1[60], P2[60]; int main() { int num1, num2, first, last; scanf( %d %d %d %d , &num1, &num2, &first, &last); int ans = 0; for (int i = 1; i <= num1; i++) scanf( %d %d , &P1[i].begin, &P1[i].end); for (int i = 1; i <...
#include <bits/stdc++.h> using namespace std; template <class T> void dbs(string str, T t) { cerr << str << : << t << n ; } template <class T, class... S> void dbs(string str, T t, S... s) { long long idx = str.find( , ); cerr << str.substr(0, idx) << : << t << , ; dbs(str.substr...
#include <bits/stdc++.h> using namespace std; int const N = 2 * 1e5 + 5; int ans = 0; int i, j, n, m, k, z, y, x, t, mi, ma; long long a[N]; long long dp[N][2], d[N][2]; char st[N]; long long poisk(int x, int t) { if (dp[x][t] != 0) return dp[x][t]; long long y = x; d[x][t]++; if (d[x][t...
#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; int main() { pair<int, int> orig[3]; int a, b, x1, y1, t = 0; for (int i = 0; i < 3; i++) { cin >> orig[i].first >> orig[i].second; } cout << 3 << endl; a = (orig[0].first + orig[1].first) / 2; b = (orig[0].second + orig[1].second) / ...
#include <bits/stdc++.h> using namespace std; int m, n, L, cnt, sum[1000005]; char s[1000005], x[1000005]; struct Node { Node *par, *go[26]; int val, sum, flag, num; void Clear(int _val) { par = NULL; for (int i = 0; i < 26; i++) go[i] = NULL; sum = flag = 0; val = _val; ...
#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; int pos = -1; void Go(vector<string> &t) { if (t[++pos] == int ) { cout << int ; } else { cout << pair< ; Go(t); cout << , ; Go(t); cout << > ; } } int main() { int n, i = 0; bool check = true; cin >...
#include <bits/stdc++.h> using namespace std; void pr(char c, int t) { while (t--) printf( %c , c); } int main() { int n, i, co(0), s; map<char, int> c; char ch; scanf( %d , &n); for (i = 0; i < n; ++i) { scanf( %c , &ch); ++c[ch]; } for (const auto &e : c) if ...
#include <bits/stdc++.h> using namespace std; using ll = long long int; using ull = unsigned long long int; using dd = double; using ldd = long double; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n, r; cin >> n >> r; vector<ll> arr((ll(1)) << n); ll sum = 0; n = ((l...
#include <bits/stdc++.h> const int intINF = 999999999; const long long i64INF = 99999999999999999ll; const double doubleINF = 9999999999.; using namespace std; int abs(int a) { if (a < 0) a *= -1; return a; } int max(int a, int b) { if (a < b) a = b; return a; } int main() { int x1...
#include <bits/stdc++.h> using namespace std; template <int _mod = 998244353> class Modular { private: static constexpr int mod = _mod; static_assert(_mod > 0, mod must be positive ); int value; public: Modular() : value(0) {} template <typename U> Modular(const U& _val...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long dp[100004][2]; int n; vector<int> g[100004]; int v[100004]; void dfs(int x) { dp[x][v[x]] = 1; for (int i = 0; i < g[x].size(); i++) { int y = g[x][i]; dfs(y); dp[x][1] = dp[x][1] * (dp[y][0] +...
#include <bits/stdc++.h> using namespace std; long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; } long long lcm(long long a, long long b) { return a * b / GCD(a, b); } int lb(int x) { return x & (-x); } const long long N = 3e5 + 7; const long long inf = 1e18 + 1; const long long mod2...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long long N = 2e5 + 7; const int mod = 1e9 + 7; bool cmp(const pair<long long, long long>& a, const pair<long long, long long>& b) { return a.first < b.first; } long long median(long long a, long long b, long lo...
#include <bits/stdc++.h> using namespace std; int n, k, p; int dp[111][555555], cur[111], a[555555], ld[111], sum[555555], dpp[555555], bit[1111], sz; void update(int x, int p) { while (x <= sz) { bit[x] = max(bit[x], p); x += x & (-x); } } int query(int x) { int res = 0; w...
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long int n, c = 0; int x; cin >> n; unsigned long long int pos[11] = {}, neg[11] = {}, z = 0, i; for (i = 0; i < n; i++) { cin >> x; if (x == 0) z++; else if (x < 0) neg[(-1) * x]++; ...
#include <bits/stdc++.h> using namespace std; class union_find { public: vector<int> arr; union_find(int n) { arr.resize(n); fill(arr.begin(), arr.end(), -1); } int find(int x) { return arr[x] < 0 ? x : arr[x] = find(arr[x]); } void unite(int x, int y) { x = find(x), y = fin...
#include <bits/stdc++.h> using namespace std; int n; double x, y, ans; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> x >> y; ans = (ans * (i - 1) + y) / i; } ans += 5; printf( %.3lf , ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n; cin >> n; char str[n + 2]; cin >> str; if (n == 1) { cout << 0 << endl; return 0; } int current = 0; int previous = 0; if (str[0] == U ) current++; else curr...
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000000000; const int maxn = 1e5 + 100; long long dp[maxn][2], c[maxn]; string reverse(string s) { string t = ; for (int i = s.size() - 1; i >= 0; i--) t += s[i]; return t; } int main() { int n; scanf( %d , &n)...