solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { int arr[26]; for (int i = 0; i < 26; i++) arr[i] = 0; string S, T, ST; cin >> S >> T >> ST; for (int i = 0; i < ST.size(); i++) arr[ST[i] - 'A']++; for (int i = 0; i < S.size(); i++) arr[S[i] - 'A']--; for (int i = 0; i < T.size(); i++) arr[T[i] -...
0
#include <bits/stdc++.h> using namespace std; template <class T> inline bool fs(T &x) { int c = getchar(); int sgn = 1; while (~c && c < '0' || c > '9') { if (c == '-') sgn = -1; c = getchar(); } for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sgn; return ~c; } in...
4
#include <bits/stdc++.h> using namespace std; int le[400000], ri[400000], a[400000], b[400000], vis[400000]; int main() { int n, i, t, ans, p, tot; cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; ri[n] = n; for (i = n - 1; i >= 1; i--) { t = i + 1; while (t <= n && a[t] % a[i] == 0) { t = ri[t] ...
12
#include <bits/stdc++.h> using namespace std; using db = double; using s64 = long long; using ld = long double; using u32 = unsigned int; using u64 = unsigned long long; using pii = pair<int, int>; const double PI = acos(-1); const double eps = 1e-7; namespace Solver { const char endl = '\n'; const int MN = 3e5 + 5; in...
14
#include <bits/stdc++.h> using namespace std; const int N = (int)4e6 + 7; const long long MOD = (long long)1e9 + 7; const int inf = (int)1e9 + 7; const long long INF = (long long)1e18 + 7; long long t[N][2], cnt[N], a[N], p[N], sz; long long n; void add(long long mask) { long long v = 0; for (long long i = 30; i >=...
10
#include<iostream> #include<math.h> #include<string> #include<algorithm> #include<bits/stdc++.h> #include<bits/stdc++.h> #define ll long long int #define ull unsigned long long int #define MOD 1000000007 #define f(i,a,b) for(int i=a;i<b;i++) #define fe(i,a,b) for(int i=a;i<=b;i++) #define fd(i,a,b) for(int i=b;i>a;i--)...
7
#include <bits/stdc++.h> using namespace std; int get(long long l, long long r, vector<long long> v) { vector<long long> dp; for (auto i : v) { if (i < l or i > r) continue; auto it = upper_bound(dp.begin(), dp.end(), i); if (it == dp.end()) dp.push_back(i); else *it = i; } return dp...
14
#include <bits/stdc++.h> using namespace std; using namespace std; const int MAXN = 500 + 5; const int MAXM = 2000000 + 5; const int INF = 1000000009; int ned, first[MAXN], work[MAXN]; int cap[MAXM], to[MAXM], nxt[MAXM], dist[MAXN]; void init() { memset(first, -1, sizeof first); ned = 0; } void add(int u, int v, in...
15
#include <bits/stdc++.h> using namespace std; string s; int pal[5010][5010], dp[5010][5010], ans[5010]; int ispal(int x, int y) { if (x > y || x == y) return 1; int &ret = pal[x][y]; if (ret != -1) return ret; ret = 0; if (s[x] == s[y]) ret = ispal(x + 1, y - 1); pal[x][y] = ret; return ret; } int fun(int...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, count, result = 0, yes_no; cin >> n; for (i = 0; i < n; i++) { count = 0; for (j = 0; j < 3; j++) { cin >> yes_no; if (yes_no == 1) { count++; } } if (count >= 2) { result++; } } cout <<...
0
#include <bits/stdc++.h> using namespace std; int A[300010]; int dp[5010][5010]; int small_members, large_members; int group_members(int l, int s) { return l * large_members + s * small_members; } int main() { int n, k; scanf("%d %d", &n, &k); for (int i = 0; i < (int)(n); i++) scanf("%d", &A[i]); sort(A, A +...
12
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353, root = 3; long long modpow(long long b, int p) { long long ans = 1; while (p) { if (p & 1) ans = ans * b % mod; b = b * b % mod; p >>= 1; } return ans; } void ntt(long long* x, long long* temp, long long* roots, int N, in...
16
#include <bits/stdc++.h> using namespace std; int n, m, t, d[55][105]; long long f[55][55][105]; struct Task { long long l, r; int id, c; bool operator<(const Task& b) const { return c < b.c; } } a[55]; void pans(int i, int j, int w) { if (j == 1) { printf("%d %lld\n", a[i].id, a[i].l + w); return; } ...
12
#include <bits/stdc++.h> using namespace std; int main() { int arr[5][5]; int a, b, count = 0; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { cin >> arr[i][j]; if (arr[i][j] == 1) { a = i; b = j; } } } if (a < 2) { count += (2 - a); } if (a > 2) {...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, d, l, maxn, minn; scanf("%d%d%d", &n, &d, &l); if (n % 2) { maxn = n / 2 * (l - 1) + l; minn = n / 2 * (1 - l) + 1; } else { maxn = n / 2 * (l - 1); minn = n / 2 * (1 - l); } if (d < minn || d > maxn) printf("-1\n"); els...
7
#include <bits/stdc++.h> const int mod = 1000000007; using namespace std; const int maxn = 2e6 + 5; long long fac[maxn]; void prec() { fac[0] = 1; for (int i = 1; i < maxn; i++) { fac[i] = (fac[i - 1] * i) % mod; } } long long power(long long a, long long b) { a %= mod; long long res = 1; while (b > 0) ...
10
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) int main() { int t; vector<long long> partSum(100001); partSum[0] = 0; for (int i = 1; i <= 100000; i++) { partSum[i] = partSum[i - 1] + i; } cin >> t; for (int i = 0; i < t; i++) { int n, k; cin >> n >> k; int l...
5
#include <bits/stdc++.h> #pragma comment(linker, "/stack:227420978") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18; const long double PI = 3.141592653589793116, EPS = 1e-9, ...
16
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll t,m,i,j,k,ct,c,b,r,l,x=0; ll n;c=0; cin>>t; while(t--) { cin>>n; if(n%11==0) cout<<"YES"<<endl; else{ m=n%11; m=m*111; if((n-m)%11==0&&n-m>=0) cout<<"YES"<<en...
6
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int j = 0; j < t; j++) { int n; cin >> n; vector<int> szamok; for (int i = 0; i < n; i++) { int a; cin >> a; szamok.push_back(a); } sort(szamok.begin(), szamok.end()); int baj = 0; fo...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n == 1) { cout << k << endl; return 0; } cout << k - 1 << " " << 1 << " "; for (int i = 2; i < n; i++) { cout << 0 << " "; } cout << endl; int a = 0, b = n - 3; for (int i = 1; i < n - 1; i++) { i...
0
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,inline") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,avx,avx2,abm,mmx") using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y)...
19
#include <bits/stdc++.h> using namespace std; const long long infl = 1e18 + 5; long long int n, m, k, q, x, y, mx = -1, mn = infl, f, val, sz, sm, cnt, ans, t = 1, i, j, ind = -1; long long int a[1000004], b[1000004]; std::vector<vector<long long int> > g(1000004); void dfs(int ver, int ...
9
#include<bits/stdc++.h> #define fi first #define se second using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int maxn=1e6+10; const int inf=0x3f3f3f3f; double pi=3.1415926535898; priority_queue <pii, vector <pii>, greater<pii> > q; ll mod=1000000007,x,ans; int t,...
8
#include <bits/stdc++.h> using namespace std; unsigned long long mincost[2001][4002]; bool vi[3000][10000]; int ti[2001]; unsigned long long c[2001]; int n; unsigned long long MaxPoss; unsigned long long mindp(int i, int t) { if (i == n) { return (unsigned long long)(MaxPoss * (t < n)); } if (t - n > n - i) r...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, i, t, j, ans = -1; scanf("%d", &n); int a[n]; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } scanf("%d", &t); sort(a, a + n); for (int i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { if (a[j] - a[i] > t) break; } ...
6
#include <bits/stdc++.h> using namespace std; int h[1110]; int nh[1100]; int str2int(char str[]) { int res = 0; for (int i = 0; str[i] != '\0'; i++) { res = res * 10 + str[i] - '0'; } return res; } char data[10000]; struct node { int s, e; } hh[1110]; int main() { int n, m, i, j, k, r_n = 0; char st[1...
5
#include <bits/stdc++.h> using namespace std; const int N = 200005; const long long INF = 1e18; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n; cin >> n; map<int, vector<int>> mp; map<int, int> ans; for (int i = 1; i <= n; ++i) { int x; cin >> x; mp[x].push_back(i); ...
7
#include <bits/stdc++.h> using namespace std; int main() { map<string, int> mp; mp["scissorsrock"] = 0; mp["rockscissors"] = 1; mp["scissorspaper"] = 1; mp["paperscissors"] = 0; mp["paperrock"] = 1; mp["scissorsrock"] = 0; mp["scissorsscissors"] = 0; mp["rockrock"] = 0; mp["paperpaper"] = 0; int f...
1
#include <bits/stdc++.h> using namespace std; long long cd, v[200001], even_up[200001], odd_up[200001], odd_left[200001], odd_right[200001], even_left[200001], even_right[200001]; long long even_down[200001], odd_down[200001], sz[200001]; long long result = 0, mod = 1e9 + 7; vector<long long> edge[200001]; void inp...
15
#include <bits/stdc++.h> using namespace std; int main() { int n, x = 4, y = 5; scanf("%d", &n); if (n == 1 || n == 2) return puts("1"), 0; while (y < n) { if (x & 1) x = 2 * y, y = x + 1; else x = 2 * y - 1, y = x + 1; } return printf("%d", (x == n || y == n)), 0; }
16
#include <bits/stdc++.h> using namespace std; const int N = 2e6; const long long mod = 1e9 + 7; const long long inf = 1e9; long long a[610][610], f[2][610][610]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); int n; cin >> n; for (int i = 0; i <= 600...
12
#include <bits/stdc++.h> using namespace std; map<long long int, long long int> answer, answer1; int main() { long long int n, k; cin >> n >> k; long long int a[n]; long long int i; long long int sum = 0; for (i = 0; i < n; i++) { cin >> a[i]; if (a[i] % k == 0) { sum = sum + answer[a[i] / k];...
9
#include <bits/stdc++.h> using namespace std; template <typename G> struct triple { G first, second, T; }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; vector<triple<long long> > v(n); for (int i = 0; i < n; i++) { cin >> v[i].first; v[i].sec...
19
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const int mod = 1000000007; const int inf = 0x3fffffff; const string imp = "IMPOSSIBLE"; const long long long_inf = 1LL << 60; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int sgn(int x) { return x == 0 ? 0 : (x > 0 ? 1 : -1); } const ...
18
#include <bits/stdc++.h> using namespace std; const int N = 300005; int a[N], b[N]; bool cmp(int a, int b) { return a > b; } int main() { ios::sync_with_stdio(false); int n, k; cin >> n >> k; long long sum = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; if (i > 1) { b[i] = a[i] - a[i - 1]; ...
6
#include <bits/stdc++.h> inline long long sbt(long long x) { return __builtin_popcount(x); } using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&....
11
#include <bits/stdc++.h> long long n, k, m, ans; long long fac[1005]; long long dp[1005][105][2]; signed main() { scanf("%lld %lld %lld", &n, &k, &m); fac[0] = 1; for (long long i = 1; i <= 1000; i++) fac[i] = fac[i - 1] * 10 % k; dp[0][0][0] = 1; for (long long i = 0; i < n; i++) for (long long j = 0; j ...
14
#include <bits/stdc++.h> using namespace std; map<string, int> mp; int a[1005]; int i, j, k, n, m, x, y, z, t; char c[1005]; string s[1005]; string res[1005]; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> c >> x; if (x > mp[c]) { mp[c] = x; } } n = 0; for (map<string, int>::iterato...
6
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define fi first #define se second #define mp make_pair #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); const int N = (int)2e5 + 10; int nx[N]; int sw[N]; int suf[N]; int main(){ fastIO; int ...
18
#include <bits/stdc++.h> using namespace std; const int N = 105; int n, g, b; void preprocessing() { scanf("%d%d%d", &n, &g, &b); } void solve() { long long m = n; n = (n + 1) / 2; cout << max(n + (long long)(((double)n) / g - 1e-9) * b, m) << endl; } int main() { int T; scanf("%d", &T); for (int Case = 0; ...
6
#include <bits/stdc++.h> using namespace std; struct E { int u, v, id; long long w; } e[300010]; int g[5010]; int a[5010]; int n, m, p, t, sos, cnt; double mid; int find(int x) { return g[x] == x ? x : g[x] = find(g[x]); } bool cmp(E x, E y) { return (x.w + (x.u == 1) * mid) < (y.w + (y.u == 1) * mid); } void kru...
16
#include <bits/stdc++.h> using namespace std; int main() { double d, h, v, e; while (~scanf("%lf%lf%lf%lf", &d, &h, &v, &e)) { double v1 = v, v2 = 3.14159265359 * (d / 2) * (d / 2) * e; if (v2 >= v1) { puts("NO"); } else { double sum = 3.14159265359 * (d / 2) * (d / 2) * h; v = v1 - v2...
3
#include <bits/stdc++.h> using namespace std; const long long maxn = 100005; long long ar[maxn]; long long n; long long get(long long f) { long long li = 0, ri, temp = 0, s = 0, ind = -1; for (long long j = 0; j < n; j++) { s += ar[j]; if (s == (f + 1) / 2 && ind == -1) ind = j; else if (s == f) {...
10
// #pragma comment(linker, "/stack:200000000") // #pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2") #include <iostream> #include <string> #include <unordered_map> #include <unordered_set> #include <cstring> #include <chrono> #include <vector> #include ...
18
#include <bits/stdc++.h> using namespace std; template <class T> inline void R(T &xx) { xx = 0; char ch = getchar(); bool F = 0; while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') F = 1, ch = getchar(); while (ch >= '0' && ch <= '9') xx = xx + xx + (xx << 3) + ch - 48, ch = getch...
19
#include <bits/stdc++.h> using namespace std; double eps = 1e-8; struct event { double x; int v; event() {} event(double x, int v) : x(x), v(v) {} }; inline bool operator<(const event &a, const event &b) { return (a.x < b.x); } inline int sign(double x) { return (x < -eps ? -1 : x > eps); } event a[200010]; dou...
13
#include <bits/stdc++.h> using namespace std; int main() { long long x = 0LL, y = 0LL; int n; cin >> n >> x >> y; long long m = 0LL + y - n + 1; bool flg = true; if (m <= 0) flg = false; else { long long k = 0LL; k = n - 1 + m * m; if (k < x) flg = false; } if (!flg) cout << -1 << ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a; int now; set<int> b; int min_set_size = 0, min_number_of_sets = 0, max_similar_objects = 0, num_of_similar_objects; for (int i = 0; i < n; i++) { cin >> now; a.push_back(now); b.insert(now)...
1
#include <bits/stdc++.h> using std::max; using std::sort; const int MAXN = 1E6 + 10; int cc[MAXN], tong[MAXN]; int w[MAXN]; int doing() { int n, v = 0; scanf("%d", &n); for (int i = 1; i <= n; ++i) { int x; scanf("%d", &x); v = max(v, x); tong[x]++; cc[i] = x; } int tail = 0; for (int i ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, count = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b; if (b - a >= 2) { count++; } } cout << count; }
0
#include <bits/stdc++.h> using namespace std; int n; long long a[1002], b[1002]; long long res; int main() { int j, i; long long temp1, temp2; cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= n; i++) cin >> b[i]; res = 0; for (i = 1; i <= n; i++) { temp1 = a[i]; temp2 = b[i]; r...
1
#include <bits/stdc++.h> using namespace std; struct node { int x, y, val; } ed[100005]; int du[100005]; vector<int> edge[100005]; int dfs(int now, int fa) { for (int i = 0; i < (int)edge[now].size(); i++) { int u = edge[now][i]; if (u != fa) return dfs(u, now); } return now; } struct kkk { int a, b, ...
8
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") using namespace std; const long long inf = 1e9 + 228; const long long infll = 4e18; const long long mod = 1e9 + 7; const long long mod2 = 998244353; const long double eps = 1e-14; void fast_io() { ios_base::sync_with_stdio(0); cin.tie(0)...
17
#include <bits/stdc++.h> using namespace std; int unx() { int x = 0, n = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) n = (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return (n) ? -x : x; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int l, ...
22
#include <bits/stdc++.h> using namespace std; inline int IN() { char c; register int first = 0; for (; (c = getchar()) < 48 && c ^ '-' || c > 57;) ; bool f = c == '-'; if (f) (c = getchar()); for (; c > 47 && c < 58; (c = getchar())) first = (first << 3) + (first << 1) + c - 48; if (f) first = -fi...
9
#include <bits/stdc++.h> inline long long sbt(long long x) { return __builtin_popcount(x); } using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&....
8
#include<iostream> #include<cstdio> #include<vector> #include<queue> #include<stack> #include<cmath> #include<map> #include<set> #include<cstring> #include<string> #include<algorithm> #define fi first #define se second //#include<stdlib.h> //#include <time.h> //srand((unsigned)time(NULL)); using namespace std; typedef ...
12
#include <bits/stdc++.h> using namespace std; using ll = long long; int n; vector<int> a; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cin >> n; a.clear(); a.resize(n); int ones = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) ones++; } if (ones == 1) { cout << ...
10
#include <bits/stdc++.h> using namespace std; int G0(int x); int G1(int x); int a[100100]; int main() { int n, k; cin >> n >> k; int Xor = 0; for (int i = 0; i < n; i++) scanf("%d", &a[i]), Xor ^= (k & 1 ? G1(a[i]) : G0(a[i])); cout << (Xor ? "Kevin" : "Nicky"); } int G0(int x) { if (x < 3) return x; ...
14
#include <bits/stdc++.h> using namespace std; const long long N = 1e5, mod = 998244353; char r[] = {"RGB"}; char g[] = {"GBR"}; char b[] = {"BRG"}; string s; int main() { int q, n, k; scanf("%d", &q); while (q--) { scanf("%d%d", &n, &k); cin >> s; int ans = N; for (int i = 0; i <= s.length() - k; ...
7
#include <bits/stdc++.h> using namespace std; const int N = 1000001; int arr[N], mul[N]; int main() { int n; scanf("%d", &n); mul[n - 1] = 1; int curr = 1; int ans = 0; for (int i = n - 2; i >= 0; i--) { mul[i] = 2LL * mul[i + 1] % 998244353 + curr; mul[i] %= 998244353; curr = 2LL * curr % 99824...
12
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize "trapv" int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int test; cin >> test; while (test--) { int n, k; cin >> n >> k; string s; cin >> s; map<char, int> m; m['R'] = 0; m['G'] = 1; m['B'] = 2; ...
8
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; template <class T> inline bool read(T &n) { T x = 0, tmp = 1; char c = getchar(); while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar(); if (c == EOF) return false; if (c == '-') c = getchar(), t...
15
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n, q; cin >> n >> q; while (q--) { long long w; string s; cin >> w >> s; long long f = (n + 1) / 2; long long x = f / 2; stack<long long> y; while (f != w) { if (w > f) { f += x; y.push(x); ...
11
#include <bits/stdc++.h> using namespace std; int n, k; int a[300]; multiset<int, greater<int> > s; multiset<int> sfront[300], sback[300], sbig; multiset<int>::iterator it; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { scanf("%d", a + i); } for (int i = 1; i <= n; i++) { sfront[i] = sfront[...
7
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n; char str[N]; int sum1[N]; int sum2[N]; int nxt[N]; int mark[N]; bool check(int val) { int done = 0; memset(mark, 0, sizeof(mark)); for (int i = 1; i <= n; ++i) { if (str[i] == '.') { continue; } if (str[i] == '*') { ...
10
#include <bits/stdc++.h> using namespace std; long long exgcd(long long a, long long b, long long &x, long long &y) { if (!b) { x = 1; y = 0; return a; } long long ans = exgcd(b, a % b, x, y), temp = x; x = y; y = temp - a / b * y; return ans; } int main() { long long a, b, c, d, x, y; cin >...
10
#include <bits/stdc++.h> using namespace std; long long mx = -1e9, mn = 1e9 + 5; long long T, n, m, k, ans, t, a[1005], b[1000005], c[1000], d, l, r, sum, mid, coin, cnt, pos, number, x, y, z, h; vector<string> v; map<string, long long> mp; map<string, long long>::iterator it; map<long long, long long> mm; pair<lon...
11
#include <bits/stdc++.h> const int MaxN = 1e6 + 10; struct edge { int next, to; } e[MaxN << 1]; std::stack<int> st; int n, m, cnt, ccnt, dfscnt, a[MaxN], b[MaxN], num[MaxN]; int head[MaxN], col[MaxN], dfn[MaxN], low[MaxN], vis[MaxN]; void add_edge(int u, int v) { ++cnt; e[cnt].to = v; e[cnt].next = head[u]; h...
16
#include<bits/stdc++.h> using namespace std; const int N=2e+5+10; vector<pair<int,long long>> adj[N]; long long int dp[N][2][2]; int n,m; int main() { cin>>n>>m; for(int i=1;i<=m;i++) { int u,v; long long int w; cin>>u>>v>>w; adj[u].push_back({v,w}); adj[v].push_back({u,w}); } set<pair<long long int,in...
16
#include <bits/stdc++.h> using namespace std; int n; int h; int A[2002]; long long dp[2002][2002]; bool vis[2002][2002]; long long f(int idx, int open) { if (idx == n) return (open == 0); if (vis[idx][open]) return dp[idx][open]; vis[idx][open] = true; long long ans = 0; if (A[idx] + open == h) { ans = (a...
13
#include <bits/stdc++.h> int main() { char str[200][200], temp[200]; int n, i, j, len, main_count = 0, count = 0, i1, j1; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", str[i]); } for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { if (strlen(str[i]) > strlen(str[j])) { ...
3
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; long long mod = 1000000007LL; long long mod2 = 998244353LL; int n, m, k; int main() { cin >> n >> m >> k; bool ok = false; for (int i = 1; i <= k; ++i) { int x, y; scanf("%d%d", &x, &y); if (abs(x - 1) <= 4 || abs(x - n) <= 4 ||...
11
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); long long a[200001]; long long prefSum[200001]; long long ans1[200001]; long long ans2[200001]; long long product; long long cost1(long long i, long long j) { long long ans = product; ans -= p...
18
#include <bits/stdc++.h> using namespace std; int q, n, i, j; int main() { cin >> q; for (i = 0; i < q; ++i) { cin >> n; int sum = 0; for (j = 0; j < n; ++j) { int x; cin >> x; sum += x; } cout << (sum + n - 1) / n << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int SIZE = 1e3 + 10; using namespace std; int n, m; struct E { int k, c; E() {} E(int _k, int _c) : k(_k), c(_c) {} } es[4200010]; struct Flow { int n, m, dis[500010]; int qq[500010], qr, ql; vector<int> e[500010]; void init(int ...
20
#include <bits/stdc++.h> using namespace std; const int N = 500010; int n; priority_queue<int, vector<int>, greater<int> > pq; map<int, int, greater<int> > mp; map<int, int, greater<int> >::iterator it; int F[N], A[N]; long long ans = 0; void dbgout(priority_queue<int, vector<int>, greater<int> > q) { if (q.empty()) ...
22
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); printf("%d %d %d\n", 1 + (n % 3 == 2), 1 + (n % 3 >= 1), n - 2 - (n % 3)); return 0; }
0
#include <bits/stdc++.h> using namespace std; int sc(int &x) { return scanf("%d", &x); } int sc(unsigned int &x) { return scanf("%u", &x); } int sc(long long &x) { return scanf("%lld", &x); } int sc(unsigned long long &x) { return scanf("%llu", &x); } int sc(double &x) { return scanf("%lf", &x); } int sc(long double &x...
8
#include <bits/stdc++.h> using namespace std; string a, b, c; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int T; cin >> T; while (T--) { cin >> a >> c; b = a; sort(b.begin(), b.end()); if (b >= c) cout << "---" << endl; else { if (a == b || a < c) c...
8
#include <bits/stdc++.h> using namespace std; const int size = 2007; const long long modulo = 1000000007; const long long INF = 1e18; const double EPS = 1e-6; int main() { cin.sync_with_stdio(0); int n; cin >> n; vector<int> a(n), b(n), ind(n + 1); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i ...
7
#include <bits/stdc++.h> using namespace std; stack<int> s; int main() { ios_base::sync_with_stdio(false); int a, b; cin >> a >> b; while (b > a) { if (b % 2 == 0) { s.push(2); b /= 2; } else if (b % 10 == 1) { s.push(1); b /= 10; } else return cout << "NO" << endl, 0; ...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; template <typename... T> void rd(T&... args) { ((cin >> args), ...); } template <typename... T> void wr(T... args) { ((cout << args << " "), ...); cout << endl; } struct Dinic { struct Edge { int from, to, cap, f...
11
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n; int d[N]; char s[N][20]; map<int, int> mp; set<int> ss; set<int> stnull[2], stwa[2]; set<int> st[2]; vector<pair<string, int> > ans; void add(char *s, int i) { ans.push_back(make_pair(s, i)); } bool dig(char c) { return c <= '9' && c >= '0'; }...
14
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,sse,sse2") using namespace std; const double pi = 3.141592653589793238460; template <typename T, typename T1> T ama(T& a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T amm(T& a, T1 b) { if...
10
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 3; int n, a[N], L[5], R[5], top = 0, ok = 0; bool check() { for (int i = 1; i <= n; i++) if (a[i] != i) return 0; return 1; } void dfs(int k) { if (ok) return; if (check()) { ok = 1; printf("%d\n", top); for (int i = top; i; i--) ...
19
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; long long a[maxn], line[maxn]; int main() { long long tot = 0; int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; tot += a[i]; } int now = 0; long long answer = 0x7FFFFFFFFFFFFFFF; for (int k = tot; k >= 2; k--) ...
10
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7, MAXN = 1e5 + 10; int main() { int n; cin >> n; if (n < 3) { cout << "No"; return 0; } else { cout << "Yes" << '\n'; cout << 1 << ' ' << n << '\n'; cout << n - 1 << ' '; for (int i = 1; i < n; i++) cout << i << ' '; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int tp = 0, bt = n, lt = m, rt = 0, blacks = 0; for (int i = n; i > 0; i--) { string t; cin >> t; for (int j = 0; j < m; j++) { if (t[j] == 'B') { blacks++; } if (t[j] == 'B' && i > tp) { ...
5
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:200000000") using namespace std; const int INF = (int)1E9; const long long INF64 = (long long)1E18; const double EPS = 1E-9; const double PI = acos((double)0) * 2; const int MAXN = 1100; const int dxy[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; int n, m; char a[M...
14
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int mod = 1e9 + 7; const int maxn = 1e5 + 10; int n; char s[maxn]; int b[maxn]; int main() { cin >> n >> s + 1; int flag = 1; for (int i = 1; i <= n && flag; i++) { for (int j = i + 1; j <= n && flag; j++) { for (int k = j + 1; k <...
10
#include <bits/stdc++.h> long long n; int main() { scanf("%I64d", &n); printf("%I64d", (n - 2) * (n - 2)); }
3
#include <bits/stdc++.h> int main() { using namespace std; ios_base::sync_with_stdio(false), cin.tie(nullptr); int NA, NB; cin >> NA >> NB; vector<int64_t> A(NA); for (auto& a : A) cin >> a; vector<int64_t> B(NB); for (auto& b : B) cin >> b; struct edge_t { array<int, 2> x; int64_t v; }; v...
16
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; int n = s.size(); if (n < 2) { cout << s << endl; return 0; } if (n == 2 || n == 3) { cout << s[0] << endl; return 0; } string ans = ""; int a, b, c; in...
11
#include <bits/stdc++.h> using namespace std; int key[] = {1, 2, 9, 64, 625, 7776, 117649, 2097152}; int main() { int a, b; scanf("%d%d", &a, &b); long long ret = key[b - 1]; int mod = 1000000007; for (int i = 0; i < a - b; i++) ret = ret * (a - b) % mod; printf("%I64d\n", ret); }
7
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " = " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args)...
3
#include <bits/stdc++.h> using namespace std; const double ep = 1e-6; const double eps = 4e-5; const double pi = acos(-1); int tmpx, tmpy; struct pnt { double x, y; pnt(double x = 0, double y = 0) : x(x), y(y) {} pnt operator+(const pnt &b) const { return pnt(x + b.x, y + b.y); } pnt operator-(const pnt &b) con...
27
#include <bits/stdc++.h> using namespace std; int check(vector<bool> s, int n) { for (int i = (1); i < (n + 1); i++) { if (s[i]) return i; } return 0; } int main() { int n, m; vector<vector<int> > c(51, vector<int>()); vector<bool> s(51, true); scanf("%d %d", &n, &m); for (int i = (0); i < (m); i++)...
6
#include <bits/stdc++.h> using namespace std; int Mat[300][300]; pair<int, int> pa[300]; int l = 0; bool vis[300]; void DFS(int a) { vis[a] = 1; for (int i = 0; i < l; i++) if (Mat[a][i] && !vis[i]) DFS(i); } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int a; scanf("%d", &a)...
7