solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 10; const double eps = 1e-9; const int inf = 1e9; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; int vis[100][100]; int n, m; bool rng(int i, int j) { return i > -1 && i < n && j > -1 && j < m; } char a[100][100]; void dfs(int i, int j, int dir, in...
9
#include <bits/stdc++.h> using namespace std; const int N = 105, mod = 1e9 + 9; inline int qpow(int x, int y = mod - 2) { int res = 1; for (; y; y >>= 1, x = 1ll * x * x % mod) if (y & 1) res = 1ll * res * x % mod; return res; } int fac[N], ifac[N], inv[N]; int C(int x, int y) { if (y < 0 || y > x) return 0...
21
#include <bits/stdc++.h> using namespace std; int main() { map<string, int> m; int n; cin >> n; pair<string, int> arr[n]; int t = n; int u = n; int i = 0; while (t--) { string s; int p; cin >> s >> p; arr[i].first = s; arr[i].second = p; i++; m[s] += p; } int max = 0; f...
7
#include <bits/stdc++.h> using namespace std; const int N = 100010; const long long inf = 1LL << 60; int n, m, k, cnt, cst[N], vis[N], id[N], d[N], f[N], t[N], c[N]; long long h[N * 10], g[N * 10], cur; inline bool cmp(const int &a, const int &b) { return d[a] < d[b]; } int main() { scanf("%d%d%d", &n, &m, &k); for...
10
#include <bits/stdc++.h> using namespace std; using i64 = long long; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); int n, x, y; cin >> n >> x >> y; string s; cin >> s; i64 ans = 0; for (int i = 0; i < s.size();) { if (s[i] == '0') { int j = i; while (s[j] == '0') j++; ...
7
#include <bits/stdc++.h> using namespace std; const int tope = 1e5 + 5; int n; vector<long long> menores; vector<long long> edad; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; long long aux; cin >> aux; edad.push_back(aux); menores.resize(n); for (int i = 1; i < n; i++) { cin >> a...
7
#include <bits/stdc++.h> using namespace std; int test[1000]; int main() { int n, k, p, x, y; scanf("%d%d%d%d%d", &n, &k, &p, &x, &y); int i; int sum = 0; int lowm = 0, highm = 0; for (i = 1; i <= k; i++) { scanf("%d", &test[i]); sum += test[i]; if (test[i] < y) lowm++; if (test[i] >= y) hig...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int prime[N], inf[N], pcnt; void primer(int n) { pcnt = 0; for (int i = 2; i <= n; i++) { if (!inf[i]) { prime[++pcnt] = i; } for (int j = 1; j <= pcnt; j++) { if (prime[j] > n / i) break; inf[prime[j] * i] = 1; ...
12
#include <bits/stdc++.h> using namespace std; int main() { int num, num_oper; cin >> num; cin >> num_oper; while (num_oper != 0) { if ((num % 10) == 0) { num /= 10; } else { num--; } num_oper--; } cout << num; return 0; }
0
#include <bits/stdc++.h> using namespace std; inline int read() { int res = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -f; ch = getchar(); } while (isdigit(ch)) { res = (res << 1) + (res << 3) + (ch ^ 48); ch = getchar(); } return res * f; } inline void write(...
2
#include <bits/stdc++.h> using namespace std; const int Maxk = 1005; string mul(string a, string b) { int res[Maxk]; memset(res, 0, sizeof(res)); reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); for (int i = 0; i < a.length(); i++) { for (int j = 0; j < b.length(); j++) { res[i + j] += (a[i...
10
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; stack<char> st; bool player1 = false; st.push('#'); for (int i = 0; i < s.size(); i++) { if (st.top() == s[i]) { player1 = !player1; st.pop(); } else { st.push(s[i]); } } if (player1) { cout ...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; char s[1000]; int k, n, ans = 10; int t[1000], c[1000000]; set<int> v; int check(int a) { memset(c, 0, sizeof(c)); for (typeof(v.begin()) it = v.begin(); it != v.end(); it++) { c[a & (*it)]++; if (c[a & (*it)] > 1) return 0; } retu...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 310000; long long cal(long long a, long long b) { return (a + b) * (b - a + 1ll) / 2; } int n, m, q; vector<int> V[maxn]; struct edge { int y, nex; } a[maxn << 1]; int len, fir[maxn]; inline void ins(const int x, const int y) { a[++len] = (edge){y, fir[...
15
#include <bits/stdc++.h> using namespace std; template <typename T> using vc = vector<T>; using pii = pair<long long, long long>; void xmax(long long& a, long long b) { a = max(a, b); } void xmin(long long& a, long long b) { a = min(a, b); } vc<pii> seg; long long pow2(long long k) { long long kk = 1; while (kk < k...
15
#include <bits/stdc++.h> using namespace std; const double E = 1e-8; const long long MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n; cin >> n; int a[n - 1], b[n - 1]; for (int i = 0; i < n - 1; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) cin >> b[i]; ...
5
#include <bits/stdc++.h> using namespace std; template <class T> inline bool isLeap(T y) { return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false); } template <class T> inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); } template <class T> inline T lcm(T a, T b) { return ((a) / gcd((a), (b))...
5
#include <bits/stdc++.h> using namespace std; void solve() { long long n, i, j; cin >> n; long long a[n + 1], b[n + 1], c[n + 1]; for (i = 1; i <= n; i++) { cin >> a[i]; c[i] = a[i]; } sort(c + 1, c + 1 + n); long long one = -1, zero = -1; for (i = 1; i <= n; i++) { cin >> b[i]; if (b[i]...
5
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; const int mod = 1e9 + 7; int n, a[N], b[N], p[N]; bool fail = 1; int main() { ios_base::sync_with_stdio(0); cin >> n; int cur = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; if (x == 0) continue; a[++cur] = x; } cur = ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { int n, m, k; cin >> n >> m >> k; if (n % 2 == 0 && m % 2 == 0) { if (k % 2 == 0) { cout << "YES" << endl; } else { cout <...
9
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; vector<int> adj[300001]; vector<int> color(300001, -1); vector<int> vis(300001, 0); void dfs(int s, int sc, int gc) { vis[s] = 1; int j = 1; for (auto u : adj[s]) if (!vis[u]) { while (j == sc || j == gc) j++; color[u] = j; ...
8
#include <bits/stdc++.h> using namespace std; int main() { string s[12], a; int i, k, m; s[0] = "December"; s[1] = "January"; s[2] = "February"; s[3] = "March"; s[4] = "April"; s[5] = "May"; s[6] = "June"; s[7] = "July"; s[8] = "August"; s[9] = "September"; s[10] = "October"; s[11] = "Novemb...
1
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1); const int _ML = 30; const char _inpf[] = ""; const char _outf[] = ""; template <typename T, typename U> inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) { _out << _p.x << ' ' << _p.y; return _out; } template <typename T, t...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; long long int count = 0, same = 1; for (int i = 0; i < n - 1; i++) { if (a[i] == a[i + 1]) { same++; } else { for (long j = 1; j ...
5
#include <bits/stdc++.h> using namespace std; int a[555][555], ans[555]; int n, m, q; void calc(int i) { ans[i] = 0; for (int j = 1; j <= m;) { if (a[i][j] == 0) { ++j; continue; } int k; for (k = j + 1; k <= m && a[i][k] == 1; k++) ; ans[i] = max(ans[i], k - j); j = k; }...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; if (n % 2 == 0) { cout << -1 << '\n'; return 0; } int a[n], b[n]; int cnt = 2; for (int i = 0; i < n; i++, cnt += 2) { a[i] = cnt % n; b[i] = (i - a[i] + n) %...
5
#include <bits/stdc++.h> using namespace std; const int oo = (int)1e9 + 7; const int N = (int)1e5 + 5; vector<int> adj[N]; vector<int> ans; int root; void dfs(int u, int p = -1) { for (int node : adj[u]) if (node != p) dfs(node, u); if ((int)((adj[u]).size()) == 1 && p != -1) ans.push_back(u); } int main() { ...
6
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; int n, m, k; uint8_t a[10][10]; uint8_t g[10]; int sol; uint8_t dg[10]; void chk(int mask) { if (n - __builtin_popcount(mask) !...
17
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); string A; cin >> A; for (int i = 0; i < 6; i++) { A[i] -= 48; } int s1 = A[0] + A[1] + A[2]; int s2 = A[3] + A[4] + A[5]; if (s1 == s2) { cout << 0; return 0; } if (s1 > s2) { swap(A[0], A[3]...
8
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); int tab; auto geti = [&]() { cin >> tab; return tab; }; ; long long n, k, m, d; cin >> n >> k >> m >> d; long long res = m;...
12
#include <bits/stdc++.h> using namespace std; int main() { int i, a, b, res; cin >> a >> b; res = 1; for (i = 1; i <= min(a, b); i++) res *= i; cout << res; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; string w; cin >> n >> w; int c1 = 0, c2 = 0; for (int color1 = 0, color2 = 1, i = 0; i < n; i++, color1 ^= 1, color2 ^= 1) { c1 += ((w[i] - '0') != color1); c2 += ((w[i] - '0') != color2); } cout << min(c1, c2) << '\n'; ret...
10
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 7; long long n, m, k, x, y, ans, cnt, g[N]; int main() { cin >> n >> m >> k; if (n & 1) for (int i = 1; i * i <= m; i++) if (m % i == 0 && ((m / i >= k && i > 1) || (i >= k && m / i > 1))) { cout << "Timur\n"; return 0;...
12
#include <bits/stdc++.h> using namespace std; struct Dsu { int n; vector<int> par; vector<long long> mn, mx; void init(vector<long long> const& pref) { n = pref.size(); par = vector<int>(n, 0); mn = mx = vector<long long>(n, 0); iota(par.begin(), par.end(), 0); for (int i = 1; i < n; i++) { ...
16
#include <bits/stdc++.h> using namespace std; char s[1000]; int main() { int n, b, a; bool flag = false; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%s", s); scanf("%d", &b); scanf("%d", &a); if (b >= 2400 && a - b > 0) flag = true; } if (flag) printf("YES\n"); else prin...
0
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int n = s.size(); vector<char> ans(n); vector<int> ind; for (int i = 0; i < n; i++) if (s[i] != t[i]) { ind.push_back(i); } if (ind.size() & 2 != 0) cout << "impossible"; else { for (int i = 0; i...
3
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = (int)1e9 + 7; const int N = (int)1e6 + 7; int n, m; vector<int> row, col; void Init() { row.clear(); col.clear(); for (int i = (0); i < (n); ++i) { int x; scanf("%d", &x); ...
9
#include <bits/stdc++.h> using namespace std; long double dp[111][111], q; int mp[1001], n; char ar[105]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> q; int i, j, k; dp[0][0] = 1; long double ans = 0; for (i = 1; i <= n; i++) { cin >> ar[i]; for (j = 0; j <= i; j++) {...
12
#include <bits/stdc++.h> using namespace std; int main() { int ans = 0, n, a2[1000], b2[1000]; string a, b; cin >> n; cin >> a; cin >> b; for (int i = 0; i < a.size(); i++) { a2[i] = a[i] - 48; b2[i] = b[i] - 48; } int q, w; for (int i = 0; i < a.size(); i++) { q = min(a2[i], b2[i]); w...
0
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const int N = 1e6 + 4; long long me(long long a, long long b) { if (b < 0) return 0; long long res = 1; while (b) { if (b & 1) res = (res * a) % mod; b >>= 1; a = (a * a) % mod; } return res; } int main() { int n; s...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 123456 + 100; const int inf = 1 << 23; vector<int> mp[maxn]; int vis[maxn]; int vis2[maxn]; int ans1, ans2, depth, sum; void dfs(int x, int pre, int dep) { if (vis[x] && dep > depth) { depth = dep; ans2 = x; } if (vis[x] && depth == dep && x <...
14
#include <bits/stdc++.h> using namespace std; long long n, m, k, y, z, l, i, j, x, r; long long a[100500], b[100500]; vector<long long> g[200500]; long long dp[200500][2]; long long binpow(long long x, long long y) { if (y == 0) { return 1; } long long tmp = binpow(x, y / 2); tmp = tmp * tmp % 998244353; ...
17
#include <bits/stdc++.h> using namespace std; int conversion(string p) { int num; num = atoi(p.c_str()); return num; } string toString(int h) { stringstream ss; ss << h; return ss.str(); } long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } long long lcm(long long a, long long b...
4
#include <bits/stdc++.h> using namespace std; const long long INF64 = (long long)(1e18); long long add(long long x, long long y) { return min(x + y, INF64); } int A1[255][2], A3[255][255], n, m, z, p[255]; long long A2[255][255], k; void build(const string& s) { z = (int)(s.size()), p[0] = 0; for (int i = 1; i < z;...
19
#include <bits/stdc++.h> void mergeSort(int arr[], int low, int mid, int high); void partition(int arr[], int low, int high); int x[100005]; int y[100005]; int main() { int n; scanf("%d", &n); int i; for (i = 0; i < n; i++) scanf("%d", &x[i]); for (i = 0; i < n; i++) y[i] = x[i]; partition(y, 0, n - 1); i...
5
#include <bits/stdc++.h> #pragma GCC optimize "O3" using namespace std; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int N = 2e5 + 5; const int M = 1 << 18; pair<long long, int> tree[M * 2 + 5]; long long lazy[M * 2 + 5]; int n, ans[N]; void push(int v) { tree[v * 2].first += lazy[v]; ...
11
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; int main() { int n; scanf("%d", &n); map<int, int> c, f; map<int, vi> grp; int last = 0, t, l, r, x; for (auto i = (0); i < (n); i++) { if (last == -1) last = 1; scanf("%d%d%d", &t, &l, &r); l ^= last, r ^= last; if (l > r...
16
#include <bits/stdc++.h> using namespace std; char m[1000][1000]; int main() { int n, count = 0, max = 0, k, r = 0; char c[100000]; bool l = true; string s; for (int i = 0; i < 1000; i++) for (int y = 0; y < 1000; y++) m[i][y] = ' '; cin >> n; for (int i = 0; i < n; i++) { cin >> c[i]; if (c[i...
6
#include <bits/stdc++.h> using namespace std; map<long long int, long long int> r, c; void sol() { int n, m, ans = 0; cin >> n >> m; long long int ar[n + 1][m + 1]; for (long long int i = 1; i <= n; i++) { for (long long int j = 1; j <= m; j++) { cin >> ar[i][j]; if (!ar[i][j]) r[i]++, c[j]++; ...
4
#include <bits/stdc++.h> using namespace std; inline long long read() { long long 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; } int m, n, p; int cnt(int ...
8
#include <bits/stdc++.h> using namespace std; int x, os[100][100], kv[100], otv[100]; ; int prov(int ii) { int z = 0; for (int i = 1; i < x; i++) { for (int iii = 0; iii < kv[i]; iii++) { if (os[i][iii] == os[0][ii]) z++; } } return z; } int main() { cin >> x; for (int i = 0; i < x; i++) { ...
0
#include <bits/stdc++.h> long long ans, n, m, i, j, k, a[10]; using namespace std; long long c(long long n, long long m) { long long h, t; long long i; h = 1; if (m == 7 && n > 500) { for (i = n - m + 1; i <= n - 1; i++) h *= i; t = h / a[6] * n / 7; return t; } for (i = n - m + 1; i <= n; i++) ...
5
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[1000000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++; } int read() { int pos = 1, num = 0; char ch = getchar(); while (!isdigit(ch)...
11
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 1000000009; void solution() { long long n = 0; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; long long b[n]; for (long long i = 0; i < n; i++) b[i] = -1; set<long long> s; for (long long ...
8
#include <bits/stdc++.h> using namespace std; string s, a, b; int to[27], k, T; bool vis[27]; bool up(int dir) { if (dir == s.size()) return 1; if (to[s[dir] - 'a'] != -1) { int t = to[s[dir] - 'a']; if (t > a[dir] - 'a') return 1; if (t < a[dir] - 'a') return 0; return up(dir + 1); } for (int i...
15
#include <bits/stdc++.h> using namespace std; int main() { int a[24], i, j, k; for (i = 0; i < 24; ++i) cin >> a[i]; int p[8], q[8]; set<int> s; for (i = 0; i < 4; ++i) s.insert(a[i]); if (s.size() == 1) { s.clear(); for (i = 8; i < 12; ++i) s.insert(a[i]); if (s.size() == 1) { p[0] = a[12...
7
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 0, 1, -1}; const int dy[] = {1, -1, 0, 0}; int p[5]; char s[55][55]; int n, m; char opt[105]; int main() { scanf("%d%d", &n, &m); int sx, sy; for (int i = 1; i <= n; ++i) { scanf("%s", s[i] + 1); for (int j = 1; j <= m; ++j) if (s[i]...
4
#include <bits/stdc++.h> using namespace std; int main() { int z; cin >> z; while (z--) { long long n; cin >> n; long long i = 0, f = 0, g = 0, a[n], b[n], an = 0, j = 1; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) cin >> b[i]; for (i = 0; i < n; i++) { if (b[i] > a[...
3
#include <bits/stdc++.h> using namespace std; struct Segment { int left, right; Segment *leftSon, *rightSon; bool full; void init(int l, int r); int get(int l, int r); }; void Segment::init(int l, int r) { left = l; right = r; full = false; if (l < r) { int m = (l + r) / 2; leftSon = new Segme...
14
#include <bits/stdc++.h> using namespace std; int mod(int n) { return n >= 0 ? n : -n; } int main() { int a, b; cin >> a >> b; if (a == 0 && b == 0 || a == 1 && b == 0) { cout << 0; return 0; } if (mod(a) > mod(b) && a + b != 1) b = a; if (mod(b) > mod(a)) a = -b; if (a >= 0 && b >= 0) { cout ...
6
// #include <bits/stdc++.h> using namespace std; #define task "" #define maxn 1005 #define maxm #define maxs #define bug(a) cerr << int (a) << "\n" #define ms(a,b) memset (a, b, sizeof (a)) #define p_b push_back #define x first #define y second #define oo 200...
0
#include <bits/stdc++.h> using namespace std; char Map[155][155]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) cin >> Map[i][j]; } int starti = 1, startj = 1, res = 0; for (int i = 1; i <= n; i++) { if (i % 2 == 1) { for (int j = 1; j <= m; ...
7
#include <bits/stdc++.h> using namespace std; int main() { string s[105]; int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> s[i]; } int cc[105], ci = 0; int i, j; int ans = 0; int f = 0; int so = 0; for (i = 0; i < m; i++) { f = 0; for (j = 1; j < n; j++) { if (s[j][i...
7
#include <bits/stdc++.h> using namespace std; const int MAXL = 400011; const int MOD = 1000000007; int sr; int sum(int a, int b) { sr = a + b; if (sr >= MOD) sr -= MOD; return sr; } int mul(int a, int b) { return (int)((1LL * a * b) % (1LL * MOD)); } int pow(int a, int k) { int ret = 1, t = a; while (k) { ...
16
#include <bits/stdc++.h> using namespace std; template <class T> bool uax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; } template <class T> bool uin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; } const int inf = 1e9 + 100500; const int MAXN = 2...
14
#include <bits/stdc++.h> using namespace std; inline void cp() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } signed main() { cp(); int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } int a, b; cin >> a >> b; if (a > b) { int temp; ...
0
#include <bits/stdc++.h> using namespace std; int qpow(int base, int n) { int ans = 1; while (n) { if (n & 1) ans = 1ll * ans * base % 1000000007; base = 1ll * base * base % 1000000007; n >>= 1; } return ans; } int inv(int x) { return qpow(x % 1000000007, 1000000007 - 2); } int l[200010], r[200010],...
17
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); int main(int argc, char **argv) { int N; int X0, Y0; cin >> N >> X0 >> Y0; vector<pair<int, int> > P(N); vector<double> seen; for (int i = (0); i < (N); ++i) { cin >> P[i].first >> P[i].second; double q = atan2(P[i].second - Y...
6
#include <bits/stdc++.h> using namespace std; string s1, s2; map<char, char> mp; map<pair<char, char>, int> ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> s1 >> s2; for (int i = 0; i < s1.size(); i++) { char a = s1[i], b = s2[i]; if (mp[a] == 0) mp[a] = b; if (mp[b] == 0) mp[b] =...
7
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(long long &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template <clas...
15
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; if (a == b) cout << a; else cout << 1 << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int sum = 0; vector<int> cnt(3, 0); for (int i = 0; i < s.size(); i++) { int x = s[i] - '0'; cnt[x % 3]++; sum += x % 3; } if (sum % 3 == 0) { cout << s; return 0; } if (!cnt[1]) { if (cnt[2] < 3 && ...
12
#include <bits/stdc++.h> using namespace std; int main() { int arr[4]; int i; for (i = 0; i < 4; i++) { cin >> arr[i]; } sort(arr, arr + 4); if (arr[0] + arr[3] == arr[1] + arr[2] || arr[0] + arr[1] + arr[2] == arr[3]) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long N = 200; long long a[N]; int32_t main() { ios::sync_with_stdio(false); long long n; cin >> n; for (long long i = 0; i < n; i++) cin >> a[i]; long long ans = 0; if (a[0] == 1) { long long id = 0; for (long long i = 1; i < n; i++) if ...
5
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; void yes() { cout << "YES" << endl; } void no() { cout << "NO" << endl; } bool compare(pair<long long int, pair<long long int, long long int> > &a, pair<long long int, pair<long long int, long long int> > &b) { if (a.first == b.fi...
6
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; for (int i = 1; i <= t; ++i) { long long n, d, p = 0; cin >> n >> d; for (int j = 0; j <= 1000000; ++j) { if (d % (j + 1) == 0 && j + (d / (j + 1)) <= n) { p++; } if (d % (j + 1) != 1 && j + (d ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s, s1, s2 = "YCM"; cin >> s; s1 = s; for (int i = 0; i < n; i++) { if (s[i] == s[i + 1] && s[i] != '?') { cout << "No\n"; return 0; } } for (int i = 0; i < n; i++) { if (s[i] != '?') continue; ...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 9; set<int> ist; map<string, int> msi; map<string, string> mss; map<int, string> mis; map<int, int> mii; pair<int, int> pii; vector<int> v; vector<pair<int, int> > vv; int cc[] = {1, -1, 0, 0}; int rr[] = {0, 0, 1, -1}; void JTK_1() { int t; int a,...
0
#include <bits/stdc++.h> using namespace std; struct IO { char buf[(1 << 20)], *p1, *p2; char pbuf[(1 << 20)], *pp; IO() : p1(buf), p2(buf), pp(pbuf) {} inline char gc() { return getchar(); if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, (1 << 20), stdin); return p1 == p2 ? ' ' : *p1++; } inline b...
19
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, k, counter = 0, count = 0, cou = 0, ma = 0; cin >> n >> m >> k; long long int arr[m], mas[k], ans[m]; for (long long int i = 0; i < m; i++) { cin >> arr[i]; } for (long long int i = 0; i < k; i++) { cin >> mas[i]; } f...
5
#include <bits/stdc++.h> #pragma GCC optimize(3) #pragma GCC optimize(2) using namespace std; inline void ckmax(int &a, int b) { a = max(a, b); } inline void ckmin(int &a, int b) { a = min(a, b); } inline int read() { int num = 0, flag = 1; char c = ' '; for (; c > '9' || c < '0'; c = getchar()) if (c == '-')...
14
#include <bits/stdc++.h> using namespace std; vector<long double> fgs; void doit() { long long n, l; cin >> n >> l; fgs.clear(); fgs.push_back(0); long double loc; for (long long i = 0; i <= n - 1; i++) { cin >> loc; fgs.push_back(loc); } fgs.push_back(l); long long f_left = 0; long long f_r...
7
#include <bits/stdc++.h> using namespace std; int main() { char a[10005]; cin >> a; int i = 0, len = strlen(a), flag = 0; for (; i < len; i++) { if (a[i] == 'h') { flag++; i++; break; } } for (; i < len; i++) { if (a[i] == 'e') { flag++; i++; break; } } ...
0
/* Hey why peeping here -_'_- ? I believe on myself and I will achieve this->author = Fuad Ashraful Mehmet, CSE ,University of Asia Pacific Todo: https://www.youtube.com/watch?v=hw_HpTI_Wkw&ab_channel=YRF https://codeforces.com/problemset/page/5?tags=1500-2500 */ #include <bits/stdc++.h> #define forn(i, n) for (int i ...
15
#include <bits/stdc++.h> long long fast_expo(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = (res * a) % 1000000007; a = (a * a) % 1000000007; b = b >> 1; } return res; } int main() { long long fact[200001]; int i, n; fact[0] = 1; for (i = 1; i < 200001; i++) ...
11
#include <bits/stdc++.h> using namespace std; const int Nmax = 300000 + 5; pair<pair<int, int>, int> v[Nmax]; priority_queue<int, vector<int>, greater<int> > q; int n, k, ans, poz; int main() { cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> v[i].first.first >> v[i].first.second; v[i].second = i; } ...
13
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& os, vector<T> V) { os << "[ "; for (auto v : V) os << v << " "; return os << "]"; } template <class T> ostream& operator<<(ostream& os, set<T> S) { os << "{ "; for (auto s : S) os << s << " "; return os << "}"; } t...
7
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; int ans = 1024; int n = s.size(); int tmp = 0; for (int i = 0; i < n; ++i) if (s[i] == '0') tmp++; ans = min(ans, tmp); tmp = 0; for (int i = 0; i < n; ++i) if (s[i] == '1') tmp++; ans = min(ans, tmp); for (in...
6
#include <bits/stdc++.h> using namespace std; const long long DESPACITO = 1000000000000000000; auto Try = [](const vector<long long>& a, long long k) { long long res = 0; for (long long i = 0; i < (long long)(a).size() - 1; i++) res += min(a[i] % k, k - (a[i] % k)); return res; }; int32_t main() { ios::sync...
13
#include <bits/stdc++.h> using namespace std; struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; long long int gcd(long long int a, long long int b) { if (b ...
7
#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 int l, r; cin >> l >> r; if (r < 2 * l) cout << "-1 -1" << "\n"; else cout << l << " " << 2 * l << "\n"; } return 0; }...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using vb = vector<bool>; using vc = vector<char>; using vd = vector<double>; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pi = pair<int, int>; using pll = pair<ll, ll>; int a[8] = {-1, -1, -1, ...
7
#include <bits/stdc++.h> using namespace std; int main() { int a[3]; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); if (a[0] == 1) { cout << "YES" << endl; return 0; } if (a[0] == a[1] && a[0] == 1) cout << "YES" << endl; else if ((a[0] == a[1] && a[1] == 2) or (a[1] == a[2] && a[1] == 2) or ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, i, a[100000], counter1 = 0, counter2 = 0, counter3 = 0, counter4 = 0, taxi_count = 0; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) counter1++; else if (a[i] == 2) counter2++; els...
3
#include <bits/stdc++.h> using namespace std; const int N = 1000; const int inf = (int)1e9 + 1; const long long big = (long long)1e18 + 1; const int P = 31; const int MOD = (int)1e9 + 7; const int MOD1 = (int)1e9 + 9; const double eps = 1e-6; const double pi = atan2(0, -1); int main() { ios_base::sync_with_stdio(0); ...
13
#include <bits/stdc++.h> using namespace std; const long long int M = 1e9 + 7; long long int arr[2002], ans[2002]; long long int power(long long int a, long long int b) { long long int val = 1; while (b) { if (b % 2) val = (val * a) % M; a = (a * a) % M; b /= 2; } return val; } int main() { long l...
11
#include <bits/stdc++.h> using namespace std; const int INF = 1000 * 1000 * 1000 + 5; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { ios_base::sync_with_stdio(false); int n, m, x, y, a, b; cin >> n >> m >> x >> y >> a >> b; int g = gcd(a, b); a /= g; b /= g; int l = 1, r = INF; whi...
9
#include <bits/stdc++.h> using namespace std; int a, ans[17] = {0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0}; int main() { cin >> a; cout << ans[a]; return 0; }
9
#include <bits/stdc++.h> using namespace std; const int DIM = 2e5 + 5; int arr[DIM], deg[DIM], in[DIM], out[DIM]; vector<int> edg[DIM]; void dfs(int x, int &p) { in[x] = ++p; for (int y : edg[x]) dfs(y, p); out[x] = p; return; } int main(void) { int n, m, k, q; cin >> n >> m >> k >> q; for (int i = 1; i <...
19
#include <bits/stdc++.h> using namespace std; struct Point { long long x, y; Point operator-(const Point& p) const { return {x - p.x, y - p.y}; } } p[100010]; int n; inline bool cross(Point a, Point b) { return a.y * b.x == a.x * b.y; } inline bool collinear(int x, int y, int z) { return cross(p[x] - p[y], p[x] -...
12