solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; string a, b, c; int a1, b1, c1; bool check(int x, int y, int z) { if (x == 8 && y == z && y == 5) return true; return false; } bool check1(int x, int y, int z) { if (x == 8 && y == z && y == 4) return true; return false; } bool check2(int x, int y, int z) { if (x ...
1
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f, oo = inf; inline long long read() { register long long x = 0; char f = 0; register char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); return f ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); int a, b; cin >> a >> b; for (int i = 1; i <= a; i++) cout << i << ' '; for (int i = a + b + 1; i > a; i--) cout << i << ' '; }
1
#include <bits/stdc++.h> using namespace std; vector<vector<int>> g; int n; long double m; int main() { cin >> n >> m; g.resize(n); for (int i = 0; i < n - 1; ++i) { int v, u; cin >> v >> u; --v, --u; g[v].push_back(u); g[u].push_back(v); } long long k = 0; for (int i = 0; i < n; ++i) { ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000100; int N, M; int nlog; string blog[MAXN]; int conv[MAXN]; int nmonth[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int cconv(char ch) { return (int)ch - '0'; } int convert(string str) { int month = 10 * cconv(str[5]) + cconv(str[6]); int...
6
#include <cassert> #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <ccomplex> #in...
0
#include<bits/stdc++.h> using namespace std; int N, M, K; map<int, long long> cnt[2]; int main(){ while(cin >> N >> M >> K, N){ cnt[0].clear(); cnt[0][0] = 1; for(int i = 0; i < N; i++){ cnt[(i+1)%2].clear(); for(auto e : cnt[i % 2]){ for(int k = 1; k <= M; k++){ cnt[(i+1)%2][e.first+k] += e.sec...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, i, co = 0, odd = 0, in; cin >> n; int arr[n], dp[n]; for (i = 0; i < n; i++) { cin >> arr[i]; dp[i] = 0; } for (i = 0; i < n; i++) { if (arr[i] % 2 == 0) { dp[i] = 1; ...
1
#include<bits/stdc++.h> #define x 100000 using namespace std; int main() { int n[x],a[x],i,b[x]; cin>>n[x]; for(i=1;i<=n[x];i++) { cin>>a[i]; b[a[i]]=i; } for(i=1;i<=n[x];i++){ cout<<b[i]<<" "; } }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, a[100010], xx[100010]; vector<int> qv[100010]; ll ans[100010]; int main(){ scanf("%d", &n); for(int i = 1; i <= n; i++){ scanf("%d", a + i); xx[i] = a[i]; } sort(xx + 1, xx + n + 1); for(int i = 1; i <= n; i++) a[i] = (int...
0
#include<iostream> using namespace std; int main(){ int n; while(cin>>n){ int a[4][3][10]={0}; for(int i=0;i<n;i++){ int b,f,r,v; cin>>b>>f>>r>>v; a[b-1][f-1][r-1]+=v; } for(int i=0;i<4;i++){ for(int j=0;j<3;j++){ for(int k=0;k<10;k++){ cout<<" "<<a[i][j][k]; } cout<<endl; } ...
0
#include<bits/stdc++.h> #define range(i,a,b) for(int i = (a); i < (b); i++) #define rep(i,b) for(int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define show(x) cerr << #x << " = " << (x) << endl; const int INF = 1e8; using namespace std; int main(){ string s; while(cin >> s){ int mini[205][205]; ...
0
#include <bits/stdc++.h> using namespace std; int n, m, x, y, z, orr[1111], now[1333], sz[3133], d[3133], nor[1111], dd[1111]; string na[1111], ty[1111], nam[1111], typ[1111], g; vector<string> v[3133]; map<string, int> M; set<string> B; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> na[i] >> ty[i]...
3
#include<iostream> #include<vector> #include<string> using namespace std; bool hamming(int a) { while (1) { if (a == 1)return true; if (a % 2 == 0) a /= 2; else if (a % 3 == 0) a /= 3; else if (a % 5 == 0) a /= 5; else return false; } } int main() { while (1) { int a; cin >> a; if (a == 0)break; i...
0
#include <bits/stdc++.h> using namespace std; bool equals(const char* a, const char* b, int length) { if (strncmp(a, b, length) == 0) return true; else if (length % 2 == 0) { int halfLength = length / 2; bool resultLeft1 = equals(a + halfLength, b, halfLength); bool resultLeft2 = equals(a, b + halfL...
2
#include <bits/stdc++.h> using namespace std; int n, r = 0, ans = 1, a[4007], freq[1000007], dp[4007][4007]; unordered_map<int, int> um; int main() { ios_base::sync_with_stdio(0); cin.tie(0); std::cin >> n; for (int i = 0; i < n; i++) std::cin >> a[i], freq[a[i]]++; for (int i = 0; i < 1000007; i++) if (f...
1
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int MOD = 1e9 + 7; long long l[2005], r[2005]; double rate[2005]; long long dp[25][5][5]; double ans[2005][2005]; int a[200]; int cnt; long long numberDP(int pos, int limit, int zero, long long ok) { long long ans = 0; if (pos == -1) { ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 3; int n, a[N]; int s, sl[N], sr[N]; long long pf[N], sf[N], ans, rt = 1e18; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; s += a[i]; } if (s == 1) { puts("-1"); return 0; } int mn; for (int x = 2; x <= ...
5
#include <bits/stdc++.h> using namespace std; const int N = 500 * 1000 + 20; int n, m, ver_3k, root, par[N], h[N], d[N], cnt; set<int> st, pap1; bool vis[N], ok, seen; vector<int> gr[N]; void find_3k_ver() { for (int i = 1; i <= n; i++) if (d[i] % 3 == 0) if (st.empty()) st.insert(i); } void dfs_find_cycle(...
6
#include<bits/stdc++.h> #define int long long #define print1(a) for(auto x:a)cout << x<<" ";cout <<endl; #define fastio ios_base::sync_with_stdio(false);cin.tie(0); #define print2(a,r,c) for(int i=0;i<r;i++){for(int j=0;j<c;j++)cout<<a[i][j]<<" ";cout << endl;} using namespace std; int dx[]={0,0,1,-1},dy[]={1,-1,0,0}; ...
4
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { long long n, a, b; cin >> n >> a >> b; string str; cin >> str; long long first = 0; for (int i = 0; i < n; i++) { if (str[i] == '0') first++; else break; } long lon...
3
#include <bits/stdc++.h> using namespace std; vector<unsigned long long int> v[5004]; vector<unsigned long long int>::iterator it; set<unsigned long long int> s; set<unsigned long long int>::iterator iter; bool check[100005]; int main() { long long int n = 0, m = 0, x = 0, res = 0, i = 0, j = 0, flag = 0; string s;...
1
#include <bits/stdc++.h> int ln(int n) { int i = 1, s = 0, a; while (n) { a = n % 10; if (a == 4 || a == 7) { s += a * i; i *= 10; } n /= 10; } return s; } int main() { int a, b; scanf("%d%d", &a, &b); while (ln(++a) != b) ; printf("%d\n", a); return 0; }
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") const long long INF = 0x3f3f3f3f3f3f3f3f; const long long llinf = (1LL << 60); const int inf = (1 << 30); const int nmax = 1e5 + 50; const long long mod = 1e9 + 7; using namespace std; int ts, n, k, z, i, j, cur, rs, a[nmax], b[nma...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int add(int a, int b) { long long x = a + b; if (x >= 1000000007) x -= 1000000007; if (x < 0) x += 1000000007; return x; } long long mul(long long a, long long b) { return (a * b) % 1000000007; } long long pw(long long a, long long b) { ...
5
#include <bits/stdc++.h> #define pb push_back #define eb emplace_back #define fi first #define se second #define rep(i,N) for(long long i = 0; i < (long long)(N); i++) #define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--) #define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++) #define repr1(i,N...
0
#include <bits/stdc++.h> using namespace std; bool PIIfs(const pair<int, int>& a, const pair<int, int>& b) { return a.first < b.first || (a.first == b.first && a.second < b.second); } bool PIIsf(const pair<int, int>& a, const pair<int, int>& b) { return a.second < b.second || (a.second == b.second && a.first < b.fi...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 2; int n, x, y; int a[N]; class SegmentTree { int *tree; public: SegmentTree() { tree = new int[4 * N]; } void build(int, int, int); int query(int, int, int, int, int); }; void SegmentTree ::build(int id, int start, int end) { if (start > end...
5
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; char buf[100000], *p1 = buf, *p2 = buf; inline int gi() { int x = 0, f = 1; char ch = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++); while (ch > '9' || ch < '0') { i...
6
#include <bits/stdc++.h> char str[60]; int main() { int len, i, j = 0; scanf("%d %s", &len, &str[1]); for (i = 1; j < len; i++) { j += i; printf("%c", str[j]); } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 5; template <typename T> void print(vector<T>& v) { cout << "["; for (int i = 0; i < v.size(); ++i) { cout << v[i]; if (i != v.size() - 1) cout << ", "; } cout << "]\n"; } template <typename T> void print(set<T>& v) { cout << "["; f...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> A(n); for (__typeof(0) i = (0); i < (n); i++) cin >> A[i]; sort(A.begin(), A.end()); int ans = 0, i = 0; while (i < ...
2
#include<iostream> using namespace std; char classify(int m, int e, int j){ if(m == 100 || e == 100 || j == 100) return 'A'; if((m+e)/2 >= 90) return 'A'; if((m+e+j)/3 >= 80) return 'A'; if((m+e+j)/3 >= 70) return 'B'; if((m+e+j)/3 >= 50 && max(m,e) >= 80) return 'B'; return 'C'; } i...
0
#include <bits/stdc++.h> using namespace std; int m[2015][2015]; bool vis[2015][2015]; int dr[] = {-1, 0, 1, 0}; int dc[] = {0, -1, 0, 1}; int n; void bfs(int row, int col) { queue<int> q; q.push(row); q.push(col); vis[row][col] = true; while (!q.empty()) { row = q.front(); q.pop(); col = q.front(...
5
#include <bits/stdc++.h> using namespace std; long long xmax(long long& a, long long b) { return a = max(a, b); } long long xmin(long long& a, long long b) { return a = min(a, b); } vector<long long> res; vector<vector<pair<long long, long long> > > adi; void do_insert(multiset<long long>& sm, multiset<long long>& la, ...
6
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; const long long mod = (long long)1e9 + 7; const long long MOD = (long long)998244353; const long long INF = (long long)1e18; void err(istream_iterator<string> it) {} template <typename T, typename... Args> voi...
1
#include <bits/stdc++.h> int IntMaxVal = (int)1e20; long long LongMaxVal = (long long)1e20; using namespace std; vector<int> depth; vector<vector<int> *> parents; int lca(int a, int b) { if (depth[a] > depth[b]) swap(a, b); for (int i = parents[b]->size() - 1; i >= 0; --i) { if (depth[b] - (1 << i) >= depth[a])...
6
#include <bits/stdc++.h> using namespace std; struct node { long long y, next; } a[200010]; long long len = 0, last[100010]; long long n, dfn[100010], z = 0; struct trnode { long long dep, fa[20]; } tr[100010]; void ins(long long x, long long y) { a[++len].y = y; a[len].next = last[x]; last[x] = len; } void d...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 10; const int mod = 1e9 + 7; int isprime[maxn]; int main() { int n; cin >> n; int a, b; a = b = 0; for (int i = 0; i < n; i++) { int g; cin >> g; if (g == 1) a++; else b++; } if (a == 0) { for (int i = 0; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int a[3]; int ans = 1000; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); for (int i = 1; i <= a[2]; i++) { int y = abs(i - a[0]) + abs(i - a[1]) + abs(i - a[2]); if (y < ans) ans = y; } cout << ans << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long int n; cin >> n; long long int ar[n]; for (long long int i = 0; i < n; ++i) cin >> ar[i]; long long int xi, fi; cin >> xi >> fi; long long int cnt = 0; for (long long int i = 0; i < n; ...
6
#include <bits/stdc++.h> using namespace std; const int block_size = 320; const long long mod = 1e9 + 7; const long long inf = 1e9 + 7; const long double eps = 1e-9; const double PI = atan(1) * 4; template <typename T> inline int sign(const T &a) { if (a < 0) return -1; if (a > 0) return 1; return 0; } template <...
6
#include<iostream> #include<algorithm> using namespace std; #define MAXN 51 int mutton[MAXN]; int plate[MAXN]; int main() { int N,K,res=0; cin>>N>>K; for(int i=0;i<N;i++) cin>>mutton[i]; //l+r+k<=K,l+r<=N int bound=min(N,K); for(int l=0;l<=bound;l++) { for(int r=0;r<=bound-l;r++) { int i,j; f...
0
#include <bits/stdc++.h> using namespace std; int32_t main() { set<long long> v; for (long long i = 0; i <= 20; i++) { for (long long j = 0; j <= 30; j++) { long long num = (powl(2, j) * powl(3, i)); if (num <= 2000000000) v.insert(num); } } for (long long i = 0; i <= 30; i++) { for (lon...
1
#include <bits/stdc++.h> using namespace std; set<pair<int, int> > a, b; int f[100005], g[100005]; int main() { int n, s, l, i, x = 0; scanf("%d%d%d", &n, &s, &l); for (i = 1; i <= n; i++) scanf("%d", &g[i]); a.clear(); b.clear(); f[0] = 0; for (i = 1; i <= n; i++) { a.insert(make_pair(g[i], i)); ...
2
#include <bits/stdc++.h> using namespace std; const int N = 500, inF = 1e9; int n, m, u, v, w, cnt[N][N], dp[N][N], edge[N][N]; vector<int> ans, nei[N]; int main() { ios::sync_with_stdio(false), cin.tie(0); cin >> n >> m; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) dp[i][j] = edge[i][j] = inF; f...
5
#include <bits/stdc++.h> using namespace std; int N, T, A[100005], F[2][100005]; struct Nod { int x, y; } Ans[100005]; inline int Next(int st, int len) { if (F[0][N] - F[0][st - 1] < len && F[1][N] - F[1][st - 1] < len) return -1; int l = st - 1, r = N; for (; l + 1 < r;) { int Mid = l + r >> 1; if (F[0...
2
#include<cstdio> int x,y; int main() { scanf("%d %d",&x,&y); if(x%y)printf("%d",x); else printf("-1"); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7, K = 18, INF = 1e9 + 7; pair<int, int> combine(const pair<int, int> &a, const pair<int, int> &b) { return pair<int, int>(min(a.first, b.first), max(a.second, b.second)); } struct SegTree { int n; vector<pair<int, int> > tr; SegTree(){}; SegTr...
4
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <tuple> using namespace std; #define all(c) (c).begin(), (c).end() int main(){ int N, Q; while(cin >> N >> Q, N|Q){ typedef tuple<int, int, string> Data; vector<Data> era; era.reserve(N); whi...
0
#include <bits/stdc++.h> using namespace std; int power(long long int x, unsigned long long y, int p) { long long int res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int main() { ios_base::sync_with_stdio(fa...
4
#include<bits/stdc++.h> using namespace std; typedef long long LL; int n,k; LL t; int main() { scanf("%d%d",&n,&k); t=n/k; LL ans=t*t*t; if (!(k&1)&&n>=k/2) { t=(n-k/2)/k+1; // cout<<t<<endl; ans+=t*t*t; } printf("%lld\n",ans); return 0; }
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:66777216") using namespace std; int a, b, c, d, i, j, n, m, k; vector<pair<int, int> > sm[100001]; bool used[100001]; int num[100001]; vector<int> bad, cand; void dfs(int v) { if (used[v]) return; used[v] = 1; for (int _n(((int)((sm[v]).size())) - 1), i(0);...
3
#include <iomanip> #include <iostream> using namespace std; int main() { double n, m, d; cin >> n >> m >> d; cout << setprecision(12) << fixed << (d == 0 ? 1 : 2) * (m - 1) * (n - d) / (n * n) << endl; }
0
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long a, b, c; int main() { int yn = 1; cout.sync_with_stdio(false); cin.sync_with_stdio(false); cin >> a >> b >> c; long long c1 = c, c2 = c; if (c % a == 0) cout << "Yes"; else if (c % b == 0) cout << "Yes"; else ...
1
#include <bits/stdc++.h> using namespace std; const long long int N = 1e6 + 2; const long long int mod = 1e9 + 7; vector<int> sfr, msbt, mnf; long long int ta, mx, f[N]; int32_t main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int n; cin >> n; for (int i = 0; i < n; i++) { int a; ...
1
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; int v[200100]; struct IT { int d[800100]; int s[800100]; IT() { for (int i = 0; i <= 800000; i++) d[i] = 1; } void upd(int num, int l, int r, int x, int y, int z) { if (l > y || r < x || l > r) return; if (l >= x && y >= r) { i...
4
#include <iostream> using namespace std; class Node{ public: int depth; int parent; int degree; int *children; }; void Depth(Node *node,int cur, int dp){ node[cur].depth = dp; for(int i=0;i<node[cur].degree;++i){ Depth(node,node[cur].children[i],dp+1); } } int main() { int n; Node *node;...
0
#include <bits/stdc++.h> using namespace std; int cnt[1000005]; int divs(int x) { int res = 0; for (int i = 1; i * i <= x; i++) { if (x % i == 0) res++; if (x % i == 0 && i * i != x) res++; } return res; } int main() { int a, b, c; scanf("%d %d %d", &a, &b, &c); int ans = 0; for (int i = 1; i <=...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { vector<int> arr; for (int i = 0; i < 3; i++) { int x; cin >> x; arr.push_back(x); } sort(arr.begin(), arr.end()); int a, b, c; a = arr[2]; b = arr[1]; c = arr[0]; if (a >...
1
#include <bits/stdc++.h> int main() { char str1[1000005], str2[1000005]; int l1, l2, sum1, sum2, i; scanf("%s", str1); scanf("%s", str2); l1 = strlen(str1); l2 = strlen(str2); sum1 = sum2 = 0; if (l1 != l2) { printf("NO\n"); } else { for (i = 0; i < l1; i++) { if (str1[i] == '1') sum1++;...
3
#include <bits/stdc++.h> using namespace std; const long long N = 2e6 + 7; const long long INF = 1e18; long long n, m, k, q, ans, a[N], b[N]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; for (long long i = 1; i <= n; i++) { cin >> a[i]; } for (long long i = 1; i <=...
3
#include <bits/stdc++.h> using namespace std; bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i = i + 6) { if (n % i == 0 || n % (i + 2) == 0) return false; } return true; } long long gcd(long lo...
2
#include <bits/stdc++.h> using namespace std; int main(void) { int i; long long n, d, m, l; cin >> n >> d >> m >> l; long long ans = (n * m + d - 1) / d * d; for ((i) = 0; (i) < (int)(m + 10); (i)++) { long long x = d * i; if (x % m > l) ans = min(ans, x); } cout << ans << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { long long x = 0; char ch = getchar(); bool positive...
6
#include <cstdio> #include <algorithm> #define repi(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,a) repi(i,0,a) constexpr int MAX_N = 100000; using ll = long long; int N, K; ll a[MAX_N]; ll S[MAX_N+1], zS[MAX_N+1]; int main() { scanf( "%d%d", &N, &K ); rep( i, N ) scanf( "%lld", a+i ); S[0] = 0; zS[0] ...
0
#include <bits/stdc++.h> using namespace std; int i, j, k, b, p, n, r = 0; string s, alc[11] = {"ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE"}; int main() { cin >> n; for (i = 1; i <= n; ++i) { cin >> s; if ((s[0] <= '9' &...
1
#include <bits/stdc++.h> using namespace std; void func(void) { freopen("input.c", "r", stdin); freopen("output.c", "w", stdout); } const long long N = 1e5 + 10; long long tree[N * 5][2], lazy[N * 5][2]; long long a[N], b[N], c[N]; void update(long long node, long long b, long long e, long long l, long long r, ...
1
#include <bits/stdc++.h> using namespace std; int sher[11], mor[11], s[1001], m[1001]; int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n; cin >> n; for (int i = 0; i < n; ++i) { char c; cin >> c; ++sher[c - '0']; s[i] = c - '0'; } for (int j = 0; j < n; ++j) { ...
2
#include <bits/stdc++.h> using namespace std; int warriors, pairse; vector<vector<int> > adjacent; vector<int> connected; vector<pair<int, int> > pairs; int main() { cin >> warriors >> pairse; adjacent.resize(warriors + 1); for (int i = 1; i < warriors + 1; i++) adjacent[i].resize(warriors + 1); connected.resiz...
2
#include <stdio.h> int main() { int N,c=0; scanf ("%d", &N); bool f[101][101] = { 0, }; for (int i = 1; i <= N; i++) for (int j = i + 1; j <= N; j++) f[i][j] = 1, c++; if (N % 2) for (int i = 1, j = N - 1; i < j; i++, j--) f[i][j] = 0, c--; else for (int i = 1, j = N; i < j; i++, j--) f[i][j] = 0, c--; printf (...
0
#include <bits/stdc++.h> using namespace std; int t; long long n, k; pair<pair<long long, long long>, long long> fnd(long long levels) { long long res = 0, lst = 0; for (int i = 0; i < levels; i++) { lst += (1LL << i); if (res > k - lst) { return make_pair(make_pair(res, levels - i), lst); } r...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); set<int> S; for (int i = 1; i <= n; i++) S.insert(i); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); auto it = S.find(x); auto b = S.end(); b--; printf("%d ", *b - (n - i - 1)); S.erase(it); ...
4
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long mod = 1e9 + 7; template <class A> void read(A& a) { a = 0; int c = getchar(), f = 0; for (; !isdigit(c); c = getchar()) f |= c == '-'; for (; isdigit(c); c = getchar()) a = a * 10 + (c ^ 48); if (f) a = -a; } template <c...
4
#include <valarray> #include <cstdio> using namespace std; typedef valarray<int>V; int main(){ int i,j,n,m,a,b,c,t; for(;scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&t),n;){ V x(n*n); V e(n*n); V z(n*n); V s(n); x[0]=b; x[1]=c; e[0]=1; for(i=1;i<n-1;i++){ x[i*n+i-1]=a; x[i*n+i]=b; x[i*n+i+1]=c; e[...
0
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c; long long h, l; while (~scanf("%lld %lld", &h, &l)) { scanf("%lld %lld %lld", &a, &b, &c); long long sa, sb; sa = a * 2 + b; sb = b + c * 3; if (h <= sa) sa = sa - h; else sa = 0; if (l <= sb) ...
1
#include<stdio.h> int main() { int a; int b; int c; scanf("%d %d %d",&a,&b,&c); if(a<b&&b<c) printf("Yes"); else printf("No"); printf("\n"); }
0
#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" struct status ...
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; template <typename T, typename TT> inline ostream &operator<<(ostream &os, const pair<T, TT> &t) { return os << t.first << " " << t.second; } template <typename T> inline ostream &operator<<(ostream &os, const vector<T> &t) { for (auto i : ...
4
#include <bits/stdc++.h> using namespace std; struct edge { int v; long long w; }; const int MOD = 1000000007; long long _MOD = 1000000009; double EPS = 1e-10; int INF = INT_MAX / 2; vector<int> solve(vector<int> a, vector<int> b) { int N = a.size(); vector<pair<int, int> > ai(N); for (int i = 0; i < N; i++) ...
4
#include <bits/stdc++.h> using namespace std; long long n, i, x, y[111111], f, fin, a, b, c[111111]; string s, ss; double ans = 1e9; map<string, int> m; int main() { cin >> n >> x >> a >> b; if (max(n * 3 / 10, n - n / 250 * a) < max(x * 3 / 10, x - x / 250 * b)) cout << "Vasya"; else if (max(n * 3 / 10, n - ...
1
#include <bits/stdc++.h> using namespace std; const int MAX = 100010; struct Node { int id; int value; Node* left; Node* right; Node* parent; Node(const Node& node) { id = node.id; value = node.value; left = node.left; right = node.right; parent = node.parent; } Node(int id, int valu...
4
#include <bits/stdc++.h> using namespace std; const int N = 82; int dp[N][N][N][N]; int n, k, m, g[N][N]; int DP(int l, int r, int cur, int k) { if (dp[l][r][cur][k] != -1) return dp[l][r][cur][k]; if (k == 1) { return dp[l][r][cur][k] = 0; } for (int i = 1; i <= n; i++) { if (g[cur][i] != 1e8 && i > l ...
4
#include <bits/stdc++.h> int main() { int a, b, c, i1, i2, r1, r2, i, r, j, k, sum = 0, n, m, tmp, t, ara[1]; double p, q, x, y; char c1[1], c2[1]; scanf("%d", &n); for (j = 0; j < n; j++) { scanf("%d %d", &i, &r); if (j == 0) { i1 = i; r1 = r; } else { if (i > i1) i1 = i; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n; long long j; int ax[N], ay[N]; int main() { scanf("%d %lld", &n, &j); int x, y; scanf("%d %d", &x, &y); for (int i = 0; i < n; ++i) scanf("%d %d", &ax[i], &ay[i]); j %= (2 * n); for (int k = 1; k <= j; ++k) { x = 2 * ax[(k - 1) %...
3
#include<bits/stdc++.h> #define speed ios::sync_with_stdio(false), cin.tie(0); using namespace std; int main() { speed; int n,i; cin>>n; long long int p,ans=0; for (i=0;i<n;i++) { cin>>p; ans^=p; } if (ans) cout<<"No"<<endl; else cout<<"Yes"<<endl; }
0
#include <bits/stdc++.h> using namespace std; void solve(); mt19937 rng(time(0)); long long qpow(long long x, long long p, long long MOD) { long long res = 1, v = x; while (p) { if (p & 1) { res *= v; res %= MOD; } v *= v; v %= MOD; p >>= 1; } return res; } long long inv(long lon...
1
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + f * (c - '0'), c = getchar(); return x; } const long long MAXN =...
4
#include <bits/stdc++.h> using namespace std; bool comp(string a, string b) { if (a.compare(b) < 0) return true; return false; } long long p1, p2, v1, v2, k; long a[10000]; long long ans = 0; long n = 1; long maxlevel; void res(long x1, long x2, long y1, long y2) { long long o1, o2, t1, t2; o1 = x1 > p1 ? x1 : ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int q; cin >> q; int mx = 0, my = 0; int x, y; char op; int menor, maior; while (q--) { cin >> op >> x >> y; menor = min(x, y); maior = max(x, y); if (op == '+') { mx = max(mx, ...
5
#include <bits/stdc++.h> using namespace std; const long long N = 100005; const long long mod = 1000000007; long long bp(long long x, long long y) { long long ans = 1; x %= mod; while (y) { if (y & 1) ans = ans * x % mod; x = x * x % mod; y >>= 1; } return ans; } long long mod_inverse(long long x)...
5
#include <bits/stdc++.h> int main() { char a[1005]; scanf("%s", &a); if (a[0] >= 'a' && a[0] <= 'z') { a[0] = a[0] - 32; } printf("%s\n", a); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { string str[3]; int win = -1; int d[3], res = 0; for (int i = 0; i < 3; i++) { cin >> str[i]; if (str[i] == "rock") d[i] = 1; else if (str[i] == "paper") d[i] = 2; else d[i] = 5; res += d[i]; } if (str[0] == str[...
1
#include <bits/stdc++.h> using namespace std; signed main() { long long n, f; cin >> n >> f; vector<long long> loss; long long sold = 0; for (long long i = 0; i < n; ++i) { long long k, l; cin >> k >> l; sold += min(k, l); if (k >= l) continue; long long tmp = min(k, l - k); loss.push_...
2
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { long long int hr, hb, wr, wb, c, result; cin >> c >> hr >> hb >> wr >> wb; if (wr > wb) { swap(hr, hb); swap(wr, wb); } result = c / wb * hb; for (int i = 0; i <= min((long long int)1000000, c / wb); ++i) { result = ...
3
#include <bits/stdc++.h> int main(void) { int pos, neg, in, sum1, sum2, sum3, res1, res2; scanf("%i", &pos); scanf("%i", &neg); scanf("%i", &in); sum1 = pos + in; sum2 = neg + in; sum3 = pos + neg; if (in == 0) { if (pos == neg) printf("0"); else if (pos > neg) printf("+"); else ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int num; while (n--) { scanf("%d", &num); printf("%d\n", num > 2 ? num - 2 : 0); } }
2
#include <bits/stdc++.h> using namespace std; long long int a[100010]; long long int tree[13][100006]; long long int dp[100005][13]; void update(long long int x, long long int len, long long int val) { while (x <= 100000) { tree[len][x] += val; x += (x & -x); } } long long int query(long long int x, long lo...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; int a[N]; int i, j; for (i = 0; i < N; i++) { cin >> a[i]; } set<int> s(a, a + N); vector<int> v(s.begin(), s.end()); j = s.size(); int b[j]; for (i = 0; i < j; i++)...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, m, mp[15] = {0}; cin >> n >> m; for (long long i = (0); i < (long long)(n); ++i) { int t; cin >> t; mp[t]++; } int res = 0; for (int i = 1; i < 11; i++) { for (int j = i + 1; j < 11; j++) { ...
2