solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { int a,b,p,x; cin >> a >> b>> p; a=a-1; a=a/p; b=b/p; x=b-a; cout << x << endl; }
0
#include <bits/stdc++.h> using namespace std; int points[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1}; struct node { int num[51]; }; map<string, node> rk; int race, peo; int main() { int i, j, k; string str; rk.clear(); cin >> race; for (i = 0; i < race; i++) { cin >> peo; for (j = 0; j < peo; j++) { ...
2
#include <bits/stdc++.h> using namespace std; void Fastio() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } long long n, q; string s; const long long mod[] = {1716590723, 2591421449}, base = 5, inv_base[] = {1029954434, 518284290}; long long pw[2][200005]; struct Node { long long Hash...
4
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cout.write(nam...
3
#include <bits/stdc++.h> using namespace std; int n, cnt = 0; long long res = 1e18; bool x; vector<int> pos; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> x; cnt += x; if (x) pos.push_back(i); } for (int i = 2; i <= cnt; i++) { if (cnt ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, a[1000][3], butt = 0, jojo = 0, cow = 0, lero = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i][0]; for (int j = 1; j <= 2; j++) { cin >> a[i][j]; } } for (int i = 0; i < n; i++) { if (a[i][0] == 1) { jojo++; ...
1
#include <bits/stdc++.h> using namespace std; const long long N = 2005; long long flag[N], ne[N], tot, S, T, x, y, f, e, dis[N], cur[N], in[N], out[N], n, m, fi[N], zz[N], sl[N], w[N]; queue<long long> Q; void jb(long long x, long long y, long long z, long long v) { ne[++tot] = fi[x]; fi[x] = tot; zz[tot] = y...
4
#include <bits/stdc++.h> using namespace std; const int N = 1000; int n, m; vector<int> ad[N]; int cnt; int mrk[N]; void dfs(int v) { mrk[v] = cnt; for (auto u : ad[v]) if (!mrk[u]) dfs(u); } int res[N]; void fil(int v, int val) { res[v] = val; if (v <= n) { if (!res[v + n]) fil(v + n, -val); } else {...
5
#include <cstdio> #include <map> #include <string> #include <queue> #include <utility> #include <iostream> using namespace std; typedef pair<int,string> P; int main(){ int d[4] = {-1,1,-4,4}; map<string,int> ans; ans["01234567"] = 0; queue<P> que; que.push(P(0,"01234567")); while(que.si...
0
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e6 + 9; const int INF = 1e9 + 9; int tab[MAX_N]; int P[MAX_N]; vector<int> G[MAX_N]; int lead[MAX_N]; int component[MAX_N]; bitset<MAX_N> been; int compcnt = 1; int root = -1; int sol = 0; int n; void DFS(int v, int comp) { component[v] = comp; for (i...
4
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); solve(); } bool isprime(long long number) { for (int i = 2; i <= sqrt(number); i++) { if (number % i == 0) { return false; } } return true; } void solve() { ...
4
#include<bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define HUGE_NUM 99999999999999999 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; struct LOC{ LOC(int arg_row,int arg_col){ row = arg_row; col = arg_col; } int row,col; }; //0:...
0
#include <bits/stdc++.h> int main() { int n; unsigned long long x = 0, y = 0; std::cin >> n; n *= 2; std::vector<int> a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; } std::sort(a.begin(), a.end()); for (int i = 0; i < n / 2; i++) { x += a[i]; } for (int i = n / 2; i < n; i++) { ...
1
#include <bits/stdc++.h> const int MAXN = 110; const int NINF = 0xcfcfcfcf; char buf[MAXN]; int H, W, dp[2][MAXN][MAXN][MAXN]; int pre[MAXN][MAXN]; void getmax(int & x, int y) { x < y ? x = y : 0; } struct M { int l, r, u, d; M(int a1, int a2, int a3, int a4) { l = a1, r = a2, u = a3, d = a4; } } ; inline int gm(...
0
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; string s, t; cin >> s >> t; deque<char> Q((s).begin(), (s).end()); bool f = 1; vector<long long> ans; for (long long i = n - 1; i >= 0; i--) { if (f) { if (Q.back() == t[i]) { Q.pop_back(); cont...
3
#include <bits/stdc++.h> const int MAXN = 5e5 + 5; struct Edge { int next, to; } e[MAXN << 1]; int head[MAXN], etot = 0; inline void add(int u, int v) { e[++etot] = (Edge){head[u], v}; head[u] = etot; } struct Node { int lst, nxt; } p[MAXN * 2]; inline void putlst(int v, int u) { p[v].lst = p[u].lst; p[p[u]...
5
#include <bits/stdc++.h> int main(void) { int n, m, t, x[200], x2[200], y[90], flag = 0, c1 = 1, c2 = 0, c3 = 0, i = 1, q1 = 0, q2 = 0; scanf("%d%d", &n, &m); if (m == 0) { if (n == 1) printf("0"); else printf("No solution"); } else { printf("%d", m...
1
//int max = 2 147 483 647 (2^31-1) //ll max = 9 223 372 036 854 775 807 (2^63-1) #include<bits/stdc++.h> using namespace std; #define forn(i,n) for(int i=0;i<n;i++) #define mp make_pair #define f first #define s second #define pb push_back #define MOD 1000000007 typedef long long ll; typedef long double ld; typedef v...
5
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ int K,N,mx=0; cin>>K>>N; vector<int> A(N); for(int &i:A)cin>>i; for(int i=0;i<N;i++)mx=max(mx,(A[(i+1)%N]-A[i]+K)%K); cout<<K-mx<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t, l, n; string s, r; cin >> t; int temp, ans; while (t > 0) { temp = 0; ans = 0; cin >> l; cin >> s; for (int i = l - 1; i >= 0; i--) { if (s[i] == 'A') { ans = max(ans, temp); temp = 0; } else { ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, x, y, k, q; cin >> n >> k >> q; vector<long long> vc(200005, 0); while (n--) { cin >> x >> y; vc[x]++; vc[y + 1]--; } for (int i = 1; i < vc.size(); i++) vc[i] += vc[i - 1]; for (int i = 0; i < vc.size(); i++) vc[i] = (vc[...
2
#include <bits/stdc++.h> using namespace std; int w[4]; int x[4]; int l[4]; int t[4]; int ans = 0; int p[4]; int a[4]; bool near(int s) { for (int i = 1; i <= 3; i++) if (s == x[i] + 1 || s == x[i] - 1) return true; return false; } void dfs(int d) { for (int i = 1; i <= 3; i++) ans = max(ans, x[i]); for (in...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 5, inf = 1e9 + 7; int n, k, i; int dp[15][1 << 15][25]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int i, j, first, second, l = 0, f, g, a, b; cin >> n; vector<int> v; for (i = 0; i < n; i++) { cin >> first; if (fir...
5
#include <bits/stdc++.h> using namespace std; int n; int nxt[105]; bool vis[105]; int check(int f) { int now = f; vis[now] = 1; int ans = 1; now = nxt[now]; while (vis[now] == 0) { vis[now] = 1; ans++; now = nxt[now]; } if (now != f) return -1; return ans; } int gcd(int a, int b) { if (b =...
1
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const int prime = 9241; const long double pi = acos(-1.); int in[100005]; int masks[1000005]; bool used[1 << 22]; int main() { int n, m, d; scanf("%d%d%d", &n, &m, &d); for (int i = 0; i < m; i++) { int s; scanf("%d", &s); for (...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, d, h; scanf("%d%d%d", &n, &d, &h); if (d > 2 * h) return 0 * puts("-1"); if (d == h) { if (d == 1 && n != 2) return 0 * puts("-1"); int now = 2; while (d) { printf("%d %d\n", now - 1, now); ++now; --d; } whil...
3
#include<bits/stdc++.h> using namespace std; const int N=2e5+5; int n,m,a[N],c[N],b[N],hs[N],tot,head[N],nex[N<<1],to[N<<1],wi[N<<1]; void add(int u,int v,int w){to[++tot]=v;nex[tot]=head[u];head[u]=tot;wi[tot]=w;} bool vis[N],use[N]; int lowb(int x) { return lower_bound(hs+1,hs+1+n,x)-hs; } int uppb(int x) { r...
0
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long int powm(long long int a, long long int b) { long long int res = 1; while (b) { if (b & 1) res = (res * 1LL * a) % mo...
3
// main.cpp // ervb // // Created by Kanak Gautam on 21/04/20. // Copyright © 2020 Kanak Gautam. All rights reserved. // #include <iostream> #include <cstdio> #include <stdio.h> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <stack> #include <map> #include <un...
6
#include <bits/stdc++.h> using namespace std; int n, ans = -1, a[105], x[105], y[105]; vector<int> adj[105]; bool vis[105]; void DFS(int node) { vis[node] = 1; for (int i = 0; i < adj[node].size(); i++) { if (!vis[adj[node][i]]) { vis[adj[node][i]] = 1; DFS(adj[node][i]); } } return; } int m...
3
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; int n; int sez[3005]; int dp[10000000]; int f(int x) { if (x == 0) return 0; if (x == 1) return 1; if (dp[x] != 0) return dp[x]; return dp[x] = 4 + f(x - 2); } int main() { cin >> n; for (int i = 0; i < (n); i++) cin >> sez[i]; int odg...
4
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cin.sync_with_stdio(0); cout.tie(0); int a[101], b[101], n, m, i, j; bool p[101]; cin >> n >> m; for (int i = 0; i <= n; i++) { p[i] = false; b[i] = 0; } for (int i = 0; i < m; i++) cin >> a[i]; i = 0; while (i < m - 2)...
2
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long tt; cin >> tt; while (tt--) { long long n, m; cin >> n >> m; ...
5
#include <bits/stdc++.h> using namespace std; double dp[2][205][205]; int n, l, k, a[205], b[205]; void solve() {} int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> l >> k; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; for (int i = 0; i < n...
2
#include <bits/stdc++.h> using namespace std; inline long long in() { int32_t x; scanf("%d", &x); return x; } inline long long lin() { long long x; scanf("%lld", &x); return x; } const long long maxn = 1e6 + 10; int32_t main() { long long n = in(); long long cur = 1; vector<long long> vc; while (n >...
1
#include <bits/stdc++.h> using namespace std; const int mm = 1000000007; int lim, i, j, k, n, m, a[610001], u[11000001], c[11000001], w[11000001], ans, q[111][2], num, p[1100001], f[1100001], pw2[610001], tmp; void work(int x, int v) { int i; if (x > num) { c[v]++; return; } for (i = 0; i <= q[x][1]...
5
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } int n, a[10010], sum, l = 1, r, cnt = 0; bool check(int x) { int tem; for (int i = 1; i <= n - x + 1; i++) { tem = a[i]; for (int j = i + 1; j < i + x; j++) { tem = gcd(tem, a[j]); } if (...
3
#include <bits/stdc++.h> using namespace std; template <typename S, typename T> ostream& operator<<(ostream& os, const pair<S, T>& x); template <typename T> ostream& operator<<(ostream& os, const vector<T>& x); template <typename T> ostream& operator<<(ostream& os, const set<T>& v); template <typename T> ostream& opera...
4
#include<bits/stdc++.h> using namespace std; signed main(){ int n; cin>>n; vector<int> a(n); for(auto& ai:a)cin>>ai; int ans = 1; for(int i=0;i<n-1;++i){ if(a[i]>=a[i+1])ans++; } cout<< ans <<endl; cout<< n <<endl; }
0
#include <bits/stdc++.h> using namespace std; const int MX = 2000 + 5; const int MXE = 1e5 + 7; const int inf = 0x3f3f3f3f; int n, m; struct edge { int u, v, nxt; } E[MXE << 1]; int head[MX], tot; vector<int> G[MX]; void init() { memset(head, -1, sizeof(head)); tot = 0; } void add_edge(int u, int v) { E[tot].u ...
6
#include <bits/stdc++.h> using namespace std; int prime[16] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; int n; int a[111]; int f[111][1 << 16], g[111][1 << 16], S[111][1 << 16]; int p[61][1 << 16]; int pd(int x, int s) { int ret = 0; for (int i = 0; i < 16; i++) { while (x % prime[i] == 0) {...
4
#include<bits/stdc++.h> using namespace std; int main(){ int a,b; cin>>a>>b; int flag=0; for(int i=1;i<3000;i++) { if(i*8/100==a&&i/10==b){ cout<<i;flag=1; break; } } if(flag==0)cout<<-1; }
0
#include <bits/stdc++.h> using namespace std; long long n, m, k; float l; string s; int main() { cin >> n >> m >> k; for (int i = 0; i < 2 * m; ++i) { n *= 10; if (n / m == k) { cout << i + 1; return 0; } n %= m; } cout << -1; return 0; }
2
#include <bits/stdc++.h> using namespace std; int n, m; char grid[1500 + 50][1500 + 50]; bool visited[1500 + 50][1500 + 50]; int pathx[1500 + 50][1500 + 50]; int pathy[1500 + 50][1500 + 50]; bool functionate(int x, int y) { int X = (x % n + n) % n; int Y = (y % m + m) % m; if (grid[X][Y] == '#') return false; i...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; int a = s.find("ab"); if (a >= 0) { cout << a + 1 << " " << a + 2 << endl; } else { int a = s.find("ba"); if (a >= 0) { cout << a + 1...
1
#include <bits/stdc++.h> using namespace std; int N; long long M; int main(int argc, char *argv[]) { vector<int> ans; cin >> N >> M; ans.push_back(N); M--; for (int i = 0; i < (N - 1); i++) { if (M % 2) ans.push_back(N - i - 1); else { reverse(ans.begin(), ans.end()); ans.push_back(N...
2
#include <bits/stdc++.h> using namespace std; void solve() { long long N; cin >> N; long long n = (N - 1) / 3; if (n == 0) { cout << N << "\n"; return; } int dig = 1; long long cnt = 1; while (true) { long long add = (1ll << (2 * dig)); if (n < cnt + add) break; dig++; cnt += add...
3
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #pragma GCC target("sse4") using namespace std; const long long int inf = 1e18; const long long int ninf = -1e18; const long long int mod = 998244353; const long long int MOD = 1000000007; templat...
1
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const long long N = 1e5 + 10; const long long mod = 1e9 + 7; const long long INF = 1e18; const long long inf = -1e18; const long long M = 5 * 1e8; long long n, m, k, a[100][100], ans, b[100][100], c[100][100]; char ch1, ch2; int main() { cin >> ...
5
#include <bits/stdc++.h> using namespace std; int main() { int a,b; cin>>a>>b; cout<<max(0,(a-(b*2))); return 0; }
0
#include "bits/stdc++.h" using namespace std; class LazySegmentTree { private: long long Size; vector<long long> Node, Lazy; public: LazySegmentTree(long long N) { Size = 1; while (Size < N) Size <<= 1; Node.assign(Size * 2, 0); Lazy.assign(Size * 2, 0); } void Eval(long long K, long long L, long long R) ...
0
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y, long long int p) { long long int r = 1; x = x % p; while (y) { if (y & 1) r = r * x % p; y = y >> 1; x = x * x % p; } return r; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());...
6
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); long long n; cin >> n; long long a[n + 10]; for (long long i = 0; i < n; i++) cin >> a[i]; long long z = (n / 2) + (n % 2); long long dp[n + 10][z + 5][2]; for (long long i = 0; i < n + 10; i++) for (long...
5
#include <bits/stdc++.h> using namespace std; long long int mulmod(long long int a, long long int b, long long int m) { long long int q = (long long int)(((long double)a * (long double)b) / (long double)m); long long int r = a * b - q * m; if (r > m) r %= m; if (r < 0) r += m; return r; } template <type...
3
#include<iostream> #include<cstring> using namespace std; int a[7]; int n, p; int main() { while (true) { memset(a, 0, sizeof(a)); cin >> n; if (n == 0) { break; } for (int i = 0; i < n; i++) { cin >> p; p /= 10; if (p > 6) { p = 6; } a[p]++; } for (int i = 0; i < 7; i++) { cout << a[i] << e...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, d, k; cin >> n >> d >> k; if (n <= d) { cout << "NO\n"; return 0; } if (k == 1) { if (n > 2) { cout << "NO\n"; return 0; } else { cout << "YES\n1 2\n"; return 0; } } ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e3 + 11; long long read() { long long x = 0, f = 1; register 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(); } ...
2
#include <bits/stdc++.h> using namespace std; const int N = 200010; const int M = 20; const int ALL = (1 << M) - 1; string tostr(int x) { string res = "{"; for (int i = 0; i < M; ++i) { if (x & (1 << i)) { res += to_string(i); res += ","; } } res += "}"; return res; } int n; int label[N]; ...
5
//^ #include<cstring> #include<cstdio> #include<vector> #define min(a,b) (a<b?a:b) #define max(a,b) (a>b?a:b) using std::vector; inline 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<<3)+(x<<1)+ch-'0';ch=getchar();} return x*f...
0
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const int nax = 1e5 + 200; const double mpi = acos(-1); const double eps = 1e-10; int dr[] = {1, -1, 0, 0, 1, -1, -1, 1}; int dc[] = {0, 0, 1, -1, 1, 1, -1, -1}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ...
1
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int solution = N / 2; if (N % 2 == 1) { solution++; } cout << solution << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, d, m, l; cin >> n >> d >> m >> l; long long k = d; for (int i = 1; i <= n; i++) { long long e = ((i - 1) * m) + l; long long s = i * m; k = e - (e % d) + d; if (i == n) { k = e - (e % d) + d; break; } if ...
2
#include <bits/stdc++.h> #define st first #define nd second #define mp make_pair #define pb push_back #define N 1000005 using namespace std; typedef long long ll; ll n, m; deque < int > q; void yap(ll n){ if(n == 1) return; if(n%2){ yap(n - 1); q.push_back(++m); }else{ yap(n/2); q.push_front(++m); } } ...
0
#include <iostream> #include <algorithm> using namespace std; string s[302]; int n,ans; int main() { cin>>n; for (int i=0;i<n;++i) cin>>s[i]; for (int iter=0;iter<n;++iter) { for (int i=0;i<n;++i) rotate(s[i].begin(),s[i].begin()+1,s[i].end()); bool flag=true; for (int i=0;i<n;++i) for (int j=i+1;j<n;++j) fla...
0
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; struct Node { int in, out, d, val; vector<int> adj; Node() { in = out = d = val = -1; } } g[N]; int n, m, t; vector<pair<int, int> > h[N]; char S[N]; void dfs(int v) { g[v].in = ++t; h[g[v].d].push_back( make_pair(g[v].in, h[g[v].d].b...
4
#include <bits/stdc++.h> using namespace std; int a[100010]; int b[100010]; int ans[100010]; int h[4][4] = {0, 1, 2, 3, 1, 1, 3, 3, 2, 3, 2, 3, 3, 3, 3, 3}; int q[4][4] = {0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 2, 2, 0, 1, 2, 3}; int main() { int n; scanf("%d", &n); for (int i = 1; i < n; i++) scanf("%d", &a[i]); for (i...
2
#include <bits/stdc++.h> using namespace std; constexpr int N = 3e3 + 1; int a[N], nxt[N], prv[N], lst[N]; uint16_t dp[N][N]; int main() { cin.tie(0), ios::sync_with_stdio(0); int t, n; cin >> t; while (t--) { cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i], --a[i]; } memset(lst, -1, n...
3
#include <bits/stdc++.h> #define rep(i, a, n) for(int i = a; i < n; i++) #define repb(i, a, b) for(int i = a; i >= b; i--) #define all(a) a.begin(), a.end() #define o(a) cout << a << endl #define int long long #define first first #define second se using namespace std; typedef pair<int, int> P; typedef vector<int> vi; ...
0
#include <iostream> using namespace std; int main(void){ // Your code here! int a,b,c,i=0,x=0; cin>>a>>b>>c; while(1){ i++; x=x+a; if(i%7==0){ x=x+b; } if(c<=x){ break; } } cout<<i<<endl; }
0
#include <cstdio> #include <iostream> #include <sstream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <climits> #include <cfloat> using namespace ...
0
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) ...
3
#include <bits/stdc++.h> using namespace std; int32_t main() { long long t; cin >> t; while (t--) { long long n, w, tsum = 0, sum = 0, rmv = -1; cin >> n >> w; pair<long long, long long> a[n]; for (long long i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i + 1; tsum += a[i...
1
#include <bits/stdc++.h> int main() { char ar[1000]; scanf("%s", ar); int i; for (i = 0; i < strlen(ar); i++) { if (ar[i] == 'H' || ar[i] == 'Q' || ar[i] == '9') { printf("YES\n"); return 0; } } printf("NO\n"); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<double> A(n), B(n); for (int i = 0; i < n; i++) { cin >> A[i]; B[i] = A[i]; } double iter = 0, low1 = -20000, high1 = 20000, mid; double ans; while (iter <= 400) { mid = (low1 + high1) / 2; for (int i = 0;...
5
#include <bits/stdc++.h> using namespace std; int main() { char s[1000020]; int a, b; bool b1[1000020]; while (~scanf("%s", s)) { scanf("%d%d", &a, &b); int len = strlen(s); int c = 0; memset(b1, 0, sizeof(b1)); for (int i = 0; i < len; i++) { c = (c * 10 + (s[i] - '0')) % a; if ...
3
#include<iostream> #include<algorithm> using namespace std; int main(){ int n,s,sum,ma,mi; while(cin >> n, n){ cin >> sum; ma = mi = sum; for(int i=1;i<n;i++){ cin >> s; sum += s; ma = max(ma,s); mi = min(mi,s); } cout << (sum-ma-mi)/(n-2) << endl; } }
0
#include <bits/stdc++.h> using namespace std; int flag[105]; double val[105]; vector<double> rest; int main() { ios_base::sync_with_stdio(false); int n, q, t; cin >> n >> q; for (int i = 0; i < n; i++) cin >> val[i]; t = n / q; double mn = 200, mx = 0.0; int qu; cin >> qu; while (qu--) { int x; ...
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const int SINF = 0x7fffffff; const long long LINF = 0x3fffffffffffffff; const long long SLINF = 0x7fffffffffffffff; const int MAXN = 3000007; const int MAXP = 107; int l, r, p; int a[MAXN], ka; int dp[MAXN], mn[MAXN]; bool isp[MAXP]; void init();...
5
#include <bits/stdc++.h> using namespace std; int n; int a[4]; int check(int a, int b, int c, int d) { int avg = a + b + c + d; int med = b + c; if (avg % 4 != 0 || med % 2 != 0) return 0; if (avg / 4 == d - a && med / 2 == d - a) return 1; return 0; } int main() { ios_base::sync_with_stdio(false); cin >>...
2
#include <bits/stdc++.h> using namespace std; int n, r; bool cmp(pair<int, int> &p1, pair<int, int> &p2) { return p1.first + p1.second > p2.first + p2.second; } signed main() { scanf("%d%d", &n, &r); int a, b; vector<pair<int, int>> pos, neg; for (int i = 0; i < n; i++) { scanf("%d%d", &a, &b); if (b ...
6
#include <bits/stdc++.h> using namespace std; long long Power(long long $a, long long $b) { long long $result = 1; $a %= 1000000007; while ($b) { if ($b % 2 == 1) $result *= $a; $a *= $a; $a %= 1000000007; $result %= 1000000007; $b /= 2; } return $result; } long long Mod_Inv(long long $a) ...
5
#include <bits/stdc++.h> using namespace std; vector<string> M; int dp[1005][1005][3][5]; int n, m; pair<int, int> OO(int x, int y, int ori) { if (ori == 1) return {x - 1, y}; if (ori == 2) return {x + 1, y}; if (ori == 3) return {x, y - 1}; return {x, y + 1}; } bool ok(int x, int y) { if (x < 0 or y < 0 or x...
2
#include <bits/stdc++.h> using namespace std; int n, m; char ar[200][200] = {0}; bool check(int i, int j) { char a[4] = {0}; a[0] = ar[i - 1][j - 1]; a[1] = ar[i][j - 1]; a[2] = ar[i - 1][j]; a[3] = ar[i][j]; sort(a, a + 4); if (a[0] == 'a' && a[1] == 'c' && a[2] == 'e' && a[3] == 'f') return true; retu...
1
#include <bits/stdc++.h> using namespace std; class vec{ public: double x,y; vec(){ x = y = 0.0; } vec(double x,double y){ this->x = x; this->y = y; } vec operator+(vec &r) const{ return vec(x+r.x,y+r.y); } vec operator-(vec &r) const{ return vec(x-r.x,y-r.y); } void operator=(vec &r){ this->x = ...
0
#include <bits/stdc++.h> using namespace std; const int N=2e3+5; int n,w[N],b[N],x; int dp[N][N],cw[N][N],cb[N][N]; int main() { ios::sync_with_stdio(0); memset(cw,0,sizeof(cw)); memset(cb,0,sizeof(cb)); cin>>n; for(int i=1;i<=2*n;i++) { char op[2]; cin>>op>>x; if(op[0]=='W') w[x]=i; else b[x]=i;...
0
#include <bits/stdc++.h> using namespace std; int N, H; long double p, q; long double dp[4][2005][2005]; int pos[2005]; double solve(int msk, int l, int r) { if (l > r) { return 0; } if (dp[msk][l][r] + 1) { return dp[msk][l][r]; } if (msk == 1 && pos[r + 1] - H <= pos[l - 1] + H) { return 0; } ...
4
#include <bits/stdc++.h> using namespace std; long long INF = 1e18; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const...
5
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return f == 1 ? x : -x; } const int N = 1e5 + 10, i...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, K; vector<int> v; cin >> n >> K; for (int i = 0; i < n; i++) { int tmp; cin >> tmp; v.push_back(tmp); } sort(v.begin(), v.end()); int size = 0; vector<int>::iterator pre, up; ...
2
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; for (int i = 1; i <= n * n / 2; i++) { cout << i << " " << (n * n) - i + 1 << "\n"; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, ans = 0; scanf("%lld%lld", &n, &m); if (n <= m) { for (long long i = 1; i <= n; i++) { for (long long j = 1; j <= n; j++) { long long tmp = i * i + j * j; if (tmp % m == 0) { ++ans; } } ...
2
#include<iostream> #define N 1000000007 using namespace std; typedef long long ll; int mod_pow(int m,int n){ ll a=1,x=m; while(n){ if(n%2)a=a*x%N; x=x*x%N; n=n/2; } return a; } int main(){ int m,n; cin>>m>>n; cout<<mod_pow(m,n)<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int i, j, n, m, k, x, y, z, col[100005], coltim[100005], row[100005], rowtim[100005]; int main() { int ans = 0; cin >> n >> m >> k; for (i = 0; i < k; i++) { scanf("%d %d %d", &x, &y, &z); if (x == 1) { row[y] = z; rowtim[y] = i + 1; } else...
2
#include<bits/stdc++.h> #define pb push_back using namespace std; typedef long long ll; const int P=1e9+7,N=2333; int fpow(int a,int t){static int r;for(r=1;t;t>>=1,a=(ll)a*a%P)if(t&1)r=(ll)r*a%P;return r;} int n,k,m,ve[N],f[N],ans; int main(){ scanf("%d%d",&n,&k); for(int i=1;i*i<=n;i++)if(n%i==0){ve[++m]=i;if(i...
0
#include <bits/stdc++.h> using namespace std; vector<char> a; string s; long long n; int main() { cin >> n; cin >> s; a.push_back(s[0]); for (int i = 1; i < n; i++) { if (a.size() % 2) { if (s[i] != a[a.size() - 1]) a.push_back(s[i]); } else { a.push_back(s[i]); } } if (a.size() % 2)...
3
#include <bits/stdc++.h> using namespace std; long long arr[1000010]; int N; bool check(long long K) { long long superCount = K; for (int i = 0; i < N; i++) { superCount -= (K - arr[i]); } return superCount <= 0; } int main() { cin >> N; long long high = 0; for (int i = 0; i < N; i++) { cin >> arr...
1
#include <bits/stdc++.h> using namespace std; const int N = 2000000; template <typename T> T read(T& x) { T f = 1; x = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48; return x *= f; } int n; long long k, ans; l...
6
#include <bits/stdc++.h> using namespace std; int n, q; vector<pair<pair<int, int>, char> > V; int revR[800010]; map<int, int> R; set<int> setR; int tree[2000010][2]; int lazy[2000010][2]; void upd(int idx, int l, int r, int a, int b, int x, bool k) { if (idx * 2 + 1 < 2000010) lazy[idx * 2 + 1][k] = max(lazy[idx...
3
#include <bits/stdc++.h> using namespace std; ifstream fin("in.in"); ofstream fout("out.out"); class compare : public std::binary_function<double, double, bool> { public: compare(double arg = 1e-7) : e(arg) {} bool operator()(const double &left, const double &right) const { return (abs(left - right) > e) && (l...
4
#include <bits/stdc++.h> using namespace std; long long a[100100], cs[100100]; int main() { long long n, s, f, i, j, x, y, p, mx = 0, ans; scanf("%lld", &n); for (i = 1; i <= n; i++) { scanf("%lld", &a[i]); cs[i] = cs[i - 1] + a[i]; } scanf("%lld", &s); scanf("%lld", &f); x = s; y = f - 1; for...
3