solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int t, a, b; string s; inline int read() { int w = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); while (ch <= '9' && ch >= '0') { w = (w << 3) + (w << 1) + (ch ^ 48); ch = getchar(); } return w; } int main() { t = read(); while...
5
#include <bits/stdc++.h> using namespace std; ; int main() { int n; cin >> n; int ans = 0; for (int i = 2; i < n; i++) { ans += i * (i + 1); } cout << ans << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; std::vector<pair<long long int, long long int> > g[100005]; std::vector<long long int> tim[100005]; long long int dis[100005]; void bfs(int n) { dis[n] = 0; priority_queue<pair<long long int, long long int>, vector<pair<long long int, long long int> >, ...
9
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; vector<vector<long long>> a; vector<vector<long long>> b; vector<vector<long long>> c; void multi() { int n = a.size(); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { c[i][j] = 0; for (int k = 0; k < n; k++) { ...
16
#include <bits/stdc++.h> using namespace std; const long long N = 1e5; vector<int> v; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n, sum = 0, arr[N]; cin >> n; for (int i = 1; i <= (n); i++) if (i * (i + 1) / 2 == n) { cout << "YES" << endl; return 0; } cout ...
0
#include <bits/stdc++.h> using namespace std; long long n, k, mv; string query(long long l, long long r) { assert(mv < 4400); ++mv; string res; cout << l << ' ' << r << '\n'; fflush(stdout); cin >> res; return res; } void f(long long l, long long r) { if ((r - l + 1) < 100) { long long x = (rand() %...
13
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int MOD = 1e9 + 7; long long pow(long long a, long long b, long long m) { long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; } int main() { ios::sync_with_stdio(0); cin.t...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<string> data; for (int i = 0; i != n; ++i) { string x; cin >> x; data.push_back(x); } int count{0}; for (int i = 0; i < m; ++i) { string x; cin >> x; for (string j : data) { if (j == x)...
3
#include <bits/stdc++.h> using namespace std; int main() { int v[1005]; int n, i, j, stc1, drc1, stc2, drc2; cin >> n; bool rasp = 0; for (i = 1; i <= n; i++) cin >> v[i]; for (i = 2; ((i <= n) && (!rasp)); i++) for (j = i + 1; j <= n; j++) { stc1 = v[i - 1]; drc1 = v[i]; stc2 = v[j - ...
6
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v[1000055]; int X[4] = {0, 0, 1, -1}; int Y[4] = {1, -1, 0, 0}; short dis[45][1000055]; int main() { int n, m, k; scanf("%d %d %d", &n, &m, &k); int a[1005][1005]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { scanf("%d"...
18
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int matX = 10; const int mod = 1e9 + 7; struct Matrix { long long n, m, s[matX][matX]; Matrix(int n, int m) : n(n), m(m) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) s[i][j] = 0; } } Matrix operator*(const ...
13
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; void __never(int a) { printf("\nOPS %d", a); } void __die(int a) { printf("%d", (a * a) / (a + a)); } int n; vector<int> graf[100500]; long long dp1[100500]; long long ans1, ans2; long long f(long long a) { return (a * (a - 1)) >> ...
16
#include <bits/stdc++.h> using namespace std; int p[500005]; vector<int> v[500005]; int ans[500005]; int main() { int n, pos; scanf("%d", &n); p[1] = 1; v[1].push_back(1); for (int i = 2; i <= n; i++) for (int j = i; j <= n; j += i) if (!p[j]) { p[j] = i; v[i].push_back(j); } ...
14
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b, long long int m) { long long int ans = 1; while (b) { if (b & 1) { ans = ((ans % m) * (a % m)) % m; } a = ((a % m) * (a % m)) % m; b = b >> 1; } return ans; } long long int powe(long long in...
10
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:255000000") bool firstout = 1; template <class T> T &minn(T &a, T b) { if (b < a) a = b; return a; } template <class T> T &maxx(T &a, T b) { if (a < b) a = b; return a; } int &madd(int &a, int b) { a += b; if (a >= 1000000007) a -...
23
#include <bits/stdc++.h> char s[150010], t[150010]; int p[150010]; void solve() { scanf("%s", s); int l; for (l = 0; s[l]; l++) ; int c = 0; for (int i = 0; i < l - 4; i++) { if (s[i] == 't' && s[i + 1] == 'w' && s[i + 2] == 'o' && s[i + 3] == 'n' && s[i + 4] == 'e') { s[i + 2] = 0; ...
6
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 30); const int mod = 1e9 + 7; int n, longest; long long dp[1003]; int a[26]; string s; long long solve(int curr, int maxx) { long long &ret = dp[curr]; if (ret == -1) { if (curr == 0) { ret = 1; } else { long long tmp = 0; ...
9
#include <bits/stdc++.h> const int N = 100010; const int K = 14; const int M = 1 << 4; const long long MOD = 1e9 + 7; using namespace std; int n, m, k; int t[N]; long long f[N][K][M], ans = 0; void read(int &x) { char c = getchar(); int flg = 0; x = 0; for (; c > '9' || c < '0'; c = getchar()) flg |= (c == '-')...
20
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 9, INF = 1e18; long long a[N], seg[N], lazy[N], f[N]; stack<long long> mn, mx; unordered_map<long long, long long> mp; void FLUSH(long long pos, long long l, long long r) { seg[pos] += lazy[pos]; if (l != r) { lazy[pos * 2] += lazy[pos]; ...
23
#include <bits/stdc++.h> using namespace std; namespace AC { const long long N = 1e5 + 66; long long BUGS = 1; inline long long read() { long long x = 0; bool flag = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') flag = 0; ch = getchar(); } while (ch >= '0' && ch <= '9') { ...
3
#include <bits/stdc++.h> using namespace std; int n, m, idx; vector<int> g[100010]; vector<int> r[100010]; int gift[100010]; int O[100010]; int d[100010]; bool v[100010]; int dep[100010]; void dfs(int node, int depth) { v[node] = true; d[node] = depth; for (int i = 0; i < (int)g[node].size(); i++) { int next ...
12
#include <bits/stdc++.h> using namespace std; int tr[70005], n, m, t, X, dis[55][55], a[105], b[105], c[105]; double f[55][40005], p[105][20005], g[105][40005]; void GetTr(int l) { for (int i = 0; i < l; i++) tr[i] = (tr[i >> 1] >> 1) | ((i & 1) ? (l >> 1) : 0); } complex<double> ta[70005], wk[70005], tb[70005]; ...
24
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n + 1); for (int i = 1; i <= n; i++) { cin >> v[i]; } long long ans, cost = 10e17; for (int i = 1; i <= n; i++) { long long x, y; x = v[i] - 1; y = 0; for (int j = 1; j <= n; j++) { if (v[j]...
3
#include <bits/stdc++.h> using namespace std; int n, k; int a[1000005]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } int ans = 0, x, y; ans = a[n]; x = n - k; y = n - k + 1; for (int i = x; i >= 0; i--) { ans = max(ans, a[x--] + a[y++]); } cout << ans << endl; ...
6
#include <bits/stdc++.h> using namespace std; const long long L = 1000000; char LZH[L]; char *SSS, *TTT; inline char gc() { if (SSS == TTT) TTT = (SSS = LZH) + fread(LZH, 1, L, stdin); return *SSS++; } inline long long read() { long long x = 0, f = 1; char c = getchar(); for (; c < '0' || c > '9'; c = getchar...
16
#include <bits/stdc++.h> using namespace std; long long l[300069], r[300069]; int n, m, o[100069]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; if (n == 1) { cout << 0 << endl; return 0; } for (int i = 0; i < m; i++) { cin >> o[i]; o[i]--; } revers...
17
#include <bits/stdc++.h> using namespace std; inline int read() { int s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar(); return s * w; } long long a[1000003]; map<long long, ...
15
#include <bits/stdc++.h> using namespace std; 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 (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } vector<long long int> prime; ...
0
#include <bits/stdc++.h> using namespace std; long long int arr[300009], brr[300009]; std::vector<long long int> v[300009]; int main() { int test_case = 1; for (int cs = 1; cs <= test_case; cs++) { long long int n; scanf("%lld", &n); string cc; cin >> cc; int ans = 0; while (1) { int m...
8
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; inline bool equals(long double a, long double b) { return fabs(a - b) < 1e-9; } inline long long gcd(long long a, long long b) { a = abs(a); b = abs(b); while (a > 0 && b > 0) (a > b ? a %= b : b %= a)...
8
#include <bits/stdc++.h> using namespace std; int main() { int n1, n2, k1, k2, r1, r2; cin >> n1 >> n2 >> k1 >> k2; r1 = n1 % k1; r2 = n2 % k2; if (n1 > n2) cout << "First" << endl; else if (n2 > n1) cout << "Second" << endl; else cout << "Second" << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int trie[2100000], cnt[100]; void add_trie(int x) { int nod = 1, p = 0; for (int bit = 19; bit >= 0; bit--) nod = nod * 2 + ((x & (1 << bit)) > 0); if (trie[nod] == 0) { nod = 1; for (int bit = 19; bit >= 0; bit--) if (x & (1 << bit)) { nod = nod...
12
#include <bits/stdc++.h> using namespace std; const long long N = 501, K = 11; long long n, k; long long c[N * K]; long long f[N]; long long h[K]; map<long long, long long> num; map<long long, long long> rs; long long ans = 0; long long dp[N * K][N]; long long read() { long long x = 0; char c = getchar(); while (...
12
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char ch = getchar(); while (ch - '0' < 0 || ch - '0' > 9) { if (ch == '-') f = -1; ch = getchar(); } while (ch - '0' >= 0 && ch - '0' <= 9) { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int n, m, M, s...
24
#include <bits/stdc++.h> using namespace std; const int N = 2e5; int par[20][N + 1], lvl[N + 1], val[N + 1]; int arr[N + 1]; long long dist[N + 1]; vector<pair<int, int> > adj[N + 1]; void dfs(int s, int p) { par[0][s] = p; for (auto nbr : adj[s]) { if (nbr.first != p) { lvl[nbr.first] = lvl[s] + 1; ...
11
#include <bits/stdc++.h> using namespace std; int Pow(int a, int b, int md, int ret = 1) { for (; b; b >>= 1, a = 1ll * a * a % md) if (b & 1) ret = 1ll * ret * a % md; return ret; } const int N = 1e6 + 10; int F[10][N], c[10], P[N], A[N], pw[10][N], mod, n, q, ptr; struct node { node *lc, *rc; long long in...
19
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7, M = 1111111; char ch[24][N]; int n, m, a[N]; long long A[M], B[M], C[M], ans; void fwt(long long* a, int len, bool g) { for (int i = 1; i < len; i <<= 1) for (int j = 0; j < len; j += i * 2) for (int k = 0; k < i; k++) { long long ...
18
#include <bits/stdc++.h> #define endl '\n' using namespace std; typedef long long lld; int n, m, k; lld dp[20][500][500], cost1[500][500], cost2[500][500]; lld combine(int cnt, int r, int c){ if(r<0 || r>=n || c<0 || c>=m)return 1e18; if(cnt==0)return 0; if(dp[cnt][r][c]!=0)return dp[cnt][r][c]; lld...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long l, r, d, u, x, y, x1, x2, y1, y2; cin >> l >> r >> d >> u; cin >> x >> y >> x1 >> y1 >> x2 >> y2; if ((x == x1 && r < l) || (x == x2 && r > l) ||...
3
#include <bits/stdc++.h> using namespace std; const int N = 2001, M = 1e9 + 7; char a[N], b[N]; int m, d, n, dp[N][N][2][2]; int calc(int at, int mod, bool A, bool B) { if (at == n) return mod == 0 && A && B; int &res = dp[at][mod][A][B]; if (res != -1) return res; res = 0; if (at & 1) { if ((A || d >= (a...
14
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const int SINF = 0x7fffffff; const long long LINF = 0x3fffffffffffffff; const long long SLINF = 0x7fffffffffffffff; const int MAXN = 100007; struct eT { void setd(int _u, int _v, int _w, int _l) { u = _u, v = _v, w = _w, last = _l; } in...
19
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } long long powmod(long long a, long long b, long long MOD) { long long ans = 1; while (b) { if (b % 2) ans = ans * a % MOD;...
10
#include <bits/stdc++.h> using namespace std; int n, a[3] = {}, b[20000000] = {}, minn, ans = 0; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) { cin >> b[i]; a[b[i]]++; } minn = min(a[1], a[2]); for (int i = 1; i <= n; i++) if (b[i] == 1) ans++; ans -= minn; ...
0
#include <bits/stdc++.h> using namespace std; const int MAX_V = 10010; int main() { int a, b; cin >> a >> b; int dif = abs(a - b); int ans = 0; int t = dif / 2; for (int i = 1; i <= t; i++) { ans += i * 2; } dif -= t * 2; if (dif & 1) ans += t + 1; cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int maxnb = (int)1e9 + 7; const double pi = acos(-1.0); const int maxnl = 100500; const double eps = 1e-9; string s1, s2; string sm(string s) { if (s.length() % 2 == 1) return s; string s1 = sm(s.substr(0, s.size() / 2)); string s2 = sm(s.substr(s.size() / 2, s....
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; int codd = 0; int ceven = 0; int ways = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] & 1) codd++; else ceven++; } if (codd % 2 == 0) ways = ceven; else { ways = codd;...
1
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } int main() { int n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); if (a[0] == a[1] && a[0] == 0)...
10
#include <bits/stdc++.h> using namespace std; using cat = long long; int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int N, K; cin >> N >> K; if (K == 1) { cout << "3\n"; return 0; } K += 2; vector<pair<int, int> > phi(N); for (int i = 0; i < N; i++) phi[i...
20
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 1e2; struct node { int id, v; bool operator<(const node &b) const { return v > b.v; } }; priority_queue<node> q; int ans[maxn], cnt = 0; node a[maxn]; bool cmp(node a, node b) { return a.v < b.v; } int getint() { char ch; int b = 1; for (ch ...
8
#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tc; cin>>tc; while(tc--){ int n,k; cin>>n>>k; if(k==0){ for(int i=1;i<=n;i++){ cout<<i<<" "; ...
0
#include <bits/stdc++.h> using namespace std; const int MAX_N = 101000; pair<long long, long long> prs[MAX_N]; long long n, tmpx, tmpy, q[MAX_N], tot; bool check(int a, int b, int c) { long long x1 = prs[b].first - prs[a].first, y1 = prs[b].second - prs[a].second; long long x2 = prs[c].first - prs[b].fi...
16
#include <bits/stdc++.h> using namespace std; long long int INF = 1e18, n, m, k, p[100100], sum, a[300100], b[300100], c[300100], d[100100], f[10], s, x, y, z, mx = -INF, mn = INF, ans, dlans[110], ind; bool marked[1010][1010]; double PI = 3.1415926535897932384626433832795; char ch[10][10], ...
4
#include <bits/stdc++.h> using namespace std; template <class T> inline void amin(T& a, const T& b) { if (a > b) a = b; } template <class T> inline void amax(T& a, const T& b) { if (a < b) a = b; } template <class T> inline void rv(vector<T>& v, int n) { vector<T>(n).swap(v); for (int i = 0; i < (n); i++) cin >...
8
#include <bits/stdc++.h> using namespace std; int a[100010], b[100010]; int main() { double n, x, y; cin >> n >> x >> y; double per = x / n * 100; y -= per; int ans = ceil(y / 100.0 * n); cout << max(ans, 0) << endl; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; --a[i]; } vector<int> k(m); for (int i = 0; i < m; ++i) { cin >> k[i]; } vector<...
10
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smax(T &a, const U &b) { if (a < b) a = b; } char gchar() { static char tbuf1[728], *tmp_st = tbuf1, *tmp_ed = tbuf1; if (tmp_st == tmp_ed) { int len = fread(tbuf1, 1, 728, stdin); if (len == 0) return -1; tmp_...
21
#include <bits/stdc++.h> using namespace std; int dp[1000004]; int mul(int N, int M) { if (M == 0) { return 0; } if (M == 1) { return N; } return ((mul(N, M / 2) * 2) % 1000000007 + (M & 1 ? N : 0)) % 1000000007; } int fact() { dp[1] = 1; for (int i = 2; i <= 1000000; ++i) { dp[i] = mul(dp[i -...
11
#include <bits/stdc++.h> using namespace std; const int M = 100010; int qs[M], qf[M], c[M], f[M], s[M], obr[M], pr[M], ls[M], kr, r[M], d[M], pj[M], was[M], v[M], nv[M]; int fin, mm, ans; void add(int x, int y, int z, int xx, int yy, int zz) { mm++; qs[mm] = x; qf[mm] = y; c[mm] = z; f[mm] = xx; s[mm] =...
14
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long double R, x, y, x2, y2; long double dis(long double x, long double y, long double a, long double b) { return sqrt((x - a) * (x - a) + (y - b) * (y - b)); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> R >> x >> y >> x2 >> ...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 1024; long long pb, ps, pc; long long nb, ns, nc; long long r; long long b = 0; long long s = 0; long long c = 0; bool verify(long long mi) { long long br = (mi * b) - nb; long long sr = (mi * s) - ns; long long cr = (mi * c) - nc; long long tt = 0;...
8
#include <bits/stdc++.h> using namespace std; int input[555555]; int n, i, m, j, answer = 0; int start, last; int main() { cin >> n; for (i = 0; i < n; i++) cin >> input[i]; for (i = 0; i < n; i++) { if (input[i + 1] != input[i]) { start = i; i++; while (input[i] != input[i + 1] && (i + 1) <...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); if (n % 2) cout << arr[n / 2]; else cout << arr[n / 2 - 1]; }
0
#include <bits/stdc++.h> using namespace std; const long long inf = (1LL << 50); int main(int argc, char const *argv[]) { int n; string s; cin >> n >> s; if (n > 26) cout << -1 << '\n'; else { set<char> ss; for (int i = 0; i < n; i++) ss.insert(s[i]); cout << (n - int(ss.size())) << '\n'; } ...
2
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 5143; const long long Linf = 1e18 + 5413; const double eps = 1e-15; const double pi = acos(-1); template <class T> inline void umax(T &a, T b) { if (a < b) a = b; } template <class T> inline void umin(T &a, T b) { if (a > b) a = b; } template <clas...
12
#include <bits/stdc++.h> using namespace std; struct bottle { int a, b; } p[101]; bool cmp(bottle x, bottle y) { return x.a < y.b; } int main() { int w[101]; int n, i, sum = 0; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d%d", &p[i].a, &p[i].b); sort(p + 1, p + 1 + n, cmp); memset(w, 0, sizeof(w)); ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (n == 1) { cout << 1 << endl; return 0; } int r = n - m; int l = m - 1; if (l >= r) printf("%d\n", m - 1); else if (l < r) printf("%d\n", m + 1); return 0; }
5
#include <bits/stdc++.h> using namespace std; int main() { string a1 = "What are you doing while sending \""; string a2 = "What are you doing at the end of the world? Are you busy? Will you save " "us?"; string a3 = "\"? Are you busy? Will you send \""; ios::sync_with_stdio(false); string second =...
9
#include <bits/stdc++.h> using namespace std; int n; int a[100010]; int main() { cin >> n; if (n % 4 > 1) { cout << -1; return 0; } for (int i = 1; i < n / 2; i += 2) { a[i] = i + 1; a[i + 1] = n - i + 1; a[n - i + 1] = n - i; a[n - i] = i; } if (n % 2 == 1) a[n / 2 + 1] = n / 2 + 1;...
6
#include <bits/stdc++.h> using namespace std; const int INF = 1e6 + 9; bool comp(pair<long long, long long> a, pair<long long, long long> b) { if (a.first < b.first) return true; if (a.first == b.first && a.second < b.second) return true; else return false; } vector<pair<long long, long long> > h; long lo...
9
#include <bits/stdc++.h> using namespace std; template <class _T> inline _T sqr(const _T &first) { return first * first; } template <class _T> inline string tostr(const _T &a) { ostringstream os(""); os << a; return os.str(); } const long double PI = 3.1415926535897932384626433832795L; const long double EPS = 1...
12
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(0); long long int n, m, r = 0, ans = 0; long long int s[1000100]; cin >> n >> m; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i < n; i++) { if (r > 0) { long long int b = m; b -= r; s[i] -=...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 9; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; void solve() { int n; cin >> n; int cnt = 1; for (int i = 1; i <= n; i++) { printf("%d ", ++cnt); } puts(""); } int main() { int t; cin >> t; while (t--) solve(); return 0; }...
0
#include <bits/stdc++.h> using namespace std; int cd, r; int a[1000000], kq[1000000]; void inp() { cin >> cd >> r; for (int i = 1; i <= cd; i++) { cin >> a[i]; } int need = 0, l; for (int i = 1; i <= cd; i++) { if (kq[i] == 1) continue; int l = -1; need++; for (int e = i; e >= max(i - r + ...
7
#include <bits/stdc++.h> using namespace std; int main() { long long n, l, r, ql, qr; cin >> n >> l >> r >> ql >> qr; long long w[n]; for (long long i = 0; i < n; i++) { cin >> w[i]; } long long ans1 = 0; for (long long i = 0; i <= ((n - 1) / 2); i++) ans1 += (w[i] * l); for (long long i = ((n - 1) ...
7
#include <bits/stdc++.h> using namespace std; void swap(long long int *a, long long int *b) { long long temp = *a; *a = *b; *b = temp; } unsigned long long mod_pow(unsigned long long b, unsigned long long p, unsigned long long mod) { unsigned long long s = 1; while (p) { if (p &...
4
#include <bits/stdc++.h> using namespace std; int n, x, y; long long cal1(int lim, long long len) { if (len <= lim) return 0; len -= lim; return len * len; } long long cal2(int lim1, int lim2, long long len) { len -= lim1 + lim2; if (len <= 0) return 0; return (1 + len) * len / 2; } long long check(long lon...
10
#include <bits/stdc++.h> using namespace std; int main() { int day, n, num[100], i; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &num[i]); } if (n == 1 && (num[n - 1] != 15 && num[n - 1] != 0)) printf("-1\n"); else if (n == 1 && num[n - 1] == 15) printf("DOWN\n"); else if (n == 1 && ...
3
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; long long n, k, a[N], b[N], ans; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; long long l = 0, r = 2e9; while (l < r) { priority_queue<pair<long long, long long>, ...
21
#include <bits/stdc++.h> using namespace std; long long a[500], g[500]; void solve() { int n; scanf("%d", &n); for (int i = (int)(1); i <= (int)(n); ++i) cin >> a[i]; bool ok = true; long long wr = 1000000000000000000LL; for (int i = (int)(2); i <= (int)(n); ++i) for (int j = (int)(i); j <= (int)(n); ++...
18
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int t[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cin >> t[i][j]; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (t[i][j] != 1) { bool yes = false; for (int s = 0;...
0
#include <bits/stdc++.h> using namespace std; long long mx[5], mi[5]; long long X[5][2], f[7], MX = 1e18; long long get(long long x, long long y) { if ((x < 0 && y < 0) || (x > 0 && y > 0)) { long long bo = 0; if (x % 2 && y % 2) bo = 1; if (x < 0 && y < 0) return x / 2 + y / 2 - bo; else ...
21
#include <bits/stdc++.h> #define range(i, n) for (int i = 0; i < (n); ++i) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define ar array using namespace std; typedef long long ll; typedef double ld; typedef unsigned long long ull; const ll INF = 2e18; const int INFi = 2e9 + 5; cons...
20
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0; cin >> n; vector<int> v; for (int i = 0; i < n; i++) { int a; cin >> a; v.push_back(a); } sort(v.rbegin(), v.rend()); int suma = 0; for (int i = 0; i < n; i++) { suma += v[i]; ans++; int sumb = 0; for ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, l; cin >> n >> l; long long a[n][2]; for (long long i = 0; i < n; i++) { long long x, y; cin >> x >> y; a[i][0] = x; a[i][1] = y; } long long ans[n]; memset(ans, 0, sizeof(ans)); long long i = 0, x, y; x = a[i][0];...
9
#include <map> #include <set> #include <ctime> #include <queue> #include <stack> #include <cmath> #include <vector> #include <bitset> #include <cstdio> #include <cctype> #include <string> #include <numeric> #include <cstring> #include <cassert> #include <climits> #include <cstdlib> #include <iostream> #include <algorit...
23
#include <bits/stdc++.h> using namespace std; const long mod = 1e9 + 7; long long min(long long a, long long b) { if (a < b) return a; return b; } long long max(long long a, long long b) { if (a > b) return a; return b; } void solve() { long long n, k, a, b; cin >> n; cin >> k; cin >> a; cin >> b; i...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); for (int i = 0; i < 8; i++) { long long b = 0, w = 0; string s; cin >> s; for (int i = 0; i < 8; i++) { if (s[i] == 'B') { ++b; } else { ++w; } if (s[...
2
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rnf(2106); const int N = 200005; int n; int a[N]; int b[N]; int q[N]; vector<pair<int, int> > g[N]; vector<int> gi[N]; bool c[N]; void solv() { scanf("%d", &n); for (int i = 1; i <= n; ++i) sca...
15
#include <bits/stdc++.h> using namespace std; long long rr[] = {0, 1, 1, 1, 0, -1, -1, -1}; long long cc[] = {1, 1, 0, -1, -1, -1, 0, 1}; const long long mod = 1e9 + 7; const long long N = 300050; long long n, m; vector<vector<long long> > a; void update_even_rows(long long x) { for (long long i = 0; i < n; i++) { ...
14
#include <bits/stdc++.h> using namespace std; mt19937 rand1(time(0)); long long randlr(long long l, long long r) { return rand1() % (r - l + 1) + l; } const long long mod1 = (1e9) + 7, mod2 = (1e9) + 9; const long long p1 = 100009, p2 = 100007; long long fpow(long long first, long long second, long long mod) { long l...
10
#include <bits/stdc++.h> using namespace std; int const MAX = 100004; int const OO = (1 << 28); char a[MAX], b[MAX]; int main() { scanf("%s%s", a, b); int a4 = 0, a7 = 0, L = strlen(a); for (int i = 0; i < L; ++i) { if (a[i] != b[i]) a4 += (a[i] == '4'), a7 += (a[i] == '7'); } int mn = min(a4, a7); int ...
4
#include <bits/stdc++.h> long long n, l, r, x, arr[100], cant = 0, may = 0, v1 = 10000000, v2, mark[20]; void recur(int pos, long long sum, int c) { if (pos == n) { if (c < 2) return; if (sum < l or sum > r) return; v1 = 10000000; v2 = 0; for (int i = 0; i < n; i++) { if (mark[i] != 0) { ...
6
#include <bits/stdc++.h> using namespace std; string s; int hal(int o, int q) { string temp = ""; char holder = ' '; while (o != 0) { holder = o % 2 + '0'; temp = holder + temp; o /= 2; } reverse(temp.begin(), temp.end()); while (temp.size() < 8) temp += "0"; reverse(temp.begin(), temp.end());...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, i, j, k, l, root; cin >> n; vector<int> vec[n + 5]; vector<int> del; int par[n + 5], chl[n + 5]; bool chhl[n + 1]; memset(chhl, false, sizeof(chhl)); for (i = 1; i <= n; i++) chl[i] = 1...
6
#include <bits/stdc++.h> typedef struct { int a; int b; int i; } scenario; scenario s[300000]; int w[300000]; long long a[300000]; long long sum[300000]; int cmp(const void *a, const void *b) { return ((scenario *)a)->b - ((scenario *)b)->b; } int main() { int n, p, i, j; scanf("%d", &n); for (i = 0; i < ...
13
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<int, int> data; while (n--) { int t; cin >> t; data[t]++; } int sum = 0; for (auto e : data) { sum += e.second / 2; } cout << sum / 2 << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main(int argc, char* argv[]) { int n, c; cin >> n >> c; int val; vector<int> x; for (int i = 0; i < n; ++i) { cin >> val; x.push_back(val); } int res = 0; for (int i = 0; i < x.size() - 1; ++i) { int cost = x[i]; if (cost < x[i + 1]) cont...
2
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 5 + 1e5; const long long INF = 2e18; const long double LINF = log2(4e18); long long POW[70][70]; vector<int> primes; long long solve(int n, int i) { if (n == 1) return 1ll; long long ret = INF; for (int j = 2; j <= n; ++j) ...
12
#include <bits/stdc++.h> using namespace std; int b[101]; bool c[101]; int main() { int n, m, x; cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> x; for (int j = x; j <= n; j++) { if (!c[j]) { b[j] = x; c[j] = 1; } else { break; } } } for (int i = 1; i...
1
#include <bits/stdc++.h> using namespace std; const int N = 1010; int n; int inrow[10], incol[10], op; int pos[5][2], cntpos; void queryrow(int u) { printf("? %d %d %d %d\n", u, 1, u, n); fflush(stdout); } void querycol(int u) { printf("? %d %d %d %d\n", 1, u, n, u); fflush(stdout); } void queryblo(int u, int v...
14