func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> int main() { char ch[116]; int i, j = 1, k, m, n, c, s, e; scanf( %d %d , &n, &m); while (j <= n) { scanf( %s , ch); for (i = 0; ch[i] != 0 ; i++) { if (ch[i] == B ) { s = i; while (ch[++i] == B ) ; e = i - 1; ...
#include <bits/stdc++.h> using namespace std; vector<pair<pair<int, int>, int> > v, ans; vector<pair<int, int> > an; int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int val, state; cin >> val >> state; v.push_back(make_pair(make_pair(val, !state), i)); } ...
#include <bits/stdc++.h> int modul(long long x, long long y) { if (x < y) return y - x; else return x - y; } long long rez, n, i, ant, x; int main() { scanf( %I64d , &n); ant = 0; for (i = 1; i <= n; i++) { scanf( %I64d , &x); rez += modul(x, ant); ant = x; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cin.ignore(); vector<vector<string> > templa(n); for (int c = 0; c < n; c++) { string s; getline(cin, s); for (int c2 = 0; c2 < s.size(); c2++) if ((s[c2] >= a && s[c2] <= z ) || (s[c2] >= A...
#include <bits/stdc++.h> using namespace std; const int s = (int)1e5 + 10; int a[s], p[s]; int main() { int x, y; int s = 0; int i = 0, j = 0; cin >> x >> y; while (i != x || j != y) { if (i == 0 && j == 0) { i = 1; j = 0; continue; } if (i >= 0 && j...
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); if (n % 2 == 0) cout << a[n / 2 - 1]; else cout << a[(n + 1) / 2 - 1]; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize( Ofast ) #pragma GCC optimize( inline ) using std::pair; using std::set; using std::vector; template <class T> inline void read(T &x) { T f = 1; x = 0; char s = getchar(); while (s < 0 || s ...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, p, x; cin >> t; for (int u = 0; u < t; u++) { cin >> n >> p; x = 2 * n + p; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { cout << i + 1 << << j + 1 << n ; x--; ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, c = getchar(), f = 0; for (; c > 9 || c < 0 ; f = c == - , c = getchar()) ; for (; c >= 0 && c <= 9 ; c = getchar()) x = (x << 1) + (x << 3) + c - 0 ; return f ? -x : x; } const int maxn = 2e5 + 10; cons...
#include <bits/stdc++.h> #pragma comment(linker, /stack:256000000 ) using namespace std; const int INF = 1000000000; const long long LINF = 4000000000000000000LL; const double eps = 1e-9; void prepare() {} struct Chat { string name, text; unsigned int hname; set<unsigned int> words; vecto...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 7; const int mod = 998244353; int ans[1007][1007]; int num[1007]; int n, k; void print(int l, int r) { cout << ? << r - l + 1 << ; for (int i = l; i <= r; i++) cout << i << ; cout << endl; fflush(stdout); } int ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3; const int maxx = 1e6; const int inf = 0x3f3f3f3f; int n, m, tot, c[maxx + 10], ans = inf; pair<int, int> a[maxn + 10], b[maxn + 10]; set<pair<int, int> > s; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; ++i) scanf(...
#include <bits/stdc++.h> using namespace std; const long long modn = 1000000007; inline long long mod(long long x) { return x % modn; } template <class num> inline void rd(num &x) { char c; while (isspace(c = getchar())) ; bool neg = false; if (!isdigit(c)) neg = (c == - ), x = 0;...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> a(n, 0); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); int s = 0, cnt = 0; for (int i = 0; i < n; i++) { if (m == 0) break; if (a[i] < 0) { s += abs(a[...
#include <bits/stdc++.h> using namespace std; int cups[1001]; int main() { int size; cin >> size; int sum = 0; int avg; for (int i = 1; i <= size; ++i) { cin >> cups[i]; sum += cups[i]; } avg = sum / size; if (size * avg != sum) { cout << Unrecoverable configurat...
#include <bits/stdc++.h> using namespace std; int n, m; int a[50][50], neigh[5][2] = {{0, 0}, {1, 0}, {0, 1}, {-1, 0}, {0, -1}}; int best; void dfs(int x) { vector<pair<int, int> > tmp; int i, j, xx = 0, yy = 0, b1 = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0; for (i = 0; i < m; i++) { for (j = 0; j ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k, i, j; cin >> n >> k; int a[n - k + 1]; string s; for (i = 0; i < n - k + 1; i++) { cin >> s; if (s[0] == Y ) a[i] = 0; else a...
#include <bits/stdc++.h> using namespace std; map<long long int, long long int> mp, mk; set<long long int> s1, s2; vector<long long int> v, w; string s = , p = , q = ; char ch; long long int m, n, c, i, j, k, l, r, x, t, y, u, e, f, g, h, mn, mx, d, z; int main() { cin >> n >> t; if (t == ...
#include <bits/stdc++.h> using namespace std; int N; int P[101010]; int V[101010]; vector<int> E[101010]; double T[101010]; void dfs(int cur, double tim) { tim += 1; T[cur] = tim; for (auto& r : E[cur]) { double el = (V[cur] - 1 - V[r]) * 0.5; dfs(r, tim + el); } } void sol...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n, m, ar[200] = {0}, tp = 1; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a >> b; for (int j = a + 1; j <= b; j++) { if (!ar[j]) tp++, ar[j]++; } } cout << ((tp == m + 1) ? YES : NO ) << end...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e12; const int maxn = 2e5 + 30; int n; long long dp[maxn][2], val[maxn], h[maxn], ans; vector<int> G[maxn]; void Min(long long &x, long long y) { if (x > y) x = y; } void dfs(int u, int fa) { for (auto v : G[u]) { if (v...
#include <bits/stdc++.h> using namespace std; const long long bruh = -1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<long long> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } sort(v.begin(), v.end()); long long sum = accumulat...
#include <bits/stdc++.h> using namespace std; vector<complex<double> > vec; double minDist(complex<double> &a, complex<double> &b, complex<double> &p) { complex<double> ab = ((b) - (a)), ap = ((p) - (a)), ba = ((a) - (b)), bp = ((p) - (b)); double distPB = sqrt(((conj(bp) * (bp)).real(...
#include <bits/stdc++.h> using namespace std; long long int ABS(long long int a) { if (a < 0) return (-a); return a; } vector<long long int> g[100001]; vector<long long int> p[100001]; map<pair<long long int, long long int>, int> l; int visited[100001]; long long int ans[100001][4]; int main()...
#include <bits/stdc++.h> #pragma optimise GCC(-O2) using namespace std; mt19937_64 rang( chrono::high_resolution_clock::now().time_since_epoch().count()); int rng(int lim) { uniform_int_distribution<int> uid(0, lim - 1); return uid(rang); } long long INF = LLONG_MAX; const long long M = 1000...
#include <bits/stdc++.h> using namespace std; long long INF = (long long)1e20; long long mod = (long long)1e9 + 7; pair<long long, long long> solve( long long v, vector<vector<pair<long long, long long>>> &nodes, long long p, long long k) { vector<pair<pair<long long, long long>, long long>> a; ...
#include <bits/stdc++.h> using namespace std; ; const double eps = 1e-8; const int mod = 1e9 + 7; const int maxn = 3e5 + 5; const int INF = 0x3f3f3f3f; const long long INFLL = 0x3f3f3f3f3f3f3f3f; struct EDGE { int v, nxt; } edge[maxn << 1]; int head[maxn], tot; void add_edge(int u, int v) { ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = double; const ll MODBASE = 1000000007LL; const int MAXN = 100010; const int MAXM = 1010; const int MAXK = 110; const int MAXQ = 200010; int n, a[MAXN], b[MAXN], f[MAXN], t[MAXN]; void update(int u, int gt) { while (u)...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int maxt = 1 << 20; int p[maxn], t[maxn]; bool vis[maxn], cut[maxn]; long long x[maxn], l[maxn], cal[maxn], bit1[maxt], bit2[maxt]; vector<int> son[maxn]; void dfs1(int u, long long rem) { rem -= l[u] << 1; for (int i ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e6 + 7; const int mod = 1e9 + 7; int a[N]; int l[N]; int c[N]; int f[N]; int binpow(int a, int b) { int ret = 1; while (b) { if (b & 1) { ret = (ret * 1LL * a) % mod; --b; } a =...
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ff first #define ss second #define lli long long int #define ll long long #define st string #define vi vector<int> #define vll vector<long long> #define tll tuple<ll,ll,ll> #define pii pair<int,int> #define pll pair<ll...
#include <bits/stdc++.h> using namespace std; char a[1111]; int main() { int h = 0, i = 0, j; bool isopen = false; gets(a); while (i < strlen(a) - 1) { if (a[i] == < && a[i + 1] != / ) { if (isopen) h += 2; for (j = 0; j < h; j++) printf( ); printf( < ); ...
#include <bits/stdc++.h> using namespace std; long long a, b, c; int getlength(int x, int y, int z) { return (x - y + 1) / (z); } int main() { int n, a, b, right, left; cin >> n >> a >> b; set<int> M; int sh = (n + 1) / (b + 1); n++; b++; M.insert(0); M.insert(n); int m, x; ...
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __prin...
#include <bits/stdc++.h> using namespace std; int n, m, k; bool debug = false; int main() { scanf( %d , &n); int x, y; long long sum = 0, ss = 0, px = 0, py = 0; for (int i = 0; i < n; i++) { scanf( %d%d , &x, &y); sum += (long long)x * x + (long long)y * y; ss += px * x + py *...
#include <bits/stdc++.h> using namespace std; const int Maxn = 2e5; const long long inf = 1e15; inline int read() { char ch = getchar(); int f = 1, x = 0; while (ch > 9 || ch < 0 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + c...
#include <bits/stdc++.h> using namespace std; int c[160][160]; int lowbit(int x) { return x & -x; } int sum(int x, int y) { int ans = 0; for (int i = x; i; i -= lowbit(i)) { for (int j = y; j; j -= lowbit(j)) { ans += c[i][j]; } } return ans; } void add(int x, int y, int ...
#include <bits/stdc++.h> using namespace std; int a, b, l, r, c, pl, pr, cl, cr; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> a >> b >> l >> r, c = a + b; cl = --l / c; pl = l % c; cr = --r / c; pr = r % c; if (cl == cr) cout << min(r - l...
#include <bits/stdc++.h> using namespace std; bool conn[4001][4001]; vector<int> path[4001]; struct Edge { int a, b; } edge[4001]; int main() { int N, M; cin >> N >> M; for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; edge[i].a = a; edge[i].b = b; conn[a][...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 4 == 1 || n % 4 == 0) { int *result = new int[n + 1]; if (n % 2 == 1) { result[(n + 1) / 2] = n / 2 + 1; } for (int i = 1; i < (n + 1) / 2; i += 2) { result[i] = i + 1; res...
#include <bits/stdc++.h> using namespace std; const long long N = 5003, mod = 1e9 + 7; long long n, k, S[N][N], ans; inline long long kasumi(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = (long long)res * a % mod; a = (long long)a * a % mod; b >>= 1; } ...
#include <bits/stdc++.h> using namespace std; using namespace chrono; void _print(long long t) { cerr << t; } void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _p...
#include <bits/stdc++.h> using namespace std; int dp[500][500] = {0}, arr[500], n; int check(int i, int j) { if (dp[i][j] != 0) return dp[i][j]; if (i > j) return 0; if (i == j) { dp[i][j] = 1; return 1; } int a = 1 + check(i + 1, j); int m = 1e9, it; for (it = i + 2; it <=...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 2e5 + 10; long long sum[N]; long long a[N], b[N]; long long f[N][20]; int n, k, top; long long MAX(long long x, long long y) { if (x < y) return y; return x; } void advan() { for (int i = 1; i <= top;...
#include <bits/stdc++.h> using namespace std; long long n, m, k, c, ans1, ans2, ans3, a[100005], dp[5]; pair<long long, long long> p[300005]; vector<long long> v; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; if (m == 0) { cout << -1 << n ; ...
#include <bits/stdc++.h> using namespace std; vector<long long int> vec; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } long long int mark[123]; int main() { std::ios::sync_with_stdio(false); string str; cin >> str; long long int n; ...
#include <bits/stdc++.h> using namespace std; int main() { long long m, n, i, t, j; cin >> t; while (t--) { long long one = 0, zro = 0, cnt = 0, ans = 0; cin >> n; vector<long long> v; for (long long j = 0; j < n; j++) { string s; cin >> s; for (long long ...
#include <bits/stdc++.h> using namespace std; struct node { int x; int y; node(int a, int b) { x = a; y = b; } }; int n, m, k, flag; vector<node> v; int vis[10005], dis[10005]; const int inf = 0x3f3f3f3f; int spfa() { memset(dis, inf, sizeof(dis)); queue<int> q; q...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1); int main() { ios_base::sync_with_stdio(false); double w, h, a; cin >> w >> h >> a; if (a > 90.0) a = 180.0 - a; cout.setf(ios::fixed); cout.precision(10); if (a < eps) { cout << w...
#include <bits/stdc++.h> using namespace std; const int N = 5000 + 10; char s[N], t[N]; int n, m, dp[N][N]; int main() { scanf( %d%d%s%s , &n, &m, s + 1, t + 1); int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { dp[i][j] = 0; if (i >= 1) dp[i][j] = ma...
#include <bits/stdc++.h> using namespace std; int in() { int x; scanf( %d , &x); return x; } long long lin() { long long x; scanf( %lld , &x); return x; } int x[200010]; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) a[i] = in(); int...
#include <bits/stdc++.h> using namespace std; double max(double a, double b) { if (a >= b) return a; else return b; } int main() { double m[5], s, u; for (int i = 0; i < 5; i++) cin >> m[i]; double sum = 0, sum1; for (int i = 0; i < 5; i++) { sum1 = 0; double x; ...
#include <bits/stdc++.h> using namespace std; const int maxlongint = 2147483647; const int P1 = 19260817, P2 = 1000000007, N = 100011, M = 1000011; long long mi1[M], mi2[M], ni1[M], ni2[M], s1[M], s2[M]; char st[M], Ans[M]; long long powder(int x, int a, const int& P) { if (!a) return 1; long long t...
#include <bits/stdc++.h> using namespace std; struct state { bool win; int first, second; state() : win(false), first(0), second(1e9){}; state(bool nwin, int nfirst, int nsecond) : win(nwin), first(nfirst), second(nsecond){}; }; bool operator<(state a, state b) { return !(a.win > b.w...
#include <bits/stdc++.h> using namespace std; int n; char ch; int x, y; int dx[200001], dy[200001]; int ans; bool check(int ans) { if (ans > n) return true; int i, iend = n - ans + 1; for (i = 1; i <= iend; i++) { int vx = dx[i - 1] + dx[n] - dx[i + ans - 1]; int vy = dy[i - 1] + d...
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; int a[n]; for (i = 0; i < n; i++) cin >> a[i]; vector<int> b; for (i = 0; i < n; i++) { if (a[i] <= 1e6 - a[i]) b.push_back(a[i] - 1); else b.push_back(1e6 - a[i]); } sort(b.beg...
#include <bits/stdc++.h> using namespace std; int main() { char a[150], b[150]; int c, d, e, f, g, x, y, z; gets(a); gets(b); c = strlen(a); for (x = 0; x < c; x++) { if (a[x] >= A && a[x] <= Z ) a[x] = a[x] + ( a - A ); if (b[x] >= A && b[x] <= Z ) b[x] = b[x] + ( a - ...
#include <bits/stdc++.h> using namespace std; const long long MAX = 1e5 + 5; const long long inf = 1e18 + 9; pair<long long, long long> dp[MAX]; long long p[MAX]; bool portal[MAX]; struct Edge { long long from, to, cost; }; long long Find(long long u) { if (p[u] != u) p[u] = Find(p[u]); re...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1024000000,1024000000 ) using namespace std; const int maxn = 1e5 + 7; int n, m; long long h[maxn], p[maxn]; bool ok(long long x) { long long cnt = 0; for (int i = 0; i < n; i++) { if (p[cnt] >= h[i]) { for (int j = cnt; j < m; j...
#include <bits/stdc++.h> using namespace std; const int MAXN = 31; int dp[MAXN][MAXN][MAXN * MAXN]; int F(int n, int m, int k) { if (n > m) swap(n, m); if (k < 0) return (1 << 30); if (dp[n][m][k] != -1) return dp[n][m][k]; if (n * m == k || k == 0) return dp[n][m][k] = 0; int p = 1 << 30, q...
#include <bits/stdc++.h> using namespace std; const int dir[5][2] = {0, 1, 0, -1, 1, 0, -1, 0, 0, 0}; const int inf = 0x7fffffff; const int mod = 1000000; const int Max = 1000000; int temp[10], ans[Max]; void check(char *s) { int index = 0, dec, sum = 0, cnt = 0; dec = atoi(s); memset(temp, 0,...
#include <bits/stdc++.h> using namespace std; signed main() { string s; cin >> s; int n = s.size(); if (n == 1) { cout << 0; return 0; } int ans = 0; int co = 1; vector<pair<char, int> > c; for (int i = 1; i < n; i++) { if (s[i] != s[i - 1]) { c.emplace_...
#include <bits/stdc++.h> using namespace std; int blocksize; int msmo7; struct query { int start, en, idxofquery, blockidx, mincolor; query() {} query(int l, int r, int i, int adeh) { start = l; en = r; idxofquery = i; blockidx = l / blocksize; mincolor = adeh; } ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string q; cin >> q; int n; cin >> n; vector<string> m(n); for (int i = 0; i < (n); ++i) cin >> m[i]; sort(m.begin(), m.end()); for (int i = 0; i < (n); ++i) { if ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2.1e5; const int MAXQ = 2.1e5; int N, Q; int P[MAXN]; char C[MAXN]; vector<int> ch[MAXN]; int depth[MAXN]; int compChild[MAXN]; int compPar[MAXN]; int cnts[MAXN][26]; int subVal[MAXN][26]; int tot[MAXN]; int main() { ios_base...
#include <bits/stdc++.h> using namespace std; long long int n, u, v; vector<int> arr[100001]; long double ans = 0.0; long long int siz[100001]{0}; void dfs(int to, int from, int val) { int ret = 1; ans += 1.0 / val; for (auto i : arr[to]) { if (i != from) { dfs(i, to, val + 1); ...
#include <bits/stdc++.h> using namespace std; struct node { long long v, p, id; } t[2000001]; bool cmp2(node a, node b) { return a.p < b.p; } struct cmp { bool operator()(node a, node b) { return a.v > b.v; } }; priority_queue<node, vector<node>, cmp> q; priority_queue<long long> q2; long long...
#include <bits/stdc++.h> using namespace std; const int mn = 1000001; bool shirt(int p, int s) { int i = (s / 50) % 475; for (int j = 0; j < 25; j++) { i = (i * 96 + 42) % 475; if ((26 + i) == p) return true; } return false; } int main() { int p, x, y; cin >> p >> x >> y; ...
#include <bits/stdc++.h> using namespace std; long long solve() { string x[12] = { C , C# , D , D# , E , F , F# , G , G# , A , B , H }; map<string, long long> m; for (long long i = 0; i < 12; ++i) { m[x[i]] = i; } long long q[3]; string a, b, c; c...
#include <bits/stdc++.h> using namespace std; int grid[2500][2500]; int s[2500 + 1][2500 + 1]; char str[2500 + 10]; long long result = 0; char *trim_line(char *str) { return strtok(str, r n ); } long long mul_ll(long long x, long long y) { return x * y; } int count_ones(int lx, int ly, int rx, int ry)...
#include <bits/stdc++.h> using namespace std; long long dx[] = {1, 0, -1, 0}; long long dy[] = {0, 1, 0, -1}; long long gcd(long long x, long long y) { if (y == 0) return x; else return gcd(y, x % y); } long long expo(long long n, long long m, long long p) { long long r = 1; n = ...
#include <bits/stdc++.h> using namespace std; mt19937_64 rng(time(0)); const long double eps = 1e-15; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> p...
#include <bits/stdc++.h> using namespace std; int n, k; int main() { long long s = 0; cin >> n >> k; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; s += b - a + 1; } s %= k; if (s) s = k - s; cout << s << endl; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 9; const int MAXN = 3e5 + 1; int l[MAXN], r[MAXN]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v(n); fo...
#include <bits/stdc++.h> #define ed end() #define bg begin() #define mp make_pair #define pb push_back #define vv(T) v(v(T)) #define v(T) vector<T> #define all(x) x.bg,x.ed #define newline puts( ) #define si(x) ((int)x.size()) #define rep(i,n) for(int i=1;i<=n;++i) #define rrep(i,n) for(int i=...
#include<iostream> #include<map> #include<cstring> #include<cmath> #include<algorithm> #include <queue> #include<map> using namespace std; typedef long long ll; inline ll gcd(ll a,ll b) { return b>0 ? gcd(b,a%b):a; } int main() { ll T,m1,m,k,a,b; cin>>T; while(T--){ int a[30]=...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c, ans[4010]; scanf( %d %d %d %d , &n, &a, &b, &c); memset(ans, -1, sizeof(ans)); ans[0] = 0; for (int i = 0; i <= n; i++) { if (i >= a && ans[i - a] != -1) ans[i] = ans[i - a] + 1; if (i >= b && ans[i - b] != -1...
#include <bits/stdc++.h> using namespace std; const long long int M = 1e18 + 7; const long long int mod = 1e9 + 7; const long long int infi = LLONG_MAX; long long int i, j, ans, k, n, x, y, m, mymax = LLONG_MIN, mymin = LLONG_MAX, b, c, z, sum; int main() { long...
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <set> // #include <stdlib.h> // #include <stdio.h> // #include <ctype.h> using namespace std; int main(void){ int n = 0; cin >> n; for(; n > 0; n--){ int num; cin >> num...
#include <bits/stdc++.h> using namespace std; using ll = long long; int MOD; struct modint { private: int v; static int minv(int a, int m) { a %= m; assert(a); return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a); } public: modint() ...
#include <bits/stdc++.h> using namespace std; const int maxN = 20; const int maxn = (1 << maxN) + 20; int t[maxn], r[maxn][maxN + 3], x[maxn][maxN + 3]; string s[maxN]; void cal(int n, int k) { if (!n) return; cal(n - 1, k); cal(n - 1, k + (1 << (n - 1))); for (int i = 0; i < (1 << n); i++) ...
#include <bits/stdc++.h> using namespace std; int main(void) { int n, bar; vector<int> choco; cin >> n; for (int i = 0; i < n; ++i) { cin >> bar; choco.push_back(bar); } if (n == 1) cout << 1 0 n ; else { auto l = choco.begin(); auto r = choco.end() - 1; ...
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; int f[1 << 23], pre[1 << 23], zt[1 << 23], tot, ans[23]; int n, fn[23], fri[23][23]; int tans[23], Ans[23][23]; void Solve(int o) { int ni, st = 1 << (o - 1), ed = (1 << n) - 1; for (int i = (1); i <= (int)(fn[o]); ++i) st |= 1...
#include <bits/stdc++.h> using namespace std; long long int n, m, q; long long int gcd(long long int t, long long int u) { if (u == 0) { return t; } return gcd(u, t % u); } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> q; long long int gcd_nm = gcd...
#include <bits/stdc++.h> int main() { int a, b, r; scanf( %d %d %d , &a, &b, &r); r *= 2; if (r > a || r > b) { printf( Second n ); return 0; } printf( First n ); return 0; }
#include <bits/stdc++.h> using namespace std; const int sz = 105; long long int r[sz], a[sz][sz], b[sz][sz], ans[sz][sz], m; void multiply(long long int a[][sz], long long int b[][sz]) { for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { ans[i][j] = 0; for (int k = 0; k < m; k...
#include <bits/stdc++.h> using namespace std; int A1, A2, A3, A4; int main() { int i; scanf( %d%d%d%d , &A1, &A2, &A3, &A4); if (abs(A3 - A4) > 1) printf( -1 ); else { if (A3 == A4) { if ((((A1) > (A2) ? (A1) : (A2)) - A3 - 1 < 0) || (((A1) < (A2) ? (A1) : (A2)) < A...
#include <bits/stdc++.h> using namespace std; long long modexpo(long long x, long long p) { long long res = 1; x = x % 1000000007; while (p) { if (p % 2) res = res * x; p >>= 1; x = x * x % 1000000007; res %= 1000000007; } return res; } long long max(long long a, long...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int Comb[2015][2015], Fact[2015], used[2015], a[2015]; int main() { cin.sync_with_stdio(false); int n, m = 0, k = 0; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (a[i] != -1) used[a[i]] = 1; } ...
#include <bits/stdc++.h> using namespace std; int main() { int r, g, b; cin >> r >> g >> b; int ans = 0; ans = r / 3 + g / 3 + b / 3; if (min(r, min(g, b)) >= 1) ans = max(ans, (r - 1) / 3 + (g - 1) / 3 + (b - 1) / 3 + 1); if (min(r, min(g, b)) >= 2) ans = max(ans, (r - 2) / 3 + ...
#include <bits/stdc++.h> using namespace std; constexpr long double pi{3.1415926535897932384}; constexpr long long mod{1000000007}; long long power(long long x, long long y) { long long res = 1; x = x % mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) ...
#include<bits/stdc++.h> using namespace std; #define ll long long #define endl n const unsigned int mod = 1000000007; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); bool prime[1000001]; memset(prime, true, sizeof(prime)); for(int...
#include <bits/stdc++.h> using namespace std; template <typename T> void print_container(ostream& os, const T& c) { const char* _s = ; if (!c.empty()) { __typeof__(c.begin()) last = --c.end(); for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it) { os << *it; ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int N = 200500; void solve() { long long n, k; cin >> n >> k; if ((n + k) % 2 == 0 && n >= k && (n + k) / 2 >= (k * (k + 1)) / 2) { cout << YES n ; } else cout << NO n ; } int main() { ios::s...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; int count = 1; a[0] = 0; a[1] = 2; for (int i = 2; i < n; i++) { count++; a[i] = a[i - 1] + count; if (a[i] > n) { int rem = a[i] - n; a[i] = a[0] + rem; } } ...
#include <bits/stdc++.h> using namespace std; int n, t, m[2]; const int N = 2100000; const int inf = 1e9 + 7; int a[2][N], x[N]; int dp[2][N]; bool b[2][N], pr[2][N]; set<int> H[2]; int main() { cin >> n >> m[0] >> m[1] >> t; int xn = 0; x[xn++] = 0; for (int j = 0; j < 2; j++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; scanf( %d , &n); vector<int> cnt(20, 0); for (int i = 0; i < n; i++) { scanf( %d , &x); for (int b = 0; b < 20; b++) { if (1 & (x >> b)) cnt[b]++; } } long long ans = 0; for (int i = 0; i < n; ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e5 + 10; long long N, L, R, X, arr[maxn], ans; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> L >> R >> X; for (register long long i = 1; i <= N; ++i) { cin >> arr[i]; } for (register long l...
#include <bits/stdc++.h> using namespace std; const char al[100] = { A , B , C , D , E , F , G , H , I , J , K , L , M , N , O , P , Q , R , S , T , U , V , W , X , Y , Z }; int main() { long long int n, m; cin >> n >> m; vector<...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(0); int n, r1 = 0, r2 = 0; cin >> n; vector<int> r(n); for (int &i : r) cin >> i; for (int i = 0; i < n; i++) { int a; cin >> a; if (a != r[i]) { if (a) r1++; ...