func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int N = 3e4; int n, aa[N + 2], fib[N + 2], con[N + 2], m; void compress() { vector<int> v; for (int i = 1; i <= n; i++) v.push_back(aa[i]); sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); map<int, int> mp; for (i...
#include <bits/stdc++.h> #pragma G++ optimize( Ofast,no-stack-protector ) #pragma G++ optimize( -O3,-O2,-O1 ) #pragma G++ target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native ) #pragma G++ optimize( unroll-loops ) using namespace std; long long binpow(long long a, long long n, long l...
#include <bits/stdc++.h> using namespace std; const long long N = 4, M = 1e5 + 10, Mo = 1e9 + 7; long long n, m, nxt[M], p, lena, lenb, lens; string aa, bb, s; struct Matrix { long long n, a[N][N]; Matrix(long long _n = 4) { n = _n, memset(a, 0, sizeof(a)); } void operator~() { for (long lon...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int main() { string s; cin >> s; int cnt0, cnt1, len = s.size(); string t(len, 0 ); cnt0 = cnt1 = 0; for (int i = len - 1; i >= 0; --i) { if (s[i] == 0 ) ++cnt0; else { if (cnt0 != cnt1) ...
#include <bits/stdc++.h> using namespace std; bool is(long long x) { return x != 1; } int main() { int t; cin >> t; while (t--) { long long x, y; cin >> x >> y; long long z = x - y; if (is(z)) cout << YES << endl; else cout << NO << endl; } ret...
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const long long maxn = 110; struct node { int v, cost; } a[1500]; int N, K, dp1[100 * 150], dp2[100 * 150]; int solve() { memset(dp1, -0x3f3f3f3f, sizeof(dp1)); ; memset(dp2, -0x3f3f3f3f, sizeof(dp2)); ; dp1[1] ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; if (a != d) { cout << 0; } else if (c && !a) { cout << 0; } else { cout << 1; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const int N = 1e6 + 5; const int inf = 1 << 30; const long long llf = 9e18; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = re...
#include <bits/stdc++.h> using namespace std; const long long int INF = (long long int)1e9 + 10; const long long int INFLL = (long long int)1e18 + 10; const long double EPS = 1e-8; const long double EPSLD = 1e-18; const long long int MOD = 1e9 + 7; template <class T> T &chmin(T &a, const T &b) { ret...
#include <bits/stdc++.h> using namespace std; using ll = long long; long double r, v; long double eps = 1e-8; const long double mpi = acos(-1.0); inline long double dist(long double theta) { return 2.0L * r * (sin(theta) + theta); } inline double ti(long double theta, long long ni) { return 2.0L...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; template <class T> ostream& operator<<(ostream& os, vector<T> V) { os << [ ; for (auto v : V) os << v << ; return os << ] ; } template <class L, class R> ostream& operator<<(ostream& os, pair<L, R> P) { retur...
#include <bits/stdc++.h> using namespace std; struct less_key { bool operator()(pair<int64_t, int64_t> p1, pair<int64_t, int64_t> p2) { return (p1.first > p2.first) || ((p1.first == p2.first) && (p1.second < p2.second)); } }; struct pair_hash { std::size_t operator()(const pair<in...
#include <bits/stdc++.h> using namespace std; const int N = 10010; char s[N]; char t[N]; int n, m; int main() { scanf( %s , s + 1); n = strlen(s); scanf( %d , &m); while (m--) { int l, r, k; scanf( %d%d%d , &l, &r, &k); k %= (r - l + 1); for (int i = 0; i < k; i++) { ...
#include <bits/stdc++.h> const int N = 200; char a[N][N]; int main() { int n, m, k; std::cin >> n >> m >> k; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { std::cin >> a[i][j]; } } int ret = 0; int replaces = 0; for (int j = 0; j < m; j++) { int p...
#include <bits/stdc++.h> using namespace std; inline int qpow(int b, int e, int m = 998244353) { int a = 1; for (; e; e >>= 1, b = (long long)b * b % m) if (e & 1) a = (long long)a * b % m; return a; } struct node { long long sum; long long pre; long long suf; long long ans; ...
#include <bits/stdc++.h> using namespace std; int a[200002]; pair<int, int> b[200002]; int main() { int n, k, max = 0; for (int i = 0; i < 200001; i++) { a[i] = 2147483647; } scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d %d , &b[i].first, &b[i].second); } sort(...
#include <bits/stdc++.h> using namespace std; int n, k, p[200005]; int vis[200005], cntn; int pre[200005], nxt[200005]; int flag = 0; struct node { int p, s; node(int p = 0, int s = 0) : p(p), s(s) {} bool operator<(const node &b) const { return p < b.p; } }; void del(int x) { nxt[pre[x]...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int n, m, k; int a[11][11]; int f[11][11]; int cnt[21]; long long read() { long long x = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 0) { cout << home << endl; return 0; } else { cout << contest << endl; return 0; } }
#include <bits/stdc++.h> using namespace std; int main() { long long n, s1 = 0, s2 = 0, s = 0; cin >> n; s1 = ((n + 1) * n) / 2, s2 = s1 / 2; vector<long> a; for (long i = n; i > 0 && s2 > 0; --i) if (s2 >= i) if (s2 - i < i && s2 - i != 0) { a.push_back(i), a.push_back(s...
#include <bits/stdc++.h> using namespace std; vector<int> t; int sz = 0; const int INF = 2e9; void build(vector<int> a) { t.assign(2 * sz + 2, INF); for (int i = 0; i < sz; i++) { t[i + sz] = a[i]; } for (int i = sz - 1; i > 0; i--) { t[i] = min(t[2 * i], t[2 * i + 1]); } } ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long infinity = 1000000000000000000; const int inf = 1e9 + 5; bool do_debug = false; template <typename T> ostream& operator<<(ostream& os, vector<T>& v) { for (auto element : v) { os << element << ; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf( %d %d , &n, &k); vector<int> a(n); for (int i = 0; i < n; ++i) scanf( %d , &a[i]); int sum = 0; for (int i = 0; i < n; ++i) sum += a[i]; if (sum % k) { printf( No n ); return 0; } int req = su...
#include <bits/stdc++.h> using namespace std; set<int> S1, S2, S3; map<int, bool> vis; int p[2000001], a[200001], b[2000001]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> p[i]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; for (in...
#include <bits/stdc++.h> using namespace std; char s[5010]; int main() { scanf( %s , s); int n = (int)strlen(s); int res = 0; for (int i = 0; i < n; i++) { int cnt1 = 0, cnt2 = 0; for (int j = i; j < n; j++) { if (s[j] == ( ) cnt1++; if (s[j] == ) ) cnt1--; if...
#include <bits/stdc++.h> using namespace std; const int N = 400000 + 10; const int M = 26; namespace Trie { int trie[N][M], cnt[N], size; void init() { size = 0; memset(trie[0], 0, sizeof(trie[0])); cnt[0] = 0; } void insert(char str[]) { int u = 0, v; for (int i = 0; str[i]; i++) { ...
#include <bits/stdc++.h> using namespace std; int log(int x) { return 32 - __builtin_clz(x) - 1; } int log(long long x) { return 64 - __builtin_clzll(x) - 1; } int n; int main() { cin >> n; if (n % 2 == 0) { cout << NO ; return 0; } cout << YES n ; bool add = false; for (...
#include <bits/stdc++.h> using namespace std; const long long N = 5e5 + 100; const long long maxN = 6e6; const long long oo = 1e18; const long long mod = 998244353; long long n, m; long long a[N], b[N], cost[N], equalpos[N]; long long IT[20 * N], lazy[20 * N]; map<long long, long long> mp; void updm...
#include <bits/stdc++.h> using namespace std; mt19937_64 rnd; const long long maxn = 1e6 + 10; const long long mod = 998244353; const long long base = 500; long long gt[maxn]; long long gtv[maxn]; long long mu(long long a, long long n) { if (n == 0) return 1; if (n == 1) return a; long long ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); string a, b; cin >> a >> b; int one[2]; one[0] = one[1] = 0; for (char ch : a) one[0] += ch == 1 ? 1 : 0; for (char ch : b) one[1] += ch == 1 ? 1 : 0; if (one[0] + (...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int arr[100005]; int pos[100005], pr[100005] = {0}; int i, j, ans = 0; for (i = 0; i < n; i++) { cin >> arr[i]; if (pr[arr[i]] == 0) ans++; pr[arr[i]]++; pos[arr[i]] = i; if (ans...
#include <bits/stdc++.h> using namespace std; long long n, m, T, x, y, x2, y2, a, b, sol = 1; char c; string s; bool t; vector<int> V; vector<int> V2; int p, p2, mn = INT_MAX; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> x; V.push_back(x); } for (int i =...
#include <bits/stdc++.h> using namespace std; int s[400], n, ret = 360; int main() { cin >> n; for (int i = 1; i <= n; i++) { int t; cin >> t; s[i] = s[i - 1] + t; } for (int i = 0; i < n; i++) { for (int j = i + 1; j <= n; j++) { ret = min(ret, abs(360 - 2 * (s[j] ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const int M = 1e4 + 5; const int Max = (1 << 26) + 5; short a[Max]; int n, m, b[M], ans[M]; char str[N], sets[30]; int main() { scanf( %s , str + 1); n = strlen(str + 1); scanf( %d , &m); for (int i = 1; i <= m; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, d, h; cin >> n >> d >> h; if (h * 2 < d) { cout << -1; return 0; } if (d == 1) { if (n >= 3) { cout << -1; return 0; } if (n == 2) { cout << 1 << << 2; return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; vector<int> vec(1, 0); vector<vector<int> > list; int counter = 0, i, j; for (i = 0; i < s.length(); i++) { if (s[i] == 0 ) { if (list.size() > counter) { list[counter].push_back(i); ...
// minako #include <bits/stdc++.h> using namespace std; #define endl n #define f first #define s second #define pb push_back #define pii pair<int,int> #define ll long long #define pll pair <ll,ll> #define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); const ll M = 1e9 + 7; ...
#include <bits/stdc++.h> using namespace std; const long double EPS = 1E-9; const int INF = (int)1E9; const long long INF64 = (long long)1E18; const long double PI = 2 * acos(.0); int main() { string num; cin >> num; int a[11]; fill(a, a + 11, 0); for (int i = 0; i < (int)((num).size());...
#include <bits/stdc++.h> using namespace std; string presidents[41] = { , Washington , Adams , Jefferson , Madison , Monroe , Adams , Jackson , Van Buren , Harrison , Tyler , Polk , Taylor , Fillmore , Pierce , Buchanan , Lincoln , John...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; long long t = 1; if (n < 30) { for (int i = 0; i < n; i++) { t *= 2; } cout << m % t; } else { cout << m; } return 0; }
//Shrey Dubey #include<iostream> #include<string> #include<algorithm> #include<map> #include<unordered_map> #include<vector> #include<set> #include<list> #include<iomanip> #include<queue> #include<stack> #include <math.h> #include<climits> #include<bitset> #include<cstring> #...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 1000000; int n; char s[MAXN + 1]; int pac[MAXN], npac; int ast[MAXN], nast; int prvpac[MAXN], prvast[MAXN]; int mxpos[MAXN]; bool canrgt[MAXN]; int calcmxpo...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const long long llinf = 1ll * inf * inf; const double eps = 1e-12; const int N = 1e5 + 10; int f[N], h[N], g[N]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= int(n); ++i) scanf( %d , &f[i]); map<int, vector...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (scanf( %d , &n) != EOF) { int a[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf( %d , &a[i][j]); } } if (n == 1) { printf( %d n , a[0][0]); brea...
#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; const long long S = (1 << 19); long long x, y, a, q, pref_x[S], pref_y[S], ans[S]; pair<long long, long long> tab[S]; vector<pair<pair<long long, long long>, pair<long long, long long> > > X; int main() { ios_base::sync_with_stdio(0); cout.tie(0); ci...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long b[n], c[n]; for (int i = 0; i < n; i++) cin >> b[i]; for (int i = 0; i < n; i++) cin >> c[i]; long long d[n], a[n], sum = 0; for (int i = 0; i < n; i++) { d[i] = b[i] + c[i]; sum += d[i]; ...
#include <bits/stdc++.h> using namespace std; long long int pwr(long long int base, long long int p, long long int mod) { long long int ans = 1; while (p) { if (p & 1) ans = (ans * base) % mod; base = (base * base) % mod; p /= 2; } return ans; } long long int gcd(long long int ...
#include <bits/stdc++.h> using namespace std; const int max_n = 1e5 + 10; vector<long long> adj[max_n]; long long par[max_n], st[max_n], p[max_n], ft[max_n], doc[max_n], x[max_n], l[max_n], r[max_n], cnt, tmp, k, n, m; bool mark[max_n]; int get_par(int u) { return par[u] == u ? u : par[u] = get_par(pa...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; void solve() { string s1; string s2; cin >> s1 >> s2; string ans = ; for (int i = s2.length() - 1; i >= 0; --i) { ans += s2[i]; } if (s1 == ans) { cout << YES << n ; } else { c...
#include <bits/stdc++.h> using namespace std; int Abs(int x) { if (x < 0) return -x; return x; } int N, M, K; bool no[2001][2001] = {false}, visited[2001] = {false}, rooted[2001] = {false}, notgo[2001]; vector<int> G[2001], g[2001]; int cn = 0; bool run = true; void dfs(int r) { if ...
#include <bits/stdc++.h> using namespace std; template <class T> struct node { T val; T lazy; int l, r; node* left; node* right; node(int l, int r) { this->l = l; this->r = r; this->left = nullptr; this->right = nullptr; } }; template <class T, int SZ> str...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5, mod = 1e9 + 7; int n, m, k; long long fact[maxn], dp[maxn], inv[maxn]; long long qpow(long long n, int p) { long long res = 1; while (p) { if (p & 1) res = res * n % mod; n = n * n % mod; p >>= 1; } retur...
#include <bits/stdc++.h> int Max(int n); int main(void) { long n, i, j; long long m; scanf( %ld , &n); m = Max(n); j = m; for (i = 1; i <= 4; i++) { m = m * j; m %= 100000; } if (m == 0) { printf( 00000 n ); } else if (m < 10) { printf( 0000%lld n , m); ...
#include <bits/stdc++.h> using namespace std; const int M = 1600; int dr[] = {-1, 0, 1, 0}, dc[] = {0, 1, 0, -1}; int n, m, pr[M][M], pc[M][M]; char g[M][M], f[M][M]; bool dfs(int r, int c) { int u = (r % n + n) % n, v = (c % m + m) % m; if ( # == g[u][v]) return 0; if (f[u][v]) return r != pr[...
#include <bits/stdc++.h> using namespace std; bool visited[2010]; vector<int> g[2010]; int dfs(int src) { visited[src] = true; int ans = 0; for (auto x : g[src]) { if (!visited[x]) { ans = max(ans, dfs(x)); } } return ans + 1; } int main() { ios_base::sync_with_st...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const long long mod = 1e9 + 7; int prime[maxn], g[maxn], last[maxn], num[maxn], cnt[maxn]; long long fac[maxn], invf[maxn]; int t[500]; bool vis[maxn]; long long fpow(long long a, long long b, long long p = mod) { long long ans...
#include <bits/stdc++.h> using namespace std; int num[1 << 18]; char str[20]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int x, y; cin >> x >> y; int a, b, c, ans = 0; a = b = c = y; while (a < x) { swap(a, b); swap(b, c); c = a + b...
#include <bits/stdc++.h> using namespace std; int v[100005], b[100005]; int k, n, m, maxim; int main() { cin >> n >> m; for (int i = 1; i <= m; i++) { int nr; cin >> nr; b[nr]++; v[b[nr]]++; if (v[b[nr]] == n) cout << 1; else cout << 0; } }
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> ostream& operator<<(ostream& o, pair<T1, T2> x) { return o << x.first << << x.second; } template <class T1, class T2> istream& operator>>(istream& o, pair<T1, T2>& x) { return o >> x.first >> x.second; } template <cl...
#include <bits/stdc++.h> using namespace std; int search(int a[], int x, int n) { int lo = 0; int hi = n; while (lo <= hi) { int mid = (lo + hi) / 2; if (a[mid] >= x && a[mid - 1] < x) return mid; else if (a[mid] > x) hi = mid - 1; else lo = mid + 1; }...
#include <bits/stdc++.h> using namespace std; int res[50010], cot; int main() { string a, b; int n; cin >> n; cin >> a; cin >> b; int s1, s2, s3; s1 = s2 = s3 = 0; int sa = 0, sb = 0; for (int i = 0; i < n; i++) { if (a[i] == 1 ) sa++; if (b[i] == 1 ) sb++; ...
#include <bits/stdc++.h> using std::max; const int MAXN = 500111; int N; struct Data { int Cnt, Id; long long Val; int next; Data() {} Data(int _c, int _i, long long _v) { Cnt = _c; Id = _i; Val = _v; } } T[MAXN << 2]; int Tcnt; namespace Map { struct Vert { ...
#include <bits/stdc++.h> using namespace std; int read(); int n; char t[102]; int w[102][102], rnk[102][102], pos[102]; vector<int> p[102]; queue<int> q; void init(int t) { for (int i = 1; i <= n; ++i) { p[i].clear(), p[i + n].clear(); for (int j = 1; j <= n; ++j) p[i].push_back(j + n), ...
#include <bits/stdc++.h> using namespace std; long long prime[1000005]; long long fac[1000005]; int mul(int a, int b) { int res = 0; while (b) { if (b & 1) res = (res + a); a = (a + a); b = b / 2; } return res; } int bexp(int a, int b) { int res = 1; while (b) { ...
#include <bits/stdc++.h> using namespace std; int const N = 100; int const M = 900; typedef double (*F)[N]; int a[N]; double _f[N][N], _g[N][N]; F f = _f, g = _g; inline int c2(int n) { return n * (n + 1) >> 1; } int main() { int n, k; scanf( %d%d , &n, &k); for (int i = 0; i < n; ++i) sca...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int N, M, K; long long F[1111][1111], T[1111], G[111111]; map<int, int> P; inline long long Pow(long long A, int B) { long long Ret = 1; for (; B; B >>= 1) { if (B & 1) { Ret = (Ret * A) % MOD; } A = ...
#include <bits/stdc++.h> const int N = 100010; int n; int head[N], to[2 * N], next[2 * N], graphmr; double ans; inline void add(int x, int y) { int p = graphmr++; to[p] = y; next[p] = head[x]; head[x] = p; } inline void dfs(int x, int fa, int dis) { ans += 1.0 / dis; for (int i = h...
#include <bits/stdc++.h> using namespace std; int a[300001]; int f[300001]; vector<int> g[33]; map<vector<int>, int> mp; vector<pair<vector<int>, int> > v; vector<int> cur; int br = 0; int n; void F(int pos, int mask) { if (pos == br) { v.push_back({cur, mask}); return; } F(p...
#include <bits/stdc++.h> using namespace std; int main() { int n, c; cin >> n >> c; int a[n]; int cnt = 0; vector<int> b; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) { if (abs(a[i] - a[i - 1]) <= c) cnt++; else { cnt = 0; } }...
#include <bits/stdc++.h> using namespace std; int main() { string str; int n; cin >> n >> str; int A[n], m = 0; string RE[n]; A[0] = 0; for (int i = 1, t = 0, tmp = [ ; i < n; i++) { if (str[i] == tmp) { if (str[i] == ] ) t--; else t++; }...
#include <bits/stdc++.h> using namespace std; int root, n, m, tot, ans, a[2000010], zy[2000010]; bool b[2000010], v[2000010]; void dfs(int k) { if (b[a[k]]) { b[a[k]] = v[a[k]] = false; dfs(a[k]); v[a[k]] = true; } else { if (!v[a[k]]) { tot++; if (root == 0) { ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const double PI = 3.14159265359; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> facts; for (int i = 1; i * i <= n; i++) { if (!(n % i)) { facts.push_back(i); ...
#include <bits/stdc++.h> using namespace std; int a[100005], n, x, minn = 3; bool m1[100005], m2[100005]; int read() { int w = 0, f = 1; char c = getchar(); while (c > 9 || c < 0 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { w = (w << 3) + (w ...
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; int count = 0; while (str.size() > 1) { string temp; int num = 0; count++; for (int i = 0; i < str.size(); i++) { num += str[i] - 48; } str = ; str = to_string(num);...
#include <bits/stdc++.h> using namespace std; void solve(long long k) { for (long long n = 3; n <= 2000; ++n) { for (long long a = 2; a < n; ++a) { if ((n + k) % a == 0) { long long y = (n + k) / a; if (y <= 1000000 && (n - a) * y >= (a - 1) && n * (y - 1) > (n - ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18, N = 1e6, mod = 1e9 + 7; const long double PI = acos(-1), eps = -1e9; inline void read(long long &a) { char c; bool neg = 0; c = getchar(); a = 0; if (c == - ) { neg = 1; c = getchar(); } while (c >...
#include <bits/stdc++.h> using namespace std; int c, a, i, n; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> a; if (i == 0) c = a; else c = min(c, a); } if (c == 1) cout << -1; else cout << 1; }
#include <bits/stdc++.h> using namespace std; int main() { int num; int a = 0; int b = 0; int n; cin >> n; int sol[n]; for (a = 0; a < n; a++) { cin >> num; sol[num - 1] = (a + 1); } for (b = 0; b < n; b++) { cout << sol[b] << ; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; const int E = 80; vector<long long> pr, f; mt19937_64 gen(time(0)); long long a[maxn]; map<long long, long long> val; int n; long long solve(long long p) { if (val.find(p) != val.end()) return val[p]; long long ret = 0; ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n; scanf( %d , &n); long long int a[n], b[n], p = 0, q = 0; for (int i = 0; i < n; ++i) { scanf( %I64d , &a[i]); p |= a[i]; } for (int i = 0; i < n; ++i) { scanf( %I64d , &b[i]); ...
#include <bits/stdc++.h> using namespace std; const int max_n = 1e5 + 10; const long long inf = 10000000000000000; vector<int> adj[max_n]; vector<long long> cst[max_n]; vector<int> arr[max_n]; vector<long long> closest[max_n]; void cmp_closest(int i) { int s = arr[i].size(); if (s > 0) { c...
#include <bits/stdc++.h> using namespace std; vector<pair<long long, vector<int> > > out; int n, k; int a[64]; bool found(long long x) { for (int i = 0; i < out.size(); i++) if (out[i].first == x) return true; return false; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) ci...
#include <bits/stdc++.h> using namespace std; static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; void solve4() { string s; cin >> s; int c = 0; int n = int((s).size()); for (char ch : s) { c += (ch == a ); } long long ans; cerr << n ...
#include <bits/stdc++.h> using namespace std; int n, m, t; set<pair<int, int> > s; string s1; vector<int> v, v1; int kek[100000]; int main() { cin >> n >> m >> t; for (int i = 1; i <= n; i++) { cin >> s1; int cur = 0; cur += 60 * 60 * 10 * (s1[0] - 0 ); cur += 60 * 60 * (s...
#include <bits/stdc++.h> using namespace std; const int MAXN = 60; long long h, n; int step[MAXN]; inline long long calc(long long high) { return (1ll << (high + 1)) - 1; } void solve() { long long tmp = (1ll << h) - 1 + n; int cnt = 0; while (tmp != 1) { if (tmp % 2 == 1) step[cnt...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int t; t = 1; while (t--) { long long int n, c1 = 0, c2 = 0, x; cin >> n; while (n--) { cin >> x; if (x == 1) c1++; else ...
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1.0); const long long LINF = (long long)1e18 + 5; const int INF = (int)1e9 + 5; template <class T> T sqr(T x) { return x * x; } template <class T> T abs(T x) { return x < 0 ? -x : x; } template <class T> long long...
#include <bits/stdc++.h> using namespace std; int getint() { unsigned int c; int x = 0; while (((c = getchar()) - 0 ) >= 10) { if (c == - ) return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - 0 ); } while (((c = getchar()) - 0 ) < 10); return x...
#include <bits/stdc++.h> using namespace std; long long int v[300001], sol[300001], S; int cnt = 0, marked[300001], dp[300001][2]; vector<int> g[300001]; long long int dfs(int node, int p) { sol[node] = v[node]; long long int res = sol[node]; for (auto it : g[node]) if (it != p) { re...
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) using namespace std; using ll = long long; using vll = int64_t; const int N = 1e6 + 1; vector<int> adj[N]; vector<bool> vis(N, false); vector<short> col(N, -1); inline bool b...
#include <bits/stdc++.h> using namespace std; long long pw(long long a, long long b, long long p) { long long res = 1; a %= p; b %= p - 1; while (b) { if (b & 1) res = (1LL * a * res) % p; a = (1LL * a * a) % p; b >>= 1; } return res; } long long a, b, x, p, ans; vect...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double esp = 1e-8; const int msz = 100000; const int mod = 2015; struct Child { int v, d; long long p; }; Child c[4444]; bool vis[4444]; queue<int> q; int n; void cut(int id) { long long v = c[id].v + 1; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; char s[maxn], t[maxn]; int n, m; vector<int> id; vector<int> ans; int main() { scanf( %d%d , &n, &m); getchar(); gets(s); gets(t); int Ans = 0x3f3f3f3f; for (int i = 0; i < m - n + 1; i++) { id.clear(); ...
#include <bits/stdc++.h> using namespace std; int make(int c) { if (c == 10000000) return 1; return 0; } long long bb[3][300005], cc[3][300005], dd[3][300005], ee[3][300005]; long long int a[3][300005 + 1]; int main() { int n, fl = 0, m, q; cin >> n; int i; for (i = 1; i <= n; i++) {...
#include <bits/stdc++.h> using namespace std; int main() { int d, n, d1 = 1, a; long long cnt = 0; cin >> d >> n; for (int i = 0; i < n; i++) { cin >> a; d1 = a; if (i != n - 1 && d1 != d) { cnt += d - d1; d1 = 1; } else if (d1 == d) { d1 = 1; } ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return !b ? a : gcd(b, a % b); } class fraction { public: int a, b; fraction() { a = 0, b = 1; } fraction(int a, int b) { if (b < 0) { a *= -1; b *= -1; } if (a == 0) b = 1; int g = gcd(abs...
#include <bits/stdc++.h> const int N = 300005; int t[N << 2], tag[N << 2], size[N << 2], st1[N], st2[N], tp1, tp2, n, x, y, a[N]; long long ans; void up(int x) { int t1 = t[x << 1] + tag[x << 1], t2 = t[x << 1 | 1] + tag[x << 1 | 1]; if (t1 == t2) size[x] = size[x << 1] + size[x << 1 | 1]; if ...
#include <bits/stdc++.h> using namespace std; const int OO = 0x3f3f3f3f, N = 1e3 + 5, mod = 1e9 + 7; string str; vector<int> p, v; vector<pair<int, vector<int>>> pos; pair<int, char> occ[26]; int c[N], x = 1, n; char ans[N]; int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } int LCM(int a, int ...
#include <bits/stdc++.h> using namespace std; void solve(long long case_no) { long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; ++i) cin >> a[i]; map<long long, long long> mp; long long mx = LONG_LONG_MIN; for (long long i = 0; i < n; ++i) { long long x = ...