solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int n, m, dist, x, y, id; int fa[1000100][25]; int d[1000100]; void add(int x, int y) { fa[x][0] = y; d[x] = d[y] + 1; for (int i = 1; i <= 20; ++i) fa[x][i] = fa[fa[x][i - 1]][i - 1]; } int len(int x, int y) { if (x == y) return 0; int dqx = x, dqy = y; if (d[d...
16
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { x = 0; char c = getchar(), f = 0; for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = 1; for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -x; } int T, n, Q, a[...
5
#include <bits/stdc++.h> struct pnt { int x, y; }; int x, y, z; int a, b, c; int ar[7]; int kenar() { pnt p1, p2, p3, p4; pnt vas; p1.x = 0; p1.y = 0; p2.x = a; p2.y = 0; p3.x = a; p3.y = c; p4.x = 0; p4.y = c; vas.x = x; vas.y = z; int res = 0; if (vas.y < p1.y) res += ar[3]; if (vas.y ...
8
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const int mod = inf + 7; const double pi = acos(-1.0); const int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; long long ax, ay, bx, by, cx, cy; long long GetDist(long long x, long long y, long long a, long long b) { return ((x - ...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; long long t; struct Point { long long x, y; } P0, a, b, St, Pre; vector<Point> vp; void init() { vp.clear(); vp.clear(); } long long dist(Point &p1, Point &p2) { long long dx = p1.x - p2....
9
#include <bits/stdc++.h> using namespace std; long long m; long long POW(long long x, long long y) { if (y == 0) return 1; long long r = (x % m * x % m) % m; if (y & 1) return (x % m * POW(r, y / 2)) % m; return POW(r, y / 2); } int main() { int n; cin >> n >> m; long long r = POW(3, n); if (r == 0) ...
6
#include <bits/stdc++.h> using namespace std; deque<pair<pair<long long, long long>, pair<long long, long long> > > p; int main() { int n, m, q; cin >> n >> m >> q; pair<pair<long long, long long>, pair<long long, long long> > l; while (q--) { cin >> l.first.first >> l.first.second; if (l.first.first !=...
6
#include <bits/stdc++.h> const long long MOD = 1000000007; const long long inf = 100000000000000000; const long long inf1 = 1000000000000000; using namespace std; long long int modpow(long long int x, long long int n) { long long int res = 1; while (n > 0) { if (n & 1) res = res * x % MOD; x = x * x % MOD; ...
5
#include <bits/stdc++.h> using namespace std; int const N = 1001; int n, m, a[N][N]; bitset<N> b[N]; bool check(int x) { for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) b[i][j] = (a[i][j] >= x); for (int i = 0; i < n; i++) { if (b[i].count() < 2) continue; for (int j = i + 1; j < n; j++) i...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string str; cin >> str; stack<char> stk; map<char, long long int> mp; for (auto it : str) mp[it]++; char ch = 'a'; string ans = ""; for (long long int i = 0; i < str.length()...
9
#include <bits/stdc++.h> using namespace std; const long long P = 1000000007; int n, m, tot; long long ans; int p[10]; inline long long pm(long long x, long long y) { long long z = 1; while (y) { if (y & 1) z = z * x % P; x = x * x % P, y >>= 1; } return z; } void dfs(int x, int y, int z) { if (x > to...
12
#include <bits/stdc++.h> using namespace std; pair<long long int, long long int> arr[7777]; map<long long int, int> mm; long long int ans, dp[66]; vector<long long int> v; int main(void) { dp[0] = 1; for (int p = 1; p <= 60; p++) dp[p] = dp[p - 1] * 2; int n; scanf("%d", &n); for (int e = 0; e < n; e++) { ...
9
#include <bits/stdc++.h> using namespace std; const int N = 505; const long long inf = 1e18; int n, tim, vs[2][N], bel[N]; long long g[N][N], tg[2][N], slack[N], ans; inline void upp(long long &x, long long y) { if (y > x) x = y; } inline void dnn(long long &x, long long y) { if (y < x) x = y; } bool dfs(int x) { ...
18
#include <bits/stdc++.h> using namespace std; const long long oo = 1e18; const int N = 2 * 1e5 + 5; const double eps = 1e-5; int n; int l, r, p; double t[N], ans; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> p; for (int i = 0; i < n; i++) { cin >> l >> r; double ...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005; int n, a[MAXN], pos[MAXN]; bool ok() { for (int i = 1; i <= n; i++) if (a[i] != i) return 0; return 1; } int L[6], R[6], top = 0; bool dfs(int k) { if (ok()) { printf("%d\n", top); for (int i = top; i; i--) printf("%d %d\n", L[i], R[...
19
#include <bits/stdc++.h> using namespace std; const int MAXN = 15e4 + 5, SQ = 400; const long long MOD = 998244353; int n, q, tim; vector<int> adj[MAXN]; vector<pair<int, int> > adj2[MAXN]; int par[MAXN]; int st[MAXN], fn[MAXN], bc[MAXN], sub[MAXN], up[MAXN]; long long seg[MAXN * 4], an[MAXN]; long long pw(long long a,...
19
#include <bits/stdc++.h> using namespace std; vector<vector<int> > G1, G2; int Visted[55] = {}; char arr[55][55]; int main() { int n, m; cin >> n >> m; G1.resize(n), G2.resize(m); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> arr[i][j]; if (arr[i][j] == '#') { G1[i]....
5
#include <bits/stdc++.h> using namespace std; vector<int> adj[100100]; int a[100100], pos[100100], dp[100100]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", a + i); pos[a[i]] = i; } for (int i = 1; i <= n; i++) { for (int j = i + a[i]; j <= n; j += a[i]) if ...
8
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-10; int dcmp(double x) { if (fabs(x) < eps) return 0; else return x < 0 ? -1 : 1; } const int INF = 0x3f3f3f3f; const int N = 1505; char s[2 * N]; int dp[30][2 * N]; int main() { memset(dp, 0, sizeof(dp)); ...
8
#include <bits/stdc++.h> using namespace std; const double eps = 1.0e-11; const double pi = acos(-1.0); const int MAXN = 2000100; int a[MAXN]; long long n, l, t; int main() { cin >> n >> l >> t; for (long long i = 0; i < n; i++) { scanf("%d", a + i); a[i + n] = a[i] + l; } long long laps = 2 * t / l; ...
12
#include <bits/stdc++.h> using namespace std; string st; pair<long, long> ps1[10], ps2[10], start; pair<pair<long, long>, pair<long, long> > temp; queue<pair<pair<long, long>, pair<long, long> > > qu; long n, m, c1, c2, dp[22][22][1 << 8][1 << 8]; bool bad[33][33]; long cost[300]; long qx, qy, qmask1, qmask2; void trym...
18
#include <bits/stdc++.h> using namespace std; const long long inf = 1e15 + 10; const long double pi = 3.141592653589793238; long long MOD = 1000000007; const long long N = 2e5 + 10; long long n, m, k; vector<long long> g1[N], g2[N]; long long a[N], dist[N]; void solve() { cin >> n >> m; for (long long i = 0; i < m;...
9
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int l, len, sum1, sum; cin >> l >> sum1; sum = sum1; len = l; string s; if (sum > 9 * len) { cout << "-1 -1" << "\n"; return 0; } if (sum == 0 &&...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 400100; const int INF = 1000000000; const int MOD = INF + 7; int main() { int q; cin >> q; vector<pair<long long, pair<long long, long long> > > vec; for (int i = 0; i < q; i++) { long long t; cin >> t; if (t == 1) { long long u, v...
7
#include <bits/stdc++.h> using namespace std; int s(long long int x) { int sum = 0; while (x != 0) { sum += x % 10; x /= 10; } return sum; } int main() { long long int n; cin >> n; long long int l = sqrt(n); int i = 0; while (i < 100) { long long int f = (l * l) + (s(l) * (l)) - n; if ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, ans = 0; cin >> a >> b; while (b) { ans += a / b; c = a % b; a = b; b = c; } cout << ans << endl; return 0; }
3
#include <bits/stdc++.h> char ar[100010]; char dn[100010]; int main() { scanf(" %s", ar); int i, uz; char max = 0; uz = strlen(ar); for (i = uz - 1; i >= 0; i--) { if (ar[i] > max) max = ar[i]; dn[i] = max; } for (i = 0; i < uz; i++) if (ar[i] >= dn[i]) printf("%c", ar[i]); return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { vector<int> v(n); for (int i = 0; i < n; cin >> v[i++]) ; sort(v.begin(), v.end()); swap(v[0], v[v.size() - 1]); for (int i = 0; i < n; i++) { if (i) { cout << " "; } cout << v[i]...
5
#include <bits/stdc++.h> using namespace std; int main() { long n, k; cin >> n >> k; long arrt[n], arrm[n]; for (int i = 0; i < n; i++) { int temp; cin >> temp; arrt[i] = temp; } for (int i = 0; i < n; i++) { int temp; cin >> temp; arrm[i] = temp; } int dp = 0; for (int i = 0; ...
4
#include <bits/stdc++.h> using namespace std; const int MAX_N = 30; char s[MAX_N][MAX_N]; char to[MAX_N][MAX_N]; int n; void X_Clr(char c[]) { int ans = n; for (int i = 0; i < n; i++) { c[ans++] = c[n - i - 1]; } c[ans] = '\0'; } bool pipei() { bool flag1 = true, flag2 = true, flag3 = true, flag4 = true; ...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, q, x, y; vector<pair<int, int> > adj[N]; struct tree { int dist[N], len[N], son[N], rnk[N], sum[N], P[N][20], rt = 0, cnt; pair<int, int> K[N]; void go(int u, int p) { for (pair<int, int> X : adj[u]) { int v = X.first, w = X.sec...
25
#include <bits/stdc++.h> using namespace std; int x[4], y[4], p = 0; void input(char a[100][100], int n, int m) { for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { cin >> a[i][j]; if (a[i][j] == '*') { x[p] = i; y[p] = j; p++; } } } int main() { char a[100][...
0
#include <bits/stdc++.h> const long long inf = 1e18, mod = 1e9 + 7; using namespace std; long long fact[1000001]; long long inv[1000001]; long long primes[100007]; long long arr[1000007]; long long modPower(long long b, long long p) { if (p == 0) return 1; long long halfpow = modPower(b, p / 2); long long toRetur...
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const long long mod = 998244353; int n; string s; long long qpow(long long a, long long b) { long long r = 1; while (b) { if (b & 1) r = r * a % mod; b >>= 1; a = a * a % mod; } return r; } long long C(int a, int b) { if (b > a |...
16
#include <bits/stdc++.h> const int big = 8; const int lim = 5032107; const int maxn = 1111111; int n, q, D[lim + 17], W[lim + 17], ans[maxn], a[maxn], l[maxn], r[maxn], f[100], R[lim + 17][10]; std::vector<int> v[200005], rec[200005]; std::vector<int> work(int x) { std::vector<int> v; while (x != 1) { int d...
21
#include <bits/stdc++.h> using namespace std; map<int, string> mapa; int a, b, c, i, j, k, n; void start() { mapa[0] = "zero"; mapa[1] = "one"; mapa[2] = "two"; mapa[3] = "three"; mapa[4] = "four"; mapa[5] = "five"; mapa[6] = "six"; mapa[7] = "seven"; mapa[8] = "eight"; mapa[9] = "nine"; mapa[10] ...
2
#include <bits/stdc++.h> using namespace std; int ary[101][101]; int main(void) { ios_base::sync_with_stdio(false); int n; int sum = 0; cin >> n; for (int i = 0; i < n; i++) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; x1 -= 1; y1 -= 1; x2 -= 1; y2 -= 1; for (int j = x1; j <=...
2
#include <bits/stdc++.h> using namespace std; const int inf = (signed)(~0u >> 1); typedef class Edge { public: int ed, nx, r; Edge() {} Edge(int ed, int nx, int r) : ed(ed), nx(nx), r(r) {} } Edge; typedef class MapManager { public: int* h; vector<Edge> E; MapManager() {} MapManager(int n) { h = new...
22
#include <bits/stdc++.h> using namespace std; const int N = 605; const int M = 605; int n, m, k; int a[M], b[M]; int deg[N]; vector<int> edges_matched_to_vertex[N]; int col[M]; const int INF = 1000000000; struct Edge { int from, to, cap, flow, index; Edge(int from, int to, int cap, int flow, int index) : from...
16
#include <bits/stdc++.h> using namespace std; long long a; set<long long> S; vector<int> v; void init() { long long t = 1; S.insert(t); for (int i = 2; i <= 30; i++) { t *= 2; S.insert(t - 1); } } int main() { init(); scanf("%lld", &a); if (S.count(a)) { printf("0\n"); return 0; } int ...
5
#include <bits/stdc++.h> using namespace std; struct Point { long long x, y; Point(){}; Point(long long xx, long long yy) { x = xx; y = yy; }; }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<pair<long long, long long> > top, bot; int pa = ...
15
#include <bits/stdc++.h> std::mt19937 rng( (int)std::chrono::steady_clock::now().time_since_epoch().count()); const int ms = 100100; std::vector<int> edges[ms]; int ans[ms]; long long tot = 0; void go(int on, int par) { for (auto to : edges[on]) { if (to == par) continue; go(to, on); if (ans[on] == -1...
13
#include <bits/stdc++.h> using namespace std; inline int ri() { int x; scanf("%d", &x); return x; } template <typename T> inline bool smax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> inline bool smin(T &a, T b) { if (a > b) { a = b; return true; ...
22
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int x = 0, y = 0; for (int i = 0; i < n; i++) { int a; cin >> a; if (a & 1) { x++; } else { y++; } } if (n == k) { if (x & 1) { cout << "Stannis" << "\n"; } else { ...
14
#include <bits/stdc++.h> using namespace std; const int N = 250000; int arr[N]; int pos[N]; int nxt[N]; int cnt[N]; int main() { int n, q; scanf("%d %d", &n, &q); for (int i = 1; i <= n; i++) scanf("%d", &arr[i]); memset(pos, -1, sizeof pos); for (int i = n; i >= 1; i--) { nxt[i] = i; if (pos[arr[i]] ...
12
#include <bits/stdc++.h> using namespace std; int solve(set<pair<int, int> > &x, set<pair<int, int> > &y) { if (x.size() == 1) return 1; set<pair<int, int> > xx, yy; set<pair<int, int> >::iterator x1 = x.begin(), y1 = y.begin(); set<pair<int, int> >::reverse_iterator x2 = x.rbegin(), y2 = y.rbegin(); do { ...
21
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, m, q, ans; int w[N]; void solve() { cin >> n >> m; memset(w, 0, 4 * n); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; if (u > v) swap(u, v); if (!w[u]) w[0]++; w[u]++; } cin >> q; for (int i = 0; i < q;...
6
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> a; map<int, int> l; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) l[i] = 1; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { cin >> a[make_pair(i, j)]; } ...
8
#include <bits/stdc++.h> using namespace std; int n, t, a[100005]; int main() { scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); sort(a + 1, a + 1 + n); int l = n / 2, r = n / 2 + 1; if (n % 2) { printf("%d ", a[n / 2 + 1]); r += 1; ...
4
#include <bits/stdc++.h> int dr[] = {2, 2, -2, -2, 1, -1, 1, -1}; int dc[] = {1, -1, 1, -1, 2, 2, -2, -2}; int dr1[] = {0, 0, 0, 1, 1, 1, -1, -1, -1}; int dc1[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; int dr2[] = {0, 0, 1, -1}; int dc2[] = {1, -1, 0, 0}; using namespace std; long long int a[1004][1004]; long long int x[10000...
5
#include <bits/stdc++.h> int t, n, a, B, head[100001], nxt[200001], b[200001], k, node[200001], top, g[200001], m[200001], h[200001]; void push(int s, int t) { nxt[++k] = head[s]; head[s] = k; b[k] = t; } int getmx(int x, int f) { int ans = -1; for (int i = head[x]; i; i = nxt[i]) if (b[i] != f) { ...
22
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int nxt[2 * N], to[2 * N], lst[N], cnt; int L1[N], L2[N], L3[N]; bool ok[N]; int Len, root; int dep[N], up[N][20], leaf[N]; bool used[N]; int a, b, n; void Init(int n) { cnt = 0; for (int i = 1; i <= n; i++) { L1[i] = L2[i] = L3[i] = 0; ok...
22
#include <bits/stdc++.h> using namespace std; const int N = 510000; int t, n, m; unsigned long long x[N], y[N], c[N]; vector<pair<unsigned long long, long long> > s; template <class T> inline void read(T &x) { x = 0; char ch = getchar(), w = 0; while (!isdigit(ch)) w = (ch == '-'), ch = getchar(); while (isdigi...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<int, int>> arr(n); int m = 0; for (int i = 0; i < n; i++) { cin >> arr[i].first >> arr[i].second; } int min = 0; for (int i = 0; i < n; i++) { if (arr[min].second < arr[i].second) { m += arr[i].first * ...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256777216") using namespace std; int main() { int n; cin >> n; string s; getline(cin, s); for (int i = 1; i <= n; i++) { getline(cin, s); if (s.length() < 5) { puts("OMG>.< I don't know!"); } else { if (s[s.size() - 5] == 'l' && ...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #define x first #define y second #define ld long double #define ll long long #define ull unsigned long long #define us unsigned short #define lsb(x) ((x) & (-(x))) using namespace std; int t, n, k; string s; string dp[505]; string f(char c) { char x = (c == ...
20
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n), b(n); for (int i = 0; i < n; i++) cin >> a[i]; int cnt = 0; b[0] = 0; for (int i = 1; ...
8
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int ans = min(a, b), sum = 0; a -= ans; b -= ans; if (a) { sum += a / 2; } if (b) { sum += b / 2; } cout << ans << " " << sum << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; signed main() { int N, M; cin >> N >> M; vector<long long> A(N), B(M); priority_queue<long long> ans; for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < M; i++) cin >> B[i]; for (int i = 0; i < N; i++) { long long mx = -1e18; for (int j = 0; ...
6
#include <bits/stdc++.h> using namespace std; char str[100100]; int main() { cin >> str; int zero = 0, one = 0, two = 0; for (int i = 0; i < strlen(str); i++) { if (str[i] == '1') one++; if (str[i] == '2') two++; if (str[i] == '0') { if (two == 0) zero++; } } while (zero--) { cout <<...
6
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string s1 = "hello"; int j = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == s1[j]) { s1[j] = '#'; j++; } } if (s1 == "#####") { cout << "YES"; } else { cout << "NO"; } return 0; }
2
#include <bits/stdc++.h> using namespace std; const int N = 2000010, mod = 1e9 + 7; 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 = getc...
11
#include <bits/stdc++.h> using namespace std; int check(string s1, string s2) { if (s1 == s2) return 1; if (s1.length() == 1 || s2.length() == 1) return 0; if (s1.length() % 2 == 0 || s2.length() % 2 == 0) { string a1 = s1.substr(0, s1.length() / 2); string a2 = s1.substr(s1.length() / 2, s1.length()); ...
9
#include <bits/stdc++.h> using namespace std; int n, a, b, x, y; int main() { cin >> n >> a >> x >> b >> y; bool meet = false; while (true) { if (a == b) { meet = true; break; } if (a == x || b == y) break; a++; b--; if (a > n) a = 1; if (b < 1) b = n; } if (meet) c...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, x; cin >> n; cout << n / 2520; return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { int n, i, m, l = 0, k = 0; cin >> n; int A[n], B[n]; for (i = 0; i < n; i++) { cin >> A[i] >> B[i]; if (B[i] - A[i] >= 2) l++; } printf("%d", l); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, b; cin >> n >> b; vector<long long int> v(n + 1, 0), odd(n + 1, 0), even(n + 1, 0); vector<long long int> ans; for (long long int i = 1; i <= n; i++) { cin >> v[i]; ...
4
#include <bits/stdc++.h> using namespace std; long long n, m, dp[2][410][410], ans; map<pair<int, int>, bool> mp; bool check(int u, int v, int x) { if (v == n - 1) return true; if (dp[1][0][u] + dp[1][u][x] + dp[1][x][v] == dp[0][0][v]) return false; return true; } int main() { ios::sync_with_stdio(false), cin....
8
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { while (a != 0) { int c = a; a = b % a; b = c; } return b; } vector<int> adj[3000]; vector<int> getAllDivisors(int num) { vector<int> divs; int square_root = (int)sqrt(num) + 1; for (int i = 1; i < square_root; i++) { if (n...
9
#include <bits/stdc++.h> using namespace std; const int N = 303030, OF = 101010; int n; pair<int, int> d[N]; int a[N]; int ans[N]; int main() { scanf("%d", &n); for (int i = (0); i < (n); i++) { int t; scanf("%d", &t); d[i] = {-t, i}; } memset(a, -1, sizeof(a)); sort(d, d + n); for (int l = OF, ...
12
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T1, class T2> ostream& operator<<(ostream&...
13
#include <bits/stdc++.h> using namespace std; int n, m, a[105], ha[105]; template <typename Drake> void read(Drake &x) { x = 0; char ch = getchar(); bool f = 1; while (!isdigit(ch)) { if (ch == '-') f ^= 1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = get...
4
#include <bits/stdc++.h> using namespace std; struct node { long long sum; long long c[2]; struct node *l; struct node *r; }; struct node *GetNode(void) { struct node *ret; ret = new struct node; ret->sum = 0; ret->c[0] = ret->c[1] = 0; ret->l = NULL; ret->r = NULL; return ret; }; void Check(struc...
14
#include <bits/stdc++.h> using namespace std; long long inv[2222222], fac[2222222], rfac[2222222], ans; int n, m; int main() { scanf("%d%d", &n, &m); fac[0] = fac[1] = 1; rfac[0] = rfac[1] = 1; inv[1] = 1; for (int i = 2; i <= 2000001; i++) { inv[i] = (998244353 - 998244353 / i) * inv[998244353 % i] % 998...
22
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 1) { cout << -1 << endl; } else { cout << "2 1"; for (int i = 3; i < n; i = i + 2) { cout << " " << i + 1 << " " << i; } cout << "\n"; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 200020; int belong[N], x, y, n, m, k, ans; int b[N], c[N]; struct node { int l, r; } A[N]; bool mycmp(node m, node n) { return (m.l < n.l); } int find(int x) { int fa = x; if (belong[x] != x) fa = find(belong[x]); belong[x] = fa; return fa; } int mai...
9
#include <bits/stdc++.h> using namespace std; const long long P = (long long)1e9 + 7; const int MAXN = 2000 + 10; int len; int p[MAXN]; int use[MAXN]; int n, k; long long dp[MAXN][MAXN]; long long fact[MAXN]; int main() { cin >> len; n = 0, k = 0; memset(use, 0, sizeof(use)); for (int i = int(1); i < int(len + ...
12
#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); int n, input, maxDist, diff, index, minDist; std::vector<int> arr; std::cin >> n; for (int i = 0; i < n; ++i) { std::cin >> input; arr.push_back(input); } index = 1, minDist = 99999; for (int i = 1; i...
1
#include <bits/stdc++.h> using namespace std; long long int powe(long long int a, long long int b) { long long int ans = 1; for (; b; b >>= 1) { if (b & 1) ans = ans * a; a = a * a; } return ans; } void solve() { long long int n; cin >> n; vector<long long int> a(n), aa; for (long long int i = 0...
4
#include <bits/stdc++.h> using namespace std; class Normalization { private: unordered_map<int, int> umap; public: Normalization(vector<int> arr) { sort(arr.begin(), arr.end()); arr.erase(unique(arr.begin(), arr.end()), arr.end()); int v = 0; for (int x : arr) umap[x] = ++v; } int operator[](...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { int k; cin >> k; int a[100000]; int number0 = 0; int number1 = 0; string s[1000]; int jishu = 0, oushu = 0; for (int i = 0; i < k; i++) { cin >> s[i]; a[i] = s[i].size(); if ...
6
#include <bits/stdc++.h> using namespace std; template <class T> string ToString(T t) { stringstream s; s << t; return s.str(); } template <class T> void ToOther(T& t, string a) { stringstream s(a); s >> t; } int n; int a[100005]; string rst; void go(char x, char y, int t) { while (t--) { rst += 'P'; ...
4
#include <bits/stdc++.h> const int MAXN = 1e5 + 5; int n, x, y; int a[MAXN], b[MAXN]; int cnt[MAXN]; std::vector<int> G[MAXN]; inline void chk() { int xx = 0, yy = 0; for (int i = 1; i <= n; ++i) if (a[i] == b[i]) ++xx; for (int i = 1; i <= n + 1; ++i) cnt[i] = 0; for (int i = 1; i <= n; ++i) cnt[a[i]]++; ...
17
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; int main() { vector<pair<int, int> > v(26, make_pair(INF, -1)); vector<vector<int> > g(26); vector<int> w; int i, k, p = 0; string s; getline(cin, s); cin >> k; for (i = 0; i < s.size(); i++) { if (v[s[i] - 'a'].second == -1) { ...
4
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; bool isprime(long long int a) { if (a == 1) return false; if (a == 2) return true; if (a % 2 == 0) return false; for (long long int i = 3; (i * i) <= a; i += 2) { if (a % i == 0) return false; } return true; } int main() { ios_base::...
7
#include <bits/stdc++.h> using namespace std; const int N = 200020; int n, m; struct Edge { int next, to; bool ontree; Edge() {} Edge(int next, int to, bool ontree = false) : next(next), to(to), ontree(ontree) {} } edge[N * 2]; int head[N], tot = 1; void AddEdge(int x, int y) { edge[++tot] = Edge(head[x...
23
#include <bits/stdc++.h> using namespace std; typedef struct S { int x, y; bool ml; } S; bool operator<(const S& a, const S& b) { if (a.x < b.x) return true; if (a.x > b.x) return false; if (a.y < b.y) return true; if (a.y > b.y) return false; return a.ml < b.ml; } const int N = 2222; const int DX[] = {1,...
10
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, su = 0, i = 1, x = 0; cin >> n; while (n != 0) { su = su + i; if (n < 10 && n > 0) { x = n; } n = n / 10; i++; } x = x - 1; su = su + 1...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k, p1 = 0, p2 = 0; string s, p, t = ""; cin >> n >> k; cin >> s >> p; p1 = n - k; p2 = n - k; for (int i = 0; i < s.length(); i++) t += '-'; for (int i = 0; i < n; i++) { if (s[i] == p[i] && p1 > 0 && p2 > 0) { p1--; p2--;...
9
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; int i; vector<long long> v; cin >> a >> b; long long x = b; if (a > b) { cout << "NO"; return 0; } v.push_back(b); while (1 == 1) { if (b == a) { break; } if (b < a) break; if (b % 2 == 0) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int k; cin >> k; string s; cin >> s; int i; int len = s.length(); if (len % k != 0) { cout << -1 << "\n"; return 0; } int new_len = len / k; vector<int> c(26, 0); for (i = 0; i < len; i++) {...
2
#include <bits/stdc++.h> using namespace std; template <typename T> T sqr(T x) { return x * x; } template <typename T> T abs(T x) { return x < 0 ? -x : x; } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } const int MAXN = 1e5 + 10; long long n, k, x; int main() { ios_base ::sync_with_std...
7
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; template <class T> T gcd(T a, T b) { return ((b == 0) ? a : gcd(b, a % b)); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<long long> x1(n), y1(n), x2(n), y2(n); for (i...
8
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 + 10; const int mod = 1; const int inf = 1e9; ll n, t, a[N], x, dp[N]; vector<ll> fac[N]; void sieve() { for (int i = 2; i < N; ++i) { for (int j = i; j < N; j += i) { fac[j].push_back(i); } } } int main() { ios_ba...
7
#include <bits/stdc++.h> const int MaxNum = 1.5e7; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int number[300005]; int imake[MaxNum + 5]; bool is_prime[MaxNum + 5]; int main() { int n, val = 0; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &number[i]); val = gcd(number[i], va...
10
#include <bits/stdc++.h> using namespace std; int n, q, per[1501], a, b, res; int vis[1501], id = 0; void change(int x, int y) { for (int i = x - 1, idx = y - 1; i < idx; i++, idx--) { swap(per[i], per[idx]); } res = 0; id++; for (int i = 0; i < n; i++) { if (vis[i] != id) { vis[i] = id; i...
10
#include <bits/stdc++.h> using namespace std; int fr[28]; int main() { int n; cin >> n; string s; cin >> s; for (int i = 0; i < n - 1; i++) { if (s[i] != s[i + 1]) { cout << "YES" << endl; cout << s[i] << s[i + 1]; return 0; } } cout << "NO"; }
2
#include <bits/stdc++.h> long long int a[50004]; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); if (a[1] + a[2] <= a[n]) { printf("%d %d %d\n", 1, 2, n); } else printf("-1\n"); } }
0
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, neg = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') neg = -1; c = getchar(); } while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); return x * neg; } inline void print(int x) { if (x < 0) { putchar('-'...
16
#include <bits/stdc++.h> using namespace std; int in[100001][2] = {}; bool ok[100001]; int val[100001]; int main() { int n, m; scanf("%d%d", &n, &m); int e[2] = {}; for (int i = 1; i <= n; ++i) { int x; scanf("%d", &x); val[i] = x; if (x < 0) { ++in[-x][0]; ++e[0]; } else { ...
8