solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e, f; scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f); if (d == 0) puts("Hermione"); else if (c == 0) puts("Ron"); else if (b == 0) puts("Hermione"); else if (a == 0) puts("Ron"); else if (f == 0) puts("Hermi...
1
#include<bits/stdc++.h> using namespace std; int main(){ string s,t; cin>>s; cin>>t; string p = s + s; if (p.find(t) != std::string::npos) { std::cout << "Yes" << '\n'; } else{ cout<<"No"<<endl; } }
0
//If you can dream it, you can do it! //author@nowadays - 2021-07-13 11:01:41 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; vector<map<char, int>> a(...
2
#include<iostream> using namespace std; int main() { int n,S; for(;cin>>n>>S,n;) { int power[n]; for(int i=0;i<n;i++) { cin>>power[i]; } int count=0; for(int i=0;i<n-1;i++) { for(int j=i+1;j<n;j++) { if(power[i]+power[j]>S) count++; } } cout<<c...
0
#include <bits/stdc++.h> int main() { int a; scanf("%d", &a), printf("%d\n", a & 1); }
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; int n = t / 2; unsigned long long ans = 1, d; d = t * n; for (int i = 1; i <= t; i++) ans *= i; ans = ans / d; cout << ans << endl; }
5
#include <bits/stdc++.h> using namespace std; bool visited[100]; int main() { long long r; cin >> r; for (long long i = 1; i * i < r; i++) { long long ec = (r - (i * i) - i - 1); if (ec % (2 * i) == 0 && ec > 0) { cout << i << " " << ec / (2 * i); return 0; } } cout << "NO"; }
1
#include <bits/stdc++.h> bool debug = 1; const double PI = acos(-1.0); const double eps = 1e-9; using namespace std; int ordem[30]; int v[30]; int v2[30]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> v[i]; v2[i] = v[i]; } sort(v2, v2 + n); for (int i = 0; i < n; i++) { for ...
2
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 100; const long long M = 1e6 + 10; struct node { long long id, l, r; node() { id = l = r = 0; }; node(long long L, long long R, long long I) { l = L; r = R; id = I; } } t[N * 4]; long long read() { long long ivy; scanf("%lld...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<char>> a(n, vector<char>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cin >> a[i][j]; } bool flag = false; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { b...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long ans = n; for (int k = n - 1; k > 0; k--) ans += (n + 1 - k) * k - (n - k); cout << ans << '\n'; }
2
#include <bits/stdc++.h> using namespace std; int x; int main() { scanf("%d", &x); printf("%d", x % 5 % 3 + 1); return 0; }
4
#include <bits/stdc++.h> using namespace std; bool hash[1000]; int n, m, last = -1; char k, f; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> k; if (last == k) { cout << "NO" << endl; return 0; } for (int j = 1; j < m; j++) { cin >> f; if (f != k) { ...
1
#include<iostream> using namespace std; int main(void) { int n; cin >> n; cout << (n<1200 ? "ABC" : (n<2800 ? "ARC" : "AGC")) << endl; }
0
#include<iostream> using namespace std; const int maxn = 3e5 + 50; int N, p[maxn]; bool check(int l, int r) { for (int i = l; i <= r; ++i) { if (p[i]<l || p[i]>r) { return false; } } int L = -1, R = -1; for (int i = l; i <= r; i += 2) { if (p[i] < i) { if (L > p[i]) return false; L = p[i]; } e...
0
#include <bits/stdc++.h> #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--) #define REP(i,n) for(int i=0;i<(n);i++) #define RREP(i,n) for(int i=n-1;i>=0;i--) #define PB push_back #define MP make_pair #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend()...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int a[maxn]; char S[maxn][10]; vector<int> F1, F2, F3, G1, G2, G3; bool p[maxn]; int f[maxn]; int main() { int n; scanf("%d", &n); int e = 0; for (int t = 1; t <= n; ++t) { scanf("%s%d", S[t], &a[t]); if (a[t]) ++e; int len = str...
3
#include <bits/stdc++.h> using namespace std; unsigned long long mod = 1000000007; int main() { int commands, inp; cin >> commands; vector<pair<int, int> > values; for (int command = 1; command <= commands; command++) { cin >> inp; if (inp == 0) { vector<pair<int, int> > now = values; sort((...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n], x; for (x = 0; x < n; x++) cin >> a[x]; sort(a, a + n); for (x = n - 1; x >= 0; x--) cout << a[x] << " "; cout << endl; } }
2
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int prev = -1; int pprev = -1; int cnt = 0; for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); if ((prev == 3 && x == 2) || (prev == 2 && x == 3)) { printf("Infinite\n"); return 0; } if ((p...
1
#include <bits/stdc++.h> using namespace std; int n,m; bool yes[10]; int dp[10004],ans[10004],sz[10004]; int num[10]={0,2,5,5,4,5,6,3,7,6}; int main(){ memset (ans,-1,sizeof(ans)); cin>>n>>m; for (int i=0;i<m;i++){ int a;cin>>a; yes[a]=1; } ans[0]=0; for (int i=1;i<=n;i++) for (int j=9;j>=1;j--) if (i-num[j...
0
#include "iostream" #include "climits" #include "list" #include "queue" #include "vector" #include "string" #include "map" #include "unordered_map" #include "algorithm" #include "functional" #include "set" using namespace std; const long long int MOD = 1000000007; long long int N, M, K, H, W, L, R; struct Edge{ in...
0
#include <bits/stdc++.h> using namespace std; int main(){ int n,c=0,a; cin>>n; for(int i=0;i<n;i++){ cin>>a; if(a%2==0){ if(a==2) c++; continue; } int j=sqrt(a)+1; if(j%2==0) j--; while(j>=3){ if(a%j==0) goto f; j=j-2; } c++; f:; } cout<<c<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const double eps = 1e-8; const double pi = acos(-1.0); int n, m; char a[110], b[110], c[110]; int d[26]; int main() { srand(time(NULL)); scanf("%d%d%s%s", &n, &m, a, b); int la = strlen(a), lb = strlen(b); int flag = 1; for (int i = 0; i <...
4
#include <bits/stdc++.h> using namespace std; int dist[2 * 100000 + 2 + 5], N, K; vector<int> G[2 * 100000 + 2 + 5]; void addedge(const string &wall, const string &wall2, int i, int offs) { int here = i + offs, there = i + N - offs; if (wall[i] == 'X') return; if (i != 0 && wall[i - 1] != 'X') G[here].push_back(h...
4
#include <iostream> #include <algorithm> #include <cstring> using namespace std; typedef long long ll; const int mod=1000000007; int N,W; int w[201]; ll dp[2][10001][202]; int main(){ cin>>N>>W; for(int i=0;i<N;i++)cin>>w[i]; for(int j=0;j<=W;j++){ for(int k=0;k<=N;k++){ if(j<=W&&(k==N||w[k]+j>W))dp[N%2][j]...
0
#include <bits/stdc++.h> using namespace std; const int z = 998244353; void zf(string &s, int z[]) { z[0] = s.length(); int l = 0, r = 0; for (int i = 1; i < s.length(); i++) { if (i >= r) { l = r = i; while (r < s.length() && s[r - l] == s[r]) { r++; } z[i] = r - l; } else...
5
#include <iostream> using namespace std; int main(){ int n,a,b; cin >>n>>a>>b; cout <<min(a*n,b); }
0
#include <bits/stdc++.h> using namespace std; int n, b[5010]; long long tr[5010]; int gx1[5010][5010], gx2[5010][5010]; inline int lowbit(int x) { return (x & (-x)); } void xg(int x, int k) { for (int i = x; i <= n + 1; i += lowbit(i)) { tr[i] += k; } } long long getsum(int x) { long long res = 0; for (int ...
3
#include <bits/stdc++.h> using namespace std; const int N = 305; int n, m, i, j, k; deque<char> a[N]; string s; vector<pair<pair<int, int>, pair<int, int> > > ans, s1, s2; inline void wk(vector<pair<pair<int, int>, pair<int, int> > >& v, bool fl) { static int b[N], c[N]; memset(b, 0, sizeof b); memset(c, 0, sizeo...
5
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 7; const int M = 59; const int mid = M / 2; const int mod = 1e9 + 9; const int inf = 1e9 + 7; const long long linf = 1ll * inf * inf; const double pi = acos(-1); const double eps = 1e-7; const double ep = 1e-5; const int maxn = 1e5 + 7; const double P...
3
#include <bits/stdc++.h> using namespace std; const int MXN = 5010; long long n, k; int a[MXN], d; int main() { cin >> n >> k; while (n > 0) { a[d] = n % k; n /= k; if (d & 1) { if (a[d] > 0) { a[d] -= k; n++; } } d++; } printf("%d\n", d); for (int i = 0; i < d;...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("tune=native") #pragma GCC optimize("unroll-loops") using namespace std; const int MAX = 2e5 + 5; const long long MOD = 1000000007; const long long MOD2 = 2010405347; const long long INF = 2e18; const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0}; const...
5
#include <bits/stdc++.h> using namespace std; const int MR = 3e5 + 10; int n, m, a, b, prv[MR], skoj[MR], p[MR], r[MR], iter, most[2][MR], znak[MR]; int base[MR]; vector<int> g[MR], k0, k1; queue<int> q; int done[MR]; int deg[MR]; bool removed[MR]; void makeset(int x) { p[x] = x; r[x] = 0; } void unionset(int x, in...
3
#include <bits/stdc++.h> typedef long long ll; typedef long long llong; typedef long double ld; typedef unsigned long long ull; using namespace std; /* ll pw(ll a, ll b) { ll ans = 1; while (b) { while (!(b & 1)) b >>= 1, a = (a * a) % MOD; ans = (ans * a) % MOD, --b; } return ans; } */ const int MAXN = 220000...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n, a[1000000]; int i; int p = 1; cin >> t; while (t--) { cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (i = 0; i < n - 1; i++) { if (a[i] != a[i + 1]) p++; } cout << p <...
2
#include <bits/stdc++.h> using namespace std; long long MOD = 1791791791; double eps = 1e-12; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); template <typename T, typename U, typename V> struct Triple { T first; U second; V third; Triple(T first, U second, V third) : first(f...
2
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int q; long long a, b, u, v, k; long long calc(long long u, long long v, long long k, long long o = 0) { if (u > v) swap(u, v); if (u < 1 || k <= 0) return 0; long long p = 1, res = 0; while (p * 2LL <= v) p *= 2LL; long long tmp = m...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, c = 0, j = 0, index[3], sum = 0, avg; cin >> n; long long int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } avg = sum / n; if (avg * n != sum) cout << "Unrecoverable configuration."; else { for (...
2
#include <bits/stdc++.h> using namespace std; long long a[100009]; int main() { long long n, x, y; int i; while (cin >> n >> x >> y) { int flag = 0; for (i = 1; i <= n - 1; i++) a[i] = 1, y--; a[n] = y; if (a[n] <= 0) flag = 1; long long sum = 0; for (i = 1; i <= n; i++) { sum = sum ...
1
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } int power(int a, int b, int m, int ans = 1) { for (; b; b >>= 1, a = 1LL * a * a % m) if (b & 1)...
5
#include <iostream> #include <string> #include <cmath> #include<algorithm> #include<stack> #include<queue> #include<map> #include<set> #include<iomanip> #define _USE_MATH_DEFINES #include <math.h> #include <functional> #include<complex> using namespace std; #define rep(i,x) for(ll i=0;i<x;i++) #define repn(i,x) for(ll...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; string s; cin >> s; int curr = 1, count = 0; for (int i = 0; i < s.length(); i++) { int index = int(s[i]) - 96; if (abs(index - curr) <= 13) { count += abs(index - curr);...
1
#include<bits/stdc++.h> #define ll long long #define mod 1000000007 #define N 2009 #define M 4000009 #define cbn(x,y) ((ll)fac[x]*inv[y]%mod*inv[(x)-(y)]%mod) using namespace std; int n,m,tot,fac[M],inv[M],dp[N][N]; int main(){ scanf("%d%d",&n,&m); tot=n*m; if (m==1){ puts("1"); return 0; } int i,j; fac[0]=inv[0]=...
0
#include <bits/stdc++.h> using namespace std; int64_t gcd(int64_t a, int64_t b){ return b==0 ? a : gcd(b, a%b); } int64_t lcm(int64_t a, int64_t b){ return a * (b/gcd(a, b)); } void fail(){ cout << 0 << endl; exit(0); } int main(){ int N, M; cin >> N >> M; vector<int> A(N); for(int i=...
0
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template <class S, class T>...
5
#include <bits/stdc++.h> using namespace std; void getint(int &v) { char ch, fu = 0; for (ch = '*'; (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ; if (ch == '-') fu = 1, ch = getchar(); for (v = 0; ch >= '0' && ch <= '9'; ch = getchar()) v = v * 10 + ch - '0'; if (fu) v = -v; } long long x, ans; i...
2
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a > b) { return a; } return b; } long long int min(long long int a, long long int b) { if (a < b) { return a; } return b; } long long int n, k; long long int arr[200005]; long long int power(long ...
4
#include <bits/stdc++.h> using namespace std; string s; int n; int main(int argc, char* argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> s; int n1 = 0, n0 = 0, n2 = 0; for (int i = 0; i < n; i++) { if (s[i] == '0') { n0++; } else if (s[i] == '1') { n1++; } else { ...
4
#include <bits/stdc++.h> using namespace std; struct node { int l, r, x; node() {} node(int l, int r, int x) : l(l), r(r), x(x) {} }; vector<int> vec[100010]; int n, m; int vis[100010]; vector<node> res; int a[100010 * 100], now[100010], nx[100010 * 100], last; int sze[100010]; queue<int> q; void add(int x, int i...
3
#include <bits/stdc++.h> using namespace std; int n; int abc[200009][26] = {0}, ans = 0, flag = 0, nouse[26] = {0}; string rem[200019]; int same[26][25] = {0}; int main() { for (int i = 0; i < 26; i++) nouse[i] = 1; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; for (int j = 0; j < s.size...
4
#include <bits/stdc++.h> using namespace std; vector<string> vec_splitter(string second) { second += ','; vector<string> res; while (!second.empty()) { res.push_back(second.substr(0, second.find(','))); second = second.substr(second.find(',') + 1); } return res; } void debug_out(vector<string> __attri...
1
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > pC, dC; bool cmp1(const pair<long long, long long> &i, const pair<long long, long long> &j) { if (i.first < j.first) return true; if (i.first == j.first) return (dC[i.second] < dC[j.second]); return false; } bool cmp2(cons...
2
#include<bits/stdc++.h> #define REP(i,s,n) for(int i=s;i<n;i++) #define rep(i,n) REP(i,0,n) #define EPS (1e-6) #define equals(a,b) (fabs((a)-(b)) < EPS) #define COUNTER_CLOCKWISE 1 #define CLOCKWISE -1 #define ONLINE_BACK 2 #define ONLINE_FRONT -2 #define ON_SEGMENT 0 using namespace std; class Point{ public:...
0
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #includ...
0
#include <bits/stdc++.h> using namespace std; template <typename T> string toString(T x) { if (x == 0) return "0"; bool negative = x < 0; string res; while (x) { res.push_back('0' + x % 10); x /= 10; } if (negative) res.push_back('-'); reverse(res.begin(), res.end()); return res; } void ioFromFi...
3
#include <bits/stdc++.h> #pragma optimise GCC(-O2) using namespace std; mt19937_64 rang( chrono::high_resolution_clock::now().time_since_epoch().count()); int rng(int lim) { uniform_int_distribution<int> uid(0, lim - 1); return uid(rang); } long long INF = LLONG_MAX; const long long M = 1000000007; long long po...
2
#include <bits/stdc++.h> using namespace std; int dist[100005], visited[100005], dp[100005], cnt = 0; vector<int> graph[100005], state[100005]; void dfs(int v) { visited[v] = 2; cnt++; int temp = 100005; for (int i = 0; i < graph[v].size(); i++) { int u = graph[v][i]; if (dist[u] == dist[v] - 1) temp = ...
5
#include <bits/stdc++.h> using namespace std; string read(char x[]) { scanf("%s", x); return x; } const int M = 2e6 + 23; int n; int x, y, a, b; void solve() { scanf("%d", &n); int ans = 1; for (int i = 0; i < n; i++) { scanf("%d %d", &a, &b); if (x == a && y == b) continue; ans += max(0, min(a, b...
2
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; int t[n],T = 0; for(int i = 0;i < n;i++){ cin >> t[i]; T += t[i]; } double v[2*T+1]; for(int i = 0;i < 2*T+1;i++){ v[i] = 1000000; } int tsum = 0; for(int i = 0;i < n;i++){ double vc; cin >> vc; for(in...
0
#include<bits/stdc++.h> using namespace std; #define ALL(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<n;i++) #define debug(n,v) cout<<#v<<":";for(int i=0;i<n;i++)cout<<v[i]<<" ";cout<<endl; #define INF 1000000000 #define mod 1000000007 typedef long long ll; const ll LINF = 1001002003004005006ll; int dx[]={1,0,-...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c, x, y, z, p, m, i, j = 0; cin >> n; int arr[n * 2]; for (i = 0; i < n; i++) { cin >> arr[j] >> arr[j + 1]; j = j + 2; } cin >> x; for (i = 0; i < n * 2; i++) { if (arr[i] >= x) { break; } else { continue;...
1
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") const int mod = 998244353; int N1, N2, K; int A1[4009], B1[4009], A2[4009], B2[4009], dp[77][4009]; int CA1[4009], CB1[4009], DA1[4009], DB1[4009], CA2[4009], CB2[4009], DA2[4009], DB2[4009]; int cnt_c1, c...
4
#include<iostream> using namespace std; int main(){ while(1){ int H,W; cin >> H >> W; if(H== 0 && W == 0)break; for(int i=1;i<=H;++i){ for(int j =1;j<=W;++j){ if((i + j) % 2 ==0){ cout <<"#"; } else{ cout << "."; } } cout << endl; } cout << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace ::std; struct info { int s; int e; int id; }; bool operator<(const info &in1, const info &in2) { return ((in1.s < in2.s) || ((in1.s == in2.s) && (in1.e > in2.e)) || ((in1.s == in2.s) && (in1.e == in2.e) && (in1.id < in2.id))); } class SegT { public: int op(i...
1
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0; i<(int)(n); i++) #define all(vec) vec.begin(), vec.end() int main() { int n; scanf("%d", &n); vector<int> vec(n); rep(i,n) scanf("%d", &vec.at(i)); bool OK[2]; rep(j,2) { int i=0, m=1; OK[j] = false; ...
0
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } typedef long long int ll; #defi...
0
#include <bits/stdc++.h> using namespace std; int main() { string x; int m, n, i, j, q; cin >> x; int len = x.length(); int dp[len + 1]; dp[1] = 0; for (i = 2; i <= len; i++) { if (x[i - 1] == x[i - 2]) dp[i] = 1 + dp[i - 1]; else dp[i] = dp[i - 1]; } cin >> q; while (q--) { ...
2
#include <bits/stdc++.h> using namespace std; int main(){ int N,C,K; cin>>N>>C>>K; std::vector<int> T(N); for(int i=0;i<N;i++)cin>>T[i]; sort(T.begin(),T.end()); int ans=0; int busgo=-1; int busfm=-1; for(int i=0;i<N;i++){ if(busgo<T[i]||i>busfm+C-1){ busgo=T[i]+K; ans++; busfm=...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 7; const int M = 2e6 + 7; const int lim = 2e6; const int mod = 998244353; const int inf = 0x3f3f3f3f; int a[N], num[N]; bool vis[N]; void init() { vis[1] = 1; for (register int i = 2; i <= lim; i++) if (vis[i] == 0) for (register int j = i ...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = 1e9 + 7; const ll INF = 1e18 + 9; ll powmod(ll base, ll exp, const ll MOD) { ll ans = 1; while (exp) { if (exp & 1) ans = (ans * base) % MOD; base = (base * base) % MOD; exp >>= 1; } return ans; } ll gcd(ll a, ll b) {...
5
#include <bits/stdc++.h> using namespace std; int n, k; vector<pair<int, int> > nei[500005]; long long dp0[500005], dp1[500005]; void Dfs(int v, int par) { multiset<long long> mx; long long sum = 0; for (int i = 0; i < nei[v].size(); ++i) { int to = nei[v][i].first; if (to == par) continue; Dfs(to, v)...
3
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 50; int n, m; int res[N]; int fa[N], fb[N]; deque<int> Sa, Sb; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 0; i < n; i++) { int a; cin >> a; fa[a]++; } for (int i = 0; i < n; i++) { ...
5
#include <bits/stdc++.h> using namespace std; int t[300005][26], st[300005], h[300005], result[300005], depth[300005]; void count_size(int v) { st[v] = 1; for (int i = 0; i < 26; i++) { int x = t[v][i]; if (x) { h[x] = h[v] + 1; count_size(x); st[v] += st[x]; } } } vector<pair<int, i...
6
#include <bits/stdc++.h> using namespace std; int main() { int N, ans = 0; scanf("%d", &N); while (N--) { ans = 0; int b[12][12] = {0}, c[6] = {0}; char a[12]; int x = 0; for (int i = 0; i < 12; i++) scanf(" %c", &a[i]); for (int i = 0; i < 12; i++) { if (a[i] == 'X') { ans++...
1
#include <bits/stdc++.h> using namespace std; template <class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template <class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } int N, M; bitset<200013> want; long long arr[200013]; long long prob[3013][3013]; long long choose[3013][3013]; long long tot,...
3
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 55; const int M = N * N; const int Mod = 1e9 + 7; int Dp[N][N][2 * M]; void add_self(int& x, int y) { if((x += y) >= Mod) x -= Mod; } int add(int x, int y) { return add_self(x, y), x; } int mul(int x, int y) { return (l...
0
#include <bits/stdc++.h> using namespace std; int n, m, i, j, nf, ne, ns, seq[25]; vector<double> all; double rf, re, rs, df, de, ans, sum; bool chg() { int i; for (i = 1; i + 2 <= n; i += 2) { if (seq[i] > seq[i + 1]) { sort(seq + i + 2, seq + n + 1); reverse(seq + i + 2, seq + n + 1); return...
5
#include <bits/stdc++.h> int init(int x, int y) { return (x > y) ? (x - y) : (y - x); } int main() { int a, b, i; int x[3] = {2, 3, 5}; int cnt_a[3], cnt_b[3]; while (scanf("%d%d", &a, &b) != EOF) { cnt_a[0] = cnt_a[1] = cnt_a[2] = 0; cnt_b[0] = cnt_b[1] = cnt_b[2] = 0; for (i = 0; i < 3; i++) { ...
2
#include <iostream> using namespace std; int n; int main() { cin>>n; int p = 0, q, ans = 0; for(int i=0;i<n;i++){ cin>>q; if(q > p) ans += q - p; p = q; } cout<<ans<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int sum = 0; for (int i = 0; i < s.size(); i++) { if ((s[i] - '1' + 1) % 2 == 0) { sum += max(0, i); sum += 1; } } cout << sum << "\n"; }
1
#include <bits//stdc++.h> using namespace std; int main() { int x,a; cin>>x>>a; if(x<a)cout<<0; else cout<<10; return 0; }
0
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T a) { return a >= 0 ? a : -a; } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T mod(T a, T b) { T ret = a % b; if (ret < 0) ret += b; return ret; } long long mulmod(long long a, long long b, long ...
3
#include <bits/stdc++.h> using namespace std; const int N = 400100; int n, m, x, y, d[N]; bool a[2][N]; void update(int col, int &cnt) { if (col < 0 || col + 1 == n) { return; } if (!a[0][col] && !a[1][col]) { cnt += 1 - d[col]; d[col] = 1; return; } if (a[0][col] && a[1][col] && !a[0][col + 1...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; const int mod = 1e9 + 7; const int hash_bit = 13331; int t; int n; string str; int a[maxn]; void solve() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } sort(a + 1, a + 1 + n); long long ans = 1ll * a[n] * a[n -...
2
#include <iostream> #include <cstdio> #include <vector> #include <string> using namespace std; char ret(int i) { if (i < 10) return '0' + i; else return 'A' + (i-10); } int main(void){ int n, m, q; char c; while (cin>>n>>m>>q && n) { vector<vector<int> > s(q, vector<int>(n)); vect...
0
#include <bits/stdc++.h> #define ll long long using namespace std; const int MAXN=6010,P=998244353; int n,s,a[MAXN],dp[MAXN],np[MAXN]; ll ans; int main () { scanf("%d%d",&n,&s); for (int i=1;i<=n;i++) { scanf("%d",&a[i]); for (int j=s;j>=1;j--) { dp[j+a[i]]=(dp[j+a[i]]+dp[j])%P; } dp[a[i]]=(dp[a[i]]+i)%P; ...
0
#include <bits/stdc++.h> using namespace std; vector<int> seen; vector<int> color; vector<vector<int> > e; int ans = 0; void dfs(int idx) { int to = -1; seen[idx] = 1; for (int i = 0; i < (int)e[idx].size(); i++) { to = e[idx][i]; if (seen[to] && color[idx] == color[to]) { ans++; return; }...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native") using namespace std; namespace cst { const double pi = acos(-1.0); const int MIN_INT8 = -128; const int MIN_INT16 = -32768; const in...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, l, k, k1, kol1 = 0, ans, ans1, a, b; cin >> n >> m; char g[n + 1][m + 1]; for (int i = 1; i <= n; i++) { int kol = 0; for (int j = 1; j <= m; j++) { cin >> g[i][j]; ...
1
#include <bits/stdc++.h> using namespace std; bool gcd(int a, int b, int& x) { if (a == 0) { x = b; return false; } int x1, y1; bool d = gcd(b % a, a, x1); x = (b / a); return d; } long double a[210]; int mas[210]; long double pre[210][210][410]; int N; long double go(int l, int n, int space) { if...
4
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> void chkmax(T1 &x, T2 y) { if (x < y) x = y; } template <typename T> void read(T &x) { x = 0; char c = getchar(); T neg = 1; while (!isdigit(c)...
5
#include <bits/stdc++.h> int main(void) { int i, j, ct, moves, tmp, p1, p2, p3, arr[1001], ans1[100000], ans2[100000]; scanf("%d", &ct); for (i = 1; i <= ct; scanf("%d", arr + i++)) ; for (p2 = 1, p3 = 2, i = 3; i <= ct; ++i) for (p1 = i;;) { if (arr[p1] > arr[p2]) { tmp = p1; p1 =...
5
#include <bits/stdc++.h> using namespace std; const int N = 401; int a[N], dp[N - 2][N][N]; int n, m, s, f, c, r; int main() { scanf("%d%d", &n, &m); for (int i = (1); i <= (n); ++i) scanf("%d", a + i); for (int s = (1); s <= (n); ++s) for (int f = (s); f <= (n); ++f) dp[0][s][f] = a[f] - a[s]; for (int r =...
6
#include <bits/stdc++.h> using namespace std; vector<long long> vec; set<long long> set2; int main() { int n; long long k; cin >> n >> k; vec.resize(n); for (int i = 0; i < (int)n; i++) cin >> vec[i]; sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end()); set2.clear(); for (int i = 0; i < (int...
1
#include <bits/stdc++.h> struct point { double x, y; int id; inline bool operator<(const point& rhs) const { return (x != rhs.x) ? (x < rhs.x) : (y < rhs.y); } } q[200005], p[200005]; int n, m; int sta[200005], top; std::vector<int> v, id[200005]; inline double slope(int a, int b) { return ((p[a].y - p[b]...
5
#include <iostream> using namespace std; int main(){ int n; while(cin >> n,n){ int i,aaa,ans=0; for(i=0;i<(n/4);i++){ cin >> aaa; ans += aaa; } cout << ans << endl; } return 0; }
0
#include<bits/stdc++.h> using namespace std; vector <int> adj[51]; int vi[51]; void dfs(int u,int x,int y) { vi[u]=1; for (int j=0;j<adj[u].size();j++) { if (!vi[adj[u][j]]) { if (u==x&&adj[u][j]==y) continue; dfs(adj[u][j],x,y); } } } int main() { int n,m; cin>>n>>m; int ans=0; memset(vi,0,sizeo...
0
#include <bits/stdc++.h> using namespace std; inline long long IN() { long long x = 0, ch = getchar(), f = 1; while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar(); if (ch == '-') { f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); ...
5
#include <bits/stdc++.h> using namespace std; int const lim = 3e5 + 1; int const MLOG = 20, mod = 1e9 + 7, bas = 47; string s[lim + 3]; vector<int> adj[lim + 3]; int st[4 * lim + 3], poww[lim + 3]; void update(int i, int j, int index, int ind, int val) { if (i > ind || j < ind) return; if (i == j && i == ind) { ...
5