func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int n, P, a[150005], lazy_tag[600005], m; int read() { char x = getchar(); int ans = 0; while (!isdigit(x)) x = getchar(); while (isdigit(x)) ans = ans * 10 + x - 0 , x = getchar(); return ans; } struct node { vector<pair<int, int> > V; ...
#include <bits/stdc++.h> using namespace std; typedef vector<long long int> vi; typedef vector<vi> vvi; typedef vector<pair<long long int, long long int> > vii; typedef vector<vii> vvii; typedef vector<bool> vb; const long long int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1}; const long long int dx8[] ...
#include <bits/stdc++.h> using namespace std; int main() { pair<long long, long long> a[1001]; a[0].second = 1; for (long long i = 1; i < 1001; i++) { a[i].first = i; if (i < 10) a[i].second = 1; else if (i < 100) a[i].second = 2; else if (i < 1000) a[i].s...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; string s[t]; for (int i = 0; i < t; i++) { cin >> s[i]; } map<string, int> m; for (int j = 0; j < t; j++) { for (int l = 1; l <= 9; l++) { for (int i = 0; i < 10 - l; i++) { string p...
#include <bits/stdc++.h> using namespace std; long long ceil(long long a, long long b) { long long res = a / b; if (a % b != 0) res++; return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m, q; cin >> n >> m >> q; vector<int> a(n), b(m); long ...
#include <bits/stdc++.h> using namespace std; int main() { string k; cin >> k; int st = 0; while (st < (int)k.length() && k[st] == a && 1) { st++; } if (st == (int)k.length()) { k[k.length() - 1] = z ; cout << k << endl; return 0; } int se = st + 1; whi...
#include <bits/stdc++.h> using namespace std; void solve() { int n, x, y; cin >> n >> x >> y; vector<int> nums(n); vector<int> a(n); vector<vector<int>> freq(n + 1); vector<vector<int>> ind(n + 1 + 1); vector<bool> mis(n); for (int i = 0; i < n; i++) { cin >> nums[i]; mis...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; n--; int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; if (a[i] == 0) --i; } int principi; int b[n]; for (int i = 0; i < n; ++i) { ...
#include <bits/stdc++.h> using namespace std; struct edge { int x, y, z, id; } e[200005]; vector<int> to[200005]; int fa[200005], f[200005][18], deep[200005], g[200005][18], id[200005], ans[200005]; bool flag[200005]; int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } void dfs(in...
#include <bits/stdc++.h> using namespace std; struct edge { int to, next; } e[400005]; int n, k, num, head[200005], a[200005], f[200005], g[200005], h[200005], g_node[200005], ans, maxa, size[200005]; bool ok[200005]; inline void insert(int u, int v) { e[++num].to = v; e[num].next = head[u...
#include <bits/stdc++.h> using namespace std; const double Pi = acos(-1.0); void DEBUG(string name, int* begin, int* end) { printf( DEBUG: %s = { , name.c_str()); for (; begin != end; begin++) { printf( %5d, , *begin); } printf( %c} n , (char)8); } void DEBUG(string name, long long* begi...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6; int n, k; int Pow10[10], F[10]; long long f[N]; long long cal(int n) { int t = 0; long long s = 0; while (n > 0) { int x = n % 10; if (x % 3 == 0) s += 1LL * F[t] * x / 3; n /= 10; t++; } return ...
#include <bits/stdc++.h> int a, b, c; int t, x = 0; int ans = 0; void find(int x) { for (t = x; t <= c + x; t++) if (b * x + (b - a) * (t - x) < 0) { x++; ans++; find(x); break; } } int main() { scanf( %d%d%d , &a, &b, &c); find(x); printf( %d n , ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a.begin(), a.end()); bool ok = true; int cur = -1; int q = 0; for (int i = 0; i < n; ++i) { if (q == 0) { if (cu...
#include <bits/stdc++.h> using namespace std; int n, f, m, k, l, g, i, h, a, b, j, a1, b1, c1, c, x, y, q, w, e, r, t, d[15]; int main() { cin >> n; d[0] = 2; d[1] = 7; d[2] = 2; d[3] = 3; d[4] = 3; d[5] = 4; d[6] = 2; d[7] = 5; d[8] = 1; d[9] = 2; a = n / 10; b...
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; x = abs(x); int pos = 0; int i; for (i = 1; pos < x; i++) pos += i; int diff = pos - x; if (diff % 2 == 0) cout << (i - 1) << endl; else { if (i % 2 != 0) cout << i << endl; else...
#include <bits/stdc++.h> using namespace std; int n; int node[101], h[101], perm[101], fav[101]; int getP(int c) { int p = node[c]; if (p < 0) return c; while (node[p] > 0) p = node[p]; return node[c] = p; } void join(int a, int b) { if (0) printf( join %d %d n , a, b); int pa = getP...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int k = 0; string a, b, c; cin >> a >> b >> c; for (int i = 0; i < a.size(); i++) { if (a[i] == c[i] || b[i] == c[i]) k++; else { k = -1; break;...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100, mod = 998244353, inf = 2e9; int n, p[N], v[N], x[N], cnt, ans; int qpow(int x, int y) { int ret = 1; while (y) { if (y & 1) ret = 1ll * ret * x % mod; x = 1ll * x * x % mod, y >>= 1; } return ret; } struct nod...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; long long x, q, b; for (int i = k - 1; i >= 1; i--) { x = n / i * k + i; q = x % k; b = x / k; if (q * b == n) return cout << x, 0; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (n - 1) * 2 + 1 << << 2 << endl; cout << 1 << << 2 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> vec(n); for (int i = 0; i < n; ++i) cin >> vec[i]; int sum = accumulate(vec.begin(), vec.end(), 0); if ((sum / 100) % 2 != 0) { cout << NO n ; return 0; } sum /= 2; int num_one = ...
#include <bits/stdc++.h> using namespace std; const int size = 3111; long long mod = 200000007; double p; int x, k, tmpx, a, m, b; double dp[2][1 << 9][2][255]; int main() { cin >> x >> k >> p; tmpx = x; p /= 100; int cur, nxt; m = (1 << 9) - 1; int res = (x & m); x >>= 9; ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; template <typename T> inline void umax(T &a, T b) { a = max(a, b); } template <typename T> inline void umin(T &a, T b) { a = min(a, b); } const long long N = 1e5 + 10; const long long INF = 1e16 + 10; const pair<long ...
#include <bits/stdc++.h> using namespace std; bool myfunction(int i, int j) { return (i < j); } istream &in = cin; int n; bool adj[1501][1501]; int vtx[1501]; vector<bool> chk; vector<pair<pair<int, int>, int> > points; vector<pair<int, int> > res; int dfs(int node) { int cnt = 0; chk[node] ...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e3 + 500; const double eps = 1e-8; int sgn(double x) { if (fabs(x) < eps) return 0; if (x < 0) return -1; else return 1; } struct Point { double x, y; Point() {} Point(double _x, double _y) : x(_x), y(_y) {} ...
#include <bits/stdc++.h> using namespace std; int A[(1 << 17)]; int A0[(1 << 17)]; int A1[(1 << 17)]; int C[(1 << 17)]; int RMQ[2 << 20]; int I[32]; void Add(int a, int b) { int i; for (i = (0); i < (20); ++i) RMQ[I[i] + (a >> i)] += b; } int Sum(int a) { int res = 0; int i; for ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int INF = 213456789; const double eps = 1e-7; int flag1 = 2, flag2 = 2, n, m; template <class T> T gcd(T a, T b) { if (!b) return a; return gcd(b, a % b); } int a[110][110]; int dy[] = {1, -1, 0, 0}; int ...
#include <bits/stdc++.h> using namespace std; int n; queue<int> q; vector<int> v[1999]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 2; i <= n; i++) { int a; cin >> a; v[a].push_back(i); } q.push(1); int ok = 1; while (!...
#include <bits/stdc++.h> using namespace std; int ans = -1; map<pair<int, int>, bool> visited, mp; void bfs(int x1, int y1, int x2, int y2) { queue<pair<pair<int, int>, int>> q; q.push({{x1, y1}, 0}); while (!q.empty()) { auto z = q.front(); q.pop(); visited[z.first] = 1; if ...
#include <bits/stdc++.h> using namespace std; void Solve() { long long n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; reverse(arr.begin(), arr.end()); for (int i = 0; i < n; i++) cout << arr[i] << ; cout << n ; } int main() { long long t; cin...
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[1 << 16], *S, *T; if (S == T) { T = (S = buf) + fread(buf, 1, 1 << 16, stdin); if (T == S) return EOF; } return *S++; } inline int read() { int x = 0, f = 1; char ch = gc(); while (ch < 0 |...
#include <bits/stdc++.h> using namespace std; int a[2000][2000], k, p[2000], Index; void add(int x, int y) { a[x][y] = a[y][x] = 1; } int main() { scanf( %d , &k); int maxbit = 0; for (int i = (1); i <= (30); ++i) if ((1 << i) & k) maxbit = i; Index = 2; int cur = ++Index; add(1, c...
#include <bits/stdc++.h> using namespace std; int n, m; const int MAXN = 200100; int win = 0, ti = 0; int vis[MAXN][2] = {0}; int vs[MAXN] = {0}; int path[MAXN], cnt; vector<int> g[MAXN]; bool dfsloop(int u) { vs[u] = 1; bool f = false; for (int i = 0; i < g[u].size(); i++) { int v =...
#include <bits/stdc++.h> using namespace std; set<int> s; int t, n, a[200020], cnt, d[200020], e[200020]; int main() { for (scanf( %d , &t); t--; s.clear(), cnt = 0) { scanf( %d , &n); for (int i = 0; i < n; i++) d[i] = e[i] = 0; for (int i = 0; i < n; i++) scanf( %d , a + i); for (i...
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 10; const double eps = 1e-6; const double mod = 1e9 + 7; struct num { int v, i; } b[MAX]; bool cmp(const num &x, const num &y) { return x.v > y.v; } bool cmp1(const num &x, const num &y) { return x.i < y.i; } int main() { int ...
#include <bits/stdc++.h> int main() { unsigned long long n; unsigned long long answer; scanf( %I64u , &n); if (n < 3) { printf( %lu , n); return 0; } if (n % 2 == 1) { answer = (n) * (n - 1) * (n - 2); } else if (n % 3 != 0) { answer = n * (n - 1) * (n - 3); } e...
#include <bits/stdc++.h> using namespace std; int Int() { int x; scanf( %d , &x); return x; } long long Long() { long long x; scanf( %lld , &x); return x; } void err(istream_iterator<string> it) { cout << endl; } template <typename T, typename... Args> void err(istream_iterator<s...
#include <bits/stdc++.h> using namespace std; long long int n, k; int a[200005]; int main() { int t; scanf( %d , &t); while (t--) { scanf( %d%d , &n, &k); int pos = 0, mn = 1000000000; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); if (i > k && a[i] - a[i - k] <...
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; for (int a = 1; a <= x; ++a) for (int b = 1; b <= x; ++b) if (a % b == 0 && a * b > x && a / b < x) { cout << a << << b << endl; return 0; } puts( -1 ); return 0; }
#include <bits/stdc++.h> using namespace std; long long n, k, l, r, sz, i, len, q, p, mid, anspos, ans[1000001]; long long mxl, mxr; long long pos[1000001], t[1000001], pr[100001]; struct Pair { long long pos; long long x; long long d; }; Pair a[100001], b[100001]; bool cmp(Pair p1, Pair p2)...
#include <bits/stdc++.h> using namespace std; int helper(long long int edges, long long int nodes) { if (edges == nodes - 1) return nodes - 1; edges -= nodes - 1; return nodes - 1 - ceil((1.0 + sqrt(1.0 + 8.0 * edges)) / 2.0); } int main() { ios::sync_with_stdio(false); ; cin.tie(0); ...
#include <bits/stdc++.h> using namespace std; priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, less<pair<long long, long long>>> q; priority_queue<long long, vector<long long>, greater<long long>> p; long long n, k, t, b, temp, res; int main() { cin >> ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int ans = 1e9; for (int i = 0; i < n - 1; i++) if (s[i] == R && s[i + 1] == L ) ans = min(ans, (a[i + 1] - a[i]) / 2); if (a...
#include <bits/stdc++.h> using namespace std; const long long linf = 1001002003004005006ll; const int inf = 1001001001; const int mod = 1000000007; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >>...
#include <bits/stdc++.h> using namespace std; inline long long rd() { register long long x = 0; register bool f = 0; register char c = getchar(); while (!isdigit(c)) { if (c == - ) f = 1; c = getchar(); } while (isdigit(c)) { x = x * 10 + (c ^ 48); c = getchar(); ...
#include <bits/stdc++.h> using namespace std; pair<int, int> Castle[100010]; int Index[100010]; int main() { int N; scanf( %d , &N); int Temp; for (int i = 1; i <= N; i++) { scanf( %d , &Temp); Castle[i] = make_pair(Temp, i); } sort(Castle + 1, Castle + N + 1); int Max = ...
#include <bits/stdc++.h> using namespace std; int read() { int num = 0; bool f = 0; char ch = getchar(); while (ch < 0 || ch > 9 ) { f = (ch == - ); ch = getchar(); } while (ch >= 0 && ch <= 9 ) { num = (num << 1) + (num << 3) + ch - 0 ; ch = getchar(); } ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx ) using namespace std; const int MX = 1e9 + 1; const int Imp = -1; const int N = 1e6 + 5; const int M = 1e6 + 5; const long long INF = 1e18 + 1; int n, k; string s; set<char> st; int...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, x; vector<int> a; cin >> n >> k; vector<int> w(k); for (int i = 0; i < n; i++) { cin >> x; a.push_back(x); } for (int i = 0; i < k; i++) { for (int j = i; j < n; j += k) { w[i] += a[j]; }...
#include <bits/stdc++.h> using namespace std; const long long N = 5000700; template <typename T> pair<T, T> operator-(pair<T, T> a, pair<T, T> b) { return make_pair(a.first - b.first, a.second - b.second); } template <typename T> pair<T, T> operator+(pair<T, T> a, pair<T, T> b) { return make_pair(...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long k; cin >> k; long long res[4][4]; for (long long i = 0; i < 4; ++i) { for (long long j = 0; j < 4; ++j) { if (i == 1 && j == 2) { re...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { long long tmp; while (b) { a %= b; tmp = a; a = b; b = tmp; } return a; } int main() { int n; cin >> n; vector<int> a(n + 1, 0); for (int i = 0; i < n; i++) { cin...
#include <bits/stdc++.h> using namespace std; int n, root, m; int a[100100]; int h[100100]; vector<int> g[100100]; int arr[200100]; int N, tin[100100], tout[100100]; vector<pair<int, int> > t[200100 * 4]; void dfs(int v, int par = -1, int len = 0) { h[v] = len; tin[v] = ++N; arr[N] = v; ...
#include <bits/stdc++.h> using namespace std; struct node { node *next[26]; node() { for (int i = 0; i < 26; i++) next[i] = NULL; } }; void insert(node *root, string &str) { node *current = root; for (char ch : str) { if (current->next[ch - a ] == NULL) { current->next[c...
#include <bits/stdc++.h> using namespace std; long long a[100500]; vector<long long> pfx[100500], vtx[100500]; long long proc(long long x, long long sum) { int n = vtx[x].size(); int mid = n / 2; long long res = sum; for (int i = mid, _n = n; i < _n; i++) res += vtx[x][i] - vtx[x][mid]; for ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; long long l = s.length(); long long ans = 0; for (long long i = l - 1; i >= 1; i--) { ans = ans + pow(2, i); } for (long long i = 0; i < l; i++) {...
#include <bits/stdc++.h> using namespace std; class Timer { clock_t start; string name; public: Timer() { name = ; start = clock(); } Timer(string s) { name = s; start = clock(); } ~Timer() { fprintf(stderr, %s: %.3gs n , name.c_str(), ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; vector<int> g[n]; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--, v--; ...
#include <bits/stdc++.h> using namespace std; const int Maxn = 10005; const int Inf = 1000000000; int n; int a[Maxn]; set<pair<int, int> > S; long long res; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &a[i]); for (int i = 0; i < n; i++) S.insert(pair<int, int>(i - a...
#include <bits/stdc++.h> using namespace std; long long n; long long arr[1005]; long long dp[1005][3 * 10000]; long long add(long long a, long long b) { return ((a % 1000000007) + (b % 1000000007)) % 1000000007; } long long f(long long idx, long long sum) { if (idx == n + 1) { return 0; ...
#include <bits/stdc++.h> using namespace std; const long long md = 998244353; int main() { long long n; cin >> n; vector<long long> a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; a[i] *= (n - i) * (i + 1); } for (int i = 0; i < n; i++) cin >> b[i]; sort(a.begin(), a...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int a[N], c[N]; int ans[N]; struct qq { int x, y, id; } s[N]; int n, Q; bool cmp(qq x, qq y) { return x.y < y.y; } int q[N]; int st, ed, now; double Y(int x) { return a[x] * x - c[x]; } double X(int x) { return -a[x]; } do...
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; signed main() { cin.tie(0); ios::sync_with_stdio(false); long long N, a, b; cin >> N >> a >> b; vector<long long> A; A.push_back(a); A.push_back(a); A.push_back(a); A.push_back(a); A.push_back(b); ...
#include <bits/stdc++.h> using namespace std; const int N = 100005, S = 100; int L[N], R[N], bel[N], to[N]; long long a[N], b[N], taga[N], tagb[N]; long double slope(int x, int y) { if (a[x] == a[y]) { if (b[x] == b[y]) return 1; return b[x] < b[y] ? 1e18 : -1e18; } return (long double...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long MOD2 = 998244353; const long long MOD3 = 1812447359; const long long INF = 1ll << 62; const double PI = 2 * asin(1); void yes() { printf( yes n ); } void no() { printf( no n ); } void Yes() { printf( Yes n ); ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, m, f[N]; bool vis[2][N]; vector<int> edges[2][N]; void dfs0(int x) { if (vis[0][x]) return; vis[0][x] = 1; for (int to : edges[0][x]) { if (f[to] != 1) dfs0(to); } } void dfs1(int x) { if (vis[1][x]) r...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( O3 ) template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const double eps = 1e-8; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const int seed = 131; int n, a[maxn], q; struct node { int l, r, sum, lazy; } Q[maxn << 2]; void build(int rt, int l, int r) { Q[rt].l = l, Q[...
#include <bits/stdc++.h> using namespace std; int n, arr[100], res, maxi, mini, g; int gcd(int a, int b) { for (; b != 0; b = b % a) swap(a, b); return a; } int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &arr[i]); maxi = g = arr[0]; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; long long fS(long long x) { long long lo = 1, hi = x - 1, cn = 0, ans = -1, out = 1; while (cn <= 80) { if (cn & 1) ans -= (lo + hi) / 2; else ans += (lo + hi) / 2; lo = (lo + hi) / 2 + 1; out = min(out, ans); cn++; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, i, j; cin >> n; long long ans = 0; for (i = 1; i <= n; i++) { for (j = i; j <= n; j++) { k = sqrt(i * i + j * j); if (k * k == i * i + j * j && j <= k && k <= n) { ans++; } } ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e5 + 5; vector<long long> adj[MAXN]; long long a[MAXN], cnt0[MAXN], cnt1[MAXN]; bool t0[MAXN], t1[MAXN]; bool b[MAXN], c[MAXN]; long long n; void input(); void dfs(long long, long long); void solve(); int main() { ios::sync_...
#include<bits/stdc++.h> using namespace std; struct _field { bool white = false; }; int mod = 998244353; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen( input.txt , r , stdin); //freopen( a.out , w ,std...
#include <bits/stdc++.h> int fr[182], ne[362], v[362], bs = 0; void addb(int a, int b) { v[bs] = b; ne[bs] = fr[a]; fr[a] = bs++; } int dp[182][182], wz[182], sz[182], cd[182][182], n, k; int fa[182], sd[182], ans[182], zy[362][182]; void dfs0(int u, int f) { fa[u] = f; sd[u] = sd[f] + 1...
#include <bits/stdc++.h> using namespace std; long double EPS = 1e-9; long long cel(long long a, int b) { return ((a - 1) / b + 1); } long long gcd(long long a, long long b) { if (a < b) swap(a, b); return (b == 0) ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return (a * b) / gcd...
#include <bits/stdc++.h> using namespace std; int main() { int n; long long l; cin >> n >> l; long double arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); long double ans = arr[0] - 0; for (int i = 1; i < n; i++) { ans = max(ans, (arr[i] - ar...
#include <bits/stdc++.h> using namespace std; long long flag, cnt, j, i, k, powe, count1, count2; long long int n, a, b, c, x, y, m, ans; long long maxy, miny, sum, ann[1000010]; string s, s2; long long mod = 1000000007; int main() { cin >> n; n--; long long arr1[n], arr2[n]; for (i = 0; i...
#include <bits/stdc++.h> using namespace std; map<string, string> m; string a = ......... ; inline int judge() { for (int i = 0; i < 3; i++) { if (a[3 * i] != . ) if (a[3 * i] == a[3 * i + 1] && a[3 * i] == a[3 * i + 2]) return 3 * i; if (a[i] != . ) if (a[i] == a[i + 3] && a[...
#include <bits/stdc++.h> using namespace std; int c[100001], s[100001]; int mx, ans, n, nc, ns; int i, j; void checkAns(int k) { if (ns <= 2) { if ((mx - 1) * nc == (i - 1) || mx * (nc - 1) == (i - 1)) { if (s[1] == 1 || s[1] == i || 1 == nc || s[mx] == 1) { ans = i; } ...
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define vi vector<int> #define pi pair<int,int> #define F first #define S second #define pb push_back #define mp make_pair #define FOR for(int i=a;i<b;++i) #define sq(a) (a)*(a) #define vll vector<long lon...
#include <bits/stdc++.h> using namespace std; int i, t, n, ciel, jiro, aux, a[10005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); for (cin >> t; t; --t) { cin >> n; for (i = 1; i <= n; ++i) { cin >> aux; if (n & 1) if (i == n / 2 + 1) a[++a[...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long n, a[10], C[110][110], dp[110][10], ans; inline long long add(long long x, long long y) { x += y; if (x > MOD) x -= MOD; return x; } inline long long mul(long long x, long long y) { x *= y; if (x > MOD...
#include <bits/stdc++.h> using namespace std; int main() { int n, ans, num; scanf( %d , &n); for (int i = 17; i >= 1; i--) { num = (pow(2, i) - 1) * pow(2, i - 1); if (n % num == 0) { ans = num; break; } } printf( %d n , ans); }
#include <bits/stdc++.h> using namespace std; int n, a[100000]; long long cost, mn; int main() { cin >> n; for (int i = 0; i < n; ++i) scanf( %d , a + i); sort(a, a + n); for (int i = 0; i < n; ++i) mn += a[i] - 1; if (n > 40) return cout << mn, 0; for (int i = 2; i <= 1e5; ++i) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 1e3; long long all[MAXN]; struct node { node *child[2]; node() { child[0] = child[1] = NULL; } }; node *root; deque<short> binary(long long x) { deque<short> ans; while (x) { ans.push_front(x % 2); x /= 2; ...
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; const long long int INF = 1e10; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; char c = s[0]; long long int a = s[1] - 0 ; long long int ans = 0; for (lon...
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> par; vector<int> rank; vector<int> sz; UnionFind(int n = 0) { if (n > 0) initialize(n); } void initialize(int n) { par.resize(n); rank.resize(n); sz.resize(n); for (int i = 0; i < n; i+...
#include <bits/stdc++.h> using namespace std; int main() { int i, k; int n; cin >> n; if (n % 2 == 0) { k = n / 2; cout << k << n ; for (i = 0; i < k; i++) cout << 2 << ; } else { k = (n - 1) / 2; cout << k << n ; for (i = 0; i < k - 1; i++) { c...
#include <bits/stdc++.h> using namespace std; const int N = 100 + 5; int n, m, ord[N << 1], nord = 0; vector<int> adj[N << 1], radj[N << 1]; bool vis[N << 1]; int ncmp = 0, cmp[N << 1]; vector<int> ans; inline void addedge(int u, int v) { adj[u].push_back((v > n ? v - n : v + n)); ; radj[(v ...
#include <bits/stdc++.h> using namespace std; long long t, n; int main() { cin >> t; vector<int> a; for (int i = 1; i <= 10000; i++) { n = i; vector<int> v; while (n > 0) { v.push_back(n % 10); n = n / 10; } reverse(v.begin(), v.end()); for (int j = ...
#include <bits/stdc++.h> int main() { int i, j = 1, x, k = 0; int c, y; int ar[1000]; char str[500]; scanf( %s , str); for (i = 0; str[i] != 0 ; i++) { x = isdigit(str[i]); if (x != 0) { ar[j] = str[i]; j++; k++; } } int pass; for (pass =...
#include <bits/stdc++.h> using namespace std; const long long INF = 2000000000000000000LL; const int inf = 0x3f3f3f3f; const long double EPS = 1e-9; int dirx[] = {0, 0, -1, 1}; int diry[] = {-1, 1, 0, 0}; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int test; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; char s[maxn], t[maxn]; int p[maxn], q[maxn], r[maxn]; int main() { int n, m, k, d; scanf( %s%d , s, &m); n = strlen(s); while (m--) { scanf( %d%d , &k, &d); for (int i = 0; i < n; i++) p[i] = q[i] = i; in...
#include <bits/stdc++.h> using namespace std; const int inf = INT_MAX; const long long int INF = LLONG_MAX; const long long int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); long long int dp[151][10]; dp[1][0] = 1; dp[2][0] = 2; dp[3][0] = 3; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int b[n]; int ans[2 * n]; for (long long i = 0; i < n; i++) cin >> b[i]; set<int> a; for...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,unroll-loops,no-stack-protector ) using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 3005; map<int, vector<int> > dif; vector<int> mod[8]; int a[N]; int n; template <class C, class F> struct Mcm...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int max_length = 1e6; int a_cnt[max_length]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; long long b = 0; long long ans = 0; int n = s.size(); for (i...
#include <bits/stdc++.h> using namespace std; int main() { int no_of_cards; scanf( %d , &no_of_cards); vector<int> card(no_of_cards); for (int i = 0; i < no_of_cards; i++) scanf( %d , &card[i]); if (no_of_cards == 1) { printf( -1 n ); return 0; } vector<int> new_cards; if...
#include <bits/stdc++.h> using namespace std; int n, m; int dmap[45][45]; int ans[45]; int dans[45]; int nans, zans; void dfs(int dn) { if (dn == n + 1) { if (nans > zans) { zans = nans; } return; } int mark = 0; for (int i = 1; i < dn; i++) if (ans[i] == 1 ...