solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int MOD = 1000 * 1000 * 1000 + 7; const int INF = 2 * MOD; int main() { ios_base::sync_with_stdio(0); int n, m, t; cin >> n >> m >> t; bool was = false; vector<int> id(n); int max_id = 0; queue<int> q; int size = 0; for (int i = 0; i < n; ++i) { ...
13
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); if (n % 2 == 0) cout << a[n / 2 - 1] << endl; else cout << a[n / 2] << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int const MAX = 5e5 + 5; int p[MAX], mob[MAX], a[MAX], cnt[MAX]; bool prime[MAX], vis[MAX], has[MAX]; vector<int> vt[MAX]; void Mobius() { int pnum = 0; mob[1] = 1; for (int i = 2; i < MAX; i++) { if (!prime[i]) { p[pnum++] = i; mob[i] = -1; } ...
15
#include <bits/stdc++.h> using namespace std; int main() { int t; long long n, k, m; cin >> t; while (t--) { long long s = 0; cin >> n >> k; while (n) { m = n % k; if (m) { n -= m; s += m; } else { n /= k; s++; } } cout << s << endl; ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; vector<int> pref(n + 1); for (int i = 1; i <= n; i++) { pref[i] = pref[i - 1] + (s[i - 1] - '0'); } const long long mod = 2e9 + 11, p = 41; v...
17
#include <bits/stdc++.h> using namespace std; int arr[100000]; int brr[100000]; int main() { int n, d, var; cin >> n >> d; for (auto i = 0; i < n; i++) { cin >> var; brr[i] = var; arr[i % d] += var; } int min = INT_MAX, idx; for (auto i = 0; i < d; i++) { if (arr[i] < min) { min = arr[...
4
#include <bits/stdc++.h> using namespace std; bool comp(stack<int> s1, stack<int> s2) { return s1.size() < s2.size(); } int main(int argc, char const *argv[]) { int n; cin >> n; int arr[n]; int sp[n]; int wt[n]; map<int, vector<int> > m; for (int i = 0; i < n; i++) { wt[i] = 1; cin >> arr[i]; ...
6
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 10, MN = 610; int mod, n, m; vector<int> adj[MN], topol; int deg[MN], mat[MN][MN], dp[MN][MN]; bool mk[MN]; void ok(int &x) { if (x >= mod) x -= mod; } int bpw(int a, int b) { int ret = 1, cur = a; while (b) { if (b & 1) ret = 1ll * ret * cur...
21
#include <bits/stdc++.h> using namespace std; using lli = long long int; using pii = pair<int, int>; using vi = vector<int>; using vb = vector<bool>; using vvi = vector<vector<int>>; using vlli = vector<long long int>; using vpii = vector<pair<int, int>>; int n, ans = 0x3f3f3f3f, zero; vi a; int check(int s, int r, int...
14
#include <bits/stdc++.h> using namespace std; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } const int INF = (((1 << 30) - 1) << 1) + 1; const int nINF = 1 << 31; const int N = 3e5 + 10; int n, m, k, len, onpath[N], vis[N], cyc, pathid[N]; vector<int> g[N], cycles[N], path; void anspath() { cout <<...
19
#include <bits/stdc++.h> const double pi = 3.141592653589793238462643383279502884197169399375105820974944; using namespace std; long long n, i, j, k, l, sum = 0, flag = 0, ans = 0, a, b, A, B; vector<long long int> v; long long f(int a, int b, int k) { if (a == 0 && b == 0) return 0; long long l = 1000000007; ...
8
#include <bits/stdc++.h> using namespace std; class figur { public: int x, y; }; bool isin(figur a, figur b, figur x) { if (a.x == b.x && a.x == x.x) { if ((x.y < a.y) && (x.y > b.y)) return 1; if ((x.y > a.y) && (x.y < b.y)) return 1; } if (a.y == b.y && a.y == x.y) { if ((x.x < a.x) && (x.x > b.x...
9
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma comment(linker, "/STACK:64000000") using namespace std; const int INF = 1000 * 1000 * 1000; const long long LINF = 1000000000000000000LL; const double eps = 1e-9; void prepare(string s) { if ((int)s.size() != 0) { freopen((s + ".in").c_str(), "r", s...
14
#include <bits/stdc++.h> using namespace std; vector<int> arr(100005); map<int, int> check; set<int> ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < k; i++) { if (check.find(arr[i...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); ; long int n, k, i, j, len; vector<long int> temp; temp.reserve(100010); cin >> n >> k; long int no, l, r; long int cnt = 0; long int flag = 0; long int last = -1; long int chain_len = 0; long int broke = 0;...
7
#include <bits/stdc++.h> using namespace std; const int T = 1e9 + 7; int a[20][20], b[20][20], n, m, k, g[20][20]; long long ans = 0; bool check(int x, int y) { b[x][y] = b[x][y - 1] | b[x - 1][y]; if (b[x][y] & (1 << a[x][y])) return 0; b[x][y] |= (1 << a[x][y]); return 1; } int p[20]; void cal() { memset(p,...
19
#include <bits/stdc++.h> using namespace std; const int maxn = 105; vector<int> G1[maxn]; int n, m, a, b, q, mp[maxn][maxn], must[maxn][maxn], num[maxn]; int dist[maxn], vis[maxn], p[maxn], fb[maxn], tb[maxn], dp[maxn], Md[maxn]; struct Heap { int u, d; Heap(int _u = 0, int _d = 0) { u = _u; d = _d; } b...
18
#include <bits/stdc++.h> using namespace std; int main() { long long h, m; cin >> h >> m; long long a, b, c, d; cin >> a >> b >> c >> d; if (h < 20) { double i; i = a / d; if (a % d != 0) i++; long long j = (20 - h) * 60 - m; long long o; a += j * b; o = a / d; if (a % d != 0) ...
3
#include <bits/stdc++.h> using namespace std; const int INF = numeric_limits<int>::max(); inline int pow2(int k) { return 1 << k; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, q; scanf("%d %d", &n, &q); int s1 = 0; int s2 = 1; for (int i = 0; i < q; i++) { int t, x; ...
10
#include <bits/stdc++.h> using namespace std; const long long N = 5e5 + 5, M = 55, OO = 0x3f3f3f3f; int t, n, k, g, ans; string s; int fr[30]; vector<long long> getDivisors(long long n) { vector<long long> ret; long long i; for (i = 1; i < n / i; ++i) { if (n % i == 0) { ret.push_back(i); ret.push...
11
#include <bits/stdc++.h> using namespace std; set<string> ss; vector<string> v; int a[4], n, m, k, c[4], p, mx = -1, nn; vector<vector<int>> b; vector<pair<int, vector<int>>> per; vector<int> pp; string s; int fact(int n) { int k = 1; for (int i = 1; i <= n; i++) { k *= i; } return k; } int inv(const vector...
9
#include <bits/stdc++.h> using namespace std; int main() { long long n; long long sum = 0; scanf("%lld", &n); sum++; sum += (2 * n * (n - 1)); printf("%lld", sum); return 0; }
0
#include<bits/stdc++.h> using namespace std; vector<int> m; unordered_set<int> us; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int t;cin>>t; while(t--) { m.clear(); us.clear(); int n,d;cin>>n>>d; int arr[n]; int M=d*10; for...
3
#include <bits/stdc++.h> using namespace std; int n, m; int f[42][730], p3[8]; inline int GetBit(int st, int pos) { return (st % p3[pos + 1]) / p3[pos]; } int dfs(int i, int j, const int lst, int ev, int nst, int et) { if (j >= m) { f[i][nst] = max(f[i][nst], f[i - 1][lst] + ev); return 0; } int bit = Get...
13
#include <bits/stdc++.h> using namespace std; inline long long read() { long long s = 0, w = 1; char c; while (c = getchar(), c > '9' || c < '0') if (c == '-') w = -1; while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar(); return s * w; } inline void write(long long x) { if (x < 0) putchar('-...
16
#include <bits/stdc++.h> using namespace std; long long b, dp[11][61][1025], digit[69]; long long f(long long pos, long long mask, bool check, bool zero) { if (!pos) { if (!zero) return (mask == 0); return 0; } if (!check && !zero && dp[b][pos][mask] != -1) return dp[b][pos][mask]; long long res = 0, n ...
14
#include <bits/stdc++.h> const int N = 1e5 + 10; int n, m, cnt[N], oth; int64_t ans = ~0ull >> 2, cur; std::vector<std::pair<int, int>> a[N], b; bool v[N]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { static int t1, t2; scanf("%d%d", &t1, &t2); cnt[t1]++; if (t1 != 1) a[t1].emp...
9
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int t = m; int t1 = n; vector<int> a; vector<int> b; if ((m == 0 and n != 1) or n * 9 < m) { cout << -1 << " " << -1; } else { if (n == 1) { cout << m << " " << m; } else { while (m - 9 > 0) { ...
6
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << ", "; err(++it, args...); cout << "\n"; } long long powm(long long a,...
15
#include <bits/stdc++.h> using namespace std; long long dis(pair<long long, long long> p1, pair<long long, long long> p2) { return (p1.first - p2.first) * (p1.first - p2.first) + (p1.second - p2.second) * (p1.second - p2.second); } bool lineLineIntersection(pair<long long, long long> A, ...
10
#include<iostream> #include<vector> #include<set> using namespace std; const int N=100009; typedef long long ll; const ll E5=100000,E10=10000000000; set<int,greater<int>>ans; int anss[N]; int main(void){ int n,m; cin>>n>>m; ans.insert(0); vector<int>temporary; for(int i=1;i<=n;i++){ ll k,t,x,y; cin>>t...
14
#include <bits/stdc++.h> using namespace std; int fa[1005]; int main() { int t; cin >> t; while (t--) { int len, k; cin >> len >> k; char ch[200005]; scanf("%s", ch + 1); int flag[k + 1][28]; memset(flag, 0, sizeof(flag)); for (int i = 1; i <= len; i += k) { for (int j = 1; j <= ...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1000010; long long n, m, ans; long long sum[maxn], num[maxn][26]; char d[2][maxn]; long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { cin >> n >> m; scanf("%s%s", d[0], d[1]); long lon...
11
#include <iostream> #include <cstdio> #include <vector> #include <map> using namespace std; const int maxn = 2e5+5; vector<int> mp[maxn]; int a[maxn]; map<int,int> num; map<int,int> * hush[maxn]; int sz[maxn]; int ans , fr , fpa; bool tag[maxn]; bool dfs(int id,int pa) { if(id==0) return true; int son = 0; sz[id] = 1...
17
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; const double pi = acos(-1.0); const int maxn = 2000006; const int mod = 1000000007; void task() { int n; cin >> n; std::vector<vector<int>> a(n, vector<int>(n, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j...
13
#include <bits/stdc++.h> int main() { char a[100]; int x; scanf("%s", a); scanf("%d", &x); int i = 0; int u; u = strlen(a); for (i = 0; i < u; i++) { a[i] = tolower(a[i]); } for (i = 0; i < u; i++) { if (a[i] < 'a' + x) { a[i] = toupper(a[i]); printf("%c", a[i]); } else ...
6
#include <bits/stdc++.h> #pragma GCC optimize(3, "inline") using namespace std; template <typename T> void read(T &x) { x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 1; for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); if (f) x = -x; } template <typen...
23
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d%d", &n, &m); int w[4], h[4]; for (int i = 1; i <= 2; i++) { cin >> w[i] >> h[i]; } for (int i = m; i >= 1; i--) { n += i; if (i == h[1]) n -= w[1]; else if (i == h[2]) n -= w[2]; if (n < 0) n = 0; ...
0
#include <bits/stdc++.h> using namespace std; long long n, m, c, h; pair<long long, long long> A[100100], B[100100], C[4]; long long dist[2][2]; int main() { scanf("%I64d%I64d", &n, &m); scanf("%I64d", &c); for (int i = 1; i <= c; i++) scanf("%I64d%I64d", &A[i].first, &A[i].second); scanf("%I64d", &h); for (i...
13
#include <bits/stdc++.h> using namespace std; const int MAXN = 2005; char str[MAXN]; int n, G[MAXN][MAXN], H[MAXN][MAXN], deg[MAXN], tdeg[MAXN]; inline bool check() { sort(tdeg + 1, tdeg + n + 1); int sum = 0; for (int i = 1; i < n; i++) { sum += tdeg[i]; if (sum == i * (i - 1) / 2) return false; } re...
24
#include <bits/stdc++.h> using namespace std; long long q, mx, mn, ans, w, x, y, z, n, a[100004]; int main() { cin >> q; while (q--) { cin >> n; mx = 1; mn = 0; for (long long i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (long long i = 0; i < n; i++) { if (a[i] <= ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; const long long INF = 1e16 + 5; const long long MOD = 1e9 + 7; vector<int> G[MAXN]; int N; vector<int> tsort() { vector<int> R, D(2 * N, 0); priority_queue<int> Q; for (int i = (0); i < int(N); i++) for (auto &v : G[i]) D[v]++; for (int...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const long double PI = 3.141592653589793238462643383279502884197169399375105820974944; template <typename _T> _T gcd(_T __m, _T __n) { while (__n != 0) { _T __t = __m % __n; __m = __n; __n = __t; } return _...
4
#include <bits/stdc++.h> const int oo = 2139063143; const int N = 101000; const int P = 1000000007; using namespace std; template <typename T> inline void sc(T &x) { x = 0; static int p; p = 1; static char c; c = getchar(); while (!isdigit(c)) { if (c == '-') p = -1; c = getchar(); } while (isdi...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 123, inf = 2e9, mod = 1e9 + 7; long long n, cnt[5], cur, a[100], b[5]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < 5; i++) cin >> b[i]; for (int i = 0; i < n; i++) { cur += a[i]; for (int j = 4; ...
4
#include <bits/stdc++.h> using namespace std; vector<int> v, d; vector<pair<int, char> > vp; int main(void) { int n, t; string a, b, an; scanf("%d %d", &n, &t); cin >> a; cin >> b; int s = 0; for (int i = 0; i < n; i++) if (a[i] == b[i]) { s++; v.push_back(i); } else { d.push_bac...
9
#include <bits/stdc++.h> using namespace std; int n, S; int in[2000], out[2000], w[2000], s[2000], v[2000]; int indice[2000]; int valor[2000][2000]; int despues[2000][2000]; int mejor[2000]; int calculado[2000]; bool compara(int i1, int i2) { return out[i1] < out[i2] or (out[i1] == out[i2] and in[i1] > in[i2]); } int...
18
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, n, x; cin >> a >> b >> n; x = a ^ b; if (n % 3 == 0) cout << a << endl; if (n % 3 == 1) cout << b << endl; if (n % 3 == 2) cout << x << endl; } }
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; vector<pair<int, int> > g[maxn]; vector<pair<int, int> > ans[maxn]; int cur_node, visit[maxn]; int in[maxn]; void dfs(int node, int val) { visit[node] = 1; if ((int)g[node].size() == 0 and node != cur_node) { ans[cur_node].push_back({node, ...
6
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } using ll = long long; const ll mod = 1e9 + 7; const int maxn = 1e6 + 5; const int inf = 2e9; const int N = 1e5; int n; vector<int> b[maxn]; int f(int x) { int cnt = b[0].size(); int tot = 0; set<p...
13
#include <bits/stdc++.h> using namespace std; vector<int> g[100005]; int n, m, nn; int c[100005], h[100005], par[100005], d[100005], dont[100005]; int dp[20][100005]; const int INF = 1e9 + 5; void dfs0(int v) { for (vector<int>::iterator it = g[v].begin(); it != g[v].end(); ++it) if (*it != dp[0][v]) { dp[0...
16
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; const int mod = 1e9 + 7; void add(int &a, int b) { a += b; if (a >= mod) a -= mod; } void sub(int &a, int b) { a -= b; if (a < 0) a += mod; } int mul(int a, int b) { return 1ll * a * b % mod; } int inv(int a, int p) { return a == 1 ? 1 : p - 1...
18
#include <bits/stdc++.h> using namespace std; long long int pow_mod(long long int a, long long int b) { long long int res = 1; while (b != 0) { if (b & 1) { res = (res * a) % 1000000007; } a = (a * a) % 1000000007; b /= 2; } return res; } long long int sz[200005]; long long int par[200005]...
10
#include <bits/stdc++.h> using namespace std; int main() { int s, b; cin >> s >> b; std::vector<int> arr(s); for (int i = 0; i < s; i++) cin >> arr[i]; std::vector<pair<int, int>> brr; for (int i = 0; i < b; i++) { int a, b; cin >> a >> b; brr.push_back({a, b}); } sort(brr.begin(), brr.end()...
6
#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--){ string s; cin>>s; int cnt1=0,cnt2=0,ans=0; for(int i=0;i<s.size();i++){ if(s[i]=='(') cnt1++; else if(s[i]=='[') cnt2++; else if(s[i]==')'){ ...
0
#include <bits/stdc++.h> using namespace std; int mi[] = {0, -1, 0, 1, -1, 1, 1, -1}; int mj[] = {1, 0, -1, 0, 1, 1, -1, -1}; class hashc { public: vector<unsigned long long> prefix; vector<unsigned long long> power; int k = 37; int t; hashc(){}; hashc(vector<int> &data) { t = data.size(); prefix.r...
5
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; void solve() { long long h, c, t; cin >> h >> c >> t; double ans = h - t; long long taken = 1; if (abs((h + c + 0.0) / 2 - t) <= ans) { ans = abs((h + c + 0.0) / 2 - t); taken = 2; } double y = (h - t + 0.0) / (2 * t - (h + c)); ...
9
#include <bits/stdc++.h> using namespace std; vector<vector<vector<long long>>> dp; long long n, m, x; long long solve(long long pos, long long open, long long rem) { if (pos == (m + 1)) { return (!open && (rem == n)); } if (dp[pos][open][rem] != -1) return dp[pos][open][rem]; long long ans = 0; if (pos =...
19
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2, s3, s4, s5, s6, s7, s8; s1 = "vaporeon"; s2 = "jolteon"; s3 = "flareon"; s4 = "espeon"; s5 = "umbreon"; s6 = "leafeon"; s7 = "glaceon"; s8 = "sylveon"; int l, i, j, c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0, c8 = ...
2
#include <bits/stdc++.h> using namespace std; const int maxx = 1e5 + 10; int a[maxx], b[maxx]; int main() { std::ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; b[i] = a[i]; } sort(b + 1, b + 1 + n); int...
5
#include <bits/stdc++.h> using namespace std; struct ww { int a, b; } f[200010]; int i, j, k, n, m, nn; int l[11], L[11], R[11], r[200010], rr[200010], t[200010], tt[200010], sa[200010], h[200010], ss[200010], dep[200010], bei[200010][20]; char s[200010], p[11][200010], v[200010]; vector<pair<int, int> > V[200010...
16
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, a, b; cin >> n >> a >> b; a += b; a %= n; a > 0 ? cout << a : cout << a + n; return 0; }
2
#include <bits/stdc++.h> int height[5001], dp[5001], mh[5001]; int getmin(int a, int b) { if (a < b) return a; return b; } int main() { int sum, n, i, j, k; while (~scanf("%d", &n)) { for (i = 1; i <= n; i++) { scanf("%d", &height[i]); dp[i] = 5001; mh[i] = 5001; } height[0] = 0; ...
13
#include <bits/stdc++.h> using namespace std; int main() { int N, M, i, L, R; cin >> N >> M; vector<pair<int, int> > A(M); vector<int> Row(N + 1, 0); vector<int> Column(N + 1, 0); for (i = 0; i < M; ++i) { cin >> L >> R; Row[L] = Column[R] = 1; } int ans = 0; for (i = 2; i + i <= N; ++i) a...
10
#include <bits/stdc++.h> #pragma GCC fast("Ofast") using namespace std; long long N = 1e6; signed main() { long long int t = 1; while (t-- > 0) { long long int n; cin >> n; vector<long long int> v(n); for (auto i = 0; i < n; i++) { cin >> v[i]; } sort(v.begin(), v.end()); long long...
1
#include <bits/stdc++.h> using namespace std; const int MA = 1e5 + 5; int num[MA]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &num[i]); } sort(num + 1, num + 1 + n); if (num[n / 2 + 1] != num[1]) { printf("Alice\n"); } else printf("Bob\n"); return 0; }
12
#include <bits/stdc++.h> using namespace std; long long cfreq[500100], org[500100]; long long arr[500100]; vector<long long> vec; int main() { long long t, n, i, j, k, l, m; ios_base::sync_with_stdio(0); cin.tie(0); t = 1; while (t--) { long long second; cin >> m >> k >> n >> second; for (i = 1; i...
11
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; int main() { int n, m, k; long long ans = 0; scanf("%d", &n); std::vector<std::vector<int>> ch(n + 1); std::vector<int> par(n + 1); std::vector<std::vector<int>> nb(n + 1); std::vector<std::vector<int>> lvl(n + 1); std::vector<int...
15
#include <bits/stdc++.h> using namespace std; int a1, a2, a3, a4, a5, a6; int solve() { int sum = 0; sum = (a1 + a2 + a6) * (a1 + a2 + a6) - a2 * a2 - a4 * a4 - a6 * a6; return sum; } int main() { scanf("%d%d%d%d%d%d", &a1, &a2, &a3, &a4, &a5, &a6); int mabi = solve(); cout << mabi << endl; return 0; }
8
#include <bits/stdc++.h> using namespace std; int main() { int k, d; cin >> k >> d; if (d == 0 && k > 1) cout << "No solution"; else { cout << d; for (int i = 0; i < k - 1; ++i) cout << 0; } return 0; }
3
#include <bits/stdc++.h> using namespace std; int inv_mod(int a, int b, int mmod) { if (a == 1) return b; int div = mmod / a + 1; return inv_mod((a * (long long)div) % mmod, (b * (long long)div) % mmod, mmod); } pair<int, int> solve(int m, int n, vector<int> a) { if (n == 1) return pair<int, in...
18
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; vector<pair<int, int> > lines; set<int> s; for (int i = 0; i < 2 * n; i++) { s.insert(i + 1); } for ...
10
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const double eps = 1e-9; const int MAX_N = 1e6 + 5; const int inf = 2e9; const long long Inf = (long long)1e18; const long long M = (long long)1e9 + 7; int Int() { int x; scanf("%d", &x); return x; } long long Long() { long long x; scanf("%l...
11
#include <bits/stdc++.h> #pragma GCC diagnostic ignored "-Wunused-result" using namespace std; struct Solution { long long int n, q; string s; void input() { do { scanf("%lld", &n); } while (0); do { scanf("%lld", &q); } while (0); do { char __tcstr[n + 9]; scanf("%s", ...
9
#include <bits/stdc++.h> using namespace std; int uzs; long long int cev = 1; string s; int main() { cin >> s; uzs = s.size(); for (int i = 0; i < uzs;) { int say = 0; int tut = s[i] - '0'; say++; i++; while (i < uzs && s[i] - '0' == 9 - tut) { tut = 9 - tut; say++; i++; ...
7
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int N = 1e5 + 5; int a[N], cnt[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; multiset<int> s; for (int i = 1; i <= n; ++i) { cin >> a[i]; cnt[a[i]] = -1; } for (int i = 1; ...
7
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 5; int a[N], prop[4 * N]; void update(int at, int l, int r, int lo, int hi, int val) { if (l > hi or r < lo) return; if (l >= lo and r <= hi) { prop[at] += val; return; } int left = at + at, right = left + 1, mid = (l + r) / 2; updat...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 505; int arr[MAXN]; int arr_copy[MAXN]; void rotate(int ind) { int num1 = arr[ind], num2 = arr[ind + 1], num3 = arr[ind + 2]; arr[ind] = num3; arr[ind + 1] = num1; arr[ind + 2] = num2; } void swap_back(int ind, int distance, vector<int>& actions) { ...
16
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { int a, b; cin >> a >> b; int k = min(b, (a + b) / 3); cout << min(a, k) << endl; } return 0; }
3
#include <bits/stdc++.h> using namespace std; const long long OO = 1e8; const double EPS = (1e-7); int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; } const int N = 100; int main() { ios::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); vector<int> p(n); for (int i = 0...
1
#include <bits/stdc++.h> struct pairhash { template <typename T, typename U> std::size_t operator()(const std::pair<T, U> &x) const { return std::hash<T>()(x.first) ^ std::hash<U>()(x.second); } }; long long compute_gcd(long long a, long long b) { if (b == 0) return a; return compute_gcd(b, a % b); } unsi...
15
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; inline long long read() { long long x = 0, ch = getchar(), f = 0; while (!isdigit(ch)) f = ch == '-', ch = getchar(); while (isdigit(ch)) x = (x << 3) + (x << 1) + ch - 48, ch = getchar(); return f ? -x : x; } inline long long ksm(long...
21
#include <bits/stdc++.h> using namespace std; int a, i, n, k, s[2000001], minn, maxx, nr, d; int main() { minn = 99999999; cin >> n >> k; for (i = 1; i <= n; i++) { cin >> a; s[a]++; if (a < minn) minn = a; if (a > maxx) maxx = a; } if (k >= minn - 1) cout << minn; else { for (i = 1;...
13
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; cin >> T; while (T--) { solve(); } } void solve() { string s; cin >> s; int i, f1 = 0, f2 = 0; string w = s; for (i = 0; i < s.length() - 1; i++) { if (s[...
1
#include <bits/stdc++.h> using namespace std; int main() { string str1, str2; cin >> str1 >> str2; if (str1 == str2) { cout << "-1\n"; } else { cout << max(str1.length(), str2.length()) << "\n"; } }
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long w, h; cin >> w >> h; long long k; cin >> k; int h1min = INT_MAX, h1max = 0; while (k--) { int temp; cin >> temp; h1min ...
2
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(2 * N), FA(N); int p0 = 0; for (int i = 0; i < N; ++i) { int x; cin >> x; if (x != 0) { FA[x] = p0; A[p0++] = x; } } vector<int> B(2 * N), FB(N); int p1 = 0; for (int i = 0; i < N; ++i...
5
#include <bits/stdc++.h> using namespace std; int qreadInt() { int x = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); while (ch >= '0' && ch <= '9') (x *= 10) += (ch ^ 48), ch = getchar(); return x; } int s[2010][2010], Ans[5010], dp[2010][2010]; pair<int, int> q[4000010]; int vis[2010][...
11
#include <bits/stdc++.h> using namespace std; int main() { long long n, ll, rr, num = 0LL, cnt = 0LL, rest = 0LL, ans = 0LL, ans_mx = 0LL, ans_mn = 1e12; scanf("%lld%lld%lld", &n, &ll, &rr); for (long long l = ll; l <= rr; ++l) { num = pow(2LL, (l - 1LL)); cnt = n - l + 1LL; res...
1
#include <bits/stdc++.h> using namespace std; template <typename T> T mabs(const T &a) { return a < 0 ? -a : a; } const int SZ = 2005; bool board[SZ][SZ]; int vertPows[SZ][SZ] = {0}; char res[SZ][SZ]; int di[] = {-1, 1, 0, 0}; int dj[] = {0, 0, -1, 1}; void run() { char buf[2005]; int n, m; scanf("%d%d", &n, &m...
12
#include <bits/stdc++.h> using namespace std; int n, m, k, q, x, y, z, grid[501][501], mn[501][501], ans = (int)1e9 + 1; multiset<int> cur; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); for (int i = 1; i <= 500; i++) for (int j = 1; j <= 500; j++) mn[i][j] = (int)1e9 + 1, g...
11
#include <bits/stdc++.h> using namespace std; void fastscan(long long &x) { bool neg = false; register long long c; x = 0; c = getchar(); if (c == '-') { neg = true; c = getchar(); } for (; (c > 47 && c < 58); c = getchar()) { x = x * 10 + c - 48; } if (neg) { x *= -1; } } void file(...
4
/* 2013-08-10 14:29:59.733670 */#include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib> #include <cmath> #include <cctype> #include <ctime> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <map> #include <set> #include <cassert>...
5
#include<bits/stdc++.h> using namespace std; #define int long long int cal() { return 1; } int32_t main() { int t = 1, n, m; cin >> t; while(t--) { cin >> n; string s; cin >> s; vector<int> pre(n, 0), suf(n, 0); int cnt = (s[0] == '.'); for(int i...
6
#include <bits/stdc++.h> using namespace std; int n, m, a[1005], x, y; long long ans; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", a + i); for (int i = 1; i <= m; i++) { scanf("%d%d", &x, &y); ans += min(a[x], a[y]); } printf("%lld", ans); return 0; }
6
#include <bits/stdc++.h> using namespace std; int main() { int a = 0, b = 0; string s; cin >> s; for (int i = 0; i < s.size(); ++i) { ((s[i] == '-') ? ++a : ++b); } if (b == 0) cout << "YES"; else cout << ((a % b == 0) ? "YES" : "NO"); return 0; }
1
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; long double yy1, y2, yw, x, y, r; long double check(long double m) { long double xx = x * (yw - m) / (yw + yw - y - m); long double mm = (yw - m) / xx; if ((y2 - m) / sqrt(mm * mm + 1.0) < r) return -1; else return xx; } int mai...
12
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int x, n, m; cin >> x >> n >> m; while (n-- && x > 20) { x = (x / 2) + 10; } while (m--) { x = x - 10; } if (x <= 0) cout << "YES" << endl; else cout << "NO" << endl; ...
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); } string toBin(long long a) { string res = ""; while (a) { res += char((a & 1) + '0'); a >>= 1; } reverse(res.begin(), res.end()); return res; } const int mod = 1e9 +...
11
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, k, l, m, n; long long negs = 0, pos = 0, zero = 0, NN = 0, PP = 0; cin >> n; for (i = 0; i < n; i++) { cin >> l; if (l < 0) { NN++; negs += l; } else if (l > 0) { PP++; pos += l; } else zero+...
1