solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int const MAX_N = 100005; int const MAX_M = 100005; int const MAX_K = 507; int const INF = 0x3F3F3F3F; int const NA = -1; int d[MAX_N]; int e[MAX_N]; int u[MAX_M]; int v[MAX_M]; int w[MAX_M]; int c[MAX_K]; int a[MAX_K][MAX_K]; int up(int p) { if (e[p] == p) { return p...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n + 9]; for (int i = 0; i < n; i++) cin >> a[i]; int j = 0; while (a[j] == 0) j++; int k = n - 1; while (a[k] == 0) k--; int count = 0, cnt = 0; for (int i = j; i <= k; i++) { if (a[i] == 1) count++; else...
2
#include<bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int c = 0; for (int i = 0; i < s.size(); ++i) if (s[i] != t[i]) c++; cout << c << endl; }
0
#include <bits/stdc++.h> const long long inf = 0x3f3f3f3f3f3f3f3fll; using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } int main() { long long n, k, sum = 0, i; cin >> n >> k; set<...
3
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > vs; int getCode(int x, int y) { return (1 << (3 * x + (2 - y))); } int n, cost[5], step, col[1010], dp[4096][1010]; string str[4]; int main() { ios_base::sync_with_stdio(false); for (int i = 0; i < 4; i++) step |= getCode(i, 0); cin >> n; for...
6
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; const int mod = 1e9 + 7; int n; pair<long long, int> a[N]; long long bit_a[N], bit_b[N]; void add(long long bit[], int x, long long y) { while (x < N) { bit[x] = (bit[x] + y) % mod; x += x & -x; } } long long sum(long long bit[], int x) { ...
6
#include <bits/stdc++.h> using namespace std; void printarr(int arr[], int n) { for (int i = 0; i < n; i++) { cout << arr[i] << " "; } cout << endl; } void printarr(vector<int> arr) { int n = arr.size(); for (int i = 0; i < n; i++) { cout << arr[i] << " "; } cout << endl; } int main() { ios_base...
3
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; bool dfs(string s){ if(s=="AKIHABARA") return true; if(s.length()>=9) return false; rep(i,s.length()+1) if(dfs(s.substr(0,i)+"A"+s.substr(i))) return true; return false; } int main(){ string s; cin>>s; puts(dfs(s)?"YES":"NO"...
0
#include <bits/stdc++.h> int main() { int i, len, count4 = 0, one = 0; char str[20]; scanf("%s", str); len = strlen(str); for (i = 0; i < len; i++) { if (str[i] == '1') one = 1; else if (str[i] == '4') { while (str[i] == '4') { count4++; i++; } i--; } else {...
1
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; char s[500050]; int n,mx[500050]; long long ans; int main() { scanf("%s",s+1); n=strlen(s+1)+1; for(int i=2;i<=n;++i)if(s[i-1]=='<')mx[i]=mx[i-1]+1; for(int i=n-1;i;--i) if(s[i]=='>')mx[i]=max(mx[i],mx[i+1]+1); for(int i=1;i<=n;++i)ans+=...
0
#include<bits/stdc++.h> using namespace std; int main(){long long int n,k,s,i,c; cin>>n>>k>>s; long long int a[n]; c=1000000000; if(s==c){c=1;} for(i=0;i<n;i++){a[i]=c;} for(i=0;i<k;i++){a[i]=s;} for(i=0;i<n;i++){cout<<a[i]<<" ";} return 0;}
0
#include<bits/stdc++.h> using namespace std; typedef pair<int,int> P; /* 平面幾何の基本要素 */ #define EPS (1e-10) #define equals(a,b) (fabs((a) - (b)) < EPS ) #define PI 3.141692653589793 class Point { // 点を表すクラス public: double x,y; Point(double x=0,double y=0): x(x),y(y) {} Point operator + (Point p) { r...
0
#include <bits/stdc++.h> using namespace std; int main() { string s,t; cin >> s >> t; vector<int> a,b; int k=0; for(int i=0; i<s.size(); i++) { if(k<t.size()&&s[i]==t[k]) { a.push_back(i); k++; } } k=t.size()-1; for(int i=s.size()-1; i>=0; i--) { if(k>=0&&s[i]==t[k]) { b....
0
#include<bits/stdc++.h> #define int long long int const int mod=1e9+7; #define fastinout ios_base::sync_with_stdio(false); cin.tie(NULL); using namespace std; int power(int x, int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >...
3
#include<bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; if(N%100<=(N/100)*5 && N>=100) cout << 1 << endl; else cout << 0 << endl; }
0
#include<bits/stdc++.h> using namespace std; #define int long long const int maxn=5*1e5+10; const int mod=1e9+7; int n,m,ans,delta,sum0; int a[maxn],sum1[maxn],sum2[maxn],sum3[maxn],fac[maxn]; bool vis[maxn]; struct Tree_arry { #define lowbit(x) (x&-x) int a[maxn]; inline void add(int x,int k){for(int i=x;i<=n;i+=lo...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, sum1 = 0, sum2 = 0, sumx = 0; cin >> n; long long arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } int i = 0, j = n - 1; sum1 = arr[i]; sum2 = arr[j]; while (i != j) { if (sum1 == sum2) { if (sum1 > sumx) { ...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; vector<int> v(n); vector<int> res(n); vector<bool> lst(n); vector<int> pos; int k = 0; cin >> v[0]; res[0] = v[0]; lst[v[0] - 1] = true; for (int j...
2
#include <bits/stdc++.h> using namespace std; using namespace std; const int K = 7; const int N = 200500; int n, k; int sz[K][N], ups[K][N]; long long len[K][N], ways[K][N]; long long f[K][N], fuh[K][N], f1[K][N], fup[K][N]; vector<int> g[N]; void dfs(int ver, int prev) { f[0][ver] = 1; sz[0][ver] = 1; for (int i...
4
#include <bits/stdc++.h> using namespace std; const long double ZERO = 1e-15; const long double EPS = 1e-10; const int MAXN = 100500; const int INF9 = 2 * 1e9; const long long INF18 = 4 * 1e18; const long long L0 = 0; const long double PI = acos(-1); const long double sq2 = sqrt(2.0); int main() { int n; cin >> n; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int x = 0, y = 0, pos = 0, ans = 0; if (s[0] == 'R') { pos = 1; } for (int i = 0; i < s.length();) { if (s[i] == 'R') { while (s[i] == 'R') { x++; i++; } } else if (s[i...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; vector<int> g[maxn]; int d[maxn]; pair<int, int> e[maxn * 2]; int main() { int n, m, h, t; scanf("%d%d%d%d", &n, &m, &h, &t); for (int i = 0; i < m; ++i) { int u, v; scanf("%d%d", &u, &v); g[u].push_back(v); g[v].push_back(u)...
2
#include <bits/stdc++.h> using namespace std; string dToB(int n) { string s = bitset<64>(n).to_string(); const auto loc1 = s.find('1'); if (loc1 != string::npos) return s.substr(loc1); return "0"; } int main() { int t; cin >> t; string s = dToB(t); while (s.length() != 6) s = '0' + s; string ans = "00...
1
#include <bits/stdc++.h> using namespace std; int n, k, na, d[32 + 1]; void nhap() { cin >> n >> k; } int dem() { int i, kq; kq = 0; for (i = 0; i <= na; i = i + 1) { kq = kq + d[i]; }; return (kq); } int tang() { int i; for (i = 1; i <= na; i = i + 1) { if (d[i] >= 1) { d[i] = d[i] - 1; ...
3
#include <bits/stdc++.h> using namespace std; int main() { char h[1000002]; scanf("%s", h); string x = string(h); int i; for (i = 0; i < x.size(); i++) if (x[i] != '0') break; if (i) x.erase(x.begin(), x.begin() + i); for (i = 0; i < x.size(); i++) if (x[i] == '.') break; if (i == x.size()) x +=...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; string s2 = "I hate "; string l = "that I hate "; string g = "that I love "; string gf = "it"; string s1 = "that I love "; string s3 = "that I love that I hate "; cin >> n; cout << s2; if (n == 2) cout << s1; else if (n == 3) ...
1
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; bool v = false, h = false; for (auto &x : s) { if (x == '0') { if (v) { cout << "3 4" << endl; } else { cout << "1 4" << endl; } v = !v; } else { if (h) { cout << "4 3" <<...
3
#include <iostream> using namespace std; int n , s; int dfs(int i , int sum , int N){ if(N == 0 && sum == 0) return 1;//yes if(N == 0 || i == 10) return 0;//no return dfs(i + 1 , sum , N) + dfs(i + 1 , sum - i , N - 1); } int main(){ while(cin >> n >> s , n){ cout << dfs(0 , s , n) << endl; } return 0; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m = 40; cin >> n; int v[n]; for (int i = 0; i < n; i++) { cin >> v[i]; if (v[i] < m) m = v[i]; } cout << 2 + (v[2] ^ m) << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; #define for_(i,a,b) for(int i=a;i<b;++i) int N, tt[22][22], use[22]; int dfs(int v, int p, int ct) { int res = ct; for_(i,0,N) { if (i == p || tt[v][i] == -1 || !use[i]) continue; res = max(res, dfs(i, v, ct + tt[v][i])); } return res; } int main() { while ...
0
#include <iostream> #define W 0 #define B 1 using namespace std; int n; int m; int p; int cou; int dy[]={0, -1, -1, -1, 0, -1, -1, -1, 0, -1, -1, -1, 0}; int dx[]={1, 1, 0, -1, 1, 1, 0, -1, 1, 1, 0, -1, 0}; int dz[]={0, 0, 0, 0, 1, 1, 1, 1, -1, -1, -1, -1, 1}; int hantei(int, int, int, int); class peg{ public: int b...
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long hxtype; template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;} template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;} const int N=100001; int a[N],c[N]; inline bool cmp(int a,int b){return a>b;} int main(){ int n,m,...
0
#include <bits/stdc++.h> using namespace std; const int N = 405, M = 1e9 + 7; int dp[N][N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; dp[1][0] = 1; dp[1][1] = 1; for (int i = 2; i <= n; i++) { dp[i][0] = 1; for (int k = 1; k <= n; k++) { for (int j = 0; j <= k; j++) ...
4
#include <bits/stdc++.h> using namespace std; int n; string a; int f[1005][5]; int main() { cin >> n >> a; string t = "", s = ""; char cur = '0'; for (int i = 0; i <= n - 1; i++) { t += cur; s += '1' - cur + '0'; cur = '1' - cur + '0'; } int ans = (int)2e9; int res = 0, res1 = 0; for (int i ...
4
#include <bits/stdc++.h> using namespace std; const int inf = 0x20202020; const int mod = 1000000007; template <class T> inline void read(T &x) { bool fu = 0; char c; for (c = getchar(); c <= 32; c = getchar()) ; if (c == '-') fu = 1, c = getchar(); for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0';...
4
#include <bits/stdc++.h> using namespace std; const int N = 20; const int mod = 998244353; struct node { int sum, tot; node(){}; node(int S, int T) { sum = S; tot = T; } bool check() { return ~sum && ~tot; } } f[2][2][N][1 << 10]; int A[N], ret, pw[30], k; int lowbit(int x) { return x & -x; } int ccou...
5
#include <bits/stdc++.h> int main() { int m, n; int sen[200000]; int change[200]; int x, y; int a, b; int c; scanf("%d %d", &n, &m); getchar(); for (a = 0; a <= 199; a++) { change[a] = a; } for (a = 0; a <= n - 1; a++) { c = getchar(); sen[a] = c; } getchar(); for (a = 0; a <= m ...
2
#include <bits/stdc++.h> using namespace std; int const N = 2e6 + 20, mod = 1e9 + 7; long long p, root[N], k, ans = 1; int find(int v) { return root[v] < 0 ? v : root[v] = find(root[v]); } void merge(int v, int u) { if ((u = find(u)) == (v = find(v))) return; if (root[u] < root[v]) swap(u, v); root[v] += root[u];...
4
#include <bits/stdc++.h> using namespace std; const int N = 6e5 + 10; const long long inf = -(1LL << 60); const long long MOD = 998244353; int n, m; int in[N << 2][2]; long long tree[N << 2][2]; long long d[N], h[N], sum[N]; void pushup(int o) { if (tree[2 * o][0] >= tree[2 * o + 1][0]) { tree[o][0] = tree[2 * o]...
5
#include "bits/stdc++.h" using namespace std; int INF = 1e8; int f(vector < pair<int, int> >vec) { sort(vec.begin(),vec.end()); int res = INF; for (int i = 1;i<vec.size();++i) { if (0 == vec[i-1].second && 0 != vec[i].second) { res = min(res,vec[i].first- vec[i-1].first); } } return res; } int f(map<int, ...
0
#include <iostream> #include <cstdio> using namespace std; int main(){ int n, m, p; scanf("%d%d%d", &n, &m, &p); printf("%d", n ^ m ^ p); return 0; }
0
#include <bits/stdc++.h> using namespace std; int vis[1010]; int minn = 1100; int main() { int n, m, x; scanf("%d%d", &n, &m); while (m--) { scanf("%d", &x); vis[x]++; } for (int i = 1; i <= n; i++) minn = min(minn, vis[i]); printf("%d\n", minn); return 0; }
1
#include<bits/stdc++.h> using namespace std; #define MAX_N 100000 struct edge{ int to,cost; }; typedef pair<int,int> P; const int INF=1000000001; int N,M; int d[MAX_N]; vector<edge> G[MAX_N]; int main(){ cin>>N>>M; for(int i=0;i<M;i++){ int a,b,c; scanf("%d %d %d",&a,&b,&c); G[a].push_back((edge){b,c}...
0
#ifdef LOCAL #pragma GCC optimize ("O0") #else #pragma GCC optimize ("O3") #endif #include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e9 + 7; const int MOD = INF; const ll INF_LL = 1e18 + 7; #define __overload3(_1, _2, _3, name,...) name #define rep(...) __overload3(__VA_ARGS__, r...
0
#include <bits/stdc++.h> using namespace std; long long powmod(long long a, long long b) { long long res = 1; a %= 1000000007; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % 1000000007; a = a * a % 1000000007; } return res % 1000000007; } int main() { int u, v; cin >> u >> v; ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long g = n - 1, res = 0; while (g > 0 && k > 0) { res += g * 2 - 1; k--; g -= 2; } cout << res; return 0; }
2
#include <bits/stdc++.h> using namespace std; string ConverToRomanNumber(int n, int index) { int m; const char *roman_number = "IVXLCDMRP"; string ret(""); if (n / 10) ret = ConverToRomanNumber(n / 10, index + 2); n %= 10; while (n < 4 && n--) ret.append(string(1, roman_number[index - 1])); ret.append(n =...
3
#include <bits/stdc++.h> const int MN = 1e6 + 44; int cou[MN]; int arr[MN]; int divcou[MN]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) { scanf("%d", arr + i); if (arr[i] <= m) cou[arr[i]]++; } for (int i = 1; i < MN; ++i) for (int k = i; k < MN; k += i) divcou[k] += ...
4
#include <bits/stdc++.h> using namespace std; int l[200], r[200]; int main() { int p1, p2, p3, t1, t2, n; cin >> n >> p1 >> p2 >> p3 >> t1 >> t2; int ans = 0; for (int i = 1; i <= n; i++) { cin >> l[i] >> r[i]; r[0] = l[i]; ans += (r[i] - l[i]) * p1; int ll = l[i] - r[i - 1]; ans += min(ll, ...
1
#include <bits/stdc++.h> using namespace std; long long N, M; const long long INF = numeric_limits<long long>::max(); struct Edge { long long u, v, c; Edge() {} Edge(long long u, long long v, long long c) : u(u), v(v), c(c) {} }; vector<vector<long long>> G(20010LL); vector<long long> match(20010LL), dist(20010LL...
2
#include <bits/stdc++.h> using namespace std; long long dp[300000], dp2[300000]; long long pos[300000], pos2[300000]; long long a[300000]; int main() { long long n, k; cin >> n >> k; memset(dp, 0, sizeof(dp)); memset(dp2, 0, sizeof(dp2)); a[0] = 0; long long val; for (long long i = 1; i <= n; i++) { c...
2
//Author:xht37 #include <bits/stdc++.h> #define ui unsigned int #define ll long long #define ul unsigned ll #define ld long double #define pi pair <int, int> #define fi first #define se second #define mp make_pair #define ls (p << 1) #define rs (ls | 1) #define md ((t[p].l + t[p].r) >> 1) #define vi vector <int> #d...
0
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int MAXN = 1e2 + 5; const long long MOD = 1e9 + 7; int a[1005][3000]; int main() { int n, s, d; int maxx = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> s >> d; for (int j = s; j <= 100000000; j += d) { if (j > maxx) ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; vector<int> G[maxn]; vector<int> leaves; int dep[maxn]; int fa[maxn]; void dfs(int u) { bool leaf = true; for (auto v : G[u]) { if (dep[v] == 0) { leaf = false; fa[v] = u; dep[v] = dep[u] + 1; dfs(v); } } if ...
5
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int n =0; for(int i=0;i<3;i++){ if(S.at(i)=='R'){ n++; } } if(n==2 && S.at(1)=='S'){ n --; } cout << n << endl; }
0
#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--) { int a, b; cin >> a >> b; string s; cin >> s; int n = s.size(); int first = n, last = -1; for (int i = 0; i < n; i++) { ...
2
#include <bits/stdc++.h> using namespace std; int a[2222][2222], out[2222][2222], was[2222][2222]; int n, m; int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0}, dy[] = {-1, 0, 1, 1, 1, 0, -1, -1}; void dfs(int i, int j, vector<int>& x, vector<int>& y) { if (i < 0 || j < 0 || i >= n || j >= m) return; if (was[i][j] || a[i][j] !...
6
#include <iostream> using namespace std; int main(){ int a,b; while(1){ a=-1; int ret = 0; int data[102]={0}; while(cin >> a >> b && a || b){ a--;b--; data[a]++; data[b]++; } if(data[0]%2==0 || data[1]%2==0)ret = 10000; for(int i=0;i<102;i++){ if(data[i]%2==1 && data[i]){ ret++; } ...
0
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); vector<vector<int> > g; vector<bool> u1, u2; int c = 0; void dfs1(int v) { u1[v] = 1; for (auto i : g[v]) if (!u1[i]) dfs1(i); } void dfs2(int v) { ++c; u2[v] = 1; for (auto i : g[v]...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n, d[maxn]; long long l[maxn][2], r[maxn][2], ans; int main() { scanf("%d", &n); for (int i = 1; i < n; i++) scanf("%d", &d[i]); l[0][0] = l[0][1] = 0; for (int i = 1; i < n; i++) { l[i][1] = d[i] < 2 ? 0 : l[i - 1][1] + d[i] / 2 * 2...
3
#include <bits/stdc++.h> using namespace std; const double eps = 1E-8; const int dx4[4] = {1, 0, 0, -1}; const int dy4[4] = {0, -1, 1, 0}; const int inf = 0x3f3f3f3f; const int N = 1E5 + 7; int tree[2][N]; int a[N], p[N]; int n; long long k; int lowbit(int x) { return x & (-x); } void update(int o, int x, int delta) { ...
5
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; while (c--) { if (a <= b) a++; else b++; } cout << min(a, b) * 2; }
1
#include "bits/stdc++.h" using namespace std; using ld = double; using Point = std::complex<ld>; const ld eps = 1e-9, pi = acos(-1.0); namespace std { bool operator<(const Point &lhs, const Point &rhs) { if (lhs.real() < rhs.real() - eps) return true; if (lhs.real() > rhs.real() + eps) retur...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); if (n <= 9) printf("1\n%d", n); else { printf("%d\n1", n); for (int i = 2; i <= n; i++) printf(" 1"); printf("\n"); } return 0; }
1
#include <iostream> #include <cstdio> #include <vector> #include <set> #include <map> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <cstring> #include <complex> #include <functional> #include <cmath> using namespace std; #define rep(i,n) for(int i=0;i<(n);++i) #define rep1(i,n) for(in...
0
#include <bits/stdc++.h> using namespace std; int a1, a2, a3, a4; int main() { scanf("%d%d%d%d", &a1, &a2, &a3, &a4); if (abs(a3 - a4) > 1) { printf("-1\n"); return 0; } if (a3 != a4) { if (min(a1, a2) < max(a3, a4)) { printf("-1\n"); return 0; } } if (a3 == a4) { if (!(((a1 ...
2
#include <bits/stdc++.h> using namespace std; int main() { int y1, m1, d1, y2, m2, d2; scanf("%d:%d:%d\n%d:%d:%d", &y1, &m1, &d1, &y2, &m2, &d2); if (m1 < 3) y1--, m1 += 12; long long ans1 = 365 * y1 + y1 / 4 - y1 / 100 + y1 / 400 + (153 * m1 - 457) / 5 + d1 - 306; if (m2 < 3) y2--, m2 += 12; long lon...
2
#include <bits/stdc++.h> using namespace std; long long l, r, k; int main() { cin >> l >> r >> k; if (k >= 4) { for (long long i = l; i + 2 < r; i++) if (i % 2 == 0) { cout << 0 << endl << 4 << endl << i << " " << i + 1 << " " << i + 2 << " " << i + 3 << " " ...
4
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long long INF = 1e18; const char nl = '\n'; void solve() { string a, b; cin >> a >> b; if (a == b) { cout << -1; return; } cout << max(a.size(), b.size()); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.ti...
1
#include <bits/stdc++.h> using namespace std; int main () { int N; cin >> N; vector<long> data(N); long ans = 0; for(int i = 0; i < N; i++)cin >> data.at(i); for(int i = 0; i < N; i++){ if(data.at(i) == i + 1){ ans++; i++; } } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; char S[500005], T[500005], A[MAXN]; struct Node { int len; int seriesAns; int seriesPre; Node *link, *slink; map<int, Node *> to; Node(int _len) : len(_len) {} int diff() { return len > 0 ? len - link->len : 0; } }; int pos; Node *las...
5
#include <bits/stdc++.h> const int N = 65540; const int mod = 1e9 + 7; long long n; int m, fac[N], inv[N]; int F[N], G[N], rnk[N], Ans; int ksm(int u, int v, int md) { int res = 1; for (; v; v >>= 1, u = 1ll * u * u % md) if (v & 1) res = 1ll * res * u % md; return res; } inline void swap(int &u, int &v) { ...
5
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; cin >> s; sort(s.begin(), s.end()); int i = 0, natija = 0; while (i != s.size()) { int m = upper_bound(s.begin(), s.end(), s[i]) - s.begin(); int l = m - i; if (l == 1) { ...
2
#include <bits/stdc++.h> using namespace std; const long long int maxn = 100010; long long int arr[maxn]; long long int cumi[maxn]; long long int n, k; bool ask(long long int start, long long int end) { long long int cumi_sum = cumi[end] - cumi[start - 1]; long long int lagbe = arr[end] * (end - start + 1); retur...
3
#include <bits/stdc++.h> using namespace std; int main() { char as[10][10]; int i, j, white = 0, black = 0; for (i = 0; i < 8; i++) for (j = 0; j < 8; j++) { cin >> as[i][j]; if (as[i][j] == 'Q') white += 9; else if (as[i][j] == 'R') white += 5; else if (as[i][j] == 'B'...
1
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; vector<int> g[N]; void dfs(int u, vector<int>& dep, int par = -1, int h = 0) { dep[u] = h; for (int v : g[u]) { if (v == par) continue; dfs(v, dep, u, h + 1); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, x;...
3
#include <bits/stdc++.h> long long max(long long a, long long b) { if (a > b) return a; return b; } int l, r; int dl, dr; int getd(int x) { if (x == 0) return 0; return 1 + getd(x / 10); } long long gs(int bd) { if (bd == 0) return 0; return 9 + gs(bd - 1) * 10; } int main() { scanf("%d %d", &l, &r); dl...
1
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cctype> #include<cstdlib> #include<algorithm> #include<bitset> #include<vector> #include<list> #include<deque> #include<queue> #include<map> #include<set> #include<stack> #include<cmath> #include<sstream> #include<fstream> #include<iomanip>...
0
#include <bits/stdc++.h> using namespace std; int n, k, a, b; long long sum = 0; int main() { scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &a); scanf("%d", &b); sum += (b - a + 1); } printf("%I64d", (k - sum % k) % k); return 0; }
1
#include <stdio.h> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <vector> typedef long long int ll; #define BIG_NUM 2000000000 #define MOD 1000000007 using namespace std; int main(){ int N,W,ans = 0,sum = 0; scanf("%d %d",&N,&W); int* dp = new int[W+1]; int* friends...
0
#include <bits/stdc++.h> using namespace std; int tc = 1; vector<string> split(const string &s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.emplace_back(x); return move(v); } void err(vector<string>::iterator it) {} template <typename T, typename... Args> void err(vec...
2
#include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <cstring> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <complex> #incl...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n, c = 0; cin >> n; while (n >= 1) { if (n % 6 == 0) { n = n / 6; c++; } else if (n % 3 == 0) { n = n * 2; c++; } else if (n == 1) { cout <<...
2
#include <bits/stdc++.h> using namespace std; double const pi = 3.1415926535897932384626433832795; int const inf = (int)1e9; long long const inf64 = (long long)2e18; const string name = "a"; int n; int main() { cin >> n; if (n & 1) { for (int i = 0; i < (int)n / 2; i++) { cout << (char)('a' + (i % 2)); ...
1
#include <bits/stdc++.h> using namespace std; vector<int> par; void bryceorz(int v, int p, const vector<vector<int>> &graph) { par[v] = p; for (int nxt : graph[v]) { if (nxt == p) continue; bryceorz(nxt, v, graph); } } int main() { int n; scanf("%d", &n); vector<double> fail(n); for (int i = 0; i ...
4
#include <bits/stdc++.h> using namespace std; void solve() { int n, x, m, a, b, mx, mi; cin >> n >> x >> m; mx = x; mi = x; int ans = 1; for (long long i = (0); i < (m); ++i) { cin >> a >> b; if (a <= mi && b >= mx) { ans = b - a + 1; mi = a; mx = b; } else if (a <= mi && b >= ...
2
#include <bits/stdc++.h> int main() { char a[9999], b[9999]; gets(a); int i, j, n = strlen(a), t, kong = 0; for (i = 0; i < n; i++) { t = 0; if (a[i] == '<') { while (a[i] != '>') { b[t++] = a[i++]; } b[t++] = '>'; b[t++] = '\0'; int flag = 1; for (j = 0; a[j]...
2
#include <bits/stdc++.h> using namespace std; const int oo = 2139063143; const int N = 2010; const int P = 1000000007; const double eps = 1e-7; template <typename T> inline void sc(T &x) { x = 0; static int p; p = 1; static char c; c = getchar(); while (!isdigit(c)) { if (c == '-') p = -1; c = getch...
5
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; if (n == 1) cout << "1" << endl; else if (n == 2) cout << "2" << endl; else if (n == 3) cout << "6" << endl; else { if (n % 2 == 1) cout << n * (n - 1) * (n - 2) << endl; else { if (n % 3 == 0) ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, count = 0, sum = 0; cin >> n >> k; int seq[n]; set<int> s; vector<int> v; for (int i = 0; i < n; i++) { cin >> seq[i]; s.insert(seq[i]); } int d = s.size(); for (int i = 1;; i++) { s.insert(i); int dd = s.size()...
3
#include <bits/stdc++.h> const long long INF = 1e18; const int32_t M = 1e9 + 7; using namespace std; int gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } void solve() { string s; cin >> s; int m = 0, c = 0; for (int i = 0; i < s.length(); i++) { if (int(s[i]) > m) { m ...
1
#include <bits/stdc++.h> using namespace std; const long long int MOD = 998244353; const long long int INF = 2000000000; const long long BIG = 1446803456761533460LL; const long long int maxn = 200010; const long long int maxm = 3010; long long int n, m, a, b; long long int dp[maxm][maxm]; pair<long long int, long long ...
3
#include <bits/stdc++.h> using namespace std; int n; int size; int as[200000]; int bs[200000]; int maxseg[19][200000]; int minseg[19][200000]; long long int ans; int getmin(int l, int r) { int len = r - l; int k = l; int ret = 1000000001; for (int i = 18; i >= 0; i--) { if ((len >> i) & 1) { ret = min...
4
#include<cstdio> #define ll long long const int M=205,N=5005; int n,m,i,j,v[M][N],t[M],q[M][N]; ll a[N],sum,f[N],ans; int read(){ char c=getchar();int k=0;for (;c<48||c>57;c=getchar()); for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k; } void gmax(ll &x,ll k){if (k>x) x=k;} int main(){ n=read();m=read(); ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int i, t, n; cin >> t; while (t--) { cin >> n; if (n == 1) { cout << "8\n"; continue; } long long int x = n / 4; if (n % 4 > 0) x++; n -= x; whi...
2
#include "bits/stdc++.h" using namespace std; static const int N = 100; int main(){ int n,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) { int j=i+l-1; m[i][j]=(...
0
#include <bits/stdc++.h> using namespace std; int main() { int i, m, n, mi, cnt; long long t; double s, tmp, sum, ans; while (~scanf("%d", &n)) { m = 2 * n; cnt = 0; sum = 0; for (i = 1; i <= m; i++) { scanf("%lf", &s); t = (long long)s; if (t == s) cnt++; else { ...
3
#include <bits/stdc++.h> using namespace std; long long a[20]; int main() { long long n; cin >> n; a[1] = 4; a[2] = 10; a[3] = 20; a[4] = 35; a[5] = 56; a[6] = 83; a[7] = 116; a[8] = 155; a[9] = 198; a[10] = 244; a[11] = 292; if (n <= 11) cout << a[n]; else cout << a[11] + (n - 11l...
2
#include <bits/stdc++.h> using namespace std; int n, b, e, cnt; bool f, ans = 1; vector<int> v, r; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0, x; i < n; ++i) { cin >> x; v.push_back(x); r.push_back(i + 1); if (v[i] != r[i]) { if (!f) b = i + 1, f = 1...
2
#include <bits/stdc++.h> using namespace std; const long long N = (1LL << 22) + 2; long long n, m; long long a[N]; bool vis[2][N]; void dfs(long long k, long long cur) { if (vis[cur][k]) return; vis[cur][k] = 1; if (cur == 1) return dfs(k, cur ^ 1); for (long long i = 0; i < n; i++) { if ((k & (1LL << i)) =...
3