func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int MaxN = 4010; const int MOD = 1000000009; int n, w, b; long long p[MaxN], r[MaxN]; long long power(long long x, long long y) { if (!y) return 1; long long t = power(x, y / 2); t = t * t % MOD; if (y & 1) t = t * x % MOD; return t; ...
#include <bits/stdc++.h> using namespace std; int main() { vector<long long int> v(1000005); long long int i, n, j; for (i = 2; i < 1000005; i++) { j = i * 2; while (j <= 1000005) { v[j] = 1; j += i; } } cin >> n; j = 1; for (j = 1; j < 1001; j++) { ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 1e5 + 5; int n, a[maxn]; int b[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; int sum = 0; map<int, int> mp; for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i...
#include <bits/stdc++.h> using namespace std; vector<int> pf(const string& s) { int n = s.size(); vector<int> pi(n); for (int i = 1; i < n; i++) { int j = pi[i - 1]; while (j > 0 && s[i] != s[j]) j = pi[j - 1]; if (s[i] == s[j]) j++; pi[i] = j; } return pi; } int main...
#include <bits/stdc++.h> int main() { int n; while (scanf( %d , &n) != EOF) { int sum = 0, i, num, he = 0, div = n + 1; for (i = 1; i <= n; i++) { scanf( %d , &num); sum += num; } for (i = 1; i <= 5; i++) { if ((sum + i) % div == 1) he++; } printf( %...
#include <bits/stdc++.h> using namespace std; template <class A, class B> inline bool mina(A &first, B second) { return (first > second) ? (first = second, 1) : 0; } template <class A, class B> inline bool maxa(A &first, B second) { return (first < second) ? (first = second, 1) : 0; } map<char, ...
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1); long long powm(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = (res * a) % 1000000007; a = (a * a) % 1000000007; b >>= 1; } return res; } long long gcd(long long a, long...
#include <bits/stdc++.h> using namespace std; int main() { long long n, ans = 0; cin >> n; long long a[n + 1]; vector<long long> last; last.push_back(-1); for (int i = 0; i < n; i++) { cin >> a[i]; if (i > 0 && a[i] <= a[i - 1]) last.push_back(i - 1); } last.push_back(n -...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } int n, m, q; int visited[205][205]; ...
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 3e4; long long lp[N], rp[N], l, r, first, second, m, so, k, n; char ch; int main() { cin >> n; for (long long i = (long long)1; i <= (long long)n; i++) { cin >> ch >> k; if (ch == ? ) { first = l - lp[k]; ...
#include <bits/stdc++.h> using namespace std; long long n, s; void dfs(long long x, long long s4, long long s7) { if (n <= x && (x < s || s == 0) && s4 == s7) s = x; if (x <= n * 100) { dfs(x * 10 + 4, s4 + 1, s7); dfs(x * 10 + 7, s4, s7 + 1); } } int main() { cin >> n; dfs(0, ...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; long long n, d; while (t--) { cin >> n >> d; long long arr[n]; for (long long i = 0; i < n; i++) cin >> arr[i]; int count = 0; int i = 1; while (i < n && d > 0 && d >= i) { i...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1000000000 ) using namespace std; const long long inf = (long long)1e18; const long double eps = 1e-8; const long double pi = 3.1415926535; string a[100000][8]; bool u[100000][8][8]; int sx, sy, tx, ty; bool f; void dfs(int x, int y, int t) { ...
#include <bits/stdc++.h> using namespace std; int n,q,a[100005],np[100005],cnt[100005],nx[19][100005],p1,p2; vector<int> p,fac[100005]; bool check(int ind) { for (int i=0; i<fac[ind].size(); i++) { if (cnt[fac[ind][i]]) return 0; } for (int i=0; i<fac[ind].size(); i++) cnt[fac[ind][i...
#include <bits/stdc++.h> using namespace std; const int MAX_N = int(1e5 + 3); template <typename T> void printV(vector<T> v, char sep) { for (long long unsigned int i = 0; i < v.size() - 1; i++) { cout << v[i] << sep; } cout << v[v.size() - 1]; } void printVPCI(vector<pair<char, int>> s) {...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:64000000 ) using namespace std; const int infi = 1e9 + 7; const long long infl = 1e18 + 7; int ar[101]; bitset<101> dp0[10500]; bitset<101> dp[10500]; bitset<101> ndp[10500]; int main() { cin.sync_with_stdio(false); cin.tie(0); int n...
#include <bits/stdc++.h> #pragma GCC optimize(3, Ofast , inline ) #pragma GCC target( avx,avx2 ) using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == - , c = getchar(); while (isdigit(c)) x = (x << 1) + (x << ...
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 9; const double error = 1e-7; const double PI = acos(-1); mt19937 rng( (unsigned int)chrono::system_clock::now().time_since_epoch().count()); inline long long int MOD(long long int x, long long int m = mod) { long long int y =...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; int n, m, cnt, k; struct node { int l, r, sum = 1999999999; } g[maxn * 20]; inline int read() { register int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getc...
#include <bits/stdc++.h> using namespace std; int main() { int n, k = 0; cin >> n; vector<int> adj[n]; for (int i = 1, u, v; i < n; i++) { cin >> u >> v; u--; v--; adj[u].push_back(v); adj[v].push_back(u); k = max(k, max((int)adj[u].size(), (int)adj[v].size()) + 1...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 1; i <= t; i++) { long long n; cin >> n; long long s = sqrt(n); long long c = cbrt(n); long long p = sqrt(cbrt(n)); cout << s + c - p << n ; } }
#include <bits/stdc++.h> using namespace std; inline int read() { int res = 0, f = 1; char ch; while (ch = getchar(), ch < 0 || ch > 9 ) if (ch == - ) f = -1; while (ch >= 0 && ch <= 9 ) res = res * 10 + ch - 0 , ch = getchar(); return res * f; } const int N = 14, M = 4782969, ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) f = ch == - ? -1 : 1, ch = getchar(); while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 48, ch = getchar(); return x * f; } const int maxn = 205; int tot; ...
#include <bits/stdc++.h> using namespace std; bool comp(const pair<int, int> &a, const pair<int, int> &b) { if (a.first == b.first) return a.second < b.second; return a.first < b.first; } bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { if (a.second == b.second) return b.first > a....
#include <bits/stdc++.h> using namespace std; const int MOD = 1073741824; const int N = 100005; const double PI = 4 * atan(1); int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}; int dy[] = {0, 0, 1, -1, 1, 1, -1, -1}; long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } long long lcm(lo...
#include <bits/stdc++.h> using namespace std; int n; int main() { ios_base::sync_with_stdio(false); while (cin >> n) { vector<int> inside(1000006, 0), ans; int stack = 0, length = 0, x, valid = 1, j = 1; unordered_map<int, int> used; for (int i = 0; i < n; ++i) { cin >> x; ...
#include <bits/stdc++.h> using namespace std; int N, H, M; int main() { scanf( %d%d:%d , &N, &H, &M); if (N == 24) { if (H / 10 >= 3) H %= 10; if (H / 10 == 2 && H % 10 >= 4) H %= 10; } else { if (H / 10 >= 2) { if (H % 10 == 0) H = H % 10 + 10; else ...
#include <bits/stdc++.h> using namespace std; uint64_t ans, fact[21]; long long t, n, cont, val; bool us[30]; vector<uint64_t> v; uint64_t calc() { uint64_t tmp = 1; uint64_t freq[30]; uint64_t ind = 0; for (int i = 0; i < 30; i++) freq[i] = 0; for (int i = 0; i < v.size(); i++) { ...
#include <bits/stdc++.h> using namespace std; int m, n, cn, nw, res, ans; int used[533]; int x[1020], y[1020]; int a[1020][1020]; int asjkjas[1020]; bool kuhn(int x) { if (used[x] == nw) return false; used[x] = nw; for (int i = (0); i < (n); ++i) if (a[x][i] && i != cn && (asjkjas[i] == ...
#include <bits/stdc++.h> using namespace std; int n; int odd, even; int miny[400001], maxy[400001], min2y[400001], max2y[400001]; vector<int> p[400001]; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 0; i <= 2e5; i++) { maxy[i] = -1, miny[i] = 2e5 + 1; } for (int ...
#include <bits/stdc++.h> using namespace std; template <class C> void mini(C& a4, C b4) { a4 = min(a4, b4); } template <class C> void maxi(C& a4, C b4) { a4 = max(a4, b4); } template <class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> pair) { return out << ( << pair.first...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; set<int> g[maxn]; set<int> vis; int u[maxn]; void dfs(int x) { u[x] = 1; vis.erase(x); vector<int> ret; for (int p : vis) { if (!g[x].count(p)) { ret.push_back(p); } } for (int t : ret) { ...
#include <bits/stdc++.h> using namespace std; int main() { int a[6]; for (int i = 0; i < 6; i++) cin >> a[i]; a[5]++; int mn = 100000; for (int i = 0; i < 6; i++) { if (i == 4) continue; if (mn > a[i]) mn = a[i]; } cout << (mn > a[4] ? mn - a[4] : 0) << endl; return 0; ...
#include <bits/stdc++.h> using namespace std; int n, s[100005]; char t[100005]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &s[i]); scanf( %s , t); int tot = 0, ans = 0; for (int i = 0; i < n; i++) { if (t[i] == 1 ) ans = max(tot, ans + s[i]); tot += s[...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const int SINF = 0x7fffffff; const long long LINF = 0x3fffffffffffffff; const long long SLINF = 0x7fffffffffffffff; const int MAXN = 2007; int n, m; vector<int> es[MAXN]; bitset<MAXN> bs[MAXN]; bool hv[MAXN]; int dp[MAXN]; ...
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& x) { return os << ( << x.first << , << x.second << ) ; } const int MOD = 998244353; long long modex(long long a, long long p, long long m = MOD) { if (!p) return 1;...
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-10; const long long MOD = 1000000007ll; const long long mod1 = 1000000009ll; const long long mod2 = 1100000009ll; int INF = (int)1e9 + 5; long long INFINF = (long long)1e18; int main() { int n; scanf( %d , &n); int a, b...
#include <bits/stdc++.h> using namespace std; long long t[50] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 10...
#include <bits/stdc++.h> using namespace std; long long modpow(long long a, long long p, long long mod) { long long ret = 1; while (p) { if (p & 1) ret = (ret * a) % mod; a = (a * a) % mod; p /= 2; } return ret; } long long power(long long a, long long p) { long long ret = ...
#include <bits/stdc++.h> using namespace std; bool sortmahstyle(const pair<int, int> &a, const pair<int, int> &b) { if (a.first == b.first && a.second < b.second) return true; return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m, d; cin >> n >>...
#include <bits/stdc++.h> using namespace std; const int MAXN = 10010; vector<pair<short int, short int> > G[MAXN]; vector<short int> cul[MAXN], row[MAXN]; pair<short int, short int> p[MAXN]; void add_edge(int u, int v, int d) { G[u].push_back(make_pair(v, d)); } void init(int n) { for (int i = 1; i <=...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int sum = 0; while (n) { if (n % 8 == 1) { sum++; } n = n / 8; } cout << sum; return 0; }
#include <bits/stdc++.h> #define maxn 10 using namespace std; int n, m; map<vector<int>, int> f, g; int a[maxn], b[maxn], c[maxn][maxn]; int main(){ scanf( %d%d , &n, &m); vector<int> v; for(int i = 1;i <= n;i++) scanf( %d , &a[i]); for(int i = 1;i <= m;i++) scanf( %d , &b[i]); for(i...
#include <bits/stdc++.h> using namespace std; void FAST_IO(string filein = , string fileout = , string fileerr = ) { if (fopen(filein.c_str(), r )) { freopen(filein.c_str(), r , stdin); freopen(fileout.c_str(), w , stdout); } cin.tie(0), cout.tie(0)->sync_with_stdio(0); } void H...
#include <bits/stdc++.h> using namespace std; struct cell { long long root_vertix, com_len; cell() {} cell(long long x, long long y) { root_vertix = x; com_len = y; } bool operator<(const cell &x) const { return com_len < x.com_len; } }; long long root[100002]; long long n, m, ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); cout << (arr[n - 1] - arr[0] + 1) - n << n ; }
#include <bits/stdc++.h> using namespace std; bool tu[305][305]; long long pri[305]; int d[305]; int n, m, t; int bg[1100000]; int top[110000]; int main() { scanf( %d%d%d , &n, &m, &t); for (int i = 1; i <= n; i++) scanf( %I64d , &pri[i]); for (int i = 1; i <= m; i++) { int b, c; ...
#include <bits/stdc++.h> using namespace std; int vis[1005], a[1005], b[25][25]; int main() { ios::sync_with_stdio(false); int p, n, r, cnt, x, i, k = 0, j, flag = 0, s, t; cin >> n; for (i = 0; i < n * n; i++) { cin >> x; if (!vis[x]) { a[k++] = x; } vis[x]++; ...
#include <bits/stdc++.h> using namespace std; int main() { long long tests, a, b, c, i,sum; cin >> tests; while (tests--) { cin >> a >> b >> c; if (c / b + 1 >= a) printf( %lld n ,(a*a-a)/2); else printf( %lld n ,(c/b)*(c/b+1)/2+(a-...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; char s[maxn], t[maxn]; int pr, mod; const int prs[60] = { 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 24...
#include <bits/stdc++.h> using namespace std; const int Maxn = 100020; char s[Maxn]; int a[Maxn]; int k, n; bool check(int m) { for (int i = 1; i <= n; i++) { if (s[i] == 1 ) continue; if (a[i - 1] - a[max(0, i - m - 1)] + a[min(n, i + m)] - a[i] >= k) return 1; } return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { string x, y, z; cin >> x; y += tolower(x[0]); z += toupper(x[0]); for (int i = 1; i < x.size(); i++) { y += toupper(x[i]); z += toupper(x[i]); } if (x == y || x == z || x.size() == 1) { for (int i = 0; i < x.siz...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, x, b, y; cin >> n >> a >> x >> b >> y; int flag = 0; while (flag == 0) { if (a == b) { flag = 1; break; } if (a == x) { break; } if (b == y) { break; } a++; ...
#include <bits/stdc++.h> #pragma GCC optmize(2) using namespace std; inline int read() { int X = 0, w = 0; char ch = 0; while (!isdigit(ch)) w |= ch == - , ch = getchar(); while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); return w ? -X : X; } int f[1000010]; vecto...
#include <bits/stdc++.h> using namespace std; const int m = 10; int a[10], b[10], ap[10], bp[10]; int n; int main() { memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); string s; cin >> s; n = int(s.size()); for (int i = 0; i < n; ++i) { int num = s[i] - 0 ; ++ap[num]; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, x, y; cin >> n >> x >> y; char c; long long s = 0; bool b = 0; for (int i = 0; i < n; i++) { cin >> c; if (b == 1 && c == 1 ) { b = 0; s++; } else if (b == 0 ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; string s; cin >> s; vector<long long int> ind; long long int t = 0; ind.push_back(0); for (long long int i = 1; i < n; i++) { if (s[i] != s[ind[t]]) { t++; ind.push_back(i); ...
#include <bits/stdc++.h> using namespace std; int d[100][110]; int grad[110]; int dp[1 << 16]; int main() { int n, m, a, b, c, sum(0); ios_base ::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i(0); i < n; i++) for (int j(0); j < n; j++) if (i != j) d[i][j] = 1e9; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[10] = {0}; char S[100001]; cin >> S; for (int i = 0; S[i]; i++) { int j = 0; if (S[i] == L ) { while (arr[j] == 1) j++; arr[j] = 1; } j = 10 - 1; if (S[i] == R ...
#include <bits/stdc++.h> using namespace std; string s; int n; long long ans; vector<int> ls, rr; long long cal(int l, int r) { long long val = 0; long long tmp = s[l] - 0 ; for (int i = l + 1; i < r; i += 2) { if (s[i] == * ) tmp *= s[i + 1] - 0 ; else { val += tm...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } return x * f; } ...
#include <bits/stdc++.h> using namespace std; long long a[100005], c[100005]; vector<pair<long long, long long>> p[100005]; long long check(long long x, long long i) { long long v = 0; for (auto j : p[i]) { long long v1 = j.first, v2 = j.second; if (v1 != -1) v += abs(v1 - x); if (v2 !...
#include <bits/stdc++.h> using namespace std; const long long mxn = 1e5 + 7; int main() { long long n, mx = 0, a[mxn]; cin >> n; for (int i = 1; i <= n; i++) { int x; cin >> x; a[x]++; } for (int i = 1; i <= 101; i++) { mx = max(mx, a[i]); } cout << mx; }
#include <bits/stdc++.h> using namespace std; int na, ma, nb, mb; char s[55][55]; char t[55][55]; int main() { while (~scanf( %d%d , &na, &ma)) { for (int i = 0; i < na; i++) scanf( %s , s[i]); scanf( %d%d , &nb, &mb); for (int i = 0; i < nb; i++) scanf( %s , t[i]); int ans = 0, xx...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; ++i) putchar( 1 ); puts( ); for (int i = 1; i < n; ++i) putchar( 8 ); puts( 9 ); return 0; }
#include <bits/stdc++.h> using namespace std; int l[10100]; int r[10100]; int per[100100]; int pr(int x) { if (x == per[x]) return x; return per[x] = pr(per[x]); } int main() { ios::sync_with_stdio(0); int n; cin >> n; int t = 0; for (int i = 1; i <= n; i++) { per[i] = i;...
#include <bits/stdc++.h> const int maxn = 100001; int n, a[maxn]; struct Segment { int val, tag; } seg[maxn << 1 | 1]; inline int seg_idx(int L, int R) { return (L + R) | (L < R); } void seg_down(int rt, int lch, int rch) { if (!seg[rt].tag) return; seg[lch].val += seg[rt].tag; seg[lch].tag ...
#include <bits/stdc++.h> using namespace std; using ll = long long; bool judge(string& s, string& t) { auto f = [](string& x, vector<int>& cnt) { ll res = 0; for (char c : x) { int v = c - a ; for (int i = v + 1; i < 26; i++) res += cnt[i]; cnt[v]++; } return r...
#include <bits/stdc++.h> using namespace std; int i, j, n, m, k; int main() { scanf( %d , &n); if (n <= 2) { printf( %d n , -1); } else { printf( %d n , 35); printf( %d n , 77); for (i = 1; i <= n - 2; i++) printf( %d n , i * 55); } return 0; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; long long read() { long long x = 0; long long f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -f; c = getchar(); } while (c >= 0 && c <= 9 ) { x = x * 10 + c - 0 ; c...
#include <bits/stdc++.h> int S, T, n, m, l, vol[200020]; int dis[400040], pos[400040], q[400040 * 2]; int E, u[200020], v[200020], go[400040], to[400040]; void AE(int s, int t) { to[++E] = t; v[s] = u[s] ? go[v[s]] = E : u[s] = E; } int spfa(int maxq) { register int i, j, k, top, tail; memse...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int counts = 0, counts2 = 0; for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; if (a < 0) counts++; else counts2++; } if (counts <= 1 || counts2 <= 1) cout << Yes ;...
#include <bits/stdc++.h> using namespace std; const int maxn = 205, inf = 1 << 27; int g[maxn][maxn], g1[maxn][maxn]; int qq[maxn], h, t, n, dis[maxn]; char col[maxn]; int aa[maxn], dd[maxn], x[maxn], bb[maxn], l; int find_min() { int i, ind, ind1, ans; ind = 1; for (i = 2; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int MAX_H = 100; const int MAX_W = 100; char s[MAX_W + 4]; int main() { int h, w; scanf( %d%d , &h, &w); for (int y = 0; y < h; y++) scanf( %s , s); int c = 0; for (int i = 0; i < w;) { while (i < w && s[i] == . ) i++; if (i ...
#include <bits/stdc++.h> using namespace std; const int MAX = 10000; int n; set<pair<int, int> > a; set<pair<int, int> >::iterator it; pair<int, int> b[MAX]; void dive(int s, int e) { if (e - s == 1) return; int mid = s + e; mid /= 2; dive(s, mid); dive(mid, e); for (int i = s; i <...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i += 2) { cout << a[n - i + 1] * -1 << ...
#include <bits/stdc++.h> using namespace std; int min(int a, int b) { if (a < b) return a; return b; } double min(double a, double b) { if (a < b) return a; return b; } int max(int a, int b) { if (a > b) return a; return b; } int ABS(int a) { if (a < 0) return -a; return ...
#include <bits/stdc++.h> using namespace std; int main() { long long k, a, b; cin >> k >> a >> b; if (k == 1) { cout << a + b << endl; return 0; } long long ret = (a / k) + (b / k); long long la = a % k, lb = b % k; if ((la / (k - 1) + (la % (k - 1) > 0)) <= b / k && ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; template <typename T> struct modular { constexpr modular() : val(0) {} constexpr modular(const modular<T>& _m) : val(_m.val) {} template <typename U> constexpr modular(const U& _r = U()) { val = -MOD <= _r && _r < MO...
#include <bits/stdc++.h> using namespace std; int N; vector<string> a; vector<int> big; vector<int> mark; string s; string t; int main() { cin >> N; string s1; for (int i = 0; i < N; i++) { cin >> s1; a.push_back(s1); } cin >> s; cin >> t; for (int i = 0; i < s.si...
#include <bits/stdc++.h> using namespace std; struct w { int c, mi; } tr[1010 * 1010 * 8]; struct ww { int h, b, l, r, x, y; } c[1010 * 1010]; int i, j, k, n, m, s, vx, vy, t, ans; int a[1010][1010], b[1010][1010]; double d[1010 * 1010]; long long an; inline bool cc1(const ww &a, const ww &b...
#include <bits/stdc++.h> using namespace std; long long arr[1000007]; long long cs[1000007]; long long ps[1000007]; int main() { int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i]; for (int i = 1; i <= n; i++) { if (i % 2) { ...
#include <bits/stdc++.h> double const PI = 4 * atan(1.0); using namespace std; int main() { long long a, b, x1, y1, x2, y2; scanf( %I64d %I64d %I64d %I64d %I64d %I64d , &a, &b, &x1, &y1, &x2, &y2); a = 2 * a; b = 2 * b; long long t1 = (x1 + y1); long long t2 = (x2 + y2); long long g1 =...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long int n, c; cin >> n >> c; long int ar[n], i, sum = 0; for (i = 0; i < n; ++i) { cin >> ar[i]; if (i != 0) { if ((ar[i] - ar[i - 1]) > c) sum = 0; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5; const long long mol = 1e9 + 7; int fa[maxn + 11], siz[maxn + 11], x[maxn + 11], y[maxn + 11]; bool cir[maxn + 11]; vector<int> row, cul; int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); } void merge(int x, int y) { int f...
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { T r; while (b != 0) { r = a % b; a = b; b = r; } return a; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <class T> int getbit(T s, int i) { return ...
#include <bits/stdc++.h> using namespace std; int a[3005]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } int ans = 0; for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (a[i] < a[j]) { ans++; } ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n, a, b; cin >> n >> a >> b; long long dp[4][n + 1]; string s; cin >> s; vector<long long> ...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int main() { int n; cin >> n; vector<vector<int> > xy(n, vector<int>(2)); for (int i = 0; i < n; i++) { cin >> xy[i][0] >> xy[i][1]; } int k = 0; for (int i = 0; i < n - 2; i++) { if (xy[i][0] == ...
#include <bits/stdc++.h> using namespace std; const int N = int(1e5) + 5; const int INF = int(1e9) + 7; const long long MINF = 1e18; vector<int> g[N]; set<int> x; int a[N]; int b[N]; vector<int> ans; void solve() { int n, m; cin >> n >> m; for (int i = 1; i <= m; i++) { int l, r; ...
#include <bits/stdc++.h> using namespace std; long long n, k; int main() { cin >> n >> k; long long falta = (n % k); long long ans = n + (k - falta); cout << ans << n ; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1 << 24; int n, f[MAXN], Tohka; bool p[MAXN]; int lowbit(int first) { return first & -first; } int main() { cin >> n; char str[4]; for (int i = 1; i <= n; ++i) { scanf( %s , str); int s = 0; for (int j = 0; j < 3; +...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; for (int x = 0; x < T; x++) { vector<long long> arry(7); for (int i = 0; i < 7; i++) cin >> arry[i]; long long least, all_sum; all_sum = arry[6]; least = arry[0]; vector<long long> a(3); ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 15; struct Node { int x0, y0, x1, y1; int num; int nex; int x, y; int tim; Node() { x0 = y0 = x1 = y1 = num = nex = tim = x = y = 0; } Node(int x0, int y0, int x1, int y1, int num) : x0(x0), y0(y0), x1(x1),...
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230; struct debugger { static void call(const char *arg) {} template <typename T, typename... aT> static void call(const char *it, T a, aT... rest) { string b; ...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int x, long long int y) { if (x < y) swap(x, y); if (x % y == 0) return y; return gcd(y, x % y); } long long int pwm(long long int a, long long int n) { long long int ans = 1; while (n > 0) { if (n % 2 == 1) { ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e7 + 9, MAXN = 1e6; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; unsigned long long int k, x; cin >> n; while (n--) { cin >> k >> x; cout << x + 9 * (k - 1) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int tree[1000000 + 5], a[1000000 + 5], data[1000000 + 5], rear, sum; int lowbit(int x) { return (x & -x); } void modify(int x, int value) { for (int i = x; i <= 1000000; i += lowbit(i)) tree[i] += value; return; } int query(int x) { int sum = 0; ...
#include <iostream> #include <bits/stdc++.h> using namespace std; #define int long long void solve(){ // int n; //cin>>n; /*int a[n]; for(int i=0;i<n;i++) cin>>a[i]; */ string s; cin>>s; int n=s.length(); cout << n << endl; } ...
#include <bits/stdc++.h> using namespace std; string st; int main() { cin >> st; char q[11] = { A , I , O , M , H , U , V , W , X , Y , T }; set<char> s(q, q + 11); for (long long i = 0; i < st.size() / 2 + 1; i++) { if (st[i] != st[st.size() - i - 1] || s.count(st[i]) == 0) { ...