solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f; cout << ((b * d * f > a * c * e || d && (!a && b || !c)) ? "Ron" : "Hermione"); return 0; }
1
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long INFLL = 1e18 + 1; const int MAX = 200001; const long long MOD = 1000000007; long long inq(long long k, long long q) { if (q == 0) return 1; long long l = inq(k, q / 2); if (q % 2 == 0) return l * l % MOD; else return (l *...
5
#include <bits/stdc++.h> using namespace std; template <class T, class L> bool smax(T& x, L y) { return x < y ? (x = y, 1) : 0; } template <class T, class L> bool smin(T& x, L y) { return x > y ? (x = y, 1) : 0; } const int maxn = 2e5 + 17; int n, m, gp[maxn], rate[maxn], cnt, sz[maxn]; template <typename KeyType, ...
3
#include <bits/stdc++.h> int main() { int n, k; scanf("%d%d", &n, &k); int res = 0; for (int i = 0; i < n; i++) { int w; scanf("%d", &w); res += (w + k - 1) / k; } printf("%d", (res + 1) / 2); return 0; }
1
#include <bits/stdc++.h> using namespace std; void read(int &k) { k = 0; char x = getchar(); while (x < '0' || x > '9') x = getchar(); while (x >= '0' && x <= '9') { k = k * 10 - 48 + x; x = getchar(); } } struct node { int L, R, siz; node *c[2]; node() { L = 0; R = 0; c[0] = c[1] = ...
5
#include <bits/stdc++.h> using namespace std; template <class T> void chmax(T& a, const T& b) { a = max(a, b); } template <class T> void chmin(T& a, const T& b) { a = min(a, b); } template <class T> void uniq(vector<T>& c) { sort(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); } template <cla...
4
#include <bits/stdc++.h> using namespace std; #define EPS (1e-10) #define equals(a,b) (fabs((a)-(b))<EPS) class Point{ public: double x,y; Point(double x=0,double y=0):x(x),y(y){} Point operator+(const Point &p){ return Point(x+p.x,y+p.y); } Point operator-(const Point &p){ ret...
0
#include <bits/stdc++.h> using namespace std; set<long long> s; long long n; void dfs(long long c, long long num, long long i, long long j) { if (num > n || c > 10) return; s.insert(num); dfs(c + 1, num * 10 + i, i, j); dfs(c + 1, num * 10 + j, i, j); } int main() { cin >> n; for (int i = 0; i <= 9; i++) { ...
2
#include <iostream> #include <queue> #include <stack> #include <vector> #include <stdio.h> #include <algorithm> #include <string.h> #include <string> #include <cmath> #include <complex> #include <map> using namespace std; #define rep(i,n) for(int i=0;i<int(n);++i) #define ALL(v) (v).begin(),(v).end() #define PB push_b...
0
#include <bits/stdc++.h> using namespace std; const int LEFT = 0, RIGHT = 1, FRONT = 2, BACK = 3, BOTTOM = 4, TOP = 5; class Dice{ public: int val[6]; Dice(){for(int i=0;i<6;i++) val[i] = i;} Dice(int val[6]){for(int i=0;i<6;i++) this->val[i] = val[i];} void rot(string s){ if(s == "N" || s == "B") rotN...
0
#include <bits/stdc++.h> using namespace std; const int oo = (int)1e9; const double eps = 1e-7; const int MAXN = 1e5 + 10; int dx[] = {1, 0, 0, -1, -1, -1, 1, 1}; int dy[] = {0, 1, -1, 0, 1, -1, 1, -1}; string s[1000]; int n, m; bool vis[504][505]; bool valid(int a, int b) { return a >= 0 && b >= 0 && a < n && b < m ...
4
#include <bits/stdc++.h> using namespace std; template< typename T > struct BinaryIndexedTree { BinaryIndexedTree(size_t n) : n(n), v(n + 1) {} size_t n; vector< T > v; T sum(int k) { T ret = 0; for(; k; k -= k & -k) ret += v[k]; return ret; } void add(int k, T x) { for(; k <= n; k += k...
0
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { long long n, m; cin >> n >> m; long long arr[n + 1]; bool in_suffix[n + 1]; for (int i = 1; i <= n; ++i) { cin >> arr[i]; in_suffix[i] = false; } vector<long long> swap[n + 1]; for (int i = 0; i < m; i++) { ...
4
#include<bits/stdc++.h> using namespace std; #define F(A) (A=='#') const int N=2010; int g[N][N]; char s[N][N]; int stk[N]; int ht[N][N]; void print(int a[][2010],int n,int m){ for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++) printf("%d",a[i][j]); cout<<endl; } cout<<endl; } int main(){ // freopen("in","r",stdin); ...
0
#include<bits/stdc++.h> #define N 55 using namespace std; const int mo=1e9+7; int n,f[N][2*N][2*N],a[2*N],ans; void inc(int &x,int y){ x=x+y>=mo ? x+y-mo : x+y;} int main() { int i,j,k,l,p,u,v; scanf("%d",&n); for(i=1;i<2*n;i++) scanf("%d",&a[i]); sort(a+1,a+2*n); f[n][1][1]=1,p=1; for(i=n;i>1;i--){ u=(a[i]!=a[...
0
#include <bits/stdc++.h> using namespace std; void gcdEx(long long a, long long b, long long& x, long long& y, long long& g) { if (!b) { x = 1; y = 0; g = a; return; } gcdEx(b, a % b, x, y, g); long long x1 = y; long long y1 = x - (a / b) * y; x = x1; y = y1; } long long inverse(long long ...
5
#include <bits/stdc++.h> using namespace std; double a[100005], b[100005]; int main() { ios_base::sync_with_stdio(0); int n; double p; cin >> n >> p; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } double lim = 10e18 / p; double lo = 0, hi = lim * 10, mid, rem, used; while (hi - lo > 0.000001...
1
#include <bits/stdc++.h> using namespace std; double matrix[128][128]; double buf[128][128]; double prob[105]; double vt[128]; double buf2[128]; void mul() { memset(buf2, 0, sizeof(buf2)); for (int i = 0; i < 128; i++) { for (int j = 0; j < 128; j++) { buf2[j] += vt[i] * matrix[i][j]; } } memcpy(v...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int sumv1 = 0, sumv2 = 0; vector<int> v1; for (int i = 0; i < n; i++) { int x; cin>>x; v1.push_back(x); ...
1
#include<stdio.h> #include<algorithm> #include<string.h> #include<assert.h> using namespace std; int ans[25010],op; int fa[2010],dep[2010],a[2010],ch[2010],dn[2010],up[2010],rk[2010],so[2010],bl[2010],M; bool del[2010],us[2010]; void rot(int x){ ans[++op]=x; assert(op<=25000); int v=a[x]; a[x]=a[1]; for(x=fa[x];x;...
0
#include <bits/stdc++.h> using namespace std; const int N = 100010; const int M = 310; int n, m, s, e0, E; pair<int, int> dp[N][M]; int a[N]; vector<int> elAtB[N]; inline int findj(int j0, int val) { if (j0 >= m) return -1; vector<int> &v = elAtB[val]; if (v.size() == 0) return -1; vector<int>::iterator it = lo...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 1; bool visit[maxn] = {false}; vector<int> vc; int main() { int i, j, k; int n; scanf("%d", &n); while (n--) { scanf("%d", &k); visit[k] = true; } n = maxn - 1; int cnt = 0; for (i = 1; i <= n / 2; ++i) { if (visit[i]) { ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<pair<int, pair<int, int>>> a(n); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second.first; a[i].second.second = i; } sort(a.begin(), a.end()); set<pai...
4
#include<bits/stdc++.h> using namespace std; const auto CHARS = 64; using Bit = bitset<800>; int to_i(char c) { if(isdigit(c)) return c - '0'; if(islower(c)) return c - 'a' + 10; if(isupper(c)) return c - 'A' + 36; return 63; } int main() { int AW, AH, BW, BH; cin >> AW >> AH >> BW >> BH; vector<string...
0
#include <bits/stdc++.h> using namespace std; int mas[1001]; int Solution() { int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> mas[i]; long long lu = 10 * mas[1], ld = 1; long long ru = lu + 10, rd = 1; for (int i = 2; i <= n; ++i) { long long newlu = 10 * mas[i]; long long newru = newlu + 10; ...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 300005; int f[MAXN][20], g[MAXN][20], lenf, leng, ff, gg, Lg[MAXN]; int n, m, i, j, k, a[MAXN], ans; inline int get() { char c; while ((c = getchar()) < 48 || c > 57) ; int res = c - 48; while ((c = getchar()) >= 48 && c <= 57) res = res * 10 + ...
5
#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...); } template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return fa...
4
#include <bits/stdc++.h> using namespace std; long long int powfi(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = ((res % p) * (x % p)) % p; y = y >> 1; x = (x * x) % p; } return res % p; } map<int, int> freq, M, lefte; map<in...
3
#include <cstdio> #include <algorithm> using namespace std; long long A[101010],S[101010]; long long n,i,ans; int main() { scanf("%lld",&n); for(i=0;i<n;i++){ scanf("%lld",A+i); } sort(A,A+n); for(S[0]=A[0],i=1;i<n;i++) S[i] = S[i-1]+A[i]; for(i=n-1,ans=1;i>0;i--,ans++) if(S[i-1]*2<A[i]) break; printf(...
0
#include<iostream> using namespace std; int a[100010]; int N; int main(){ cin >> N; for(int i = 1; i <= N; i++){ cin >> a[i]; } int m = 0; int cnt = 0; for(int i = N; i; i--){ if(a[i-1] >= a[i]) cnt++; else cnt = 0; m = max(cnt, m); } cout << m; }
0
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx2") #pragma GCC optimization("unroll-loops") #pragma GCC optimize("O2") int main() { long long n, m; cin >> n >> m; vector<vector<char> > v(n, vector<char>(m)); map<char, long long> m1; for (long long i = 0; i < n; i++) { for (long long ...
2
#include <bits/stdc++.h> using namespace std; const double Pi = acos(-1.0); long long mod = 1000000007; vector<int> ans; bool visit[100005]; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; if (n & 1) { cout << -1; return 0; } int now = 0; for (int i = 0; i < (int)(n + 1); i++) { ...
5
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; char G[27][27]; int hve[27][27], add[27][27]; int val[27]; int dist[27][27][1 << 8]; int n, m, cnt = 0; int ans = 0; int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0}; int main() { int sx, sy; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) ...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; int CASE = 1; const int mxn = 1e5 + 1; const long long INF = 1e18; bool prime(int n) { if (n <= 1) return false; if (n == 2 or n == 3) return true; if (n % 2 == 0 or n % 3 == 0) return false; for (int i = 5; i * i <= n; i += 6) i...
1
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const long double pi = acos(-1.0); const long double eps = 1e-5; const int INF = 0x3f3f3f3f; const long long INFLL = 0x3f3f3f3f3f3f3f3f; const int maxn = 200010; long long les[maxn]; long long gte[maxn]; long long a[maxn]; int main() { ios:...
1
#include <bits/stdc++.h> long a[1001], b[1001], min, max, i, j, p, n, m, k; int main() { scanf("%ld %ld", &n, &m); p = n; for (i = 1; i <= m; i++) { scanf("%ld", &j); a[j]++; } for (i = 1; i <= 1000; i++) { if (a[i] != 0) { k = a[i]; while (n > i && k > 0) { min += (i * (i + 1)...
2
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<vector> #define SF scanf #define PF printf #define MAXN 65636 #define MAXM 20 #define MOD 1000000007 using namespace std; long long dp[2][MAXN],q[MAXN],p[MAXN]; int a[MAXM],n,m; bool cmp(int x,int y){ return x>y; } long long fsp(long long ...
0
#include <bits/stdc++.h> using namespace std; long long n, i, j, ans[100000 + 6]; vector<long long> v[100000 + 4]; bool visit[100000 + 5]; long long leaf[100000 + 5]; long long z; long long dfs(long long x, long long par) { visit[x] = 1; if (v[x].size() == 1 and v[x][0] == par) { z++; return 1; } long l...
4
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 2e5 + 10; int a[N]; double b[N]; long long sum[N]; int main() { int n, T; double c; scanf("%d%d%lf", &n, &T, &c); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); sum[i] = sum[i - 1] + a[i]; b[i] = (b[i - 1]...
2
#include <iostream> #include <map> using namespace std; int main() { string s, t; cin >> s >> t; string ans = "Yes"; map<char, char> map1, map2; for (auto i = 0; i < s.size(); i++) { if (map1[s[i]] || map2[t[i]]) { if (map1[s[i]] != t[i] || map2[t[i]] != s[i]) { ans = "No"; } } map1[...
0
#include <bits/stdc++.h> using namespace std; int n, x, y, z, i, v[5010], s; int main() { cin >> n; cout << "? 1 2\n"; cin >> x; cout << "? 1 3\n"; cin >> y; cout << "? 2 3\n"; cin >> z; s = (x + y + z) >> 1; v[1] = s - z; v[2] = s - y; v[3] = s - x; for (i = 4; i <= n; ++i) { cout << "? 1 "...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 510; const int A = 26; const int INF = 2000000; long long int dp[maxn][A][A], cost[maxn][A + 3][A + 3], c[maxn][A + 3][A + 3]; int n, m; char str[maxn][maxn]; int arr[maxn][maxn]; pair<int, int> par[maxn][A + 3][A + 3]; int pars[maxn]; pair<int, int> prnt[m...
5
#include<bits/stdc++.h> using namespace std; #define f first #define s second #define M 1000000007 typedef pair<int,int> P; typedef pair<int,int> PP; typedef pair<int,int> Q; int n,m,k,i,j,l,q,ki,kaz; int mp[5001][5001],mp2[5001],flg[5001],mp3[5001][5001]; int len[5001]; int main(void) { long long min; queue <int> qe...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, a; bool check = true; cin >> n; for (a = 2; a <= sqrt(n); a++) { if (n % a == 0) check = false; } if (check == true) { cout << 1; return 0; } if (n % 2 == 0) cout << 2; else { check = true; for (a = 2; a <= sqrt(...
2
#include <bits/stdc++.h> using namespace std; const long long N = 1e9 + 1; struct Node; typedef Node* pNode; struct Node { pNode l, r; long long sum; int cnt; Node() { l = NULL, r = NULL; sum = cnt = 0; } }; pNode root = NULL; inline void add(long long x, long long val, pNode& v = root, long long L = ...
5
#include <bits/stdc++.h> using namespace std; long double INF = 1e18; const int N = 1e5 + 1; long double PI = 2 * acos(0); long double EPS = 1e-7; complex<long double> v[N]; long double dot(complex<long double> u, complex<long double> v) { return u.real() * v.real() + u.imag() * v.imag(); } void get_line(complex<long...
3
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; } template <class S, class T>...
6
#include <bits/stdc++.h> using namespace std; int main() { int t, n; char s[200050]; map<int, map<int, int>> vis, cnt; scanf("%d", &t); while (t--) { vis.clear(); cnt.clear(); int l = -5, r = 0x3f3f3f3f; scanf("%d%s", &n, s); int x = 0, y = 0; vis[x][y] = 1; cnt[x][y] = 0; for ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x, y = -1, z = -1; for (int i = 0; i < n; i++) { cin >> x; y = max(x, y); } cin >> n; for (int i = 0; i < n; i++) { cin >> x; z = max(x, z); } cout << y << " " << z; return 0; }
1
#include <bits/stdc++.h> using namespace std; int MOD; inline int add(int a,int b) {a+=b;return a>=MOD?a-MOD:a;} inline int sub(int a,int b) {a-=b;return a<0?a+MOD:a;} inline int mul(int a,int b) {return 1ll*a*b%MOD;} int ksm(int a,int b) { int ans=1; for(;b;b>>=1,a=mul(a,a)) if(b&1)ans=mul(ans,a); return ans; } c...
0
#include<bits/stdc++.h> using namespace std; char s[1005][1005]; int d[1005][1005]; int x[1000005],y[1000005]; int h,w; int dx[4]={0,0,-1,1}; int dy[4]={1,-1,0,0}; int main(){ scanf("%d%d",&h,&w); getchar(); int t=0; for(int i=1;i<=h;i++){ for(int j=1;j<=w;j++){ scanf("%c",&s[i][j]); if(s[i][j]=='.') d[...
0
#include <bits/stdc++.h> using namespace std; vector<int> val[1048588], id[1048588], ret; int d; void query(int a, int b, int vl, int vr, int k, int l, int r) { if(a <= l && r <= b) { int ptl = lower_bound(val[k].begin(), val[k].end(), vl) - val[k].begin(); int ptr = lower_bound(val[k].begin(), val[k].end(), vr) -...
0
#include <bits/stdc++.h> #define chkmin(x,y) x=min(x,y) #define ll long long using namespace std; const int Md=1000000007; int n,m,k,tim,top=0,low[55],dfn[55]; bool vis[55]; ll mi[210],ans=1,fac[210],ifac[210],inv[210]; struct edge { int t;bool vis; edge *nx,*rev; }*con[55],*st[110]; void ins(int x,int y) { edge...
0
#include<iostream> #include<cmath> #include<cstdio> struct Point{ double x; double y; }; void kock(int n,struct Point p1,struct Point p2){ if(n==0){ return; } Point s,t,u; s.x=(2*p1.x+p2.x)/3.0; s.y=(2*p1.y+p2.y)/3.0; t.x=(p1.x+2*p2.x)/3.0; t.y=(p1.y+2*p2.y)/3.0; u.x=(t.x-s.x)*cos((60*M_PI)/180)-(t.y-s.y)*s...
0
#include <bits/stdc++.h> using namespace std; void files(); int N; pair<int, pair<int, int> > V[2 * 100000 + 5]; char S[3][100000 + 5]; int main() { int i, k = 0, a, b, c; scanf("%d", &N); for (i = 1; i <= N; i++) { scanf("%d%d", &a, &b); V[++k] = make_pair(a, make_pair(i, 1)); V[++k] = make_pair(b, m...
2
#include <bits/stdc++.h> using namespace std; int main() { double a, b, c, d; while (cin >> a >> b >> c >> d) { double ans = (a / b) / (1 - (1 - a / b) * (1 - c / d)); cout << ans << endl; } return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int c, sum; cin >> c >> sum; int base = sum / c; int res = sum - base * c; int rr = c - res; cout << 1ll * res * (base + 1) * (base + 1) + ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int R[maxn], C[maxn], pa[maxn], x[maxn], y[maxn]; int n, m, Q, last, reX, reY, ans; vector<int> X[maxn], Y[maxn], q[maxn]; inline int getpa(int x) { return pa[x] == x ? x : pa[x] = getpa(pa[x]); } int main() { scanf("%d%d%d", &n, &m, &Q); if (!Q...
2
#include <bits/stdc++.h> using namespace std; const int N = 2005500; int n; map<int, int> D; long long B = 19; long long P = 32; bool can(int k) { cout << "> " << k << endl; bool b; cin >> b; return b; } int a[N], diff; vector<int> w; int ask(int v) { cout << "? " << v << endl; cin >> v; return v; } map<i...
5
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f, mod = 1e9 + 7; const int maxn = 500; const long double PI = acos(-1.0); long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); } long long power(long long a, long long n) { long long p = 1; while (n > 0) { if (n % 2) { ...
3
#include <bits/stdc++.h> using namespace std; int second, p, Min; set<int> st; bool winners(int second) { st.clear(); int i = (second / 50) % 475; for (int j = 0; j < 25; j++) { i = (i * 96 + 42) % 475; st.insert(i + 26); } return (st.find(p) != st.end()); } int main() { ios::sync_with_stdio(false);...
2
#include <bits/stdc++.h> using namespace std; int n, m, K, mxd, Log[150012], h[150012], cnt = 0, dep[150012], siz[150012], son[150012], fa[150012], tp[150012], L[150012], R[150012], dfst = 0, f[150012][19], X[150012], Y[150012]; long long ans = 0; struct Edge { int to, next; } e[150012 << 1]; inline void AddE...
6
#include <bits/stdc++.h> //#include<string> using namespace std; bool is_p(int a) { for(int i=2;i*i<=a;++i) { if(a%i==0) return false; } return true; } int main() { int t; cin>>t; while(t--) { int d; cin>>d; if(d==1) {cout<<"6\n"; continue;} long long ans=1; int c=...
2
#include <bits/stdc++.h> using namespace std; int can(int b, int d) { long long s = 1; for (int i = (1); i <= (6); i++) { s *= b; if (s % d == 0) return 1; } if ((b - 1) % d == 0) return 1; if ((b + 1) % d == 0) return 1; return 0; } void lemon() { int b, d; scanf("%d%d", &b, &d); long long s ...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using i2 = pair<int, int>; using ll2 = pair<ll, ll>; const int N = 2009; const ll M = 1000000007; vector<pair<int, ll> > adj[N]; ll dp[2][N]; ll2 F[N], CH[N]; inline double ip(ll2 f1, ll2 f2) { double a1 = f1.first, b1 = f1.second; double a2 = f2.f...
6
#include <iostream> #include <vector> using namespace std; void solve() { int k; while(cin >> k, k) { int c = k * (k - 1) / 2; vector<int> Vec(c); for(int i = 0; i < c; ++i) { cin >> Vec[i]; } int sum = 0; for(int i = 0; i < c; ++i) { sum += Vec[i]; } sum /= (k - 1); cout << sum << endl...
0
#include <bits/stdc++.h> using namespace std; long long s(0), p, k; int main() { cin >> k >> p; for (long long cz(1), i(0); i < k; ++i, ++cz) { string str = to_string(cz); string res(str); reverse(begin(str), end(str)); res += str; s += stoll(res) % p; } cout << s % p << endl; }
2
#include <stack> using namespace std; struct Rectangle { int height; int pos; }; #include <stdio.h> #define SIZ 1400 int m[SIZ+1][SIZ+1]; int st[SIZ]; char z[9999999]; int get(){ static int input_count=0; int r=0; for(;'0'<=z[input_count]&&z[input_count]<='9';)r=r*10+z[input_count++]-'0'; input_count++; re...
0
#include <bits/stdc++.h> // #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") // #pragma GCC optimize("avx, avx2") typedef long long ll; typedef long double ld; // #define int ll #define f first #define s second #define pb push_back #define vi vector<int> #define pii pair<int, int> #define cmax(a, b) a = a < b ...
4
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<long long> v(n); vector<long long> a(n - 1); for (size_t i = 0; i < n; i++) { cin >> v[i]; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; vector<pair<int, int>> adj[N]; bool vis[N]; bool b[N]; int ba[N]; int main() { int n, m, k; int u, v, x; scanf("%d %d %d", &n, &m, &k); for (int i = 0; i < m; i++) { scanf("%d %d %d ", &u, &v, &x); adj[u].push_back({v, x}); adj[v]....
2
#include <bits/stdc++.h> using namespace std; using namespace std; const int N = 100005; vector<int> graph[N]; int ans[N]; int now[N][26]; void dfs(int v, int pr) { for (size_t i = 0; i < graph[v].size(); ++i) { int to = graph[v][i]; if (to == pr) continue; dfs(to, v); for (int j = 0; j < 26; ++j) now...
3
#include <bits/stdc++.h> using namespace std; const long long MAX1 = 3e5 + 10; long long a, b, c, d, e, cnt, x, y, z, l, r, flag, num[MAX1], p[MAX1]; string s, t, g, st[MAX1]; char ch1, ch2; vector<long long> vec; long long top(long long n, long long m) { if (n % m == 0) return n / m; return n / m + 1; } long long ...
1
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } template <typename T> inline void Read(T &x) { char c = getchar(); bool f = false;...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; //#define int ll using vb = vector<bool>; using vvb = vector<vb>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; template<class T> using V = vector<T>; template<class T> us...
0
#include <iostream> #include <cmath> using namespace std; #define _USE_MATH_DEFINES const int NMax = 150; const double eps = 1e-8; const double eps1 = 1e-4; const double gravity = 9.8; const double PI = 3.14159265; int N, V, X, Y; int L[NMax], B[NMax], R[NMax], T[NMax]; int main() { cin >>N >>V >>X >>Y; for (in...
0
#include <bits/stdc++.h> using namespace std; long long n, a, b; int main() { cin >> n >> a >> b; cout << n / (a + b) * a + min(n % (a + b), a) << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const long long INFLL = 1e18 + 7; const long double EPS = 1e-9; const int MAXN = 1e5 + 17; mt19937 myRand(1337); mt19937_64 myRand64(1337); signed main(void) { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int k; cin >> k; int len = k / ...
5
#include <bits/stdc++.h> using namespace std; int f[555555], g[555555], pos[555555], i, j, ans, n, a[555555], q, t1, x, y; void update(int x, int d) { while (x <= n) { f[x] += d; x = x | (x + 1); } } int count(int x) { int ans = 0; while (x > 0) { ans += f[x]; x = x & (x + 1); x -= 1; } ...
2
#include <bits/stdc++.h> using namespace std; int main() { pair<int, int> a[1000]; int n; cin >> n; int s = 0; for (int i = 0; i < n; i++) { cin >> a[i].first; s += a[i].first; a[i].second = i; } if (a[0].first == 0 || s < n - 1) { cout << -1; return 0; } sort(a + 1, a + n); reve...
2
#include <bits/stdc++.h> using namespace std; int main() { int n = 0; bool check = false; bool check2 = false; char *str = new char[2]; cin >> str >> n; for (int i = 0; i < n; i++) { string str3; cin >> str3; if (str == str3) { check = true; check2 = true; break; } if (...
1
#include <bits/stdc++.h> using namespace std; struct fastIO { inline fastIO operator>>(int& num) { num = 0; char c = getchar(); while (c != '-' && (c < '0' || c > '9')) c = getchar(); bool foo = 0; if (c == '-') { foo = 1; c = getchar(); } while (c >= '0' && c <= '9') { n...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int w = 0; int b = 0; int c = 0; int f = 0; vector<int> vec; for (int i = 0; i < n; i++) { if (s[i] == 'B') { b++; } else { w++; } } if (w % 2 != 0 && b % 2 != 0) { cout <<...
2
#include <bits/stdc++.h> using namespace std; bool arr[201] = {0}; long long increment(long long start, long long end) { long long cnt = 0; bool initialarr[end]; for (long long i = 0; i < end; i++) { initialarr[i] = arr[i]; } for (long long i = start; i < end; i++) { if (initialarr[i]) { if (i -...
1
#include <bits/stdc++.h> using namespace std; int n, m, l, r, cnt = 0; int main() { cin >> n >> m; int a[m]; a[0] = 1; for (int i = 0; i < n; i++) { cin >> l >> r; for (int i = l; i <= r; i++) a[i] = 1; } for (int i = 0; i < m + 1; i++) { if (a[i] != 1) cnt++; } cout << cnt << endl; for (i...
1
#include<cstdio> #include<algorithm> #define maxn 100005 #define LL long long #define INF (LL)(1e16) using namespace std; int n,a[maxn],f[maxn]; LL sum,ans=-INF,pre[maxn]; int main() { scanf("%d%d",&n,&a[1]); for(int i=2;i<=n;i++) { char s[5]; scanf("%s",s); if(s[0]=='-') f[i]=1; scanf("%d",&a[i]); } for(i...
0
#include <bits/stdc++.h> using namespace std; long long a[100010]; int power[100], between[100]; bool judge(int x) { int r = 0; for (int i = 0; i < 63; i++) { if (i > 0) r += between[i - 1]; if (power[i] > x) { r += power[i] - x; } else if (power[i] < x) { r -= min(r, x - power[i]); x ...
3
#include <bits/stdc++.h> using namespace std; char str[110][110]; void fill(int x1, int y1, int x2, int y2, int t) { int i, j; char ch = 'a'; bool arr[30] = {0}; if (x1 > 0) arr[str[x1 - 1][y1] - 'a'] = 1; if (y1 > 0) arr[str[x1][y1 - 1] - 'a'] = 1; if (t == 1) { if (x1 > 0) arr[str[x1 - 1][y1 + 1] - 'a...
3
#include <cstdio> using namespace std; int n,d[102][4]; bool ch[102]; int gcd(int a,int b){ if(b == 0) return a; return gcd(b,a % b); } int dfs(int x){ int p = d[x][0]; int q = d[x][1]; int w = gcd(p,q); p /= w; q /= w; if(d[x][2] == 0 && d[x][3] == 0){ return (p+q); } int red=1,blu...
0
#include <bits/stdc++.h> using namespace std; template <typename T> inline int read(T& x) { x = 0; char c = getchar(), f = 1; while (c > '9' || c < '0') { if (c == '-') f = -1; if (c == -1) return -1; c = getchar(); } while (c <= '9' && c >= '0') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar...
6
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; struct A { int x, y; } a[N]; long long n, m, l[N], r[N], k, ans, f[N][2]; inline int d(int x, int y) { return abs(a[x].x - a[y].x) + abs(a[x].y - a[y].y); } inline bool cmp(A a, A b) { if (max(a.x, a.y) == max(b.x, b.y)) { if ((max(a.x, a.y)...
6
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch <= '9' && ch >= '0') { x = 10 * x + ch - '0'; ch = getchar(); } return x * f; } void print(int x) { i...
3
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const long long LLINF = 9223372036854775807LL; struct bor { bor* to[30]; int win; int lose; bor() { memset(to, 0, sizeof(to)); win = 0; lose = 0; } }; void calculate(bor* v) { int win = 0; int lose = 0; int was = 0; ...
2
#include <iostream> #include <algorithm> #include <string.h> #include <queue> #include <vector> #define INF 987654321 using namespace std; int main() { int t; scanf("%d",&t); while(t--){ int a,b,flag=0; scanf("%d %d",&a,&b); if(a==b)printf("YES\n"); else if(a>b)printf("NO\...
4
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define ss second #define ff first #define pb push_back #define mp make_pair int x[100100]; vector<pair<int,int> > v; int main() { int n; cin>>n; for(int i=0;i<n;i++) cin>>x[i]; sort(x,x+n); ll b=x[0]; for(int i=1;i<n-1;...
0
#include <bits/stdc++.h> using namespace std; const int NN = 1010; char s[NN][NN]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> s[i] + 1; } int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { ans += (s[i][j] == '*'); } } for (int i ...
2
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 1; int n, cnt = 1, f, l, r; int a[N], b[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(b, b + n); for (int i = 0; i < n - 1; i++) { ...
2
#include <bits/stdc++.h> using namespace std; long long T[300000 + 1]; long long p, z; int main() { int t; long long N = 123 - 123; for (long long j = 0; j <= 3e5; j++) { N ^= j; T[j] = N; } cin >> t; while (t--) { cin >> p >> z; long long OP = 123; OP -= 123; OP = T[p - 2 + 1]; ...
2
#include<iostream> #include<algorithm> #include<vector> #include<queue> #include<set> #include<unordered_map> using namespace std; typedef long long ll; typedef pair<ll,ll> P; #define chmax(a,b) a=max(a,b) #define chmin(a,b) a=min(a,b) #define mod 1000000007 #define mad(a,b) a=(a+b)%mod #define N 1010 #define X 22 ll h...
0
#include <iostream> #include <algorithm> #include <cassert> #include <cctype> #include <cstdio> #include <math.h> #include <map> #include <queue> #include <string> using namespace std; typedef long long ll; int n,N; ll s[4000][2],a,b; string d; int main(){ while(cin>>N){ if(N==0)return 0; for(int i=0;i<4000;i+...
0