solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 20; vector<int> children[maxn]; int N, depth[maxn], max_dep; void dfs(int n, int dep) { depth[dep]++; max_dep = max(max_dep, dep); for (int i = 0; i < children[n].size(); i++) { int t = children[n][i]; dfs(t, dep + 1); } } int main(...
4
#include <bits/stdc++.h> using namespace std; long long ans = 0, n, b, c, i, j, x, y; int main() { scanf("%lld%lld%lld%lld", &n, &x, &y, &c); b = x / 2 + y; for (i = 0; i <= b; i++) { for (j = 0; j <= c; j++) { if (i + j * 2 == n) { if (j * 2 == n) { ans++; continue; ...
2
#include<bits/stdc++.h> using namespace std; int main() { int a, b, h; cin >> a >> b >> h; cout << (h/2)*(a+b); }
0
#include <bits/stdc++.h> using namespace std; const int N = 105; char tunnel[3][N]; bool vis[3][N]; int n, k; int sx, sy; int main() { int cases; scanf("%d", &cases); for (int cas = 1; cas <= cases; cas++) { scanf("%d %d", &n, &k); memset(vis, 0, sizeof(vis)); for (int row = 0; row <= 2; row++) { ...
2
#define _USE_MATH_DEFINES #define INF 0x3f3f3f3f #include <cstdio> #include <iostream> #include <sstream> #include <cmath> #include <cstdlib> #include <algorithm> #include <queue> #include <stack> #include <limits> #include <map> #include <string> #include <cstring> #include <set> #include <deque> #include <bitset> #in...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int t, n, p; int main() { cin.sync_with_stdio(0); cin.tie(); cin.exceptions(cin.failbit); cin >> t; while (t--) { cin >> n; vector<int> vec; for (int i = 1; i <= n; i++) { cin >> p; vec.push_back(p); } rever...
1
#include <bits/stdc++.h> using namespace std; int N, M; char ar[2010][2010]; inline void f(int k, int l) { if (k < 1 || l < 1 || k > N || l > M) return; if (ar[k][l] != '.') return; int res = 0; if (k + 1 <= N && ar[k + 1][l] == '.') res++; if (k - 1 >= 1 && ar[k - 1][l] == '.') res++; if (l + 1 <= M && ar[...
2
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long calc(long long n, long long x) { long long z = 0; while (n) { z += n / x; n /= x; } return z; } long long mul(long long x, long long y) { x %= mod; y %= mod; return (x * y) % mod; } long long pp(long long x, lon...
3
#include <bits/stdc++.h> using namespace std; long long n, i, a, b, x[100001], y[100001], j; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (i = 0; i < n; i++) { cin >> a; x[a]++; cin >> y[i]; } for (i = 0; i < n; i++) { a = n - 1 + x[y[i]]; b = 2 * (n - 1) - a; cout...
2
#include <bits/stdc++.h> using namespace std; const int MOD = 3046201; string s; bool use[150]; int main() { while (getline(cin, s)) { long long ans = 1; int cnt = 0; int len = s.size() - 1; memset(use, false, sizeof(use)); int c = 10; if (s[0] == '?') ans = 9; else if (s[0] >= 'A' &...
1
#include <bits/stdc++.h> using namespace std; bool ok(const string& a, const string& b) { if (a.size() != b.size()) return false; for (int i = 0; i < a.size(); i++) if (not(b[i] == '.' or b[i] == a[i])) return false; return true; } int main() { vector<string> P = {"vaporeon", "jolteon", "flareon", "espeon",...
1
#include <bits/stdc++.h> using namespace std; int n; string s, t; int P[2000000]; bool VIS[2000000]; int C[2000000], E[2000000]; int brute[50][50][50]; int L[2000000]; void dfs(int v, int len) { if (v == -1) return; if (VIS[v] && len == 0) return; if (VIS[v]) { C[v] = len; return; } VIS[v] = true; d...
3
#include <bits/stdc++.h> using namespace std; long long w[100005]; int n, m; bool cmp(long long A, long long B) { return A > B; } bool can(long long K) { if (K & 1) return K * (K - 1) / 2 <= n - 1; return K * K / 2 <= n; } int binary(int r) { while (r) { if (can(r)) return r; r--; } } int main() { cin...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string s; cin >> s; if (k == 0) cout << s << endl; else if (n == 1 && k > 0) cout << "0" << endl; else if (k >= n && n > 1) { cout << 1; for (int i = 1; i < n; i++) cout << 0; cout << endl; } else if ...
2
#include<iostream> #include<string> using namespace std; struct dice{ int num[10]; }; dice d, d2, t, z; dice hoge(dice d){ int temp = d.num[6]; d.num[6] = d.num[2]; d.num[2] = d.num[1]; d.num[1] = d.num[5]; d.num[5] = temp; return d; } dice fuga(dice d){ int temp = d.num[6]; d.num[6] = d.num[3]; ...
0
#include <bits/stdc++.h> using namespace std; int n, ans, az; double et[21][21], f[1 << 19]; int main() { scanf("%d", &n); for (int i = (1); i <= n; i++) for (int j = (1); j <= n; j++) scanf("%lf", &et[i][j]); f[(1 << n) - 1] = 1; for (int s = ((1 << n) - 2); s >= 1; s--) { ans = 0, az = s; while (a...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int vis[N]; int ans; int n, m; char s[N]; void dfs(int x, int y) { if (ans) return; if (x == n - 1 && y == m - 1) { ans++; return; } if (x + 1 < n && vis[(x + 1) * m + y] == 0) { vis[(x + 1) * m + y] = 1; dfs(x + 1, y); } ...
4
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1e6 + 5; long long int power(long long int base, long long int exp) { long long int res = 1; while (exp) { if (exp % 2) res *= base; base *= base; res %= mod; base %= mod; exp /= 2; } return res; } int ma...
2
#include <cstdio> #include <cstdlib> #define fo(i,a,b) for(int i=a;i<=b;i++) #define fod(i,a,b) for(int i=a;i>=b;i--) #define min(q,w) ((q)>(w)?(w):(q)) #define abs(q) ((q)<0?-(q):(q)) using namespace std; const int N=500500; int read(int &n) { char ch=' ';int q=0,w=1; for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar(...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; string s; for (i = 1; s.size() < 11000; i++) { s = s + to_string(i); } cout << s[n - 1] << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAXN = 305; int a[MAXN], cnt[MAXN], vis[MAXN], C[MAXN][MAXN], fac[MAXN], f[MAXN][MAXN]; vector<int> size; int n, N, total = 0; void init() { C[0][0] = 1; for (int i = 1; i < MAXN; i++) C[i][0] = C[i][i] = 1; for (int i = 2; i < MAXN;...
3
#include<bits/stdc++.h> using namespace std; int main() { string a; cin>>a; if((a.length()%2==1)^(a[a.length()-1]==a[0])==1)cout<<"First\n"; else cout<<"Second\n"; return 0; }
0
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; const int MAX_N = 1e6 + 7; int n, k; std::vector<int> gr[MAX_N]; std::pair<int, int> drev[MAX_N]; int d[MAX_N]; int pre[2][MAX_N], dep[MAX_N], po = 0; int dfs(const int& cur, const int& depth) { pre[0][cur] = po++; dep[cur] = depth; for (const auto& nei : gr[cu...
6
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; int main() { int a, b, n; cin >> n; while (n--) { cin >> a >> b; cout << b * 2 << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; bool bfs(string s[], int n, int m, map<pair<int, int>, bool> &vis) { if (s[n - 1][m - 1] == '#') return 0; queue<pair<int, int> > q; q.push({n - 1, m - 1}); vis[{n - 1, m - 1}] = 1; while (!q.empty()) { pair<int, int> p = q.front(); int i = p.first; in...
4
#include <bits/stdc++.h> using namespace std; struct edge { int x, y, g, s; edge() : x(0), y(0), g(0), s(0) {} edge(int x_, int y_, int g_, int s_) : x(x_), y(y_), g(g_), s(s_) {} void operator=(const edge& rhs) { x = rhs.x; y = rhs.y; g = rhs.g; s = rhs.s; } }; int n, m, uf[205]; bool f[50005...
1
#include <bits/stdc++.h> using namespace std; long long n, m; double p, a, b, ans = 1e18; pair<double, double> w[2003]; long long poww(long long x, long long y) { if (x == 0) return 0; if (x == 1) return 1; if (y == 0) return 1; if (y == 1) return x; long long d = poww(x, y / 2); d *= d; if (y % 2) return...
2
#include <bits/stdc++.h> using namespace std; const long long infl = 1e8 + 5; long long int n, m, k, q, x, y, mx = -1, mn = infl, f, val, sz, sm, cnt, ans, t = 1, i, j, ind = -1; char a[104][104]; int dist[104][104]; int xa[] = {0, 1, 0, -1}; int ya[] = {1, 0, -1, 0}; std::map<pair<long ...
4
#include <bits/stdc++.h> int n, m, f[153][53][53][53], v[151][3], z, p = 51123987, u; char s[160]; void inc(int &x, int y) { x = (x + y) % p; } int K(int x, int y) { return x - y < 2 && y - x < 2; } int main() { scanf("%d%s", &n, s + 1); for (int i = n; i; i--) v[i][0] = v[i + 1][0], v[i][1] = v[i + 1][1], v[i]...
3
#include<cstdio> #include<cstring> #include<algorithm> #include<vector> using namespace std; typedef long long ll; inline int rd(){ char c=getchar();int x=0,flag=1; for(;c<'0'||c>'9';c=getchar())if(c=='-')flag=-1; for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0'; return x*flag; } int len,sz[26]={0},nw[26]={0},c[200010]...
0
#include <bits/stdc++.h> using namespace std; char s[1010]; int main() { int n; scanf("%d", &n); scanf(" %s", s); for (int i = 0; i < n; ++i) { for (int j = 1; j <= n; ++j) { bool ok = 1; for (int k = 0; k < 5; ++k) { int t = i + j * k; if (t >= n || s[t] == '.') { ok =...
1
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int rand(int x, int y) { ++y; return (rng() % (y - x)) + x; } int TC, N, M; int A[1000010], B[1000010]; pair<int, int> C[1000010]; int D[1000010]; struct node { int second, e, m, lazy = 0; p...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int B[n / 2]; for (int i = 0; i < n / 2; i++) { B[i] = a[i] + a[n - i - 1]; } long long int total = 0; for (int i = 0; i < n / 2; i++) { to...
3
#include <bits/stdc++.h> int t; char a[2010], b[2010]; int main() { scanf("%d", &t); while (t--) { scanf("%s%s", a + 1, b + 1); int n = strlen(a + 1), m = strlen(b + 1); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m && i + j - 1 <= n; j++) if (a[i + j - 1] != b[j]) break;...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; const int inf = 0x3f3f3f3f; int n, m, S[maxn], M[maxn], R[maxn], b[maxn], c[maxn]; long long sumM[maxn]; inline pair<long long, long long> operator+(pair<long long, long long> a, pair<long long, long ...
5
#include <bits/stdc++.h> using namespace std; std::mt19937 rnd( (int)std::chrono::steady_clock::now().time_since_epoch().count()); long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 500000; const int MAXQ = 100000; const int MAXS = 4 * MAXN; struct Val { int sz, prefl,...
6
#include <bits/stdc++.h> using namespace std; char O[100010]; string s, t; int n, m; int dp[40][100010]; const int MAX = 300010; string txt; int iSA[MAX], SA[MAX]; int cnt[MAX], hehe[MAX]; bool bh[MAX], b2h[MAX]; bool smaller_first_char(int a, int b) { return txt[a] < txt[b]; } void suffixSort(int n) { for (int i = 0...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 99999; int d[maxn], s[maxn]; int n; int m; queue<int> q; vector<pair<int, int> > p; bool inq[maxn]; int main() { cin >> n; for (int i = 0; i < n; i++) { scanf("%d %d", &d[i], &s[i]), m += d[i]; if (d[i] == 1) q.push(i); } m /= 2; while (!q...
1
#include <bits/stdc++.h> using namespace std; using namespace std; int N; long long int pt[100005][2]; long long int CP(long long int x1, long long int y1, long long int x2, long long int y2) { return x1 * y2 - y1 * x2; } bool dir(long long int x1, long long int y1, long long int x2, long lo...
5
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=100010; int n,tot,Next[N<<1],head[N],tree[N<<1],In[N],color[N],Q[N],sum,Max,a[N],f[N],g[N]; char s[N]; bool vis[N]; void add(int x,int y) { tot++; Next[tot]=head[x]; head[x]=tot; tree[tot]=y; } int calc(int id,int x) { return (!...
0
#include <bits/stdc++.h> typedef long long ll; const ll M = 1000000007; int n, m, k; ll f[1000010], fi[1000010], thr[1000010], ans; ll pw(ll x, ll k){ if(k == 1) return x; return (k % 2 ? x : 1) * pw(x * x % M, k / 2) % M; } ll cm(int n, int r){ return f[n] * fi[r] % M * fi[n - r] % M; } ll cal(int x, int b){ l...
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") using namespace std; const int N = 100005; const int inf = 1000 * 1000 * 1000; const int mod = 1000 * 1000 * 1000 + 7; int n, m; vector<int> g[N]; int p[N],...
5
#include<iostream> using namespace std; typedef long long ll; int main(){ ll n,t,sum=0; cin>>n; for(int i=0;i<n;i++){ cin>>t; sum+=t; } cout<<sum/n<<endl; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long int; int main() { cin.tie(0); ios::sync_with_stdio(false); int t; cin >> t; for (int i = 0; i < t; i++) { int n, m; cin >> n >> m; vector<int> used(n * 3, 0); vector<int> matching; for (int j = 0; j < m; j++) { int u,...
5
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll const int mod = 1000000007; inline int fastpow(int a, int n) { int ans = 1; while(n) { if(n & 1) ans = ans * a % mod; a = a * a % mod; n >>= 1; } return ans; } inline int inv(int x) { return fastpow(x, mod - 2); } int inv2...
4
#include <bits/stdc++.h> using namespace std; using namespace std; void init() { cin.tie(0); cin.sync_with_stdio(0); cout.tie(0); } struct point { double x, y; point() { x = y = 0.0; } point(double _x, double _y) : x(_x), y(_y) {} bool operator<(point other) const { if ((fabs(x - other.x) > 1e-9)) ret...
2
#include <bits/stdc++.h> long long T, n, m; int main() { scanf("%lld", &T); while (T--) { scanf("%lld%lld", &n, &m); if (n == 1) printf("%lld\n", n - 1); else if (n == 2) printf("%lld\n", m); else printf("%lld\n", 2 * m + 1 - 1); } }
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1510; int n, q, tim, f[maxn], c[maxn][maxn], vis[maxn * maxn]; vector<pair<int, int>> S[maxn][maxn]; int main() { scanf("%d %d", &n, &q); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { scanf("%d", &c[i][j]); ...
4
#include<cstdio> #include<cmath> int n,m,a[100][100],ans,sum,t; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) scanf("%d",&a[i][j]); for(int j=1;j<i;j++) { sum=0; for(int k=1;k<=m;k++) sum+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]); t=sqrt(sum); if(t*t==sum)ans++; ...
0
#include <bits/stdc++.h> using namespace std; int A[1000000]; int S[1000000]; int T[1000000]; int P[1000000]; long long N, K, L; long long LN; long long R = 0; int TL = 0; long long mul(long long a, long long b) { return (a * b) % 1000000007; } long long add(long long a, long long b) { return (a + b) % 1000000007; } vo...
2
#include<bits/stdc++.h> #define N 400005 using namespace std; int n,fa[N],rd[N],fl[N],a[N]; vector<int>s[N]; void OK() { puts("POSSIBLE"); exit(0); } void dfs(int x) { //cout<<x<<endl; rd[x]=-1; for (int i=0;i<s[x].size();i++) fl[a[s[x][i]]]=x; for (;fl[a[x]]==x;a[x]++); rd[fa[x]]--; s[fa[x]].push_back(x); i...
0
#include <bits/stdc++.h> using namespace std; long long const M = 2e5 + 10, M2 = 1e7 + 10, mod = 1e9 + 7, inf = 1e9 + 10; long double seg[M * 4], lazy[M * 4], p[M * 4]; long long tmp; void shift(long long id1, long long id2, long long len) { p[id2] *= p[id1]; seg[id2] = (p[id1]) * seg[id2] + lazy[id1] * (long doubl...
5
#include <bits/stdc++.h> using namespace std; template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; } template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define l...
0
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); std::cin.tie(NULL); long long T; cin >> T; while (T--) { long long n; cin >> n; long long A[n]; for (int i = 0; i < n; i++) cin >> A[i]; int l = 0; while (l < n) { if (A[l] == 0) ...
2
#include <bits/stdc++.h> using namespace std; struct node { int l, r; mutable int v; node(int L, int R = -1, int V = 0) : l(L), r(R), v(V) {} bool operator<(const node &o) const { return l < o.l; } }; int n, m, k, las, f[15][15]; char s[200005]; set<node> st; set<node>::iterator split(int pos) { set<node>::it...
5
#include <bits/stdc++.h> using namespace std; const long long INF = 1001001001001001001ll; int size; vector<long long> val; vector<long long> lazy; void lazy_propagate(int p) { if (lazy[p] != -1) { val[p] = lazy[p]; if (p < size-1) { lazy[p*2+1] = lazy[p]; lazy[p*2+2] = la...
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);} ll ans[510][510]; int n; int prime[20010], cnt; int np[20010]; int main() { scanf("%d", &n); if (n == 2) return puts("4 7\n23 10"), 0; for (int i = 0; i <= n + 1; i++) ans[0][i]...
0
#include <bits/stdc++.h> using namespace std; int sum[210], b[210]; int bj[210], maxp[20], minp[20]; int n, k; int main() { scanf("%d%d", &n, &k); sum[0] = 0; for (int i = 1; i <= n; i++) { scanf("%d", &b[i]); sum[i] = sum[i - 1] + b[i]; } int ans = -10000; for (int i = 1; i <= n; i++) { for (in...
1
#include <bits/stdc++.h> const int oo = 2e5 + 7; int n, a[oo]; int left[oo], right[oo]; bool solve() { int x = 0, y = n - 1; bool alice = true; int maxx = -1; while (x < y) { bool levi = a[x] >= a[y]; if (std::max(a[x], a[y]) <= maxx) return !alice; if (levi) { int kraj = left[x + 1]; if...
5
#include <bits/stdc++.h> using namespace std; const int mol = 1e9 + 9; long long solve(long long a, long long y) { long long ans = 1; while (y) { if (y & 1) ans = (ans * a + mol) % mol; a = (a * a + mol) % mol; y >>= 1; } return ans; } int main() { long long n, m, k, cnt, sum = 0, pp; scanf("%I6...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); vector<int> cnt(n + 1, 0); int sum = 0; for (int i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; cnt[i] += sum; } int k; int num = 0; for (int i = 0; i < n; i++) for (int j = i; j < n; j++) {...
1
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << (((a*b)%2)?"Odd":"Even") << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef unsigned int UI; typedef long int LI; typedef unsigned long int ULI; typedef long long int LL; typedef unsigned long long int ULL; LL mod = 1e9 + 7; inline int scanInt() { int n = 0; char ch = getchar(); int sign = 1; while (ch < '0' || ch > '9') { if (c...
2
#include <bits/stdc++.h> using namespace std; int n; long long d[2020][2020]; int level[2020]; long long oo = 1e15; vector<vector<int> > adj(2020); priority_queue<pair<long long, pair<int, int> > > pq; long long dist[2020]; bool vis[2020]; vector<int> id, lvl; int indx[4040]; void dfs(int i, int l, long long c, int p) ...
4
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cout.tie(0); long long int n, m; cin >> n >> m; if (n == 0 && m != 0) { cout << "Impossible" << endl; } else if (n != 0 && m != 0) { if (n > m) { cout << n << " "; cout << (n - 1) + m << endl; } else if (n < m) { ...
1
#include <bits/stdc++.h> using namespace std; int get() { int f = 0, v = 0; char ch; while (!isdigit(ch = getchar())) if (ch == '-') break; if (ch == '-') f = 1; else v = ch - '0'; while (isdigit(ch = getchar())) v = v * 10 + ch - '0'; if (f) return -v; else return v; } const int max...
5
#include <bits/stdc++.h> using namespace std; struct node { int t; int p; }; stack<int> ans; node order[200010]; node stk[200010]; int num[200010]; int n, m, top, pos; int cmp1(int u, int v) { return u < v; } int cmp2(int u, int v) { return u > v; } void init() { int i, j, maxx; stk[0].t = 0, stk[0].p = 0; ma...
3
#include <bits/stdc++.h> using namespace std; const int sz = 1e3, sz2 = 1e5 + 10, mod = 1e9 + 7; int nex[sz][32], sm[sz][sz]; unsigned int nmask[sz][32]; unsigned int f(unsigned int mask, int x) { unsigned int re = mask | (1 << x); for (int i = 0; i < 32; i++) { if (mask & (1 << i)) re |= (1 << (i ^ x)); } ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m, sum = 0; cin >> n >> m; vector<int> vec; for (int i = 0; i < n; ++i) { int a; cin >> a; vec.push_back(a); } sort(vec.begin(), vec.end()); for (int i = 0; i < m; ++i) { if (vec[i] <= 0) sum = sum + vec[i]; } cout << ab...
2
#include <bits/stdc++.h> #define MAX_N 3000 using namespace std; typedef long long lnt; template <class T> inline void read(T &x) { x = 0; int c = getchar(), f = 1; for (; !isdigit(c); c = getchar()) if (c == 45) f = -1; for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-48); } int n; lnt P, C[MAX_N+5][MAX_N+5]; ln...
0
#include<iostream> using namespace std; int main(){ int a,b;cin>>a>>b; int c=(a+b)%24; cout<<c<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long a[10005], i, j, k, m, p, ans; while (cin >> k) { m = 0; ans = 0; for (i = 0; i < k; i++) { cin >> a[i]; } for (i = 0; i < k; i++) { for (j = i; j < k; j++) { for (p = i; p <= j; p++) m = m ^ a[p]; an...
1
#include <bits/stdc++.h> using namespace std; long long N, A[100]; int main(void) { cin >> N; for (long long i = ((long long)0); i < ((long long)N); i++) cin >> A[i]; bool ans = true; long long p1 = 1, p2 = 2, s = 3; for (long long i = ((long long)0); i < ((long long)N); i++) { if (A[i] == p1) { swa...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, i, j, x = 1, cn = 0; cin >> n >> m; int a[m]; for (i = 0; i < m; i++) cin >> a[i]; for (i = 0; i < m; i++) { if (a[i] > x) { cn += a[i] - x; x = a[i]; } if (a[i] < x) { cn += n - x + a[i]; x = a[...
2
#include<cstdio> int main(){ int N,Ans=0; scanf("%d",&N); for(int i=1;i<=N;i+=2){ int cnt=0; for(int j=1;j<=i;j++) cnt+=i%j==0; Ans+=cnt==8; } printf("%d",Ans); }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int a[maxn]; int dp[110][110]; int main() { int n, ans = 0; cin >> n; while (n--) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; for (int i = y1; i <= y2; i++) { for (int j = x1; j <= x2; j++) { dp[i][j]++; ...
1
#include <bits/stdc++.h> using namespace std; int dp[1 << 24]; int n, a[30]; int dfs(int state, int p) { int v; if (dp[state]) return dp[state]; v = __builtin_popcount(state); int ret = 1e9; for (int i = 0; i < p; i++) { for (int j = 0; j <= i; j++) { if (a[i] + a[j] != a[p]) continue; int tmp...
4
#include <bits/stdc++.h> int n, head[1001], nxt[2001], b[2001], k, size[1001], mx[1001], root; void push(int s, int t) { nxt[++k] = head[s]; head[s] = k; b[k] = t; } void getroot(int x, int f) { size[x] = 1, mx[x] = 0; for (int i = head[x]; i; i = nxt[i]) if (b[i] != f) { getroot(b[i], x); siz...
4
#include <bits/stdc++.h> using namespace std; string str; int ar[100010]; int main() { ios::sync_with_stdio(false); int i, j, x, y, n, m = 0, k, a, b, c, d, e, f, wa; cin >> n >> k; cin >> str; for (int i = 0; i <= n - 1; i++) { if (str[i] == '0') ar[m] = i + 1, m++; } wa = n; for (int i = 0; i <= m...
3
#include <bits/stdc++.h> using namespace std; int n, k; int C[1000100]; long long sum; long long avgfloor, avgceil; long long f1(long long cut) { long long ret = 0; for (int i = n - 1; i >= 0; i--) { if (C[i] <= cut) break; ret += C[i] - cut; } return ret; } long long bs1() { long long l = avgceil, r ...
2
#include <bits/stdc++.h> using namespace std; int n, x; int t[2200], h[2200], m[2200], vis[2200]; int main() { while (~scanf("%d%d", &n, &x)) { for (int i = 0; i < n; i++) { scanf("%d%d%d", &t[i], &h[i], &m[i]); } int heigh = x; memset(vis, 0, sizeof(vis)); bool flag = 1; int tag = 0; ...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } int n; int m; int ans[10][10][10][2][8]; int was[10][10][10][2][8]; pair<pair<int, int>, pair<int, int> > prev239[10][10][10][2][8]; int pflag[10][10][10][2][8]; int ppa[10...
5
#include<iostream> #include<sstream> using namespace std; typedef long long ll; ll pw(ll b,ll e){ ll i,r=1; for(i=0;i<e;i++)r*=b; return r; } int main(){ ll n,k; while(cin>>n>>k,n){ ll m,s,r; for(m=1;n>9*m*pw(10,m-1);m++)n-=9*m*pw(10,m-1); for(r=0;n>m;r++)n-=m; s=pw(10,m-1)+r; stringstream ans; while(a...
0
#include <bits/stdc++.h> using namespace std; int a[100004], b[100004], d[100004]; vector<int> c; int search(int x, int l, int r) { if (r - l <= 1) { if (c[r] <= x) return r; else if (c[l] > x) return -1; else return l; } int m = (l + r) / 2; if (c[m] == x) return m; else if ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int data[N]; int temp[N]; int n; bool check(int nn, int mm, int x, int y) { memset(temp, 0, sizeof(temp)); for (int i = 1; i <= nn; i++) { for (int j = 1; j <= mm; j++) { int a = abs(i - x) + abs(j - y); temp[a]++; } } for ...
4
#include <bits/stdc++.h> using namespace std; const pair<int, int> DD[] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; template <class T> T smin(T &a, T b) { if (a > b) a = b; return a; } template <class T> T smax(T &a, T b) { if (a < b) a = b; return ...
5
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int inf = 0x3f3f3f3f; #define dbg(x...) do { cout << "\033[32;1m" << #x <<" -> "; err(x); } while (0) void err() { cout << "\033[39;0m" << endl; } template<class T, class... Ts> void err(const T& arg,const Ts&... args) { cout << arg << " "; err(ar...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int sum[maxn], num[maxn], n, k, q; int main() { cin >> n >> k >> q; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; num[a]++, num[b + 1]--; } for (int i = 1; i < maxn; i++) { num[i] += num[i - 1]; sum[i] = sum[i ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long int x; cin >> x; if (x % 3 == 0) { cout << x / 3 << " " << x / 3 << '\n'; } else { long long temp = x / 3 + 1; ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } long long ans = 0; for (long long i = 30; i >= 1; i--) { long long max_sum = 0; for (long long j = 0; j < n; j++) { if (a[j] > i) { ...
4
#include <bits/stdc++.h> using namespace std; int n, a[100005]; int test(int x, int y) { swap(a[x], a[y]); int da = 0, xi = 0; for (int i = 2; i <= n; i++) { if (a[i] > a[i - 1]) da = 1; else if (a[i] < a[i - 1]) xi = 1; } swap(a[x], a[y]); return da + xi; } int main() { cin >> n; fo...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string s[n]; for (int i = 0; i < n; i++) { if (i % 2 == 0) { for (int j = 0; j < m; j++) s[i] += '#'; } else { for (int j = 0; j < m - 1; j++) s[i] += '.'; s[i] += '#'; } } for (int i = 3; i < n...
1
#include <bits/stdc++.h> using namespace std; long long factorial(long long n) { if (n == 1) { return 1; } else { return n * factorial(n - 1); } } long long gcd(long long a, long long b) { return factorial(min(a, b)); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long a, b; cin...
1
#include <bits/stdc++.h> int dr[] = {2, 2, -2, -2, 1, -1, 1, -1}; int dc[] = {1, -1, 1, -1, 2, 2, -2, -2}; int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1}; int dr2[] = {0, 0, 1, -1}; int dc2[] = {1, -1, 0, 0}; using namespace std; long long b[12][12], n; string t; struct data { int a[...
5
#include<iostream> using namespace std; void solve(char* s, int n){ char prev=s[0]; char curr=s[0]; bool arr[26]={0}; arr[curr-65]=1; for(int i=0; i<n ;i++){ curr=s[i]; if(curr==prev){ continue; } if(arr[curr-65]!=0){ cout<<"NO"<<endl; return; } arr[curr-65]=1; prev=curr; } cout<<"YES"<<...
1
#include <bits/stdc++.h> using namespace std; template <class T> const T& max(const T& a, const T& b, const T& c) { return max(a, max(b, c)); } template <class T> const T& min(const T& a, const T& b, const T& c) { return min(a, min(b, c)); } long long stoi(string& str) { istringstream second(str); long long i; ...
4
#include <bits/stdc++.h> using namespace std; constexpr int const maxn = 5120; int d[maxn], fa[maxn], f[maxn], g[maxn], id[maxn]; vector<pair<int, int>> adj[maxn]; void dfs(int u, int p, int i) { d[u] = d[p] + 1; fa[u] = p; id[u] = i; for (auto const& e : adj[u]) if (e.first != p) dfs(e.first, u, e.second);...
6
#include <bits/stdc++.h> using namespace std; long long n, i, j, k, m, c; void solve() { cin >> n; vector<pair<long long, long long> > a; for (i = 0; i < n; i++) { cin >> j; a.push_back({j, i}); } string b; cin >> b; long long int ans[b.size()]; sort(a.begin(), a.end()); priority_queue<pair<lo...
2
#include <bits/stdc++.h> using namespace std; long long a, b, x, n; void input() { cin >> a >> b >> n >> x; return; } long long powmod(long long a, long long b) { if (b == 1) return a; if (b < 1) return 1; long long t = powmod(a, b / 2) % 1000000007; t = (t * t) % 1000000007; if (b % 2 == 1) { t = (t ...
4
#include<bits/stdc++.h> using namespace std; int main() { int r; cin>>r; cout<<(3*r*r); return 0; }
0