solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; long long add(long long a, long long b, long long c) { long long res = a + b; return (res >= c ? res - c : res); } long long mod_neg(long long a, long long b, long long c) { long long res; if (abs(a - b) < c) res = a - b; else res = (a - b) % c; return (...
4
#include <bits/stdc++.h> using namespace std; char s[15]; int main() { int t; scanf("%d", &t); while (t--) { scanf("%s", s + 1); int f = 0; for (int i = 5; i <= 9; i++) { int cnt10 = 0, cnt20 = 0, cnt11 = 0, cnt21 = 0; for (int j = 1; j <= i; j += 2) { if (s[j] == '1') { ...
2
#include <bits/stdc++.h> int main() { long long n, i, cnt = 0, m = 0; scanf("%lld", &n); int s[n]; for (i = 0; i < n; i++) scanf("%lld", &s[i]); for (i = 0; i < n - 1; i++) { if (s[i] * 2 >= s[i + 1]) cnt++; else { m = (m > cnt) ? m : cnt; cnt = 0; } } m = (m > cnt) ? m : cnt...
2
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 0x3f3f3f3f; const int NINF = 0xc0c0c0c0; const int maxn = 1e5 + 5; const int maxm = (maxn << 2) + 2e6; struct Node { int x, r, q; bool operator<(const Node &A) const { return r > A.r; } }; Node a[maxn]; map<int, int> Hashq, ...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; long long n; int k; int a[100]; int b[100][MAXN]; long long get_ans(int i, long long N) { if (N == 0) return 0; if (i >= k) return N; if (N < MAXN && b[i][N] != -1) return b[i][N]; long long res = get_ans(i + 1, N) - get_ans(i + 1, N / a[i])...
9
#include <bits/stdc++.h> void dfs(long node, const std::vector<std::vector<long> > &g, std::vector<bool> &visited, long dist, long &maxDist, long &furthest) { if (visited[node]) { return; } visited[node] = true; if (dist > maxDist) { furthest = node; maxDist = dist; } for (long p = 0; p...
3
#include <bits/stdc++.h> using namespace std; int x, y, f[10][10]; double dp[10][10]; int main() { for (int i = (0); i < (10); i++) for (int j = (0); j < (10); j++) cin >> f[i][j]; for (int i = (0); i < (10); i++) { for (int j = i & 1 ? 9 : 0; j < 10 && j >= 0; j += i & 1 ? -1 : 1) { if (i == 0 && j <...
7
#include <bits/stdc++.h> using namespace std; int check(string &a, string &b) { if (a.size() > b.size()) return 0; else { int l = a.size() - 1; int r = b.size() - 1; int ans = 1; while (l >= 0) { if (a[l] == b[r]) { l--; r--; } else { ans = 0; break; ...
4
#include <bits/stdc++.h> using namespace std; const int N = 4e5; const int mod = 1000000007; const int inf = 1e9; const double pi = acos(-1.0); const double eps = 1e-8; struct unionset { int fat[1003], len; void init(int x) { len = x; for (int i = 0; i < x; i++) fat[i] = i; return; } int getf(int x)...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = 1000000000000000000; long long mpow(long long a, long long b) { a %= mod; if (!b) return 1; long long temp = mpow(a, b / 2); temp = (temp * temp) % mod; if (b % 2) return (a * temp) % mod; return temp; } lo...
3
#include <bits/stdc++.h> using namespace std; vector<int> start; map<int, int> mp; int n, v[400002], k, lim, nr, ans; int main() { cin >> n >> k; k = 8 * k; int aux = k / n; if (aux > 30) lim = n; else lim = min((1 << aux), n); for (int i = 1; i <= n; i++) { cin >> v[i]; if (mp.find(v[i]) ==...
4
#include <bits/stdc++.h> using namespace std; struct node { int cost, s; }; node a[11000], b[11000]; int pos1[100010], pos2[100010], vis1[100010], vis2[100010]; bool cmp(node x, node y) { return x.cost > y.cost; } bool cmp1(node x, node y) { return x.cost < y.cost; } int main() { int n, s; while (~scanf("%d%d", &...
2
#include <bits/stdc++.h> using namespace std; long long int Mod = 1e9 + 7; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; while (t--) { int n, mx = -1; cin >> n; vector<long long int> h(n); for (int i = 0; i < n; i++) { cin >> h[i]; } vec...
5
#include <bits/stdc++.h> using namespace std; class str { public: char s[100001]; int len; str() { len = 0; } str(const string& ss, int breakp) { len = 0; int carry = 0, curr; for (int i = ss.size() - 1, j = breakp - 1; (i >= breakp) || (j >= 0) || (carry > 0); i--, j--, len++) { cur...
3
#include <bits/stdc++.h> using namespace std; template <typename T> void chkmax(T &x, T y) { x = x > y ? x : y; } template <typename T> void chkmin(T &x, T y) { x = x < y ? x : y; } const int N = 3010; const long double eps = 1e-10; long double p[N], u[N]; struct Node { long double v; int a, b; bool operator>...
11
#include <bits/stdc++.h> using namespace std; int lis(int A[], int size) { int *lis, i, j, Max = 0; lis = (int *)malloc(sizeof(int) * size); for (i = 0; i < size; i++) { lis[i] = 1; } for (i = 0; i < size; i++) { for (j = 0; j < i; j++) { if (A[i] >= A[j] && lis[i] < (lis[j] + 1)) lis[i] = lis[j...
5
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = INT_MAX; const long long LINF = LLONG_MAX; const int N = 1e6 + 20; int a[N], n, res; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; for (int g = 0...
6
#include <bits/stdc++.h> using namespace std; void input() { int i, n, x, xmax = 0; long long tt = 0; scanf("%d", &n); for ((i) = 0; (i) < (n); (i)++) scanf("%d", &x), tt += x, xmax = ((xmax) > (x) ? (xmax) : (x)); long long dau = xmax, cuoi = tt, giua; while (dau <= cuoi) { giua = (dau + cuoi) >> 1...
4
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { long long x = 0; char ch = getchar(); bool positive...
11
#include <bits/stdc++.h> using namespace std; class Solution { public: void solve(std::istream& in, std::ostream& out) { int a, ta, b, tb; in >> a >> ta >> b >> tb; string s; in >> s; int t0 = ((s[0] - '0') * 10 + (s[1] - '0')) * 60 + (s[3] - '0') * 10 + (s[4] - '0'); int res = 0...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 0; cin >> n; int p[n], q[n]; for (int i = 0; i < n; i++) { cin >> p[i] >> q[i]; } for (int i = 0; i < n; i++) { if (q[i] - p[i] >= 2) count++; } cout << count; }
0
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); int x[110000], y[110000], n; set<pair<int, int> > sx, sy; int work(set<pair<int, int> > &sx, set<pair<int, int> > &sy) { if (sx.size() == 1) return 1; set<pair<int, int> >::iterator it1, it2, it3, it4; it1 = sx.begin(); it2 = sx.end(); ...
10
#include <bits/stdc++.h> using namespace std; int n, m, qu, f[100005], v[100005 + 100005], o[100005 + 100005], p, s[100005], r, fr[100005], to[100005], si[100005], curm, grp[100005], gr, rt[100005]; bool u[100005], vis[100005]; vector<int> b[100005], c[100005], q[100005], ans[100005]; void bd(int a, int b) { v[++...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n; long long x[maxn], y[maxn]; int main() { scanf("%d", &n); if (n & 1) return puts("NO"), 0; for (int i = 1; i <= n; i++) scanf("%lld %lld", x + i, y + i); x[n + 1] = x[1]; y[n + 1] = y[1]; int mid = n / 2; for (int i = 1; i <= ...
5
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int dp[5005][5005]; void add(int floor, int l, int r, int d) { dp[floor][l] = (dp[floor][l] + d) % mod; dp[floor][r] = (dp[floor][r] - d + mod) % mod; } int main() { int n, a, b, k; while (~scanf("%d", &n)) { scanf("%d%d%d", &a, &b, &k);...
5
#include <bits/stdc++.h> using namespace std; long long GCD(long long a, long long b) { while (b) b ^= a ^= b ^= a %= b; return a; } long long LCM(long long a, long long b) { return a * (b / GCD(a, b)); } const double EPS = 10e-7; const double INF = (1LL << 62); struct Point { double x; double y; }; int K[100];...
9
#include <bits/stdc++.h> using namespace std; int a[300][300]; char s[4 * 300][4 * 300]; char t[2 * 7][4][4] = { {"...", "...", "..."}, {"...", ".O.", "..."}, {"..O", "...", "O.."}, {"..O", ".O.", "O.."}, {"O.O", "...", "O.O"}, {"O.O", ".O.", "O.O"}, {"O.O", "O.O", "O.O"}, {"...", "...", "..."}, {"...", ".O...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 2 * 1000 * 100 + 17, inf = 1e9; int n, d, a[MAXN], m, ans; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> d; for (int i = 1; i <= n; i++) cin >> a[i]; cin >> m; sort(a + 1, a + n + 1); int i = 1; while (m >...
1
#include <bits/stdc++.h> using namespace std; int calc(int n, vector<int> input) { map<int, int> process; for (int i = 0; i < n; i++) process[input[i]]++; int sum = 1; for (int i = 0; i < n; i++) sum = sum + max(0, process[i] - 1); return sum; } int main() { int n; cin >> n; vector<int> input(n); for ...
2
#include <bits/stdc++.h> using namespace std; int n, m, w[100005], a; int licz(int q) { if (q == 2) return 2; int wyn = q * (q - 1) / 2; if (q % 2 == 0) return wyn + q / 2; return wyn + 1; } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < m; ++i) scanf("%d%d", &a, &w[i]); sort(w, w + m); int ile...
6
#include <bits/stdc++.h> using namespace std; long long a; char s[20]; bool check(int x) { while (x > 0) { int y = x % 10; x /= 10; if (y == 8) return true; } return false; } int main() { cin >> s; if (s[0] == '-') { int cnt = 1; for (int i = strlen(s) - 1; i > 0; i--) { int c = s[i]...
1
#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<string> v; multiset<string> ms; set<string> st; for (int i = 0; i < n; i++) { string s; cin >...
3
#include <bits/stdc++.h> using namespace std; int IN() { int x = 0, f = 0, ch; for (; (ch = getchar()) < '0' || ch > '9';) f = (ch == '-'); for (; ch >= '0' && ch <= '9'; (ch = getchar())) x = x * 10 + ch - '0'; return f ? -x : x; } int N, D, C, A[100005], st[100005]; map<vector<int>, int> G; set<int> F; map<pa...
10
#include <bits/stdc++.h> inline int read() { int data = 0, w = 1; char ch = getchar(); while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar(); if (ch == '-') w = -1, ch = getchar(); while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar(); return data * w; } const int maxn(1e5 + 10); ...
11
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; char str[100005]; struct node { int x, y; }; int a[100005], vis[100005], r[100005]; vector<int> aa, bb; vector<int> t1, t2; queue<int> tc; int n, mm; long long m; void doit() { aa.clear(); bb.clear(); memset(vis, 0, sizeof(vis)); ;...
5
// Problem: G. Forbidden Value // Contest: Codeforces - Educational Codeforces Round 99 (Rated for Div. 2) // URL: https://codeforces.com/contest/1455/problem/G // Memory Limit: 256 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> #define int long long ...
10
#include <bits/stdc++.h> using namespace std; map<string, int> sti; char fr[33], to[33]; int pr[605][605], pt; int main() { int n, a, b, k, f; scanf("%d%d%d%d%d", &n, &a, &b, &k, &f); int prv = -1, ans = 0; for (int i = 0; i < n; i++) { scanf("%s%s", fr, to); int x, y; if (sti.count(fr)) x = s...
5
#include <bits/stdc++.h> using namespace std; typedef class Point { public: int x, y; Point() {} Point(int x, int y) : x(x), y(y) {} } Point; typedef class Line { public: Point v; int a, b; double ang; Line(Point v, int a, int b) : v(v), a(a), b(b) { ang = atan2(v.y, v.x); } bool operator<(Line b) con...
10
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:66777216") using namespace std; const int INF = 100000; const int N = 22; char st[N][N]; int n, dp[2 * N][1 << 20]; bool mark[2 * N][1 << 20]; int cnt, x[N], y[N]; int minimize(int d, int m); int maximize(int d, int m) { if (d == 2 * n - 2) return 0; if (mark...
8
#include <bits/stdc++.h> using namespace std; int n, i, x, y, sol; int main() { ios_base::sync_with_stdio(0); cin.tie(); cin >> n; for (i = 1; i <= n; i++) { cin >> x >> y; sol = max(sol, x + y); } cout << sol; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, y = 3; cin >> n; n = n / 2; y = y * n; cout << y; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { string str; int t, i, min; cin >> t; while (t--) { cin >> str; int count_0 = 0, count_1 = 0; for (i = 0; i < str.length(); i++) { if (str[i] == '0') { count_0++; } else { count_1++; } } if (count_0 >...
0
#include <bits/stdc++.h> const double EPS = 1e-8; using namespace std; int main() { int n, w, m; while (cin >> n >> w >> m) { bool ok = true; double target = (double)n * w / m; vector<double> p(m, 0.0); vector<vector<pair<int, double> > > ans(m); for (int i = 0; i < (int)n; i++) { double l...
5
#include <bits/stdc++.h> using namespace std; const double pi = acos(0.0) * 2.0; const double eps = 1e-12; const int step[8][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; template <class T> inline T abs1(T a) { return a < 0 ? -a : a; } template <class T> inline ...
6
#include <bits/stdc++.h> using namespace std; const long long N = 53, INF = 1e18, MOD = 1e9 + 7; long long dis[N][N][2], way[N][N][2]; long long POW(long long a, long long b) { if (b == 0) return 1; long long ans = POW(a, b / 2); ans *= ans; ans %= MOD; if (b % 2) ans *= a; ans %= MOD; return ans; } long ...
6
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n, k, q, p; scanf("%d", &n); int A[120][120]; int B[120], C[120]; memset(B, 0, sizeof(B)); memset(C, 0, sizeof(C)); for (i = 0; i < n; i++) for (j = 0; j < n; j++) { char ch; do { scanf("%c", &ch); } while (...
3
#include <bits/stdc++.h> using namespace std; long long L[10005]; long long R[10005]; char ASK[10005][20]; long long ask[10005]; int len[10005]; void deal(long long &a, char str[]) { int i, tlen = strlen(str); a = 0; long long pls = 1; for (i = tlen - 1; i >= 4; i--) { a += ((str[i] - '0') * pls); pls *...
6
#include <bits/stdc++.h> using namespace std; int new_pow(int a, int b, int c) { long long tmp = a; while (b > 0) { if (b % 2) c = (c * tmp) % 1000000007; b >>= 1; tmp = (tmp * tmp) % 1000000007; } return c; } int main() { int n, k; cin >> n >> k; int ans; ans = new_pow(n - k, n - k, 1); a...
3
#include <bits/stdc++.h> using namespace std; const int NMAX = 155, MOD = 1e9 + 7; int64_t dp[2][4][NMAX][NMAX]; int64_t sdp[2][4][NMAX][NMAX]; int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; int64_t ans = 0; for (int i = 1, u = 1; i <= n; ++i, u ^= 1) { memset(dp[u], 0, sizeof dp[u]); ...
8
#include <bits/stdc++.h> void solve(int x) { for (int i = (x); i >= (1); i--) printf("%d %d\n", i, x + 1); for (int i = (x); i >= (1); i--) printf("%d %d\n", i, x + 2); printf("%d %d\n", x + 1, x + 3), printf("%d %d\n", x + 2, x + 4); for (int i = (1); i <= (x); i++) printf("%d %d\n", i, x + 4); for (int i = ...
11
#include <bits/stdc++.h> using namespace std; int r() { int xy; scanf("%d", &xy); return xy; } bool odw[1000007]; const int mod = 1000000007; long long ile[1000007]; long long cc[1000007]; long long dp[1000007]; int main() { long long wyn = 1; int p, k; scanf("%d%d", &p, &k); for (int i = 0; i < p; i++) {...
5
#include <bits/stdc++.h> using namespace std; const int V = 100010; const int E = 400040; int head[V], nxt[E], cur[E], ne; inline void addEdge(int u, int v) { cur[ne] = v, nxt[ne] = head[u]; head[u] = ne++; } bool vist[V]; int dist[V]; bool solved(int n, int m, int s, int t) { priority_queue<pair<int, int> > q; ...
6
#include <bits/stdc++.h> using namespace std; const int Nn = 1e5 + 5; struct node { int v, s, id, h; node() {} node(int a, int b, int c) { v = a; s = b; id = c; h = 0; } bool operator<(const node &a) const { if (h == a.h) return h > a.h; else if (v == a.v) return s > a.s; ...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int T; long long a, b, c, s; cin >> T; while (T--) { cin >> a >> b >> c >> s; if (s - a * c < 0) { s %= c; if (b >= s) { cout << "YES\n"; } else cout << "NO\n"; ...
1
#include <bits/stdc++.h> using namespace std; long long gcd(long long x, long long y) { if (y == 0) return x; else return gcd(y, x % y); } long long lcm(long long x, long long y) { return x / gcd(x, y) * y; } long long binpow(long long a, long long p) { if (!p) return 1; long long g = binpow(a, p >> 1);...
6
#include <bits/stdc++.h> using namespace std; const int N = 444444; pair<int, int> a[N]; int b[N], ans[N]; int n, h, i, k; int main() { scanf("%d %d", &n, &h); for (i = 0; i < n; i++) { int foo; scanf("%d", &foo); a[i] = make_pair(foo, i + 1); } sort(a, a + n); for (i = 0; i < n; i++) b[i] = a[i]....
5
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; constexpr ll inf = 1000000000; constexpr ll mod = 1000000007; constexpr long double eps = 1e-15; template <typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1, T2> p) { os << to_string(p.first) << " " << to_stri...
7
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; n = 2 * n; int ar[n + 10]; int i, j, k, cnt = 0, mx = 0; for (i = 1; i <= n; i++) { cin >> ar[i]; if (ar[i] % 2 == 0) cnt++; else mx++; } int...
1
#include <bits/stdc++.h> using namespace std; int main() { int l; cin >> l; string s; cin >> s; if (l < 26) { cout << "NO\n"; return 0; } int f[26] = {}; for (int i = 0; i < l; i++) f[tolower(s[i]) - 'a']++; for (int i = 0; i < 26; i++) if (f[i] == 0) { cout << "NO\n"; return 0...
0
#include <bits/stdc++.h> using namespace std; long long N, M; int p[1000005]; bool f[1000005]; int cal(int m) { int n = 1; while (m) { n <<= 1; m >>= 1; } return n - 1; } int main() { int i, j; cin >> N; M = (1 + N) * N; cout << M << endl; (memset(p, 0, sizeof(p))); (memset(f, 0, sizeof(f)))...
4
#include <bits/stdc++.h> using namespace std; int i, j, m, n, k, t; int main() { cin >> n >> m >> k; for (i = 0; i < n; ++i) for (j = 0; j < m; ++j) cin >> t; cout << m * (m - 1) / 2 << endl; if (k == 0) { for (i = m - 1; i >= 0; --i) for (j = 0; j < i; ++j) cout << j + 1 << ' ' << j + 2 << endl; ...
3
#include <bits/stdc++.h> using namespace std; inline long long read() { long long sum = 0, ff = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') ff = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') sum = sum * 10 + ch - '0', ch = getchar(); return sum * ff; } void write(lon...
4
#include <bits/stdc++.h> using namespace std; const long long int mod = 998244353; const long long int inf = 0x3f3f3f3f3f3f3f3fLL; const double eps = 1e-9; const double PI = acos(-1); long long int i, j, k; void solve(void); inline bool equal(double a, double b) { return fabs(a - b) < eps; } inline long long int power(...
5
#include <bits/stdc++.h> using namespace std; long long pwr(long long base, long long p, long long mod) { long long ans = 1; while (p) { if (p & 1) ans = (ans * base) % mod; base = (base * base) % mod; p /= 2; } return ans; } long long gcd(long long a, long long b) { if (b == 0) return a; return...
9
#include <bits/stdc++.h> using namespace std; unsigned long long gcd(unsigned long long a, unsigned long long b) { return (b == 0 ? a : gcd(b, a % b)); } long long n, m, r, z, x, l, k, a, h, res, tmp; string s; vector<vector<long long> > g; void solve() { res = 0; tmp = 0; cin >> n >> m; long long v1[n + 2]; ...
2
#include <bits/stdc++.h> using namespace std; pair<int, long long> a[100010]; long long pow4[40]; void preprocess() { for (int i = 1; i < 32; i++) pow4[i] = pow(4, (double)i); } bool comp(pair<int, long long> a, pair<int, long long> b) { return a.first < b.first; } int main() { preprocess(); int n; cin >> n; ...
4
#include <bits/stdc++.h> using namespace std; template <class _T> inline _T sqr(const _T& first) { return first * first; } template <class _T> inline string tostr(const _T& a) { ostringstream os(""); os << a; return os.str(); } const long double PI = 3.1415926535897932384626433832795L; const double EPS = 1 - 9;...
5
#include <bits/stdc++.h> using namespace std; template <class T> bool remin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <class T> bool remax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } int nxt() { int first; scanf("%d", &firs...
8
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-8; const int MX = 1e5 + 5; const int mod = 1e9 + 7; char str[MX]; int main() { scanf("%s", str); int len = strlen(str); long long ans = 1, num = 1; for (int i = 0; i < len; i++) { if (str[i] == 'a') num++...
3
// Create your own template by modifying this file! #include <array> #include <string> #include <vector> #include <climits> #include <cstring> #include <map> #include <queue> #include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <set> #include <unordered_set> #include <unordered_map> #inc...
4
#include <bits/stdc++.h> using namespace std; const long long oo = 2e9; const double PI = acos(-1); const long long M = 1e9 + 7; long long oor(long long a, long long b) { return (a | b); } struct mseg { int best, a1[10]; int& operator[](int x) { return a1[x]; } } seg[800010]; mseg change(mseg& seg, int vl) { int ...
7
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,tune=native") template <typename T> void print(T&& x) { cout << x << "\n"; } template <typename T, typename... S> void print(T&& x, S&&... y) { cout << x << ' '; print...
10
#include <bits/stdc++.h> using namespace std; vector<pair<long long int, long long int>> f; vector<pair<long long int, long long int>> f2; long long int number, threshold, rich, value; long long int binarysearch(long long int a) { long long int low = a; long long int high = f2.size() - 1; long long int mid; lon...
3
#include <bits/stdc++.h> using namespace std; signed main() { long long n; cin >> n; long long ans = pow((long long)2, n + 1) - 2; cout << ans << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int ABS(int a) { if (a < 0) a = -a; return a; } bool cmp(pair<int, int> a, pair<int, int> b) { return (ABS(a.first) + ABS(a.second)) < (ABS(b.first) + ABS(b.second)); } int main() { int n, m, k, i, j; int a[310]; int x; int u, v; int root; scanf("%d%d%d", ...
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const int INF = (int)(1e9 + 1e6); const long long LINF = (long long)(4e18); const double EPS = 1e-14; mt19937 ggen; void solve(); int main() { iostream::sync_with_stdio(false); cin.tie(0); ggen = mt19937(1337); solve(); } ...
1
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> G[100001]; int dist[100001]; int main(void) { scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); a--; b--; G[a].push_back(b); G[b].push_back(a); } memset(dist, -1, sizeof(dist)); dist...
3
#include <bits/stdc++.h> using namespace std; const int N = 505; inline int read() { int s = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar(); return s; } int n, m, a[N], b[N], f[N][N], pre[N][N], out[N], cnt, ii, jj; int main() { ...
10
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 5; const int M = 36; const int maxn = 2e7 + 5; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3e; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') f = -1; ch = getchar(); } while...
8
#include <bits/stdc++.h> using namespace std; struct coordinate { int x, y; }; int a, x, y; coordinate c[10]; int main() { cin >> a >> x >> y; if (x >= a || x <= -a || y % a == 0) { cout << -1 << endl; return 0; } int q = y / a + 1; if ((q == 1 || q % 2 == 0) && (x * 2 >= a || x * 2 <= -a)) { co...
3
#include <bits/stdc++.h> using namespace std; const int N = 50 + 5; int a[N][N], b[N][N], x[N], y[N], val[N]; vector<pair<int, int> > in, out; int n, m, last = 1; void move(int x1, int y1, int x2, int y2) { out.push_back({x1, y1}); in.push_back({x2, y2}); a[x2][y2] = a[x1][y1]; a[x1][y1] = 0; } void build() { ...
9
#include <bits/stdc++.h> using namespace std; int l, b, f, n, c, d, g, p; bool ff; struct au { int p, l, n; au(int pp = 0, int ll = 0, int nn = 0) { p = pp; l = ll; n = nn; } }; vector<au> a; vector<bool> t; int main() { cin >> l >> b >> f >> n; for (int i = 0; i < n; i++) { cin >> c >> d; ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int main() { int n, k; scanf("%d%d", &n, &k); if (n == 1) { if (k == 0) printf("1\n"); else printf("-1\n"); return 0; } int ile = n / 2; if (ile > k) { printf("-1\n"); return 0; } int wyn = k - ile + 1...
3
#include <bits/stdc++.h> using namespace std; int a[999]; int main() { int i, n, m, res = 0, sum = 0; scanf("%d", &n); for (i = 0; i < 12; i++) { scanf("%d", &a[i]); } sort(a, a + 12, greater<int>()); for (i = 0; i < 12; i++) { sum += a[i]; if (n != 0 && sum >= n) { res = i + 1; brea...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int k; while (cin >> k) { if (k > 36) cout << "-1" << endl; else if (k == 1) cout << "6" << endl; else if (k == 2) cout << "8" << endl; else if (k == 3) cout << "86" << endl; else if...
2
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2000 + 1; const int mod = 1e9 + 7; void addto(int& a, int b) { a += b; if (a >= mod) a -= mod; } int mul(int a, int b) { return ((long long)a * b) % mod; } int mpow(int a, int n) { int r = 1; while (n > 0) { if (n & 1) r = mul(r, a); a = mu...
6
#include <bits/stdc++.h> using namespace std; const int N = 512; namespace PQ { const int P = -1, Q = -2; enum col { White = 0, Gray, Black }; struct node { int v; node *son, *bro; col c; inline node() {} inline node(int v, node *son, node *bro, col c) : v(v), son(son), bro(bro), c(c) {} } pool[N << 2],...
11
#include <bits/stdc++.h> const long long N = 200005; long long hi, ls, n, X[N], t, A[N], bk[N]; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> t; for (int i = 0; i < n; ++i) { cin >> A[i]; } for (int i = 0; i < n; ++i) { cin >> X[i], --X[i]; } for (in...
7
#include <bits/stdc++.h> using namespace std; int n, m = 0; int lsh[100010]; struct Question { int f, x; } que[100010]; struct Segment_Tree { long long data[5]; int num, l, r; } a[100010 << 2]; inline int read() { int date = 0, w = 1; char c = 0; while (c < '0' || c > '9') { if (c == '-') w = -1; c ...
7
#include <bits/stdc++.h> using namespace std; long long Pow(long long x, long long y, long long m) { if (y == 0) return 1; long long p = Pow(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } set<long long> pr[100004]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ...
4
#include <bits/stdc++.h> using namespace std; int main() { char map[110]; int pos[3][2], ans[2], all[2] = {0, 0}; int i, j, n, m, k = 0; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { scanf("%s", map); for (j = 0; j < m; j++) { if (map[j] == '*') { all[0] += i + 1; pos[k][0] = ...
0
#include <bits/stdc++.h> using namespace std; const long long md = 1e9 + 7; const int xn = 2e5 + 10; const int xm = 5e5; const int SQ = 320; const int sq = 1e3 + 10; const long long inf = 1e18 + 10; long long power(long long a, long long b) { return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2) % md ...
5
#include <bits/stdc++.h> using namespace std; #define ll long long int dp[100001]; void solve(){ int n, q; string s; cin >> n >> q >> s; for(int i = 0; i < n; i++){ dp[i+1] = dp[i] + (int)s[i] - 96; } int l, r; while(q--){ cin >> l >> r; cout << dp[r] - dp[l-1] << '\n'; } } int main(){ ios_base::s...
0
#include <bits/stdc++.h> using namespace std; template <class t> inline void read(t& res) { char ch; while (ch = getchar(), !isdigit(ch)) ; res = ch ^ 48; while (ch = getchar(), isdigit(ch)) res = res * 10 + (ch ^ 48); } template <class t> inline void print(t x) { if (x > 9) print(x / 10); putchar(x % 1...
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 80; const int INF = 0x3f3f3f3f; int dp[MAXN][MAXN][MAXN][2]; int VV[MAXN]; int KK[MAXN]; int XX[MAXN]; int sv, sk, sx; int find(int *data, int l, int r, int d) { int cnt = 0; for (int i = l; i < r && data[i] < d; i++) { cnt++; } return cnt; } in...
8
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1); const double pi2 = pi * 2.0; char answer[100]; double iabs(const double &k) { return k < 0 ? -k : k; } class Point { public: double x, y; Point(const double &a = 0, const double &b = 0) : x(a), y(b) {} Point operat...
6
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, M = 1000000007; cin >> a >> b; cout << ((((b - 1) * b / 2) % M) * ((b * ((a * (a + 1) / 2) % M) + a) % M)) % M; }
4
#include <bits/stdc++.h> using namespace std; int main() { int k, n, i, j; char s[100001]; vector<int> v[26]; string ans = ""; scanf("%s", s); scanf("%d", &k); n = strlen(s); if ((long long)n * (n + 1) / 2 < k) { puts("No such line."); return 0; } for (i = 0; i < n; i++) { v[s[i] - 'a']....
6
#include <bits/stdc++.h> using namespace std; const int p = 100003; int n, m; int main() { printf("%d %d\n", p, p); scanf("%d%d", &n, &m); printf("1 2 %d\n", p - n + 2); for (int i = 2; i < n; ++i) printf("%d %d 1\n", i, i + 1); m -= n - 1; int i = 0, j = n; while (m--) { ++j; if (j > n) { +...
4
#include <bits/stdc++.h> int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } using namespace ::std; const int maxn = 3e6 + 500; const int inf = 1e9 + 800; const int mod = 1e9 + 7; const long double pi = 3.14159265359; complex<long double> a[maxn]; complex<long double> b[maxn]; void fft(complex<long double> a[]...
10