func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int n, m, z; int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); } int main() { cin >> n >> m >> z; cout << (z / ((long long)n * m / gcd(n, m))); return 0; }
#include <bits/stdc++.h> using namespace std; bool compare(string &s1, string &s2) { return s1.size() < s2.size(); } bool sortmahstyle(const pair<int, int> &a, const pair<int, int> &b) { if (a.first < b.first) return true; return false; } void solve() { long long int n, op; cin >> n >> op; ...
#include <bits/stdc++.h> using std::swap; const int N = (1 << 18) + 5, p = 998244353, G = 3; int rev[N], invG, f[N], g[N], inv2; inline int Dec(int x, int y) { x -= y; return x < 0 ? x + p : x; } inline int Plus(int x, int y) { x += y; return x >= p ? x - p : x; } inline void read(int &x...
#include <bits/stdc++.h> using namespace std; bool isPrime(long long n) { if (n == 1) return false; if (n == 2) return true; for (long long i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } long long powm(long long a, long long b) { long long res = 1; whi...
#include <bits/stdc++.h> using namespace std; const int maxn = 10001; int st, en; const int limit = -5000000; const int maxlongint = 1 << 20; struct edges { int v, flow, rev; int cost; } make; vector<edges> g[maxn]; int dist[maxn]; bool vis[maxn]; int tot; bool ans[maxn]; int i, j, m, ...
#include <bits/stdc++.h> using namespace std; namespace FFT { const int N = 1 << 21; struct Complex { double r, i; }; inline Complex operator+(const Complex &a, const Complex &b) { return {a.r + b.r, a.i + b.i}; } inline Complex operator-(const Complex &a, const Complex &b) { return {a.r - b...
#include <bits/stdc++.h> using namespace std; inline void write(long long a) { if (a >= 10) write(a / 10); putchar( 0 + a % 10); } inline void writeln(int a) { write(a); puts( ); } inline int read() { int x = 0; char ch = getchar(); bool positive = 1; for (; !isdigit(ch); c...
#include <bits/stdc++.h> using namespace std; int const INF = numeric_limits<int>::max(); long long const LLINF = numeric_limits<long long>::max(); long double const EPS = 1e-9; int n, m, k, q; int const N = 505; int a[N][N]; struct qu { int x, y, t; }; bool operator<(const qu& a, const qu& b) {...
#include <bits/stdc++.h> using namespace std; struct node { int x, y; }; int main() { int n; while (scanf( %d , &n) != EOF) { int i, j, cnt = 0; node a[110]; for (i = 0; i < n; i++) { scanf( %d%d , &a[i].x, &a[i].y); } bool u[110] = {0}; queue<int> q; ...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long a, b; cin >> a >> b; long long xx = fabs(a - b); long long d = xx / 2; if ((a + b) % 2) { long long yy = a + b - 2 * d + 1; cout << yy << n ; ...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long N = 2e5 + 5, M = N; long long mx, n; vector<long long> a; long long dp[N]; void solve() { long long i, j, m; cin >> n; a.resize(n); map<long long, long long> m...
#include <bits/stdc++.h> using namespace std; int power(int a, int b, int c) { long long x = 1, y = a; while (b > 0) { if (b % 2 == 1) { x = (x * y) % c; } y = (y * y) % c; b /= 2; } return x % c; } long long int gcd(long long int a, long long int b) { if (b =...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e+5 + 10; const int INF = 0x7fffffff; struct edge { int v, n; } e[maxn * 2]; struct node { int mx, mi, i, c; bool operator<(const node &sec) const { return mx > sec.mx; } } a[maxn]; int n, m, k; int head[maxn], rd[maxn]; voi...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1024000000,1024000000 ) using namespace std; int pre[1005], c[1005]; vector<int> a[1005]; int find(int x) { return pre[x] = (x == pre[x] ? x : find(pre[x])); } void Union(int a, int b) { if (a != b) pre[a] = b; } int main() { int n, m, cnt...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7, N = 2e2 + 10; long long c[8]; int main() { int t; cin >> t; while (t--) { long long x, y; scanf( %lld%lld , &x, &y); for (int i = 1; i <= 6; i++) { scanf( %lld , &c[i]); } for (int i = 1; i <...
#include <bits/stdc++.h> using namespace std; double calcC(int N, int M) { if (M > N) return 0; M = min(N - M, M); double res = 1; for (int i = 1; i <= M; ++i) res *= N - M + i, res /= i; return res; } int main() { int N, M; while (cin >> N >> M) { double result = 0; for ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, l, r, l1 = 0, r1 = 1e9, l2 = 0, r2 = 1e9; cin >> n; for (i = 0; i < n; i++) { cin >> l >> r; l1 = max(l1, l); r1 = min(r1, r); } cin >> n; for (i = 0; i < n; i++) { cin >> l >> r; l2 = max(l2, ...
#include <bits/stdc++.h> using namespace std; int n; char A[200]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> A[i]; for (int i = 1; i <= n; i++) { for (int j = 1; 4 * j <= n; j++) { if (A[i] == * ) ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n = 4; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } if (max(a[2], a[3]) - 1 > min(a[2], a[3])) { cout << -1; return 0; } string ans = ; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); long long n, q; cin >> n >> q; long long* m = (long long*)malloc((n + 2) * sizeof(long long)); for (int i = 0; i < n + 2; i++) { m[i] = 0; } long long* num = (long long*)malloc(n * sizeof(long long)...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > days; vector<int> visited; int main() { int k, n; pair<int, int> temp; cin >> n >> k; for (int i = 0; i < n; i++) { temp.first = i + 1; cin >> temp.second; days.push_back(temp); } for (int i = 0; i < ...
#include <bits/stdc++.h> using namespace std; int PASSED_POINT = 0; void Duxar() {} void read_int(int &value) { int sign = 1; char ch; value = 0; while (!isdigit(ch = getchar())) { (ch == - ) && (sign = -1); } do { value = value * 10 + (ch - 0 ); } while (isdigit(ch = g...
#include <bits/stdc++.h> using namespace std; const int N = 8e5 + 5, B = 20; char s[N]; int n, fa[N], len[N], sz[N], a[N], cc[N], np = 1, cnt = 1; map<int, int> c[N]; int poi[N]; vector<int> e[N]; int st[B][N << 1], dfn[N], pos[N], tim; int qq[N << 1], pre[N], za[N], zb[N], siz; bool cmp(int a, int ...
#include <bits/stdc++.h> using namespace std; inline int Max(int a, int b) { return (((b - a) >> (32 - 1)) & (a ^ b)) ^ b; } inline int Min(int a, int b) { return (((b - a) >> (32 - 1)) & (a ^ b)) ^ a; } string s; long long num[2][1000005], len[2][1000005]; long long rnum[2][1000005]; int main() { cin...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 1; const long long int mod2 = 1e9 + 9; const long long int maxn = 1e6 + 1; const int root = 1e7 + 5; const long long inf = 1e18 + 18; double pie4 = 3.1415926535; long long int visit[maxn], a[maxn]; void die() { cout << ...
#include <bits/stdc++.h> using namespace std; void solve() { long long a, b, c; cin >> a >> b >> c; long long flag = 0, temp; temp = b - a % b; for (long long i = temp; (i + a) <= c; i += b) { cout << i << ; flag = 1; } if (!flag) cout << -1 ; } int main() { ios_b...
#include <bits/stdc++.h> using namespace std; using ll = long long int; ll ara[300005], ans_ara[300005]; set<ll> st; vector<pair<ll, ll> > vv; int main() { ll n, k, i, j, ans = 0; scanf( %I64d %I64d , &n, &k); for (i = 1; i <= n; i++) { scanf( %I64d , &ara[i]); ans -= (ara[i] * i); ...
#include <bits/stdc++.h> int Abs(int x) { return x < 0 ? -x : x; } int main() { int i, N, ans = 0, sum = 0, c = 0, d = 0; double p; scanf( %d , &N); for (i = 0; i < 2 * N; i++) { scanf( %lf , &p); int t = ((int)(p * 1000 + 0.1)) % 1000; if (!t) c++; sum += t; } ans = ...
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v(4); for (int i = 0; i < 4; i++) { cin >> v[i]; } if (v[3] > v[2] * 2) { cout << -1 ; return 0; } if (v[2] > v[3] * 2) { cout << -1 ; return 0; } vector<int> s(3); for (int i =...
#include <bits/stdc++.h> struct Edge { int u, v, next; } edge[100000]; int head[105], num[105]; bool visited[105]; int en, cnt, tt; void add_edge(int u, int v) { edge[en].u = u; edge[en].v = v; edge[en].next = head[u]; head[u] = en++; } void DFS1(int u) { int v; visited[u] = ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; vector<long long> a(n); for (long long i = 0; i < n; i++) cin >> a[i]; vector<long long> q(n); for (long long i = 0; i < k; i++) q[k - 1] += a[i]; for (long long i = k; i < n; i++) q[i] = q[i - 1] +...
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, n, m, r, s; cin >> n; if (n % 2 == 0) { m = n / 2; } else { m = n - 1; m = m / 2 - n; } cout << m << endl; }
#include <bits/stdc++.h> using namespace std; void fun() { int n, k; cin >> n >> k; map<string, int> m; string s; string a[n]; for (int i = 0; i < n; i++) { cin >> s; a[i] = s; m[s]++; } int c = 0; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++...
#include <bits/stdc++.h> using namespace std; const int maxx = 600010; const double pi = acos(-1.0); const double eps = 1e-15; stack<int> h; vector<int> g[maxx]; int t, n, m; int ans = 0, total = 0, sum = 0, cnt = 0; int a[maxx], bj[maxx], vis[maxx], dfn[maxx], low[maxx]; char ch[3111]; char c[311...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; vector<long long> v; long long h = 1, m; while (h <= 25820) { m = ((3 * h + 1) * h) / 2; v.push_back(m); h++; } for (l...
#include <bits/stdc++.h> using namespace std; const int MaxN = 111; int op[123456], val[123456], b[123456]; vector<int> x; vector<int>::iterator it; long long sum[333][5]; int k[333], sumk; map<int, int> ma; char s[5]; int main(void) { int i, j, n; int no, ni; long long res; scanf( %...
#include <bits/stdc++.h> using namespace std; int main() { vector<int> a; int n, t; cin >> n; for (int i = 1; i <= n; i++) { cin >> t; a.push_back(t); } sort(a.begin(), a.end()); for (int i = 0; i < n / 2; i++) cout << a[i] << << a[n - i - 1] << ; if (n % 2 == 1) c...
#include <bits/stdc++.h> using namespace std; long long a[1000000]; int main() { long long i, num, res = 0, n, k, rem, fl = 0; cin >> n >> k; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (i = 1; i < n; i++) { if ((a[i] - a[0]) % k != 0) { fl = 1; ...
#include <bits/stdc++.h> using namespace std; int n, a[101], piller; int main() { cin >> n; for (auto i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (auto i = 0; i < n; i++) { if (piller * a[i] + piller <= i) piller++; } cout << piller; }
#include <bits/stdc++.h> using namespace std; int t[3000]; int main() { int n, k; cin >> n >> k; string s; cin >> s; for (int i = 0; i < n; i++) { t[s[i]] += 1; } int lk = t[ A ]; for (char c = A ; c < A + k; c++) { if (t[c] < lk) { lk = t[c]; } } ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int mod = 1e9 + 7; struct SAM { int n, tot, last; int ch[N][26], dep[N], fa[N]; int root[N], ls[N * 20], rs[N * 20], cnt; vector<int> G[N]; void init() { tot = last = 1; memset(ch[1], 0, sizeof(ch[1])); ...
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 5; int n, q, l[N], r[N], level[N], p[N][20]; pair<int, int> res[N]; int import[N], numCity, numVirus, node[N], total_num; vector<int> adj[N], newAdj[N]; struct T { int city, speed; }; T virus[N]; int cnt = 0; void dfs(int x, int...
#include <bits/stdc++.h> using namespace std; long long n, A[100005]; int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) cin >> A[i]; sort(A, A + n); int mid = n / 2; long long res = 0; for (int i = 0; i < mid; i++) { res = (res + A[i] * A[n - 1 ...
#include <bits/stdc++.h> using namespace std; struct node { int x, y, next; } a[1010000]; int len, last[510000]; inline void ins(int x, int y) { len++; a[len].x = x; a[len].y = y; a[len].next = last[x]; last[x] = len; } int tt[510000]; int col[510000]; int cnt, belong[510000]; ...
#include <bits/stdc++.h> using namespace std; int main() { double n, m; while (cin >> m >> n) { double res = 0; for (double i = 1; i <= m; i++) { res += i * (pow(i / m, n) - pow((i - 1) / m, n)); } cout << res << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> void print(T &x) { cout << x; } template <class T, class U> void print(pair<T, U> &p) { cout << ( ; print(p.first); cout << , ; print(p.second); cout << ) ; } template <class T> void print(vector<T> &v) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 50; const int inf = 0x3f3f3f3f; int n, mod; long long ans; int head[maxn], nxt[maxn << 1], to[maxn << 1], cost[maxn << 1], edge_tot; void add_edge(int u, int v, int c) { nxt[++edge_tot] = head[u]; head[u] = edge_tot; to[edge_...
#include <bits/stdc++.h> using namespace std; long long dp[41]; void prec() { dp[0] = 0; long long x = 1; for (int i = int(1); i < int(41); i++) { dp[i] = 2 * dp[i - 1] + x; x = x << 1; } } int main(int argc, const char* argv[]) { long long n; cin >> n; prec(); n--;...
#include <bits/stdc++.h> using namespace std; int main() { int n, a[100001], i; set<int> mysetp, mysetn, left, right; set<int>::iterator l, r, p; scanf( %d , &n); scanf( %d , &a[1]); mysetn.insert(-a[1]); mysetp.insert(a[1]); for (i = 2; i <= n; i++) { scanf( %d , &a[i]); ...
#include <bits/stdc++.h> using namespace std; using DB = double; using LL = long long; using PII = pair<int, int>; void err() { puts( ); } template <template <typename...> class T, typename t, typename... Args> void err(T<t> a, Args... args) { for (auto x : a) cout << x << ; err(args...); } ...
#include <bits/stdc++.h> using namespace std; const int N = 1000010; const long long inf = 1000000000000000000LL; int a[N]; long long prefix_cost[N], cost[N], suffix_cost[N]; set<int> factors; set<int>::iterator it; void pf(int x) { for (int j = x - 1; j <= x + 1; j++) { int d = j; for (...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t ope...
#include <bits/stdc++.h> using namespace std; static const int MOD = 51123987; static const int MAXN = 150 + 10; char s[MAXN]; int p[MAXN][3]; int dp[MAXN][55][55][55]; int n, res; int main() { scanf( %d%s , &n, s + 1); p[n + 1][0] = p[n + 1][1] = p[n + 1][2] = n + 1; for (int i = n; i >= 1;...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; template <class T> T gcd(T a, T b) { return ((b == 0) ? a : gcd(b, a % b)); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector<int> a(n); ...
#include <bits/stdc++.h> using namespace std; long long m; int k; vector<int> a; long long memo[66][2][66]; long long dp(int id, int tight, int cnt) { long long &res = memo[id][tight][cnt]; if (res == -1) { res = 0; if (id == a.size()) { if (cnt == k) res = 1; } else { ...
#include <bits/stdc++.h> using namespace std; bool compare(int a, int b) { return a > b; } int main() { int n, a, index; cin >> n; vector<int> A; int temp; int count = 0; for (int i = 0; i < n; i++) { cin >> a; A.push_back(a); } for (int i = 0; i < n; i++) { if (A...
#include <bits/stdc++.h> using namespace std; void solve() { vector<long long> v, ans; long long n; cin >> n; for (long long i = 0; i < n; i++) { long long q; cin >> q; v.push_back(q); } sort(v.begin(), v.end()); bool cur = 0; while (!v.empty()) { if (!cur) { ...
#include <bits/stdc++.h> using namespace std; const long long INF64 = (long long)(1e18) + 10; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int q = 1, i, j, test, k; for (test = 1; test < (q + 1); test++) { long long n, ans = 0, x = 0; cin >> n...
#include <bits/stdc++.h> using namespace std; bool isBeautiful(int n) { bool flag[10]; for (int i = 0; i < 10; i++) flag[i] = false; while (n > 0) { int digit = n % 10; if (flag[digit]) return false; flag[digit] = true; n = n / 10; } return true; } int main() { io...
#include <bits/stdc++.h> using namespace std; long long INF = (1e15) + 1; int n, dp[100004], par[100004]; long long d, arr[100004]; struct Node { Node *leftNode, *rightNode; long long leftBound, rightBound; pair<int, int> mx; Node() { leftNode = rightNode = NULL; leftBound = rightB...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void Read(T &x) { x = 0; char c; while (!isdigit(c = getchar())) ; do { x = x * 10 + c - 0 ; } while (isdigit(c = getchar())); } long long read() { long long tmp; cin >> tmp; return tmp; }...
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> ostream& operator<<(ostream& out, const pair<A, B>& p) { out << ( << p.first << , << p.second << ) ; return out; } template <typename A, typename B> void printP(const pair<A, B>& p, const char* str = NULL) { if...
#include <bits/stdc++.h> using namespace std; const int N = 500010; int n, a; multiset<int> st; int main() { cin >> n; st.insert(0); for (int i = 1; i <= n; ++i) { scanf( %d , &a); if (st.find(a) != st.end()) { st.erase(st.find(a)); st.insert(i); } else { ...
#include <bits/stdc++.h> using namespace std; long long arr[200005]; long long n; map<long long, long long> ans; bool debug = false; long long rec(long long node) { if (debug) cout << entering << node << endl; if (node == 1) return 1000000000000; if (node <= 0 || node > n) return 0; if (a...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 100; int a[25]; int ans[25]; map<int, int> mp; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); ans[i] = a[i]; } sort(ans, ans + n); for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a; cin >> n >> a; vector<int> vi(n); for (int i = 0; i < n; ++i) cin >> vi[i]; sort((vi).begin(), (vi).end()); if (n == 1) cout << 0; else if (a <= vi[0]) cout << llabs(vi[n - 2] - a); else if (a >= vi[n - ...
#include <bits/stdc++.h> using namespace std; int m[11]; int dig(int i) { while (i) { if (m[i % 10]) return 1; i /= 10; } return 0; } int main() { int n, i, s(0); cin >> n; int temp = n; for (int i = 0; i < 11; i++) m[i] = 0; while (temp) { m[temp % 10] = 1; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, a, b, ans; cin >> n >> a >> b; if (b > 0) { ans = (a + b) % n; if (ans == 0) ans = n; } else if (b < 0) { if (a > abs(b)) { ans = a - abs(b); ...
#include <bits/stdc++.h> using namespace std; int main() { map<char, int> ma; int p; char a, k[1000]; cin >> p; for (int i = 0; i < p; i++) { cin >> k[i]; a = tolower(k[i]); ma[a]++; } if (ma.size() == 26) cout << YES << endl; else cout << NO << endl...
#include <bits/stdc++.h> using namespace std; const long long oo = 3e18, M = 54; long long q, n, k; string F = What are you doing at the end of the world? Are you busy? Will you save us? ; string X = What are you doing while sending ; string Y = ? Are you busy? Will you send ; strin...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; const double eps = 1e-9; int a[maxn]; int main() { std::ios::sync_with_stdio(false); int n, sum = 0; cin >> n; for (int i = 0; i < n; ++i) cin >> a[i], sum += a[i]; sort(a, a + n); int ans = 0; while (fabs(roun...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( unroll-loops ) using namespace std; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long n, m, p; cin >> n >> m >>...
#include <bits/stdc++.h> using namespace std; using std::ios; constexpr int MOD = 1e9 + 7; constexpr int mod = 998244353; template <typename T> T power(T a, T b) { T r = 1; while (b) { if (b & 1) r *= a; b /= 2; a *= a; } return r; } int d[100005]; int main() { io...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n; string s; cin >> n; cin >> s; int flag = 0; int p = n / 2; p = p - 1; for (int i = 0; i <= p; i++) { if ((abs(s[i] - s[n - 1 - i]) != 2...
#include <bits/stdc++.h> using namespace std; int o[100100]; int ans[6000100]; int main() { int i, j, n; int e = 0; long long x, y; long long m, tmp, st, ed, mid; scanf( %d %I64d , &n, &m); for (i = 1; i <= n; i++) scanf( %d , &o[i]); sort(o + 1, o + n + 1); o[0] = 0; o[n + 1...
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int n, m, x, y, c[maxn]; int lowbit(int x) { return x & -x; } void add(int x, int k) { for (; x <= n; x += lowbit(x)) { c[x] += k; } } int Query(int x) { int ans = 0; for (; x; x -= lowbit(x)) { ans += c[x]; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; int n, m, q, v[maxn], lp[maxn]; vector<int> e[maxn], t[maxn]; vector<long long> ps[maxn]; int mx, argmx; void dfs(int id, int p, int d, int cpn) { if (cpn) v[id] = cpn; lp[id] = max(lp[id], d); if (d > mx) { mx =...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1, 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 *...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; struct PP { int l, r, k; int rank, ans; bool operator<(const PP& b) const { if (r == b.r) return l < b.l; return r < b.r; } } a[MAXN], b[MAXN]; struct Point { int l, r, rank; bool operator<(const Point&...
#include <bits/stdc++.h> using namespace std; int a, b, c; int main() { cin >> a >> b >> c; int i, s = 0; for (i = 1; i <= a - 1; i++) s += i; cout << (c + a - 1) * (b + a - 1) - 2 * s; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; int i, j, res = 0; for (i = 0; i < n; i++) { if (s[i] == . ) { res++; } else if (s[i] == L ) { res...
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int n, m, p; int a[200004], b[200004]; int sol[200004]; int ns = 0; int main() { scanf( %d%d%d , &n, &m, &p); for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); for (int i = 1; i <= m; ++i) scanf( %d , &b[i]); int num = m; f...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; for (int i = 0; i < n; i++) { cout << 3 * n + i; if (i == n - 1) cout << endl; else cout << ; } }
#include <bits/stdc++.h> using namespace std; const long long maxn = 65 + 5, maxk = (1 << 15) + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f; long long n, m, Q, K, T, S; long long read() { long long x = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; while (cin >> n) { long long g[200000] = {0}; long long a[200000] = {0}, i; long long sum = 0; for (i = 1; i <= n; i++) cin >> a[i]; long long ans = 0; long long m1 = 0, m2 = 0; while (sum < n) { ...
#include <bits/stdc++.h> using namespace std; int n, k, t; int a[25][25]; int vis[25]; int dfs(int x, int sum, int limit) { if (sum > limit) return 0; if (x == n + 1) return 1; int ans = dfs(x + 1, sum, limit); for (int i = 1; i <= n; i++) if (vis[i] == 0 && a[x][i]) vis[i] = 1, ...
#include <bits/stdc++.h> using namespace std; int main() { int n, c, a, b; scanf( %d %d %d %d , &n, &c, &a, &b); a--; b--; int ca = a % c, cb = b % c; if (ca == 0) { if ((cb == (c - 1)) or b == (n - 1)) printf( 1 n ); else if (b / c == a / c) printf( 1 n ); ...
#include <bits/stdc++.h> using namespace std; bool checkThree(char cc, char lc, char nc) { return (cc != lc && cc != nc); } int main() { int t; cin >> t; while (t--) { string s, t; cin >> s >> t; for (int i = 0; i < s.length(); i++) { int x = t.find(s[i]); if (x < t.l...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000000000 ) using namespace std; int n, m; vector<pair<int, int> > ans; int main() { ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { ans.clear(); cin >> n >> m; int k = 0; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } signed main(void) { vector<long long> in(101, 0); long long sum = 0; for (long long i ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a1, a2, b1, b2; cin >> a1 >> a2; cin >> b1 >> b2; if ((a2 == b2 && (a1 + b1 == a2)) || (a1 == b1 && (a2 + b2 == a1)) || (a2 == b1 && (a1 + b2 == a2)) || (a1 == b2 && (a2 + b1 =...
#include <bits/stdc++.h> using namespace std; int a[1000 + 5], b[1000 + 5]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= m; i++) scanf( %d , &b[i]); int ans = 0; for (int i = 1, j = 1; i <= n; i++) { if (b[j] >= a...
#include <bits/stdc++.h> using namespace std; long long a[300010], po[300010], ans; int n, p = 1e9 + 7; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]); sort(a + 1, a + n + 1); po[0] = 1; for (int i = 1; i <= n; i++) po[i] = po[i - 1] * 2 % p; for (int i ...
#include <bits/stdc++.h> using namespace std; int matrix[101][101]; struct HATE { int t, r, c, x; HATE(int t, int r, int c, int x) { this->t = t; this->r = r; this->c = c; this->x = x; } }; HATE* hates[10001]; int main() { int n, m, q; cin >> n >> m >> q; for ...
#include <bits/stdc++.h> using namespace std; pair<pair<int, int>, pair<int, int> > a[60000]; int ans[60000], b[60000], n, m, maxx; int main() { cin >> n >> m; for (int i = 1; i <= m; i++) cin >> a[i].first.first >> a[i].first.second >> a[i].second.first >> a[i].second.second; for (i...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:64000000000 ) using namespace std; const double EPS = 1e-9; const int INF = (int)(2e9 + 0.5); const int MAXN = 201000; int n, k, a; vector<int> mass; set<int> minima; map<int, int> bad; int main() { scanf( %d%d , &n, &k); for (int i = ...
#include <bits/stdc++.h> using namespace std; const int N = 100000; const int delt = 255; long long fa[N], fb[N], fc[N]; int main() { ios::sync_with_stdio(false); string a, b, c; cin >> a; cin >> b; cin >> c; for (int i = 0; i < a.size(); i++) { fa[a[i] + delt]++; } for (...
#include <bits/stdc++.h> using namespace std; int c[26]; int main() { string s; cin >> s; if (s.length() < 26) { cout << -1; return 0; } int f = 0, h = 0; for (int i = 0; i < 25; i++) { if (s[i] != ? ) { h += (c[s[i] - A ] == 0); c[s[i] - A ]++; }...
#include <bits/stdc++.h> using namespace std; int nos; void split(int n) { if (nos == 0 || n == 1) cout << n << ; else { --nos; split(n / 2); split(n / 2); } } int main() { ios::sync_with_stdio(false); int n, k; cin >> k >> n; if (n > k) cout << NO...
#include <bits/stdc++.h> using namespace std; const int iinf = 1e9 + 7; const int oo = 0x3f3f3f3f; const long long linf = 1ll << 60; const double dinf = 1e60; template <typename T> inline void scf(T &x) { bool f = 0; x = 0; char c = getchar(); while ((c < 0 || c > 9 ) && c != - ) c = g...