solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433832795l; template <typename T> inline auto sqr(T x) -> decltype(x * x) { return x * x; } template <typename T> inline T abs(T x) { return x > T() ? x : -x; } template <typename T1, typename T2> inline bool umx(T1& a, T2 ...
2
#include<bits/stdc++.h> using namespace std; queue<int> stand[10]; int main(){ int n,m; cin>>n>>m; for(int i=0;i<m;i++){ int a,b; cin>>a>>b; if(a==1){ int mSize=100000, p=-1; for(int i=0;i<n;i++){ if(mSize>stand[i].size()){ mSize=stand[i].size(); p=i; } } stand[p].push(b); }else ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long prev, l, r, p, k; cin >> p >> k; vector<int> res; prev = p; while (1) { l = ceil(-(long double)prev / k); r = ceil((long double)(k - prev) / k); r--; if (l > r) { cout << -1; return 0; } if (l >= k || r < ...
4
#include <bits/stdc++.h> using namespace std; bool remd[200000]; bool assigned[200000]; int main() { int n, m; cin >> n >> m; if (m < n - 1) { cout << "No" << endl; return 0; } vector<pair<long long, long long> > ro; vector<pair<pair<long long, long long>, int> > to; for (int i = 0; i < (n); ++i) ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, x = 0, y, i; scanf("%d", &n); for (i = 1; i <= n; i++) { x += (i % 3 != 0); y = (i % 3 == 0) ? 3 : 0; printf("%d %d\n", x, y); } }
3
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y, i; cin >> n >> x >> y; string s; int ans = 0; cin >> s; for (i = n - 1; i >= 0; i--) { if (n - i - 1 == x) { break; } else if (n - i - 1 == y) { if (s[i] == '0') { ans++; } } else { if (s[i] =...
1
#include <bits/stdc++.h> using namespace std; int main() { int k; int s[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; cin>>k; cout<<s[k-1]<<endl; }
0
#include <bits/stdc++.h> using namespace std; string s; const int N = 201000; int pre[N]; inline int f(char x) { return x == '0' ? 0 : 1; } int main() { int T; cin >> T; while (T--) { cin >> s; int len = s.length(); int ans = 0; pre[0] = 0; for (int i = 1; i < len; i++) pre[i] = s[i - 1] == '0...
3
#include <bits/stdc++.h> using namespace std; int main() { int t, a, b, x, y, m; cin >> t; for (int i = 0; i < t; i++) { cin >> a >> b >> x >> y; m = 0; m = max(max(max(max(m, ((a - x - 1) * b)), max(m, (x * b))), max(m, ((b - y - 1) * a))), max(m, (y * a))); cout << m ...
1
#include <cstdio> #include <algorithm> #include <vector> int main() { size_t n; scanf("%zu", &n); std::vector<int> a(n); for (auto& ai: a) scanf("%d", &ai); printf("%td\n", std::min_element(a.begin(), a.end())-a.begin()+1); }
0
#include <bits/stdc++.h> using namespace std; inline int nxt() { int x; scanf("%d", &x); return x; } const int L = 21; const int N = 1 << L; struct Max2 { int x, y; Max2() : x(-1), y(-1) {} void refresh(int z) { if (z > x) { y = x; x = z; } else if (z > y) { y = z; } } void...
6
#include <bits/stdc++.h> using namespace std; const long long maxN = 1e2 + 1; int p, f, ans; pair<int, int> person[maxN]; int main() { cin >> p >> f; for (int i = 0; i < p; i++) cin >> person[i].first >> person[i].second; for (int i = p - 1; i > -1; i--) ans = max(ans + (i == p - 1 ? f : person[i + 1].first) ...
1
#include<bits/stdc++.h> using namespace std; int main(){ int a,z,x; cin>>a>>z>>x; cout <<x<<" "<<a<<" "<<z; }
0
#include <bits/stdc++.h> using namespace std; inline int qr() { int ret = 0, f = 0, c = getchar(); while (!isdigit(c)) f |= c == 45, c = getchar(); while (isdigit(c)) ret = ret * 10 + c - 48, c = getchar(); return f ? -ret : ret; } const int maxn = 1e5 + 5; const int inf = 0x3f3f3f3f; int r[maxn], siz[maxn], st...
5
#include <bits/stdc++.h> using namespace std; const long long maxVal = 500 * 500; bool arr[500 + 50][500 + 50][500 + 50]; int main() { iostream::sync_with_stdio(0); int n, k; cin >> n >> k; vector<int> inp(n); for (int i = 0; i < n; i++) { cin >> inp[i]; } arr[0][0][0] = 1; for (int i = 0; i < n; i+...
3
#include <bits/stdc++.h> using namespace std; long long n, r; vector<vector<long long> > v; long double solve() { vector<vector<long double> > dp(n + 1, vector<long double>(r + 1, 0.l)); long double lo = 0, hi = (1e20), mid, eps = 1e-11; while ((hi - lo) > eps) { mid = (lo + hi) / 2.l; for (int i = n - 1;...
3
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long lli; typedef vector<lli> vll; typedef pair<char,lli> pcl; typedef vector<pcl> vec; lli partition(vec& a,lli p,lli r){ lli x = a[r].second; lli i = p; for(lli j = p;j < r;j++){ if(a[j].second <= x){ swap(a[j],a[i...
0
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long a, b; cin >> a >> b; long long mod = a % b; long long ans = b - mod; if (mod == 0) cout << 0 << endl; else cout << ans << endl; } }
4
#include<iostream> using namespace std; int main(){ char c; cin>>c; if(c=='A') cout<<'T'; else if(c=='T') cout<<'A'; else if(c=='C') cout<<'G'; else if(c=='G') cout<<'C'; return 0; }
0
#include <bits/stdc++.h> using namespace std; const double INF = 1e9; const int N = 52; double dp[N][N][N]; int n, a[N], b[N], id[N]; int cmp(int x, int y) { return a[x] > a[y]; } void M(double& x, double y) { x = min(x, y); } int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; id[i] = i; }...
6
#include <bits/stdc++.h> using namespace std; const int n = 1e5+5; int N, M; vector<int> G[n]; bool vis[n]; bool col[n]; void DFS(int v, int pr, bool c){ col[v] = c; vis[v] = true; for(int j : G[v]){ //int j = p.first; //bool cg = p.second; if(!vis[j] && j != pr){ DFS(j, v, c); } } } int main(){ cin >...
0
#include<bits/stdc++.h> using namespace std; int main(){ string S,T; while(cin >> S >> T, S != "0" && T != "0"){ set<char> st; for(char& c : S) st.insert(c); int hit = 0; int blow = 0; for(int i = 0; i < T.size(); i++){ if(S[i] == T[i]) hit++; el...
0
#include <bits/stdc++.h> using namespace std; bool Can(long long n, long long m, long long c) { if (c / 2 < n) return false; if (c / 3 < m) return false; long long odd_threes = c / 3 - c / 6; if (m <= odd_threes) { m = 0; return true; } m -= odd_threes; long long even_used = m; if (c / 2 - even_...
3
#include<iostream> #include<string> using namespace std; int main(){ string a; while(getline(cin,a)){ int i=0; while(true){ bool t=false; if(a[i]=='@'){ for(int j=0;j<a[i+1]-'0';j++) cout<<a[i+2]; i+=2; if(i>=a.size()) break; t=true; } if(i>=a.size()) break; if(t==false...
0
#include <bits/stdc++.h> using namespace std; namespace fft { struct num { long double x, y; num() { x = y = 0; } num(long double x, long double y) : x(x), y(y) {} }; inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); } inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); } i...
3
#include <bits/stdc++.h> using namespace std; int a[101]; int b[101]; int storage[200001]; int storage2[200001]; int* value = storage + 100000; int* prevalue = storage2 + 100000; int n, k; int main() { scanf("%d%d", &n, &k); int gtzero = 0, lezero = 0; for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i ...
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const int INF = 1000001000; const long long INFLL = INF * 1LL * INF; const int mod = 1000 * 1000 * 1000 + 7; const int mod9 = 1000 * 1000 * 1000 + 9; const int modr = 99990001; const long double PI = 3.1415926535897932385; templat...
1
#include <bits/stdc++.h> using namespace std; int n, m, k; struct tuhla { int vertex; long long cost; }; vector<struct tuhla> v[100007]; long long dist[100007]; int used[100007]; int prv[100007]; bool operator<(struct tuhla p1, struct tuhla p2) { return (p1.cost > p2.cost); } priority_queue<struct tuhla> q; void di...
2
#include<iostream> using namespace std; int main(void) { int w; cin>>w; cout<<w*32<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { long a, b, c; cin >> a >> b >> c; cout << min(min(a + b + c, 2 * (a + b)), min(2 * (a + c), 2 * (b + c))); }
1
#include <bits/stdc++.h> using namespace std; const int maxn = 52; const int mod = 1000000007; int n, k, li, hi; struct node { int x, y, id; }; long long dp[maxn][maxn][2]; long long way[maxn][maxn][2]; long long c[maxn][maxn]; void bfs() { memset(dp, -1, sizeof(dp)); memset(way, 0, sizeof(way)); dp[li][hi][0] ...
5
#include <bits/stdc++.h> using namespace std; int main(){ string S, T; cin >> S >> T; int ans = T.length(); for(int i=0; i<S.length()-T.length()+1; ++i){ int cnt = 0; for(int j=0; j<T.length(); ++j){ if(T[j]!=S[j+i]) ++cnt; } ans = min(ans,cnt); } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, L; int a[100010]; int memo[100010]; int f(int x) { if (x == 0 || x == n + 1 || memo[x]) return memo[x]; int res = L - a[x]; if (a[x - 1] > a[x] && a[x] > a[x + 1]) { res += f(x - 1); } else if (a[x - 1] < a[x] && a[x] < a[x + 1]) { res += f(x + 1);...
0
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9 + 100; const int maxN = 5010; int dp[maxN][maxN / 2][2][2]; int a[maxN]; int n; int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; a[0] = -(int)1e9; a[n + 1] = -(int)1e9; for (int i = 0; i ...
3
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const int INF = 2e9; const long long LNF = 9e18; const int mod = 1e9 + 7; const int maxn = 2e3 + 10; int n, m, k; bool val[maxn], pos[maxn]; long long C[maxn][maxn], A[maxn]; void init() { scanf("%d", &n); for (int i = 1; i <= n; i++) { int ...
3
#include <bits/stdc++.h> using namespace std; struct node { int level; vector<int> child; }; int nodes_per_level[100001] = {0}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, p, sum = 1; cin >> n; node a[n + 1]; for (int i = 2; i <= n; i++) { cin >> p; a[p].child.push_back(...
4
#include <bits/stdc++.h> using namespace std; int main() { long n, m; cin >> n >> m; long A = 2l * n; long B = 3l * m; long C = min(A, B) / 6; for (int c = 0; c < C; c++) { if (A <= B + 1) { A += 2; } else { B += 3; } C = min(A, B) / 6; } cout << max(A, B) << endl; }
3
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { string str, ans; int n, k; cin >> n >> k; cin >> str; ans = str; for (int i = k; i < n; i++) ans[i] = ans[i - k]; if (str <= ans) { cout << ans.length() << endl; cout << ans; return; } for (int i = k - 1; i ...
3
#include <bits/stdc++.h> using namespace std; char s[12][12]; bool check() { for (int i = 0; i < 10; i++) { int cnt1 = 0; for (int j = 0; j < 10; j++) { if (s[i][j] == 'X') cnt1++; else { if (cnt1 >= 5) return true; cnt1 = 0; } } if (cnt1 >= 5) return true; ...
2
#include <bits/stdc++.h> using namespace std; int main(){ map<char,int> dic; char tmp; int cnt=0; while(cin>>tmp){ dic[tmp]++; cnt++; } if(cnt==dic.size())cout <<"yes"<<endl; else cout <<"no"<<endl; }
0
#include <bits/stdc++.h> using namespace std; int A[300005], cum[300005], f[300005], fcum[300005], mark[300005]; vector<pair<int, int> > queries; int mod(int a) { a %= 1000000009; if (a < 0) a += 1000000009; return a; } int main() { int n, q, type, l, r, a, b, ans, pos; scanf("%d %d", &n, &q); for (int i = ...
3
#include <bits/stdc++.h> using namespace std; int main() { cin.sync_with_stdio(0); cin.tie(0); int x, y, z, t1, t2, t3; cin >> x >> y >> z >> t1 >> t2 >> t3; int walk = abs(x - y) * t1, elv = abs(x - z) * t2 + abs(x - y) * t2 + 3 * t3; cout << (walk < elv ? "NO\n" : "YES\n"); }
1
#include <bits/stdc++.h> using namespace std; int a[][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9, -1, 0, -1}; char h[101]; int main() { int q, w, e, r, t, sum = 0; int e1, r1, c, v, c1, v1; cin >> q; cin >> h; for (e = 0; e < 4; e++) { for (r = 0; r < 3; r++) { e1 = e; r1 = r; if (a[e1][r1] == -1) ...
1
#include <bits/stdc++.h> using namespace std; const double Pi = acos(-1.0); pair<int, int> toPoint[100011]; map<pair<int, int>, int> toIndex; int N, lo[100011]; bool check(pair<int, int> a) { if (!toIndex[a]) return false; for (int dx = -1; dx <= 1; dx++) { pair<int, int> n(a.first + dx, a.second + 1); int ...
2
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") const long long int inf = 9e18; const long double pi = 2 * acos(0.0); const int N = 1000005; long long int tes, n; vector<long long int> sieve(N, 0); void si() { siev...
6
#include <stdio.h> int n, v, a[25][2], r; bool f[25]; void p1(int u) { if(!~u) return; printf(" %d", u), p1(a[u][0]), p1(a[u][1]); } void p2(int u) { if(!~u) return; p2(a[u][0]), printf(" %d", u), p2(a[u][1]); } void p3(int u) { if(!~u) return; p3(a[u][0]), p3(a[u][1]), printf(" %d", u); } int main() { scanf("%d", &n)...
0
#include <bits/stdc++.h> using namespace std; const int mod = 1e8; struct bigNum { int a[20], len; bigNum() { len = 0; memset(a, 0, sizeof a); } inline void operator=(int x) { memset(a, 0, sizeof a); a[0] = x; len = 1; } inline void print() { cout << a[len - 1]; for (int i = len ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, k, x; cin >> n >> k; int *count = new int[k + 5]; for (int i = 0; i < k + 5; i++) count[i] = 0; for (int i = 0; i < n; i++) { cin >> x; count[x]++; } int coins = 0; while (count[k] != n) { for (int i = k - 1; i >= 1; i--) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); int t, i, j; double n, a, b, lo, hi, mid, mul; cin >> t; for (i = 0; i < t; i++) { cin >> n; lo = 0.0; hi = n; for (j = 0; j <= 100; j++) { mid = (lo + hi) / 2.0; ...
3
#include <bits/stdc++.h> using namespace std; const int MX = 100007; vector<int> liczby; int N; void dane() { cin >> N; int i; for ((i) = 0; (i) < (int)(N); (i)++) { int a; cin >> a; liczby.push_back(a); } } int main() { dane(); int pocz = 0; int kon = N - 1; pocz++; kon--; int czeko1 = ...
3
#include <bits/stdc++.h> using namespace std; long long x, y, d[100 + 5]; void Process(); int main() { Process(); return 0; } long long Make(long long x, long long p, long long q) { long long k = 0ll; for (long long i = 1; i <= q; ++i) k = (k << p) + x; return k; } long long Check(long long p, long long q, lo...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using db = double; void out(int x, int y) { printf("%d %d\n", x + 1, y + 1); } int n; void foo(int x) { for (int i = 0; i < n; ++i) { int j = (x - i + n) % n; if (i < j) out(i, j); } } int main() { cin >> n; if (...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int n, k, p; vector<int> adj[maxn]; int h[maxn]; int total[maxn]; int hmax; void dfs(int v, int par) { ++total[h[v]]; hmax = max(hmax, h[v]); for (auto u : adj[v]) if (u != par) { h[u] = h[v] + 1; dfs(u, v); } } int used[...
4
#include <bits/stdc++.h> using namespace std; void Weapons19() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); } long long t = 0; set<pair<long long, long long>> w; void dfs(char k, char p, vector<string> &v, long long n, long long m, long long a, long long b) { if (a < 0 || b < 0 || a + 1 > n |...
3
#include <bits/stdc++.h> using namespace std; int edge(int n, int x, int y) { if (y == 0) return x; if (y == n) return 2 * n + n - x; if (x == n) return n + y; if (x == 0) return 3 * n + n - y; return -1; } int main() { int n, x1, y1, x2, y2; cin >> n >> x1 >> y1 >> x2 >> y2; int e1, e2; e1 = edge(n, ...
1
#include<cstdio> #define MAX 50 int Pre[MAX]; int In[MAX]; int Post[MAX]; int pos = 0; int p = 0; int n; void reconstruction(int l, int r) { if(l >= r) return; int root = Pre[pos++]; int m; for(int i=0; i<n; i++) { if(In[i] == root) { m = i; break; } } reconstruction(l,m); reconstruction(m+1,r); ...
0
#include<bits/stdc++.h> using namespace std; #define N 100005 typedef long long ll; ll ans[N]; int main() { string s; cin >> s; int n = s.size(); int start = 0; while(start < n){ int end = start; while(s[end] == 'R') end++; int r = end - 1; int l = end; while(s[end] == 'L') ...
0
#include <bits/stdc++.h> using namespace std; const long long int N = 1e5 + 10; long long int rangeQuery(long long int segtree[], long long int qlow, long long int qhigh, long long int low, long long int high, long long int pos) { if (qlow > qhigh) return 0; if (qlo...
3
#include <bits/stdc++.h> using namespace std; bool helper(string &s, int n, int p) { char maxi = (p - 1 + 'a'); for (int i = n - 1; i >= 0; i--) { for (char c = s[i] + 1; c <= maxi; c++) { if (i >= 1 && s[i - 1] == c) continue; if (i >= 2 && s[i - 2] == c) continue; s[i] = c; for (int j ...
1
#include <bits/stdc++.h> using namespace std; const int N = 500 + 10; struct node { int x, y; }; int n, m, deg[N][N], sum[N][N], val[N][N]; int dis[N * N], fa[N * N]; int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; string s[N]; int in(int x, int y) { return 0 <= x && x < n && 0 <= y && y < m; } int find(int x) { if...
6
#include <bits/stdc++.h> using namespace std; void File() { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } void IO() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int main() { IO(); int n; int a, b, c, ans = 0; cin >> a >> b >> c >> n; for (int i = 0; i < n; ++i) ...
1
#include <bits/stdc++.h> using namespace std; long long inline gcd(long long x, long long y) { return !y ? (long long)abs(x) : gcd(y, x % y); } long long inline lcm(long long a, long long b) { return ((long long)abs((a / gcd(a, b)) * b)); } double inline cartesian_dist(double x1, double y1, double x2, double y2) { ...
6
#include <bits/stdc++.h> using namespace std; const int64_t infll = 9223372036854775807LL; bool doQuery(int64_t x, int64_t y) { cout << 1 << " " << x << " " << y << endl; fflush(stdout); string s; cin >> s; return (s == "TAK"); } int64_t doBinSearch(int64_t l, int64_t r) { while (r != l) { int64_t m = (...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, x; cin >> n >> x; int ans = 0, now = 0; for (int i = 1; i <= n; i++) { int l, r; cin >> l >> r; now++; ans += (l - now) % x; ans += (r - l) + 1; now = r; } cout << ans; r...
1
#include<bits/stdc++.h> using namespace std; using ll = long long; const int MOD = 1e9+7; int main(){ int a,b,c,d,e,k; cin>>a>>b>>c>>d>>e>>k; cout <<(e-a>k?":(":"Yay!")<<endl; }
0
#include <bits/stdc++.h> using namespace std; long long k, p, n, m; long long dp[100][5]; long long tmp[10]; long long ok = 0; void print(char str[], long long num, long long len) { if (str[1] == 'C') { for (long long i = 2; i <= 2 * num; i += 2) { str[i] = 'A'; str[i + 1] = 'C'; } for (long l...
4
#include <iostream> using namespace std; const int INF = (1 << 30); struct Edge { int from, to, cost; }; int main() { int V, E, r; cin >> V >> E >> r; Edge edges[E]; for (int i = 0; i < E; ++i) { int s, t, c; cin >> s >> t >> c; edges[i] = Edge({s, t, c}); } int d[V]; fill(d, d + V, INF);...
0
#include <bits/stdc++.h> using namespace std; int n, p; char str[10001]; int mem[1001][1001]; char GetMin(int m1, int m2) { m1 -= 'a'; m2 -= 'a'; for (int i = 0; i < p; i++) { if (i != m1 && i != m2) return i + 'a'; } return 'a'; } string nextString(string str, bool &isGood) { isGood = true; string re...
3
#include <bits/stdc++.h> using namespace std; int multiplicativeOrder(long long a, int Q) { int res = 1; for (int i = 1;; ++i) { res = res * a % Q; if (res == 1) return i; } return -1; } int power(long long a, int b, int MOD) { int res = 1; while (b > 0) { if (b & 1) { res = res * a % MOD;...
6
#include <bits/stdc++.h> using namespace std; using ll = long long; const int sz = 2e5 + 10; bool check(ll mid, ll n, ll k) { ll pw = 1; ll sum = 0; while (mid / pw) { sum += (mid / pw); pw *= k; } return sum >= n; } int main() { ll n, k; ll l, r, mid; while (cin >> n >> k) { l = 1; r = ...
2
#include <bits/stdc++.h> using namespace std; const int INF = 1001001001; const long long INFLL = 1001001001001001001LL; template <typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template <typename T> void chmin(T& a, T b) { if (a > b) a = b; } template <typename T> v...
5
#include<bits/stdc++.h> using namespace std; #define ll long long typedef pair<ll,ll> P; typedef pair<ll,P> PP; const ll MOD = 1e9+7; int main(){ ll n,m; while(cin>>n>>m,n){ ll a[1111]; for(int i=0;i<n;i++){ cin>>a[i]; } ll ans=0; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ ll tmp=a[i]+a[j]; if...
0
#include <bits/stdc++.h> using namespace std; #define sz(x) ((int) (x).size()) #define forn(i,n) for (int i = 0; i < int(n); ++i) typedef long long ll; typedef long long i64; typedef long double ld; const int inf = int(1e9) + int(1e5); const ll infl = ll(2e18) + ll(1e10); const int mod = 86400; const int len = 10801; ...
0
#include<iostream> using namespace std; int main() { char a; cin >> a; if (a >= 'a' && a <= 'z')cout << 'a'; else cout << "A"; }
0
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long #define ull un...
2
#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 main() { string a; while(cin >> a) { string b; cin >> b; int ans = 0; rep (va, 2) { string & s = va ? a : b, & ...
0
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000, N = 300000; int n, a[N + 5], lmax[N + 5], rmax[N + 5], lmin[N + 5], rmin[N + 5], cnt[2 * N + 5]; long long ans; void solve(int l, int r) { if (l == r) { ans++; return; } int mi = (l + r) / 2; rmin[mi + 1] = rmax[mi + 1] = a[mi...
6
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long N = 200005; vector<long long> vis(N); vector<vector<long long>> adj(N); void dfs(long long v) { vis[v] = 1; for (auto i : adj[v]) { if (!vis[i]) { dfs(i); } } return; } bool isPrime(long long n) { for...
3
#include <bits/stdc++.h> using namespace std; using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int main() { fast(); long long n, k; cin >> n >> k; n++; { for (int i = 1; i < k + 1; i++) if (n % i != 0) { cout << "no"; return 0; ...
3
#include <iostream> #include <set> #include <vector> #include <algorithm> int main() { int n; while (true) { std::cin >> n; if (n==0) break; std::set<int> rem; for (int i=1; i<=n/2; i++) { rem.insert((i*i)%n); } std::vector<int> v(n/2); for (std::set<int>::iterator it1 = rem.begin(); it1 != rem.e...
0
#include <cstdio> int ls[299999]; int main() { int N; scanf("%d",&N); int ret=0; for(int i=1;i<=N;i++) scanf("%d",&ls[i]); for(int i=1;i<=N;i++) if(ls[ls[i]]==i) ret++; printf("%d\n",ret/2); return 0; }
0
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <string> #include <map> #include <queue> #include <stack> #include <algorithm> #define rep(i,j) REP((i), 0, (j)) #define REP(i,j,k) for(int i=(j);(i)<(k);++i) #define between(a,x,b) ((a)<=(x)&&(x)<=(...
0
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10, mod = 1e9 + 7; long long n, dp[2][N], d[2][N], t[2][N]; vector<long long> ch[N]; void dfs(long long v) { if (!ch[v].size()) { dp[0][v] = 0; dp[1][v] = 1; return; } for (long long i : ch[v]) dfs(i); d[0][0] = 1; for (long l...
4
#include <bits/stdc++.h> using namespace std; const int MAXM = 3000 + 10; int n, m; struct Person { int id; int p; long long c; Person() {} Person(int id, int p, int c) : id(id), p(p), c(c) {} bool operator<(const Person& a) const { return c < a.c; } } person[MAXM]; struct Party { int id; int vote; Pe...
1
#include <bits/stdc++.h> using namespace std; signed main() { long long t; cin >> t; while (t--) { long long n; cin >> n; cout << n / 2 + 1 << endl; } }
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { string st; cin >> st; int a[26] = {0}; for (int i = 0; i < st.length(); i++) { a[st[i] - 97]++; } int f = 0, s = 0, d = 0; for (int i = 0; i < 26; i++) { if (a[i] > 0) { s = i;...
1
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long INF = 1e18; long long n, m, sum = 0; vector<long long> a(n); bool f(long long k) { long long q = (n - k) / k; long long r = (n - k) % k; long long tmp = sum; long long idx = 0; for (long long i = 0; i < r; i++) { ...
4
#include <bits/stdc++.h> const int MX = 10010896; const int lmt = 3164; const int N = 10000001; int flag[MX >> 6]; long long int seg_tree[2 * N]; int n = 5; using namespace std; using namespace std::chrono; long long int extgcd(long long int a, long long int b, long long int& x, long long int& y) {...
4
#include <bits/stdc++.h> using namespace std; long long convertToNum(string s) { long long val = 0; for (int i = 0; i < (s.size()); i++) val = val * 10 + s[i] - '0'; return val; } char bu[50]; string convertToString(int a) { sprintf(bu, "%d", a); return string(bu); } long long GCD(long long x, long long y) { ...
4
#include <bits/stdc++.h> using namespace std; const signed int inf = (signed)((1u << 31) - 1); const signed long long llf = (signed long long)((1ull << 61) - 1); const double eps = 1e-6; const int binary_limit = 128; template <typename T> inline bool readInteger(T& u) { char x; int aFlag = 1; while (!isdigit((x =...
3
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; for (int i = a; i <= b; i++) { string s = to_string(i); int dc[10] = {0}; bool b = true; for (char x : s) { if (dc[x - '0'] > 0) { b = false; break; } else { dc[x - '0']++; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int a, b, f, e = 0, g = 0; char c[10], d[10]; scanf("%d %d", &a, &b); g = a; for (int i = 0; i < b; i++) { scanf("%s %s %s", c, c, c); scanf("%s %d", d, &f); if (c[0] == 'r') { if (e < f) e = f; } else { if (g > f - 1) g = ...
1
#include <iostream> using namespace std; const int SIZE=500000; int A[SIZE+1], H; void maxheap(int v){ int l=v*2,r=v*2+1,lar; int sto; if(l<=H&&A[l]>A[v])lar=l; else lar=v; if(r<=H&&A[r]>A[lar])lar=r; if(lar!=v){ sto=A[v];A[v]=A[lar]; A[lar]=sto;maxheap(lar); } return; } void buildmaxh(){ for(int i=H/2;i>=...
0
#ifndef ONLINE_JUDGE #include "debug.cpp" #endif #include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long void solve(); int binaryConc(int x, int y); string decToBinary(int n); int binaryToDecimal(string n); string decToBinary(int n) { string r...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 50; const int maxm = 25 + 1; const long long inf = 1e18; int dp[maxn][maxn]; string dig[maxn]; int n, k; pair<int, int> pre[maxn][maxn]; string num[10] = { string("1110111"), string("0010010"), string("1011101"), string("1011011"), string("01...
4
#include <bits/stdc++.h> int f(int a, int k) { int c = 0; while (a > 0) { if (a % 10 == 4 || a % 10 == 7) { ++c; } a /= 10; } return c <= k; } int main(void) { int a, n, k, i, ans = 0; scanf("%d %d", &n, &k); for (i = 0; i < n; ++i) { scanf("%d", &a); if (f(a, k)) { ++ans; ...
1
#include <bits/stdc++.h> using namespace std; const int MAX_N = 3e5 + 10; int N, A[MAX_N]; bool check(int x) { int min_s = 0, s = 0; for (int i = 1; i < N; i += 2) { s += A[i]; bool succ = s >= min_s + x; s -= A[i + 1]; if (succ) min_s = min(min_s, s); } s += A[N]; ...
0
#include <bits/stdc++.h> using namespace std; using LL = long long; const int M = 3e3 + 5; const int inf = 1e9 + 5; int a[M]; int dp[M][M]; int dp1[M]; int main() { int n; scanf("%d", &n); int up = 0; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); up = max(up, a[i]); } up += n; dp[n][a[n]] = n...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int k = n; for (int i = 0; i <= n; i++) { for (int p = 0; p < k; p++) { cout << " "; } k--; for (int j = 0; j < i; j++) { cout << j << " "; } cout << i; for (int j = i - 1; j >= 0; j--) { c...
2
#include <bits/stdc++.h> using namespace std; int main() { int a,b; cin>>a>>b; if(b%a==0) cout<<a+b; else cout<<b-a; }
0