solution
stringlengths
52
181k
difficulty
int64
0
6
#include<iostream> #define C std::cin>> int main(){int n,c=0,j,l[100];C n>>l[0];for(j=1;j<n;j++)C l[j],l[j-1]==l[j]?c++,l[j]=0:0;std::cout<<c<<"\n";}
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10, mod = 1e9 + 7; char s[maxn], t[maxn]; int bita[maxn], bitb[maxn], ans[maxn], pa[maxn], pb[maxn]; int lowbit(int x) { return x & -x; } void update(int b[], int v, int val, int up) { while (v <= up) { b[v] += val; v += lowbit(v); } } int...
4
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979; const double PI2 = 6.28318530717958; const double PId2 = 1.570796326794895; template <typename T> T sqr(T x) { return x * x; } template <typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); } long long pw(long long a, long lo...
2
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b) { long long r; while (b) { r = a % b; a = b...
5
#include <iostream> using namespace std; #define ll long long int main(){ int n,x,y; cin>>n; ll s=0; int a[n+1]; for(int i=0;i<=n;i++){ cin>>a[i]; } for(int i=0;i<n;i++){ cin>>x; y=min(x,a[i]); s+=y; x-=y; y=min(x,a[i+1]); s+=y; a[i+1]-=y; } cout<<s<<"\n"; }
0
#include <bits/stdc++.h> using namespace std; vector<int> primes; void primegen(int ub) { bool w[1001] = {false}; for (int p = 2; p <= ub; p++) if (!w[p]) { for (int i = p; i <= ub; i += p) w[i] = true; primes.push_back(p); } } int main() { string s; cin >> s; int len = int((s).size()); ...
3
#include<iostream> #include<cstdio> #include<algorithm> typedef long long ll; const int N=1e5+5,INF=1e9+7; int n,m,par[N],id[N],a[N]; void init(){ for(int i=0;i<n;i++) par[i]=i,id[i]=i; } int fd(int x) { return par[x]==x?x:par[x]=fd(par[x]); } int main() { scanf("%d%d",&n,&m); for(int i=0;i<n;i++) scanf...
0
#include <bits/stdc++.h> using namespace std; int n, m; int main() { cin >> n >> m; int a = n / m; int b = n % m; for (int i = 1; i <= m; ++i) { if (b > 0) { cout << a + 1 << " "; b--; continue; } cout << a << " "; } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int maxn = 105; const int mod = 1e9 + 7; int n, m, k, ans; int dp[maxn][maxn][maxn], ndp[maxn][maxn][maxn], binom[maxn][maxn]; void Add(int &a, int b) { a += b; if (a >= mod) a -= mod; } int main() { scanf("%d%d%d", &n, &m, &k); binom[0][0] = 1; for (int i =...
5
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(0); int w,h,n;cin>>w>>h>>n; int x1=0,x2=w,y1=0,y2=h; for(int i=0;i<n;i++) { int x,y,a;cin>>x>>y>>a; if(a==1)x1=max(x1,x); if(a==2)x2=min(x2,x); if(a==3)y1=max(y1,y); ...
0
#include <bits/stdc++.h> using namespace std; const int MaxN = 1005; int cnt[30], n; char s[MaxN]; bool bio[MaxN]; void add(int p) { for (int i = p; i <= n; i += p) bio[i] = true; } int main() { scanf("%s", s + 1); n = strlen(s + 1); if (n <= 2) { puts("YES"); puts(s + 1); return 0; } for (int i...
3
#include <bits/stdc++.h> using namespace std; int compareAscending(const void *a, const void *b) { return (*(int *)a - *(int *)b); } int compareDecending(const void *a, const void *b) { return (*(int *)b - *(int *)a); } int compareFirst(const void *a, const void *b) { if (((pair<int, int> *)a)->first == ((pair<in...
1
#include <bits/stdc++.h> using namespace std; int pre[100005][20], suf[100005][20], mn[100005][20]; int a[100005], lg[100005], n, ans; int getmn(int x, int y) { if (x > y) return 1e9; int k = lg[y - x + 1]; return min(mn[x][k], mn[y - (1 << k) + 1][k]); } int getmn1(int x, int y) { if (x > y) return 1e9; int ...
5
#include <bits/stdc++.h> using namespace std; vector<long long int> v[1000007]; vector<long long int> vv[2]; map<long long int, long long int> mp; long long int a[1000007]; int aa[2]; int vis[1000007]; long long int dfs(int pos, int id) { vis[pos] = 1; int i; long long int ans = 0; int lt = 0; for (i = 0; i <...
5
#include <bits/stdc++.h> using namespace std; inline bool isvowel(char c) { c = tolower(c); if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1; return 0; } const double eps = 0.000001; const long double pi = acos(-1); const int maxn = 1e7 + 9; const int mod = 1e9 + 7; const lon...
5
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define MOD2 1000000007 #define MOD 998244353 #define PRIM 3 #define INF (1 << 29) #d...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 52; int Nextint() { char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); int x = 0; while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x; } int A[maxn][maxn], S[maxn], N, lt, B[maxn][maxn], C[ma...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5, inf = 1e9 + 7; const long double eps = 1e-12; const long long linf = (long long)1e18 + 7, mod = 1e14; int main() { string s; cin >> s; long long n = (int)(s).size(), ans = 0; for (int i = 0; i < n; i++) { stack<char> st; long long cnt ...
3
#include <bits/stdc++.h> using namespace std; struct Tar { int x, y, t; double p; void read() { scanf("%d%d%d%lf", &x, &y, &t, &p); } } r[1010]; bool cmp(Tar a, Tar b) { return a.t < b.t; } double dis(double x, double y) { return sqrt(x * x + y * y); } bool good(int a, int b) { return dis(r[a].x - r[b].x, r[a]....
3
#include <bits/stdc++.h> using namespace std; long long b[7]; const long long M = 6 * 1e5 + 7; struct data1 { long long x; long long val; }; data1 a[M]; bool cmp(data1 u, data1 v) { return (u.x < v.x) || (u.x == v.x && u.val < v.val); } int main() { for (long long i = 1; i <= 6; i++) { cin >> b[i]; } lo...
3
#include <bits/stdc++.h> using namespace std; int n, d, a[100005], b[100005], idx[100005]; long long x; int s = 30; vector<int> ones; long long getNextX() { x = (x * 37 + 10007) % 1000000007; return x; } void initAB() { int i; for (i = 0; i < n; i = i + 1) { a[i] = i + 1; } for (i = 0; i < n; i = i + 1)...
4
#include<bits/stdc++.h> #define INF 0x3f3f3f3f #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef pair<int, int>P; int c[6], cost[110][1 << 6], m, n, k, d; struct st { int a, b, c; }; int num(string s) { if (s == "H")return m + n; if (s == "D")return m + n + 1; if (s[0] == 'C')return s[1] - '1'; ...
0
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long binpow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; } int main() { long long m, n; cin >> n >> m; cout << binp...
2
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c = 1000; for (cin >> a >> b; cin >> a; b = a) if (a > b) c += c / b * (a - b); cout << c; }
0
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> three(N); vector<int> four(N); for (int i = 0; i < N; i++) { cin >> three[i]; } for (int i = 0; i < N; i++) { cin >> four[i]; } vector<int> revind_t(N + 1); vector<int> revind_f(N + 1); for (int i = 0; ...
6
#include <bits/stdc++.h> using namespace std; const int N = 2005; int n, m; int f[N][N], to[N]; char s[N], p[N]; int main() { scanf("%s%s", s + 1, p + 1); n = strlen(s + 1), m = strlen(p + 1); for (int i = 1; i <= n; i++) { to[i] = n + 2; int k = 1; for (int j = i; j <= n; j++) { if (s[j] == p[k...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 2; vector<int> g[N]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } for (int i = 1; i <= n; ++i) sort(g[i].begin(), g[i].end()); vector<int>...
2
#include<bits/stdc++.h> using namespace std; #define Uni All right #define REP(i,a,b) for(int i=(a),i##_end_=(b);i<i##_end_;++i) #define DREP(i,a,b) for(int i=(a),i##_end_=(b);i>i##_end_;--i) #define LREP(i,a) for(int i=Head[a];i;i=Next[i]) #define LL long long #define Mod 1000000007 static const int M=(1<<17)+4; in...
0
#include <bits/stdc++.h> using namespace std; inline long long mulmod(long long x, long long n, long long _mod) { long long res = 0; while (n) { if (n & 1) res = (res + x) % _mod; x = (x + x) % _mod; n >>= 1; } return res; } inline long long powmod(long long x, long long n, long long _mod) { long ...
3
#include <bits/stdc++.h> using namespace std; const long long int cons = 100005; const long long int MOD1 = 1000000007; const long long int MOD2 = 998244353; const long long int const_INT_MAX = 100000000000000000; const long long int const_INT_MIN = -1 * 100000000000000000; int main() { ios_base::sync_with_stdio(fals...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1123456; char s[maxn], t[maxn]; int dp[maxn][8]; long long ans; int main() { scanf("%s%s", s, t); int n = strlen(s), m = strlen(t); for (int(i) = (0); (i) <= ((n)-1); (i)++) s[i] %= 3; for (int(i) = (0); (i) <= ((m)-1); (i)++) t[i] %= 3; for (int(...
4
#include <bits/stdc++.h> using namespace std; struct node { long long start; long long end; long long count; }; node arr[1000010]; long long ans[1000010]; long long maxi = -1; long long mini = 10000000; int main() { for (long long i = 1; i <= 1000000; i++) arr[i].count = 0; long long n; cin >> n; for (lon...
2
#include<iostream> #include<algorithm> #include<vector> using namespace std; int main(){ int d,n,m,ans,In; vector<int> vec; while(cin >> d && d){ ans = 0; vec.clear(); vec.push_back(0); cin >> n >> m; for(int i=0;i<n-1;i++){ cin >> In; vec.push_back(In); } vec.push_back(...
0
#include <bits/stdc++.h> using namespace std; const int Maxn = 500005; int n, m, q, a[Maxn], cnt[Maxn], ct, out[Maxn], tot, rk[Maxn]; long long tmp[Maxn], now[Maxn], all; vector<int> Ve[Maxn]; struct quest { int id; long long x; bool operator<(const quest& tmp) const { return x < tmp.x; } } Q[Maxn]; struct node {...
4
#include <bits/stdc++.h> using namespace std; vector<long long> g; long long a[300100]; long long now, tmp, k; int b, l, i, j, ans, n; int main() { cin >> n >> k; for (i = 0; i <= n; i++) { scanf("%d", &b); a[i] = b; g.push_back(a[i]); } for (i = 0; i < g.size(); i++) { tmp = g[i]; if (abs(t...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; bool a[256] = {}; string s; cin >> n; cin >> s; int sl = s.length(); int t = 0; for (int i = 0; i < sl; i++) { t += a[s[i]] == false; a[s[i]] = true; } if (t >= n) { cout << "YES\n"; bool first = true; for (int i =...
1
#include <bits/stdc++.h> using namespace std; int main() { int b = 0, c = 0; string a; cin >> a; for (int i = 0; i < a.size(); i++) { if (a[i] != a[a.size() - 1 - i]) b++; } if (b == 0) { for (int i = 0; i < a.size(); i++) { if (a[i] == 'A') c++; else if (a[i] == 'H') c++...
2
#include <bits/stdc++.h> using namespace std; int ON(int N, int pos) { return N = N | (1 << pos); } int OFF(int N, int pos) { return N = N & ~(1 << pos); } bool isON(int N, int pos) { return (bool)(N & (1 << pos)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int tc, cs; int i, j, k; int n; whil...
1
#include "bits/stdc++.h" using namespace std; using VS = vector<string>; using LL = long long; using VI = vector<int>; using VVI = vector<VI>; using PII = pair<int, int>; using PLL = pair<LL, LL>; using VL = vector<LL>; using VVL = vector<VL>; #define ALL(a) begin((a)),end((a)) #define RALL(a) (a)....
0
#include <bits/stdc++.h> using namespace std; class Solution { public: void solve(std::istream& in, std::ostream& out) { int n; in >> n; std::vector<int> known; std::vector<string> s(n); std::vector<int> info; int target_size = 0; for (int i = 0; i < n; ++i) { std::string t; i...
3
#include <cstdio> int main() { int a,b; scanf("%d %d", &a, &b); printf("%d", a * a - b); }
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") using namespace std; bool is_prime(long long n) { for (long long i = 2; i * i <= n; ++i) { if (n % i == 0) { return false; } } return true; } vector<long long> fact(long long n) { v...
4
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = 1e9; const long long ninf = LLONG_MIN; const double eps = 1e-12; const long long N = 1000005; const long long LOGN = 19; const double PI = 3.14159265358979323846; long long n, m; long long d[505][505], is[505][505], in...
5
#include <bits/stdc++.h> using namespace std; int a[123456], b[123456], c[123456]; int main(void) { int n; scanf("%d", &n); int cnt = 99999999; int ans = 0; for (int i = 0; i < n; i++) { scanf("%d%d", &a[i], &b[i]); cnt = min(cnt, b[i]); ans += a[i] * cnt; } printf("%d\n", ans); return 0; }
1
#include <bits/stdc++.h> int poss(char ch) { if (ch == '3' || ch == '4') return 3; if (ch == '0' || ch == '6' || ch == '9' || ch == '2') return 2; if (ch == '1') return 7; if (ch == '5') return 4; if (ch == '8') return 1; if (ch == '7') return 5; } int main() { char str[3]; gets(str); printf("%d\n", p...
1
#include <iostream> #include <cstdio> using namespace std; int main(){ int price,num,sump=0,sum=0,i=0; double ave; while(scanf("%d,%d",&price,&num)!=EOF){ sump += price*num; sum += num; i++; } ave = sum/(double)i; ave += 0.5; cout<<sump<<endl<<(int)ave<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 3e3 + 5, inf = 2e9, mod = 1e9 + 7; vector<int> prime_Numbers; bool primes[1000005]; double dot(complex<double> a, complex<double> b) { return (conj(a) * b).real(); } double cross(complex<double> a, complex<double> b) { return (conj(a) * b).imag(); } int ma...
4
#include <stdio.h> #include <algorithm> using namespace std; int main() { int a, b; bool first = true; while (scanf("%d %d", &a, &b), a|b) { if (!first) { puts(""); } first = false; if (a > b) { swap(a, b); } bool output = false; for (int i = a; i <= b; i++) { if (i % 400 == 0 || (i % 1...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int d, h, v, e; cin >> d >> h >> v >> e; double vw = (double)v / (3.14159265359L * d * d / 4); vw -= (double)e; double ret = double(h) / (vw); if (ret >= 0) { cout << "YES\n"; cout << ret; } else cout <<...
1
#include <bits/stdc++.h> using namespace std; int max(int a, int b, int c) { int x = c + b, y = a + c, z = a + b; if (x <= y && x <= z) cout << x << endl; else if (z <= y && x >= z) cout << z << endl; else if (x >= y && y <= z) cout << y << endl; return 0; } int main() { int n, a = 0, b = 0, c =...
1
#include<iostream> #include<map> using namespace std; map<char,char> go,back; string S,T; int main () { cin >> S >> T; bool flag = true; for(int i=0; i<S.size(); i++) { if(go[S[i]] && go[S[i]] != T[i]) flag = false; if(back[T[i]] && back[T[i]] != S[i]) flag = false; go[S[i]] = T[i]...
0
#include <bits/stdc++.h> using namespace std; int n, q; int a[1005], d[1005], mark[1005]; vector<int> v[1005]; void solve() { int i, x, y, da, vt, ln, maxx, gt; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 1; i <= q; i++) { cin >> x >> y; d[x] += a[y]; d[y] += a[x]; v[x].push_back(y); ...
3
#include <bits/stdc++.h> using namespace std; char in[200005]; long long bignum[212345], l; long long bigmod(long long c) { long long ret = 0; for (long long i = l; i >= 1; i--) { ret *= 10; ret += bignum[i]; ret %= c; } return ret; } signed main() { std::ios::sync_with_stdio(false); cin.tie(0);...
5
#include <iostream> #include <complex> #include <sstream> #include <string> #include <algorithm> #include <deque> #include <list> #include <map> #include <numeric> #include <queue> #include <vector> #include <set> #include <limits> #include <cstdio> #include <cctype> #include <cmath> #include <cstring> #include <cstdli...
0
#include <bits/stdc++.h> using namespace std; double dp[101][101010]; int main() { int a, b; cin >> a >> b; if (b == 1) { cout << 1 << endl; return 0; } vector<int> ms; for (int i = 0; i < a; ++i) { int s; cin >> s; ms.push_back(s); } int msum = accumulate(ms.begin(), ms.end(), 0); ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n, x, y, i, ans = 0; cin >> n >> x >> y; string s; cin >> s; reverse(s.begin(), s.end()); for (i = 0; i < x; ++i) ans += s[i] == (i == y ? '0' : '1'); cout << ans; return 0; }
1
#include <cstdio> #include <iostream> #include <vector> #include <list> #include <cmath> #include <fstream> #include <algorithm> #include <string> #include <queue> #include <set> #include <map> #include <complex> #include <iterator> #include <cstdlib> #include <cstring> #include <sstream> #include <stack> using namesp...
0
#include <cstdio> #define MAXN 14 int main(void) { long long i,c0,c1,c2,N,m[5]={0}; long long s; char name[MAXN]; const char sign[7]="MARCH"; scanf("%lld",&N); for(i=0;i<N;i++) { scanf("%s",name); for(int j=0;j<5;j++) if(name[0]==sign[j]) m[j]++; } s=0; for(c0=0;c0<5;c0++) for(c1=c0+1;c1<5;c1++...
0
#include <bits/stdc++.h> using namespace std; int a[111], b[111], n, m; int gcd(int a, int b) { if (a < b) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } int main() { while (~scanf("%d%d", &n, &m)) { n += 1; m += 1; for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < m...
2
#include <bits/stdc++.h> using namespace std; const int mxn = 1e5 + 5; const int mod = 1e9 + 7; const int mod1 = 998244353; int main() { ios_base::sync_with_stdio(false); string s, t, x; cin >> s >> t; int n = s.size(), m = t.size(), i; x = t + "#" + s; vector<bool> v(n); vector<int> pi(x.size()); for (...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int arr[n]; for (long long int i = 0; i < n; i++) { cin >> arr[i]; } set<long long int> s; for (long long int i = 0; i < n; i++) { if (arr[i] == 0) { continue; } s.insert(arr[i]); } co...
1
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int sum = 7; for(int i = 1; i<=n; i++){ if(sum%n==0){ cout<<i; return 0; } else sum = (sum*10+7)%n; } cout<<-1; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t = 1; while (t--) { int n; cin >> n; vector<long long int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<long long int> turn = a; for (int i = 0; i < n; i++) turn[i]--; for (int i = 1; i < n; i++) turn[i] = turn[i - ...
2
#include <bits/stdc++.h> using namespace std; int compare(const void *a, const void *b) { if (*(int *)a > *(int *)b) return -1; if (*(int *)a < *(int *)b) return 1; return 0; } int main() { int x = 1; int n, m, *d, *a, l, i, j, *con, up, down, flag, niz, prev; cin >> n >> m; d = new int[n]; for (i = 0; ...
4
#include <bits/stdc++.h> using namespace std; int tree[800001]; pair<int, int> arr[200001]; void build(int node, int start, int end) { if (start == end) { tree[node] = 1; } else { int mid; mid = (start + end) / 2; build(2 * node, start, mid); build(2 * node + 1, mid + 1, end); tree[node] = t...
4
#include <bits/stdc++.h> using namespace std; int x[10001], y[10001], z[10001]; int main() { int n; int x0, y0, z0, x1, y1, z1; scanf("%d", &n); for (int i = 0; i <= n; i++) scanf("%d %d %d", &x[i], &y[i], &z[i]); int vs, vp; int px, py, pz; scanf("%d %d", &vp, &vs); scanf("%d %d %d", &px, &py, &pz); ...
3
#include <bits/stdc++.h> using namespace std; struct nodo { string t; int l, r; }; int N; nodo a[2000005]; int ori[2000005]; int ans[2000005]; void llena(int x, int v) { if (!x) return; if (a[x].t == "IN") { ans[x] = v; return; } llena(a[x].l, v); llena(a[x].r, v); } void dfs2(int x, int v) { if...
4
#include <bits/stdc++.h> using namespace std; inline int gcd(int x, int y) { if (x % y == 0) return y; else return gcd(y, x % y); } int main() { int n, k, g; cin >> n >> k >> g; int maxi = g; n--; while (n--) { int a; cin >> a; g = gcd(g, a); maxi = max(maxi, a); } cout << ((k % g == 0 && k <= maxi) ? "...
0
#include <iostream> #include <vector> #include <set> using namespace std; int n, m; vector<pair<int, int> > target; set<pair<int, int> > stars; bool containsAll(int dx, int dy) { for (int i = 0; i < m; i++) { pair<int, int>& p = target[i]; if (stars.find(make_pair(p.first + dx, p.second + dy)) == stars.end()) { ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, n, aux, sq; int x; scanf("%d", &x); n = x; long long menor = 999999999999999LL, maior = 0; long long ate = sqrt(n) + 1; for (a = 1; a <= ate; a++) { if (n % a != 0) continue; sq = sqrt(n / a) + 1; for (b = 1; b <= sq...
3
#include <cstdio> #define max(a,b) ((a>b)?a:b) using namespace std; int ops[]={1,-1}; char sop[]={'+','-'},N[4]; bool add(int op){ int num=N[0]-'0'; for(int i=0;i<3;i++){ num+=(N[i+1]-'0')*ops[op%2]; op/=2; } return num==7; } void print(int op){ for(int i=0;i<3;i++){ printf("%c%c",N[i],sop[op%2]); op/=2; ...
0
#include <iostream> using namespace std; int main() { int k; while(cin >> k, k) { int sum; sum = 0; for(int i = 0; i < k*(k-1)/2; i++) { int a; cin >> a; sum += a; } cout << sum / (k-1) << endl; } }
0
#include <cstdio> #include <cstring> const int N=500010; char c[N]; int q,l,r,f[N][30],d[N][25],n,j,h,i; int main(){ scanf("%s",c+1); n=strlen(c+1); for(i=1;i<=n;++i)f[i][c[i]-'a']=i; for(i=n;i;--i){ for(j=c[i]+1-'a';j<=26;++j){ if(f[i][j-1])f[i][j]=f[f[i][j-1]+1][j-1]; //printf("f[%d][%d]=%d\n",i,j,f[i][...
0
#include <bits/stdc++.h> using namespace std; int main() { vector<int> x(4); cin >> x[0] >> x[1] >> x[2] >> x[3]; if (x[1] - x[0] == x[2] - x[1] && x[3] - x[2] == x[2] - x[1]) { cout << x[3] + (x[1] - x[0]); return 0; } double r = double(x[1]) / double(x[0]); if (r == double(double(x[2]) / double(x[...
1
#include <bits/stdc++.h> using namespace std; struct indexed_tree { private: int N; std::vector<long long int> tree; void update_tree(int x, long long int cnt, long long int f(long long int, long long int)) { if (x == 0) return; tree[x] = f(tree[x], cnt); update_tree(x >> 1, cnt, f...
6
#include <bits/stdc++.h> using namespace std; #define PI 4*atan(1) #define INF 1e8 int dx[4] = {1,0,-1,0}; int dy[4] = {0,1,0,-1}; int main(){ int N, A, B, C, X; while(cin >> N >> A >> B >> C >> X, N||A||B||C||X){ vector<int> Y(N); for(int i = 0; i < N; i++){ cin >> Y[i]; } int x = X, index...
0
#include <bits/stdc++.h> using namespace std; signed main(signed argc, const char *argv[]) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; string ans(n, '0'); vector<pair<long long, long long>> ab(n); map<pair<long long, lon...
3
#include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; const int N=200005; const int INF=1061109567; int n; int p[N],q[N]; int ida[N],cnta; int idb[N],cntb; struct Edge { int to,flow; int next; }edge[N<<1]; int head[N],cnt=1; void add_edge(int u,int v,int flow) { cnt++; edge[cnt]...
0
#include <bits/stdc++.h> using namespace std; int n, L[400010], R[400010], D[400010], Head[400010], Next[400010], Go[400010], Cnt = 0; double Val[400010], O[400010]; vector<int> big[400010]; void addedge(int x, int y) { Go[++Cnt] = y; Next[Cnt] = Head[x]; Head[x] = Cnt; } int main() { scanf("%d", &n); for...
4
#include <bits/stdc++.h> using namespace std; const int N = 22; char ss[N][N]; int n, m; int check(int x, int y) { if (x < 0 || y < 0 || x >= n || y >= m) return 0; return 1; } int mp[N * 3][N * 3][N * 3][N * 3], ed = 20; int que(int x1, int x2, int y1, int y2) { return mp[x1][x2][y1][y2]; } void up(int x1, int x2,...
4
#include <cstdio> const int N=41; int a[N],mx=-1,t; long long n; int main(){ scanf("%lld",&n); for(int i=40;~i;--i) if((n>>i)&1) if(~mx)a[i]=mx+(++t); else mx=i; printf("%d\n",mx+mx+2+t+t); if(a[0])printf("%d ",a[0]); for(int i=1;i<=mx;++i){ printf("%d ",i); if(a[i])printf("%d ",a[i]); } for(int i=...
0
#include <bits/stdc++.h> using namespace std; int n, pre[1000001]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) pre[i] = i ^ pre[i - 1]; int res = 0; for (int i = n; i > 0; --i) if ((n - i) % 2) res ^= i; for (int i = 1; i <= n; ++i) { if ((n - i) / i % 2) res ^= pre[i - 1]; res ^= p...
3
#include <bits/stdc++.h> using namespace std; int n, m; int main() { while (cin >> n >> m) { int tt = min(n + 1, m + 1); cout << tt << endl; for (int i = 0; i < tt; ++i, --m) { cout << i << " " << m << endl; } } return 0; }
3
#include <bits/stdc++.h> using namespace std; const int N = 2e2 + 10; int t, n, a[N], ans[N]; void solve() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { int k = i, t = a[i], cnt = 0; while (t - 1 != i) { cnt++; k = t - 1; t = a[k]; } ans[i] = ...
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const int maxn = 110; int main() { int n, d; int a[maxn], x[maxn], y[maxn]; int dist[maxn][maxn], cost[maxn][maxn]; scanf("%d%d", &n, &d); a[1] = a[n] = 0; for (int i = 2; i < n; i++) scanf("%d", &a[i]); ...
4
#include <bits/stdc++.h> using namespace std; int arr[101][101]; int main() { int n; cin >> n; int plus = 0; int minus = 0; for (int i = 0; i < n; i++) { int x; int y; cin >> x; cin >> y; if (x > 0) plus++; else minus++; if (plus > 1 && minus > 1) { cout << "No"; ...
1
#include <bits/stdc++.h> using namespace std; bool cmpa(pair<int, int>& a, pair<int, int>& b) { return a.first < b.first; } bool cmpd(pair<int, int>& a, pair<int, int>& b) { return a.first > b.first; } const int T = 1005; int main() { ios::sync_with_stdio(false); int n; cin >> n; vector<vector<pair<int, int>>> ...
5
#include <bits/stdc++.h> using namespace std; set<string> Set; int main() { string s; cin >> s; int n = s.size(); for (int i = 0; i < n; i++) { s = s.substr(1, n - 1) + s.substr(0, 1); Set.insert(s); } printf("%d\n", Set.size()); return 0; }
1
#include <bits/stdc++.h> using namespace std; vector<int> a; vector<int> b; set<int> c; int n, m; pair<int, int> dichSeach(int e) { int i = lower_bound(a.begin(), a.end(), e) - a.begin(); int p = lower_bound(b.begin(), b.end(), e) - b.begin(); return make_pair((n - i) * 3 + i * 2, p * 2 + (m - p) * 3); } int main...
3
#include <iostream> #include <string> #include <queue> using namespace std; struct cha{ string name; queue<int> q; int toku; }; int main() { int n; while (cin >> n) { if (n == 0) { break; } int d[30]; for (int i = 0; i < 30; i++) { d[i] = n+1; } cha c[20]; int a, b; for (int i = 0; i < n; ...
0
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') f = -1, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return f * x; } const int maxn = 2e5 + 7; con...
5
#include <bits/stdc++.h> using namespace std; long long a[505][505]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf("%lld", &a[i][j]); } } if (n == 1) { printf("1\n"); return 0; } int fg = 0; long long sm = 0; for (int i = 0...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; const int mod = 998244353; const int maxn = 2e5 + 10; struct edge { int st, ed; int w; bool operator<(const edge &b) const { return w < b.w; } edge() {} edge(int st, int ed, int w) :...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int k; string s; cin >> k >> s; int n = s.size(); set<char> se; for (char c = 'a'; c < char('a' + k); c++) se.insert(c); bool flag = true; vector<int> a; for (int i = 0; i < n / 2; i++) {...
3
#include <bits/stdc++.h> struct node { int v, len; node *next; } * head[10100], tree[10100]; int n, m, dp[10100][2], cnt; int high, low, mid, len; int ptr, vis[10100], ans, num[10100]; void Initial() { ans = 10000001, len = 0, ptr = 1; memset(head, NULL, sizeof(head)); } void AddEdge(int a, int b) { tree[ptr]...
5
#include <bits/stdc++.h> bool dfs_topo(std::vector<std::vector<int> > &adjacent, std::vector<int> &des, int node, std::list<int> &topo_sort) { des[node] = 0; for (int x : adjacent[node]) { if (des[x] == 0) return false; else if (des[x] == -1) { dfs_topo(adjacent, des, x, topo_sort)...
3
#include <bits/stdc++.h> using namespace std; int n, m, s, t; vector<int> g[1005]; int dis_s[1005], dis_t[1005]; bool vis[1005]; bool adj[1005][1005]; void bfs(int v, int dis[]) { queue<int> q; vis[v] = 1; dis[v] = 0; q.push(v); while (q.size()) { v = q.front(); q.pop(); for (int u : g[v]) { ...
4
#include <bits/stdc++.h> using namespace std; int main() { long n; cin >> n; long a[n]; for (long i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); a[n - 1] = (a[n - 1] == 1) ? 2 : 1; sort(a, a + n); for (long i = 0; i < n; i++) cout << a[i] << " "; }
1
#include <bits/stdc++.h> using namespace std; template <class T> inline T sqr(const T &a) { return a * a; } template <class T> inline int len(const T &c) { return static_cast<int>(c.size()); } template <class T> inline bool maximize(T &r, const T c) { if (r < c) { r = c; return true; } return false; }...
3
#include <bits/stdc++.h> using namespace std; char arr[150] = {'a'}; int main() { int n; scanf("%d", &n); int a = 0, b = 0, c = 0, d = 0, k = 0, count = 0; scanf("%s", arr); while (k < n) { if (arr[k] == 'L') a += 1; else if (arr[k] == 'R') b += 1; else if (arr[k] == 'U') c += 1;...
2