solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { int arr[101] = {0}; int operation = 0, current = 0; int n, x; cin >> n >> x; for (int i = 0; i < n; i++) { cin >> current; arr[current]++; current = 0; } if (x == 0) { if (arr[0] == 0) operation = 0; else operation ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (n % 2 ? "Ehab" : "Mahmoud"); return 0; }
0
#include <bits/stdc++.h> using namespace std; int col[111111]; vector<int> g[111111]; bool dfs(int v, int c, pair<int, int>& cs) { col[v] = c; cs.first++; for (int i : g[v]) { if (col[i] == c) { return true; } if (col[i] == -1) { swap(cs.first, cs.second); if (dfs(i, 1 - c, cs)) { ...
12
#include <bits/stdc++.h> using namespace std; int n, m, k; string s[605]; int mark[605][605]; bool vis[260000]; vector<int> v[260000]; vector<int> vertices; void graph() { for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (mark[i][j] == 0) { vertices.push_back(((i - 1) * m) + j); ...
8
#include <bits/stdc++.h> using namespace std; const int N = 100000; const int inf = (int)1e9 + 1; const long long big = (long long)1e18 + 1; const int P = 239; const int MOD = (int)1e9 + 7; const int MOD1 = (int)1e9 + 9; const double eps = 1e-9; const double pi = atan2(0, -1); const int ABC = 26; int main() { ios_bas...
12
#include <bits/stdc++.h> using namespace std; int main() { string s, t; string x = "AHIMOTUVWXY"; cin >> s; t = s; for (int i = 0; i < s.size(); i++) { if (x.find(s[i]) == -1) { cout << "NO" << endl; return 0; } } reverse(s.begin(), s.end()); if (t == s) { cout << "YES" << endl; ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 100; int num[maxn]; int cnt[50]; int n, k, x; int main() { scanf("%d %d %d", &n, &k, &x); long long now = 1; for (int i = 0; i < k; ++i) now *= x; memset(cnt, 0, sizeof(cnt)); for (int i = 1; i <= n; ++i) { scanf("%d", &num[i]); f...
9
#include <bits/stdc++.h> using namespace std; long long n, m, dx, dy; pair<long long, long long> a[100005]; long long cnt[1000005]; pair<long long, long long> ans; long long mx = 0ll; int main() { scanf("%I64d%I64d%I64d%I64d", &n, &m, &dx, &dy); long long x = 1ll; long long y = 1ll; long long d = 0ll; for (in...
12
#include <bits/stdc++.h> using namespace std; int N, M; char S[200005], T[200005]; long long pw[2][200005], ha[2][26], me[2][26], cut[26], mul[2] = {97, 107}; int see = 0; map<long long, int> chk[2]; int main() { scanf("%d %d", &N, &M); scanf("%s %s", S, T); for (int a = 0; a < 2; a++) { pw[a][0] = 1; for...
16
#include <bits/stdc++.h> using namespace std; int n, cnt = 0; vector<int> a; set<int> b; vector<bool> used; vector<vector<int> > g; vector<multiset<int> > value; map<multiset<int>, int> num; void dfs(int x = 1) { used[x] = true; multiset<int> key; for (int i = 0; i < (int)g[x].size(); i++) { int to = g[x][i];...
21
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, const U &b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, const U &b) { if (a < b) a = b; } const int NN = 1000100; int b[NN], dp[NN], s[NN]; char a[NN]; int main() { int t; sc...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, pos, l, r; cin >> n >> pos >> l >> r; int ans = 0; if (l > 1 && r < n) { if (pos >= l && pos <= r) { ans += min(pos - l, r - pos) + r - l + 2; } else if (pos >= l) { ans += pos - l + 2; } else if (pos <= r) { ans += ...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 100, mod = 998244353; int qpow(int x, int y) { int res = 1; while (y) { if (y & 1) res = 1ll * res * x % mod; x = 1ll * x * x % mod, y >>= 1; } return res; } int n, m, fac[N], inv[N], pre[N], suf[N], ans; char str[N]; int C(int x, int y) ...
21
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <string> #include <sstream> #include <cstring> #include <cctype> #include <cmath> #include <vector> #include <set> #include <bitset> #include <map> #include <stack> #include <queue> #include <ctime> #define _for(i,a,b) for(int i=(a);...
21
#include <bits/stdc++.h> using namespace std; signed main() { long long t; cin >> t; while (t--) { long long x, n, m, flag = 0; cin >> x >> n >> m; if (x > 20) { while (n--) { if (x <= 0) { flag = 1; break; } else { x = (x / 2) + 10; } ...
1
#include <bits/stdc++.h> using namespace std; bool go(int n, long long k, int a[], int b[], long long val); int main() { ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; int a[n], b[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; int cookies = 1e9; for (in...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 3; int d[maxn]; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 2; i <= n; i++) { if (d[i] == 0) { for (int j = i + i; j <= n; j += i) { d[j] = i; } } } int maxd = d[n]; int ans = ...
9
#include <bits/stdc++.h> using namespace std; int min(int a, int b) { return a == -1 || a > b ? b : a; } int max(int a, int b) { return a == -1 || a < b ? b : a; } const int maxn = 2000 + 10; char s[maxn][maxn], ss[maxn][maxn]; int n, m; bool ok(int l, int r, int u, int d) { for (int i = 0; i < n; i++) for (int j...
13
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long testcases = 1; cin >> testcases; while (testcases--) { long long n; cin >> n; string s; cin >> s; string str1 = ""; for (long long i = 0; i < s.size(); i...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:20000000") using namespace std; int ri() { int x; scanf("%d", &x); return x; } long long rll() { long long x; scanf("%lld", &x); return x; } void solve() { int lx = -2e9, rx = 2e9; int n = ri(); for (int i = (int)(1); i <= (int)(n); i++) { s...
6
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); long long T = clock(); long long t = 1; cin >> t; while (t--) { long long n, k; cin >> n >> k; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; }; long long x = *...
0
#include <bits/stdc++.h> using namespace std; inline int read() { int first = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = 0; c = getchar(); } while (isdigit(c)) first = first * 10 + c - '0', c = getchar(); return f ? first : -first; } char s[705]; int d[705], dp[705][705][1...
20
#include <bits/stdc++.h> using namespace std; int lucky(int temp) { int count = 0, check; while (temp > 0) { check = temp % 10; if (check == 4 || check == 7) { count++; } temp /= 10; } return count; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s, t; cin >>...
0
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int mod = 1000000007; int Mod(long long x) { return x >= mod ? x - mod : x; } long long read() { long long x = 0; int f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch =...
18
#include <bits/stdc++.h> using namespace std; const int MAXN = 510; int arr[MAXN]; int ANS = 0; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 1; i < n; i++) { if (arr[i] + arr[i - 1] < k) { ANS += a...
2
#include <bits/stdc++.h> using namespace std; int main() { long long m, b, ans = 0; cin >> m >> b; for (long long x = 0; x <= b * m; x += m) { long long y = b - x / m; ans = max(ans, x * (1 + x) / 2 * (y + 1) + y * (y + 1) / 2 * (x + 1)); } cout << ans; return 0; }
5
#include <bits/stdc++.h> using namespace std; int main() { long long n, count = 0; cin >> n; for (int a = 1; a <= n; a++) { for (int b = a; b <= n; b++) { long long c = a ^ b; if (a + b > c && c >= b && c <= n) { count++; } } } cout << count; return 0; }
5
#include <bits/stdc++.h> using namespace std; double const pi = 3.1415926535897932384626433832795; int const inf = (int)1e9; long long const inf64 = (long long)2e18; const string name = "c"; const int NMAX = 4011; int ti, td, ts, tc, n1, n2; char s1[NMAX], s2[NMAX]; int ans[NMAX][NMAX]; int last1[150], exist1[NMAX][150...
18
#include <bits/stdc++.h> using namespace std; const int INF = 1e18; const int N = 1e6 + 23; long long i, j, k, m, res, ans, cnt, temp, f = 1; struct Node { long long x, y, id; } t[9]; long long ck[3] = {1, 4, 6}, ck2[3] = {3, 5, 8}; bool cmp(Node a, Node b) { if (a.x != b.x) return a.x < b.x; else return ...
6
#include <bits/stdc++.h> using namespace std; long long n, m; long long Pow(long long a, long long b) { long long ret = 1; while (b) { if (b & 1) ret = (ret * a) % m; a = (a * a) % m; b >>= 1; } return ret; } int main() { while (cin >> n >> m) { cout << (Pow(3, n) - 1 + m) % m << endl; } r...
6
#include <bits/stdc++.h> using namespace std; char s[20]; int ans[210]; int main() { int n; while (scanf("%d", &n) != EOF) { scanf("%s", s); int tot = 0; for (int i = 0; i < n; i++) { if (s[i] == '4') { ans[tot++] = 2; ans[tot++] = 2; ans[tot++] = 3; } else if (s[i] =...
6
#include <bits/stdc++.h> int main() { int a, b; scanf("%d%d", &a, &b); if (a < b) printf("%d %d\n", a, (b - a) / 2); else printf("%d %d\n", b, (a - b) / 2); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int k; cin >> k; string a; cin >> a; if (k > a.length()) { string ans; ans += "1"; for (int i = 0; i < k - 1; i++) ans += "0"; cout << ans << endl; return 0; } b...
9
#include <bits/stdc++.h> const long long MOD = 1000000007; int N, a[502][502]; long long R[501][501], F[501][501]; int main() { scanf("%d", &N); for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) scanf("%d", a[i] + j); for (int i = 1; i <= N; i++) a[i][N + 1] = a[1][i]; for (int i = N; i; i--) { ...
17
#include <bits/stdc++.h> using namespace std; char mat[4][110]; char let = 'a'; int n; void printMat() { for (int i = 0; i < 4; i++) { for (int j = 0; j < n; j++) if (mat[i][j] == 0) for (;;) ; else cout << mat[i][j]; cout << endl; } } void put(int i, int j, int dir) { ...
5
#include <bits/stdc++.h> using namespace std; int main() { long long l, r, k; cin >> l >> r >> k; bool f = 1; long long t = 1; while (t <= r) { if (t >= l) { f = 0; cout << t << " "; } if (r / k >= t) t *= k; else break; } if (f) cout << -1; return 0; }
7
#include <bits/stdc++.h> using namespace std; const string nl = "\n"; using ll = int64_t; using vi = vector<int>; using vl = vector<ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using str = string; using vpii = vector<pii>; using vpll = vector<pll>; template <class T> inline bool ckmin(T& a, T b) { retur...
10
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:36777216") template <class T> inline T &RD(T &); template <class T> inline void OT(const T &); inline long long RD() { long long x; return RD(x); } inline double &RF(double &); inline double RF() { double x; return RF(x); } inline cha...
23
#include <bits/stdc++.h> using namespace std; const int md = 1000003; long long binpow(long long n, long long k) { long long ans = 1; while (k != 0) { if (k % 2 == 1) ans = (ans * n) % md; n = (n * n) % md; k >>= 1; } return ans; } int main() { long long n, k; long long ed = 1; cin >> n >> k; ...
15
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const int MAXN = 1e5 + 5; int n, m; int a[MAXN]; int main() { register int i, j, s = 0; scanf("%d %...
23
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n > 1) { cout << ((n / 2) * 2 + (n + 1) / 2) << "\n"; for (int i = 2; i <= n; i += 2) cout << i << " "; for (int i = 1; i <= n; i += 2) cout << i << " "; for (int i = 2; i <= n; i += 2) cout << i << " "; } if (n ==...
8
#include <bits/stdc++.h> using namespace std; const int N = 2000010; const int mod = 1e9 + 7; int n; int a[N]; int f[N]; long long ans; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; f[a[i]]++; } for (int i = 0; i <= n; i++) ans += f[i] & 1; if (ans > 1) { cout << 0; return ...
17
#include <bits/stdc++.h> long long GCD(long long a, long long b) { long long mod; while (mod = a % b) { a = b; b = mod; } return b; } struct Fra { long long de, nu; void reduce() { long long gcd = GCD(de, nu); de /= gcd; nu /= gcd; } bool sub(long long x) { nu -= de * x; if (...
9
#include <bits/stdc++.h> using namespace std; typedef long long int64; typedef unsigned long long uint64; const double pi = acos(-1.0); const double eps = 1e-11; const int MAXI = 0x7fffffff; int in() { int x = 0, c; for (; (unsigned)((c = getchar()) - '0') >= 10;) { if (c == '-') return -in(); if (!~c) thro...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int a, b, c = 0; cin >> a >> b; if (b < a) { if ((a - b) % 2 == 0) cout << 1 << endl; else cout << 2 << endl; } else if (b > a) { if ((a - b) % 2 == 0) cout...
0
#include <bits/stdc++.h> using namespace std; int fail[100005], cal[100005][207], n, m; string s, p; vector<int> dp[100005]; void build_failure() { int k = 0; fail[0] = 0, fail[1] = 0; for (int i = 2; i <= m; ++i) { while (k > 0 && p[i - 1] != p[k]) k = fail[k]; if (p[i - 1] == p[k]) k++; fail[i] = k;...
15
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, m, x, y; int v[N]; vector<int> g[2][N]; int dist[N]; bool used[2][N]; deque<int> q; void dfs(int u) { used[0][u] = true; for (int i = 0; i < (int)g[0][u].size(); i++) { int to = g[0][u][i]; if (!used[0][to]) dfs(to); } } void bfs...
9
#include <bits/stdc++.h> template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; const long long MOD = 1000000007; class ModInt { public: ...
16
#include <bits/stdc++.h> using namespace std; inline int read() { int f = 1, x = 0; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } inline long long readll() { long long f ...
18
#include <bits/stdc++.h> using namespace std; const int N = 17; const int M = 32770; const int inf = 1e9; int n, a[N], bin[N], low[M][N], f[N][N][M], pos[N][N][M], sta[N][N][M], id[N], s[M]; void init() { bin[0] = 1; for (int i = 1; i <= 15; i++) bin[i] = bin[i - 1] * 2; for (int i = 1; i < bin[15]; i++) ...
22
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; void test_case() { int ans = 0; int n; cin >> n; vector<int> a(n); map<int, int> h; for (int i = 0; i < n; i++) { cin >> a[i]; h[a[i]]++; } for (auto x : h) { if (x.first != 0 && x.second > 2) { cout << "-1"; ...
0
#include <utility> #include <iostream> #include <cmath> #include <deque> #include <string> #include <time.h> #include <stack> #include <vector> #include <map> #include <set> #include <sstream> #include <algorithm> #include <bitset> #include <fstream> #define pii pair<ll,ll> #define mp make_pair #define X first #define...
13
#include <bits/stdc++.h> using namespace std; int i, j, n, m, mx, t, pos; int h[200001], h2[200001]; int x[200001], y[200001]; int q[200001], w[200001], z[200001]; int a[1001][1001]; int main() { cin >> n; for (i = 1; i <= n; i++) h[i] = 1000000000; for (i = 1; i < n; i++) { cin >> x[i] >> y[i]; a[x[i]][y...
13
#include <bits/stdc++.h> using namespace std; long long N, x_0, y_0, rs, mini = 100000; string s; long long M[10]; int main() { cin >> s; int l = s.length(); for (int i = 0; i < l; ++i) { if (s[i] == 'B') M[1]++; else if (s[i] == 'u') M[2]++; else if (s[i] == 'l') M[3]++; else if...
2
#include <bits/stdc++.h> using namespace std; int kol, a[2000], n, lrr[10], rrr[10]; int f(int x) { int i, j, g, l = 0; for (i = 1; i <= n; i++) if (a[i] != i) { l = 1; break; } if (l == 0) { kol = x - 1; return 1; } if (x > 3) return 0; for (i = 1; i <= n; i++) { for (j = i ...
19
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { long long unsigned n, k, x; cin >> n; for (int i = 1; i <= n; i++) { cin >> k >> x; cout << 9 * (k - 1) + x << '\n'; } return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; vector<pair<int, int> > v; map<int, int> m; int pre = 1; int i = 1; for (; i <= n; i++) { m[a[i]]++; if (m[a[i]] == 2) { m.clear(); v.push_back(make_p...
8
#include <bits/stdc++.h> using namespace std; int abs(int, int); bool b(double, double, double[], int); int fin(int[], int, int); int main() { int n; double p; cin >> n >> p; p = 1 - p / 100; double a[10000]; for (int i = 0; i < n; i++) cin >> a[i]; double l = 0; double c; double h = 10000000; for (...
8
#include <bits/stdc++.h> using namespace std; int main() { vector<int> a; int n, k, c, sum = 0, min = INT_MAX, index; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> c; a.push_back(c); } for (int i = 0; i < k; i++) sum += a[i]; if (sum < min) { min = sum; index = 1; } for (int i = ...
3
#include <bits/stdc++.h> const int OO = 0x3f3f3f3f, mod = 1e9 + 7; using namespace std; int dx[]{1, -1, 0, 0, 1, 1, -1, -1}; int dy[]{0, 0, 1, -1, 1, -1, 1, -1}; void K_K() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } set<pair<int, int>> ps; map<int, set<int>> mp; int main() { K_K(); int n, m, a; c...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 10; const int maxq = 100000 + 10; bitset<maxn> b[maxn]; bitset<maxn> c; vector<int> edges[maxq]; int op[maxq], x[maxq], y[maxq]; int n, m, q; int ans[maxq]; void dfs(int s) { if (s == 0) { for (int i = 0; i < edges[s].size(); i++) { ans[e...
14
#include <bits/stdc++.h> using namespace std; int main() { long long int t, s, x; cin >> t >> s >> x; if (x >= t) { if (x == t) { printf("YES\n"); return 0; } if ((x - t) % s == 0) { printf("YES\n"); return 0; } if ((x - t - 1) % s == 0 && x != t + 1) { printf("YE...
1
#include <bits/stdc++.h> int main() { int h, a, c; int H, A; scanf("%d %d %d", &h, &a, &c); scanf("%d %d", &H, &A); int i; int fightArr[100000]; for (i = 0; H > 0; ++i) { if (a >= H) { fightArr[i] = 1; H -= a; continue; } if (A >= h) { fightArr[i] = 0; h += c; ...
4
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& _p) { return os << "(" << _p.first << "," << _p.second << ")"; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& _V) { bool f = true; os << "["; for (auto v ...
24
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long int LINF = 0x3f3f3f3f3f3f3f3fll; const long double pi = acos(-1); const int MOD = 1e9 + 7; vector<vector<long long int> > graph; bool bfs(long long int start, long long int end) { vector<long long int> visited(105, 0); queue<l...
22
#include <bits/stdc++.h> using namespace std; int x[200005]; long long y[200005]; bool cw(int i, int j, int k) { return (x[j] - x[i]) * (y[k] - y[i]) - (y[j] - y[i]) * (x[k] - x[i]) < 0; } int up[19][200005]; int lenToRoot(int a) { int ret = 0; for (int i = 18; i >= 0; --i) { if (up[i][a] != -1) { ret +...
14
#include <bits/stdc++.h> using namespace std; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } const int maxn = 3e5 + 10; int x[maxn], n; int p[maxn]; int a[maxn], b[maxn], m; int c; double _min(double x, double y) { return x <= y ? x : y; } double _max(double x, ...
14
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (n == 2 ? 2 : 1); return 0; }
0
#include <bits/stdc++.h> using namespace std; long long n, k[111], m[111][111], ans, minn = 100000; int main() { cin >> n; for (long long i = 1; i <= n; i++) cin >> k[i]; for (long long i = 1; i <= n; i++) { for (long long j = 1; j <= k[i]; j++) { cin >> m[i][j]; ans += m[i][j] * 5 + 15; } ...
1
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-12; const long double PI = 2 * acos(0); long double solve(long double r1, long double r2, long double d) { long double lo = 0; long double hi = PI; for (int it = 0; it < 1000; it++) { long double mid = (lo + hi) / 2.0; long double x ...
12
#include <bits/stdc++.h> using namespace std; long long s1[55]; long long s2[55]; long long s12[55]; long long s21[55]; long long s22[55]; int k, x, n, m; bool can(int m1, int m2, int m3, int n, int m, int &i, int &j) { for (i = 0; 2 * i <= n; i++) { for (j = 0; 2 * j <= m; j++) { if ((s1[k] * i + s2[k] * j...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; const long long mod = 1000000007; long long C[maxn][maxn]; int main() { memset(C, 0, sizeof(C)); C[0][0] = 1; for (int i = 1; i <= 1000; i++) { C[i][0] = C[i][i] = 1; for (int j = 1; j < i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) ...
12
#include <bits/stdc++.h> using namespace std; long long s[200010], ba[200010], bb[200010]; void add(long long *b, int p, long long x) { while (p < 200010) { b[p] += x; p += p & -p; } } long long sum(long long *b, int p) { long long res = 0; while (p > 0) { res += b[p]; p -= p & -p; } return ...
9
#include <bits/stdc++.h> using namespace std; const int B = 27397, MOD = 1e9 + 7; const int B1 = 33941, MOD1 = 1e9 + 9; int k, n; bool zapeci(int x, int y) { printf("1 %d %d\n", x, y); fflush(stdout); string ans; cin >> ans; if (ans == "TAK") return true; return false; } int binary(int lo, int hi) { if (l...
14
#include <bits/stdc++.h> int main() { for (int i = 0; i < 10; i++) printf("??%d>>%d??\n", i, i); printf("??>>?\n"); for (int i = 0; i < 9; i++) printf("%d?<>%d\n", i, i + 1); printf("9?>>?0\n?<>1\n>>??\n"); }
17
#include <bits/stdc++.h> using namespace std; inline long long r() { long long s = 0, k = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') k = -1; c = getchar(); } while (isdigit(c)) { s = s * 10 + c - '0'; c = getchar(); } return s * k; } long long T, n, c[1000005], a[1000005], ...
9
#include <bits/stdc++.h> using namespace std; void optimise() { ios_base::sync_with_stdio(false); cin.tie(NULL); } long long int mod = 998244353; void normalize(long long int &a) { a = (a + mod) % mod; } long long int modmul(long long int a, long long int b) { a = a % mod; b = b % mod; normalize(a); normali...
10
#include <bits/stdc++.h> using namespace std; const int MAX_SIZE = 10 * 1000 * 5; string tolower(string s) { for (int i = 0; i < s.size(); ++i) s[i] = tolower(s[i]); return s; } void push_to_hash(string s, map<string, int> &hash, vector<int> &minR, vector<int> &minL) { s = tolower(s); if (hash...
16
#include <bits/stdc++.h> template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using namespace std; string to_string(const string &s) { return '"' + s + '"'; ...
22
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << 1; return 0; } n *= 2; n--; int c = n; int s = n; c -= 2; while (c > 1) { s += c * 2; c -= 2; } s += 2; cout << s; }
0
#include <bits/stdc++.h> using namespace std; int p[100000], patch[100000], vis[100000]; int n, a[2], flag = 0; map<int, int> M; bool dfs(int x, int y) { if (vis[x] == flag) return true; patch[x] = y; vis[x] = flag; if (!M.count(a[y] - p[x])) return false; if (!M.count(a[!y] - p[x])) return dfs(M[a[y] - p...
12
#include <bits/stdc++.h> using namespace std; long long n, m, first[100001]; int main() { cin >> n >> m; first[1] = first[0] = 1; for (int k = 2; k <= n; ++k) first[k] = first[k - 1] + first[k - 2]; for (int k = 1; k <= n; k) { if (first[n - k] >= m) { cout << k << ' '; k += 1; continue; ...
11
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; const double PI = acos(-1.0); const long long EPS = (1e-10); const long long N = 1e5 * 2 + 10; const long long inf = 1e9 * 2 + 10; const ll INF = 1e18 * 2 + 10; const long long MOD = 1e9 + 7; long...
9
#include <bits/stdc++.h> long long a[100010]; int main() { long long n, m; scanf("%I64d%I64d", &n, &m); long long resu = 0; long long time = 0; long long i; long long cnt; a[0] = 0; cnt = 1; for (i = 1; i <= n; i++) { scanf("%I64d", &a[i]); time += a[i]; while (cnt <= i && time > m) { ...
6
#include <bits/stdc++.h> using namespace std; int main() { FILE* we; long long mod = 998244353; int n, m; cin >> n >> m; long long ans = 4; for (int i = 0; i < n - 1; i++) ans = (ans * 2) % mod; for (int i = 0; i < m - 1; i++) ans = (ans * 2) % mod; cout << ans; return 0; }
5
#include <bits/stdc++.h> using namespace std; const long long infl = 0x3f3f3f3f3f3f3f3fLL; const long long infi = 0x3f3f3f3f; const long long mod = 1000000007; const long double pi = 3.14159265358979323846264; long long powm(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = (res * a) %...
1
#include <bits/stdc++.h> #pragma GCC optimize("", on) using namespace std; const long long maxn = 5e5 + 13; const long long INF = 2e9 + 13; const long long MOD = 1e9 + 7; double a[maxn]; double f(double x, long long n) { vector<double> pref(n), b(n); double minS = INF, maxS = -INF; pref[0] = a[1] - x; for (long...
12
#include <bits/stdc++.h> using namespace std; const int N = 1005; double a[N][N]; double f[N][N]; int n, m; int x, y; void print() { for (int i = 1; i <= m; ++i) { for (int j = 1; j <= m; ++j) printf("%.4lf ", a[i][j]); puts(""); } } void gauss() { for (int i = 1; i <= m; ++i) { double tmp = a[i][i]; ...
16
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { char s[200005]; int i, j; scanf("%s", s); int k, n; n = strlen(s); for (i = 0, j = 0; i < n; i = j) { while (j < n && s[j] == s[i]) j++; char c = 'a'; while (c == s[i] || (i > 0 && c == s[i - 1]) || (j < n && ...
5
#include <bits/stdc++.h> using namespace std; long long pow(long long a, long long b, long long m) { if (a == 0) return 0; if (b == 0) return 1; long long temp = pow(a, b / 2, m); temp = ((temp % m) * (temp % m)) % m; if (b & 1) temp = ((temp % m) * (a % m)) % m; return temp; } long long string_to_num(strin...
10
#include <bits/stdc++.h> using namespace std; int main() { long double ax, ay, bx, by, cx, cy; cin >> ax >> ay >> bx >> by >> cx >> cy; if ((by - ay) / (bx - ax) != (cy - by) / (cx - bx) && (by - ay) * (by - ay) + (bx - ax) * (bx - ax) == (cy - by) * (cy - by) + (cx - bx) * (cx - bx)) { printf...
6
#include <bits/stdc++.h> using namespace std; void key() { long long x, y, n, k; cin >> n >> x >> y; vector<long long> a(n), b(n); b[n - 1] = 1e9 + 2; for (long long i = 0; i < n; i++) { for (long long j = i + 1; j < n; j++) { a[i] = x; a[j] = y; long long dif = y - x; long long d ...
4
#include <bits/stdc++.h> using namespace std; const uint64_t mod = (1ull << 61) - 1; const unsigned long long bas = 31; inline uint64_t mult(uint64_t a, uint64_t b) { uint64_t l1 = (uint32_t)a, h1 = a >> 32, l2 = (uint32_t)b, h2 = b >> 32; uint64_t l = l1 * l2, m = l1 * h2 + l2 * h1, h = h1 * h2; uint64_t ret = ...
22
#include <bits/stdc++.h> using namespace std; int n, k; int cnt1 = 0, v1 = -1, cnt2 = 0, v2 = -1; int main() { scanf("%d%d", &n, &k); for (int kase = 1; kase <= k + 1; kase++) { printf("? "); for (int i = 1; i <= k + 1; i++) if (i != kase) printf("%d ", i); printf("\n"); fflush(stdout); in...
26
#include <bits/stdc++.h> using namespace std; int main() { long long n, X; scanf("%lld", &n); long long sum = 0, maxX = 0; for (int i = 1; i <= n; i++) { scanf("%lld", &X); sum += X; maxX = max(maxX, X); } if (sum % 2 == 1 || maxX * 2 > sum) printf("NO\n"); else printf("YES\n"); retu...
7
#include <bits/stdc++.h> using namespace std; int polynomial[3][222], n, a = 1, b = 0, c = 2, i, j, v; int main() { scanf("%d", &n); polynomial[a][0] = 1; for (i = 1; i <= n; i++) { for (j = 0; j <= i; j++) { v = polynomial[b][j]; if (j) v += polynomial[a][j - 1]; if (v >= 2) v = 0; po...
14
#include <bits/stdc++.h> using namespace std; void task(); int main() { srand(time(0)); task(); return 0; } const int N = 2e5 + 17; int n, i; string s[N]; char buf[17]; map<string, int> m; void task() { scanf("%d", &n); for (i = 0; i < n; ++i) { scanf("%s", buf); s[i] = buf; } for (i = n - 1; i >=...
4
#include <bits/stdc++.h> int n, m; char s[100010]; int cont[110]; int v[100010]; void f() { int l = 0, k = 0; char b = 'a'; for (int i = 0; i < n && i < n - m + 1; i++) { k = 0; char a = 'z'; for (int j = i; j < m + i; j++) { if (s[j] < b) { k = j; break; } if (s[j] <...
11
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 1e2; const int oo = 1 << 30; char line[MAX]; int n, k; int f[MAX]; int g[MAX]; void increase(int i) { if (i == -1) { putchar('1'); return; } if (line[i] == '.') return increase(i - 1); if (line[i] != '9') line[i]++; else { lin...
9
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; void solve(); const int maxn = 1e6 + 10; char str[maxn]; int main() { while (~scanf("%s", str)) { solve(); } return 0; } void solve() { int a = 0; int ans = 0; int poa = 1; int len = strlen(str); for (int i = 0; i < len; i++) { ...
6