func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> int N; int Weight[300005]; long long SubWeight[300005]; std::vector<int> ADC[300005]; inline void AddEdge(int x, int y) { ADC[x].push_back(y); ADC[y].push_back(x); } long long Max; int Count; void DFS(bool Step, int Node = 1, int Parent = 0) { SubWeight[Node] = Wei...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int id[n]; vector<int> ans(k, -1); for (int i = 0; i < n; i++) { cin >> id[i]; if (find(ans.begin(), ans.end(), id[i]) == ans.end()) { ans.insert(ans.begin(), id[i]); ans.resize(k); ...
#include <bits/stdc++.h> using namespace std; int tt; string input; int main() { cin >> tt; for (int qq = 1; qq <= tt; qq++) { cin >> input; int count[250] = {}; for (char c : input) count[c - a ]++; int diff = 0; for (int i = 0; i < 250; i++) { if (count[i] > 0) d...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const int inf = 0x3f3f3f3f; const long long inff = 0x3f3f3f3f3f3f3f3f; int n; int a[200010]; int dp[200010]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T t) { return t < 0 ? -t : t; } const long long modn = 1000000007; inline long long mod(long long x) { return x % modn; } const int MAXN = 212345; int n, m, k; int s[MAXN]; int main() { scanf( %d , &n); for ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2600; int n, m; char s[60][60]; int addedge[MAXN][MAXN]; int blocks[60][60]; int cnt; int dis[MAXN]; bool inside(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; } vector<int> B; vector<int> e[MAXN]; int dx[] = {-1, 0, 1, 0...
#include <bits/stdc++.h> int S(int x) { return x & 1 ? -(x + 1) / 2 : x / 2; } int main() { int q; scanf( %d , &q); while (q--) { int l, r; scanf( %d%d , &l, &r); printf( %d n , S(r) - S(l - 1)); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; int m; cin >> n >> m; int a[6]; int b[6]; for (int i = 1; i < 6; i++) { if (n % 5 >= i) { a[i] = (n / 5) + 1; } else { a[i] = n / 5; } } for (int i = 1; i < 6; i++) { if (m % 5 >...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a < 0) a = -a; if (b < 0) b = -b; return b == 0 ? a : gcd(b, a % b); } template <typename T> void read(T &res) { bool flag = false; char ch; while (!isdigit(ch = getchar())) (ch == - ) && (flag...
#include <bits/stdc++.h> using namespace std; void _read(); const int nax = 2001; const int inf = 1e9 + 11; void NO() { cout << NO n ; exit(0); } int mat[nax][nax]; using tp = tuple<int, int, int>; struct Solution { int n; bool in_a[nax]; vector<vector<pair<int, int>>> adj; vo...
#include <bits/stdc++.h> using namespace std; string tsize[] = { S , M , L , XL , XXL }; int a[6]; int main() { int n = 5; for (int i = 0; i < 5; i++) { cin >> a[i]; } int m; cin >> m; for (int k = 0; k < m; k++) { string tshirt; cin >> tshirt; int tcode = 0; ...
#include <bits/stdc++.h> using namespace std; const int N = 300500; int n, a[N]; vector<int> v; int cnt[N]; vector<int> all; int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); v.push_back(a[i]); } sort(v.begin(), v.end()); v.resize(unique(v.beg...
#include <bits/stdc++.h> using namespace std; int mod; unsigned long long work(vector<int> &x) { sort(x.begin(), x.end()); int n = x.size(); int m = x.end() - unique(x.begin(), x.end()); unsigned long long ret = 1; for (int i = 2; i <= n; i++) { unsigned long long tmp = i; while (m...
#include <bits/stdc++.h> using namespace std; int main() { string s; int i, count1 = 0, count = 0; cin >> s; for (i = 0; i < s.length(); i++) { if (s[i] == 1 ) { count++; count1 = 0; if (count == 7) { cout << YES ; return 0; } } else ...
#include <bits/stdc++.h> using namespace std; const int N = 5009; struct edge { int to, nxt; } e[N * 2]; int hd[N], tot; void add(int u, int v) { e[++tot] = (edge){v, hd[u]}; hd[u] = tot; } int n, leaf, lcnt[N], l[N]; void dfs1(int u, int fa) { for (int i = hd[u], v; i; i = e[i].nxt) {...
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 5; const int MAXM = 2e6 + 5; char s[MAXN]; vector<int> v[MAXN]; multiset<int> ss[MAXN]; int trie[MAXN][26], fail[MAXN]; int pos[MAXN], dat[MAXN], siz[MAXN]; int fa[MAXN], dep[MAXN], top[MAXN], dfn[MAXN]; int rev[MAXN], son[MAXN], d...
#include <bits/stdc++.h> using namespace std; int n, m; char a[60][60], b[60][60]; int dir[4][2] = {0, 1, 1, 0, -1, 0, 0, -1}; struct node { int x, y, sum; }; node ans[2600]; bool cmp(node a, node b) { return a.sum < b.sum; } int bfs(int x, int y) { queue<node> q; node t, next; t.x = x...
#include <bits/stdc++.h> using namespace std; struct cell { int x, y, cost; cell(int i, int j, int k) { x = i; y = j; cost = k; } }; int main() { int n, m, s; scanf( %d%d%d , &n, &m, &s); s--; int t1, t2, t3; vector<vector<pair<int, int> > > g(n); vector<int...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long cs = 1, t = 15, ar[100], n; while (t--) { long long ans = 0; n = cs; map<long long, long long> mp; for (long long i = 0; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<string> a(n); for (long long i = 0; i < n; ++i) { cin >> a[i]; } unordered_set<char> diagonal, non_diagonal; for (long long i = 0; i < n; ++i) { for (long long j = 0; j < n; ++j) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int dif[n]; memset(dif, 0, sizeof(dif)); int ans = 0; for (i...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int ans = 0; for (int i = 0; i < s.size(); i++) { if (((s[i] - 0 ) % 2) == 0) { ans = ans + i + 1; } } cout << ans; }
#include <bits/stdc++.h> using namespace std; vector<int> v[200005]; vector<int> par(200005, -1); vector<int> ran(200005, 1); int fi(int c) { while (1) { if (par[c] == -1) return c; else c = par[c]; } } int main() { int n, m; cin >> n >> m; long long int a[n...
#include <bits/stdc++.h> using namespace std; int main() { int N, n, m, min, max; while (cin >> N) { n = N % 7; if (n <= 2) { max = N / 7 * 2 + n; min = N / 7 * 2; } else if (n == 6) { min = N / 7 * 2 + 1; max = N / 7 * 2 + 2; } else { min = N ...
#include <bits/stdc++.h> using namespace std; long long n, pos, kol; long long a[1000]; int main() { cin >> n; for (long long i = 1; i <= 2 * n; ++i) cin >> a[i]; for (long long i = 1; i < 2 * n; ++i) { for (long long j = i + 1; j <= 2 * n; ++j) { if (a[i] == a[j]) { pos = j;...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char 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(); } r...
#include<iostream> #include<cstring> #include<cstdio> #include<climits> #include<algorithm> #include<queue> #include<vector> #define int long long #define pii pair<int,int> #define mp make_pair #define pb push_back #define fi first #define se second using namespace std; inline int read(){ ...
#include <bits/stdc++.h> using namespace std; int a[51]; long long c[51][51]; double dp[51][51][51]; bool state[51][51][51]; double cal(int stu, int room, int mval) { if (state[stu][room][mval]) return dp[stu][room][mval]; state[stu][room][mval] = true; double &ret = dp[stu][room][mval]; if ...
#include <bits/stdc++.h> using namespace std; int N, M; pair<pair<long long, long long>, int> range[200000 - 1]; pair<long long, int> bridge[200000]; priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > rends; int ans[200000 - 1]; int ...
#include <bits/stdc++.h> using namespace std; int main() { int s; cin >> s; while (s) { int n, a, b, c, d; bool status = true; cin >> n >> a >> b >> c >> d; int rangem = (a - b) * n, rangeM = (a + b) * n; if (((c + d) < rangem) || (c - d) > rangeM) status = false; if ...
#include <bits/stdc++.h> using namespace std; long long num[200000]; int sn = 0, asn = 0, save[200000], as[200000], m, n; struct str { int v, x; long long l, c; } str[200000]; void pre1() { scanf( %d , &m); int i, j; for (i = 0; i < m; i++) { scanf( %I64d , &str[i].v); if (st...
#include <bits/stdc++.h> using namespace std; void setIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const long long N = 3e2 + 0; const long long M = 5e5 + 5; const long long L = 2e1 + 1; const long long inf = 9e17; const long long mod = 1e9 + 7; long long xyz = 1; long ...
#include <bits/stdc++.h> using namespace std; int odd[2000], even[2000]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n * n; i += 2) { odd[(i - 1) / 2] = i; } for (int i = 2; i <= n * n; i += 2) { even[i / 2 - ...
#include <bits/stdc++.h> using namespace std; const long long N = 5e3 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e18 + 7; const long long infll = 1e18 + 7; long long n, k, X, Y, Z; long long a[(long long)3e5 + 5]; long long dp[N][N]; signed main() { ios_base::sync_w...
#include <bits/stdc++.h> using namespace std; int a[100][100]; int main() { int n, m, z, sum, sum2, ans = 1e9, temp; scanf( %d %d %d , &n, &m, &z); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) scanf( %d , &a[i][j]); if (n > 10) for (int i = 0; i < n; i++) { temp = 0;...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<long long> arr(n); for (long long i = 0; i < n; ++i) { cin >> arr[i]; } sort(arr.begin(), arr.end()); long long grp = 0; long long ptr = 0; unordered_map<long long, long long> mp; ...
#include <bits/stdc++.h> using namespace std; long long a[100005]; void solve() { long long n; cin >> n; for (long long i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); vector<long long> ans; long long st = 0, end = n - 1; while (end > st) { ans.push_back(a[end]); ans.push_b...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int n, v[200000], m[200000]; long long s[200000]; pair<int, int> p[200000]; unordered_map<int, vector<pair<int, long long> > > mp; bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } int main() { sc...
#include <bits/stdc++.h> using namespace std; inline int in() { int32_t x; scanf( %d , &x); return x; } inline long long lin() { long long x; scanf( %lld , &x); return x; } inline int mul(int a, int b) { long long x = a; x *= (long long)b; if (x >= 1000000007) x %= 100000...
#include <bits/stdc++.h> using namespace std; const int ans[] = {0, 4, 10, 20, 35, 56, 83, 350 - 234, 400 - 245, 450 - 252, 500 - 256}; int main() { int n; cin >> n; if (n <= 10) cout << ans[n] << endl; else cout << 1LL * n * 50 - n - 2...
#include <bits/stdc++.h> using namespace std; int n, last; struct rec { int s, t; } da[50100]; bool cmp(rec a, rec b) { if (a.s < b.s) return true; if (a.s > b.s) return false; if (a.t < b.t) return true; return false; } int main() { scanf( %d , &n); for (int i = 1; i <= n; i++...
#include <bits/stdc++.h> using namespace std; int N; long long A[10], rem[10]; int totnum, numv[10], pos[10], tat[10]; int result = 0x3f3f3f3f; inline bool compare(const int& i1, const int& i2) { return numv[i1] > numv[i2]; } void Back(int x) { if (x == N + 1) { int num0 = 0; for (in...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; const int SZ = 110; const int INF = 1000 * 1000 * 1000; double start, finish; void prepare(string s) { if ((int)s.size() != 0) { freopen((s + .in ).c_str(), r , stdin); freopen((s + .out ).c_str(), ...
#include <bits/stdc++.h> using namespace std; void RI() {} template <typename... T> void RI(int& head, T&... tail) { scanf( %d , &head); RI(tail...); } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; RI(n); cout << YES << endl; while (n--) { int x1, y1, x2, y...
#include <bits/stdc++.h> using namespace std; bool point[2002][2002]; int N; int x[3000], y[3000]; const int offset = 1001; int main() { while (scanf( %d , &N) != EOF) { memset(point, 0, sizeof point); for (int i = 0; i < N; ++i) { scanf( %d%d , &x[i], &y[i]); point[x[i] + of...
#include <bits/stdc++.h> using namespace std; int head[(1000 + 10)], to[(1000 + 10) * (1000 + 10)], pre[(1000 + 10) * (1000 + 10)], tot; bool vis[(1000 + 10)], color[(1000 + 10)]; int tag[(1000 + 10)], cc, L[(1000 + 10)], dis[(1000 + 10)]; int n, m; void adde(int u, int v) { to[++tot] = v, pre[tot] = ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; const long long INF = 1e18; const long long LIMIT = 1500000LL * 1500000LL; vector<int> V; int ans[MAXN]; struct node { long long x, y, pos; long long dis() { return x * x + y * y; } }; node p[MAXN]; bool cmp(node A, node...
#include <bits/stdc++.h> const int N = 120005; int n, p[N], m; int stack1[N], top1, stack2[N], top2; struct query { int l, r, id; } q[N]; bool operator<(query a, query b) { return a.r < b.r; } int min[N << 2], num[N << 2], tag0[N << 2], tag1[N << 2]; long long sum[N << 2], ans[N]; void build(int o...
#include <bits/stdc++.h> using namespace std; inline long long isqrt(long long k) { long long r = sqrt(k) + 1; while (r * r > k) r--; return r; } inline long long icbrt(long long k) { long long r = cbrt(k) + 1; while (r * r * r > k) r--; return r; } inline long long mnz(long long& a,...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const int EPS = 1e-6; const int mod = 1000000007; const long double PI = 3.14159265359; const int dx4[4] = {0, 1, 0, -1}; const int dy4[4] = {-1, 0, 1, 0}; const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; const int dy8[8] = {-1, 0,...
#include <bits/stdc++.h> using namespace std; const int N = 2005; int n; long long dp[N], a[N], ans, k, l[N], r[N]; int main() { scanf( %d%lld , &n, &k); for (int i = 1; i <= n; ++i) scanf( %lld%lld%lld , l + i, r + i, a + i); int flag = 0; for (int i = n; i >= 1; --i) { if (r[i] == l[i ...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 11; int n, m; int cha[N], fa[N]; int dfn[N], tot, sz[N]; int U, V; int head[N], nex[N << 1], to[N << 1], size = 1; bool vis[N << 1]; int fr[N]; int dl[N], zh[N], tp; void add(int x, int y) { to[++size] = y; nex[size] = head[...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long x1, y1; long long d = gcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b); return d; } bool find_an...
#include <bits/stdc++.h> using namespace std; long long int a, b, x1, y, x2, y2; int main() { cin >> a >> b >> x1 >> y >> x2 >> y2; long long int da; long long int k1 = x1 + y; long long int k2 = x2 + y2; long long int mi = min(k1, k2); long long int ma = max(k1, k2); long long int c =...
#include <bits/stdc++.h> using namespace std; long long m; int matrix[2][2] = {{3, 1}, {0, 1}}; class Matrix { public: long long c[2][2]; Matrix() { for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) c[i][j] = 0; } void deal() { for (int i = 0; i < 2; i++) for...
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1); void boos() { ios_base ::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void file() { freopen( array.in , r , stdin); freopen( array.out , w , stdout); } const long long INF = 1e9 + 7; const int INF1...
#include <bits/stdc++.h> using namespace std; int n, m, q, e[65][65][65], d[65][65][65]; int main() { scanf( %d %d %d , &n, &m, &q); for (int i = (1); i <= (n); i++) for (int j = (1); j <= (n); j++) for (int k = (0); k <= (n); k++) d[i][j][k] = 1e9; for (int i = (1); i <= (m); i++) { ...
#include <bits/stdc++.h> using namespace std; int n, m; int main() { scanf( %d%d , &n, &m); if (m == 3) { if (n == 4) { printf( 0 0 n3 0 n0 3 n1 1 n ); return 0; } if (n >= 5) { printf( -1 n ); return 0; } } for (int i = 0; i < m; i++) printf...
#include <iostream> #include <algorithm> using namespace std; int INF = 2e9; int pre[200001]; struct node{ int l, r, max, min; } segtree[800001]; void build(int ind, int l, int r){ if (l == r){ segtree[ind] = (node){l, r, pre[l], pre[l]}; } else { build(2*ind...
#include <bits/stdc++.h> using namespace std; char b[9], s[9]; struct tm t; int k, i; string m(int i) { if (i == 8) return September ; t.tm_mon = i; strftime(b, 9, %B , &t); return b; } int main() { cin >> s >> k; for (;; i++) if (m(i) == s) return cout << m((i + k) % 12), ...
#include <bits/stdc++.h> int main() { char ai[105]; while (~scanf( %s , ai)) { int t = 1, max = 1; for (int i = 0; ai[i] != 0 ; i++) { if (ai[i] != A && ai[i] != E && ai[i] != I && ai[i] != O && ai[i] != U && ai[i] != Y ) { t++; max = max > t ? ...
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; int mx[maxn << 2], ls[maxn << 2], rs[maxn << 2], lp[maxn << 2], rp[maxn << 2]; bool col[maxn << 2]; void make(int rt, int l, int r) { lp[rt] = l; rp[rt] = r; ls[rt] = rs[rt] = r - l + 1; mx[rt] = (ls[rt] - 1) / 2; col[r...
#include <bits/stdc++.h> using namespace std; ifstream in; ofstream out; const long long kk = 1000; const long long ml = kk * kk; const long long mod = ml * kk + 7; const long long inf = ml * ml * ml + 7; long long n, i, j; vector<long long> m; vector<pair<long long, long long> > x; bool viv = fal...
#include <bits/stdc++.h> using namespace std; int main() { long long x; while (cin >> x) { long long c = x / 2, t = 0; if (x % 2 == 1) c--, t = 1; cout << c + t << endl; for (int i = 0; i < c; i++) cout << 2 ; for (int i = 0; i < t; i++) cout << 3 ; cout << endl; ...
#include <bits/stdc++.h> using namespace std; const long long MX = 6e4, C = 10, L = 20; long long nxt[MX][C], sz; bitset<170> b[MX]; unordered_map<bitset<170>, long long> id; inline long long low_bit(bitset<170> s) { for (long long i = 0; i < 10; i++) if (s.test(i)) return i; return -1; } ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 202020, INF = 0x3f3f3f3f; vector<int> G[MAXN], iG[MAXN]; int n, m, k, p[MAXN]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= m; ++i) { static int u, v; scanf( %d%d , &u, &v); G[u].push_back(v); iG[v].push...
#include <bits/stdc++.h> using namespace std; const long double INF = 1e20; vector<pair<long double, long double> > vec; struct Line { long double m, c; Line(long double x, long double y) { m = x; c = y; } long double Get(long double x) { return m * x + c; } bool operator<(const ...
#include <bits/stdc++.h> using namespace std; template <class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template <class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } const int MAXN = 52; const int MAXM = 113; const int MAXT = 20013; const int INF = 1000000007; con...
#include <bits/stdc++.h> using namespace std; const int dx[9] = {-1, 0, 1, 0, -1, -1, 1, 1, 0}; const int dy[9] = {0, 1, 0, -1, -1, 1, -1, 1, 0}; long long n; void solve() { int a = sqrt(n); int b = cbrt(n); int c = sqrt(cbrt(n)); cout << a + b - c << n ; } int main() { ios::sync_wit...
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)2e5 + 5; const int MOD = 998244353; int bit[MAXN]; bool got[MAXN]; int p[MAXN]; void gcd(long long a, long long b, long long& x, long long& y) { if (b == 0) { x = 1; y = 0; return; } gcd(b, a % b, y, x); ...
#include <bits/stdc++.h> using namespace std; char a[15][15], b[15][15], t[15][15]; int n; void copy() { for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) t[i][j] = a[i][j]; } int check() { for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (a[i][j] != b[i][j]) retu...
#include <bits/stdc++.h> using namespace std; int n, cnt; bool f; vector<int> p, m, z; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { int x; scanf( %d , &x); if (x < 0) m.push_back(x); if (x > 0) p.push_back(x); if (x == 0) z.push_back(x); } printf( 1...
#include <bits/stdc++.h> using namespace std; const int inf_int = 2e9; const long long inf_ll = 2e18; int Gcd(int p, int q) { return q == 0 ? p : Gcd(q, p % q); } int Pow(int p, int q) { int ans = 1; while (q) { if (q & 1) ans = ans * p; p = p * p; q >>= 1; } return ans; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, b; scanf( %d , &n); int a = sqrt(n); if (n % a == 0) b = n / a; else b = n / a + 1; printf( %d , (a + b) * 2); }
#include <bits/stdc++.h> using namespace std; long long tu[2000001], tu1[2000001]; int main() { long long n, m; cin >> n; long long q; map<long long, long long> wp; for (long long a = 1; a <= n; a++) { scanf( %I64d , &q); wp[q]++; } cin >> m; for (long long a = 1; a <= ...
#include <bits/stdc++.h> using namespace std; int main() { long long t, n, i; cin >> t; while (t--) { cin >> n; if (n == 1) { cout << -1 n ; continue; } cout << 2 ; for (i = 2; i <= n; i++) { cout << 9 ; } cout << endl; } retur...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) const long long INF = 1e9 + 7; const long long maxn = 2e5 + 7; using namespace std; void solve() { long long a, b, c, d; cin >> a >> b >> c >> d; long long ans = 0; for (long long z = c; z < d + 1; z++) { long long r1 = z - c + 1; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 5, mod = 1e9 + 7; int koszt[31], tmp[31]; int main() { int a, b, c, d, e, f, g, z, k, n, m, q; scanf( %d , &n); for (a = 1; a <= 30; a++) koszt[a] = 1000000000; while (n--) { scanf( %d , &a); if (a == 1000) { ...
#include <bits/stdc++.h> using namespace std; map<int, int> m; int main() { int long long n; cin >> n; int long long arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); int long long a = 0, b = 0; if (arr[0] == arr[n - 1]) { cout << 0 << << n ...
#include <bits/stdc++.h> using namespace std; vector<long long int> xi; vector<long long int> hi; int main() { long long int n, x, h, ans = 1, temp, temp1, curr, i; scanf( %lld , &n); for (i = 0; i < n; i++) { scanf( %lld %lld , &x, &h); xi.push_back(x); hi.push_back(h); } ...
#include <bits/stdc++.h> using namespace std; struct single_node { long long total; long long prefix; long long suffix; }; vector<pair<long long, pair<int, int> > > v; set<int> bounds; long long a[300000 + 50]; long long d[300000 + 50]; long long c[300000 + 50]; long long lazy[1200000 + 50...
#include <bits/stdc++.h> using namespace std; void preKmp(char *src, int m, int *rule) { int i = 0, j = -1; rule[0] = j; while (i < m) { while (j != -1 && src[j] != src[i]) j = rule[j]; i++, j++; if (j >= m) rule[i] = rule[j - 1]; else rule[i] = j; } } int...
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 10; int n, a[N], vis[N]; int main() { scanf( %d , &n); int64_t ans = 0; int f = 0, g = 1, pos = 0; for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); ans += abs(a[i] - i); if (a[i] == 1) continue; if (a[i] ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a[1010], maxx = -1, res[1010], ans = 0; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; if (res[a[i]] > 0) res[a[i]]++; else res[a[i]] = 1; maxx = max(maxx, res[a[i]]); } maxx =...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; if (n - a > b + 1) { cout << b + 1 << endl; } else { cout << n - a << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long a, b, sum = 0; cin >> a >> b; while (a > 0 && b > 0) { if (a < b) swap(a, b); sum += a / b; a = a - b * (a / b); } cout << sum << endl; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; int a[n + 1]; a[0] = 0; for (i = 1; i <= n; i++) { cin >> a[i]; } if (n == 2) { cout << NO ; return 0; } for (i = 1; i <= n; i++) { int x; x = a[i]; x = a[x]; ...
#include <bits/stdc++.h> using namespace std; template <typename T> std::ostream& operator<<(std::ostream& str, const std::vector<T>& v) { str << [ ; for (auto n : v) str << n << , ; str << ] ; return str; } template <typename K, typename V> std::ostream& operator<<(std::ostream& str, co...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, x, y; scanf( %d , &t); while (t--) { scanf( %d%d%d , &n, &x, &y); int d, dif = y - x; for (int i = 1; i <= dif; i++) { if (dif % i == 0 && (dif / i <= n - 1)) { d = i; break; } ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const long long INF = 1e18 + 5; const int MAXN = 1e6; const int base = 317; const long long bs = 1e5 + 1; const long long mod = 998244353; struct node { node *left, *right; int val; node(node* l = NULL, node* r = NULL, int ...
#include <bits/stdc++.h> const int inf = 0x7f7f7f7f; inline void gettime() { ; } inline int read() { static char c; static int x; int flag = 1; while (c = getchar(), !isdigit(c)) if (c == - ) flag = -1; x = c - 0 ; while (c = getchar(), isdigit(c)) x = (x << 1) + (x << 3) + c - 0 ...
#include <bits/stdc++.h> using namespace std; const long long N = 3e6; long long n, m; long long a[N]; long long read(void) { long long s = 0, w = 0; char c = getchar(); while (c < 0 || c > 9 ) w |= c == - , c = getchar(); while (c >= 0 && c <= 9 ) s = s * 10 + c - 48, c = getchar(); ...
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7, P = 1e7 + 19; const int N = 200005; int nt = 1, k, n, Q, x, y, tot, op; long long pm(long long x, long long p) { long long res = 1; while (p) { if (p & 1) res = res * x % M; p >>= 1; x = x * x % M; } r...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 201; inline void NEXT(const char *T, int *next, int t_len) { next[0] = -1; for (int i = 1; i < t_len; i++) { int j = next[i - 1]; while (j >= 0 && T[i - 1] != T[j]) j = next[j]; if (j >= 0 && T[i - 1] == T[j]) next[i...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { x = 0; int f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == - ) f = -1; for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - 0 ; x *= f; } int t,...
#include <bits/stdc++.h> #include <iostream> #define ll long long using namespace std; const long long mod=998244353; const long long mod2=1ll<<32; const double pi = 2 * acos(0.0); const ll N=200001; bool compare(pair<int,int> quan1,pair<int,int> quan2) { return quan1.second <quan2.s...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[5] = {0}; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; arr[tmp]++; } int ret = arr[4]; ret += min(arr[1], arr[3]); ret += arr[2] / 2; if (arr[3] > arr[1]) { ret += ar...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long inf = 0x3f3f3f3f3f3f3f3f; const long long mod = 1e9 + 7; const int N = 2e5 + 10; int T; int n, m; int cnt[1000][2], mz[40][40]; int main() { scanf( %d , &T); while (T--) { scanf( %d%d , &n, &m); ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; int N, M, dx, dy; int xidx[MAXN]; int cnt[MAXN]; int ans[MAXN][2]; int main() { cin >> N >> M >> dx >> dy; for (int i = 0; i < N; i++) xidx[((long long)i * dx) % N] = i; for (int i = 0; i < M; i++) { int x, y; ...
#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) { int idx = str.find( , ); cerr << str.substr(0, idx) << : << t << , ; dbs(str.substr(idx +...