solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { double y; int x = 0, n, m, n1, j = 1; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &m); if (j == 1 && m < 0) { n1 = m; j = 0; } if (n1 <= m && m < 0) { n1 = m; } else { y = (int)sqrt((m)); ...
1
#include <bits/stdc++.h> using namespace std; double Px, Py, Vx, Vy, A, B, C, D, M; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> Px >> Py >> Vx >> Vy >> A >> B >> C >> D; M = sqrt(Vx * Vx + Vy * Vy); cout << fixed << setprecision(12); cout << Px + B * Vx / M << ' ' << Py + B ...
12
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, x, y; cin >> a >> b >> x >> y; int ans = max(max(x, a - 1 - x) * b, max(y, b - 1 - y) * a); cout << ans << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18 + 7; const long long maxn = 1e6 + 700; const int M = 1e6 + 8; const long long mod = 1000000007; const double eps = 1e-9; const double PI = acos(-1); template <typename T> inline void read(T &a) { char c = getchar(); T x = 0, f = 1; while (!i...
15
#include <bits/stdc++.h> using namespace std; string vow = "aeiou"; const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2}; const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1}; const int dx[] = {-1, 0, 0, 1}; const int dy[] = {0, -1, 1, 0}; const long double pie = 3.14159265358979; const long long mod = 1e9 + 7; void solve(...
7
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; void hebin(int x, int y); int getf(int v); int f[1005]; int main(void) { long long n, k; scanf("%I64d%I64d", &n, &k); long long l = 0, r = k; long long m; while (l < r) { m = l + (r - l) / 2; long long n1 = m * k - (m - 1) * (m ...
9
#include <bits/stdc++.h> using namespace std; int main() { int vladikCandies, valeraCandies; cin >> vladikCandies >> valeraCandies; int nextRound = 1; while (1) { if (vladikCandies < nextRound) { cout << "Vladik" << endl; break; } vladikCandies -= nextRound; nextRound++; if (vale...
0
#include <bits/stdc++.h> using namespace std; int n; string s; int main() { cin >> n >> s >> s, cout << (s == "week" ? (n == 6 || n == 5 ? 53 : 52) : (n == 31 ? 7 : (n == 30 ? 11 : 12))); return 0; }
1
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read() { T x = 0, f = 1; int c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = x * 10 + (c & 15), c = getchar(); return x * f; } long long sum[4005]; long lo...
17
#include<iostream> #include<bits/stdc++.h> #define m_p make_pair #define fi first #define se second #define pb push_back #define pi pair<ll, ll> typedef long long ll; typedef long double ld; #define f(i,n) for(ll i=0;i<n;i++) #define f1(i,n) for(ll i=1;i<=n;i++) #define crap ios_base::sync_with_stdio(0); cin.tie(0)...
0
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double eps = 1e-8; char mat[10][10]; int w[26]; int main() { w['q' - 'a'] = 9; w['r' - 'a'] = 5; w['b' - 'a'] = 3; w['n' - 'a'] = 3; w['p' - 'a'] = 1; char c; int black = 0, white = 0; for (int i = 0; i < 8; i++) { for (...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1002; int a[maxn], b[maxn], n, ans; int work(int k) { int s = 0; for (int i = 1; i <= n; i++) a[i] = b[i]; a[0] = k; for (int i = 0; i != n; i++) if (a[i] == a[i + 1]) { a[i + 1] = 1 - a[i]; s++; } ans = min(ans, s); return 0...
10
#include <bits/stdc++.h> using namespace std; class N { public: long id, value; N(long _id, long _value); }; N::N(long _id, long _value) { id = _id; value = _value; } class H { private: vector<N> elem; void swap(long a, long b); public: bool empty(); H(); void modify(long value); void pop(); N...
13
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; void solve() { int c[26] = {0}; int n; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; for (auto x : s) { c[x - 'a']++; } } int cnt = 0; for (int i = 0; i < 26; i++) { if (c[i] % n == 0) { cn...
0
#include <bits/stdc++.h> using namespace std; char s[100005]; int main() { int a, b, c, d, n1 = 0, n0 = 0; scanf("%d%d%d%d", &a, &b, &c, &d); if (!b && !c && a && d) { printf("Impossible"); return 0; } if (!a && !b && !c && !d) { printf("1"); return 0; } for (int i = 1; i * (i - 1) <= 2 * ...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i = 0, j = 0, l = 0; cin >> n >> k; if (k > n * (n / 2) + (n & 1) * (n + 1) / 2) { cout << "NO"; } else { cout << "YES" << endl; while (i < n && l < k) { if ((i & 1) ^ (j & 1)) cout << "S"; else { cout <...
6
#include <bits/stdc++.h> using namespace std; const int N = int(3e6); int n, a[55]; long long m, d[55]; int main() { cin >> n >> m; d[0] = 1; for (int i = 1; i <= n; i++) { d[i] = 2 * d[i - 1]; } int i = 1, j = n, k = 1; while (k <= n) { if (m > d[n - k - 1]) { m -= d[n - k - 1]; a[j] = ...
10
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; const long double PI = 3.141592653589793238462643383279502884197; long long fac[1] = {1}, inv[1] = {1}; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long mp(long long a, long long b) { long long r...
15
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 10; const long long INF = 2147483647; const long long mod = 1e9 + 7; const double eps = 1e-8; const long long pi = 3.1415926; long long n; long long st[N]; void solve() { cin >> n; memset(st, 0, sizeof st); long long k = sqrt(n), q = 0; for...
0
#include <bits/stdc++.h> using namespace std; int n, d, a[111], p[111][2], dist[111][111]; int main() { for (int i = 0; i < 9; ++i) printf("%d??<>%d\n", i, i + 1); printf("9??>>??0\n"); printf("??0<>10\n"); for (int i = 0; i < 10; ++i) printf("?%d>>%d?\n", i, i); printf("?>>??\n"); printf(">>?\n"); return...
17
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const int maxn = 1e5 + 7; const double pi = acos(-1.0); const int v2 = (mod + 1) / 2; int n, q, a[maxn]; struct { int l, r; double sum, k, lazy; } b[4 * maxn]; void push_up(int now) { b[now].sum = b[now << 1].sum + b[...
15
#include <bits/stdc++.h> using namespace std; int points[100][2], n; bool visited[1001][1001]; void mark(int x, int y) { if (visited[x][y]) return; visited[x][y] = true; for (int i = 0; i < n; i++) if (points[i][0] == x || points[i][1] == y) mark(points[i][0], points[i][1]); } int solve() { int result...
4
#include <bits/stdc++.h> int main() { int n, k; scanf("%d %d", &n, &k); if (n == 1 && k != 2) printf("0\n"); else if (n == 1 && k == 2) printf("1\n"); else { int temp = k - n * 2; if (temp >= n) printf("0\n"); else printf("%d\n", n - temp); } }
1
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:16777216") const int inf = 0x3f3f3f3f; const string debug_line = "yolo"; const double PI = 4 * atan(1); struct Point { long long first, second; Point(long long a = 0, long long b = 0) { first = a, second = b; } bool operator<(Point b) c...
16
#include <bits/stdc++.h> using namespace std; int a[105]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; vector<int> ans; int cnt = 0; for (int i = 1; i <= n; i++) { if (a[i] % 10 == 0) { if (a[i] % 100 / 10 != 0) { if (cnt == 1) continue; cnt++; } ...
8
#include <bits/stdc++.h> using namespace std; int main() { int a = 0, b = 0, n, m; int x = 0; cin >> n >> m; if (n == 1 && m == 1) { cout << 2; return 0; } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (((i * i) + j == n) && (i + (j * j) == m)) { x++; } ...
0
#include <bits/stdc++.h> using namespace std; const long long MOD = (1e9) + 7; const long double EPS = 0.0000001; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; bool taken[n + n + n + 1]; memset(taken, false, sizeof(tak...
12
#include <bits/stdc++.h> using namespace std; void fasto() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int n; string s; int main() { fasto(); cin >> s; bool f = false; pair<int, pair<int, int> > p; n = s.size(); for (int i = 0; i < n; i++) { if (s[i] == '8' or s[i] == '0')...
7
#include <bits/stdc++.h> using namespace std; int n, i, k, b, a = 0; string s, s1, s2; double c; int main() { cin >> s >> n; c = s.size() % n; if (c) { cout << "NO"; return 0; } k = s.size() / n; b = k; for (i = 0; i < n; i++) { s1 = s.substr(a, b); a += k; s2 = s1; reverse(s2.begi...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int a[maxn]; vector<int> g[maxn]; int od[maxn], fa[maxn], sz[maxn]; int n; bool less2(int x, int y) { return a[x] < a[y]; } bool less3(int x, int y) { return a[x] > a[y]; } inline int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); } ...
16
#include <bits/stdc++.h> using namespace std; template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template <typename T> using max_heap = priority_queue<T>; template <class T> ostream &operator<<(ostream &os, min_heap<T> H) { while (!H.empty()) { os << H.top() << " "; H.pop(); } ...
12
#include <bits/stdc++.h> using namespace std; int n; const int N = 105; char s[N][N]; vector<char> fr[26]; bool visited[26]; bool Forward[26]; int level[26]; bool comp(pair<int, char> a, pair<int, char> b) { if (a.first != b.first) return a.first < b.first; else return a.second > b.second; } bool DFS(char c...
8
#include <bits/stdc++.h> using namespace std; const int inf = 1000 * 1000 * 1000; int n, k, m; int main() { cin >> n >> m >> k; bool f = 0; for (int i = 2; i * i <= m; ++i) if (m % i == 0 && m / i >= k) f = 1; if (k == 1 && m > 1) f = 1; if (f && (n & 1)) cout << "Timur" << endl; else cout << "M...
12
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, ans = 1, last = -1; cin >> n; for (int i = 0; i < n; i++) { cin >> a; if (a) { if (last != -1) ans *= (i - last); last = i; } } if (last == -1) cout << 0; else cout << ans; return 0; }
5
#include <bits/stdc++.h> using namespace std; int n, M[100], ch; char S[10], s[100100]; bool check() { int ans = 0, C = 0; for (int i = 1; i <= 26; i++) if (M[i] == 1) { ans++; C = i; } if (ans == 1) { ch = C; return 1; } return 0; } int main() { scanf("%d", &n); bool flag = fa...
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 110000; int n, h[MAXN], a[MAXN]; int lowbit(int x) { return x & -x; } int ask(int pos) { int res = 0; for (int i = pos; i; i -= lowbit(i)) { res = max(res, h[i]); } return res; } void ins(int pos, int val) { for (int i = pos; i <= n; i += lowb...
7
#include <bits/stdc++.h> using namespace std; int main() { int x, n, sum = 0, mx = -1, resultK = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> x; mx = max(mx, x); sum += x; } resultK = mx; while (true) { if (resultK * n - sum > sum) break; resultK++; } cout << resultK; return 0...
0
#include <bits/stdc++.h> using namespace std; const int MAXINT = 1 << 31 - 1; const int MAXN = 55 * 1e4 + 5; int dp[MAXN]; int arr[60]; int n, d; int main() { while (cin >> n >> d) { int big = 0; for (int i = (0); i < (n); i += 1) { scanf("%d", &arr[i]); big += arr[i]; } fill(dp, dp + big ...
14
#include<bits/stdc++.h> using namespace std; #define ll long long int int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; cin>>t; while(t-->0) { ll n; cin>>n; vector<ll>arr; for(int i=0;i<n;i++) { ll temp; cin>>temp; arr....
6
#include <bits/stdc++.h> using namespace std; int32_t main() { long double a, b, c, d; cin >> a >> b >> c >> d; if (d - c == c - b && c - b == b - a) { cout << 2 * d - c; } else if (b / a == c / b && d / c == c / b) { if ((int)d * (int)d % (int)c == 0) cout << d * d / c; else cout << 42;...
10
#include <bits/stdc++.h> using namespace std; using ii = pair<int, int>; int main() { int n; cin >> n; vector<int> A(n); queue<ii> segs; for (int i = 0; i < n; i++) scanf("%d", &A[i]); set<int> s; int start = 1; for (int i = 0; i < n; i++) { if (s.find(A[i]) != s.end()) { segs.push(ii(start, i...
7
#include <bits/stdc++.h> using namespace std; using pr = pair<int, int>; using vp = vector<pr>; using vvp = vector<vp>; using vi = vector<int>; int N; void dfs(vvp& g, vi& vis, int& fl, int fin, int col, int nd) { if (nd == fin) { fl = 1; return; } if (fl) return; vis[nd] = 1; for (auto& pr : g[nd]) {...
6
#include <bits/stdc++.h> using namespace std; const int N = 102; int t, n, m, id[N]; map<string, int> userid; string name[N], chat[N], sender[N], mess[N]; bitset<100> cand[N], all1; int First1(const bitset<100> &bit) { for (int i = 0; i < n; ++i) if (bit[i]) return i; assert(false); } bitset<100> GetUsers(const...
14
#include <bits/stdc++.h> using namespace std; const int MAXN = 501; int n, k, x; int h[MAXN]; int main() { scanf("%d %d\n", &n, &k); for (int i = 1; i <= 2 * n + 1; ++i) scanf("%d", &h[i]); for (int i = 1; i <= n; ++i) { int j = 2 * i; if (k && h[j] - 1 > h[j - 1] && h[j] - 1 > h[j + 1]) { h[j]--; ...
3
#include<bits/stdc++.h> using namespace std; int main() { int t, n, a; cin >> t; int odd = 0, even = 0; while(t--) { cin >> n; for(int i = 0; i < 2*n; i++) { cin >> a; if(a%2) even++; else odd++; } ...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const double eps = 1e-9; struct point { double x, y; point() { x = y = 0; } point(double x, double y) : x(x), y(y) {} void read() { cin >> x >> y; } bool operator==(const point& other) const { return fabs(x - other.x...
18
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 2; int N, student[MAXN * 3]; vector<int> membersWith[MAXN * 3]; bool assigned[MAXN * 3], printed[MAXN * 3]; int K; int main() { scanf("%d", &N); for (int i = 0; i < 3 * N; i++) scanf("%d", &student[i]); for (int i = 0; i < N; i++) { int a, b...
12
#include <bits/stdc++.h> using namespace std; int n, m, Q, col; int vis[100005], f[100005], sz[100005]; vector<int> d[100005], v[100005]; int pos[100005]; long long s[100005]; vector<long long> sum[100005]; map<pair<int, int>, long long> mp; void dfs(int x, int last) { vis[x] = col; f[x] = 0; for (int i = 0; i < ...
17
#include <bits/stdc++.h> using namespace std; const long long int M = 10000000007; long long int binarySearch(vector<long long int> arr, long long int l, long long int r, long long int x) { if (r >= l) { long long int mid = l + (r - l) / 2; if (arr[mid] == x) return mid; if (arr...
7
#include <bits/stdc++.h> int main(void) { int z, o; scanf("%d %d", &z, &o); int i; if (o <= (z + 1) * 2 && z - 1 <= o) { for (i = 0; i < z; i++) { int curr1 = 0; while (o > 0 && curr1 < 2 && o > z - i - 1) { printf("1"); curr1++; o--; } printf("0"); } ...
6
#include <bits/stdc++.h> using namespace std; char a[1000000]; int b[1000000]; int main() { int n; cin >> n; scanf("\n"); int k = 1; for (int i = 1; i <= n; i++) { scanf("%c", &a[i]); } for (int i = 1; i <= n; i++) { cin >> b[i]; } for (int i = 1; i <= n; i++) { if (a[k] == '>' && k + b[k]...
2
#include <bits/stdc++.h> using namespace std; template <class T> inline T mod_v(T num) { if (num >= 0) return num % 1000000007; else return (num % 1000000007 + 1000000007) % 1000000007; } template <class T> inline T gcd(T a, T b) { a = abs(a); b = abs(b); while (b) b ^= a ^= b ^= a %= b; return a; }...
6
#include <bits/stdc++.h> using namespace std; #define ll long long #define yes cout<<"YES\n" #define no cout<<"NO\n" #define pb push_back #define mp make_pair #define all(v) v.begin(),v.end() #define mxe(a,n) max_element(a,a+n)-a #define mne(a,n) min_element(a,a+n)-a #define mod 1000000007 //#define mod 998244353 ll...
9
#include <bits/stdc++.h> using namespace std; int v[102]; int main() { int i, n; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &v[i]); int l, r; do { l = r = -1; for (i = 1; i < n; i++) { if (l == -1) { if (v[i] > v[i + 1]) { l = i; swap(v[i], v[i + 1]); ...
3
#include <bits/stdc++.h> using namespace std; int64_t mod = 1e9 + 7, inf = 4e18; int64_t sum = 0; int64_t tmp3 = 0, tmp = 0, tmp2 = 0, comb = 1; vector<int64_t> check, st; int64_t maxi = 0, mini = inf; string s2, s; vector<vector<int64_t> > g; bool high = 0; int32_t main() { ios::sync_with_stdio(false), cin.tie(nullp...
5
#include <bits/stdc++.h> using namespace std; inline int nextint() { int x; scanf("%d", &x); return x; } inline long long nextll() { long long x; scanf("%lld", &x); return x; } template <typename T> void scanint(T& x) { T c = getchar(); while (((c < 48) || (c > 57)) && (c != '-')) c = getchar(); bool ...
9
#include <bits/stdc++.h> using namespace std; long long int mod = (long long int)1e12 + 7; int main() { long long int be, bd, t, m, mint, x, n; scanf("%lld%lld%lld", &be, &bd, &t); scanf("%lld", &n); m = mod; while (n--) { scanf("%lld", &x); if (x <= bd - t) { if (max(be, x - 1) <= bd - t && (be...
13
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; long long powmod(long long a, long long b, long long mod) { 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 % mod; } const int N = 1e5 + 10; int main()...
5
#include <bits/stdc++.h> std::map<std::pair<int, long long>, std::pair<long long, int>> Hash; std::pair<long long, int> dfs(std::pair<int, long long> p) { std::pair<int, long long> ppp = p; long long power = 1, x = p.second; for (; x >= 10; power *= 10, x /= 10) ; if (!p.first && !p.second) { return {0,...
16
#include <bits/stdc++.h> using namespace std; const int N = 5 + 1e5; double base[128]; struct Matrix { int N; double a[130][130]; Matrix(int y) { N = y; } void one() { for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) a[i][j] = (i == j); } Matrix operator*(Matrix B) { Matrix ret(B.N), A ...
11
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } using ll = long long; const ll mod = 1e9 + 7; const int maxn = 1e6 + 5; const ll inf = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n >> n >> n; ...
13
#include <bits/stdc++.h> using namespace std; int g[105][105]; int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; for (int i = 1; i <= m; i++) for (int j = 1; j <= n; j++) cin >> g[i][j]; for (int i = 1; i <= m; i++) { int maxid = 1; for (int j = 2; j <= n; j++) { if (g[i][m...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, s = 0; cin >> n; for (int i = 1; i <= n / 2; i++) { s += i * 1ll * i; } cout << s * 8 << endl; } }
2
#include <bits/stdc++.h> using namespace std; const int maxn = (int)(1e5 + 5); const long long mod = (long long)(998244353); int a[maxn]; long long gcd(long long a, long long b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } long long get(long long m) { return (m * (m + 1)) / 2ll; } int main...
13
#include <bits/stdc++.h> using namespace std; const int N = 210000; int n, k, d; int a[N], b[N]; struct link { int l, r, w; } sma[N], big[N]; int ts, tb; map<int, int> gt; int lazy[N * 4]; int mi[N * 4]; void build(int me, int l, int r) { if (l == r) { mi[me] = -l; return; } int mid = (l + r) >> 1; bu...
23
#include <bits/stdc++.h> using namespace std; int main() { int n, k, cnt = 0; cin >> n >> k; cout << k + 1; for (int i = k; i >= 1; i--) cout << " " << i; for (int i = k + 2; i <= n; i++) cout << " " << i; return 0; }
3
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e5 + 1; const long long INF = 2e18 + 77; long long cnt[MAXN][31]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, k; cin >> n >> k; for (long long i = 0; i < n; i++) { long long num; cin >> num; long long...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, d, k, r; d = 0; r = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) { if ((a[i + 1] - a[i]) > d) { d = a[i + 1] - a[i]; k = i; } } int j = 1; r = a[j + 1] - a[j - 1];...
1
#include <bits/stdc++.h> using namespace std; vector<int> parent(200004, 0); vector<bool> vis(200004, false); void dfs(int node, vector<vector<int> > &vec, vector<int> &colors); int cnt = 1; int main() { int n, x, y; cin >> n; vector<vector<int> > vec(n + 1); for (int i = 0; i < n - 1; i++) { cin >> x >> y;...
8
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int N = 5043; int add(int x, int y) { x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x; } int mul(int x, int y) { return (x * 1ll * y) % MOD; } int binpow(int x, int y) { int z = 1; while (y > 0) { if (y % ...
18
#include <bits/stdc++.h> using namespace std; const int MN = 3e3 + 7; long long dp[MN][MN]; int mx = 1, st[MN][MN], par[MN][MN], mark[MN]; vector<int> g[MN]; void dfs(int now, int z) { st[now][z] = 1; for (int i = 0; i < g[now].size(); i++) { if (!st[g[now][i]][z]) { dfs(g[now][i], z); par[g[now][i]...
15
#include <bits/stdc++.h> using namespace std; const long long maxn = 1000 * 2 + 10; int d1[maxn], d2[maxn], d3[maxn]; int ans; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; d1[x + y]++; if (x <= y) d2[y - x]++; else d3[x - y]++; } for (int...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; char a[N], b[N]; long double l[N][26], r[N][26]; int main() { int n; scanf("%d", &n); scanf("%s", a); scanf("%s", b); for (int i = 0; i < n; i++) { for (int j = 0; j < 26; j++) { l[i][j] = l[i - 1][j]; } l[i][b[i] - 'A'] +...
12
#include <bits/stdc++.h> using namespace std; const int up = 36000; char s[4005]; long long sum[4005], cnt[up + 5]; int main() { int a, cc = -1; cc = 2; scanf("%d", &a); scanf("%s", s); long long res = 0; long long n = strlen(s); for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + s[i] - '0'; for (int i =...
8
#include <bits/stdc++.h> using namespace std; int mat[6][7] = { {0, 0, 0, 1, 1, 1, 1}, {0, 1, 1, 0, 0, 1, 1}, {1, 0, 1, 0, 1, 0, 1}, {0, 1, 1, 1, 1, 0, 0}, {1, 0, 1, 1, 0, 1, 0}, {1, 1, 0, 0, 1, 1, 0}, }; int aux[6][7]; int res[7]; bool solve() { int p, div; for (int i = 0; i < 6; ++i) { p = i; for ...
16
#include <bits/stdc++.h> using namespace std; const long long M = 998244353; const long long MN = 2020; inline long long mul(long long a, long long b) { return a * b % M; } long long bp(long long b, long long p) { long long ac = 1; while (p) { if (p & 1) { ac = mul(ac, b); } b = mul(b, b); p >...
18
#include <bits/stdc++.h> using namespace std; int n, a[100010], q; long long node[400010][10], combi[400010][10], sum[10]; void built_tree(int i, int l, int r) { if (l > r) return; if (l == r) { int k = a[l], p = 1ll; while (k) node[i][k % 10] += p, p *= 10, k /= 10; for (int j = 0; j < 10; j++) combi[i...
20
#include <bits/stdc++.h> using namespace std; inline int readint() { int a = 0; char c = getchar(), f = 1; for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -f; for (; '0' <= c && c <= '9'; c = getchar()) a = (a << 3) + (a << 1) + (c ^ 48); return a * f; } const int MaxN = 16; int dp[1 << Ma...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int len1 = 1, len2 = 1; for (int i = 7; i < n; i = i * 7) { len1++; } for (int i = 7; i < m; i = i * 7) { len2++; } if (len1 + len2 > 7) { cout << 0 << endl; return 0; } int ans = 0; vector<int> x =...
9
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 50, m = 2e5 + 5; int n, Q; int a[N]; set<int> st[N]; struct Segment_tree { int vmi[N << 2], lmx[N << 2], rmx[N << 2], mx[N << 2], sum[N << 2], tag[N << 2]; void cover(int rt, int w) { vmi[rt] += w; tag[rt] += w; } void mdown(int rt)...
12
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const long long N = 100; long long dr[4] = {0, 0, 1, -1}; long long dc[4] = {1, -1, 0, 0}; long long ddr[8] = {0, 0, 1, -1, 1, -1, 1, -1}; long long ddc[8] = {1, -1, 0, 0, 1, -1, -1, 1}; long long ...
3
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 10; long long n, a[2][maxn], f[maxn][3]; 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 * 10 + ...
6
#include <bits/stdc++.h> using namespace std; int main() { string t, f; int k = 0, mx = 0, n; getline(cin, f); getline(cin, t); t += ' '; for (int i = 0; i < t.size(); i++) if (t[i] == ' ') { mx = max(k, mx); k = 0; } else if (int(t[i]) < 97) k++; cout << mx; }
0
#include <bits/stdc++.h> using namespace std; vector<int> edge[2050]; int n; int x[2050]; int dp[2050]; int val[2050]; int sub[2050]; void dfs(int v) { int maxv = 0; int sum = 0; sub[v] = 1; for (int i = 0; i < edge[v].size(); i++) { dfs(edge[v][i]); maxv = max(maxv, val[edge[v][i]] + x[edge[v][i]]); ...
6
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; long long x = 0; int idx = 0; while (str[idx] >= '0' && str[idx] <= '9') { x = x * 10 + (str[idx] - '0'); idx++; } char y = str[str.size() - 1]; long long ans = 0; if (x % 4 != 1 && x % 4 != 3) ans += 7; x--; ...
4
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n, k; long long res, cur; cin >> n >> k; res = 0; cur = n * 2; res += (cur + k - 1) / k; cur = n * 5; res += (cur + k - 1) / k; cur = n * 8;...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int a, b; cin >> b >> a; int m = a; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int ans = 0; for (int i = 0; i < n; i++) { if (b == 0 && a == 0) break; if (arr[i...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = long double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<db, db>; using vi = vector<int>; using vb = vector<bool>; using vc = vector<char>; using vl = vector<ll>; using vd = vector<db>; using vs = ...
6
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; string c; cin >> c; if (c.size() == 1 && b == 1) { cout << "0" << endl; return 0; } for (int i = 0; i < a; i++) { if (b == 0) { cout << c << endl; return 0; } if (i == 0 && c[i] != '1') { ...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double eps = 1e-8; const int N = 2097155; const int mo = 998244353; const double pi = acos(-1); inline int read() { int x = 0, f = 1; char ch = 0; for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); c...
14
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int inf = 1e9 + 5; const int nax = 2e5 + 5; void min_self(int& a, int b) { a = min(a, b); } void max_self(int& a, int b) { a = max(a, b); } void add_self(int& a, int b) { a = (a + b) % mod; } signed main() { ios::sync_with_stdio(0); cin.ti...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a; cin >> n >> m; vector<int> v; queue<int> q; for (int i = 0; i < n; i++) { cin >> a; v.push_back(a); q.push(i); } while (q.size() != 1) { for (int i = 0; i < q.size(); i++) { int j = q.front(); q.pop(); ...
2
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const double eps = 1e-6; const double pi = acos(-1.0); void debug() { cerr << '\n'; } template <typename T, typename... Ts> void debug(T x, Ts... y) { cerr << "\033[31m" << x << "\033[0m"; if (...
10
#include <bits/stdc++.h> using namespace std; inline long long read() { char ch = getchar(); long long p = 1, data = 0; while (ch < '0' || ch > '9') { if (ch == '-') p = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { data = data * 10 + (ch ^ 48); ch = getchar(); } return p * data; ...
13
#include <bits/stdc++.h> using namespace std; double DEG_to_RAD(double d) { return d * acos(-1.0) / 180.0; } double RAD_to_DEG(double r) { return r * 180.0 / acos(-1.0); } struct point_i { int x, y; point_i() { x = y = 0; } point_i(int _x, int _y) : x(_x), y(_y) {} }; struct point { double x, y; point() { x =...
8
#include <bits/stdc++.h> using namespace std; string s[10][1002]; int main() { int n, k; cin >> n >> k; cout << "YES" << '\n'; for (int i = 1; i <= 4; i++) { for (int j = 1; j <= n; j++) s[i][j] = '.'; } if (k % 2 == 0) { for (int i = 1; i <= k / 2; i++) { s[2][i + 1] = '#'; s[3][i + 1] ...
8
#include <bits/stdc++.h> #define ll long long #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f #define PI acos(-1) #define pb push_back #define F first #define S second #define lson i << 1 #define rson i << 1 | 1 #define mem(x, y) memset(x, y, sizeof(x)) #define fin(x) freopen(x, "r", stdin) #define fout(x) freope...
14
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; int main() { ios::sync_with_stdio(false); int k, a; cin >> k; a = 2000 - k % 2000 + 998000; cout << 2000 << endl; int i; for (i = 1; i <= 1998; i++) { cout << 0 << " "; } cout << -a + (k + a) / 2000 << " " << a << endl; return...
12
#include <bits/stdc++.h> using namespace std; template <typename T> T BigMod(T b, T p, T m) { if (p == 0) return 1; if (p % 2 == 0) { T s = BigMod(b, p / 2, m); return ((s % m) * (s % m)) % m; } return ((b % m) * (BigMod(b, p - 1, m) % m)) % m; } template <typename T> T ModInv(T b, T m) { return BigMo...
15
#include <bits/stdc++.h> using namespace std; bitset<7> digit[10] = {bitset<7>("1110111"), bitset<7>("0010010"), bitset<7>("1011101"), bitset<7>("1011011"), bitset<7>("0111010"), bitset<7>("1101011"), bitset<7>("1101111"), bitset<7>("1010010"), ...
9