solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> struct DOM { int id; int x; int h; } dom[100010]; int n; int i, j; int ans[100010]; bool cmpx(const DOM& A, const DOM& B) { return A.x > B.x; } int main() { scanf("%d", &n); for (i = 1; i <= n; i++) ans[dom[i].id = i] = 1; for (i = 1; i <= n; i++) scanf("%d%d", &dom[i].x, &dom[i].h)...
5
#include <stdio.h> int main(void){ int n,b,f,r,v,i; int p[4][3][10] = {}; scanf ("%d",&n); for (i = 0; i < n; i++){ scanf("%d %d %d %d",&b,&f,&r,&v); p[b - 1][f - 1][r - 1] += v; } for (b = 0; b < 4; b++){ if (b != 0){printf("####################\n");} for (f = 0; f < 3; f++){ for ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int n = -1; cin >> n; long long int a = min((long long int)2, n); vector<array<long long int, 3>> t; int x, h; for (int i = 0; i < n; i++) { cin >> x >> h; t.push_back({x, h, 1}); } sort(t.begin(), t.end()); for (int i = 1; i...
3
#include <bits/stdc++.h> using namespace std; const int NN = 100000 + 117; const int MM = 10000 + 117; int read() { int fl = 1, x; char c; for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar()) ; if (c == '-') { fl = -1; c = getchar(); } for (x = 0; c >= '0' && c <= '9'; c = getcha...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); if (x > a[n - 1]) { cout << n + 1; return 0; } if (x < a[0]) { cout << n; return 0; } int med, c, ind, ind2; bool...
3
#include <bits/stdc++.h> using namespace std; long long n; long long seive() { vector<set<long long> > v(n + 1); vector<long long> primes; for (long long i = 2; i <= n; i++) { if (v[i].size() == 0) { primes.push_back(i); for (long long j = i; j <= n; j += i) { v[j].insert(i); } }...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n; vector<int> a(n); vector<pair<int, int> > d; for (int i = 0; i < n; i++) { cin >> a[i]; d.push_back(make_pair(a[i], 0)); } cin >> m; vector<int> b(m); vector<pair<int, int> > c(n + m); vector<pair<int, int> > sum(...
3
#include <bits/stdc++.h> using namespace std; int n, a[3005], m; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) scanf("%d", &a[i]); sort(a + 1, a + m + 1); if (a[1] == 1 || a[m] == n) { printf("NO"); return 0; } for (int i = 1; i <= m - 2; i++) if (a[i] == a[i + 1] - 1 && a[i +...
2
#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() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; while (t--)...
4
#include <bits/stdc++.h> using namespace std; long long f[100007], ans[100007]; struct tak { long long s; long long d; long long p; long long id; }; long long cmp(tak x, tak y) { return x.s < y.s; } tak a[100007]; int main() { long long n, m, i, j, sum, c; cin >> n >> m; for (i = 0; i < m; i++) { cin ...
3
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e5 + 5; long long w[MAXN]; vector<long long> path[MAXN]; long long dp[MAXN], sdp[MAXN]; vector<long long> nd[MAXN]; long long n, l, s; long long ver[MAXN], tin[MAXN], tout[MAXN]; pair<long long, long long> dfahdasfdashsdf[MAXN << 2]; long long fasjkf...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> arr(n); for (auto& x : arr) cin >> x; vector<int> p(m); for (int i = 0; i < m; i++) p[i] = i; vector<vector<int>> mp(m); int ans = 0; for (in...
5
#include <bits/stdc++.h> using namespace std; void solve() { int n, m, x, y; cin >> n >> m >> x >> y; x--, y--; vector<vector<bool> > v(n, vector<bool>(m, true)); vector<pair<int32_t, int32_t> > ans; int x1 = x, y1 = y; for (int i = y; i >= 0; --i) { ans.push_back({x, i}); v[x][i] = false; } f...
2
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; const int N = 1e5 + 5; vector<int> adj[N]; int n, k, a[N], ans; int dfs(int u) { int ret = 0; for(int v : adj[u]) { int x = dfs(v); if(x == k - 1 && u != 1) ++ans; else ret = max(ret, 1 + x); } ...
0
#include <bits/stdc++.h> 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) const { static const ui...
3
#include <stdio.h> #include <stdlib.h> #include <stdio.h> #include <math.h> #include <cctype> #include <iostream> #include <vector> #include <deque> #include <queue> #include <map> #include <algorithm> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) typedef pair<int ,int> P; class Coordinates { ...
0
#include<stdio.h> int A[20],n; int solve(int i,int m) { if (m == 0) return 1; else if (i >= n) return 0; return solve(i + 1, m) || solve(i+1,m-A[i]); } int main() { int p, key; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &A[0] + i); } scanf("%d", &p); for (int i = 0; i < p; i++) { ...
0
#include <bits/stdc++.h> inline int getInt() { int s; scanf("%d", &s); return s; } using namespace std; int g[60][60][60]; int memo[1001][60][60]; int main() { int n = getInt(); int m = getInt(); int r = getInt(); for (int c = 0; c < (int)(m); c++) { for (int i = 0; i < (int)(n); i++) for (int j...
2
#include <bits/stdc++.h> int main() { int n, x, mn = 51, c = 0; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &x); if (x < mn) mn = x, c = 0; if (x == mn) ++c; } puts(c > n / 2 ? "Bob" : "Alice"); }
3
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long infLL = 0x3f3f3f3f3f3f3f3fLL; const int hash_mod = 1000037; const double eps = 1e-10; const double pi = acos(-1); const int maxn = 1000000 + 5; int n; char s[maxn]; int cnt[10]; int main() { scanf("%s", s); n = strlen(s); fo...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(b, b + n); int k = *min_element(a, a + n); bool bl = true; for (int i = 0; i < n...
3
#include<bits/stdc++.h> using namespace std; long long sum,n,q,tong[233333]; int main(){ ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin>>n; for(long long i=1,x;i<=n;i++)cin>>x,tong[x]++,sum+=x; cin>>q; while(q--){ long long b,c; cin>>b>>c; sum=sum-b*tong[b]+c*tong[b]; tong[c]+=tong[b]; tong[b]=0; ...
0
#include <stdio.h> int main(){ int x=0; char buf[5]; scanf("%s", buf); for (int i = 0; buf[i]; ++i){ if (buf[i] == '+') ++x; else --x; } printf("%d\n", x); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; string s; cin >> s; long long int maxlen = 1; for (int i = 1; i < n; ++i) { if (s[0] == s[i]) { long long int a = 0, b = i; while (a < i && b < n && s[a] == s[b]) { a++; b++; } i...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; mt19937 rnd(time(nullptr)); long long mod; int ppow(int first, int second) { int res = 1; while (second) { if (second & 1) res = res * 1LL * first % mod; first = first * 1LL * first % mod; second >>= 1LL; } return res % mod; } ...
4
#include <bits/stdc++.h> using namespace std; int main() { double h, m, s, t1, t2; cin >> h >> m >> s >> t1 >> t2; if (h == 12) h = 0; s = s * 6; m = m * 6 + s / 60; h = h * 30 + m / 12; int flag = 0; t1 *= 30, t2 *= 30; if (t1 > t2) swap(t1, t2); if (s <= t2 && s >= t1) flag++; if (h <= t2 && h >...
2
#include <bits/stdc++.h> using namespace std; const long long mx1 = 1e6 + 20, mx2 = 1e7 + 2; const long long mod = 1e9 + 7; const int imf1 = 1 << 31, inf1 = ~imf1; const long long imf2 = 1LL << 63, inf2 = ~imf2; int main() { long long a, b, c = 0; cin >> a >> b; while (b) { c = c * 10 + b % 10; b /= 10; ...
1
#include <bits/stdc++.h> using namespace std; bool vis[1111][1111]; int a[1111][1111]; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int fa[1111111]; int getfa(int x) { if (fa[x] == x) return x; else return fa[x] = getfa(fa[x]); } void Union(int x, int y) { int fx = getfa(x); int fy = getfa(y); ...
5
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)1e9 + 1; const long long INF = (long long)5e18; const long long MOD = 998244353; long long _abs(long long x) { return x < 0 ? -x : x; } long long add(long long x, long long y) { x += y; return x >= MOD ? x - MOD : x; } long long sub(long...
5
#include <bits/stdc++.h> #pragma GCC target("sse4.2") using namespace std; bool home = 1; signed realMain(); signed main() { home = 0; if (home) { freopen("tony_stark", "r", stdin); } else { ios::sync_with_stdio(0); cin.tie(0); } realMain(); } const int M = (int)1e9 + 7; int add(int a, int b) { ...
3
#include <bits/stdc++.h> using namespace std; #define ll long long int main(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); int t; cin >> t; while(t--) { ll n, res = 0; cin >> n; vector <ll> v(n + 1); for(int i = 1; i <= n; i++) cin >> v[i]; for(int i = 1;...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n, j = 1; string x; cin >> n >> x; for (int i = 1; i <= n; i += j) { cout << x[i - 1]; j++; } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; long long a[1500]; long long b[1500]; long long ai[1500]; long long bi[1500]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; long long maxx = 0; for (int x = 0; x < n; +...
1
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k, i; cin >> n >> k; vector<int> v(n); for (i = 0; i < n; i++) { v[i] = i + 1; } if (k == 0) { for (i = 0; i < n; i++) { cout << v[i] << " "; } return; } if (k == n - 1) { reverse(v.begin(), v.end()); ...
1
#include <bits/stdc++.h> const double PI = acos(-1.0); using namespace std; const int Max = 10055; int gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); } bool com(string x, string y) { return x + y < y ...
2
#include <bits/stdc++.h> using namespace std; int n, u, v, a[120000]; int main() { scanf("%d%d%d", &n, &u, &v); for (int i = 1; i <= n; i++) scanf("%d", a + i); sort(a + 2, a + n + 1); long long sum = a[1]; for (int i = 2; i <= n; i++) { sum += a[i]; if (sum * v > (long long)a[1] * u) { printf("...
2
#include <bits/stdc++.h> using namespace std; template <typename T> bool get_int(T &x) { char t = getchar(); bool neg = false; x = 0; for (; (t > '9' || t < '0') && t != '-' && t != EOF; t = getchar()) ; if (t == '-') neg = true, t = getchar(); if (t == EOF) return false; for (; t <= '9' && t >= '0'; ...
5
#include <bits/stdc++.h> using namespace std; int cnt[27]; int ans[27]; int main() { memset(cnt, 0, sizeof(cnt)); memset(ans, 0, sizeof(ans)); string s, p; cin >> s >> p; if (p.size() > s.size()) { cout << 0 << endl; return 0; } int sum = 0; for (int i = 0; i < p.size(); i++) { if (s[i] != '...
3
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9, maxn = (int)1e5 + 5; const double eps = (double)1e-8; const int mod = (int)1000000007; int a[maxn], b[maxn]; int fa(int l, int r) { int ans = a[l]; for (int i = (l + 1); i < (r); i++) ans = ans | a[i]; return ans; } int fb(int l, int r) { i...
1
#include <bits/stdc++.h> using namespace std; int main() { int p1, p2, p3, p4, a, b, i, c = 0; cin >> p1 >> p2 >> p3 >> p4 >> a >> b; for (i = a; i <= b; i++) { if (i == ((((i % p1) % p2) % p3) % p4)) c++; } cout << c; return 0; }
1
#include <bits/stdc++.h> using namespace std; inline void _() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); } void __() {} inline void ___(char *i, char *j) { freopen(i, "r", stdin); freopen(j, "w", stdout); } template <class T1> bool tk(T1 &e1) { if (cin >> e1) return true; return false; } template ...
3
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef double db; typedef pair<int, int> pii; typedef pair<int, ll> pil; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; typedef pair<pii, int> piipi; typedef pair<int, pii> pipii; typedef pair<pii, pii> piipii; typedef ...
5
#include <bits/stdc++.h> using namespace std; const int N = 310; vector<int> s[8]; int n; int tar[N], chk[N]; inline int read() { int x = 0; for (int i = 0; i < 3; i++) { int s = 0; scanf("%d", &s); x = x * 2 + s; } return x; } vector<int> t8; vector<pair<int, int> > mp; bool B[N]; int cur[N]; int g...
4
#include <bits/stdc++.h> using namespace std; int i, j, k, n, m, l, r, ql, qr; int w[100010], an; int main() { scanf("%d%d%d%d%d", &n, &l, &r, &ql, &qr); for (i = 1; i <= n; i++) scanf("%d", &w[i]), w[i] += w[i - 1]; an = 2147483647; for (i = 0; i <= n / 2; i++) { int A = w[i] * l + (w[n] - w[n - i]) * r; ...
1
#include<bits/stdc++.h> using namespace std; int main(){ long long i,j,k,n,c=0; cin>>n; long long a[n]; for(i=0;i<n;i++){ cin>>a[i]; } for(i=1;i<n;i++){ if(a[i]<a[i-1]){ c += a[i-1]-a[i]; a[i] = a[i-1]; } } cout<<c; }
0
#include <bits/stdc++.h> #define range(i, a, b) for(int i = (a); i < (b); i++) #define rep(i, a) range(i, 0, a) using namespace std; int n, a, b, c, x, y[110]; int main() { while (cin >> n >> a >> b >> c >> x, n) { rep (i, n) cin >> y[i]; int cnt = 0, index = 0; while (cnt < 10001) { if (x == y[index]) inde...
0
#include<bits/stdc++.h> #include<vector> #include<deque> #include<list> #define rep(i,n) for(ll i=0;i<n;++i) #define rrep(i,n) for(int i=n-1;i>=0;--i) #define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} #define MAX_N 1002 #define i197 1000000007 using namespace std; typedef long long ll; typedef pai...
0
#include <bits/stdc++.h> using namespace std; int N,K; int dx[2] = {1,-1}; const int INF = 2000000000; int main(){ cin >> N >> K; int x[N]; int d[N]; for(int i=0;i<N;i++){ cin >> x[i]; d[i] = abs(x[i]); } int ans=INF; for(int i=0;i<N-K+1;i++){ int mid = abs(x[i] - x[i+K-1]); ans = min(min(d[i],d[i...
0
#include <bits/stdc++.h> int main() { int i, j, k, n, a, b, u; scanf("%d", &n); scanf("%d", &u); u = 7 - u; k = 1; scanf("%d%d", &a, &b); for (i = 1; i < n; i++) { scanf("%d%d", &a, &b); if (u == a || u == b) k = 0; a = 7 - a; b = 7 - b; if (u == a || u == b) k = 0; u = 7 - u; } ...
1
#include <bits/stdc++.h> #pragma GCC optimize("O2") #pragma GCC target("sse3", "sse2", "sse") #pragma GCC target("avx", "sse4", "sse4.1", "sse4.2", "ssse3") #pragma GCC target("f16c") #pragma GCC optimize("inline", "fast-math", "unroll-loops", \ "no-stack-protector") #pragma GCC optimize("Ofast,no-...
4
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb(x) push_back(x) #define mp(a, b) make_pair(a, b) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define lscan(x) scanf("%I64d", &x) #define lprint(x) printf("%I64d", x) #define rep(i, n) for (ll i = 0; i < (n); i++) #...
5
#include <bits/stdc++.h> using namespace std; mt19937_64 mt(time(0)); const int MAXN = 5e5 + 10; struct Item { bool head; int len = 0; int8_t type[2] = {}; int in = 0; int cnt[2] = {}; Item() = default; Item(int h) { head = h; len = 1; type[1 - h] = 1; cnt[1 - h] = 1; } }; string s; Item...
6
#include <bits/stdc++.h> using namespace std; #define modulo 998244353 #define mod(mod_x) ((((long long)mod_x+modulo))%modulo) #define Inf 1000000000 int main(){ int H,W; cin>>H>>W; vector<string> grid(H); for(int i=0;i<H;i++)cin>>grid[i]; vector<string> R(H,string(W,'.')),B(H,string(W,'.')); for(int i...
0
#include <map> #include <iostream> #include <string> using namespace std; int main() { map<char, char> mp; char a,b,c; string x; int n; cin >> n; do{ mp.clear(); x.clear(); do{ cin >> a >> b; mp[a] = b; } while (--n); cin >> n; do{ cin >> c; if (mp[c] != NULL) { x += mp[c]; } ...
0
#include<cstdio> #include<algorithm> using namespace std; const int N=2005; int n,m,Q,i,j,a[N][N],f1[N][N],f2[N][N]; char s[N][N]; int read(){ char c=getchar();int k=0;for (;c<48||c>57;c=getchar()); for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k; } void write(int x){if (x>9) write(x/10);putchar(x%10+48);...
0
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; if (n == 1) { cin >> n; cout << (n ? "YES" : "NO"); } else { bool zero = 0; for (int i = 0; i < n; ++i) { int a; cin >> a; if (!a ...
1
#include <bits/stdc++.h> using namespace std; int main(){ int n,m,k,ans=0; cin>>n>>m; for(int i=0;i<n;i++){ cin>>k;ans+=(k>=m); } cout<<ans; return 0; }
0
#include <bits/stdc++.h> using namespace std; const unsigned long long B = 100000007; const double pi = acos(-1.0); deque<int> dq1, dq2, dq3; int main() { int k, n1, n2, n3, t1, t2, t3; cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3; int cur_t = 0; while (k--) { if (dq1.size() < n1 && dq2.size() < n2 && dq3.s...
4
#include <bits/stdc++.h> using namespace std; long long n, p[200005], anw = 0, mul = 1, hd[200005]; const long long mod = 998244353; long long pw(long long a, long long b) { long long ret = 1; while (b) { if (b & 1) ret = ret * a, ret = ret % mod; b >>= 1, a = a * a, a = a % mod; } ret = ret % mod; re...
3
#include <bits/stdc++.h> using namespace std; map<int, int> m; int a[2000003], b[2000003]; int main() { long long n, i, j; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; m[a[i]] = 1; } for (i = 0; i < n; i++) { cin >> b[i]; m[b[i]] = 1; } int cnt = 0; for (i = 0; i < n; i++) for (j...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 9; const int maxm = 2e5 + 9; const long long inf = 1e18; const int mod = 1e6; int n, m; int id[maxn]; namespace IO { inline int read() { int a = 1, b = 0; char c = getchar(); while (c > '9' || c < '0') { if (c == '-') a = -1; c = getchar...
4
#include <bits/stdc++.h> void swap(int *x, int *y); int main() { int a[100], b[100], i, j, n, k, max_sum, s, l, r, bools_max_ind, max_ind; scanf("%d", &n); for (i = 0; i < 100; ++i) a[i] = b[i] = 0; max_ind = -1; bools_max_ind = 0; for (i = 0; i < n; ++i) { scanf("%d %d", a + i, b + i); if (*(a + i)...
1
#include <bits/stdc++.h> using namespace std; const int N = 5050; long long f[20]; int ans[20] = {0, 1, 0, 18, 0, 1800, 0, 670320, 0, 734832000, 0, 890786230, 0, 695720788, 0, 150347555, 0}; const long long mod = 1000000007; int n, m, num; void dfs(int pos, int B, int C) ...
4
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653589793238; template <typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vector) { for (size_t i = 0; i < vector.size(); ++i) { os << vector[i] << " "; } return os; } template <typename T> std::ostream& operato...
3
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,a) for(int i=0;i<(a);i++) const ll MOD=1000000007; int main(){ int N; cin>>N; int sum=0; set<int> s; rep(i,N){ int a; cin>>a; sum^=a; // a^(a-1)=111・・・111 s.insert(__builtin_popcount(a^(a-1))); } int cnt=0; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, a; set<int> s; cin >> n; for (int i = 0; i < n; ++i) { cin >> a; if (a != 0) s.insert(a); } cout << s.size() << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const int maxn = 112345; pair<int, int> arr[maxn]; int n; int preMin[maxn], preMax[maxn], sufMin[maxn], sufMax[maxn]; int passed(double mid) { int j = 1; for (int i = 1; i <= n; i++) { while (j <= n && 1.0 * (arr[j].first - arr[i].first) <= 2.0 ...
4
#include <bits/stdc++.h> using namespace std; long long read() { long long a = 0, b = getchar(), c = 1; while (!isdigit(b)) c = b == '-' ? -1 : 1, b = getchar(); while (isdigit(b)) a = a * 10 + b - '0', b = getchar(); return a * c; } vector<int> g[500]; int n, m, k, ans, l, r, e[10000]; bool b[10000]; void dfs(...
4
#include <bits/stdc++.h> long long list[100]; long long del[100]; char s[5][10] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; int main() { long long now = 5; int ptr = 1; list[0] = 1; while (now <= 1000000000) { list[ptr] = list[ptr - 1] + now; ++ptr; now *= 2; } long long n; scanf("%...
1
#include <bits/stdc++.h> using namespace std; const int N = 15; int n, m, p[N]; struct po { int x, y; } a[N], b[N]; bool g[N * N][N * N]; double mult(po a, po b, po c) { return (a.x - c.x) * (b.y - c.y) - (b.x - c.x) * (a.y - c.y); } bool inters(po aa, po bb, po cc, po dd) { if (max(aa.x, bb.x) < min(cc.x, dd.x))...
5
#include <bits/stdc++.h> using namespace std; string ITS(long long x) { string s = ""; while (x > 0) { s += (char)(x % 10 + '0'); x /= 10; } string t = ""; for (int i = s.size() - 1; i > -1; i--) t += s[i]; return t; } long long inf = 1e18; long long mod = 1e9 + 7; const long long M = 2e5; long long...
3
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f; const double eps = 1e-6; const long long mod = 1000000007; namespace fastio { char in[100000]; long long itr = 0, llen = 0; char get() { if (itr == llen) llen = fread(in, 1, 100000, stdin), itr = 0; if (llen == 0) return EOF; return i...
5
#include <bits/stdc++.h> using namespace std; char pk[1000002]; int main() { while (~scanf("%s", pk)) { int slen = strlen(pk); int mnum = 0, ans = 0, pos = 0; while (pos < slen && pk[pos] == 'F') ++pos; for (int i = pos; i < slen; ++i) { if (pk[i] == 'M') ++mnum; else ans =...
4
#include <bits/stdc++.h> using namespace std; struct rebro { int l, r; int x, y; int prop; }; rebro a[3003]; rebro b[3003]; int n, m; void mergesort(rebro *a, rebro *b, int n) { int i, i0, i1, iRight, iEnd, width, j; for (width = 1; width < n; width *= 2) for (i = 0; i < n; i += width * 2) { i0 = i;...
4
#include <bits/stdc++.h> using namespace std; long long f[20], jv, n; inline long long pow(long long, long long), take(long long); int main() { long long s, ans(0); int i, j, li; scanf("%lld%lld", &n, &s), li = (1 << n) - 1; for (i = 0; i < n; ++i) scanf("%lld", &f[i]); for (i = jv = 1; i < n; ++i) (jv *= i) ...
5
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3fll; const int MAX = 3e5 + 5; const int MAXN = 1000000; const int MAX_N = MAX; const long long MOD = 1e9 + 7; const long double pi = acos(-1.0); int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } templ...
4
#include <bits/stdc++.h> using namespace std; void FAST() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int Rselect(vector<int>&, int, int, int); int partition(vector<int>&, int, int); template <typename T> ostream& operator<<(ostream& stream, const vector<T>& vec) { for (auto& i : vec) { stream << ...
2
#include <iostream> #include <stdio.h> #include <vector> #include <string> #include <algorithm> #include <map> using namespace std; typedef long long int ll; const ll mod = 1000000007; const ll lim = 100000 + 1; ll solve(void); int main(void) { cout << solve() << endl; return 0; } ll solve(void) { ll N, T;...
0
#include <bits/stdc++.h> int n, m, a, b, v[1111], d[1111]; int min(int a, int b) { if (a <= b) return a; else return b; } int main() { int i; while (scanf("%d%d", &n, &m) != EOF) { for (i = 1; i <= n; i++) scanf("%d", &v[i]); int ans = 0; for (i = 0; i < m; i++) { scanf("%d%d", &a, &b)...
3
#include <iostream> using namespace std; int main(void){ string s; cin>>s; int w; cin>>w; for(int i=0;i<s.size();i+=w){ cout<<s[i]; } }
0
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long INF = 4e18; const int inf = 2e9; const int N = 1e5 + 5; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a * b / gcd(a, b); } int n, k, h, m[N], v[N], ans[N], pos[N]; bool by(int lef, int r...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") using namespace std; const int INF = int(1e9), mod = 10056, N = int(1e6) + 5; int second, b; pair<int, int> a[N]; pair<int, int> c[N]; int main() { ...
2
#include <bits/stdc++.h> using namespace std; void test_case() { int n, m; cin >> n >> m; vector<unsigned long long> v1(n), v2(m); for (auto &x : v1) cin >> x; for (auto &x : v2) cin >> x; sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); unsigned long long best = numeric_limits<unsigned long long...
2
#include <bits/stdc++.h> #include <iostream> #include <vector> #include <algorithm> #include <string> #define range(x) x.begin(), x.end() #define pb push_back using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef unsigned long long ull; void print(vector<int> &a) { for...
1
#include <bits/stdc++.h> using namespace std; long long a[300005]; long long b[300005]; long long alla[300005]; long long allb[300005]; long long suma1[300005]; long long suma2[300005]; long long sumb1[300005]; long long sumb2[300005]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) scanf("%lld", &a[i]...
3
#include <bits/stdc++.h> using namespace std; int N, M; const int NMax = 100005; vector<pair<int, int> > G[NMax]; bool Use[NMax]; void Read() { scanf("%d%d", &N, &M); for (int i = 1; i <= M; i++) { int x, y; scanf("%d%d", &x, &y); G[x].push_back(make_pair(y, i)); G[y].push_back(make_pair(x, i)); }...
3
#include <bits/stdc++.h> using namespace std; int C[205][205], f[2][55][55][102]; int n, m, K, k, mx, i, j, r, prv, nxt, ans, mod = 1000000007; void add(int &x, int y) { x += y; if (x >= mod) x -= mod; } int main() { scanf("%d%d%d", &n, &m, &K); C[0][0] = 1; for (i = 0; i <= n; i++) for (j = 0; j <= i; j+...
5
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool read(T& x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c) && (c != '-') && (c != EOF)) c = getchar(); if (c == EOF) return 0; if (c == '-') f = -1, c = getchar(); while (isdigit(c)) { x = x * 10 + (c & 15); ...
3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long int n, k; cin >> n >> k; long long int rem = max(n - (2ll * k), 0ll); cout << ((n * (n - 1ll)) / 2ll) - ((rem * (rem - 1ll)) / 2ll) << '\n'; return 0; }
2
#include <bits/stdc++.h> using namespace std; int n; int mat[2][4] = {{-1, 0, 0, 1}, {0, -1, 1, 0}}; long long x[33], y[33]; vector<vector<int> > v; void dfs(int topi, int prev, int dir, long long dist) { if (v[topi].size() > 4) { cout << "NO" << endl; exit(0); } for (int i = 0, j = 0; i < v[topi].size();...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 901; int n, r; int s; vector<pair<int, int> > p; vector<int> candidate; int res = 0; vector<int> ret; int getDist(int x1, int x2, int y1, int y2) { return ((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)); } void backtrack(int start, int len, int dist) { ...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; inline long long power(int a, int b) { if (b == 0) return 1LL; if (b == 1) return 1LL * a; long long tmp = power(a, b / 2); tmp = tmp * tmp % mod; if (b & 1) tmp = tmp * a % mod; return tmp; } int main() { int n; long long a...
3
#include <bits/stdc++.h> using namespace std; int main() { int h, m, a; char c; cin >> h >> c >> m >> a; int hh = a / 60, mm = a % 60; while (mm--) { m++; if (m == 60) m = 0, hh++; } while (hh--) { h++; if (h == 24) h = 0; } printf("%.2d:%.2d", h, m); }
2
#include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <map> #include <utility> #include <set> #include <iostream> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <stack> #include <queue> #include <numeric> #include <cstring> using n...
0
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; using std::string; bool isZeroString(string Str) { for (int i = 0; i < Str.length(); i++) if (Str[i] == '1') return false; return true; } bool isChangable(string A, string B) { if (A == B) return true; if (A.length() != 1 && (A.lengt...
3
#include <bits/stdc++.h> using namespace std; const long long N = 500000; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> v(n), left(n), right(n); for (long long i = 0; i < n; i++) cin >> v[i]; ...
1
#include <bits/stdc++.h> const int N = 2005; using namespace std; bitset<N> f[N]; int n; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { int t; scanf("%d", &t); if (t > 0) f[i][j] = 1; } } for (int i = 1; i <= n; i++) { for (int j = 1; j ...
5
#include <bits/stdc++.h> using namespace std; unsigned int nextPowerOf2(unsigned int n) { unsigned int p = 1; if (n && !(n & (n - 1))) return n; while (p < n) p <<= 1; return p; } int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; std::vector<long long> v(n); for (lon...
3
#include <bits/stdc++.h> using namespace std; long long int inf = 1e14; long long int mod = 1e9 + 7; char en = '\n'; long long int arr[5005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int a; cin >> a; long long int cnt1 = 0; ...
2
#include <bits/stdc++.h> using namespace std; set<string> s; string str; void init() { s.clear(); } int main() { int n; while (~scanf("%d", &n)) { init(); for (int i = 0; i < n; i++) { cin >> str; string tp = ""; int len = str.size(); for (int j = 0; j < len; j++) { if (str[j...
6