func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; struct dragon { int sila; int dodatek; }; bool operator<(dragon A, dragon B) { return A.sila < B.sila; } int main() { int s, n; cin >> s >> n; vector<dragon> D(n); for (int i = 0; i < n; i++) { cin >> D[i].sila >> D[i].dodatek; } ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-12; const int inf = 2000000000; const long long int infLL = (long long int)1e18; long long int MOD = 1000000007; int MOD1 = 1000000007; int MOD2 = 1000000009; inline bool checkBit(long long int n, long long...
#include <bits/stdc++.h> using namespace std; long long qpow(long long x, long long k, long long mod) { long long ret = 1; while (k) { if (k & 1) { ret = ret * x; ret = ret % mod; } x = x * x; x = x % mod; k = (k >> 1); } return ret; } const int Maxn...
#include <bits/stdc++.h> using namespace std; int n, a[100050], cnt = 0; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) if (a[i] > cnt) cnt++; cout << cnt + 1; return 0; }
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { int N; cin >> N; pair<char, int> list[N]; for (int i = 0; i < N; i++) cin >> list[i].first >> list[i].second; int initial = 0; set<int> presents; for (int i = 0; i < N; i++) { int count = 0; cha...
#include <bits/stdc++.h> using namespace std; const int rozmiar_kubelka = 356; int n, m; vector<int> her; vector<pair<char, int> > mov; int dp[(1 << 20)]; void policz() { dp[0] = 0; int a = 1; for (; a < (1 << m); a++) { int c = __builtin_popcount(a); c = m - c; auto akt = mo...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); long long t; cin >> t; for (long long _ = 0; _ < t; ++_) { long long n; cin >> n; vector<long long...
#include <bits/stdc++.h> using namespace std; char str[1000]; int main() { int n, k; while (scanf( %d %d , &n, &k) == 2) { scanf( %s , str + 1); int left = k - 1; int right = n - k; int di; if (right >= left) { di = 1; for (int i = k; i > 1; i--) printf( LEFT ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int a, b, c, d; cin >> a >> b >> c >> d; if (a * d < c * b) { int g = gcd(b * c - a *...
#include <bits/stdc++.h> using namespace std; int main() { long long int x, y; long double maxd = 0.00000000; long long int ans = 0; long long int n; cin >> n; while (n--) { long long int a, b; cin >> a >> b; ans = max(ans, (a + b)); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int i, j, x[2][4], y[2][4]; pair<int, int> p[2][4]; for (j = 0; j < 2; j++) { for (i = 0; i < 4; i++) { cin >> x[j][i] >> y[j][i]; p[j][i] = {x[j][i], y[j][i]}; } } sort(p[0], p[0] + 4); sort(p[1], p[1] + ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 1e5 + 5; const int mod = 1e9 + 7; vector<int> v[26]; int main() { int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) v[s[i] - a ].push_back(i); int m; cin >> m; while (m-...
#include <bits/stdc++.h> const int N = 100005; int solve(int n, int k, int cnt[]) { if (k == n || cnt[0] == 0 || cnt[1] == 0) { return 1 - cnt[1] % 2; } if ((n - k) / 2 < cnt[0] && (n - k) / 2 < cnt[1]) { if ((n - k) % 2 == 0) return 1; else return 0; } if ((n -...
#include <bits/stdc++.h> using namespace std; int main(){ int T; cin >> T; long long A[114514]; while(T--){ int N; cin >> N; long long S = 0; for(int i = 0; i < N; i++){ cin >> A[i]; S += A[i]; } sort(A, A+N, greater<long long>()); if(S == 0) cout << 0 << n ; else ...
#include <bits/stdc++.h> #define ll long long int #define vi vector<int> #define vll vector<long long int> #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define ABS(x) ((x) < 0 ? -(x) : (x)) #define setpr(x, y) cout << fixed << setprecision(x) << y #define tr(x) cou...
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; long long a[maxn]; int n; long long k; long long d[maxn]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]); long long sum = 0; int num = 0; for (int i = 1; i <= n; i++) { d[i] = s...
#include <bits/stdc++.h> using namespace std; bool check(string s) { int count = 0; for (char el : s) { if (el == ( ) { count++; } else { count--; } if (count < 0) return false; } return true; } void solve() { int n; cin >> n; string s; ci...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j; cin >> n; vector<int> ct[n + 1]; for (i = 0; i < 2 * n; i++) { int x; cin >> x; ct[x].push_back(i); } int p1 = 0, p2 = 0; long long ans = 0; for (i = 1; i <= n; i++) { ans += min(abs(ct[i]...
#include <bits/stdc++.h> const int N = 1e6 + 7; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-7; using namespace std; int a[N], s[N]; map<int, int> asum, ssum; map<int, vector<int> > pos; map<int, int> size; int main() { int n, m, k, S; cin >> m >> k >> n >> S; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long mypow(long long base, long long exp) { long long res = 1; while (exp) { if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod; } return res; } long long gcd(long long a, lo...
#include <bits/stdc++.h> using namespace std; const int maxN = 1000 * 1000 + 5; bool mark[4][maxN]; int n, m, comp; inline void dfs(int x, int y) { if (mark[x][y]) return; mark[x][y] = true; if (x == 0 && y == 1) mark[3][1] = true; if (x == 0 && y == m) mark[1][1] = true; if (x == 1 && y =...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; const long double INF = 2e30; struct node { int id; long double da, db, len; node(int _id = 0, long double _da = 0, long double _db = 0, long double _len = 0) { id = _id; da = _da; db = _db; le...
#include <bits/stdc++.h> using namespace std; long long a, b, n; long long power(long long b, long long p) { if (p == 0) return 1; long long ret = power(b, p / 2); ret *= ret; if (p & 1) ret *= b; return ret; } long long check(long long x) { return a * power(x, n); } int main() { cin...
#include <bits/stdc++.h> int ma[100005]; int main() { int n, k; scanf( %d%d , &n, &k); for (int i = 1; i <= k + 1; i++) { if (i & 1) printf( %d , i / 2 + 1); else printf( %d , k + 2 - i / 2); } int s = (k + 1) / 2 + 1; int e = k + 2 - (k + 1) / 2; for (int i...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long maxn = 2e5 + 5; struct range { long long a, b, c, id; range(long long A, long long B, long long C, long long ID) { a = A; b = B; c = C; id = ID; } }; bool compare(const range &i, ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n; int a[n][2]; for (int i = 0; i < n; ++i) cin >> a[i][0] >> a[i][1]; cin >> k; for (int i = 0; i < n; ++i) { if (a[i][0] <= k && k <= a[i][1]) { cout << n - i; return 0; } } }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long a, b; cin >> a >> b; long long steps = 0; while (b != 0) { steps += (a / b); a %= b; swap(a, b); } cout << steps << endl; return ...
#include <bits/stdc++.h> using namespace std; int a[105], a2[105], n; int getabs() { int e = 0, s = 0, i; for (i = 1; i <= n; i++) { if (a[i] == 1) e++; if (a[i] == -1) s++; } return abs(e - s); } int main() { int k, i, c, b, ans = 0; scanf( %d%d , &n, &k); for (i = 1; ...
#include <bits/stdc++.h> using namespace std; int main() { int ans = 0; int n, m; cin >> n >> m; map<int, int> type; vector<int> a(m); for (int i = 0; i < m; i++) { cin >> a[i]; type[a[i]] += 1; } int sum = accumulate(a.begin(), a.end(), 0); int mel = 0; for (auto...
#include <bits/stdc++.h> using namespace std; int T, n, k; int main() { cin >> T; for (int i = 0; i < T; i++) { cin >> n >> k; if (n % 3 != 0 && k % 3 != 0) { cout << Alice << endl; } else if (n % 3 == 0 && k % 3 != 0) { cout << Bob << endl; } else { n %...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; char s; int rock[4][2]; int k = 0; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { cin >> s; if (s == * ) { rock[k][0] = i; rock[k][1] = j; k++; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 10; int n, m, cnt, counter, b[maxn * maxn], par[maxn][maxn]; char a[maxn][maxn]; vector<pair<int, int> > adj[maxn][maxn]; bool mark[maxn][maxn]; void dfs(int x, int y) { mark[x][y] = true; par[x][y] = cnt; counter++; for...
#include <bits/stdc++.h> using namespace std; int n, m; char ch[5200][5200]; int main() { int top, down, lft, rht; top = down = -1; lft = rht = -1; scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) { scanf( %s , ch[i]); } for (int i = 0; i < n; i++) { bool flag = false; ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; bool flag = 0; int ch = getchar(); while ( 0 > ch || ch > 9 ) { if (ch == - ) flag = 1; ch = getchar(); } while ( 0 <= ch && ch <= 9 ) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar...
#include <bits/stdc++.h> volatile bool isLocalTestEnabled = 0; bool g_isLocalPrintEnabled = (bool)(0); template <typename T> void UpdateMin(T& a, const T b) { a = std::min(a, b); } template <typename T> void UpdateMax(T& a, const T b) { a = std::max(a, b); } const long double Pi = std::atan(1....
#include <bits/stdc++.h> #pragma GCC optimize( O3 , unroll-loops ) using namespace std; template <typename T1, typename T2> inline void checkmin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> inline void checkmax(T1 &x, T2 y) { if (x < y) x = y; } int main() { ios_...
#include <bits/stdc++.h> using namespace std; vector<string> posn(8); int ans[8][8][8]; int movex[9] = {-1, -1, -1, 0, 1, 1, 1, -1, 0}; int movey[9] = {-1, 0, 1, 1, 1, 0, -1, -1, 0}; int dp(int x, int y, int t) { if (t > 7) return 1; if (ans[x][y][t] != -1) return ans[x][y][t]; for (int i = 0; i...
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; typedef pair<int, int> pii; int n, k; char s[300005]; void solve() { while (~scanf( %d%d , &n, &k)) { memset(s, 0, sizeof(s)); s[n + 1] = 0 ;...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, d, b; long long sum[N]; inline int gi() { int x = 0, o = 1; char ch = getchar(); while (ch != - && (ch < 0 || ch > 9 )) ch = getchar(); if (ch == - ) o = -1, ch = getchar(); while (ch >= 0 && ch <= 9 ) x = ...
#include <bits/stdc++.h> using namespace std; const int N = 50010; string g[N]; int q, n, m, ro[N], co[N]; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> q; while (q--) { cin >> n >> m; for (int i = 0; i < n; ++i) cin >> g[i]; for (int i = 0; i < n; ++i) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1.2e5 + 7; int n, m, a[N]; int flag[N << 2], times[N << 2]; long long sum[N << 2], Ans[N]; struct PII { int minn, cnt; } f[N << 2]; PII operator+(PII aa, PII bb) { PII res; res.minn = min(aa.minn, bb.minn), res.cnt = 0; if (aa.m...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast,no-stack-protector ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( unroll-loops ) const int MAX = 2e3 + 10; const int MOD = 1e9 + 7; using namespace std; ...
#include <bits/stdc++.h> using namespace std; struct point { int y, x, kind; }; int main() { int n, m, k, s; cin >> n >> m >> k >> s; vector<vector<int>> a(n, vector<int>(m)); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> a[i][j]; a[i][j]--; }...
#include <bits/stdc++.h> using namespace std; const int P = 998244353; vector<int> L, R; pair<long long, long long> f[25][1500]; long long l, r, dx[25]; int k; pair<long long, long long> dfs(vector<int> w, int pos, int mask, int cnt, int op) { if (pos < 0) return make_...
#include <bits/stdc++.h> using namespace std; int solve() { int n; cin >> n; if (n == 1) cout << 1 << endl; else { cout << n << ; for (int i = 1; i <= n - 1; ++i) cout << i << ; cout << n ; } return 0; } int main() { ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> using namespace std; const int N = 200500; long long a[N]; long long p[N], s[N]; int n, k, x; long long get(int i) { long long res = 0; if (i) res |= p[i - 1]; if (i != n - 1) res |= s[i + 1]; return res | (a[i] * x); } int main() { cin >> n >> k >> x; fo...
#include <bits/stdc++.h> using namespace std; using ld = long double; void run(); signed main() { ios::sync_with_stdio(0); cin.tie(); cout << fixed << setprecision(13); run(); } void print(vector<long long> a) { for (long long i : a) { cout << i << ; } cout << endl; } ...
#include <bits/stdc++.h> using namespace std; const int MAX = 5005; int main() { ios::sync_with_stdio(false); int n; cin >> n; vector<int> a(MAX); for (int i = 0; i < n; i++) { int k; cin >> k; a[k]++; } vector<int> p(MAX); for (int i = 2; i < MAX; i++) { if...
#include <bits/stdc++.h> using namespace std; const int N = 222222; const int mod = 1e9 + 7; long long n; int main() { cin >> n; for (long long i = 1; i * (i + 1) <= n * 2; ++i) { long long x = n - (i * (i + 1) / 2); long long t = sqrt(x * 2); for (long long j = t - 10; j <= t + 10; ...
#include <bits/stdc++.h> using namespace std; struct rec { double x, y; } v, p, w1, w2, m1, m2, p_, m; double eps = 1e-10; inline rec operator+(rec a, rec b) { return (rec){a.x + b.x, a.y + b.y}; } inline rec operator-(rec a, rec b) { return (rec){a.x - b.x, a.y - b.y}; } double mul(rec a, rec b, rec ...
#include <bits/stdc++.h> using namespace std; const int inf = 2e9 + 2; int bound; int dp[220000], n, r, num, ans; int num_del; struct point { int l, r, id; bool operator<(const point &temp) const { if (l == temp.l) return id < temp.id; return l < temp.l; } }; point pt[220000]; ...
#include <bits/stdc++.h> using namespace std; long long read() { char ch = getchar(); long long f = 1, x = 0; while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } return f...
#include <bits/stdc++.h> using namespace std; template <typename T> T prod(const T &a, const T &b, const T &mod) { return ((a % mod) * (b % mod)) % mod; } template <typename T> T pow_(const T &a, const T &b) { if (!b) return 1; T p = pow_(a, b / 2); p *= p; return (b % 2) ? (p * a) : p; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 50005; const long long UP = 2.2e9; long long num[maxn], sum[maxn]; int cnt, wei[15]; inline void init() { long long up = 0, pre = 0, x = 0, cut = 0; cnt = 0; int flag = 0; for (int k = 1; k <= 9; ++k) { cut = x; x = x...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; int a[26]; fill(a, a + 26, 0); for (int(i) = (0); (i) < (s.length()); (i)++) { a[s[i] - a ]++; } int ans = 0; for (int(i) = (0); (i) < (...
#include <bits/stdc++.h> using namespace std; int f(int k) { int p = 1; while ((p * (p + 1)) / 2 < k) p++; if (k == (p * (p + 1)) / 2) return 0; p--; return (p * (p + 1)) / 2; } int main() { int n; int p = 1; cin >> n; int k = int((sqrt((8 * n) + 1)) + 1) / 2; cout << k <...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; while (cin >> a >> b) { if (a == 0 && b == 0) cout << NO << endl; else { if (abs(a - b) == 1 || a == b) cout << YES << endl; else cout << NO << endl; } } return 0;...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, k, p; int odd[N], even[N], po, pe; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> k >> p; for (int i = 0; i < n; ++i) { int x; cin >> x; if (x & 1) ...
#include <bits/stdc++.h> using namespace std; const int N = 505, M = 300005; int a[N][N]; int main() { int n, k; scanf( %d%d , &n, &k); int res = n * k - n + 1, rp = n - k + 1; int ans = 0; int k1 = 0; for (int i = (1); i <= (n); i++) { ans += res; for (int j = (1); j <= (k -...
#include <bits/stdc++.h> using namespace std; map<long long int, long long int>::iterator it; vector<pair<long long int, long long int> > v; map<long long int, long long int> mp; int main() { long long int n; scanf( %lld , &n); for (long long int i = 0; i < n; i++) { long long int l, r; ...
#include <bits/stdc++.h> using namespace std; struct fast_ios { fast_ios() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_; string solve(string S) { const int N = S.length(); int L = N; while (L % 2 == 0) L /= 2; while (L...
#include <bits/stdc++.h> #include <climits> #define F first #define S second #define all(v) v.begin(),v.end() #define li long int #define lli long long int #define pb push_back #define loop(a,b,i) for(lli i=a ; i<b ; i++) #define rev_loop(a,b,i) for(lli i=a ; i>=b ; i--) #define MAX(a,b) (a>b)?a:b ...
#include <bits/stdc++.h> using namespace std; inline int read() { int f = 1, x = 0; char ch; do { ch = getchar(); if (ch == - ) f = -1LL; } while (ch < 0 || ch > 9 ); do { x = x * 10 + ch - 0 ; ch = getchar(); } while (ch >= 0 && ch <= 9 ); return f * x; ...
#include <bits/stdc++.h> using namespace std; int ans[200002] = {0}; void fill() { for (int i = 0; i < 200002; i++) ans[i] = 1e7; } int main() { fill(); int n; cin >> n; int arr[200002]; queue<int> q; stack<int> st; for (int i = 0; i < n; i++) { cin >> arr[i]; if (a...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; long long n, m, l, r; long long binpow(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res % mod; } long long inv(lon...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1; void solve() { long long int n, x, ans = 1, p = -1, q = -1, c; cin >> n; set<long long int> s; long long int a[n]; for (long long int i = 0; i < n; i++) cin >> a[i], s.insert(a[i]); for (long long int i = 0; i < n; i++) {...
#include <bits/stdc++.h> using namespace std; int main() { int hh, mm, h, d, c, n; cin >> hh >> mm; cin >> h >> d >> c >> n; float a; if (h % n == 0) a = (h / n) * c; else a = (h / n + 1) * c; float b; int tim = hh * 60 + mm; if (tim <= 1200) { h += (1200 - tim)...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, m, d, x, ans; cin >> n >> k >> m >> d; ans = m; for (int i = 2; i <= d && (k * i - k + 1) <= n; i++) { x = (n / ((i * k) - (k - 1))); x = min(x, m); ans = max(ans, x * i); } cout << ans << endl; ...
#include <bits/stdc++.h> using namespace std; int n, num[64]; string s[64]; int number(string s1, string s2) { if (s1 == s2) return 0; for (int i = 1; i < s1.length(); i++) { string tail = s1.substr(0, i); string head = s1.substr(i, s1.length() - i); if (head + tail == s2) return i; ...
#include <bits/stdc++.h> using namespace std; long long k = 1000003; long long exp(long long p, long long q) { if (q == 1) return (long long)p; if (q == 0) return 1; long long temp = (long long)(exp(p, q / 2) % k); if (q % 2 == 0) { return (long long)((temp) * (temp)) % k; } else { ...
//#include bits/stdc++.h #define _USE_MATH_DEFINES #include<cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <deque> #include <algorithm> #include <functional> #include <iostream> #include <list> #include <map> #include <array> #include <unordered_map> #include<un...
#include <cstdio> #include <iostream> #include <cstring> #include <queue> using namespace std; const int M = 2005; const int inf = 0x3f3f3f3f; #define int long long int read() { int x=0,f=1;char c; while((c=getchar())< 0 || c> 9 ) {if(c== - ) f=-1;} while(c>= 0 && c<= 9 ) {x=(x<<3)+(x<<1)+(...
#include <bits/stdc++.h> using namespace std; long long int n, m, modu = 1e9 + 7, prod = 1, sum = 0; long long int power(long long int x, long long int y) { if (y == 0) return 1; if (y & 1) return (x * power((x * x) % modu, y >> 1)) % modu; return power((x * x) % modu, y >> 1); } long long int com...
#include <bits/stdc++.h> using namespace std; const int mxN = 1000000; int a[mxN]; void solve() { int n, k; cin >> n >> k; int idx = ceil((double)n / 2); int sub = (n - idx) + 1; for (int i = 0; i < n * k; i++) { cin >> a[i]; } long long ans = 0, cnt = 0; for (int i = n * k...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } return f...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast,no-stack-protector ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; template <typename T> void read(T &a) { T x = 0, f = 1; char ch = getchar(); wh...
/** * created: 25/03/2021, 15:47:17 * pause: 16:11 - 16:18 **/ #include <bits/stdc++.h> using namespace std; const int max_n = 200222, inf = 1000111222; const int max_x = 2 * max_n; vector<long long> all; struct node { int cnt; long long sum, sum_l, sum_r; frien...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int a[MAXN], b[MAXN], pos[MAXN]; map<int, int> zoom; bool vis[MAXN]; int main() { ios::sync_with_stdio(false); int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); b[i] = a[i]; } ...
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; double n; long int sum = 0; for (int i = 0; i < q; i++) { cin >> n; long long int a; for (int j = 0; j < n; j++) { cin >> a; sum += a; } cout << fixed << setprecision(0) << c...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5, MOD = 1e9 + 7; long long k, p, q; string ans; set<long long> s; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> k; if (k < 25) { cout << -1 << endl; return 0; }...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; long long a[100]; long long b[100]; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i]; long long ans = 1000000000000000000LL; for (int i = 1; i <= n; i++) { long...
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; using ll = long long; using ld = long double; const int mod = 1e9 + 7; const int inf = INT_MAX; vector<string> l = { x^y^z , x^z^y , (x^y)^z , (x^z)^y , y^x^z , y^z^x , (y^x)^z , (y^z)^x , ...
#include <bits/stdc++.h> using namespace std; int main() { long long t, n; string s; cin >> t; while (t--) { cin >> n >> s; long long ans = 0, o = 0, ans1 = 0; for (long long i = 0; i < n; i++) { if ((s[i] - 48) % 2 == 1) { ans = (ans * 10) + (s[i] - 48); ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, pos, num[100005]; cin >> n; for (i = 1; i <= n; i++) scanf( %d , &num[i]); pos = upper_bound(num + 1, num + 1 + n, 5e5) - num; if (pos > n) cout << num[n] - 1 << endl; else if (pos <= 1) cout << 1e6 - num[1] ...
#include <bits/stdc++.h> using namespace std; int suspect[100000]; int justify[100000]; bool killer[100000]; pair<int, int> a[100000]; int main() { int n, m; scanf( %d%d , &n, &m); int cnt = 0; for (int i = 0; i < n; i++) { killer[i] = false; char x; int k; scanf( %d ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, j, k, l, a, b, c, d, m, s, f; cin >> n >> m; c = 0; for (i = 1; i <= n; i++) { c++; if (i % m == 0) { n++; } } cout << c << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int Dx[] = {1, -1, 0, 0}; int Dy[] = {0, 0, 1, -1}; double x, y, n, mn = 10000000.0, a, b, i; bool ok(int m) { if (x * i > m * y) return 1; return 0; } int main() { cin >> x >> y >> n; for (i = 1; i <= n; i++) { int s = 0, e = 1e9; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100100; vector<int> v; struct mmp { int to, next, len; mmp() {} mmp(int a, int b, int c) { to = a, next = b, len = c; } } e[maxn << 1]; int vis[maxn], st, ed, cnt, head[maxn], val[maxn], len; void add(int u, int v, int len) { e...
#include <bits/stdc++.h> using namespace std; int main() { int n, b; cin >> n >> b; vector<int> arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } vector<int> s; for (int i = 0; i < n - 1; i++) { if (arr[i] <= b) { int m = INT_MIN; for (int j = i + 1; j < ...
#include <bits/stdc++.h> using namespace std; const int NMAX = 1000 + 5; int n, m, W; int w[NMAX]; int b[NMAX]; vector<int> graph[NMAX]; int comp[NMAX]; void dfs(int node, int cmp) { comp[node] = cmp; for (auto it : graph[node]) if (!comp[it]) dfs(it, cmp); } vector<pair<int, int> > gr...
#include <bits/stdc++.h> using namespace std; struct pkt { int x, y; }; int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; vector<string> p(n); for (int i = 0; i < n; ++i) cin >> p[i]; vector<vector<int> > a(n, vector<int>(m, -1)); for (int k = 0; k < n; ++k) { ...
#include <bits/stdc++.h> using namespace std; struct pt { double x, y; }; pt a[1005]; long long n; double kv(double g) { return g * g; } double dist(pt a, pt b) { return sqrt(kv(a.x - b.x) + kv(a.y - b.y)); } double visina(pt a, pt b, pt c) { return abs((b.y - a.y) * c.x - (b.x - a.x) * c.y + b....
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6; int pref[MAXN + 1]; string S; int n, k; void fast_io() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } pair<int, int> query(int s) { int lo = s, hi = n; int res = -1; while (lo <= hi) { int ...
#include <bits/stdc++.h> using namespace std; template <typename T> void display(T a[], int size) { for (int i = 0; i < size; i++) { cout << a[i] << ; } cout << endl; } void display(vector<pair<int, int> > a) { for (int i = 0; i < a.size(); i++) { cout << ( << a[i].first << ,...
#include <bits/stdc++.h> using namespace std; int n; long long ans = 0x3f3f3f3f3f3f, a[510]; void calc(long long val) { if (!val) return; long long res = 0; for (int i = 1; i <= n; i++) { long long p = a[i] / val, q = a[i] % val; if (p < q) return; res += p - (p - q) / (val + 1); ...
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(const T &a) { return a * a; } int a, b, x, ans; int main() { scanf( %d%d , &a, &b); while (1) { ans += a; x += a; if (x / b == 0) break; a = x / b; x -= (x / b) * b; } printf( %d n , ans)...
#include <bits/stdc++.h> using namespace std; int main() { int z = 0, f = 0, n, a; cin >> n; while (n--) { cin >> a; a == 0 ? z++ : f++; } if (z > 0 && f > 8) { f -= f % 9; while (f--) cout << 5 ; while (z--) cout << 0 ; cout << endl; } else if (z > 0) ...
#include <bits/stdc++.h> using namespace std; int t, n; string s; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> t; while (t--) { cin >> s; n = s.length(); int m = n, M = -1; for (int i = 0; i < n; i++) { if (s[i] == 1 ) { m = min(m, i); ...
#include <bits/stdc++.h> using ll = long long; using namespace std; int n, m; int const N = 3e5 + 2; int const M = (1 << 21); struct Triple { int fi; int se; int th; Triple(int f, int s, int t) : fi(f), se(s), th(t) {} }; struct Compare { bool operator()(const Triple& f, const Triple...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 11; const long long mod = 1e9 + 7; int n, m, k; long long a[N], ans; int par[N], sz[N]; pair<long long, pair<int, int> > b[N]; vector<pair<int, int> > v; vector<int> cur; bool u[N]; int find_set(int v) { if (v == par[v]) return ...