solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 10; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; long long qp(long long base, long long n) { long long res = 1; while (n) { if (n & 1) res = (res * base) % mod; base = (base * base) % mod; n >>= 1; } return res; } int n, q;...
5
#include <bits/stdc++.h> using namespace std; long long int powmod(long long int a, int b, int n) { long long int rm = 1; while (b) { if (b % 2) { rm = (rm * a) % n; } a = (a * a) % n; b /= 2; } return rm; } int a[int(1e5 + 10)], t = 0, k; long long int fun(int v1, int v2, int p1, int p2, ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int ans = 0; vector<char> fans; for (int i = 0; i < s.length() - 1; i++) { if (s[i] == s[i + 1]) { fans.push_back(s[i]); ans++; i++; if (i + 1 <= s.length() - 1) { if (s[i - ...
4
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int N = 100005; const double PI = 4 * atan(1); set<char> vowel = {'A', 'O', 'Y', 'E', 'U', 'I', 'a', 'o', 'y', 'e', 'u', 'i'}; int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}; int dy[] = {0, 0, 1, -1, 1, 1, -1, -1}; long long gcd(long long a, long l...
1
#include<bits/stdc++.h> using namespace std; int main() { int n; while(cin>>n&&n!=-1){ int sum=3130,num[3]={125,140,160}; for(int i=0;i<3;i++){ n-=10; if(n>10&&i!=2)sum-=num[i]*10; else if(n>0)sum-=num[i]*n; } cout<<sum<<endl; } }
0
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); const int mn = 1e5 + 10; const long long inf = 0x3f3f3f3f3f3f3f3f; int bit[mn]; void upd(int a, int b) { for (a++; a < mn; a += a & -a) bit[a] += b; } int qu(int a) { int b = 0; for (a++; a; a -= a &...
5
#include <bits/stdc++.h> using namespace std; void __print(long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' <<...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int n, arr[8000], ans, sum; vector<bool> b(8001); void solve() { cin >> n; for (long long int i = 0; i < n; i++) { cin >> arr[i]; b[i] = 0; } b[n] = 0; for (int i = 0; i < n - 1; i++) { sum = arr[i] + arr[i + 1]; if (sum <= n) b[...
5
#include <bits/stdc++.h> using namespace std; template <typename T> inline void checkmin(T &a, T b) { if (b < a) { a = b; } } template <typename T> inline void checkmax(T &a, T b) { if (b > a) { a = b; } } const int maxn = (int)1e5 + 10; const long long inf = (long long)1e18; struct Node { long long w...
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int N, k; cin >> N >> k; vector<int> eu(k), ev(k), ew(k), all; for (int i = 0; i < k; ++i) cin >> eu[i] >> ev[i] >> ew[i], --ew[i], all.push_back(eu[i]), all.push_back(ev[i] + N); sort(all.begin(), all.end())...
5
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, n, m, ans = 0; cin >> n >> m; vector<long long> a(n + 1); vector<long long> c(n + 1); priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> q; for (...
2
#include <bits/stdc++.h> using namespace std; const long long INF = (1LL) << 53; long long a[200010], dp[200010][2]; int n; long long dfs(int x, int flag) { if (x <= 0 || x > n) return 0; if (dp[x][flag] != -INF) return dp[x][flag]; dp[x][flag] = INF; int next = flag ? x - a[x] : x + a[x]; return dp[x][flag] ...
2
#include <iostream> #include <string> #include <algorithm> #include <functional> #include <vector> #include <utility> #include <cstring> #include <iomanip> #include <numeric> #include <cmath> #include <queue> #include <map> using namespace std; typedef long long ll; const int INF = 1<<30; const int MOD = 1e9 + 7; bool...
0
#include <bits/stdc++.h> using namespace std; long long a[3]; int main() { ios::sync_with_stdio(0); cin >> a[0] >> a[1] >> a[2]; long long k = min(a[0], min(a[1], a[2])); a[0] -= k; a[1] -= k; a[2] -= k; if (!a[0] && !a[1] && !a[2]) { cout << "0\n"; return 0; } if (a[0] && !a[1] && !a[2]) { ...
3
#include <bits/stdc++.h> using namespace std; double DP[2005][2005]; int main() { int i, j, k, l, m, n, t; double ans, p; scanf("%d %lf %d", &n, &p, &t); DP[1][1] = p; DP[1][0] = 1 - p; for (i = 2; i <= t; i++) { DP[i][0] = DP[i - 1][0] * (1 - p); for (j = 1; j <= i && j <= n; j++) { if (j < n...
4
#include <stdio.h> int main(){ char a[8]; scanf("%s", a); (a[2] == a[3] && a[4] == a[5])? puts("Yes") : puts("No"); return 0; }
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 100005; ll n, l, t, a[N], b[N], c[3]; vector<ll> ans; int main() { scanf("%lld%lld%lld",&n,&l,&t); for(ll i=0;i<n;i++) { scanf("%lld%lld",&a[i],&b[i]); if(b[i] == 1) { if(l - a[i] <= t % l) c[1]++; ans.push_back((a[i] + t) %...
0
#include <bits/stdc++.h> using namespace std; vector<int> arr[100010]; bool isprime[100010]; bool geh[100010]; set<int> seet; set<int>::iterator it; int bta3men[100010]; void sevie() { isprime[1] = 1; isprime[0] = 1; for (int i = 2; i <= 100000; ++i) { if (!isprime[i]) { arr[i].push_back(i); for (...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5, maxs = 28, maxl = 8e5 + 100; int n; char s[maxl + 5]; int ch[maxl + 1][maxs + 1], d[maxl + 1], name[maxl + 1], ps[maxl + 1], tt = 0; vector<int> N[maxl + 1], P[maxl + 1]; int mat[maxn + 1]; void newn(int &x) { x = ++tt; d[x] = name[x] = ps[x] =...
1
#include<iostream> using namespace std; int main(){ int n,q; cin >> n >> q; string s; cin >> s; int sum[n]; for(int i=0;i<n;i++){ if(i==0) sum[i]=0; else if(s[i-1]=='A' && s[i]=='C') sum[i]=sum[i-1]+1; else sum[i]=sum[i-1]; } for(int i=0;i<q;i++){ int l,r; cin >> l >> r; l--,r--; cout << sum[r]-s...
0
#include <bits/stdc++.h> using namespace std; int main(){ long long a,b,c,s,ss; while(1){ cin >> a >> b >> c; if(a<0 or b<0 or c<0){ return 0; } s=7200-a*3600-b*60-c; ss=(7200-a*3600-b*60-c)*3; cout << 0 << s/3600 << ":"; s%=3600; cout << ((s<600)?"0":"") << s/60 << ":"; s%...
0
#include <bits/stdc++.h> using namespace std; const int V = 2100; int x[V], n, K; int main() { while (~scanf("%d%d", &n, &K)) { int ct = 0; for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) ct++; if (K >= ct) { puts("no solution"); continue; } x[0] = 0; for (int i...
1
#include <bits/stdc++.h> using namespace std; int main() { vector<int> left, right; int n, m, s, l, r; string kata, q; cin >> n >> m >> s; cin >> kata >> q; size_t pos = kata.find(q, 0); while (pos != string::npos) { left.push_back(pos + 1); right.push_back(pos + m); pos = kata.find(q, pos + 1...
2
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } struct SegTree { int n; struct Node { int64_t sum; int64_t add; int l, r; Node operator * (const Node &rhs) const { return {sum + rhs.sum, 0, l, rhs.r}; } }; std::vector<Node> nodes; SegTree (int n_) { for (n = 1; n < n_; n...
0
#include <bits/stdc++.h> using namespace std; vector<pair<long long, char> > s, t, p; vector<int> z; int n, m; long long ans = 0ll; char myget() { char res = '!'; while (!(res >= 'a' && res <= 'z')) res = getc(stdin); return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); scanf("%d%d", &m,...
4
#include <bits/stdc++.h> using namespace std; long long ncr(long long n, long long r) { if (n < r) return 0; else if (n == r) return 1; r = min(r, n - r); long long ans = 1; for (int i = 1; i <= r; i++) { ans *= (long long)(n - i + 1); ans /= i; ans %= 1000000007; } return ans % 100000...
1
#include<bits/stdc++.h> using namespace std; unordered_set<int>a[200003]; bool vis[200003]; int dfs(int k){ vis[k]=true; int sz=1; for(auto c:a[k]){ if(!vis[c]){ vis[c]=true; sz+=dfs(c);} } return sz; } int main(){ int n,m; cin>>n>>m; while(m--){ int x,y; cin>>x>>y; a...
0
#include <bits/stdc++.h> using namespace std; int n, k; pair<long long, long long> a[100007]; int r[100007]; int c[100007]; int used[100007]; long long ans = -1; bool cmp1(int x, int y) { return (a[x].first < a[y].first); } bool cmp2(int x, int y) { return (a[x].second < a[y].second); } void input() { cin >> n >> k; ...
5
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (b) { a %= b; swap(a, b); } return a; } int main() { long long n, m, k; cin >> n >> m >> k; if ((2 * m * n) % k != 0) return cout << "NO", 0; long long a, n1, m1, k1; a = gcd(n, k); n1 = n / a; k1 =...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 1; long long d[maxn << 1], inf; int n, Q, s; vector<int> to[maxn << 1], w[maxn << 1]; void addEdge(int x, int y, int z) { to[x].push_back(y); w[x].push_back(z); return; } struct node { int i; long long dis; }; bool operator<(node a, node b) ...
2
#include <bits/stdc++.h> using namespace std; int n, x, y, z, sub[111111], rt, cnt, a[111111], pos[111111], wh, Rt[111111], sz, tree[11111111], ls[11111111], rs[11111111]; vector<pair<int, int> > g[111111]; int l, r, mid, pp; long long ans; set<int> s[111111]; set<pair<int, int> > ss; set<pair<int, int> >::iterator...
4
#include <bits/stdc++.h> using namespace std; struct info { int pr, af; } arr[2000 + 5]; int main(void) { int n; scanf("%d", &n); bool ch = false; for (int i = 1; i <= n; i++) { scanf("%d %d", &arr[i].pr, &arr[i].af); if (arr[i].pr != arr[i].af) { ch = true; } } if (ch) { printf("rat...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 1; vector<int> p[N]; int main() { for (int i = 2; i < N; ++i) { if (p[i].empty()) { for (int j = i + i; j < N; j += i) { p[j].emplace_back(i); } } } int n; scanf("%d", &n); int ans = 1 << 20; for (int i = n - p[n]....
1
#include <bits/stdc++.h> using namespace std; long long int p4[] = {-1, 1, 0, 0}; long long int q4[] = {0, 0, 1, -1}; long long int p8[] = {-1, 1, 0, 0, -1, 1, -1, 1}; long long int q8[] = {0, 0, 1, -1, 1, 1, -1, -1}; long long int gcd(long long int a, long long int b) { if (b > a) gcd(b, a); return ((b == 0) ? a :...
1
#include <bits/stdc++.h> using namespace std; 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; } int main() { string s; cin >> s; long long f = 0, k = 0; long long n = s.size(); for (int i = 0; i <...
2
#include <bits/stdc++.h> using namespace std; int n, m; set<int> myset; int main() { scanf("%d", &n); m = 2 * n * n; myset.insert(1); set<int>::iterator it; for (int i = 2; myset.size() < n; i++) { it = myset.begin(); while (it != myset.end() && (*it) * i <= m) { myset.insert((*it) * i); i...
3
#include <bits/stdc++.h> using namespace std; int main() { int A,B,C;cin>>A>>B>>C; string ans="NO"; for(int i=1; i<B; i++){ if((i*A)%B==C)ans="YES"; } cout<<ans<<endl; }
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define PLL pair<ll,ll> #define mod 1000000007 #define mx 200005 #define FILE freopen("input.txt","r",stdin) #define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); ll a[mx]; int main() { fastio ll t,n,p,x,id; cin>>t; while(t--...
4
#include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) int main() { int N, C; while(cin >> N >> C && N && C) { int panel[N]; memset(panel, 0, sizeof panel); rep(i, N) rep(j, 16) { int x; cin >> x; if(x) { panel[i] += 1<<j; } ...
0
#include <bits/stdc++.h> using namespace std; int main() { int A; int B; cin>>A; cin>>B; for (int i=1; i<1010; i++){ if ((int)(0.08*i)==A && (int)(0.1*i)==B){ cout<<i; exit(0); } } cout<<-1; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t) { t--; int n; cin >> n; int t[n]; cin >> t[0]; int ost = t[0]; int ile = 1; vector<int> V; for (int i = 1; i < n; i++) { cin ...
3
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long inf = 1e9 + 7; const double eps = 1e-9; struct segtree { int n; pair<int, int> t[2400005], lz[2400005]; const pair<int, int> neutral = {0, -1}; void init(int n) { this->n = n; fill(t + 1, t + 4 * n + 5, neutral)...
4
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int mul(long long a, long long b) { a %= mod; b %= mod; return a * b % mod; } int add(long long a, long long b) { a %= mod; b %= mod; return (a + b) % mod; } int sum(long long k) { return mul(mul(k, add(k, 1)), (mod + 1) / 2); } int m...
5
#include <bits/stdc++.h> using namespace std; void input(vector<int>& a) { for (int i = 0; i < a.size(); i++) cin >> a[i]; } void inputp(vector<pair<int, int> >& a) { for (int i = 0; i < a.size(); i++) cin >> a[i].first >> a[i].second; } void output(vector<int>& a) { for (int i = 0; i < a.size(); i++) cout << a[i...
3
#include <bits/stdc++.h> using namespace std; vector<int> edges[100005]; int hei[100005], par[100005]; int mxd = 0, mxu; void dfs(int u, int p) { int mxv = 0, smxv = 0; hei[u] = 1; for (auto v : edges[u]) { if (v == p) continue; par[v] = u; dfs(v, u); hei[u] = max(hei[u], hei[v] + 1); if (hei[...
4
#include <bits/stdc++.h> using namespace std; const int N = 100005, mod = 1000000007; long long ncr(long long n, long long r) { long long sum = 1; long long f = 2; for (long long i = n - r + 1; i <= n; i++) { sum *= i; if (sum % f == 0 && r >= f) sum /= f++; } if (r >= f) { for (long long i = f; i...
1
#include <bits/stdc++.h> int n, i, x, ind[210], o = 0, e = 0; char a[200001], arr[200010]; int main() { scanf("%s", a); n = strlen(a); if (n == 1) { printf("%s\n", a); return 0; } for (int i = 0; i < n; i++) { ind[a[i]]++; } for (int i = 'a'; i <= 'z'; i++) { if (ind[i] > 0) { ind[i]...
3
#include <bits/stdc++.h> using namespace std; template <long long mod> struct modular { long long value; modular(long long x = 0) { value = x % mod; if (value < 0) value += mod; } modular& operator+=(const modular& other) { if ((value += other.value) >= mod) value -= mod; return *this; } mod...
5
#include <bits/stdc++.h> using namespace std; int main() { int n{0}, m{0}; cin >> n >> m; vector<vector<int> > adj(n, vector<int>()); for (int i = 0; i < m; i++) { int x{0}, y{0}; cin >> x >> y; x--; y--; adj[x].push_back(y); adj[y].push_back(x); } int max_degree{0}, max_vertex{-1}; ...
5
#include <bits/stdc++.h> using namespace std; int read() { int 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 + ch - '0'; ch = getchar(); } return x * f; } const long long INF = 0x3f3f3f...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 4; const int inf = 0x3f3f3f3f; int main() { int n; char s[1010]; while (cin >> n >> s) { bool flag = true; int ans = 0, now = 0; for (int i = 0; i < n; i++) { if (!flag) flag = true; now += (s[i] != '0'); if (flag &...
1
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } void transfer(int& now, int add) { if (add < 0) add = add % MOD + MOD; now = (now + add) % MOD; } int main() { int n, m; ios::sync_with_stdio(false); while (ci...
2
#include <bits/stdc++.h> using namespace std; string s; int n, m; int str[3][50005]; int main() { while (cin >> s) { str[0][0] = 0; str[1][0] = 0; str[2][0] = 0; int l = s.length(); for (int i = 0; i < l; i++) { str[0][i + 1] = str[0][i] + (s[i] == 'a'); str[1][i + 1] = max(str[0][i], ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 10; int gi() { int x = 0, o = 1; char ch = getchar(); while (!isdigit(ch) && ch != '-') ch = getchar(); if (ch == '-') o = -1, ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * o; } int n, l, r, a[N], dp[N]...
5
#include <bits/stdc++.h> using namespace std; int n, m, k; const int MAXN = 200005; const long long inf = 1e9; struct segTree { struct Node { long long pre, suf, mx, sum; Node() {} Node(long long pre, long long suf, long long mx, long long sum) { this->pre = pre; this->suf = suf; this->m...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } long long int sum = 0; for (int i = 0; i < n; i++) { sum += a[i]; } long long int s = 0; set<long long int> nums; bool res = false; for (int i = 0;...
4
#include <bits/stdc++.h> using namespace std; const int dx[5] = {1, -1, 0, 0}; const int dy[5] = {0, 0, 1, -1}; int r, c, sx, sy, ex, ey, dis[1010][1010], vis[1010][1010]; char grid[1010][1010]; int ans = 0; queue<pair<int, int> > q; inline bool is_le(int x, int y) { if (vis[x][y] || x >= r || x < 0 || y >= c || y < ...
2
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 5; int n, t; double p, dp[N][N]; signed main() { scanf("%d %lf %d", &n, &p, &t); dp[0][0] = 1; for (int i = 1; i <= t; ++i) { dp[i][0] = dp[i - 1][0] * (1 - p); for (int j = 1; j <= n; ++j) { if (j == n) dp[i][j] = dp[i - 1][j...
4
#include<bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define sz(x) ( (int)(x).size() ) using LL = long long; template<class T> inline bool asMn(T &a, const T &b) { return a > b ? a = b, true : false; } template<class T> inline bool asMx(T &a, const T &b) { return a < b ? a = b, true : f...
0
#include <bits/stdc++.h> using namespace std; int main (){ int x,y,z,n; cin >> x >> y>> z; n=(x-z)/(y+z); cout << n; }
0
#include <bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } using ll = int64_t; using ull = uint64_t; using ld = long double; const int N = 1e5 + 5, INF = 1e9 + 5; int ...
5
#include <bits/stdc++.h> const int mod = 1e9 + 7; using namespace std; vector<string> v; int MI(int n) { string s = to_string(n); int mi = 100; string s2 = s; for (int i = 0; i < (55); i++) { int OP = 0; s = s2; for (int j = 0; j < min(v[i].size(), s.size()); j++) { if (v[i][j] != s[j]) { ...
4
#include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <cstring> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <fstream> #inclu...
0
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979323846; const double EPS = 1e-9; const int INF = 2e9; const long long LINF = 1e18; template <class T> const T sqr(const T &x) { return x * x; } template <class T> const T &min(const T &a, const T &b, const T &c) { return min(min(a, b), ...
1
#include <bits/stdc++.h> int64_t B, D; std::string A, C; int64_t next[25][105]; int main() { std::cin >> B >> D >> A >> C; for (int64_t i = 0; i < C.size(); i++) { int64_t nxt = 0; for (char c : A) { if (c == C[(i + nxt) % C.size()]) { nxt++; } } next[0][i] = nxt; } for (int6...
2
#include <bits/stdc++.h> using namespace std; int main() { long n = 0; cin >> n; long ca = 0, cb = 0; long a[100000] = {0}; long b[100000] = {0}; while (n--) { cin >> a[n] >> b[n]; if (a[n] > 0) { ca++; } else if (a[n] < 0) { cb++; } } if ((cb == 1 || cb == 0) || (ca == 1 || ...
1
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> f; vector<vector<int> > g, q; vector<char> used1, used2; void DFS1(int u) { used1[u] = 1; for (int i = 0; i < g[u].size(); ++i) { int v = g[u][i]; if (!used1[v]) DFS1(v); } } void DFS2(int u) { used2[u] = 1; if (f[u] == 1) return; f...
1
#include <cstdio> int N, a[100001]; long long S, C; int main() { scanf("%d", &N); if (N == 1) { puts("YES"); return 0; } for (int i = 1; i <= N; i++) { scanf("%d", a + i); S += a[i]; } if (S % ((long long)N * (N + 1) / 2)) { puts("NO"); return 0; } S /= (long long)N * (N + 1) / 2; for (int i = 1...
0
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") long long mul(long long a, long long b) { return (a * b) % (1000000007); } long long add(long long a, long long b) { return (a + b) % (1000000007); } long long sub(long long a, long long b) { return ((a - b) % (1000000...
5
#include <iostream> using namespace std; int main() { string s; cin >> s; int len = s.length(); cout << (len % 2 == 0 && s == string("hihihihihi", len) ? "Yes" : "No") << endl; }
0
#include<bits/stdc++.h> #define pb emplace_back #define pf first #define ps second #define all(x) x.begin(),x.end() #define allr(x) x.rbegin(),x.rend() #define endl '\n' #define mod 1000000007 #define INF 1000000001 #define forn(i,n) for(ll i=0;i<n;i++) #define MAX 200001 #define fast ios_base::sync_with_stdio(false);c...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T, class U> using Pa = pair<T, U>; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vec<ll> A(N); for (int i = 0...
3
#include <bits/stdc++.h> using namespace std; #define ll long long #define dbg puts("It's Just Begining.Wait For The End!!!!!\n") #define CHECK(x) cout << (#x) << " is " << (x) <<"\n"; #define endl printf("\n") #define pi acos(-1) typedef pair<ll,ll> pii; #define pb push_back #define ms(a,b) memset(a, b, sizeof(a)) #de...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; template <typename T> void read(T &x) { int p = 1; x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') p = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - 48; c = getchar(); } x ...
1
#include <bits/stdc++.h> using namespace std; int ar[505]; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> ar[i]; } int ans = 0; for (int i = 2; i <= n; i++) { if (ar[i] + ar[i - 1] < k) { int add = k - (ar[i] + ar[i - 1]); ans += add; ar[i] += add; ...
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int prime = 999983; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f; const double pi = acos(-1.0); const double inf = 1e18; const double eps = 1e-8; const long long mod = (long long)1e9 + 7; const unsigne...
4
#include <cstdio> #include <algorithm> using namespace std; int g[300000],h[300000]; int i,n; int main() { scanf("%d",&n); for (i=1;i<=n;i++) scanf("%d",&g[i]); for (i=1;i<=n;i++) h[i]=g[i]; sort(h+1,h+n+1); for (i=1;i<=n;i++) if (g[i]<=h[n/2]) printf("%d\n",h[n/2...
0
#include <bits/stdc++.h> using namespace std; int main(){ int H,R; cin >> H >> R; if (H + R == 0) { cout << 0 << endl; } else if (H + R > 0) { cout << 1 << endl; } else { cout << -1 << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; double ex[2][100005]; double acc[100005]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; ex[1][0] = m - 1; acc[0] = 0; acc[1] = m - 1; for (int j = 2; j <= n * m + 1; ++j) acc[j] = ex[1][j - 1] + acc[j - 1]; int s...
3
#include <bits/stdc++.h> const int maxn = 1e5 + 5; using namespace std; int k, ans; char a[maxn]; int A[maxn]; int powmod(int a, long long b) { int tmp = 1; while (b) { if (b & 1) tmp = (long long)tmp * a % 1000000007; a = (long long)a * a % 1000000007; b >>= 1; } return tmp; } int main() { while ...
3
#include <iostream> #include <string> using namespace std; int main() { int n; cin >> n; string f; getline(cin,f); while(n--) { string s; getline(cin,s); while(1) { int i=s.find("Hoshino"); if(i==-1) break; s=s.substr(0,i)+"Hoshina"+s.substr(i+7); } cout << s << endl; ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int maxm = 1e6 + 10; const int maxc = 26; const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; const long long INF = 0x3f3f3f3f3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-8; inline int read() { int f = 1, x = 0; c...
2
#include<bits/stdc++.h> using namespace std; int A,B,C; int main() { cin>>A>>B>>C; if(B-A==C-B)cout<<"YES\n"; else cout<<"NO\n"; return 0; }
0
#include <bits/stdc++.h> using namespace std; vector<int> st; bool vis[10000]; vector<string> vec; bool cmp(string &a, string &b) { return a.size() < b.size(); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { string x; cin >> x; vec.push_...
2
#include <bits/stdc++.h> long long S, N, K, x, F[2005], W[2005]; int main() { scanf("%I64d%I64d", &N, &K); for (int i = 1; i <= N; i++) for (int j = i + 1; j <= N; j++) { scanf("%I64d", &x); if (x >= 0) { F[i] += x, F[j] += x, W[i]++, W[j]++; } } for (int i = 1; i <= N; i++) S +=...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 610000; char A[maxn]; int main() { scanf("%s", A); int n = strlen(A); vector<pair<int, int> > vec; for (int i = 0; i < n; ++i) { int ch = A[i]; if (vec.empty() || ch != vec.back().first) vec.emplace_back(ch, 1); else vec.back...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k; cin >> n; long d[8] = {0}, c; for (i = 1; i < 8; i++) { d[i] = 1000000; } for (i = 0; i < n; i++) { int s = 0; string st; cin >> c >> st; for (j = 0; j < st.length(); j++) s |= (1 << (st[j] - 'A')); for (j = 0...
2
#include <bits/stdc++.h> using namespace std; const long long int INF = 100000000000000000; const long long int MAXN = 1100; long long int a[MAXN][MAXN]; vector<long long int> col, row; multiset<long long int> cc, rr; multiset<long long int>::iterator itlow; long long int r[MAXN * MAXN], c[MAXN * MAXN]; int main() { ...
2
#include<cstdio> #define min(a,b) (a<b?a:b) long long n,k; int main(){ scanf("%lld%lld",&n,&k); printf("%lld",min(n%k,k-n%k)); }
0
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using vpii = vector<pii>; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using vll = vector<long long>; template <class T> istream &operator>>(istream &, vector<T> &); template <class T> ostream &operator<<(ostream &, const...
5
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; template <class T, class U> inline void Max(T &a, U b) { if (a < b) a = b; } template <class T, class U> inline void Min(T &a, U b) { if (a > b) a = b; } inline void add(int &a, int b) { a += b; while (a >= 99824...
5
#include<bits/stdc++.h> using namespace std; int f[1000005][4],inv6,n,g[1000005][4]; const int mod=998244353; const int inv2=(mod+1)/2; int M(int x){return x>=mod?x-mod:x;} int mypow(int a,int b) { int ans=1; while(b) { if(b&1)ans=1ll*ans*a%mod; a=1ll*a*a%mod; b>>=1; } return ans; } int main() { g[0][0]=1; ...
5
#include <bits/stdc++.h> using namespace std; void parr(int arr[], int n, string name) { int i; for (i = 0; i < n; i++) cout << arr[i] << " "; cout << "\n"; } long long int fn(int arr[], int n) { int i; long long int pre[n]; sort(arr, arr + n, greater<int>()); pre[0] = arr[0]; for (i = 1; i < n; i++) pr...
1
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T t) { return t < 0 ? -t : t; } const long long modn = 1000000007; inline long long mod(long long x) { return x % modn; } int n, i, j, p[3000010]; int main() { scanf("%d", &n); for (i = 1; i <= n; i++) p[i] = i; for (i = 2; i <= n;...
4
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e5 + 100; const long long mod = 1e9 + 7; const long long base = 1e15; vector<long long> adj[maxn]; vector<long long> adj1[maxn]; bool dd[maxn]; long long siz[maxn]; long long cntnw = 0; long long dinh; long long anc[maxn][20]; long long dep[maxn]; lo...
5
#include <bits/stdc++.h> using namespace std; int a[105], b[105]; int main() { string str, str1; int n, x[105], y[105], i; char ch[105], ch1[105]; cin >> str >> str1; cin >> n; for (i = 1; i <= n; i++) { cin >> x[i] >> ch[i] >> y[i] >> ch1[i]; } for (i = 1; i <= n; i++) { if (ch[i] == 'h') { ...
1
#include <bits/stdc++.h> using namespace std; int n, s, x, ans = 0x3f3f3f3f; int v[100010], nx[100010]; std::default_random_engine generator(time(NULL)); std::uniform_int_distribution<int> dis(0, 2e9); auto dice = std::bind(dis, generator); void Init() { scanf("%d %d %d", &n, &s, &x); } void Work() { int i, j, l; f...
2
#include <iostream> #include <cmath> using namespace std; void koch(double x0, double y0, double x1, double y1, int n) { if (n == 0) { cout << x0 << " " << y0 << endl; } else { double c1x,c1y,c2x,c2y,c3x,c3y; double dx = x1 - x0; double dy = y1 - y0; //double L = sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) *...
0
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; long long qpow(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % MOD; a = (a * a) % MOD; b >>= 1; } return ans; } long long inverse(long long a) { return qpow(a, MOD - 2) % MOD; } int gcd(...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll N = 2e6; vector<ll> g[N]; vector<ll> e[N]; ll col[N]; vector<ll> comp[N]; ll sum[N]; void dfs(ll v) { comp[col[v]].push_back(v + 1); sum[col[v]] += v + 1; for (ll u : g[v]) { if (col[u] == -1) { col[u] = col[v] ^ 1; dfs(u...
4