solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; long long pwr(long long base, long long p, long long mod = (1000000007LL)) { long long ans = 1; while (p) { if (p & 1) ans = (ans * base) % mod; base = (base * base) % mod; p /= 2; } return ans; } long long gcd(long long a, long long b) { if (b == 0) r...
5
#include <bits/stdc++.h> const int MXN = 300010; int main() { int n; scanf("%d", &n); std::map<int, int> first, last; static int ary[MXN]; static int cut[MXN]; static long long sum[MXN]; for (int i = 1; i <= n; i++) { scanf("%d", &ary[i]); if (ary[i] > 0) { cut[i] = cut[i - 1]; sum[i] ...
1
#include <iostream> #include <string> #include <vector> using namespace std; int str_to_min(string s){ int num=0; num+=(s[0]-'0')*600; num+=(s[1]-'0')*60; num+=(s[3]-'0')*10; num+=(s[4]-'0'); return num; } int main(){ int N,T; cin>>N>>T; int cnt=0; string s1,s2,s3,s4; cin>>s1>>s2; vector<string>name; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, i, c; c = 0; cin >> n; long int x; vector<long int> r; vector<long int>::iterator it; long long int sum = 0; for (i = 0; i < n; i++) { cin >> x; r.push_back(x); } sort(r.begin(), r.end()); for (it = r.begin(); it != r.end();...
4
#include <bits/stdc++.h> using namespace std; const int N = 2003; char a[N][N]; vector<pair<int, int> > q; pair<int, int> tmp; int n, m; inline bool f(int x, int y) { int res = 0; if (a[x][y] != '.') return false; if (a[x + 1][y] == '.') res++; if (a[x - 1][y] == '.') res++; if (a[x][y - 1] == '.') res++; i...
2
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "RDLU"; long long ln, lk, lm; void etp(bool f = 0) { puts(f ? "YES" : "NO"); exit(0); } void addmod(int &x, int y, int mod) { x += y; if (x >= mod) x -= mod; } void et() { ...
6
#include <bits/stdc++.h> using namespace std; template <typename T> string to_string(const vector<T>& vc, int w) { if (vc.empty()) return ""; if (w + 1 == vc.size()) return to_string(vc[w]); return to_string(vc[w]) + "," + to_string(vc, w + 1); } template <typename T> string to_string(const vector<T>& vc) { ret...
3
#include <bits/stdc++.h> using namespace std; const int maxN = 200 * 1000 + 9; const int INF = 1e9; int n; pair<int, int> pts[maxN]; map<pair<int, int>, long long> cnt; void read() { cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; pts[i] = make_pair(x, y); cnt[make_pair(x, y)]++; ...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 1 + 1e5; const int MAXM = 1 + 5e3; int n, m, n1, n2, n3, col[MAXN], kt, vis[MAXN], dp[MAXM][MAXM], cnt, ma, res[MAXN], cnt1; vector<int> g[MAXN], f[MAXN][3]; pair<int, int> p[MAXN]; void dfs(int u) { vis[u] = 1; if (g[u].size() == 0) { p[cnt].fi...
5
#include<cstdio> #include<unordered_map> #define int long long std::unordered_map<int,int>f; int t,n,a,b,c,d; inline int mn(int x,int y) {return x<y?x:y;} int dfs(int x) { if(f.count(x))return f[x]; f[x]=1e18; if(x<=2e9)f[x]=mn(f[x],x*d); if(!(x%2))f[x]=mn(f[x],dfs(x/2)+a); if(!(x%3))f[x]=mn(f[x],dfs(x/3)+b); if(...
0
#include <bits/stdc++.h> using namespace std; long long h[100001] = {0}; long long hops[100001] = {0}; long long previous[100001] = {0}; long long ans[100001] = {0}; int main() { int n, d; cin >> n >> d; int end_point = 1; for (int i = 1; i <= n; ++i) { cin >> h[i]; hops[i] = 1; for (int j = max(1, ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, mi, mx, rem; cin >> n; mi = mx = (n / 7) * 2; rem = n % 7; if (rem >= 2) { mx += 2; } else if (rem > 0) { mx++; } if (rem > 5) { mi++; } cout << mi << " " << mx << endl; return 0; }
1
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; struct Edge { int to, id; Edge(int to, int id): to(to), id(id) {} }; vector<Edge> g[55]; vector<int> es; bool dfs(int v, int tv, int p=-1) { if (v == tv) return true; ...
0
#include<bits/stdc++.h> using namespace std; #define pb push_back #define fr first #define sc second typedef pair<int, int> Pii; typedef pair<int, Pii> Pip; typedef vector<int> Vi; const int INF = (1<<25); const int MAX_V = 101; const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1}; int w, h, f, m; int c[10][10]; struct State {...
0
#include <bits/stdc++.h> using namespace std; long long n, L, a[200005], b[200005 << 2], c[200005], m; int judge(int mid) { int l = 1, r = m; for (int i = 1; i <= n; i++) { while (a[i] - mid > b[l]) ++l; while (a[i] + mid < b[r]) --r; if (l > r) return 0; ++l, ++r; } return 1; } int main() { c...
6
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned...
1
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); struct node { double a, b; } e[100010]; int n; double getl(node X, node Y) { double d1 = (X.a - Y.a) * (X.a - Y.a); double d2 = (X.b - Y.b) * (X.b - Y.b); return sqrt(d1 + d2); } double getlength(node A, node B, node C, double &temp) { ...
3
#include <bits/stdc++.h> int isUp(char ch); int main() { char arr[1001]; scanf("%s", arr); if (!isUp(arr[0])) { arr[0] -= 32; } printf("%s\n", arr); } int isUp(char ch) { if (ch >= 'A' && ch <= 'Z') return 1; else return 0; }
1
#include<bits/stdc++.h> #define MAXN 100010 #define int long long using namespace std; int a[MAXN],b[MAXN],cnt[MAXN]; int fa[MAXN],size[MAXN],ans; int fi(int now){ if(fa[now]==now) return now; return fa[now]=fi(fa[now]); } void con(int x,int y){ int fx=fi(x),fy=fi(y); if(fx==fy) return ; ans+...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; int pos[maxn], ans[maxn], a[maxn]; vector<int> e[maxn]; int main() { ios::sync_with_stdio(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; pos[a[i]] = i; } for (int i = 1; i <= m; i++) { int l, r; ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, ab; cin >> a >> b >> ab; long long ans = a + b + ab * 2; if (abs(b - a) > 1) cout << ans - abs(b - a) + 1; else cout << ans; }
1
#include <bits/stdc++.h> using namespace std; unsigned long long power(unsigned long long x, int y, int p) { unsigned long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } bool cmp(pair<string, int> &a, pair<string, int> &b) { ...
3
#include <bits/stdc++.h> using namespace std; int dp[1000 + 10][12][12]; bool w[120]; int up[1000 + 10][12][12]; int j[1000 + 10]; void javab(int m, int x, int y) { if (m == 0) { return; } j[m - 1] = up[m][x][y]; javab(m - 1, y - x, j[m - 1]); } int main() { string s; int m; cin >> s >> m; for (int ...
3
#include <bits/stdc++.h> using std::sort; int n; char s[100000 + 1]; struct SH { unsigned int s, h; }; struct SH cnt[100000 + 1]; unsigned long long ans; void read() { scanf("%d", &n); ans = 0; for (int i = 1; i <= n; ++i) { scanf("%s", s); int l = strlen(s); unsigned int sum = 0; for (int j = 0...
4
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; long long n, m, a, b, c, k, temp, x, y; const int MAXN = 1e5 + 11, mod = 1e9 + 7; inline long long max(long long a, long long b) { return ((a > b) ? a : b); } inline ...
5
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; long long inv[5110], fac[5110], s_inv[5110]; void prepare() { fac[0] = inv[0] = s_inv[0] = 1; inv[1] = s_inv[1] = fac[1] = 1; for (long long i = (2); i <= (5100); ++i) { inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD; s_inv[i] =...
5
#include <iostream> #include <map> using namespace std; const int N = 2e5 + 10; int n, k, a[N], cum[N]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; a[i] += k-1; a[i] %= k; cum[i+1] = (a[i] + cum[i]) % k; } long long res = 0; map<int,int> ...
0
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; string s; cin >> s; unordered_map<char, int> mp; for (int i = 0; i < s.length(); i++) { mp[s[i]]++; } string ans = ""; for (auto f : mp) { if (f.second % k == 0) { for (int i = 0; i < (f.second / k); i++) { ...
1
#include <bits/stdc++.h> using namespace std; #define rep(i, a) for(int i=0; i<(a); i++) typedef long long ll; const ll mod = 998244353; int main() { ll n, s; cin >> n >> s; vector<ll> a(n); for (int i=0; i<n; i++){ cin >> a[i]; } vector<vector<ll>> dp(n+2, vector<ll>(s+1, 0)); ll ans = 0; rep(i, n) ...
0
#include <bits/stdc++.h> using namespace std; const int N = 100010; const int M = 1000010; const int MOD = 1000000007; const int INF = 0x7fffffff; const int dir4[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; const int dir8[8][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}, {-1, 1}, {1, -1}, {-1, -1}, {1...
3
#include <bits/stdc++.h> using namespace std; int main() { string word; stack<char> letters; bool p1 = true; cin >> word; for (int i = 0; i < word.length(); i++) { if (letters.empty()) { letters.push(word[i]); } else { if (word[i] == letters.top()) { letters.pop(); p1 = !p1...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 10; int main() { int n, b; cin >> n >> b; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int ans = b; for (int i = 0; i < n; i++) { int mx = 0; for (int j = i + 1; j < n; j++) mx = max(mx, a[j]); ans = max(ans, b / a[i] * m...
2
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; const long long LINF = 1LL << 60; const double inf = 1e15; long long mod = 1e9 + 9; char READ_DATA; int SIGNAL_INPUT; template <typename Type> inline Type ru(Type &v) { SIGNAL_INPUT = 1; while ((READ_DATA = getchar()) < '0' || READ_DATA > '9') ...
2
#include <bits/stdc++.h> using namespace std; char s[1010]; int main() { scanf("%s", s); int l = strlen(s); int dian, e_; for (int i = 0; i < l; i++) { if (s[i] == '.') dian = i; if (s[i] == 'e') e_ = i; } if (s[0] == '0') { int p = -1; for (int i = dian + 1; i < e_; i++) { if (s[i] !=...
2
#include <bits/stdc++.h> using namespace std; int n, i, last[28], tmp[28]; long long ans[28]; char s[300005]; int main() { scanf("%s", s); for (i = 0; i <= 26; i++) last[i] = -1; int length = strlen(s); for (i = 0; i < length; i++) { last[s[i] - 'a'] = i; for (int j = 0; j <= 26; j++) tmp[j] = last[j]; ...
3
#include <bits/stdc++.h> using namespace std; int n, k, l; int d[300200]; int main() { ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int boolean = 1; cin >> n >> k >> l; for (long long i = 1; i <= n; i++) { cin >> d[i]; if (d[i] > l) boolean = 0; } int b, c; b =...
2
/**বিসমিল্লাহির রহমানির রহীম **/ #include<bits/stdc++.h> #define pi acos(-1.0) #define eps 1e-9 #define ff first #define ss second #define nl '\n' #define sp ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; map<string, int> m; map<string, int>::iterator it; for (int i = 0; i < (n - 1); i++) { string x = s.substr(i, 2); it = m.find(x); if (it == m.end()) m.insert({x, 1}); else m[x]++; ...
2
#include <cstdio> #include <iostream> #include <queue> #include <vector> #include <cmath> using namespace std; double prim(int n, vector< vector<double> > &G){ double ans = 0.0; priority_queue< pair<double,int> > wait; bool connected[n]; fill(connected,connected+n,false); wait.push(make_pair(0.0,0)); while...
0
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e5 + 10; const long long mod = 998244353; const long long inf = 2e18; const long long INF = 2e9; long long n, m, k; long long F(long long m) { if (m <= 0) return 0; long long ans = m; while (!(m & 1)) m >>= 1; if (m >= INF) return inf; retu...
2
#include <cstdio> #include <vector> #include <algorithm> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; typedef long long ll; const ll INF=1LL<<61; struct vertex{ int p,d; bool operator<(const vertex &v)const{ return p!=v.p?p<v.p:d<v.d; } }; int main(){ for(int n;scanf("%d",&n),n;){ vertex V[40...
0
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; long long change[30][30]; signed main() { ios::sync_with_stdio(0); cin.tie(0); string s, t, ans = ""; cin >> s >> t; char a, b; long long n, i, j, k, l, sum = 0, min1, imin; cin >> n; for (i = 1; i <= 26; i++) { for (j = 1; j ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; set<int> h, w; vector<int> ans; scanf("%d", &n); for (int i = 0; i < n * n; i++) { scanf("%d%d", &x, &y); if (h.find(x) == h.end() && w.find(y) == w.end()) { ans.push_back(i + 1); h.insert(x); w.insert(y); } ...
1
#include <bits/stdc++.h> using namespace std; const int N = 2005, p = 1e9 + 7; int n, m; int a[N][N], shr[N][N], slr[N][N], f[N][N][2], shf[N][N], slf[N][N]; char s[N]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%s", s + 1); for (int j = 1; j <= m; j++) { if (s[j] == 'R'...
5
#include<bits/stdc++.h> using namespace std; int main() { string s; cin>>s; int n=s.size(); if(s.substr(0,(n-1)/2)==s.substr((n+3)/2-1)) { cout<<"Yes"<<endl; } else {cout<<"No"<<endl;} return 0; }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 105000; const double eps = 1e-12; struct point { double x, y; int idx; }; bool cmp(point a, point b) { return (a.x < b.x || (a.x == b.x && a.y < b.y)); } bool eq(double a, double b) { return abs(a - b) <= eps; } double crossProduct(point a, point b, poi...
3
#include <bits/stdc++.h> using namespace std; using ll=long long; int main(){ int n,q;cin>>n>>q; vector<ll> v; v.push_back(n); while(q--){ ll a;cin>>a; while(v.size()&&v.back()>=a)v.pop_back(); v.push_back(a); } int L=v.size(); vector<ll> t(L,0),ans(n+1,0); t[L-1]=1; for(int i=L-1;i>=0;i...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; int nq; cin >> n >> nq; while (nq--) { long long iq; cin >> iq; for (long long s = (n - iq) + (iq - 1) / 2; !(iq % 2); s /= 2) iq += s + 1; cout << (iq + 1) / 2 << '\n'; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, i, j; cin >> n >> m; for (i = 0; i < 2225; i++) printf("1"); puts(""); for (i = 0; i < 2224; i++) printf("8"); printf("9"); puts(""); }
2
#include <bits/stdc++.h> using namespace std; template <class T> bool uin(T &a, T b) { return a <= b ? true : false; } template <class T> bool uax(T &a, T b) { return a >= b ? true : false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); cout << fixed; long long H; int ...
5
#include <bits/stdc++.h> using namespace std; const int mxN = 101; vector<pair<int, int> > G[mxN]; int vis[mxN]; void dfs(int u, int ci) { vis[u] = 1; for (pair<int, int> to : G[u]) { int v = to.first; int col = to.second; if (!vis[v] && ci == col) dfs(v, ci); } } int main() { int n, m; cin >> n >...
4
#include "bits/stdc++.h" #include<unordered_map> #include<unordered_set> #pragma warning(disable:4996) using namespace std; using ld = long double; template<class T> using Table = vector<vector<T>>; const ld eps = 1e-9; //// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Downl...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char s[2200]; cin >> s; int l = strlen(s); int i = 0; int total = 0; for (i = 1; i < l; i++) { if (i % n == 0) { if (s[i - 1] == s[i - 2] && s[i - 2] == s[i - 3]) total++; } } cout << total; return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, x[100001], y[100001]; unsigned long long getSum(int *h) { unsigned long long sum = 0, sumH = 0; for (int i = 0; i < n; i++) { sum += (unsigned long long)h[i] * (unsigned long long)h[i] * (n - 1); sum -= 2ULL * (unsigned long long)h[i] * sumH; sumH += ...
5
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; int dy[] = {-1, 1, 0, 0, -1, -1, 1, 1}; const int mod = 1000000007; const double pi = acos(-1); const long long OO = INT_MAX; int main() { cin.tie(0); std::ios::sync_with_stdio(false); int n; cin >> n; int prev = 0; int cu...
3
#include <stdio.h> typedef long long ll; int main(void) { ll i, j, k, n, m, ra, rb, na, nb; scanf("%lld%lld%lld", &n, &m, &k); ll uf[n], a[m], b[m], c, d, ans[n]; for(i = 0; i < n; ++i) uf[i] = i, ans[i] = 0; for(i = 0; i < m; ++i) { scanf("%lld%lld", &a[i], &b[i]); a[i]--, b[i]--; na = a[i], nb ...
0
#include <iostream> #include <cmath> using namespace std; int main(void) { double x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; cout.setf(ios::fixed, ios::floatfield); cout<<sqrt(pow(x1-x2,2.0)+pow(y1-y2,2.0)); return 0; }
0
#include <bits/stdc++.h> using namespace std; int a14; inline int rd(int l, int r) { return rand() % (r - l + 1) + l; } const int mxn = 5e5 + 3; int to[mxn * 2], nxt[mxn * 2], fir[mxn], gn = 1, n, m; void gadd(int x, int y) { to[++gn] = y, nxt[gn] = fir[x], fir[x] = gn, to[++gn] = x, nxt[gn] = fir[y], fir[y] = gn; ...
5
#include <bits/stdc++.h> using namespace std; const int Dian = 200005; const int Bian = Dian * 2; const int M = Dian; const int Segment_Size = Dian * 4; int fir[Dian], ne[Bian], to[Bian], cnt, n, m; int dp[Dian], depth[Dian], fa[Dian], Bigson[Dian], top[Dian], S[Dian], dep[Dian], info[Dian]; struct One { int from...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 0) { cout << "white" << endl; cout << "1 2" << endl; } else { cout << "black" << endl; } }
4
#include <bits/stdc++.h> using namespace std; int n, m, k; int main() { cin >> n >> m >> k; for (int i = 1; i <= k; i++) { int x, y; cin >> x >> y; if (min(min(x - 1, n - x), min(y - 1, m - y)) <= 4) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }
3
#include<iostream> #include<string> using namespace std; char map[20][20]; int dx[4]={0,0,-1,1},dy[4]={-1,1,0,0}; char dm[4]={'^','v','<','>'}; int main(){ int t; cin>>t; for(int r=0;r<t;r++){ if(r!=0)cout<<endl; int h,w; cin>>h>>w; int set,x,y; for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ cin>>map[i][j]; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int speeds[101]; int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> speeds[i]; } sort(speeds, speeds + n); cout << speeds[n - k] << endl; return 0; }
2
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main(){ ios_base::sync_with_stdio(false); int q; cin >> q; while(q--){ string s, t; cin >> s >> t; const int n = s.size(); if(s == t){ cout << 0 << endl; continue; } int f = 0, b = n - 1, a = n ...
0
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b, long long m = 998244353) { long long res = 1; while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res; } long long inverse(long long a, long long m = 998244353) { return power(a, ...
1
#include <cstdio> #include <iostream> #define ll long long using namespace std; const int N=1e6+10; ll sum[N][2],num[N]; char str[N]; int n; int main () { scanf("%d%s",&n,str+1); for(int i=1;i<=n;i++) sum[i][0]=sum[i-1][0]+(str[i]=='M'),sum[i][1]=sum[i-1][1]+(str[i]=='C'),num[i]=num[i-1]+(str[i]=='C')*sum[i][0]; i...
0
#include <bits/stdc++.h> using namespace std; struct cell { long long root_vertix, com_len; cell() {} cell(long long x, long long y) { root_vertix = x; com_len = y; } bool operator<(const cell &x) const { return com_len < x.com_len; } }; long long root[100002]; long long n, m, p, q; long long find_roo...
4
#include <bits/stdc++.h> using namespace std; int main() { long long n, x1, x2; while (cin >> n >> x1 >> x2) { vector<pair<int, int> > arr(n, pair<int, int>()); for (int i = 0; i < n; i++) { cin >> arr[i].first; arr[i].second = i; } sort(arr.begin(), arr.end(), greater<pair<int, int> >()...
2
#include <iostream> #include <vector> #include <string> #include <cmath> #include <algorithm> #include <utility> #include <queue> #include <set> #include <map> #include <complex> using namespace std; typedef long long ll; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<VI> VVI; #define MP make_pair...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; vector<pair<int, int>> b; for (int i = 1; i <= 100; i++) { int sum = 0; for (int j = 0; j < n; j++) { if (abs(a[j] - i) > 1) sum += abs(a[j] - i) - 1; } b.push...
1
#include <bits/stdc++.h> static int solve(); using ll = long long; int main(int argc, char* argv[]) { int tc = 1; while (tc--) solve(); return 0; } static constexpr int MOD = 998244353; const int N = 5005; int tp[N][N]; int fact[N]; int n, ans[N]; static int solve() { scanf("%d", &n); tp[1][1] = 1; for (int...
6
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> a(n + 1), b(n + 1), c(n + 1), ans(n + 1); for (long long i = 1; i <= n; ++i) cin >> a[i]; for (long long i =...
1
#include <bits/stdc++.h> using namespace std; int main() { int N; long long a[10000]; cin >> N; for (int i = 0; i < N; i++) scanf("%lld", &a[i]); sort(a, a + N); long long int ans = a[N - 1] - a[0] + 1 - N; cout << ans << endl; }
1
#include <bits/stdc++.h> using namespace std; int n, m, a, b, p[222][222]; string s, r[222]; bool f[222][222]; int main() { cin >> m >> a >> b; cin >> s; n = s.size(); f[0][0] = true; for (int i = 1; i <= m; i++) for (int j = 1; j <= n; j++) for (int k = a; k <= b; k++) if (j >= k && f[i - 1...
5
#include <bits/stdc++.h> using namespace std; int n, m, a[200100], pos; long long ans; map<int, int> cnt; int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] == m) pos = i; } int x = 0, y = 0; cnt[0]++; for (int i = pos - 1; i ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n >> t; int total = 0; for (int i = 0; i < n; i++) { int cur; cin >> cur; cur = 86400 - cur; total += cur; if (total >= t) { cout << i + 1 << endl; return 0; } } return 1; }
1
#include <bits/stdc++.h> using namespace std; const int mo = 1000000009, mn = 101000; int n, m, k, Q, i, j, rt; int lg[mn], h[mn][20]; int l[mn], r[mn], le[mn], ri[mn]; pair<int, int> a[mn], f[mn]; bool cmp(int i, int j) { return a[i].second < a[j].second; } void RMQ() { int i, j; for (i = 1; i <= n; ++i) h[i][0] =...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { int t, a, b, c, d; cin >> t >> a >> b >> c >> d; if ((a - b) * t <= c + d && (a + b) * t >= c - d) cout << "Yes" << endl; else cout << "No" << endl; } }
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 2 * 100000; vector<int> g[MAXN + 1]; int used[MAXN + 1], ptr[MAXN + 1], deg[MAXN + 1], was[MAXN + 1]; int main() { int n; cin >> n; for (int i = 0; i < n - 1; i++) { int a, b; scanf("%d%d", &a, &b); g[a].push_back(b); g[b].push_back(a)...
5
#include <bits/stdc++.h> using namespace std; bool cmp(vector<int> a, vector<int> b) { return a.size() < b.size(); } int main() { int a, b; cin >> a >> b; int ans = 0; for (int i = a; i <= b; i++) { int n = i; int m = 0; while (n > 0) { m = n % 10; (m == 0 || m == 6 || m == 9) ? ans +=...
2
#include <bits/stdc++.h> using namespace std; int main() { int x1, y1, x2, y2, x3, y3; scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3); printf("3\n"); printf("%d %d\n", x2 - x3 + x1, y2 - y3 + y1); printf("%d %d\n", x1 - x2 + x3, y1 - y2 + y3); printf("%d %d\n", x3 - x1 + x2, y3 - y1 + y2); return 0; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; cout << (N + 111 - 1) / 111 * 111 << endl; }
0
#include <bits/stdc++.h> using namespace std; int n, i, a, f[5], s; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> a; f[a % 3]++; } if (f[1] < f[2]) s = f[1]; else s = f[2]; s = s + f[0] / 2; cout << s; }
3
#include <bits/stdc++.h> int main() { int n; int m; int arr[100]; int x; int y; scanf("%d", &n); int i; for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } scanf("%d", &m); for (int i = 0; i < m; i++) { scanf("%d %d", &x, &y); if ((x - 1) >= 1) { arr[x - 2] = arr[x - 2] + (y - 1); ...
1
#include<bits/stdc++.h> using namespace std; int main() { int a,b; set<int>iset; cin>>a; for(int i=0;i<a;i++) { cin>>b; iset.insert(b); } cout<<iset.size(); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 + 10; const long long MOD = 1e9 + 7; int n; long long quickpow(long long a, long long b) { if (b < 0) return 0; long long ret = 1; a %= MOD; while (b) { if (b & 1) ret = (ret * a) % MOD; b >>= 1; a = (a * a) % MOD; } return ret %...
1
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int n, w, m; struct ST { int x, y; } A[100001]; struct ft { int p, q; } C[100001], BB[100001]; struct DT { ft x, y; } B[100001]; int com(ft a, ft b) { long long int aa = (long long int)a.p * b.q - (long long int)a.q * b.p; if (aa > ...
5
#include <bits/stdc++.h> #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)n;++i) #define all(v) (v).begin(),(v).end() using namespace std; typedef pair<int,int>P; typedef complex<double> C; //?????? double cross(const C& a, const C& b) { ret...
0
#include <bits/stdc++.h> using namespace std; int lsone(int n) { return (n & -n); } void mult(long long int a[25][25], long long int b[25][25], long long int c[25][25], int m, int n, int p) { for (int i = 1; i <= m; i++) { for (int j = 1; j <= p; j++) { c[i][j] = 0; for (int k = 1; k <= n; k...
5
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; const int M = 35; const int mod = 998244353; int n, m; int cnt0; long long a[N]; long long wB[N]; long long wA[19][N]; long long ans[N]; long long qpow(long long a, long long b) { long long r = 1; while (b) { if (b & 1) r = r * a % mod; b ...
5
#include <bits/stdc++.h> using namespace std; char mp[110][110]; int d[110][110]; int p[1000010]; int pre[1000010]; int dp[1000010]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%s", mp[i] + 1); int m; scanf("%d", &m); for (int i = 1; i <= m; i++) scanf("%d", &p[i]); memset(d, ...
3
#include <iostream> #include <sstream> #include <string> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cassert> using namespace std; #define FOR(i,k,n) for(int i=(k); i<(int)(n);...
0
#include <bits/stdc++.h> using namespace std; const long long mod = (int)1e9 + 7; int t, k; int dp[100001]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.setf(ios::fixed), cout.precision(20); cin >> t >> k; dp[0] = 1; for (int i = 1; i < k; i++) { dp[i] = 1; } for (int i = k; i ...
4
#include<bits/stdc++.h> #define rep(i,x,y) for(register int i = x;i <= y; ++ i) #define repd(i,x,y) for(register int i = x;i >= y; -- i) using namespace std; typedef long long ll; template<typename T>inline void read(T&x) { char c;int sign = 1; x = 0; do { c = getchar(); if(c == '-') sign = -1; }while(!isdigit(c)); ...
0
#include <bits/stdc++.h> using namespace std; const int oo = 1e9; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; int c = 0; for (int i = (0); i < (n); ++i) { for (int j = (0); j < (m); ++j) { int a, b; cin >> a >> b; c += (a + b > 0); } } co...
1
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 7; const int INF = 1e9; int s, k, n, m, x, y, p, q, a, b, c, d, caseno = 0; int ar[MAX], ans = 0; int MAIN() { scanf("%d", &n); for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) { scanf("%d", &a); if (i == j) ans ^= a; }...
1
#include <bits/stdc++.h> using namespace std; int n; int size[500100], f[500100], l[500100], soli[30][30]; int main() { cin >> n; string s; getline(cin, s); for (int i = 0; i < n; i++) { getline(cin, s); size[i] = s.size(); f[i] = s[0] - 'a'; l[i] = s[s.size() - 1] - 'a'; } for (int i = 0; i...
3
#include <bits/stdc++.h> using namespace std; int main() { set<int> done; vector<pair<int, int> > grads1, grads2; vector<long long> sols; int n, q; scanf("%d%d", &n, &q); vector<int> vals; vals.resize(n); for (int c = 0; c < n; c++) scanf("%d", &vals[c]); for (int c = 0; c < n - 1; c++) grads1.pus...
4
#include <bits/stdc++.h> using namespace std; map<string, int> table; int main() { int n; while (cin >> n) { table.clear(); for (int i = 0; i < n; i++) { string t; cin >> t; table["void"] = 0; if (t[4] == 'd') { string a, b; cin >> a >> b; string bare; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int a[100005]; for (int j = 0; j < n; j++) { int m; scanf("%d", &m); for (int i = 0; i < m; i++) { scanf("%d", &a[i]); } sort(a, a + m); int o = min(a[m - 1], a[m - 2]) - 1; printf("%d\n", min(o,...
1