func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; long long ar[200004]; long long prefix[200004]; long long D[200004]; void calc(long n) { D[n] = 0; long long mx = -1000000000000000000; for (long i = n - 1; i >= 1; i--) { D[i] = max(mx, prefix[i + 1] - D[i + 1]); mx = max(mx, D[i]); } ...
#include <bits/stdc++.h> using namespace std; void solve() { int n, i, u; cin >> n >> u; long long int a[n + 2]; bool pos = false; double res = 0; for (i = 0; i < n + 1; ++i) { cin >> a[i]; } int j = 0; for (int i = 0; i < n - 2; i++) { j = max(j, i + 2); while ...
#include <bits/stdc++.h> using namespace std; const int maxn = 99999; int d[maxn], s[maxn]; int n; int m; queue<int> q; vector<pair<int, int> > p; bool inq[maxn]; int main() { cin >> n; for (int i = 0; i < n; i++) { scanf( %d %d , &d[i], &s[i]), m += d[i]; if (d[i] == 1) q.push(i);...
#include <bits/stdc++.h> using namespace std; int n; int a[200005]; int b[200005]; long long sum; int res[200005]; int ge[35]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]), sum += a[i]; for (int i = 1; i <= n; i++) scanf( %d , &b[i]), sum += b[i]; if (n =...
#include<bits/stdc++.h> using namespace std; #define endl n #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield); const int mx=1e5+123; int arr[mx]; long long x,cnt; int main(...
#include <bits/stdc++.h> using namespace std; int q; unsigned long long a, b, c; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> q; while (q--) { cin >> a >> b >> c; unsigned long long sum = a + b + c; cout << sum / 2 << n ; sum = 0; ...
#include <bits/stdc++.h> int a[5000], b[5000], n, m, i, j, k = 0; int main() { scanf( %d%d , &n, &m); for (i = 0; i < n; i++) { scanf( %d , &a[i]); b[i] = a[i]; } for (i = 0; i < n; i++) if (a[i] == b[i]) for (j = 0; j < n; j++) if (a[j] != b[i] && a[i] != b[j]) {...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); srand(42u); unsigned int n; unsigned int m; cin >> n >> m; cout << (min(n, m) & 1 ? Akshat : Malvika ) << endl; return EXIT_SUCCESS...
#include <bits/stdc++.h> using namespace std; int adder[1234567], pre[1234567]; int main() { std::ios::sync_with_stdio(false); long long n, k; cin >> n >> k; int i, l, r; l = 0; r = 0; string s; cin >> s; for (i = 1; i < n; i++) { if (r < i) { l = i; r = i...
#include <bits/stdc++.h> using namespace std; FILE *stm; const double PI = 22.0 / 7.0; const long long MXN = 1e5 + 1; const long long MNN = 1e3 + 1; const long long MOD = 1e9 + 7; const long long INF = 1e18; bool srt(string a, string b) { return a.size() > b.size(); } int gcd(int a, int b) { if (b...
#include <bits/stdc++.h> const int N = 100010; const int M = 25; long long dp[M][N]; int cnt[N], a[N]; long long cost, left, right; void move(int nleft, int nright) { while (nleft < left) cost += cnt[a[--left]]++; while (nright > right) cost += cnt[a[++right]]++; while (nleft > left) cost -= --c...
#include <bits/stdc++.h> using namespace std; string s; string name; string hostname; string res; int is_good(char c) { if (c - a >= 0 && c - a < 26) return 1; if (c - A >= 0 && c - A < 26) return 1; if (c - 0 >= 0 && c - 0 < 10) return 1; if (c == _ ) return 1; return 0; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; int main() { int i, j; int n, pare[maxn], mark[maxn]; while (scanf( %d , &n) != EOF) { memset(pare, 0, sizeof(pare)); memset(mark, 0, sizeof(mark)); for (i = 2; i <= n; i++) { scanf( %d , &pare[i]); ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int k; cin >> k; k += 2000; cout << 2000 << n ; cout << -1 << ; for (int i = 0; i < 1999; i++) { if (k > 1000000) { cout << 1000000 << ; ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( Ofast ) using namespace std; void solve() { long long n; cin >> n; vector<long long> a(n), b(n); for (long long &i : a) cin >> i; for (long long &i : b) cin >> i; sort(a.begin(), a.end()); sort(b.begin(), b.end...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; namespace A { int ch[10001000][2], fail[10001000], end[10001000], cnt; inline int insert(char *s, int id, int *dis) { int len = strlen(s), rt = 0; for (int i = 0; i < len; ++i) { int d = s[i] - a ; if (!ch[rt][d]) c...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, t, cnt = 0, flag, cs = 1; pair<int, int> A[110]; scanf( %d %d , &j, &k); for (i = 0; i < j; i++) { scanf( %d , &A[i].first); A[i].second = i + 1; } sort(A, A + j); vector<int> v; int sum = 0; for ...
#include <bits/stdc++.h> using namespace std; int d[1008][1008]; int main() { int n, x1, x2, y1, y2; int di[] = {0, 0, 1, -1}; int dj[] = {1, -1, 0, 0}; cin >> n >> x1 >> y1 >> x2 >> y2; int i, j, k; d[n - y1][x1] = 1; queue<int> qi, qj, dist; qi.push(n - y1); qj.push(x1); ...
#include <bits/stdc++.h> int main() { using namespace std; ios_base::sync_with_stdio(false); cin.tie(nullptr); string b, b1, b2, e, e1, e2; cin >> b1 >> b2 >> e1 >> e2; swap(b2[0], b2[1]); swap(e2[0], e2[1]); b = b1 + b2; e = e1 + e2; b.erase(b.find( X ), 1); e.erase(e.find...
#include <bits/stdc++.h> using namespace std; int t, k; int a, b; int dp[100005]; int sum[100005]; int main() { scanf( %d%d , &t, &k); for (int i = 1; i <= k - 1; i++) { dp[i] = 1; } dp[k] = 2; for (int i = k + 1; i <= 100000; i++) { dp[i] = (dp[i - 1] + dp[i - k]) % 10000000...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pll; #define all(x) (x).begin(),(x).end() #define X first #define Y second #define sep #define endl ...
#include <bits/stdc++.h> using namespace std; string s; map<char, int> u; int main() { cin >> s >> s; for (auto x : s) ++u[x]; if (u.size() == 1) return puts( Yes ), 0; for (auto& x : u) if (x.second >= 2) return puts( Yes ), 0; puts( No ); }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int n, k; int A[25], B[2]; int fact[25]; int mod(long long int a) { return (a % MOD + MOD) % MOD; } int poww(int pw) { if (pw == 0) return 1; return 3 * poww(pw - 1); } int result = 0; int precompute(int U1) { int ret...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); ; long long int T, N, X; cin >> T; while (T--) { cin >> N >> X; vector<bool> Pl(100100); for (long long int i = 0, P; i < N; i++) { cin >> P; Pl[P - 1] = true; } ...
#include <bits/stdc++.h> using namespace std; set<pair<int, int> > second; int arr[(int)(1e5) + 30]; int main() { int n, m; int u, v; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> u >> v; second.insert(make_pair(u, v)); second.insert(make_pair(v, u)); } for (int i...
#include <bits/stdc++.h> using namespace std; pair<int, int> v[100005]; int a[100008]; int b[100005]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &v[i].first); v[i].second = i; } sort(v, v + n); int val = 0; int qt = (n + 2) / 3; i...
#include <bits/stdc++.h> using namespace std; int main() { int h, m, m2; char c; scanf( %d %c %d , &h, &c, &m); scanf( %d , &m2); m2 += m; int h2 = (int)(m2 / 60); h2 += h; h2 %= 24; m2 = m2 % 60; if (h2 >= 0 && h2 <= 9) printf( 0 ); printf( %d: , h2); if (m2 >= 0 && ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int32_t M = 1e9 + 7; const long long N = 1e6 + 5; void no() { cout << 0 0 0 << endl; } void cpc() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(NULL); } void solve() { long long n; cin >> n;...
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 10, N = 2e4 + 10; const int n = 1e5; long long ans, s[M]; int gcd(int x, int y) { int i = 0, j = 0; if (x == 0) return y; if (y == 0) return x; for (; 0 == (x & 1); i++) x >>= 1; for (; 0 == (y & 1); j++) y >>= 1; if (i ...
#include <bits/stdc++.h> using namespace std; long long t, d, ct, q, ans, l, m, r, n, mx, mn, i, j, k, x, y, z, s; char ch; string ss = , str = ; long long a[200003], b[200003]; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); s = k = d = l = mx = m = mn = r = q = i = j = z = x =...
#include <bits/stdc++.h> using namespace std; int a[200100]; deque<int> Q; bool cnt[10001000]; int main() { int n, m, k; cin >> n >> m >> k; for (int i = 0; i < n; i++) cin >> a[i], cnt[a[i]] = true; sort(a, a + n); int Min = a[0], Max = a[n - 1], Ans = 0; for (int i = Min; i <= 1e7; i...
#include <bits/stdc++.h> using namespace std; int n, a[1003]; const int mod = 1000000007; int comb[1005][1005], i, j; int main() { int lim = 1002; for (i = 1; i <= lim; i++) comb[i][i] = comb[i][0] = 1; for (i = 2; i <= lim; i++) for (j = 1; j < i; j++) { long long aux = comb[i - 1][...
#include <bits/stdc++.h> using namespace std; char buf[5000010], ch; int a[5000010]; int dc[] = {0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}; int sd = 24 * 60 * 60; int main() { int n, m, top = 1; int YY, MM, DD, hh, mm, ss; scanf( %d%d , &n, &m); getchar(); a[0] = 0xc0c0c0...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long long n; cin >> n; for (long long y = 2; y <= 10005; y++) { for (long long z = y + 1; z <= 10005; z++) { if (2 * y * z - n * y - n * z <= 0) continue; long long x = (n * y * z) / (2 * y ...
#include <bits/stdc++.h> using namespace std; int n, x, y, ans; string s; int main() { cin >> n; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == U ) y++; if (s[i] == D ) y--; if (s[i] == L ) x--; if (s[i] == R ) x++; } if (y < 0) y *= (-1); if (x < 0) x *=...
#include <bits/stdc++.h> using namespace std; int n, m, x, ans = 0; int MUL(int u, int v) { return (int)((1LL * u * v) % (int)(1e9 + 7)); } int main() { scanf( %d%d%d , &n, &m, &x); if (n > m) { cout << 0 << endl; return 0; } int dp[m + 10][n + 10][n + 10][2]; dp[m + 1][n][0][1] ...
#include <bits/stdc++.h> using namespace std; struct node { int v, id; node(int _id) { id = _id; cin >> v; } bool operator<(const node& from) const { return v > from.v; } }; vector<node> Q; bool IN[200005]; int l[200005]; int r[200005]; int pt = 1, mx = 1; void update(int x...
#include <bits/stdc++.h> int n; int main() { int i; long long ans, sumx, sumy, x, y; scanf( %d , &n); ans = sumx = sumy = 0; for (i = 0; i < n; i++) { scanf( %I64d%I64d , &x, &y); ans += (long long)x * x * n + y * y * n; sumx += x; sumy += y; } printf( %I64d , ans...
#include <bits/stdc++.h> using namespace std; int dp[1000000], arr[1000000]; int main() { int fi = 1, se = 1; int n; cin >> n; int last = 20; for (int i = 1; i <= n; i++) { int x; cin >> x; arr[i] = x; if (i == 1) { cout << 20 << n ; dp[i] = 20; ...
#include <bits/stdc++.h> using namespace std; int fr[300005], v[300005]; int main() { int n, i, x, sol = 0, pos1, pos2, cate = 0; cin >> n; for (i = 1; i <= n; ++i) { cin >> v[i]; x = v[i]; ++fr[x]; if (fr[x] == 1) ++cate; if (cate == 1 && fr[x] == 1) pos1 = i; if (...
#include <bits/stdc++.h> using namespace std; int main() { string s; int t[4] = {1, 1, 2, 1}; getline(cin, s); for (int i = 0; i < s.length(); i++) { if (s[i] == h && t[0]) { t[0]--; } else if (s[i] == e && t[1] && !t[0]) { t[1]--; } else if (s[i] == l && !t[1...
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); while (t--) { int n, k; scanf( %d %d , &n, &k); int div = n / k; int mod = n % k; for (int i = 0; i < k; i++) { for (int j = 1; j <= div; j++) { printf( %c , ( a + i)); ...
#include <bits/stdc++.h> void err() { std::cout << std::endl; } template <typename T, typename... Args> void err(T a, Args... args) { std::cout << a << ; err(args...); } using namespace std; const int mod = 998244353; const int inf = 1 << 30; const int maxn = 200000 + 5; const int maxq = 30...
#include <bits/stdc++.h> using namespace std; long double a[(1000000)], x[(1000000)]; long double b[(1000000)], y[(1000000)]; int n, A, B; long double ans; const long double inf = 3e9; bool check(double t) { int k = B; long double cnt = inf * inf; for (int i = A; i > 0; i--) { while (k &...
#include <bits/stdc++.h> using namespace std; const int maxn = 55; int n, a[maxn]; long long k; long long f[maxn]; int main() { scanf( %d %I64d , &n, &k); f[0] = f[1] = 1; for (int i = 2; i <= n; i++) f[i] = f[i - 1] + f[i - 2]; for (int i = 1; i <= n;) { if (f[n - i] >= k) { a...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; if (k >= n) cout << abs(n - k) << endl; else { if (n % 2 == 0) { if (k % 2 == 1) cout << 1 << endl; else ...
#include <bits/stdc++.h> using namespace std; bool marked[100000 + 2]; vector<int> prime; int ase[100000 + 2], num[100000 + 2]; bool isPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; return marked[n] == false; } void sieve(int n) { for (in...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int calc(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = (res * a) % MOD; a = (a * a) % MOD; n /= 2; } return res; } int main() { ios_base::sync_with_stdio(0); long ...
#include <bits/stdc++.h> using namespace std; const int INF = 2 * 1e9; const double EPS = 1e-9; const int MaxN = 100000 + 5; const int MaxM = 2 * 100000 + 5; int N, M, S, L, Dist[MaxN]; typedef struct Node { int idx; Node(void) {} Node(int _idx) { idx = _idx; } inline bool operator<(const ...
#include <bits/stdc++.h> using namespace std; int main() { set<char> s; char a[100005]; s.insert( A ); s.insert( H ); s.insert( I ); s.insert( M ); s.insert( O ); s.insert( T ); s.insert( U ); s.insert( V ); s.insert( W ); s.insert( X ); s.insert( Y ); scanf( ...
#include <bits/stdc++.h> using namespace std; inline long long power(long long a, long long b) { long long x = 1; a = a % 1000000007ULL; while (b) { if (b & 1) x = (x * a) % 1000000007ULL; a = (a * a) % 1000000007ULL; b >>= 1; } return x; } inline long long inv(long long a)...
#include <bits/stdc++.h> using namespace std; int p[400050]; int ran[400050]; int find_set(int a) { return p[a] == a ? a : (p[a] = find_set(p[a])); } int unite(int a, int b) { int x = find_set(a); int y = find_set(b); if (x == y) return -1; if (ran[x] < ran[y]) { p[x] = y; } else { ...
#include <bits/stdc++.h> using namespace std; long long t = 1, T; void print2d(vector<vector<long long>> &v) { for (long long i = 0; i < v.size(); i++) { for (long long x : v[i]) { cout << x << ; } cout << n ; } } void print(vector<long long> &a) { for (long long x :...
#include <bits/stdc++.h> int battle(std::string player1, std::string player2) { if (player1 == player2) { return 0; } if (player1 == rock ) { if (player2 == scissors ) { return 1; } else { return -1; } } if (player1 == paper ) { if (player2 == rock...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; void io() {} long long fast_exp(long long base, int exp, int m) { long long res = 1; while (exp > 0) { if (exp % 2 == 1) { res = (res * base) % m; } base = (base * base) % m; exp /= 2; } retu...
#include <bits/stdc++.h> using namespace std; int n, m; int a, b; vector<int> undiradj[100001]; vector<int> diradj[100001]; vector<int> dirjda[100001]; stack<int> s; bool vis[100001]; vector<int> scc[100001]; bool isinscc[100001]; bool hascycle; void dfs(int node) { if (!vis[node]) { v...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s = ; int r = 1; while (s.size() < 1050) { int k = r; string t = ; while (k > 0) { t = char((k % 10) + 0 ) + t; k = k / 10; } s = s + t, r++; } cout << s[...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n; long int a = 0, b = 0, c = 0; for (int i = 0; i < n; i++) { cin >> k; a = a + k; } for (int i = 0; i < n - 1; i++) { cin >> k; b = b + k; } for (int i = 0; i < n - 2; i++) { c...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; if (n == 1 || m == 1) cout << max(n, m); else if (m == 2 && n % 4) cout << n + 2 - (n & 1); else if (n == 2 && m % 4) cout << m + 2 - (m & 1); else ...
#include <bits/stdc++.h> using namespace std; long long mod = 998244353; long long binpow(long long a, long long p) { return p ? binpow(a * a % mod, p >> 1) * (p & 1 ? a : 1) % mod : 1; } long long bininv(long long a) { return binpow(a, mod - 2); } set<int> solved; map<long long, vector<long long> > m...
#include <bits/stdc++.h> using namespace std; unsigned long long dsum(unsigned long long n) { unsigned long long res = 0; while (n) { res += n % 10; n /= 10; } return res; } int main() { unsigned long long n, s; cin >> n >> s; unsigned long long dif = n - dsum(n); if ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int n = sqrt(a); if ((n * (n + 1)) <= b) cout << Vladik << endl; else cout << Valera << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long _gcd(long long x, long long y) { return (!y ? x : _gcd(y, x % y)); } long long _lcm(long long x, long long y) { return x / _gcd(x, y) * y; } int main() { std::ios_base::sync_with_stdio(0); long long n; string s; cin >> n >> s; long long...
#include <bits/stdc++.h> int main() { char x[101], y[101], z[101]; int len; scanf( %s%s , x, y); len = strlen(x); for (int i = 0; i < len; i++) { z[i] = y[i]; } int flag = 1; for (int i = 0; i < len; i++) { if (y[i] > x[i]) { flag = 0; printf( -1 n ); ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool cmax(T &x, T y) { return x < y ? x = y, 1 : 0; } template <typename T> inline bool cmin(T &x, T y) { return y < x ? x = y, 1 : 0; } const int _ = 2e5 + 55, __ = 5e5 + 55; int N; long long a[_], b[_]; char ans[_...
#include <bits/stdc++.h> template <typename T> class IntegerIterator : public std::iterator<std::input_iterator_tag, T, std::ptrdiff_t, T*, T> { public: explicit IntegerIterator(int value) : value(value) {} IntegerIterator& operator++() { ++value; return *this; } IntegerIterator...
#include <iostream> #include <cstdio> using namespace std; #define MAXN 200005 int t, n; int a[MAXN]; int pre[MAXN], suf[MAXN]; bool pre_ok[MAXN], suf_ok[MAXN]; bool ans; int main() { //freopen( CF#696D.in , r , stdin); scanf( %d , &t); while(t --) { ans =...
#include <bits/stdc++.h> using namespace std; int main() { int c, v, m, l, a, i = 1, x; cin >> c >> v >> m >> a >> l; x = v; while (x < c) x += min(v + i * a - l, m - l), i++; cout << i << endl; }
#include <bits/stdc++.h> using namespace std; const long long N = 1005; int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}; int dy[] = {0, 0, 1, -1, 1, -1, 1, -1}; string toBinary(int x) { string ret = ; while (x) { ret = (x & 1 ? 1 : 0 ) + ret; x >>= 1; } while (((int)(ret).size()) < 8) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 5010; int dp[maxn][maxn], sa[maxn], sb[maxn]; char a[maxn], b[maxn]; void gao(char *p, char *q, int n, int m) { memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) if (p[i] == q[j]) dp[i][j] =...
#include <bits/stdc++.h> using namespace std; int n, V[171]; void cauta(int p) { vector<pair<int, int> > Queries; int res, st = 2, dr = n; for (int m = dr; m >= st; --m) { cout << ? ; for (int i = 1; i <= n; ++i) { if (i != p) cout << 1 ; else cout <...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, a[55]; cin >> n >> m >> k; for (int i = 0; i < n; i++) cin >> a[i]; a[n] = 0; sort(a, a + n); int ans = -1, sum = 0; for (int i = 0; i < n + 1; i++) { sum += a[n - i]; if (sum + k - i >= m) { ans ...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e3 + 7; const int maxa = 1e5 + 7; int dp[maxn][maxn]; int num[maxn], n; int get_ans() { memset(dp, 0, sizeof(dp)); int max_mod[7], max_num[maxa]; memset(max_mod, 0, sizeof(max_mod)); memset(max_num, 0, sizeof(max_num)); int ...
#include <bits/stdc++.h> #pragma GCC optimize(fast - math) using namespace std; long long powmod(long long a, long long b, long long mod) { if (b == 0 || a == 1) { if (mod == 1) return 0; else return 1; } if (b % 2 == 0) { long long k = powmod(a, b / 2, mod); re...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 1000000000; const int MOD = 1073741824; const int M = INF; const double RRR = 180.0 / PI; vector<vector<pair<int, int> > > g; vector<int> used; void dfs(int v, int l, int r) { used[v] = 1; for (int i = ...
#include <bits/stdc++.h> #pragma g++ opitmize(3) #pragma g++ opitmize(2) #pragma g++ opitmize( fast ) #pragma g++ opitmize( inline ) using namespace std; int n, m, head[400010], k = -1, vis[400010], h[400010], tot = 1; long long a[400010], f[400010], f1; struct node { int to, nt, fg; } edge[100001...
#include <bits/stdc++.h> int a[5][100005]; int b[100005][5]; int main() { int n, m; std::cin >> n >> m; if (n == 1 && m == 1) std::cout << YES n1 n ; else if (n == 3 && m == 3) { std::cout << YES n ; std::cout << 5 1 9 n7 6 4 n2 8 3 n ; } else if (std::max(n, m) <= 3) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 5; int n, k; int v[MAXN], c[MAXN], a[MAXN]; double f[MAXN]; int rv[MAXN][20], rc[MAXN][20]; inline int GetV(int l, int r) { int x = log2(r - l + 1); return max(rv[l][x], rv[r + 1 - (1 << x)][x]); } inline int GetC(int l, int ...
#include <bits/stdc++.h> using namespace std; const int inf = (1 << 30); int dp[110][700][40], g[35][35]; string s; int solve(int p, int k, int q) { if (p < 0 && k >= 0) return 0; if (p < 0 || k < 0) return -inf; if (dp[p][k][q] != -1) return dp[p][k][q]; char ch = q + a ; int ans = -inf;...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<pair<int, int>> t(N), b(N); for (int i = 0; i < N; i++) cin >> b[i].first >> b[i].second >> t[i].first >> t[i].second; multiset<int> tm[2], bm[2]; for (int i = 0; i < N; i++) { tm[0].insert(t[i].fi...
#include <bits/stdc++.h> using namespace std; int main() { int count = 0; char k[4]; cin >> k; int a[5]; for (int i = 0; i < 4; i++) { a[i] = k[i] - 0 ; } int b[5]; for (int i = 0; i < 4; i++) { b[i] = a[i]; } while (1) { if (b[3] == 9) { b[3] = 0; ...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long INF = 1e18; bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2)...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 1e6 + 4; long long fac[N], infac[N]; long long me(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = (res * a) % mod; b >>= 1; a = (a * a) % mod; } return res; ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const long long INFLL = 0x3f3f3f3f3f3f3f3f; const int maxn = 1e6 + 10; struct Edge { int to, nxt; long long cost; Edge() {} Edge(int to, int nxt, long long cost) : to(to), nxt(nxt), cost(...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << 2 * n * n - 2 * n + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 400000 + 1000; struct node { int l, r, dir; long long w; } temp; vector<node> v; long long vis[N]; bool cmp(node a, node b) { if (a.l == b.l) return a.dir < b.dir; return a.l < b.l; } int main() { int n, x, i, l, w, r, tim...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, m, k, u, v, c[200005] = {}, d[200005] = {}, z = 0; vector<int> g[200005] = {}; cin >> n >> m >> k; for (int i = 1; i <= n; i++) cin >> c[i]; for (int i = 0; i < m; i++) cin >> u >> v, g[u].pu...
#include <bits/stdc++.h> using namespace std; int p = 0, cnt = 0, cplus, cminus, val[10005], Child[10005]; pair<int, int> F[10005][105], FF[105]; string s; vector<int> g[10005]; void DFS(int u) { while (p < s.size()) { p++; if (s[p - 1] == ( ) { g[u].push_back(++cnt); DFS(cn...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 1; vector<pair<char, int> > v; map<int, int> mp1, mp2; int arr[105][105]; int main() { int x, y, z, n = 0, m = 0, c = 0, lo = 2, mn = 1e9, mx = 0; char ch; cin >> x >> y; for (int i = 0; i < x; i++) { for (int j = 0; j <...
#include <bits/stdc++.h> using namespace std; long long a[400001], b[400001]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); unsigned n; cin >> n; for (unsigned i = 1; i <= n / 2; ++i) cin >> b[i]; a[1] = 0; a[n] = b[1]; for (unsigned i = 2; i <= n / 2; ++i) { if (b[i]...
#include <bits/stdc++.h> using namespace std; long long n, i, j = 0, k, l, T, c = 0, t = 0; long long a[10010], d[10010], e[10010]; string s; int main() { getline(cin, s); a[0] = s[0] - 48; d[0] = a[0]; e[0] = 0; for (i = 1; i < s.length() - 1; i += 2) { if (s[i] == * ) { a[...
#include <bits/stdc++.h> using namespace std; int n, m; int edge[1005]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> edge[i]; } int sum = 0; int tmp1, tmp2; for (int i = 0; i < m; i++) { cin >> tmp1 >> tmp2; sum += min(edge[tmp1], edge[tmp2]); }...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; scanf( %lld%lld , &n, &k); if (k > (long long)1e8) { printf( -1 n ); return 0; } long long b = n / (k * (k + 1) / 2); if (b == 0) { printf( -1 n ); return 0; } long long r = 1; for ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000 + 123; int n, p[MAXN], s[MAXN], a[MAXN]; vector<int> c[MAXN]; void inp(); void dfs(int); int main() { inp(); a[0] = s[0]; dfs(0); for (int i = 0; i < n; i++) if (a[i] < 0) return cout << -1, 0; cout << accu...
#include <bits/stdc++.h> using namespace std; int main() { double c = 0, l = 0, i, j; string x; cin >> x; if (x.size() == 1) { cout << x[0] << x[0]; return 0; } if (x.size() % 2 == 0) c = x.size() / 2 + 1; else c = x.size() / 2; string a, b, m; for (i = x....
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; int arr[14] = {4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777}; int i; for (i = 0; i < 14; i++) { if (a % arr[i] == 0) break; } if (i < 14) cout << YES ; if (i == 14) cout << NO ; re...
#include <bits/stdc++.h> using namespace std; const long long p = 1e9 + 7; char s[500010]; long long ans, n, i, sum, fac[500010], a[500010], f[500010][2]; int main() { scanf( %s , s + 1); n = strlen(s + 1); for (i = 1; i <= n / 2; i++) swap(s[i], s[n - i + 1]); f[1][0] = 10; f[1][1] = 1; ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const double eps = 1e-10; const int INF = 0x3f3f3f3f; const long long INFLL = 0x3f3f3f3f3f3f3f3fll; const int MAXN = 2e5 + 5; const int mod = 1e9 + 7; int a[MAXN], b[MAXN]; long long fastpow(long long a, int n) { long long base...
#include <bits/stdc++.h> using namespace std; int n, k; string A[6][3]; int B[6][4], p[4][3]; string name[4], s; bool C[4][4]; bool foo() { int i, j; for (i = 0; i < 4; i++) { for (j = 0; j < 3; j++) p[i][j] = 0; for (j = 0; j < 6; j++) { if (B[j][0] == i && B[j][2] > B[j][3]) ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int temp[100012], arr[100012], t[100012]; for (int i = 0; i < n; i++) { cin >> arr[i]; t[i] = arr[i]; } sort(t, t + n); int v = 0; for (int i = 0; i < n; i++) { if (t[i] != arr[i]) { ...