solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; long long l3[3][100005]; int main() { long long n; cin >> n; long long l1[n + 1], l2[n + 1]; map<long long, long long> mp, mp2; vector<long long> v; for (int i = 1; i <= n; i++) { cin >> l1[i] >> l2[i]; mp[l1[i]] = 1; mp[l2[i]] = 2; mp2[l1[i]] = ...
5
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 10; const long long int MOD = 1e9 + 7; int n, m; long long int d[2][N], ans; string s, t; int main() { cin >> s >> t; n = s.size(), m = t.size(); for (int i = 0; i < m; ++i) d[0][i] = d[0][i - 1] + (int)(t[i] == s[0]); ans = d[0][m - 1]; for (i...
9
#include <bits/stdc++.h> using namespace std; const int Maxn = 10000010; int p[20] = {2, 3, 5, 7, 11, 13, 17, 19}; int a[Maxn]; int main() { int n; while (~scanf("%d", &n)) { int cnt = 1; a[0] = 1; int tmp = 2 * n * n; int ch; for (int i = 0;; i++) { for (int j = 0; j < cnt; j++) { ...
15
#include<bits/stdc++.h> #define ll __int128 #define ld long double #define ull unsigned ll #define uint unsigned int #define db double #define pint pair<int,int> #define mk make_pair #define pb push_back #define eb emplace_back #define ins insert #define fi first #define se second #define Rep(x,y,z) for(int x=(y);x<=(z...
24
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q > 0) { q--; long long n, m; cin >> n >> m; long long k = n / m; int mlast = m % 10; int s10 = 0; for (int i = 1; i <= 9; i++) s10 += (mlast * i) % 10; long long s = 0; s += (k / 10) * s10; ...
4
#include <bits/stdc++.h> using namespace std; int x[500]; int main() { int n, m; scanf("%d%d", &n, &m); int i = -1; for (int j = 1; j <= m; j++) { int u; scanf("%d", &u); if (x[u % n] == 0) x[u % n]++; else { if (i == -1) i = j; } } printf("%d\n", i); }
0
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(), z = 0, o = 0, u = 0; for (int i = 0; i < n; ++i) { if (s[i] == '0') ++z; else if (s[i] == '1') ++o; else ++u; } int p = n / 2, q = (n + 1) / 2; if (o < q) puts("00"); if (s[n - ...
11
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; const long long int INF = 1e18; const long long int N = 2e6 + 20; vector<long long int> g[N]; vector<long long int> vis(N); vector<long long int> ans(N); void pre() { ans[3] = 4; for (long long int i = 4; i < N; i++) { ans[i] = (an...
11
#include <bits/stdc++.h> using namespace std; const int maxx = 600010; const double pi = acos(-1.0); const double eps = 1e-15; int t, n, m, u, v; int ans = 0, total = 0, sum = 0, cnt = 0, l = 0, r = 0; int a[maxx], x[maxx], y[maxx], upx[maxx], upy[maxx], dx[maxx], dy[maxx]; char c[311][311]; int main() { scanf("%d", ...
10
#include <bits/stdc++.h> using namespace std; template <class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template <class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } int N, K, A; long long arr[100013]; long long cost[100013]; priority_queue<long long, vector<long long>, greater<long long> > ...
7
#include <bits/stdc++.h> using namespace std; int n, k, asdasjkd, adsnamsd, a[101], mna, mnb, b[101]; int ans; int main() { int t23 = 1; cin >> t23; for (int qwe = 1; qwe <= t23; qwe++) { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; ans = 1e9; sort(a + 1, a + n + 1); for (int i = 2; i <...
0
#include <bits/stdc++.h> int main() { int n, m; int x, y; int i, j; char grid[100][101]; while (~scanf("%d%d", &n, &m)) { x = y = 0; for (i = 0; i < n; ++i) { scanf("%s", grid[i]); for (j = 0; j < m; ++j) { if (grid[i][j] == '*') { x ^= i; y ^= j; } ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 1000; int n, m, q; long long tmp; int vis[maxn]; pair<long long, long long> a[maxn], b[maxn]; int ans[maxn]; int v[maxn * 4]; void build(int l, int r, int x) { v[x] = 0; if (r == l) { return; } int mid = (l + r) / 2; build(l, mid, x << 1...
14
#include <bits/stdc++.h> using namespace std; const int N = 300002; int col[N]; map<vector<int>, int> ind; int n, m, c; vector<int> adj[N], adj2[N]; void go(int u) { int v, i; col[u] = c++; for (i = 0; i < adj[u].size(); i++) { v = adj[u][i]; if (col[v] == 0) go(v); } } int main() { scanf("%d %d", &n,...
16
#include <bits/stdc++.h> using namespace std; struct Circle { int x, y; long long radi; Circle() {} Circle(int x, int y, long long radi) { this->x = x; this->y = y; this->radi = radi; } }; int main(void) { int n, m, k; scanf("%i %i %i", &n, &m, &k); vector<int> X(n), Y(n); for (int i = 0; ...
12
#include <bits/stdc++.h> using namespace std; long long sqr(long long x) __attribute__((always_inline)); long long sqr(long long x) { return x * x; } struct Point { Point(int x = 0, int y = 0) : x(x), y(y) {} Point &operator-=(const Point &o) { x -= o.x; y -= o.y; return *this; } double norm() const...
19
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000086; char buf[MAXN], s[MAXN]; vector<pair<int, int> > tt; int main() { int i, j, k; int m, n; int len; int c, e; scanf("%s", buf); len = strlen(buf); for (i = 0; i < len; ++i) s[i] = buf[len - 1 - i]; s[i] = '\0'; for (i = 0; i < len;)...
13
#include <bits/stdc++.h> using namespace std; int n, i, j, h; string s; vector<char> v[100002]; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> s; h = s.size(); for (j = 0; j < s.size(); j++) { if (s[j] == '?') continue; if (v[j].size() == 0) { v[j].push_back(s[j]); ...
4
#include <bits/stdc++.h> using namespace std; long long a[36] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8092, 16184, 32368, 64736, 129472, 258944, 517888, 1035776, 2...
11
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int a, b, n, p; cin >> a >> b >> n; p = a ^ b; if (n % 3 == 0) cout << a << endl; else if ((n - 1) % 3 == 0) cout << b << endl; else cout << p << endl; } retu...
1
#include <bits/stdc++.h> using namespace std; class mexMap { private: map<int, int> S; int MEX; public: mexMap() { MEX = 0; } int get() { return MEX; } void insert(int v) { S[v]++; if (v == MEX) { map<int, int>::iterator it = S.find(v); for (; it != S.end(); it++) { if (MEX != i...
14
#include <bits/stdc++.h> using namespace std; int n, dp[500005][30], maxx[30][30]; struct cuv { int ul, pr; int len; } a[500005]; int main() { int i, j, sol = -2000000000, pr; char sir[100]; cin.sync_with_stdio(0); cin >> n; for (i = 1; i <= n; ++i) { cin >> (sir + 1); a[i].pr = sir[1] - 'a'; ...
7
#include <bits/stdc++.h> using namespace std; long long n, k, a[1000001], l[1000001], r[1000001], ans; long long S(long long k) { return k & 1 ? (k + 1) / 2ll % 1000000007 * k % 1000000007 : k / 2ll % 1000000007 * (k + 1) % 1000000007; } long long f(long long a, long long b, long long c, long long n) {...
17
#include <bits/stdc++.h> using namespace std; int main() { string s; map<char, long long> m; cin >> s; long long count = 0; for (int i = 0; i < s.length(); i++) { m[s[i]] += 1; } for (map<char, long long>::iterator it = m.begin(); it != m.end(); ++it) { count += (it->second) * (it->second); } ...
7
#include <bits/stdc++.h> using namespace std; int main() { int s, n, x, y; cin >> s >> n; multimap<int, int> dragons; for (int i = 0; i < n; i++) { cin >> x >> y; dragons.insert({x, y}); } bool flag = true; for (auto it = dragons.begin(); it != dragons.end(); it++) { if (it->first < s) { ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005; inline long long readint() { long long res = 0, f = 1; char c = 0; while (!isdigit(c)) { c = getchar(); if (c == '-') f = -1; } while (isdigit(c)) res = res * 10 + c - '0', c = getchar(); return res * f; } int n, m, T, a[MAXN][MAXN...
12
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long power(long long num, long long r) { if (r == 0) return 1; if (r == 1) return num % mod; long long ans = power(num, r / 2) % mod; if (r % 2 == 0) { return (ans * ans) % mod; } return (((ans * ans) % mod) * num) % mod; } long...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v; for (int i = 0; i < n; i++) { int x; cin >> x; v.push_back(x); } sort(v.begin(), v.end()); long long t; cin >> t; while (t--) { int l; cin >> l; int lower = upper_bound(v.begin(), v.end()...
3
#include <bits/stdc++.h> using namespace std; long long gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); } bool isprime(long long n) { if (n == 2) { return true; } if (n % 2 == 0) { return false; } for (long long i = 3; i <= sqrt(n); i += 2) { if (n % i == 0) { return false; ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << -1 << endl; return 0; } if (n == 2) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (x1 == x2 || y1 == y2) { cout << -1 << endl; return 0; } int p = x1 - x2; int ...
3
#include <bits/stdc++.h> using namespace std; long long t1, t2, x1, x2, tt, l, r, c, a1, a2, ans = 2e12, sa; int main() { cin >> t1 >> t2 >> x1 >> x2 >> tt; for (int i = 0; i <= x1; i++) { l = 0; r = x2; while (l < r) { c = (l + r) / 2; if (i == 0 || t1 == t2 || (i * t1 + c * t2) < tt * (i +...
11
#include <bits/stdc++.h> using namespace std; const int N = 200 + 5; const int C = 26; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; int n, m, v[N]; char s[N]; long long k; struct matrix { long long a[N][N]; } A, Z, E; template <class T> void relax(T &a, T b) { if (a < b) a = b; } matrix mul(matrix &A, matri...
17
#include <bits/stdc++.h> using namespace std; long long dp[55][55][55]; long long DFS(int n, int m, int k) { if (k <= 0 || n * m == k) return 0; if (dp[n][m][k]) return dp[n][m][k]; long long now = 0x7f7f7f7f; for (int i = 1; i < n; i++) { for (int j = 0; j <= k; j++) { now = min(now, DFS(i, m, j) + D...
12
#include <bits/stdc++.h> using namespace std; inline void read() {} template <typename T, typename... Ts> inline void read(T& A, Ts&... As) { T 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 << 1) + (...
17
#include <bits/stdc++.h> int main(void) { int n, H, i; scanf("%d %d", &n, &H); for (i = 1; i < n; i++) { printf("%.12lf ", H * sqrt(i * 1.0 / n)); } return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { int k, a, b, c, n; cin >> k >> a >> b >> c; for (int i = 1; i <= 1000; i++) { n = k * i; n = min(n, b + i); if (c * n >= a) { printf("%d\n", i); return 0; } } }
3
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger &operator,(const T &v) { cerr << v << " "; return *this; } } dbg; inline long long gcd(long long a, long long b) { a = ((a) < 0 ? -(a) : (a)); b = ((b) < 0 ? -(b) : (b)); while (b) { a = a % b; swa...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tc, cas = 1; int n, m, k; cin >> n >> m >> k; vector<vector<int>> g(n); vector<int> a(m), b(m); for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--, b[i]--; g[a[i...
13
#include <bits/stdc++.h> using namespace std; struct node { int r, c, dist; node() {} node(int _r, int _c, int _dist) : r(_r), c(_c), dist(_dist) {} bool operator<(node X) const { return dist > X.dist; } }; int n, m, r[7], c[7], M[100][100], id[100][100]; int dist[200][200], px[200][200], py[200][200]; int memo...
17
#include <bits/stdc++.h> using namespace std; int long long inline power(int long long a, int long long b, int long long p) { a %= p; int long long ans = 1; while (b > 0) { if (b & 1) ans = (ans * a) % p; a = (a * a) % p; b >>= 1; } return ans; } int long long inv(int long long n, int long long p)...
11
#include <bits/stdc++.h> using namespace std; int main() { double a, b, c, x, y, mn, mx, ans1, ans2; cin >> a >> b >> c; x = b * b - 4 * a * c; x = sqrt(x); mn = -b - x; mx = -b + x; mn = mn / (2 * a); mx = mx / (2 * a); ans1 = max(mn, mx); ans2 = min(mn, mx); printf("%.6lf\n%.6lf\n", ans1, ans2);...
5
#include <bits/stdc++.h> using namespace std; inline namespace Infinity { inline namespace Constant { constexpr const int eof = EOF; constexpr const int maxint = INT_MAX; constexpr const long long maxll = LLONG_MAX; constexpr const double eps = DBL_EPSILON; } // namespace Constant inline namespace TypeDefine { using u...
15
#include <bits/stdc++.h> using namespace std; long long sum[100100 << 2][12]; int per[100100 << 2][12]; void up(int o) { for (int i = 0; i < 10; ++i) sum[o][i] = sum[(o << 1)][i] + sum[((o << 1) | 1)][i]; } void build(int o, int l, int r) { for (int i = 0; i < 10; ++i) per[o][i] = i; if (l == r) { int x, ...
20
#include <bits/stdc++.h> using namespace std; const int inf = int(1e9); bool my_compare(const pair<int, int>& i, const pair<int, int>& j) { if (i.first > j.first) return false; if (j.first > i.first) return true; return j.second > i.second; } int check(vector<pair<int, int> > x, vector<pair<int, int> > y, int h) ...
10
#include <bits/stdc++.h> using namespace std; int n, m; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; set<pair<int, pair<int, bool> > > eaten; set<pair<int, pair<int, bool> > >::iterator it; int x, y, ans; char d; bool dr; eaten.insert(make_pair(0, make_pair(...
14
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int n; cin >> n; int best = -1; int idx, op1, op2; for (int i = 0; i < 4; i++) { int v1, v2, v3, v4; cin >> v1 >> v2 >> v3 >> v4; int temp = min(v1, v2) + min(v3, v4); ...
3
#include <bits/stdc++.h> using namespace std; namespace Stand_IO_Operation { inline int read() { int f = 1, res = 0, ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') res = res * 10 + ch - 48, ch = getchar(); return f * res; } int _s...
16
#include <bits/stdc++.h> using namespace std; int main() { char s[15], i; int k; cin >> s; cin >> k; int n = strlen(s), r = 0, count = 0; for (i = n - 1; i >= 0; i--) { if (s[i] == '0') count++; if (k == count) { r = 1; break; } } if (r == 1) { cout << n - i - k; return 0...
3
#include <bits/stdc++.h> using namespace std; int main() { int x1, y1, x2, y2, x3, y3, x4, y4; cin >> x1 >> y1 >> x2 >> y2; if (x1 == x2) x3 = x4 = x1 + (y2 - y1), y3 = y1, y4 = y2; else if (y1 == y2) y3 = y4 = y1 + (x2 - x1), x3 = x1, x4 = x2; else if (fabs((float)(y2 - y1) / (x2 - x1)) != 1) { c...
4
#include <bits/stdc++.h> using namespace std; int main() { char tramp; string f, s; cin >> tramp >> f >> s; map<char, int> rank; rank['6'] = 1; rank['7'] = 2; rank['8'] = 3; rank['9'] = 4; rank['T'] = 5; rank['J'] = 6; rank['Q'] = 7; rank['K'] = 8; rank['A'] = 9; if (f[1] == tramp and s[1] !...
2
#include <bits/stdc++.h> using namespace std; int t, n, m; int main() { cin >> n; for (int i = sqrt(n);; i--) { if (n % i == 0) { cout << i << ' ' << n / i << endl; break; } } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5, M = 1e6 + 5, C = 1e3 + 5, MOD = 1e9 + 7, OO = 1e9 + 5; int fre[N][30]; int main() { cin.sync_with_stdio(false), cin.tie(0), cout.tie(0); string str; cin >> str; int q; cin >> q; int n = str.size(); for (int i = 0; i < n; ++i) { if (i...
10
#include <bits/stdc++.h> using namespace std; const long long M = 1000000007; void PV(vector<long long> v) { for (long long i = 0; i < v.size(); i++) cout << v[i] << " "; cout << "\n"; } void PA(long long v[], long long n) { for (long long i = 0; i < n; i++) cout << v[i] << " "; cout << "\n"; } void IN(long lon...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; map<int, long long> cnt; for (int i = 0, x; i < n; i++) { cin >> x; cnt[(i) % 2] += (x) / 2; cnt[(i + 1) % 2] += (x + 1) / 2; } cout << min(cnt[0], cnt[1]); return (0); }
12
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long powm(long long a, long long b) { long long r = 1; while (b) { if (b & 1) { r *= a; r %= mod; } b >>= 1; a *= a; a %= mod; } return r; } long long gcd(long long a, long long b, long long& x, long l...
9
#include <bits/stdc++.h> using namespace std; template <typename T> T abs(T x) { return x > 0 ? x : -x; } string s; int l, r, i, z[100005], sum[100005]; vector<int> ans; int main() { cin >> s; l = 0; r = 0; for (i = 1; i < s.size(); i++) { if (r >= i) z[i] = min(r - i + 1, z[i - l]); while (i + z[i] <...
12
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5+5; const int SQRTN = 450; int n,x; int p[N],d[N],id[N],val[N]; vector<int> g[N],posd[N],w[N]; bool f[SQRTN][N]; int k[SQRTN][N]; bool ans[N]; void dfs(int x){ posd[d[x]].push_back(x); for(int i=0;i<g[x].size();++i){ int y=g[x][i]...
23
#include <bits/stdc++.h> using namespace std; int main() { int maxi = 0, som = 0, n; cin >> n; int t[n + 1]; t[0] = 0; int pos_i, pos_f, max_pos; for (int i = 1; i <= n; i++) { cin >> t[i]; t[i] += t[i - 1]; } for (pos_f = n; pos_f > 0; pos_f--) { for (pos_i = 0; pos_i + pos_f <= n; pos_i++)...
6
#include <bits/stdc++.h> using namespace std; int main() { int formNumber, i, sum = 0; cin >> formNumber; int form[formNumber]; for (int i = 0; i < formNumber; i++) cin >> form[i]; for (i = 0; i < formNumber; i++) { for (int k = 0; k < formNumber; k++) { if (i == k) continue; sum = form[i] + f...
4
#include <bits/stdc++.h> using namespace std; set<pair<int, int>> nodeSet; set<pair<int, int>> alreadyTaken; queue<pair<int, int>> que; queue<int> dist; int x[] = {1, 1, 1, 0, 0, -1, -1, -1}; int y[] = {-1, 0, 1, -1, 1, -1, 0, 1}; pair<int, int> currentNode; pair<int, int> node; int currentDistance; int BFS(pair<int, i...
10
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5, M = 2e6 + 5, OO = 0x3f3f3f3f; const double EPS = 0.0000001, PI = 2 * acos(0.0); long long n, a, d, t, v; double last = 0, ans; int main() { cin.sync_with_stdio(0); cin >> n >> a >> d; while (n--) { cin >> t >> v; if (v * v / (2.0 * a) > ...
8
#include <bits/stdc++.h> using namespace std; int m, n, f1[200005], f2[200005], S[200005], T[21][1048600], Max; char str[200005][25]; int get(int A, int B) { int T1 = str[A][1] - '0', T2 = str[B][m] - '0', x = 1, s = 0; while (x <= m) { if (T1 == T2) s = x; x++; T1 = (T1 << 1) + str[A][x] - '0'; T2 ...
20
#include <bits/stdc++.h> using namespace std; int a[12]; int b[12]; int main() { int n, m, d, e, ii, jj, i, j; scanf("%d %d", &n, &m); memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); for (i = 0; i < n; i++) { scanf("%d", &d); a[d] = 1; } for (i = 0; i < m; i++) { scanf("%d", &e); b[e] = ...
1
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; s += '+'; long long ans = 0, cur = 0; int sign = +1; for (char c : s) { if (c == '+' || c == '-') { ans += sign * cur; cur = 0; c == '+' ? sign = +1 : sign = -1; } cur = cur * 10 + (c - '0'); } c...
16
#include <bits/stdc++.h> using namespace std; int n, maxa; int main() { scanf("%d", &n); while (n--) { int a; scanf("%d", &a); maxa = max(maxa, a); } printf("%d", max(maxa - 25, 0)); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long> c(n); for (int i = 0; i < n; i++) { cin >> c[i]; } long long ans = 0; for (int i = 0; i < n; i += 2) { long long l = 1, r = c[i]; for (int j = i + 1; j < n; j++) { if (j % 2 == 1) { ans ...
10
#include <bits/stdc++.h> using namespace std; void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); } template <class T1, class T2> inline void gmax(T1 &a, T2 b) { if (b > a) a = b; } template <class T1, class T2> inline void gmin(T1 &a, T2 b) { if (b < a) a = b; ...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 2; vector<int> g[maxn]; vector<long long> c[maxn], acum[maxn]; int n, m, q, idx, comp[maxn]; long long d[maxn], dist[maxn]; map<pair<int, int>, long long> memo; vector<int> cur; void dfs(int node, int par) { comp[node] = idx; cur.push_back(node); ...
17
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 15; long long L[N], odd[N], R[N]; int ar[N]; int main() { int pos = 1; int n; cin >> n; long long ret = 0; for (int i = 1; i < n; ++i) { scanf("%d", &ar[i]); ret = max(ret, (long long)ar[i]); } L[1] = 0; for (int i = 2; i <= n; ++...
12
#include <bits/stdc++.h> using namespace std; int n; string keyboard1, keyboard2, s1; pair<char, char> translate[26]; int main() { cin >> keyboard1 >> keyboard2 >> s1; n = s1.size(); for (int i = 0; i < 26; i++) { translate[i].first = char(keyboard1[i]); translate[i].second = char(keyboard2[i]); } for...
0
#include <bits/stdc++.h> using namespace std; int n; int l, r, u, d; int main() { cin >> n; int c1 = 0, c2 = 0, c3 = 0; for (int i = 0; i < n; ++i) { string s; cin >> s; if (s == "UL" || s == "DR") ++c1; else if (s == "UR" || s == "DL") ++c2; else ++c3; } cout << (long lo...
9
#include <bits/stdc++.h> using namespace std; char c[505]; int a[505][505], f[250005], g[250005], h[250005], s; bool v[505][505]; int find(int x) { if (f[x] == x) return x; else return f[x] = find(f[x]); } void merge(int x) { x = find(x); if (!g[x]) s += h[x]; g[x]++; } void del(int x) { x = find(x)...
16
#include <bits/stdc++.h> using namespace std; double A, B, X, sum, k; int a[100001], n; int main() { cin >> n >> A >> B; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } X = a[1]; sort(a + 2, a + n + 1); if (A * (X / sum) >= B) { cout << 0; return 0; } for (int i = n; i >= 2; i...
2
#include <bits/stdc++.h> using namespace std; map<string, int> d, d1; map<string, int>::iterator i1; int a, s, f, g[10005], h, j, k, l, c, v, b, n, mx = 0, q, w, e, r, t, y, u, i, o, p; string x[10005], z; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> z >...
7
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const long long INF = (1e9); char str[(3000 + 4)]; vector<vector<int>> f; int main() { int n, k; scanf("%d%d", &n, &k); scanf("%s", str + 1); int mx = 0; while (1) { vector<int> t; for (int i = 1; i < n; i++) { if (st...
13
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(); string S; cin >> S; long long a = 0, b = 0, c = 0; for (int i = 0; i < (int)S.size(); i++) if (S[i] == 'o') b += a; else if (i > 0 && S[i - 1] == 'v') { a++; c += b; } cout << c << ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, k, m; double l, v1, v2, l1; cin >> n >> l >> v1 >> v2 >> k; m = (n - 1) / k; l1 = (v1 + v2) * l / ((2. * m + 1.) * v1 + v2); printf("%.8f", (l1 / v2 + (l - l1) / v1)); }
11
#include <bits/stdc++.h> using namespace std; struct node { int u, v, val, id, dep; node() {} node(int u1, int v1, int val1, int id1) : u(u1), v(v1), val(val1), id(id1) {} bool operator<(const node &a) const { if (val != a.val) return val < a.val; return dep > a.dep; } } l[100010]; long long ans[10001...
15
#include <bits/stdc++.h> using namespace std; template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != ',') cerr << *sdbg++; cerr << '=' << h << ','; _dbg(sdbg + 1, a...); } template ...
18
#include <bits/stdc++.h> using namespace std; long long POW(long long A, long long N, long long MOD) { if (N == 0) return 1 % MOD; if (N == 1) return A % MOD; long long tmp = POW(A, N / 2, MOD) % MOD; if (N % 2) return ((tmp * tmp) % MOD * A % MOD) % MOD; else return (tmp * tmp) % MOD; } long long MUL...
10
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int m, n, a[100005], b[100005]; long long sum = 0; cin >> m; for (int i = 1; i <= m; i++) cin >> a[i]; sort(a + 1, a + 1 + m); cin >> n; for (int i = 1; i <= n; i++) cin >> b[i]; sort(b + 1, b + 1 + n); sum = 0; while (...
6
#include <bits/stdc++.h> using namespace std; vector<long long> vec; map<long long, long long> mp; vector<long long> adj[1000009]; long long arr[1000009], need[1000009]; bool sign[1000009]; int32_t main() { long long i, j, n, m, k, d, a, b, p, sum = 0, ans = 0, mini = 199999999999, ...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; const long long MOD = 1000000007; const double EPS = 1e-6; int arr[55][55]; int n, m; int numberOfInRow(int num, int i) { int res = 0; for (long long j = 0; j < (int)m; j++) if (arr[i][j] == num) res++; return res; } int ...
5
#include <bits/stdc++.h> using namespace std; const int N = 200005; const int LOGN = 18; const long long INF = 1.1e18; struct Dat { long long a; int w, v, id; } dat[N]; struct Node { long long sw[LOGN], sv[LOGN], aw[LOGN], av[LOGN]; } st[N * 4]; int n, q, idx[N]; void Upd(int i, int l, int r, int lf, int rg) { if (...
26
#include <bits/stdc++.h> using namespace std; const long long INF = 0x3f3f3f3f3f3f3f3f; const long long inf = 0xc0c0c0c0c0c0c0c0; const double pi = acos(-1); const int MAXN = 3e5 + 7; const int MAXA = 2; const int MAX = MAXN * 30; int tree[MAX][MAXA]; int C[MAX]; int root, cnt; int m[MAXN]; int N; int query(int str) { ...
10
#include <bits/stdc++.h> using namespace std; struct rect { int x1, x2, y1, y2; int maxval; rect() {} rect(int a, int b, int c, int d) { x1 = a; y1 = b; x2 = c; y2 = d; } }; vector<rect> rec; int n, m; string s[1111]; vector<int> mustx, musty; vector<int> vx, vy; void Print(rect fuk) { cout ...
18
#include <bits/stdc++.h> const int MOD = 1e9 + 7; const int N = 1e5 + 110; const int K = 100 + 10; int n, m; int c[K][N]; int CC[N][K]; inline void qmod(int &x) { x = (x >= MOD) ? (x - MOD) : x; } int main() { int i, j, x; int l, r, k; for (i = int(0); i <= int(N - 1); i++) { CC[i][0] = 1; for (j = 1; j <...
17
#include <bits/stdc++.h> using namespace std; mt19937 azino(1337); const long double PI = 3.14159265358979323846; void io() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); } const int32_t MOD = 1e9 + 7; int32_t add(int32_t a, int32_t b) { if (a + b < MOD) return a + b; ...
15
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; scanf("%lld%lld", &n, &k); vector<long long> v; long long x; map<long long, long long> make_pair; for (long long i = 0; i < n; i++) { scanf("%lld", &x); v.push_back(x); make_pair[x]++; } sort(v.begin(), v.end()); lo...
4
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; using PQ = priority_queue<ll>; using PQG = priority_queue<ll, vector<ll>, greater<ll>>; using PQP = priority_queue<P>; using PQPG = priority_queue<P, vector<P>, greater<P>>; template <class T> usi...
7
#include <bits/stdc++.h> using namespace std; const int M = 200; int uv, n, t, k, root, r, h, num, anum[] = {6, 2, 0}, arad[] = {3, 2, 1}; vector<int> v, vb, g[M]; bool mark[M]; void ask(int u) { if (mark[u]) return; cout << "? " << u << endl; mark[u] = true; cin >> k; if (k == 2) root = u; for (int i = 0; ...
20
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-8; const int N = 2005; struct node { double x, y, k; int px, py; } a[N * N]; double mid_x, mid_y; int n, x[N], y[N], ans, k, t, p[N], die[N], X[N], Y[N], cnt, lst, pos; bool cmp(const node &A, const node &B) { return A.k...
21
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pii pair<int, int> #define rep(i, a, b) for(ll i = a; i < b; i++) #define rfor(i, b, a) for(ll i = b; i >= a; i--) #define X first #define Y second #define pb push_back #define play {ios_base::sync_with_stdio(false);}...
4
#include <bits/stdc++.h> using namespace std; const int maxN = 1100; int used[maxN]; vector<int> g[maxN]; vector<int> query; int n; void dfs(int v, int p, int dep, int target) { if (used[v]) { return; } used[v] = 1; if (target == dep) { query.push_back(v); return; } for (int i = 0; i < g[v].size...
16
#include <bits/stdc++.h> using namespace std; int main() { long long a; cin >> a; for (int i = 0; i < a; i++) { long long b, c, d; cin >> b >> c >> d; long long ans = (b + c + d) / 2; cout << ans << '\n'; } }
0
#include <bits/stdc++.h> using namespace std; const int MAX = 200005; int a[MAX], X[MAX], Y[MAX], idxX, idxY; int main() { int n, l, x, y; scanf("%d %d %d %d", &n, &l, &x, &y); for (int i = 0; i < n; ++i) { scanf("%d", a + i); } bool checkX = 0, checkY = 0; for (int i = 0; i < n; ++i) { if (binary_s...
9
#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; vector<int> V(10000); for(int i = 1;i<10000;i++) { V[i] = V[i-1] + i; } while(t--) { int n; cin>>n; int i = lower_bound(V.begin(),V.end(),n) - V.begin(); if(V[i] == n + 1) ...
4
#include <bits/stdc++.h> using namespace std; const int M = (1 << 24) + 10; const int inf = 0x3f3f3f3f; int n, sx, sy; int dp[M], las[M], res[2][M]; int x[30], y[30], c[30][30]; inline int cost(int x1, int y1, int x2, int y2) { int dx = x1 - x2, dy = y1 - y2; return dx * dx + dy * dy; } inline int lowbit(int x) { r...
12
#include <bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; long long n, m, l, s, vl[100002], vs[100002], spl; long long q, xa, ya, xb, yb; long long bls(long long nr) { if (nr < vl[1]) return -1; int b = 1; int e = l; long long sol = -1; while (b <= e) { int mid = (b + e) / 2; if (vl[mid...
8
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int l1, l2, l3; cin >> l1 >> l2 >> l3; if (l1 + l3 == l2 || l1 + l2 == l3 || l2 + l3 == l1) cout << "YES" << endl; else if ((l1 == l2 && l3 % 2 == 0) || (l2 == l3 && l1 % 2 == 0) || ...
0