solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> int n, i; long long f(long long t[]) { long long ans = t[0]; for (i = 1; i < n; i++) { ans = (ans | t[i]); } return ans; } int main() { long long a[1001], b[1001]; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%I64d", &a[i]); for (i = 0; i < n; i++) scanf("%I64d", &b[i]); ...
1
#include <bits/stdc++.h> #define r(i,n) for(int i=0;i<n;i++) using namespace std; typedef pair<int,int>P; typedef pair<int,P>P2; int N,T,x[200009],n; map<int,int>a[200009]; set<string>st; vector<P2>v[200009]; string start,goal,str[200009]; map<int,string> s[200009]; P dis[200099]; int main(){ cin>>N>>T; cin>>...
0
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long p) { long long ans = 1; x = x % p; if (x == 0) { return 0; } while (y > 0) { if (y & 1) { ans = (ans * x) % p; } y = y >> 1; x = (x * x) % p; } return ans; } signed main() { ios_ba...
5
#include <bits/stdc++.h> using namespace std; const long long m = 1000000007; const double pi = acos(-1); const int N = 5e2 + 10; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; long long n, a, b; cin >> n >> a >> b; for (long long i = 0; i < n / a + 1; i++) if ((n - a * i)...
2
#include <bits/stdc++.h> using namespace std; int d[1050]; int n, m, h; double lg[1050 * 1050]; double getlgc(int n, int m) { return lg[n] - lg[m] - lg[n - m]; } int main() { while (scanf("%d%d%d", &n, &m, &h) != EOF) { int sum; sum = 0; for (int i = 1; i <= m; i++) { scanf("%d", &d[i]); sum +...
4
#include<bits/stdc++.h> using namespace std; const int N = 5005, M = 202, LG = 14; int n, m, B[M][N], Log[N]; long long Mx, A[N], dp[N][N]; pair < int , int > MX[LG][N]; inline int RMQ(int l, int r) { int &lg = Log[r - l]; return (max(MX[lg][l], MX[lg][r - (1 << lg)]).second); } void Solve(int l, int r) { i...
0
#include <bits/stdc++.h> using namespace std; int main(){ long long int n,ans=0; cin >> n; long long int a[300010]; for (int i=0;i<3*n;i++) cin >> a[i]; sort(a,a+3*n,greater<int>()); for (int i=0;i<n;i++)ans+=a[1+2*i]; cout << ans <<endl; }
0
#include <string> #include <vector> #include <iostream> #include <algorithm> #include <functional> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int C, N; cin >> C >> N; vector<string> S(N); for (int i = 0; i < N; ++i) { cin >> S[i]; } function<bool(int, int)> judge = [&](int...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; long long n, m, l, r; set<pair<int, int> > s; vector<int> dv[maxn]; inline void Add(int i) { for (auto A : dv[i]) s.insert({A, i}); } inline void Del(int i) { for (auto A : dv[i]) s.erase({A, i}); } int main() { ios::sync_with_stdio(false); ...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, LG = 20, INF = 1e9 + 7; long long par[N][LG + 2], cnt[N], n, m, k, h[N], highest[N], cutedge[N]; vector<int> adj[N]; bool mark[N]; void DFS(int v, int parent, int t) { mark[v] = 1; for (int i = 0; i < adj[v].size(); i++) { int u = adj[v][i]; ...
2
#include<bits/stdc++.h> using namespace std; #define gc getchar_unlocked #define ll long long #define PI 3.1415926535897932384626 #define pb push_back #define mp make_pair #define F first #define S second #define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); typedef pair<int, int> pi; typedef pair<ll, ll>...
1
#include <bits/stdc++.h> using namespace std; const int N = 100001; long long mod = 1000000009; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } bool is_vowel(char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o...
6
#include <iostream> #include <cstdio> using namespace std; int map[50][50]; int w, h; void dfs(int x, int y){ map[y][x] = 0; for(int i = -1; i <= 1; i++){ for(int j = -1; j <= 1; j++){ int nx = x + i, ny = y + j; if(nx >= 0 && nx < w && ny >= 0 && ny < h && map[ny][nx] == 1) dfs(nx, ny); } } return; } ...
0
#include <iostream> using namespace std; int main() { int q1, b, c1, c2, q2; while (cin >> q1) { if (q1 == 0) { break; } cin >> b >> c1 >> c2 >> q2; if (b < c1) { cout << "NA" << endl; } else { int counter = 0; while (q2 > 0 && b >= c1) { b -= c1; q1--; q2--; counter++; } ...
0
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const bool debug = true; const long long INFL = LLONG_MAX; int A, B, N, M, H, S[1010]; long double memo[100100][102]; bool was[100100][102]; long double dp(int b, int n) { int a = A; if (a + b < n) return 0; if (b < n) return 0; if (n == 0) ...
2
#include <bits/stdc++.h> using namespace std; struct state { int x, y, s; state(int _x, int _y, int _s) { x = _x; y = _y; s = _s; }; }; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; char a[22][22]; int v[22]; int px[22], py[22]; int d[22][22][1 << 8]; struct cmp { bool operator()(const state &...
3
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; string but[10]={"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; for(int x=0;x<n;x++){ string a; cin>>a; string ans=""; int b=0,c=0; for(int i=0;i<a.size();i++){ if(a[i]=='0'){ if(b!=0){ int num=(c+but[b].s...
0
#include <bits/stdc++.h> using namespace std; const int nmax = 1e6 + 42; vector<string> ans[nmax]; int n; string in; int depth = 0; pair<string, int> inp[nmax]; bool vis[nmax]; void dfs(int node, int level) { if (inp[node].second == 0) { vis[node] = 1; ans[level].push_back(inp[node].first); depth = max(de...
5
#include<iostream> #include<vector> #include<queue> using namespace std; int main(){ while(1){ int m,nmin,nmax; cin >> m >> nmin >> nmax; if (m + nmin + nmax == 0) break; int dis = 0; int max = 0; int maxi = 0; int pre_p = 0; for (int i = 1; i <= m; i++){ int p1; cin >> p1; if (nmin < i and i <= n...
0
#include <bits/stdc++.h> using namespace std; long long int i, n, m, x, y, z, j, k, l, mn = LLONG_MAX, mx = 0, c, a[100005], r, s, cnt = 0, sum = 0; string str; char ch; vector<vector<long long int>> g; bool v[1000]; void swap(int *xp, int *yp) { int temp = *xp; *xp = *yp; ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int ans; int n, m, d; int c[maxn]; int t[maxn]; int cnt[maxn]; int num[maxn]; int bois[maxn]; bool bad[maxn * 20]; void in(); void solve(); void add(); void out(); int main() { ios::sync_with_stdio(false); cout.tie(0); cin.tie(0); in(); ...
4
#define _USE_MATH_DEFINES #include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <complex> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include...
0
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2e5 + 10; typedef long long ll; int N, P[MAX_N], V[MAX_N]; ll ans; struct DSU { int pa[MAX_N]; void init(int n) { for (int i = 1; i <= n; i++) pa[i] = i; } int query(int x) { return pa[x] == x ? x : pa[x] = query(pa[x]); } void merg...
0
#include <bits/stdc++.h> /** special:n-1相加不互质,n-1分开互质 数目<=20000,值<=30000 **/ int n; int main() { scanf("%d",&n); int n3=n/3; int adjust=0; if(n==3||n==6) { if(n==3) printf("2 5 63\n"); else printf("2 4 8 10 3 9\n"); return 0; } if(n3>50...
0
#include <bits/stdc++.h> using namespace std; int cube(int a, int b) { int o = a; for (int i = 1; i < b; i++) { o *= a; } return o; } void testing_ifs() { bool isMale; string a, b; bool isTall; int i = 0; bool repeat = true; while (repeat == true) { while (a != "yes" && a != "no") { co...
1
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> using namespace std; const int maxn = 50 + 3; int mat[maxn][maxn],n,m,q; int on[maxn][maxn]; int off[maxn][maxn]; int t[maxn][maxn]; int ptr[maxn][maxn]; vector<int>PPP[maxn][maxn]; char s[maxn][maxn]; struct node { in...
0
#include <bits/stdc++.h> using namespace std; const int oo = 1e9; const int N = 15; int g[N][N]; void dfs(int i, int j, int pi, int pj) { int u, v; if (g[i + pi][j + pj] > g[i][j]) { g[i + pi][j + pj] = g[i][j]; dfs(i + pi, j + pj, pi, pj); } for (u = -1; u < 2; ++u) for (v = -1; v < 2; ++v) i...
1
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007, M = 3e5 + 7; long long powe(long long x, long long y) { x = x % mod; long long ans = 1; while (y > 0) { if (y & 1) { ans = (1ll * x * ans) % mod; } y >>= 1; x = (1ll * x * x) % mod; } return ans; } stack<int>...
3
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; inline void multiply(long long mat1[][2], long long mat2[][2]) { long long res[2][2]; long long i, j, k; for (i = 0; i < 2; i++) { for (j = 0; j < 2; j++) { res[i][j] = 0; for (k = 0; k < 2; k++) res[i][j] = (res[i][...
1
#include <bits/stdc++.h> using namespace std; double dis(int x1, int y1, int x2, int y2) { return sqrt((powl((x1 - x2), 2)) + (powl((y1 - y2), 2))); } bool com(pair<int, int> x1, pair<int, int> x2) { if (x1.first == x2.first) return x1.second < x2.second; else return x1.first < x2.first; } const int mod =...
3
#include <bits/stdc++.h> using namespace std; int main() { long long n, t, a, countL = 0, countR = 0; int v[100001]; cin >> n; for (int i = 0; i < n; i++) { cin >> a; v[a] = i; } cin >> t; while (t--) { cin >> a; countL = countL + v[a] + 1; countR = countR + (n - v[a]); } cout << c...
2
#include <bits/stdc++.h> int max(int a, int b) { return a > b ? a : b; } int min(int a, int b) { return a < b ? a : b; } const int Maxn = 500000; const int Inf = 0x3f3f3f3f; struct Segment_Tree_1 { struct Segment_Node { int lazy; int val; } seg[Maxn << 2 | 5]; void build(int root = 1, int left = -Maxn, in...
5
#include<bits/stdc++.h> using namespace std; #define FOR(i, a, n) for(int i = (a); i < (n); i++) #define REP(i, n) FOR(i, 0, (n)) #define ALL(a) (a.begin(), a.end()) typedef vector<int> vi; int64_t h(const vector<vi> &t, int i, int p, vi &v) { int64_t res = 1; for (int c : t[i]) { if (c == p) continue...
0
#include <bits/stdc++.h> using namespace std; int n; int vx[100111], vy[100111]; bool check(int x1, int y1, int x2, int y2, long long int x, long long int y) { return (y - y2) * (x1 - x) - (y1 - y) * (x - x2) > 0; } long long int count(int x, int y) { long long int ans = (long long int)n * (n - 1) * (n - 2) / 6; ...
5
#include <cstdio> #include <cstring> #define repu(i,x,y) for (int i=x; i<=y; ++i) #define repd(i,x,y) for (int i=x; i>=y; --i) using namespace std; typedef long long LL; int n,m,nxt[200100]; LL l,r,ans[26],sum[100][26],len[100]; char a[200100]; int calc(int m) { int x=m-n%m; return (n+x)/m&1?x+m:x; } void so...
0
#include <bits/stdc++.h> #define REP(i,n,N) for(int i=n;i<N;i++) #define p(S) cout<<S<<endl using namespace std; int chizu[51][51]; void labeling(int y,int x,int w,int h){ chizu[y][x]=0; REP(dy,-1,2){ REP(dx,-1,2){ if(0 <= y+dy && y+dy < h && 0 <= x+dx && x+dx < w){ if(chizu[y+dy][x+dx]){ labeling(y+d...
0
#include <bits/stdc++.h> using namespace std; vector<vector<long long> > graph; vector<bool> visited; long long ans; long long *getArray(long long size) { long long *arr = new long long[size]; for (long long i = 0; i < size; i++) arr[i] = 0; return arr; } void merge(long long *childarr, long long *parentarr, long...
3
#include <bits/stdc++.h> using namespace std; char ch[610]; bitset<2100> now[2010], s[2010]; int n, pos[2010], num[2010]; void init(int id) { int i, j, k, l = strlen(ch); for (i = 0; i <= l - 1; i++) num[l - i] = ch[i] - '0'; for (i = 1; i <= 2010; i++) { int res = 0, lastres; for (j = l; j >= 1; j--) { ...
4
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O2") vector<long long int> ar[1000001]; long long int vis[1000001], dis[1000001], level[1000001]; const int MAX_SIZE = 1000001; const int N = 2000010; const int mod = 1e9 + 7; vector<int> isprime(MAX_SIZE, true); vector<int> prime; vector<int> SPF(MAX_...
1
#include <bits/stdc++.h> using namespace std; int n; int par[200010][18]; int dep[200010]; int lca(int u, int v) { if (dep[u] < dep[v]) swap(u, v); for (int i = 18 - 1; i >= 0; i--) if (dep[par[u][i]] >= dep[v]) u = par[u][i]; if (u == v) return u; for (int i = 18 - 1; i >= 0; i--) if (par[u][i] != par[...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int c = 0; for (int i = 0; i < n; i++) { if (a[i] <= k) c++; if (a[i] > k) break; } if (c != n) { for (int i = n - 1; i >= 0; i--) { if (a[i] <= k) ...
1
#include<iostream> #include<queue> using namespace std; int main(){ int n,k,m,c; queue<int> stone; while(cin >>n>>k>>m,n||k||m){ for(int i=0; i<n; i++){stone.push(i+1);} for(int i=0; i<m-1; i++){ c = stone.front(); stone.pop(); stone.push(c); } stone.pop(); for(int i=1; i<n; ...
0
#include <bits/stdc++.h> int main() { int A, B, C, D; scanf("%d %d %d %d", &A, &B, &C, &D); printf("%d", std::max(A * B, C * D)); }
0
#include <bits/stdc++.h> using namespace std; long long int a[25], b[25], dp[50][50]; vector<vector<long long> > c(const vector<vector<long long> > &a, const vector<vector<long long> > &b) { long long int size = a.size(); vector<vector<long long> > MP(size, ...
5
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main(){ int N, K; cin >> N >> K; int x[N]; for(int i = 0; i < N; i++){ cin >> x[i]; } int ans = INF; for(int i = 0; i <= N - K; i++){ ans = min(ans, min(abs(x[i])+ abs(x[i+K-1]-x[i]), abs(x[i+K-1])+abs(x[i+K-1]-x[i]))); } ...
0
#include <bits/stdc++.h> using namespace std; int n, mx, bas = 1, h[50]; char a[1000005]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { if (a[i] <= 'z' and a[i] >= 'a') { h[a[i] - 'a']++; continue; } if (a[i] >= 'A' and a[i] <= 'Z') { ...
2
#include <bits/stdc++.h> using namespace std; int r, c, n, k, x, y, ans; int a[20][20]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> r >> c; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> x >> y; a[x][y] = 1; } for (int i = 1; i <= r; i++) for (int j = 1; j <= c; j++) fo...
1
#include<bits/stdc++.h> using namespace std; int m,n,q,A[20]; int ans(int x,int y){ if(x==0)return 0; if(y>=n)return 1; if(ans(x,y+1)==0 || ans(x-A[y],y+1)==0)return 0; else return 1; } int main(){ cin>>n; for(int i=0;i<n;i++)cin>>A[i]; cin>>q; for(int i=0;i<q;i++){ cin>>m; if(ans(m,0)==0)co...
0
#include<bits/stdc++.h> #define rep(i,n)for(int i=0;i<n;i++) using namespace std; struct st { int t, s, d; }; bool b[20000]; st p[20000]; int main() { int n, m; while (scanf("%d%d", &n, &m), n) { rep(i, m) { int t, s, d; scanf("%d%d%d", &t, &s, &d); p[i] = { t,s - 1,d - 1 }; } sort(p, p + m, [](st a, st...
0
#include <bits/stdc++.h> using namespace std; int n, s, k; int r[51]; int color[51]; vector<int> v[51]; int pd[2001][51]; int func(int c, int idx) { if (c <= 0) return 0; if (pd[c][idx] != -1) return pd[c][idx]; int ans = 1000000; for (int i = 0; i < v[idx].size(); i++) { int t = v[idx][i]; int cost = a...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("-ffloat-store") using namespace std; void read(vector<long long> &v) { for (int i = 0; i < v.size(); i++) cin >> v[i]; } long long n, m, a, b, c, k, temp, x, y; vo...
2
#include <bits/stdc++.h> using namespace std; int main() { char a[21], b[21]; scanf("%s%s", a, b); int cnt1 = 0, cnt2 = 0; int len = strlen(a); for (int i = 0; i < len; i += 2) { if (a[i] == '8') { if (b[i] == '[') { cnt1++; } else if (b[i] == '(') { cnt2++; } } else ...
1
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long p10[10] = {}; p10[0] = 1; for (int i = 1; i <= 9; ++i) p10[i] = p10[i - 1] * 10; int t; cin >> t; while (t--)...
3
#include <bits/stdc++.h> using namespace std; struct node { int x, y, v; } b[200005]; bool operator<(node p, node q) { if (p.x == q.x) { if (p.y == q.y) { return p.v < q.v; } return p.y < q.y; } return p.x < q.x; } int main() { int t, n, x, y, ans, l, r; cin >> t; string s; while (t--)...
3
#include <bits/stdc++.h> using namespace std; const int DIM = 100005; deque<int> que; vector<int> lst, edg[DIM]; bool oki[DIM]; int val[DIM]; int main(void) { int n, m; cin >> n >> m; for (int i = 1; i <= m; ++i) { int x, y; cin >> x >> y; edg[x].push_back(y); edg[y].push_back(x); } for (int i...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<long long, long long>; const long long INF = 2e18; template <class A, class B> ostream &operator<<(ostream &os, const pair<A, B> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <class A> ostream &operat...
2
#include <bits/stdc++.h> using namespace std; int n, m; int orderm[21]; int table[21][21]; bool checkvalid(); int main() { ios::sync_with_stdio(0); cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> table[i][j]; for (int i = 1; i <= m; i++) orderm[i] = i; bool valid = checkval...
2
#include <bits/stdc++.h> using namespace std; template <class T> long long size(const T &x) { return x.size(); } const long long INF = ~(1 << 31); const double pi = acos(-1); const double EPS = 1e-9; int main() { cin.sync_with_stdio(false); long long n; long long cnt = 0; long long num = 0; cin >> n; vect...
2
#include <iostream> #include <algorithm> #include <string> #include <map> #include <vector> using namespace std; int list[10000][6]; int ko[10000][4]; bool check(int a,int b,int c,int d){ int e[10]={0}; e[a]++;e[b]++;e[c]++;e[d]++; for(int i=0;i<10;i++)if(e[i]>1)return 0; return 1; } int main(){ int N; while(cin...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const long long inf = 2e9; long long w, m; void solve(long long x, long long y) { if (x == m) { cout << "YES\n"; exit(0); } if (y > inf) return; solve(x + y, y * w); solve(x - y, y * w); solve(x, y * w); } int main() { ios_base::...
3
#include <bits/stdc++.h> using namespace std; class FenwickTree { private: vector<int> ft; public: FenwickTree(int n) { ft.assign(n + 1, 0); } int rsq(int b) { int sum = 0; for (; b; b -= (b & (-b))) { sum += ft[b]; } return sum; } int rsq(int a, int b) { if (a > b) return 0; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int x, y; scanf("%d%d", &x, &y); if (y == 0 && (x == 0 || x == 1)) { printf("0\n"); return 0; } if (y >= x && y < -x) printf("%d\n", (abs(x) - 1) * 4 + 3); if (y <= -x + 1 && y < x) printf("%d\n", (-y - 1) * 4 + 4); if (y <= x && y > -x + ...
1
#include <bits/stdc++.h> using namespace std; vector<int> primesUntil(int n) { vector<int> p; p.push_back(2); for (int i = 3; i <= n; ++i) { for (int j = 0; j < p.size(); ++j) { if (i % p[j] == 0) break; if (p[j] * p[j] > i) { p.push_back(i); break; } } } return p; } ...
1
#include <bits/stdc++.h> using namespace std; #define N 5010 #define mod 998244353 int c[N][N]; inline int read() { int x=0; char ch=getchar(); while (!isdigit(ch)) ch=getchar(); while (isdigit(ch)) x=x*10+ch-'0',ch=getchar(); return x; } int Ans[N]; int main() { int k=read(),n=read(); c[0][...
0
#include <bits/stdc++.h> using namespace std; int n, m; char s[504][504]; int v[1000005][3], nv; void go(int step, int x, int y) { if (x != -1 and y != -1 and s[x][y] == '.') { s[x][y] = 'B'; v[nv][0] = 'B'; v[nv][1] = x; v[nv][2] = y; nv++; go(step + 1, x + 1, y); go(step + 1, x - 1, y); ...
4
#include <bits/stdc++.h> using namespace std; int main(){ string S; cin >> S; cout << S.at(0) << S.at(1) << S.at(2); }
0
// Rakib (CSE'19) #include<bits/stdc++.h> #define boost_ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define pb push_back #define read(i,n,a) for...
3
#include <bits/stdc++.h> using namespace std; void file_put() { freopen("filename.in", "r", stdin); freopen("filename.out", "w", stdout); } const int N = 1e5 + 5; int n, w, a[N], s = 0, p = 1e9; vector<int> ret; void print() { for (auto x : ret) printf("%d ", x); printf("\n"); } int main() { scanf("%d%d", &n,...
5
#include <bits/stdc++.h> using namespace std; const int nax = 1000 * 1007; const int INF = 1e9; long long int pow(long long int x, long long int y) { long long int res = 1; while (y > 0) { if (y & 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } int main() { ios::sync_with_stdio(0); ...
2
#include <bits/stdc++.h> #define rep(i, x, y) for (int i = x; i <= y; i++) using namespace std; const int N = 1e6 + 10; int pre[N], n, sub[N]; char s[N], t[N]; bool chkpre(int x) { return x % (x - pre[x]) > 0 || !pre[x]; } bool chksub(int x) { return x % (x - sub[x]) > 0 || !sub[x]; } void getfail(char *s, ...
0
#include <bits/stdc++.h> using namespace std; int main() { int m = 0; int n = 0; cin >> m; cin >> n; vector<vector<char> > vec(m, vector<char>(n, 0)); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cin >> vec[i][j]; } } int count_s = 0; for (int i = 0; i < m; i++) { coun...
1
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFLL = 0x3f3f3f3f3f3f3f3fLL; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x ...
4
#include <bits/stdc++.h> using namespace std; long long MX = 1e9 + 7; vector<pair<int, int> > v[5000050]; void print(vector<long long> const &input) { for (int i = 0; i < input.size(); i++) { cout << input.at(i) << ' '; } cout << "\n"; } void solve(int m) {} int main() { int t; cin >> t; while (t--) { ...
4
#include <cstdio> int n, x, d; int main() { scanf("%d%d", &n, &x); if(x==1 || x==2*n-1) return puts("No"), 0; puts("Yes"); d = n-x; n += n-1; for(int i=0; i<n; i++) printf("%d\n", (i-d+n)%n+1); }
0
#include <bits/stdc++.h> using namespace std; int sum[200010], n, dp[200010][2]; int mxv, mnv; int main() { scanf("%d", &n); dp[n][0] = dp[n][1] = 0; for (int i = 1; i <= n; i++) { scanf("%d", &sum[i]); sum[i] += sum[i - 1]; } mxv = sum[n]; mnv = -sum[n]; for (int i = n - 1; i >= 1; i--) { dp[...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 210; struct node { int v, next, use; } edge[MAXN << 2]; bool bridge[MAXN]; int low[MAXN], dfn[MAXN], vis[MAXN]; int head[MAXN], pre[MAXN], ip, sol, Count, u[MAXN], v[MAXN], n, m, p[MAXN], i, viss[MAXN], s, ans = -1, j, t[MAXN]; void init(void) { mem...
6
#include <bits/stdc++.h> using namespace std; int main() { long int c[110], g[110][110], n, m, sum = 0, min = 10000000; cin >> n >> m; for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) g[i][j] = 0; for (int i = 1; i <= n; i++) cin >> c[i]; for (int i = 0; i < m; i++) { int a, b; cin >> a >...
1
#include<cstdio> #include<algorithm> using namespace std; #define LL long long const int maxn = 5e3 + 5; const LL mod = 1e9 + 7; LL x[maxn], cnt[maxn]; LL dp[maxn][maxn]; int main() { // freopen("in.txt","r",stdin); int n, k, q;scanf("%d %d %d",&n,&k,&q); for(int i = 1;i <= n;i++)scanf("%lld",&x[i]),dp[i][...
4
#include <bits/stdc++.h> const int N = 2e5 + 5; const int INF = 0x3f3f3f3f; using namespace std; int T, n, f[N][2], a[N], sum[N]; template <typename T> inline T read() { T x = 0, w = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') w = -1; c = getchar(); } while (c >= '0' && c <= '9')...
3
#include <bits/stdc++.h> using namespace std; int n; int down(int a, int b) { if (a >= b) { return a - b; } else return a + 1 + (n - 1) - b; } int up(int a, int b) { if (a > b) { return n - 1 - a + b + 1; } else return b - a; } int main() { cin >> n; int i; int a[n]; for (i = 0; i < n; i...
2
#include <bits/stdc++.h> using namespace std; int main() { string k; cin >> k; set<char> s; for (int i = 0; i < k.size(); i++) { s.insert(k[i]); } if (s.size() % 2 == 0) { cout << "CHAT WITH HER!\n"; } else if (s.size() % 2 != 0) { cout << "IGNORE HIM!\n"; } }
1
#include <iostream> int main() { int N; std::cin >> N; std::cout << (N-2) * 180 << std::endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; long long power(long long x, long long y) { long long res = 1; x = x % MOD; while (y > 0) { if (y & 1) res = (res * x) % MOD; y = y >> 1; x = (x * x) % MOD; } return res; } long long modInverse(long long x) { return power(x, ...
2
#include <bits/stdc++.h> using namespace std; int p[1000000]; bool vis[100000 + 10]; int main() { bool f = 0; string s; int ct = 0; cin >> s; char curp = '0'; for (int i = 0; i < s.size(); i++) { if (s[i] == curp) ct++; else ct = 1; curp = s[i]; if (ct == 7) f = 1; } if (f) c...
1
#include<stdio.h> int main() { int e,y,z,m,ans=100000000; while(1){ scanf("%d",&e); ans=100000000; if(e==0) break; else{ for(y=0; y<=1000; y++){ for(z=0; z<=100; z++){ m=e-y*y-z*z*z+y+z; if(ans>m && e-y*y-z*z*z>=0) ans=m; } } printf("%d\n",ans); } } return 0; } ...
0
#include <bits/stdc++.h> const int N = 3001; using namespace std; vector<int> G[N], rG[N], q[N]; int d[N][N]; bool vis[N]; int c[N][3], rc[N][3]; void bfs(int k, vector<int> g[], bool f) { int h = 0, t = 1, i, p; memset(vis, false, sizeof(vis)); q[k].clear(); q[k].push_back(k); if (f) d[k][k] = 0; vis[k] = ...
4
#include <bits/stdc++.h> using namespace std; struct edge { int a, b, t, index; }; struct Constraint { int a, b, best0, best1; vector<int> sol0, sol1; int cons; }; void nope() { cout << "No\n"; exit(0); } void dfs(int node, vector<vector<edge>> &G, vector<int> &seen, int &end, int par, vector<int> ...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6; const int MOD = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int N; cin >> N; int arr[N]; for (int i = 0; i < N; i++) cin >> arr[i]; for (int i = 0; i < N; i++) { int cnt = 1; for (int j = 0; j < N...
1
#include <bits/stdc++.h> using namespace std; bool f[101][101], v[101]; int n, m, g[101][101], l[101][101], ans[101]; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } bool dfs(int x) { v[x] = true; for (int y = 1; y <= n; ++y) { if (!f[x][y]) continue; if ((ans[x] % g[x][y] != 0) ||...
3
#include <bits/stdc++.h> using namespace std; inline char read() { static const int IN_LEN = 1000000; static char buf[IN_LEN], *s, *t; return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++); } template <class T> inline void read(T &x) { static bool io...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:36777216") using namespace std; int n; long long sum, ans, a[50005]; int main() { cin >> n; for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]), sum += a[i]; long long k = sum / n; for (int i = 1; i <= n; i++) { if (a[i] != k) { if (a[i] > k) { ...
2
#include <bits/stdc++.h> using namespace std; char field[2005][2005]; int cur = 0; int sum(int x, int y) { int c = 0; if (x > 0) if (field[x - 1][y] == '.') c++; if (y > 0) if (field[x][y - 1] == '.') c++; if (field[x + 1][y] == '.') c++; if (field[x][y + 1] == '.') c++; return c; } bool paint(int &...
2
#include<bits/stdc++.h> #define ll long long using namespace std; const ll N=1e5+10; ll n,m,a,b,cnt; ll head[N],bl[N]; struct Edge{ll nxt,to;}edge[N<<1]; inline void add(ll u,ll v){edge[++cnt]=(Edge){head[u],v};head[u]=cnt;} void dfs(ll u,ll col){ bl[u]=col; for(ll i=head[u];i;i=edge[i].nxt){ ll v=edge[i].to; if(...
0
#include <bits/stdc++.h> using namespace std; const int N = 100000; const double pi = acos(-1.0); int n, k, l; long long dp[4020][4020], fac[4040]; int read() { int x = 0, f = 1; char ch = getchar(); while ((ch < '0') || (ch > '9')) { if (ch == '-') f = -1; ch = getchar(); } while ((ch >= '0') && (ch ...
6
#include <bits/stdc++.h> using namespace std; string s; const long long MAXN = 600; long long k, cnt[MAXN][MAXN], n, dp[MAXN][MAXN], dad[MAXN][MAXN], mindp, minj, j, ji, t[MAXN]; void T(long long l, long long r) { if (l == r) return; for (long long i = l; i <= (l + r) / 2; i++) { s[i] = s[r - i + l]; } } ...
4
#include <bits/stdc++.h> using namespace std; const int N = 200010; vector<int> g[N]; int sub[N]; int centlvl[N]; int p[N]; char s[N]; int ma[N]; int dfs(int u, int last, int d) { sub[u] = 1; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; if (v != last) { p[v] = u; sub[u] += dfs(v, u, ...
5
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <typename P> P dectobin(P a) { if (a == 0) return 0; else return (a % 2 + 10 * dectobin(a / 2)); } template <typename Y> Y bintodec(Y a) { long long ans = 0, b =...
2
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int C = 26; void add(int &x, int y) { x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; } int fix(int x) { while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x; } int pw(int a, int b) { int ret = 1; while (b) ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<string, int> mp; for (int i = 0; i < n; i++) { string s; cin >> s; mp[s]++; } int m; cin >> m; for (int i = 0; i < m; i++) { string s; cin >> s; mp[s]--; } int ans = 0; for (auto i = mp.begin(); i != mp....
0
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> a(n), b(n); long long maxto = 1e9; for (long long i = 0; i < n; i++) { cin >>...
6