solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; b = b % n; if (b > 0) { a = a + b; if (a > n) { cout << a % n; } else { cout << a; } } else { a += b; if (a <= 0) { cout << n + a; } else { cout << a; } } ret...
1
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int t; cin >> t; while (t--) { long long n, m; cin >> n >> m; long long a[n][m], i, j; for (i = 0; i < n; i++) { for (j = 0;...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c, ans; cin >> n >> a >> b >> c; swap(a, c); ans = 0; for (int i = 0; i <= a; i++) for (int j = 0; j <= b; j++) { int t = (n - i * 2 - j) * 2; if (t <= c && t >= 0) ans++; } cout << ans << endl; }
2
#include <bits/stdc++.h> using namespace std; vector<int> adj[100005]; vector<int> v; int frr[100005]; int vis[100005]; int counter = 0; void edge(int a, int b, int c) { frr[a]++; frr[b]++; frr[c]++; adj[a].push_back(b); adj[a].push_back(c); adj[b].push_back(a); adj[b].push_back(c); adj[c].push_back(a);...
3
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; int n, m, map[16][16]; ll in[1 << 16], f[1 << 16][16]; int main() { scanf("%d%d", &n, &m); int x, y; for (int i = 1; i <= m; i++) { scanf("%d%d", &x, &y); x--, y--; scanf("%d", &map[x][y]); map[y][x] = map[x...
0
#include <bits/stdc++.h> using namespace std; int a[5010]; int fence(int l, int r, int k) { if (l == r) return 1; else { int Min = 1000000010; for (int i = l; i <= r; i++) Min = min(Min, a[i] - k); int ans = 0; for (int i = l; i <= r; i++) { if (a[i] - k > Min) { int ll = i, rr = i...
3
#include<iostream> #include<vector> using namespace std; int main(){ while(1){ int n; cin>> n; if(!n) break; string s[n]; for(int i=0; i<n; i++) cin>> s[i]; for(int i=1; i<n; i++){ for(int j=0; j<s[i].size(); j++){ if(s[i][j]!='.'){ s[i][j-1...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } long long int ans = 0; map<vector<pair<long long int, long long int> >, long long int> mp; for (int i = 0; i < n; i++) { vector<pair<long...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, i, x; cin >> n; int a[n + 5]; for (i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); a[1] = 1; for (i = 2; i <= n; i++) { x = a[i]; if (a[i] > a[i - 1] + 1) { a[i] = a[i - 1] + 1; } if (a[i] > x) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; long long m; cin >> n >> m; vector<long long> v(n); set<int> s; for (int i = 0; i < n; ++i) { cin >> v[i]; s.insert(v[i]); } sort(v.begin(), v.end()); vector<long long> acc(n + 1); ...
3
#include <bits/stdc++.h> using namespace std; vector<long long> v; long long getcost(long long l, long long idx) { if (idx == 0) return l * v[0]; long long x = 1 << idx; long long val = l / x; return min(v[idx] * (val + 1), v[idx] * val + getcost(l - val * x, idx - 1)); } int32_t main() { ios::sync_with_stdio...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const int mod = 1e9 + 7; long long exp(long long a, long long b) { long long ans = 1; while (b != 0) { if (b % 2) ans = ans * a; a = a * a; b /= 2; } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout...
1
#include <bits/stdc++.h> using namespace std; vector<vector<long long int> > base; long long int rr[2][2]; void mul(long long A[2][2], long long B[2][2]) { memset(rr, 0, sizeof(rr)); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { rr[i][j] += (A[i][k] * B[...
3
#include<bits/stdc++.h> using namespace std; const int N = 200003; long long d,f[N],g[N],a[N],ans=0; int n; int main(){ scanf("%d%lld",&n,&d); for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); ans+=a[i]; } f[1]=a[1];g[n]=a[n]; for(int i=2;i<=n;i++) f[i]=min(f[i-1]+d,a[i]); for(int i=n-1;i>=1;i--) g[i]=min(g[i+1]+d...
0
#include <iostream> #include <string> using namespace std; int main() { int n; cin >> n; int c[10][10] = {}; for (int i = 1; i <= n; ++i) { string s = to_string(i); ++c[s[0]-'0'][s.back()-'0']; } long long ans = 0; for (int i = 1; i <= 9; ++i) for (int j = 1; j <= 9; ++j) ans += c[i][j] ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; long long ans = 0; vector<long long> v; v.push_back(0); for (int i = 0; i < n; i++) { int e; cin >> e; v.push_back(e + v[i]); } map<long long, in...
3
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int MOD = 1e9 + 7; struct dt { LL v, ev; dt(LL v = 0, LL ev = 0) : v(v % MOD), ev(ev % MOD) {} dt followed(const dt &o) const { dt ret; ret.v = (v * o.ev % MOD + o.v) % MOD; ret.ev = ev * o.ev % MOD; return ret; } }; LL modExp(LL x, ...
0
#include <iostream> using namespace std; int main() { string s; cin >> s; if (s == "RRR") cout << "3\n"; else if (s == "RRS" || s == "SRR") cout << "2\n"; else if (s == "SSS") cout << "0\n"; else cout << "1\n"; }
0
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int a[n]; int i; for(i=0;i<n;i++) cin>>a[i]; int b[n]; memset(b,0,sizeof(b)); b[1]=abs(a[1]-a[0]); for(i=2;i<n;i++) b[i]=min(b[i-1]+abs(a[i]-a[i-1]),b[i-2]+abs(a[i]-a[i-2])); cout<<b[n-1]; }
0
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e6 + 10, inf = 1e18, mod = 1e9 + 7; struct pair_hash { template <class T1, class T2> std::size_t operator()(const std::pair<T1, T2> &p) const { auto h1 = std::hash<T1>{}(p.first); auto h2 = std::hash<T2>{}(p.second); return h1 ^ h2; ...
1
#include <iostream> using namespace std; int main(void){ int i; for(i = 1; i <= 7; i++){ int a,b; cin >> a >> b; cout << a - b; cout << endl; } }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { bool possible = false; int n, e, ops = 0; cin >> n; int arr[n]; int max_ops = (n * (n - 1) / 2) - 1; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < n - 1; i++) { ...
1
#include<bits/stdc++.h> const int MN=100000+5,P=1000000007,inv2=P+1>>1; using namespace std; typedef long long ll; template<typename T>inline T&IN(T&in){ in=0;char c=getchar();int f=1; while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} while(isdigit(c))in=in*10+c-'0',c=getchar(); return in*=f; } int n; int a[4][MN],c[...
0
#include<stdio.h> unsigned long long n, m; int main() { scanf("%llu%llu", &n, &m); if(n != 1 && m != 1)printf("%llu\n", (n * m + 1) / 2); else printf("1\n"); return 0; }
0
#include <bits/stdc++.h> using namespace std; template <class T> inline void remax(T& A, T B) { if (A < B) A = B; } template <class T> inline void remin(T& A, T B) { if (A > B) A = B; } string ToString(long long num) { string ret; do { ret += ((num % 10) + '0'); num /= 10; } while (num); reverse(ret...
1
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.writ...
3
#include <bits/stdc++.h> using namespace std; template <class T> void print(T a) { for (auto x : a) cout << x << ' '; cout << endl; } template <class T, class U> inline istream& operator>>(istream& str, pair<T, U>& p) { return str >> p.first >> p.second; } template <class T, class U> inline ostream& operator<<(os...
2
#include <bits/stdc++.h> using namespace std; int n, m, k, a, b, c, p; int mas[1010][1010]; int main() { scanf("%d %d %d", &n, &m, &k); for (int i = 0; i < k; i++) { scanf("%d %d %d", &a, &b, &c); mas[a - 1][b - 1] = c; } scanf("%d", &p); if (n % 2 != m % 2) { printf("0"); return 0; } for ...
5
#include <bits/stdc++.h> using namespace std; pair<int, int> a, b, c; int n; bool vis[1010][1010]; bool check(int x, int y) { if (x == c.first && y == c.second) return true; if (x < 1 || y < 1 || x > n || y > n || vis[x][y] || x == a.first || y == a.second || x - y == a.first - a.second || x + y == a.fi...
1
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char c = getchar(); while ((c < '0' || c > '9') && (c != '-')) c = getchar(); if (c == '-') f = -1, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } const int N = 2...
6
#include <math.h> #include <utility> #include <string> #include <vector> #include <algorithm> #include <iostream> using namespace std; long long int iti = 1; int main(){ while(true) { int n; cin >> n; if ( n == 0 ) break; vector<long int> yotei; vector<long long int> tizu; for ( int i = 0; i < n; i++ ) {...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 9; const int MOD = 998244353; const long long oo = 8e18 + 9; int n; pair<int, int> a[N], x[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); ; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second; for (int i = 1; i <= n...
2
#include<iostream> #include<vector> #include<queue> #include<algorithm> using namespace std; int main() { int n, u, k, v; cin >> n; vector<int> ans(n,1000000000); vector<vector<int>> adj(n); for (int i = 0; i < n; i++) { cin >> u >> k; while (k--)cin >> v, adj[u-1].push_back(v-1); } queue<pair<int, int>> q...
0
#include <bits/stdc++.h> using namespace std; const int N = 501010; const int qwq = 303030; const int inf = 0x3f3f3f3f; const int mp = 998244353; int T; int n, k; int a[N]; bool vis[N]; int st[N], cnt; int ans; inline int read() { int sum1 = 0, ff = 1; char c = getchar(); while (c < '0' || c > '9') { if (c ==...
2
#include <bits/stdc++.h> using namespace std; map<long long, long long> m1; long long dp[1000][1000]; bool used[100001]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); memset(dp, 0, sizeof(dp)); long long a; string s1; cin >> a >> s1; long long ans = 0; long long count[100005]...
1
#include <bits/stdc++.h> using namespace std; long long mo(const long long input, const long long ceil) { return input >= ceil ? input % ceil : input; } void solve(long long tt) { string str[1600]; map<string, long long> mp; long long n, k, num = 0; cin >> n >> k; for (long long i = 0; i < n; i++) { cin...
2
#include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<(n);i++) #define pb push_back #define all(v) (v).begin(),(v).end() #define fi first #define se second typedef vector<int>vint; typedef pair<int,int>pint; typedef vector<pint>vpint; template<typename A,typename B>inline ...
0
#include <bits/stdc++.h> using namespace std; int n, m, dp[(int)(1e5 + 4)], cost[(int)(1e5 + 4)]; vector<pair<int, int> > g[(int)(1e5 + 4)]; int dfs(int node) { if (dp[node]) return dp[node]; dp[node] = 1; for (auto it : g[node]) { if (dfs(it.first) + 1 > dp[node]) { dp[node] = dp[it.first] + 1; c...
4
#include <bits/stdc++.h> using namespace std; int main() { int a[6]; for (int i = 0; i < 6; i++) cin >> a[i]; int curr = a[0]; int next = curr + 1; int step = 1; int side1 = a[5], side2 = a[1]; int ind1 = 5, ind2 = 1; int subt = 0; int ans = 0; while (1) { ans += curr + next; curr = next; ...
3
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <string> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) const int dx[8] = { 1,1,0,-1,-1,-1,0,1 }; const int dy[8] = { 0,1,1,1,0,-1,-1,-1 }; int w, h; char grid[10][20]; map<string, int> spell; void dfs(int sy, int sx, int ...
0
#include <bits/stdc++.h> using namespace std; void gogo() {} int main() { gogo(); int m; cin >> m; map<double, int> mp; std::vector<double> v; while (m--) { string s; cin >> s; double a = 0, b = 0, c = 0; int i = 0; while (s[i] != '+') { if (s[i] >= '0' && s[i] <= '9') a = a * 10 +...
4
#include <iostream> #include <cstdio> using namespace std; int main(){ string str; bool first; first = true; while(true){ cin >> str; if(cin.eof()){ cout << endl; break; } if(str[str.size() - 1] == '.' || str[str.size() - 1] == ','){ if(str.size() >= 4 && str.size() <= 7){ if...
0
#include <iostream> #include <cstdlib> #include <string> #include <cmath> #include <algorithm> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) char back(char ch, int a){ int p = ch - 'a'; p = ( p + a + 26) % 26; return 'a' + p; } int a[200]; int b[200]; int main(){ int n; string s; whi...
0
#include <bits/stdc++.h> using namespace std; const int N = 5005; int A[N], B[N], C[N], preB[N]; int D[N]; int hitter[N]; vector<int> adj[N]; int k; int dp[N][N]; int main() { int n, m, u, v; cin >> n >> m >> k; for (int i = 1; i <= n; i++) cin >> A[i] >> B[i] >> C[i]; preB[0] = 0; bool ok = 1; if (k < A[1]...
4
#include <map> #include <queue> #include <iostream> typedef unsigned long long ull; using namespace std; struct state { ull x; int zero, pre, dist, remain; }; bool operator<(const state& s1, const state& s2) { return s1.dist + s1.remain > s2.dist + s2.remain; } int a, dist[16][16], goals[16], goals2[16]; ull s, goal = ...
0
#include <bits/stdc++.h> using namespace std; const int maxn=123; int m,n,x,c[maxn],a[maxn][maxn],sum[maxn],mini=INT_MAX,cost; void dfs(int cur){ if(cur==n+1){ bool bad=0; for(int i=0;i<m;i++) if(sum[i]<x)bad=1; if(bad==0){ mini=min(mini,cost); } return; } for(int i=0;i<m;i++)sum[i]+=a[cur][i]; cost...
0
#include <bits/stdc++.h> using namespace std; long long fun(long long x, long long y) { long long tmp; while (x % y != 0) { tmp = x % y; x = y; y = tmp; } return y; } int main() { long long n; cin >> n; long long k; if (n == 1) { k = 1; } else if (n == 2) { k = 2; } else if (n % ...
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int P=1e9+7; int n,m,K,U; ll f[1<<19],ans; bool vis[20][20],pos[20][20]; #define lowbit(x) ((x)&-(x)) int main(){ scanf("%d%d%d",&n,&m,&K); for(int i=1,a,b,c;i<=K;i++)scanf("%d%d%d",&a,&b,&c),a--,b--,vis[a][b]=true,pos[a][b]=c; U=1<<--n,f[0...
0
#include <bits/stdc++.h> using namespace std; inline int read() { int n = 0, k = 1; char ch = getchar(); while ((ch > '9' || ch < '0') && ch != '-') ch = getchar(); if (ch == '-') { k = -1; ch = getchar(); } while (ch <= '9' && ch >= '0') { n = n * 10 + ch - '0'; ch = getchar(); } return...
4
#include <bits/stdc++.h> using namespace std; string s; vector<pair<short, int>> v; int z; inline short cti(char c) { switch (c) { case '(': return 1; case ')': return -1; case '[': return 2; case ']': return -2; case '{': return 3; case '}': return -3; ...
3
#include <bits/stdc++.h> using namespace std; namespace zyt { template <typename T> inline bool read(T &x) { char c; bool f = false; x = 0; do c = getchar(); while (c != EOF && c != '-' && !isdigit(c)); if (c == EOF) return false; if (c == '-') f = true, c = getchar(); do x = x * 10 + c - '0', c = getch...
6
#include <bits/stdc++.h> using namespace std; int n, w, m, a[100005], l = 1, r = 1100000005, mid, c[100005], f[100005]; bool check(int x) { for (int i = 1; i <= n; i++) { c[i] = a[i] - a[i - 1]; } int kkk = 0; for (int i = 1; i <= n; i++) { f[i] = f[i - 1] + c[i]; if (f[i] < x) { if (kkk + (x ...
3
#include <cstdio> int x; int main() { scanf("%d", &x); if (x == 3 || x == 5 || x == 7) puts("YES"); else puts("NO"); }
0
#include <bits/stdc++.h> using namespace std; const int M = 55; int read() { int x = 0, flag = 1; char c; while ((c = getchar()) < '0' || c > '9') if (c == '-') flag = -1; while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); return x * flag; } int n, m, K, a[M], b[M], c[M]; ...
5
#include<iostream> #include<algorithm> using namespace std; static const int Max =1000; static const int Vmax=10000; int n,A[Max],s; int B[Max],T[Vmax+1]; int solve(){ int ans=0; bool V[Max]; for(int i=0;i<n;i++){ B[i]=A[i]; V[i]=false; } sort(B,B+n); for(int i=0;i<n;i++)T[B[i]]=i; for(int i=0;...
0
#include <bits/stdc++.h> using namespace std; int a[12][111]; int b[12][111]; int c[12][111]; pair<int, int> diff[111]; string s; int main() { int n, m, k; cin >> n >> m >> k; for (int i = 0; i < n; i++) { cin >> s; for (int j = 0; j < m; j++) { cin >> a[i][j] >> b[i][j] >> c[i][j]; } } int ...
3
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &t) { t = 0; char c = getchar(); int f = 1; while (c < '0' || c > '9') { if (c == '-') f = -f; c = getchar(); } while (c >= '0' && c <= '9') { t = (t << 3) + (t << 1) + c - '0'; c = getchar(); } t *= f...
5
#include <vector> #include <map> #include <set> #include <stack> #include <queue> #include <algorithm> #include <utility> #include <functional> #include <sstream> #include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> #include <c...
0
#include <bits/stdc++.h> using namespace std; struct que { int op, x, y; } q[200010]; int n, bin[200010], cnt, id; map<int, int> M; int F[200010], cur, ml[200010], mr[200010], tot, seq[200010], vis[200010]; int gf(int x) { return (F[x] == x) ? x : (F[x] = gf(F[x])); } vector<int> s[200010 << 2]; void find(int pos, in...
5
#include <bits/stdc++.h> using namespace std; int main() { string s, s1 = "BWBWBWBW", s2 = "WBWBWBWB"; bool k = true; for (int i = 1; i <= 8; i++) { cin >> s; if ((s == s1) || (s == s2)) continue; else k = false; break; } if (k == true) cout << "YES\n"; else cout << "NO\n...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, m; cin >> n >> m; vector<int> x(n); for(int i = 0; i < n; i++) { cin >> x[i]; } vector<int> per(m); set<int> s; vector<int> same(m); for(int i = 0; i < n; i++) { int cand =...
0
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const long long LMT = 100000000; long long binpow(long long a, long long b, long long m) { a %= m; long long res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } int32_t main() ...
4
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAX = 1e5 + 5; int a[MAX], b[MAX], rnk[MAX]; int main() { int n, l, r; cin >> n >> l >> r; for (int i = 0; i < n; i++) { cin >> a[i]; a[i] = -a[i]; } for (int i = 0; i < n; i++) { int x; cin >> x; x--; rnk...
4
#include <bits/stdc++.h> using namespace std; const int N = 1100; int n, m, k; char s[N]; int le[N][N], up[N][N], aa[N][N], bb[N][N]; int col[N][N]; int main() { cin >> n >> m >> k; int Ncnt = 0; for (int i = (1); i <= (2 * n - 1); i++) { scanf("%s", s + 1); if (i & 1) for (int j = (1); j <= (m - 1)...
4
#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n; std::cin >> n; std::vector<int> a; int g, d; std::cin >> g >> d; if (g > 0 && d == 0 && g + 1 == n) { std::cout << "-1\n"; return 0; } a.push_back(2); if (d == 0) { a.push_back(2); ...
3
#include <bits/stdc++.h> using namespace std; long long int fast_exp(long long int A, long long int B, long long int C) { if (A == 0) return 0; if (C == 0) return 0; if (B == 0) return 1; if (B == 1) return A % C; long long int res = A; if (res > C) res = res % C; int counter = 2; while (counter < B) { ...
1
#include <bits/stdc++.h> using namespace std; long long p; int k; long long q[10000]; int f[10000]; int main() { scanf("%I64d%d", &p, &k); int len = 0; f[0] = k; while (p < 0 || p >= k) { ++len; if (p > 0) q[len] = -p / k; else q[len] = -(p - k + 1) / k; f[len - 1] = p + q[len] * k; ...
4
#include <iostream> using namespace std; int main() { int sum=0,n,i; cin>>n; i=n; while(n!=0) { sum+=n%10; n=n/10; } if(i%sum==0) cout<<"Yes"; else cout<<"No"; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { long long a = 0, n, k = 0, x; cin >> n; while (n--) { cin >> x; a += k * (x - 1) + x; k++; } cout << a; }
1
#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 print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define print(x) #endif const int inf=1e9; const int64_t inf64=1e18; c...
0
#include <bits/stdc++.h> using namespace std; inline void R(int &a) { char ch = getchar(); a = 0; bool f = false; for (; ch != '-' && (ch < '0' || ch > '9'); ch = getchar()) ; if (ch == '-') { f = true; ch = getchar(); } for (; ch >= '0' && ch <= '9'; ch = getchar()) a = a * 10 + ch - 48; if...
4
#include <bits/stdc++.h> using namespace std; int T, Pow[31], X; int main() { Pow[0] = 1; for (int i = 1; i <= 30; i++) Pow[i] = 2 * Pow[i - 1]; cin >> T; for (int t = 1; t <= T; t++) { cin >> X; int b = 0; while (X > 0) { if (X % 2) b++; X /= 2; } cout << Pow[b] << '\n'; } r...
2
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; string to_string(string s) { return '"' + s + '"'; } string to_string(char s) { return string(1, s); } string to_string(const char* s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A>...
6
#include <bits/stdc++.h> using namespace std; constexpr int N = 5000 + 10; int cnt[N], now, c; string s; vector<int> pos[N]; double all; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> s; for (int i = 0; i < (int)s.size(); i++) pos[s[i] - 'a'].push_back(i); for (int i = 0; i <...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long q; cin >> q; vector<long long> v, pr; for (long long i = 2; i <= sqrt(q); i++) { if (q % i == 0) { v.push_back(q / i); v.push_back(i); } } for (long long i = 0; i < v.size()...
1
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline int read() { char c = getchar(); int tot = 1; while ((c < '0' || c > '...
6
#include <bits/stdc++.h> #pragma GCC optimize(2, 3, "Ofast") using namespace std; template <typename T1, typename T2> void ckmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> void ckmax(T1 &a, T2 b) { if (a < b) a = b; } int read() { int x = 0, f = 0; char ch = getchar(); while (!isdi...
5
#include<iostream> #include<queue> #include<map> #include<string> #include<sstream> #include<algorithm> using namespace std; int main(){ map<string, int> ans; queue<string> log; string f = "01234567"; int dx[4] = {1,-1,4,-4}; log.push(f); ans[f] = 0; while(!log.empty()){ string s = log.front(); in...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 100; const long long inf = 1e18 + 7; const long long mod = 1e9 + 7; int n; long long ans[maxn]; int v[maxn]; int d[maxn]; int x[maxn]; vector<pair<int, int> > queries[maxn]; vector<int> g[maxn]; const int segn = 1 << 20; long long tree[segn * 2]; long...
5
#include<iostream> #include<queue> #include<algorithm> #include<functional> #include<vector> #include<cstring> #include<cmath> using namespace std; #define WHITE 0 #define GRAY 1 #define BLACK 2 #define BFSMAX 1100 #define MAX_W 210000 #define MAX_N 210000 #define INF 1LL<<60 long long h, w, K; pair<long long, long ...
0
#include <bits/stdc++.h> using namespace std; #define DEBUG_MODE #define endl '\n' #ifdef DEBUG_MODE #define DEBUG(...) debug_func_mult(split_names(#__VA_ARGS__), __VA_ARGS__) #define DEBUG_ENDL endl << flush #define DEBUG_SEPARATOR_LINE cout<<"=================\n" #else #define DEBUG(...) 0 #define DEBUG_ENDL 0 #defin...
0
#include<bits/stdc++.h> using namespace std; int main(){ int n, s = 1; cin >> n; for(int i = 0; i < n; i++){ int a; cin >> a; if(a == s) s++; } s--; if(s) cout << n - s; else cout << -1; }
0
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops") #pragma GCC optimize("Ofast") using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } for (int i = 0; i < n; i++) { ...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") double eps = 1e-10; using namespace std; template <typename Type> void print_vector(vector<Type> &v) { for (int i = 0; i < v.size(); i++) cout << v[i]; puts(""); } long long n, m, cnt1, cnt2, ans; int used[100005], cmp, c[100005]; bool ind; vector<...
4
#include <bits/stdc++.h> using namespace std; int main() { int r, d; cin >> r >> d; int n; cin >> n; int ans = 0; for (int i = 0; i < n; i++) { int x, y, ra; cin >> x >> y >> ra; if (sqrt(x * x + y * y) + ra <= r && sqrt(x * x + y * y) - ra >= r - d) ans++; } cout << ans; }
2
#include <bits/stdc++.h> const long long MAXN = 1e5 + 10; using namespace std; long long ans = 0, cnt = 0; bool mark[MAXN]; vector<long long> vec[MAXN], rev[MAXN], ft, node; queue<long long> q; void dfs(long long x, vector<long long>* g, vector<long long>& node) { mark[x] = 1; for (auto u : g[x]) if (mark[u] ==...
5
#include<iostream> #include<string> using namespace std; int main() { string str; int n,i,j; cin >> n; for(i=0;i<=n;i++) { getline(cin,str); if(i!=0) { for(;;) { if(str.find("Hoshino")<str.size()) str[str.find("Hoshino")+6]='a'; else break; } cout << str << endl; } }...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 100; int vis[maxn]; int main() { string s1, s2; int n; cin >> n; cin >> s1 >> s2; vector<int> V; for (int i = 0; i < n; i++) { if (s1[i] != s2[i]) { int pos = 0; for (int j = i + 1; j < n; j++) { if (s2[i] == s1[j]) { ...
2
#include<iostream> #include<stdio.h> #include<string.h> #include<ctype.h> #include<cmath> #include<iomanip> using namespace std; int main(void){ int d,b,t,a[200][200],c,q[200][200],hokan,ue,mae,m; cin>>m; for(c=0;c<m;c++){ cin>>a[1][c]>>a[2][c]>>a[3][c]>>a[4][c]>>a[5][c]>>a[6][c];} for(c=0;c<m;c++){ for(d=0;d<c...
0
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; const int inf = 1e9 + 1; const long long OO = 1e18; long long p1, p2, c1, c2, w1, w2; long long solve() { long long a2, b1, b3, ans = 0; for (int i = 0; i <= min(p1 / w1, c1); i++) { long long a2 = min((p1 - i * w1) / w2, c2); long long ...
2
#include <bits/stdc++.h> using namespace std; const int N = 6e2 + 10; int n, MAX; string second; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> second; int n = second.size(), p = 0; while (p <= n) { string t = second; int k = 0; if (p < n && t[p] == 'V') t[p] = 'K'; el...
1
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int q; unsigned long long n, m; string s; cin >> q; int tab[70]; while (q--) { cin >> n; bool bad = false; unsigned long long pow3 = 1; m = n; ...
3
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int mi(int a, int b) { int s = 1; for (; b; b >>= 1, a = 1LL * a * a % mod) if (b & 1) s = 1LL * s * a % mod; return s; } int n, Pa, Pb, pa[2001], pb[2001], dp[2001][2001], f[2001], g[2001]; int main() { cin >> n >> Pa >> Pb; Pa = 1L...
6
#include<bits/stdc++.h> using namespace std; long long a[82],sum=1000,t=0; int main(){ long long n; 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]) { continue; } else { t=sum/a[i]; sum=sum%a[i]; sum=sum+a[i+1]*t; } } cout<<sum; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; struct point { int t, limit, id; } pt[maxn]; bool comp(point a, point b) { return a.t < b.t; } struct cmp { bool operator()(const point &a, const point &b) { if (a.limit == b.limit) return a.t < b.t; return a.limit > b.limit; } }; pr...
4
#include <bits/stdc++.h> using namespace std; int main(){ int N,X,Y; cin >> N >> X >> Y; int count[2002]={}; for(int i=1; i<=N-1; i++){ for(int j=i+1; j<=N; j++){ count[min(j-i,abs(X-i)+1+abs(Y-j))]++; } } for(int k=1; k<=N-1; k++) cout << count[k] << endl; }
0
#include<bits/stdc++.h> #define ll long long #define ull unsigned ll #define uint unsigned #define pii pair<int,int> #define pll pair<ll,ll> #define PB push_back #define fi first #define se second #define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++) #define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--) #define CLR...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k = 0; cin >> n >> m; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { if (i * i + j == n && j * j + i == m) k++; } } cout << k; }
1
#include <bits/stdc++.h> using namespace std; int sub(int n) { int max = 0; while (n != 0) { int x = n % 10; if (x > max) max = x; n /= 10; } return max; } int main() { int m; while (scanf("%d", &m) != EOF) { int nlen = 0; while (m != 0) { m = m - sub(m); nlen++; } co...
3
#include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<vector> #include<map> using namespace std; #define INF (1 << 30) typedef pair<int, int> P; int s, d, m; vector<P> snack[1080]; int w, p, k; int dp[10800]; int f; int main(){ while(~scanf("%d%d%d", &s, &d, &m)){ int res = 0;...
0