solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; char s[100010]; long long dp[2010][2010]; int l, r; int main() { int n; int m; scanf("%d%d", &n, &m); scanf("%s", s); if (n % 2) { printf("0\n"); return 0; } int maxx = -1000010; for (int i = 0; i < m; i++) { if (s[i] == '(') l++; else ...
12
#include <bits/stdc++.h> using namespace std; void solve() { long long int str, mnd, exp, ans, zero = 0; cin >> str >> mnd >> exp; ans = max(zero, (mnd + exp - str + 2) / 2); cout << max(zero, exp - ans + 1) << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); long long int t = 1; cin >> t; wh...
5
#include <bits/stdc++.h> using namespace std; int fx[] = {0, 1, 0, -1}; int fy[] = {-1, 0, 1, 0}; int main() { long long t, i, j, n, m, k, r, r1, q, ck, ck1, cnt = 0, sum = 0, c = 0, ans = 0, res = 0; string s, s1, s2, tmp, tmp1; cin >> n; if (n == 1) { cout ...
7
#include <bits/stdc++.h> using namespace std; int main() { srand((unsigned int)time(NULL)); map<char, char> ma; ma['A'] = 'A'; ma['H'] = 'H'; ma['I'] = 'I'; ma['M'] = 'M'; ma['O'] = 'O'; ma['T'] = 'T'; ma['U'] = 'U'; ma['V'] = 'V'; ma['W'] = 'W'; ma['X'] = 'X'; ma['Y'] = 'Y'; string s; cin...
2
#include <bits/stdc++.h> using namespace std; int n; int a[200]; string w, s[200], ans; char ch, ch1; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> s[i]; for (int j = 0; j < s[i].size(); j++) if (s[i][j] <= 'Z') s[i][j] = s[i][j] - 'A' + 'a'; } cin >> w; for (int i = 0; i < w.size(...
8
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; const ld PI = acos(-1); const ll mod = 998244353; const ll root = 62; void debug(vll A) { for (auto i : A) { cerr << i << ' '; } cerr << '\n'; } ll fpow(ll a, ll b) { ll ret = 1; while (b) {...
18
#include <bits/stdc++.h> using namespace std; long long n, k; int a[124], ans; int dp[124][50024], maxN = 50024; long long get(long long nn, int ind) { if (!nn) { return 0; } if (ind == k) { return nn; } if (nn < maxN && dp[ind][nn] >= 0) { return dp[ind][nn]; } long long crr = get(nn, ind + 1...
18
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using vpii = vector<pii>; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using pll = pair<ll, ll>; using vpll = vector<pll>; using vll = vector<long long>; using vvll = vector<vll>; template <class T> istream &operator>>(is...
0
#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); unsigned n, k; std::cin >> n >> k; const unsigned maxn = 500000; std::array<unsigned, maxn> a, b; for (unsigned i = 0; i < n; i++) std::cin >> a[i]; for (unsigned i = 0; i < n; i++) std::cin >> ...
21
#include <bits/stdc++.h> using namespace std; int n, m, k; vector<vector<int> > v; bool transponer; void escribe() { if (transponer) { vector<vector<int> > nextv(m + 2, vector<int>(n + 2, 0)); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) nextv[j][i] = v[i][j]; swap(n, m); v = nextv;...
23
#include <bits/stdc++.h> int n; double x[510], y[510], t; int main() { scanf("%d", &n); printf("%d\n", 4 * n + 1); x[1] = y[1] = 0; t = atan(1.0) * 0.8; x[2] = cos(t) * 10; y[2] = sin(t) * 10; x[3] = x[2] * 2; y[3] = 0; x[4] = x[3] - sin(t / 2) * 10; y[4] = -cos(t / 2) * 10; x[5] = sin(t / 2) * 10...
15
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), (c > '9' || c ...
11
#include <bits/stdc++.h> using namespace std; bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) { if (a.first.first != b.first.first) return a.first.first > b.first.first; if (a.first.second != b.first.second) return a.first.second < b.first.second; return a.second < b.second; } void _print(long ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, i, j, z = 0; cin >> n >> m >> x; for (i = x - 1; i < n - x + 1; i++) { for (j = x - 1; j < m - x + 1; j++) { if (i == x - 1 || i == n - x || j == x - 1 || j == m - x) { if ((i + j) % 2 == 0) { z++; } ...
8
using namespace std; #include <cstdio> #include <cstring> #include <algorithm> #include <cassert> #define N 57 #define ll long long #define INF 0x3f3f3f3f3f3f3f3f int n,k; ll lim[N][2]; int lg(ll x){ ll c=0; for (;x;x>>=1) ++c; return c; } int kb[N]; ll c[N]; ll f[N][N][N][4][4];//(0/1,0/1) keybit , if equal to i ...
27
#include <bits/stdc++.h> using namespace std; const int MAXN = 300000; const int bse[2] = {131, 13131}; const int MOD[2] = {int(1E9) + 7, int(1E9) + 9}; void exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1, y = 0; return; } long long x1, y1; exgcd(b, a % b, x1, y1); x...
12
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const long long infLL = 9000000000000000000; inline bool checkBit(long long n, int i) { return n & (1LL << i); } inline long long setBit(long long n, int i) { return n | (1LL << i); ; } inl...
9
#include <bits/stdc++.h> using namespace std; int n; int x[1100000]; int main() { cin >> n; cout << n << endl; int t; for (int i = 0; i < n; i++) { scanf("%d", &t); x[t] = 1; } int A = 1000000; int k = 0; for (int i = 1; i <= A / 2; i++) { if (x[i]) { if (!x[A + 1 - i]) { print...
9
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long INF = 1e18; const long long MAX = 105; vector<string> vec(MAX); vector<pair<int, int>> ans; void check() { int i = 3; auto itr = ans.end(); --itr; while (i) { vec[itr->first][itr->second] = (vec[itr->firs...
7
#include <bits/stdc++.h> using namespace std; vector<int> children[1000001]; int n, k; vector<int> edge[1000001]; bool seen[1000001]; void dfs(int parent) { seen[parent] = true; for (int e : edge[parent]) { if (seen[e]) continue; children[parent].push_back(e); dfs(e); } } multiset<int> alloc[1000001];...
16
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long N = 1e9 + 7; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n; cin >> n; string s; cin >> s; long long cnt = 0; while (s...
9
#include <bits/stdc++.h> int main() { long long int n; scanf("%lld", &n); n = (n / 10000LL) * 10000LL + ((n / 100LL) % 10LL) * 1000LL + (n % 10) * 100LL + (n / 10LL % 10LL) * 10LL + (n / 1000LL % 10LL); n = 10LL * (n / 100LL) * (n / 100LL) * 10000LL % 100000LL * (n % 100LL) * (n % 100LL) * (n % ...
6
#include <bits/stdc++.h> using namespace std; long long n; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; cout << n << '\n'; for (int i = 0; i < n; i++) cout << 1 << ' '; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, j, k; cin >> n; if (n % 2 == 0) cout << "-1\n"; else { if (n == 1) cout << "0\n0\n0\n"; else { long long arr[n], brr[n], crr[n]; for (i = 0; i < n; i++) arr[i] = i; brr[n - 1] = 1; brr[n - 2] = 0...
5
#include <bits/stdc++.h> using namespace std; int n; int a, b, c, d; int f; void gao(int x) { if (f) return; if (a + c <= n) { printf("%d %d %d", x, a, n - a); f = 1; return; } if (a + d <= n) { printf("%d %d %d", x, a, n - a); f = 1; return; } if (b + c <= n) { printf("%d %d %d"...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; struct Chairman_Tree { int cnt, lson[maxn * 40], rson[maxn * 40], sum[maxn * 40]; void clear() { cnt = 0; } int Newnode(int rt) { int nrt = ++cnt; sum[nrt] = sum[rt] + 1; lson[nrt] = lson[rt]; rson[nrt] = rson[rt]; return ...
15
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7; int n, q, a[N], l[N], ans[N], seg[N * 4], lazy[N * 4]; vector<int> id[N]; void LAZY(int p, int L, int R) { if (L != R) { lazy[2 * p] += lazy[p]; lazy[2 * p + 1] += lazy[p]; } seg[p] += lazy[p]; lazy[p] = 0; return; } void update(int ...
15
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void solve() { string a, s, b; cin >> a >> s; long long curr_a, curr_s, len_a = 1, len_s = 1, ai = a.length() - 1, si = s.length() - 1; while (ai >= 0 && si >= 0) { ...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; template <class T, class U> inline void Max(T &a, U b) { if (a < b) a = b; } template <class T, class U> inline void Min(T &a, U b) { if (a > b) a = b; } inline void add(int &a, int b) { a += b; if (a >= 10000000...
25
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T& x) { char c; int sign = 1; x = 0; do { c = getchar(); if (c == '-') sign = -1; } while (!isdigit(c)); do { x = x * 10 + c - '0'; c = getchar(); } while (isdigit(c)); x *= sign; } const int N = 3e5 + 5...
24
#include <bits/stdc++.h> using namespace std; int a[50][2]; int d[50]; bool v[50]; vector<int> ans; vector<int> e; vector<int> iso; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; if (m > n) { cout << -1; return 0; } int u, z; for (int i = 1; i <= m; i++) {...
7
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long MX = 2e5 + 5; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc; cin >> tc; while (tc--) { int n; cin >> n; vector<int> v; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { ...
5
#include <bits/stdc++.h> int number(std::string arg) { if (arg == "") { return 0; } if (arg == "T") { return 1; } if (arg == "int") { return 2; } if (arg == "string") { return 3; } if (arg == "double") { return 4; } } void h5(int* Mat_5, std::string arg5) { if (arg5 == "T") { ...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = cost; if (m > (T - t))...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; const int mod = 1e9 + 7; int n, k; long long s[maxn], lv[maxn], lv1[maxn]; char num[maxn]; long long ans; long long C(int n, int r) { if (r > n) return 0; if (r == 0 || n == r) return 1; return ((lv[n] * lv1[r]) % mod * lv1[n - r]) % mod; } lo...
14
#include <bits/stdc++.h> using namespace std; priority_queue<pair<int, int> > big, small; int par[((int)(1e6 + 1))], cnt[((int)(1e6 + 1))], lef[((int)(1e6 + 1))]; int findpar(int n) { if (n == par[n]) return n; return par[n] = findpar(par[n]); } int main() { int n, m, k, i, a, b, ans, prov; scanf("%d %d %d", &n...
14
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x1, x2, y1, y2, x, y; cin >> n >> m >> x1 >> y1 >> x2 >> y2; x = abs(x1 - x2); y = abs(y1 - y2); if (x > 4 || y > 4) { cout << "Second"; return 0; } if (x < 3 || y < 3) { cout << "First"; return 0; } if (x == 3 && y =...
12
#include <bits/stdc++.h> using namespace std; int main() { int i, a, spd, pr = 0, count = 0, in, val, l, j; stack<int> s; scanf("%d", &a); while (a--) { scanf("%d", &in); if (in == 2) pr += count, count = 0; else if (in == 4) count = 0; else if (in == 6) count++; else if (i...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int mini = INT_MAX; vector<int> a(n), b(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) { b[i] = a[i]; a[i] = ((k - a[i - 1]) > a[i]) ? (k - a[i - 1]) : a[i]; } b[0] = a[0]; int sum = 0...
2
#include <bits/stdc++.h> int power(int x, unsigned int y) { int res = 1; while (y > 0) { if (y & 1) { res = res * x; } y = y >> 1; x = x * x; } return res; } int powermod(int x, unsigned int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) { res = (res * x) % ...
15
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e5 + 5; long long dp[MAXN][2]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<pair<int, int>> a; a.push_back(make_pair(0, 1)); a.push_back(make_pair(0, 1)); for (int i = 0; i < 2 * n; i++) { int...
4
#include <bits/stdc++.h> using namespace std; int n, m, k; bool debug = false; int main() { scanf("%d", &n); if (n == 2) puts("-1"); else { int a[3] = {6, 10, 15}; set<int> ans; int j = 1; while (ans.size() < n) { for (int i = 0; i < 3; i++) { ans.insert(a[i] * j); } ...
9
#include <bits/stdc++.h> using namespace std; int n, m, head[1234567], ord[1234567], id; int cnt, u, v, w, in[1234567], l, r, s; vector<int> p; struct data { int u, v, w; } e[1234567]; struct node { int to, v, w; } edge[1234567]; void add(int u, int v, int w) { edge[++cnt].v = v; edge[cnt].to = head[u]; edge[...
14
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, const U &b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, const U &b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), ...
18
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { if (a > b) return a; return b; } int main() { ifstream myFile("task.in"); if (!myFile.fail()) { assert(freopen("task.in", "r", stdin)); } long long n; cin >> n; vector<int> v, tmp; int all = 0; if (n < 10) { ...
4
#include <bits/stdc++.h> using namespace std; int II; long long I_O; char CC, SS[20]; const int N = 2e5 + 4; inline long long read() { II = 1, I_O = 0; while (!isdigit(CC = getchar())) if (CC == '-') II = -1; while (isdigit(CC)) I_O = I_O * 10 + CC - '0', CC = getchar(); return I_O * II; } inline void wonl(...
11
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long n, f[300][300], sum; bool vis[300][300]; struct node { long long x, y; node(long long x = 0, long long y = 0) : x(x), y(y) {} node operator-(const node &p) const { return node(x - p.x, y - p.y); } } a[300]; long long cross(n...
17
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } int n; int m; int x[200000]; int y[200000]; long double p[200001]; int gcd(int a, int b) { return a ? gcd(b % a, a) : b; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &x[i], &y[...
20
#include <bits/stdc++.h> using namespace std; const double eps = 0.000000000000001; string convertstring(long long n) { stringstream ss; ss << n; return ss.str(); } bool pr[2000007]; long long a[2000007], lo[2000007], hi[2000007], cum[2000007]; int main() { long long n, X, Y, i, j; scanf("%lld%lld%lld", &n, &...
13
#include <bits/stdc++.h> using namespace std; int n, m, head[10005], cnt, ll[10005], rr[10005], vis[10005], ans, ma[1005][1005]; int id; struct node { int v, l, r; node() {} node(int vv, int ll, int rr) : v(vv), l(ll), r(rr) {} }; vector<node> q[10005]; bool check(int u, int l, int r) { if (l > r) return 0;...
12
#include <bits/stdc++.h> using namespace std; #pragma GCC diagnostic ignored "-Wmissing-declarations" int main() { cout << fixed << setprecision(15); ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; double ans = 1.0 / n; if (n > 1) { ans += (n - 1.0) / n * (m - 1.0) ...
13
#include <bits/stdc++.h> using namespace std; const int maxt = 45; long long C[maxt][maxt]; void solve(long long n, int cnt) { int cntn = 0; for (long long x = n; x; x >>= 1, cntn++) ; assert(cntn < maxt); long long ans = 0; int need = cnt, left = cntn - 1; for (int put = 0; put <= cntn && need >= 0; pu...
12
#include <bits/stdc++.h> using namespace std; const long long MAXN = 100005; const long long MOD = 1e9 + 7; long long n; long long x[MAXN]; vector<long long> g[MAXN]; map<long long, long long> mp[MAXN]; long long ans = 0; long long gcd(long long a, long long b) { while (b) { a %= b; swap(a, b); } return a...
12
#include <bits/stdc++.h> using namespace std; int a[1005]; pair<int, int> p[1005]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); p[i] = make_pair(a[i], i); } sort(p + 1, p + 1 + n); reverse(p + 1, p + 1 + n); vector<pair<int, string> > v; for (int i = 1;...
18
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b, long long m) { long long res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } long long seg[4000005]; long long lz[4000005]; long long dp[1000005]; void push(long long ve...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int nr = 1; vector<int> lv = {0}; vector<int> room = {0}; for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); if (room[x] < nr && lv[room[x]] == x) { lv[room[x]] = i; room.push_back(room[x]); } else { ...
5
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a >= b) return a; else return b; } long long int min(long long int a, long long int b) { if (a >= b) return b; else return a; } int main() { int t; scanf("%d", &t); for (int i = 0; i < t...
0
#include <bits/stdc++.h> int main() { long long int a, b, c, s1 = 0, s2 = 0, s3 = 0, rem, com1 = 0, n1 = 0, n2 = 0, com2; scanf("%I64d", &a); scanf("%I64d", &b); c = a + b; while (c != 0) { rem = c % 10; if (rem != 0) { s1 = s1 * 10 + rem; } c /= 10; } while ...
2
#include <bits/stdc++.h> using namespace std; int mas[100010]; int cnt[100010]; int main() { memset(cnt, 0, sizeof(cnt)); int n, x; cin >> n >> x; long long result = 0; for (int i = 0; i < n; ++i) { cin >> mas[i]; if ((mas[i] ^ x) <= 100000) { result += cnt[mas[i] ^ x]; } cnt[mas[i]]++; ...
7
#include <bits/stdc++.h> using namespace std; int main() { int q = -2.1e9, w = -2.1e9, e = -2.1e9, r = -2.1e9, x, y, c, a = -(-2.1e9), C, p; cin >> x >> y >> c; while (c--) scanf("%d%d", &x, &y), q = max(q, x + y), w = max(w, x - y), e = max(e, y - x), r = max(r, -x - y); ci...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<string> words(n); for (int i = 0; i < n; i++) cin >> words[i]; string str; cin >> str; string wh; for (int i = 0; i < n; i++) { wh += "<3" + words[i]; } wh += "<3"; size_t pos...
7
#include <bits/stdc++.h> using namespace std; long long n; long long dfs(long long n) { if (n < 10) { return max((long long)1, n); } return max((n % 10) * dfs(n / 10), 9 * dfs(n / 10 - 1)); } int main() { cin >> n; cout << dfs(n) << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; long long const mod = 1000000007; long long const md = 998244353l; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } ifstream in...
8
#include <bits/stdc++.h> const int N = 100005; const long double pi = 3.141592653; const long long MOD = 1000000007; using namespace std; int dx[9] = {1, -1, 0, 0, 1, 1, -1, -1, 0}; int dy[9] = {0, 0, 1, -1, 1, -1, 1, -1, 0}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; while...
4
#include <bits/stdc++.h> using namespace std; int pd[2][55][105], n, k, p, v[20005]; int main() { cin >> n >> k >> p; for (int i = 1; i <= n; ++i) { cin >> v[i]; v[i] %= p; } int sum = 0; memset(pd, -1, sizeof(pd)); pd[1][1][v[1]] = v[1]; sum = v[1]; for (int i = 2; i <= n; ++i) { sum += v[i...
12
#include <bits/stdc++.h> using namespace std; vector<int> G[100100]; vector<int> ans; bool full[100100]; bool is[100100]; int dep[100100], want[100100]; bool cmp(const int &o, const int &p) { return dep[want[o]] > dep[want[p]]; } void dfs(int o, int fa, int depth) { dep[o] = depth; for (auto &i : G[o]) { dfs(i,...
12
#include <bits/stdc++.h> using namespace std; int p1, p2, p3; int t1, t2; int n; int main() { cin >> n; cin >> p1 >> p2 >> p3; cin >> t1 >> t2; int prev = 0; int res = 0; for (int i = 0; i < n; ++i) { int l, r; cin >> l >> r; if (i > 0) { res += max(0, min(l - prev, t1)) * p1; prev +...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m, cnt = 0, maxi = 1, a, i, mini = 10e9, res; double sum = 0; cin >> n; for (i = 0; i < n; i++) { scanf("%d", &a); sum += a; maxi = max(maxi, a); } res = ceil(sum / (n - 1)); cout << max(maxi, res); return 0; }
8
#include <bits/stdc++.h> using namespace std; bool vis[100005] = {0}; set<int> d[100005]; char ch[5]; int tmp; int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> ch >> tmp; if (ch[0] == '+') { if (vis[tmp]) printf("Already on\n"); else { bool flag = true...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> d(8, 0); int cnt = 0; for (int i = 0; i < n; i++) { int b; cin >> b; d[b]++; cnt++; } int a = d[4]; int c = d[2] - a; int b = d[6] - c; if (a < 0 || b < 0 || c < 0 || a + b + c != d[1] || d[3] != ...
4
#include <bits/stdc++.h> using namespace std; int n, i, sum; int main() { int q; cin >> q; while (q--) { sum = 0; cin >> n; int a[n + 1]; for (i = 0; i < n; i++) { cin >> a[i]; } bool is = 0; for (i = 0; i < n; i++) { if (a[i] < 2048) sum += a[i]; else if (a[i...
2
#include <bits/stdc++.h> using namespace std; const int mxN = 1e3, M = 998244353; int n, a[mxN], m, f[3][3], l; vector<array<int, 2>> v[mxN]; map<array<int, 3>, int> mp; vector<vector<long long>> ta[3], tb, tc[30]; long long dp[mxN + 1][4]; vector<vector<long long>> matMul(vector<vector<long long>> a, ...
19
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; if (n % 2 == 0) cout << -1; else { int j = 0; for (int i = n - 1; i >= 0; i--) { cout << i << " "; a[j] = i; j++; } cout << "\n"; j = 0; for (int i = 0; i < n; i++) { cout ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> input(n); for (int i = 0; i < n; ++i) cin >> input[i]; map<int, int> ends; vector<vector<int>> output(n); for (int i = 0; i < n; ++i) { if (!ends.empty()) { ends.emplace(input[i], i); auto cool_it = end...
8
#include <bits/stdc++.h> using namespace std; map<long long int, vector<long long int>> arr; void solve() { long long int n; cin >> n; vector<long long int> a(n); for (long long int &i : a) { cin >> i; } for (long long int i = 0; i < n; i++) { long long int x; cin >> x; arr[a[i]].push_back(x...
9
#include <bits/stdc++.h> using namespace std; long long int inf = 1e18; int main() { std::cout.precision(15); ios_base::sync_with_stdio(false); cout << fixed; long long int i, j, t = 1; while (t--) { long long int n, k; cin >> n >> k; double a[n]; for (i = 0; i < n; i++) cin >> a[i]; doubl...
5
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int N = 1010; struct Matrix { int G[65][65]; Matrix() { memset(G, 0, sizeof(G)); } int* operator[](int x) { return G[x]; } Matrix operator*(Matrix b) { Matrix res; for (int i = 1; i <= 64; i++) for (int j = 1; j <= 64; ...
19
#include <bits/stdc++.h> using namespace std; inline long long read() { long long 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;...
13
#include <bits/stdc++.h> using namespace std; int n; map<pair<int, int>, int> mp; vector<int> adj[100001]; bool vis[100001]; int dis[100001]; void bfs(int i) { queue<int> q; q.push(i); dis[i] = 0; vis[i] = true; while (!q.empty()) { int v = q.front(); q.pop(); for (auto it : adj[v]) { if (!v...
10
#include <bits/stdc++.h> using namespace std; int main() { string ss; long long nb, ns, nc, pb, ps, pc, r, ri = 1e14, ans, l = 0, md, number = md; cin >> ss >> nb >> ns >> nc >> pb >> ps >> pc >> r; map<char, int> m; for (auto f : ss) m[f]++; long long b = m['B'], s = m['S'], c = m['C'], tb, ts, tc, tr; w...
8
#include <bits/stdc++.h> using namespace std; const int N = 300010; int n, d[N], k = 0; int flag[N]; int fa[N]; vector<int> e[N]; void dfs(int u) { if (e[u].size() == 0) { ++k, d[u] = 1; return; } if (flag[u]) d[u] = n + n; for (auto v : e[u]) { dfs(v); if (flag[u]) d[u] = min(d[v], d[u]);...
11
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<pair<long long, long long> > v(n); for (auto& e : v) scanf("%lld %lld", &e.first, &e.second); for (int i = n - 1; i >= 0; --i) v[i].first -= v[0].first, v[i].second -= v[0].second; long long base = 1; for (;; bas...
15
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int sl, tl, nxt[N], ss[N], tt[N], ans, Stack[N]; bool p[N][27], has[27]; char s[N], t[N]; int main() { scanf("%d %d %s %s", &sl, &tl, s + 1, t + 1); if (tl == 1) { printf("%d\n", sl); for (int i = 1; i <= sl; i++) printf("%d ", i); exi...
16
#include <bits/stdc++.h> #pragma GCC optimize 2 using namespace std; const int maxn = 3E3 + 5; int tot, n, m; long long int mod; struct edge { int to, next; }; map<unsigned long long, int> num; map<int, vector<pair<int, int> > > what; short to[8005][8005], sizeTree[8005]; vector<int> have[maxn]; int ans, f[maxn][8005...
20
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1000000007LL; void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; } long long int power(long long int a, long long int b) { long long int x = 1; long long int y = a; while (b > 0) { if (b & 1) { x = x * y; x %...
11
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.writ...
0
#include <bits/stdc++.h> using namespace std; int main() { double n; cin >> n; double sum = 0; if (sqrt(n) == round(sqrt(n))) { sum = 4 * sqrt(n); } else { sum = 2 * floor(2 * sqrt(n)) + 2; } cout << sum << endl; }
2
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline void mine(T1 &x, const T2 &y) { if (y < x) x = y; } template <typename T1, typename T2> inline void maxe(T1 &x, const T2 &y) { if (x < y) x = y; } ostream &operator<<(ostream &out, const vector<long long> &b) { for (auto k : ...
16
#include <bits/stdc++.h> using namespace std; int n, m, Q, deg[400], d[400], q[400]; long long T; long long dp[3000000]; int a[400], b[400], w[400][400]; vector<int> vec[400]; int main() { for (int i = (0); i < (400); i++) for (int j = (0); j < (400); j++) w[i][j] = (1 << 28); for (int i = (0); i < (400); i++) ...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, l1, l2, i, u, v; cin >> n; string prev, curr; cin >> prev; n--; vector<bool> vis(26, false); vector<int> adj[26], indeg(26, 0); vector<char> ans; bool fg, fg2 = true; while (n--) { cin >> curr; fg = false; l1 = prev.size()...
8
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int N = 2000010; int b, fatorial[10]; vector<int> seq; int total, divisao; void base_7(int x, bool flag) { vector<int> aux; while (x) { aux.push_back(x % 7); x /= 7; } reverse(aux.begin(), aux.end()); for (int i = 0; i <...
9
#include <bits/stdc++.h> using namespace std; int memo[500][26][26]; int son[500][26][26]; int cambios[500][26][26]; string A[500]; int m, n; void solve(int x, int y, int z) { for (int row = 0; row < x; row++) for (int a = 0; a < y; a++) for (int b = 0; b < z; b++) { int &res = memo[row][a][b]; ...
12
#include <bits/stdc++.h> using namespace std; int main() { double a, b, c, d, p, q; cin >> a >> b >> c >> d; p = max(3 * a / 10, a - a / 250 * c); q = max(3 * b / 10, b - b / 250 * d); if (p == q) puts("Tie"); else if (p < q) puts("Vasya"); else puts("Misha"); }
1
#include <bits/stdc++.h> using namespace std; const int MX = 100005, lg = 17; int n, m, Q, L[MX], sp[lg + 1][MX]; vector<int> G[MX], V[lg + 1][MX]; void bfs() { queue<int> q; q.push(1), L[1] = 1, sp[0][1] = 1; while (!q.empty()) { int u = q.front(); q.pop(); for (auto v : G[u]) if (!sp[0][v]) { ...
14
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string...
20
#include <bits/stdc++.h> using namespace std; void solve() { int r, c, i, j; cin >> r >> c; for (i = 0; i < r - 1; i++) { for (j = 0; j < c; j++) { char ch; cin >> ch; } } char a[c]; int cnt = 0; for (i = 0; i < c; i++) cin >> a[i]; for (i = 0; i < c; i++) { if (a[i] == 'B') { ...
4
#include <bits/stdc++.h> using namespace std; long long int tree[5 * 300006]; long long int lazy[5 * 300006]; long long int n; long long int arr[300006]; bool vis[300006]; map<long long int, long long int> m; vector<long long int> v, vv; long long int p = 1000000007; long long int power(long long int x, long long int y...
5
#include <bits/stdc++.h> using namespace std; const int N = 205; const int INF = 0x3f3f3f3f; int n, m, s, ind[N]; int to[N][N]; int read() { register 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 = ...
14
#include <bits/stdc++.h> using namespace std; int n, a[4000], b[4000], v; pair<int, int> p[5000000]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d%d", &a[i], &b[i]); a[i] += 1000; b[i] += 1000; } for (int i = 1; i < n; ++i) { for (int j = i + 1; j <= n; ++j) { if (...
5
#include <bits/stdc++.h> using namespace std; template <class T> long long size(const T& x) { return x.size(); } #pragma GCC optimize("Ofast") template <class T> T smod(T a, T b) { return (a % b + b) % b; } long long pw(long long a, long long b) { long long res = 1; while (b > 0) { if (b % 2) res = (res * a...
12