solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; map<int, int> m1, m2; set<int> s; const int INF = 1e9; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int x, y; scanf("%d%d", &x, &y); m1[x]++; m2[y]++; if (x == y) m2[y]--; s.insert(x); s.insert(y); } int r = n / 2 + n % 2...
7
#include <bits/stdc++.h> using namespace std; unordered_map<int, int> mp; const long long INF = (1e18); int main() { long long a; scanf("%lld", &a); long long L = a - (INF % a * 9 % a * 9 % a) % a; long long R = L + INF - 1; printf("%lld %lld\n", L, R); return 0; }
17
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; long long i, j, k; long long x = 0; while (5 * (pow(2, x + 1) - 1) <= t) { if (5 * (pow(2, x + 1) - 1) == t) { cout << "Howard"; return 0...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int n, ans[maxn], opt[maxn], son[maxn][2], val[maxn]; bool v[maxn]; int turn(char s[]) { if (s[0] == 'I') return 1; if (s[0] == 'N') return 2; if (s[0] == 'O') return 3; if (s[0] == 'A') return 4; if (s[0] == 'X') return 5; } int dfs1(in...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m, k; cin >> n >> m >> k; long long ans = 0; set<long long> X, Y; for (int i = 0; i < m; i++) { long long x; cin >> x; if (x <= k) { X.insert(x); } els...
6
#include <bits/stdc++.h> using namespace std; long long ask(long long c, long long d) { cout << '?' << ' ' << c << ' ' << d << endl; cout.flush(); long long ans; cin >> ans; return ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long a = 0, b = 0; long long ans...
12
// besmellah #include <bits/stdc++.h> using namespace std; typedef long long int64; typedef pair<int,int> pii; #define PB push_back #define MP make_pair #define F first #define S second #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() const int maxn = 1e6; const int64 MO = 1000000007; const int64...
14
#include <bits/stdc++.h> using namespace std; const int MAX = 200005; int arr[MAX], ans[MAX], L[MAX], R[MAX]; int n; int getR(int i, int v) { if (i == -1 || i >= n) return -1; if (arr[i] < v) return i; return getR(R[i], v); } int getL(int i, int v) { if (i < 0) return -1; if (arr[i] < v) return i; if (!i) r...
11
#include <bits/stdc++.h> using namespace std; long long m = -1; int main() { int l, r, n1, n2, rem; cin >> l >> r; n1 = l, n2 = r; int len1 = 0, len2 = 0, arr[10] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; while (n1 > 0) { len1++; n1 /= 10; } while (n2 > 0) { len2++; n2 /= 10; } if (len1 < len2...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, p; scanf("%d%d", &n, &p); for (int i = 1; i <= 10000000; ++i) { long long m = n - 1ll * i * p, tmp = m; if (m < 0 && p > 0) break; int x = 0; while (m) x += (m & 1), m >>= 1; if (i >= x && i <= tmp) { printf("%d", i); ...
8
#include <bits/stdc++.h> using namespace std; constexpr int kN = int(1E5 + 10); vector<int> graph[kN]; vector<pair<int, int>> ans; bool dfs(int pos, int from, int val, int x, bool f) { if (val > x) return false; if (pos == 1) { if (f) ans.push_back({1, 0}); int now = 0; for (int i : graph[pos]) if...
18
/* problem : algorithm : created : Programmer_juruo */ #include <bits/stdc++.h> using namespace std; #define int long long #define N 2000005 #define M 2005 #define lowbit(x) x & (-x) #define F1(i, n) for(int i = 1; i <= n; i++) #define F(i, a, n) for(int i = a; i <= n; i++) #define F0(i, n) for(int i = 0; i < n; i++)...
5
#include <bits/stdc++.h> using namespace std; template <class U> inline void smin(U& a, U b) { if (a > b) a = b; } using VI = vector<int>; using VVI = vector<VI>; const int N = 1e6 + 1, M = 488, K = 2000; int f[N]; map<VI, int> mp; VI bag[K]; VI cur; int d[N], bn; int dst[K][M]; void make_bag(int m = 60, int k = 1) {...
20
#include <bits/stdc++.h> using namespace std; int main() { string s, s1; s = "Bulbasaur"; cin >> s1; map<char, long long int> m, m1; for (long long int i{0}; i < s.size(); i++) m[s[i]]++; for (long long int i{0}; i < s1.size(); i++) m1[s1[i]]++; map<char, long long int>::iterator itr, itr1; vector<long ...
2
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; struct node { int x, p; } a[N]; int d, n, m, top, xx, nexttttt[N], last, q[N]; long long ans; bool cmp(node a, node b) { return a.x < b.x; } int main() { scanf("%d%d%d", &d, &n, &m); for (int i = 1; i <= m; i++) scanf("%d%d", &a[i].x, &a[i].p);...
14
#include <bits/stdc++.h> using namespace std; long long int a, b; long long int A[100100]; long long int con; long long int isOk(long long int x) { if (x == 0) return 0; while (x > 0) { long long int u = x % 10; x = x / 10; if (u == 0) return 0; } return 1; } void makeChange() { long long int uu =...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int f[100001]; int b[100001]; bool amb[100001]; for (int i = 1; i <= n; i++) { f[i] = 0; amb[i] = false; } for (int i = 0; i < n; i++) { int x; cin >> x; if (f[x] != 0) amb[x] = true; f[x] = i + 1...
7
#include <bits/stdc++.h> using namespace std; bool SortbySecDesc(const pair<long long, long long> &a, const pair<long long, long long> &b) { return a.second > b.second; } bool SortbySecAsc(const pair<long long, long long> &a, const pair<long long, long long> &b) { return a.secon...
5
#include <bits/stdc++.h> using namespace std; struct xy { int x, y, i; xy(int _x, int _y, int _i) : x(_x), y(_y), i(_i) {} }; int N, K; bool cmp0(xy a, xy b) { return make_tuple(a.y, a.x, a.i) > make_tuple(b.y, b.x, b.i); } bool cmp1(xy a, xy b) { return make_tuple(a.x, a.y, a.i) > make_tuple(b.x, b.y, b.i); } ...
15
#include <bits/stdc++.h> using namespace std; const char S[8][10] = {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}; int main() { long long n; while (cin >> n) { char s[10]; cin >> s; long long v[10]; memset(v, 0, sizeof(v)); for (...
2
#include <bits/stdc++.h> using namespace std; const int N = 100005; vector<pair<int, int> > edge[N]; int dis[N], rdis[N], fa[N], rfa[N], mins[N]; int vis[N], stamp; int n, m; bool byrDis(int i, int j) { return rdis[i] < rdis[j]; } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < m; ++i) { int u, v, len; ...
14
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &x) { int f = 0; x = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) f |= (ch == '-'); for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; if (f) x = -x; } const int N = 55, mod = 1e9 + 7; int f[N][N], g[...
21
#include <bits/stdc++.h> using namespace std; long long power(long long, long long); long long mpower(long long, long long); long long BIT[1000009]; long long query(long long); void update(long long, long long); vector<long long> graph[1000009]; ; long long ans[1000009], dp[1000009], num[1000009]; long long val[1000009...
10
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; vector<long long int> a(n, 0); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); long long int ans = 0; for (int i = 0; i < n - 1; i++) { if (a[0] % k != a[i + 1] % k) { cout ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; const int maxm = 55; const int inf = 2147483647; const long long p = 998244353; const double eps = 1e-9; const long long INF = 9223372036854775807ll; long long fac[maxn], rev[maxn]; long long qpow(long long a, long long b) { long long ans = 1; w...
15
#include <bits/stdc++.h> using namespace std; struct Node { int l, r; long long x; }; vector<vector<Node> > node; int main() { int n, m; cin >> n >> m; node.resize(n + 1); for (int i = 0; i < m; ++i) { int op; cin >> op; if (op == 1) { int level; Node n; cin >> level >> n.l >> ...
16
#include <bits/stdc++.h> using namespace std; int n, a[20]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < (1 << n); i++) { int sum = 0; for (int j = 0; j < 16; j++) { if (((1 << j) & i)) sum += a[j]; else sum -= a[j]; } if (sum % 36...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; int parent[MAXN], size[MAXN]; int n; vector<int> erased; set<int> st; int Find(int x) { if (x == parent[x]) return x; return parent[x] = Find(parent[x]); } void Union(int x, int y) { x = Find(x), y = Find(y); if (x != y) { parent[y] = x...
13
#include <bits/stdc++.h> using namespace std; vector<int> vec[10]; queue<int> qu; bool ch[10] = {false}; int main() { string s1; cin >> s1; cout << s1; reverse(s1.begin(), s1.end()); cout << s1; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); char alcohol[][100] = {"ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE...
2
#include <bits/stdc++.h> using namespace std; const int N = 100005; struct NodeInfo { int node1 = -1; int dist1 = -1; int node2 = -1; int dist2 = -1; }; int n, m, d; int p[N]; int parent[N]; int depth[N]; bool isInfected[N]; vector<int> graph[N]; NodeInfo dp[N]; NodeInfo longestLCA; int longestLCANode = -1; Nod...
12
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long mod2 = 32416190039; long double PI = acosl(-1); const long long inf = 1e15; const int nmax = 2e5 + 6; long long dp[nmax][3]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, l, r; cin >> n >> l >> r; long ...
7
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } void sol() { int n, c = 0, i; cin >> n; int a[n]; for (i = 0; i < n; ++i) { cin >> a[i]; } for (i = 1; i < n - 1; i++) { if (a[i - 1] & a[i + 1] && !a[i]) c++, a[i + 1] = 0; } ...
2
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int MX = (int)1e10 + 7; const long long INF = 1e18 + 7; const long double PI = 3.141592653589793238462643383279; long long M = MOD; long long BinMul(long long a, long long b) { long long res = 0; while (a > 0) { if (a % 2) res = (...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, M = 40 * N; int n, rt, a[N], d[N], m, x, y, tin[N], tout[N], timer, sz, l[M], r[M], t[M], root[N]; vector<int> g[N], q[N]; inline int vcopy(int v) { sz++; l[sz] = l[v]; r[sz] = r[v]; t[sz] = t[v]; return sz; } void dfs(int v, int pr = -1...
15
#include <bits/stdc++.h> using namespace std; int arr[109]; int n, k, x, qwe; struct cont { int c, n; cont() {} cont(int c, int n) : c(c), n(n) {} }; vector<cont> con; int main() { scanf("%d%d%d", &n, &k, &x); memset(arr, 0, sizeof(arr)); for (int i = 1; i <= n; i++) scanf("%d", &arr[i]); int len = 0; f...
6
#include <bits/stdc++.h> using namespace std; bool comp(long long a, long long b) { return (a < b); } void solve(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); int t = 1; while (t--) { solve(); } cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" ...
5
#include <bits/stdc++.h> using namespace std; template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << '{'; for (int i = (0), __i = (((int)(vec).size())); i < __i; i++) { os << vec[i]; if (i + 1 != ((int)(vec).size())) os << ','; } os << '}'; return os; } template <class T1, c...
18
#include <bits/stdc++.h> using namespace std; int n, q, m; long long a[int(2e5 + 20)]; struct st { int re[2][6]; st() { for (int i = 0; i < m; i++) re[0][i] = re[1][i] = i + 1; re[0][m] = m; re[1][m] = 0; } inline st mr(st g) { st ru; for (int i = 0; i < 2; i++) for (int j = 0; j < m +...
22
#include <bits/stdc++.h> using namespace std; using LL = long long; const int MAXN = 500010; int n, k; vector<pair<int, LL>> x[MAXN]; LL f[MAXN][2]; void DP(int a, int fa) { LL sum = 0; vector<LL> z; LL pv = 0; for (auto [b, c] : x[a]) { if (b == fa) { pv = c; continue; } DP(b, a); s...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 300010; const int inf = 0x3f3f3f3f; int n, x, m; int a[maxn]; int b[maxn]; bool check(int x) { for (int i = 1; i <= n; ++i) b[i] = a[i]; if (b[1] + x >= m) b[1] = 0; for (int i = 2; i <= n; ++i) { if (b[i] > b[i - 1]) { if (b[i] + x - m >= b...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1000005; int n, k; int dp[maxn], length[maxn]; vector<int> E[maxn]; set<int> S; void addedge(int u, int v) { E[u].push_back(v); } void getdp(int u, int fa) { length[u] = 0; dp[u] = 1; bool first = true; for (int i = 0; i < E[u].size(); i++) { in...
16
#include <bits/stdc++.h> using namespace std; int days; string currentA, currentB, choose, rep; int main() { cin >> currentA >> currentB; cout << currentA << " " << currentB << endl; cin >> days; for (int i = 0; i < days; i++) { cin >> choose >> rep; if (choose == currentA) { currentA = rep; }...
1
#include <bits/stdc++.h> using namespace std; const int LEN = (int)1e6; int n, w; int l[LEN]; vector<pair<int, int>> add[LEN], rm[LEN]; multiset<int> s[LEN]; long long ans; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> w; for (int i = 0; i < n; i++) { int l; cin >> l; ...
14
#include <bits/stdc++.h> int main(void) { long long n, k, x; int p, flag = 0, i; scanf("%I64d%I64d%d", &n, &k, &p); if (n % 2 == 1) { flag = 1; if (k == 0) { for (i = 0; i < p; ++i) { printf("."); } return 0; } --n; --k; } long long full = (n + 1 - k), free = n ...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, c, m = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> c; m = max(m, c); } cout << m; return 0; }
3
#include <bits/stdc++.h> using namespace std; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; int n, m, k, col[1111][1111], dist[44][1111][1111], d[1111][1111], x, y, z, dd[44][44], res; int ax, ay, bx, by, q; bool In(int x, int y) { return (x >= 1 && x <= n && y >= 1 && y <= m); } void bfs(int c) { memset(d, -1,...
18
#include <bits/stdc++.h> using namespace std; const int N = 100005; int dr8[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dc8[] = {1, -1, 0, 0, -1, 1, -1, 1}; int dr4[] = {0, 1, -1, 0}; int dc4[] = {1, 0, 0, -1}; const int maxn = 3e5; int a[maxn + 10]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf...
11
#include <bits/stdc++.h> using namespace std; unordered_map<int, int> um; int main() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); um.clear(); int m = 0; for (int i = 0; i < n; i++) { int x; scanf("%d", &x); um[x]++; m = max(um[x], m); } int ty...
3
#include <bits/stdc++.h> using namespace std; int main() { long long c, d, n, m, k; cin >> c >> d >> n >> m >> k; if (k >= n * m) { cout << "0"; return 0; } else { long long t = (n * m - k); long long second, j, i; if (t % n == 0) second = (t / n) * c; else second = ((t / n) ...
7
#include <bits/stdc++.h> using namespace std; const int K = 1005, N = 55, M = 55, INF = 1E9 + 7; int k, n, m; int kmp_s[N], nxt_s[N][26], kmp_t[M], nxt_t[M][26]; int dp[K][N][M]; char code[K], s[N], t[M]; void init(char s[], int n, int kmp[], int nxt[][26]) { kmp[1] = 0; for (int i = 2; i <= n; i++) { int cur =...
13
#include <bits/stdc++.h> using namespace std; int a[15]; int main() { int n, maxn = -1; cin >> n; for (register int i = 1; i <= n; i++) { cin >> a[i]; maxn = max(maxn, a[i]); } cout << (maxn ^ a[n]) << endl; return 0; }
10
#include <bits/stdc++.h> using namespace std; const int MAX_N = (int)2e5; char conv(char a) { if (a >= 'a' && a <= 'z') return char(a - 'a' + 'A'); else if (a >= 'A' && a <= 'Z') return char(a - 'A' + 'a'); return ' '; } bool used[MAX_N] = {}; int cnt[MAX_N] = {}; int main() { string a, b; getline(cin...
6
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:134217728") using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } int n; int m; int main() { long long n, k, p; cin >> n >> k >> p; long long e = n - k; for (int i = 0; i < (p); i++) { long long x; cin >> x; x--; ...
11
#include <bits/stdc++.h> #pragma GCC optimize(3) #pragma GCC optimize(2) #pragma GCC optimize("Ofast") using namespace std; const long long mod = 1e9 + 7; long long fac[1000011]; long long inv(long long p) { long long ret = 1, base = p, pw = mod - 2; while (pw > 0) { if (pw % 2 == 1) { ret = ret * base; ...
15
#include <bits/stdc++.h> using namespace std; template <typename T> inline T POW(T B, T P) { if (P == 0) return 1; if (P & 1) return B * POW(B, P - 1); else return SQR(POW(B, P / 2)); } template <typename T> inline T ModInv(T b, T m) { return BigMod(b, m - 2, m); } template <typename T> inline T ABS(T a...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m, y, a[N], b[N], base2[31], ans, LUOGU; void solve(int u) { map<int, int> cntd, cntu; int mod = base2[u + 1]; for (int i = 1; i <= n; i++) { cntd[a[i] % mod]++; } for (int i = 1; i <= m; i++) { cntu[b[i] % mod]++; } for (...
17
#include <bits/stdc++.h> int main() { int n, arr[101], input[101], i, sum = 0, count = 0, count2 = 0; scanf("%d", &n); for (i = 0; i < 101; i++) { arr[i] = 0; } for (i = 0; i < n; i++) { scanf("%d", &input[i]); } int x = input[0]; for (i = 0; i < n; i++) { arr[input[i]]++; } for (i = 0; ...
2
#include <bits/stdc++.h> namespace chtholly { inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) f ^= c == '-'; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ '0'); return f ? x : -x; } template <typename mitsuha> inline bool read(mitsuha &x) { x =...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 400010, maxm = maxn << 1; int to[maxm], head[maxn], Next[maxm], w[maxm], dis[maxn][110]; int tot; int n, m, k, S; void add(int x, int y, int v) { to[++tot] = y; Next[tot] = head[x]; head[x] = tot; w[tot] = v; } struct node { int x, y; node(int a...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n; cin >> n; long long int arr[n + 3]; for (long long int i = 0; i < n; i++) cin >> arr[i]; long long int diff = arr[1] - arr[0]; for (long long int i = 2; i < n; i...
2
#include <bits/stdc++.h> int main() { double a, b, x, y, k, m; char c; scanf("%lf%c%lf", &x, &c, &y); if (x >= 12) x = x - 12; k = ((x + (y / 60)) * 60) / 2; m = (y * 6); printf("%.1lf %.0lf", k, m); }
4
#include <bits/stdc++.h> struct NODE { int x; int y; } node[10]; int main() { int i, def, att, a, b, c, d; a = 0; b = 0; c = 0; for (i = 1; i <= 4; i++) { scanf("%d%d", &node[i].x, &node[i].y); } def = node[1].x; att = node[2].y; if (node[3].x < att && node[4].y < def && node[3].y < def && ...
9
#include <bits/stdc++.h> #pragma comment(linker, "/stack:32000000") using namespace std; const int INF = 2147483647; const long long LLINF = 9223372036854775807LL; const int maxn = 100010; vector<int> a[maxn]; vector<pair<pair<int, int>, pair<int, int> > > ans; int u[maxn]; pair<int, int> dfs(int x, int par) { u[x] =...
15
#include <bits/stdc++.h> using namespace std; class pont { public: long long x, y; int id; }; int n, m; vector<pont> p; pont operator-(const pont& p1, const pont& p2) { return {p1.x - p2.x, p1.y - p2.y}; } int sgn(long long a) { return (a > 0) - (a < 0); } int irany(const pont& p1, const pont& p2) { return sgn...
13
#include <bits/stdc++.h> using namespace std; int cnt[100001]; int a[100001]; int n; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); cnt[a[i]]++; } for (int i = 2; i <= 100001; i++) if (cnt[i] > cnt[i - 1]) { printf("-1\n"); return 0; } printf("%d\n"...
7
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000000000LL; const int maxn = 100010; vector<long long> v; long long s[maxn], a[maxn], c[maxn], K; inline int lowbit(int x) { return x & (x ^ (x - 1)); } void add(int x, int t, int n) { while (x <= n + 5) { c[x] += t; x += lowbit(x); ...
14
#include <bits/stdc++.h> int main() { char A[100001]; char B[100001]; while (scanf("%s%s", A, B) == 2) { int count = 0; int _4, _7; _4 = _7 = 0; for (int i = 0; A[i] != '\0'; i++) { if (A[i] != B[i]) { count++; if (A[i] == '4') _4++; else _7++; ...
4
#include <bits/stdc++.h> using namespace std; int n; int a[300005]; long long p[300005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) p[i] = p[i - 1] + a[i]; long long ans = 0;...
4
#include <bits/stdc++.h> const int N = 100005; int t, n; char str[N]; int main(void) { scanf("%d", &t); while (t--) { scanf("%d%s", &n, str + 1); int l = 1, r = n; while (str[l] == '0') ++l; while (str[r] == '1') --r; if (l > r) printf("%s\n", str + 1); else { for (int i = 1; i <...
4
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char ch = getchar(); while (ch - '0' < 0 || ch - '0' > 9) { if (ch == '-') f = -1; ch = getchar(); } while (ch - '0' >= 0 && ch - '0' <= 9) { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int n, m, A, B...
18
#include <bits/stdc++.h> using namespace std; long long in() { long long a; scanf("%lld", &a); return a; } double din() { double a; scanf("%lf", &a); return a; } long long bigmod(long long b, long long p, long long md) { if (p == 0) return 1; if (p % 2 == 1) { return ((b % md) * bigmod(b, p - 1, md)...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> vt(n - 1, 1); for (int i = 0; i < n - 1; i++) { cin >> vt[i]; } vector<int> path; int i = n; while (true) { path.push_back(i); i = vt[i - 2]; if (i == 1) { break; } } cout << 1 << " "; ...
1
#include <bits/stdc++.h> using namespace std; int n, maxx; string s, max_two_gram; unordered_map<string, int> two_gram; int main() { cin >> n >> s; for (int i = 0; i < n - 1; i++) { two_gram[s.substr(i, 2)]++; } for (auto i : two_gram) { if (i.second > maxx) { maxx = i.second; max_two_gram =...
1
#include <bits/stdc++.h> using namespace std; int main(void) { string a, b, c; getline(cin, a); getline(cin, b); getline(cin, c); int f = 0; for (int i = 0; i < a.length(); i++) { if (a[i] == 'a' || a[i] == 'e' || a[i] == 'i' || a[i] == 'o' || a[i] == 'u') f++; } if (f == 5) { int s = 0; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; while (cin >> n >> m) { int str[550][550], cnt[550], ans[550]; memset(str, 0, sizeof(str)); memset(cnt, 0, sizeof(cnt)); memset(ans, 0, sizeof(ans)); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; str[...
10
#include <bits/stdc++.h> using namespace std; char s[1000000]; int cnt[26], t[3000][3000], n; int f(int from, int to) { if (from < 0 || to >= n) return 0; if (t[from][to] > -1) return t[from][to]; t[from][to] = max(f(from - 1, to), f(from, to + 1)); if (s[from] == s[to]) t[from][to] = max(t[from][to], 2 + f(fro...
11
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int C = 26; void add(int &x, int y) { x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; } int fix(int x) { while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x; } int pw(int a, int b) { int ret = 1; while (b) { ...
12
#include <bits/stdc++.h> using namespace std; int main() { int m, n, x; int arr[100], a1[100], a[100]; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> a1[i]; } x = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i]...
0
#include <bits/stdc++.h> using namespace std; std::mt19937 rnd( (int)std::chrono::steady_clock::now().time_since_epoch().count()); long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 100000; const int MAXSUMLEN = 1000000; const int MOD = 1000000007; void inc(int& a, int b...
24
#include <bits/stdc++.h> using namespace std; int n, k; int a[1007]; long long ans = 0; long long dp[2][1007]; long long pref[1007]; long long prv_ans; long long calc(int sr) { int curr = 0, prv = 1; for (int i = 1; i <= n; i++) { dp[prv][i] = 1; } for (int j = 2; j <= k; ++j) { for (int i = 1; i <= n; ...
17
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const long long linf = 1LL << 62; const int MAX = 1020000; long long dy[8] = {0, -1, 0, 1, 1, -1, 1, -1}; long long dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const double pi = acos(-1); const double eps = 1e-7; template <typename T1, typename T2> inline ...
14
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; long int a[100002], b[100002]; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 1; i < n; i++) { b[i] = a[i] + a[i + 1]; } b[n] = a[n]; for (i = 1; i <= n; i++) { cout << b[i] << " "; } }
0
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, i, j, t = 0, p = 0, q = 0; cin >> n >> m; for (i = 0; i < n; i++) { string s; cin >> s; for (int j = 0; j < m; j++) if (s[j] == 'B') { t++; p += (i + 1); q += (j + 1); } } p /= t; q...
0
#include <bits/stdc++.h> using namespace std; struct trie { int sum; int u[4200005][2]; long long v[4200005]; void clear() { sum = 1; memset(u[0], 0, sizeof(u[0])); } void insert(int *str, long long val) { int x = 0; for (int i = 0; i < 40; i++) { int c = str[i]; if (!u[x][c]) { ...
14
#include <bits/stdc++.h> using namespace std; int main() { int n, s; int a[1100], b[1100]; scanf("%d%d", &n, &s); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &b[i]); if (!a[1]) { printf("NO\n"); return 0; } if (a[s]) { printf("YES\n"); return...
1
#include <bits/stdc++.h> using namespace std; class TaskB { private: int dirx[4]{1, -1, 0, 0}; int diry[4]{0, 0, 1, -1}; int n, m; bool valid(int x, int y, const vector<string>& grid) { return (x >= 0 && x < n && y >= 0 && y < m && grid[x][y] != '*'); } bool dfs(int x, int y, int turn, int dir, const v...
8
#include <bits/stdc++.h> using namespace std; const int64_t INF = 1e9, MOD = 1e9 + 7, MAXN = 1e5 + 7, MAX = 5; const long double EPS = 1e-9, PI = acos(-1); int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int64_t n, u; cin >> n >> u; vector<int64_t> nums(n); for (int64_t i = 0; ...
8
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; const int MOD = 1e9 + 7; const ll INF = 1e18; inline void fastio() { ios_base::sync_with_stdio(false); cin.tie(NULL); } template <typename A, typename B> ostream &operator<<(ostream &os, const...
6
#include <bits/stdc++.h> using namespace std; long long f[55][55][2], n, m, ans, c[55][55]; long long qmod(long long a, long long b) { long long t = 1; while (b) { if (b % 2) t = ((long long)t * (long long)a) % 1000000007; b /= 2; a = ((long long)a * (long long)a) % 1000000007; } return t; } int mai...
18
#include <bits/stdc++.h> using ll = long long; const ll mod = 998244353; const ll N = 3e5 + 5; const int base = 400; using ull = unsigned long long; using namespace std; ll n, m, t, k, T, a[N], dp[N], lab[N], u, v, b[N], d[N], tong, cnt, q, fe[N], ans; vector<ll> adj[N]; vector<pair<ll, ll> > adt[N]; void add(ll id...
15
#include <bits/stdc++.h> using namespace std; template <typename T> bool get_int(T &x) { char t = getchar(); bool neg = false; x = 0; for (; (t > '9' || t < '0') && t != '-' && t != EOF; t = getchar()) ; if (t == '-') neg = true, t = getchar(); if (t == EOF) return false; for (; t <= '9' && t >= '0'; ...
17
#include <bits/stdc++.h> using namespace std; long long power(long long a, int b) { long long res = 1; for (int i = 0; i < b; ++i) { res *= a; } return res; } int nbc(long long a) { int b = 0; while (a > 0) { a /= 10; b++; } return b; } int main() { long long w, m, k, n, r, u, v, z, res = ...
8
#include <bits/stdc++.h> using namespace std; long long i, j, k, n, x, y, m[600000], a, b, z; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> a >> b; x = 0; y = 0; if (b <= a) { cout << b << endl; continue; } x = b % a; z = b / a; for (j = 0; j < x; j++) { y...
2
#include <bits/stdc++.h> const double E = 2.7182818284590452353602874713527; using namespace std; long in[100000], fn[100000]; int main() { long i, j, n, num, cn, cnt, y = 0, p, q; scanf("%ld%ld", &num, &n); for (i = 0; i < num; i++) { scanf("%ld%ld", &p, &q); in[i] = (p < q ? p : q); fn[i] = (p < q ?...
2
#include <bits/stdc++.h> using namespace std; signed main() { long long t; cin >> t; while (t--) { long long p, q; cin >> p >> q; if (p % q != 0) { cout << p << endl; continue; } long long w = sqrt(q); long long ma = 1; long long h; for (long long i = 2; i <= w; i++) { ...
7
#include <bits/stdc++.h> using namespace std; int main() { long double x1, x2, y1, y2, r1, r2; cin >> x1 >> y1 >> r1; cin >> x2 >> y2 >> r2; long double d = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); if (r1 < r2) { swap(r1, r2); swap(x1, x2); swap(y1, y2); } if (d >= r1 + r2) { r...
12
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; const int MAXX = 1e7 + 10; int cnt[MAXX]; int A[MAXN]; int main() { int n; scanf("%d", &n); int mx = -1; for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); A[i] = x; cnt[x]++; mx = max(mx, x); } long long ans = ...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 * 100 + 10; long long ent[maxn], ext[maxn], a[maxn], dp[maxn], ans_min[maxn], ans_max[maxn]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n, m, open, close; cin >> n >> m; long long cur = 0; for (int i = 0; i < n; i+...
11
#include <bits/stdc++.h> using namespace std; int dp[100100][24]; int a[3000100]; int n, mas[100100], st[100100][24], inf = 10000000, ans; int was[25]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &mas[i]); int xx = mas[i]; for (int j = 1; j <= 20; j++) { st[i][j] = xx ...
8