solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; void open() { freopen("in.txt", "r", stdin); } int main() { int n; cin >> n; long long k; cin >> k; long long ans = 0; long long v; long long s = 0; map<long long, int> sk; sk[0]++; long long p; for (int j = 0; j < n; j++) { cin >> v; s += v; ...
10
#include <bits/stdc++.h> using namespace std; bool question(int x, int y) { cout << '?' << ' ' << x << ' ' << y << endl; string c; cin >> c; if (c == "x") return 1; return 0; } void solve() { int z = question(0, 1); if (z) { cout << '!' << ' ' << 1 << endl; return; } int l, r; for (int i = 1...
12
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, flag = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') flag = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + (ch ^ 48); ch = getchar(); } return x * flag; } l...
7
#include <bits/stdc++.h> using namespace std; const int MAX_LEN = 1e5 + 1000; int main() { int n; cin >> n; int root; scanf("%d", &root); set<pair<int, int> > tree; tree.insert(make_pair(root, 1)); int num; int parent = 0; for (int i = 2; i <= n; i++) { scanf("%d", &num); auto itr = tree.lower...
10
#include <bits/stdc++.h> using namespace std; int n, x[4], y[4], a, b, c, d; int main() { cin >> n; for (int i = 0; i < 4; i++) { cin >> a >> b >> c >> d; x[i] = min(a, b); y[i] = min(c, d); } for (int i = 0; i < 4; i++) { if ((x[i] + y[i]) <= n) { cout << i + 1 << " " << x[i] << " " << n ...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, i, sum = 0; cin >> n; int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } sort(a, a + n); if (sum == 0) cout << "NO" << '\n'; else { cout << "YES" <<...
1
#include <bits/stdc++.h> std::multiset<long long> M[100002], M1; long long c[100002], v[100002]; int f[100002], d[100002], n, m; void ins(int i) { if (!M[i].empty()) M1.insert(*M[i].begin() + c[i] / (d[i] + 1)); if (M[i].size() >= 2) { auto pt = M[i].end(); pt--; M1.insert(*pt + c[i] / (d[i] + 1)); } ...
21
#include <bits/stdc++.h> using namespace std; const int MAX = 1024; int n; int rje[MAX]; vector<int> ask(vector<int> T) { printf("%d\n", (int)T.size()); for (auto it : T) printf("%d ", it + 1); printf("\n"); fflush(stdout); vector<int> R; for (int i = 0; i < n; i++) { int x; scanf("%d", &x); R.p...
11
#include <bits/stdc++.h> using namespace std; string s = "abcd"; int i, n; int main() { cin >> n; for (i = 0; i < n; i++) { cout << s[i % 4]; } cout << endl; }
3
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a, b, c, d, num = 0; int arr[3]; cin >> arr[0] >> arr[1] >> arr[2] >> d; sort(arr, arr + 3); if (arr[1] - arr[0] < d) num = d - (arr[1] - arr[0]); if (arr[2] - arr[1] < d) num += d - (arr[2] - arr[1]); cout << num; }
0
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::istream &operator>>(std::istream &i, pair<T, U> &p) { i >> p.first >> p.second; return i; } template <typename T> std::istream &operator>>(std::istream &i, vector<T> &t) { for (auto &v : t) { i >> v; } return i; } templat...
16
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7; int add(int a, int b) { a += b; if (a >= mod) { return a - mod; } if (a < 0) { return a + mod; } return a; } int mul(int a, int b) { return a * (long long)b % mod; } const int N = 1000 + 7; int dp[N][N]; int p[N][N]; int mai...
12
#include <bits/stdc++.h> using namespace std; string f, m, s; int main() { cin >> f >> m >> s; if (f == "rock" && m == "scissors" && s == "scissors") { cout << "F"; return 0; } if (f == "scissors" && m == "paper" && s == "paper") { cout << "F"; return 0; } if (f == "paper" && m == "rock" && ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; int i = 1, j = 2 * m, x, y = 1, cnt = 0; char ch = (k % 2 == 0) ? 'R' : 'L'; while (true) { if (k >= i && k <= j) { x = cnt + 1; int l = 1; if (k % 2 == 0) { int g = i + 1; while (...
0
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { int a, b; cin >> a >> b; if (a == b) { cout << "Yes"; } else { cout << "No"; } return 0; }
8
#include <bits/stdc++.h> using namespace std; struct Node { int idx, v; bool operator<(const Node& rhs) const { if (v == rhs.v) return idx < rhs.idx; return v < rhs.v; } }; priority_queue<Node> q; int n, a[100000 + 5], ans[100000 + 5]; bool used[100000 + 5]; int main() { memset(ans, -1, sizeof(ans)); ...
7
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; inline void add(int &x, int y) { if ((x += y) >= MOD) x -= MOD; } inline int mult(int x, int y) { return (long long)x * y % MOD; } const int maxn = 2001; int d[maxn][maxn]; int C[maxn][maxn]; void countD(int nm, int km) { memset(C, 0, sizeo...
12
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, -1}; int m, k, n, level[1000005], vis[1000005], up[1000005][31]; set<int> st; string s1 = "one", s2 = "zero", s, ch = ""; vector<int> v[1000005], vans; vector<pair<int, int> > vv; vector<pair...
14
#include <bits/stdc++.h> using namespace std; const int C = 200001; vector<vector<int> > tr(C); int ij[C], a, b, n, m; int s[C], is = 0, son[C], par[C], ji[C], dead[C], v[C], fll[C], best[2][C], ab[C]; int proc_tree(int a, int n, vector<vector<int> > &tab, int ij[]) { s[0] = a, is = 1; int b, k, mx = 0, z...
18
#include <bits/stdc++.h> struct xxx { int a[64][64]; } t[33]; struct yyy { int a[64]; }; int a[1010]; int ok[4][4]; bool used[4]; std::vector<std::pair<int, int> > v[1010]; int f[1010][4]; int cnt[4]; xxx operator*(xxx a, xxx b) { xxx c; memset(c.a, 0, sizeof(c.a)); for (int i = 0; i < 64; i++) for (int k...
19
#include <bits/stdc++.h> using namespace std; const int MAXN = 101010; const int MAXM = 1000; int N, K; long double prob[2][MAXM]; long double comb[MAXN]; long double s[2][MAXM]; long double ev[MAXN]; void make_prob() { s[0][1] = 0; ev[0] = 0; prob[0][1] = 1; for (int t = 1; t <= N; t++) { for (int l = 1; l...
19
#include <bits/stdc++.h> using namespace std; template <class A> void pr(A a) { cout << a; cout << '\n'; } template <class A, class B> void pr(A a, B b) { cout << a << ' '; pr(b); } template <class A, class B, class C> void pr(A a, B b, C c) { cout << a << ' '; pr(b, c); } template <class A, class B, class ...
9
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { x = 0; char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - 48, c = getchar(); } const int maxn = 5e5 + 5; int n, tot, fat[maxn], first[maxn], d[maxn], f[maxn]; struct Roa...
24
#include <bits/stdc++.h> using namespace std; struct PI { long long x, y; PI() {} PI(long long _, long long __) { x = _, y = __; } friend bool operator<(PI x, PI y) { return x.x < y.x; } }; PI X[200010]; int Q[200010], T = 0, W = 1; map<long long, long long> hsh; int main() { long long n, d, m; scanf("%lld%...
14
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n,k; cin>>n>>k; int a[n]; bool check=true; for(int i=0;i<n;i++)cin>>a[i]; sort(a,a+n); if(a[0]+a[1]>k&&a[n-1]>k) check=false; if(check==true) cout<<"YES"; els...
0
#include <bits/stdc++.h> using namespace std; const int N = 100005; const double eps = 1e-12; const double pi = acos(-1); int x[N], y[N], n; double get(int a, int b) { double aa = x[a] - x[b]; double bb = y[a] - y[b]; return atan2(bb, aa); } long long C(long long t) { return t * (t - 1) / 2LL; } long long calc(in...
19
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const int maxn = 2200000; char s[maxn]; char t[maxn]; char q[maxn]; int p[maxn]; int rp[maxn]; void calcPrefix(int *p, char *s) { int n = strlen(s); p[0] = -1; for (int i = 1; i < n; ++i) { int r = p[i - 1]; while (r >= 0 && s[i] ...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int t; cin >> t; while (t--) { ll n, g, b; cin >> n >> g >> b; ll l = n, r = 1000000000000000005; while (l < r) { ll m = (l + r) / 2; ll cnt = g * (m / (g + b)) + min(m % (g + b), g); if (cnt >= (n +...
6
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long N = 1e6 + 1; const long long mod = 1e9 + 7; const long double EPS = 1E-15; string s; long long n, x, ans; long long a[N], b[N]; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> s;...
7
#include <bits/stdc++.h> using namespace std; int main(void) { ios_base::sync_with_stdio(false), cin.tie(NULL); ; long long t; cin >> t; while (t--) { long long n, k, x = 0, i, loop = 0, j, count; cin >> n >> k; string s; for (i = 0; i < n - 2; ++i) s += 'a'; s += 'b'; s += 'b'; i ...
5
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } x *= f; } const double Pi = acos(-1....
24
#include <bits/stdc++.h> using namespace std; long long dp[2010][2010]; string s[2010]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 1; i < m - 1; i++) if (s[0][i] == '.') dp[0][i] = 1 << 0; for (int i = 1;...
15
#include <bits/stdc++.h> using namespace std; #define int long long int #define w(t) int t;cin>>t;while(t--) #define rep(i,a,b) for(int i=a;i<b;i++) #define REP for(int i=0;i<n;i++) #define FTR(v,itr) for(itr=v.begin();itr!=v.end();itr++) #define si set<int> #define vi ...
6
#include <bits/stdc++.h> using namespace std; const long long N = 1000005; const long long INF = 1e18; long long x, m, n, i, j, k; pair<long long, long long> a[N]; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcd(long long a, long long b) { return a * b / gcd(a, ...
6
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long inf = 1e18; long long m_inf = INT_MIN; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); std::cout.unsetf(std::ios::fixed); std::cout.precision(9); long long t = 1; while (t--) { long long ...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<ld, ld>; using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>; using vd = vector<ld>; using vs = vector<str>; using vpi = ...
4
#include <bits/stdc++.h> using namespace std; int Min(int x, int y) { return x < y ? x : y; } int Max(int x, int y) { return x > y ? x : y; } int main() { int x1, x2, a, b; long long kk; scanf("%d%d%d%d", &x1, &x2, &a, &b); kk = a; kk = kk * b; if (kk <= 0) { if (x1 > x2) { int d = Min(a, b); ...
16
#include <bits/stdc++.h> using namespace std; int x, t, a, b, da, db, i, j; int main() { cin >> x >> t >> a >> b >> da >> db; for (i = 0; i < t; i++) for (j = 0; j < t; j++) { if (a - da * i + b - db * j == x) { cout << "YES"; return 0; } if (a - da * i == x) { cout << ...
4
#include <bits/stdc++.h> using namespace std; const int limite = 151; int n; const int infinito = 2000000000; vector<vector<int> > codifica(vector<vector<int> > m) { vector<vector<int> > r(n, vector<int>(5, 0)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) r[i][j >> 5] |= m[i][j] << (j & 31); retur...
19
#include <bits/stdc++.h> using namespace std; int main() { string str[] = {"S", "M", "L", "XL", "XXL"}; int a[10]; for (int i = 0; i < 5; i++) { cin >> a[i]; } int k; cin >> k; string s; for (int i = 0; i < k; i++) { cin >> s; int r = 0; for (r = 0; r < 5; r++) if (str[r] == s) bre...
3
#include <bits/stdc++.h> using namespace std; int main() { string x; cin >> x; string y; cin >> y; string z; int n = x.length(); for (int i = 0; i < n; i++) { if (x[i] == y[i]) z.push_back('z'); else if (x[i] > y[i]) z.push_back(y[i]); else { cout << -1; return 0; }...
1
#include <bits/stdc++.h> using namespace std; void solve() { long long n, x; cin >> n >> x; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); int prev = n; int ans = 0; for (int i = n - 1; i >= 0; i--) { long long mn = a[i]; long long nm = prev ...
6
#include <bits/stdc++.h> using namespace std; void solve() { int a, b; cin >> a >> b; if (a < b) { cout << abs(a - b) << endl; } else { cout << (a % 2 + b % 2) % 2 << endl; } } int main() { int t; cin >> t; for (int i = 1; i <= t; i++) { solve(); } }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, s1[100002], s2[100002], p1, p2; scanf("%d %d %d", &n, &m, &k); p1 = n, p2 = m; for (int i = 0; i < n; i++) scanf("%d", &s1[i]); sort(s1, s1 + n); for (int i = 0; i < m; i++) scanf("%d", &s2[i]); sort(s2, s2 + m); while (p1 && p2) { ...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int inf = 0x3f3f3f3f; const long long base2 = 239; const long long base1 = 233; const long long mod = 1e9 + 7; const long long hmod1 = 1e9 + 93; const long long hmod2 = 1e9 + 97; const double e = exp(1.0); const double pi = acos(-1); long lon...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = 100050; const long long mod = 1e9 + 7; long long inp1[MAXN], inp2, inp3, ans = 1; long long n, k, st[MAXN][40], sum[MAXN][40], mn[MAXN][40], mi[40]; int main() { mi[0] = 1; for (long long i = 1; i <= 34; i++) mi[i] = mi[i - 1] << 1; scanf("%lld%lld", ...
13
#include <bits/stdc++.h> using namespace std; int n; int w[111][111]; int a[111]; int f[111]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { cin >> f[i]; w[i][i] = 1; if (i + f[i] <= n) { w[i][i + f[i]] = 1; w[i + f[i]][i] = 1; ...
8
#include <bits/stdc++.h> using namespace std; const int MAX_N = (int)2e5 + 20; int a[MAX_N]; int b[MAX_N]; int ans[MAX_N]; int n, max_ans, Cnt; string s; char v[] = {'a', 'o', 'i', 'u', 'e'}; inline int check(char x) { if (x >= 'A' && x <= 'Z') x += 'a' - 'A'; for (int i = 0; i < 5; i++) if (x == v[i]) return -...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 8; int n; string ss; int num[26] = {0}; int flag = 0; int main() { cin >> n; cin >> ss; if (n > 26 || n == 1) cout << "Yes"; else { for (int i = 0; i < ss.size(); i++) { num[ss[i] - 'a']++; if (num[ss[i] - 'a'] >= 2) { ...
1
#include <bits/stdc++.h> using namespace std; const long long N = 21; const long long M = 1 << 20; long long n, m, ans, S, inv[N], e[N][N], f[M][N]; long long lowbit(long long x) { return x & -x; } signed main() { ios::sync_with_stdio(0); cin >> n >> m; S = 1 << n; inv[0] = 1; for (long long i = 1; i <= n; i+...
14
#include <bits/stdc++.h> using namespace std; int n, m, k; long long a[1005][1005]; long long s1[1005][1005]; long long s2[1005][1005]; int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf("%lld", &a[i][j]); for (int i = 1; i <= n; i++) for (int j = 1; ...
17
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(0); cin.tie(0); long long ax, ay, bx, by, cx, cy; cin >> ax >> ay >> bx >> by >> cx >> cy; long double dist1 = ((by - ay) * (by - ay) + (bx - ax) * (bx - ax)); long double dist2 = ((by - cy) * (by - cy) + (bx - cx) * (...
6
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 5; const int INF = 0x3f3f3f3f; vector<int> edge[N]; int n; int dp[N][N][2]; int DFS(int u, int fa) { if (edge[u].size() == 1) { dp[u][0][0] = dp[u][1][1] = 0; return 1; } dp[u][0][0] = dp[u][0][1] = 0; int tot = 0; for (int v : edge[u])...
16
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { int N; cin >> N; vector<unordered_set<int>> triplets; vector<unordered_set<int>> mapping(N + 1); int q1, q2, q3; for (int i = 0; i < N - 2; ++i) { cin >> q1 >> q2 >> q3; triplets.push_back({q1, q2, q3}); mapping[q1]....
8
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e; scanf("%d%d%d%d%d", &a, &b, &c, &d, &e); int x = a + b + c + d + e; if (x % 5 == 0 && x != 0) { x = x / 5; cout << x; } else cout << "-1"; return 0; }
3
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; int tab[300000]; int visited[300000]; int compt = 0; long long int fastPow(long long int a, long long int b) { long long int res = 1; while (b > 0) { if (b & 1) res = (res * a) % mod; b /= 2; a = (a * a) % mod; } return re...
11
#include <bits/stdc++.h> using namespace std; const int MAX = (1 << 21) + 5; int n; char s[MAX]; unsigned long long a[MAX], b[MAX], Pow[23], Count[MAX]; void FMT_or(unsigned long long *f, unsigned long long op) { for (int i = 1; i < (1 << n); i <<= 1) { for (int j = 0; j < (1 << n); j++) { if (!(j & i)) { ...
24
#include <bits/stdc++.h> using namespace std; bool sub(string s1, string s2) { int i = 0; int j = 0; while (1) { if (i >= int(s1.length())) return true; if (j >= int(s2.length())) return false; if (s1[i] == s2[j]) { i++; j++; } else if (i == 0) j++; else { i = 0; } ...
6
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(0); string s; int n; cin >> s >> n; int count = 0; for (auto it = s.rbegin(); it != s.rend() && n > 0; ++it) { if (*it != '0') ++count; else --n; } if (n > 0) count = s.length() - 1; cout ...
3
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &num) { T x = 0, f = 1; char ch = getchar(); for (; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') f = -1; for (; ch <= '9' && ch >= '0'; ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ '0'); num = x * f; } in...
22
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; vector<int> edg[100005]; int n, m; bool vis[100005]; vector<int> num; int cnt = 0; int dp[100005]; map<int, int> tim; bool lucky(int x) { if (x % 10 != 4 and x % 10 != 7) { return false; } if (x < 10) { return true; } return lucky(x / ...
17
#include <bits/stdc++.h> using namespace std; const int MAXN=100005,B=600,BC=(MAXN/B)+1; struct BlockCnt { int f[MAXN],g[BC]; void add(int p,int d) { f[p]+=d; g[(p-1)/B]+=d; } void query(int k,int &p,int &s) { s=k; for (int i=0;;i++) { if ((i+1)*B+g[i]>=s) for (int j=i*B+1;;j++) { if...
24
#include <bits/stdc++.h> using namespace std; const int MAXN = 100; double x[MAXN], y[MAXN], z[MAXN], dx[] = {1, -1, 0, 0, 0, 0}, dy[] = {0, 0, 1, -1, 0, 0}, dz[] = {0, 0, 0, 0, 1, -1}; int main() { int n; cin >> n; for (int i = 0; i < n; i++) ci...
13
#include <bits/stdc++.h> using namespace std; void fast_io() { ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void my_file_in_out() { freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout); } inline void OK(string t = "") { cerr << "OK " << t << '\n'; } inline lon...
7
#include <bits/stdc++.h> using namespace std; const int N = 110; int mod = 998244353; int n, m; string g[300010], ret_t[300010], ans_t[300010]; int ans; int check1(const vector<char> &p) { int num = 0; for (int i = 0; i < n; ++i) { char c[2]; c[0] = p[(i & 1) * 2], c[1] = p[(i & 1) * 2 + 1]; int tmp1 = ...
13
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; long int a = 0, b = 0; int a_c = 0, b_c = 0; for (int i = 0; i < n; i++) { int t, x, y; cin >> t >> x >> y; if (t == 1) { a += x; a_c += 1; } else { b += x; b_c += 1; } } string A, B...
0
#include <bits/stdc++.h> const int N = 85; using namespace std; int dp[N][N][N][N]; int n, k, m, u, v, w, ma[N][N]; int dfs(int l, int r, int st, int cnt) { if (dp[l][r][st][cnt] != -1) return dp[l][r][st][cnt]; if (cnt == 1) { dp[l][r][st][cnt] = 0; return 0; } int ans = 0x3f3f3f3f; for (int i = 1; i...
13
#include <bits/stdc++.h> using namespace std; int n, sum; int a[30]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } for (int i = sum; i >= 1; i--) { if (sum % i == 0) { bool ok = true; f...
17
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); std::ios::sync_with_stdio(false); long long counter = 0, result = 0, maxi = 0; long long n, arr[100000]; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) { if (arr[i] >= maxi) { counter = 0; ...
6
#include <bits/stdc++.h> using namespace std; int main(void) { vector<pair<int, int> > pts; vector<pair<int, int> >::iterator it; int n; int tt = 0; scanf("%d", &n); for (int i = 0; i < n; ++i) { int px, py; scanf("%d %d", &px, &py); pts.push_back(make_pair(px, py)); } sort(pts.begin(), pts....
5
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { set<int> list; set<pair<int, int>> y; int count; cin >> count; for (int i = 0; i < count; i++) { int x; cin >> x; list.insert(x); } int count2 = count / 2; auto end = list.en...
2
#include <bits/stdc++.h> using namespace std; int dp[5050][5050]; int ans[5050]; int main() { ios::sync_with_stdio(0); cout.tie(NULL); cin.tie(NULL); string s; cin >> s; int i, j; for (i = 1; i <= s.length(); i++) for (j = 0; j < s.length() - i + 1; j++) { if (i == 1) { dp[j][j + i] = 1;...
11
#include <bits/stdc++.h> using namespace std; pair<int, pair<int, int> > Edges[200005]; multiset<long long> SP; multiset<long long>::iterator Sit; long long Graph[805][805]; map<int, int> M; map<int, int>::iterator it; long long MAX = 1000000000000000000; long long FindAns(int k, int N) { int i, j; for (i = 1; i <=...
14
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 10; struct Node { int siz; int p[4], x[4]; Node() { siz = 0; } void push(int _x, int _p) { p[siz] = _x; x[siz] = _p; siz++; for (int i = siz - 1; i > 0; i--) { if (x[i] > x[i - 1]) swap(x[i], x[i - 1]), swap(p[i], p[i - 1]);...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d %d", &n, &m); vector<int> A(m + 1, -1), B(m + 1), f(n + 1); vector<vector<int> > cnt(n + 1, vector<int>()); for (int i = 0; i < (int)n; ++i) { scanf("%d", &f[i + 1]); cnt[f[i + 1]].push_back(i + 1); } bool amb = false; ...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t = 1; while (t--) { long long n, sum = 0; vector<long long> a(100001); cin >> n; for (long long i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } ...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; int n, q; pair<int, int> p[500005]; int main() { scanf("%d", &n); int m = 1; while (m * 2 <= n) m *= 2; for (int i = 1; i < m; i <<= 1) { for (int j = 1; ...
15
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; int len = s.size(); int s1[100] = {0}, x = 2, y = 1, z = 0, k = 0; if (len % 2 == 0) { while (x <= len) { s1[k] = len - x; x += 2; k++; } if...
0
#include <bits/stdc++.h> using namespace std; int n, m; struct INT { long long a[100]; int sig; INT() { memset(a, 0, sizeof(a)); a[0] = 1; sig = 1; } void I() { memset(a, 0, sizeof(a)); a[0] = 1; a[1] = sig = 1; } void mul(long long x) { if (x < 0) { x *= -1; sig *=...
15
#include <bits/stdc++.h> using namespace std; const int M = 100000 + 10; int dis[2][2 * M]; int water[2][2 * M]; queue<pair<int, int> > Q; bool inque[2][2 * M]; int main() { int n, k; cin >> n >> k; string s[2]; cin >> s[0] >> s[1]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2 * M; j++) { dis...
6
#include <bits/stdc++.h> using namespace std; int n, a, b, ans; int t[10]; int lest[10]; void dfs(int x, int cnt) { if (x == 7) { ans = min(ans, cnt); return; } for (int i = 1; i <= cnt; i++) if (lest[i] >= t[x]) { lest[i] -= t[x]; dfs(x + 1, cnt); lest[i] += t[x]; } lest[cnt +...
8
#include <bits/stdc++.h> int main() { char col; int row; scanf("%c%d", &col, &row); if ((row == 1 || row == 8) && (col == 'a' || col == 'h')) printf("3"); else if ((row == 1 || row == 8) && (col != 'a' || col != 'h')) printf("5"); else if ((row != 1 || row != 8) && (col == 'a' || col == 'h')) pr...
0
#include <bits/stdc++.h> using namespace std; const int INF_I = 1e9; const long long INF_LL = 1e18; const long long MOD = 998244353; const int N = 2 * 1e5 + 1; vector<int> f(N); int mul(int a, int b) { return (a * 1ll * b) % MOD; } int fact(int a) { return f[a]; } int pw(int a, int k) { if (k == 0) return 1; if (k ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (int i = 0; i < n; i++) { if (i % 2 == 0) { cout << a[i] << " "; } } for (int i = (n - 1); i >= 0; i--) { if (i % 2 != 0) { ...
4
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma G++ optimize(2) using namespace std; std::mt19937_64 rnd(time(0)); const int MAX_N = 5e5 + 5; inline int qi() { int f = 0, fu = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') fu = -1; c = getchar(); } while (c >= '0' && c <= '...
17
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--){ int n; cin>>n; int a[n]; for(int i = 0; i < n; i++){ cin>>a[i]; } sort(a, a+n); int maxi = 0, count = 1; for(int i = 0; i < n; i++){ ...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); const int mod = (int)1e9 + 7; int dp[1 << 24], last[1 << 24], sum[1 << 24]; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i...
15
#include <bits/stdc++.h> using namespace std; void openfile() {} const int M = 200000 + 11; struct smt { int sm[M << 2]; void build(int p, int l, int r) { if (l == r) sm[p] = 1; else { int mid = l + r >> 1; build(p << 1, l, mid); build(p << 1 | 1, mid + 1, r); sm[p] = sm[p << 1...
6
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; for (int j = 0; j < n; j++) { cout << 7 << " "; } cout << endl; } }
0
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 1, mod = 998244353; int n; vector<int> g[N]; long long f[N][3]; void dfs(int v, int p = -1) { for (int u : g[v]) if (u != p) dfs(u, v); f[v][0] = 1; f[v][1] = 1; f[v][2] = 1; for (int u : g[v]) if (u != p) { f[v][0] = f[v][0] * (2...
17
#include <bits/stdc++.h> using namespace std; long long int a[30][30]; int main() { long long int n, i, j, k; long long int q, cnt, x, y; cin >> n; for (i = 1; i <= n; i++) { for (j = 1, x = 1 << max(i - 2, 0LL); j <= n; j++, x <<= 1) { cout << ((i & 1) ? 0 : x) << ' '; cout.flush(); } c...
13
#include <bits/stdc++.h> using namespace std; int ws(long long x) { int ans = 0; while (x) ans++, x /= 10; return ans; } long long mypow(long long x, long long p) { long long ans = 1; while (p--) ans *= x; return ans; } int main() { long long w, m, k, ans = 0; while (cin >> w >> m >> k) { ans = 0; ...
8
#include <bits/stdc++.h> using namespace std; int main() { long long T; cin >> T; while (T--) { long long m, n; cin >> m >> n; long long arr[1000][1000]; bool cond = true; for (long long i = 0; i < m; i++) { for (long long j = 0; j < n; j++) { cin >> arr[i][j]; if (i == 0...
4
#include <bits/stdc++.h> using namespace std; const long long N = 100005; long long A[N]; long long fnc(long long h, long long n) { long long sum = 0; for (__typeof((n)) i = (1); i <= (n); i++) { if (A[i] >= h) sum += A[i] - h; } return sum; } void solve() { long long n, k, x; cin >> n >> k; long long...
4
#include<bits/stdc++.h> using namespace std; const int M = 1000000007; int main() { cin.tie(0); ios::sync_with_stdio(0); int T; cin >> T; for (int _ = 0; _ < T; ++_) { vector<int> c(3); for (int i = 0; i < 3; ++i) { cin >> c[i]; } vector<int> a(5); ...
1
#include <bits/stdc++.h> using namespace std; char grid[2010][2010]; int deg[2010][2010]; int n, m, ct, rm, cm, x, y; int dy[4] = {0, -1, 0, 1}; int dx[4] = {1, 0, -1, 0}; char ss[2][8] = {"^>v<", "v<^>"}; queue<pair<int, int>> q; int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int r = 1; r <= n; ++...
12
#include <bits/stdc++.h> using namespace std; int n, m; bool rev; char t[52][52]; pair<int, int> ans[2][100010]; int cnt[2]; char revchange(char ch) { if (ch == 'U') return 'L'; else if (ch == 'D') return 'R'; else if (ch == 'L') return 'U'; else return 'D'; } void work(int i, int j, int id) { ...
19
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 5; const int mod = 1e9 + 7; int n, ar[N]; vector<pair<int, int> > adj[N]; vector<int> ans; int cnt[N]; bool can[N]; void dfs(int x, int p) { for (auto pp : adj[x]) if (pp.first != p) { if (pp.second == 2) can[pp.first] = 1, cnt[x]++; df...
8
#include <bits/stdc++.h> using namespace std; pair<long long, long long> A[201000]; long long f[201000], g[201000]; double F[201000]; pair<long long, long long> calc(int x, int y) { long long a = (A[x].first - g[y] - 1) / A[y].second + 1; long long b = 1ll * A[y].second * a - (A[x].first - g[y]); return pair<long...
20
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; void solve() { int n; cin >> n; string s; cin >> s; if (n == 6) { cout << "espeon"; return; } if (n == 8) { ...
2