func_code_string
stringlengths
59
71.4k
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <queue> #include <map> #include <set> #include <vector> #include <string> #include <stack> #include <numeric> #include <cassert> #define endl n ...
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 10; int rd() { int x = 0, w = 1; char ch = 0; while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + (ch ^ 48); ch = getchar(); } ret...
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; int main() { ios::sync_with_stdio(0); int n; cin >> n; int a[n]; for (int i = 0; i < (n); i++) cin >> a[i]; int b[n]; for (int i = 0; i < (n); i++) cin >> b[i]; set<int> rem; int top = 0; for (int i = 0;...
#include <bits/stdc++.h> int main() { int a[5], maxx = -1, k; for (int i = 0; i < 4; i++) { scanf( %d , &a[i]); if (maxx < a[i]) { maxx = a[i]; k = i; } } for (int i = 0; i < 4; i++) { if (k == i) continue; printf( %d , maxx - a[i]); } printf( n ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int x,y; cin>>x>>y; int count =0; while(x>0&&y>0) { x--; y--; count+=2; } if(x!=...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, mod = 1000000007, a[26], f[1000] = {}, l[1000] = {}, g[1000]; string s; cin >> n >> s; for (int i = 0; i < 26; i++) cin >> a[i]; f[0] = l[0] = g[0] = 1; for (int i = 1; i...
#include <bits/stdc++.h> using namespace std; int main() { long long n; while (scanf( %lld , &n) != EOF) { long long tpn = n; long long ninenum = 0; long long tezheng; while (tpn) { tpn /= 10; ninenum++; } ninenum--; long long sum = 1; while (n...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e18; const long long MAX = 100100; void pre() {} void solve() { long long n; cin >> n; vector<long long> p(n), c(n); for (long long i = 0; i < n; ++i) cin >> p[i] >> c[i]; for (long long i...
#include <bits/stdc++.h> #pragma GCC optimize( O2 ) #pragma GCC optimize( unroll-loops ) using namespace std; long long power(long long a, long long b, long long md) { return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md))...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0LL) return a; return gcd(b, a % b); } long long bigmod(long long a, long long b, long long mod) { if (b == 0LL) return 1LL; long long sq = bigmod(a, b / 2LL, mod); sq = (sq * sq) % mod; if (...
#include <bits/stdc++.h> using namespace std; const int N = 100 * 1000; int n; long long dp[2][N]; int c[N], a[N]; bool read() { if (!(cin >> n)) return false; for (int i = 0; i < int(n); ++i) { cin >> a[i]; c[i] = a[i]; } return true; } void upd(long long &a, long long b) { ...
#include <bits/stdc++.h> using namespace std; long long dp[55][2]; int main() { long long X, Y; scanf( %lld %lld , &Y, &X); dp[51][0] = 1; for (int i = 50; i >= 0; i--) { for (int flag = 0; flag <= 1; flag++) { bool x = (X >> i) & 1, y = (Y >> i) & 1; if (x) dp[i][f...
#include <bits/stdc++.h> using namespace std; int a[120][120] = {0}, n; int main() { int i, j, k; scanf( %d , &n); if (n == 1) { puts( 0 ); return 0; } if (n == 2) { puts( 1 n1 2 ); return 0; } if (n == 3) { puts( 2 n1 2 n2 3 ); return 0; } i...
#include <bits/stdc++.h> using namespace std; template <class T> constexpr T inf = numeric_limits<T>::max() / 2; long long calc(long long border, const vector<int> &h, const vector<long long> &acc, const vector<long long> &acc_rev, int a, int r, int m) { int n = h.size(); ...
#include <bits/stdc++.h> int main() { int n, flag = 0; while (scanf( %d , &n) != EOF) { int a[n]; for (int i = 0; i < n; i++) { scanf( %d , &a[i]); if (a[i] == 1) { flag = 1; } } if (flag == 1) printf( -1 n ); else printf( 1 n ); ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long w, m; cin >> w >> m; vector<int> f; while (m) { f.push_back(m % w); m /= w; } f.push_back(0); f.push_back(0); reverse(f.begin(), f.end()); for (int i...
#include <bits/stdc++.h> using namespace std; int n, a[211111]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } long long l = 0; long long r = 0; long long suml = 0; long long sumr = 0; for (int i = 0; i < n; i++) { if (a[i] == 1) { r++; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000; int from[MAXN + 5]; void Gauss(int n, int d, double a[][MAXN + 5], double *Ans) { for (int i = 1; i <= n; i++) from[i] = i; for (int i = 1; i <= n; i++) { if (!a[i][i]) for (int j = i + 1; j <= min(n, i + d); j++) ...
#include <bits/stdc++.h> using namespace std; const int N = 6e3; const int M = 2 * 5e3 + 2; int n, m; int G[N], H[N]; int q[N], qf, qb; int dG[N][N], bG[N][3], szG[N]; int dH[N][N], bH[N][3], szH[N]; int ansv[4], aux[6], as; int to[M], nx[M], es; void calculate(int* ad, int d[][N], int b[][3], int...
#include <bits/stdc++.h> using namespace std; long long n; pair<long long, long long> loc[2001]; long long cp[2001]; long long cw[2001]; pair<long long, pair<long long, long long> > road[4000001]; long long ct = 0; long long val[2001]; long long ans = 0; long long ansleft; long long ansr = 0; bo...
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( Ofast ) constexpr long long INF = 200000000000000001LL; constexpr int INF32 = 2100000001; size_t seed42 = std::chrono::system_clock::now().time_since_epoch().count(); std::mt19937 rng(seed42); ...
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int dp[1005][1005]; bool vis[1005][1005]; int sx, sy, x, y; vector<string> v; bool valid(int xx, int yy) { if (xx >= 0 && yy >= 0 && xx < x && yy < y && v[xx][yy] != * ) return 1; return 0; } i...
#include <bits/stdc++.h> using namespace std; const int N = 100001; int h, t; set<int> G[N]; vector<int> g[N]; bool check(int gr, int ji) { int sw = 0; int com = 0; if (((int)g[gr].size()) > ((int)g[ji].size())) swap(gr, ji), sw = 1; for (int i = 0; i < ((int)g[gr].size()); i++) com += G[ji]...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> v) { os << ( << v.first << , << v.second ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:66777216 ) using namespace std; const int N = 1e6 + 7; int d[1024], k, ver[1024], ans[1024], num[1024]; map<pair<string, int>, int> M; map<string, bool> was; vector<vector<int> > v(1024); string name[1024]; bool comp(int a, int b) { if (name...
#include <bits/stdc++.h> using namespace std; char s[2002000], t[2002000]; int n; int a = 0, b = 0, c = 0, d = 0; int main() { cin >> n >> s >> t; for (int i = 0; i < 2 * n; i++) { if (s[i] == 1 && t[i] == 1 ) a++; else if (s[i] == 1 ) b++; else if (t[i] == 1 ) ...
#include <bits/stdc++.h> using namespace std; bool visited[300000]; long long int parent[300000]; void initialise() { for (long long int i = 0; i < 300000; i++) { visited[i] = false; parent[i] = i; } } pair<long long int, long long int> dfs( vector<pair<long long int, long long int...
#include <bits/stdc++.h> using namespace std; int q; int k; int main() { cin >> q; for (int i = 0; i < q; ++i) { cin >> k; if (k % 4 == 0) cout << (k / 4 <= 0 ? -1 : k / 4); if (k % 4 == 1) cout << (k / 4 - 1 <= 0 ? -1 : k / 4 - 1); if (k % 4 == 2) cout << (k / 4 <= 0 ? -1 : k / ...
#include <bits/stdc++.h> using namespace std; const int N = 2010; struct P { long long x, y; int id; bool operator<(P B) const { if (y != B.y) return y < B.y; return x < B.x; } } p[N], op; long long cross(P A, P B, P C) { return (A.x - B.x) * (C.y - B.y) - (C.x - B.x) * (A.y - ...
#include <bits/stdc++.h> using namespace std; template <class T> void printVector(std::vector<std::vector<T>> const &matrix) { for (std::vector<T> row : matrix) { for (T val : row) { std::cout << val; } std::cout << n ; } } static void solve() { int n; cin >> n; ...
#include <bits/stdc++.h> using namespace std; int main() { printf( YES n ); int n, a, b, c, d; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d%d%d%d , &a, &b, &c, &d); if (!(a % 2) && !(b % 2)) printf( 3 n ); else if (!(a % 2) && (b % 2)) printf( 4 n ); ...
#include <bits/stdc++.h> int power(int x, int y) { int res = 1; x = x % 1000000007; while (y > 0) { if (y & 1) res = (res * x) % 1000000007; y = y >> 1; x = (x * x) % 1000000007; } return res; } int ncr(int n, int r) { int res = 1; if (r > n - r) r = n - r; for (i...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; long long sum[200005]; long long sum2[200005]; long long a[200005]; int n; int sgn(double x) { if (fabs(x) < eps) return 0; return x > 0 ? 1 : -1; } struct point { long long x, y; point(){}; point(long long x, l...
#include <bits/stdc++.h> using namespace std; int main() { string a; int b; cin >> b >> a; for (int i = 2; i <= b; i++) { if (b % i == 0) { reverse(a.begin(), a.begin() + i); } } cout << a; }
#include <bits/stdc++.h> using namespace std; const int N = 300100; int arr[N]; #pragma warning(disable : 6031) #pragma warning(disable : 4996) int t, n; bool c1[N], c2[N]; int main() { scanf( %d , &t); while (t--) { scanf( %d , &n); bool f1 = 1, f2 = 1; bool f3 = 1; for ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T> using vec = vector<T>; template <typename T> using Prior = priority_queue<T>; template <typename T> using prior = priority_queue<T...
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long INFL = LLONG_MAX; const long double pi = acos(-1); const int MOD = 1e9 + 7; int ans; int N; inline long long mod(long long a) { a %= MOD; a += MOD; a %= MOD; return a; } inline int add(int a, int b...
#include <bits/stdc++.h> using namespace std; const int N = (int)3e3; int p[N], n, m, deg[N], d[N]; char a[N][N]; vector<int> adj[N]; queue<int> q; bool visited[N]; int findSet(int u) { return p[u] == u ? p[u] : p[u] = findSet(p[u]); } void unionSet(int u, int v) { int x = findSet(u), y = findSet(...
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e6; const long long Inf = 0x3f3f3f3f3f3f3f3f; const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; const double eps = 1e-7; template <class T> inline void read(T &res) { char c; T flag = 1; while ((c = getchar()) < 0 || ...
#include <bits/stdc++.h> using namespace std; int howfar(const std::string& s) { const int N = s.length(); int r(0); int d(1); for (int i = 0; i != N; ++i) { switch (s[i]) { case F : r += d; break; case T : d = -d; break; defaul...
#include <bits/stdc++.h> using namespace std; int n, m, q; long long dp[15][(1 << 13) + 10][15]; struct E { int a, b; } e[20]; struct Lca { int a, b, c; } lca[100 + 10]; int num[(1 << 13) + 10]; bool il(int u, int state, int last) { for (int i = 1; i <= q; i++) { int xx = ((state >> ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1e3 + 7; int n, m, tot, root[N]; long long p, ans; struct node { int ls, rs; long long sum; } t[N * 30]; void insert(int x, int &y, int l, int r, int v) { y = ++tot; t[y] = t[x]; t[y].sum++; if (l == r) return; i...
#include <bits/stdc++.h> using namespace std; char _buf[100000], *_op(_buf), *_ed(_buf); inline int getint() { int _s = 0, _f = 1; char _ch = (_op == _ed && (_ed = (_op = _buf) + fread(_buf, 1, 100000, stdin), _op == _ed) ? EOF : *_op+...
#include <bits/stdc++.h> using namespace std; int n, m, K; char maze[2010][2010]; int up[2010][2010], down[2010][2010]; struct Segtree { int key[2010 * 4], ans[2010 * 4]; void add(deque<pair<int, int> > &que, int pos, int val) { while (!que.empty() && val < que.back().second) que.pop_back(); ...
#include <bits/stdc++.h> using namespace std; int n, m; vector<pair<int, int> > v[1000007]; vector<int> rv[1000007]; int comp[1000007]; vector<pair<int, int> > g[1000007]; long long sm[1000007]; int used[1000007]; int stver; stack<int> s; vector<int> srt; bool val[100000002]; long long hval[10...
#include <bits/stdc++.h> using namespace std; const long long int INF = 2e18; bool isPrime(long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long int i = 5; i * i <= n; i = i + 6) { if (n % i == 0 || n % (i + 2) == 0) ...
#include <bits/stdc++.h> using namespace std; int n, m, a[105], rev[105], b[105]; long double ans = 0, cnt = 0, f[2][35][35], g[31][31]; void dfs(int u) { if (!u) { for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) if (a[i] > a[j]) ans++; cnt++; return; } ...
#include <bits/stdc++.h> using namespace std; long long int inv[32][2]; void rec(vector<int>& a, int b) { if (b < 0 || a.size() == 0) return; int c[2] = {0}; vector<int> v[2]; for (int x : a) { int val; if ((x & (1 << b)) > 0) val = 1; else val = 0; if (val ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; vector<int> g[N]; void dfs(int u, vector<int>& dep, int par = -1, int h = 0) { dep[u] = h; for (int v : g[u]) { if (v == par) continue; dfs(v, dep, u, h + 1); } } int main() { ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long inf = 1e18; const int maxn = 1e5 + 10; const double eps = 1e-7; const double pi = 3.14159265359; int n, m, t[maxn]; int par[maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; int b[10] = {0, 2, 3, 1}, a[maxn]; int main() { int t; scanf( %d , &t); while (t--) { long long n, ans = 1; cin >> n; int m = n % 3; n = (n + 2) / 3; while (n > ans) { n -= ans; an...
#include <bits/stdc++.h> using namespace std; long long int q; void solve(long long int x) { for (long long int i = 2; i * i <= x; i++) { if (x % i == 0) { long long int temp = x / i; for (long long int j = 2; j * j <= temp; j++) { if (temp % j == 0) { cout << 1 << ...
#include <bits/stdc++.h> int n; int x[200050]; int f[200050]; int ans = 0; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &x[i]); for (int i = 0; i < n; i++) scanf( %d , &f[i]); int k = 0, l = 0; while (l < n) { if (x[k] == f[l]) k++, l++; else ...
#include <bits/stdc++.h> using namespace std; int n, m; struct point { double x, y, z; } P[5200]; inline double sqr(double x) { return x * x; } inline double dist(point a, point b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y) + sqr(a.z - b.z)); } inline double len(point a, point b, point c) { ...
#include <bits/stdc++.h> int main() { int m, n, i, j, p, q; scanf( %d %d , &m, &n); scanf( %d %d , &p, &q); int ar[m], br[n]; for (i = 0; i < m; i++) { scanf( %d , &ar[i]); } for (i = 0; i < n; i++) { scanf( %d , &br[i]); } if (ar[p - 1] < br[n - q]) printf( YES n...
#include <bits/stdc++.h> using namespace std; int A[100005]; int F[100005]; int main() { int n, x; cin >> n >> x; for (int i = 1; i <= n; i++) { scanf( %d , &A[i]); F[A[i]]++; } int idx = (n + 1) / 2; bool wasPresent = true; if (!F[x]) { wasPresent = false; A[...
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000000000000; map<pair<long long, int>, long long> memo; long long solve(long long n, int x) { pair<long long, int> p = make_pair(n, x); if (memo.find(p) != memo.end()) return memo[p]; if (n == 0) return memo[p] = 0; if (...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); int a = 0, b = 0, c = 0, d = 0; for (int i = 0; i < n; i++) { if (s[i] >= A && s[i] <= Z ) a = 1; else if (s[i] >= a && s[i] <= z ) b = 1; else if (s[i] >= 0 ...
#include <bits/stdc++.h> using namespace std; long long a[200010]; int main() { int n; while (~scanf( %lld , &n)) { long long ans = 0; for (int i = 0; i < n; ++i) scanf( %lld , &a[i]); for (int i = 0; i < n;) { ans++; long long j = i; while (j < n && a[j] == -1) j...
#include <bits/stdc++.h> #pragma GCC optimize( -O2 ) using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << endl; err(++it, args...); } const int LIM = 1e5 + 5, MO...
#include <bits/stdc++.h> int main() { int n, m; char ch[51]; scanf( %s , &ch); n = strlen(ch); if (n == 1) printf( %c , ch[0]); else { if (n % 2 == 0) m = (n / 2) - 1; else m = (n / 2); printf( %c , ch[m]); int j = 1; for (int i = 1; i <= n /...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, m, n, a = 0, b = 0; cin >> n >> m; k = n; k = k / 9; n = n % 9; if (n != 0) k++; for (i = 0; i < k; i++) cout << 54; cout << endl; for (i = 0; i < k - 1; i++) cout << 45; cout << 46; cout << endl; ...
#include <bits/stdc++.h> using namespace std; int n, k; int query(int l, int r) { if (l < 1 || r > n) return false; string re; cout << 1 << << l << << r << endl; cin >> re; return re == TAK ; } int get(int l, int r) { if (l > r) return false; while (l < r) { int mid ...
#include <bits/stdc++.h> using namespace std; long long m, tot, cnt; long long geta(long long limit) { long long res = 1; while (res * res * res <= limit) res++; return res - 1; } void dfs(long long limit, long long num, long long vol) { if (limit == 0) { if (cnt < num) { cnt = n...
#include <bits/stdc++.h> using namespace std; template <typename T, typename C> class mcmf { public: static constexpr T eps = (T)1e-9; struct edge { int from; int to; T c; T f; C cost; }; vector<vector<int> > g; vector<edge> edges; vector<C> d; vector<i...
#include <bits/stdc++.h> #pragma GCC optimize( O2,unroll-loops ) using namespace std; const int inf = 1000000010; const long long INF = 10000000000000010LL; const int mod = 1000000007; const int MAXN = 300010, LOG = 20; int n, m, k, u, v, x, y, t, a, b, ans; int par[MAXN], h[MAXN], leaf[MAXN]; vector<...
#include <bits/stdc++.h> using namespace std; const int oo = 1 << 30; int ds[500500], par[500500], parEdge[500500], depth[500500], anc[500500], ans[500500]; vector<pair<int, int>> a[500500]; int get(int ds[], int x) { return x == ds[x] ? x : ds[x] = get(ds, ds[x]); } void dfs(int x) { for (auto [y...
#include <bits/stdc++.h> using namespace std; const int N = 112345; vector<int> v[N]; int read() { int x; scanf( %d , &x); return x; } int cnt[N]; bool used[N]; bool t[N]; bool never[N]; int main() { int n, m, i, j, x, y; n = read(); for (i = 2; i <= n; i++) { x = read(...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) a.push_back(a[i]); int Max = 0, cur = 0; for (int i = 0; i < 2 * n; ++i) { if (a[i] == 1) cur++; else { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, co; int a[100019]; cin >> n >> co; int count = 0; for (int i = 0; i < n; i++) { cin >> a[i]; count += a[i] / 10; a[i] %= 10; } sort(a, a + n); reverse(a, a + n); for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const double pi = acos(-1); void print() { cout << n ; } template <typename T, typename... Params> void print(const T& var1, const Params&... var2) { cout << var1 << ; print(var2...); } template <typename T> ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n; double a, d; double p[maxn], t[maxn], v[maxn], s[maxn]; int main() { scanf( %d %lf %lf , &n, &a, &d); for (int i = 0; i < n; i++) scanf( %lf%lf , &t[i], &v[i]), p[i] = t[i] + v[i] / a; s[0] = t[0] + v[0] / a + (...
#include <bits/stdc++.h> using namespace std; int main() { char a[5], b[5], aa[5][5]; for (int i = 1; i <= 3; i++) { scanf( %s , aa[i]); a[i] = aa[i][0]; b[i] = aa[i][1]; } if ((a[1] == a[2]) && (a[2] == a[3]) && (b[1] == b[2]) && (b[2] == b[3])) { printf( 0 n ); return...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const long long inf = 9e18; struct NODE { long long v, id; bool operator<(const NODE& other) const { return v > other.v || (v == other.v && id > other.id); } } node[N]; long long a[N], b[N]; long long n; long long f(...
#include <bits/stdc++.h> using namespace std; const int MAXN = 10 + 1e5; const int MOD = 1e9 + 7; int n, m; int a[MAXN], c[MAXN]; void Inout() { freopen( ABC .inp , r , stdin); freopen( ABC .out , w , stdout); } int main() { ios_base::s...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long long mod = 1e9 + 7; const long long N = 2e5 + 10; inline long long add(long long x, long long y) { x += y; if (x >= mod) x -= mod; return x; } inline long long mul(long long x, long long y) { x = (1LL * x ...
#include <bits/stdc++.h> using namespace std; int A[1000000]; map<char, int> M; int main() { for (int i = 0; i <= 63; i++) for (int j = 0; j <= 63; j++) A[i & j]++; for (int i = 0; i <= 9; i++) M[i + 0 ] = i; for (int i = 0; i < 26; i++) M[i + A ] = i + 10; for (int i = 0; i < 26; i++) M...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 1000 + 10; int n, maxLevel; vector<int> edge[maxn]; vector<int> gu; int dis[maxn]; vector<int> level[maxn]; int fa[maxn]; bool used[maxn]; void print(int a[], int n, int st = 0) { for (int i = 0; i < n; ...
#include <bits/stdc++.h> using namespace std; int main() { int i, ans, n, a[3001]; while (cin >> n) { for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); if (a[0] > 1) ans = 1; else { for (i = 1; i < n; i++) { if (a[i] - a[i - 1] > 1) { ...
#include <bits/stdc++.h> using namespace std; struct event { long long x, type; event() {} event(long long _x, long long _type) { x = _x; type = _type; } }; string a, b; long long n; long double ans = 0; vector<long long> v[500]; vector<event> d[500]; bool operator<(const e...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:300000000 ) const long double eps = 1e-20; const long double pi = acos(-1.0); const long long inf = 1000 * 1000 * 1000 * 1000 * 1000 * 1000; const long long base = 1000 * 1000 * 1000 + 7; using namespace std; int n, m, z, a[111111], x, y; bool fl;...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { vector<long long> nums(n); for (int i = 0; i < n; i++) { cin >> nums[i]; } bool hasAns = false; for (int i = 31; i >= 0; i--) { long long num = 1; num = num << i; ...
#include <bits/stdc++.h> using namespace std; const int add = 1e9; const int INF = 2e9; const long long mod = 1e9 + 7; const long long mod1 = 3e9 + 19; const long long mod2 = 3e9 - 71; const long long longINF = 3e18; const long long ph = 31; const long double pi = acos(-1); const long double eps = 1...
#include <bits/stdc++.h> using namespace std; int main() { int tu[200], a[200]; int f[200]; int n, m, k; int min; int i, j; scanf( %d %d %d , &n, &m, &k); for (i = 0; i < m; i++) { scanf( %d , &f[i]); a[i] = 0; } for (i = 0; i < k; i++) scanf( %d , &tu[i]); for (i...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { string s; cin >> s; string word = ; for (auto x : s) { if (x == _ ) { word = ; } else { word = word + x; } } if (word.s...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; t = 1; while (t--) { long long int n; cin >> n; long long int x, y, i; long long int suma = 0, sumb = 0; bool found = false; ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int MOD = 1e9 + 7; const int MAXN = 1e6 + 3; long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } long long power(long long x, long long y) { long long res = 1; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 20; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const long long LLINF = 0x3f3f3f3f3f3f3f3f; const double PI = acos(-1.0); const double RATE = 0.995; const double eps = 1e-4; int arr[MAXN]; signed main() { int n; lo...
#include <bits/stdc++.h> using namespace std; const int mxN = (int)1e5 + 5; int n, ar[mxN]; void solve() { ar[0] = 0; cin >> n; for (int i = 1; i <= n; i++) cin >> ar[i]; int mx = 0; for (int i = 1; i <= n; i++) { mx = max(mx, ar[i]); } cout << mx; } int main() { ios::s...
#include <bits/stdc++.h> using namespace std; int n, m, k, h[300005], tot; map<pair<int, int>, int> c; struct edge { int to, nxt, val; } e[300005 << 1]; void add(int x, int y, int z) { e[++tot].nxt = h[x]; h[x] = tot; e[tot].to = y; e[tot].val = z; } priority_queue<pair<long long, in...
#include <bits/stdc++.h> using namespace std; int main() { int count = 0; int n, d; cin >> n >> d; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; if (abs(arr[i] - arr[j]) <= d) cou...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long x = 0; bool vis[100010] = {false}; vector<int> adj[100010]; long long pow(long long a, long long b, long long m) { stack<int> k; int j = 128; int l = 1; int an = 1; while (b) { if (b >= j) { ...
#include <bits/stdc++.h> using namespace std; using Int = long long; constexpr static int mod = 1e9 + 7; constexpr static int inf = (1 << 30) - 1; constexpr static Int infll = (1LL << 61) - 1; int Competitive_Programming = (ios_base::sync_with_stdio(false), cin.tie(nullptr), cout << fixed << se...
#include <bits/stdc++.h> using namespace std; long long MOD; inline void modulas(long long a) { MOD = a; } inline void normal(long long &a) { a %= MOD; (a < 0) && (a += MOD); } inline long long modMul(long long a, long long b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a * b) % ...
#include <bits/stdc++.h> using namespace std; bool solve() { int n; bool ret = false; int m = 0; scanf( %d , &n); int a; scanf( %d , &a); while ((a & 1) == 0) a >>= 1; while (a % 3 == 0) a /= 3; m = a; for (int i = 1; i < n; i++) { int a; scanf( %d , &a); wh...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b) { long long r; while (b) { ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int n, x; cin >> n; int i = 0; while (n--) { cin >> x; if (x > b && x < c) i++; } cout << i; }
#include <bits/stdc++.h> using namespace std; int main() { int A[3][3], B[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cin >> A[i][j]; B[i][j] = 1; } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (A[i][j] % 2 != 0) { ...
#include <bits/stdc++.h> using namespace std; template <class T> T By(T x, T y, T P) { T F1 = 0; while (y) { if (y & 1) { F1 += x; if (F1 < 0 || F1 >= P) F1 -= P; } x <<= 1; if (x < 0 || x >= P) x -= P; y >>= 1; } return F1; } template <class T> ...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18, minf = 1e18 * (-1); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int k, b; cin >> k >> b; int xyr[k][2], xyb[b][2]; for (long long i = 0; i < k; i++) cin >> xyr[i][0] >> xyr[i][1]; for (...