solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; int n, a[26], p, i; string s; int f(int a) { return (a * (a - 1)) / 2; } int main() { for (cin >> n; n--;) cin >> s, a[s[0] - 97]++; for (; i < 26; i++) p += (f(a[i] / 2) + f(a[i] - a[i] / 2)); cout << p; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--){ string gg; vector<char> nn; int n; cin>>n; cin>>gg; nn.push_back(gg[0]); for (int i = 1; i < gg.size(); i++) if (gg[i]!=gg[i-1]) nn.push_back(gg[i]); // for (int i = 0; i < nn.size();...
0
#include <bits/stdc++.h> using namespace std; const long long md = 1e9 + 7; const int xn = 3e5 + 10; const int xm = 5e5 + 10; const int SQ = 700; const long long inf = 1e18 + 10; int a[xn][8], n, m; int f[300], ff[300]; bool fl[xn]; pair<int, int> ans; void bin(int s) { int ss = s; for (int i = 0; i < 10; i++) fl[i...
6
#include <bits/stdc++.h> using namespace std; int main() { time_t START = clock(); int n, m, d = 1; cin >> n >> m; int i; for (i = 0; i < 2 * m; i += 2) { cout << d << ' ' << d + 1 << ' '; d += 2; } for (i; i < 2 * n; i += 2) { cout << d + 1 << ' ' << d << ' '; d += 2; } time_t FINISH ...
3
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; long long i, j, x, y, z, m, n, k, l, r, f, mi = 1e18, ans, x2, y2, ma, t, a[1010000]; string s, s2; vector<long long> v[410000], v2, v3; ...
8
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long md) { long long res = 1; x %= md; while (y > 0) { if (y & 1) res = (res * x) % md; x = (x * x) % md; y = y >> 1; } return res % md; } vector<long long> v[100010]; vector<long long> second(100010); vec...
4
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; const int INFINITE = 0x3f3f3f3f; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } template <class T> inline T sqr(T x...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000 + 5; const int inf = 1e9; int n, m, c; int ans[MAXN]; void insert1(int x) { for (int i = 1; i <= n; ++i) { if (!ans[i] || ans[i] > x) { cout << i << endl; ans[i] = x; return; } } } void insert2(int x) { for (int i = n; i...
6
#include <bits/stdc++.h> using namespace std; set<int> s[100005]; int cnt[1000005]; int main() { int n, A; scanf("%d%d", &n, &A); for (int i = 1; i <= 1e6; i++) s[0].insert(i); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); cnt[x]++; if (x == A) { s[cnt[x] - 1].clear(); s[cnt...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10, SQ = 500; int n, q, l, r, ans, cnt[MAXN + 5], a[MAXN + 50], dp[MAXN + 50][SQ]; vector<int> v; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> q; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] ...
5
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { long long x1, y1, x2, y2; scanf("%lld %lld %lld %lld", &x1, &y1, &x2, &y2); printf("%lld\n", (x2 - x1) * (y2 - y1) + 1); } return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { int n, k, l, c, d, p, nl, np; cin >> n >> k >> l >> c >> d >> p >> nl >> np; int a = (k * l) / nl; int aa = c * d; int aaa = p / np; std::cout << min({a, aa, aaa}) / n << std::endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; struct point { int x, y; point() {} point(int a, int b) { x = a, y = b; } }; template <class T> T sqr(T a) { return a * a; } template <class T> T power(T n, T p) { T res = 1; for (int i = 0; i < p; i++) res *= n; return res; } template <class T> double getdist...
3
#include <bits/stdc++.h> using namespace std; long long z[300001]; long long pot[300001]; void po(int n) { int sum = 1; pot[0] = 1; while (n > 0) { pot[sum] = (pot[sum - 1] * 2) % 1000000007; sum++; n--; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); po(300000); in...
3
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; int n, m, w[22][22], dp[1 << 22], same[22][22], cost[22][22]; char g[22][22]; int main() { scanf("%d%d", &n, &m); for (register int i = 0; i <= (1 << n); i++) dp[i] = inf; dp[0] = 0; for (register int i = 0; i < n; ++i) scanf("%s", &g[i]); for...
8
#include <bits/stdc++.h> using namespace std; long long a[100000], b; int n; long long maxSubArraySum() { long long max_so_far = 0, max_ending_here = 0, max_so_far_2 = 0, max_ending_here_2 = 0; for (int i = 0; i < n; i++) { if (i > 0) { max_ending_here += a[i]; if (max_ending_here < 0) ...
2
#include <bits/stdc++.h> using namespace std; typedef struct node { struct node* nexNode[2]; int cnt; } Node; Node* root; void trie_insert(int num) { int i = 30; string s = ""; while (i > 0) { char digit = '0' + num % 2; s = digit + s; num /= 2; i--; } Node* current = root; while (i < s....
6
#include <bits/stdc++.h> using namespace std; const int N = int(3e5) + 9; int n; long long a[N]; int b[N]; int cnt[2]; int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; b[i] = __builtin_popcountll(a[i]); } long long res = 0; int sufSum = 0; cnt[0] ...
6
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int len = s.length(); int n; cin >> n; int a[1][len]; int count = 0; for (int i = 0; i < len - 1; i++) { if (s[i] == s[i + 1]) count++; a[0][i] = count; } while (n--) { int l, r; cin >> l >> r; l--; ...
1
#include <bits/stdc++.h> using namespace std; int vis[10006]; int colour[10006]; vector<int> adj[10006]; int ans = 0; void dfs(int N, int clr) { stack<int> S; S.push(N); if (colour[N] != clr) { ans++; } while (!S.empty()) { int u = S.top(); S.pop(); int l = adj[u].size(); for (int i = 0; i...
2
#include <bits/stdc++.h> using namespace std; int build[55]; bool cmp(int x, int y) { return x > y; } int main() { ios::sync_with_stdio(0); int n, h, m; int l, r, x, ans = 0; cin >> n >> h >> m; for (int i = 1; i <= n; i++) build[i] = h; for (int i = 1; i <= m; i++) { cin >> l >> r >> x; for (int i ...
0
#include <bits/stdc++.h> using namespace std; int to_num['z' + 1]; char to_char(int n); void fill_to_num() { for (char c = 'a'; c <= 'z'; c++) { to_num[c] = c - 'a'; } for (char c = '0'; c <= '9'; c++) { to_num[c] = c - '0' + 26; } to_num['\\'] = 36; to_num['.'] = 37; } const int SLASH = 36; const i...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; pair<int, int> ar[n]; int tot = 0; for (int i = 0; i < n; i++) { cin >> ar[i].first; tot += ar[i].first; ar[i].second = i + 1; } sort(ar, ar + n); int dif = ar[n - 1].first; for (int i = 1; i < n; i++) { ar[i]....
3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n; scanf("%d %d %d", &a, &b, &n); if (b == 0) { printf("0\n"); } else if (a == 0) { printf("No solution\n"); } else { int x = round(pow(1.0 * abs(b) / abs(a), 1.0 / n)); double t = a, u = a; for (int i = 0; i < n; i++) { ...
3
#include <bits/stdc++.h> using namespace std; int a[100010], num[100010]; int main() { int n, maxx = 0, minn = 1000000000, flag = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); minn = min(a[i], minn); } for (int i = 1; i <= n; i++) { a[i] = a[i] - minn; if (a[i] > n) { ...
6
#include <bits/stdc++.h> using namespace std; double p[22], eps = 1e-4; double ans[(1 << 21)], x, a[22]; int main() { int n, k, i, j, y = 0; scanf("%d%d", &n, &k); for (i = 0; i < n; i++) { scanf("%lf", &p[i]); if (p[i] < eps) y++; } ans[0] = 1; k = min(k, n - y); for (i = 0; i < (1 << n); i++) { ...
8
#include <bits/stdc++.h> using namespace std; const int MaxN = 150005; const int MaxS = MaxN * 4; struct Seg { int l, r; long long maxl, maxr, maxs, s; Seg operator+(const Seg& other) const { Seg ret; ret.l = l; ret.r = other.r; ret.maxl = max(maxl, s + other.maxl); ret.maxr = max(other.maxr, ...
7
#include <bits/stdc++.h> int main() { unsigned short length; char line[101]; unsigned short count[101]; unsigned short i, j; unsigned short blacks = 0; char current; scanf("%hu", &length); scanf("%c", &current); for (i = 0; i < length; i++) { scanf("%c", &current); if (current == 'B') { ...
0
#include <bits/stdc++.h> using namespace std; long long l, r, f[30]; long long cal(long long r) { int l, s[30]; if (r == 0) return 0; for (l = 0; r != 0; r /= 10) s[++l] = r % 10; if (l == 1) return s[1]; long long ans = 9, p = 0; for (int i = 2; i < l; i++) ans += 9 * f[i - 2]; if (l == 2) { if (s[1]...
3
#include<iostream> #include<cstdio> #include<cstring> #include<vector> using namespace std; const int N=2e5+500; int to[N<<1],fst[N],nxt[N<<1],n,mm; void ade(int u,int v){to[++mm]=v,nxt[mm]=fst[u],fst[u]=mm;} struct HLD { int dep[N],fa[N],tp[N],dfn[N],nid[N],dfs_cnt,son[N],size[N]; void dfs1(int u,int Fa) { fa[u]=...
13
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; pair<double, int> c[10010]; int n; struct point { double x, y; } p[600][5]; int dblcmp(double x) { if (fabs(x) < eps) return 0; return x > 0 ? 1 : -1; } double cross(point p1, point p2, point p3) { return (p2.x - p1.x) * (p3.y - p1.y) - (p2...
9
#include<bits/stdc++.h> using namespace std; const int N=2e5+5; map<int,int> mp; int a[N]; int main(){ int T; scanf("%d",&T); while(T--){ int n,tt=-1,t; scanf("%d",&n); mp.clear(); for(int i=1;i<=n;++i){ scanf("%d",&a[i]); } int l=1,r=n; while(a[l]==a[l+1]&&l<r) ++l; while(a[r]==a[r-1]&&r>l) --r...
2
#include <bits/stdc++.h> using namespace std; int n, a[1010], ans, x[300010]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) x[a[i] + a[j]]++; for (int i = 0; i < 300000; i++) ans = max(ans, x[i]); cout << ans << endl; return 0...
2
#include <bits/stdc++.h> using namespace std; int n, m, q; string s[555]; int U[555][555], D[555][555], L[555][555], R[555][555]; int a[555][555]; int dp1[555][555]; int dp2[555][555]; vector<int> rr[555]; vector<int> cc[555]; int cut(int len) { if (len < 2) return 0; else return (len - 1); } int main() { ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int a[n], b, rez[n]; for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < n; i++) { scanf("%d", &b); rez[(a[i] - 1)] = b; } for (int i = 0; i < n - 1; i++) { printf("%d ", rez[i]); } printf("%...
2
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int N = 2e5 + 1; const long long mod = 1e9 + 7; int arr[32][N], tree[32][4 * N]; void build(int ss, int se, int si, int k) { if (ss == se) { for (int mask = 0; mask < (1 << k); mask++) { tree[mask][si] = arr[mask][ss]; } } else {...
7
#include <bits/stdc++.h> inline long long read() { char c; long long x; for (c = getchar(); !isdigit(c); c = getchar()) ; for (x = 0; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } return x; } int T, n; long long k, sum; std::vector<std::pair<int, int>> e; std::vector<int> ans; bool check() { ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m; while (cin >> n >> m) { bool flag = 0; int sum = 0; int min = 0; int max = 0; int temp = 0; int arr[1000]; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] > m || arr[i] < -m) { flag = 1; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[2 * n + 2]; for (int i = 1; i <= 2 * n + 1; i++) { cin >> a[i]; } for (int i = 1; i <= 2 * n + 1; i++) { if (k && i % 2 == 0) { if (a[i - 1] < a[i] - 1 && a[i] - 1 > a[i + 1]) { a[i]--; k-...
1
#include <bits/stdc++.h> using namespace std; int a[8]; int main() { int test, d; cin >> test; while (test--) { cin >> d; int s = 0; for (int i = 1; i <= 7; ++i) { cin >> a[i]; s += a[i]; } int ans = (d - 1) / s * 7, res = 2e9 + 5; d = (d - 1) % s; ++d; for (int i = 1; ...
3
#include <bits/stdc++.h> using namespace std; int a[] = {0, 4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346, 355, 378, 382, 391, 438, 454, 483, 517, 526, 535, 562, 576, 588, 627, 634, 636, 645, 648, 654, 663, 666, 690, 706, 728, 729, 762, 778, 825, 852, 861, ...
4
#include <bits/stdc++.h> using namespace std; void DFS(int v, vector<vector<int> >& adj, vector<bool>& used) { used[v] = true; for (int i = 0; i < (int)adj[v].size(); ++i) { int u = adj[v][i]; if (!used[u]) { DFS(u, adj, used); } } } class Segment { public: int x; int y; Segment() {} Se...
3
#include <bits/stdc++.h> using namespace std; const double g = 10.0, eps = 1e-7; const int N = 200000 + 10, maxn = 60000 + 10, inf = 0x3f3f3f; int l[N], r[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> v1, v2; for (int i = 1; i <= n; i++) { cin >> l[i] >> r[i]; ...
3
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); long long n, f = 0; cin >> n; while (n--) { string s; long long a, b; cin >> s >> a >> b; if (a >= 2400 && b > a) f = 1; } if (f == 1) cout << "Yes"; else cout << "No"; return 0; }
0
#include <bits/stdc++.h> using namespace std; struct matching { int n, m; vector<int> pa; vector<int> pb; vector<vector<int>> g; vector<int> q; vector<int> was; matching(int n, int m) : n(n), m(m) { pa.resize(n, -1); pb.resize(m, -1); g.resize(n); q.resize(n + 1); was.resize(n); } ...
5
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { int n, x, y; cin >> n >> x >> y; if (x * 100 >= y * n) { cout << 0; } else { cout << (y * n - x * 100 + 99) / 100; } return 0; }
0
#include <bits/stdc++.h> using namespace std; void solve() { int n, x; cin >> n; vector<vector<int>> v(n + 1); for (int i = 0; i < n; ++i) { for (int j = 0; j < 5; ++j) { cin >> x; v[i].push_back(x); } } int cnt = 0, pos = 0, c = 1; for (int i = 1; i < n; ++i) { cnt = 0; for (i...
3
#include <bits/stdc++.h> #ifndef ONLINE_JUDGE #define debug(x) cout << #x << ": " << (x) << endl #else #define debug(x) #endif using namespace std; typedef long long ll; typedef vector<int> vi; const int maxn=1e6+7,inf=0x3f3f3f3f,mod=1e9+7; int main() { ios::sync_with_stdio(false); cin.tie(0); int kase; ...
8
#include <bits/stdc++.h> using namespace std; const long long N = 200022; int n, ans; string s; int a[10]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { cin >> s; for (int i = 0; i < s.size(); i++) a[i] += s[i] - '0'; } for (int i = 0; i < 10; i++) ans = max(ans, a[i]); cout << ans; }
0
#include <bits/stdc++.h> using namespace std; int n, a, b, arr[2003]; int main(void) { cin >> n >> a >> b; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); cout << arr[b] - arr[b - 1] << endl; }
0
#include <bits/stdc++.h> using namespace std; struct point { long long x; long long y; point(long long _x = 0, long long _y = 0) : x(_x), y(_y) {} point operator+(point rhs) const { return point(x + rhs.x, y + rhs.y); } point operator-(point rhs) const { return point(x - rhs.x, y - rhs.y); } long long opera...
10
#include <bits/stdc++.h> using namespace std; using i64 = long long int; using ii = pair<int, int>; using ii64 = pair<i64, i64>; vector<int> edge[100005]; vector<int> oneWay[100005]; int deg[100005]; int deg2[100005]; bool used[100005]; i64 n, m; bool visit[100005]; void dfs(int root) { visit[root] = true; for (aut...
5
#include <bits/stdc++.h> using namespace std; long long fexp(long long b, long long e, long long m) { long long ans = 1; while (e) { if (e % 2 == 1) ans = (ans * b) % m; b = (b * b) % m; e /= 2; } return ans; } int main() { long long n; cin >> n; if (!n) cout << 1 << endl; else cout ...
2
#include <bits/stdc++.h> using namespace std; struct Dominator { struct min_DSU { int N; vector<int> par, val; vector<int> const &semi; min_DSU(int _N, vector<int> const &semidom) : N(_N), par(N, -1), val(N), semi(semidom) { iota(val.begin(), val.end(), 0); } void comp(int x) { ...
10
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int t, n, m, tot, cnt; struct node { int per, to; } e[1000010 << 1]; int head[1000010]; bool tag[1000010], vis[1000010]; int id[1000010], dis[1000010], f[1000010]; void init() { tot = 0, cnt = 0; for (int i = 1; i <= n; ++i) { head[i...
9
#include <bits/stdc++.h> using namespace std; int n; int nums[2000000]; int main() { cin >> n; for (int i = 0; i < n; ++i) nums[i] = i + 1; int start = 0; for (int i = 2; i <= n; ++i) { int pos = start; int temp = nums[pos]; ++start; while (true) { pos += i; if (pos - start >= n - 1)...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; const int inf = (1 << 30) - 1; const ll INF = (1LL << 60) - 1; template <typename T> bool chmax(T &x, const T &y) { ...
3
#include <bits/stdc++.h> using namespace std; long long int vis[1000000]; int main() { long long int h, n; cin >> h >> n; long long int rem = pow(2, h); long long int ans = 0; long long int sto = 0; long long int flag = 0; while (rem > 1) { ans++; if (flag == 0) { if (n > rem / 2 + sto) { ...
4
#include <bits/stdc++.h> int b[110], vis[110]; int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int main(void) { int n, i, cur, k, pile; while (scanf("%d%*c", &n) != EOF) { for (i = 0; i < n; i++) scanf("%d", &b[i]); qsort(b, n, 4, cmp); memset(vis, 0, sizeof(vis)); k = 0; ...
3
#include <bits/stdc++.h> using namespace std; void solve(); int main() { int t = 1; while (t--) { solve(); } return 0; } namespace input { inline int nextInt() { int res = 0; char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') res = res * 10 + c - '0', c = getc...
3
#include <bits/stdc++.h> using namespace std; inline int read() { int a = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) { a = (a << 3) + (a << 1) + (c ^ '0'); c = getchar(); } return a; } const int MAXN = 300010; struct point { int a, b, ind; } now[MAXN]; int nxt[MAX...
9
#include <bits/stdc++.h> template <typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First& first, Rest&... rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } template <typename T> void MACRO_VEC_ROW_Init(int n, T& t) { t.resize(n); } tem...
5
#include <bits/stdc++.h> using namespace std; int main() { int T, x, y, k; int cost = 0; int n, a, b; cin >> n >> a >> b; int c[n]; for (int i = 0; i < n; i++) { cin >> c[i]; } int i, j; for (i = 0, j = n - 1; i < j; i++, j--) { if (c[i] == c[j]) { if (c[i] == 2) { cost += (2 * m...
1
#include <bits/stdc++.h> using namespace std; int pp[1000][1000]; int main() { int n, k, i, j; while (cin >> n >> k) { memset(pp, 0, sizeof(pp)); for (i = 1; i <= n; i++) pp[i][i] = 1; if (n * (n - 1) / 2 < k * n) { cout << -1 << endl; continue; } cout << n * k << endl; for (i = ...
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g = 10.0, eps = 1e-9; const int N = 100000 + 10, maxn = 300, inf = 0x3f3f3f; int a[N]; int d[maxn + 10][N]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n; for (int i = ...
6
#include <bits/stdc++.h> using namespace std; long long int ok = 1000 * 1000 * 1000 + 7; map<long long int, long long int> m; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long int n, k; cin >> n >> k; vector<long long int> v; for (long long int i = 0; i < n; i++) { l...
1
#include <bits/stdc++.h> int a[100000]; int b[100000]; int main() { long long m, n; scanf("%lld%lld", &m, &n); for (int i = 0; i < m; i++) scanf("%d", &a[i]); for (int i = 0; i < m; i++) scanf("%d", &b[i]); long long left = 0, right = 2000000000, ans = 0; while (left <= right) { long long t = n; lon...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 5e4 + 10; int book1[500]; int book2[500]; int main() { int t; cin >> t; while (t--) { string s, t, p; cin >> s >> t >> p; int s1 = s.size(); int t1 = t.size(); int p1 = p.size(); int j = 0; int flag = 1; for (int i = 0;...
2
#include <bits/stdc++.h> using namespace std; static const int MAXN = 1e5 + 10; int a[MAXN]; int n, k; long long sum, tmp, ans; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); sum += a[i]; } if (sum % 3) puts("0"); else { sum /= 3; for (int i = 0; i < n - 1;...
2
#include <bits/stdc++.h> using namespace std; int x, y, s; int main() { cin >> x >> y; s = x * x + y * y; for (int i = 10000; i >= 0; --i) if (i * i <= s) { if (0) { cout << "i" << ": " << i << endl; }; if (i * i == s) { puts("black"); } else if (i % 2 == 0...
2
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void avneetsng() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int32_t main() { avneetsng(); long long t; cin >> t; while (t--) { string s; cin >> s; long long n = s....
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; using cd = complex<double>; const double PI = acos(-1); const int N = 1e5 + 10; ll dp[N], sum[N]; ll OO = 3e18; ll calc (int n, int mx){ if(dp[n - 1] == OO) return OO; return sum[n - 1] - sum[n - mx - 1]; } void solve(){ int n; ll k...
5
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; inline long long read() { long long t = 0, dp = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') dp = -1; ...
9
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxm = 5e3 + 10; const int inf = 0x3f3f3f3f; namespace io { const int SIZE = (1 << 21) + 1; char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr; inline void fl...
8
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } vector<long long> p; int main() { long long x, y; scanf("%lld%lld", &x, &y); long long t = x; for (long long i = 2; i * i <= t; i++) if (t % i == 0) { p.push_back(i); while (t...
6
#include <bits/stdc++.h> using namespace std; template <typename... Args> void read(Args &...args) { ((cin >> args), ...); } template <typename... Args> void show(Args... args) { ((cout << args << " "), ...); } void solve() { int64_t n, k; read(n, k); vector<int> v(k); iota(v.begin(), v.end(), 1); int add...
5
#include <bits/stdc++.h> using namespace std; int n, x, y; int main() { while (scanf("%d%d%d", &n, &x, &y) == 3) { int a = max(0, n * y - 100 * x), b = 100; printf("%d\n", a % b ? a / b + 1 : a / b); } return 0; }
0
#include <bits/stdc++.h> template <typename T> void read(T& num) { num = 0; int w = 1; char ch = getchar(); if (ch == '-') w = -1; while (ch < '0' || ch > '9') { ch = getchar(); if (ch == '-') w = -1; } while ((ch >= '0' && ch <= '9')) num = num * 10 + ch - '0', ch = getchar(); num = num * w; } ...
9
#include <bits/stdc++.h> using namespace std; template <typename T> void chkmax(T &x, T y) { x = x > y ? x : y; } template <typename T> void chkmin(T &x, T y) { x = x > y ? y : x; } template <typename T> void update(T &x, T y, T mod) { x = x + y > mod ? x + y - mod : x + y; } const int INF = (1ll << 30); template...
7
#include <bits/stdc++.h> using namespace std; int a[30][30]; int sum[30][2]; int main() { int n; cin >> n; int ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { cin >> a[i][j]; sum[j][1] += a[i][j]; sum[i][0] += a[i][j]; } for (int i = 0; i < n; i++) for (int j =...
0
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const int mod = 1e9 + 7; const int maxn = 1010; int n, d, h; int main() { while (cin >> n >> d >> h) { if (d < h || d > 2 * h) { puts("-1"); } else if (d == 1 && h == 1 && n > 2) { puts("-1"); } ...
4
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2>& p) { out << p.first << ' ' << p.second; } template <class T> istream& operator>>(istream& in, vector<T>& v) { for (auto& x : v) in >> x; return in; } template <class T> ostream& operator<<(o...
5
#include <bits/stdc++.h> using namespace std; template <class T> void chkmin(T &a, T b) { if (b < a) a = b; } template <class T> void chkmax(T &a, T b) { if (a < b) a = b; } int n; int sz[100005]; int sum[100005]; vector<pair<int, int> > con[100005]; long long dfs(int u, int p) { int i, v, w; long long rlt = 0;...
7
#include <bits/stdc++.h> using namespace std; int main() { queue<pair<int, int> > bfs; queue<int> cekori; pair<int, int> start, kraj; map<pair<int, int>, int> mapa; map<pair<int, int>, int>::iterator it; int n, i, j, one, two, three; cin >> start.first >> start.second >> kraj.first >> kraj.second; cin >...
5
#include <bits/stdc++.h> using namespace std; pair<long long, long long> m[150]; bool f(pair<long long, long long> a, pair<long long, long long> b) { if (b.second > a.second) return 1; return 0; } int main() { int n; long long a, b, c, k = 0, i = 0; cin >> n; for (a = 0; a < n; a++) { cin >> m[a].first;...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 1; double p[MAXN][MAXN]; double E[MAXN]; double A[MAXN], B[MAXN]; bool vis[MAXN]; int n; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf("%lf", &p[i][j]); } } for (int i = 0; i < MA...
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> bad; int ar[n]; for (int i = 0; i < n; i++) { cin >> ar[i]; } for (int i = 1; i < n - 1; i++) { if ((ar[i - 1] <= ar[i] && ar[i] <= ar[i + 1]) || ...
2
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; for (int t = 1; t <= q; t++) { int n; cin >> n; long long a[n]; for (int i = 0; i < n; i++) cin >> a[i]; long long c = 1; for (int i = 0; i < n - 1; i++) { if (a[i] != a[i + 1]) { c = 0; break...
2
#include <bits/stdc++.h> using namespace std; char field[1005][1005]; char test[1005][1005]; char f[1005][1005]; int n, m; int dx[4] = {1, 1, 1, 0}, dy[4] = {-1, 0, 1, 1}; set<char> s[2]; bool check() { for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) for (int k = 0; k < 4; ++k) { if (tes...
8
#include <bits/stdc++.h> void Get(int &T) { char C; bool F = 0; for (; C = getchar(), C < '0' || C > '9';) if (C == '-') F = 1; for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0') ; F && (T = -T); } void Get(long long &T) { char C; bool F = 0; for (; C = getchar(), C < '...
7
#include <bits/stdc++.h> using namespace std; long d[100001]; void calc(int k) { d[0] = 1; for (int i = 1; i < 100001; i++) { d[i] += d[i - 1]; if (i >= k) { d[i] = (d[i] + d[i - k]) % 1000000007; } } for (int i = 2; i < 100001; i++) { d[i] = (d[i] + d[i - 1]) % 1000000007; } } int main(...
4
#include <bits/stdc++.h> using namespace std; using vll = vector<long long>; long long mod = 1000000007; void solve() { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; map<long long, vll> cnt; for (long long i = 0; i < n; i++) { cnt[i + 1 - a[i]].push_back(a[i]); ...
3
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } long long dx[4] = {0, 0...
11
#include <bits/stdc++.h> using namespace std; int n, k, x[100010], y; inline double sqr(double x) { return x * x; } inline double dist(int k, int l, int r) { double ret = sqrt(sqr(y) + sqr(x[n] - x[k])); if (l <= r) ret += min(dist(l, 1, 0), dist(r, 1, 0)) + x[r] - x[l]; return ret; } int main() { scanf("%d%d",...
9
#include <bits/stdc++.h> using namespace std; std::vector<int> numbers; int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; int mask[60]; int best[101][(1 << 16)]; int last[101][(1 << 16)]; int main(int argc, const char* argv[]) { int N; cin >> N; numbers.resize(N); for (int k = 2; k < ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; int tot = 0, cnt = 0; for (auto x : s) { if (x == ')') tot--; if (x == '(') tot++; if (x == '?') cnt++; } if (abs(cnt) % 2 != abs(tot) % 2 |...
4
#include <bits/stdc++.h> using namespace std; struct node { int F[4]; }; set<node> Set, Set2; bool operator<(node A, node B) { int j = 0; while (A.F[j] == B.F[j] && j + 1 < 4) j++; return (A.F[j] < B.F[j]); } set<node>::iterator it; node T; string s[4] = {"Gryffindor", "Hufflepuff", "Ravenclaw", "Slytherin"}; s...
7
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const double Pi = 3.1415926535897932; const int dir[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1}; int main() { int n, a, b; cin >> n >> a >> b; b *= 5; int ans = n; for (int i = 0; i <= n; i += a) { int now = (n - i) % b; ans = min(ans, now...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int i = 1; while (pow(n, i) < m) { i++; } if (pow(n, i) == m) cout << "YES\n" << i - 1; else cout << "NO"; return 0; }
1
#include <bits/stdc++.h> using namespace std; int ans[110][110] = {0}; vector<int> adj[110][110]; int vis[110]; void dfs(int parent, int u, int color) { vis[u] = 1; ans[parent][u]++; for (int v = 0; v < (int)adj[u][color].size(); v++) { if (!vis[adj[u][color][v]]) { dfs(parent, adj[u][color][v], color);...
3