func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } int ans = 0; for (int i = 1; i < n; i++) { int a = max(0, k - (arr[i] + arr[i - 1])); arr[i] += a; ans += a; } co...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int c = 0, i; for (i = 4; i < s.size(); i++) { if (s[i - 4] == D && s[i - 3] == a && s[i - 2] == n && s[i - 1] == i && s[i] == l ) c++; } for (i = 3; i < s.size(); i++) { if ...
#include <bits/stdc++.h> using namespace std; const int N = 100001; int main(void) { char arr1[N] = {0}; char arr2[N] = {0}; char str1[2] = {0}, str2[2] = {0}; scanf( %[^ n]s , arr1); scanf( %[^ n]s , arr2); if (strlen(arr1) != strlen(arr2)) { cout << NO n ; return 0; } ...
#include <bits/stdc++.h> using namespace std; int n, k; int main() { cin >> n >> k; if (n / 2 > k) return !printf( -1 ); if (n == 1) { if (k == 0) printf( 1 ); else printf( -1 ); return 0; } int t = k - (n - 2) / 2; printf( %d %d , t, 2 * t); for (int ...
#include <bits/stdc++.h> using namespace std; void input() {} void solve() { long long int n, m; cin >> n >> m; long long int a[n][m]; long long int flag = 1, temp = 0; for (long long int i = 0; i < n; i++) { for (long long int j = 0; j < m; j++) { char ch; cin >> ch; ...
#include <bits/stdc++.h> using namespace std; long long pow(long long p, long long r, long long m) { long long ans = 1; while (r > 0) { if (r & 1) { ans = ((ans % m) * (p % m)) % m; } r = r >> 1; p = ((p % m) * (p % m)) % m; } return ans; } string con(string s) { ...
#include <bits/stdc++.h> using namespace std; string dna = ACGT ; string word[20]; set<string> words; map<string, int> mp; string pm[110]; pair<int, int> graph[110][20][4]; long long dp[1010][110][20]; int main() { ios::sync_with_stdio(false); int N, K, i, j, k, l, x; cin >> N >> K; f...
#include <bits/stdc++.h> using namespace std; const int N = 100005; vector<int> v[2][N]; int a[N], q[N], n; bool vst[2][N]; void bfs(int val) { int i, j, qh = 0, qe = 0, k = val - 1, s, out; for (i = 1; i <= n; i++) if (a[i] == val) q[qe++] = i, vst[k][i] = 1; while (qh < qe) { out =...
#include <bits/stdc++.h> using namespace std; bool isPossible(long long k, long long x, long long y, long long p, long long q) { p = p * k; q = q * k; if (x > p || y > q) { return false; } if (q - y < p - x) { return false; } return true; } long long sol...
#include <bits/stdc++.h> using namespace std; inline bool eq(double a, double b) { return fabs(a - b) < 1e-9; } const long long int inf = 1e15; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n >> b) & 1; } inline void set_bit(int& n, int b) { n |= two(b); } inline void un...
#include <bits/stdc++.h> using namespace std; int d, m, n, x[25], a[30005]; vector<long long> ok; long long L, R; map<long long, vector<long long> > ans; map<long long, vector<long long> > zip; vector<long long> calc(long long lim) { if (zip.find(lim) != zip.end()) return zip[lim]; vector<long lon...
#include <bits/stdc++.h> int gcd(int a, int b) { return !b ? a : gcd(b, a % b); } long long pow(long long a, int p) { long long ans = 1; while (p) { if (p & 1) ans *= a; a *= a; p >>= 1; } return ans; } int main() { int n, l, r; scanf( %d%d%d , &n, &l, &r); if (n ==...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long int n, m; cin >> n >> m; long long int a[n], b[m]; long long int aux[n]; for (long long int i = 0; i < n; ++i) { cin >> a[i]; if (i == 0) aux[i] = a[i]; else aux[i] = aux[i - 1] + a[i]; ...
#include <bits/stdc++.h> using namespace std; int n, m; set<long long> bms[6]; long long to_bit(string &s) { long long x = 0; for (long long i = 0; i < n; i++) { if (s[i] == 0 ) continue; x |= (1LL << i); } return x; } int main() { ios_base::sync_with_stdio(0); cin.tie(0...
#include <bits/stdc++.h> using namespace std; int n, m; int g[100000], cnt[100000]; int v[100000], b[100000]; int s[100005], sc[100005], sz; bool used[100005] = {}, dead[100005] = {}, marked[100005] = {}; int main() { scanf( %d%d , &n, &m); for (int i = 0; i < (int)(n); ++i) scanf( %d , g + i), --...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200010; int a[MAXN]; int b[MAXN]; int tmp[MAXN]; int main() { int n; cin >> n; int aidx; for (int i = 0; i < n; i++) { cin >> tmp[i]; if (tmp[i] == 0) aidx = i; } for (int i = 0; i < n; i++) a[i] = tmp[(i + ai...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-11; const int INF = 101e7; template <class T> T sqr(T first) { return first * first; } template <class T> T abs(T first) { return (first < 0) ? -first : first; } int main() { int n, m, h; ...
#include <bits/stdc++.h> using namespace std; void solve() { long long k; cin >> k; long long i = 0, prev = 0; while (k > prev + (9 * pow(10, i) * (i + 1))) { prev += 9 * pow(10, i) * (i + 1); i++; } k -= prev; long long temp; temp = pow(10, i) + (k / (i + 1)) - 1; if...
#include <bits/stdc++.h> using namespace std; const int64_t N = 1e3 + 5, M = 1e9 + 7; int64_t a[N][N]; int main() { ios::sync_with_stdio(0), cin.tie(0); int64_t n, m, s = 0; cin >> n >> m; for (int64_t i = 0; i < n; i++) for (int64_t j = 0; j < m; j++) cin >> a[i][j]; for (int64_t i = ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5; long long line[maxn]; int sum, q1, q2; int flag1, k, qw, wa, flag2; int main() { int n, zz = 1; cin >> n; for (int i = (int)(1); i < (int)(n + 1); i++) cin >> line[i]; while (zz <= n) { q1 = 0, q2 = 0, flag1 = 0, k = 0...
#include <bits/stdc++.h> using namespace std; long long n, m, a, b = 1, c, can[100000 * 10], cc, M, tmp[100000 * 10], ans = 0x3f3f3f3f3f3f3f3f, XH; inline long long cheng(long long u, long long v) { long long res = 0; for (; v; v >>= 1) { if (v & 1) res = (res + u) % M; u ...
#include <bits/stdc++.h> using namespace std; int store[20][1 << 20]; struct trie { int k; struct Node { Node* ch[2]; Node() { ch[0] = ch[1] = NULL; } }; Node* root; trie(int k) : k(k) { root = new Node(); } void insert(int x) { Node* cur = root; for (int i = k - 1;...
#include <bits/stdc++.h> using namespace std; int main() { int n, a[101], x = 0; string s1, s2; cin >> s1 >> s2; for (int i = 0; i < s1.size(); i++) { if (s1[i] != s2[i]) a[i] = 1; else a[i] = 0; x++; } for (int i = 0; i < x; i++) { cout << a[i]; }...
#include <bits/stdc++.h> using namespace std; struct app { int x, y; }; int main() { int n, m; scanf( %d , &n); scanf( %d , &m); int m1, m2; vector<app> arr(n); for (__typeof(0) i = 0; i <= n - 1; i++) { scanf( %d , &arr[i].x); scanf( %d , &arr[i].y); if (i == 0) { ...
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const double eps = 1e-9; const int MOD = 1000003; int R, C; char *grid[600000]; int main() { scanf( %d%d , &R, &C); for (int i = (0); i < (R); i++) { grid[i] = new char[C + 5]; scanf( %s , grid[i]); } int ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); long long n; cin >> n; long long s = 0; for (int i = 0; i < n; ++i) { long long x; cin >> x; s += x; } long long add = (s - n * (n - 1) / 2) / n; long ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7, maxn = 2e3 + 5; long long f[maxn][maxn][2][2]; long long g[maxn]; long long n, m; long long upd(const long long &x) { if (x < 0) return x + mod; if (x >= mod) return x - mod; return x; } void add(long long &x, const...
#include <bits/stdc++.h> using namespace std; template <typename T> bool chmax(T &x, const T &y) { return (x < y) ? (x = y, true) : false; }; template <typename T> bool chmin(T &x, const T &y) { return (x > y) ? (x = y, true) : false; }; constexpr long long int MOD = 10; constexpr long long in...
#include <bits/stdc++.h> using namespace std; const long long int K = 998244353; long long int mu(long long int a, long long int n) { if (n == 0) return 1; long long int q = mu(a, n / 2); if (n % 2 == 0) return q * q % K; return q * q % K * a % K; } long long int d[55][55][55][55], inv[5305]; ...
#include <bits/stdc++.h> using namespace std; mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); void setIO(string name) { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.exceptions(istream::failbit); } const int inf = 0x3f3f3f3f, mod = 1e9 + 7, maxn = 1e5 + 5; ...
#include <bits/stdc++.h> using namespace std; int M[33][33]; int S[33][33]; int m; int n; int solve(int sid) { memcpy(S, M, sizeof(int) * 33 * 33); for (int i = 0; i < m; i++) { if ((1 << i) & sid) { for (int k = m - 1; k < n; k++) { for (int l = i; l < i + m; l++) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; const int INF = 1 << 30; const double eps = 1e-6; const int mod = 1000000007; string s; void getVal(int& a, int& b, char x) { a = b = -1; for (int i = 0; i < s.size(); i++) { if (s[i] != x) continue; if (a == -1) a ...
#include <bits/stdc++.h> using namespace std; int N, i; double H, K, x, y, xp, yp; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> K >> x >> y; for (i = 1; i < N; i++) { cin >> xp >> yp; H += sqrt((xp - x) * (xp - x) + (yp - y) * (yp - y)) * K / 50...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:2000000 ) #pragma comment(linker, /HEAP:2000000 ) using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; long long m[n][n], a[n]; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 600, oo = 2e9; int nn[N], mm[N], n, m; int check() { int mn = oo; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (nn[i] == mm[j]) mn = min(mn, nn[i]); } } if (mn == oo) return -1; return mn; } ...
#include <bits/stdc++.h> using namespace std; string s, t, temp; bool check(int mid, vector<int>& v) { temp = s; for (int i = 0; i < mid; i++) { temp[v[i]] = # ; } int x = 0; for (int i = 0; i < temp.size(); i++) { if (t[x] == temp[i]) { x++; } if (x == t.size(...
#include <bits/stdc++.h> using namespace std; int da[100010], db[100010], ida[100010], idb[100010]; map<int, int> mp; map<int, int>::iterator it; void solve(int n) { for (int i = 1; i <= n; i++) { int ret = 0x3fffffff; it = mp.lower_bound(i - 1); if (it != mp.end()) ret = min(ret, it->fi...
#include <bits/stdc++.h> using namespace std; long long modexpo(long long x, long long p) { long long res = 1; x = x % 1000000007; while (p) { if (p % 2) res = res * x; p >>= 1; x = x * x % 1000000007; res %= 1000000007; } return res; } struct compare { bool opera...
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 5; struct Ans { long long a, b, c; }; void solve() { long long a, b, c; cin >> a >> b >> c; long long ans = 1e9; auto x = Ans{a, b, c}; for (long long aa = 1; aa <= 2 * a; aa++) { for (long long bb = aa; bb <...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { long long n, k; cin >> n >> k; int a[n]; int ma = INT_MIN; for (int i = 0; i < n; i++) { cin >> a[i]; ...
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > xy; vector<pair<long long, long long> > ab; vector<long long> x; vector<long long> y; string str, str1, str2, star[2000]; long long ara[200005], ara2[200005]; bool flagar[200005], flagar2[200005]; bool compare(pair<long ...
#include <bits/stdc++.h> using namespace std; const int N = 2005, M = 200005; struct node { int x, y; } d[N]; int h, w, n, mod = 1e9 + 7; long long c[M] = {1, 1}, inv[M] = {1, 1}, ni[M] = {1, 1}, f[N]; long long quick_mod(long long a, long long b) { long long ans = 1; while (b) { if (b &...
#include <bits/stdc++.h> using namespace std; const int MAXINT = 2147483647; const long long MAXLL = 9223372036854775807LL; const int MAX = 400000; long long n, q, col, pref[MAX], l, r, sum, ans, t[MAX]; string s; int main() { cin >> n >> q; cin >> s; for (int i = 0; i < n; i++) { if (s[...
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>; using pll = pair<ll, ll>; using vpll = vector<pll>; ll a, n; vll inp; void func() { cin >> a; string s; cin >> s; n = s.length(); inp.resize(n); for (ll i = 0; i ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( unroll-loops ) using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 300007; int n, a[maxn]; sta...
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T& x) { bool fu = 0; char c; for (c = getchar(); c <= 32; c = getchar()) ; if (c == - ) fu = 1, c = getchar(); for (x = 0; c > 32; c = getchar()) x = x * 10 + c - 0 ; if (fu) x = -x; }; inline cha...
#include <bits/stdc++.h> using namespace std; int n, p, a[100005], fqn[100005], fqo[100005], mx, cur, exc = 0, lesdan = 0, mnvl[100005], gmod = 0, rekt = 0; int mc[100005], vl[100005]; vector<int> ok; map<int, int> fq; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> p; ...
#include <bits/stdc++.h> using namespace std; int n, m; struct EDGE { int to, w; EDGE *las; } e[100005]; int ne; EDGE *last[100005]; void link(int u, int v, int w) { e[ne] = {v, w, last[u]}; last[u] = e + ne++; } long long dis[100005], f[100005]; void adjust() { for (int i = 1; i...
#include <bits/stdc++.h> using namespace std; vector<int> adj[105]; bool visited[105]; int df[1005]; int ans = 0, k = 0; void dfs(int i, int parent) { visited[i] = true; for (int j = 0; j < adj[i].size(); j++) { if (!visited[adj[i][j]]) dfs(adj[i][j], i); } } int main() { int n, m;...
#include <bits/stdc++.h> using namespace std; long long m, n, x, y, p, q; int main() { cin >> n; for (long long k = 0; k < n; k++) { cin >> x >> y >> p >> q; m += (p - x + 1) * (q - y + 1); } cout << m; }
#include <bits/stdc++.h> using namespace std; struct data { int x; int y; }; int main() { long long n; cin >> n; vector<data> info; long long smallest = 9999999999; long long largest2 = -1; for (int i = 0; i < n; i++) { data temp; cin >> temp.x >> temp.y; if (te...
#include <bits/stdc++.h> using namespace std; const int MAX = 1010; int n, t, pop = -1, p[2 * MAX], para[2 * MAX], odw[2 * MAX]; inline void dodaj_pare(int a, int b) { para[a] = b; para[b] = a; } void wczytaj_dane() { int m; cin >> n >> m; for (int i = 0; i < (2 * n); i++) cin >> p[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { int N; scanf( %d , &N); static int X[100]; for (int i = 0; i < N; i++) scanf( %d , &X[i]); vector<int> Ans; for (int i = 0, Count = 0, First = 0; i < N; i++) { if (X[i] < 0) Count++; if (i == N - 1 || (Count == 2 && X[i +...
#include <bits/stdc++.h> using namespace std; long long bigmod(long long b, long long p, long long m) { if (p == 0) return 1; long long my = bigmod(b, p / 2, m); my *= my; my %= m; if (p & 1) my *= b, my %= m; return my; } int setb(int n, int pos) { return n = n | (1 << pos); } int res...
#include <bits/stdc++.h> using namespace std; bool check(string& a) { for (int i = 1; i < a.size(); i++) { if (abs(a[i] - a[i - 1]) == 1) return false; } return true; } string gen(string a) { if (check(a)) return a; while (next_permutation(a.begin(), a.end())) { if (check(a)) ret...
#include <bits/stdc++.h> using namespace std; int max2[205][6005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); fill_n(max2[0], 205 * 6005, -1); max2[0][0] = 0; int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { long long int a; cin >> a; int p2 =...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f |= (ch == - ), ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return f ? -x : x; } inline void write(long long x) { if ...
#include <bits/stdc++.h> using namespace std; int row[1010]; int main() { int n, m, k; scanf( %d %d %d , &n, &m, &k); memset(row, 0x3f3f3f3f, sizeof row); long long ans = 0; for (int i = (0); i < (n); ++i) { int r, c; scanf( %d %d , &r, &c); row[r] = min(c, row[r]); } ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int INF = 0x3f3f3f3f; const int inf = -INF; const int mod = 1e9 + 7; const double pi = acos(-1.0); string s; int pre[N]; int dp[N][2]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int T; cin >> T; ...
#include <bits/stdc++.h> using namespace std; int main(void) { double d, l, v1, v2; cin >> d >> l >> v1 >> v2; printf( %.10lf , double((l - d) / (v1 + v2))); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, rej = 0; cin >> n; vector<int> a(n); for (size_t i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); for (int i = 0; i < n; i++) if (a[i] == a[0] || a[i] == a[n - 1]) rej++; cout << n - rej; }
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long read() { long long x = 0, f = 1; char ch; while (!isdigit(ch = getchar())) (ch == - ) && (f = -f); for (x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48)) ; return x * f...
#include <bits/stdc++.h> using namespace std; long long int hell = 9223372036854775807; bool a[40000000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t; t = 1; while (t--) { for (long long int i = 1; i < 4000000; i++) { a[i] =...
#include <bits/stdc++.h> using namespace std; int main() { int a[6]; for (int i = 0; i < 6; i++) { cin >> a[i]; } cout << (a[0] + a[1] + a[2]) * (a[0] + a[1] + a[2]) - (a[0] * a[0]) - (a[2] * a[2]) - (a[4] * a[4]) << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 5050; const int inf = 0x37373737; int L[N], R[N], size[N], tot, n, i, a, b, cnt, j, k; int d[N], root; int dp[N][N]; vector<pair<int, int> > vec[N]; vector<int> e[N]; void dfs(int x, int fa) { int i, j, k; if (e[x].size() == 1) size[x...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { T f = 1; x = 0; char s = getchar(); while (s < 0 || s > 9 ) { if (s == - ) f = -1; s = getchar(); } while (s >= 0 && s <= 9 ) { x = x * 10 + s - 0 ; s = getchar(); } ...
#include <bits/stdc++.h> int main() { int i, j, k, l, y, m, n; char s[101], t[101]; scanf( %d , &y); for (i = y + 1;; i++) { n = i; j = n % 10; n = n / 10; k = n % 10; n = n / 10; l = n % 10; n = n / 10; if (n != l && n != k && n != j && l != k && l != j...
#include <bits/stdc++.h> using namespace std; inline int read() { int s = 0, t = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) t = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar(); return s * t;...
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline int read() { int x = 0; char ch = getchar(); boo...
#include <bits/stdc++.h> using namespace std; int n; vector<stack<int>> ids; vector<int> b; string answer; int segtree_size; template <typename T> struct segtree { int segtree_size; vector<T> segtree; T identity; T (*UpdateFn)(T, T); void InitSegtree(int main_size, T (*UpdateFunction...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, i; cin >> n; long long a[n + 1]; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long ans = 0, sum = 0; for (i = 0; i < n; i++) { if (sum <= a[...
#include <bits/stdc++.h> using namespace std; inline int dcmp(double a, double b) { return fabs(a - b) < (1e-9) ? 0 : a < b ? -1 : +1; } int main() { int tc; scanf( %d , &tc); while (tc--) { int n; scanf( %d , &n); printf( %d n , n / 2); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long inf = 4e18; long long ver[305][305], hor[305][305], ver2[305][305], hor2[305][305]; int con[305][305]; pair<pair<int, int>, pair<int, int> > ans; long long dif = inf, cur, a, b; int main(void) { memset(ver, 0, sizeof(ver)); memset(hor, ...
#include <bits/stdc++.h> using namespace std; int const N = 1e6 + 2; int a[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < (int)(n); ++i) cin >> a[i]; for (int i = 0; i < (int)((1 << n)); ++i) { long long sum = 0; for (int j = 0; j <...
#include <bits/stdc++.h> using namespace std; vector<long long> ft(1, 1LL); int n, ans[3], hg, xxx = 0; vector<int> graph[200005], vis(200005); queue<int> q; void dfs(int node, int par, int i, int h) { if (h >= hg) hg = h, ans[i] = node; for (auto child : graph[node]) if (child != par) dfs(chi...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, maxn = 200007; const long long MOD = 1004535809; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const long long P = 19260817; char nc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread...
#include <bits/stdc++.h> using namespace std; bool bysec(const pair<int64_t, int64_t> &a, pair<int64_t, int64_t> &b) { return a.first > b.first; } void solve() { int64_t n, x, an = 0; cin >> n; pair<int64_t, int64_t> A[n]; for (int64_t i = 0; i < n; i++) cin >> x, A[i] = {x, i + 1}; sort...
#include <bits/stdc++.h> using namespace std; int main() { char s[100]; int n, t; cin >> n >> t; if (n == 1 && t == 10) cout << -1; else { if (t < 10) s[0] = t + 48; else s[0] = 1 ; for (int i = 1; i < n; i++) { s[i] = 0 ; } for (int ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long sum = 0, ff = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) ff = -1; ch = getchar(); } while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar(); return sum * ff; } const lo...
#include <bits/stdc++.h> using namespace std; struct V { vector<int> lnk; int p; int countBad(); }; V tab[400000]; int V::countBad() { int c = 0; for (__typeof((lnk).begin()) it = (lnk).begin(); it != (lnk).end(); ++it) if (tab[*it].p == p) ++c; return c; } int main() { i...
#include <bits/stdc++.h> using namespace std; int n; char dir[200005]; int l[200005], r[200005], ll, rl; int ans = 0x7fffffff; int main() { cin >> n; getchar(); for (int i = 1; i <= n; i++) scanf( %c , &dir[i]); for (int i = 1; i <= n; i++) if (dir[i] == L ) scanf( %d , &l[++l...
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using ull = uint64_t; using ld = long double; using vi = vector<int64_t>; using pii = pair<int64_t, int64_t>; ll powr(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a); a = (a * a); b >>= 1; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; pair<long long int, long long int> a[100005]; for (int i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i + 1; } sort(a, a + n); if (n % 2 == 0) { cout << n / 2 << endl; } else { ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long f = 1, ans = 0; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { ans = ans * 10 + c - 0 ; c = getchar(); } retu...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<int, int>> v(n); for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second; sort(v.begin(), v.end()); for (int i = 0; i < n - 1; i++) { if (v[i].second > v[i + 1].second && v[i].first != v[i + 1]...
#include <bits/stdc++.h> using namespace std; int cnt[2]; int main() { ios::sync_with_stdio(false); string s; cin >> s; for (int i = s.size() - 1; i >= -1; i--) { if (i > -1) cnt[s[i] - 0 ]++; if (s[i] == 1 && (i == 0 || s[i - 1] == 0 )) { int req = cnt[1] - cnt[0]; ...
#include <bits/stdc++.h> using namespace std; const int nax = 3e5 + 5; int nxt[nax][20]; int reach[20]; int main() { int n, q; cin >> n >> q; vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; for (int bit = 0; bit < 19; bit++) reach[bit] = n; for (int i = n - 1; i >= 0; i-...
#include <bits/stdc++.h> using namespace std; int n, m, k, ta, tb, i, ans[100005], tc, ca[2][1005]; vector<int> va[2][1005], vb[2], ve; int main() { scanf( %d%d%d , &n, &m, &k); for (int a = 0; a < k; a++) { scanf( %d%d , &ta, &tb); ta--; tb--; vb[0].push_back(ta); vb[1].pu...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 100; int n, k; long long C[maxn][maxn]; void Init() { C[0][0] = 1; for (int i = 1; i < maxn; ++i) { for (int j = 0; j <= i; ++j) { if (j == 0 || j == i) { C[i][j] = 1; } else { C[i][j] = C[i...
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const long long LLINF = 9223372036854775807LL; int l, r, p; bool isprime(int x) { for (int i = 2; i * i <= x; ++i) if (x % i == 0) return false; return true; } const int maxn = 3000010; int a[maxn]; int acnt = 0; ...
#include <bits/stdc++.h> using namespace std; void speed() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void convertString(string &s, char t) { if (t == L ) { for (int i = 0; s[i] != 0 ; i++) if (s[i] >= 65 && s[i] <= 90) s[i] += 32; } else { for (int i = 0; s...
#include <bits/stdc++.h> using namespace std; string s, ans; bool flag = 0; int main() { cin >> s; for (int i = 0; i < s.length(); ++i) { if (s[i] == / ) { if (!flag) { ans += s[i]; flag = 1; } } else { ans += s[i]; flag = 0; } }...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; struct Graph { int head[N], v[N << 1], w[N << 1], next[N << 1], e; void clear() { e = 0; memset(head, -1, sizeof(head)); } void add(int u, int v, int w) { this->v[e] = v; this->w[e] = w; next[e] = he...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } set<int> vals; set<int> cur; for (int i = 0; i < n; ++i...
#include <bits/stdc++.h> using namespace std; int main() { string p; int i; bool work = false; cin >> p; for (i = 0; i < p.size(); i++) if (p[i] == H || p[i] == Q || p[i] == 9 ) work = true; if (work) cout << YES ; else cout << NO ; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int q; cin >> q; while (q--) { long long int n, m; cin >> n >> m; char s[n][m]; for (long long int i = 0; i < n; i++) { for (long long int j = 0; j < m; j++) { cin >> s[i][j]; } }...
#include <bits/stdc++.h> using namespace std; int a[300005]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); int Sum = 0; for (int i = 1; i <= n; i++) Sum += a[i]; int indx = 0; int Taken = 0; while (Sum > 2 * Taken) { indx++; Taken...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, fl = 1; char st = getchar(); while (st < 0 || st > 9 ) { if (st == - ) fl = -1; st = getchar(); } while (st >= 0 && st <= 9 ) x = x * 10 + st - 0 , st = getchar(); return x * fl; } const int ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n; cin >> n; int w, b; cin >> w >> b; vector<int> ve; for (int i = 0; i < n; i++) { int x; cin >> x; ve.push_back(x); } int res = 0; for (int i = 0, j = n - 1; i <= j...