solution
stringlengths
52
181k
difficulty
int64
0
6
#include<bits/stdc++.h> using namespace std; int main(void){ long long mod = 1000000007LL; long long N, M; cin >> N >> M; if(abs(N - M) > 1){ cout << 0 << endl; return 0; } long long ans = 1; for(int i = 1; i <= N; i++){ ans *= i; ans %= mod; } for(int i = 1; i <= M; i++){ ans *=...
0
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string(string(s)); } string to_string(bool b) { return to_string(int(b)); } string to_string(vector<bool>::reference b) { return to_string(int(b)); } string to_stri...
6
#include <bits/stdc++.h> using namespace std; int R, b[4], p[4]; bool valid[105][105]; bool vis[105][105]; void add(int &a, int b) { a += b; if (a >= 1000000007) a -= 1000000007; } void dec(int &a, int b) { a -= b; if (a < 0) a += 1000000007; } int pow_mod(int a, int i) { int s = 1; while (i) { if (i & ...
5
#include <bits/stdc++.h> #include <stdlib.h> using namespace std; typedef long long ll; int main() { int h,w; cin>>h>>w; char a[h][w]; int res[h][w]; queue<int> memo; for(int i=0;i<h;i++){ for(int j=0;j<w;j++) { cin>>a[i][j]; if(a[i][j]=='#') { res[i][j]=0; memo.push(i);memo...
0
#include<bits/stdc++.h> using namespace std; typedef double Float; typedef pair<Float, Float> Point; typedef pair<Float, Float> P; typedef pair<Point, Point> Line; // (frm, to) #define _IsLine 0 #define _IsRay 1 #define _IsSegment 2 const Float eps = 1e-12; Float norm(Point a) { return sqrt(a.first * a.firs...
0
#import <iostream> using namespace std; int main(){ int A,B,C,D; int s1,s2; cin >>A>>B>>C>>D; s1 = A*B; s2 = C*D; cout << max(s1,s2); }
0
#include <iostream> #include<vector> #include<algorithm> #define mod 1000000007 using namespace std; typedef long long ll; int main() { int n, w; cin >> n >> w; vector<int> frnd; int sum=0; for (int i = 0; i < n; i++) { int x; cin >> x; frnd.push_back(x); sum += x; } sort(frnd.begin(), frnd.end()); ...
0
#include <bits/stdc++.h> using namespace std; int main() { int a[7]; for (int i = 0; i < 6; i++) cin >> a[i]; sort(a, a + 6); do { if (a[0] + a[1] + a[2] == a[3] + a[4] + a[5]) { cout << "YES"; return 0; } } while (next_permutation(a, a + 6)); cout << "NO"; }
1
#include <bits/stdc++.h> #pragma comment(linker, ”/ STACK : 38777216“ using namespace std; const int N = 100005; const int inf = 1000 * 1000 * 1000; const int mod = 1000 * 1000 * 1000 + 7; long long n, a, b; int main() { cin >> n; if (n == 2) { cout << 1 << endl; return 0; } if (n == 3) { cout << 2 ...
1
#include <bits/stdc++.h> using namespace std; long long n, m, mem[19][1 << 19]; bool f[21][21]; long long run(int start, int at, int been, int cnt) { long long &res = mem[at][been]; if (res == -1) { res = 0; if (cnt >= 3 && f[at][start]) ++res; for (int to = start + 1; to < n; to++) { if (!f[at][t...
4
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0LL) return b; if (b == 0LL) return a; return gcd(b, a % b); } const int N = 200005; long long A[N], W[N]; pair<long long, long long> tree[N << 2]; pair<long long, long long> temp[N << 2]; void build(int node, int l, ...
3
#include <bits/stdc++.h> using namespace std; long long n, k, f, x, y, i; string a; int main() { cin >> n >> k; cin >> a; for (i = 0; i < a.length(); i++) { if (a[i] == 'G') x = i; if (a[i] == 'T') y = i; } for (i = min(x, y) + k;; i += k) { if (i == max(x, y)) { cout << "YES"; exit(0)...
1
#include <iostream> #include <sstream> #include <map> #include <queue> #include <vector> #include <cstdio> #include <cstring> using namespace std; #define all(c) (c).begin(), (c).end() #define loop(i,a,b) for(int i=(a);i<int(b);i++) #define rep(i,b) loop(i,0,b) // Verify : http://judge.u-aizu.ac.jp/onlinejudge/descri...
0
#include <bits/stdc++.h> using namespace std; inline int log(const char* format, ...) { return 0; } const double EPS = 10e-8; const int MAX = 1005; const int INF = 1 << 30; int A[MAX][MAX]; int up[MAX][MAX]; int down[MAX][MAX]; int leftt[MAX][MAX]; int rightt[MAX][MAX]; int main(int argc, char** argv) { int n, m, q; ...
4
#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))...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; long long int arr[n], maxi = 0; long long int cumlht[200005] = {0}; long long int cumlBlocks[200005] = {0}; long long int mini = 100000000; for (int i = 0; i < n; i++) { cin >> arr[i]; maxi = max(maxi, ar...
3
#include <bits/stdc++.h> using namespace std; const int MAXM = 10 * 1000; const int MAXN = 1000; const long long UNKNOWN = 1ll << 30; int ext1[MAXM], ext2[MAXM]; long long weight[MAXM]; vector<int> adj[MAXN]; long long dist[2][MAXN]; int n, m, L; int end(int e, int u) { return (u == ext1[e] ? ext2[e] : ext1[e]); } bool...
2
#include <bits/stdc++.h> using namespace std; const long long MOD = (int)998244353; long long binPow(long long a, long long b) { if (b == 0) return 1; long long ans = binPow(a, b / 2); ans = ans * ans % MOD; if (b % 2) ans = ans * a % MOD; return ans; } vector<int> a(6); vector<int> w; int n; bool check(int c...
4
#include <bits/stdc++.h> using namespace std; long long int powmod(long long int a, int b, int n) { long long int rm = 1; while (b) { if (b % 2) { rm = (rm * a) % n; } a = (a * a) % n; b /= 2; } return rm; } int a[int(1e5 + 10)], t = 0, q1[int(1e5 + 10)], q2[int(1e5 + 10)]; int main() { ...
3
/* /+==================================================+\ //+--------------------------------------------------+\\ |.|\\...>>>>>>> Hollwo_Pelw(ass) 's code <<<<<<<...//|.| \\+--------------------------------------------------+// \+==================================================+/ */ #include <bits/stdc++.h> using ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, a; long long ans = 0, currA = 1, currB = 1; cin >> n; vector<long long> ar[n + 1]; for (int i = 1; i <= n * 2; i++) { cin >> a; ar[a].push_back((long long)i); } for (int i = 1; i <= n; i++) { if ((abs(currA - ar[i][0]) + abs(cur...
2
#include <bits/stdc++.h> using namespace std; using Long = long long; vector<vector<int>> G(100010); int D[100010]; int dist[100010]; int P[100010]; int ep1 = -1, ep1lvl = -1, ep2 = -1, ep2lvl = -1; void dfs(int u, int p, int lvl) { if (lvl > ep1lvl) { ep1lvl = lvl; ep1 = u; } for (auto v : G[u]) { if...
2
#include <bits/stdc++.h> using namespace std; const int inf = 1.01e9; const double eps = 1e-9; const int N = 3010; char s[N][N]; int a[N]; pair<int, int> p[N]; int pc = 0; int dead[N]; int n, m; int solve() { int rest = n * (n - 1); for (int i = 0; (i) < (m); ++i) rest -= a[i]; for (int i = 0; (i) < (n - m); ++i)...
5
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; int GetVal(char c) { if (c == 'W') return 1; return -1; } char s[105][105]; int a[105]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%s", s[i]); int res = 0; for (int i = n - 1; i >...
4
#include <bits/stdc++.h> using namespace std; const int N = 200005; char s[N]; int ans, tot = 1, n, f[N][26], g[N], sd[N]; struct cmp { int operator()(int a, int b) { return sd[a] < sd[b]; } }; priority_queue<int, vector<int>, cmp> q[N]; void build(char s[]) { int now = 1; for (int i = 0; s[i]; i++) { if (f[n...
5
#include <bits/stdc++.h> using namespace std; struct sv { int pow, dmg, num; }; int n, reg, mx, now; bool _less(sv a, sv b) { if (((now * 100 / mx < a.pow) || (now * 100 % mx == 0 && now * 100 / mx == a.pow)) && ((now * 100 / mx < b.pow) || (now * 100 % mx == 0 && now * 100 / mx == b.pow))) { ...
2
#include <iostream> #include <cstdio> using namespace std; typedef long long LL; const int N = 100005, P = 1e9 + 7; int n, K, f[N]; int inline power(int a, int b) { int res = 1; while (b) { if (b & 1) res = (LL)res * a % P; a = (LL)a * a % P; b >>= 1; } return res; } int main() { scanf("%d%d", &n, &K);...
0
#include <bits/stdc++.h> using namespace std; long long f[55], g[55], d[55], h[55]; long long a, b; int k, x, n, m; bool AC = false; char toChar(int x) { if (x == 0) return 'A'; else if (x == 1) return 'C'; return 'Z'; } void comp(int l, int x, int y, int &minn, int &maxx) { if (l == 1) { minn = max...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n; cin >> n; long long a[n], i; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { if (i % 2 && a[i] > 0) a[i] = -1 * a[i]; else if (!(i % 2) && a[i] < 0) ...
1
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k; int n, m; cin >> n; int a[n]; map<int, int> mp; for (i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } bool f; int ans = 0; for (i = 0; i < n; i++) { f = false; for (j = 0; j < 32; j++) { int x = (1 << j) - a...
3
#include <bits/stdc++.h> using namespace std; long long calcdis(long long x1, long long y1, long long x2, long long y2) { return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); long long n, x1, y1, x2, y2; cin >> n >> x1 >> y1 >> x2 >> y2; vector<pa...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v0,v1,v2,v3,v4; for(int i=0; i<n; i++) { int x; cin >> x; if(x==0) v0.push_back(x); else if(x==1) v1.push_back(x); else if(x==2) v2.push_back(x); else if(x==3) v3.push_back(x); else v4.push_back...
0
#include <bits/stdc++.h> bool f(int& x, int& y, char c, int X, int Y) { int a = x, b = y; c == 'U' ? --a : c == 'D' ? ++a : c == 'R' ? ++b : --b; return a * b && a <= X && b <= Y && (x = a, y = b); } int z[501][501]; int main() { std::string s; int count = 1, x, y, x0, y0; std::cin >> x >> y >> x0 >> y0 >> ...
2
#include <iostream> using namespace std; typedef long long ll; int n; string s; int n1, n2; char c1[50], c2[50]; ll d[50][50]; ll calc2() { for (int u1 = 0; u1 <= n1; u1++) { for (int u2 = 0; u2 <= n2; u2++) { int p = n-1+u1+u2; d[u1][u2] = u1+u2 == 0; if (u1 > 0 && s[p] == c1[n1-u1]) d...
0
#include <bits/stdc++.h> using namespace std; unsigned long long int powe(int a, int b) { if (b == 0) return 1; unsigned long long int s = 1LL << (b); return s; } int main() { unsigned long long int m, n; cin >> m >> n; unsigned long long int a[m][n]; for (unsigned long long int i = 0; i < m; i++) { f...
2
#include <bits/stdc++.h> using namespace std; long long dp[2005][2005]; long long SumDp[2005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; string s; cin >> s; s = " " + s; dp[0][0] = 1; SumDp[0] = 1; for (int i = 1; i <= n; i++) { for (int j...
3
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { long long x = 0; char ch = getchar(); bool positive...
5
#include <iostream> using namespace std; int main() { string str[3]; while(1) { for(int i=0;i<3;i++) { getline(cin,str[i]); if(cin.eof()) return 0; // cout << str[i] << endl; } bool r = false; for(int i=0;i<3;i++) { //yoko if(str[i][0] == str[i][1] && str[i][1] == str...
0
#include <bits/stdc++.h> using namespace std; long long a[100000]; map<int, int> s; int main() { long long k, b, n; cin >> k >> b >> n; for (long long ni = 0; ni < n; ni++) cin >> a[ni]; long long count = 0; long long dr = 0; long long zeroc = 0; long long seq = 0; for (int ni = 0; ni < n; ni++) { i...
5
#include <iostream> #include <string> #include <algorithm> using namespace std; #define BIAS 20000 bool ab[BIAS * 2]; bool bc[BIAS * 2]; bool ca[BIAS * 2]; void init(const string& S, const string& T, bool *M) { for (int i = 0; i < S.size(); i++) { for (int j = 0; j < T.size(); j++) { if (S[i] != '?' && T[...
0
#include <bits/stdc++.h> using namespace std; string s; long long int count(long long int l, long long int r, char c) { long long int i, ans = 0; for (i = l; i <= r; i++) { if (s[i] != c) ans++; } return ans; } long long int calc(long long int l, long long int r, char c) { if (r == l) { if (s[l] != c)...
4
#include <bits/stdc++.h> using namespace std; using LL = long long; void Print() { cout << endl; } template <typename T1, typename... T> void Print(const T1 &t1, const T &...t) { cout << t1 << " "; Print(t...); } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "...
5
#include <bits/stdc++.h> using namespace std; namespace IO { template <class T> inline bool read(T &x) { int c = getchar(); int sgn = 1; while (~c && c < '0' || c > '9') { if (c == '-') sgn = -1; c = getchar(); } for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sgn; ...
6
#include <iostream> using namespace std; int a; int main() { cin >> a; cout << 180 * (a - 2); return 0; }
0
#include <bits/stdc++.h> int root(int x); int main() { int number; scanf("%d", &number); int n = number; int dig = 0, num[10], i = 0; int d = 0, r[10], m = 0; int ans, p; while (number > 0) { num[i] = number % 10; number = number / 10; dig++; i++; } i = 0; root(n); if (root(n) == 0...
3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; int a, b, c; vector<vector<int> > A(t); vector<int> B(t, 0); for (int i = 0; i < t - 2; i++) { cin >> a >> b >> c; bool w = true; int e = 0; while (w && e < A[a - 1].si...
3
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<cassert> #include<iostream> #include<sstream> #include<string> #include<vector> #include<queue> #include<set> #include<map> #include<utility> #include<numeric> #include<algorithm> #include<bitset> #include<complex> using namespace std; typ...
0
#include<iostream> using namespace std; int main(){ int a, b, n; while( cin >> a >> b >> n ) { for(int i=0;i<n;i++) { int x, y; cin >> x >> y; if(x < b && a < y) { cout << "1\n"; return 0; } } cout << "0\n"; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, q, t[4000005], a[1000005], qwq = 0; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } void build(int x, int l, int r) { int md; if (l == r) return (void)(scanf("%d", &t[x])); else md = (l + r) >> 1; build(x << 1, l, md), build(x << 1 | 1, md + 1...
4
#include <bits/stdc++.h> using namespace std; void solve() { long long a1, b1; cin >> a1 >> b1; long long a2, b2; cin >> a2 >> b2; if (a1 == a2 && b1 + b2 == a1) cout << "YES\n"; else if (a1 == b2 && b1 + a2 == a1) cout << "YES\n"; else if (b1 == a2 && a1 + b2 == b1) cout << "YES\n"; else if...
2
#include<cstdio> #include<algorithm> #include<vector> using namespace std; const int N=100005; int n; vector<int>t[N]; int dp[N]; void dfs(int v,int from){ int sum=0,mx=0,cnt=0; for(int i=0;i<t[v].size();i++){ int u=t[v][i]; if(u==from)continue; dfs(u,v); sum+=dp[u]; if(dp[u]==0)cnt++; } if(cnt>=1){ dp[...
0
#include <cstdio> #include <vector> using namespace std; vector<int> s[250005],v,vv,t; int main() { int n,m,x,mx,now,a,b; scanf("%d%d",&n,&m); for(int i=0;i<n;i++) for(int j=0;j<m;j++) { scanf("%d",&x); s[i].push_back(x); } mx=0; for(int i=1;i<n;i++) ...
5
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m, i, j, k, sum; cin >> n >> sum; if (sum <= n) { cout << 1 << "\n"; return 0; } if (sum % n == 0) { cout << sum / n << "\n"; } else { cout << sum / n + 1 ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c, counter = 0; cin >> n >> a >> b >> c; for (int i = 0; i <= a; i++) { for (int j = 0; j <= b; j++) { if (n - i * 0.5 - j <= c * 2 && fmod(n - i * 0.5 - j, 2) == 0 && n - i * 0.5 - j >= 0) counter++; } } c...
2
#include <bits/stdc++.h> int main() { int ab, bc, ca; scanf("%d %d %d", &ab, &bc, &ca); printf("%d", ab * bc / 2); }
0
#include <bits/stdc++.h> using namespace std; int n, m, ans[6001], tmp[6001], mi[6001], ord[6001][4]; int main() { cin >> n >> m; int l, r, c, t; for (int i = 0; i < n; i++) mi[i] = 1000000007; for (int i = 0; i < m; i++) { cin >> t >> l >> r >> c; l--; ord[i][0] = t, ord[i][1] = l, ord[i][2] = r, o...
3
#include <bits/stdc++.h> using namespace std; multiset<int> sk; vector<int> v; int main(void) { int T = 1; while (T--) { int n; long long ans = 0, cnt = 0; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; v.push_back(x); if (!sk.empty() && *sk.begin() < x) { a...
5
#include <bits/stdc++.h> using namespace std; int power(long long int x, long long int y) { long long int temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else return x * temp * temp; } bool prime_check(long long int n) { long long int i, j; if (n == 1) { ...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 100; const long long INF = 1e18; int N; pair<int, int> pts[MAXN]; long long dp[MAXN][2]; pair<int, int> mn[MAXN][2]; int cmp1(const pair<int, int>& a, const pair<int, int>& b) { return max(b.first, b.second) - max(a.first, a.second); } bool cmp2(con...
6
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") long long n, m, a[303030], p, k, ans; map<long long, long long> cnt; void solve() { cin >> n >> p >> k; for (long long i = 1; i <= n...
2
#include <bits/stdc++.h> using namespace std; template <class T> inline bool checkMin(T& a, T b) { return (a > b ? a = b, 1 : 0); } template <class T> inline bool checkMax(T& a, T b) { return (a < b ? a = b, 1 : 0); } void init() {} void solve() { int ga, gb; putchar('?'); putchar(' '); for (int i = 0; i < ...
2
#include <bits/stdc++.h> using namespace std; const int Maxn = 500005; int n, k; int S[Maxn], M[Maxn]; multiset<long long> St; int main() { scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d %d", &S[i], &M[i]); while (!St.empty() && *St.begin() <= S[i]) St.erase(St.begin()); long long cur =...
4
#include <bits/stdc++.h> using namespace std; int a[105]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int len = n >> 1; for (int i = 1; i <= len; ++i) cin >> a[i]; sort(a + 1, a + 1 + len); int ans1 = 0; int now = 2; for (int i = 1; i <= len; ++i) { ans1 += abs(a[i] - ...
1
#include <bits/stdc++.h> int main(int argc, char const *argv[]) { int l, r, a; std::cin >> l >> r >> a; if (std::abs(l - r) > a) { if (r > l) { std::cout << 2 * (l + a) << "\n"; } else { std::cout << 2 * (r + a) << "\n"; } } else { std::cout << 2 * ((r + l + a) / 2) << "\n"; } re...
1
#include "bits/stdc++.h" using namespace std; #define rep(i,N) for(int i=0;i<(int)N;++i) #define rep1(i,N) for(int i=1;i<=(int)N;++i) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define SZ(x) (int)x.size() #define e_b emplace_back using ll = long long; const ll LINF=1LL<<60; const int INF=1<<30...
0
#include <bits/stdc++.h> using namespace std; template <class T> T gmin(T u, T v) { return (u < v) ? u : v; } template <class T> T gmax(T u, T v) { return (u > v) ? u : v; } template <class T> T gcd(T u, T v) { if (v == 0) return u; return (u % v == 0) ? v : gcd(v, u % v); } int w1[111][111]; int main() { int...
3
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } inline int readChar(); template <class T = int> inline T readInt(); template <class T> inl...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; scanf("%d%d%d", &n, &x, &y); if (x >= n / 2 && x <= n / 2 + 1 && y >= n / 2 && y <= n / 2 + 1) printf("NO\n"); else printf("YES\n"); return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { cout << "Black"; return 0; }
4
#include <bits/stdc++.h> using namespace std; const int N = 210000; int n, k; long long money; int ar[N]; vector<pair<int, int> > v; long long pref; int ans; long long topay; int at[N]; int main() { ios_base::sync_with_stdio(0); cin >> n >> k; cin >> money; for (int i = 1; i <= n; i++) { cin >> ar[i]; i...
2
#include<iostream> #include<string.h> using namespace std; int coin[17]; int memo[301][17]; int calc(int n,int c) { if(memo[n][c] != 0) return memo[n][c]; if(n==0) return 1; if(c>17 || n<0 || coin[c]>n) return 0; int a = calc(n-coin[c], c); int b = calc(n, c+1); memo[n-coin[c]][c] = a; memo[n][c+1] = b;...
0
#include <bits/stdc++.h> using namespace std; struct debugger { static void call(string::iterator it, string::iterator ed) {} template <typename T, typename... aT> static void call(string::iterator it, string::iterator ed, T a, aT... rest) { string b; for (; *it != ','; ++it) if (*it != ' ') b += *i...
1
#include <bits/stdc++.h> using namespace std; const long long MAXN = 100005; inline long long read() { long long weight = 0, symbol = 1; char in = getchar(); while (!isdigit(in)) { if (in == '-') symbol = -1; in = getchar(); } while (isdigit(in)) { weight = weight * 10 + in - '0'; in = getchar...
6
#include <algorithm> #include <iostream> #include <vector> #include <cstdio> #define N (1<<18) #define INF (1e9) using namespace std; vector<int> tree[N]; int n,d; void Update(){ for(int i=0;i<n;i++){ int pos=i+N/2-1; while(pos){ pos=(pos-1)/2; tree[pos].push_back(tree[i+N/2-1][1]); } } f...
0
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long fast_power(long long base, long long power) { long long result = 1; while (power > 0) { if (power & 1) result = result * base % mod; base = base * base % mod; power >>= 1; } return result % mod; } int main() { long lo...
1
#include <iostream> #include <set> using namespace std; int main(){ int n,m; cin >> n >> m; if(n+m>=10) cout << "error"; else cout << n+m; }
0
#include <bits/stdc++.h> using namespace std; int n, z, a[200004]; multiset<int> tr; multiset<int>::iterator it; int main() { tr.clear(); scanf("%d%d", &n, &z); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + n + 1); for (int i = n / 2 + 1; i <= n; i++) { tr.insert(a[i]); } int ans = ...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native") using namespace std; int a[610], b[610], N, i, cnt, ans, ans2, j, x; char c[310]; int divide(int a[]) { int x = 0, i; for (i = a...
4
#include<iostream> #include<cstring> #include<algorithm> #include<math.h> #include<vector> using namespace std; double MapData[101][101]; int XbyId[101], YbyId[101], N; vector<int> Path; const int INF = 1000000; void Init() { for (int i = 0; i < 100; i++) { XbyId[i] = YbyId[i] = INF; for (int j = 0; j < 100; ...
0
#include <bits/stdc++.h> using namespace std; const int N = 1010; vector<pair<int, int>> g[N]; int deg[N]; int leaves[N]; vector<vector<int>> ans; int root = 1; int parent[N]; void dfs(int u, int p) { parent[u] = p; for (auto v : g[u]) { if (v.first == p) continue; dfs(v.first, u); leaves[u] = leaves[v....
1
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { int x, y; cin >> x >> y; int g = gcd(x, y); cout << g + 1 + ((x / g - 1) + (y / g - 1)) * g << endl; }
0
#include <bits/stdc++.h> using namespace std; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; void mad(long long &a, long long b) { a = (a + b) % 1000000007; if (a < 0) a += 1000000007; } long long gcd(long long a, long long b) { if...
5
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:1024000000,1024000000") bool check(string s) { int l = s.length(); for (int i = 1; i < l; i++) if (s[i] == s[i - 1]) return 0; for (int i = l - 2; i >= 1; i--) if (s[i + 1] == s[i - 1]) return 0; return 1; } string solve(strin...
3
#include <bits/stdc++.h> char str[15][15] = {0}; char prefix[106][15] = {0}; long o = 0; long g[106][4] = {0}, m; char gene[5] = "ACGT"; long f[1006][106][15] = {0}; long a[106] = {0}; char opt[15] = {0}; long find(char opt[], long l, long r) { long i, j, k; long a[15] = {0}; for (i = 1; i <= m; i++) { for (j...
3
#include <bits/stdc++.h> using namespace std; using namespace std; const long long mod = 998244353; long long power(long long a, long long n = (mod - 2ll)) { if (a == 0) return (0); if (n == 0) return (1ll); if (n == 1) return (((a % mod) + mod) % mod); long long val = 1; if (n % 2 != 0) val = (a % mod + mod)...
5
#include <cstdio> #include <complex> #include <algorithm> #include <cmath> using namespace std; typedef double D; typedef complex<D> P; const D eps = 0.0001; int N; P ps[300]; bool get_centre(P a, P b, P& r1, P& r2) { if (norm(a - b) > 4) { return false; } P m = (a + b) / 2.0 - a; D l = sqrt(1 * 1 - no...
0
#include <bits/stdc++.h> using namespace std; const int N = 2010; int n, k; int a[N]; int dp[N]; bool check(int x) { for (int i = 1; i <= n; i++) { dp[i] = 1; } for (int i = 2; i <= n; i++) { for (int j = 1; j < i; j++) { if (abs(a[i] - a[j]) <= 1ll * x * (i - j)) { dp[i] = max(dp[i], dp[j] ...
2
#include <bits/stdc++.h> #pragma comment(linker, "/stack:64000000") using namespace std; template <typename first> inline first abs(const first& a) { return a < 0 ? -a : a; } template <typename first> inline first sqr(const first& a) { return a * a; } const long double PI = 3.1415926535897932384626433832795; const ...
4
#include <bits/stdc++.h> using namespace std; int main() { string a,b; cin>>a>>b; string x=a+b; int c=stoi(x); for(int i=1;i<=400;i++){ if(c==i*i) {cout<<"Yes"<<endl; return 0;} } cout<<"No"<<endl; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 100; const string s[2] = {"typedef", "typeof"}; struct var { string name; int num; }; int N; int vart = 1; var t[maxn]; string order; bool flag; bool flag2; int findTof(string input) { int num1 = 0; int T = 0; flag = true; flag2 = true; while ...
2
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; pair<int, int> ans[6]; struct Line { double a, b, c; int id; }; struct point { double x, y; }; inline int dcmp(double x) { if (fabs(x) < eps) return 0; return x > 0 ? 1 : -1; } inline int inter(Line L1, Line L2, point &p) { double a1 = L...
4
#include <bits/stdc++.h> using namespace std; int n, m; const int max_n = 100; int a[max_n], l[max_n]; int dp[max_n][3 * max_n + 1]; int Map[3 * max_n + 1]; const int inf = 1e9; int find_in_map(const int &x) { return lower_bound(Map, Map + m, x) - Map; } int find(const int k, const int x) { if (k == n) return 0; co...
5
#include <bits/stdc++.h> using namespace std; void solve() { int n; long long k, sum = 0; cin >> n >> k; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } sort(a.begin(), a.end()); if (sum <= k) { cout << "0\n"; return; } long long need = k / n; long...
3
#include <bits/stdc++.h> using namespace std; const int maxN = 100 * 1000 + 100; pair<int, int> edge[maxN]; char t[maxN]; int par[maxN]; int dfind(int u) { return par[u] < 0 ? u : par[u] = dfind(par[u]); } void merge(int u, int v) { u = dfind(u); v = dfind(v); if (u == v) return; if ((-par[u] < -par[v])) swap(u...
3
#include <bits/stdc++.h> using namespace std; const int B = 1000000, P1 = 998244353, P2 = 1000000007; long long n, cnt; vector<int> val[7]; int ans, sum[7]; int main() { scanf("%lld", &n); function<void(int, int)> dfs1 = [&](int d, int v) { val[d].push_back((++cnt - v + P1) % P1); if (d == 6) return; fo...
6
#include <bits/stdc++.h> using namespace std; int dist[61][61][61], dp[61][61][61], n, m, r, sh[61][61]; int f(int s, int t, int k) { if (dp[s][t][k] != -1) return dp[s][t][k]; int i, j, ret = 100000000; for (i = 1; i <= m; i++) ret = min(ret, dist[i][s][t]); if (k == 0) return dp[s][t][k] = ret; for (i = 1; ...
4
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; unordered_map<long long, long long> mark, mark2; vector<long long> adj[200000]; long long vis[200000], u[100001], v[100001]; void dfs(long long src) { cout << mark2[src] << " "; vis[src] = 1; for (long long i = 0; i < adj[src].size(); i++) ...
3
#include <bits/stdc++.h> using namespace std; const int N_MAX = 5e5, magic = 40; int n, down[N_MAX - 1], up[N_MAX - 1], sol[N_MAX + 1]; bool seen[N_MAX]; pair<int, int> E[N_MAX - 1]; vector<int> G[N_MAX]; int DFS1(int u) { int ans = 0; seen[u] = true; for (int e : G[u]) { if (seen[E[e].first] && seen[E[e].sec...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); if (n == 2) printf("1\n"); else if (n % 2 == 0) printf("2\n"); else if (n % 2 == 1) { int t = 1; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { t = 0; break; } } if (t =...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; int a[n], b[n - 1], c[n - 2]; int s1 = 0, s2 = 0, s3 = 0; for (i = 0; i < n; i++) { cin >> a[i]; s1 += a[i]; } for (i = 0; i < n - 1; i++) { cin >> b[i]; s2 += b[i]; } for (i = 0; i < n - 2; i++) { cin >...
2