func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int n, m, k; int arr[51][51] = {0}, visit[51][51] = {0}; vector<pair<int, pair<int, int> > > v; int dfs(int a, int b, int count); void make_land(int i, int j); int main() { int i, j, sum = 0; char ch; cin >> n >> m >> k; for (i = 0; i < n; i++)...
#include <bits/stdc++.h> const int maxed = 200000 + 10; struct Node { int x, y; }; std::vector<Node> ve[maxed]; std::vector<Node>::iterator it; std::map<long long, int> id; std::map<std::pair<int, int>, int> ma; int n, id_cnt; int gcd_(int a, int b); int main() { scanf( %d , &n); int a, ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; if (k == 1) { if (n > 1) cout << n; else cout << -1 ; return 0; } int i; vector<int> res; for (i = 2; i * i <= n; i++) { while (n % i == 0 && k != 1) { ...
#include <bits/stdc++.h> using namespace std; int n, a, b, k; int dp[5010][5010]; int main() { scanf( %d %d %d %d , &n, &a, &b, &k); dp[0][a] = 1; for (int i = 1; i <= k; ++i) { for (int j = 1; j <= n; ++j) { dp[i - 1][j] += dp[i - 1][j - 1]; dp[i - 1][j] %= (1000000007); ...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, const U &b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, const U &b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; ...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; const int block_size = 320; const long long mod = 1e9 + 7; const long long inf = 1e9 + 7; const long doubl...
#include <bits/stdc++.h> using namespace std; int n, m, i, x, q, w[110000]; long long ans; int f(int x) { return x * (x / 2) + x % 2; } bool cmp(int x, int y) { return x > y; } int main() { scanf( %d%d , &n, &m); for (i = 0; i < m; i++) scanf( %d%d , &q, w + i); sort(w, w + m, cmp); while (f...
#include <bits/stdc++.h> using namespace std; template <class L, class R> ostream& operator<<(ostream& os, pair<L, R> P) { return os << ( << P.first << , << P.second << ) ; } template <class T> ostream& operator<<(ostream& os, vector<T> V) { os << [ ; for (auto v : V) os << v << ; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); double l, x, v1, v2, k; cin >> l >> x >> v1 >> v2 >> k; double n = ceil(l / k); double t2, t1; t2 = x / (v2 * (n * ((v1 + v2) / (v2 - v1)) - (n - 1))); t1 = t2 * (v1 + v2) / (v2 - v1); ...
#include <bits/stdc++.h> char c = G ; void incrementa(); int main() { int n; scanf( %d , &n); n = n - 7; printf( ROYGBIV ); for (int i = 0; i < n; i++) incrementa(); return 0; } void incrementa() { printf( %c , c); switch (c) { case G : c = B ; break; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; for (int i = 2; i <= n; i++) { if (n % i == 0) reverse(s.begin(), s.begin() + i); } cout << s; return 0; }
#include <bits/stdc++.h> using namespace std; char grid[55][55]; int T, N; int main() { cin >> T; for (int QQQ = 0; QQQ < T; QQQ++) { cin >> N; bool works = true; for (int i = 0; i < N; i++) cin >> grid[i]; for (int r = 0; r < N - 1; r++) for (int c = 0; c < N - 1; c++) ...
#include <bits/stdc++.h> using namespace std; using LL = long long; constexpr int N = 150005; double x[N], ex[N]; array<double, 4> seg[4 * N]; array<double, 4> merge(const array<double, 4> &l, const array<double, 4> &r) { array<double, 4> rv; rv[0] = l[0] + r[0]; rv[1] = max(l[1], l[0] + r[1]); ...
#include <bits/stdc++.h> using namespace std; const int N = 100005; vector<int> e[N]; int n, ans, f[N][2], g[N][2]; void dfs1(int x, int fa) { f[x][0] = 0; f[x][1] = 0; int d = e[x].size() - (fa != 0); for (auto i : e[x]) if (i != fa) { dfs1(i, x); f[x][0] = max(f[x][0], ...
#include <bits/stdc++.h> using namespace std; long long a[100009]; int main() { long long n, x, y; int i; while (cin >> n >> x >> y) { int flag = 0; for (i = 1; i <= n - 1; i++) a[i] = 1, y--; a[n] = y; if (a[n] <= 0) flag = 1; long long sum = 0; for (i = 1; i <= n;...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); inline long long int rand(long long int x, long long int y) { ++y; return (rng() % (y - x)) + x; } long long int n, q, fw[300006], st[300006], en[300006], co, dist[300006], zero, li...
#include <bits/stdc++.h> using namespace std; int main() { int t, i; double sum, n; cin >> t; while (t--) { cin >> n; sum = 360 / (180 - n); if ((sum - (int)sum) == 0) cout << YES << endl; else cout << NO << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int Maxn = 300005; int res, cnt, head[Maxn], choose[Maxn], target[Maxn], las[Maxn], ct, n[Maxn], k, val[Maxn], a[20][Maxn], b[Maxn], bel[Maxn], state_cnt; bool vis1[Maxn], vis2[Maxn], ans[Maxn], done[20], flag; map<long long, int> Ma; long long sum[M...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx2 ) using namespace std; const int MX = 1005; int n, a, b; vector<int> adj[2 * MX][2]; int leaf[MX][2]; int pos[2 * MX][2]; int siz[2 * MX][2]; int best[MX][MX][2]; int ans[MX][2]; pair<int, int> rang[2 * MX][2]; voi...
#include <bits/stdc++.h> using namespace std; ifstream file( input.txt ); int main() { int ta = 0, tb = 0, tc = 0, v = 2; string str; cin >> str; for (int i = 0; i < str.size(); i++) { if (str[i] == a ) ta++; else if (str[i] == b ) tb++; else tc++; }...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int M = 2e3 + 5; const int INF = 0x7fffffff; const int mod = 998244353; const double eps = 1e-8; const double pi = acos(-1); int n, m; char str[N]; int f[N][26]; template <class T> inline void read(T &x) { char c; ...
#include <bits/stdc++.h> template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long l...
#include <bits/stdc++.h> using namespace std; double us1[210]; double us2[210]; int deal(double *us, int s, int e, int p) { int flag = 0; for (int i = 1; i <= 200; i++) { if (us[i] < 1e-4 / 200.) continue; double dd = us[i] * (100 - p) / 100.; dd /= (e - s + 1); us[i] = us[i] / 1...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) using namespace std; const int maxn = 200000; int t[4 * maxn]; int p[maxn]; int n; int mina(int x, int y) { if (x == -1) return y; if (y == -1) return x; return (p[x] < p[y] ? x : y); } void build...
#include <bits/stdc++.h> int a[500]; int temp1[500]; int temp2[500]; int sum[500]; void merge(int l, int mid, int r) { int i, j, k; for (i = l; i <= mid; i++) temp1[i - l] = a[i]; temp1[i - l] = 10000000; for (j = mid + 1; j <= r; j++) temp2[j - mid - 1] = a[j]; temp2[j - mid - 1] = 100000...
#include <bits/stdc++.h> using namespace std; char s[100005]; int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; map<string, int> my; void check(char* s) { if (((s[0]) >= 0 && (s[0]) <= 9 ) && ((s[1]) >= 0 && (s[1]) <= 9 ) && ((s[3]) >= 0 && (s[3]) <= 9 ) && ((s[4]) >= 0 && (...
#include <bits/stdc++.h> using namespace std; const int mxn = 2e5 + 5; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); ; int tc; cin >> tc; while (tc--) { string s; cin >> s; int a = 0, b = 0, c = 0; for (int i = 0; i < s.size(); i++) { if (s...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 4 ; int a[N] , prefMin[N] , prefMax[N] , suffixMin[N] , suffixMax[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t ; cin >> t ; while(t--){ int n , m , q , sum =0 , s1 = 0 , s2 =0; ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; ch < 0 || ch > 9 ; ch = getchar()) if (ch == - ) f = -1; for (; ch >= 0 && ch <= 9 ; ch = getchar()) x = (x << 1) + (x << 3) + ch - 0 ; return x * f; } const in...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c; long long x0, y0, x, y; cin >> a >> b >> c >> x0 >> y0 >> x >> y; c += a * x0; c += b * y0; c = -c; x -= x0; y -= y0; if (x < 0) a = -a, x = -x; if (y < 0) b = -b, y = -y; if (c < 0) a = -a, b =...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; reverse(a, a + n); stack<pair<int, int>> st; for (int i = 0; i < n; i++) { pair<int, int> p = make_pair(a[i], 0); while (!st.empty()) { pair<...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; struct edge { public: int flow, cap, cost; int u, v; edge(int _u, int _v, int _flow, int _cost, int _cap) { u = _u; v = _v; flow = _flow; cost = _cost; cap = _cap; } edge()...
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> istream &operator>>(istream &in, pair<T1, T2> &P) { in >> P.first >> P.second; return in; } template <class T1, class T2> ostream &operator<<(ostream &out, const pair<T1, T2> &P) { out << ( << P.first << , << P.seco...
#include <bits/stdc++.h> namespace my_std { using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> inline T rnd(T first, T second) { return uniform_int_distribution<T>(first, second)(rng); } template <typename T> inline bool chkmax(T &x, T y) ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2000 + 10; int n, k, a[MAX_N], dp[MAX_N]; bool check(int x) { for (int i = 0; i < n; i++) { dp[i] = 1; for (int j = i - 1; ~j; j--) if (abs(a[i] - a[j]) <= 1LL * (i - j) * x) dp[i] = max(dp[i], dp[j] + 1); if (n - dp[i...
#include <bits/stdc++.h> using namespace std; enum actions { JUMP1, UP1, DOWN1, JUMP2, UP2, DOWN2, NONE }; int n, x; vector<vector<int> > v(6); bool wut(int state, int i, actions last, int water) { if (water - 1 >= i) return false; if (state == 1) { if (n < 50000) { if (v[JUMP1][i] == 1)...
#include <bits/stdc++.h> using namespace std; int n, m, ans; struct aa { int l, r; int v; }; bool operator<(aa a, aa b) { return a.r < b.r; } inline aa qwq(int l, int r, int v) { aa a; a.l = l; a.r = r; a.v = v; return a; } set<aa> s; int read() { register int x = 0, ch...
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f3f3f3f3f; const long long MAXN = 1e5 + 7; const long long MAXM = 1e5 + 7; const long long MOD = 1e9 + 7; const double eps = 1e-6; const double pi = acos(-1.0); long long a[200005]; int main() { int n; cin >> n; f...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; map<pair<int, int>, int> mp; map<int, int> mp1; vector<pair<int, int>> v; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; mp1[x]++; mp1[y]++; mp[{x, y}]++; mp[{y, x}...
#include <bits/stdc++.h> using namespace std; int n; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; vector<long long> a; vector<int> pos; for (int i = n; i > 0; i--) { long long p; cin >> p; if (p == 0) continue; a.push_back(p); ...
#include <bits/stdc++.h> using namespace std; int n, p; char a[20000]; int b[20000]; int main() { cin >> n >> p; scanf( %s , a); memset(b, -1, sizeof(b)); for (int i = 0; i < n; ++i) { if (a[i] == . ) { if (i - p >= 0 && b[i - p] != -1) { b[i] = b[i - p] ^ 1; }...
#include <bits/stdc++.h> using namespace std; int main() { char com[200]; char *p; int man = 0; int sum = 0; int i; int word; while (scanf( %c , com) == 1) { i = 1; while ((com[i] = getchar()) != n ) i++; com[i] = 0 ; word = 0; if (com[0] == + ) { ...
#include<bits/stdc++.h> #define ll long long #define F first #define S second #define endl n using namespace std; const ll mod=1e9+7; const int N=5+3e5; const int INF=1e9; ll a[3][N],s[3],n[3]; int x[3]= {0,1,2}; int main() { #ifdef LOCAL freopen( input.in , r , stdin); #endif ...
#include <bits/stdc++.h> const long long INF = (long long)1e18 + 2; using namespace std; void solve(); void fastIO() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int main() { fastIO(); solve(); } void solve() { int n, m; cin >> n >> m; char a[n][m]; for (...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; if (b % a) { cout << -1 << n ; } else { int x = b / a; int ans = 0; while (x % 2 == 0) { ans++; x /= 2; } while (x % 3 == 0) { ans++; x /= 3; ...
#include <bits/stdc++.h> using namespace std; long long n, nn = 0, nm = 0, dr[5069], dh[10069], pd[5069], pr[5069], fq[10069], sbt[10069], sm = 0, z = 1e18; vector<pair<long long, long long>> fz[5069], al[10069]; pair<long long, long long> sk[5069]; vector<long long> pst[5069]; bitset<10069> ...
#include <bits/stdc++.h> using namespace std; int main() { long long t, n, i, j, k; double p, q, m; cin >> n >> m; p = pow(1.000000011, m); q = n * p; printf( %.12lf , q); return 0; }
#include <bits/stdc++.h> using namespace std; int a[100005], in[100005]; int main() { int n, m; scanf( %d , &n); int i, j; for (i = 0; i < n; i++) { scanf( %d , &in[i]); in[i] = ++a[in[i]]; } for (i = 2; i <= 100000; i++) if (a[i] > a[i - 1]) break; if (i <= 100000) ...
#include <bits/stdc++.h> using namespace std; const int N = 200005; struct ST { int l, r, mx, c; } t[N << 2]; int n, k, m, nn, tot, R, sum; int ls[N], rs[N], a[N], rk[N], sa[N], h[N], tp[N], tax[N], f[N][18], lg[N], tag[N], len[N], num[N]; long long ans[N]; char s[N]; void rsort() { int ...
#include <bits/stdc++.h> using namespace std; vector<vector<int>> arr(5, vector<int>(200005)); int main() { int t, n, i, ans, a, b, c, d, e, m, j, s, curr; string s1; cin >> t; while (t--) { cin >> n; for (i = 0; i < n; i++) { cin >> s1; a = 0; b = 0; c ...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, l, m, n, f, t; string s, s1, s3, s4; while (cin >> s) { s1 = s; k = 0; for (i = 0; i < s.size(); i++) { k += s[i] - 0 ; } k = k % 3; if (k == 0) { cout << s << endl; } else ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; int c2i(char c) { if (c <= 9 ) return c - 0 ; return c - A + 10; } long long conv(string num, int base) { long long res = 0; for (int i = 0; i < (int)num.length(); i++) { if (c2i(num[i]) >= base) return INF; ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int n; int m; int a, b; long long fast_mod_pow(long long a, long long b) { long long res = 1; a %= mod; while (b) { if (b & 1) { res = (res * a) % mod; } a = (a * a) % mod; b >>= 1; ...
#include <bits/stdc++.h> using namespace std; bool comp(pair<float, int> a, pair<float, int> b) { if (a.first > b.first) return true; else if (a.first == b.first) return a.second < b.second; else return false; } inline istream& skip_endl(istream& is) { return is.ignore(numeric_...
#include <bits/stdc++.h> using namespace std; mt19937_64 rd(787); int a[500010]; int cnt[500010]; unsigned long long has[500010]; unsigned long long val[500010]; list<int> vec[500010]; int main() { ios::sync_with_stdio(0); cin.tie(0); auto t = clock(); auto now_time = [&] { return (clock...
#include <bits/stdc++.h> using namespace std; int N; vector<int> V; bool solve(int n); int main() { ios_base::sync_with_stdio(false); int i, st, dr, mid; cin >> N; V.resize(N); for (i = 0; i < N; ++i) { cin >> V[i]; } sort(V.begin(), V.end()); st = 1; dr = N; whil...
#include <bits/stdc++.h> using namespace std; string s, t; int l = 0, r = 0; int main() { cin >> s >> t; while (s[l] != | ) l++; r = s.size() - l - 1; int dif; if (l > r) dif = t.size() - (l - r); else dif = t.size() - (r - l); if (dif < 0 || dif & 1) { cout << Im...
#include <bits/stdc++.h> using namespace std; long long fib[100]; void init() { fib[0] = 1, fib[1] = 2; for (int i = 2; i <= 85; i++) fib[i] = fib[i - 1] + fib[i - 2]; } int w[100]; int dp[100][2]; void solve(long long x) { memset(w, 0, sizeof(w)); memset(dp, 0, sizeof(dp)); int num = ...
#include <bits/stdc++.h> using namespace std; int a, s, d, n; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a >> s; if (s - a >= 2) d++; } cout << d; }
#include <bits/stdc++.h> using namespace std; const int N = 1000005; int n, t1, t2, cnt; vector<int> mem[N]; int imp[N], hgt[N], res[N]; int p[N], noww[2 * N], goal[2 * N]; void link(int f, int t) { noww[++cnt] = p[f]; goal[cnt] = t, p[f] = cnt; } void DFS(int nde, int fth) { for (int i = ...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) f = ch == - ? -1 : f, ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return x * f; } const int N = 200050; int sta[3][N], f[3][N], F[3]; in...
#include <bits/stdc++.h> using namespace std; struct ans { int s, t; }; const int nmax = 100006; int n, v[nmax], s1[nmax], s2[nmax], rasp, acts, fp1[nmax], fp2[nmax]; ans vrasp[nmax]; bool ver; int compar(ans a, ans b) { if (a.t != b.t) return a.t < b.t; else return a.s < b.s; ...
#include <bits/stdc++.h> using namespace std; int o, trues, Bruh, YO; bool levls[696969]; int main() { int n, X; cin >> n; for (int a = 0; a < 2; a++) { cin >> Bruh; for (int AL = 0; AL < Bruh; AL++) { cin >> YO; levls[YO] = true; } } for (int x = 1; x <= n;...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int N = 1000040; long long fact[N], invf[N]; vector<long long> primes; long long add(long long x, long long y) { return (x + y) % mod; } long long mul(long long x, long long y) { return (x % mod) * (y % mod) % mod; } l...
#include <bits/stdc++.h> using namespace std; int main() { int t, y; cin >> t; while (t--) { int n; cin >> n; long long a[n]; for (int i = 0; i < n; i++) cin >> a[i]; long long res, mx = 0; for (int i = 0; i < n - 1; i++) { res = a[i] * a[i + 1]; mx = ...
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; if (n == 0) { printf( a ); return 0; } for (char c = a ; c <= z && n; c++) { int sum = 0, i; for (i = 0; i <= n; i++) { n -= i; cout << c; } } printf( n ); retu...
#include <bits/stdc++.h> using namespace std; inline long long mult(long long a, long long b, long long mod) { if (b == 0) return 0; if (b % 2 == 1) return (mult(a, b - 1, mod) + a) % mod; return (mult(a, b / 2, mod) * 2) % mod; } inline long long BinPow(long long a, long long b, long long mod) { ...
#include <bits/stdc++.h> using namespace std; int setbit(int n, int pos) { return n = n | (1 << pos); } int resetbit(int n, int pos) { return n = n & ~(1 << pos); } bool checkbit(int n, int pos) { return (bool)(n & (1 << pos)); } template <typename T> T modMul(T x, T y, T mod = 1e9 + 7) { x %= mod; ...
#include <bits/stdc++.h> using namespace std; template <class T> T max(T a, T b, T c) { return max(a, max(b, c)); } int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long a, b, c; cin >> a >> b >> c; cout << 2 * min(a + c, min(b + c, (a + b + c...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int x, y, z; cin >> x >> y >> z; if (x > y) { if (x > y + z) cout << + ; else cout << ? ; } else if (x < y) { if (y > x + z) cout << - ; else...
#include <bits/stdc++.h> using namespace std; const int INF = (int)2e9; const long long INFL = (long long)9e18; const int MAXINT = ((~0) ^ (1 << 31)); const long long MAXLL = ((~0) ^ ((long long)1 << 63)); template <class T> inline T pow2(T a) { return a * a; } template <class T> inline bool min...
#include <bits/stdc++.h> using namespace std; int main() { int n, h, m; int mo, md, ho, hd; string t; cin >> t; n = t.size(); m = (t[n - 2] - 0 ) * 10 + t[n - 1] - 0 ; h = (t[n - 5] - 0 ) * 10 + t[n - 4] - 0 ; for (;;) { m = (m + 1) % 60; if (m == 0) { h = (h ...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(NULL); int n; cin >> n; priority_queue<int, vector<int>, greater<int>> servers; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> const int maxn = 1e5, maxm = 1e5, maxCell = 1e5; const int maxv = maxCell + 4, maxe = maxCell * 4 + 4 * maxCell; const int inf = std::numeric_limits<int>::max() / 2; namespace Network { struct GraphInfo { int vertex, source, sink; }; struct Edge { int from, to; mutable...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int i = k - 1; while (n % i != 0) { i--; } cout << n / i * k + i << endl; }
#include <bits/stdc++.h> using namespace std; vector<int> v[30]; string s[100010]; char aver[300010]; long long f(int p, int ch, int si) { int mi = 99999999; if (v[ch].size() == 0) return s[si].size(); for (int i = 0; i < v[ch].size(); i++) mi = min(mi, abs(p - v[ch][i])); return mi; } int...
#include <bits/stdc++.h> char a[1111]; int main() { int i, j, k, l, s, flag; while (~scanf( %s , a + 2)) { a[0] = a[1] = 0 ; s = 0; l = strlen(a); flag = 0; for (i = 0; i < l - 2; i++) { if (flag) break; for (j = i + 1; j < l - 1; j++) { if (flag) bre...
#include <bits/stdc++.h> using namespace std; const int N = 510; const int INF = 0x3f3f3f3f; const int MOD = (int)1e9 + 7; int n; long long ans; void dfs(int a, int b, int c) { if (a == n) { ++ans; return; } for (int i = 0; i < n; ++i) { if (b & (1 << i)) continue; if (...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; while (cin >> a >> b >> c) { if (b == a / 2 && c == a / 2) cout << NO << endl; else if (b == a / 2 && c == a / 2 + 1) cout << NO << endl; else if (b == a / 2 + 1 && c == a / 2 + 1) cout << ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a[100000], p[100000], i, ans = 0, price = INT_MAX; scanf( %d , &n); for (i = 0; i < n; i++) scanf( %d %d , &a[i], &p[i]); for (i = 0; i < n; i++) { price = min(price, p[i]); ans += (a[i] * price); } printf( %d , an...
#include <bits/stdc++.h> using namespace std; long long h12, h13, h14, h23, h24, h34; long long k1, k2, k3; long long x1, x2, x3, x4, x5, x6, x7; long long min_x7, max_x7, best_x7; long long good = 0; long long len = -1; void fail() { printf( -1 n ); exit(0); } int main() { cin >> h12 >>...
#include <bits/stdc++.h> using namespace std; bool used[1005]; vector<int> v; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k, a, b, c, d; cin >> n >> k >> a >> b >> c >> d; if (n == 4 or k <= n) { cout << -1; return 0; } used[a] = used[b] = used[c]...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int i, j, n, k, m, t, x = 0, y, c = 0, sum = 0, maxx, t1, t2, x1, x2, y1, y2, m1, m2; double ans1, ans2, ans = 1000000000000000000; ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, h, m, i, j, x, y, z, ans; cin >> n >> h >> m; long long int a[n + 10]; for (i = 1; i <= n; i++) { a[i] = h; } for (i = 1; i <= m; i++) { cin >> x >> y >> z; for (j = x; j <= y; j++) { a[j] =...
#include <bits/stdc++.h> using namespace std; int n, m; char jz[1000006][5]; int cnt2 = 0, cnt3 = 0, dp[1000006][8]; int cal(int x) { int ans = 0; while (x > 0) { if (x & 1) ans++; x /= 2; } return ans; } bool check_3(int x, int y) { int sum = cal(x / 2) + cal(y / 2); i...
#include <bits/stdc++.h> using namespace std; int n, q, p; long long* pt; long long a[200000], k, sum = 0LL; int main() { cin >> n >> q; for (int i = (0); i < (n); i++) { cin >> a[i]; if (i) a[i] += a[i - 1]; } for (int i = (0); i < (q); i++) { cin >> k; sum += k; ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; inline bool chmax(int& a, int b) { if (a < b) { a = b; return true; } return false; } constexpr int B = 210; int q, n, e, i, j, ans, res, l, r, val, x, mid; void solve() { cin >> n; vector<vector<in...
#include <bits/stdc++.h> const int maxn = 100000 + 5; using namespace std; int main() { int n, a[maxn]; cin >> n; bool flag = false; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 2; i < n; i++) { int x = a[i], y = a[i - 1]; int z = a[i - 2]; if ((y...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = 998244353; const ll MX = 3e5 + 5; ll fct[MX] = {1}, inv[MX] = {1}; ll power(ll a, ll b, ll p = 1) { if (b == 0) return 1; ll res = power(a, b / 2) % MOD; if (b & 1) { return (((res * res) % MOD) * a) % MOD; ...
#include <bits/stdc++.h> using namespace std; int a[100][100], n, row[55][100005], col[55][100005]; bool valid(int i, int j) { for (int k = 0; k < n; k++) { if (k == i) continue; int x = a[i][j] - a[k][j]; if (x > 0 && row[i][x] && (x != a[i][j] || row[i][x] > 1)) return 1; } return ...
#include <bits/stdc++.h> using namespace std; using namespace std; const long long mo = 1000000007; int n, k; long long c[15][15]; long long f[210][210][10]; int flag[10][10] = {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 1, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 0, 1, 0, 0, 0, 0, 0, 0, 0}, {1, 2, 0, 1, 0, 0, ...
#include <bits/stdc++.h> using namespace std; int mobius[500005], prime_cnt[500005], prime[500005], present[500005], nums[500005], cnt[500005]; vector<int> divisors[500005]; void calc_divisors(int val) { int i; if (divisors[val].size() > 0) return; int foo = sqrt(val); for (i = 1; i <= foo...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, T, i, j, temp, le, ri, mid, ma = 0; cin >> n >> a >> b >> T; char str[n]; cin >> str; int r[n], l[n]; if (str[0] == h ) r[0] = 1; else r[0] = b + 1; for (i = 1; i < n; i++) { if (str[i] == h )...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 1e3 + 10; char s[N], x[N], y[N]; int n, d; namespace Trie { const int M = N * 60; int ch[M][10], tot = 1, rt = 1, fail[M]; bool ed[M]; inline void insert(int l, int r) { int now = rt; for (int i = l; i <= r;...
#include <bits/stdc++.h> using namespace std; int inp[105][105]; int a[105]; int b[105]; int temp[105]; int main() { int n, m; scanf( %d , &n); scanf( %d , &m); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) scanf( %d , &inp[i][j]); for (int i = 0; i < m; i++) b[i] = inp[0...
#include <bits/stdc++.h> using namespace std; const int maxn = 55, maxm = 9; int loc[maxn][2], col[maxn]; char s[maxn][maxn], res[maxn][maxn]; int num[maxn][maxn], used[maxm][maxm]; int n, m, ans, cnt; void dfs(int u, int v) { int i, j, x, y; if (u > 14) { memset(used, 0, sizeof used); ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6; vector<int> num, low, S, vis; int cntr, numCC; int par[N]; vector<int> adj[N]; void tarjanSCC(int v) { low[v] = num[v] = ++cntr; vis[v] = 1; S.push_back(v); for (auto u : adj[v]) { if (num[u] == -1) tarjanSCC(u); ...
#include <bits/stdc++.h> using namespace std; using namespace std; template <typename T, typename U> std::istream& operator>>(std::istream& i, pair<T, U>& p) { i >> p.first >> p.second; return i; } template <typename T> std::istream& operator>>(std::istream& i, vector<T>& t) { for (auto& v : t...
#include <bits/stdc++.h> using namespace std; template <class T, size_t... Is> struct arr_helper; template <class T, size_t... Is> using arr = typename arr_helper<T, Is...>::type; template <class T> struct arr_helper<T> { using type = T; }; template <class T, size_t I, size_t... Is> struct arr_h...
#include <bits/stdc++.h> using namespace std; int main() { int n; int t; cin >> n >> t; if (t == 10 && n == 1) return cout << -1, 0; string s; if (t == 10) s += 10 , n -= 2; else s += (char)(t + 48), n--; while (n--) s += 0 ; cout << s; }