solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int read() { int ret = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); for (; ch >= '0' && ch <= '9'; ch = getchar()) ret = ret * 10 + ch - '0'; return ret; } int m, n; int a[105]; int l[105]; map<int, bool> s; in...
2
#include <bits/stdc++.h> using namespace std; long long int n; queue<long long int> q; vector<pair<long long int, long long int> > ans; void bfs(long long int s, vector<long long int> g[]) { bool b[n + 1]; for (long long int i = 0; i < n; i++) { b[i] = false; } b[s] = true; q.push(s); while (!q.empty())...
5
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<vector<int>> cnt(2, vector<int>(2)); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; a /= 2; b /= 2; cnt[a % 2][b % 2]++; } long long ans1 = 0, ans2 = 0; for (int i = 0; i < 2; i++) { for (i...
4
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; constexpr long long mod = 998244353; const long long INF = mod * mod; template <typename T> void chmin(T& a, T b) { a = min(a, b); } template <typename T> void chmax(T& a, T b) { a = max(a, b); } template <...
6
#include <bits/stdc++.h> using namespace std; const long long prime_const = 1e9 + 7; bool sort_function(long long a, long long b) { return a < b; } long long minim(long long x, long long y) { if (x < y) return x; else return y; } long long maxim(long long x, long long y) { if (x > y) return x; else ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int n, x, y; scanf("%lld", &n); ; scanf("%lld", &x); ; scanf("%lld", &y); ; string s; { char temp[1000000]; scanf("%s", temp); s = temp; }; int count0 = 0; int i = 0; int boo = 1; while (i < n) { if (boo && ...
1
#include<bits/stdc++.h> using namespace std; #define maxn 300013 #define maxm 23 #define ll long long #define M1 (ll)998244353 #define M (ll)1000000007 #define eps 1e-10 int fa[maxn][23], _log=19; int T; int a[maxn], c[maxn]; int main() { scanf("%d%d%d", &T, &a[1], &c[1]); int typ, u, w; for(int v=2; v<=T+1; v++){ ...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int c[maxn], s[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; ++i) cin >> c[i] >> s[i]; set<pair<int, int>> st[2]; for (int i = 0; i < n; ++i) st[c[i]].insert(make_pair(s[i],...
4
#include <bits/stdc++.h> using namespace std; const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1}; const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1}; template <typename T_n> void read(T_n &n) { cin >> n; } template <typename T_n, typename T_a> void read(T_a a[], T_n n...
2
#include <bits/stdc++.h> using namespace std; int main() { int n_people, n_chips, i; cin >> n_people >> n_chips; int answer = 0; int c_answer; L1: for (i = 1; i <= n_people; i++) { c_answer = answer; answer += i; if (answer > n_chips) break; } if (answer <= n_chips) goto L1; cout << (n_chips...
1
#include <bits/stdc++.h> template <class T> inline void read(T &res) { res = 0; bool bo = 0; char c; while (((c = getchar()) < '0' || c > '9') && c != '-'); if (c == '-') bo = 1; else res = c - 48; while ((c = getchar()) >= '0' && c <= '9') res = (res << 3) + (res << 1) + (c - 48); if (bo) res = ~res + 1; } co...
0
#include<iostream> #include<algorithm> #include<vector> #include<stack> #include<map> #include<set> #include<queue> #include<cstdio> #include<climits> #include<cmath> #include<cstring> #include<string> #include<sstream> #include<numeric> #include<cassert> #define f first #define s second #define mp make_pair #define ...
0
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { long long res = 1; a = a % 1000000007; while (b > 0) { if (b & 1) { res = (res * a) % 1000000007; b--; } a = (a * a) % 1000000007; b >>= 1; } return res; } long long fermat_inv(long long y) { ...
4
#include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <ctime> #include <cassert> #include <string> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <functional> #include <iostream> #include <map> #include <set> using namespace std; typedef pair<int,int> P; ty...
0
#include <bits/stdc++.h> using namespace std; long long a[3000000]; int main() { long long int i, j, n, m, sum = 0; cin >> n >> m; j = (n + 1) / 2; for (i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); for (i = 1; i <= n; i++) { sum += a[i]; if (i == j) a[i] = m; else if (i < (j)) ...
2
#include <bits/stdc++.h> using namespace std; int n, fr[2010], dr[1010], st[1010], ok, j, mx, nrdist, aux; struct chestie { int ind, nr; } v[2010]; void verif(); bool compind(chestie A, chestie B); bool compnr(chestie A, chestie B); int main() { cin >> n; ok = 1; for (int i = 1; i <= n; i++) { cin >> st[i];...
3
#include <iostream> #include <queue> #include <string> using namespace std; int main(void) { priority_queue<int> queue; string command; int num; while(true) { cin >> command; if(command=="end") { break; } if(command=="extract") { cout << queue.top() << endl; queue.pop(); } else { ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s, a = "", b = ""; cin >> s; long long int k = s.size(); for (long long int i = 0; i < k / 2; i++) { a = a + s[i]; } for (long long int i = k / 2; i < k; i++) { b = b + s[i]; } long long int z = 0, m = 0; so...
2
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 5; const int Maxn = 305; const int S = 0; const int T = 301; int n, m; vector<int> ss[Maxn]; int value[Maxn]; int match[Maxn << 1]; bool used[Maxn << 1]; vector<int> adj1[Maxn << 1]; vector<int> adj2[Maxn]; int dist[Maxn]; int capa[Maxn][Maxn]; int ans...
5
#include <bits/stdc++.h> using namespace std; long long n, nr, inc, sf, i, sf1, v[100000]; bool ok; int main() { cin >> n; if (n == 4) cout << '1'; else if (n == 7) cout << '2'; else { nr = 2; v[1] = 4; v[2] = 7; inc = 1; sf = 2; sf1 = 2; ok = true; while (ok == true) { ...
2
#include <bits/stdc++.h> using namespace std; int c, v0, v1, a, l; void solve() { cin >> c >> v0 >> v1 >> a >> l; int left = c - v0; int ans = 1; if (left <= 0) { cout << 1 << "\n"; } else { for (int i = 1; left > 0; i++) { int x = v0 + i * a; x = min(x, v1); x -= l; left -= x;...
1
#include <bits/stdc++.h> int n, m, k; char s[105][105][105]; bool u[105][105][105]; bool p[105][105][105]; int dx[] = {1, 0, 0}; int dy[] = {0, 1, 0}; int dz[] = {0, 0, 1}; inline bool goes(int x0, int y0, int z0, int x1, int y1, int z1) { for (int d = 0; d < 3; ++d) { if (x0 + dx[d] == x1 && y0 + dy[d] == y1 && ...
4
#include <cmath> #include <cstdlib> #include <iostream> #include <unordered_map> using namespace std; #define REP(i, a, b) for(int i = (a); i < int(b); ++i) #define rep(i, n) REP(i, 0, n) template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; } template<class T> inline void chmin(T &a, const T &b) {...
0
#include <bits/stdc++.h> using namespace std; int n, i, ans; int main() { cin >> n; vector<int> h(n); for (i = 0; i < n; i++) cin >> h[i]; ans = h[0] + 1; for (i = 1; i < n; i++) { if (h[i] < h[i - 1]) ans += h[i - 1] - h[i] + 2; else ans += h[i] - h[i - 1] + 2; } cout << ans; }
2
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const double PI = acos(-1.); const double eps = 1e-10; const int INF = 0x3f3f3f3f; const long long INFLL = 0x3f3f3f3f3f3f3f3f; const int MAXN = 262144 * 8 + 5; char s[MAXN]; char t[MAXN]; struct CP { double x, y; CP() {} CP(double x, dou...
5
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265358979323; long long int mod = 1000000000 + 7; const double pii = acos(-1.0); const long long int INF = 1e18; const long long int inf = 1e9; long long power(long long x, long long y) { long long res = 1; x = x; while (y > 0) { if (y & 1...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int c1 = 0; int c2 = 0; int c3 = 0; int c4 = 0; int a; int b; int m[n][2]; for (int i = 0; i < n; i++) { cin >> a >> b; m[i][0] = a; m[i][1] = b; if (a == 1) { c1++; } if (a == 0) { c2++; ...
1
#include <bits/stdc++.h> using namespace std; long long nCr(int n, int r) { if (r > n - r) r = n - r; long long ans = 1; int i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long a, b, c, d, e, g...
3
#include <bits/stdc++.h> using namespace std; bool seen[200]; int lvl[200]; int main() { int N, K; cin >> N >> K; memset(seen, false, sizeof(seen)); for (int i = 0; i < N; ++i) cin >> lvl[i]; int Q; cin >> Q; int T = N / K; double mi = 1e9, ma = 0; int CNT = 0; for (int q = 0; q < Q; ++q) { doub...
2
#include <bits/stdc++.h> bool vis[30][30]; int n, p; int main() { int T; scanf("%d", &T); while (T--) { scanf("%d %d", &n, &p); memset(vis, 0, sizeof(vis)); for (int i = 0; i < n; i++) for (int j = 1; j <= 2; j++) { vis[i][(i + j) % n] = 1; vis[(i + j) % n][i] = 1; } in...
3
#include <bits/stdc++.h> using namespace std; #pragma optimize(2) const int inf = 0x7FFFFFFF; template <class T> inline void MAX(T &x, T y) { if (y > x) x = y; } template <class T> inline void MIN(T &x, T y) { if (y < x) x = y; } template <class T> inline void rd(T &x) { x = 0; char o, f = 1; while (o = getch...
3
#include <bits/stdc++.h> using namespace std; vector<int> ed[2000]; int sho[1200][1200]; int col[1200]; int n, m; int makk[1200]; int sp[1200]; void dfs(int v, int ccc) { sp[v] = ccc; for (int a = 0; a < ed[v].size(); a++) { if (sp[ed[v][a]] == -1) dfs(ed[v][a], ccc); } } void getsho(int v) { int q[3000]; ...
5
#include<bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; int main() { int n; while (scanf("%d", &n), ~n) { double x = 1, y = 0; rep(i, n - 1) { double X = ((x - y) - (x + y)) / 2, Y = ((x - y) + (x + y)) / 2; double d = sqrt(i + 1); x += X / d; y += Y / d; } printf("%.7lf\...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; cin >> s; string s1 = s.substr(0, 2); for (int i = 3; i < s.length(); i = i + 2) { s1 = s1 + s[i]; } cout << s1 << endl; } return 0; }
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int n,q,b,c; cin>>n; ll sum=0; map<int,ll>m; int a[n];for(int i=0;i<n;i++)cin>>a[i],sum+=a[i],m[a[i]]++; cin>>q; while(q--){ cin>>b>>c; sum+=(c-b)*m[b]; m[c]+=m[b],m[b]=0; cout<<sum...
0
#include <bits/stdc++.h> using namespace std; void comparearr(int A[], int B[], int n) { int sumA = 0, sumB = 0; for (int i = 0; i < n; i++) sumA = sumA + A[i]; for (int i = 0; i < n; i++) sumB = sumB + B[i]; if (sumA >= sumB) cout << "Yes"; else cout << "No"; } int main() { int n; cin >> n; int...
1
// C - Sequence #include <bits/stdc++.h> using namespace std; using ll = long long; #define up(i,s,e,d) for(int i=(s);i<(e);i+=(d)) int main(){ int N; cin>>N; vector<ll> A(N); ll csum = 0; ll a = 0; up(i,0,N,1){ cin>>A[i]; csum += A[i]; if(i%2==0 && csum<=0){//even + a += abs(csum) + 1; csum = 1; }...
0
#include <bits/stdc++.h> using namespace std; const int INFI = (1LL << 30) - 100; const long long INFL = (1LL << 62) - 100; const double eps = 1e-10; const long double pi = acos(-1.0); const int MAXN = 200010; int cows[MAXN], clf[MAXN]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf...
1
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e9; const long long SZ = 2000010; const double PI = 3.1415926535897932384626433832795; const double EPS = 1e-6; const long long MUL = 239017; string a, b1, b2; map<string, vector<string>> ...
3
#include <bits/stdc++.h> using namespace std; vector<long long> v; vector<long long> dp; long long gg(long long i, long long j) { j = min(j, (long long)v.size() - 1); long long res = dp[j]; if (i > 0) res -= dp[i - 1]; return res; } int main() { int n; cin >> n; v.resize(n); dp.resize(n); for (int i =...
2
#include <bits/stdc++.h> using namespace std; const int N = 52; const int Mod = 1e9 + 7; void add(int &x, int y) { x += y; if (x >= Mod) x -= Mod; } int mul(long long x, int y) { return x * y % Mod; } int n; int d[N]; int dp[2][N][N][N][N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", ...
5
#include <bits/stdc++.h> using namespace std; void _print() { cout << '\n'; } void print() { cout << '\n'; } template <typename T, typename... Ts> void _print(const T& value, const Ts&... values) { cout << ' ' << value; _print(values...); } template <typename T, typename... Ts> void print(const T& value, const Ts&....
4
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; int e, f, g; if (d > 2 * c || 2 * d < c) { cout << -1 << endl; return 0; } g = max(d, c); f = max(b, 2 * d + 1); if (f > 2 * b) { cout << -1 << endl; return 0; } e = max(a, f + 1); i...
1
#include<bits/stdc++.h> using namespace std; static const int N=100; int main() { int n; int p[N+1],m[N+1][N+1]; cin>>n; for(int i=1;i<=n;i++) { cin>>p[i-1]>>p[i]; } for(int i=1;i<=n;i++)m[i][i]=0; for(int l=2;l<=n;l++) { for(int i=1;i<=n-l+1;i++) { ...
0
#include <bits/stdc++.h> using namespace std; const int maxN = 2e5 + 10; int T, n; int ans, mx, tot, cnt; int c[26], b[maxN + 1]; int top, now; char s[maxN + 1]; pair<int, int> p[maxN + 1], q[maxN + 1], stk[maxN + 1]; inline void clear() { for (int i = 0; i < 26; i++) c[i] = 0; for (int i = 0; i <= n; i++) b[i] = 0...
4
#include <bits/stdc++.h> using namespace std; int a[100005]; int main() { int n, i; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); int maxnum = a[0]; for (i = 1; i < n; i++) { if (a[i] > maxnum) maxnum = a[i]; } int maxlen = 1; int len = 1; for (i = 0; i < n; i++) { if (a[i] == m...
1
#include <bits/stdc++.h> using namespace std; bool isLeapYear(int year) { return ((year % 400 == 0 || year % 100 != 0) && year % 4 == 0); } int main() { int n, days = 1, ourYearDay = 0, max = 1000000; cin >> n; bool isLeap = isLeapYear(n), ready = false; for (int year = 0; year <= max; year++) { if (year ...
2
#include <bits/stdc++.h> long long m[200000], t[200000], ans, n; int main() { scanf("%I64d", &n); for (int i = 1; i <= n; ++i) scanf("%I64d", &m[i]), t[i] = m[i] + 1; for (int i = 2; i <= n; ++i) if (t[i] < t[i - 1]) t[i] = t[i - 1]; for (int i = n; i >= 2; --i) if (t[i - 1] < t[i] - 1) t[i - 1] = t[i] ...
3
#include <iostream> #include <cmath> #include <algorithm> using namespace std; int main(){ int x; cin>>x; int ret=sqrt(2*x); while(ret*(ret+1)/2<x) ret++; cout<<ret<<endl; return 0; }
0
#include<bits/stdc++.h> #define MOD 1000000007 #define LLI long long int using namespace std; int N; LLI dp[22][1<<21] = {}; int a[21][21] = {}; int main() { int i,j; int N; cin >> N; for( i=0; i<N; i++) { for( j=0; j<N; j++) { cin >> a[i][j]; } } dp[0][0] = 1; for( i=0; i<N; i++) { for( j=0; j ...
0
#include <bits/stdc++.h> using namespace std; double sq(double a) { return a * a; } struct pos { double y, x; double sqdis(const pos& b) const { return sq(x - b.x) + sq(y - b.y); } double dis(const pos& b) const { return sqrt(sqdis(b)); } double cj(const pos& b) const { return x * b.y - y * b.x; } }; pos p, ps[...
3
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 1e5 + 6; long long int binpower(long long int a, long long int b, long long int m) { long long int res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b = b >> 1; } return res; } void solve() { i...
3
#include <bits/stdc++.h> using namespace std; int n, m, k; int ma; int a[111], b[111], v[111][111]; int main() { scanf("%d%d", &n, &m); ma = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { scanf("%d", &v[i][j]); ma = max(ma, v[i][j]); } a[i] = v[i][0]; } k = 2000000000; ...
4
#include <iostream> using namespace std; int n,r,b; char x; int main() { cin>>n; for (int i=1;i<=n;++i) cin>>x,(x=='R'?r++:b++); cout<<(r>b?"Yes\n":"No\n"); }
0
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, d; cin >> n >> d >> m; long long int a[n]; vector<long long int> r, l; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] > m) r.push_back(a[i]); else l.push_back(a[i]); } sort(r.rbegin(), r.rend()); ...
4
#include<iostream> #include<cstdio> using namespace std; #define MAX 450 inline int read() { int x=0;bool t=false;char ch=getchar(); while((ch<'0'||ch>'9')&&ch!='-')ch=getchar(); if(ch=='-')t=true,ch=getchar(); while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar(); return t?-x:x; } int n,H,f[MAX],In[MAX],Ot[MAX];bool v...
0
#include<stdio.h> int main() { int a,b; scanf("%d %d",&a,&b); if(a+b==15)printf("+"); else if(a*b==15)printf("*"); else printf("x"); printf("\n"); return 0; }
0
#include <bits/stdc++.h> using namespace std; int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; } int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; } const long long int N = 1e5 + 5; long long int n, m, ans = 0; long long int dp[N], deg[N]; vector<long long int> graph[N];...
2
#include <iostream> #include <vector> #include <string> #include <cstring> #include <algorithm> #include <sstream> #include <map> #include <set> #define REP(i,k,n) for(int i=k;i<n;i++) #define rep(i,n) for(int i=0;i<n;i++) #define INF 1<<30 #define pb push_back #define mp make_pair using namespace std; typedef long l...
0
#include <bits/stdc++.h> using namespace std; int n, k, t, a[33][33], p[33], i, j, ans, x, use; long long q[1 << 22]; char c[210000]; int main() { scanf("%d%d%d%s", &n, &k, &t, c + 1); for (i = 0; i <= k; ++i) for (j = 1; j <= k; ++j) scanf("%d", &a[i][j]); memset(p, -1, sizeof(p)); for (i = 1; i <= n; ++i)...
3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; int i = 0, j = 0; while (b != d && i <= 100 && j <= 100) { if (b > d) { d += c; j++; } else { b += a; i++; } } if (i <= 100 && j <= 100) cout << d << endl; else c...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; int x[2000], y[2000], p[2000]; while (cin >> n) { int i, j; for (i = 0; i <= n; i++) cin >> x[i] >> y[i]; int cnt = 0, sum = 0; x[n + 1] = x[1]; y[n + 1] = y[1]; for (i = 1; i <= n; i++) if ((x[i] - x[i - 1]) * (y[i + ...
4
#include<stdio.h> int main(){ double r; double PI=3.141592653589; scanf("%lf",&r); printf("%f %f",r*r*PI,r*2*PI); return 0; }
0
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& a) { in >> a.first >> a.second; return in; } template <typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> a) { out << a.first << " " << a.second; return out; } t...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = int(5e4) + 100; const int MOD = int(360); const int oo = INT_MAX; const long double PI = acos(-1.0); const long double EPS = 1e-9; struct pt { long double x, y; pt() {} pt(long double x, long double y) : x(x), y(y) {} }; inline long double x(pt P) { r...
5
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 20, p = 37, mod = 1e9 + 143; long long N, M, K, seg[4 * maxn], lazy[4 * maxn], pw[maxn], pre[maxn]; char ar[maxn]; long long build(long long k, long long b, long long s) { if (s == b) return seg[k] = ar[s]; long long m = (s + b) >> 1; long...
5
#include <bits/stdc++.h> using namespace std; const int N = 300000; int x[N][2]; int ans[N]; bool hear[N]; vector<pair<int, int> > G[N]; int color[N]; void dfs1(int s) { color[s] = 1; for (int i = 0; i < (int)G[s].size(); i++) { int v = G[s][i].first; if (color[v] == 0) { if (G[s][i].second > 0) { ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; if (s[6] == '0') cout << 0; else if (s[6] == '2') cout << 0; else if (s[6] == '4') cout << 0; else if (s[6] == '6') cout << 0; else if (s[6] == '8') co...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int t, id, n, m, x, y, k, c, p, dif, ans, sum, pre, rem, cur, tmp, tot, r, l, u, d, xx, yy; int a[N], vis[N], f[N], b[N], cu[N]; vector<int> v, adj[N]; bool fl, ok; int dp[N]; int mem[N]; int sol(int i = n) { int &ret = mem[i]; if (~ret) retur...
4
#include <bits/stdc++.h> using namespace std; int const MOD = 1e9 + 7; int const N = 31; int dp[N][2][2][2], dc[N][2][2][2]; int sum(int a, int b) { return (a + b) % MOD; } void add(int &a, int b) { a += b; if (a >= MOD) a -= MOD; } int mul(int a, int b) { return a * 1LL * b % MOD; } void sub(int &a, int b) { a -...
3
#include <bits/stdc++.h> using namespace std; int M, N; int A[26]; int main() { scanf("%d", &M); for (int i = 0; i < M; i++) scanf("%d", A + i), N += A[i]; for (int i = N; i >= 1; i--) { int good = 1; for (int j = 0; j < M; j++) good &= (A[j] % i == 0); if (good) { int odd = 0; for (int j ...
5
#include <bits/stdc++.h> using namespace std; template <typename T> long long int power(T a, T b) { long long int pow = 1; for (int i = 0; i < b; i++) { pow *= a; } return pow; } int a[100005] = {0}; int main() { int a; cin >> a; string s; cin >> s; int p = 0, m = 0; for (int i = 0; i < s.size()...
1
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << "\n"; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(nam...
4
#include<iostream> using namespace std; int main() { int S; cin >> S; cout << S/3600 << ":" << S/60%60 << ":" << S%60 << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, k = 1; cin >> n; unordered_map<string, long long> map; map["polycarp"] = 0; vector<long long> v; v.push_back(1); for (long long i = 0; i < n; i++) { string name1, s, name2; cin ...
1
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; bool ispalindrome(string s) { long long int len = s.length(); for (long long int i = 0; i < len; i++) { if (s[i] != s[len - i - 1]) return false; } return true; } long long binpow(long long a, long long b) { long long res = 1; whi...
1
#include <bits/stdc++.h> using namespace std; template <class T> inline bool isLeap(T y) { return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false); } template <class T> inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); } template <class T> inline T lcm(T a, T b) { return ((a) / gcd((a), (b))...
1
#include <bits/stdc++.h> using namespace std; struct Node { int id, val; bool operator<(const Node& node) const { return val < node.val; } } a[110000], b[110000]; int t1 = 0, t2 = 0; int lst[110000], K = 0; int main() { int n, v, m, val; int ret = 0; scanf("%d%d", &n, &v); for (int i = 0; i < n; i++) { ...
2
//02 #include<iostream> #include<cmath> using namespace std; int main(){ for(int m;cin>>m,m;){ int mr=360; double ms=0; for(int i=0;i<m-1;i++){ int a; cin>>a; mr-=a; ms+=sin(acos(-1)*a/180); } ms+=sin(acos(-1)*mr/180); int nr=360; double ns=0; int n; cin>>...
0
#include <bits/stdc++.h> using namespace std; int main() { long long a; cin >> a; long long b[a]; for (long long i = 0; i < a; i++) { cin >> b[i]; } long long meow = 0; for (long long i = a - 1; i > 0; i--) { if (b[i] < b[i - 1]) { meow = meow + b[i - 1] - b[i]; } } cout << meow; r...
2
#include <bits/stdc++.h> using namespace std; int main() { long long int n, a[7], i; cin >> n; for (i = 0; i < 7; i++) { cin >> a[i]; } while (n != 0) { for (i = 0; i < 7; i++) { n = n - a[i]; if (n <= 0) { cout << i + 1; return 0; } } } }
1
#include <bits/stdc++.h> using namespace std; const int N = 2100; char c[N][N], ans[N][N]; bool chk[N][N]; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; vector<pair<int, int>> v, vec[N]; bool valid(int x, int y, int p, int q) { return 0 <= x && x < p && 0 <= y && y < q; } bool check(int x, int y, int p, int q) ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int i, mn = INT_MAX, a, b; long long int arr[n]; for (i = 0; i <= n - 1; i++) { cin >> arr[i]; } for (i = 0; i <= n - 1; i++) { if (i == 0) { if (abs(arr[n - 1] - arr[0]) < mn) { mn = abs(...
1
#include <bits/stdc++.h> using namespace std; template <typename T> inline void cmax(T &x, T y) { x < y ? x = y : x; } template <typename T> inline void cmin(T &x, T y) { y < x ? x = y : x; } char bf[1 << 21], *p1(bf), *p2(bf); template <typename T> inline void read(T &x) { char t( (p1 == p2 && (p1 = bf, p2...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> A(n); for (int i = 0; i < n; ++i) cin >> A[i]; int j = max_element(A.begin(), A.end()) - A.begin(); bool fail = false; for (int i = 0; i < j; ++i) fail |= A[i] > A[i + ...
2
#include <bits/stdc++.h> using namespace std; long long sum[100005 << 2], col[100005 << 2], add[100005 << 2]; void build(int l, int r, int rt) { sum[rt] = 0; col[rt] = 0; add[rt] = 0; if (l == r) { col[rt] = l; return; } int m = (l + r) >> 1; build(l, m, rt << 1); build(m + 1, r, rt << 1 | 1); }...
5
#include <bits/stdc++.h> using namespace std; priority_queue<long long> pq; long long a[1002], b[1002], arr[1002]; int main() { int n, k1, k2, k; cin >> n >> k1 >> k2; k = k1 + k2; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) { cin >> b[i]; arr[i] = (long long)abs(a[i] - b[i]);...
2
#include <bits/stdc++.h> using namespace std; int n, m; long long po(long long a, long long b) { long long c = 1, d = a; while (b) { if (b & 1) c = 1LL * c * d % 1000000007; d = 1LL * d * d % 1000000007; b >>= 1; } return c; } int main() { scanf("%d %d", &n, &m); if (m == 1) printf("%d\n", n...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; long long int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; a[i] -= 1; sum = sum + (long long int)a[i]; if (sum % 2 == 0) { cout << 2 << endl; } else cout << 1 << endl; } return 0; }...
2
#include <bits/stdc++.h> using namespace std; int n; pair<int, int> p[100005]; vector<int> ch[100005]; pair<int, int> dp[100005][18]; int d[100005]; void dfs(int cn) { for (auto nn : ch[cn]) { d[nn] = d[cn] + 1; dfs(nn); } } void prepro() { for (int i = (1); i <= (signed)(n); i++) { dp[i][0] = p[i]; ...
4
#include <iostream> #include <cstring> using namespace std; typedef pair<int,int> P; P t[101][101]; int loop[101][101]; int solve(int x,int y,int now){ while(loop[y][x] == 0){ loop[y][x] = now; int nx = t[y][x].first; int ny = t[y][x].second; x = nx; y = ny; } if(loop[y][x] == now) return 1; return 0;...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n, a, b; cin >> n >> a >> b; char str[n], word = 'a'; int j = 0; for (int f = 0; f < n; f++) { str[f] = word; word++; j++; if (j == b) { word = 'a'; ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, a, b; cin >> n; cin >> a; cin >> b; vector<int> aa(a); vector<int> bb(b); vector<int> cc(n); vector<int> ans(n); for (int i = 0; i < a; i++) { cin >> aa[i]; } for (int i = 0; i < b; ...
1
#include <bits/stdc++.h> using namespace std; const long long N = 2 * 1e5 + 5; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; vector<long long> cnt(40, 0); ...
2
#include <bits/stdc++.h> using namespace std; using Int = long long; int main(){ cin.tie(0); ios::sync_with_stdio(false); Int k,a,b,ans; cin>>k>>a>>b; if(b-a>2)ans=a+(k-(a-1))/2*(b-a)+(k-(a-1))%2; else ans=k+1; cout<<ans<<'\n'; }
0
#include <bits/stdc++.h> using namespace std; int main() { int N, i, j, k; string S; int a = 0, b = 0, c = 0; cin >> S; for (i = 0; i < S.size(); i++) { if (S[i] == 'a') a++; else if (S[i] == 'b') b++; else c++; } if (a == 0 || b == 0 || c == 0) { cout << "NO\n"; retu...
1
#include <bits/stdc++.h> using namespace std; template <typename T> class Modular { public: using Type = typename decay<decltype(T::value)>::type; constexpr Modular() : value() {} template <typename U> Modular(const U& x) { value = normalize(x); } template <typename U> static Type normalize(const U& ...
5
#include <iostream> #include <fstream> #include <typeinfo> #include <vector> #include <stack> #include <cmath> #include <set> #include <map> #include <string> #include <algorithm> #include <cstdio> #include <queue> #include <iomanip> #include <cctype> #include <random> #define syosu(x) fixed<<setprecision(x) using name...
0
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cer...
2
#include <bits/stdc++.h> using namespace std; int main() { int freq[26] = {}; string s; cin >> s; for (int i = 0; i < s.length(); i++) { freq[s[i] - 'a']++; } int ans = 1, flag = 0; for (int i = 0; i < 26; i++) { if (freq[i] > 0 && freq[i] % 2 == 1) { flag++; if (flag > 1) { an...
2