solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> #pragma comment(linker, "/stack:16777216") using namespace std; const int INF = 1000000000; const int BASE = 1000000007; const int MAX = 1000007; const int MAX2 = 7777; const int MAXE = 100000; const int ADD = 1000000; const int MOD = 1000000007; const int CNT = 800; int dp[MAX]; int main() { ...
2
#include <bits/stdc++.h> using namespace std; template <class T, class U> inline void smin(T &a, U b) { if (a > b) a = b; } template <class T, class U> inline void smax(T &a, U b) { if (a < b) a = b; } template <class T> inline void gn(T &x) { char c, sg = 0; while (c = getchar(), (c > '9' || c < '0') && c != '...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 300005; const int maxm = 1000005; const int inf = 2147483647; const double eps = 1e-9; const long long INF = 9223372036854775807ll; long long qpow(long long a, long long b, long long c) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % c; ...
3
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return f == 1 ? x : -x; } const long lo...
3
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, x, m = 0, i, j, y = 0, f = 0; cin >> n >> k >> x; long long a[n]; for (i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 0) f++; if (a[i] < 0) m++; if (abs(a[i]) < abs(a[y])) y = i; } if (f == 0) { if (m % 2 == 0) { ...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; bool seive[MAXN + 4]; int m[MAXN]; vector<vector<int> > g(MAXN + 4); void func() { for (int i = 2; i <= MAXN; i++) if (!seive[i]) for (int j = 2; j * i <= MAXN; j++) { seive[i * j] = true; g[i * j].push_back(i); } ...
2
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int N = 1e5 + 5, inf = 2e9; int n, m, sx, sy, tx, ty, dis[N << 2]; vector<pii> G[N << 2]; pii p[N]; void add(int u, int v, int w) { G[u].emplace_back(v, w), G[v].emplace_back(u, w); } void Dij(int s) { for (int i = 1; i <= 3 * m; i++) d...
4
#include <bits/stdc++.h> using namespace std; const int N = 50000; void player_1() { cout << "Ashishgup" << endl; } void player_2() { cout << "FastestFinger" << endl; } bool check_prime(int n) { for (int i = 2; i < min(N, n); i++) if (n % i == 0) return 0; return 1; } int main() { int tc; cin >> tc; while...
3
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") const int MAXN = 1e6 + 20; string s[MAXN]; int _next_[MAXN]; vector<int> edge[MAXN]; vector<int> sta; int n, r, c; pair<int, pair<int, int> > ans(0, pair<int, int>(0, 0)); inline void dfs(int u) { sta.push_back(u); int now = (int((sta).size...
2
#include <bits/stdc++.h> char map[6][9]; int main() { for (int i = 0; i < 6; i++) { scanf("%s", map[i]); } int priority[][2] = { {0, 3}, {0, 4}, {1, 3}, {1, 4}, {0, 0}, {0, 1}, {0, 6}, {0, 7}, {1, 0}, {1, 1}, {1, 6}, {1, 7}, {2, 3}, {2, 4}, {3, 3}, {3, 4}, {2, 0}, {2, 1}, {2, 6}, {2, 7}, {3,...
4
#include <bits/stdc++.h> int main(int argc, const char* argv[]) { long long int n; (scanf("%lld", &n)); ; long long int asallar[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 1...
3
#include <bits/stdc++.h> using namespace std; long long facto[100005]; int main() { int n; string s; cin >> n; cin >> s; int a = count(s.begin(), s.end(), 'A'); int c = count(s.begin(), s.end(), 'C'); int g = count(s.begin(), s.end(), 'G'); int t = count(s.begin(), s.end(), 'T'); int arre[4] = {a, c, ...
1
#include <bits/stdc++.h> using namespace std; vector<vector<int> > arr(1009, vector<int>(1009)); int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) scanf("%d", &arr[i][j]); vector<int> row(n), col(m); for (int i = 0; i < n; i++) row[i] = i; for...
2
#include <bits/stdc++.h> using namespace std; void itval(istream_iterator<string> it) {} template <typename T, typename... Args> void itval(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; itval(++it, args...); } const long long int MOD = 1e9 + 7; template <typename T> inline voi...
6
#include <bits/stdc++.h> using namespace std; using ll = long long int; const ll mod = 1000000007; const ll M = 1000000000000000000ll; inline ll add(ll a, ll b) { return ((a % mod + b % mod) % mod); } inline ll sub(ll a, ll b) { return ((a % mod - b % mod + mod) % mod); } inline ll mult(ll a, ll b) { return (((a % mod)...
4
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); string s; cin >> s; long long aux = 1, A = 0, B = 0, I = 0; for (long long i = 0; i < s.size(); i++) { if (s[i] == '+') aux = 2; else if (s[i] == '=') aux = 3; else if (aux == 1) A++;...
1
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const int mod = 10056; void gcd(long long a, long long b, long long& d, long long& x, long long& y) { if (!b) { d = a; x = 1; y = 0; } else { gcd(b, a % b, d, y, x); y -= x * (a / b); } } const int MAXN = 1e5 + 10; i...
2
#pragma GCC optimize(2) #include<bits/stdc++.h> #define rg register #define il inline using namespace std; typedef long long ll; const ll mod=1e9+7; int n,x,y,z,ok,all; ll ans=1,dp[45][1<<18]; int main(){ scanf("%d%d%d%d",&n,&x,&y,&z); for(int i=1;i<=n;++i)ans=10*ans%mod; all=(1<<x+y+z)-1; ok=(1<<x+y+z-1)|(1<<y+z-...
0
#include <bits/stdc++.h> using namespace std; int lw[100100], rw[100100], srw[100100], ans[100100], nw; int l[100100], r[100100], v[100100], sr[100100], fl[100100], n; struct stcomp { bool operator()(const int x, const int y) const { if (l[x] == l[y]) return x > y; return l[x] > l[y]; } }; set<int, stcomp> ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const int mod = 1e9 + 7; int main() { int n, sum = 0; cin >> n; if (n <= 2) { cout << "No"; return 0; } int k = (n & 1) ? (n + 1) / 2 : n / 2; cout << "Yes" << "\n"; ; cout << 1 << " " << k << "\n"; ; cout << n - 1 <...
2
#include <bits/stdc++.h> using namespace std; void ganekasar() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { ganekasar(); int t; cin >> t; while (t--) { long long int n, k; cin >> n >> k; long long int mul = k / (n - 1); long long int start = mul * n; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> v(N); for (size_t i = 0; i != v.size(); i++) { cin >> v[i]; } int gap; if (!v[0]) gap = 0; else gap = N - v[0]; for (size_t i = 0; i < v.size(); i += 2) { if ((v[i] + gap) % N != i) { cout << ...
2
#include <bits/stdc++.h> using namespace std; const int M = 62; const int N = M * (M - 1) / 2; int f[70][40][2010]; int d[40]; int a[70]; int work(int num, int id, int sum) { if (sum < 0) return 0; if (f[num][id][sum] != -1) return f[num][id][sum]; f[num][id][sum] = 0; if (num * (num - 1) / 2 > sum) return 0; ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int tnum, num; scanf("%d%d", &n, &k); int nf = n, nt = 2 * n; int no = 0; for (int i = 0; i < k; i++) { scanf("%d", &num); tnum = num; num = num / 4 > nf ? num - nf * 4 : num % 4; nf = tnum / 4 > nf ? 0 : nf - tnum / 4; ...
2
#include <bits/stdc++.h> using namespace std; long long n, m, k = 1, t, x, y; long long a[1000005], b[1000005]; bool f[1000005]; int main() { int n; cin >> n; a[1] = 1; for (int i = 2; i <= n; i++) a[i] = a[i - 1] * i % 998244353; for (int i = 1; i < n; i++) { cin >> x >> y; k = k * (++b[x]) % 9982443...
4
#include <bits/stdc++.h> using namespace std; vector<long long> g[7]; map<int, int> pos1, pos2; const int MAX = 2e5 + 5; long long ara[MAX]; long long binpow(long long a, long long b) { if (b == 0) return 1; long long res = binpow(a, b / 2); if (b % 2) return res * res * a; else return res * res; } int ...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") 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...
3
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long double PI = 4 * atan((long double)1); void Init() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int frq[107]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { int x, tp = m, ct = 0; cin >> x...
3
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433; const long long M = 1e9 + 7; long long t, n, p, x, ans, a[300100]; bool q; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> t; while (t--) { cin >> n >> a[1]; vector<pair<lon...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const int maxN = 210000; const int maxD = 10; int n, k; int a[maxN]; long long p[maxD]; long long p2[maxD][maxN]; long long x[maxD][maxN], y[maxD][maxN]; long long v[maxD][maxN]; long long w[maxD]; bool isPrime(long long n) { fo...
3
#include<bits/stdc++.h> using namespace std; int main(){ int n,a,b; cin>>n>>a>>b; cout<<min(n*a,b); }
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") using namespace std; void itval(istream_iterator<string> it) {} template <typename T, typename... Args> void itval(istream_iterator<string> it, T a, Args... args)...
2
// Drawing heavily from 2579705 by vjudge2 // http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2579705#1 #include <algorithm> #include <iostream> #include <set> #include <vector> using namespace std; #define NMAX 500010 int dim = 0, tree_idx = 1; struct Point { int xy[2], id, left, right; bool operator<(cons...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { string s, ans = ""; cin >> s; int n = s.length(); if (count(s.begin(), s.end(), '0') == n || count(s.begin(), s.end(), '1') == n) { cout << s...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long x, y, x1, y1, i, bb, sum = 0; cin >> x >> y >> x1 >> y1; if (x == x1 || y == y1) { if (x == x1) bb = abs(y1 - y); else if (y1 == y) bb = abs(x - x1); } else bb = ab...
1
#include <bits/stdc++.h> using namespace std; char s[100010]; int x[100010], y[100010], z[100010]; void input() { scanf("%s", s); for (int i = 0; s[i]; ++i) { if (s[i] == 'x') x[i + 1]++; if (s[i] == 'y') y[i + 1]++; if (s[i] == 'z') z[i + 1]++; x[i + 1] += x[i]; y[i + 1] += y[i]; z[i + 1] +...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) a[i] += a[i - 1]; long long max_sum = 0; for (int i = 0; i < n - 1; i++) { long long x = a[i]; int l = i, h = n - 2, m; while...
3
#include <bits/stdc++.h> using namespace std; const int64_t mod = 1000000007; int64_t maxm(int64_t a, int64_t b) { return a > b ? a : b; } int64_t minm(int64_t a, int64_t b) { return a > b ? b : a; } const int64_t inf = 1e18; int main() { ios_base::sync_with_stdio(false); int64_t n, i; cin >> n; string a, b; ...
3
#include<cstdio> #include<cstring> #include<iostream> #define MAXN 510 #define MOD 1000000007 #define ll long long using namespace std; ll f[MAXN][MAXN],cig[MAXN][MAXN],n,c; ll A[MAXN],B[MAXN]; inline ll read(){ ll x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; map<long long, long long> mp; int c = 0; for (int i = 1; i <= m; i++) { long long x; cin >> x; mp[x]++; int flag = 1; for (int j = 1; j <= n; j++) { if (mp[j] == 0) { flag = 0; b...
1
#include<iostream> #include<string> using namespace std; char A1[33] = " ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char B1[33] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"; string A2[32] = { "101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010...
0
#include <bits/stdc++.h> using namespace std; const int INF = 999999999; int n, m; char s[600]; int dp[501][26][26]; pair<int, int> fr[501][26][26]; pair<int, pair<int, int> > mm[501][26][26][2][2]; void output(int i, int j, int k) { if (!i) return; output(i - 1, fr[i][j][k].first, fr[i][j][k].second); for (int i...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 * 2 + 5; int n, x[MAX], y[MAX]; bool mk[MAX * 10]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; ++i) { cin >> x[i]; mk[x[i]] = true; } for (int i = 0; i < n; ++i) { cin >> y[i]; mk[y[...
1
#include <bits/stdc++.h> using namespace std; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } const int INF = 1 << 29; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n >> b) & 1; } inline void set_bit(int& n, int b) { n |= two(b); } inline void unset_bit(int& n, int b...
1
#include <bits/stdc++.h> using namespace std; int k, n, s, p; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> k >> n >> s >> p; int each = 0; while (each * s < n) each++; int i = 0; while (i * p < k * each) i++; cout << i; return 0; }
1
#include<bits/stdc++.h> using namespace std; #define mp make_pair #define mt make_tuple #define rep(i,begin,end) for (__typeof(begin) i=(begin),_end=(end),_step=1-2*((begin)>(end));i!=_end;i+=_step) // OUTPUT template<class a, class b> ostream& operator << (ostream& os, const pair<a,b>& p) { os<<"["<<p.first<<",...
6
#include <bits/stdc++.h> using namespace std; const int N = 205; struct edge { int to, next, f; } e[N * 20]; struct Edge { int x, y, v; bool operator<(const Edge &a) const { return v < a.v; } } E[N]; int head[N], tot, n, m, top; int dis[N], q[N], vis[N]; int X[N * 5], Y[N * 5], C[N * 5]; int fa[N], ans; vector<in...
5
#include <bits/stdc++.h> using namespace std; int main() { int a, b; vector<int> va, vb; cin >> a; for (int i = 0; i < a; i++) { int temp; cin >> temp; va.push_back(temp); } cin >> b; for (int i = 0; i < b; i++) { int temp; cin >> temp; vb.push_back(temp); } int mx = -1, mxcnt ...
1
#include <bits/stdc++.h> using namespace std; const int Maxl = 26; string s; int k; int cnt[Maxl]; bool del[Maxl]; priority_queue<pair<int, int> > Q; int res; int main() { cin >> s >> k; for (int i = 0; i < s.length(); i++) cnt[s[i] - 'a']++; for (int i = 0; i < Maxl; i++) if (cnt[i]) Q.push(make_pair(-cnt[i]...
1
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } bool isKthBitSet(long long n, long long k) { if (n & (1 << (k - 1))) return true; else return fals...
1
#include<bits/stdc++.h> using namespace std; #define ll long long const int M=2e5+7; ll a[M],dp[M]; int main() { int t; cin>>t; while(t--) { int n; cin>>n; ll kq=0; for(int i=1;i<=n;i++) { cin>>a[i]; } sort(a+1,a+n+1); for(int...
3
#include <bits/stdc++.h> const int N = 1000010; using namespace std; vector<pair<int, int> > mp[101]; int sum[111]; bool in[111]; void dfs(int c) { for (int i = 0; i < mp[c].size(); i++) { int u = mp[c][i].first; int w = mp[c][i].second; if (w == 0) continue; sum[c] -= w; sum[u] += w; mp[c][i]...
2
#include <bits/stdc++.h> const int N = 100005; int n; long long a[N], sum[N]; long long l, r; long long A, B, C; long long cal(long long k) { int i = std::lower_bound(a + 1, a + n + 1, k) - a - 1; long long begin = i * k - sum[i], end = sum[n] - sum[i] - k * (n - i); if (end > begin) return begin * C + (end -...
5
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v; int x, y, z, a, b, count = 0; cin >> x >> y >> z >> a >> b; for (int i = 1; i <= b; i++) { if (i % a == 0 || i % z == 0 || i % y == 0 || i % x == 0) v.push_back(i); } sort(v.begin(), v.end()); for (int i = 0; i < v.size(); i++) ...
1
#include <bits/stdc++.h> using namespace std; int n, a, b, k; int dp[5001][5001] = {0}; int sum[5001][5001] = {0}; int solve1() { for (int i = 0; i <= k; i++) { for (int j = 1; j <= n; j++) { if (!i) { dp[i][j] = 1; } else { int diff = abs(j - b); dp[i][j] = (dp[i][j] + (sum[i ...
5
#include <bits/stdc++.h> using namespace std; map<pair<long long, long long>, pair<long long, long long> > f; pair<long long, long long> dfs(pair<long long, long long> a) { if (a.second < 10) return pair<long long, long long>(a.first || a.second, a.second - max(a.first, a.sec...
3
#include <bits/stdc++.h> struct Cell { Cell() : x(0), y(0) {} Cell(int xx, int yy) : x(xx), y(yy) {} int x; int y; }; template <typename T, int MAXSIZE> class Queue { public: Queue() : mHead(0), mTail(0) {} void push(T e) { mQUEUE[mTail++] = e; } T pop(void) { T tmp = mQUEUE[mHead++]; return tmp;...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; n--; m--; k--; int ans = 0; int x = 0, y = 0; if (k == n - k && k == m - k) { { if (!((k + k) % 2)) ans++; } } else if (k == m - k) { for (x = k; x <= n - k; x++) { if (!((x + y) % 2)) a...
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:66777216") using namespace std; int n, L, v1, v2, k; void solve() { cin >> n >> L >> v1 >> v2 >> k; int q = (n + k - 1) / k; long double val = ((1 + (long double)(v2 - v1) / (v2 + v1)) * (q - 1)) * v1 + v2; long double t = L / val; long double res...
1
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const bool debug = true; const long long INFL = LLONG_MAX; const int output_precision = 15; stringstream ss; string s; int main() { ios_base::sync_with_stdio(0); cout.precision(output_precision); cout << fixed; ss.precision(output_precision)...
2
#include <bits/stdc++.h> using namespace std; vector<long long> parent, len; long long n, m, k; long long binomialCoeff(long long n, long long k) { long long res = 1; if (k > n - k) k = n - k; for (long long i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } void init() { parent.re...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int m, n; cin >> m >> n; double tmp = 0, ct = 0; for (int i = 1; i <= m; i++) { double tp = (pow((double)i / m, n)) - ct; tmp += tp * i; ct = (pow((double)i / m, n)); } co...
3
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int n, x, y; struct node { int l, r; } a[1005]; bool cmp(node a, node b) { if (a.l != b.l) return a.l < b.l; else return a.r < b.r; } vector<int> v; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i].l >> a...
4
#include <bits/stdc++.h> using namespace std; int main() { int i, n, m, j; string s; map<string, int> ma; pair<string, int> p; cin >> n >> m; for (i = 0; i < n; i++) { cin >> s; for (j = 0; j < m; j++) { if (j % 2 == 0) s[j] = 155 - s[j]; } ma[s] = i + 1; } map<string, int>::iterat...
1
#pragma GCC optimize("O3") #include<bits/stdc++.h> #define ll long long #define MOD 1000000007LL #define MXN 300005 #define INF 1e9 #define EPS 1e-8 #define endl '\n' #define lowbit(x) (x&-x) using namespace std; mt19937 gen(time(0)); ll n,m,k,sum; ll w[MXN],ans[MXN]; bool v[MXN]; vector<pair<ll,int>> edge[MXN]; voi...
6
#include <bits/stdc++.h> using namespace std; using ll = long long; const vector<int> dx = {1, -1, 0, 0}; const vector<int> dy = {0, 0, 1, -1}; int n, k; vector<string> a; vector<vector<int>> num; vector<int> sz; inline bool ok(int x, int y) { return 0 <= min(x, y) && max(x, y) < n; } void dfs(int x, int y, vector<pair...
3
#include <bits/stdc++.h> using namespace std; long long int m; struct sort_pred { bool operator()(const pair<int, int> &left, const pair<int, int> &right) { if (left.first == right.first) return left.second < right.second; return left.first < right.first; } }; vector<pair<int, int> > a; int p[200010]; int p...
2
#include<iostream> using namespace std; int n,m,pd[100001],x1[100001],y1[100001],ans; int main() { cin>>n>>m; for(int i=1; i<=n; i++) { int x,y; char c; cin>>x>>y>>c; x%=2*m,y%=2*m; if(c=='W')pd[i]=1; else pd[i]=0; x1[i]=x; y1[i]=y; } for(int i=0; i<=m; i++) { int big=0,hh[10001]={0}; for(int j=...
0
#include <iostream> using namespace std; int main(){ int a, b; cin >> a >> b; cout << ((a * b) % 2 == 0 ? "Even" : "Odd") << endl; }
0
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; long long k; cin >> n >> k; vector<int> a(n), f(n); for (int i = 0; i < n; ++i) { cin >> a.at(i); } for (int i = 0; i < n; ++i) { cin >> f.at(i); } sort(a.begin(), a.end()); sort(f.rbegin(), f...
0
#include<bits/stdc++.h> using namespace std; int main() { string s,t,u; int a,b; cin>>s>>t>>a>>b>>u; if(s==u) a--; else b--; cout<<a<<' '<<b<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int n; struct tree { int pos; int quant; } trees[110]; bool cmp(tree a, tree b) { return a.pos < b.pos; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d %d", &trees[i].pos, &trees[i].quant); int neg = 0, posit = 0; for (int i = 0; i < n; i++...
1
#include <bits/stdc++.h> using namespace std; int n, m; int a[105][105], cl[105]; pair<int, int> b[105]; vector<int> pos; int main() { cin >> n >> m; for (int i = 1; i <= m; i++) for (int j = 1; j <= n; j++) cin >> a[i][j]; int res = 0; for (int u = 1; u <= n - 1; u++) { for (int i = 1; i <= m; i++) b[i...
5
#include <bits/stdc++.h> using namespace std; unordered_map<int, int> par, dis; unordered_map<int, int>::iterator i; int findRep(int n) { i = par.find(n); if (i == par.end()) return par[n] = n; int p = (*i).second; if (p == n) return n; int r = findRep(p); dis[n] ^= dis[p]; return par[n] = r; } void join(...
6
#include <bits/stdc++.h> using namespace std; struct ura { int nr; int ord; } v[1137]; bool cmp(ura a, ura b) { return a.nr > b.nr; } int n; int sorin; int ans[1137]; int main() { cin >> n; for (register int i = 1; i <= n; ++i) { cin >> v[i].nr; v[i].ord = i; } sort(v + 1, v + n + 1, cmp); for (re...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; char ss[maxn]; int sum[maxn], a[maxn]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { int x; cin >> x; a[x] = i; } scanf(" %s", ss + 1); sum[0] = 0; for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + (ss[i] ...
3
/*Lucky_Glass*/ #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; const int M=500,N=8000; ll num[M+5][M+5],prm[N+5]; bool avoid[N+5]; int n; void Prepare_Prime(){ for(int i=2;i<=N;i++){ if(!avoid[i]) prm[++prm[0]]=i; for(int j=1;j<=prm[0];j++){ if(i*prm[j]>N) brea...
0
#include <bits/stdc++.h> using namespace std; int is[5010][5010]; int cnt[5010][5010]; long long p1[5100]; long long p2[5100]; long long h1[5100]; long long h2[5100]; int mod1 = 1000000007; int mod2; string s; string t; long long nowh1 = 0; long long nowh2 = 0; pair<int, int> check() { pair<int, int> res = make_pair(...
5
#include <bits/stdc++.h> using namespace std; int n, q0, k; int q[500010], f[500010], d[500010]; char s1[500010], s2[500010]; vector<int> v[500010]; int main() { scanf("%d%d\n", &n, &k); scanf("%s\n", s1); scanf("%s\n", s2); for (int i = 0; i < n; ++i) { if (s1[i] == 'X') f[i] = 1; if (s2[i] == 'X') f[i...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> n >> s; if (s % n != 0) cout << (s / n) + 1 << endl; else cout << (s / n) << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n0, n1, n2; cin >> n0 >> n1 >> n2; string temp = ""; if (n0 != 0) { temp += "0"; while (n0 != 0) { n0--; temp += "0"; } } ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long N,P,answer = 1,frequency; cin >> N >> P; if (N == 1) { cout << P; return 0; } for (int i = 2; 1ll*i*i <= P; i++) { for (frequency = 0; !(P%i); frequency++, P /= i); answer *= (long long)pow(i,frequency/N); } cout << answe...
0
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return x * f; } const ...
3
#include <bits/stdc++.h> using namespace std; int n, u, r, b[30], k[30], p[30], t; long long solve(const vector<int>& a, int u) { long long score = 0, f = u & 1; for (int i = 0; i < n; ++i) score += (a[i] ^ (f * b[i])) * k[i]; vector<int> v(30); for (f = 0; f < 2 && f < u; ++f) { for (int i = 0; i < n; ++i)...
2
#include <bits/stdc++.h> using namespace std; const int N = 100005; vector<int> E[N]; int sx, sy, s[N], y[N], sum[N], p[N]; bool vis[N]; double r = 0.0; void get(int x) { vis[x] = true; p[x] = s[x]; for (int i = E[x].size() - 1; i >= 0; i--) { int j = E[x][i]; if (!vis[j]) { get(j); sum[x] += ...
5
#include <bits/stdc++.h> using namespace std; int nf, ne, ns, rf, re, rs, df, de, n, c[15]; double Rf, Re, Rs, ans, g[15][21][21], E[15], F[15]; double cross(double l, double r, double x, double y) { return max(0., min(r, y) - max(l, x)); } void work() { for (int i = 0; i < n; i++) { E[i] = 2 * Re * de, F[i] = ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; char C[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> C[i][j]; } } int i = n - 1; bool brick = false, titik = true; int counter = 0; for (int j = 0; j < m; j++) { if (C[i][j...
4
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long N = 3e5 + 2; const long long mod = 1e9 + 7; const long double eps = 1E-7; long long n, ans; pair<long double, long double> c; long double a, b, x[N], y[N]; map<pair<long double, long double>, long long> mp; int main() { ios_base:...
4
#include <bits/stdc++.h> using namespace std; int main() { int X,N;cin>>X>>N; vector<int> p(N); for(int i=0;i<N;i++)cin>>p[i]; int m=-1000; for(int i=-300;i<300;i++){ bool d=true; for(int j=0;j<N;j++){ if(i==p[j])d=false; } if(d){ if(abs(m-X)>abs(i-X)){ m=i; } } ...
0
#define _USE_MATH_DEFINES #include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <cfloat> #include <climits> #include <cstdlib> #include <cstring> #include <cmath> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #i...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, q(0), k, k1, k2; cin >> n; k = 1; k1 = 0; k2 = 0; while (n >= k) { k2 = k1 + k; k1 = k; k = k2; q++; } cout << q - 2; return 0; }
3
#include <bits/stdc++.h> int main() { char a[100]; int len, sign1, sign2, i; gets(a); len = strlen(a); sign1 = 0; sign2 = 0; if (a[0] < 'A' || a[0] > 'Z') sign1++; for (i = 0; i < len; i++) { if (a[i] >= 'A' && a[i] <= 'Z') sign2++; } if (sign2 == len || sign2 == len - 1 && sign1 == 1) { for...
1
#include <bits/stdc++.h> using namespace std; int N, M, P, S, T; int st, ed; char ss[205]; int dp[205][205][205], ans; int f[205 * 2][205 * 2], g[205 * 2][205 * 2], tp[205 * 2][205 * 2]; int sum[205]; void Calc(int x) { int tmp, i, j, t, s; while (x) { if (x & 1) { for (i = 1; i <= P; i++) for (j ...
5
#include <bits/stdc++.h> using namespace std; int main(void) { int n, h; vector<int> v; cin >> n >> h; v.resize(n); for (int i = 0; i < n; i++) { cin >> v[i]; } int i; for (i = 0; i < n; i++) { sort(v.begin(), v.begin() + i + 1); int th = 0; for (int j = i; j >= 0; j -= 2) { th += ...
2
#include<bits/stdc++.h> using namespace std; #define PI acos(-1) #define hell 1000000007 #define HELL 998244353 #define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define fix(n) cout << fixed << setprecision(n) #define mset(a,n) memset(a,n,sizeof a) #define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; string x; string y; string m; bool flag = false; cin >> n; for (int i = 0; i < n; i++) { cin >> x; y = y + "<3" + x; if (i == n - 1) y += "<3"; } cin >> m; int j = 0; for (int i = 0; i < m.length(); i++) { if (m[i] =...
2
#include <bits/stdc++.h> #define maxn 200086 using namespace std; int n, m; int ans, sum, x, y; vector<int> v[maxn]; bool vis[maxn]; void dfs(int i){ sum++, vis[i] = true; for(int j = 0;j < v[i].size();j++){ int to = v[i][j]; if(vis[to]) continue; dfs(to); } } int main(){ scanf("%d%d", &n, &m); while(m-...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const int mod = 1e9 + 7; const long long lim = 1e18; struct Point { long long x, y; }; bool Compx(Point x, Point y) { return x.x < y.x; } bool Compy(Point x, Point y) { return x.y < y.y; } vector<Point> mem; long long sqr(long long u) { return u * u...
4
#include<bits/stdc++.h> using namespace std; int main(){ int n,m,s,g; while(cin>>n>>m,n||m){ cin>>s>>g; //cout << n << m << s << g << endl; s--;g--; int d[n][n],c[n][n]; memset(d,-1,sizeof(d)); memset(c,-1,sizeof(c)); int i,j,k,l,x,y; for(i=0;i<m;i++){ cin>>x>>y>>j>>k; x-...
0
#include <bits/stdc++.h> using namespace std; double pi = acos(-1.); struct node { double x, y, r; double s; } q[1010]; double f(node a, node b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) <= a.r - b.r; } int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin ...
4