solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main(void) { int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f; int l = b + a + c; return cout << l * l - a * a - c * c - e * e << '\n', 0; }
1
#include <bits/stdc++.h> using namespace std; const int N = 105; int a[N]; bool judge(int n) { int state = 1; for (int i = 2; i <= n; i++) { if (state == 1) { if (a[i] < a[i - 1]) state = 3; else if (a[i] == a[i - 1]) state = 2; } else if (state == 2) { if (a[i] < a[i - 1])...
1
#include <bits/stdc++.h> using namespace std; vector<long long> pows2; map<long long, long long> mp; long long rec(long long n) { if (mp.find(n) != mp.end()) return mp[n]; if (n <= 1) return 0; long long ans = 0; int index = 0; for (int i = 0; i < 60; i++) { if (pows2[i] < n) { index = i; } else...
5
/* Author: QAQAutomaton Lang: C++ Code: F.cpp Mail: lk@qaq-am.com Blog: https://www.qaq-am.com/ */ #include<bits/stdc++.h> #define int long long #define debug(...) fprintf(stderr,__VA_ARGS__) #define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__) #define Debug debug("Passing [%s] in LINE %d\n",__FUNCTI...
0
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; int X,k,r[100010],Q; struct node{int t,a,id; }q[100010];int ans[100010]; bool cmp(node x,node y) {return x.t<y.t;} int pls(int x,int y){return max(0,min(X,x+y));} int main() { scanf("%d%d",&X,&k); for ...
0
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1}; int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2}; int ky8[] = {2, -2, 1, -1, 2,...
3
#include <bits/stdc++.h> using namespace std; int N; int a, b; bool read() { if (scanf("%d", &N) < 1) { return 0; } scanf("%d%d", &a, &b); return 1; } const int MAXN = 2e3 + 10; namespace double_solver { double ans[MAXN]; double dp[MAXN]; double p_full[MAXN]; double f[MAXN][MAXN]; double pow_p[MAXN]; double...
6
#include <bits/stdc++.h> using namespace std; long long n; long long dpx[300005], dpy[300005], x[300005], y[300005], k; int main() { cin >> n >> k; for (long long i = 1; i <= n; i++) cin >> x[i]; for (long long i = 1; i <= n; i++) cin >> y[i]; for (long long i = 1; i <= n; i++) { dpx[i] = max(0ll, dpx[i - 1...
6
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; for(int i=a;i<a*102;i+=a){ if(i%b==c){ cout<<"YES"<<endl; return 0; } } cout<<"NO"<<endl; }
0
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int N = 1e5 + 5; int main() { int n, i, j, minA, maxA, minB, maxB, ans, x, y; scanf("%d", &n); minA = minB = INF; maxA = maxB = -INF; for (i = 0; i < n; i++) { scanf("%d%d", &x, &y); minA = min(minA, x + y - 1); maxA = max(ma...
3
#include <bits/stdc++.h> using namespace std; struct node { long long num, lab; bool operator<(const node& a) const { return num > a.num; } } e[100005]; long long a[100005], w[100005], ans1[100005], ans2[100005]; priority_queue<node, vector<node>, less<node> > sp; int main() { long long n, m, i, j, ans = 0; sca...
5
#include <bits/stdc++.h> using namespace std; double gen(double x, double y, double z) { return log(log(x)) + z * log(y); } double gen(double x, double y) { return log(log(x)) + log(y); } vector<pair<double, string> > genall(double x, double y, double z) { vector<pair<double, string> > r; if (x > 1.) { r.push_b...
4
#include <iostream> #include <string> using namespace std; int main() { string in; int n = 0; while (cin >> in) { n = 0; in += '\0'; for (int i = 0; i < in.size(); i++) { if (in[i] == 'M') n += 1000; if (in[i] == 'D') n += 500; if (in[i] == 'L') n += 50; if (in[i] == 'V') n += 5; ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string t1, t2; cin >> t1; t2 = t1; reverse(t2.begin(), t2.end()); cout << t1 + t2; return 0; }
1
#include <bits/stdc++.h> using namespace std; long long dp[2005][2005]; int lol[2005][2005]; int cnt[2005][2005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) {...
5
#include<bits/stdc++.h> using namespace std; #define ll long long #define M 20005 #define inf 998244353 struct edge{ int t,v,f,nxt; }e[M]; int head[M],tot=1; void add(int st,int t,int v,int f) { e[++tot].nxt=head[st],e[tot].t=t,e[tot].v=v,e[tot].f=f,head[st]=tot; e[++tot].nxt=head[t],e[tot].t=st,e[tot].v=-v...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long N; cin >> N; long long v[N]; for (long long i = 0; i < N; i++) cin >> v[i]; long long arr1[N - 1], arr2[N - 1]; for (long long i = 0; i < N - 1; i++) { arr1[i] ...
1
#include <bits/stdc++.h> using namespace std; map<string,set<int> > mp; string random2(){ string w; for(int i = 0 ; i < 100 ; i++) w += rand() % 26 + 'a'; return w; } string itos(int n){ stringstream ss; ss << n; return ss.str(); } bool inte(string s){ return '0' <= s[0] && s[0] <= '9'; } bool ope(string s)...
0
#include <bits/stdc++.h> using namespace std; int MOD; struct mint { int x; mint(int _x) : x((_x % MOD + MOD) % MOD) {} mint() : x(0) {} mint &operator=(const mint &rhs) { x = rhs.x; return *this; } mint pow(long long n) const { assert(0 <= n); mint x = *this, r = mint(1); while (n) { ...
4
#include <bits/stdc++.h> using namespace std; int n, t, e; int x[111111]; long long f[111111], g[111111]; int main(){ // freopen("input.inp", "r", stdin); scanf("%d%d%d",&n,&e,&t); for(int i = 1; i <= n; ++i) scanf("%d",&x[i]); int p = 0; g[0] = - 2 * x[1]; for(int i = 1; i <= n; ++i){ while (2ll * (x[i] - x[...
0
#include <bits/stdc++.h> using namespace std; long long int MOD = 1e9 + 7; long long int power(long long int a, long long int n) { unsigned long long int result = 1, x = a; while (n > 0) { if (n % 2 == 1) result = (result * x) % MOD; x = (x * x) % MOD; n = n / 2; } return result; } vector<int> adj[5...
4
#include <bits/stdc++.h> using namespace std; const int INF = int(1e9); const int N = 20; const int M = (1 << N); struct BracketSeqn { int balance; int lowestBalance; vector<int> queryAns; pair<int, bool> go(int x, bool f) { if (f) return make_pair(0, true); else return make_pair(x < queryAn...
6
#include <bits/stdc++.h> using namespace std; const int MAX = 5005; vector<int> llist[MAX]; int dpA[MAX], dpB[MAX]; int n, a, b, c, d, ofA, ofB, ofC, ofD, p[MAX], leaf[MAX]; void dfs(int u, int v) { p[u] = v; for (int i = 0; i < llist[u].size(); ++i) { int t = llist[u][i]; if (t == v) continue; dfs(t, u...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string a[150]; int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; int mxh = 0, mxw = 0, mnh = INT_MAX, mnw = INT_MAX; for (int i = 0; i < n; i++) { for (int j = 0; j...
1
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const int N = 10 + 5; const int MAX = 2147483647; int prime[25] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}; int main() { int n, m, a, b, ans, fa, fb; scanf("%d %d %d...
1
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define oo 1000000010 const int N = 1510; int n , m , in[N]; vector< pair< vector< int > , int > > a , b; vector< int > from[N] , to[N]; bool done[N]; int edge_cnt = 0; vector< int > g[N]; vector< int > v1 , v2; inline void add(vector< int > ...
3
#include <bits/stdc++.h> using namespace std; long long n, A, a[200005], sum, smol, lurg; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> A; for (long long i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } for (long long i = 1; i <= n; i++) { smol = A - sum + a[...
3
#include <bits/stdc++.h> using namespace std; void read(int& x) { scanf("%d", &x); } void read(long long& x) { scanf("%lld", &x); } template <typename T, typename... Args> void read(T& a, Args&... b) { read(a); read(b...); } int n; int a[100010]; int c[100010]; int cc[100010]; const int under = 340; int uc[100010],...
4
#include <bits/stdc++.h> using namespace std; int ary[200]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> ary[i]; int a, b; cin >> a >> b; a--, b--; int x = a; int s1 = 0, s2 = 0; while (x != b) { s1 += ary[x]; x++; x %= n; } int y = b; while (y != a) { s2 += a...
1
#include <bits/stdc++.h> using namespace std; bool isP(int n) { bool pr = 1; for (int j = 2; 1LL * j * j <= n && pr; j++) if (n % j == 0) pr = 0; return pr; } int main() { int n; cin >> n; if (isP(n)) cout << "1\n" << n; else if (isP(n - 2)) cout << "2\n2 " << (n - 2); else { cout << "3\...
4
#include <bits/stdc++.h> using namespace std; bool a[502][502]; int pre[502][502]; int main() { long long n, i, j, m, k, l, r; char c; cin >> n >> m >> k; for (i = 1; i <= n; i++) for (j = 1; j <= m; j++) cin >> c, a[i][j] = c - '0'; for (i = 1; i <= m; i++) for (j = 1; j <= n; j++) { pre[j][i] ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[n + 1], b[m + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; for (int j = 1; j <= m; j++) cin >> b[j]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (a[i] == b[j]) { cout << a[i] << ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, s; cin >> a >> b >> s; if (a < 0) a *= -1; if (b < 0) b *= -1; long long int steps = a + b; if (s >= steps && (s - steps) % 2 == 0) cout << "Yes" << endl; else cout << "No" << endl; }
1
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; int n, x[N], y[N], ans[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; int mnx = 2e9, mxx = -2e9, mny = 2e9, mxy = -2e9; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; mnx = min(mnx, x[i]); ...
5
#include <bits/stdc++.h> using namespace std; mt19937 rnd(time(0)); #define ios ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0); #define int long long #define ld long double #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() //ll p = 131; int mod = 1e9 + 7; int inf = 1000000000000000000; int ask(int t,...
3
#include<bits/stdc++.h> #define itr(i, n) for(int i=1;i<=n;++i) using namespace std; const int SIZE = 5e5+1; vector<int> num_arr(SIZE), idx_arr(SIZE); stack<int> s, t; int memo[SIZE]; int n, k; void NIT(){ //Num Index Transform 数とインデックスを入れ替える itr(i, n) //両方とも要素を1からnにする idx_arr[num_arr[i]] = i; } void INT(){...
0
#include <bits/stdc++.h> using namespace std; long long cnt1, cnt2, x, y; bool ok(long long t) { long long ob = t / x + t / y - (t / (x * y)); long long per = t / x + t / y - ob; long long num1 = min(max(t / y - per, (long long)0), cnt1); long long num2 = min(max(t / x - per, (long long)0), cnt2); long long n...
2
#include <bits/stdc++.h> using namespace std; long long n, m, ans; string st; int main() { cin >> n >> m; cin >> st; ans = n * m - n; for (int k = 0; k < st.size(); ++k) { if (k > 0 && st[k] != st[k - 1]) ans += n * m - n; } long long c = 1; for (int k = 1; k < st.size(); ++k) { if (c == 1) { ...
4
#include <bits/stdc++.h> using namespace std; void solve(long double d) { long double D = sqrt(d * (d - 4)); long double a = (d - D) / 2; long double b = (d + D) / 2; cout << "Y " << setprecision(15) << b << " " << setprecision(15) << a << endl; } int main() { int t; cin >> t; long double arr[t]; for (i...
3
#include <bits/stdc++.h> using namespace std; long long n, m, k, l, h, a, b, c, d, e, f, ans = 0; int main() { cin >> n; for (int t = 1; t <= n; t++) { cin >> a >> b >> k; ans = k; if (a < b) swap(a, b); if (a > k) { cout << "-1" << endl; continue; } else { if ((k - a) % 2) ans...
2
#include <bits/stdc++.h> using namespace std; char s[100005]; char tmp[100005]; stack<char> st; int main() { scanf("%s", s); int l = strlen(s); int cnt = 0; for (int i = 0; i < l; i++) { if (!st.empty()) { char topp = st.top(); if (topp == s[i]) { cnt++; st.pop(); } else { ...
2
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<long long> a(n), b(n); for (auto &x : a) { cin >> x; } for (auto &x : b) { cin >> x; } if (n == 1) { if (a[0] == b[0]) { cout << "SMA...
6
#include <bits/stdc++.h> using namespace std; inline int Get() { int res = 0, q = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') q = -1, ch = getchar(); while (ch >= '0' && ch <= '9') res = res * 10 + ch - '0', ch = getchar(); return res * q; } const doubl...
4
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, k = 0, ans = 1; cin >> a >> b; if (a == b) { cout << "1"; } else { while (k < 5 && a < b) { a++; ans *= (a % 10); if (ans % 10 == 0) break; k++; } cout << ans % 10; } return 0; }
2
#include <bits/stdc++.h> using namespace std; long long modpow(long long a, long long p, long long mod) { long long ret = 1; while (p) { if (p & 1) ret = (ret * a) % mod; a = (a * a) % mod; p /= 2; } return ret; } long long power(long long a, long long p) { long long ret = 1; while (p) { if ...
5
#include <iostream> using namespace std; int main() { int n,a,max=-1000000,min=1000000; cin >> n; long long int sum=0; for (int i=0;i<n;i++) { cin >> a; if (max<a) max=a; if (min>a) min=a; sum+=a; } cout << min << " " << max<< " " << sum << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = (1e6) + 7; int n, m, L, R, size, ansx[maxn], ansy[maxn]; int main() { scanf("%d%d", &n, &m); L = 1, R = m; for (int i = 1; i <= m >> 1; i++) { for (int j = 1; j <= n; j++) { ++size; ansx[size] = j, ansy[size] = L; ++size; a...
2
#include <bits/stdc++.h> using namespace std; int main() { int n,ans=0; scanf("%d",&n); ans+=min(9,n); ans+=min(900,max(0,n-99)); ans+=min(90000,max(0,n-9999)); printf("%d\n",ans); }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << n; int i; for (i = 1; i < n; i++) cout << " " << i; cout << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { long long int z, o, i, j, k; cin >> o >> z; if (o == z) { for (i = 0; i < o; i++) { cout << "10"; } return 0; } else if (o == z + 1) { for (i = 0; i < z; i++) { cout << "01"; } cout << "0"; return 0; } k = 0; ...
3
#include <bits/stdc++.h> using namespace std; const int N = 3e6 + 10, MOD = 1e9 + 7; int a[N], has[N]; long long f[N]; int main() { int n, m; scanf("%d", &n); int maxn = 0; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); has[a[i]]++; maxn = max(maxn, a[i]); } maxn = 3e6; for (int i = 1; i <...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int n; vector<long long> piles; vector<long long> melt; vector<long long> melt_initial; vector<long long> cnt; vector<long long> alone; int main() { cin >> n; cnt.resize(n + 2, 0); alone.resize(n + 2, 0); for (int i = 0; i < n; i++) { l...
3
#include <bits/stdc++.h> using namespace std; const int N = 1234567; int n, que[N]; char s[N], w[N]; int main() { scanf("%d %s %s", &n, s, w); if (strcmp(s, w) == 0) { puts("0"); return 0; } int ans = 1; int qh = 0, qt = 0; int j = n - 1; for (int i = n - 1; i >= 0; i--) { if (i == 0 || w[...
0
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; #define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define MOD 1000000007 #define mod 1000000007 #define mfor(i,a,b) for(int i=a;i<=b;i++) #define...
2
#include <bits/stdc++.h> using namespace std; bool lengh(char str[10000], int& len); bool syntax(char str[10000], int& len); int main() { char str[10000]; cin.get(str, 10000, '\n'); cin.ignore(10000, '\n'); int len = strlen(str); if (!lengh(str, len) || !syntax(str, len)) { cout << "NO \n"; } else c...
1
#include <bits/stdc++.h> using namespace std; int n; map<int, int> occ; set<pair<int, int> > st; set<pair<int, int> >::iterator stIter; vector<vector<int> > res; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int element; scanf("%d", &element); occ[element]++; } map<int, int>::iterator ...
3
#include <bits/stdc++.h> using namespace std; bool isodd(long long int x) { return x % 2; } int main() { long long int n; cin >> n; vector<long long int> arr(n), ans; for (int i = n - 1; i != -1; i--) cin >> arr[i]; if (n == 1) { cout << arr[0]; return 0; } ans.push_back(arr[0]); int size = n / ...
2
#include<bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define HUGE_NUM 99999999999999999 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; #define NUM 100 int N,M; int boss[NUM],height[NUM],member_num[NUM]; int len_num[NUM+1]; bool check[NU...
0
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a < b) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } long long cnt[1000000 + 10][30]; int main() { ios::sync_with_stdio(false); long long n, m; cin >> n >> m; string x, y; cin >> x >> y; if (x.size(...
2
#include <bits/stdc++.h> using namespace std; int const maxn = 1e6 + 1; int a[300005]; int b[300005]; int tree[4 * maxn]; int psh[4 * maxn]; inline void push(int i, int len) { tree[i] += psh[i]; if (len != 1) psh[2 * i + 1] += psh[i], psh[2 * i + 2] += psh[i]; psh[i] = 0; } void update(int i, int l, int r, int lq...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; string x, y, z; int ans = 0; scanf("%d", &n); cin >> x; for (int i = 0; i < n; i++) { y += char(i % 2 + 48); z += char((1 - i % 2) + 48); } int cnt1 = 0; int cnt2 = 0; for (int i = 0; i < n; i++) { if (x[i] != y[i]) cnt1++...
4
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const int N = 1e6 + 5; const int INF = 0xfffffff; template <typename T> void scan(T& x) { x = 0; char ch = getchar(); while (ch == ' ' || ch == '\n') ch = getchar(); do { x = 10 * x + ch - '0'; ch = getchar(); } while (ch >=...
3
#include <bits/stdc++.h> using namespace std; long long prime(long long x) { long long mark = 0; { for (int i = 2; i <= sqrt(x); i++) { if (x % i == 0) { mark = 1; break; } } } return mark; } int main() { long long mark = 0; string s, s1; cin >> s; for (int i = 0; i <...
1
#include <bits/stdc++.h> using namespace std; int been[500000]; int a[500000]; int n; long long ff[500000]; int cc; long long f(int x) { if (ff[x] != -0X3fffffff && x != 1) return ff[x]; long long r; long long xx = x; been[x] = cc; long long ans = 0; xx += a[x]; ans += a[x]; if (xx > n) { r = ans; ...
2
#include <bits/stdc++.h> using namespace std; void solve() { long long a, b, x, y, n; cin >> a >> b >> x >> y >> n; long long diff1 = a - x; long long diff2 = b - y; long long ta = a; long long tb = b; if (a - n <= x) { a = x; if (b - n + diff1 <= y) { b = y; } else { long long to ...
2
#include <bits/stdc++.h> using namespace std; long long int n, k, x; long long int a[200005]; long long int pre[200005], post[200005]; int main() { scanf("%lld", &n); scanf("%lld", &k); scanf("%lld", &x); long long int m = pow(x, k); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 1; i <= n;...
2
#include <bits/stdc++.h> using namespace std; const int N = 5e5; int n, dp[30][30], cnt[N + 2], ans; string s[N + 2], tmp; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> tmp; cnt[i] = tmp.size(); s[i].push_back(tmp.front()); s[i].push_back(...
1
#include <bits/stdc++.h> using namespace std; string s, t; bool check(string ns) { int pos = 0; for (int i = 0; i < ns.size(); ++i) { if (ns[i] == t[pos]) ++pos; } return (pos == t.size()); } bool checksz(int m) { if (m == 0) return false; for (int i = 0; i + m <= s.size(); ++i) { string ns1 = s.sub...
4
#include <bits/stdc++.h> using namespace std; struct Node { int numComp; vector<pair<int, int> > lft; vector<pair<int, int> > rgt; }; Node dft; int n, K, m; vector<int> a[100010]; Node T[4 * 100010]; set<pair<int, int> > edges; int pr[100010]; vector<int> temp; int getParent(int u) { if (pr[u] == u) return u; ...
5
#include <bits/stdc++.h> using namespace std; int n; vector<pair<int, int>> st; void dfs(int cur, vector<vector<int>> &g, vector<int> &used, vector<int> &tps) { used[cur] = true; for (auto t : g[cur]) { if (!used[t]) { dfs(t, g, used, tps); } } tps.push_back(cur); } bool check(int k) { vector<ve...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int n, m; cin >> n >> m; vector<string> v1; vector<string> v2; for (int i = 0; i < m; i++) { string a, b; cin >> a >> b; v1.push_back(a); v2.push_back(b); } ...
2
#include<bits/stdc++.h> using namespace std; int slove(int x,int y,int n); int main(void) { int N,Q; scanf("%d %d",&N,&Q); while(Q) { Q--; int x,y; scanf("%d %d",&x,&y); if(N==1) printf("%d\n",min(x,y)); else printf("%d\n",slove(x,y,N)); } ...
0
#include <bits/stdc++.h> using namespace std; long long int MSS(long long int A[], long long int n) { long long int best = INT_MIN; long long int sum = 0; long long int i; for (i = 0; i < n; i++) { sum = max(A[i], A[i] + sum); best = max(best, sum); } return best; } long long int binarytodecimal(str...
1
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; const int mod = 1e9 + 7; int n, ind[N]; char s[N]; int main() { while (~scanf("%d%s", &n, s)) { int c = 0, out = 0; int m = (n - 11) / 2; for (int i = 0; i <= n - 1; i++) if (s[i] == '8') { c++; ind[c] = i + 1; ...
2
#include <bits/stdc++.h> bool vis[111]; using namespace std; int main() { int n; string s; cin >> n; cin >> s; for (int i = 0; i < n; ++i) if (s[i] == '*') vis[i] = 1; for (int i = 0; i < n; ++i) { if (vis[i]) { for (int j = 1; i + j * 4 < n; ++j) { if (vis[i + j] && vis[i + j * 2] && ...
1
#include<iostream> int main(){ int a, b; std::cin >> a >> b; std::cout << (a < b ? "a < b" : a>b ? "a > b" : "a == b") << std::endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long MX = 2e5 + 5; long long s[MX]; long long a[MX]; long long f[MX]; long long n, m; const long long D = 1e9 + 7; long long p; long long q; long long pow2(long long x, long long y) { if (y == 0) return 1; long long ret = pow2(x, y / 2); ret *= ret; ret %...
6
#include <bits/stdc++.h> using namespace std; int main() { long n, k; cin >> n >> k; if (n < k) cout << k; else cout << (n / k + 1) * k; }
1
#include <bits/stdc++.h> using namespace std; long long GCD(long long x, long long y) { if (y == 0) return x; return GCD(y, x % y); } long long LCM(long long x, long long y) { return (x * y) / GCD(x, y); } long long MPOW(long long a, long long b, long long m) { if (b == 0) return 1; long long x = MPOW(a, b / 2,...
1
#include <bits/stdc++.h> using namespace std; inline char nc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } template <typename T = int> inline T nxt() { char c = nc(); T x = 0; int f = ...
3
#include <bits/stdc++.h> int main() { long long a, b, c = 0, product = 1; scanf("%I64d %I64d", &a, &b); while (a > 0 || b > 0) { c += ((b % 3 - a % 3 + 3) % 3) * product; a /= 3; b /= 3; product *= 3; } printf("%I64d\n", c); return 0; }
2
#include<bits/stdc++.h> using namespace std; int a[100010],s[100010]; int main() { int n,i,tot; scanf("%d",&n); for(i=1;i<=n;i++)scanf("%d",&a[i]); for(i=1;i<=n;i++)s[a[i]]++; tot=0; for(i=1;i<=100000;i++)if(s[i]>1)tot+=(s[i]-1); if(tot%2==0)printf("%d",n-tot); else printf("%d",n-tot-1); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 3e4 + 5; const int maxk = 505; int N, d; int dp[maxn][maxk], gem[maxn], vis[maxn][maxk]; int dfs(int pos, int prev) { int jj = prev - (d - 250); if (pos > 30000) return 0; if (vis[pos][jj]) return dp[pos][jj]; vis[pos][jj] = 1; int ans = 0; if (...
1
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); int dx[] = {+0, +0, +1, -1, -1, +1, -1, +1}; int dy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 =...
3
#include <bits/stdc++.h> double a[200001]; int b[200001]; using namespace std; int main() { int T; double sum = 0; scanf("%d", &T); for (int i = 0; i < T; i++) { scanf("%lf", &a[i]); sum += a[i]; } double av = 0; av = sum / T; int num = 0, l = 0; ; for (int j = 0; j < T; j++) { if (a[j] ...
1
#include <bits/stdc++.h> using namespace std; int ar[] = {0, 0, 1, -1, 1, 1, -1, -1}; int ac[] = {1, -1, 0, 0, -1, 1, -1, 1}; int main() { ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; map<int, int> mp; for (int i = 0; i < n; i++) { int x; cin >> x; mp[x]++; } int ans = 0; for (...
1
#include "iostream" using namespace std; int main(){ int a; cin>>a; cout<<a+a*a+a*a*a<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> mal; vector<int> dev; for (int i = 0; i < n; i++) { int x; cin >> x; mal.push_back(x); } int m; cin >> m; for (int i = 0; i < m; i++) { int x; cin >> x; dev.push_back(x); } sort(mal.begi...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k, ans, count = 0; cin >> n >> k; int a[n]; map<int, int> m, m1; for (int i = 0; i < n; i++) { cin >> a[i]; m[a[i]]++; } for (auto i : m) for (int j = 1; j < i.se...
4
#include <bits/stdc++.h> using namespace std; long long op[100005], k, n, s[100005]; int f1(long long s) { int l = 1, r = n + 1, mid; while (l < r) { if (r == l + 1) { return op[l] <= s ? l : -1; } mid = (l + r) >> 1; if (op[mid] <= s) l = mid; else r = mid; } } int f2(long l...
5
#include <bits/stdc++.h> using namespace std; int getNextX(int& x) { return x = (x * 37LL + 10007) % 1000000007; } void initAB(vector<int>& a, vector<int>& b, int n, int d, int x) { for (int i = (0); i < ((n)); ++i) a[i] = i + 1; for (int i = (0); i < ((n)); ++i) swap(a[i], a[getNextX(x) % (i + 1)]); for (int i =...
2
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int a[30]; bool mark[N]; bool dp[30][1000]; int n; void update() { dp[0][0] = 1; for (int i = 1; i <= n; i++) for (int j = 0; j < 1000; j++) { dp[i][j] = dp[i - 1][j]; if (j >= a[i] && !mark[i]) dp[i][j] |= dp[i - 1][j - a[i]]; ...
5
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 1e3 + 10; long long getans(long long x1, long long x2, long long d) { if (x1 < 0) x1 = -x1, x2 = -x2; if (x1 < x2) swap(x1, x2); long long o = (x1 + d - 1) / d; x1 -= d * o; x2 -= d * o; swap(x1, x2); return x2 / d ...
2
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) typedef long long ll; typedef pair<int, int> P; #define MAX 500005 int main(int, char**) { int n, l; cin >> n >> l; vector<int> a(n); rep(i,n) cin >> a[i]; deque<int> q; vector<int> ans; rep(i,n) { while (!q.emp...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b; cin >> a >> b; string prawdopodobienstwo[7] = {"0/0", "1/1", "5/6", "2/3", "1/2", "1/3", "1/6"}; cout << prawdopodobienstwo[max(a, b)]; }
1
#include <bits/stdc++.h> using namespace std; int min(int x, int y) { return x < y ? x : y; } int main() { int n, r; cin >> n; r = n % 10; cout << (r <= 10 - r ? n - r : n - r + 10) << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int arr[2000]; int main() { int n; cin >> n; int k = n / 2; if (n % 2) k++; cout << (n / 2 + 1) * k << endl; return 0; }
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:200000000") using namespace std; template <typename T> inline T Abs(T x) { return (x >= 0) ? x : -x; } template <typename T> inline T sqr(T x) { return x * x; } template <typename T> inline string toStr(T x) { stringstream st; st << x; string s; st >>...
2
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; int n; vector<long long> f(200100, 0); vector<long long> cf(200100, 0); long long rangeSum(int l, int r) { long long sec = 0; if (r >= 200100) { sec = n; } else { sec = cf[r - 1]; } return sec - cf[l - 1]; } int main() { ios::...
6
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int x, d, i = 0, j = 0; int a[100][2]; for (i = 0; i < n; i++) { for (j = 0; j < 2; j++) { scanf("%d", &a[i][j]); } } int l = 0, k = 0, z = 0; int flag = 0; for (k = 0; k < n; k++) { for (l = 0; l < n; l++) { if ((a[...
1