func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-11; long long n, l, v1, v2, k; bool check(double tim) { int tmp = n; double t = 0; double grx = 0, bus = 0; while (tmp > 0) { double del = l - grx; if (del / v2 > tim + EPS / 100) { return 0; } do...
#include <iostream> #include <cstdio> #include <cmath> #include <ctime> #include <cstdlib> #include <cassert> #include <vector> #include <list> #include <stack> #include <queue> #include <deque> #include <map> #include <set> #include <bitset> #include <string> #include <algorithm> #inclu...
#include <bits/stdc++.h> using namespace std; int main() { int a[112]; int i; for (i = 0; i < 4; i++) cin >> a[i]; sort(a, a + 4); int tr = 0, seg = 0, im = 0; if (a[1] + a[2] > a[3]) { tr++; } else if (a[0] + a[1] > a[3]) { tr++; } else if (a[0] + a[2] > a[3]) { tr...
#include <bits/stdc++.h> using namespace std; const int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1}; const double EPS = 1e-8; const double PI = acos(-1.0); int popcount(int n) { return __builtin_popcount(n); } int popcount(long long n) { return __builtin_popcountll(n); } template <class T> int SIZE(T a) ...
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); } void online_judge() { freopen( input.txt , r , stdin); freopen( output.txt , w , stdout); } const int flag_max = 0x3f3f3f3f; const long long OO = 1e9; const doubl...
#include <bits/stdc++.h> using namespace std; namespace { using T = long long; constexpr char endl = n ; const int maxN = 205; const int maxM = 1e5 + 5; const T base = 100000; T Ceil(T x, T y) { return (x + y - 1) / y; } int n, m; T t[maxN], x[ma...
#include <bits/stdc++.h> using namespace std; int n, maxi[((int)101 * 1000) / ((int)350) + 1000], fnsh, id[((int)101 * 1000)], ex[((int)101 * 1000)]; vector<int> v[((int)101 * 1000) / ((int)350) + 1000]; void reset() { int num = 0; for (int i = 0; i < fnsh; v[i].clear(), v[i].resize(0), i++) ...
#include <bits/stdc++.h> using namespace std; inline int _Int() { int x; scanf( %d , &x); return x; } long long int bigMod(long long int A, long long int P, int M) { long long int R = 1; for (A %= M; P; P >>= 1) { if (P & 1) R = (R * A) % M; A = (A * A) % M; } return R; ...
#include <bits/stdc++.h> using namespace std; string to_string(string s) { return + s + ; } string to_string(char c) { return + string(1, c) + ; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? true : false ); } template <typename A...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; map<long long, vector<long long> > m; map<long long, bool> v; map<long long, long long> c; vector<long long> b; long long i, j, k, x, y, r; for (i = 1; i <= n; i++) { cin >> x >> y; if (x ==...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double eps = 1e-8; const double PI = acos(-1.0); const int maxn = 370360; int dp[maxn], k, vis[maxn], sp[maxn], head, tail; long long q[maxn]; int gcd(int x, int y) { int tp = x % y; while (tp) { x = y; y...
#include <bits/stdc++.h> using namespace std; const int size = 1e5 + 10; int afx[size]; int dis[size]; int main() { int n, k; scanf( %d%d , &n, &k); int total = 0; int ans = 0; for (int i = 0; i < n; i++) { scanf( %d , afx + i); dis[i] = 10 - afx[i] % 10; total += dis[i];...
#include <bits/stdc++.h> using namespace std; int d[100]; int main() { int n, a, b, c = 0; cin >> n; for (int i = 1; i < n; i++) { cin >> d[i]; } cin >> a >> b; for (int i = a; i < b; i++) { c += d[i]; } cout << c; return 0; }
#include <bits/stdc++.h> using namespace std; using Int = long long; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << ( << a.first << , << a.second << ) ; }; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1005, maxd = 15; int f[maxn], g[maxn][maxd][maxn], rfac[maxn], n, d, mo; int pow(int a, int b) { int tmp = 1; for (; b; b >>= 1, a = a * 1ll * a % mo) if (b & 1) tmp = tmp * 1ll * a % mo; return tmp; } int main() { cin >> n...
#include <bits/stdc++.h> using namespace std; const int MAX = 1000 * 100 + 1; const long long INF = 1e12; const int MOD = 1000 * 1000 * 1000 + 7; const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; const int MAXN = 2 * 1000 * 100 + 1; struct edge { int to, w...
#include <bits/stdc++.h> using namespace std; int T, n, m, u, v, lab[300001]; vector<int> g[300001]; long long cnt[3]; long long const mod = 998244353; bool impossible; void DFS(const int& u) { for (const int& v : g[u]) if (!lab[v]) { lab[v] = 3 - lab[u]; cnt[lab[v]]++; D...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); template <typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } template <typename T> inline void write(T x) { ...
#include <bits/stdc++.h> using namespace std; int main() { int smallest, largest, n, count = 0, a; cin >> n; for (int i = 0; i < n; i++) { cin >> a; if (i == 0) { smallest = a; largest = a; } else { if (a > largest) { count += 1; largest = a;...
#include <bits/stdc++.h> using namespace std; int n, a, b; string s, g; map<string, pair<int, int> > m; int main() { m[ goat ] = make_pair(1, 1); m[ asiago ] = make_pair(1, 2); m[ camembert ] = make_pair(1, 3); m[ gouda ] = make_pair(2, 1); m[ feta ] = make_pair(2, 2); m[ swiss ] = mak...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int n, m, p; const double PI = acos(-1); vector<int> a, b; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; cin >> n >> m >> p; for (int i = (int)1; i <= (int)n; i++) { int x;...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:400000000 ) int n, a[200010], b[200010], f[200010]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { int x; cin >> x; f[x - 1] = i; } for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; int memo[77][107][107]; inline int index(char ch) { return (ch == @ ) ? 0 : ch - a ; } bool eval(char ch, int i, int j, vector<vector<pair<int, char>>> &adj) { int val = memo[index(ch)][i][j]; if (val == 1) return true; if (val == 2) return false; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 126, MOD = 12345; int res[maxn][maxn], tmp[maxn][maxn], POW[maxn][maxn], flag[maxn], check[maxn]; int A[maxn][maxn], B[maxn][maxn], a[maxn << 3], b[maxn << 3]; int m, size = 1, temp, ans, vec[maxn << 3], judge; char ch; long long n; void mul...
#include <bits/stdc++.h> using namespace std; char s[100005]; char b[100005]; int main() { cin >> s; int cnt = 0; char x = a ; for (int i = strlen(s); i >= 0; --i) { if (s[i] >= x) { x = s[i]; b[cnt++] = x; } } while (cnt--) { printf( %c , b[cnt]); ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<string> nap(n); for (int i = 0; i < n; ++i) cin >> nap[i]; vector<vector<int> > dp(26); for (int i = 0; i < 26; ++i) for (int j = 0; j < 26; ++j) dp[i].push_back(0); ...
#include <bits/stdc++.h> using ld = long double; using ul = std::size_t; template <typename T, ul C> using ar = std::array<T, C>; const int MN = 55; const ld INF = 1e10; const ld EPS = 1e-9; template <ul C> ar<ld, C>& operator*=(ar<ld, C>& a, const ld& v) { for (ul i = 0; i < C; ++i) a[i] *= v; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, dd, hh, mm, t; int sep[16]; char buf[80]; vector<string> todo; map<string, int> cost; vector<pair<int, int> > time; vector<vector<pair<int, bool> > > dp; vector<pair<pair<int, int>, pair<int, int> > > job; scanf...
#include <bits/stdc++.h> using namespace std; bool r[100010], c[100010]; int main() { ios_base::sync_with_stdio(false); long long n, m, a, b, li, co; cin >> n >> m; li = co = 0; long long ans; for (int i = 0; i < m; i++) { cin >> a >> b; if (r[a] == false) { r[a] = true...
#include <bits/stdc++.h> using namespace std; map<string, int> Ts; string size[101] = { S , M , L , XL , XXL }; inline int to_size(string s) { for (int i = 0; i < 5; ++i) { if (s == size[i]) return i; } } int main() { int a[11], k; string pe[10010]; for (int i = 0; i < 5; ++i) ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 5010; vector<int> G[maxn]; int d[maxn][maxn][2]; void check(int &a, int b) { if (a > b) a = b; } int dfs(int u, int fa) { int num = G[u].size(), tot = 0, now = 0; d[u][0][0] = 0; d[u][0][1] = 0; ...
#include <bits/stdc++.h> const int inf = (1ll << 30) - 1; const int maxn = (int)1e5 + 10; const int mod = (int)1e9 + 7; using namespace std; void solve() { string second; cin >> second; sort(second.begin(), second.end()); int cnt = 0; vector<string> v; string x = ; x += second[0]...
#include <bits/stdc++.h> using namespace std; struct flow_graph { int V, E, s, t; int *flow, *low, *cap, *to, *next, *last, *delta; int *dist, *q, *now, head, tail; flow_graph() {} flow_graph(int V, int E) { (*this).V = V; (*this).E = 0; int TE = 2 * (E + V + 1); flow = n...
#include <bits/stdc++.h> using namespace std; int n, m, K; vector<int> G[700005], W[700005], I[700005]; long long int ptr[700005]; long long int ans[700005]; int dis[700005], rem[700005], ulta[700005], vis[700005], tim = 0, lev[700005]; int mx = 0; vector<int> jinish[700005]; void dfs(int u, int l) { ...
#include <bits/stdc++.h> using namespace std; class Timer { clock_t start; public: Timer() : start(clock()) {} double now() { return (double)(clock() - start) / CLOCKS_PER_SEC; } } timer; struct node { int u, v, l; friend bool operator<(const node& a, const node& b) { return a.l < b.l;...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, i; cin >> a >> b; int c = a; while (a >= b) { c++; a++; a = a - b; } i++; cout << c; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, K; int s[1000005], p[1000005]; int main() { scanf( %d%d%d , &n, &m, &K); ++K; for (int i = 1; i <= m; i++) { int x, y; scanf( %d%d , &x, &y); if (x + K == y) s[x] = 1; else if (x + 1 != y) return puts( 0 ...
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c, co, i, j, k, l, m, n; cin >> n; co = 0; set<long long int> myset; for (i = 0; i < n; i++) { cin >> a; myset.insert(a); } if (myset.size() > 3) cout << NO n ; else if (myset.size() == ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mod = 1e9 + 7; const int inf = (1 << 30) - 1; const ll infll = (1LL << 61) - 1; double a[1 << 17]; int b[1 << 17], N; ll pos_sum = 0, neg_sum = 0; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); ci...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); double a[1001][1001], x, y, z1, z2, z3, z4; long long t, n, i, j; for (i = 0; i < 1001; i++) { if (i == 0) a[0][0] = 0.0; else a[i][0] = 1.0; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(NULL); int n, m; cin >> n >> m; vector<char> A(n * 2); for (int i = 0; i < n * 2; i++) cin >> A[i]; vector<vector<pair<int, int> > > table(n * 2, vector<pair<int, int> >(20)); for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, mod = 1e9 + 7; int grundy[2000][2000], dr[50], dc[50]; int x, y, n, d; bool valid(int x, int y) { return x * x + y * y <= d * d; } int mex(set<int> &st) { int ret = 0; while (st.count(ret)) ret++; return ret; } int solve(in...
#include <bits/stdc++.h> long long int MAX(long long int a, long long int b) { if (a > b) return a; else return b; } using namespace std; int main() { string S, SS; cin >> S >> SS; int PR = 0, DIF = 0, l = S.length(); for (int x = 0; x < l; x++) if (S[x] != SS[x]) DIF++...
#include <bits/stdc++.h> using namespace std; int b, ans, r; bool x; int main() { cin >> b; while (!x) { b++; ans++; r = abs(b); if ((r - 8) % 10 == 0 && r != 0) x = 1; r /= 10; if ((r - 8) % 10 == 0 && r != 0) x = 1; r /= 10; if ((r - 8) % 10 == 0 && r !=...
#include <bits/stdc++.h> using namespace std; const long long oo = (long long)1e4; long long n, k; vector<pair<int, int> > l, r; int length(int x) { return x < 10 ? 1 : length(x / 10) + 1; } pair<int, int> checkWavy(int x) { if (x < 10) return make_pair(1, 0); int digits[8] = {x % 10, x / 10 % 10}, ...
#include <bits/stdc++.h> using namespace std; const int N = 505; int a[N]; int b[N]; int dp[N]; int pv[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } int m; cin >> m; ...
#include <bits/stdc++.h> using namespace std; const int N = 200010; int main() { int t; cin >> t; while (t--) { int a, b; cin >> a >> b; int s = abs(a - b); int ans = s / 5; s %= 5; if (s > 2) ans += 2; else if (s != 0) ans++; cout << ans...
#include <bits/stdc++.h> using namespace std; const int NN = (1 << 15); int pre[NN], suf[NN]; map<string, int> mp; int main() { int n; cin >> n; for (int i = 1, x; i <= n; i++) { cin >> x; pre[i] = x >> 15; suf[i] = x & (NN - 1); } for (int i = 0; i < NN; i++) { str...
#include <bits/stdc++.h> using namespace std; int m, n; int mat[105][105]; int main() { cin >> m >> n; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cin >> mat[i][j]; } } if (m % 2 != 0) { cout << m << endl; } else { int aux = m; bool flag ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m; cin >> n >> m; double num; num = (double)m / n; if (n == m) { cout << 0 ; } else { long long int x = num, counter1 = 0, counter2 = 0; if (ceil(num) == num) { if (x % 2 == 0 || x % 3 == 0...
#include <bits/stdc++.h> using namespace std; long long calc(int n, int d, long long m, int l) { for (long long i = 0; i < n; i++) { long long high = i * m + l; long long x = high % d; if (d < (x + m - l)) { return high + (d - x); } } long long high = (n - 1) * m + l; ...
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { if (a.second == b.second) return (a.first < b.first); return (a.second < b.second); } int main(void) { long long a, b; cin >> a >> b; string str = to_string(b); reverse(str.be...
#include <bits/stdc++.h> using namespace std; int n; void finish(int x) { printf( ! %d n , x); fflush(stdout); exit(0); } int query(int x) { int a, b, mult = 1; if (x > n / 2) { x -= n / 2; mult = -1; } printf( ? %d n , x); fflush(stdout); scanf( %d , &a); p...
#include <bits/stdc++.h> using namespace std; const int N = 500005; int n, k, i, t, j, m; char c[N]; long long ans, s; struct str { int l, r; } p[N], a[N]; bool cmp(str a, str b) { return a.r - a.l > b.r - b.l; } bool cmp2(str a, str b) { return a.r < b.r; } int main() { scanf( %d , &n); ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 9, B = 511; inline long long read() { long long res = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { res = (res << ...
#include <bits/stdc++.h> const int MAX_MEM = 1e8; int mpos = 0; char mem[MAX_MEM]; inline void *operator new(size_t n) { assert((mpos += n) <= MAX_MEM); return (void *)(mem + mpos - n); } inline void operator delete(void *) noexcept {} using namespace std; struct Ex { int s, d, c, i; }; ...
#include <bits/stdc++.h> using namespace std; int n, s1[1000005], r, s2[1000005], dp[1000005], w, mi, mid, ma; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &s1[i]); } for (int i = 1; i <= n; i++) { scanf( %d , &r); s2[r] = i; } for (int i = 1; ...
#include <bits/stdc++.h> using namespace std; vector<long long> sieve(long long n) { long long *arr = new long long[n + 1](); vector<long long> vect; for (long long i = 2; i <= n; i++) if (arr[i] == 0) { vect.push_back(i); for (long long j = 2 * i; j <= n; j += i) arr[j] = 1; ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000000,100000000000 ) const long long INF = 1000000007; const double cp = 2 * asin(1.0); const double eps = 1e-9; const long long mod = 1000000007; using namespace std; int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> using namespace std; const int N = 1000000 + 100, logN = 23; long long read() { long long 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 * 10 + c - 0 ; ...
#include <bits/stdc++.h> using namespace std; char s[100001], a[5] = hard ; int x[100001]; long long d[5][100001]; const long long inf = 0x3f3f3f3f3f3f3f3f; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %c , &s[i]); for (int i = 1; i <= n; i++) scanf( %d , &x[i])...
#include <bits/stdc++.h> using namespace std; long long fastModPow(long long a, long long n, long long mod) { if (mod == 1) return 0; if (n == 1) return a % mod; long long res = fastModPow(a, n / 2, mod); res = res * res % mod; if (n & 1) res = res * a % mod; return res; } long long fast...
#include <bits/stdc++.h> using namespace std; const int maxN = 100 * 1000 + 5; const int lim = 1000 * 1000 * 1000; const int inf = 1000 * 1000 * 1000 + 5; int f[3 * maxN]; vector<pair<int, string> > a[maxN]; string t; int ans; void dfs(int v, int F) { for (auto u : a[v]) { int tmp = F; ...
//#include <bits/stdc++.h> //using namespace std; #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC target( avx ) #pragma GCC optimize( Ofast ) #include <cstdio> #define rep(i,_l,_r) for(signed i=(_l),_end=(_r);i<=_end;++i) #define fep(i,_l,_r) for(signed i=(_l),_end=(_r);i>=_end;--i) #de...
#include <bits/stdc++.h> using namespace std; int n, t; char G[500005]; int solve(int k) { int last = n, i; int hs, ss; hs = ss = 0; for (i = 1; i <= n; i++) { if (G[i] == H ) hs++; if (G[i] == S ) ss++; if (G[i] == H ) last = i; if (hs - ss >= k && G[i] != . ) last =...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n - 1; i++) cout << 8; cout << 9 << endl; for (int i = 0; i < n; i++) cout << 1; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <class T, size_t N> ostream& operator<<(ostream& os, const array<T, N>& v); template <class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << ( << p.first << , << p.second << ) ; } template <class T> ostr...
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f; const double eps = 1e-6; const long long mod = 998244353; inline string getstr(string &s, long long l, long long r) { string ret = ; for (long long i = l; i <= r; i++) ret.push_back(s[i]); return ret; } long long...
#include <bits/stdc++.h> int main() { double n, m; scanf( %lf%lf , &n, &m); int a[1000], b[1000]; for (int i = 0; i < n; i++) scanf( %d , a + i); for (int i = 0; i < n; i++) scanf( %d , b + i); double x; if (b[0] != 1 && a[0] != 1) { x = m + m / (b[0] - 1); for (int i = n - 1; ...
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; int l = 0, r = 0, u = 0, d = 0; int tx = 0, ty = 0, dir = 0, px = 0, py = 0, k = 0; while (true) { px = tx; py = ty; if (dir == 0) { r = tx = r + 1; dir = 1; } else if (dir...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; int mini1 = 0; for (int i = 0; i < n; i++) { cin >> a[i]; mini1 = max(mini1, a[i]); } int mini2 = 0; cin >> n; int b[n]; for (int i = 0; i < n; i++) { cin >> b[i]; mi...
#include <bits/stdc++.h> using namespace std; void read(int &a) { a = 0; char c = getchar(); while (c < 0 || c > 9 ) { c = getchar(); } while (c >= 0 && c <= 9 ) { a = (a << 1) + (a << 3) + (c ^ 48); c = getchar(); } } const int Maxn = 200000; struct Segment { ...
#include <bits/stdc++.h> using namespace std; int main() { int problem, time; cin >> problem >> time; int sum = 240; int j = 0; for (int i = 1; i <= problem; ++i) { sum -= i * 5; if (sum < time) { break; } j++; } cout << j; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100 + 20; const int LG = 15; int a[N], cnt[N]; map<vector<int>, int> mp; int main() { ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; cnt[i] = __bui...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7, maxn = 3e5 + 500; vector<pair<int, int> > v[maxn]; bool visited[maxn], deg[maxn]; int d[maxn]; set<int> s; void dfs(int u, int par) { visited[u] = 1; int idx; for (int i = 0; i < v[u].size(); i++) { int w = v[u][i].fi...
#include <bits/stdc++.h> using namespace std; vector<int> print; const int Maxn = int(1e2) + 10; int primes[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59}; int n, a[Maxn], xrn[60 + 10], dp[Maxn][(1 << 18) + 1000], adad[Maxn][(1 << 18) + 1000]; void xr() ...
#include <bits/stdc++.h> using namespace std; int x[100010]; int main() { int n, a; cin >> n >> a; if (n == 1) { cout << 0 << endl; return 0; } for (int i = 0; i < n; ++i) { cin >> x[i]; } sort(x, x + n); int l = 1, r = n - 1; int ans = 0; ans = min(abs(a ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, op, i, index = 0; cin >> n >> k; char ss[n - 1]; op = k; i = 97; while (op--) { ss[index] = char(i); i++; index++; } if (n - k != 0) { for (int d = 0; d < n - k; d++) { ss[index] = ss...
#include <bits/stdc++.h> using namespace std; inline int in() { int x; scanf( %d , &x); return x; } inline void priv(vector<int> a) { for (int i = 0; i < ((int)(a).size()); ++i) printf( %d%c , a[i], i == (int)(a).size() - 1 ? n : ); } template <typename T> istream& operator>>(i...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 3; int n; int main() { cin >> n; cout << (int)log2(n) + 1; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, m, n, rstart, rend, cstart, cend; scanf( %d %d %d %d , &n, &m, &a, &b); if ((m >= n) || (m == 1)) printf( 1 n ); else { rstart = (a / m) + 1; if ((a % m) == 0) --rstart; cstart = a - ((rstart - 1) * m); ...
#include <bits/stdc++.h> using namespace std; int n, m, ans, fa[100001]; bool mark[100001]; int find(int x) { if (x == fa[x]) return x; return fa[x] = find(fa[x]); } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) fa[i] = i; for (int i = 1; i <= m; i++) { int x, y; c...
#include <bits/stdc++.h> using namespace std; using ll = long long; using uint = unsigned int; template <class T> using V = vector<T>; template <class T> using VV = vector<vector<T>>; template <class T, class U> void chmax(T& x, U y) { if (x < y) x = y; } template <class T, class U> void chm...
#include <bits/stdc++.h> using namespace std; const int N = 1e5; const int INF = 1e9; long long MOD = 998244353; long long sum(long long n) { long long sm = 0; while (n) { sm += n % 10; n /= 10; } return sm; } int main() { list<int> a; list<int> b; long long n; ...
#include <bits/stdc++.h> using namespace std; int a[514]; long long int dp[514][514]; long long int mod = 1000000007ll; long long int mdp(int s, int e) { if (s == e) return 1; if (dp[s][e] != -1) return dp[s][e]; long long int& ans = dp[s][e]; if (s + 1 == e) return ans = 1; ans = mdp(s + ...
#include <bits/stdc++.h> using namespace std; int N, a, b, Q; long long W[(500000)], S[(500000)], O[(500000)]; map<pair<int, int>, vector<pair<int, int> > > M; void pro(int t, int b, long long* g, int& l) { *g = 0, l = 1; while (b < N) { long long S = W[b] + g[l - 1]; g[l++] = S, b += t; ...
#include <bits/stdc++.h> using namespace std; template <class T> int chkmax(T& a, T b) { if (b > a) { a = b; return 1; } return 0; } template <class T> int chkmin(T& a, T b) { if (b < a) { a = b; return 1; } return 0; } template <class iterator> void out...
#include <bits/stdc++.h> using namespace std; int main() { int n, d; cin >> d >> n; long long int ilosc = 0; for (int i = 0; i < n - 1; i++) { int p; cin >> p; ilosc += (d - p); } cin >> d; cout << ilosc << n ; return 0; }
#include <bits/stdc++.h> using namespace std; long long fastpow(long long base, long long power, long long M) { if (power == 1) return base; long long val = fastpow(base, power / 2, M); return (power % 2 == 0) ? (val * val) % M : (((val * val) % M) * base) % M; } inline void debugMode() { ios_ba...
#include <bits/stdc++.h> using namespace std; template <typename T> void cmax(T& a, T b) { a = max(a, b); } template <typename T> void cmin(T& a, T b) { a = min(a, b); } void _BG(const char* s) {} template <typename T, typename... TT> void _BG(const char* s, T a, TT... b) { for (int c = ...
#include <bits/stdc++.h> using namespace std; const int a[] = {4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346, 355, 378, 382, 391, 438, 454, 483, 517, 526, 535, 562, 576, 588, 627, 634, 636, 645, 648, 654, 663, 666, 690, 706, 728, 729, ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1003; int n, k; int pos[5][maxn]; int dp[maxn]; bool vis[maxn]; vector<int> v[maxn]; int dfs(int cur) { if (vis[cur]) return dp[cur]; vis[cur] = true; for (int i = 0; i < v[cur].size(); i++) { int nxt = v[cur][i]; dp[...
#include <bits/stdc++.h> using namespace std; string imp = Impossible n ; const int N = 2e5 + 5; int bfstim[N]; long long MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tests; tests = 1; cin >> tests; while (tests--) { int ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int UNDEF = -1; const long long INF = 1e18; template <typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; } template <typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ?...
#include <bits/stdc++.h> using namespace std; using ll = int; vector<pair<ll, string>> con[101010]; int main() { ios_base::sync_with_stdio(false); cout.tie(NULL); int n, m; cin >> n >> m; int reg, sc; string name; while (n--) { cin >> name; cin >> reg; cin >> sc; ...
#include <bits/stdc++.h> using namespace std; long long n, m, x, y, a, l, w, z, ss, t, k, e, c, total, nnn, yes, mx = 531, mn = -1, r, xx, yy, last, cas; map<string, int> wow; int main() { string s; cin >> s; wow[s] = 1; x = 1; l = s.size(); for (int i = 0; i < l; i++) { char...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, p1l, p1r, p2l, p2r; string s, t, ans; int main() { ios_base::sync_with_stdio(false); cin >> s >> t; sort(s.begin(), s.end()); sort(t.begin(), t.end()); ans.resize(s.length(), 0); p1l = 0; p2r = (int)s.len...
#include <bits/stdc++.h> using namespace std; vector<int> finger; int seq[100]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> seq[i]; for (int i = 0; i < m; i++) { int x; cin >> x; finger.push_back(x); } for (int i = 0; i < n; i++) { for...
#include <bits/stdc++.h> using namespace std; vector<int> split, ans; int a[300002]; int p[300002][3]; long long max(long long a, long long b) { return a >= b ? a : b; } long long min(long long a, long long b) { return a <= b ? a : b; } int main() { int n, i, j, l, r; scanf( %d , &n); for (i =...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int u, v, w; cin >> u >> v; if (u > v || (u + v) % 2 != 0) cout << -1 << endl; else if (u == v && u == 0) cout << 0 << endl; else if (u == v) cout << 1 ...