func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; vector<int> q[200010], g[200010]; int n, m, a[200010], b[200010]; unsigned long long A, B, C, ans; unsigned long long calc(unsigned long long a, unsigned long long b, unsigned long long c) { unsigned long long s[3] = {a, b, c}; so...
#include <bits/stdc++.h> using namespace std; long long n, a[100005]; int main() { ; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); if (a[n - 1] == 1) a[n - 1] = 2; else a[n - 1] = 1; sort(a, a + n); for (int i = 0; i < n; i++) cout << a[i] << ; ...
#include <bits/stdc++.h> using namespace std; const int N = 2010; int n; string s; int a[N], tot, vis[N]; bitset<N> d, ba[N], sel[N]; void Trans(string s) { reverse(s.begin(), s.end()); while (s.size() % 8) s += 0 ; int L = s.size() / 8; for (int i = 0; i < L; i++) { a[i] = 0; ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; const long long mod = 1000000007; const int N = 201000; int n, y[N]; double k; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) scanf( %d , &y[i]); int b = -1; for (int i = 2; i < n...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> inline T lowbit(T x) { return x & -x; } template <typename S, typename T> void debug(S s, T t) { cerr << s << == << t << n ; } templa...
#include <bits/stdc++.h> using namespace std; long long a[100005], tmp[100005], b[100005]; bool die[100005]; int n, m; vector<long long> candidate; bool solve(int pos) { candidate.clear(); for (int i = 1; i <= n; i++) if ((!die[i]) && (a[i] & (1ll << pos))) { candidate.push_back(a[i]);...
#include <bits/stdc++.h> using namespace std; long long modpow(long long a, long long b, long long m = 998244353) { a %= m; long long res = 1; while (b) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } long long bpow(long long a, long long b) { lo...
#include <bits/stdc++.h> using namespace std; struct node { int st, en; } TV[200010]; bool cmp(node a, node b) { if (a.st == b.st) { return a.en < b.en; } return a.st < b.st; } int main() { int n; int tv1, tv2; int flag; cin >> n; tv1 = -1; tv2 = -1; flag = ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( O3 ) #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) ifstream fin( input.txt ); ofstream fout( output.txt ); bool isPrime(int x) { if (x <= 4 || x % 2 == 0 || x % 3 == 0...
#include<bits/stdc++.h> using namespace std; const int Maxn=2021; const int Mod=998244353; int C[Maxn<<1|5][Maxn<<1|5]; int w[Maxn+5][Maxn+5]; int sum[Maxn+5][Maxn+5]; int ans; void init(){ C[0][0]=1; for(int i=1;i<=(Maxn<<1);i++){ C[i][0]=C[i][i]=1; for(int j=1;j<i;j++){ C[i][j]=(C[i...
#include <bits/stdc++.h> using namespace std; const int N_ = 1050; int N; int P[N_]; char S[N_]; int group[N_]; int find_group(int x) { if (x == group[x]) return x; return group[x] = find_group(group[x]); } void merge_group(int a, int b) { a = find_group(a); b = find_group(b); if (...
#include <bits/stdc++.h> using namespace std; long long int a, b, c, d, n, i, cnt = 0, snt = 0; float f, flo, fload = 0; string s, h, o, name; int main() { ios_base::sync_with_stdio(0); setlocale(LC_ALL, Russian ); ; string t; size_t i; getline(cin, t, n ); while ((i = t.find( ...
#include <bits/stdc++.h> using namespace std; const int maxn = int(3e5) + 5, inf = int(1e9) + 5; int H[maxn], sz[maxn], start[maxn], en[maxn], res[maxn]; pair<int, int> st[4 * maxn]; vector<pair<pair<int, int>, int>> Q; vector<int> dis, graph[maxn]; inline int left(int node) { return (node << 1); } inli...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, a, c1 = 0, c2 = 0; vector<int> v; cin >> n; for (int i = 1; i <= n; i++) { cin >> x; if (x & 1) { x /= 2; for (int j = 1; j <= x; j++) { cin >> a; c1 += a; } cin >> a;...
#include <bits/stdc++.h> using namespace std; struct Point { long long x, y; Point() {} Point(long long a, long long b) : x(a), y(b) {} Point operator-(Point b) { return Point(x - b.x, y - b.y); } }; long long cross(Point x, Point y) { return x.x * y.y - x.y * y.x; } Point st[100005]; int to...
#include <bits/stdc++.h> int main() { long q; scanf( %ld , &q); while (q--) { long n; scanf( %ld , &n); long div = n / 4; if (n <= 3 || n == 5 || n == 7 || n == 11) { puts( -1 ); continue; } if (n & 1) { --div; } printf( %ld n , div);...
#include <bits/stdc++.h> using namespace std; string s; int mynum(int x, int y) { int temp; stringstream ss; ss << (s.substr(x, y - x)); ss >> temp; if (temp > 1000000 || (y - x != 1 && s[x] == 0 ) || x == y) return -1; return temp; } int main() { int mx = -1, x, y, z; cin >> ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 * 100 + 5; int n, l, k; long long a[maxn]; void input() { scanf( %d %d , &n, &l); for (int i = 0; i < n; i++) scanf( %lld , &a[i]); scanf( %d , &k); } long long first() { long long javab = 0, MAX = 0, x; int y; set...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return (b == 0LL ? a : gcd(b, a % b)); } long double dist(long double x, long double arayikhalatyan, long double x2, long double y2) { return sqrt((x - x2) * (x - x2) + ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int size = 31; const int mod = 1e8 + 7; long long hash1[maxn], jec[maxn], hash2[maxn]; int cnt[maxn]; char s[maxn]; int main() { int n; scanf( %d , &n); scanf( %s , s + 1); jec[0] = 1; for (int i = 1; i <= ...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int FFTMOD = 119 << 23 | 1; const int INF = (int)1e9 + 23111992; const long long LINF = (long long)1e18 + 23111992; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long...
#include <bits/stdc++.h> using namespace std; const pair<int, int> queen[8] = {pair<int, int>(-1, 0), pair<int, int>(-1, 1), pair<int, int>(0, 1), pair<int, int>(1, 1), pair<int, int>(1, 0), pair<int, int>(1, -1), ...
#include <bits/stdc++.h> using namespace std; long long N = 10000000000000000; int points = 0; int main() { long long xo, yo, ax, ay, bx, by; cin >> xo >> yo >> ax >> ay >> bx >> by; long long x, y, t; cin >> x >> y >> t; long long X[100], Y[100]; X[0] = xo, Y[0] = yo; for (int i = 1...
#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; const int maxn = 1500 + 5; int count(vector<int>& rec, vector<int>& temp, int l, int h) { if (h - l < 1) r...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, sum; int xx[10005], yy[10005], a[10005]; while (scanf( %d , &n) != EOF) { sum = 0; for (i = 0; i <= n; i++) { scanf( %d %d , &xx[i], &yy[i]); } for (i = 0; i < n; i++) { if (xx[i] == xx[i + 1] &&...
#include <bits/stdc++.h> using namespace std; const int N = 1e8 + 5; long long MAX = 1e9; long long MOD = 1e9 + 7; long long Mod = 1e9 + 7; double EPS = 0.0001; long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } long long lcm(long long a, long long b) { return ((a * b) / gc...
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000LL * 1000000LL * 1000000LL; int n, k; int tyl, l, sum; int T[1000][1000]; int main() { scanf( %d %d , &n, &k); tyl = n * n; for (int i = 1; i <= n; i++) { for (int j = n; j >= k; j--) { T[i][j] = tyl; ...
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; vector<long long> cnt(26, 0); for (auto x : s) { cnt[x - a ]++; } deque<long long> d; for (long long i = 0; i < 26; i++) { if (cnt[i]) { d.push_back(i); } } deque<long long...
#include <bits/stdc++.h> using namespace std; int dx[] = {0, -1, 0, 1}; int dy[] = {1, 0, -1, 0}; int c[2010][2010], edge[2010]; long double s[2010], C[2010][2010]; int main(int argc, char *argv[]) { int n, k; scanf( %d%d , &n, &k); for (int i = (1); i <= (n); ++i) { C[i][0] = 1; for...
#include <bits/stdc++.h> using namespace std; int main() { int n, h, a; vector<int> home, away; cin >> n; vector<int> cnt(100000, 0); vector<int> ans_home(n, 0); vector<int> ans_away(n, 0); for (int i = 0; i < n; i++) { cin >> h >> a; home.push_back(h); away.push_back(a...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const int inf = 1e9; const int N = 1e5; vector<long long int> tot(N); vector<bool> vis(N); vector<int> adj[N]; void dfs(int node) { vis[node] = true; for (auto &i : adj[node]) { if (!vis[i]) { dfs(i); ...
#include <bits/stdc++.h> void Get(int &T) { char C; bool F = 0; for (; C = getchar(), C < 0 || C > 9 ;) if (C == - ) F = 1; for (T = C - 0 ; C = getchar(), C >= 0 && C <= 9 ; T = T * 10 + C - 0 ) ; F && (T = -T); } int L[2005][2005]; int R[2005][2005]; bool Rot; int ...
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f; const double eps = 1e-6; const long long mod = 1000000007; inline string getstr(string &s, long long l, long long r) { string ret = ; for (long long i = l; i <= r; i++) ret.push_back(s[i]); return ret; } long lon...
#include <bits/stdc++.h> using namespace std; int n; vector<pair<int, int>> vp; int chk() { bool ok = true; int d = vp[2].first - vp[1].first; for (int i = 2; i < n; i++) if (vp[i].first - vp[i - 1].first != d) ok = false; if (ok) { printf( %d n , vp[0].second + 1); exit(0); ...
#include <bits/stdc++.h> using namespace std; int buff1, buff2; void solution(vector<int> v) { map<int, int> counter; for (int n : v) counter[n]++; vector<int> counts; for (auto it : counter) { counts.push_back(it.second); } sort(counts.begin(), counts.end(), greater<int>()); int...
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; for (int i = 0, c = 2 % n; i < n - 1; i++, c = (c + i + 1) % n) { if (c) cout << c << ; else cout << n << endl; } cout << endl; return 0; }
#include <bits/stdc++.h> int ss[250000], ff[250000], cc[250000], rr[250000], ii[250000]; int compare(const void *a, const void *b) { int i = *(int *)a; int j = *(int *)b; return rr[i] - rr[j]; } int main() { static int aa[400]; typedef int ian[400]; static ian dp_[400], dq_[400], *dp = d...
#include <bits/stdc++.h> using namespace std; int n, k; int ans; inline int f(int n) { int rt = 0; for (int i = 0; n / pow(k, i) != 0; i++) rt += n / pow(k, i); return rt; } void bin_search() { int s = 1, e = n; int m; while (s <= e) { m = (s + e) / 2; if (f(m) >= n) { ...
#include <bits/stdc++.h> using namespace std; long long f[200][200], a[200], x[200], y[200], d; int n; long long dist(int i, int j) { return abs(x[i] - x[j]) + abs(y[i] - y[j]); } int main() { cin >> n >> d; for (int i = 2; i <= n - 1; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> x[i] >> ...
#include <bits/stdc++.h> using namespace std; const int mx = 4e5 + 10; int sum[mx]; int x[mx]; int n, m; void add(int x) { while (x <= 2 * n + 1) { sum[x]++; x += x & (-x); } } int query(int x) { int ans = 0; while (x) { ans += sum[x]; x -= x & (-x); } ret...
#include <bits/stdc++.h> using namespace std; void topsort(long long int s, vector<vector<long long int>> &graph, vector<long long int> &vis, vector<long long int> &ans) { vis[s] = 1; for (long long int i = 0; i < graph[s].size(); i++) { if (vis[graph[s][i]] == 0) topsort(graph[s][i], g...
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 11; set<int> ans; int n, m, len; int a[N], b[N], c[N], p[N]; inline void manacher() { c[0] = -2; for (register int i = 0; i <= n + n - 2; ++i) c[++len] = b[i], c[++len] = -1; c[len + 1] = -3; int id = 0, mx = 0; for (regis...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000000 + 1; int a[MAXN], parent[MAXN], rnk[MAXN], p[10 * MAXN]; int n; void make_set(int v) { parent[v] = v; rnk[v] = 0; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> edges; vector<int> g[300001]; int police[300001]; int nearest[300001]; int stat[300001]; void dfs1(int beta, int baap) { int mini = (police[beta] ? 0 : (int)1e9), minpos = (police[beta] ? beta : -1); for (int i = 0; i < g[beta].s...
#include <bits/stdc++.h> using namespace std; void _split(vector<string>& vc, const string& str, char ch) { string temp; for (int i = 0; i <= str.size(); i++) if (i == str.size() || str[i] == ch) { vc.emplace_back(temp); temp = ; } else { temp += str[i]; } } v...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e18; const int MAXN = 3e5 + 10; const int MAXM = 1e4 + 500; const int N = 5600 + 15; const double EPS = 1e-9; double len(complex<long long> a) { return sqrt(a.real() * a.real() + a.imag() * a.imag());...
#include <bits/stdc++.h> using namespace std; pair<int, long long> solve(long long n) { if (!n) return {0, 0}; long long a = 1; while ((a + 1) * (a + 1) * (a + 1) <= n) a++; pair<int, long long> r1 = solve(n - a * a * a), r2 = solve((a * a * a) -...
#include <bits/stdc++.h> using namespace std; unordered_map<int, int> X, pre; unordered_map<int, int>::iterator it; int Find(int u) { it = pre.find(u); if (it == pre.end()) { X[u] = 0; return u; } int v = it->second; int tmp = Find(v); X[u] ^= X[v]; return pre[u] = tmp; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[1000]; int m = 0; for (int i = 0; i < n; i++) { cin >> a[i]; m = max(m, a[i]); } for (int i = 1; i <= m; i++) { for (int j = 0; j < n; j++) a[j]--; bool f[1000]; f[0] = (a[0] >...
#include <bits/stdc++.h> using namespace std; int main() { int tc; cin >> tc; while (tc--) { int test = 0; int t[1005]; int n, x, nb1 = 0, nb2 = 0, i; cin >> n >> x; for (i = 0; i < n; i++) { cin >> t[i]; if (t[i] % 2 == 0) nb1++; else ...
#include <bits/stdc++.h> using namespace std; char a[55][55]; int n, m, x; int dist(int p, int q, int r, int s) { return (p - r) * (p - r) + (q - s) * (q - s); } int ok[128] = {}, appear[128] = {}; char s[1000000]; int main(void) { scanf( %d%d%d , &n, &m, &x); for (int i = 0; i < n; i++) sca...
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const long long ooo = 9223372036854775807ll; const int _cnt = 1000 * 1000 + 7; const int _p = 1000 * 1000 * 1000 + 7; const int N = 300005; const double PI = acos(-1.0); const double eps = 1e-9; int o(int x) { return x % _p; } ...
#include <bits/stdc++.h> using namespace std; vector<vector<int>> gr; vector<long long> c; vector<int> parent; vector<int> size; vector<char> used; void make_set(int v) { parent[v] = v; size[v] = 1; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(paren...
#include <bits/stdc++.h> using namespace std; int n, m, a[100005], b[100005]; int l[100005], r[100005]; using pii = pair<int, int>; using ppi = pair<pii, int>; int tr[100005 * 2]; int get(int k) { int res = 0; for (; k; k -= k & -k) res += tr[k]; return res; } void update(int k) { for ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %i , &n); vector<pair<int, int>> tree(n); for (int x = 0; x < n; x++) { scanf( %i%i , &tree[x].first, &tree[x].second); } sort(tree.begin(), tree.end()); int current_day = 0; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; string s; vector<string> ss; double check(const string& x) { double res = 0; if (x.size() < 3) { for (char c : x) { res = res * 10 + (int)c - 0 ; } return res; } if (x[x.size() - 3] == . ) { for (int i = 0; i < x.siz...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000000000 ) using namespace std; int n; double a[500001], b[500001], p, q; string st; double calc(double y1) { double y2 = 1.; for (int i = 0; i < n; i++) { y2 = min(y2, (1. - (a[i] * y1)) / b[i]); } double ret = p * y1 + q...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; vector<vector<int> > col; vector<vector<int> > adj; int color[N]; void dfs(int v, int p) { set<int> st; int toapply = 1; for (int i = 0; i < col[v].size(); i++) { int c = col[v][i]; if (color[c] != -1) st.insert(col...
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e3 + 100; const long long mod = 1e9 + 7; const long long inf = 1e18; long long n, dsu[maxn], sz[maxn], t[maxn], a[maxn], mx, s, ans; pair<long long, pair<long long, long long> > e[maxn]; void init() { mx = 0; for (long long i = ...
#include <bits/stdc++.h> using namespace std; const int mn = 1e6 + 10; const long long mod = 998244353; int a[100], t[100]; string s[100]; int dp[21][1 << 20]; int main() { int n, m; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , a + i); sort(a, a + n, greater<int>()); scanf(...
#include <bits/stdc++.h> int min(int a, int b) { return a > b ? b : a; } int max(int a, int b) { return a < b ? b : a; } int main() { int n, a, b, c, d, i, pos; int sum, next; while (~scanf( %d , &n)) { int ans = 0; for (i = 1; i <= 4; i++) { scanf( %d%d%d%d , &a, &b, &c, &d); ...
#include <bits/stdc++.h> using namespace std; unsigned long long l, r, x, y; unsigned long long gcd(unsigned long long a, unsigned long long b) { while (b > 0) { unsigned long long t = b; b = a % b; a = t; } return a; } int main() { cin >> l >> r >> x >> y; if (x == y) { ...
#include <bits/stdc++.h> using namespace std; long long i, j, k, l, n, m, c, d, a[2005][2005], b[10005], f, mod = 1e9 + 7; vector<long long> v; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; a[0][0] = 1; for (i = 1; i <= n; i++) for (j = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n; getline(cin, s); while (n--) { getline(cin, s); bool L = false, M = false; if (s.length() < 5) { cout << OMG>.< I don t know! << endl; continue; } if (s.substr(0,...
#include <bits/stdc++.h> using namespace std; int main() { long long t; t = 1; while (t--) { int n; cin >> n; int a[n + 1]; a[1] = 0; for (int i = 2; i <= n; i++) cin >> a[i]; vector<int> v; v.push_back(n); n = a[n]; v.push_back(n); while (n !=...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(false); long long n; cin >> n; set<long long> s = {-2, -1}; vector<long long> arr(n, 0); while (n--) { long long x; cin >> x; --x; if ((*prev(s.end())) > x && (*prev(prev(s.end()))) < ...
#include <bits/stdc++.h> using namespace std; int s[105], d[105], c[105]; int ans[105] = {0}; vector<pair<int, int>> v; int main() { int tc; tc = 1; while (tc--) { int n, m; cin >> n >> m; int flag = 1; for (int i = 1; i <= m; i++) { cin >> s[i] >> d[i] >> c[i]; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int t, n, m, a[3005] = {0}; string ans[3005]; vector<pair<string, int> > v[3005]; map<string, int> mp; map<int, string> mp1; vector<string> v1[3005]; int F(int x, int vis[]) { int i, i1, i2, idx; for (i = 0; i < v1[x].size(...
#include <bits/stdc++.h> using namespace std; long long n, k, a[100100], sum = 0, Min = 1e6; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (a[i] < 0 && k) a[i] *= -1, k--; Min = min(Min, abs(a[i])); sum += a[i]; } if (k ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, MOD = 1e9 + 7; long long power(long long a, long long n) { long long p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } long long power(long long a, long long ...
#include <bits/stdc++.h> using namespace std; const int maxN = 1005, maxD = 10, oo = 1e9; int Len, dp[maxN][maxN]; int t[maxN][maxN], s[maxN], tool[maxN]; int n, perm[maxN], cost[maxD], cnt[maxN][maxD], lost[maxN]; bool flag = 0; inline void solve(int i, int j, int d) { int jp = 0, sum = 0; for (i...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e6 + 7; const int INF = 0x7fffffff; long long c[maxn], s[maxn]; long long a[maxn], num[maxn]; int main() { long long n, x, y; while (cin >> n >> x >> y) { long long ans = n * x; memset(num, 0, sizeof(num)); for (int i ...
#include <bits/stdc++.h> using namespace std; struct st { int x, y; bool operator<(const st o) const { return y < o.y || (y == o.y && x < o.x); } }; long long a[1000000][2]; long long n, m, x, y; long long M[1000000][2]; int main() { cin >> n >> m; cin >> M[0][0] >> M[0][1]; for (int i...
#include <bits/stdc++.h> using namespace std; int yee[6][3] = {{0, 1, 2}, {1, 0, 2}, {1, 2, 0}, {2, 1, 0}, {2, 0, 1}, {0, 2, 1}}; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, x; cin >> n >> x; n %= 6; cout << yee[n][x] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, n; int main() { while (~scanf( %I64d%I64d%I64d%I64d%I64d , &n, &a, &b, &c, &d)) { long long mi = min(b - c, min(a - d, a + b - c - d)), ma = max(b - c, max(a - d, a + b - c - d)); long long num1 = min(n - ma, n), n...
#include <bits/stdc++.h> using namespace std; int binarySearch(int arr[], int l, int r, int x) { while (l <= r) { int m = l + (r - l) / 2; if (arr[m] == x) return m; if (arr[m] < x) l = m + 1; else r = m - 1; } return -1; } bool isprime(int n) { if (n <= 1...
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)(1e5 + 1e1); const double PI = acos(-1.0); long long a, m, t; int main() { cin >> m >> a; if (a == 0 && m > 1) { cout << No solution ; return 0; } cout << a; for (int i = 1; i < m; i++) cout << 0; return 0...
#include <bits/stdc++.h> using namespace std; int main() { bool ok[999]; memset(ok, false, sizeof(ok)); ok[ A ] = true; ok[ H ] = true; ok[ I ] = true; ok[ M ] = true; ok[ O ] = true; ok[ T ] = true; ok[ U ] = true; ok[ V ] = true; ok[ W ] = true; ok[ X ] = true; ...
#include <bits/stdc++.h> int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1}; int dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } long long to_int(string s) { long long ans = 0; for (int i = 0; i < s.size(...
#include <bits/stdc++.h> using namespace std; long long f[2][200500], g[2][200500], sf[2][200500], sg[2][200500], ans; int a, b, k, t; const long long MOD = 1000000007; int main() { scanf( %d%d%d%d , &a, &b, &k, &t); f[0][a + 100210] = 1; g[0][b + 100210] = 1; for (int j = -100000; j <= 100100...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-7; const long long MOD = 1000000007LL; const int INF = 0x3f3f3f3f; const int _NAN = -0x3f3f3f3f; const double EULC = 0.5772156649015328; const int NIL = -1; template <typename T> void read(T &x) { x...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; string s; cin >> s; long long o = 0; long long z = 0; for (long long i = 0; i < n; i++) if (s[i] == n ) o++; else if (s[i] == z ) z++; while (o--) cout << 1 << ; w...
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; int add(int a, int b) { a += b; if (a >= MOD) a -= MOD; if (a < 0) a += MOD; return a; } int mul(int a, int b) { return a * 1ll * b % MOD; } int binpow(int a, int b) { int res = 1; while (b) { if (b & 1) r...
#include <bits/stdc++.h> using namespace std; long long n, cnt = 0; long long a[623456], b[623456], v[9999999]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; v[a[i]] = 1; } for (int i = 1; i <= n; i++) { cin >> b[i]; v[b[i]] = 1; } for (int i ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200010; struct Node { long long dis, mxdis; int id; bool operator<(const Node &rhs) const { if (dis == rhs.dis) return mxdis < rhs.mxdis; return dis < rhs.dis; } } p[MAXN]; struct NO { long long dis, mxdis; int ...
#include <bits/stdc++.h> using namespace std; template <typename T> T modpow(T base, T exp) { T result = 1; while (exp > 0) { if (exp & 1) result = (result * base); base = (base * base); exp >>= 1; } return result; } int main() { queue<string> poss; long long int n, q...
#include <bits/stdc++.h> using namespace std; long long int arr[100005]; map<long long int, int> m; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %I64d , &arr[i]); } for (int i = 1; i <= n; i++) { arr[i] += arr[i - 1]; m[arr[i]]++; } int...
#include <bits/stdc++.h> using namespace std; string solve() { int a, b, n; string number = ; cin >> a >> b >> n; bool added; added = false; a *= 10; for (int j = 1; j < 11; j++) { if (a % b == 0) { added = true; break; } a++; } if (!added) ret...
#include <bits/stdc++.h> using namespace std; vector<int> adj[3003]; int cost[3003], par[3003]; bool vis[3003]; map<pair<int, int>, bool> mark; void path(int x, int y) { if (x == y) return; cost[x] = 0; path(par[x], y); } void dfs(int u) { vis[u] = true; for (int v : adj[u]) { ...
#include <bits/stdc++.h> using namespace std; long long a[200010]; vector<int> v[70]; int main() { int i, j, n; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %lld , &a[i]); for (j = 1; j < 63; j++) { if (a[i] % (1LL << j)) { v[j].push_back(i); break; ...
#include <bits/stdc++.h> using namespace std; char a[100010]; vector<int> qe[710000]; map<pair<int, int>, int> dp; long long hehe[20]; long long find(int x, int y) { int k = y, n = 1; while (k) { n++; k /= 10; } return hehe[n] * x + y; } int get(char a[], int n) { int ans...
#include <bits/stdc++.h> using namespace std; int p[100]; queue<int> q; int main() { ios::sync_with_stdio(false); int n, m, k, t; cin >> n >> m >> k; for (int i = 0; i < k; ++i) cin >> p[i]; for (int i = 0; i < m * n; ++i) { cin >> t; q.push(t); } int an = 0; for (int...
#include <bits/stdc++.h> using namespace std; const string alf = abcdefghijklmnopqrstuvwxyz ; const int hashP = 239017; const int N = 1e5 + 10; const int MOD = 1e9 + 7; const int MOD2 = 998244353; const int INF = 1e9; const long long INF2 = 1e18; template <typename T> bool umn(T &a, T b) { retu...
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; FILE* stream; mt19937 rng(1337); void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < int(n); i++) { cin >> a[i]; } vector<int> b(n); for (int i = 0; i < int(n); i++) { if (i % 2) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, a[4005], b[4005]; bitset<4005> adj[4005]; cin >> n >> m; vector<int> tam(n + 1); for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; adj[a[i]][b[i]] = 1; adj[b[...
#include <bits/stdc++.h> using namespace std; int i, j, k, l, s[4], s_indx = 0, m, n, o, p; int main() { float x[8], y[8], x1, y1, x2, y2, sq = 0, r = 0, indx = 0, a, b, c, d, square[3]; for (int i = 0; i < 8; i++) { cin >> x[i] >> y[i]; } for (i = 0; i ...
#include <bits/stdc++.h> using namespace std; #define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #define FF first #define SS second #define pb push_back #define sz(x) (int)x.size() #define oo 1e9 #define eps 1e-9 #define PI acos(-1.0) #define lb lower_bound #define ub ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n, m; std::cin >> n >> m; if (n == 1 && m == 2) { std::cout << 0 << n ; std::cout << 1 1 << n ; std::cout << 1 2 << n ; std::cout << 1 1 << n ; return 0; } if ...
#include <bits/stdc++.h> using namespace std; int n; int ar[50][50]; int dp[51][51]; bool leaf[50]; vector<int> adj[50]; vector<int> adjw[50]; vector<int> leafs; int bad; vector<int> pos; int go(int rem, int now) { if (rem == 0) { return 0; } if (dp[rem][now] != -1) { retur...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; const int maxn = 5e5 + 5; int n, k; vector<ii> g[maxn]; ll dp[maxn][2]; void solve(int u, int par) { for (ii e : g[u]) { int v = e.first; ll w = e.second; if (v - par) { solve(v, ...