solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; cout << "1 " << n - 1 << endl; } }
0
#include <bits/stdc++.h> using namespace std; struct snow { friend bool operator<(snow a, snow b) { return a.count < b.count; } int num, count; } S[100005]; int a[34000][3]; priority_queue<snow> Q; int cmp(snow a, snow b) { return a.num < b.num; } int cmpn(snow a, snow b) { return a.count > b.count; } int cmpm(int ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, k; cin >> n >> k; set<long long int> s; long long int i; for (i = 1; i * i <= n; i++) { if (n % i == 0) { s.insert(i); s.insert(n / i); } } if (k > s.size())...
3
#include <bits/stdc++.h> using namespace std; const int MAX_N = 200200; int n, m; vector<int> adj[MAX_N]; vector<int> radj[MAX_N]; bool vis[MAX_N]; bool above[MAX_N]; bool hasCycle = 0; bool visf[MAX_N]; bool visb[MAX_N]; char res[MAX_N]; void dfs(int u) { above[u] = 1; vis[u] = 1; for (int v : adj[u]) { if (...
9
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; long long a[n + 1]; pair<long long, long long> b[n + 1]; for (long long i = 1; i <= n; i++) { cin >> a[i]; b[i] = {a[i], i}; } sort(b + 1, b + n + 1); reverse...
5
#include <bits/stdc++.h> using namespace std; int n, m, k; int main() { int i; scanf("%d%d%d", &n, &m, &k); if (n % 2 && k == 1 && m > 1) { printf("Timur\n"); return 0; } if (n % 2 == 0) { printf("Marsel\n"); return 0; } for (i = 2; i <= sqrt(m); i++) { if ((k <= (m / i)) && ((m % i) =...
6
#include <bits/stdc++.h> using namespace std; int main() { string repo; int pt = 0; const int prime[] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61}; for (int i = 1; i <= 18; ++i) { cout << prime[i] << endl; fflush(stdout); cin >> repo; if (...
3
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,abm,mmx,tune=native") #include<vector> #include<iostream> #include<stack> #include<cmath> #include<algorithm> #include<set> #include<map> #include<string> #include<tuple> #include<bitset> #include<queue> #include<...
10
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:33554432") using namespace std; int n, k; int ip[1 << 17]; int m[1 << 17]; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { int a, b, c, d; scanf("%d.%d.%d.%d", &a, &b, &c, &d); ip[i] = (a << 24) | (b << 16) | (c << 8) | d; } ...
4
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, unique_i, unique_j; cin >> n >> m; char matrix[n][m]; for (auto cell : matrix) cin >> cell; for (int i = 0, count = 0; i < n && count != 1; i++) { ...
0
#include <bits/stdc++.h> using namespace std; int toInt(string s) { int r = 0; istringstream sin(s); sin >> r; return r; } long long toInt64(string s) { long long r = 0; istringstream sin(s); sin >> r; return r; } double toDouble(string s) { double r = 0; istringstream sin(s); sin >> r; return r...
4
#include <bits/stdc++.h> using namespace std; int n; int eval(int cnt[26], int scnt[26]) { int ret = 0; for (int i = 0; i < 26; ++i) { ret += min(cnt[i], scnt[i]); } return ret; } int main() { cin >> n; vector<string> name(n), surname(n); for (int i = 0; i < n; ++i) { cin >> name[i]; } for (in...
6
#include <bits/stdc++.h> using namespace std; int power(int h) { if (h == 0) return 1; return 10 * power(--h); } int main() { int m; cin >> m; string s; cin >> s; int x = 0, n = 0, y = 0; for (int i = m - 1; i >= 0; --i) { if (s[i] == '1') ++x; else { n += x * power(y++); x = 0...
1
#include <bits/stdc++.h> #pragma GCC optimize "-O3" const int N = 101010; using namespace std; int n, m; vector<pair<int, int> > g[N]; int sc[N], sd[N], vis[N]; pair<int, int> dfs(int i, int d, int c) { pair<int, int> ret = {0, 0}; sd[i] = d; sc[i] = c; vis[i] = 1; for (pair<int, int> j : g[i]) { if (!vis...
6
#include <bits/stdc++.h> using namespace std; int arr[101]; int main() { int n; cin >> n; int sum = 0, min = 999999; for (int i = 0; i < n; cin >> arr[i++]) ; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (arr[i] > arr[j] && i != j) { arr[i] -= arr[j]; i = (-1); ...
1
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * f; } struct edge { int from, to, nxt; bool ok; } g[804040...
10
#include <bits/stdc++.h> using namespace std; int n, m; int main() { cin >> n >> m; vector<vector<int> > bubbles = vector<vector<int> >(n, vector<int>(m, 0)); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) { cin >> bubbles[i][j]; } long long ans1 = 0; for (int p = 0; p < 16; ++p) { ...
6
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7, LIM = 1e5; unsigned long long int fact[2 * LIM + 1]; unsigned long long int binpow(long long int x, int y) { unsigned long long int res = 1; while (y > 0) { if (y & 1) res = (res * x) % MOD; y >>= 1; x = (x * x) % MOD; } return r...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 820; int n; int a[maxn]; int dp[maxn][maxn][3]; int v[maxn][maxn]; int gcd(int x, int y) { int t; if (x < y) swap(x, y); while (y) { t = x % y; x = y; y = t; } return x; } int check(int l, int r, int k) { if (l > r) return 1; retur...
6
#include <bits/stdc++.h> double EPS = 1E-9; using namespace std; struct node { int a, b, x, y; }; node Rotate(node n) { int t = n.x; n.x = n.a + -n.y + n.b; n.y = t - n.a + n.b; return n; } double dist(node a, node b) { return sqrt(0.1 * (a.x - b.x) * (a.x - b.x) + 0.1 * (a.y - b.y) * (a.y - b...
6
#include <bits/stdc++.h> #define f first #define s second #define mp make_pair #define pb push_back using namespace std; typedef long long ll; /* remember: precomputation should be done in main */ void solve(){ int n; cin >> n; vector <int> nums(n); ll sum = 0; for(int i=0; i<n; i++){ cin >> nums[i]; ...
0
#include <bits/stdc++.h> using graph = std::vector<std::vector<int> >; void DFS(int node, int node_parent, const graph& G, std::vector<int>& parent, graph& kids, std::vector<std::vector<int> >& v_to_child) { parent[node] = node_parent; kids[node].push_back(node); for (int i = 0; i < G.size(); i++) v_to_c...
6
#include <bits/stdc++.h> const long long maxn = 1e6 + 9, mod = 998244353, inf = 0x3f3f3f3f; long long Read() { long long x(0), f(1); char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 3ll) + (x << 1ll) + c - '0'; c =...
6
#include <bits/stdc++.h> inline int cmp(double x, double y = 0, double tol = 1e-9) { return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1; } const long long int MOD = 1000000009; inline long long int mod(long long int n) { return (n < MOD ? n : n % MOD); } inline long long int paths_inside(int n) { n += 1; long lon...
9
#include <bits/stdc++.h> using namespace std; template <typename T, typename S> ostream& operator<<(ostream& os, const pair<T, S>& v) { os << '(' << v.first << ' ' << v.second << ')'; return os; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { int cnt = 0; for (auto it : v) { c...
0
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int n; pair<int, int> p[5555]; set<int> get(int x0, int y0, int x1, int y1) { if (x0 > x1) swap(x0, x1); if (y0 > y1) swap(y0, y1); set<int> res; for (int i(0); i < n; ++i) if (x0 <= p[i].first && p[i].first <= x1 && y0 <= p[i].second...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 150000; vector<int> a[maxn + 10]; bool mark[maxn + 10]; bool marko[maxn + 10]; int cnt = 0; bool b = 1; void solve(int x, int par) { mark[x] = 1; cnt++; for (int i = 0; i < a[x].size(); i++) { if (!mark[a[x][i]] && a[x][i] != par) { solve(a[...
3
#include <bits/stdc++.h> using namespace std; inline void R(int &x) { char ch = getchar(); x = 0; for (; ch < '0'; ch = getchar()) ; for (; ch >= '0'; ch = getchar()) x = x * 10 + ch - '0'; } const int N = 1700, dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1}; int a[N][N], s[N][N], c[N][N]; bool v[N][N]; int n, ...
7
#include<iostream> #include<string> #include<algorithm> #include<string.h> #define rep(i,a,b) for(ll i=a;i<=b;++i) #define per(i,a,b) for(ll i=a;i>=b;--i) #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) x.begin(),x.end() using namespace std; typedef long long ll; typedef pair...
4
#include <bits/stdc++.h> using namespace std; vector<int> v; void digit() { for (long long i = 1; i <= 9; i++) { v.push_back(i); } for (long long i = 1; i < 10; i++) { for (long long j = 0; j < 10; j++) { v.push_back(i); v.push_back(j); } } for (long long i = 1; i < 10; i++) { for ...
1
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + c - '0'; c = getchar(); } return x * f; } int n, ...
9
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int base = 31; void MAIN(); int main() { ios::sync_with_stdio(false); cin.tie(0); MAIN(); return 0; } const int N = 304; int n, V, e, a[N], b[N]; bool c[N][N]; vector<int> G[N]; vector<pair<pair<int, int>, int> > ans; void dfs(int...
8
#include <bits/stdc++.h> using namespace std; int g[20] = {0, 1, 0, 18, 0, 1800, 0, 670320, 0, 734832000, 0, 890786230, 0, 695720788, 0, 150347555, 0}; int main() { int n; cin >> n; cout << g[n] << endl; }
5
#include <bits/stdc++.h> using namespace std; const long long INF = 4e18 + 7; int n, x[200005]; long long t, a[200005], b[200005], l[200005], r[200005]; int main() { scanf("%d%lld", &n, &t); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &x[i]); for (int i = 1; i <= ...
7
#include <bits/stdc++.h> using namespace std; const int maxM = 4e5 + 5, mod = 1e9 + 7; int N, M; int a[maxM], b[maxM], c[maxM]; long long cost; int s[maxM]; set<int> p0, p1; bool cmp(int i, int j) { return c[i] < c[j]; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> M >> N; for...
8
#include <bits/stdc++.h> using namespace std; const int maxint = -1u >> 1; template <class T> void toMax(T &a, T b) { if (b > a) a = b; } template <class T> void toMin(T &a, T b) { if (b < a) a = b; } const int MaxN = 200010; struct Node { char c; Node *nxt, *pre; } node[MaxN], *np, *head, *tail, *cur; int main...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; set<int> ts; set<int> toLookAt; for (int i = 0; i < s.size(); i++) { ts.insert(i); toLookAt.insert(i); } set<int> deletedIdx; for (int op = 0;; op++) { deletedIdx....
6
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); int n, a, b, k, f; cin >> n >> a >> b >> k >> f; map<pair<string, string>, int> sum; string last = ""; for (int i = 0; i < n; i++) { string ...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; int n; unordered_map<int, vector<pair<int, int>>> mp; int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<int> s(n); s[0] ...
5
#include <bits/stdc++.h> using namespace std; int n; vector<int> v[3030]; char nome[3030][128]; int a[3030], r[3030]; inline void anexa(stack<int> &d, vector<int> &v) { for (int i = 0; i < (int)v.size(); i++) d.push(v[i]); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) v[i].clear(); for (int i = 0;...
5
#include <bits/stdc++.h> using namespace std; vector<int> adj[300001]; long long int visited[300001], x, y, n, pathx, pathy; bool dfs_check(int i, int parent) { if (visited[i]) return false; if (i == y) { pathy = parent; return true; } visited[i] = 1; for (int j = 0; j < adj[i].size(); j++) { if (...
4
#include <bits/stdc++.h> using namespace std; const long long modulo = (long long)1e9 + 7; template <typename T> T input() { T res; cin >> res; return res; } long long n = 0; pair<long long, bool> dp[2005][2005]; int main() { cin.sync_with_stdio(false); cin.tie(NULL); n = input<long long>() * 2; dp[0][0] ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; cout << (n / 2520); return 0; }
1
#include <bits/stdc++.h> using namespace std; long long a[200009]; long long b[200009]; int main() { cin.sync_with_stdio(false); long long i, j, k, l, c, v, n, m, r, tt, t; cin >> t; while (t--) { cin >> k >> m >> n; for (i = 0; i < m; i++) cin >> a[i]; sort(a, a + m); for (i = 0; i < n; i++) ci...
0
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); } const int MAXN = 1e6 + 10; const int INF = 0x3f3f3f3f; const long long INFLL = 0x3f3f3f3f3f3f3f3f; const long long mod = 998244353; long long l, r, k; int str[25]; struct Res { long long cnt; long long sum...
7
#include <bits/stdc++.h> using namespace std; void remove(std::vector<int> &v) { auto end = v.end(); for (auto it = v.begin(); it != end; ++it) { end = std::remove(it + 1, end, *it); } v.erase(end, v.end()); } int main() { int t; cin >> t; while (t--) { int n, x; cin >> n; std::vector<int>...
0
#include <bits/stdc++.h> using namespace std; int tx[] = {0, 0, 1, -1}; int ty[] = {-1, 1, 0, 0}; template <class T> T gcd(T a, T b) { if (b == 0) { return a; } return gcd(b, a % b); } int toInt(string& s) { stringstream ss(s); int x; ss >> x; return x; } int main() { ios_base::sync_with_stdio(false...
3
#include <bits/stdc++.h> using namespace std; int const MOD = 1000000007; int main() { bool b1 = 0, b2 = 0; int sz; string s1, s2; cin >> sz >> s1 >> s2; long long bigR = 1, R1 = 1, R2 = 1, plus = 1; for (int i = 0; i < sz; i++) { if (s1[i] == s2[i] && s1[i] == '?') { bigR *= 100; R1 *= 55; ...
6
#include <bits/stdc++.h> using namespace std; template <typename Tp> inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") { for (Tp current = _begin; current != _end; ++current) { std::cout << *current << _delim; } std::cout << '\n'; } using ll = long long; using pii = std::pair<int, int>; constex...
6
#include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; string a, b; cin >> n >> a >> b; if (a == b) { cout << 0 << endl; continue; } vector<int> v1, v2; fo...
4
#include <bits/stdc++.h> using namespace std; int solve(string a) { int maxDiff = 1, lst = 0, diff; a = '#' + a + 'R'; bool found = false; for (int i = 0; i < a.size(); i++) { if (a[i] == '#' || a[i] == 'L') continue; if (a[i] == 'R') { diff = i - lst; lst = i; if (diff > maxDiff) maxD...
1
#include <bits/stdc++.h> using namespace std; const int SIZ = 500000, MOD = 998244353; char buf1[SIZ], *p1 = buf1, *p2 = buf1; char gchar() { if (p1 == p2) p1 = buf1, p2 = buf1 + fread(buf1, 1, SIZ, stdin); return p1 == p2 ? EOF : *p1++; } int read() { int ret; register int c; while ((c = gchar()) > '9' || c ...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 21; const int MAXB = 30; const int MOD = 1E9 + 7; int N; long long S; long long ar[MAXN]; long long inv[MAXN]; void mmult(long long& a, long long b) { a %= MOD; b %= MOD; a *= b; a %= MOD; } long long mpow(long long base, int exp) { long long ret ...
7
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") #pragma GCC target("sse4") const double PI = acos(-1.0); const double EPS = 1e-8; const long long INF = 1e9; const long long LINF = 5e18; const long long mod = 1e9 + 7; const long long MAX = 1 << 17; long long n, h; inline long long get(long long ...
6
#include <bits/stdc++.h> using namespace std; long long mod = 1; struct infrm { public: long long x, y; } var[100005]; long long n, m; long long sum; int ar[100005], br[100005]; long long r; bool cmp(infrm a, infrm b) { return a.y < b.y; } bool cmp1(infrm a, infrm b) { return a.x < b.x; } int main() { int i, j, t,...
3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << max(a + (b * c), max(a * (b + c), max(a * b * c, max((a + b) * c, max(a + b + c, a * b + c))))); return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, m, f[200012], g[200012], mn[200012], mx[200012], su; inline int getf(int x) { if (f[x] == x) return x; int y = getf(f[x]); g[x] += g[f[x]]; return (f[x] = y); } int main() { scanf("%d%d", &n, &m); int i, x, y, c, v, v1, t1, t2; for (i = 1; i <= n; i++) ...
11
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1e6 + 5; int add(int x, int y) { x += y; return x >= mod ? x - mod : x; } int sub(int x, int y) { x -= y; return x < 0 ? x + mod : x; } int mul(int x, int y) { return 1ll * x * y % mod; } int ksm(int a, int b) { if (b < 0)...
8
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long int n; cin >> n; unsigned long long int p = 0; unsigned long long int val = 0; while (val < n) { p++; val = (p * (p + 1)) / 2; } int diff = val - n; int ans = p - diff; cout << ans << endl; }
1
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; char a[200005] = {'*'}, b[200005] = {'*'}; vector<pair<long long int, long long int> > v; stack<char> st; int main() { long long int i, j, k, nb = 0, x, y, m, l, n, sc = 0, nbround = 1; string s, ch; cin >> s; n = s.size(); cin >...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 55, maxm = 55; int n, m, a[maxn]; double f[maxm][maxn][maxn], s[maxm][maxn][maxn]; long long C[maxn][maxn]; int main() { scanf("%d%d", &n, &m); C[0][0] = 1; for (int i = 1; i <= n; i++) { C[i][0] = 1; for (int j = 1; j <= n; j++) C[i][j] = C[i...
7
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } return x * f; } const int...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 100; const int mod = 1e9 + 7; long long prim[maxn]; bool vis[maxn]; int cnt = 0; long long f[maxn]; long long mul[maxn]; long long inv[maxn]; long long qp(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) { ans = ans ...
9
#include <bits/stdc++.h> using namespace std; int t = 1, n; int dp[4][226][(1LL << 15) + 5]; vector<int> tim(18), genre(19); inline int add(int x, int y) { x += y; return x % (int)1000000007; } inline int mult(int x, int y) { return (x * 1LL * y) % (int)1000000007; } inline int powMod(int base, int expo) { int an...
6
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-12, PI = 2 * acos(0.0); void came(int x) { cout << "Came " << x << endl; } class Circle { public: long long x, y, r; Circle() {} Circle(long long x, long long y, long long r) : x(x), y(y), r(r) {} Circle(const Circle &c) : x(c.x), y(c.y), r(c....
6
#include <bits/stdc++.h> using namespace std; int F1[1009][1009]; int main() { int n; vector<int> V[1009]; vector<pair<int, int> > B; cin >> n; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; V[a].push_back(b); V[b].push_back(a); B.push_back(pair<int, int>(a, b)); } vector<i...
5
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; struct mat { long long m[2][2]; mat() { m[0][0] = m[0][1] = m[1][0] = m[1][1] = 0; }; mat(long long a, long long b, long long c, long long d) { m[0][0] = a; m[0][1] = b; m[1][0] = c; m[1][1] = d; } mat operator+(co...
7
#include <bits/stdc++.h> using namespace std; inline bool isprime(long long num) { if (num == 2 || num == 3) return true; if (num % 6 != 1 && num % 6 != 5) return false; for (int i = 5; 1ll * i * i <= num; i += 6) { if (num % i == 0 || num % (i + 2) == 0) return false; } return true; } const int mod = 998...
7
#include <bits/stdc++.h> using namespace std; const int N = 32; const int MX = 1e9 + 7; const int inf = 1e9 + 9; int n; int strength[N]; bool is[2 * N][2 * N]; int p[N][2 * N][2 * N * N]; bool dp[N][2 * N][2 * N * N]; void solve(vector<pair<int, int> > cur) { if (cur.size() == 0) return; sort(cur.begin(), cur.end()...
10
#include <bits/stdc++.h> int main() { int n, i, j, temp = 0; scanf("%d", &n); int a[n]; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (a[i] < a[j]) { temp = a[j]; a[j] = a[i]; a[i] = temp; } } } int ...
1
#include <bits/stdc++.h> using namespace std; long long pwr(long long base, long long exp, long long mod = (1000000007LL)) { long long res = 1; while (exp > 0) { if (exp % 2) { res = (res * base) % mod; } base = (base * base) % mod; exp /= 2; } return res; } long long gcd(long long a, long...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1000; int n, x[maxn + 9], y[maxn + 9], a[maxn + 9], b[maxn + 9], d[maxn + 9][maxn + 9], xmin, ymin, xmax, ymax; int main() { cin >> n; for (int i = 1; i <= n * 4 + 1; i++) { cin >> a[i] >> b[i]; x[a[i]]++, y[b[i]]++; } xmin = maxn, xmax ...
4
#include <bits/stdc++.h> using namespace std; int const N = int(1e5) + 7; int const mod = int(1e9) + 7; int a[505][505]; int b[505][505]; map<int, int> cnta; map<int, int> cntb; bool check(int d, int n, int m) { cnta.clear(); cntb.clear(); for (int r = 0; r < n; ++r) { int c = d - r; if (0 <= c && c < m) ...
3
#include <bits/stdc++.h> using namespace std; int main() { string start, end; cin >> start >> end; int sc = start[0] - 'a' + 1; int sr = start[1] - '0'; int ec = end[0] - 'a' + 1; int er = end[1] - '0'; vector<string> v; while (true) { if (sc == ec and sr == er) break; if (sc < ec and sr < er) ...
1
#include <bits/stdc++.h> using namespace std; long long n, t, c, a[200005], ans = 0, num = 0; int main() { scanf("%lld%lld%lld", &n, &t, &c); for (int i = 0; i < n; i++) { long long b; scanf("%lld", &b); a[i] = b; } for (int i = 0; i < n; i++) { if (a[i] > t) { num = 0; continue; ...
1
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const int Mod = 1e9 + 7; long long jc[N]; long long jcinv[N]; char s[N]; int n; int beh[N]; long long Ksm(long long a, long long b) { long long ret = 1; while (b) { if (b & 1) ret = ret * a % Mod; a = a * a % Mod; b >>= 1; } retur...
7
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1}; int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2}; int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1}; vector<int> adj[305]; long long a[305], cost[305]; long ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k, l, m; cin >> n >> m; char p[n + 1][m + 2]; int c = 0; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { cin >> p[i][j]; if (p[i][j] == '*') c++; } } int fl = 0; for (i = 0; i < n; i++) { for (j = 0; j < ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long n; cin >> n; long long a = 0, b = 0; for (long long int i = 0; i < n; i++) { int c; cin >> c; if (c == 1) a++; else b++; } if (!a) while (b--) cout <<...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; int a[1001], b[1001]; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; int ans = 0; for (int i = 0; i < n; i++) { int x, y; x = y = 0; for (int j = i; j < n; j++) { x = x | a[j]; ...
0
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 5; int q, n, l, r; char x, t; map<int, int> book; int main(void) { ios::sync_with_stdio(false); cin.tie(0); cin >> q; l = r = M; for (int k = 1; k <= q; k++) { cin >> t >> n; if (k == 1) { if (t == 'L') book[n] = l--, r++;...
3
#include <bits/stdc++.h> using namespace std; const long long INF = 2e14 + 1; long long n, m, pp = 0; map<long long, long long, greater<long long>> x; vector<int> v; vector<long long> q; bool first(long long mi, long long sk) { long long cur = 0, skip = 0; priority_queue<int, vector<int>, greater<int>> active; fo...
7
#include <bits/stdc++.h> using namespace std; long long mod1 = 1e9 + 7; long long mod2 = 998244353; long long mul(long long x, long long y) { return (1ll * (x % mod1) * (y % mod1)); } long long power(long long x, long long y) { long long z = 1; while (y > 0) { if (y % 2) z = mul(z, x); x = mul(x, x); ...
4
#include <bits/stdc++.h> using namespace std; void assign(long long int pre[9], long long int partial[9], int type) { long long int temp[9]; for (int i = 0; i < 9; i++) temp[i] = 0; if (type == 1) { for (int i = 0; i < 9; i++) { int p = i / 3, q = i % 3; for (int j = 0; j < 3; j++) { for (...
5
#include <bits/stdc++.h> using namespace std; long long arr[100007]; int main() { long long n, i, j, k, l, x, y, u; cin >> n >> u; for (i = 1; i <= n; i++) { cin >> arr[i]; } i = 1, j = 2, k = 3; double maxx = 0; for (i = 1; i < n - 1; i++) { long long val = arr[i] + u; int pos = upper_bound(a...
4
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e6 + 3; const int K = 11; long long x[K] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; long long m[K][K], a[K][K], c[K]; long long r[K]; long long binpow(long long b, int p = MOD - 2) { long long res = 1; while (p) { if (p & 1) { res *= b; ...
7
#include <bits/stdc++.h> using namespace std; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; void file() {} void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); } int main() { file(); fast(); int n; cin >> n; vector<int> v1(n), copy(n); for (int i = 0; i < n; ...
2
#include <bits/stdc++.h> using namespace std; int x[1000005]; int p[1000005]; int vis[1000005]; long long ans = 1e18; int n, a, b; long long dp[1000005][3]; long long add; void check(int p) { dp[0][0] = dp[0][1] = dp[0][2] = ans; dp[0][0] = 0; for (int i = 1; i <= n; i++) { add = ans; if (x[i] % p == 0) a...
7
#include <bits/stdc++.h> using namespace std; string s[100010], a, b; int n; bool total; void triv_case() { for (int i = 0; i < a.length(); i++) { if (a[i] == '?' && i != 0) a[i] = '0'; else if (a[i] == '?') a[i] = '1'; } } int nadji_cifru() { for (int i = 0; i < a.length(); i++) { if (a[i...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int tt = 1; cin >> tt; for (long long int tc = 1; tc <= tt; tc++) { long long int n; cin >> n; vector<long long int> arr(n), brr(n); for (long long int i = 0; i <= n - 1; i++) ...
4
#include <bits/stdc++.h> const int N = 100005; int a[N] = {0}, b[N] = {0}, c[N] = {0}, lx[N] = {0}, ly[N] = {0}; int main() { bool bb = false; int n = 0, t = 0, i = 0, g = 0, tol = 0, x = 0, j = 0; while (scanf("%d", &n) == 1) { t = 0; g = 0; tol = 0; for (i = 1; i <= n + 1; i++) { if (i <= ...
5
#include <bits/stdc++.h> template <typename T> void amax(T& a, T b) { a = a > b ? a : b; } template <typename T> void amin(T& a, T b) { a = a < b ? a : b; } template <typename T> void sadd(T& a, T b) { a = (a + b) % 1000000007; } template <typename T> void ssub(T& a, T b) { a = ((a - b) % 1000000007 + 100000000...
5
#include <bits/stdc++.h> using namespace std; namespace MCF { const int wEPS = 0; const int wINF = 1001001001; const int cEPS = 0; const int cINF = 1001001001; int n, m, ptr[100010], next[100010], zu[100010]; int capa[100010], tof; int cost[100010], toc, d[100010], pot[100010]; int vis[100010], pree[100010]; void init(...
6
#include <bits/stdc++.h> using namespace std; string s; bool flag; int main() { cin >> s; for (int i = 0; i < s.length(); ++i) { if (flag || (s[i] == '1' && i != s.length() - 1)) { cout << s[i]; } else { flag = true; } } return 0; }
1
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; int main() { ::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int r, c, n, k; cin >> r >> c >> n >> k; v.resize(n); for (int i = 0; i < n; i++) { cin >> v[i].first >> v[i].second; --v[i].first; --v[i].second; ...
1
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; int len = a.size(), ans = 0; for (int i = 0; i < len; i++) { if (a[i] == '0' && b[i] == '0' && a[i + 1] == '0') { a[i] = b[i] = a[i + 1] = 'x'; ans++; } else if (a[i] == '0' && b[i] == '0' && b[i + 1] == '...
3
#include <bits/stdc++.h> using namespace std; int a1, b1, c1, a2, b2, c2; int d1, d2, d3, d4, d5, d6, d7; int f1, f2, f3, f4, f5, f6, f7; bool check() { return f1 <= d1 && f2 <= d2 && f3 <= d3 && f4 <= d4 && f5 <= d5 && f6 <= d6 && f7 <= d7 && (f1 + f2 + f3 + f4 <= a1) && (f1 + f2 + f5 + f6 <= b1) && ...
9
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 5; int main() { int t; cin >> t; while (t--) { int n; cin >> n; map<int, int> cnt; vector<int> r(N); int ans = 2e5 + 5; for (int i = 0; i < n; ++i) { int x; cin >> x; cnt[x]++; i...
2
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { x = 0; T f = 1; char ch; do { ch = getchar(); if (ch == '-') f = -1; } while (ch < '0' || ch > '9'); do x = x * 10 + ch - '0', ch = getchar(); while (ch <= '9' && ch >= '0'); x *= f; } template <typename...
7
#include <bits/stdc++.h> using namespace std; bool prime[1001]; void sieve(int n) { memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) { prime[i] = false; } } } } bool comp(const pair<char, int> &a, const p...
2