solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { long long x, b = 0; cin >> x; for (int i = 1; i < x; i++) b += (x - i) * i; cout << b + x << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> ostream& operator<<(ostream& cout, pair<A, B> const& p) { return cout << "(" << p.first << ", " << p.second << ")"; } template <typename A> ostream& operator<<(ostream& cout, vector<A> const& v) { for (int i = 0; i < v.size(); i++) { ...
16
#include <bits/stdc++.h> using namespace std; int n, a[110000], num[110000]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); memset(num, 0, sizeof(num)); for (int i = 1; i <= n; i++) num[a[i]]++; for (int i = 1; i <= n; i++) if (num[i] % 2 == 1) num[0]++; if (num[0] > 1) {...
17
#include <bits/stdc++.h> using namespace std; int a, b, c, d; char p[5]; long long map[6][6]; long long num[10]; long long ans; void dfs(int lv) { if (lv == 4) { for (int i = 1; i <= 4; i++) if (num[i] >= 0 && num[i] < ans) ans = num[i]; return; } long long ans1, ans2; for (int i = 1; i <= 4; i++)...
8
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int siz = 1e6 + 5; int n, m, a[siz], f[10][siz]; int go(int x) { if (x < 10) return x; int ret = 1; while (x) { if (x % 10) ret *= (x % 10); x /= 10; } return go(ret); } int main() { ios_base::sync_with_stdio(0); cin.tie(...
5
#include <bits/stdc++.h> using namespace std; template <typename T> void print(vector<T> v) { for (T &i : v) cout << i << " "; cout << "\n"; } template <typename T> void read(vector<T> &v) { for (T &i : v) cin >> i; } void solve() { int n; cin >> n; vector<int> v(n); read(v); string res = ""; int l = ...
5
#include <bits/stdc++.h> using namespace std; int simge[100], n; char ch1, ch2; struct node { char num; char harf; } tmp, dizi[55]; bool control(int a, int b) { return ((dizi[a].harf == dizi[b].harf) || (dizi[a].num == dizi[b].num)); } int dn[55][55][55][55]; int rec(int k, int x, int y, int z) { int &res = dn[...
11
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:167772160000") template <typename T> using min_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>; template <typename T> using max_heap = std::priority_queue<T, std::vector<T>, std::less<T>>; using namespace std; int main() { ios_base::sync_with_std...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:60000000") using namespace std; const long double eps = 1e-9; const int inf = (1 << 30) - 1; const long long inf64 = ((long long)1 << 62) - 1; const long double pi = 3.1415926535897932384626433832795; template <class T> T sqr(T x) { return x * x; } int t[4][105...
8
#include <bits/stdc++.h> using namespace std; bool ch(string& s, string& a, string& b, vector<vector<long long> >& prec) { long long dp[(long long)a.length() + 5][(long long)b.length() + 5]; for (long long i = 0; i <= a.length(); i++) { for (long long j = 0; j <= b.length(); j++) { dp[i][j] = INT_MAX; ...
14
#include <bits/stdc++.h> using namespace std; long long pows(long long n, long long m) { long long ans = 1; for (int i = 1; i <= m; i++) { ans = ans * n; } return ans; } int main() { long long i, ans = 0, p; string s; cin >> s; long long l = s.size(); for (i = l - 1; i >= 0; i--) { if ((s[i] -...
5
#include <bits/stdc++.h> using namespace std; int main() { int y, b, r; cin >> y >> b >> r; b = min(b, y + 1); r = min(r, b + 1); cout << r + r + r - 3; return 0; }
0
//orz Gold_7 //orz SqwrIwy //orz yzh1505 //orz yzh2019 //orz new //orz hejinfan //orz chenkuowen //#pragma comment(linker,?STACK:1677721600? //#pragma GCC optimize("O2") //#pragma G++ optimize("O2") //#pragma GCC optimize("O3") //#pragma G++ optimize("O3") #include<bits/stdc++.h> using namespace std; typedef long long ...
17
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; bool az = true, bz = true; if (a.size() == b.size()) { for (int i = 0; i < a.size(); i++) { if (a[i] == '1') az = false; if (b[i] == '1') bz = false; } if (az && bz) cout << "YES" << endl; el...
7
#include<bits/stdc++.h> using namespace std; #define N 1000010 const int mod=1e9+7; typedef long long ll; inline ll read(){ ll x=0,f=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')f=-1; c=getchar(); } while(c>='0'&&c<='9'){ x=(x<<1)+(x<<3)+c-'0'; c=getchar(); } return x*f; } int T,n,k,fac[N],ifac[N]...
18
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; int main() { int n, m; scanf("%d%d", &n, &m); int l, r, k = INF; for (int i = 0; i < m; i++) { scanf("%d%d", &l, &r); k = min(k, r - l + 1); } printf("%d\n", k); for (int i = 0; i < n; i++) printf("%d ", i % k); puts(""); ...
9
#include <bits/stdc++.h> namespace IO { char gc() { return getchar(); } template <typename Tp> bool get1(Tp &x) { bool neg = 0; char c = gc(); while (c != EOF && (c < '0' || c > '9') && c != '-') c = gc(); if (c == '-') c = gc(), neg = 1; if (c == EOF) return false; x = 0; for (; c >= '0' && c <= '9'; c =...
19
#include <bits/stdc++.h> int n, m; int G[101][101]; int p[2002]; int v[101]; int need[101]; void dfs(int x) { for (int y = 1; y <= n; y++) { if (G[x][y] && !v[y]) { v[y] = 1; dfs(y); } } } int main(int argc, char const *argv[]) { std::cin >> n >> m; int i; for (i = 0; i <= m; i++) { st...
15
#include <bits/stdc++.h> using namespace std; #define FAST1 ios_base::sync_with_stdio(false) #define FAST2 cin.tie(NULL) #define ll long long int #define vctl vector<long long int> #define vlrl valarray<long long int> #define f(i, init, n) for (ll i = init; i < n; i++) #define rf(i, n, end) for (ll i = n; i > end; i--)...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m, s, t, f, m1; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d%d%d", &s, &f, &t); m1 = 2 * (m - 1); if (s == f) printf("%d\n", t); else if (f > s) { if (t % m1 < s) { printf("%d\n", f + t / m1 * ...
5
#include <bits/stdc++.h> using namespace std; vector<long long> vec; long long a[300001], p, ans = 0; set<pair<long long, long long> > s; int main() { long long n, m; scanf("%lld %lld", &n, &m); long long i, j, ans = 0; for (i = 1; i <= n; i++) scanf("%lld", &a[i]); p = a[n]; for (i = 0; i < m; i++) { l...
10
#include <bits/stdc++.h> using namespace std; int main() { int a[200001]; int c[200001]; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; c[i] = a[i]; } sort(c, c + n); string s; cin >> s; int beg = 0; for (int i = 1; i <= n; i++) { if (i == n || s[i - 1] == '0') { sor...
6
#include <bits/stdc++.h> using namespace std; int positions[103]; int N; int starter, ender; int main(int argc, const char* argv[]) { cin >> N; for (int i = 1; i < N + 1; i++) { cin >> positions[i]; } positions[N + 1] = 1 << 30; positions[N + 2] = (1 << 30) + 1; bool changed = true; for (int i = 1; i ...
3
#include <bits/stdc++.h> using namespace std; string ch[10] = {"", "", "2", "3", "223", "5", "53", "7", "7222", "7332"}; int main() { int(n); scanf("%d", &n); string str, an; cin >> str; for (int i = 0; i < (((int)(str).size())); ++i) an += ch[str[i] - '0']; sort((an).begin(), (an).end()); reverse((an).be...
6
#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...
14
#include <bits/stdc++.h> using namespace std; template <class T> T ABS(T x) { return x < 0 ? -x : x; } long long read() { long long s = 0, w = 1; char ch; while ((ch = getchar()) < '0' || ch > '9') if (ch == '-') w = -1; while (ch >= '0' && ch <= '9') s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar(...
12
#include <bits/stdc++.h> using namespace std; using namespace std; vector<int> arr[100][100]; long long int dp[101][101][11] = {0}; int main() { int n, q, i, c, x, y; int s, k, z, j, x1; long long int ans = 0; int x2, y1, y2, t; scanf("%d%d%d", &n, &q, &c); for (i = 0; i < n; i++) { scanf("%d%d%d", &x, ...
8
#include <bits/stdc++.h> using namespace std; int n, x, y, ans = 999999999; map<int, int> a, b; int main() { scanf("%d", &n); int nd = (n + 1) / 2; for (int i = 0; i < n; i++) { scanf("%d%d", &x, &y); a[x]++, b[x]++; if (x != y) a[y]++; } for (map<int, int>::iterator it = a.begin(); it != a.end();...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5, maxk = 5555; long long a[maxn], f[maxk][maxk]; int l1, l2, n1, n2, n, k; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%I64d", &a[i]); sort(a, a + n); f[0][0] = 0; l1 = (n - 1) / k + 1; l2 = l1 - 1; n1 = n - (l1 -...
12
#include <bits/stdc++.h> int inp() { char c = getchar(); while (c < '0' || c > '9') c = getchar(); int sum = 0; while (c >= '0' && c <= '9') { sum = sum * 10 + c - '0'; c = getchar(); } return sum; } char s[400010]; bool used[30]; long long fpow[400010], hsh1[400010], hsh2[400010]; void gethash(int ...
20
#include <bits/stdc++.h> using namespace std; int a[100005]; int main() { int n, ans = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); int cur = a[1], cnt1 = 0, cnt2 = 0; if (cur == 1) cnt1 = 1; else cnt2 = 1; for (int i = 2; i <= n; i++) if (a[i] != cur) { ans = max...
1
#include <bits/stdc++.h> using namespace std; int X, Y; string board[1510]; queue<int> q; pair<int, int> used[1510][1510]; int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; int main(void) { int i, j; cin >> X >> Y; for ((i) = 0; (i) < (int)(X); (i)++) cin >> board[i]; for ((i) = 0; (i) < (int)(X); (i)++) for ...
12
#include <bits/stdc++.h> using namespace std; void solve() { long long int t = 1; cin >> t; while (t--) { long long int n, i; cin >> n; string s, s1; s.push_back('x'); cin >> s1; s += s1; long long int flg = 0; for (i = 1; i < n + 1; i++) { if (s[i] == '0') { if (i <=...
7
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long INFL = LLONG_MAX; const long double pi = acos(-1); int N; int ord[10]; int L[10010]; int R[10010]; long double f[8][10010]; long double tot = 0; long double solve() { memset(f, 0, sizeof(f)); ; for (int i = 0; i <= 10010 - 10; ...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (n - 4) / 2 << endl; return 0; }
7
#include <bits/stdc++.h> using namespace std; int dp[83][83][83][83]; vector<pair<int, int> > adj[103]; int n, k, m; const int inf = 1e9; int f(int nw, int baki, int l, int r) { if (baki == 0) return 0; if (dp[nw][baki][l][r] != (-1)) return dp[nw][baki][l][r]; int ret = inf; for (pair<int, int> x : adj[nw]) { ...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; int n, k, q, c; long long res; string s; vector<int> v[maxn]; int par[maxn], dis[maxn]; long long val[maxn][2]; int find(int x) { if (x == par[x]) return x; int pp = par[x]; par[x] = find(par[x]); dis[x] += dis[pp]; return par[x]; } long ...
16
#include <bits/stdc++.h> using namespace std; bool debug = false; int n, m, k; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; long long ln, lk, lm; class MinCostFlow { public: int V, E; int cap[100000]; int cost[100000], dist[1000], pot[1000]; int to[100000], prev[100000], last[1000], path[1000]; bool use...
14
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; long long POW(long long a, long long b, long long MMM = MOD) { long long ret = 1; for (; b; b >>= 1, a = (a * a) % MMM) if (b & 1) ret = (ret * a) % MMM; return ret; } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) :...
16
#include <bits/stdc++.h> using namespace std; int dist[205][205]; int edges[205 * 205][3]; int N, M; int ans; pair<int, int> events[205]; void test(int ind) { int u = edges[ind][0]; int v = edges[ind][1]; int c = edges[ind][2]; for (int i = 1; i <= N; i++) { events[i].first = dist[u][i]; events[i].secon...
16
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void chkmax(T& x, U y) { if (x < y) x = y; } template <typename T, typename U> inline void chkmin(T& x, U y) { if (y < x) x = y; } int n; long long m; const int MAXN = 111111; long long a[MAXN], x[MAXN]; int xn; int b[MAXN]; int ...
14
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long gcd(long long x, long long y) { while (y) x %= y, swap(x, y); return x; } pair<long long, long long> operator+(pair<long long, long long> a, pair<long long, long long> b) { return pair<long long, ...
8
#include <bits/stdc++.h> using namespace std; ifstream in("f.in"); ofstream out("f.out"); pair<int, int> x[4000]; int v[4002], l[4002][4002]; int main() { int n, val, maxx = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i].first; x[i].second = i; } sort(x + 1, x + n + 1); v[x[1].second] = val...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> vec = vector<int>(n, 0); for (int i = 0; i < n; ++i) cin >> vec[i]; int last_dif = 0; for (int i = 1; i < n; ++i) { if (vec[i] != vec[i - 1]) last_dif = i; } if (last_dif > k - 1) cout << -1; else ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m, v[110], s = 0; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &v[i]); sort(v, v + n); for (int i = 0; i < n; i++) { if (v[i] < 0 && m > 0) { s += -v[i]; m--; } else break; } printf("%d\n", s); ...
1
#include <bits/stdc++.h> using namespace std; int main() { string s = ""; cin >> s; bool b = false, f = false, m = false, l = false; int c = s.find('@'); for (int i = 0; i < c; i++) { if (isalpha(s[i]) || isalnum(s[i]) || s[i] == '_') { b = true; } else { b = false; break; } } ...
11
#include <bits/stdc++.h> using namespace std; int n, a[500005], c[500005]; long long sum, ans = -1e18; bool cmp(const int x, const int y) { return a[x] < a[y]; } int main() { scanf("%d", &n); int ct0 = 0, ct1 = 0, fl0 = 0, fl1 = 0; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); c[i] = i; sum += a[...
19
#include <bits/stdc++.h> using namespace std; const int MAXN = 2010; int used[MAXN]; vector<int> E[MAXN]; int bfs(int src) { queue<pair<int, int> > Q; vector<bool> visited(2010); Q.push(make_pair(src, 0)); visited[src] = true; while (!Q.empty()) { pair<int, int> u = Q.front(); Q.pop(); if (u.first...
15
#include <bits/stdc++.h> using namespace std; int main() { double n, x, y, p, q, r; int a; cin >> n >> x >> y; p = y / 100; q = n * p; r = q - x; a = r; if (r > a) { cout << a + 1; } else if (a < 0) { cout << "0"; } else { cout << a; } }
1
#include <bits/stdc++.h> using namespace std; set<pair<long long int, int> > prime; vector<long long int> Data; map<int, int> dp; long long int dfs(long long int x) { if (dp.count(x)) return dp[x]; unordered_set<int> s; for (int i = 1; i <= 30; ++i) { int y = (x >> i) | (x & ((1 << (i - 1)) - 1)); if (y !...
14
#include <bits/stdc++.h> using namespace std; int a[10009]; int n, r; int find(int minn, int maxn) { int yuan = -1; int ss = min(maxn, n); for (int i = minn; i < ss; i++) { if (a[i] == 1) { yuan = i; } } return yuan; } int main() { scanf("%d %d", &n, &r); for (int i = 0; i < n; i++) { sc...
7
#include <bits/stdc++.h> using namespace std; int n, m, v[100001], x, y, DIM, dp[320][100001]; int main() { cin >> n; DIM = sqrt(n) + 1; for (int i = 1; i <= n; i++) cin >> v[i]; for (int i = 1; i <= DIM; i++) { for (int j = n; j >= 1; j--) { dp[i][j] = dp[i][j + v[j] + i] + 1; } } cin >> m; ...
12
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; const int INF = 0x3f3f3f3f; const double EPS = 1e-7; const double PI = acos(-1); const long long MOD = 1e9 + 7; vector<int> G[N]; int op[N]; int cnt; int dfs(int pos) { int sz = G[pos].size(); if (sz == 0) { cnt++; return 1; } int ret;...
11
#include <bits/stdc++.h> using namespace std; const int N = int(3e5), mod = int(1e9) + 7; int n; int d[N], p[N]; int cnt[N]; int main() { scanf("%d", &n); cnt[0] = 1; for (int i = 2; i <= n; i++) { scanf("%d", &p[i]); d[i] = d[p[i]] + 1; cnt[d[i]]++; } int ans = 0; for (int i = 0; i <= n; i++) {...
7
#include <bits/stdc++.h> using namespace std; int n, t; char str[500050]; bool judge(int init) { int lv = init; int end_pos = 0; for (int i = 0; i < n; i++) { if (str[i] == 'H') { end_pos = i; lv--; } else if (str[i] == 'S') { lv++; if (!lv) end_pos = i; } } if (lv < 0) ret...
15
#include <bits/stdc++.h> using namespace std; vector<int> graph[3005]; int dist[3005][3005]; int n; priority_queue<pair<int, int>> max1[3005], max2[3005]; vector<pair<int, int>> max11[3005], max12[3005]; bool visit[3005]; void bfs(int t) { memset(visit + 1, 0, n); queue<int> que; visit[t] = true; dist[t][t] = 0...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int maxm = maxn * 4 + 10; const int inf = 1e9; const long long mod = 1e9 + 7; int getint() { char c; while ((c = getchar()) && !(c >= '0' && c <= '9') && c != '-') ; int ret = c - '0', sgn = 0; if (c == '-') sgn = 1, ret = 0; w...
15
#include <bits/stdc++.h> using namespace std; char s1[110], s2[110]; int cnt[130], nxt[130]; int main() { int n, m; cin >> n >> m >> s1 >> s2; for (int i = 0; s2[i]; ++i) { int k = i; for (int j = 0; s1[j]; ++j) if (s2[k] == s1[j]) { ++k; if (!s2[k]) { cnt[i]++; k...
12
#include <bits/stdc++.h> int n, s, i, x, y, r, v; int main() { scanf("%d%d", &n, &s); for (i = 2 * n - 2; i >= 0; i -= 2) { r = 4 * v | (s >> i) & 3; x = (x << 1) | (0x936C >> r) & 1; y = (y << 1) | (0x39C6 >> r) & 1; v = (0x3E6B94C1 >> 2 * r) & 3; } printf("%d %d\n", x, y); return 0; }
7
#include <bits/stdc++.h> using namespace std; int n, k; long long A[100005], D[100005]; long long sumA[100005], minD[100005]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%lld", &A[i]); sumA[i] = sumA[i - 1] + A[i]; } minD[0] = 0x3f3f3f3f; for (int i = 1; i <= n; i++) { ...
14
#include <bits/stdc++.h> using namespace std; const long long MAXN = 200500; const long long INF = 0x3f3f3f3f; const long long LINF = 0x1f3f3f3f3f3f3f3f; const long long MOD = 998244353; const long long OVER_FLOW = 0xffffffff; long long n; long long lb[MAXN], rb[MAXN]; vector<long long> v[MAXN], buf; long long dp[MAXN]...
13
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; int n, q; string cmd; int node[N << 2]; bool lazy[N << 2]; int curr_state[N << 1]; vector<int> num, tree[N]; int st[N], ft[N]; void dfs(int v) { num.push_back(v); st[v] = num.size() - 1; for (int i = 0; i < (int)tree[v].size(); i++) { dfs(tr...
12
#include <bits/stdc++.h> #pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-but-set-variable" using namespace std; long long A[500006]; long long B[500006]; long long C[500006]; vector<long long> V; vector<long long> Ans; vecto...
8
#include <bits/stdc++.h> using namespace std; int main() { int val[128]; for (int i = (0); i < (128); i++) val[i] = 2; string vow = "aeiouAEIOU"; for (int i = (0); i < (int((vow).size())); i++) val[vow[i]] = -1; vector<int> price; price.push_back(0); map<int, int> maxprice; maxprice[0] = 0; cin >> vow...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; vector<int> v; for (int i = 0; i < n; i++) { if (s[i] == '0' || s[i] == '1') continue; if (s[i] == '4') { v.push_back(2); v.push_back(2); v.push_back(3); continue; } if (s[i] == '...
6
#include <bits/stdc++.h> using namespace std; template <typename X> inline void pl(X ab) { cout << ab << endl; } template <typename X> inline void ps(X ab) { cout << ab << " "; } int main() { long long int n, t = 0, x, y, i, j; cin >> n; if (n % 2 == 0) pl(n / 2); else pl(n / 2 + 1); return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { int sum = 0, ar[1000]; for (int i = 0; i < 5; i++) cin >> ar[i]; for (int i = 0; i < 5; i++) sum += ar[i]; if (sum == 0) cout << "-1" << endl; else { if (sum % 5 == 0) cout << sum / 5 << endl; else cout << "-1" << endl; } r...
3
#include <bits/stdc++.h> using namespace std; int n; long long val[100100]; vector<int> adj[100100]; long long bst[100100]; long long dp[100100]; long long dp2[100100]; void merge(long long a, long long b, long long c, long long d, long long &_1, long long &_2) { _1 = a; _2 = b; _2 = max(_2, c); if (...
18
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; const long long infLL = 9000000000000000000; template <typename first, typename second> ostream& operator<<(ostream& os, const pair<first, second>& p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream& op...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; struct node { int sluong; char ch; int index; }; struct NodeZ { int sluong; char ch; int Count; }; struct NodeX { int sluong; int Count; }; int n; string s[maxn]; node a[maxn]; node b[maxn]; NodeZ az[maxn]; NodeX ax[maxn]; int i...
9
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; inline long long read() { long long x = 0, w = 0; char ch = getchar(); while (!isdigit(ch)) w |= ch == '-', ch = getchar(); while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = getchar(); return w ? -x : x; } char s[506003...
14
#include <bits/stdc++.h> using namespace std; int a[100010]; int main() { int n, u; cin >> n >> u; for (int i = 1; i <= n; i++) cin >> a[i]; double ans = -100000; for (int i = 1; i <= n - 2; i++) { int j = i + 1; int l = i + 2, r = n; int key; if (a[l] - a[i] > u) continue; while (l <= r) ...
8
#include <bits/stdc++.h> using namespace std; int main() { long i, j, a[100001], n, x, mn, mx, v, y; cin >> n; i = 0; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { x = a[i]; if (i == 0) mn = abs(x - a[i + 1]); else if (i == n - 1) mn = abs(x - a[i - 1]); else ...
1
#include <bits/stdc++.h> using namespace std; int n, q, fa[250000], order, x, y, park[250000]; int fond(int x) { return x == fa[x] ? x : fa[x] = fond(fa[x]); } int main() { ios::sync_with_stdio(false); scanf("%d%d", &n, &q); for (int i = 1; i <= n; i++) { fa[i] = i; park[i] = i + 1; } while (q--) { ...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 2000000 + 10; bool vis[maxn]; int pcnt, prime[150000]; void preprocess() { for (long long i = 2; i < maxn; i++) { if (!vis[i]) prime[pcnt++] = i; for (int j = 0; j < pcnt; j++) { if (i * prime[j] >= maxn) break; vis[i * prime[j]] = tru...
13
#include "bits/stdc++.h" #include <chrono> #include <random> #define lli long long int using namespace std; #define mod 1000000007 #define mod1 998244353 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define INF 1000000000 #define common cout << "Case #" << w+1 << ": " #define maxn 20...
11
#include <bits/stdc++.h> using namespace std; bool ls(const string& a, const string& b) { if (a.length() == b.length()) return a < b; return a.length() < b.length(); } struct Expression { int p, t; string e; Expression(string _e, int t_, int _p) : e(_e), t(t_), p(_p) {} bool operator<(const Expression& ex) ...
16
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int k, a, b; cin >> k >> a >> b; string str; cin >> str; int n = str.length(); if (n >= k * a && n <= k * b) { int i = 0; while (k > 0) { int temp = n / k; co...
6
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } inline void def() {} template <typename T, typename T1> T amax(T &a, T1 b) { if ...
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d = 0; cin >> a >> b >> c; if (a >= b + c) { d = a - (b + c); d++; } else if (b >= a + c) { d = b - (a + c); d++; } else if (c >= a + b) { d = c - (a + b); d++; } cout << d; return 0; }
0
#include <bits/stdc++.h> using namespace std; template <typename T> bool vmin(T& a, T b) { return (a > b) ? (a = b, true) : (false); } template <typename T> bool vmax(T& a, T b) { return (a < b) ? (a = b, true) : (false); } template <typename T> T smax(T x) { return x; } template <typename T, typename... K> T sma...
16
#include <bits/stdc++.h> using namespace std; long long Mod = 998244353; int poww(int a, int b, int mod) { int res = 1; if (b < 0) b = (b % (mod - 1) + mod - 1) % (mod - 1); for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) res = 1ll * res * a % mod; return res; } void Max(long long& x, long long y) { x ...
12
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265358979323846; #pragma GCC optimize("-O2") const int LM = 2e5; int n, ans; long long a[LM + 2], p[LM + 2], sz[LM + 2], w[LM + 2], l[LM + 2], r[LM + 2], num[LM + 2]; struct interval { int w, left, right, rep; interval(int wgt, int lft, int ...
12
#include <bits/stdc++.h> using namespace std; int n, a[100010], ans[100010]; vector<int> tmp[100010]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), tmp[a[i]].push_back(i); int cnt = 0; for (int i = 0; i < n; ++i) if (tmp[i].size()) { int num = tmp[i].size(), need = n -...
7
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); if (n == 0) { printf("1"); return 0; } switch (n % 4) { case 0: printf("6"); break; case 1: printf("8"); break; case 2: printf("4"); break; case 3: printf("2"); break; } }
2
#include <bits/stdc++.h> using namespace std; map<string, int> mp; int main() { int n; cin >> n; string s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; } for (int i = n - 1; i >= 0; i--) { if (!mp[s[i]]) { cout << s[i] << endl; mp[s[i]] = 1; } } }
4
#include <bits/stdc++.h> using namespace std; int main() { int a, b, x, y, mi; cin >> a >> b; mi = min(a, b); a -= mi; b -= mi; cout << mi << " "; if (a) cout << a / 2; else cout << b / 2; return 0; }
0
#include <bits/stdc++.h> using namespace std; long long f[124]; long long a[124]; int main() { f[0] = f[1] = 1; for (int i = 2; i < 110; i++) f[i] = (f[i - 1] + f[i - 2]) % 1000000000; int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i + 1]; for (int i = 0; i < m; i++) { int type; cin >...
7
#include <bits/stdc++.h> using namespace std; template <typename T> void remin(T& a, const T& b) { if (b < a) a = b; } template <typename T> void remax(T& a, const T& b) { if (b > a) a = b; } int occ[2], occ_t[2]; char S[500005], T[500005]; int kmp[500005]; int main(int argc, const char** argv) { int SS, ST, K; ...
8
#include <bits/stdc++.h> using namespace std; int main() { string s, t; getline(cin, s); getline(cin, t); if (s.length() != t.length()) { cout << "NO" << endl; return 0; } else { for (int i = 0; i < s.length(); i++) { if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || ...
2
#include <bits/stdc++.h> using namespace std; const int N = 505; int f[N], g[N], fac[N], n, mo; int F[N][N], G[N][N]; void init() { n = 400; g[1] = 1; f[1] = 0; fac[0] = 1; for (int i = (int)(1); i <= (int)(n); i++) fac[i] = 1ll * fac[i - 1] * i % mo; F[0][0] = F[1][1] = 1; G[0][0] = G[1][1] = 1; for (i...
18
#include <bits/stdc++.h> using namespace std; int i, j, n, m, T; char s[200], t[200][200], c, _c; bool u[200], big[200]; int main() { scanf("%d", &T); for (i = 0; i < T; i++) scanf("%s", &t[i]); scanf("%s", &s); n = strlen(s); for (i = 0; i < n; i++) if (s[i] >= 'A' && s[i] <= 'Z') { big[i] = 1; ...
8
#include <bits/stdc++.h> using namespace std; int dirx[] = {1, -1, 0, 0}, diry[] = {0, 0, 1, -1}; long long bigmod(long long x, long long p) { long long res = 1; while (p) { if (p & 1) res = (res * x) % 998244353; x = (x * x) % 998244353; p >>= 1; } return res; } int32_t main() { ios_base::sync_wi...
11
#include <bits/stdc++.h> using namespace std; const double EPS = 1E-9; const int INF = 1000000000; const long long INF64 = (long long)1E18; const double PI = 3.1415926535897932384626433832795; typedef struct { int a; double p; } tpo; int main() { long long i, j, n, x; int a[2000]; int o[2000]; memset(&o, 0,...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { string s; cin >> s; int cnt = 0, cnt1 = 0, cnt0 = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == '1') cnt1++; else cnt0+...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, l, w; cin >> n >> l >> w; vector<long long> a; vector<long long> b; int t1, t2; double th; long long t; for (int i = 0; i < n; i++) { cin >> t1 >> t2; t = t1; if (t2 =...
17
#include <bits/stdc++.h> using namespace std; int main() { int a, b, fashiondays, normaldays; cin >> a >> b; if (a < b) { fashiondays = a; normaldays = (b - a); } else { fashiondays = b; normaldays = (a - b); } if (normaldays == 1) { cout << fashiondays << " " << 0; } else if (normalda...
0
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const long long longinf = 1LL << 60; const long long mod = 1e9 + 7; const long long mod2 = 998244353; const long double eps = 1e-10; template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, ty...
14
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; string s, t; cin >> s; t = s; vector<long long int> ans; for (__typeof(n - 1) i = (0) - ((0) > (n - 1)); i != (n - 1) - ((0) > (n - 1)); i += 1 - 2 * ((0) > (n - 1))) { if (t[i] != 'B') { t[i] = 'B'; ...
5
#include <bits/stdc++.h> using namespace std; long long a, b, c, x, y, p, q; int main() { cin >> x >> y >> p >> q; int ans = 0; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b >> c; if ((a * x + b * y + c > 0) ^ (a * p + b * q + c > 0)) ans++; } cout << ans << endl; return 0; }
9