solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int N = 3010, mod = 998244353, INF = 0x3f3f3f3f; const double eps = 1e-6; char a[N], b[N]; long long f[N][N]; int main() { scanf("%s%s", a + 1, b + 1); int n = strlen(a + 1), m = strlen(b + 1); for (int i = 1; i <= n; i++) if (i > m || a[1] == b[i]) f[i][i] = 2; for (int len = 2; len <= n; len++) { for (int l = 1; l + len - 1 <= n; l++) { int r = l + len - 1; if (l > m || a[len] == b[l]) f[l][r] += f[l + 1][r]; f[l][r] %= mod; if (r > m || a[len] == b[r]) f[l][r] += f[l][r - 1]; f[l][r] %= mod; } } long long ans = 0; for (int i = m; i <= n; i++) ans += f[1][i], ans %= mod; printf("%d\n", ans % mod); return 0; }
3
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int N = 30000; bool f[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); int n; cin >> n; string a, b; for (int i = 0; i < n; i++) { cin >> a >> b; string aa = ""; string bb = ""; bool f = true; vector<int> A; vector<char> CA; vector<int> B; vector<char> CB; for (int k = 0; k <= a.length(); k++) { if (a[k] != a[k - 1]) { A.push_back(aa.length()); CA.push_back(aa[0]); aa = ""; } aa += a[k]; } for (int k = 0; k <= b.length(); k++) { if (b[k] != b[k - 1]) { B.push_back(bb.length()); CB.push_back(bb[0]); bb = ""; } bb += b[k]; } if (A.size() != B.size()) { f = false; } for (int k = 1; k < A.size(); k++) { if (CA[k] != CB[k]) { f = false; } if (B[k] < A[k]) { f = false; } } if (f) cout << "YES" << "\n"; else cout << "NO" << "\n"; } return 0; }
2
#include<iostream> using namespace std; long long N, A, B, C, D, E; int main(){ cin >> N >> A >> B >> C >> D >> E; long long m = min(A, min(B, min(C, min(D, E)))); cout << 4 + (N + m - 1) / m << endl; }
0
#include <bits/stdc++.h> using namespace std; long long n, m; vector<long long> diag[2000]; vector<long long> diag1[2000]; bool used[2000]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; int mas[n][m]; int mas1[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int a; cin >> a; diag[i + j].push_back(a); } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int a; cin >> a; diag1[i + j].push_back(a); } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (used[i + j]) continue; used[i + j] = true; sort(diag[i + j].begin(), diag[i + j].end()); sort(diag1[i + j].begin(), diag1[i + j].end()); if (diag[i + j] != diag1[i + j]) { cout << "NO"; return 0; } } } cout << "YES"; return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { int X, Y, Z; cin >> X >> Y >> Z; cout << (X - Z) / (Y + Z) << "\n"; }
0
#include <bits/stdc++.h> using namespace std; const int N = 1000 + 5; const int K = 100 + 5; int n, k, mod; inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } inline int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; } inline int mul(int a, int b) { return 1LL * a * b % mod; } int dp[N][K][2], base10mod[N], base10k[N]; bool dped[N][K][2]; int go(int, int, bool); int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k >> mod; base10mod[0] = base10k[0] = 1; for (int i = 1; i <= n; i++) base10mod[i] = mul(base10mod[i - 1], 10); for (int i = 1; i <= n; i++) base10k[i] = 1LL * base10k[i - 1] * 10 % k; cout << go(0, 0, 0) << '\n'; return 0; } int go(int i, int j, bool any) { if (dped[i][j][any]) return dp[i][j][any]; if (j == 0 and any) return i == n ? 1 : mul(base10mod[n - i - 1], 9); if (i == n) return 0; auto& ret = dp[i][j][any]; dped[i][j][any] = true; for (int a = 0; a < 10; a++) { ret = add(ret, go(i + 1, (j + 1LL * a * base10k[i] % k) % k, any or a > 0)); } return ret; }
4
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, m; cin >> n >> m; vector<vector<int>> g(n + 1, vector<int>()); vector<int> list, degree(n + 1, 0); for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; g[x].push_back(y); g[y].push_back(x); degree[x]++; degree[y]++; } int c = 0; while (1) { bool flag = 0; for (int i = 1; i <= n; i++) { if (degree[i] == 1) { flag = 1; degree[i]--; list.push_back(i); } } if (!flag) break; else { c++; for (auto i : list) { for (auto j : g[i]) { degree[j]--; } } } list.clear(); } cout << c; return 0; }
2
#include <bits/stdc++.h> const int N = 1e5 + 5; std::vector<int> edge[N]; int a[N]; long long best[N], down[N]; long long ans; int n; void DFS(int u, int fa) { std::vector<long long> downs; for (auto v : edge[u]) { if (v == fa) continue; DFS(v, u); best[u] = std::max(best[u], best[v]); downs.push_back(down[v]); } long long mx1 = 0, mx2 = 0; for (auto d : downs) { if (d > mx1) { mx2 = mx1; mx1 = d; } else if (d > mx2) { mx2 = d; } } best[u] = std::max(best[u], mx1 + mx2 + a[u]); down[u] = mx1 + a[u]; ans = std::max(ans, best[u]); } void DFS2(int u, int fa, long long up) { up += a[u]; std::vector<int> children; for (auto v : edge[u]) { if (v == fa) continue; children.push_back(v); } int sz = children.size(); if (sz == 0) return; std::vector<long long> prebest(sz + 1), sufbest(sz + 1); prebest[0] = 0; for (int i = 0; i < sz; ++i) { prebest[i + 1] = std::max(prebest[i], best[children[i]]); } sufbest[sz] = 0; for (int i = sz - 1; i >= 0; --i) { sufbest[i] = std::max(sufbest[i + 1], best[children[i]]); } std::vector<long long> predown(sz + 1), predown2(sz + 1); predown[0] = predown2[0] = 0; for (int i = 0; i < sz; ++i) { predown[i + 1] = predown[i]; predown2[i + 1] = predown2[i]; long long x = down[children[i]]; if (x > predown[i + 1]) { predown2[i + 1] = predown[i + 1]; predown[i + 1] = x; } else if (x > predown2[i + 1]) { predown2[i + 1] = x; } } std::vector<long long> sufdown(sz + 1), sufdown2(sz + 1); sufdown[sz] = sufdown2[sz] = 0; for (int i = sz - 1; i >= 0; --i) { sufdown[i] = sufdown[i + 1]; sufdown2[i] = sufdown2[i + 1]; long long x = down[children[i]]; if (x > sufdown[i]) { sufdown2[i] = sufdown[i]; sufdown[i] = x; } else if (x > sufdown2[i]) { sufdown2[i] = x; } } for (int i = 0; i < sz; ++i) { long long cur = std::max(prebest[i], sufbest[i + 1]); cur = std::max(cur, up + std::max(predown[i], sufdown[i + 1])); cur = std::max(cur, a[u] + predown[i] + sufdown[i + 1]); cur = std::max(cur, a[u] + predown[i] + predown2[i]); cur = std::max(cur, a[u] + sufdown[i + 1] + sufdown2[i + 1]); cur += best[children[i]]; ans = std::max(ans, cur); } for (int i = 0; i < sz; ++i) { int v = children[i]; long long new_up = up; new_up = std::max(new_up, a[u] + std::max(predown[i], sufdown[i + 1])); DFS2(v, u, new_up); } } int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", a + i); for (int u, v, i = 1; i < n; ++i) { scanf("%d%d", &u, &v); edge[u].push_back(v); edge[v].push_back(u); } DFS(1, 0); DFS2(1, 0, 0); printf("%I64d\n", ans); return 0; }
6
#include <bits/stdc++.h> using namespace std; int lx[6] = {4, 5, 3, 4, 6, 6}; char fol[6][10] = {"lios", "liala", "etr", "etra", "initis", "inites"}; char s[100100]; char e = 'a'; int len = 0; int gend = -1; int flagn = -1; int flagv = -1; int flag = 1; int num = 0; char word[100100]; void check() { int match = 0; int nn = 0; for (int i = 0; i < 6; i++) { if (len >= lx[i]) { int t = 1; for (int j = 0; j < lx[i]; j++) if (word[len - lx[i] + j] != fol[i][j]) t = 0; if (t == 1) { match = 1, nn = i; break; } } } if (match == 0) { flag = 0; return; } else { if (gend < 0) gend = nn % 2; else if (gend != (nn % 2)) { flag = 0; return; } if (nn < 2) { if (flagn > 0 || flagv > 0) { flag = 0; return; } } else if (nn < 4) { if (flagv > 0 || flagn > 0) { flag = 0; return; } else flagn = 1; } else if (nn < 6) { flagv = 1; } } return; } int main() { { len = 0; while (e != '\n') { scanf("%c", &e); if (e != ' ' && e != '\n') word[len++] = e; if (e == ' ') { num++; check(); len = 0; } } check(); num++; if (flag == 0) cout << "NO" << endl; else if (num > 1 && flagn < 1) cout << "NO" << endl; else cout << "YES" << endl; } }
3
//#include<bits/stdc++.h> //using namespace std; #include<stdio.h> #include<string.h> const int MAXN=1e6+50; char s[MAXN]; int main () { scanf("%s",s); int ans=0; for(int i=strlen(s)-1;i>=1;i--) { if(s[i]>='6'||(s[i]=='5'&&s[i-1]>='5')) {ans+='0'+10-s[i];s[i-1]++;} else ans+=s[i]-'0'; } if(s[0]>='6') ans+='0'+10-s[0]+1; else ans+=s[0]-'0'; printf("%d",ans); return 0; }
0
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; const int INF=1e9,MOD=1e9+7,ohara=1e6+10; const ll LINF=1e18; using namespace std; #define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++) #define rrep(i,a,b) for(int i=(a);i<(b);i++) #define rrrep(i,a,b) for(int i=(a);i>=(b);i--) #define all(v) (v).begin(), (v).end() #define Size(n) (n).size() #define Cout(x) cout<<(x)<<endl #define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl; #define Cerr(x) cerr<<(x)<<endl #define fi first #define se second #define P pair<ll,ll> #define m_p make_pair #define V vector<ll> ll n,cnt,ans,a,b,c,d,tmp[5],tmpp,m,h,w,x,y,sum,pos,k; ld doua; int dy[]={1,0,-1,0}; int dx[]={0,1,0,-1}; //int dy[]={-1,0,1,-1,1,-1,0,1}; //int dx[]={-1,-1,-1,0,0,1,1,1}; string alph("abcdefghijklmnopqrstuvwxyz"),s; bool fl; struct edge{int to,cost;}; set<pair<ll,pair<ll,ll>>> st; //-------------------------↓↓↓↓↓↓------------------------ int main(void){ cin.tie(0); ios::sync_with_stdio(false); cin>>n; rep(i,n){ rep(j,3)cin>>tmp[j]; sort(tmp,tmp+3); st.insert({tmp[0],{tmp[1],tmp[2]}}); } Cout(n-Size(st)); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int INF(0x3f3f3f3f); const long long LINF(0x3f3f3f3f3f3f3f3fLL); const double DINF(1e20); const double EPS(1e-12); const double PI(acos(-1.0)); inline double cot(double x) { return 1.0 / tan(x); } inline double sec(double x) { return 1.0 / cos(x); } inline double csc(double x) { return 1.0 / sin(x); } template <class T> inline T max(T a, T b, T c) { return max(max(a, b), c); } template <class T> inline T max(T a, T b, T c, T d) { return max(max(a, b), max(c, d)); } template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); } template <class T> inline T min(T a, T b, T c, T d) { return min(min(a, b), min(c, d)); } template <class T> inline void Scan(T& x) { char c; for (c = getchar(); c <= ' '; c = getchar()) ; bool ngt(c == '-'); if (ngt) c = getchar(); for (x = 0; c > ' '; c = getchar()) x = (x << 3) + (x << 1) + c - '0'; if (ngt) x = -x; } template <class T> inline void Scan(T& x, T& y) { Scan(x), Scan(y); } template <class T> inline void Scan(T& x, T& y, T& z) { Scan(x), Scan(y), Scan(z); } char ch[] = "ACGT"; int n, m, a[4]; char s[300]; void Main() { cin >> n >> s; m = n / 4; if (n % 4) { cout << "===" << endl; return; } for (int(i) = (0); (i) <= (n - 1); ++(i)) for (int(j) = (0); (j) <= (3); ++(j)) a[j] += (s[i] == ch[j]); for (int(i) = (0); (i) <= (3); ++(i)) if (a[i] > m) { cout << "===" << endl; return; } for (int(i) = (0); (i) <= (n - 1); ++(i)) if (s[i] != '?') cout << s[i]; else { for (int(j) = (0); (j) <= (3); ++(j)) if (a[j] < m) { ++a[j]; cout << ch[j]; break; } } } int main() { Main(); return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int count = 0; int ind = -1; int Min = INT32_MAX; for (int i = 1; i <= n; ++i) { int num; cin >> num; if (num < Min) { count = 1; Min = num; ind = i; } else if (num == Min) count++; } cout << ((count == 1) ? to_string(ind) : "Still Rozdil") << '\n'; }
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 5; using LL = int64_t; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; LL x, temp, sum = 0; cin >> n >> x; for (int i = 1; i <= n; i++) { cin >> temp; if (i != 1) temp++; sum += temp; } if (sum == x) cout << "YES\n"; else cout << "NO\n"; return 0; }
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 50 * 1000 + 5, K = 500; int p[MAXN], comp[MAXN], snd[MAXN]; char root[MAXN]; long long s[MAXN], ts[MAXN], pv[MAXN], pvs[MAXN], sv[MAXN]; pair<char, pair<int, int> > q[MAXN]; vector<int> g[MAXN], gc[MAXN]; bool dfsLca(int v) { int cnt = root[v]; for (size_t i = 0; i < g[v].size(); i++) cnt += dfsLca(g[v][i]); if (cnt > 1) root[v] = true; return cnt; } void dfs0(int v) { ts[v] = 1; sv[v] = 1; for (size_t i = 0; i < g[v].size(); i++) { dfs0(g[v][i]); sv[v] += 2ll * ts[g[v][i]] * ts[v]; ts[v] += ts[g[v][i]]; } } void dfs1(int v, int c) { comp[v] = c; if (root[v]) pvs[v] = 0; else { pvs[v] = pv[v] + pvs[p[v]]; snd[v] = (root[p[v]] ? v : snd[p[v]]); } for (size_t i = 0; i < g[v].size(); i++) if (!root[g[v][i]]) dfs1(g[v][i], c); } bool anc(int v, int u) { for (int w = u;; w = comp[p[w]]) { if (w == v) return true; if (w == 0) return false; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(12); int n; cin >> n; for (int i = 1; i < n; i++) { cin >> p[i]; p[i]--; g[p[i]].push_back(i); } for (int i = 0; i < n; i++) cin >> s[i]; dfs0(0); for (int i = 1; i < n; i++) pv[i] = (ts[p[i]] - ts[i]) * s[p[i]]; long long ans = 0; for (int i = 0; i < n; i++) ans += s[i] * sv[i]; cout << (long double)ans / ((long long)n * n) << '\n'; int m; cin >> m; for (int i = 0; i < m; i++) { cin >> q[i].first >> q[i].second.first >> q[i].second.second; q[i].second.first--; if (q[i].first == 'P') q[i].second.second--; } for (int bl = 0; bl < m; bl += K) { int br = min(m, bl + K); for (int i = 0; i < n; i++) root[i] = false; root[0] = true; for (int i = bl; i < br; i++) { root[q[i].second.first] = true; if (q[i].first == 'P') root[q[i].second.second] = true; } dfsLca(0); dfs0(0); for (int i = 1; i < n; i++) pv[i] = 2 * (ts[p[i]] - ts[i]) * s[p[i]]; for (int i = 0; i < n; i++) if (root[i]) dfs1(i, i); vector<int> roots; for (int i = 0; i < n; i++) if (root[i]) roots.push_back(i); int k = roots.size(); for (int i = 0; i < k; i++) if (roots[i] != 0) gc[comp[p[roots[i]]]].push_back(roots[i]); for (int i = bl; i < br; i++) { if (q[i].first == 'P') { int v = q[i].second.first, u = q[i].second.second; if (anc(v, u)) swap(v, u); for (int w = v; w != 0; w = comp[p[w]]) { ans -= ts[v] * (pv[w] + pvs[p[w]]); if (p[w] != comp[p[w]]) ts[snd[p[w]]] -= ts[v]; ts[comp[p[w]]] -= ts[v]; sv[comp[p[w]]] -= 2 * (ts[comp[p[w]]] - (p[w] == comp[p[w]] ? (w == v ? 0 : ts[w]) : ts[snd[p[w]]])) * ts[v]; for (size_t j = 0; j < gc[comp[p[w]]].size(); j++) if (gc[comp[p[w]]][j] != w) { if (p[gc[comp[p[w]]][j]] == comp[p[w]]) pv[gc[comp[p[w]]][j]] -= 2 * ts[v] * s[comp[p[w]]]; else pvs[p[gc[comp[p[w]]][j]]] -= 2 * ts[v] * s[comp[p[w]]]; } } for (size_t j = 0; j < gc[comp[p[v]]].size(); j++) if (gc[comp[p[v]]][j] == v) { gc[comp[p[v]]].erase(gc[comp[p[v]]].begin() + j); break; } p[v] = u; gc[u].push_back(v); pv[v] = 2 * ts[u] * s[u]; for (int w = v; w != 0; w = comp[p[w]]) { ans += ts[v] * (pv[w] + pvs[p[w]]); if (p[w] != comp[p[w]]) ts[snd[p[w]]] += ts[v]; ts[comp[p[w]]] += ts[v]; sv[comp[p[w]]] += 2 * (ts[comp[p[w]]] - (p[w] == comp[p[w]] ? ts[w] : ts[snd[p[w]]])) * ts[v]; for (size_t j = 0; j < gc[comp[p[w]]].size(); j++) if (gc[comp[p[w]]][j] != w) { if (p[gc[comp[p[w]]][j]] == comp[p[w]]) pv[gc[comp[p[w]]][j]] += 2 * ts[v] * s[comp[p[w]]]; else pvs[p[gc[comp[p[w]]][j]]] += 2 * ts[v] * s[comp[p[w]]]; } } } else { int v = q[i].second.first, x = q[i].second.second; ans += (x - s[v]) * sv[v]; for (size_t j = 0; j < gc[v].size(); j++) if (p[gc[v][j]] == v) pv[gc[v][j]] += 2 * (x - s[v]) * (ts[v] - ts[gc[v][j]]); else pvs[p[gc[v][j]]] += 2 * (x - s[v]) * (ts[v] - ts[snd[p[gc[v][j]]]]); s[v] = x; } cout << (long double)ans / ((long long)n * n) << '\n'; } for (int i = 0; i < n; i++) { g[i].clear(); gc[i].clear(); } for (int i = 1; i < n; i++) g[p[i]].push_back(i); } return 0; }
5
#include <iostream> #include <cstdio> using namespace std; const int P=1000000007; const int N=2005; int f[N][N][2]; int n,K,ans; inline void update(int &x,int y){(x+=y)%=P;} int main() { //freopen("solitaire.in","r",stdin),freopen("solitaire.out","w",stdout); scanf("%d%d",&n,&K); f[n+1][0][0]=1; for (int i=n+1;i>=2;--i) { for (int j=n-1;j>=0;--j) update(f[i][j][0],f[i][j+1][0]); for (int j=0;j<=n;++j) for (int k=0;k<2;++k) if (f[i][j][k]) { update(f[i-1][j+1][1],f[i][j][k]); update(f[i-1][j][0],f[i][j][k]); } } ans=f[1][n-K][0]; for (int i=1;i<=n-K-1;++i) (ans<<=1)%=P; printf("%d\n",ans); //fclose(stdin),fclose(stdout); return 0; }
0
#include <bits/stdc++.h> using namespace std; int a[51][51], dp[51][51][51][51]; int solve(int x1, int y1, int x2, int y2) { if (x1 == x2 && y1 == y2) return a[x1][y1]; if (dp[x1][y1][x2][y2] != -1) return dp[x1][y1][x2][y2]; int ans = max(x2 - x1 + 1, y2 - y1 + 1); for (int i = x1; i < x2; i++) { ans = min(ans, solve(x1, y1, i, y2) + solve(i + 1, y1, x2, y2)); } for (int i = y1; i < y2; i++) { ans = min(ans, solve(x1, y1, x2, i) + solve(x1, i + 1, x2, y2)); } return dp[x1][y1][x2][y2] = ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; for (int i = 0; i < n; i++) { cin >> s; for (int j = 0; j < n; j++) { a[i][j] = (s[j] == '#'); } } memset(dp, -1, sizeof(dp)); cout << solve(0, 0, n - 1, n - 1) << "\n"; }
6
#include <bits/stdc++.h> using namespace std; const int N = 5e6 + 100; int n, x, LOG[N]; bool have; vector<int> vec; int main() { ios::sync_with_stdio(false), cin.tie(0); for (int i = 0; i <= 20; i++) LOG[1 << i] = i; cin >> n >> x; if (x >= (1 << n)) { for (int i = 0; i < n; i++) vec.push_back(1 << i); cout << (1 << vec.size()) - 1 << '\n'; for (int i = 1; i < (1 << vec.size()); i++) cout << vec[LOG[i & -i]] << ' '; return 0; } vector<int> help = {0}; for (int i = 1; i < (1 << n); i++) if ((i ^ x) > i) help.push_back(i); cout << help.size() - 1 << '\n'; for (int i = 1; i < help.size(); i++) cout << (help[i] ^ help[i - 1]) << ' '; return 0; }
4
#include <bits/stdc++.h> using namespace std; int n, m, l[101], r[101], t[101], c[101], d, s, k; int main() { cin >> n >> m; for (int i = 1; i <= m; i++) cin >> l[i] >> r[i] >> t[i] >> c[i]; for (int i = 1; i <= n; i++) { s = 0; k = 1001; for (int j = 1; j <= m; j++) { if (l[j] <= i && r[j] >= i) { if (t[j] < k) k = t[j], s = c[j]; } } d += s; } cout << d; }
2
#include <stdio.h> #include <bitset> std::bitset<4000400> b; int main(){ int N, a[2020], s, i; for (scanf("%d", &N), b[0] = 1, s = i = 0; i != N; i++) scanf("%d", a+i), s += a[i], b |= b<<a[i]; for(i = s>>1; !b[i]; i--) ; printf("%d\n", s-i); }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; struct edge { int to; }; using graph = vector<vector<edge>>; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { ll n, m; cin >> n >> m; vector<ll> a, b; for (int i = 0; i < (m); ++i) { ll ai, bi; cin >> ai >> bi; a.push_back(ai); b.push_back(bi); } vector<ll> asort(begin(a), end(a)); sort(begin(asort), end(asort), greater<ll>()); vector<ll> a_s(m + 1, 0); for (int i = 1; i < (m + 1); ++i) a_s[i] = a_s[i - 1] + asort[i - 1]; ll best = 0; for (int i = 0; i < (m); ++i) { auto it = lower_bound(begin(asort), end(asort), b[i], greater<ll>()); ll n_gb = it - begin(asort); ll ans; ll na = min(n, n_gb); if (a[i] > b[i]) { ll nb = n - na; ans = nb * b[i] + a_s[na]; } else { if (na >= n - 1) { ans = a_s[n]; } else { ll nb = n - na - 1; ans = nb * b[i] + a[i] + a_s[na]; } } best = max(best, ans); } cout << best << "\n"; } }
3
#include <bits/stdc++.h> using namespace std; int n; string s; int main() { scanf("%d", &n); cin >> s; if (n & 1) printf("%c%c%c", s[0], s[1], s[2]); else printf("%c%c", s[0], s[1]); for (int i = (n & 1) + 2; i < n; i += 2) printf("-%c%c", s[i], s[i + 1]); printf("\n"); return 0; }
2
#include <bits/stdc++.h> using namespace std; const int Maxn = 200010; const int inf = 2147483647; 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 <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); return x * f; } map<pair<int, int>, int> ans; map<long long, int> id; int tot = 0, cnt = 0; struct Point { int x, y; Point(int _x, int _y) { x = _x, y = _y; } }; bool operator<(Point a, Point b) { if (a.x != b.x) return a.x < b.x; return a.y < b.y; } set<Point> S[Maxn]; int gcd(int a, int b) { if (!a) return b; return gcd(b % a, a); } int main() { int q = read(); while (q--) { int op = read(), x = read(), y = read(); if (op == 1) { cnt++; long long d = (long long)x * x + (long long)y * y; if (!id[d]) id[d] = ++tot; for (set<Point>::iterator it = S[id[d]].begin(); it != S[id[d]].end(); it++) { int tx = (*it).x + x, ty = (*it).y + y, g = gcd(tx, ty); ans[make_pair(tx / g, ty / g)] += 2; } int g = gcd(x, y); ans[make_pair(x / g, y / g)]++; S[id[d]].insert(Point(x, y)); } else if (op == 2) { cnt--; long long d = (long long)x * x + (long long)y * y; S[id[d]].erase(Point(x, y)); for (set<Point>::iterator it = S[id[d]].begin(); it != S[id[d]].end(); it++) { int tx = (*it).x + x, ty = (*it).y + y, g = gcd(tx, ty); ans[make_pair(tx / g, ty / g)] -= 2; } int g = gcd(x, y); ans[make_pair(x / g, y / g)]--; } else { int g = gcd(x, y); printf("%d\n", cnt - ans[make_pair(x / g, y / g)]); } } }
6
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <cassert> #include <iostream> #include <cctype> #include <sstream> #include <string> #include <list> #include <vector> #include <queue> #include <set> #include <stack> #include <map> #include <utility> #include <numeric> #include <algorithm> #include <iterator> #include <bitset> #include <complex> #include <fstream> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef pair<int, int> pint; #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for(int i = x; i < n; i++) template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); } template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; } template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; } template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); } const int MOD = 100000; int n, m, s; int dp[50][3005]; // dp[‘I‘ð‚µ‚½ŒÂ”][—ÝŒv”]‚ð–ž‚½‚·‘g‚ݍ‡‚킹‚̐” int main() { while(cin >> n >> m >> s && n) { memset(dp,0,sizeof(dp)); dp[0][0]=1; for(int i = 1; i <= m; i++) { for (int j = n * n; 0 < j; j--) { for(int k = s; i <= k; k--) { (dp[j][k] += dp[j - 1][k - i]) %= MOD; } } } cout << dp[n * n][s] << endl; } }
0
#include <bits/stdc++.h> #define rep(i, N) for (int i = 0; i < (int)N; i++) using namespace std; typedef long long ll; const ll LLINF = 9223372036854775807; const int INF = pow(2,29); const int MOD = 1000000007; int main() { int Q; cin >> Q; priority_queue<ll> l; l.push(-1*LLINF); priority_queue<ll, vector<ll>, greater<ll>> r; r.push(LLINF); ll pos = 0, result = 0; rep(i, Q) { int type; cin >> type; if (type==1) { ll a, b; cin >> a >> b; result += b; if (l.top()>a) { ll x = l.top(); result += x-a; l.pop(); r.push(x); l.push(a); l.push(a); } else if (r.top()<a) { ll x = r.top(); result += a-x; r.pop(); l.push(x); r.push(a); r.push(a); } else { l.push(a); r.push(a); } pos = l.top(); // cout << l.top() << " " << r.top() << endl; } else { cout << pos << " " << result << endl; } } return 0; }
0
#include <bits/stdc++.h> using namespace std; int tmp[109], arr[109]; int main() { int n, m, r; cin >> n >> m >> r; if (m >= 2 * r && n >= 2 * r) cout << "First\n"; else cout << "Second\n"; return 0; }
1
#include<iostream> #include<iomanip> #include<algorithm> using namespace std; int main(){ int n, w, x; while(cin >> n >> w, n+w){ int hist[11] = {}; for(int i = 0; i < n; i++){ cin >> x; hist[x/w]++; } int ma = *max_element(hist, hist+11); int width; for(width = 10;; width--) if(hist[width]) break; double ink = 0.01; for(int i = 0; i <= width; i++){ ink += (double)hist[i] / ma * (width-i) / width; } cout << fixed << setprecision(10) << ink << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; map<int, vector<int>> mp; cin >> n; int arr[n]; int min = 1000000001; for (int i = 0; i < n; i++) { cin >> arr[i]; mp[arr[i]].push_back(i); if (arr[i] < min) min = arr[i]; } map<int, vector<int>>::iterator itr = mp.find(min); int ans = n + 2; vector<int> v1 = itr->second; for (int j = 1; j < v1.size(); j++) { if (v1[j] - v1[j - 1] < ans) ans = v1[j] - v1[j - 1]; } cout << ans; return 0; }
1
#include <bits/stdc++.h> using namespace std; long long binpow(long long a, long long b) { a %= 1000000007; long long res = 1; while (b > 0) { if (b & 1) res = res * a % 1000000007; a = a * a % 1000000007; b >>= 1; } return res; } void fun(int x, vector<int>& v) { if (x == 4) { v.push_back(3); v.push_back(2); v.push_back(2); } if (x == 6) { v.push_back(5); v.push_back(3); } if (x == 8) { v.push_back(7); v.push_back(2); v.push_back(2); v.push_back(2); } if (x == 9) { v.push_back(3); v.push_back(3); v.push_back(7); v.push_back(2); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; string s; cin >> s; int a[n]; for (long long i = 0; i < n; i++) { a[i] = s[i] - 48; } vector<int> v; for (long long i = 0; i < n; i++) { if (a[i] == 4 || a[i] == 6 || a[i] == 8 || a[i] == 9) { fun(a[i], v); } else v.push_back(a[i]); } sort(v.begin(), v.end(), greater<int>()); for (long long i = 0; i < v.size(); i++) { if (v[i] < 2) break; cout << v[i]; } }
1
#include <bits/stdc++.h> using namespace std; const int MAXS = 1000; char str[MAXS]; unsigned char pre; unsigned char rever(unsigned char now) { unsigned char ret = 0; for (unsigned int i = 0; i < 8; i++) ret |= ((now & (1 << i)) != 0) << (7 - i); return ret; } int main() { cin.getline(str, MAXS); pre = 0; for (int i = 0; str[i]; i++) { unsigned char res = pre - rever(str[i]); cout << (unsigned int)res << endl; pre = rever(str[i]); } return 0; }
1
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<map> #include<set> #include<utility> #include<cmath> #include<cstring> #include<queue> #include<cstdio> #include<sstream> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) #define pb push_back #define mp make_pair #define all(in) in.begin(),in.end() const double PI=acos(-1); const double EPS=1e-8; const int inf=1e9; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pii; int main(){ int n; cin>>n; while(n--){ string s=""; rep(i,8){ string q=""; char c;cin>>c; int t; if(isalpha(c))t=c-'a'+10; else t=c-'0'; rep(j,4){ q=(char)(t%2+'0')+q; t/=2; } s+=q; } int out=0; int t=1; for(int i=24;i>0;i--){ out+=t*(s[i]-'0'); t*=2; } if(s[0]=='1')cout<<"-"; cout<<out<<"."; // t=10000000; out=0; for(int i=25;i<32;i++){ t/=2; out+=t*(s[i]-'0'); } if(out==0)cout<<0<<endl; else{ int t=7; while(t>1&&out%10==0){out/=10;t--;} //cout<<out<<endl; printf("%0*d\n",t,out); } } }
0
#include <bits/stdc++.h> using namespace std; typedef bool boolean; #define ll long long void exgcd(int a, int b, int& x, int& y) { if (!b) { x = 1, y = 0; } else { exgcd(b, a % b, y, x); y -= (a / b) * x; } } int inv(int a, int n) { int x, y; exgcd(a, n, x, y); return (x < 0) ? (x + n) : (x); } const int Mod = 1e9 + 7; template <const int Mod = :: Mod> class Z { public: int v; Z() : v(0) { } Z(int x) : v(x){ } Z(ll x) : v(x % Mod) { } friend Z operator + (const Z& a, const Z& b) { int x; return Z(((x = a.v + b.v) >= Mod) ? (x - Mod) : (x)); } friend Z operator - (const Z& a, const Z& b) { int x; return Z(((x = a.v - b.v) < 0) ? (x + Mod) : (x)); } friend Z operator * (const Z& a, const Z& b) { return Z(a.v * 1ll * b.v); } friend Z operator ~(const Z& a) { return inv(a.v, Mod); } friend Z operator - (const Z& a) { return Z(0) - a; } Z& operator += (Z b) { return *this = *this + b; } Z& operator -= (Z b) { return *this = *this - b; } Z& operator *= (Z b) { return *this = *this * b; } friend boolean operator == (const Z& a, const Z& b) { return a.v == b.v; } }; Z<> qpow(Z<> a, int p) { Z<> rt = Z<>(1), pa = a; for ( ; p; p >>= 1, pa = pa * pa) { if (p & 1) { rt = rt * pa; } } return rt; } typedef Z<> Zi; const int N = 1e3 + 5; int n; int L = -1, D; vector<int> G[N]; Zi g[N][N], fl[N], fr[N], _g[N], h[N]; void find_far(int p, int fa, int d, int& mxd, int& id) { if (d > mxd) { mxd = d; id = p; } for (auto e : G[p]) { if (e ^ fa) { find_far(e, p, d + 1, mxd, id); } } } int da, db; void get_diameter() { int mxd = -1; find_far(1, 0, 0, mxd, da); find_far(da, 0, 0, L, db); D = (L + 1) >> 1; } bool ind[N]; vector<int> dia; void get_chain(int p, int fa) { dia.push_back(p); if (p == db) { throw 1; } for (auto e : G[p]) { if (e ^ fa) { get_chain(e, p); } } dia.pop_back(); } void dfs(int p, int fa, int l, int lmx) { for (auto e : G[p]) { if (e ^ fa) { dfs(e, p, l - 1, lmx); } } for (int i = 0; i <= lmx; i++) { Zi f1 = (!!i), f2 = (i < l); if (f1.v) { for (auto e : G[p]) { if (e ^ fa) { f1 *= g[e][i - 1]; } } } if (f2.v) { for (auto e : G[p]) { if (e ^ fa) { f2 *= g[e][i]; } } } g[p][i] = f1 + f2; } } Zi work_odd() { for (int i = 1; i <= n; i++) { fill(g[i], g[i] + n + 2, Zi(0)); } Zi ret = 0; g[dia[0]][0] = 1; fill(fl, fl + n + 2, Zi(0)); for (int i = 1; i < D; i++) { int ls = dia[i - 1], p = dia[i]; for (int j = 0; j < i; j++) { g[p][j + 1] += g[ls][j]; g[p][j] += g[ls][j]; } for (int j = i; j; j--) { fl[j] += fl[j - 1]; } for (auto e : G[p]) { if (!ind[e]) { int l = i; dfs(e, p, l, l); copy(g[p], g[p] + l + 1, _g); copy(g[e], g[e] + l + 1, h); for (int j = 0; j <= l; j++) { g[p][j] *= g[e][j]; } dfs(e, p, l + 1, l); for (int j = 0; j <= l; j++) { fl[j] = fl[j] * g[e][j] + _g[j] * (g[e][j] - h[j]); } } } } g[dia[L]][0] = 1; fill(fr, fr + n + 2, Zi(0)); for (int i = L - 1; i >= D; i--) { int ls = dia[i + 1], p = dia[i]; for (int j = 0; j < L - i; j++) { g[p][j + 1] += g[ls][j]; g[p][j] += g[ls][j]; } for (int j = L - i; j; j--) { fr[j] += fr[j - 1]; } for (auto e : G[p]) { if (!ind[e]) { int l = L - i; dfs(e, p, l, l); copy(g[p], g[p] + l + 1, _g); copy(g[e], g[e] + l + 1, h); for (int j = 0; j <= l; j++) { g[p][j] *= g[e][j]; } dfs(e, p, l + 1, l + 1); for (int j = 0; j <= l; j++) { fr[j] = fr[j] * g[e][j + 1] + _g[j] * (g[e][j + 1] - h[j]); } } } } int x = dia[D - 1], y = dia[D]; for (int j = 0; j <= L; j++) { ret += (g[x][j] + fl[j]) * (g[y][j] + fr[j]) - fl[j] * fr[j]; } for (int i = 1; i <= n; i++) { fill(g[i], g[i] + n + 2, Zi(0)); } g[dia[0]][0] = 1; fill(fl, fl + n + 2, Zi(0)); for (int i = 1; i < D; i++) { int ls = dia[i - 1], p = dia[i]; for (int j = 0; j < i; j++) { g[p][j + 1] += g[ls][j]; g[p][j] += g[ls][j]; } for (int j = i; j; j--) { fl[j] += fl[j - 1]; } for (auto e : G[p]) { if (!ind[e]) { int l = i; dfs(e, p, l, l); copy(g[p], g[p] + l + 1, _g); copy(g[e], g[e] + l + 1, h); for (int j = 0; j <= l; j++) { g[p][j] *= g[e][j]; } dfs(e, p, l + 1, l + 1); for (int j = 0; j <= l; j++) { fl[j] = fl[j] * g[e][j + 1] + _g[j] * (g[e][j + 1] - h[j]); } } } } g[dia[L]][0] = 1; fill(fr, fr + n + 2, Zi(0)); for (int i = L - 1; i >= D; i--) { int ls = dia[i + 1], p = dia[i]; for (int j = 0; j < L - i; j++) { g[p][j + 1] += g[ls][j]; g[p][j] += g[ls][j]; } for (int j = L - i; j; j--) { fr[j] += fr[j - 1]; } for (auto e : G[p]) { if (!ind[e]) { int l = L - i; dfs(e, p, l, l); copy(g[p], g[p] + l + 1, _g); copy(g[e], g[e] + l + 1, h); for (int j = 0; j <= l; j++) { g[p][j] *= g[e][j]; } dfs(e, p, l + 1, l); for (int j = 0; j <= l; j++) { fr[j] = fr[j] * g[e][j] + _g[j] * (g[e][j] - h[j]); } } } } for (int j = 0; j <= L; j++) { ret += (g[x][j] + fl[j]) * (g[y][j + 1] + fr[j + 1]) - fl[j] * fr[j + 1]; } return ret; } int main() { scanf("%d", &n); for (int i = 1, u, v; i < n; i++) { scanf("%d%d", &u, &v); G[u].push_back(v); G[v].push_back(u); } get_diameter(); try { get_chain(da, 0); } catch(int) { } for (auto p : dia) { ind[p] = true; } Zi ans = 0; if (!L) { ans = 1; } else if (L & 1) { ans = work_odd() * 2; } else { g[dia[0]][0] = 1; for (int i = 1; i <= D; i++) { int ls = dia[i - 1], p = dia[i]; for (int j = 0; j < i; j++) { g[p][j + 1] += g[ls][j]; g[p][j] += g[ls][j]; } for (auto e : G[p]) { if (!ind[e]) { dfs(e, p, i, i); for (int j = 0; j <= i; j++) { g[p][j] *= g[e][j]; } } } } g[dia[L]][0] = 1; for (int i = L - 1; i > D; i--) { int ls = dia[i + 1], p = dia[i]; for (int j = 0; j < L - i; j++) { g[p][j + 1] += g[ls][j]; g[p][j] += g[ls][j]; } for (auto e : G[p]) { if (!ind[e]) { dfs(e, p, L - i, L - i); for (int j = 0; j <= L - i; j++) { g[p][j] *= g[e][j]; } } } } int x = dia[D], y = dia[D + 1]; for (int j = 0; j <= L; j++) { ans += g[x][j] * g[y][j]; if (j) { ans += g[x][j] * g[y][j - 1]; } } } printf("%d\n", ans.v); return 0; }
0
//Largest Rectangle #include <iostream> #include <algorithm> #include <stack> #include <vector> using namespace std; class Rectangle { public: int pos, height; Rectangle(int pos, int height): pos(pos), height(height) {} }; int largestRectangle(int h, int w, vector<vector<int>> &G) { vector<vector<int>> dp(h+1, vector<int>(w+1, 0)); for(int i=1; i<h+1; i++) { for(int j=1; j<w+1; j++) { if(G[i][j] == 1) continue; dp[i][j] = dp[i-1][j]+1; } } int s = 0; stack<Rectangle> st; for(int i=1; i<h+1; i++) { for(int j=1; j<w+1; j++) { Rectangle rect = Rectangle(j, dp[i][j]); if(st.empty()) st.push(rect); else if(dp[i][j] > st.top().height) st.push(rect); else if(dp[i][j] < st.top().height) { int pos = j; while(!st.empty() && st.top().height > dp[i][j]) { s = max(s, st.top().height * (j - st.top().pos)); pos = st.top().pos; st.pop(); } rect.pos = pos; st.push(rect); } } while(!st.empty()) { s = max(s, st.top().height * (w + 1 - st.top().pos)); st.pop(); } } return s; } int main() { int h, w; cin >> h >> w; vector<vector<int>> G(h+1, vector<int>(w+1, 1)); for(int i=1; i<h+1; i++) for(int j=1; j<w+1; j++) cin >> G[i][j]; cout << largestRectangle(h, w, G) << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = (int)4e6; int n, m; int cnt[maxn], d[maxn]; int head, tail; int q[maxn]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &d[i]); } scanf("%d", &m); for (int i = 0; i < m; ++i) { int x; scanf("%d", &x); --x; cnt[x]++; } if (m == 1) { puts("0"); return 0; } int zero = 0; for (int i = 0; i < n; ++i) if (cnt[i] == 0) zero++; int c = 0, cd = 1; long long curlen = 0; set<long long> S; q[tail++] = 0; if (cnt[c] == 0) zero--; cnt[c]--; if (cnt[c] == 0) zero++; for (int i = 0; S.size() < 2 && i < 2 * n + 2 * m; ++i) { if (tail - head == m) { curlen -= abs(d[q[head]] - d[q[head + 1]]); if (cnt[q[head]] == 0) zero--; cnt[q[head]]++; if (cnt[q[head]] == 0) zero++; head++; } if (c == n - 1) cd = -1; if (c == 0) cd = 1; curlen += abs(d[c + cd] - d[c]); c += cd; q[tail++] = c; if (cnt[c] == 0) zero--; cnt[c]--; if (cnt[c] == 0) zero++; if (tail - head == m && zero == n) { S.insert(curlen); } } if (S.size() != 1) { puts("-1"); } else { cout << *S.begin() << endl; } return 0; }
5
#include <iostream> #include <cstdio> #include <cstring> using namespace std; int main(){ int n,data[11][11]; while(1){ cin>>n; if(n==0)break; for(int i=0;i<n;i++){ data[n][i]=0; for(int j=0;j<n;j++){ cin>>data[j][i]; data[n][i]+=data[j][i]; } } for(int i=0;i<=n;i++){ data[i][n]=0; for(int j=0;j<n;j++){ data[i][n]+=data[i][j]; } } for(int i=0;i<=n;i++){ for(int j=0;j<=n;j++){ printf("%5d",data[j][i]); } cout<<endl; } } return 0; }
0
#include <bits/stdc++.h> using namespace std; long long int MOD = 998244353; long long int mod = 1e9 + 7; long long int INF = 1e18; long long int dx[] = {1, -1, -1, 1}; long long int dy[] = {1, -1, 1, -1}; long long int binpow(long long int a, long long int b) { if (b == 0) return 1; long long int res = binpow(a, b / 2); if (b % 2 == 1) return res * res * a; else return res * res; } long long int loga(long long int n) { double ans = (log((double)n)) / (log(2.0)); ans = ceil(ans); return (long long int)ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m; cin >> n >> m; m = m * 8; map<long long int, long long int> k; long long int a[n]; vector<long long int> freq; freq.push_back(0); for (int i = 0; i < n; i++) { cin >> a[i]; k[a[i]]++; } if (n * loga(k.size()) <= m) m = k.size(); else { m = m / n; m = binpow(2, m); } for (auto j : k) { freq.push_back(j.second); } for (int i = 2; i < freq.size(); i++) freq[i] = freq[i] + freq[i - 1]; if (m + 1 >= freq.size()) cout << 0; else { long long int ans = 0; for (int i = m; i < freq.size(); i++) ans = max(ans, freq[i] - freq[i - m]); cout << freq[freq.size() - 1] - ans; } return 0; }
3
#include <bits/stdc++.h> using namespace std; const int N = 5000005; int prime[N + 2]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); for (int i = 2; i <= N; i++) { if (!prime[i]) for (int j = i; j <= N; j += i) { prime[j] = prime[j / i] + 1; } } for (int i = 2; i <= N; i++) { prime[i] += prime[i - 1]; } int t; cin >> t; while (t--) { int a, b; cin >> a >> b; cout << prime[a] - prime[b] << '\n'; ; } }
4
#include <bits/stdc++.h> using namespace std; int main() { for (int i = 21; i <= 50; i++) cout << ((min(i, 25) + i) % (2 + (i % 3)) > 0) << endl; return 0; }
5
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int num[111111], n, a, b, timer = 1, val[111111]; vector<int> graf[111111]; void dfs(int v, int prev) { printf("%d ", val[v]); for (int i = 0; i < graf[v].size(); i++) { int now = graf[v][i]; if (now == prev) continue; dfs(now, v); } } int main() { cin >> n; for (int i = 0; i < n; i++) { scanf("%d%d", &a, &b); int aa = mp[a]; int bb = mp[b]; if (aa == 0) { aa = timer++; mp[a] = aa; val[aa] = a; } if (bb == 0) { bb = timer++; mp[b] = bb; val[bb] = b; } num[aa]++; num[bb]++; graf[aa].push_back(bb); graf[bb].push_back(aa); } for (int i = 1; i <= n; i++) { if (num[i] == 1) { dfs(i, -1); return 0; } } return 0; }
3
#include <iostream> using namespace std; int main(){ int x,y; cin>>x>>y; int ans=0; ans+=max((4-x)*100000,0); ans+=max((4-y)*100000,0); if(ans==600000)ans=1000000; cout <<ans<<endl; }
0
#include<bits/stdc++.h> using namespace std; int a,b; int main(){ scanf("%d %d",&a,&b); if(a+b==15) puts("+"); else if(a*b==15) puts("*"); else puts("x"); return 0; }
0
#include <bits/stdc++.h> #define fo(a,b,c) for (a=b; a<=c; a++) #define fd(a,b,c) for (a=b; a>=c; a--) #define max(a,b) (a>b?a:b) #define min(a,b) (a<b?a:b) #define ll long long //#define file using namespace std; int d[250001],n,i,j,k,l,l1,l2,x,y,t; ll a[501][501],mx,s; map<ll,bool> mp; bool bz[1000001]; ll gcd(ll x,ll y) {ll r=x%y; while (r) x=y,y=r,r=x%y; return y;} ll lcm(ll x,ll y) {ll s=gcd(x,y);return (x/s)*(y/s)*s;} int main() { #ifdef file freopen("agc027d.in","r",stdin); freopen("agc027d.out","w",stdout); #endif scanf("%d",&n),s=((n+1)/2)*((n+1)/2); i=2; while (t<s) { if (!bz[i] && !bz[i*2]) d[++t]=i,bz[i]=bz[i*2]=1; ++i; } l1=0,l2=t+1; fo(i,1,n) { fo(j,1,n) if ((i&1) && (j&1)) { if (((i+j)/2)&1) { ++l1; a[i][j]=d[l1]; if (i<n && j<n) a[i+1][j+1]=d[l1]*2; } else { --l2; a[i][j]=d[l2]; if (i<n && j<n) a[i+1][j+1]=d[l2]*2; } } } fo(i,1,n) fo(j,1,n) if (a[i][j]) mp[a[i][j]]=1; mx=0; fo(i,1,n) { fo(j,1,n) if (!a[i][j]) { a[i][j]=1; if (i>1) a[i][j]=lcm(a[i][j],a[i-1][j]); if (i<n) a[i][j]=lcm(a[i][j],a[i+1][j]); if (j>1) a[i][j]=lcm(a[i][j],a[i][j-1]); if (j<n) a[i][j]=lcm(a[i][j],a[i][j+1]); s=a[i][j],++a[i][j]; while (mp[a[i][j]]) a[i][j]+=s; mp[a[i][j]]=1; mx=max(mx,a[i][j]); } } fo(i,1,n) { fo(j,1,n) printf("%lld ",a[i][j]); printf("\n"); } fclose(stdin); fclose(stdout); return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18 + 5; const long long naxN = 1e2 + 5; long long fact[naxN], inv_fact[naxN]; long long power(long long a, long long n) { long long res = 1; while (n) { if (n % 2) res = (res * a) % 1000000007, n--; else a = (a * a) % 1000000007, n /= 2; } return res; } void init() { fact[0] = inv_fact[0] = 1; for (long long i = 1; i < naxN; i++) { fact[i] = (i * fact[i - 1]) % 1000000007; inv_fact[i] = power(fact[i], 1000000007 - 2) % 1000000007; } } long long ncr(long long a, long long b) { if (a < 0 || b < 0 || a < b) return 0; return (fact[a] % 1000000007 * inv_fact[b] % 1000000007 * inv_fact[a - b] % 1000000007) % 1000000007; } const long long maxN = 1e5 + 5; void solve() { long long n; cin >> n; vector<long long> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; for (long long i = 0; i < n; i++) { if (i % 2 == 0) cout << v[i + 1] << " "; else cout << -v[i - 1] << " "; } cout << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(6); long long T = 1; cin >> T; while (T--) { solve(); } }
1
#include<bits/stdc++.h> using namespace std; int N,M; int G[20][20],U[110],V[110],W[110]; int Sum[(1<<15)+5],F[(1<<15)+5][20]; int main() { int i,j,k,s; scanf("%d%d",&N,&M); for(i=1; i<=M; i++) { scanf("%d%d%d",&U[i],&V[i],&W[i]); U[i]--,V[i]--; G[U[i]][V[i]]=G[V[i]][U[i]]=W[i]; } for(i=0; i<1<<N; i++) for(j=1; j<=M; j++) if(i>>U[j]&1&&i>>V[j]&1) Sum[i]+=W[j]; memset(F,-0x3f,sizeof(F)); F[1][0]=0; for(i=1; i<1<<N; i++) for(j=0; j<N; j++) if(F[i][j]>=0) { s=(1<<N)-1-i; for(k=s; k; k=(k-1)&s) F[i|k][j]=max(F[i|k][j],F[i][j]+Sum[k|1<<j]); if(~i>>N-1&1) for(k=0; k<N; k++) if(~i>>k&1&&G[j][k]) F[i|1<<k][k]=max(F[i|1<<k][k],F[i][j]+G[j][k]); } printf("%d\n",Sum[(1<<N)-1]-F[(1<<N)-1][N-1]); return 0; }
0
#include <bits/stdc++.h> using namespace std; template <class T> T &get(T &n) { cin >> n; return n; } int main() { int T, N, i, j; ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long row; char col; cin >> row >> col; row--; col -= 'a'; long long ans = 0; ans += (row / 4) * 16; row %= 4; vector<int> order = {5, 4, 3, 0, 1, 2}; vector<vector<int>> matrix(4, vector<int>(6)); int time = 0; for (auto it = (order).begin(); it != (order).end(); it++) { ++time; matrix[0][*it] = time; matrix[2][*it] = time; } time++; for (auto it = (order).begin(); it != (order).end(); it++) { ++time; matrix[1][*it] = time; matrix[3][*it] = time; }; ans += matrix[row][col]; cout << ans << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; int n, m; int g[405][405]; vector<int> v[405]; double ans; double gai[405]; double pos[405]; double suan(int yi, int juli) { memset(gai, 0, sizeof(gai)); for (int i = 1; i <= n; i++) { if (g[i][yi] == juli) { for (int j = 0; j < (int)v[i].size(); j++) { gai[v[i][j]] += 1.0 / n / (int)v[i].size(); } } } vector<int> r; r.clear(); for (int i = 1; i <= n; i++) if (gai[i]) r.push_back(i); double ret = 0; for (int i = 1; i <= n; i++) { double tmp = 0; for (int j = 0; j < (int)r.size(); j++) { pos[g[i][r[j]]] = max(pos[g[i][r[j]]], gai[r[j]]); } for (int j = 0; j < (int)r.size(); j++) { tmp += pos[g[i][r[j]]]; pos[g[i][r[j]]] = 0; } ret = max(ret, tmp); } return ret; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) if (i != j) g[i][j] = 199912310; } for (int i = 1; i <= m; i++) { int x, y, z; scanf("%d%d", &x, &y); g[x][y] = 1; g[y][x] = 1; v[x].push_back(y); v[y].push_back(x); } for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) g[i][j] = g[j][i] = min(g[i][j], g[i][k] + g[k][j]); } } for (int i = 1; i <= n; i++) { double now = 0; for (int dist = 0; dist < n; dist++) { int cnt = 0; for (int j = 1; j <= n; j++) { if (g[i][j] == dist) cnt++; } if (!cnt) continue; double p = 1.0 / n; double q = suan(i, dist); now += max(p, q); } ans = max(ans, now); } printf("%.8lf\n", ans); return 0; }
4
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> x; int main() { cin >> n >> k; for (int i = 1, j = n; i <= j; i++, j--) { x.push_back(i); if (i != j) x.push_back(j); } for (int i = 0; i < k; i++) cout << x[i] << ' '; sort(x.begin() + k, x.end()); if (k % 2 == 0) reverse(x.begin() + k, x.end()); for (int i = k; i < x.size(); i++) cout << x[i] << ' '; }
1
#include <bits/stdc++.h> inline long long rd() { long long _x = 0; int _ch = getchar(), _f = 1; for (; !isdigit(_ch) && (_ch != '-') && (_ch != EOF); _ch = getchar()) ; if (_ch == '-') { _f = 0; _ch = getchar(); } for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - '0'; return _f ? _x : -_x; } void write(long long _x) { if (_x >= 10) write(_x / 10), putchar(_x % 10 + '0'); else putchar(_x + '0'); } inline void wrt(long long _x, char _p) { if (_x < 0) putchar('-'), _x = -_x; write(_x); if (_p) putchar(_p); } int n, m; int a[5005]; int f[5005], h[5005], L[5005], R[5005]; int col[5005][4]; bool tag[5005]; int main() { n = rd(), m = rd(); for (int i = 1; i <= n; i++) a[i] = rd(); for (int i = 1; i <= m; i++) { f[i] = rd(), h[i] = rd(); L[i] = n + 1; for (int j = 1, t = h[i]; j <= n; j++) if (a[j] == f[i]) { t--; if (t == 0) { L[i] = j; break; } } for (int j = n, t = h[i]; j >= 1; j--) if (a[j] == f[i]) { t--; if (t == 0) { R[i] = j; break; } } if (L[i] == n + 1) { i--, m--; continue; } tag[L[i]] = 1; } if (m == 0) { wrt(0, ' '), wrt(1, '\n'); return 0; } tag[0] = 1; int mx = 0, sum = 0; for (int i = 0; i <= n; i++) if (tag[i]) { memset(col, 0, sizeof col); for (int j = 1; j <= m; j++) if (L[j] != i) { int cnt = 0; if (L[j] < i) cnt++; if (R[j] > i) cnt += 2; col[f[j]][cnt]++; } int A = i > 0, B = 1; for (int j = 1; j <= n; j++) if (a[i] != j) { int X = col[j][1] * col[j][2]; int Y = col[j][3] * (col[j][3] - 1); int Z = col[j][1] * col[j][3] + col[j][2] * col[j][3]; long long r1 = (long long)X + Y + Z; long long r2 = (long long)col[j][1] + col[j][2] + col[j][3] * 2; if (r1) A += 2, B = r1 * B % 1000000007; else if (r2) A++, B = r2 * B % 1000000007; } else { if (col[j][3] || col[j][2]) B = 1ll * B * (col[j][3] + col[j][2]) % 1000000007, A++; } if (A > mx) mx = A, sum = B; else if (A == mx) sum = (sum + B) % 1000000007; } wrt(mx, ' '), wrt(sum, '\n'); }
5
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> adj[1000]; stack<int> s; int pos[1000]; bool vis[1000]; void dfs(int i) { vis[i] = 1; for (auto j : adj[i]) if (!vis[j]) dfs(j); s.push(i); } int main() { scanf("%d", &n); scanf("%d", &m); for (int i = 1; i <= m; i++) { int x, y; scanf("%d", &x); scanf("%d", &y); adj[x].push_back(y); } bool y = 0; for (int i = 1; i <= n; i++) { int in = 1; for (int j = 1; j <= n; j++) vis[j] = 0; dfs(i); for (int j = 1; j <= n; j++) if (!vis[j]) dfs(j); while (s.size()) { pos[s.top()] = in++; s.pop(); } int cnt = 0; for (int i = 1; i <= n; i++) for (auto j : adj[i]) if (pos[j] < pos[i]) cnt++; if (cnt <= 1) y = 1; } if (y) printf("YES\n"); else printf("NO\n"); return 0; }
4
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > l[300009]; vector<pair<long long int, int> > lol; vector<int> temp; set<pair<long long int, int> > possible; long long int dp[300009][2]; void dfs(int ver, int par, int typ) { for (auto it : l[ver]) { if (it.first == par) { continue; } dp[it.first][typ] = dp[ver][typ] + it.second; dfs(it.first, ver, typ); } } int main() { int i, j, t1, t2, t3, t4, n, m, v1, v2; long long int buf1, buf2, buf3, ans, maxi = -1e9; scanf("%d %d", &n, &m); for (i = 0; i < n - 1; i++) { scanf("%d %d %d", &t1, &t2, &t3); l[t1].push_back(make_pair(t2, t3)); l[t2].push_back(make_pair(t1, t3)); } dfs(1, -1, 0); dfs(n, -1, 1); for (i = 1; i <= n; i++) { lol.push_back(make_pair(dp[i][0] - dp[i][1], i)); possible.insert(make_pair(dp[i][1], i)); } sort(lol.begin(), lol.end()); for (i = 0; i < n; i++) { t1 = lol[i].second; possible.erase(make_pair(dp[t1][1], t1)); temp.clear(); for (auto it : l[t1]) { t2 = it.first; if (possible.find(make_pair(dp[t2][1], t2)) != possible.end()) { temp.push_back(t2); possible.erase(make_pair(dp[t2][1], t2)); } } if (!possible.empty()) { auto it = possible.rbegin(); buf1 = it->first; t2 = it->second; buf1 += dp[t1][0]; if (buf1 > maxi) { maxi = buf1; v1 = t1; v2 = t2; } } for (auto it : temp) { possible.insert(make_pair(dp[it][1], it)); } } for (i = 0; i < m; i++) { scanf("%d", &t1); buf1 = dp[v1][0] + dp[v2][1] + t1; buf2 = dp[v1][1] + dp[v2][0] + t1; ans = min(dp[n][0], min(buf1, buf2)); printf("%lld\n", ans); } return 0; }
6
#include <bits/stdc++.h> using namespace std; vector<int> ans; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { bool good = true; for (int j = 0; j < n; ++j) { int res; cin >> res; if (res == 1 || res == 3) good = false; } if (good) ans.push_back(i + 1); } cout << ans.size() << endl; for (int i = 0; i < (int)ans.size(); ++i) cout << ans[i] << " "; return 0; }
1
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } vector<long long> primeFact(long long n) { vector<long long> ans; for (long long t = 2; t <= sqrt(n); t++) { if (n % t == 0) { ans.push_back(t); while (n % t == 0) { n = n / t; } } } if (n > 2) ans.push_back(n); return ans; } vector<long long> fact(long long n) { vector<long long> ans; for (long long i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (i * i == n) { ans.push_back(i); } else { ans.push_back(i); ans.push_back(n / i); } } } return ans; } long long powerr(long long base, long long exp, long long mod) { if (exp == 0) return 1; long long t = powerr(base, exp / 2, mod) % mod; if (exp % 2 == 0) { return (t % mod * t % mod) % mod; } else { return (t % mod * t % mod * base % mod) % mod; } } void fastio() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int32_t main() { fastio(); long long n, a, b, k; cin >> n >> a >> b >> k; string s; cin >> s; s = " " + s; vector<long long> dp(n + 1, 0); vector<pair<long long, long long> > ans(n + 1); long long pos = -1; for (long long i = 1; i <= n; i++) { if (s[i] == '0') { pos++; ans[pos] = {i, 0}; for (; i <= n; i++) { if (s[i] == '0') { ans[pos] = {ans[pos].first, ans[pos].second + 1}; } else { break; } } } } deque<long long> fa; for (long long i = 0; i <= pos; i++) { for (long long j = ans[i].first + b - 1; j < ans[i].first + ans[i].second; j += b) { fa.push_back(j); } } for (long long i = 0; i < a - 1; i++) { fa.pop_front(); } cout << fa.size() << "\n"; for (long long i = 0; i < fa.size(); i++) { cout << fa[i] << " "; } cout << "\n"; return 0; }
4
#include <bits/stdc++.h> using namespace std; long long s[1000003], a[2][1000003], p[2][1000003], n, ans, r, d; int main() { cin >> n; for (int i = 0; i < 2; i++) for (int j = 0; j < n; j++) scanf("%d", &a[i][j]); for (int i = n - 1; i >= 0; i--) s[i] = s[i + 1] + a[0][i] + a[1][i]; for (int i = n - 1; i >= 0; i--) p[0][i] = p[0][i + 1] + s[i + 1] + ((n - i) * 2 - 1) * a[1][i]; for (int i = n - 1; i >= 0; i--) p[1][i] = p[1][i + 1] + s[i + 1] + ((n - i) * 2 - 1) * a[0][i]; for (int i = 0; i < n; i++) { ans = max(ans, p[i & 1][i] + s[i] * i * 2 + r); r += d * a[i & 1][i]; d++; r += d * a[(i + 1) & 1][i]; d++; } cout << ans << endl; }
3
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; const long long inf = 1e18 + 10; int n; vector<int> G[maxn]; vector<pair<int, int> > ans; int du[maxn]; int T; void dfs(int u, int fa, int pre) { int i = pre; int j = (int)G[u].size() - 1; ans.push_back({u, pre}); for (auto v : G[u]) { if (v == fa) continue; if (++i <= T) { dfs(v, u, i); } else { i = pre - j - 1; ans.push_back({u, i}); i++; dfs(v, u, i); } ans.push_back({u, i}); j--; } if (u != 1) { if (i + 1 != pre) { ans.push_back({u, pre - 1}); } } } int main(void) { scanf("%d", &(n)); for (int i = (1); i < (n); ++i) { int u, v; scanf("%d%d", &u, &v); du[u]++; du[v]++; T = max(du[u], T); T = max(du[v], T); G[v].push_back(u); G[u].push_back(v); } dfs(1, 0, 0); printf("%d\n", (int)ans.size()); for (auto e : ans) printf("%d %d\n", e.first, e.second); return 0; }
6
#include <bits/stdc++.h> using namespace std; vector<int> vec[100010]; long long a[100010]; long long s; int n; long long dfs(int f, int u, long long val) { int sz = vec[u].size(), v; long long ret = 0, mv = ((long long)1e18), tmp; if (sz == 1 && vec[u][0] == f) return (a[u] = ((val) < (a[u]) ? (val) : (a[u]))); if (u != 1) val = val / (sz - 1) * (sz - 1) / (sz - 1); else val = val / sz * sz / sz; for (int i = 0; i < sz; i++) { v = vec[u][i]; if (v == f) continue; tmp = dfs(u, v, val); mv = ((mv) < (tmp) ? (mv) : (tmp)); } while (true) { tmp = mv; for (int i = 0; i < sz; i++) { v = vec[u][i]; if (v == f) continue; if (a[v] > tmp) tmp = ((dfs(u, v, mv)) < (tmp) ? (dfs(u, v, mv)) : (tmp)); } if (tmp == mv) break; else mv = tmp; } for (int i = 0; i < sz; i++) if (vec[u][i] != f) ret += a[vec[u][i]]; return a[u] = ret; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%I64d", a + i), s += a[i]; for (int i = 1; i < n; i++) { int u, v; scanf("%d%d", &u, &v); vec[u].push_back(v); vec[v].push_back(u); } long long ret = dfs(0, 1, ((long long)1e18)); cout << s - ret << endl; return 0; }
4
#include <bits/stdc++.h> int a[100010]; char b[100010]; int main() { int damn = 1; int n, l = -1000000000, r = 1000000000, cnt = 0, z = 0; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); scanf("%s", &b); for (int i = 4; i < n; ++i) { if (!damn) { if (++cnt == 4) damn = 1; } else if (b[i] != b[i - 1]) { if (b[i] == '0' && b[i - 1] == '1') { z = r + 1; for (int j = 0; j < 5; ++j) z = std::min(z, a[i - j]); r = z - 1; } else if (b[i] == '1' && b[i - 1] == '0') { z = l - 1; for (int j = 0; j < 5; ++j) z = std::max(z, a[i - j]); l = z + 1; } damn = 0; cnt = 1; } } printf("%d %d\n", l, r); return 0; }
4
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void chkmax(T& x, U y) { if (x < y) x = y; } template <typename T, typename U> inline void chkmin(T& x, U y) { if (y < x) x = y; } int deg[110000]; const int MOD = 1e9 + 7; int main() { int n; cin >> n; if (n == 1) return puts("1"), 0; for (int i = 1; i < n; i++) { int u, v; scanf("%d%d", &u, &v); deg[u]++, deg[v]++; } int cnt = 0, cur = 1; for (int i = 1; i <= n; i++) { if (deg[i] == 1) cnt++; else cur = 2 * cur % MOD; } int ans = 1LL * (n + cnt) * cur % MOD; cout << ans << endl; return 0; }
5
#include <stdio.h> #include <iostream> #include <vector> #include <assert.h> #include <set> #include <map> #include <cmath> #include <queue> #include <stack> #include <string> #include <sstream> #include <memory.h> #include <time.h> #include <string.h> #include <stdlib.h> #include <algorithm> using namespace std; typedef long long ll; const int N = 100000; int n, a[N], b[N], c[N]; double fx(int i, double x) { return (-a[i] * x + c[i]) / b[i]; } vector<pair<double, int> > order; int BIT[N + 1]; void add(int idx, int val) { ++idx; while (idx <= n) { BIT[idx] += val; idx += idx&-idx; } } int get(int idx) { ++idx; int ret = 0; while (idx) { ret += BIT[idx]; idx -= idx&-idx; } return ret; } ll check(double x) { vector<pair<double, int> > q(n); for (int i = 0; i < n; ++i) { q[i].first = fx(i, x); q[i].second = i; } sort(q.begin(), q.end()); vector<int> loc(n); for (int i = 0; i < n; ++i) loc[q[i].second] = i; memset(BIT, 0, sizeof(BIT)); ll res = 0; for (int i = 0; i < n; ++i) { int x = loc[order[i].second]; res += i - get(x); add(x, 1); } return n*(n - 1) / 2 - res; } double calc() { order.resize(n); for (int i = 0; i < n; ++i) { order[i].first = fx(i, 1e14); order[i].second = i; } sort(order.begin(), order.end()); double l = -1e9, r = 1e9, m; for (int it = 0; it < 64; ++it) { m = (l + r) / 2; if (check(m) >= ((ll)n*(n - 1) / 2 + 1) / 2) r = m; else l = m; } return (l + r) / 2; } int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d%d%d", a + i, b + i, c + i); printf("%.12lf ", calc()); for (int i = 0; i < n; ++i) swap(a[i], b[i]); printf(" %.12lf\n", calc()); return 0; }
0
#include <bits/stdc++.h> int gcd(int a, int b) { if (a > b) { a = a + b; b = a - b; a = a - b; } if (b % a == 0) return a; return gcd(b % a, a); } int main() { int T, tc, n, k, d, l, r, tans, ans, sum, m, tgt; register int i; scanf("%d", &T); for (tc = 1; tc <= T; tc++) { scanf("%d %d", &n, &k); if (gcd(n, k) == 1) printf("Finite\n"); else printf("Infinite\n"); } }
1
#include <bits/stdc++.h> using namespace std; #define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++) template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; } template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; } typedef long long ll; int N; const double PI = acos(-1.0); int main() { while(scanf("%d",&N),N != -1){ double rad = 0.0,dist = 1.0; FOR(i,1,N){ double x = sqrt(1 + dist * dist); double d = acos(dist / x); rad += d; dist = x; } printf("%.10f\n%.10f\n",cos(rad) * dist,sin(rad) * dist); } return 0; }
0
#include<iostream> #include<string.h> #include<string> #include<stdio.h> #include<algorithm> #include<math.h> #include<vector> #include<queue> #include<map> #include<set> using namespace std; #define lowbit(x) (x)&(-x) #define rep(i,a,b) for (int i=a;i<=b;i++) #define per(i,a,b) for (int i=a;i>=b;i--) #define maxd 1000000007 typedef long long ll; const int N=200000; const double pi=acos(-1.0); int B,W; ll fac[200200],invfac[200200],f[200200],g[200200],bin[200200]; 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<='9')) {x=x*10+(ch-'0');ch=getchar();} return x*f; } ll qpow(int x,int y) { ll ans=1,sum=x; while (y) { if (y&1) ans=(ans*sum)%maxd; sum=(sum*sum)%maxd; y>>=1; } return ans; } ll inv(int x) {return qpow(x,maxd-2);} ll C(int n,int m) { if (m>n) return 0; return ((fac[n]*invfac[m])%maxd*invfac[n-m])%maxd; } int main() { int B=read(),W=read(); fac[0]=1;invfac[0]=1;bin[0]=1; ll inv2=inv(2); rep(i,1,N) fac[i]=(fac[i-1]*i)%maxd; invfac[N]=inv(fac[N]); per(i,N-1,1) invfac[i]=(invfac[i+1]*(i+1))%maxd; rep(i,1,N) bin[i]=(bin[i-1]<<1)%maxd; rep(i,1,B+W) { f[i]=(f[i-1]+(C(i-1,W-1)*inv(bin[i]))%maxd)%maxd; g[i]=(g[i-1]+(C(i-1,B-1)*inv(bin[i]))%maxd)%maxd; } rep(i,1,B+W) { ll tmp=(1+maxd-f[i-1]+maxd-g[i-1])%maxd, ans=((tmp*inv2)%maxd+f[i-1])%maxd; printf("%lld\n",ans); } return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, par[200000][18], dist[200000], ans[200000]; long long a[200000], b[200000], pre[200000]; vector<int> g[200000]; void dfs(int x) { for (int i = 1; i < 18; i++) par[x][i] = par[par[x][i - 1]][i - 1]; dist[x] = dist[par[x][0]] + 1; pre[x] = b[x]; if (x != 0) pre[x] += pre[par[x][0]]; for (int i = 0; i < g[x].size(); i++) dfs(g[x][i]); } void dfs2(int x) { for (int i = 0; i < g[x].size(); i++) { dfs2(g[x][i]); ans[x] += ans[g[x][i]]; } } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n - 1; i++) { cin >> par[i + 1][0] >> b[i + 1]; par[i + 1][0]--; g[par[i + 1][0]].push_back(i + 1); } dfs(0); for (int i = 0; i < n; i++) { ans[i]++; int cur = i; for (int j = 17; j >= 0; j--) { int x = par[cur][j]; long long y = pre[i] - pre[x]; if (y <= a[i]) cur = x; } if (cur != 0) ans[par[cur][0]]--; } dfs2(0); for (int i = 0; i < n; i++) { cout << ans[i] - 1 << " "; } cout << endl; }
2
#include <bits/stdc++.h> using namespace std; struct point { int x, y; }; point a, b; double d(point a, point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } int ok1(int ra, int rb) { double t = d(a, b); int t1 = ra - rb; if (t1 < 0) return 0; if (t - t1 < 1E-6) return 1; else return 0; } int ok2(int ra, int rb) { double t = d(a, b); int t1 = ra - rb; if (t1 < 0) t1 = -t1; if (t >= ra + rb - 1E-6) return 1; else return 0; } int main() { int ra, rb, Ra, Rb, ans = 0; cin >> a.x >> a.y >> ra >> Ra; cin >> b.x >> b.y >> rb >> Rb; if (ok1(ra, Rb) || ok1(rb, Ra) || ok2(Ra, Rb)) ans = 4; else { double t = d(a, b); if (t >= ra + Rb || t <= rb - ra) ans++; if (t >= rb + Ra || t <= ra - rb) ans++; if (ok1(Ra, Rb) || ok1(Rb, Ra)) ans++; } cout << ans << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; const int NIL = -1; void sizeDfs(const vector<vector<int>>& tree, const vector<bool>& isErased, const int x, const int father, vector<int>& sizes) { sizes[x] = 1; for (const auto& y : tree[x]) { if (y != father && !isErased[y]) { sizeDfs(tree, isErased, y, x, sizes); sizes[x] += sizes[y]; } } } void centerDfs(const vector<vector<int>>& tree, const vector<bool>& isErased, const vector<int>& sizes, const int root, const int x, const int father, int& center, int& bestSplitSize) { int splitSize = sizes[root] - sizes[x]; for (const auto& y : tree[x]) { if (y != father && !isErased[y]) { centerDfs(tree, isErased, sizes, root, y, x, center, bestSplitSize); splitSize = max(splitSize, sizes[y]); } } if (splitSize < bestSplitSize) { center = x; bestSplitSize = splitSize; } } int findCenter(const vector<vector<int>>& tree, const vector<bool>& isErased, const int root, vector<int>& sizes) { sizeDfs(tree, isErased, root, NIL, sizes); int center = root; int bestSplitSize = sizes[root]; centerDfs(tree, isErased, sizes, root, root, NIL, center, bestSplitSize); return center; } void solve(const vector<vector<int>>& tree, const int root, const char rank, vector<bool>& isErased, vector<int>& sizes, vector<char>& ranks) { const int center = findCenter(tree, isErased, root, sizes); isErased[center] = true; for (const auto& y : tree[center]) { if (!isErased[y]) { solve(tree, y, rank + 1, isErased, sizes, ranks); } } ranks[center] = rank; } vector<char> solve(const vector<vector<int>>& tree) { const int size = int(tree.size()); auto isErased = vector<bool>(size, false); auto sizes = vector<int>(size); auto ranks = vector<char>(size); solve(tree, 0, 'A', isErased, sizes, ranks); return ranks; } int main() { int size; cin >> size; auto tree = vector<vector<int>>(size); for (int i = 1; i < size; i++) { int x, y; cin >> x >> y; tree[x - 1].push_back(y - 1); tree[y - 1].push_back(x - 1); } const auto ranks = solve(tree); for (int x = 0; x < size; x++) { cout << ranks[x] << (x + 1 < size ? " " : "\n"); } return 0; }
3
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int SIZE = 3e5 + 10; int v[SIZE]; int nxt[SIZE][26], sz[SIZE]; char s[SIZE]; vector<int> e[SIZE]; void merge(int x, int y, int &num) { for (int i = 0; i < (26); ++i) { if (nxt[y][i]) { if (!nxt[x][i]) { num += sz[nxt[y][i]]; nxt[x][i] = nxt[y][i]; } else { sz[x] -= sz[nxt[x][i]]; merge(nxt[x][i], nxt[y][i], sz[nxt[x][i]]); sz[x] += sz[nxt[x][i]]; } } } } void dfs(int x, int lt) { sz[x] = 1; for (int i = 0; i < (((int)(e[x]).size())); ++i) { int y = e[x][i]; if (y == lt) continue; dfs(y, x); int c = s[y]; if (!nxt[x][c]) { sz[x] += sz[y]; nxt[x][c] = y; } else { sz[x] -= sz[nxt[x][c]]; if (sz[nxt[x][c]] < sz[y]) { swap(y, nxt[x][c]); } merge(nxt[x][c], y, sz[nxt[x][c]]); sz[x] += sz[nxt[x][c]]; } } v[x] += sz[x]; } int main() { int(N); scanf("%d", &N); for (int i = 0; i < (N); ++i) scanf("%d", &(v[i])); scanf("%s", (s)); for (int i = 0; i < (N); ++i) s[i] -= 'a'; for (int i = (1); i < (N); ++i) { int x, y; scanf("%d%d", &x, &y); x--; y--; e[x].push_back(y); e[y].push_back(x); } dfs(0, 0); pair<int, int> an = make_pair(0, 0); for (int i = 0; i < (N); ++i) { if (an.first < v[i]) { an = make_pair(v[i], 1); } else if (an.first == v[i]) an = make_pair(v[i], an.second + 1); } printf("%d\n%d\n", an.first, an.second); return 0; }
4
#include<iostream> #include<algorithm> #include<vector> #include<utility> #include<algorithm> using namespace std; int N; int l[523456],r[523456]; int nc[523456]; long long wos[523456]; long long mem[523456]; long long rec(int x,int d){ if(x==N)return 0; auto lr=rec(l[x],d+1),rr=rec(r[x],d+1); nc[x]=nc[l[x]]+nc[r[x]]; wos[x]=wos[l[x]]+nc[l[x]]+wos[r[x]]+nc[r[x]]; return min({nc[l[x]]+wos[l[x]]+rr+1, nc[r[x]]+wos[r[x]]+lr+1, lr+rr+2+d}); } int main(){ cin>>N; for(int i=1;i<N;i++){ cin>>l[i]>>r[i]; } nc[N]=1; vector<pair<int,int> > v; v.emplace_back(0,1); for(int i=0;i<v.size();i++){ int x=v[i].second; if(l[x]!=N){ v.emplace_back(v[i].first+1,l[x]); } if(r[x]!=N){ v.emplace_back(v[i].first+1,r[x]); } } for(int i=v.size()-1;i>=0;i--){ int x=v[i].second; auto lr=mem[l[x]],rr=mem[r[x]]; nc[x]=nc[l[x]]+nc[r[x]]; wos[x]=wos[l[x]]+nc[l[x]]+wos[r[x]]+nc[r[x]]; mem[x]=min({nc[l[x]]+wos[l[x]]+rr+1, nc[r[x]]+wos[r[x]]+lr+1, lr+rr+2+v[i].first}); } cout<<mem[1]<<endl; }
0
#include <bits/stdc++.h> using namespace std; template <typename... T> void read(T &...args) { ((cin >> args), ...); } template <typename... T> void write(T... args) { ((cout << args << ' '), ...); } const long long MOD = 1000000007; const long long INF = 1000000050; const long long BIG = (long long)2e18 + 50; const long long MX = 200010; const double EPS = 1e-9; long long a[MX]; bool good; long long m; vector<long long> g[MX]; long long sz[MX]; long long cnt[MX]; long long mx = 0; void dfs(long long v) { if (g[v].size() == 0) cnt[v] = 1; else cnt[v] = 0; sz[v] = a[v]; for (auto &to : g[v]) { dfs(to); cnt[v] += cnt[to]; sz[v] += sz[to]; } mx = max(mx, (sz[v] + cnt[v] - 1) / cnt[v]); } void solve() { long long n; cin >> n; long long arr[n]; for (long long i = 0; i < n; i++) cin >> arr[i]; if (n == 1) { cout << 0 << '\n'; return; } sort(arr, arr + n); long long mid = n / 2; long long ret1 = 0; long long ret2 = 0; long long arr_val[n]; for (long long i = 0; i < n; i++) { arr_val[i] = arr[mid] - mid + i; } if (arr_val[0] <= 0) { long long val = 1 - arr_val[0]; for (long long i = 0; i < n; i++) arr_val[i] += val; } for (long long i = 0; i < n; i++) { ret1 += abs(arr_val[i] - arr[i]); } write('\n'); for (long long i = 0; i < n; i++) write(arr_val[i]); if (n % 2 == 0) { mid--; for (long long i = 0; i < n; i++) { arr_val[i] = arr[mid] - mid + i; } if (arr_val[0] <= 0) { long long val = 1 - arr_val[0]; for (long long i = 0; i < n; i++) arr_val[i] += val; } for (long long i = 0; i < n; i++) { ret2 += abs(arr_val[i] - arr[i]); } } write('\n'); for (long long i = 0; i < n; i++) write(arr_val[i]); if (n % 2 == 0) cout << min(ret1, ret2); else cout << ret1; cout << "\n"; } long long arr[201]; long long dp[201][405]; long long n; long long recur(long long index, long long time) { if (index == n) return 0; if (dp[index][time] != -1) return dp[index][time]; long long ret = INT_MAX; for (long long i = time + 1; i <= 405; i++) { ret = min(ret, abs(arr[index] - i) + recur(index + 1, i)); } return dp[index][time] = ret; } void solveA() { cin >> n; memset(dp, -1, sizeof(dp)); for (long long i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); cout << recur(0, 0) << '\n'; } int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); long long x; cin >> x; while (x--) { solveA(); } }
3
#include <bits/stdc++.h> #pragma hdrstop #pragma argsused using namespace std; int main(int argc, char* argv[]) { int n, m; cin >> n >> m; vector<int> Y(n, 0), N(n, 0), Z(n); vector<bool> K(n, false); int yes = 0, no = 0; for (int i = 0; i < n; i++) { scanf("%d", &Z[i]); if (Z[i] > 0) { Y[Z[i] - 1]++; yes++; } else { N[-Z[i] - 1]++; no++; } } int killers = 0, tr = 0; for (int i = 0; i < n; i++) { tr = Y[i] + no - N[i]; if (tr == m) { K[i] = true; killers++; } } string s; for (int i = 0; i < n; i++) { if (Z[i] > 0) { if (K[Z[i] - 1]) s = killers == 1 ? "Truth" : "Not defined"; else s = "Lie"; cout << s << endl; } else { if (K[-Z[i] - 1]) s = killers == 1 ? "Lie" : "Not defined"; else s = "Truth"; cout << s << endl; } } return 0; }
2
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array int n, k, p[200001]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for(int i=0; i<n; ++i) { cin >> p[i+1]; p[i+1]+=p[i]; } int ans=0; for(int i=k; i<=n; ++i) { ans=max(ans, p[i]-p[i-k]); } cout << fixed << setprecision(9) << (double)(ans+k)/2.0; }
0
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; int na, nb, nc, ra, rb, rc, da, db, lim = 1594323, num[13], sp[110], ss, tp, vp, op; pair<double, double> p[110], rg[110], obj[110]; double v[110], f[110][110], g[110][110], ans; bool cmp(pair<double, double> x, pair<double, double> y) { return x.first > y.first; } double dp() { sort(obj + 1, obj + op + 1, cmp); for (int i = 0; i <= op + 1; i++) for (int j = 0; j <= op + 1; j++) f[i][j] = g[i][j] = 0; for (int i = op; i; i--) { for (int j = op - i; j; j--) g[i][j] = max(g[i + 1][j], g[i + 1][j - 1] + obj[i].second); g[i][op - i + 1] = g[i + 1][op - i] + obj[i].second; } for (int i = 1; i <= op; i++) { f[i][0] = f[i - 1][0] + obj[i].second; for (int j = 1; j < i; j++) f[i][j] = max(f[i - 1][j] + obj[i].second, f[i - 1][j - 1] + obj[i].first); f[i][i] = f[i - 1][i - 1] + obj[i].first; } double res = 0; for (int i = na; i <= min(na + nb, op); i++) res = max(res, f[i][na] + g[i + 1][nb - (i - na)]); return res; } double func(int ip) { ss = 0, tp = 0, vp = 0, op = 0; v[++vp] = 1e7, v[++vp] = -1e7; for (int i = 0; i < 13; i++) num[i] = ip % 3, ip /= 3, ss += num[i]; if (ss != nc) return 0; for (int i = 0; i < 13; i++) { if (num[i]) v[++vp] = i - sqrt(rc * rc - 1), v[++vp] = i + sqrt(rc * rc - 1); for (int j = 1; j <= num[i]; j++) rg[++tp] = make_pair(i - sqrt(rc * rc - 1), i + sqrt(rc * rc - 1)); } sort(v + 1, v + vp + 1); for (int i = 1; i < vp; i++) { sp[i] = 1; for (int j = 1; j <= tp; j++) if (v[i] - rg[j].first > -eps && v[i + 1] - rg[j].second < eps) sp[i]++; } for (int i = 0; i < 13; i++) { double x = i - sqrt(ra * ra - 1), y = i + sqrt(ra * ra - 1); p[i].first = p[i].second = 0; for (int j = 1; j < vp; j++) { double a = max(x, v[j]), b = min(v[j + 1], y); if (a - b > eps) continue; p[i].first += (b - a) * sp[j]; } x = i - sqrt(rb * rb - 1), y = i + sqrt(rb * rb - 1); for (int j = 1; j < vp; j++) { double a = max(x, v[j]), b = min(v[j + 1], y); if (a - b > eps) continue; p[i].second += (b - a) * sp[j]; } p[i].first *= da, p[i].second *= db; } for (int i = 0; i < 13; i++) for (int j = 1; j <= 2 - num[i]; j++) obj[++op] = p[i]; return dp(); } int main() { scanf("%d%d%d%d%d%d%d%d", &na, &nb, &nc, &ra, &rb, &rc, &da, &db); for (int i = 0; i < lim; i++) ans = max(ans, func(i)); printf("%.8lf\n", ans); return 0; }
5
#include <bits/stdc++.h> using namespace std; #define FOR(i,k,n) for(int i = (k); i < (n); i++) #define REP(i,n) FOR(i,0,n) #define ALL(a) a.begin(), a.end() #define MS(m,v) memset(m,v,sizeof(m)) #define D10 fixed<<setprecision(10) typedef vector<int> vi; typedef vector<string> vs; typedef pair<int, int> pii; typedef long long ll; const int INF = 114514810; const int MOD = 1000000007; const double EPS = 1e-10; typedef double weight; struct edge { int to; weight cost; bool operator < (const edge& e) const { return cost < e.cost; } bool operator >(const edge& e) const { return cost > e.cost; } }; typedef vector<edge> Edges; typedef vector<Edges> Graph; //int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 }; template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); } template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); } bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); } int place(int x, int y, int w) { return w*x + y; } ///*************************************************************************************/// ///*************************************************************************************/// ///*************************************************************************************/// typedef long double ld; const double PI = acos(-1.0); bool eq(double a, double b) { return fabs(a - b) < EPS; } typedef complex<double> Point; typedef vector<Point> Polygon; namespace std { bool operator < (const Point& a, const Point& b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); } } struct Line { Point a, b; Line(Point p, Point q) :a(p), b(q) {}; Line(double x1, double y1, double x2, double y2) :a(Point(x1, y1)), b(Point(x2, y2)) {}; }; struct Circle { Point p; double r; Circle(Point a, double b) :p(a), r(b) {}; }; double dot(Point a, Point b) { return real(conj(a)*b); } double cross(Point a, Point b) { return imag(conj(a)*b); } int ccw(Point a, Point b, Point c) { b -= a; c -= a; if (cross(b, c) > EPS) return 1; //counter cloclwise if (cross(b, c) < -EPS) return -1; //cloclwise if (dot(b, c) < 0) return 2; //c--a--b on line if (norm(b) < norm(c)) return -2; //a--b--c on line return 0; //a--c--b on line } bool isis_ll(Line l, Line m) { return abs(cross(l.b - l.a, m.b - m.a)) > EPS; } bool isis_ls(Line l, Line s) { return cross(l.b - l.a, s.a - l.a)*cross(l.b - l.a, s.b - l.a) < EPS; } bool isis_ss(Line s, Line t) { return (ccw(s.a, s.b, t.a)*ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a)*ccw(t.a, t.b, s.b) <= 0); } bool isis_lp(Line l, Point p) { return (abs(cross(l.b - p, l.a - p)) < EPS); } bool isis_sp(Line s, Point p) { return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a)) < EPS; } Point projection(Line l, Point p) { Point base = l.b - l.a; double r = dot(p - l.a, base) / norm(base); return l.a + base*r; } Point mirror(Line l, Point p) { return 2.0*projection(l, p) - p; } double dist_lp(Line l, Point p) { return abs(p - projection(l, p)); } double dist_ll(Line l, Line m) { return isis_ll(l, m) ? 0 : dist_lp(l, m.a); } double dist_ls(Line l, Line s) { if (isis_ls(l, s)) return 0; return min(dist_lp(l, s.a), dist_lp(l, s.b)); } double dist_sp(Line s, Point p) { Point r = projection(s, p); if (isis_sp(s, r)) return abs(r - p); return min(abs(s.a - p), abs(s.b - p)); } double dist_ss(Line s, Line t) { if (isis_ss(s, t)) return 0; return min(min(dist_sp(s, t.a), dist_sp(s, t.b)), min(dist_sp(t, s.a), dist_sp(t, s.b))); } Point is_ll(Line s, Line t) { double a = cross(s.b - s.a, t.b - t.a); double b = cross(s.b - s.a, s.b - t.a); return t.a + b / a*(t.b - t.a); } vector<Point> is_cc(Circle c1, Circle c2) { vector<Point> res; double d = abs(c1.p - c2.p); double rc = (d*d + pow(c1.r, 2) - pow(c2.r, 2)) / (2 * d); double dfr = pow(c1.r, 2) - rc*rc; if (abs(dfr) < EPS) dfr = 0; if (dfr < 0.0) return res; double rs = sqrt(dfr); Point diff = (c2.p - c1.p) / d; res.push_back(c1.p + diff*Point(rc, rs)); if (dfr != 0.0) res.push_back(c1.p + diff*Point(rc, -rs)); return res; } int isis_cc(Circle c1, Circle c2) { double d = abs(c1.p - c2.p); if (d - c1.r - c2.r < -EPS) return -2; //separate if (abs(d - c1.r - c2.r) < EPS) return -1; //circumscribe if (c1.r < c2.r) swap(c1, c2); if (abs(d - c1.r + c2.r) < EPS) return 1;//inscribe if (c1.r - d - c2.r>EPS) return 2;//involve else return 0;//intersect } vector<Line> tangent_cp(Circle c, Point p) { vector<Line> res; Point v = c.p - p; double d = abs(v); double l = sqrt(norm(v) - c.r * c.r); if (l<EPS) { return res; } Point v1 = v * Point(l / d, c.r / d); Point v2 = v * Point(l / d, -c.r / d); res.push_back(Line(p, p + v1)); if (l < EPS) return res; res.push_back(Line(p, p + v2)); return res; } vector<Line> tangent_cc(Circle c1, Circle c2) { vector<Line> res; if (abs(c1.p - c2.p) - (c1.r + c2.r) > -EPS) { Point center = (c1.p * c2.r + c2.p * c1.r) / (c1.r + c2.r); res = tangent_cp(c1, center); } if (abs(c1.r - c2.r) > EPS) { Point out = (-c1.p * c2.r + c2.p * c1.r) / (c1.r - c2.r); vector<Line> nres = tangent_cp(c1, out); res.insert(res.end(), nres.begin(), nres.end()); } else { Point v = c2.p - c1.p; v /= abs(v); Point q1 = c1.p + v * Point(0, 1) * c1.r; Point q2 = c1.p + v * Point(0, -1) * c1.r; res.push_back(Line(q1, q1 + v)); res.push_back(Line(q2, q2 + v)); } return res; } int main() { int n; while (cin >> n, n) { vector<Circle> cs; REP(i, n) { double x, y, r, m; cin >> x >> y >> r >> m; Point p(x, y); cs.push_back(Circle{ p, r }); cs.push_back(Circle{ p, r + m }); } int ans = 1; REP(i, cs.size())REP(j, i) { vector<Line> ls = tangent_cc(cs[i], cs[j]); REP(k, ls.size()) { int cnt = 0; REP(l, cs.size()) { if (l % 2) { if (dist_lp(ls[k], cs[l].p) - cs[l].r < EPS) cnt++; } else { if (dist_lp(ls[k], cs[l].p) - cs[l].r < -EPS) cnt--; } } chmax(ans, cnt); } } cout << ans << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; inline long long read() { char ch = getchar(); long long w = 1, c = 0; for (; !isdigit(ch); ch = getchar()) if (ch == '-') w = -1; for (; isdigit(ch); ch = getchar()) c = (c << 1) + (c << 3) + (ch ^ 48); return w * c; } const int M = 3e5 + 10; map<vector<vector<int> >, int> mp; vector<vector<int> > sg; long long a[M]; int x, y, z, n; int mex(int a, int b, int c) { int k = 0, ret = 0; k |= (1 << a); k |= (1 << b); k |= (1 << c); while (k & 1) ret++, k >>= 1; return ret; } void con() { int o = ((int)sg.size() - 1) + 1; vector<int> tmp(3, 0); tmp[0] = mex(sg[max(o - x, 0)][0], sg[max(o - y, 0)][1], sg[max(o - z, 0)][2]); tmp[1] = mex(sg[max(o - x, 0)][0], sg[max(o - z, 0)][2], 4); tmp[2] = mex(sg[max(o - x, 0)][0], sg[max(o - y, 0)][1], 4); sg.push_back(tmp); } int pre, len; int ral(long long x) { return (x <= pre ? x : (x - pre) % len + pre); } int s[10]; int main() { int T = read(); while (T--) { n = read(); x = read(); y = read(); z = read(); for (int i = (1); i <= (n); ++i) a[i] = read(); mp.clear(); sg.clear(); sg.push_back({0, 0, 0}); for (int i = (1); i <= (5); ++i) con(); while (1) { vector<vector<int> > tmp(sg.end() - 5, sg.end()); if (mp.count(tmp)) { pre = mp[tmp]; len = ((int)sg.size() - 1) - 4 - pre; break; } mp[tmp] = ((int)sg.size() - 1) - 4; con(); } int sumsg = 0; memset(s, 0, sizeof s); for (int i = (1); i <= (n); ++i) { long long val0 = ral(max(a[i] - x, 0ll)), val1 = ral(max(a[i] - y, 0ll)), val2 = ral(max(a[i] - z, 0ll)); int now = sg[ral(a[i])][0], X = sg[val0][0], Y = sg[val1][1], Z = sg[val2][2]; sumsg ^= now; s[X ^ now]++; s[Y ^ now]++; s[Z ^ now]++; } cout << s[sumsg] << "\n"; } return 0; }
6
#include <bits/stdc++.h> using namespace std; int N; char str[15]; int main() { scanf("%d", &N); while (N--) { scanf("%s", str); vector<pair<int, int> > ans; for (int a = 1; a <= 12; a++) if (12 % a == 0) { int b = 12 / a; for (int i = 0; i < b; i++) { bool is_ans = 1; for (int j = 0; j < a; j++) is_ans &= (str[i + j * b] == 'X'); if (is_ans) { ans.push_back(make_pair(a, b)); break; } } } printf("%u", ans.size()); for (size_t i = 0; i < ans.size(); i++) printf(" %dx%d", ans[i].first, ans[i].second); printf("\n"); } return 0; }
1
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long mod = 1e9 + 7; const long long maxn = 1e5 + 10, maxt = 100 + 10; long long pa[9][49]; long long n, ans; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; for (int i = 0; i < 9; i++) { for (int j = 0; j < 49; j++) { pa[i][j] = 1; } } for (int i = 0; i < 9; i++) { for (int j = 0; j < 49; j++) { for (int ip = 0; ip < 9; ip++) { for (int jp = 0; jp < 49; jp++) { long long x = 4 * ip + 9 * jp, y = 4 * i + 9 * j; if (x < y && !((y - x) % 49)) { pa[i][j] = 0; } } } } } cin >> n; for (int i = 0; i <= min(n, 8ll); i++) { for (int j = 0; j <= min(n - i, 48ll); j++) { if (pa[i][j]) { ans += n - i - j + 1; } } } cout << ans << endl; }
2
#include <bits/stdc++.h> using namespace std; long long a, b, n; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); long long t; scanf("%I64d", &t); while (t--) { scanf("%I64d%I64d%I64d", &a, &b, &n); if (n == 0) printf("%I64d\n", a); else if (n == 1) printf("%lld\n", b); else { long long x = a ^ b; if (n % 3 == 0) printf("%I64d\n", a); else if (n % 3 == 1) printf("%I64d\n", b); else if (n % 3 == 2) printf("%I64d\n", x); } } }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = cost; if (m > (T - t)) aux1 += m * x; long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1; aux2 *= cost; ans += min(aux1, aux2); } cout << ans << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; int n, m, b[300001], a[300001], l, r, mid, res; bool check(int x) { int y; for (int i = 1; i <= n; i++) b[i] = a[i]; for (int i = 1; i <= n; i++) { y = b[i - 1] - b[i]; if (y < 0) y += m; if (y <= x) b[i] = b[i - 1]; else if (b[i] < b[i - 1]) return 0; }; return 1; } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; l = 0; r = m; res = m; do { mid = (l + r) / 2; if (check(mid)) { r = mid - 1; res = min(res, mid); } else l = mid + 1; } while (l <= r); cout << res; return 0; }
3
#include <bits/stdc++.h> using namespace std; vector<long long> smPrime(1000000 + 2); vector<long long> primeAr; void prAr(vector<long long> a) { auto print = [](const long long &n) { cout << n << " "; }; for_each(a.begin(), a.end(), print); cout << endl; } void prAr(vector<vector<long long> > a) { auto print = [](const vector<long long> &n) { prAr(n); }; for_each(a.begin(), a.end(), print); cout << endl; } void seiveAtulAg() { long long i, j, k; for (i = 0; i < 1000000; i++) smPrime[i] = i; smPrime[0] = smPrime[1] = -1; for (i = 2; i <= 1000000; i += 2) smPrime[i] = 2; for (i = 3; i * i < 1000000; i += 2) { if (smPrime[i] == i) { for (j = i * i; j < 1000000; j += i) { smPrime[j] = i; } } } for (i = 2; i <= 1000000; i++) { if (smPrime[i] == i) { primeAr.push_back(i); } } } void pfact(long long &n, vector<pair<long long, long long> > &factAr) { factAr.clear(); long long i, loop = primeAr.size(), cnt; for (i = 0; i < loop && n > 1; i++) { cnt = 0; while (n > 1 && n % primeAr[i] == 0) { n /= primeAr[i]; cnt++; } if (cnt != 0) factAr.push_back({primeAr[i], cnt}); } } int main() { long long t, m, i, j, k, fpr, fcnt, lcm = 1, dm; seiveAtulAg(); vector<bool> hs(1000010, false); vector<long long> ans; cin >> m; vector<long long> ar(m, 0); for (i = 0; i < m; i++) { cin >> ar[i]; hs[ar[i]] = true; } bool pos = true; for (i = 1; i < m && pos; i++) { if (ar[i] % ar[0]) { pos = false; } } if (pos) { cout << (2 * ar.size() - 1) << endl; cout << ar[0] << " "; for (i = 1; i < m; i++) { cout << ar[i] << " " << ar[0] << " "; } } else { cout << "-1"; } return 0; }
3
#include <bits/stdc++.h> using namespace std; void update(int, int, int, int, int, int, int); long long int query(int, int, int, int, int, int, int); int l[200001], r[200001], c[200001]; pair<int, int> tree[2][10000001]; vector<int> v[200001]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, x, i, j; long long int ans = 1000000000000; cin >> n >> x; for (i = 0; i < n; i++) { cin >> l[i] >> r[i] >> c[i]; v[r[i] - l[i] + 1].push_back(i); } for (i = 1; i < x; i++) { for (j = 0; j < v[i].size(); j++) { if (x - i == i) { ans = min(ans, c[v[x - i][j]] + query(1, 1, 200000, r[v[x - i][j]] + 1, 200000, 0, i)); ans = min(ans, c[v[x - i][j]] + query(1, 1, 200000, 1, l[v[x - i][j]] - 1, 1, i)); } update(1, 1, 200000, l[v[i][j]], c[v[i][j]], 0, i); update(1, 1, 200000, r[v[i][j]], c[v[i][j]], 1, i); } if (x - i != i) { for (j = 0; j < v[x - i].size(); j++) { ans = min(ans, c[v[x - i][j]] + query(1, 1, 200000, r[v[x - i][j]] + 1, 200000, 0, i)); ans = min(ans, c[v[x - i][j]] + query(1, 1, 200000, 1, l[v[x - i][j]] - 1, 1, i)); } } } if (ans >= 1000000000000) cout << -1 << "\n"; else cout << ans << "\n"; return 0; } void update(int node, int st, int en, int id, int val, int fid, int d) { if (st == en) { if (tree[fid][node].second == d) tree[fid][node].first = min(tree[fid][node].first, val); else tree[fid][node] = {val, d}; return; } int mid = (st + en) / 2; if (id <= mid) update(2 * node, st, mid, id, val, fid, d); else update(2 * node + 1, mid + 1, en, id, val, fid, d); if (tree[fid][node].second == d) { if (tree[fid][2 * node].second == d) tree[fid][node].first = min(tree[fid][node].first, tree[fid][2 * node].first); if (tree[fid][2 * node + 1].second == d) tree[fid][node].first = min(tree[fid][node].first, tree[fid][2 * node + 1].first); } else { if (tree[fid][2 * node].second == d) tree[fid][node].first = tree[fid][2 * node].first; else tree[fid][node].first = tree[fid][2 * node + 1].first; tree[fid][node].second = d; } } long long int query(int node, int st, int en, int l, int r, int fid, int d) { if (r < st || en < l || r < l) return 1000000000000; if (tree[fid][node].second != d) return 1000000000000; if (l <= st && en <= r) return tree[fid][node].first; int mid = (st + en) / 2; long long int p1 = query(2 * node, st, mid, l, r, fid, d); long long int p2 = query(2 * node + 1, mid + 1, en, l, r, fid, d); return min(p1, p2); }
3
#include <bits/stdc++.h> using namespace std; struct unit { int w1, w2, w3, sw1, sw2, sw3; long long up, l, l1, l2, l3, s1, s2, s3; }; struct unit f[100010]; struct edge { int u, v, next; }; struct edge e[400010]; int n, num; int head[200010], a[200010]; long long ans; void add(int u, int v) { e[num].u = u; e[num].v = v; e[num].next = head[u]; head[u] = num; num++; e[num].u = v; e[num].v = u; e[num].next = head[v]; head[v] = num; num++; } void update(int i, int j) { if (f[i].l1 + a[j] > f[j].l1) { f[j].l3 = f[j].l2; f[j].w3 = f[j].w2; f[j].l2 = f[j].l1; f[j].w2 = f[j].w1; f[j].l1 = f[i].l1 + a[j]; f[j].w1 = i; } else if (f[i].l1 + a[j] > f[j].l2) { f[j].l3 = f[j].l2; f[j].w3 = f[j].w2; f[j].l2 = f[i].l1 + a[j]; f[j].w2 = i; } else if (f[i].l1 + a[j] > f[j].l3) { f[j].l3 = f[i].l1 + a[j]; f[j].w3 = i; } if (f[i].l > f[j].s1) { f[j].s3 = f[j].s2; f[j].sw3 = f[j].sw2; f[j].s2 = f[j].s1; f[j].sw2 = f[j].w1; f[j].s1 = f[i].l; f[j].sw1 = i; } else if (f[i].l > f[j].s2) { f[j].s3 = f[j].s2; f[j].sw3 = f[j].sw2; f[j].s2 = f[i].l; f[j].sw2 = i; } else if (f[i].l > f[j].s3) { f[j].s3 = f[i].l; f[j].sw3 = i; } f[j].l = max(f[j].l, f[i].l); } void work(int i, int fa) { int j, w1, w2; long long s1 = 0, s2 = 0; j = head[i]; f[i].l1 = a[i]; while (j != -1) { if (e[j].v != fa) { work(e[j].v, i); update(e[j].v, i); if (f[e[j].v].l > s1) { s2 = s1; s1 = f[e[j].v].l; } else if (f[e[j].v].l > s2) s2 = f[e[j].v].l; } j = e[j].next; } f[i].l = max(f[i].l, f[i].l1 + f[i].l2 - a[i]); ans = max(ans, s1 + s2); } void work1(int i, int fa) { int j; j = head[i]; while (j != -1) { if (e[j].v != fa) { if (f[i].w1 == e[j].v) f[e[j].v].up = a[e[j].v] + max(f[i].l2, f[i].up); else f[e[j].v].up = a[e[j].v] + max(f[i].l1, f[i].up); work1(e[j].v, i); } j = e[j].next; } if (f[i].w1 != f[i].sw1) ans = max(ans, f[i].l1 + f[i].up - a[i] + f[i].s1); else { ans = max(ans, f[i].l1 + f[i].up - a[i] + f[i].s2); ans = max(ans, f[i].l2 + f[i].up - a[i] + f[i].s1); } if (f[i].sw1 == f[i].w1) ans = max(ans, f[i].s1 + f[i].l2 + f[i].l3 - a[i]); else if (f[i].sw1 == f[i].w2) ans = max(ans, f[i].s1 + f[i].l1 + f[i].l3 - a[i]); else ans = max(ans, f[i].s1 + f[i].l1 + f[i].l2 - a[i]); if (f[i].sw2 == f[i].w1) ans = max(ans, f[i].s2 + f[i].l2 + f[i].l3 - a[i]); else if (f[i].sw2 == f[i].w2) ans = max(ans, f[i].s2 + f[i].l1 + f[i].l3 - a[i]); else ans = max(ans, f[i].s2 + f[i].l1 + f[i].l2 - a[i]); if (f[i].sw3 == f[i].w1) ans = max(ans, f[i].s3 + f[i].l2 + f[i].l3 - a[i]); else if (f[i].sw3 == f[i].w2) ans = max(ans, f[i].s3 + f[i].l1 + f[i].l3 - a[i]); else ans = max(ans, f[i].s3 + f[i].l1 + f[i].l2 - a[i]); ans = max(ans, f[i].l1 + f[i].l2 + f[i].l3 - a[i] * 2); ans = max(ans, f[i].l1 + f[i].l2 + f[i].up - a[i] * 2); } int main() { int i, j, x, y; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &a[i]); memset(head, -1, sizeof(head)); for (i = 1; i < n; i++) { scanf("%d%d", &x, &y); add(x, y); } work(1, 0); f[1].up = a[1]; work1(1, 0); cout << ans << endl; return 0; }
6
#include <bits/stdc++.h> using namespace std; template <class T> inline int size(T& n) { return n.size(); } int toInt(string s) { int r = 0; istringstream sin(s); sin >> r; return r; } template <class T> string toString(T n) { ostringstream ost; ost << n; ost.flush(); return ost.str(); } int N, x, y; int main() { cin >> N >> x >> y; if ((x == N / 2 && y == N / 2) || (x == (N / 2) + 1 && y == (N / 2) + 1)) cout << "NO" << endl; else if ((x == N / 2 && y == (N / 2) + 1) || (x == (N / 2) + 1 && y == N / 2)) cout << "NO" << endl; else cout << "YES" << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; struct node { long long int left1, right1, ans; }; node st[401001]; long long int n, array1[100001], destr, compleft[401000], compright[401000]; void build(int a, int b, int index) { if (a == b) { st[index].left1 = st[index].right1 = st[index].ans = array1[a]; compleft[index] = 1; compright[index] = 1; } else { build(a, (a + b) / 2, 2 * index); build((a + b) / 2 + 1, b, 2 * index + 1); st[index].left1 = st[index].right1 = st[index].ans = st[2 * index].right1 + st[2 * index + 1].left1; compleft[index] = 1; compright[index] = 1; } } void update(int a, int b, int index) { if (destr < a or destr > b) return; if (a == b and a == destr) { st[index].left1 = st[index].right1 = st[index].ans = 0; compleft[index] = compright[index] = 0; } else { update(a, (a + b) / 2, 2 * index); update((a + b) / 2 + 1, b, 2 * index + 1); if (compleft[2 * index] == 1) { st[index].left1 = st[2 * index].left1 + st[2 * index + 1].left1; if (compleft[2 * index + 1] == 1) compleft[index] = 1; else compleft[index] = 0; } else { st[index].left1 = st[2 * index].left1; compleft[index] = 0; } if (compright[2 * index + 1] == 1) { st[index].right1 = st[2 * index + 1].right1 + st[2 * index].right1; if (compright[2 * index] == 1) compright[index] = 1; else compright[index] = 0; } else { st[index].right1 = st[2 * index + 1].right1; compright[index] = 0; } st[index].ans = max(st[2 * index].ans, max(st[2 * index + 1].ans, (st[2 * index].right1 + st[2 * index + 1].left1))); st[index].ans = max(st[index].left1, max(st[index].right1, st[index].ans)); } } int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { cin >> array1[i]; } build(0, n - 1, 1); for (int i = 0; i < n; i++) { cin >> destr; destr--; update(0, n - 1, 1); st[1].ans = max(0ll, st[1].ans); cout << st[1].ans << "\n"; } }
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long a[n], s[n], p[n]; for (int i = 1; i <= n; i++) { cin >> a[i]; s[i] = a[i]; p[i] = 0; } sort(s + 1, s + n + 1); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { p[j] += abs(a[i] - s[j]); if (j > 1) p[j] = min(p[j], p[j - 1]); } cout << p[n]; return 0; }
3
#include <bits/stdc++.h> using namespace std; long long int pow(long long int x, long long int y, long long int m) { long long int res = 1; x = x % m; while (y > 0) { if (y & 1) res = ((res % m) * (x % m)) % m; y = y >> 1; x = ((x % m) * (x % m)) % m; } return res % m; } template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) { std::cerr << name << " = " << arg1 << endl; } template <typename Arg1, typename... Args> void ZZ(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); std::cerr.write(names, comma - names) << " = " << arg1; ZZ(comma, args...); } const long long int INF = 0xFFFFFFFFFFFFFFFL; clock_t time_p = clock(); void abhigyan10() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n"; } long long int seed; mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count()); inline long long int rnd(long long int l = 0, long long int r = INF) { return uniform_int_distribution<long long int>(l, r)(rng); } const long long int mod = 1000000007; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int ans, i, j = 1, n, ma = 0, dp = 0; cin >> n; vector<int> a(n + 1); for (i = 0; i < n; i++) cin >> a[i]; dp = 1; ma = 1; for (i = 1; i < n; i++) { if (a[i] <= (2 * a[i - 1])) dp++; else { ma = max(dp, ma); dp = 1; } } ma = max(dp, ma); cout << ma; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, mx2, meet = 0; cin >> a >> b; long long res = abs(a - b); long long mx = max(a, b); mx2 = mx; long long mn = min(a, b); long long ab = a * b; while (mx <= ab) { if ((mx % mn) == 0) meet++; mx += mx2; } res -= meet; if (res >= 1) { if (mn == a) cout << "Dasha"; else cout << "Masha"; } else { cout << "Equal"; } return 0; }
3
#include<bits/stdc++.h> using l=long long;int main(){l h;std::cin>>h;printf("%llu",(l)pow(2,floor(log2(h))+1)-1);}
0
#include <bits/stdc++.h> using namespace std; string ans[] = { "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "OUT", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "OUT", "IN", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "OUT", "IN", "IN", "IN", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "IN", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "OUT", "OUT", "IN", "OUT", "IN", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "IN", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "IN", "OUT", "IN", "OUT", "IN", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "OUT", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "OUT", "IN", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "OUT", "IN", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "OUT", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "OUT", "OUT", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "IN", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT", "OUT"}; int main() { int x, y; cin >> y >> x; int ind = x * 64 + y; cout << ans[ind] << endl; return 0; }
5
#include<cstdio> #include<algorithm> #include<iostream> #include<map> #include<string> #include<cstring> using namespace std; map <string,int> ke; int main(){ int n; char k[256]; while(scanf("%d,%s",&n,k)!=EOF){ string st=k; ke[st]++; } cout << ke["A"] << endl; cout << ke["B"] << endl; cout << ke["AB"] << endl; cout << ke["O"] << endl; }
0
#include <bits/stdc++.h> using namespace std; struct al { int kol_vo; int ob; int rev; priority_queue<int> s, s1; }; int main() { int kol_vo, len, max_pol = 0, answ = 0; cin >> kol_vo >> len; unordered_map<string, al> m; unordered_map<string, pair<int, priority_queue<int> > > pol; for (int c = 0; c < kol_vo; c++) { string s, s1; int kras; cin >> s >> kras; s1 = s; reverse(s.begin(), s.end()); if (s == s1) { pol[s].first++; pol[s].second.push(kras); } else { m[s].kol_vo++; m[s].ob++; m[s].s.push(kras); m[s1].kol_vo++; m[s1].s1.push(kras); m[s1].rev++; } } for (auto i : m) { while (i.second.ob != 0 && i.second.rev != 0 && i.second.s.top() + i.second.s1.top() > 0) { answ += i.second.s.top() + i.second.s1.top(); i.second.s1.pop(); i.second.s.pop(); i.second.ob--; i.second.rev--; } } answ /= 2; int pot = 0; for (auto i : pol) { while (i.second.first >= 2) { int f = i.second.second.top(); i.second.second.pop(); int s = i.second.second.top(); i.second.second.pop(); i.second.first -= 2; if (s + f > 0) { answ += s + f; if (s < 0) pot = max(pot, abs(s)); } else { i.second.second.push(f); i.second.first = 1; } } if (i.second.first == 1) { max_pol = max(max_pol, i.second.second.top()); } } answ += max(max_pol, pot); cout << answ; return 0; }
4
#include <bits/stdc++.h> using namespace std; int n, a[200010]; int qd(int l, int r, int tot, int b) { if (r - l <= 1) return 0; int lb = lower_bound(a, a + n, tot + (1 << b)) - a; if (lb >= r - 1) return qd(l, lb, tot, b - 1); if (lb <= l + 1) return qd(lb, r, tot + (1 << b), b - 1); return min(lb - l - 1 + qd(lb, r, tot + (1 << b), b - 1), r - 1 - lb + qd(l, lb, tot, b - 1)); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); printf("%d\n", qd(0, n, 0, 30)); return 0; }
5
#include <bits/stdc++.h> using namespace std; long long n; int cnt; int main() { cin >> n; while (n > 0) { if (n % 10 == 4 || n % 10 == 7) cnt++; n = n / 10; } if (cnt == 4 || cnt == 7) cout << "YES"; else cout << "NO"; return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, a[3 * 100000 + 5], r[3 * 100000 + 5]; bool cmp(int x, int y) { return a[x] < a[y]; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); r[i] = i; } sort(r + 1, r + n + 1, cmp); for (int i = 2; i <= n; i++) { if (a[r[i]] <= a[r[i - 1]]) a[r[i]] = a[r[i - 1]] + 1; } printf("%d", a[1]); for (int i = 2; i <= n; i++) printf(" %d", a[i]); }
3
#include <bits/stdc++.h> using namespace std; const long long N = (long long)(1e6) + 10; const long long mod = 998244353; const long long inf = 1e9; const double eps = 1e-16; const double pi = acos(-1); inline long long rd() { long long p = 0; long long f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f *= -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { p = p * 10 + ch - '0'; ch = getchar(); } return p * f; } char s[N], t[N], ans[N]; signed main() { long long tcase = rd(); while (tcase--) { scanf("%s", s + 1); long long len = strlen(s + 1); long long ansl = 2 * len; for (long long i = 1; i <= len; i++) ans[i] = ans[i + len] = s[i]; for (long long i = 1; i <= len; i++) for (long long j = i; j <= len; j++) { long long l = j - i + 1; for (long long p = 1; p <= l; p++) t[p] = s[i + p - 1]; long long ti = 2 * len / l; long long cir = l; for (long long p = 1; p <= cir * ti; p++) l++, t[l] = t[l - cir]; long long k = 1; for (long long p = 1; p <= l; p++) if (t[p] == s[k] && k <= len) k++; if (k == len + 1 && cir < ansl) { ansl = cir; for (long long p = 1; p <= l; p++) ans[p] = t[p]; } } long long ti = 2 * len / ansl; for (long long i = 1; i <= ansl * ti; i++) printf("%c", ans[i]); puts(""); } return 0; }
2
#include <bits/stdc++.h> using namespace std; int N; int A[202020]; int main() { int tc; scanf("%d", &tc); while(tc--) { scanf("%d", &N); for(int i = 1; i <= N; i++) scanf("%d", &A[i]); set<int> S; set<int>::iterator it; bool ok = true; for(int i = 1; i <= N; i++) { S.insert(A[i]); if(i > 1) { int cnt = 0; while(*it < A[i]) { it++; cnt++; } while(*it > A[i]) { it--; cnt++; } if(cnt >= 2) { ok = false; break; } } else it = S.begin(); } puts(ok ? "YES" : "NO"); } return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { int n, k; double l, v1, v2; while (~scanf("%d%lf%lf%lf%d", &n, &l, &v1, &v2, &k)) { int g = n / k + (n % k != 0); double a = (v1 + v2) * l / (v1 + v2 + 2 * (g - 1) * v1); double sum = a / v2 + (l - a) / v1; printf("%.10f\n", sum); } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int N = 2010; int n, k; int a[N], f[N]; bool check(long long x) { memset(f, 0, sizeof f); f[1] = 1; int ans = 0; for (int i = 2; i <= n; i++) { f[i] = 1; for (int j = i - 1; j >= 1; j--) if (abs(a[i] - a[j]) <= 1ll * (i - j) * x) f[i] = max(f[i], f[j] + 1); ans = max(ans, f[i]); } return n - ans <= k; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; long long l = 0, r = 2e15; while (l != r) { long long mid = ((l + r) >> 1); if (check(mid)) r = mid; else l = mid + 1; } cout << l << endl; }
2
#include <bits/stdc++.h> using namespace std; int main() { int n, k, aux; cin >> n >> k; char w[2 * n]; for (int i = 1; i <= 2 * n; i++) { cin >> w[i]; } int d[2 * n + 1]; d[1] = 0; for (int i = 2; i < 2 * n + 1; i++) { d[i] = n; } queue<int> cola; cola.push(1); while (cola.empty() == 0) { aux = cola.front(); if (w[aux] == '-') { if (aux > n - k && aux <= n) { cout << "YES"; return 0; } else if (aux > 2 * n - k && aux <= 2 * n) { cout << "YES"; return 0; } if (aux <= n) { if (d[n + aux + k] > d[aux] + 1) { d[n + aux + k] = d[aux] + 1; if (d[n + aux + k] < aux + k) { cola.push(n + aux + k); } } if (d[aux + 1] > d[aux] + 1) { d[aux + 1] = d[aux] + 1; if (d[aux + 1] < aux + 1) { cola.push(aux + 1); } } if (aux > 1 && d[aux - 1] > d[aux] + 1) { d[aux - 1] = d[aux] + 1; if (d[aux - 1] < aux - 1) { cola.push(aux - 1); } } } if (aux > n) { if (d[aux - n + k] > d[aux] + 1) { d[aux - n + k] = d[aux] + 1; if (d[aux - n + k] < aux - n + k) { cola.push(aux - n + k); } } if (d[aux + 1] > d[aux] + 1) { d[aux + 1] = d[aux] + 1; if (d[aux + 1] < aux - n + 1) { cola.push(aux + 1); } } if (aux > 1 && d[aux - 1] > d[aux] + 1) { d[aux - 1] = d[aux] + 1; if (d[aux - 1] < aux - n - 1) { cola.push(aux - 1); } } } } cola.pop(); } cout << "NO"; }
4
#include <bits/stdc++.h> using namespace std; const int MXN = 1e5 + 1; const int TMXN = 2e6 + 10; const long long INF = 2e9 + 7; const long long INFL = 1e18; int n, ans, res, cnt[4], x, y, k, add; string second = "BGR"; char a[MXN]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] == 'B') cnt[1]++; if (a[i] == 'G') cnt[2]++; if (a[i] == 'R') cnt[3]++; } for (int i = 1; i <= 3; i++) { k = cnt[i]; if (i == 1) x = cnt[2], y = cnt[3]; if (i == 2) x = cnt[1], y = cnt[3]; if (i == 3) x = cnt[1], y = cnt[2]; if ((x && y) || (y > 1 && k) || (x > 1 && k) || (x == 0 && y == 0)) { cout << second[i - 1]; continue; } } return 0; }
2
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; vector<pair<long long int, long long int> > a; int asdasd[N]; int main() { int d, n, m; cin >> d >> n >> m; for (int i = 0; i < m; i++) { int x, p; cin >> x >> p; a.push_back(make_pair(x, p)); } a.push_back(make_pair(d, 0)); a.push_back(make_pair(0, 1000000007 + 10)); m += 2; sort(a.begin(), a.end()); stack<int> xx; for (int i = m - 1; i >= 0; i--) { while (!xx.empty() && a[xx.top()].second > a[i].second) xx.pop(); if (xx.empty()) asdasd[i] = -1; else asdasd[i] = xx.top(); xx.push(i); } long long int left = n; long long int ans = 0; for (int i = 0; i < m - 1; i++) { if (left < 0) { puts("-1"); return 0; } int idx = asdasd[i]; long long int need = 0; if (idx == -1) need = max(min(1LL * n, d - a[i].first) - left, 0LL); else need = max(min(1LL * n, a[idx].first - a[i].first) - left, 0LL); if (idx != -1) ; ans += 1LL * need * a[i].second; left = left + need - (a[i + 1].first - a[i].first); } if (left < 0) puts("-1"); else cout << ans << "\n"; return 0; }
5
#include <bits/stdc++.h> using namespace std; long long n, m, ans, mod = 1e9 + 7; long long fexp(long long a, int x, long long mod) { if (x == 0) return 1ll; if (x % 2 == 0) { long long y = fexp(a, x / 2, mod); return (y * y) % mod; } return (a * fexp(a, x - 1, mod)) % mod; } long long divv(long long a, long long b, long long mod) { return (a * fexp(b, mod - 2, mod)) % mod; } long long f[1000100]; long long fat(long long a, long long mod) { if (a <= 1) return 1; return f[a] ? f[a] : (f[a] = (a * fat(a - 1, mod)) % mod); } long long choose(long long n, long long k, long long mod) { return divv(fat(n, mod), (fat(k, mod) * fat(n - k, mod)) % mod, mod) % mod; } long long fw(long long x) { return choose(m + x - 1, x - 1, mod); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 1; i <= n; i++) { ans += choose(m + i - 2, i - 1, mod) * fw(n - i + 1); ans %= mod; } cout << ans << endl; }
3