solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; void getio(); void solve() { long long a, b, c, d; cin >> a >> b >> c >> d; long long one = 0, to = 0; if (a % 2) one++; else to++; if (b % 2) one++; else to++; if (c % 2) one++; else to++; if (d % 2) one++; else to++; ...
1
#include <bits/stdc++.h> #pragma Gpref optimize("O3") using namespace std; const long long MOD = (long long)1e9 + 7; const long long N = 1e5 + 5; long long modmul(long long a, long long b) { long long res = 0; a %= MOD; while (b) { if (b & 1) res = (res + a) % MOD; a = (a << 1) % MOD; b >>= 1; } r...
3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; string s; while (cin >> n) { cin >> s; int cnt8 = 0; for (int i = 0; i < n; i++) if (s[i] == '8') cnt8++; int n8 = n - cnt8; int ans = min(n / 11, cnt8); cout...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; if (m >= n && k >= n) { cout << "Yes"; return 0; } cout << "No"; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int MAX_N = 200005; const long long inf = (1e18) + 10; long long a[MAX_N], b[MAX_N]; int n; int main() { scanf("%d", &n); for (int i = 1; i <= n / 2; i++) { scanf("%I64d", &b[i]); } int l = 0, r = n + 1; a[0] = -inf; a[n + 1] = inf; for (int i = 1; i...
2
#include <bits/stdc++.h> using namespace std; long long int cnt, b, n, a, gnt, des, m; int Max, Min; string s; int main() { ios::sync_with_stdio(0); cin.tie(0); int Gr = 0, Ins = 0; cin >> n >> a; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 'G') Gr = i; if (s[i] == 'T') Ins = i; } ...
0
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 50; const int M = 5e3 + 50; int n, m, u, k, l, r, t, x, y; int cnt, cnt1, cnt2, ans; int mn = INT_MAX; int mx = INT_MIN; const int fx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; const int fy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; const int dx[] = {0, 1, 0, -1}; const int...
2
#include <bits/stdc++.h> using namespace std; string s1[105], s2[105], s3[105], s4[105]; struct ab { string a; string b; } ans[105]; int an, a3, a4; int cmp(const void *x, const void *y) { ab xx = *(ab *)x; ab yy = *(ab *)y; if (xx.a > yy.a) return 1; if (xx.a < yy.a) return -1; if (xx.b > yy.b) return 1;...
6
#include <bits/stdc++.h> const long long mxn = 1e6 + 7; const long long mod = 1e9 + 9; const long long inf = 1e18 + 9; using namespace std; vector<long long> v; long long l, r, sum = 0; void gen(long long x) { if (x >= 10000000000) return; v.push_back(x); gen(x * 10 + 4); gen(x * 10 + 7); return; } int main()...
1
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma loop_opt(on) using namespace std; template <class T> using vec = vector<T>; template <class T> using stack = stack<T, vec<T> >; template <class T> using MaxHeap = priority_queue<T, vec<T>, less<T> >; template <class T> using MinHeap = priority_queue<T, vec<T>,...
2
#include<algorithm> #include<iostream> #include<vector> using namespace std; constexpr int MOD = 1e9 + 7; constexpr int MAXN = 2e5; int powMOD(int a, int b) { if (b == 1) { return a; } else if(b % 2 == 0) { int t = powMOD(a, b / 2); return 1LL * t * t % MOD; } else { return 1LL * a * powMOD(a, b - 1) % ...
7
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; int n, m, y[200011], p[200011], id; int v[200011]; struct sgt { int sum[800011]; void clear(int k, int l, int r) { sum[k] = r - l + 1; if (l == r) return; int mid = (l + r) >> 1; clear(k << 1, l, mid); clear(k << 1 | ...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int n, a[N + 1], segTree[4 * N][60]; void build_tree(int v, int l, int r) { if (l == r) { for (int Time = 0; Time < 60; Time++) { if (Time % a[r] == 0) { segTree[v][Time] = 2; } else segTree[v][Time] = 1; } return...
8
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 3; const int M = 1e6 + 9; const long long INF = 1e9 + 7; const int SM = 1e3 + 5; const double EPS = 3e-16; int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n, k; cin >> n >> k; vector<int> d; for (int i = 0; i < n; ...
1
#include <bits/stdc++.h> using namespace std; int mod = 1000000007; const int inf = 1034567891; const long long LL_INF = 1234567890123456789ll; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* na...
4
#include <bits/stdc++.h> using namespace std; int n, m, k, x, y, sum, cnt, ans, a[100005], b[100005]; int main() { scanf("%d %d %d", &n, &m, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < m; i++) scanf("%d", &b[i]); sort(a, a + n); sort(b, b + m); reverse(a, a + n); reverse(b, b ...
4
#include <bits/stdc++.h> using namespace std; void solve() { vector<int> arr(3); cin >> arr[0] >> arr[1] >> arr[2]; sort(arr.begin(), arr.end()); if (arr[0] + arr[1] == arr[2]) { cout << "YES" << endl; return; } else { if (arr[0] == arr[1] && arr[2] % 2 == 0) { cout << "YES" << endl; r...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int a, b, c = 0, k, u, d; cin >> a >> b; while (1) { if (b > a) swap(a, b); k = a / b; c = c + k; u = a % b; a = b; b = u; a = a - b; if (min(a,...
0
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007LL; long long large = 2000000000000000000LL; int main() { int n, k; cin >> n >> k; int z = (n - k) / 2; int t = z; while (n--) { if (t) { cout << 0; t--; } else { cout << 1; t--; } if (t < 0) t = z;...
7
#include <bits/stdc++.h> using namespace std; const int M = 998244353; int n, m; char c[200004]; int cnt[23][26]; int mn[26], f[8400000]; long long ans; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s", c), m = strlen(c); for (int j = 0; j < m; j++) cnt[i][c[j] - 'a']++; } for (int...
8
#include <bits/stdc++.h> using namespace std; const int N = 2002; int dx[] = {1, 0, -1, 0}; int dy[] = {0, -1, 0, 1}; int n, m, deg[N][N]; bool fail; bool used[N][N]; char a[N][N], b[N][N]; queue<pair<int, int> > q; bool valid(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m && used[x][y] == 0; } void add(...
6
#include <bits/stdc++.h> int main() { int x1, y1, x2, y2, x3, y3; scanf("%d %d %d %d %d %d", &x1, &y1, &x2, &y2, &x3, &y3); printf("3\n%d %d\n%d %d\n%d %d", x2 + x3 - x1, y2 + y3 - y1, x1 + x3 - x2, y1 + y3 - y2, x1 + x2 - x3, y1 + y2 - y3); return 0; }
2
#include <bits/stdc++.h> using namespace std; bool tri(int a, int b, int c) { if (a + b > c && a + c > b && b + c > a) return true; else return false; } int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; if (tri(a[0], a[1], a[2])) { cout << "YES"; return 0; ...
1
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 1e6 + 5; const int MOD = 1e9 + 7; const double PI = acos(-1.0); const double EPS = 1e-8; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a * b / gcd(a, b); }...
4
#include <bits/stdc++.h> using namespace std; const int N = 2005; const int M = 1000005; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } long long fact(long long n) { long long ret = 1; for (int i = 1; i <= n; i++...
7
#include <bits/stdc++.h> int N, M; double e[1000][1000]; int main() { scanf("%d%d", &N, &M); int x, y; scanf("%d%d", &x, &y); if (x == N) { printf("%.5f\n", 0.0); return 0; } int loop_max = 100000000 / M / (N - x); for (int i = 0; i < (int)(N); i++) for (int j = 0; j < (int)(M); j++) e[i][j] =...
8
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; int n, m, k; int spe[N]; vector<int> adj[N]; vector<int> comp[N]; int vis[N]; void dfs(int u, int num) { vis[u] = 1; comp[num].push_back(u); for (auto v : adj[u]) { if (!vis[v]) dfs(v, num); } } long long C2(int x) { return (x * (x - 1)) /...
3
#include <bits/stdc++.h> using namespace std; struct Point { int x, y; bool operator<(const Point &p) const { return x < p.x; } } a[100001]; struct Q { int l, r, y, type, rl, rr; bool operator<(const Q &x) const { return y < x.y; } } q[100001 << 1]; vector<int> tt; int K, n; long long ans[100001]; int main() { ...
9
#include <bits/stdc++.h> int count(int n) { int i, count = 0; for (i = 1; n != 0; i++) { if (n % 2 == 1) count++; n /= 2; } return count; } int main() { int i, n, m, k, x, cnt = 0; scanf("%d %d %d", &n, &m, &k); int ara[m + 1]; for (i = 0; i < m + 1; i++) { scanf("%d", &ara[i]); } for (i...
1
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define sz(a) a.size() #define all(a) a.begin(),a.end() #define lb lower_bound #define ub upper_bound #define owo ios_base::sync_with_stdio(0);cin.tie(0); #define MOD (ll)(998244353) #defi...
10
#include <bits/stdc++.h> using std::abs; using std::array; using std::cerr; using std::cin; using std::cout; using std::generate; using std::make_pair; using std::map; using std::max; using std::max_element; using std::min; using std::min_element; using std::pair; using std::reverse; using std::set; using std::sort; us...
7
#include <bits/stdc++.h> using namespace std; int rev(int a) { int res = 0; for (int i = 0; i < 8; i++) { res = res * 2 + a % 2; a /= 2; } return res; } int main() { string str; getline(cin, str); int old = 0; for (int i = 0; i < str.size(); i++) { for (int j = 0; j < 256; j++) { int k...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 8; const int INF = (int)1e+9; int a[MAXN][MAXN]; int n, k; int p[MAXN]; int ans; int main() { scanf("%d %d\n", &n, &k); for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { char c; scanf("%c", &c); a[i][j] = c - '0'; } ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, s = 0, ans = 0; cin >> n >> s; --s; vector<int> a(n), b(n), o(n), f(n); vector<vector<int>> bin(n + 1); for (int i = 0; i < n; ++i) cin >> a[i], b[i] = a[i]; for (int i = 0; i < n; ++i) if (!a[i]) a[i] = n; if (a[s]) a[s] = 0; for (...
5
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const double eps = 1e-9; const int maxn = 100000 + 10; char t(char c) { if (c == 'L') return 'U'; if (c == 'U') return 'L'; if (c == 'R') return 'D'; if (c == 'D') return 'R'; } vector<string> transpose(vector<string> A) { int n = (int)A...
9
#include <bits/stdc++.h> using namespace std; int n, m, ans[100005], tra[100005]; struct que { int xl, xr, yl, yr, z, id; bool operator<(const que &A) const { return z < A.z; } } q[100005]; struct Point { int x, y, id; } g[100005]; struct node { int xl, xr, yl, yr, id; node() {} node(int A, int B, int C, in...
8
#include <bits/stdc++.h> using namespace std; const int MAX_T = 100 * 1000; int tab[MAX_T]; int tab_inc[MAX_T]; int tab_dec[MAX_T]; int tab_f[MAX_T]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &tab[i]); int prec = 0; for (int i = 0; i < n; i++) { tab_inc[i] = max(prec, ta...
4
#include <bits/stdc++.h> using namespace std; long long n, m, k, a[100010], kol[2000005], anser; bool cmp(pair<pair<long long, long long>, long long> x, pair<pair<long long, long long>, long long> y) { long long lx = x.first.first / 316; long long ly = y.first.first / 316; if (lx != ly) return lx < ly; ...
7
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n; cin >> n; ; vector<int> v(n); set<int> s; for (int i = 0; i < n; i++) { cin >> v[i]; s.insert(v[i]); ...
6
#include <bits/stdc++.h> int power(int x, long long y) { int p; if (y == 0) return 1; p = power(x, y / 2); p = (long long)p * p % 1000000007; if (y % 2 == 1) p = (long long)p * x % 1000000007; return p; } int main() { int k, p, x, y, even; scanf("%d", &k); p = 2; even = 0; while (k-- > 0) { lo...
6
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:10000000000") using namespace std; string s; int mod = 1000000007; bool check(int a, int b, int c) { int t[3] = {0}; if (a == 3) t[1]++; if (b == 3) { t[0]++; t[2]++; } if (c == 3) t[1]++; if (a == 3) t[0] = 3; if (b == 3) t[1] = 3; if (c ...
5
#include <bits/stdc++.h> using namespace std; long long s, ans, f[130][2], g[130][2]; long long calc(int one, long long sum, int lena, int lenb) { memset(f, 0, sizeof(f)); f[0][0] = 1; for (int i = 0; (1LL << i) <= sum; i++) { for (int j = 0; j <= one; j++) for (int k = 0; k <= 1; k++) g[j][k] = f[j][k]...
12
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; bool Finish_read; template <class T> inline void read(T &x) { Finish_read = 0; x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; if (ch == EOF) return; ch = getchar(); } while (isdigit(ch))...
4
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e5 + 15; const int INF = 1e9; int n, k, m; unordered_map<string, int> mp; int cost[MaxN]; int group[MaxN], groupCost[MaxN]; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k >> m; for (int i = 1; i <= n; ++i) { string...
2
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> inline bool mina(A &x, B y) { return (x > y) ? (x = y, 1) : 0; } template <typename A, typename B> inline bool maxa(A &x, B y) { return (x < y) ? (x = y, 1) : 0; } const int K = 200002; int N; int X[(200004)]; int Y[(200004)]; int XY[(2...
9
#include <bits/stdc++.h> using namespace std; const int M = 3e5 + 10; const int mod = (int)1e9 + 9; int n, m; int a[M]; int fib[M][2]; int sumfib[M][2]; void add(int &a, int b) { a += b; if (a < 0) a += mod; if (a >= mod) a -= mod; } struct Node { int f[2]; int sum; bool mk; void Init() { f[0] = f[1] = su...
8
#include <bits/stdc++.h> using namespace std; void fast() { ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } signed main() { fast(); long long t; cin >> t; while (t--) { long long i, n, a, b; cin >> n; set<long long> second; for (i = 0; i < n; i++) { ...
2
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int n, ans; int dp[77][77][77][2]; string s; vector<int> V, K, O; void mini(int &a, int b) { a = min(a, b); } int count_remaining(const vector<int> &List, int from, int limit_val) { int cnt = 0; for (int i = from; i < List.size() && List[i] < limit_...
8
#include <bits/stdc++.h> using namespace std; const int sq = 646; const int INF = 1031231234; struct block : vector<pair<long long, int> > { long long inc = 0; bool invalid = false; }; void modifyPartial(block &b, int l, int r, int x) { if (b.invalid) return; for (int i = 0; i < b.size(); i++) { if (b[i].se...
8
#include <bits/stdc++.h> using namespace std; const int INF = 1000000007; const long long INFLL = (long long)INF * (long long)INF; const long double EPS = 10e-9; const unsigned int M = 1000000007; long double pi = 2 * acos(0.0); void solve() { long long n; cin >> n; std::map<long long, long long> need; while (n...
3
#include <bits/stdc++.h> using namespace std; long long modx(long long Base, long long exponent) { long long ans = 1; if (Base == 1) return Base; while (exponent) { if (exponent & 1) ans = (ans * Base) % 1000000007LL; Base = (Base * Base) % 1000000007LL; exponent = exponent >> 1; } return ans; } l...
6
#include <bits/stdc++.h> const int MOD = 9973; const int INF = 99999999; using namespace std; int n, m, k; int a[20]; int c[20][20]; long long int dp[1 << 18][20]; int count(int i) { int nums = 0; while (i) { i &= (i - 1); nums++; } return nums; } int main() { while (~scanf("%d %d %d", &n, &m, &k)) { ...
5
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s; for (int i = 0; i < n - ((n + 3) / 4); i++) s.push_back('9'); for (int i = 0; i < (n + 3) / 4; i++) s.push_back('8'); cout << s << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int N = 200001; const int p = 1e9 + 7; int n; long long mul[N], inv[N]; void read(int &x) { char ch = getchar(); x = 0; for (; ch < '0' || ch > '9'; ch = getchar()) ; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 3) + (x << 1) + ch - '0'; } ...
5
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; int mod1 = 998244353; long long fact(long long n) { long long f = 1; for (long long i = 1; i <= n; i++) f = (f * i) % mod; return f; } long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long lcm(long lon...
0
#include <bits/stdc++.h> using namespace std; const long long INF = 0x7f7f7f7f7f7f; template <typename _T> void read(_T &x) { _T f = 1; x = 0; char s = getchar(); while (s > '9' || s < '0') { if (s == '-') f = -1; s = getchar(); } while (s >= '0' && s <= '9') { x = (x << 3) + (x << 1) + (s ^ 48)...
4
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int n; vector<int> id[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; int n; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; id[x].push_back(i + 1); } int cur = 0; vector<int> ans; while (n && cur ...
5
#include <bits/stdc++.h> using namespace std; const int MX = 300000005, B = 41000; int pre[] = { 0, 2127, 3996, 5753, 7490, 9181, 10827, 12468, 14086, 15695, 17279, 18864, 20424, 22003, 23532, 25112, 26628, 28145, 29652, 31137, 32651, 34178, 35662, 37146, ...
7
#include <bits/stdc++.h> #pragma warning(disable : 4786) #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const double PI = acos(-1.0); const double eps = 1e-6; const int maxn = 1e5 + 5; long long c[maxn], w[maxn]; int pay1[maxn], pay2[maxn]...
8
#include <bits/stdc++.h> using namespace std; const int Maxn = 5e3 + 5; const long long Mod = 51123987; const long long inf = 0x3f3f3f3f3f3f3f; int f[155][55][55][55] = {}, Next[151][3] = {}; int main() { long long n, ans = 0; string s; cin >> n >> s; f[0][0][0][0] = 1; int a[300] = {}; a['a'] = n + 1; a[...
8
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int MOD = 1000000007; int h = 1, r, g; int dp[2][200005]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> r >> g; int l = 1, high = 900; while (l <= high) { int med = (l + high) >> 1; if...
6
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read() { T f = 1, x = 0; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return x * f; } const int N = 3e3 + 7; int n, k...
10
#include <bits/stdc++.h> using namespace std; unsigned long long ans, a[100010], x; int n; int get(int u) { while (u & (u - 1)) u &= u - 1; return u; } int main() { scanf("%d", &n); for (int i = 1; i < n; i++) { scanf("%llu", &x); a[i] += x; ans += a[i]; printf("%llu\n", ans); a[i + get(n - ...
1
#include <bits/stdc++.h> using namespace std; int main() { int e, c; scanf("%d %d", &e, &c); if (e == 0 && c == 0) { puts("0 0"); return 0; } if (e == 0 && c != 0) { puts("Impossible"); return 0; } int mx = (c == 0) ? e : c + (e - 1); int mn = (c == 0 || c <= e) ? e : c; printf("%d %d"...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b; cin >> a >> b; if (a > 5 && b > 5) { if (b - a > 10) { cout << "0"; return 0; } else { long long int k = 1; for (long long int i = a + 1; i <= b; i++) { long long int x = i % 10; k = k * ...
1
#include <bits/stdc++.h> using namespace std; char str[300007]; int main() { memset(str, '\0', sizeof(str)); long long n; long long ans = 0; long long pos = 1; cin >> n; scanf("%s", str); for (int i = 1; i < n; i++) { if (str[i - 1] == str[i]) { pos++; } if (str[i - 1] != str[i]) { ...
5
#include <bits/stdc++.h> using namespace std; int chh; const int N = 1005; long long a[N], m[N]; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } void extend_Euclid(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return; } extend_Euclid(b, a...
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int a, b; cin >> a >> b; int n = s.size(); vector<int> v(n); v[0] = (s[0] - '0') % a; for (int i = 1; i < n - 1; i++) v[i] = (v[i - 1] * 10 + s[i] - '0') % a; int rem = 0, p = 1; for (int i = n - 1; i > 0; i--) { rem ...
4
#include <bits/stdc++.h> using namespace std; int n; int ans[1001]; void mark(int st, int mn) { for (int i = 1; i <= n; i++) { ans[i] = 0; if (i >= mn && i != st) ans[i] = 1; } } int ask(int st, int mn) { mark(st, mn); int tot = 0, tmp, sum = 0; for (int i = 1; i <= n; i++) if (ans[i] == 1) tot++;...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n; int t = n / 2 + 1; int d = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (j < t - d || j > d + t) { cout << "*"; } else { cout << "D"; } } cout << endl; if (i ...
0
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; vector<vector<int>> adj; vector<long long> subtree; int dfs(int v, int parent) { int sum = 1; for (auto u : adj[v]) if (u != parent) { subtree.push_back(dfs(u, v)); sum += subtree.back(); } return sum; } int main() { ios_...
5
#include <bits/stdc++.h> using namespace std; string adj[] = {"lios", "liala"}; string noun[] = {"etr", "etra"}; string verb[] = {"initis", "inites"}; bool suffix(const string &a, const string &sufijo) { int idx = a.rfind(sufijo); if (idx < 0) return false; return idx + sufijo.size() == a.size(); } vector<string>...
4
#include <bits/stdc++.h> using namespace std; int n, k; int main() { scanf("%d %d", &n, &k); if (n < (2 * k + 1)) { printf("-1\n"); return 0; } printf("%d\n", (n * k)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { printf("%d ", i); if ((i + j) <= n) { printf("%...
3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, q, dfn[N], ed[N], pr[N], clk = -1, add[N << 2]; int fa[N][20], mn[N << 2], cnt[N << 2]; vector<int> g[N]; map<int, map<int, int> > r; inline void dfs(int x, int ff) { pr[x] = ff; dfn[x] = ++clk; for (auto u : g[x]) { if (u == ff) cont...
9
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int dx[8] = {0, -1, 0, 1, -1, -1, 1, 1}, dy[8] = {1, 0, -1, 0, -1, 1, -1, 1}; long long dp[200005]; void solve() { int n; cin >> n; for (int i = 1; i <= n; i++) { long long x; cin >> x; dp[i] = dp[i - 1] + x; ...
7
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 100 + 3; int n, ans1, h[N]; bool par[N], mark[N], vis[N]; vector<int> adj[N]; void input() { cin >> n; for (int i = 0; i + 1 < n; i++) { int u, v; cin >> u >> v; adj[--u].push_back(--v); adj[v].push_back(u); } } void dfs2(int u) { ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<int> c(n), ans(n); for (int i = 0; i < n; i++) cin >> c[i]; priority_queue<pair<int, int> > pq; for (int i = 0; i < n + k; i++) { if (i < n) pq.push({c[i], i}); if (i >...
3
#include <bits/stdc++.h> using namespace std; const int N = (1e5) + 10; long long n, sum, mx, tmp; int main() { scanf("%lld", &n); for (int i = 0; i < n; i++) { scanf("%lld", &tmp); mx = max(tmp, mx); sum += tmp; } long long ans = ceil(1.0 * sum / (n - 1)); ans = max(mx, ans); printf("%lld\n", a...
4
#include <bits/stdc++.h> using namespace std; int main() { set<char> mySet; int n; cin >> n; char dig[n][n]; char x; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> dig[i][j]; if (i == 0 && j == 1) x = dig[i][j]; if (j != i && j != (n - i - 1)) { if (dig[i][j...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; while (t--) { long long int x, d; cin >> x >> d; long long int num = 1; vector<long long int> v; while (x > 0) { long long int z = 0; while ((pow(2, ...
4
#include <bits/stdc++.h> using namespace std; template <class T> using VV = vector<vector<T>>; template <class T> inline T SMIN(T& a, const T b) { return a = (a > b) ? b : a; } template <class T> inline T SMAX(T& a, const T b) { return a = (a < b) ? b : a; } template <class Iter> void dumpc(Iter begin, Iter end) { ...
2
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5, M = 1e9 + 5, MOD = 1e9 + 7; long long int t, n, m, k, f, x, freq[N], b[N], c, mn = 1e9, mx, ans; long long int sum = 0; struct node { long long int v, p; } a[N]; bool cmp(node a, node b) { return a.v > b.v; } int main() { ios_base::sync_with_stdio...
2
#include <bits/stdc++.h> using namespace std; template <class X, class Y> void minimize(X &x, const Y &y) { if (x > y) x = y; } template <class X, class Y> void maximize(X &x, const Y &y) { if (x < y) x = y; } template <class T> T Abs(const T &x) { return (x < 0 ? -x : x); } const int base = 16; const long long I...
8
#include <bits/stdc++.h> using namespace std; const int mx = 1e7 + 10; long long dp[mx][2]; const int mod = 1e9 + 7; int main() { int n; cin >> n; dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = (dp[i - 1][1]) % mod; dp[i][1] = (dp[i - 1][0] * 3 + dp[i - 1][1] * 2) % mod; } cout << dp[n][0] ...
3
#include <bits/stdc++.h> using namespace std; int a, b, c = 0, d = 0; int main() { int n, i, j, k = 1, cot = 0; scanf("%d", &n); for (i = b = 0; i < n; i++) { scanf("%d", &a); a--; if (i && (b + k + n) % n != a) { if (k + 1) c = i + 1, k = -1; else d = i, k = 1; cot++...
2
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; if (n % 2 != 0) { cout << n / 2 << endl; } else { cout << (n / 2 - 1) << endl; } } }
0
#include <bits/stdc++.h> using namespace std; struct EDGE { int x, y, v, c; double r; EDGE(int _x = 0, int _y = 0, int _v = 0, int _c = 0, double _r = 0) { x = _x; y = _y; v = _v; c = _c; r = _r; } } ee[100000]; int en, used[2000], tt; double an; vector<EDGE*> e[2000]; void add(int x, int y,...
8
#include <bits/stdc++.h> using namespace std; int main() { int u, j, v, c = 0, d = 0; cin >> u >> v; int w[u]; for (j = 0; j < u; j++) { cin >> w[j]; } sort(w, w + u); for (int k = u - 1; k >= 0; k--) { c += w[k]; d++; if (c >= v) { break; } } cout << d << endl; return 0; }...
0
#include <bits/stdc++.h> using namespace std; int a[100005]; int b[100005]; int n, maxn = 0; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); int mid = n % 2 == 1 ? n / 2 + 1 : n / 2; for (int i = 1; i <= mid; i++) if (a[i] + 1 - i > 0) b[a[i] + 1 - i]++; for (int i = mid + 1...
5
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; if (n == 3) cout << 5; else { for (int i = 1; i <= 100; i++) if (i % 2 == 1 && (i * i + 1) / 2 >= n) { cout << i; return 0; } } return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<vector<pair<int, int>>> graph(n); long long total = 0; for (int i = 0; i < n - 1; i++) { int x, y, z; cin >> x >> y >> z; x--; y--; graph[x].emplace_back(y, z); ...
13
#include <bits/stdc++.h> using namespace std; int pr[100000 + 10]; vector<unsigned long long> prv; void sev() { pr[1] = 1; for (int i = 2; i <= 100000; ++i) { if (pr[i]) continue; prv.push_back(i); for (int j = i; j <= 100000; j += i) { pr[j] = i; } } } int main() { int n, t; cin >> t; ...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; int x = 1; while (x <= n) { int k = (n - x) / 2; for (int i = 0; i < k; i++) cout << "*"; for (int i = 0; i < x; i++) cout << "D"; for (int i = 0; i < k; i++) co...
0
#include <bits/stdc++.h> using namespace std; const long long int inf = 0x3f3f3f3f3f3f3f3fll; long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int ...
5
#include <bits/stdc++.h> using namespace std; int a[2][2]; int main() { int T; scanf("%d", &T); while (T--) { a[0][0] = a[0][1] = a[1][0] = a[1][1] = 0; int n; scanf("%d", &n); int t; for (int i(0); i < n; i++) { scanf("%d", &t); if (t % 2) { a[0][0]++; } else ...
1
#include <bits/stdc++.h> using namespace std; long long intersect(pair<long long, long long> segmentA, pair<long long, long long> segmentB) { long long res; if (segmentA.first > segmentA.second) { swap(segmentA.first, segmentA.second); } if (segmentB.first > segmentB.second) { swap(s...
0
#include <bits/stdc++.h> using namespace std; const double eps = 5e-7; const double Inf = 1e9; const int Maxn = 105; const int Maxl = 3; const double lim = 10000; int n; int x[Maxn], y[Maxn], z[Maxn]; double c[Maxl]; double ternarySearch(int lvl, double l, double r) { if (lvl == Maxl) { double X = c[0], Y = c[1],...
6
#include <bits/stdc++.h> using namespace std; int s, x1, x2, t1, t2, p, d; int go(int p, int& d, int x) { int ans = 0; int dd = (x - p); if (dd * d < 0) { int to = (d > 0) ? s : 0; ans += 2 * abs(to - p) * t1; d *= -1; } ans += abs(x - p) * t1; return ans; } int main() { assert(cin >> s >> x1 ...
4
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 10; int AAAAAA[MAX]; int IIIANS[MAX]; int main() { int n, m; scanf("%d%d", &n, &m); int MAXXXXXXX = 0; for (int i = 1; i <= n; i++) { scanf("%d", &AAAAAA[i]); MAXXXXXXX = max(MAXXXXXXX, AAAAAA[i]); } sort(AAAAAA + 1, AAAAAA + n + 1)...
4
#include <bits/stdc++.h> using namespace std; int n, mx[500200], p[500200], ind[500200], ans[500200], f[500200], d[500200]; vector<pair<int, int> > g[500200]; unordered_map<int, int> mp[500200]; char c[500200]; void Merge(int a, int b, int vert) { unordered_map<int, int>::iterator it = mp[a].begin(); while (it != m...
10