solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:65536535") using namespace std; char ss[51][51]; char s[51]; int n, m; bool was[51][51]; int dfs(int x, int y) { if (x < 0 || y < 0 || x >= n || y >= m || was[x][y] || ss[x][y] == '.') return 0; was[x][y] = true; int count = 1; for (int dx = -1; dx <=...
1
#include <bits/stdc++.h> using namespace std; long long n, k, a, s, i, j; int x[101][101]; int main() { cin >> k; i = 4; s = 1; while (s < k) { s = s + (i - 2) * (i - 1) / 2; i++; } i--; if (s > k) { s = s - (i - 2) * (i - 1) / 2; i--; } n = i; for (i = 1; i <= n; i++) { for (j =...
3
#include<stdio.h> int main(){ int n; while(1){ scanf("%d",&n);if(n==0)break; int c=0; while(n!=1){ if(n%2==0)n=n/2; else {n=3*n+1;} c++; } printf("%d\n",c); } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 110; int R, N; pair<int, int> bad[MAXN]; int sg[MAXN][4]; bool seen[2 * MAXN]; int main() { sg[0][0] = sg[0][2] = 0; sg[0][1] = sg[0][3] = 1; sg[1][0] = 1; sg[1][1] = 2; sg[1][2] = 1; sg[1][3] = 0; for (int i = 2; i < MAXN; i++) { for (int...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; multiset<int> s; int a; for (int i = 0; i < n; i++) { cin >> a; s.insert(a); } multiset<int>::iterator it = s.begin(); int sum1 = 0; int sum2 = 0; for (it; it != s.end(); it++) { if (*it < 0) sum1 += *it; ...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; ...
1
#include <bits/stdc++.h> using namespace std; const long long int maxi = 20000; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, k; cin >> n >> k; vector<long long int> ans; for (long long int i = 1; i <= 2 * n; i++) ans.push_back(i); long long int i = 0; long long int x = ...
2
#include <bits/stdc++.h> using ll = long long; const int C = 2001, M = 1000000007; ll dp[C][C], equal[C][C]; int main() { std::string a; int k, ln, i, j, ij, x; std::cin >> ln >> k >> a; dp[0][0] = a[0] - 'a'; equal[0][0] = 1; i = 0, j = 0; for (ij = 0, x = ln - i; i + ij < ln && j + (ij + 1) * x <= k; ij...
3
#include <iostream> #define NMAX 1005 using namespace std; int n,m,i,j; const long long MOD=1000000007; long long d[NMAX][NMAX]; char c; int main() { cin>>n>>m; d[1][1]=1; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { cin>>c; if(i==1 && j==1) continue; ...
0
#include <cstdio> #include <cstring> #include <algorithm> #define MAXN 200010 #define LL long long using namespace std; namespace Fenwick{ int c[MAXN]; void add(int x,int v){ while(x<MAXN){ c[x]+=v; x+=x&(-x); } } int sum(int x){ int res=0; while(x){ res+=c[x]; x-=x&(-x); } return res; }...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, T; cin >> N >> T; vector<pair<int, int>> AB(N); for (int i = 0; i < N; i++) { cin >> AB[i].first >> AB[i].second; } sort(AB.begin(), AB.end()); vector<int> dp(T + 1, 0); for (int i = 0; i...
0
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; vector<char> res; int dotnum = 0, atnum = 0; int n = s.size(); for (int i = 0; i < (n); ++i) { if (i <= n - 4 && i) { bool dotfound = (s[i] == 'd') && (s[i + 1] == 'o') && (s[i + 2] == 't'); if (dotfound) { ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, a[100000], b = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { if (a[i] != a[i + 1]) b++; } cout << b; return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, m, k; int p[205], a[205]; double dp[205][205][405]; double ans; int main() { scanf("%d %d %d", &n, &m, &k); if (k > n) k = n; for (int i = 1; i <= n; ++i) scanf("%d", &p[i]); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); dp[1][0][k] = 1; for (int i = 1...
2
#include<cstdio> using namespace std; int main(void){ int n,max=0,num[101]={0}; while(scanf("%d",&n)!=EOF){ num[n]++; if(num[n]>max) max=num[n]; } for(int i=1;i<=100;i++){ if(num[i]==max) printf("%d\n",i); } return 0; }
0
#include<iostream> #include<math.h> using namespace std; int main() { long long n, x, ans = 0; cin >> n; x = sqrt(n); while(n % x != 0){ x--; } x = n / x; while(x != 0){ x /= 10; ans++; } cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; string s; cin >> n >> m; cin >> s; map<char, long long> mp; for (int i = 0; i < n; i++) { mp[s[i]]++; } if (mp.size() < m) { cout << 0; return 0; } long long ans = 1000000; for (auto i = mp.begin(); i != mp.end(...
1
#include <bits/stdc++.h> using namespace std; long long n, x, y; string solve(); int main() { while(1) { cin >> n >> x >> y; if(n + x + y == 0) break; cout << solve() << endl; } return 0; } string solve() { string res; --y; --x; for(int i = 0; i < n; ++i) { if((y % 2) ^ (x % 2)) ...
0
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <complex> #include <cstring> #include <cstdlib> #include <string> #include <cmath> #include <queue> #include <bitset> using namespace std; #define REP(i,n) for(int i=0;i<(int)n;++i) #define FOR(i,c) for(__typeof((c).begin())i=(c).beg...
0
#include<iostream> using namespace std; int main(){ int table[55000]={}; for(int i=2; i*i<55000; ++i){ if(!table[i]){ for(int j=i*2; j<=55000; j+=i){ table[j]=1; } } } int n; while(cin >> n){ int i; for(i=n-1; table[i]; --i); cout << i << " "; for(i=n+1; table[i];...
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; inline int read(){ int x=0,f=1; char c=getchar(); while(c<48||c>57){if(c=='-')f=-1;c=getchar();} while(c>=48&&c<=57)x=x*10+c-48,c=getchar(); return x*f; } inline void write(int x){ char c[20],len=0; if(!x){putchar('0');return;} if(x<0)x=-x,putch...
3
#include <bits/stdc++.h> using namespace std; const int MOD(1000000007); const int INF((1 << 30) - 1); const int MAXN(55); struct nnode { int x, y, d; string s; nnode(){}; nnode(int x, int y, int d, string s) : x(x), y(y), d(d), s(s){}; bool operator<(const nnode &other) const { if (d != other.d) return d...
3
#include<bits/stdc++.h> #define mp make_pair using namespace std; typedef pair<int, vector<int> > piv; int d[4] = {-4, -1, 1, 4}; int main(int argc, char *argv[]){ vector<int> a(8); for (int i = 0; i < 8; i++) { a[i] = i; } map<vector<int>, int> hash; hash[a] = 0; queue<piv> que; que.push(mp(0, a)); ...
0
#include <bits/stdc++.h> using namespace std; int main() { int r, c, n = 0, nn = 0; cin >> r >> c; vector<string> s(r); for (int i = 0; i < r; i++) { cin >> s[i]; } for (int i = 0; i < r; i++) { nn = 0; for (int j = 0; j < c; j++) { if (s[i][j] == 'S') break; else nn+...
1
#include <bits/stdc++.h> using namespace std; void ASS(bool b) { if (!b) { ++*(int*)0; } } #pragma comment(linker, "/STACK:106777216") struct RSQ { int n; vector<int> a; void I(int i) { if (i >= n) { a[i] = 1; return; } I(i * 2); I(i * 2 + 1); a[i] = a[i * 2] + a[i * 2 + 1]...
4
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, c[200010]; ll mod = 1e9+7; ll p(ll a, ll b) { if (b < 0) return 0; if (b == 0) return 1LL; if (b == 1) return a; ll ret = p(a, b/2); ret *= ret; ret %= mod; if (b&1) ret *= a; return ret % mod; } int main() { ...
0
#include <bits/stdc++.h> using namespace std; long long int n, m, i, j, k; long long int sum = 0; long long int b_search(long long int b[], long long int lo, long long int hi, long long int x, long long int pos) { if (lo > hi) { return pos; } long long int mid = lo + (hi - lo) / 2; if...
2
#include <bits/stdc++.h> using namespace std; int i, j, k, n, m, nn, an, id, biu, jiu; int f[(1 << 15)][120], a[500010], b[500010][20], g[(1 << 15)]; map<string, int> Map; inline string read() { char p[20]; int i; string s; scanf("%s", p + 1); for (i = 1; i <= strlen(p + 1); i++) s += p[i]; return s; } inli...
4
#include <bits/stdc++.h> using namespace std; int vis[10000000]; string tostring(int Number) { ostringstream ss; ss << Number; return ss.str(); } int toint(string Text) { istringstream ss(Text); int result; return ss >> result ? result : 0; } int main() { int n, x, counter = 0, sum = 0, sum1 = 0, val; s...
3
#include <bits/stdc++.h> char s[100003]; int a[100003]; int main() { int n; scanf("%d", &n); gets(s); gets(s); int len = strlen(s); for (int i = 0, j = 0; i < len; ++i) if (s[i] == '.' || s[i] == '!' || s[i] == '?') a[++a[0]] = j + 1, j = 0, ++i; else ++j; int ans = 0; for (int i = 1...
2
#include <bits/stdc++.h> int main() { std::string S; std::cin >> S; for (auto& e: S) putchar('x'); putchar('\n'); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; int n = 2000; printf("%d\n-1 ", n); int sum = n + k; int d = sum / (n - 1); for (int i = 1; i <= n - 1; i++) printf("%d ", i < n - 1 ? sum / (n - 1) : sum - (n - 2) * d); puts(""); return 0; }
5
#include <bits/stdc++.h> using namespace std; vector<pair<long long int, pair<long long int, long long int> > > v; vector<pair<long long int, long long int> > v1, v2; vector<pair<pair<long long int, long long int>, long long int> > v3; int main() { long long int n, i, j; cin >> n; for (j = 0; j < n; j++) { lo...
3
#include<bits/stdc++.h> using namespace std; int n,m,u[5010],v[5010],w[5010],p,vis[5010],c[5010]; long long d[5010]; void bfs() { queue<int> q; q.push(n);vis[n]=1; while(!q.empty()) { int s=q.front();q.pop(); for(int i=1;i<=m;++i) if(v[i]==s&&!vis[u[i]]) { q.push(u[i]); vis[u[i]]=1; } } } int main() { ...
0
#include <bits/stdc++.h> using namespace std; struct Edge { int v, next; } edge[200050 * 2]; int e, ft[200050]; int n, k; int size[200050]; long long dp[200050][5 + 1]; bool flag[200050]; long long total_dist; void init() { memset(flag, false, sizeof(flag)); memset(dp, 0, sizeof(dp)); memset(ft, -1, sizeof(ft))...
4
#include <bits/stdc++.h> using namespace std; template <typename T> inline void _abs(T &first) { if (first < 0) first = -first; }; const int N = 1606; int n; pair<long long, long long> a[N]; void inp() { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second; } long long dientich(pair<long long, ...
2
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n; int a[N]; map<int, int> cnt; bool fail() { if (cnt[0] >= 2) return true; int cnt2 = 0; for (auto c : cnt) { if (c.second >= 3) return true; if (c.second >= 2) { cnt2++; if (cnt2 >= 2) return true; } if (c.second...
2
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int fx[] = {-1, +0, +1, +0, +1, +1, -1, -1, +0}; int fy[] = {+0, -1, +0, +1, +1, -1, +1, -1, +0}; int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; template <typename T> inline bool isLeap(T y) { return (y % 400 == 0) || (y % 100 ? y %...
5
#include <bits/stdc++.h> using namespace std; int T, n, m, l, r; vector<pair<int, int> > t1[200500], t2[200500]; long long f[200500][2], v[200500]; void solve() { scanf("%d%d", &n, &m); for (int i = 0; i <= n + 1; i++) t1[i].clear(), f[i][0] = f[i][1] = 1e17; for (int i = 1; i <= n; i++) scanf("%lld", &v[i]); s...
6
#include <bits/stdc++.h> using namespace std; string s[55]; long long arr[55][5]; int che(char c) { if (c >= '0' && c <= '9') return 1; else if (c >= 'a' && c <= 'z') return 2; else return 3; } long long min(long long a, long long b) { return (a < b ? a : b); } int main() { cin.sync_with_stdio(0); ...
3
#include<iostream> #include<stdio.h> #include<string.h> using namespace std; char s[120000]; int fa[120000],p,n; int a[120000]; int main(){ scanf("%s",s+1); n=strlen(s+1); for(int i=1;i<=n;i++)a[i]=s[i]=='1'; if(a[n]==1||a[1]==0){ printf("-1\n"); return 0; } for(int i=1;i<=n;i++){ if(a[n-i]!=a[i]){ print...
0
#include <bits/stdc++.h> const int inf = 1000000007; const long long INF = 3e18; const double pi = 2 * acos(0.0); using namespace std; int gcd(int a, int b) { a = abs(a); b = abs(b); while (b) { a = a % b; swap(a, b); } return a; } const int maxn = 1e3 + 10; int arr[maxn]; int main() { int n, k; c...
2
#include<bits/stdc++.h> using namespace std; typedef int s32; typedef unsigned int u32; typedef long long s64; typedef unsigned long long u64; typedef long double ld; #define watch(x) cout << #x << ": " << x << "\n"; #define files(name)\ ifstream cin(#name".in");\ ofstream cout(#name".out"); int n, m; vector<vector...
5
#include "bits/stdc++.h" using namespace std; const int mod = 1000000009; struct Mod { public: int num; Mod() : Mod(0) { ; } Mod(long long int n) : num((n % mod + mod) % mod) { static_assert(mod<INT_MAX / 2, "mod is too big, please make num 'long long int' from 'int'"); } Mod(int n) : Mod(static_cast<long long...
0
#include <bits/stdc++.h> using namespace std; inline int read() { int s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { s = (s << 3) + (s << 1) + (ch ^ 48); ch = getchar(); } return s * w; } const int...
5
#include<iostream> using namespace std; int p[1001]; int main() { int i,n,cnt=0; cin>>n; for(i=1;i<=n;i++) cin>>p[i]; for(i=2;i<=n-1;i++) { if((p[i]>p[i-1]&&p[i]<p[i+1])||(p[i]<p[i-1]&&p[i]>p[i+1])) cnt++; } cout<<cnt; }
0
#include <bits/stdc++.h> using namespace std; void fail() { cout << "NO" << endl; exit(0); } int main() { int n; cin >> n; vector<int> bef(26, -1), aft(26, -1); vector<bool> used(26, true); for (int i = 0; i < n; ++i) { string s; cin >> s; for (auto& ch : s) ch -= 'a', used[ch] = false; fo...
2
#include<cstdio> #include<cstring> #define fo(i,a,b)for(int i=a;i<=b;i++) #define min(a,b)(a<b?a:b) using namespace std; int n,g,p[105],c[105],f[2][105505],o,zs,ans; int main(){ scanf("%d%d",&n,&g);g/=100; fo(i,1,n)scanf("%d%d",&p[i],&c[i]),c[i]/=100; fo(i,0,105500)f[0][i]=f[1][i]=1e9;f[0][0]=0; fo(i,1,n){ o^=1; ...
0
#include <bits/stdc++.h> int a[200050]; int main() { int n, x, f, i, t; long long ans = 0; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &a[i]); scanf("%d%d", &x, &f); for (i = 1; i <= n; i++) if (a[i] > x) { t = a[i] - x; ans += (t + x + f - 1) / (x + f); } printf("%lld", ans ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x = n - 10; if (x == 10) { cout << "15"; return 0; } (((x > 0) && (x < 10)) || (x == 11)) ? (cout << 4) : (cout << 0); }
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); string s; cin >> s; int n = s.size(); int j = 0, k = 0; int b = 0, c = 0; for (int i = n - 1; i >= 0; i--) { if (s[i] == 'a') { b++; }; }; if ((n - b) % 2 != 0) { cout << ":("...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; int pol = x1 + y1; int mn = min(x2, y2); int vas = mn + x2 - mn + y2 - mn; if (pol <= vas || (x1 <= x2 && y1 <= y2)) { cout << "Poly...
3
#include <bits/stdc++.h> using namespace std; int main() { double a, b, m, vx, vy, vz; scanf("%lf", &a); scanf("%lf", &b); scanf("%lf", &m); scanf("%lf", &vx); scanf("%lf", &vy); scanf("%lf", &vz); vy *= -1; double time = m * 1.0 / vy; double z = vz * time; int num = (int)floor(z / b); if (num %...
4
#include<bits/stdc++.h> using namespace std; int nt[5010000]; bool bl[5010000]; int cnt; int main(){ string s;cin>>s; nt[0]=-1; int k=-1,j=0; int l=s.size(); int xh; while(j<l){ if(k==-1||s[j]==s[k]){ j++;k++;xh=j-k; bl[j-1]=(xh!=j&&j%xh==0); if(s[j]!=s[k]) nt[j]=k; else nt[j]=nt[k]; } else k=...
0
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; template <class T> inline void ckmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void ckmax(T &a, T b) { if (b > a) a = b; } template <class T> inline T sqr(T x) { return x * x; } using VI = vector...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); string s, t; cin >> s; t = s; int m; cin >> m; for (int query = 0; query < m; query++) { int l, r, k; cin >> l >> r >> k; l--, r--; int len = r - l + 1; k %= len; int start_pos = l + (len -...
2
#include <bits/stdc++.h> inline long long read() { long long num = 0, f = 1; char c = getchar(); while (c < 48 || c > 57) { if (c == '-') f = -1; c = getchar(); } while (c > 47 && c < 58) num = (num << 3) + (num << 1) + (c ^ 48), c = getchar(); return num * f; } inline long long min(long long a,...
6
#include <bits/stdc++.h> using namespace std; const int MAX_N = 522; int a[MAX_N], b[MAX_N], last[2 * MAX_N], d[MAX_N][MAX_N]; pair<int, int> pr[MAX_N][MAX_N]; set<int> s; map<int, int> ma; vector<int> numbers; int main() { int n, m; scanf("%d", &n); for (int i = 0; (i) < (n); ++i) scanf("%d", &a[i]), s.insert(a[...
4
#include <bits/stdc++.h> using namespace std; const int MX = 5e5 + 5; double dist[MX]; struct Point { double x, y; } P[MX]; double f(Point a, Point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } int main() { Point a, b, w; scanf("%lf%lf%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y, &w.x, &w....
3
#include<stdio.h> #include <iostream> #include <math.h> #include <numeric> #include <vector> #include <map> #include <functional> #include <stdio.h> #include <array> #include <algorithm> #include <string> #include <string.h> #include <assert.h> #include <stdio.h> #include <queue> #include<iomanip> #include<bitset> #inc...
0
#include <bits/stdc++.h> using namespace std; long long n, x1 = 1023, x0, ans[3] = {0, 0, 1023}, t; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; ++i) { int a; char b; cin >> b >> a; if (b == '|') { x1 |= a; x0 |= a; } else if (b == '&') { x0 &= ...
1
#include<algorithm> #include <iostream> using namespace std; int main() { string s; cin >> s;int cnt = 0;int mx = 0; for (int i = 0; i < s.size();i++) { if (s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G') { cnt++; mx = max(mx, cnt); } else cnt = 0; } cout << mx << endl; }
0
#include <bits/stdc++.h> using namespace std; int main(){ int n,m,p,x,d,a; while(cin>>n>>m>>p,n){ int sum=0; for(int i=0;i<n;i++){ cin>>x; if(i+1==m)d=x; sum+=x; } a=sum*100*(100-p)/100; if(d!=0)cout<<a/d<<endl; else cout<<0<<endl; } }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, l, v1, v2, k; scanf("%d%d%d%d%d", &n, &l, &v1, &v2, &k); double res = 0; int cnt; if (n % k == 0) cnt = n / k; else cnt = n / k + 1; double up = (double)(v1 + v2) * l; double down = (double)((2 * (cnt - 1) + 1) * v1 + v2); doubl...
4
#include <bits/stdc++.h> using namespace std; struct query { int t, l, r; }; int main() { ios::sync_with_stdio(0); int n, q, m; cin >> n >> q >> m; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<query> qs(q); for (int i = 0; i < q; i++) { int t, l, r; cin >> t >...
4
#include <bits/stdc++.h> using namespace std; vector<long long int> factors(long long int n) { vector<long long int> fact; fact.push_back(1); fact.push_back(n); for (long long int i = 2; i <= n / 2; i++) { if (n % i == 0) { fact.push_back(i); fact.push_back(n / i); } } return fact; } voi...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; vector<vector<int> > g(N); bool vis[N]; int color[N]; map<int, int> best_color; int dfs(int node) { vis[node] = 1; best_color[color[node]]++; int tot = 1; for (auto to : g[node]) { if (!vis[to]) { vis[to] = 1; tot += dfs(to); ...
3
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const int inf = 0x3f3f3f3f; const long long int INF = 1e18; const int mod = 1e9 + 7; const int maxn = 1e2 + 5; int cas = 1; int a[maxn], vis[maxn]; void solve() { int n; while (~scanf("%d", &n)) { memset(vis, 0, sizeof(vis)); for (int i ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 0; string s; cin >> n >> s; for (int i = n; i < s.size(); i += n) { if (s[i - 1] == s[i - 2] && s[i - 1] == s[i - 3]) count++; } cout << count << endl; }
1
#include <bits/stdc++.h> using namespace std; using Matrix = vector< vector<int> >; const int INF = 1 << 30; int W, H, ans = 0; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; void dfs(Matrix &mat, int turn, int x, int y) { if (turn > 10) return; for (int i = 0; i < 4; i++) { int nx = x + dx[i], ny ...
0
#include <bits/stdc++.h> #define ll long long #define mkp make_pair #define fi first #define se second #define pb push_back using namespace std; int n; void solve() { cin >> n; if(n % 2) { int s = (n - 1) / 2; for(int i = 1; i <= n; i++) for(int j = 1; j <= n - i; j++) if(j <= s) cout << 1 << " "; else...
3
#include <bits/stdc++.h> using namespace std; int main() { int input, times, length; cin >> times; for (int i = 0; i < times; i++) { cin >> length; int counter = 0; for (int j = 0; j < length; j++) { cin >> input; if (input <= 2048) { counter += input; } } if (counter...
1
#include<bits/stdc++.h> using namespace std; int gcd(int a,int b){return b==0?a:gcd(b,a%b);} const int N=2005; int n,t,s,v,id,a[N],d[N],vis[N]; set<int>S; vector<int>f[N],e[N]; void dfs(int v){ vis[v]=1;d[++t]=a[v]; int i,u; for(i=0;i<e[v].size();i++){ u=e[v][i]; if(vis[u]==0)dfs(u); } } int main(){ scanf("%d"...
0
#include <bits/stdc++.h> using namespace std; long long work(long long n) { long long sum = 0; while (n) { sum += n % 10; n /= 10; } return sum; } int main() { long long n, m, k = 9; cin >> n; m = n; while (m >= k) { k = k * 10 + 9; } k /= 10; long long a = k; long long b = n - k; ...
2
#include <stdio.h> int main(void) { int n; scanf("%d",&n); if(n==17 || n==13 || n==10 || n==9 || n==6 || n==5 || n==3 || n==2 || n==1){ printf("No\n"); }else{ printf("Yes\n"); } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5, mod = 1e9 + 7; int n, q, a[N], w[N]; long long ans; void upd(int &x, int y) { x += y; x -= x >= mod ? mod : 0; } long long t[N]; void add(int x, int y) { for (; x <= n; x += x & -x) t[x] += y; } long long qry(int x) { long long s = 0; for (;...
3
#include <bits/stdc++.h> using namespace std; int dirs[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; int MAX_CELLS = 500 * 500 + 5; vector<int> leader(MAX_CELLS); vector<int> hoogte(MAX_CELLS, 1); vector<int> cc_size(MAX_CELLS, 1); int get_leader(int nd) { if (leader[nd] == nd) { return nd; } return leader[nd] ...
3
#include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<math.h> #include<string> #include<string.h> #include<stack> #include<queue> #include<vector> #include<utility> #include<set> #include<map> #include<stdlib.h> #include<iomanip> using namespace std; #define ll long long #define ld long dou...
0
#include <bits/stdc++.h> using namespace std; const int MN = 5011; int f[2][MN][MN], n, g[MN], sz[MN]; vector<int> ke[MN]; void dfs(int u, int fu) { if (((int)((ke[u]).size())) == 1) { sz[u] = 1; f[0][u][0] = 0; f[0][u][1] = MN; f[1][u][1] = 0; f[1][u][0] = MN; return; } for (int v : ke[u]...
6
#include <algorithm> #include <cstdio> #include <cstring> #include <cctype> #define int long long inline int read(int f = 1, int x = 0, char ch = ' ') { while(!isdigit(ch = getchar())) if(ch == '-') f = -1; while(isdigit(ch)) x = x*10+ch-'0', ch = getchar(); return f*x; } const int N = 4e3+5, P = 924844033...
0
#include <bits/stdc++.h> using namespace std; const int N = 1E5 + 5; int n; vector<multiset<int> > graph; vector<int> v; vector<pair<int, int> > edge; void dfs(int src) { while (!graph[src].empty()) { int edge_idx = *(graph[src].begin()); int u = edge[edge_idx].first; int v1 = edge[edge_idx].second; v...
5
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { double n, o = 0, f = 0; cin >> n; while (1) { if (n < 0.6) { o = o + n; break; } else { o = o + n; n = n / 10; } } cout << (int)o << endl; } }...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { long long int x, y; cin >> x >> y; long long int maxx = x, minx = x, maxy = y, miny = y; for (int i = 0; i < n - 1; i++) { cin >> x >> y; if (x > maxx) maxx = x; else if (x < minx) ...
2
#include <bits/stdc++.h> using namespace std; const long long mod = (1e9 + 7); const long long inf = (1e18 + 3); const long long N = 1e3 + 2; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; ...
1
#include <bits/stdc++.h> using namespace std; vector<string> v; int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, 1, 0, -1}; void dfs(int i, int j, int &cnt, vector<pair<int, int>> &temp, vector<vector<int>> &vis) { vis[i][j] = 1; temp.push_back(make_pair(i, j)); for (int k = 0; k < 4; k++) { int x = i + dx...
4
#include <bits/stdc++.h> using namespace std; int grundy[5][1000100]; long long sqrto(long long n) { long long ret = sqrt(n); if (ret * ret > n) ret--; else ret++; if (ret * ret > n) ret--; return ret; } int makegrundy(long long n) { int i; long long st = sqrto(sqrto(n)); if (st * st * st * st =...
3
#include <bits/stdc++.h> const int mod = (int)1e9 + 7; long long power(long long a, int b) { long long ret = 1; while (b > 0) { if (b % 2) { ret *= a; ret %= mod; } a = (a * a) % mod; b /= 2; } return ret; } long long inverse_mod(long long n) { return power(n, mod - 2); } long long c...
2
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; int mov = 0; char cur = 'a'; for (int i = 0; i < (int)str.size(); i++) { mov += min(abs(cur - str[i]), 26 - abs(cur - str[i])); cur = str[i]; } cout << mov << endl; }
1
#include <bits/stdc++.h> using namespace std; template <class T> void minn(T &A, T B) { A = min(A, B); } template <class T> void maxx(T &A, T B) { A = max(A, B); } const long long mod = 1e9 + 7; long long n, h, a[2005], diff, res = 1; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ...
4
#include <bits/stdc++.h> using namespace std; int Arr[100100], n; int BS(int d, int k) { int L = k, R = n - 1; while (L < R) { int mid = L + (R - L + 1) / 2; if (Arr[mid] <= d) L = mid; else R = mid - 1; } return R; } int main() { int d; long long ans = 0; cin >> n >> d; for (int...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; const int INF = 1e9; int n, k; char s[N]; int z[N]; void read() { scanf("%d%d", &n, &k); scanf("%s", s); } void z_f() { int l = 0, r = 0; for (int i = 1; i < n; i++) { if (r > i) z[i] = min(z[i - l], r - i); for (; i + z[i] < n && s[...
4
#include<complex> #include<algorithm> #include<iostream> #include<iomanip> #include<bitset> #include<cmath> #include<vector> #include<map> #include<sstream> #include<ctime> #include<cstdio> #include<cstdlib> #include<cassert> #include<deque> #include<queue> #include<climits> #include<list> #include<stack> #include<ctim...
0
#include <bits/stdc++.h> using namespace std; const int N = 3e3 + 50; int R, C, n, k; struct pnt { int x, y; pnt(int _x = 0, int _y = 0) { x = _x; y = _y; } bool operator<(const pnt &a) const { return y < a.y || (y == a.y && x < a.x); } } p[N]; int pre[N], suf[N], ct[N]; long long Ans, as; vector<...
5
#include <bits/stdc++.h> using namespace std; int main() { long double a, b, x1, x2, x3, y1, y2, y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; a = y2 - y1; a = a / (x2 - x1); b = y3 - y2; b = b / (x3 - x2); if (a == -INFINITY) a = INFINITY; if (b == -INFINITY) b = INFINITY; if (a == b) cout << "TOW...
1
#include <bits/stdc++.h> using namespace std; vector<vector<int> > opt; vector<int> nr, nd; int fd(int a, int b) { int c = 0; for (int i = 0; i < (a); ++i) c = nd[c]; for (int i = 0; i < (b); ++i) c = nr[c]; return c; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, q; cin >> n >> m >> q; ...
5
#include <bits/stdc++.h> using namespace std; vector<long long> mx, mn; int main() { long long n; cin >> n; long long ans = 0; for (long long i = 0; i < n; i++) { long long l; cin >> l; long long a[l + 5]; long long mnn = 100000000, mxx = -1000; long long fg = 0; for (long long j = 0; j ...
2
#include <bits/stdc++.h> using namespace std; long long int dp[80][80]; vector<pair<int, int> > eq, gr, gre; long long int solve(int left, int right) { long long int &ret = dp[left][right]; if (ret != -1) return ret; int i; for (i = 0; i < eq.size(); i++) { if ((eq[i].first >= left and eq[i].first <= right)...
6
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 1e4 + 10; int dp[N]; int a[N]; int main() { int n; cin >> n; int tot = 0; int cur = 0; string str; while (cin >> str) { cur += str.length() + (cur > 0); if (str.back() == '.' || str.back() == '?' || str.back()...
2
#include <bits/stdc++.h> using namespace std; int GCD(int x, int y) { if (x % y == 0) return y; else return (GCD(y, x % y)); } int main() { int n, x, i; while (scanf("%d", &n) == 1) { int ara[100005]; int ar[100005] = {0}; for (i = 0; i < n; i++) { scanf("%d", &x); ara[i] = x; ...
2
#include <bits/stdc++.h> const int maxn = 1e6 + 5; const long long inf = 0x3f3f3f3f; long long dp[2][maxn]; long long a[maxn]; long long min(long long a, long long b) { if (a > b) return b; return a; } int main() { long long n, r1, r2, r3, d; scanf("%lld%lld%lld%lld%lld", &n, &r1, &r2, &r3, &d); for (int i = ...
5