solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const int M = 1000; set<int> zb; set<int>::iterator it; int sp[M + 5], i, j, k, l, i1, j11, k1, d, suma, kk, m; vector<int> liczby, znaki; int odczytaj(int a, int z1, int b, int z2, int c, int z3, int d) { int i, res, dod; liczby.resize(0); ...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n, k; cin >> n >> k; int ara[n + 1]; for (int i = 0; i < n; ++i) ara[i] = i + 1; int sz = k, first = 0, last = n - 1, cnt = 0; bool accf = 1, ...
1
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int32_t M = 1e9 + 7; void solve() { long long n, k; cin >> n >> k; vector<long long> arr(n), temp(n); for (auto &x : arr) cin >> x; temp = arr; sort((arr).begin(), (arr).end()); unordered_map<long long, long long> mp; for (l...
2
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; while (k--) { int n; cin >> n; string s, t; cin >> s >> t; vector<int> cnt; for (int i = 0; i < n; i++) { if (s[i] != t[i]) cnt.push_back(i); } int cur = cnt.size(); if (cur == 0) { puts("Ye...
2
#include <bits/stdc++.h> using namespace std; int32_t main() { int n; cin >> n; if (n == 2) return cout << -1, 0; cout << "385\n21\n165\n"; for (int i = 0; i < n - 3; i++) { cout << 21 * (i + 100) << endl; } }
4
#include <bits/stdc++.h> using namespace std; const int N = 2010; char mat[N][N]; int dp[N][N][4]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%s", mat[i] + 1); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (mat[i][j] == '#') continue;...
6
#include <bits/stdc++.h> using namespace std; const int mod=1000000007; int n,x,y,z,dp[45][1<<17]; int main() { scanf("%d%d%d%d",&n,&x,&y,&z); int mask=(1<<(x+y+z))-1; int valid=(1<<(x+y+z-1))+(1<<(x+y-1))+(1<<(x-1)); dp[0][0]=1; for (int i=1;i<=n;++i) for (int j=1;j<=10;++j) for...
0
#include <bits/stdc++.h> using namespace std; int const N = 100 + 5; int n, m, x, u, v, arr[N]; vector<int> adj[N]; set<int> my_set; bool vis[N]; void dfs(int u) { vis[u] = 1; for (auto child : adj[u]) { if (!vis[child]) { dfs(child); } } } int main() { ios_base::sync_with_stdio(false); int c = ...
3
#include <bits/stdc++.h> using namespace std; #define ll long long const int maxn=1e5+5; int main() { ios::sync_with_stdio(false); cin.tie(0); ll t,n,i,j,k,a[maxn],b[maxn],c[maxn],result,here; cin>>t; while (t--){ cin>>n; result=0; for(i=1;i<=n;i++){ cin>>c[i]; ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const long long INF = 1e18; long long dp[N][3]; long long val[N]; long long a, b; int n; vector<long long> gcd; void init(long long x) { for (long long i = 2; i * i <= x; i++) { if (x % i == 0) gcd.push_back(i); while (x % i == 0) x /= i; ...
2
#include <bits/stdc++.h> using namespace std; long long bigmod(long long a, int p, long long int m) { if (p == 0) return 1; if (p & 1) { return ((a % m) * (bigmod(a, p - 1, m))) % m; } else { long long tmp = bigmod(a, p / 2, m); return (tmp * tmp) % m; } } vector<long long int> v1; void SieveOfErato...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; int x = 0; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; if (a > x) { cout << "NO"; return 0; } x = max(x, b); } if (x == m) ...
1
#include <bits/stdc++.h> using namespace std; int n, v[110], f[110], dp[11000][110], c[110][110]; int main() { int cnt = 0, sum = 0, ans = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> v[i]; sum += v[i]; f[v[i]]++; if (f[v[i]] == 1) cnt++; } c[0][0] = 1; for (int i = 1; i <= n; i++) { ...
5
#include <bits/stdc++.h> using namespace std; const int NICO = 1e6 + 7; int n; int pre[NICO], a[NICO]; long long dp[NICO]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } int p = 1; for (int i = 2; i <= n; i++) { dp[i] = max(dp[p - 1] + abs(a[i] - a[p]), dp[p] + abs(...
4
#include <bits/stdc++.h> int main() { int k; std::cin>>k; int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; std::cout << a[k-1] << std::endl; }
0
#include <bits/stdc++.h> using namespace std; const int N = 200005, M = N - 5; using ll = long long; int n, m; vector<int> g[N]; ll lp, rp; int main() { ios::sync_with_stdio(false); cin >> n >> m >> lp >> rp; for (int i = 1; i <= M; i++) for (int j = i; j <= M; j += i) g[j].push_back(i); int cl = m + 1, cr ...
6
#include <bits/stdc++.h> using namespace std; int main() { char code[5][5]; for (int i = 0; i < 3; ++i) { cin >> code[i]; } if (code[0][0] == code[2][2] && code[0][2] == code[2][0] && code[0][1] == code[2][1] && code[1][0] == code[1][2]) { cout << "YES\n"; } else { cout << "NO\n"; } retu...
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, m; cin >> n >> m; vector<long long int> x(n); for (long long int i = 0; i < n; i++) cin >> x[i]; double ans = 0; for (long long int i = 0; i < m; i++) { long long int a, b,...
3
#include <iostream> using namespace std; int a[200005],qzh[200005]; int n,k; inline bool pd(int x) { for(int i=1;i<=n;i++) { if(a[i]>=x) qzh[i]=qzh[i-1]+1; else qzh[i]=qzh[i-1]-1; } int mn=n; for(int i=k;i<=n;i++) { mn=min(mn,qzh[i-k]); if(qzh[i]>mn) return 1; } return 0; } int main(int argc, char** arg...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v(n, 0); vector<int> cnt(33, 0); int high = 0; bool ans = true; for (int i = 0; i < n; i++) { cin >> v[i]; int j = 0; int a = v[i]; while (a) {...
2
#include <bits/stdc++.h> using namespace std; bool isPrime(int n) { if (n == 2 || n == 3 || n == 5) return true; if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0) return false; for (int i = 7; i * i <= n; i++) if (n % i == 0) return false; return true; } void printA() { printf("Ashishgup\n"); } void printB() { pr...
3
#include <bits/stdc++.h> using namespace std; string match = "abacaba"; string ans; bool call(long long i, long long n, string s) { long long j = i; long long k = 0; while (j < n && k < 7 && (s[j] == match[k] || s[j] == '?')) { s[j] = match[k]; j++; k++; } long long count = 0; if (k == 7) { ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 100100; int f[maxn]; int main() { int n, m, k; while (scanf("%d%d%d", &n, &m, &k) != EOF) { memset(f, 0, sizeof(f)); for (int i = 1; i <= n; i++) { char ch; scanf(" %c", &ch); f[i] = ch - '0'; } if ((f[m] + f[k]) % 2 ==...
1
#include <bits/stdc++.h> using namespace std; struct edg { int from, to, next; } b[500000 * 2 + 5], ob[500000 + 5], nb[500000 * 10 + 5]; int g[500000 + 5], cntb, n, m, k, group[500000 + 5], dis[500000 + 5], cntg, cnte, belong[500000 + 5], ndis[500000 * 2 + 5]; int ng[500000 * 2 + 5], cntn; long long ans; bool ise...
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int maxn = 2e5 + 10; const int inf = 0x7fffffff; const long long INF = 9E18; const int mod = 1e9 + 7; const long long mod2 = 1e9 + 9; const int eps = 1e-7; const double pi = acos(-1.0); template <typename T> inline...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 202020; int a[maxn]; int sol[maxn * 2][2]; int n, m, p; int main() { scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); if (a[i] == m) p = i; } memset(sol, 0, sizeof(sol)); int sum = 0; sol[0 + n][0] = 1; for (in...
5
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; while (cin >> n >> k) { long long t[n]; for (int i = 0; i < (int)n; i++) cin >> t[i]; sort(t, t + n); set<long long> S; long long cnt = 0; for (int i = 0; i < (int)n; i++) { if (S.count(t[i])) continue; cn...
1
#include <bits/stdc++.h> using namespace std; int main(){ int t; while(cin>>t&&t){ int n,s,f,sum=0; cin>>n; for(int i=0;i<n;i++){ cin>>s>>f; sum+=f-s; } if(sum>=t)cout<<"OK"<<endl; else cout<<t-sum<<endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; struct edge { int u, v; long long w; }; long long MOD = 1000000007; long long _MOD = 1000000009; int INF = INT_MAX / 10; double EPS = 1e-10; int main() { int N, M; cin >> N >> M; vector<vector<int> > G(N); vector<vector<int> > d(N, vector<int>(N, INF)); for (i...
4
#include<map> #include<set> #include<cmath> #include<deque> #include<queue> #include<stack> #include<string> #include<bitset> #include<cstdio> #include<vector> #include<iomanip> #include<cstring> #include<sstream> #include<iostream> #include<algorithm> #include<unordered_map> //#include<bits/stdc++.h> #define fi first ...
6
#include <bits/stdc++.h> using namespace std; const int inf = 1e8; const long double pi = 3.141592653589793238; int MOD = 998244353; const int N = 1e6 + 22; int n, k, p[N], q[N]; bool vis[N] = {0}; int seg[4 * N] = {0}, lazy[4 * N] = {0}; int fun(int a, int b) { return min(a, b); } void rangeUpdate(int ind, int low, in...
6
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int nega = 1; while (!isdigit(ch)) { if (ch == '-') nega = -1; ch = getchar(); } int ans = 0; while (isdigit(ch)) { ans = ans * 10 + ch - 48; ch = getchar(); } if (nega == -1) return -ans; return ans...
6
#include <bits/stdc++.h> using namespace std; #define rep(i,x,y) for(int i=(x);i<(y);++i) #define debug(x) #x << "=" << (x) #ifdef DEBUG #define _GLIBCXX_DEBUG #define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define show(x) #endif typedef long long int ll; typedef pair<int,int> ...
0
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-8; vector<string> parse(string s, string c) { int len = c.length(), p = -len, np; vector<string> ans; do { np = s.find(c, p + len); ans.push_back(s.substr(p + len, np - p - len)); p = np; } while (p != ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 4005; const int M = 998244353; int ans, f[maxn], C[maxn][maxn], n, m, q, dx[maxn], dy[maxn], w, tmp[maxn], sx, sy; bool x[maxn], y[maxn]; void init() { for (int i = 0; i < maxn; i++) { C[i][0] = C[i][i] = 1; for (int j = 1; j < i; j++) C[i][j]...
6
#include<bits/stdc++.h> using namespace std; map<pair<int,int>,long long >m; vector<pair<int,int> >v; int main(){ long long n,x,y,ans=0; cin>>n; for(long long i=0;i<n;i++){ cin>>x>>y; v.push_back({x,y}); } sort(v.begin(),v.end()); for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ x=v[j].first-v[i].first; y=...
0
#include <cstdio> #include <cstring> #include <vector> #include <string> #include <iostream> using namespace std; struct data{ int next[4],cnt; data(int prx=-1,int nex=-1,int pry=-1,int ney=-1){ next[0]=prx; next[2]=nex; next[1]=pry; next[3]=ney; cnt=0; } }; int h,w; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0...
0
#include <bits/stdc++.h> int main() { int i, n, l, r, c; int a[100005] = {0}, b[100005] = {0}; scanf("%d %d %d", &n, &l, &r); for (i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (i = 1; i <= n; i++) { scanf("%d", &b[i]); } c = 0; for (i = 1; i < l; i++) { if (a[i] != b[i]) c = 1; } fo...
4
#include <bits/stdc++.h> using namespace std; map<string, int> h, type; int a[1010], b[1010][10], c[1010], d[1010], n, m, t, tot, i, j, k, tp, ans[1010], nam; char s[20], na[20]; void get(char s[20], char end) { int n = 0; char ch; while (ch = getchar()) if (ch == end) break; else if (ch != ' ')...
4
#include <bits/stdc++.h> using namespace std; namespace { typedef long long T; const int maxN = 3e5 + 5; int n, a; int cnt[maxN]; int ans; void Solve(int test) { for(int i = 1; i <= n * 2 + 5; i++) cnt[i] = 0; cin >> n, ans = 0; for(int i = 1; i <= n; i++) ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (n + 1) / 2 - 1; }
1
#include <bits/stdc++.h> using namespace std; int dif[1010]; int K, N; int main() { while (scanf("%d%d", &N, &K) != EOF) { int solve = K, ans = 0; for (int i = 0; i < N; i++) scanf("%d", &dif[i]); sort(dif, dif + N); for (int i = 0; i < N; i++) { if (2 * solve >= dif[i]) solve = max(dif[...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { map<double, long long> ko; int n, k; cin >> n >> k; double a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); double p[n]; for (int i = 0; i < n - k; i++) { p[i] = abs(a[i + ...
3
#include <bits/stdc++.h> int k; double v[300 + 1], d[300 + 1], aux[300 + 1]; void combina(double a[], double b[]) { for (int i = 0; i <= k; i++) aux[i] = 0; for (int i = 0; i <= k; i++) for (int j = 0; j <= k; j++) aux[i ^ j] += a[i] * b[j]; for (int i = 0; i <= k; i++) a[i] = aux[i]; } int main() { int n, ...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000") using namespace std; int i, j, k, n; vector<int> v[500000]; int ans[500000]; int q[500000]; int ma[500000]; int rF, rS; void findQ(int i, int p) { int j, k; q[i] = 1; for (k = 0; k < v[i].size(); k++) { j = v[i][k]; if (j == p) continue;...
3
#include <bits/stdc++.h> using namespace std; int comb(int n) { return (n * (n - 1)) / 2; } int main() { int n; cin >> n; char a[n][n]; int ans = 0, count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; if (a[i][j] == 'C') { count++; } } i...
1
#include <bits/stdc++.h> const long long md = 1e9 + 7; const int Inf = 1e9; const long long Inf64 = 1e18; const long long MaxN = 1e5 + 10; const long long LogN = 21; const long long MaxM = 5e5 + 10; const long double eps = 1e-7; const long long dx[4] = {0, 1, 0, -1}; const long long dy[4] = {1, 0, -1, 0}; const long lo...
5
#include <bits/stdc++.h> using namespace std; using LL = long long; constexpr int N = 1e7 + 5; int d[N]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int a, n; cin >> a >> n; int b = a + n - 1; for (int i = 1; i * i <= b; i++) { int x = i * i; for (int j = a / x * x; j <= b; j += x) {...
4
#include <bits/stdc++.h> using namespace std; const int N = 4000004; int l, r, p; int prime[111], js; int n, a[N], f[N]; int b[N], ans; bool cn[111]; void get_prime(int n) { for (int i = 2; i <= n; ++i) { if (!cn[i]) prime[++js] = i; for (int j = 1; j <= js && prime[j] * i <= n; ++j) { cn[prime[j] * i] ...
5
#include <bits/stdc++.h> using namespace std; const long long INF = 1e10; void bye() { cout << "\n"; cin.get(); cin.get(); exit(0); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; vector<int> a(m); for (auto& v : a) { cin >> v; } vec...
2
#include <bits/stdc++.h> const int maxn = 2E+5 + 5; int n, m, ind; int dp[maxn], dfn[maxn], Max[maxn]; std::vector<int> to[maxn], E[maxn]; struct Edge { int u, v, w; } e[maxn]; namespace BIT { int t[maxn]; inline int lowbit(int x) { return x & -x; } inline void Add(int p, int v) { while (p <= n) t[p] += v, p += low...
4
#include <bits/stdc++.h> using namespace std; string reverse(string s) { string temp; for (int i = s.size() - 1; i >= 0; --i) temp += s[i]; return temp; } bool isWordPalindrome(string s) { for (int i = 0; i < s.size() / 2; ++i) { if (s[i] != s[s.size() - i - 1]) return false; } return true; } int main()...
2
#include <bits/stdc++.h> const int N = 200005, mu = 998244353; int f[N][4], n, x, y, a[N], d[N], pre[N], suf[N]; std::vector<int> e[N]; void dfs(int x, int y) { int *dpx = f[x], id = 0, cnt = 0; dpx[0] = dpx[1] = 1; for (auto u : e[x]) if (u != y) dfs(u, x); for (auto u : e[x]) { int *dpu = f[u]; if...
4
#include <bits/stdc++.h> using namespace std; const int base = 500; const int MAXN = 100000 + 10; char a[MAXN][12]; int n, m, q; int fx[MAXN][12], fy[MAXN][12]; void go(int index) { int lo = index * base + 1; int hi = min(n, (index + 1) * base); for (int row = lo; row <= hi; row++) { int l = 1; while (l <...
4
#include <bits/stdc++.h> using namespace std; const int N = 500003; template <typename T> void rd(T &x) { int ch = getchar(); x = 0; for (; ch < '0' || ch > '9'; ch = getchar()) ; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0'; } template <typename T> bool chmin(T &a, const T &b) { i...
6
#include <bits/stdc++.h> using namespace std; const long long inf = 707406378; const int maxn = 200005 * 4 + 3; void read(long long &x) { char ch; bool flag = 0; for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar()) ; for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch ...
3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, mod = 1e9 + 7; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; int a[n], b[m]; map<int, long long> mp[2]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin ...
3
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(a);i>(b);i--) #define ALL(v) (v).begin(),(v).end() typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-1...
0
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } vector<int> g[310]; int...
5
#include <bits/stdc++.h> using namespace std; bool compFirst(pair<long long, long long> a, pair<long long, long long> b) { return a.first < b.first; } int main() { long long n, d; vector<pair<long long, long long> > friends; cin >> n >> d; for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; fri...
2
#include <bits/stdc++.h> using namespace std; int main (){ long long n,m;cin>>n; if (n%2==1) puts("0"); else{ long long ans=0;m=n; while (m) ans+=(m/2)/5,m/=5; printf ("%lld",ans); } return 0; }
0
#include <bits/stdc++.h> using namespace std; #define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++) #define REP(i,n) FOR(i,0,n) #define ALL(a) a.begin(), a.end() #define MS(m,v) memset(m,v,sizeof(m)) typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<string> vs; typedef pair<int,...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n = 1, x = 1; cin >> n; while (n > x) { n = n - x; x++; } cout << n << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; vector<long long> ed[100010], cost[100010]; long long ans; long long sz[100010], m; long long tp[100011]; bool done[100010]; map<long long, long long> downf, upf, downfl[100010], upfl[100010]; void dfs(long long n, long long p) { sz[n] = 1; for (long long i = 0; i < ed[...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, t, k, d; cin >> n >> t >> k >> d; int time = 0; while (true) { if (time > d) break; time += t; n -= k; } if (n > 0) puts("YES"); else puts("NO"); return 0; }
1
#include <bits/stdc++.h> using namespace std; using namespace std; const int maxn = 1000 + 5; int a[maxn], b[maxn]; int main() { int n; cin >> n; int x = -1; for (int i = 1; i * i <= n; i++) if (!(n % i)) x = i; cout << x << endl << n / x << endl; return false; }
1
#include <bits/stdc++.h> using namespace std; const int MN = 1e5 + 100; bool used[MN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; ++i) { cin >> v[i]; } for (int i = 0; i < n; ++i) { if (v[i] == i + 1) { cout << "YES\n"; ...
2
#include <bits/stdc++.h> using Azir = int; namespace fastIO { bool IOerror = 0; inline char nc() { static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000; if (p1 == pend) { p1 = buf; pend = buf + fread(buf, 1, 100000, stdin); if (pend == p1) { IOerror = 1; return -1; } } r...
1
#include <bits/stdc++.h> using namespace std; long long int n, m, k; char mat[303][303]; void testcase() { cin >> n >> m >> k; for (long long int i = 1; i < n + 1; i++) for (long long int j = 1; j < m + 1; j++) cin >> mat[i][j]; long long int cnt = 0; for (long long int radii = 1; radii < n; radii++) { ...
4
#include <bits/stdc++.h> using namespace std; template <class T> inline bool RD(T &ret) { char c; int sgn; if (c = getchar(), c == EOF) return 0; while (c != '-' && (c < '0' || c > '9')) c = getchar(); sgn = (c == '-') ? -1 : 1, ret = (c == '-') ? 0 : (c - '0'); while (c = getchar(), c >= '0' && c <= '9') r...
5
#include <bits/stdc++.h> using namespace std; long long i, j, n, m, k, t, l, r, x, y, s, a[1000009], d[100009]; bool ok, vis[1000009]; long long mn = -1000000009, mx = 1000000009; vector<long long> g[100009]; string p, q; queue<int> st; int main() { cin >> n; a[1] = 1; a[2] = 1; d[1] = 1; for (i = 3; i <= 100...
1
#include<iostream> #include<algorithm> using namespace std; int A[200001]; int main() { int N; cin >> N; for (int i = 1; i <= N; i++) cin >> A[i]; for (int i = 1; i <= N; i++) A[i] -= i; sort(A + 1, A + N + 1); int b = A[N / 2 + 1]; long long sum = 0; for (int i = 1; i <= N; i++) sum += abs(A[i] - b...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio( false ); const int N = 50021; vector<bool> primes( N+1, true ); primes[0] = false; primes[1] = false; for( int i = 2; i*i <= N; ++i ) { if( primes[i] ) { for( int j = 2*i; j <= N; j += i ) { if( j%i == 0 ) { pr...
0
#include<cstdio> #include<algorithm> #include<vector> #include<utility> #define mod 1000000007 using namespace std; int main(){ int a[100000],b[100000]; vector<pair<int,int> > p; long long ans=1LL,l=0LL,n,x=0,y=0; scanf("%lld",&n); for(int i=0;i<n;i++){ scanf("%d",&a[i]); p.push_back...
0
#include <bits/stdc++.h> using namespace std; int d[100 * 1000]; int main() { int n, m; cin.sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--, v--; d[u]++, d[v]++; } bool cir = true; int leaf = 0; for (int i = 0; i < n; i++) { if (d[i] ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, t, i; cin >> t; for (i = 0; i < t; i++) { cin >> a >> b; cout << a + b << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int N = 5e4 + 4; const int M = 5e3 + 3; const int MAX = 1e6 + 6; int n, q; int arr[N]; int l[M]; int r[M]; int ans[M]; int prexor[MAX]; int arr2[N]; int mx[N]; int main() { prexor[0] = 0; for (int i = 1; i < MAX; ++i) { prexor[i] = prexor[i - 1] ^ i; } sca...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; char s[N], res[N * 2]; int f[N * 2]; int fa(int c) { return c == f[c] ? c : f[c] = fa(f[c]); } int main() { for (int i = 0; i < N * 2; i++) f[i] = i; int n, a, b; int ma = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%s", s)...
3
#include <bits/stdc++.h> using namespace std; int dx4[] = {0, 0, 1, -1}; int dy4[] = {1, -1, 0, 0}; int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; const double pi = acos(-1.0); const int mod = 1000000007; const int maxn = 200100; int main() { ios::sync_with_stdio(0); cin.tie(0); ...
4
#include<bits/stdc++.h> #define rep(i,n)for(int i=0;i<n;i++) using namespace std; #ifndef EPS #define EPS (1e-10) #endif struct Point { double x, y; Point(double x = 0, double y = 0) :x(x), y(y) {} Point operator+(const Point&p)const { return Point(x + p.x, y + p.y); } Point operator-(const Point&p)const { return ...
0
#include <bits/stdc++.h> using namespace std; int n, a[200005], dp[200005], vis[200005]; std::vector<int> v[200005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; dp[i] = n; vis[i] = 0; if (i - a[i] >= 0) v[i - a[i]...
5
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, x, y; cin >> a >> b >> x >> y; int c = a - x - 1; int d = b - y - 1; int p = a - c - 1; int q = b - d - 1; int area3 = p * b; int area4 = q * a; int area1 = c * b; int area2 ...
1
#include <bits/stdc++.h> using namespace std; const int Maxn = 100; string str; double ans; int len, a[Maxn + 5], Pow[5] = {1, 10, 100, 1000, 10000}; int Len(int x) { if (!x) return 1; int l = 0; while (x) { l++; x /= 10; } return l; } void Print(int x) { if (x >= 1000) { Print(x / 1000); pr...
2
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; if (n % 2) { int i; for (i = 0; i < n; i++) { printf("%i", i); printf("%c", ' '); } printf("%c", '\n'); for (i = 0; i < n; i++) { printf("%i", i); printf("%c", ' '); } printf("%c", '\n'); ...
3
#include <bits/stdc++.h> using namespace std; int solve(int n) { int sum = 0; while (n > 0) { sum += (n % 10); n /= 10; } return sum; } int main() { int n, C = 0; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } for (int i = 0; i < v.size(); i++) { if (v[i] ==...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; const int xinc[] = {0, 0, 1, -1}; const int yinc[] = {1, -1, 0, 0}; const long double PI = acos(-1.0); int n, m, possible; vector<pair<int, string> > attempt; bool check(string s) { for (auto a : attempt) { int corr = 0; for (int i = 0; i < ...
4
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265358979323846; const int mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int a[n][5]; int z = 0; int cnt = 0; for (int i = 0; i < n; i++) { ...
2
#include <bits/stdc++.h> using namespace std; int a, b; int foo[500]; int main() { cin >> a >> b; if (b > 1) { cout << "Yes"; return 0; } int point; for (int i = 0; i < a; i++) { cin >> foo[i]; if (foo[i] == 0) { point = i; } } cin >> b; foo[point] = b; for (int i = 1; i < a;...
1
#include <bits/stdc++.h> using namespace std; char x[500][501]; int d[2][501][501], n, m; int main() { cin >> n >> m; for (int i = 0; i < (n); i++) cin >> x[i]; for (int ei = 0; ei < (n); ei++) for (int si = n; si--;) for (int sj = m; sj--;) { auto &c = d[ei & 1][si][sj] = 0, ej = n + m - 2 - si...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; char s[10]; scanf("%d%s", &n, s); int a = (s[0] - '0') * 10 + (s[1] - '0'); int b = (s[3] - '0') * 10 + (s[4] - '0'); if (n == 12) { if (a == 0) s[1] = '1'; else if (a > 12) { if (s[1] == '0') s[0] = '1'; els...
1
#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<complex> #define f first #define s second #define mp make_pair #define REP(i,n) for(int i...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n; cin >> n; vector<vector<long long int> > v; for (long long int i = 0; i <= n; i++) v.push_back(vector<long long int>()); for (long long int i = 0; i < 2 * n; i++) ...
2
#include <bits/stdc++.h> using namespace std; int main() { long int l, r; int q, i, j, s, t; cin >> q; for (i = 0; i < q; i++) { s = 0; t = 0; cin >> l >> r; if (l == r) { if (l % 2 == 0) s += l; else s -= l; cout << s << endl; } else { l--; if (...
2
#include <bits/stdc++.h> //typedef //-------------------------#include <bits/stdc++.h> #define M_PI 3.14159265358979323846 using namespace std; //conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template<class T> inline s...
0
#include <bits/stdc++.h> using namespace std; long long int inf = 1e18; long long int mod = 1e9 + 7; long double eps = 1e-9; long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x...
3
#include <iostream> using namespace std; int main(void){ int length,high_jump; cin>>length>>high_jump; cout<<length/high_jump+length%high_jump<<endl; }
0
#include <bits/stdc++.h> using namespace std; int d[405][405]; int dg[405]; int n, m; double u[405][405]; int ut[405][405]; double sm[405]; int st[405]; int T; void clr() { T++; } double &gu(int i, int j) { if (ut[i][j] != T) { u[i][j] = 0; ut[i][j] = T; } return u[i][j]; } double &gsm(int i) { if (st[i...
4
#include <bits/stdc++.h> using namespace std; vector<vector<int> > trie; vector<int> val, qtd; int tam, a[300010], b[300010]; int create() { if (tam < trie.size()) return tam++; trie.push_back({-1, -1}); val.push_back(-1); qtd.push_back(0); tam++; return trie.size() - 1; } void bin(int num, string &res) { ...
3
#include <bits/stdc++.h> using ld = long double; using ll = long long; using uint = unsigned int; using ull = unsigned long long; using namespace std; const int INTMAX = 2147483647; const int INTMIN = -2147483647; const ll LLMAX = 9223372036854775807; const ll LLMIN = -9223372036854775807; ll MOD = 1000000007; ll MOD2 ...
3
#include <bits/stdc++.h> using namespace std; bool realTable[310][310]; bool DP[35][8][310][310]; vector<pair<int, int>> mov{{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; int main() { int N; cin >> N; DP[1][0][155][155] = true; for (int stage = 1; stage <=...
4