solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1;
int n, m, q, mark[N], bounds[N], lb[N];
vector<int> g[N];
long long ls[N], gr[N];
stack<int> st;
void dfs(int u, int par) {
mark[u] = 1;
st.push(u);
for (int v : g[u])
if (v != par) {
if (!mark[v])
dfs(v, u);
else if (mark[v] == 1) {
stack<int> tmp;
int mn = v, mx = v;
while (st.top() != v) {
mn = min(st.top(), mn);
mx = max(st.top(), mx);
tmp.push(st.top());
st.pop();
}
while (!tmp.empty()) st.push(tmp.top()), tmp.pop();
bounds[mx] = min(mn, bounds[mx]);
}
}
mark[u] = 2;
st.pop();
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0, u, v; i < m; i++) {
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
fill(bounds + 1, bounds + n + 1, INT_MAX);
for (int i = 1; i <= n; i++)
if (!mark[i]) dfs(i, -1);
for (int i = 1, j = 1; i <= n; i++) {
j = max(bounds[i] + 1, j);
lb[i] = j;
ls[i] = ls[i - 1] + i;
gr[i] = gr[i - 1] + i - j + 1;
}
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
int s = l, e = r;
while (s < e) {
int mid = s + e + 1 >> 1;
if (lb[mid] < l)
s = mid;
else
e = mid - 1;
}
long long res = 0;
if (lb[s] < l) {
res += ls[s] - ls[l - 1] - 1ll * (s - l + 1) * (l - 1);
res += gr[r] - gr[s];
} else {
res += gr[r] - gr[l - 1];
}
cout << res << '\n';
}
}
| 9 | CPP |
# https://codeforces.com/contest/1409/problem/B
for ctr in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
if(a[0] + a[1] > a[-1]):
print(-1)
else:
print(1, " ", 2, " ", n)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long maxn = 15e5 + 10;
const long long inf = 1e14;
long long n, m, k, t;
long long cur1, cur2;
long long C[maxn];
vector<long long> ANS;
vector<pair<long long, long long> > X[4];
void add(vector<long long> good) {
long long mn = inf + 1, mni = 3;
for (long long q = 0; q < 4; q++) {
if (!good[q]) {
continue;
}
if (X[q].back().first < mn) {
mn = X[q].back().first;
mni = q;
}
}
ANS.push_back(X[mni].back().second);
X[mni].pop_back();
if (mni / 2 == 1) {
cur2 = max(0LL, cur2 - 1);
}
if (mni % 2 == 1) {
cur1 = max(0LL, cur1 - 1);
}
}
void add1() { add({0, 1, 0, 1}); }
void add2() { add({0, 0, 1, 1}); }
void add0() { add({1, 1, 1, 1}); }
void add3() { add({0, 0, 0, 1}); }
void add_def() {
long long q, w, e;
vector<long long> mni = {0, 1};
long long mn = inf;
for (q = 0; q < 4; q++) {
for (w = q + 1; w < 4; w++) {
if ((q | w) != 3) {
continue;
}
vector<long long> dmni = {q, w};
long long dmn = X[q].back().first + X[w].back().first;
if (dmn < mn) {
mn = dmn;
mni = dmni;
}
}
}
for (auto i : mni) {
ANS.push_back(X[i].back().second);
X[i].pop_back();
if (i / 2 == 1) {
cur2 = max(cur2 - 1, 0LL);
}
if (i % 2 == 1) {
cur2 = max(cur2 - 1, 0LL);
}
}
}
bool used[maxn];
long long I[maxn];
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long q, w, e, a, b, c;
cin >> n >> m >> k;
cur1 = cur2 = k;
vector<pair<long long, long long> > ALL;
for (q = 0; q < n; q++) {
cin >> a >> b >> c;
C[q] = a;
long long i = b * 2 + c;
X[i].push_back(make_pair(a, q));
ALL.push_back(make_pair(a, q));
}
for (q = 0; q < n; q++) {
for (w = 0; w < 4; w++) {
X[w].push_back(make_pair(inf, n + q * 4 + w));
ALL.push_back(make_pair(inf, n + q * 4 + w));
}
}
long long alln = n + n * 4;
sort(ALL.begin(), ALL.end());
for (q = 0; q < 4; q++) {
sort(X[q].begin(), X[q].end());
}
long long mn = 1e18, mni = 0;
long long cur = 0;
for (q = 0; q < k; q++) {
cur += X[3][q].first;
used[X[3][q].second] = 1;
}
for (q = 0; q < ALL.size(); q++) {
I[ALL[q].second] = q;
}
long long cnt = 0;
for (q = 0; cnt < m - k; q++) {
if (used[ALL[q].second]) {
continue;
}
cur += ALL[q].first;
cnt++;
}
long long iall = q - 1;
if (cur < mn) {
mn = cur;
mni = k;
}
for (q = k - 1; q >= 0; q--) {
if (q + 2 * (k - q) > m) {
break;
}
used[X[3][q].second] = 0;
cur -= X[3][q].first;
if (I[X[3][q].second] <= iall) {
cur -= ALL[iall].first;
cur += X[3][q].first;
iall--;
while (iall >= 0 && used[ALL[iall].second]) {
iall--;
}
}
long long i1 = k - q - 1;
used[X[2][i1].second] = 1;
cur += X[2][i1].first;
if (I[X[2][i1].second] <= iall) {
cur -= X[2][i1].first;
iall++;
while (used[ALL[iall].second]) {
iall++;
}
cur += ALL[iall].first;
}
used[X[1][i1].second] = 1;
cur += X[1][i1].first;
if (I[X[1][i1].second] <= iall) {
cur -= X[1][i1].first;
iall++;
while (used[ALL[iall].second]) {
iall++;
}
cur += ALL[iall].first;
}
cur -= ALL[iall].first;
iall--;
while (iall >= 0 && used[ALL[iall].second]) {
iall--;
}
if (cur < mn) {
mn = cur;
mni = q;
}
}
for (q = 0; q < alln; q++) {
used[q] = 0;
}
for (q = 0; q < mni; q++) {
ANS.push_back(X[3][q].second);
used[X[3][q].second] = 1;
}
for (q = 0; q < k - mni; q++) {
ANS.push_back(X[1][q].second);
used[X[1][q].second] = 1;
ANS.push_back(X[2][q].second);
used[X[2][q].second] = 1;
}
cnt = 0;
for (q = 0; cnt < m - mni - 2 * (k - mni); q++) {
if (!used[ALL[q].second]) {
ANS.push_back(ALL[q].second);
cnt++;
}
}
for (auto i : ANS) {
if (i >= n) {
cout << -1;
return 0;
}
}
cout << mn << endl;
for (q = 0; q < ANS.size(); q++) {
cout << ANS[q] + 1 << " ";
}
return 0;
}
| 11 | CPP |
n, m = map(int, input().split())
d = list(map(int, input().split()))
s = input()
i = res = 0
while i < len(s):
j = i;
while i+1 < len(s) and s[i+1] == s[i]:
i += 1
res += sum(sorted(d[j:i+1])[-m:])
i += 1
print(res)
| 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long fac[2000009], not_prime[2000009];
long long power(long long x, long long n) {
if (n == 0) return 1;
if (n % 2 == 0)
return power((x * x), n / 2);
else
return (x * power((x * x), (n - 1) / 2));
}
void fact() {
fac[0] = 1;
for (long long i = 1; i < 2000009; i++)
fac[i] = (i * fac[i - 1]) % 1000000007;
}
void sieve() {
not_prime[1] = 1;
not_prime[0] = 1;
for (long long p = 2; p * p < 2000009; p++) {
if (!not_prime[p]) {
for (long long i = p * 2; i <= 2000009; i += p) not_prime[i] = 1;
}
}
}
long long modi(long long a, long long m) {
long long m0 = m, t, q;
long long x0 = 0, x1 = 1;
if (m == 1) return 0;
while (a > 1) {
q = a / m;
t = m;
m = a % m, a = t;
t = x0;
x0 = x1 - q * x0;
x1 = t;
}
if (x1 < 0) x1 += m0;
return x1;
}
long long n, m, id[2000009], st[2000009];
int main() {
long long i, j, r, k, l, c, test, flag, ans1, ans2, a, b;
string s;
cin >> a >> b >> c;
a %= b;
for (i = 1; i <= 1000000; i++) {
a *= 10;
if (a / b == c) {
cout << i;
return 0;
}
a %= b;
}
cout << "-1";
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[181][181], type[12001], one[12001], two[12001], three[12001], n, m, i, j,
q;
void revR(int nom) {
int i;
for (i = m; i >= 2; i--) swap(a[nom][i - 1], a[nom][i]);
}
void revC(int nom) {
int i;
for (i = n; i >= 2; i--) swap(a[i - 1][nom], a[i][nom]);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> q;
for (i = 1; i <= q; i++) {
cin >> type[i] >> one[i];
if (type[i] == 3) cin >> two[i] >> three[i];
}
for (i = q; i >= 1; i--)
if (type[i] == 1)
revR(one[i]);
else if (type[i] == 2)
revC(one[i]);
else
a[one[i]][two[i]] = three[i];
for (i = 1; i <= n; i++) {
for (j = 1; j <= m - 1; j++) cout << a[i][j] << " ";
cout << a[i][m] << '\n';
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long getn() {
long long h;
scanf("%d", &h);
return h;
}
int main() {
vector<pair<int, int> > V;
int n = getn();
for (int i = 0; i < n; i++) {
int po = getn();
int x = getn();
V.push_back(make_pair((po + x), (po - x)));
}
sort(V.begin(), V.end());
int maxi = 0;
int kon = -2000100100;
int zob = 0;
for (int i = 0; i < n; i++) {
if (V[i].second >= kon) {
kon = V[i].first;
zob++;
}
}
printf("%d\n", zob);
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int N = 2 * 5000000;
bool isexist[N + 1] = {false};
long long solve(long long b, long long c) {
long long ret = 0;
long long tmp1 = (long long)sqrt(b * b - 1),
tmp2 = (long long)sqrt(b * b - min(b * b, c + 1));
ret = 2 * (min(b * b - 1, c) - (tmp1 - tmp2));
long long cnt = (long long)floor(sqrt(b * b - 1)) -
(long long)ceil(sqrt(b * b - min(b * b, c + 1)));
if (c >= b * b) {
if (!isexist[N - b]) ret++;
isexist[N - b] = true;
}
long long l = (long long)ceil(sqrt(b * b - min(b * b, c))),
r = (long long)floor(sqrt(b * b - 1));
for (int i = l; i < r + 1; i++) {
if (!isexist[N + -b + i]) ret++;
isexist[N + -b + i] = true;
if (!isexist[N + -b - i]) ret++;
isexist[N + -b - i] = true;
}
return ret;
}
int main() {
long long b, c;
long long ans = 0;
cin >> b >> c;
for (int i = 0; i < N + 1; i++) isexist[i] = false;
for (int i = 1; i < b + 1; i++) {
ans += solve(i, c);
}
cout << ans << endl;
return false;
}
| 11 | CPP |
n = int(input())
if n % 2 != 0:
print(-1)
else:
count = 0
for i in range(1, n + 1):
count += 1
if count == 2:
print(i, i - 1, end=" ")
count = 0
| 7 | PYTHON3 |
from sys import stdin
def solve(vec):
ans=0
lista=[]
for i in range (len(vec)):
if '+' in vec[i]:
ans+=1
else:
ans-=1
return ans
def main():
vec=[]
line=int(stdin.readline().strip())
for i in range(line):
v=stdin.readline().strip()
vec.append(v)
print(solve(vec))
main()
| 7 | PYTHON3 |
param = input().split(' ')
n = int(param[0])
m = int(param[1])
if (m-1) >= (n-m):
if m-1 == 0:
print(m)
else:
print(str(m-1))
else:
print(str(m+1)) | 8 | PYTHON3 |
hero_strength, n = map(int, input().split())
dragons = []
for i in range(n):
dragon = list(map(int, input().split()))
dragons.append(dragon)
while dragons:
ddddd = dragons.copy()
for dragon in dragons:
if dragon[0] < hero_strength:
hero_strength += dragon[1]
dragons.remove(dragon)
if ddddd == dragons:
break
if dragons:
print('NO')
else:
print('YES') | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
scanf("%d", &n);
stack<int> st;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
if (st.size() && st.top() % 2 == x % 2) {
st.pop();
} else {
st.push(x);
}
}
if (st.size() <= 1)
printf("YES\n");
else
printf("NO\n");
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 1201000;
int n, L;
long long a[N], b[N];
pair<long long, int> pos[N], s[N], q[N];
bool check(int x) {
if (2 * x >= L) return 1;
int tot = 0;
for (int i = 1; i < 3 * n + 1; i++) pos[tot++] = make_pair(a[i] + x, -1);
for (int i = 1; i < 3 * n + 1; i++) pos[tot++] = make_pair(b[i], 1);
inplace_merge(pos, pos + 3 * n, pos + 6 * n);
int cur = 0;
int m = 0;
s[m++] = make_pair(-1, cur);
for (int i = 0; i < tot; i++) {
cur += pos[i].second;
if (pos[i].first != pos[i + 1].first) s[m++] = make_pair(pos[i].first, cur);
}
int r1 = 0, r2 = 0;
int h = 0, t = -1;
for (int i = n + 1; i < 2 * n + 1; i++) {
while (a[r1 + 1] <= b[i] + x) r1++;
while (r2 < m && s[r2].first <= b[i]) {
while (h <= t && s[r2].second < q[t].second) --t;
q[++t] = s[r2++];
}
while (h + 1 <= t && q[h + 1].first < b[i] + 2 * x - L) ++h;
if (i - r1 > q[h].second) return 0;
}
return 1;
}
bool checkbf(int x) {
if (2 * x >= L) return 1;
int h = 0, t = -1;
int r1 = 0, r2 = 0;
for (int i = 1; i < n + 1; i++) {
while (a[r2 + 1] <= b[i] - x - 1) r2++;
int val = i - r2 - 1;
while (h <= t && val < q[t].second) --t;
q[++t] = make_pair(b[i], val);
}
for (int i = n + 1; i < 2 * n + 1; i++) {
while (a[r1 + 1] <= b[i] + x) r1++;
while (a[r2 + 1] <= b[i] - x - 1) r2++;
int val = i - r2 - 1;
while (h <= t && val < q[t].second) --t;
q[++t] = make_pair(b[i], val);
while (h <= t && q[h].first < b[i] + 2 * x - L) ++h;
if (i - r1 > q[h].second) return 0;
}
return 1;
}
int main() {
while (scanf("%d%d", &n, &L) != EOF) {
for (int i = 1; i < n + 1; i++) scanf("%lld", a + i);
sort(a + 1, a + n + 1);
for (int i = 1; i < n + 1; i++) scanf("%lld", b + i);
sort(b + 1, b + n + 1);
for (int i = n + 1; i < 3 * n + 1; i++) b[i] = b[i - n] + L;
for (int i = n + 1; i < 3 * n + 1; i++) a[i] = a[i - n] + L;
int l = -1, r = L + 1;
while (l + 1 < r) {
int md = (l + r) >> 1;
if (checkbf(md))
r = md;
else
l = md;
}
printf("%d\n", r);
}
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 2 * 100009;
struct Node {
long long int inc;
long long int max;
} nodes[SIZE * 8];
void inc(int idx, int l, int r, int s, int e, long long int d) {
if (s <= l && r <= e) {
nodes[idx].inc += d;
nodes[idx].max += d;
} else {
int m = (l + r) >> 1;
if (nodes[idx].inc) {
inc(idx * 2, l, m, l, m, nodes[idx].inc);
inc(idx * 2 + 1, m, r, m, r, nodes[idx].inc);
nodes[idx].inc = 0;
}
if (s < m) inc(idx * 2, l, m, s, e, d);
if (e > m) inc(idx * 2 + 1, m, r, s, e, d);
nodes[idx].max = max(nodes[idx * 2].max, nodes[idx * 2 + 1].max);
}
}
long long int query(int idx, int l, int r, int s, long long int e) {
if (s <= l && r <= e)
return nodes[idx].max;
else {
int m = (l + r) >> 1;
if (nodes[idx].inc) {
inc(idx * 2, l, m, l, m, nodes[idx].inc);
inc(idx * 2 + 1, m, r, m, r, nodes[idx].inc);
nodes[idx].inc = 0;
}
if (s >= m)
return query(idx * 2 + 1, m, r, s, e);
else if (e <= m)
return query(idx * 2, l, m, s, e);
else
return max(query(idx * 2, l, m, s, e), query(idx * 2 + 1, m, r, s, e));
}
}
int cs[SIZE];
struct Race {
int a, b, c;
bool operator<(const Race& other) const { return b < other.b; }
} races[SIZE];
int main() {
int N, M;
scanf("%d%d", &N, &M);
for (int i = 1; i <= N; i++) scanf("%d", cs + i);
for (int i = 0; i < M; i++)
scanf("%d%d%d", &races[i].a, &races[i].b, &races[i].c);
sort(races, races + M);
long long int ans = 0;
for (int i = 1, j = 0; i <= N; i++) {
long long int t = query(1, 0, N + 1, i - 1, i);
long long int cost = cs[i];
inc(1, 0, N + 1, 0, i, -cost);
while (j < M && races[j].b == i) {
inc(1, 0, N + 1, 0, races[j].a, races[j].c);
j++;
}
long long op = max(t, query(1, 0, N + 1, 0, i));
ans = max(ans, op);
inc(1, 0, N + 1, i, i + 1, ans);
}
printf("%I64d\n", ans);
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("popcnt")
using namespace std;
struct point {
int x, y;
} ps[1010];
struct Line {
int x, l, r;
Line(int _x = 0, int _l = 0, int _r = 0) { x = _x, l = _l, r = _r; }
};
int match[2][1010], n;
bool mark[2][1010], vis[1010];
vector<int> nxt[2][1010];
vector<Line> vx, vy;
set<int> set_x, set_y;
set<pair<int, int> > set_point;
template <class T>
void read(T &x) {
char ch = x = 0;
bool fl = false;
while (!isdigit(ch)) fl |= ch == '-', ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
x = fl ? -x : x;
}
bool hungary(int x) {
for (auto &v : nxt[0][x]) {
if (!vis[v]) {
vis[v] = true;
if (!match[1][v] || hungary(match[1][v]))
return match[0][x] = v, match[1][v] = x, true;
}
}
return false;
}
void dfs(int x, int type) {
mark[type][x] = true;
for (auto &v : nxt[type][x]) {
if ((match[type][x] == v) ^ type && !mark[type ^ 1][v]) dfs(v, type ^ 1);
}
}
inline bool intersact(Line A, Line B) {
return A.x >= B.l && A.x <= B.r && B.x >= A.l && B.x <= A.r;
}
int main() {
read(n);
for (int i = 1; i <= n; i++) {
read(ps[i].x), read(ps[i].y);
set_x.insert(ps[i].x), set_y.insert(ps[i].y);
set_point.insert({ps[i].x, ps[i].y});
}
auto cmp_x = [&](point A, point B) {
return A.x == B.x ? A.y < B.y : A.x < B.x;
};
auto cmp_y = [&](point A, point B) {
return A.y == B.y ? A.x < B.x : A.y < B.y;
};
sort(ps + 1, ps + 1 + n, cmp_x);
for (int i = 1; i <= n; i++)
if (ps[i].x == ps[i - 1].x)
vx.push_back(Line(ps[i].x, ps[i - 1].y, ps[i].y));
sort(ps + 1, ps + 1 + n, cmp_y);
for (int i = 1; i <= n; i++)
if (ps[i].y == ps[i - 1].y)
vy.push_back(Line(ps[i].y, ps[i - 1].x, ps[i].x));
int szx = vx.size(), szy = vy.size();
for (int i = 0; i < szx; i++)
for (int j = 0; j < szy; j++)
if (intersact(vx[i], vy[j]))
if (set_point.find({vx[i].x, vy[j].x}) == set_point.end())
nxt[0][i + 1].push_back(j + 1), nxt[1][j + 1].push_back(i + 1);
for (int i = 1; i <= szx; i++) {
memset(vis, 0, sizeof(vis)), hungary(i);
}
for (int i = 1; i <= szy; i++) {
if (!match[1][i]) dfs(i, 1);
}
int ans_x = set_x.size(), ans_y = set_y.size();
for (int i = 1; i <= szy; i++) ans_y += !mark[1][i];
printf("%d\n", ans_y);
sort(ps + 1, ps + 1 + n, cmp_y);
for (int i = 1, lst = 0, tmp = 0; i <= n + 1; i++) {
if (ps[i].y == ps[i - 1].y) {
if (!mark[1][++tmp])
printf("%d %d %d %d\n", lst, ps[i].y, ps[i - 1].x, ps[i].y),
lst = ps[i].x;
} else {
if (i > 1)
printf("%d %d %d %d\n", lst, ps[i - 1].y, ps[i - 1].x, ps[i - 1].y);
lst = ps[i].x;
}
}
for (int i = 1; i <= szx; i++) ans_x += mark[0][i];
printf("%d\n", ans_x);
sort(ps + 1, ps + n + 1, cmp_x);
for (int i = 1, lst = 0, tmp = 0; i <= n + 1; i++) {
if (ps[i].x == ps[i - 1].x) {
if (mark[0][++tmp])
printf("%d %d %d %d\n", ps[i].x, lst, ps[i].x, ps[i - 1].y),
lst = ps[i].y;
} else {
if (i > 1)
printf("%d %d %d %d\n", ps[i - 1].x, lst, ps[i - 1].x, ps[i - 1].y);
lst = ps[i].y;
}
}
return 0;
}
| 12 | CPP |
st = input()
newst = str(set(st))
if len(newst)%2 == 0:
print("CHAT WITH HER!")
else:
print("IGNORE HIM!") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const long long LINF = 1000000000000000000;
const long long MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
inline void add(T& a, T b) {
a = ((a + b) % MOD + MOD) % MOD;
};
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long lcm(long long m, long long n) {
if ((0 == m) || (0 == n)) return 0;
return ((m / gcd(m, n)) * n);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long n, x, y;
cin >> n >> x >> y;
vector<long long> atk, cum;
long long X = x;
long long Y = y;
for (int i = 0; i < x + y; i++) {
if (X < Y) {
atk.push_back(X);
X += x;
} else if (X > Y) {
atk.push_back(Y);
Y += y;
} else {
atk.push_back(X);
X += x;
atk.push_back(Y);
Y += y;
i++;
}
}
sort(atk.begin(), atk.end());
for (int i = 0; i < n; i++) {
long long a;
cin >> a;
a--;
int idx = a % (x + y);
if (atk[idx] % x == 0) {
if (atk[idx] % y == 0)
cout << "Both" << endl;
else
cout << "Vova" << endl;
} else
cout << "Vanya" << endl;
}
}
| 10 | CPP |
#include <bits/stdc++.h>
using std::max;
using std::min;
inline int read() {
register int x = 0, v = 1;
register char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') v = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * v;
}
const int MOD = 1e9 + 7;
const int MAXN = 5000;
int n, K, ans;
int a[MAXN | 1], frac[MAXN | 1], ifrac[MAXN | 1], c[MAXN | 1];
inline int fpow(int x, int y) {
int res = 1, base = x;
while (y > 0) {
if (y & 1) res = 1LL * res * base % MOD;
base = 1LL * base * base % MOD;
y >>= 1;
}
return res;
}
int main() {
frac[0] = 1;
for (int i = 1; i <= MAXN; ++i) frac[i] = 1LL * frac[i - 1] * i % MOD;
ifrac[MAXN] = fpow(frac[MAXN], MOD - 2);
for (int i = MAXN - 1; ~i; --i) ifrac[i] = 1LL * ifrac[i + 1] * (i + 1) % MOD;
n = read();
K = read();
c[0] = 1;
for (int i = 1; i <= n; ++i) {
a[i] = read();
for (int j = i; j >= 1; --j)
c[j] = (1LL * a[i] * c[j] % MOD + MOD - c[j - 1]) % MOD;
c[0] = 1LL * c[0] * a[i] % MOD;
}
ans = c[0];
int ninv = fpow(n, MOD - 2);
for (int i = 0, dm = 1, pw = 1; i <= min(n, K);
dm = 1LL * dm * (K - i) % MOD, pw = 1LL * pw * ninv % MOD, ++i)
ans = (ans - 1LL * c[i] * dm % MOD * pw % MOD + MOD) % MOD;
printf("%d\n", ans);
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
cin >> m >> n;
int k = m * n / 2;
cout << k << endl;
return 0;
}
| 7 | CPP |
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define mod 1000000007
using namespace std;
bool prime[1000010];
long long dp[1000000];
int q[1000000];
int main(){
rep(i,1000000)prime[i]=true;
prime[0]=prime[1]=false;
loop(i,2,1000000){
for(int j=2*i;j<1000000;j+=i)prime[j]=false;
}
int n;
cin>>n;
rep(i,n)cin>>q[i];
dp[1]=(prime[q[0]]?1:0);
loop(i,1,n+1){
dp[i]%=mod;
if(prime[q[i+1]]&&q[i-1]<q[i+1])dp[i+2]+=dp[i];
if(prime[q[i]]&&q[i-1]<q[i])dp[i+1]+=dp[i];
}
cout<<(dp[n]+dp[n-1])%mod<<endl;
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, q;
const int MAXN = 100005;
vector<int> a[MAXN];
int best[MAXN];
int main() {
ios::sync_with_stdio(0);
cin >> n >> m;
for (int i = 0; i < n; i++) {
best[i] = i;
for (int j = 0; j < m; j++) {
int x;
cin >> x;
a[i].push_back(x);
}
}
for (int j = 0; j < m; j++) {
int k = 0;
for (int i = 1; i < n; i++) {
if (a[i][j] < a[i - 1][j]) k = i;
best[i] = min(best[i], k);
}
}
cin >> q;
for (int i = 0; i < q; i++) {
int l, r;
cin >> l >> r;
if (best[r - 1] <= l - 1)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 220000;
pair<int, int> a[N];
int nxt[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int d, n, m;
cin >> d >> n >> m;
for (int i = 0; i < m; i++) cin >> a[i].first >> a[i].second;
sort(a, a + m);
a[m] = make_pair(d, 0);
for (int i = m - 1; i >= 0; i--) {
if (a[i + 1].second < a[i].second)
nxt[i] = i + 1;
else {
int cnt = nxt[i + 1];
while (a[cnt].second > a[i].second) {
cnt = nxt[cnt];
}
nxt[i] = cnt;
}
}
int now = 0, gas = n;
long long cost = 0;
for (int i = 0; i < m; i++) {
gas -= (a[i].first - now);
now = a[i].first;
if (gas < 0) {
cout << -1 << endl;
return 0;
}
long long how = (long long)(min(n, a[nxt[i]].first - now) - gas);
if (how >= 0) {
cost += how * a[i].second;
gas = min(n, a[nxt[i]].first - now);
}
}
gas -= (d - now);
if (gas < 0) {
cout << -1 << endl;
return 0;
}
cout << cost << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (y1 != y2 && x1 != x2 && (abs(x1 - x2) != abs(y1 - y2))) {
cout << "-1" << endl;
return 0;
}
int x3, y3, x4, y4;
if (abs(x1 - x2) == abs(y1 - y2)) {
x3 = x1;
y3 = y2;
x4 = x2;
y4 = y1;
} else if (x1 == x2) {
x3 = x2 + abs(y2 - y1);
x4 = x1 + abs(y2 - y1);
y3 = y2;
y4 = y1;
} else if (y1 == y2) {
y3 = y2 + abs(x2 - x1);
y4 = y1 + abs(x2 - x1);
x3 = x2;
x4 = x1;
}
cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
return 0;
}
| 7 | CPP |
import sys
import math
def fast_input():
return sys.stdin.readline().strip()
def data_input():
return [int(x) for x in fast_input().split()]
def binary_search(array, x):
left, right = -1, len(array)
while left + 1 != right:
middle = (left + right) // 2
if array[middle] >= x:
right = middle
elif array[middle] < x:
left = middle
return right
def solve_of_problem():
n = int(fast_input())
r1 = data_input()
b = data_input()
o, r, count = 0, 0, 0
for i in range(n):
if b[i] == 1 and r1[i] == 0:
count += 1
elif r1[i] == 1 and b[i] == 0:
r += 1
if r == 0:
print(-1)
return
print((r + count) // r)
return
for ______ in range(1):
solve_of_problem() | 7 | PYTHON3 |
D,T,S=map(float,input().split())
if D/S<=T:
print('Yes')
else:
print('No') | 0 | PYTHON3 |
#include <bits/stdc++.h>
const int N = 500;
bool have_cycle;
int cycle_head = -1, cycle_start, mark[N], prev[N];
std::vector<int> cycle_vertexes;
std::vector<int> g[N];
bool dfs1(int u);
void dfs2(int u);
int main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
int n, m;
std::cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
std::cin >> u >> v;
u--;
v--;
g[u].emplace_back(v);
}
std::fill(prev, prev + n, -1);
for (int u = 0; u < n; u++) {
if (dfs1(u)) {
break;
}
}
if (cycle_head == -1) {
std::cout << "YES" << std::endl;
} else {
for (int u = cycle_head; u != cycle_start; u = prev[u]) {
cycle_vertexes.emplace_back(u);
}
cycle_vertexes.emplace_back(cycle_start);
std::stack<std::pair<int, int>> cycle_edges;
for (int u = cycle_vertexes.size() - 1; u; u--) {
cycle_edges.push({cycle_vertexes[u], cycle_vertexes[u - 1]});
}
cycle_edges.push({cycle_vertexes.front(), cycle_vertexes.back()});
for (; !cycle_edges.empty(); cycle_edges.pop()) {
std::pair<int, int> edge = cycle_edges.top();
auto pos = find(g[edge.first].begin(), g[edge.first].end(), edge.second);
*pos = -1;
have_cycle = false;
std::fill(mark, mark + n, 0);
for (int u = 0; u < n; u++) {
if (!mark[u]) {
dfs2(u);
}
}
*pos = edge.second;
if (!have_cycle) {
std::cout << "YES" << std::endl;
return 0;
}
}
std::cout << "NO" << std::endl;
}
return 0;
}
bool dfs1(int u) {
mark[u] = 1;
for (auto v : g[u]) {
if (!mark[v]) {
prev[v] = u;
if (dfs1(v)) {
return true;
}
} else if (mark[v] == 1) {
cycle_head = u;
cycle_start = v;
return true;
}
}
mark[u] = 2;
return false;
}
void dfs2(int u) {
mark[u] = 1;
for (auto v : g[u]) {
if (v != -1) {
if (!mark[v]) {
dfs2(v);
} else if (mark[v] == 1) {
have_cycle = true;
}
}
}
mark[u] = 2;
}
| 10 | CPP |
#include<bits/stdc++.h>
using namespace std;
const int INF=1<<30;
const int MaxRC=1e3;
int dx[4]={ 0, 1, 0,-1};
int dy[4]={ 1, 0,-1, 0};
struct DATA{
int x, y;
DATA(int x=0,int y=0):x(x),y(y){}
} st, ed, now, nxt;
int main(){
int R, C, K;
while(scanf("%d %d %d\n",&R,&C,&K)!=EOF){
scanf("%d %d %d %d\n",&st.x,&st.y,&ed.x,&ed.y);
st.x--, st.y--, ed.x--, ed.y--;
vector<vector<char>> mat(R, vector<char>(C));
for(int i=0;i<R;i++,getchar())
for(int j=0;j<C;j++)
mat[i][j]=getchar();
vector<vector<int>> step(R, vector<int>(C,INF));
queue<DATA> Q;
Q.push(DATA(st.x,st.y));
step[st.x][st.y]=0;
while(Q.empty()==0){
now=Q.front(); Q.pop();
if(now.x==ed.x and now.y==ed.y) break;
for(int i=0;i<4;i++)
for(int k=1;k<=K;k++){
nxt=DATA(now.x+k*dx[i],now.y+k*dy[i]);
if(nxt.x==-1 or nxt.x==R or nxt.y==-1 or nxt.y==C or mat[nxt.x][nxt.y]=='@' or step[nxt.x][nxt.y]<=step[now.x][now.y])
break;
if(step[nxt.x][nxt.y]>step[now.x][now.y]+1){
step[nxt.x][nxt.y]=step[now.x][now.y]+1;
Q.push(nxt);
}
}
}
printf("%d\n",(step[ed.x][ed.y]==INF)? -1: step[ed.x][ed.y]);
}
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct Graph {
unordered_map<int, unordered_set<int>> list;
void add_edge(int u, int v) {
list[u].insert(v);
list[v].insert(u);
}
};
int dfs(Graph& g, int u, unordered_set<int>& visited, vector<int>& succ) {
for (int v : g.list[u]) {
if (visited.count(v) <= 0) {
visited.insert(v);
succ[u] += 1 + dfs(g, v, visited, succ);
}
}
return succ[u];
}
void dfs(Graph& g, unordered_map<int, int>& dists) {
stack<int> s;
unordered_set<int> visited;
s.push(1);
visited.insert(1);
dists[1] = 0;
while (!s.empty()) {
int u = s.top();
s.pop();
bool has = false;
for (int v : g.list[u]) {
if (visited.count(v) <= 0) {
visited.insert(v);
s.push(v);
dists[v] = dists[u] + 1;
has = true;
}
}
}
}
long long dfs(Graph& g, vector<bool>& marked) {
vector<int> above(g.list.size() + 1);
above[1] = 1;
unordered_set<int> visited;
stack<int> s;
s.push(1);
visited.insert(1);
while (!s.empty()) {
int u = s.top();
s.pop();
for (int v : g.list[u]) {
if (visited.count(v) <= 0) {
s.push(v);
visited.insert(v);
if (marked[v])
above[v] = above[u];
else
above[v] = above[u] + 1;
}
}
}
long long sum = 0;
for (int u = 1; u < g.list.size() + 1; ++u) {
if (marked[u]) sum += above[u];
}
return sum;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
Graph g;
for (int i = 0; i < n - 1; ++i) {
int u, v;
cin >> u >> v;
g.add_edge(u, v);
}
vector<int> succ(n + 1, 0);
unordered_set<int> visited;
visited.insert(1);
dfs(g, 1, visited, succ);
unordered_map<int, int> dists;
dfs(g, dists);
vector<pair<int, int>> vertices;
for (auto& e : dists) {
vertices.push_back({e.first, dists[e.first] - (succ[e.first] - 1)});
}
sort(vertices.begin(), vertices.end(),
[&](const pair<int, int>& a, const pair<int, int>& b) {
return a.second > b.second;
});
vector<bool> marked(n + 1);
for (int i = 0; i < k; ++i) {
marked[vertices[i].first] = true;
}
long long sum = dfs(g, marked);
cout << sum << endl;
}
| 9 | CPP |
def Floornum(house,num):
count=2
flag=0
if house<=2:
return 1
else:
while flag==0:
if house>=((count-2)*num)+3 and house<=((count-1)*num)+2:
floor_count=count
flag=1
return floor_count
count+=1
test=int(input())
for i in range(0,test):
input_int_array = [ int(x) for x in input().split()]
house=input_int_array[0]
num=input_int_array[1]
floornum=Floornum(house,num)
print(floornum)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
using namespace std;
//typedef
//-------------------------#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s)
{
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T>
inline string toString(T x)
{
ostringstream sout;
sout << x;
return sout.str();
}
inline int readInt()
{
int x;
scanf("%d", &x);
return x;
}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
//repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
//#define MOD 1000000007
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-8;
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const int INF = 2147483647;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit()
{
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++)
{
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
int N;
cin >> N;
vector<string> C(N);
vector<int> D(N);
set<string> st;
for (int i = 0; i < N; i++)
cin >> C[i] >> D[i], st.insert(C[i]);
map<string, int> mp;
int ct = 0;
for (auto e : st)
{
mp[e] = ct;
ct++;
}
vector<vector<int>> v(ct);
for (int i = 0; i < N; i++)
{
v[mp[C[i]]].push_back(D[i]);
}
for (int i = 0; i < ct; i++)
{
sort(all(v[i]));
//reverse(all(v[i]));
}
int M;
cin >> M;
int mx = -1;
for (int i = 0; i < M; i++)
{
string s;
cin >> s;
if (st.find(s) == st.end())
{
cout << "No" << endl;
return 0;
}
auto itr = lower_bound(all(v[mp[s]]), mx + 1);
if (itr == v[mp[s]].end())
{
cout << "No" << endl;
return 0;
}
mx = *itr;
}
cout << "Yes" << endl;
return 0;
}
| 0 | CPP |
for _ in range(int(input())):
n,a,b,c,d=map(int,input().split())
miw=(a-b)*n
maw=(a+b)*n
mit=(c-d)
mat=(c+d)
if((miw<mit and maw<mit) or (miw>mat and maw>mat)):
print('No')
else:
print('Yes') | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long dp1[360360 + 1];
long long dp2[360360 + 1];
long long a, b, k;
int main() {
scanf("%I64d %I64d %I64d", &a, &b, &k);
dp1[0] = 0;
for (int i = 1; i <= 360360; i++) {
dp1[i] = dp1[i - 1] + 1;
for (int j = 2; j <= k; j++) {
int mod = i % j;
dp1[i] = min(dp1[i], dp1[i - mod] + 1);
}
}
long long m = b % 360360;
dp2[0] = 0;
for (int i = 1; i <= 360360; i++) {
dp2[i] = dp2[i - 1] + 1;
for (int j = 2; j <= k; j++) {
int mod = (i + m) % j;
if (mod > i) continue;
dp2[i] = min(dp2[i], dp2[i - mod] + 1);
}
}
if (a / 360360 == b / 360360) {
printf("%I64d\n", dp2[a - b]);
} else {
long long hi = a - a % 360360;
long long lo = b - b % 360360 + 360360;
printf("%I64d\n",
dp1[a - hi] + dp2[lo - b] + (hi - lo) / 360360 * dp1[360360]);
}
}
| 9 | CPP |
n = input();
arr = list(map(int, input().split()))
mp = {}
ans = 0
sums = 0
count = 0
for i in range(int(n)-1,-1,-1):
sums += arr[i];
if arr[i] in mp:
mp[arr[i]] += 1
else:
mp[arr[i]] = 1
count = count + 1;
ans1 = 0;
ans2 = 0;
# print(i)
if (arr[i]+1) in mp:
ans1 = mp[arr[i]+1]
if (arr[i]-1) in mp:
ans2 = mp[arr[i]-1]
# print(ans1,ans2,count,arr[i])
ans += (sums + ans2 - ans1 - arr[i] * count);
print(ans)
| 10 | PYTHON3 |
import sys
input()
accum = 0
for line in sys.stdin:
if '++' in line:
accum += 1
else:
accum -= 1
print(accum) | 7 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
string a,b="CODEFESTIVAL2016";
cin>>a;
for(int i=0; i<16; i++)
{
if(a[i]!=b[i])n++;
}
cout<<n;
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int toInt(string s) {
int r = 0;
istringstream sin(s);
sin >> r;
return r;
}
long long toInt64(string s) {
long long r = 0;
istringstream sin(s);
sin >> r;
return r;
}
double toDouble(string s) {
double r = 0;
istringstream sin(s);
sin >> r;
return r;
}
string toString(long long n) {
string s, s1;
while (n / 10 > 0) {
s += (char)((n % 10) + 48);
n /= 10;
}
s += (char)((n % 10) + 48);
n /= 10;
s1 = s;
for (long long i = 0; i < s.length(); i++) s1[(s.length() - 1) - i] = s[i];
return s1;
}
bool isUpperCase(char c) { return c >= 'A' && c <= 'Z'; }
bool isLowerCase(char c) { return c >= 'a' && c <= 'z'; }
bool isLetter(char c) { return c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z'; }
bool isDigit(char c) { return c >= '0' && c <= '9'; }
char toLowerCase(char c) { return (isUpperCase(c)) ? (c + 32) : c; }
char toUpperCase(char c) { return (isLowerCase(c)) ? (c - 32) : c; }
char grid[101][101];
bool markRow[101], markCol[101];
int main() {
int n;
cin >> n;
for (long long i = 0; i < n; i++) {
for (long long j = 0; j < n; j++) {
cin >> grid[i][j];
if (grid[i][j] == '.') {
markRow[i] = true;
markCol[j] = true;
}
}
}
bool fRow = false, fCol = false;
for (long long i = 0; i < n; i++)
if (!markRow[i]) {
fRow = true;
break;
}
for (long long i = 0; i < n; i++)
if (!markCol[i]) {
fCol = true;
break;
}
if (fRow && fCol) {
cout << -1 << endl;
return 0;
}
if (fRow) {
for (long long i = 0; i < n; i++) {
for (long long j = 0; j < n; j++) {
if (grid[j][i] == '.') {
cout << j + 1 << ' ' << i + 1 << endl;
break;
}
}
}
} else {
for (long long i = 0; i < n; i++) {
for (long long j = 0; j < n; j++) {
if (grid[i][j] == '.') {
cout << i + 1 << ' ' << j + 1 << endl;
break;
}
}
}
}
}
| 7 | CPP |
#include <bits/stdc++.h>
const bool unsyncedio = std::ios::sync_with_stdio(false);
using namespace std;
int main() {
int n, z;
cin >> n >> z;
vector<int> x(n);
vector<int> id(n);
for (long long i = 0; i < (n); i++) {
cin >> x[i];
id[i] = i;
}
sort(x.begin(), x.end());
int lidx = n / 2;
int i = 0;
int ans = 0;
while (lidx < n && i < n / 2) {
while (lidx < n && x[lidx] - x[i] < z) lidx++;
if (lidx >= n) break;
lidx++;
i++;
ans++;
}
cout << ans << endl;
}
| 9 | CPP |
n=lambda: a.index(min(s))+s.index(max(s))
x=input
i=int
m=i(x())
s=list(map(i,x().split()))
a=s[m-1::-1]
print(n()-(n()>=m)) | 7 | PYTHON3 |
#!/usr/bin/env python3
def intersects(x1, y1, x2, y2):
if x1 <= x2 and y1 >= y2:
return True
if x2 <= x1 and x1 <= y2:
return True
if x2 <= y1 and y1 <= y2:
return True
return False
t = int(input())
for _ in range(t):
n, a, b, c, d = map(int, input().split())
if intersects(n * (a - b), n * (a + b), c - d, c + d):
print("Yes")
else:
print("No")
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int k, q, p;
double f[1010];
int g[1010];
int main() {
scanf("%d%d", &k, &q);
f[1] = 1;
int now = 1, day = 2;
while (now <= 1000) {
for (int j = k; j >= 1; j--)
f[j] = f[j - 1] * (k - j + 1) / k + f[j] * j / k;
while (now <= 1000 && f[k] > now * 1.0 / 2000) g[now++] = day;
day++;
}
while (q--) {
scanf("%d", &p);
printf("%d\n", k == 1 ? 1 : g[p]);
}
return 0;
}
| 10 | CPP |
n, a = int(input()), []
for _ in range(n):
a.append(list(map(int, input().split())))
print(sum(a[n // 2]) + sum(list(zip(*a))[n // 2]) +
sum([a[i][i] + a[i][n - i - 1] for i in range(n)]) -
a[n // 2][n // 2] * 3)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long r, g, i, j, h, a, f[200005], mod = 1000000007;
int main() {
cin >> r >> g;
f[0] = 1;
for (i = 1; i * (i + 1) / 2 <= r + g; i++)
for (j = r; j >= 0; j--)
if (j >= i) f[j] = (f[j] + f[j - i]) % mod;
h = i - 1;
for (i = 0; i <= r; i++)
if (h * (h + 1) / 2 - i <= g) a = (a + f[i]) % mod;
cout << a;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
const int maxm = 10000000;
bool inD[maxm];
int main() {
int a, b, m;
std::cin >> a >> b >> m;
bool p1CanWin = false;
int ans;
if (a > 0 and b < m) {
int x0 = 1000000000 % m;
int d = 0;
for (int i = 0; i < m; i++) inD[i] = false;
int min_d, min_i;
min_d = m;
for (int i = 1; i <= a; i++) {
d = (d + x0) % m;
if (inD[d]) break;
inD[d] = true;
if (d > 0 and d < m - b) {
p1CanWin = true;
ans = i;
break;
}
}
}
if (p1CanWin) {
printf("1 %09d\n", ans);
} else {
printf("2\n");
}
}
| 8 | CPP |
n, k = map(int, (input().split()))
s = input()
print(s[:k-1] + s[k-1].lower() + s[k:]) | 0 | PYTHON3 |
s1 = input()
s2 = input()
dp=[[0 for j in range(len(s1) + 1)]for k in range(len(s2) + 1)]
for i in range(len(s1) + 1):
dp[0][i] = i
for i in range(len(s2) + 1):
dp[i][0] = i
for i in range(1, len(s1) + 1):
for j in range(1, len(s2) + 1):
if s1[i-1] == s2[j-1]:
dp[j][i] = dp[j-1][i-1]
else:
dp[j][i] = min(dp[j-1][i], dp[j][i-1], dp[j-1][i-1]) + 1
print(dp[len(s2)][len(s1)])
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void scortier() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
string h[3];
map<string, long long int> id;
string fuck[12] = {"C", "C#", "D", "D#", "E", "F",
"F#", "G", "G#", "A", "B", "H"};
void solve() {
for (long long int i = 0; i < 12; i++) id[fuck[i]] = i;
while (cin >> h[0] >> h[1] >> h[2]) {
long long int t[3];
for (long long int i = 0; i < 3; i++) t[i] = id[h[i]];
sort(t, t + 3);
long long int ans = 0;
for (long long int i = 0; ans == 0 && i < 3; i++) {
long long int d1 = (t[(i + 1) % 3] - t[i] + 12) % 12;
long long int d2 = (t[(i + 2) % 3] - t[(i + 1) % 3] + 12) % 12;
if (d1 == 4 && d2 == 3)
ans = 1;
else if (d1 == 3 && d2 == 4)
ans = 2;
}
if (ans == 0)
cout << "strange"
<< "\n";
else if (ans == 1)
cout << "major"
<< "\n";
else
cout << "minor"
<< "\n";
}
}
int32_t main() {
scortier();
solve();
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
int pset[300005];
int findset(int i) {
if (pset[i] == i) return i;
return pset[i] = findset(pset[i]);
}
int main() {
int n, m;
int ans[300005];
scanf("%d %d", &n, &m);
for (int i = 1; i <= 300005; i++) pset[i] = i;
memset(ans, 0, sizeof ans);
for (int i = 1; i <= m; i++) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
int P = findset(l);
while (P <= r) {
if (P == x)
P++;
else {
ans[P] = x;
pset[P] = P + 1;
}
P = findset(P);
}
}
for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}
| 7 | CPP |
import math,sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda:int(input())
li = lambda:list(map(int,input().split()))
def case():
n=int(input())
a=li()
s=0
m=0
for i in a:
i=m+i
m=max(m,i)
print(i,end=" ")
for _ in range(1):
case() | 8 | PYTHON3 |
#include<stdio.h>
int main()
{
int n,i,b;
scanf("%d",&n);
int s[n];
for(i=0;i<n;i++)
{
scanf("%d",&b);
s[b-1]=i+1;
}
for(i=0;i<n;i++)
{
printf("%d ",s[i]);
}
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const char IO_MODE = 3;
inline long long ReadInt() {
long long x = 0, s = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') s = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return s * x;
}
inline void WriteInt(long long x) {
char c[20];
if (!x) {
putchar('0');
return;
}
if (x < 0) putchar('-'), x = -x;
int i = 0;
while (x > 0) c[++i] = x % 10, x /= 10;
while (i) putchar(c[i--] + 48);
}
template <typename T>
inline void out(T x) {
if (IO_MODE & 1)
WriteInt(x);
else if (typeid(x) == typeid(int))
printf("%i", x);
else
printf("%lld", (long long)x);
}
template <typename T, typename... Args>
inline void out(T x, Args... args) {
out(x);
putc(' ', stdout);
out(args...);
}
template <typename T>
inline void in(T &x) {
if (IO_MODE & 2)
x = ReadInt();
else if (typeid(x) == typeid(int))
scanf("%i", &x);
else if (typeid(x) == typeid(long long))
scanf("%lld", &x);
}
template <typename T, typename... Args>
inline void in(T &x, Args &...args) {
in(x);
in(args...);
}
int aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, mm, nn, oo, pp, qq, rr, ss, tt,
uu, vv, ww, xx, yy, zz;
int tc;
int n;
int Dp[100100];
vector<pair<int, int> > v[100100];
int main() {
int n = ReadInt();
for (int i = 1; i < n; i++) {
int sum = i;
for (int j = i + 1;; j++) {
if ((sum += j) > n) break;
v[sum].emplace_back(i, j);
}
}
for (int i = 1; i <= n; i++) {
set<int> mex;
for (auto ii : v[i]) mex.insert(Dp[ii.first - 1] ^ Dp[ii.second]);
int last = 0;
int done = 0;
for (auto x : mex)
if (x == last)
last++;
else
Dp[i] = Dp[i - 1] ^ last, done = 1;
if (!done) Dp[i] = Dp[i - 1] ^ last;
if (i == n) {
pair<int, int> ans;
if (last) {
for (auto ii : v[i])
if ((Dp[ii.first - 1] ^ Dp[ii.second]) == 0) ans = ii;
printf("%i\n", ans.second - ans.first + 1);
} else
printf("-1\n");
}
}
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, a, b, toth = 0, ca, cb;
cin >> a >> b;
toth += a;
ca = a;
cb = 0;
while (1) {
if (ca > 0) {
cb += ca;
ca = cb / b;
toth += ca;
cb = cb % b;
} else {
break;
}
}
cout << toth;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int sz = 3e5 + 100;
vector<pair<long long int, long long int> > ad[sz];
long long int dp[sz];
long long int ara[sz];
long long int ans = 0;
void DFS(long long int p, long long int par) {
dp[p] = ara[p];
for (auto xx : ad[p]) {
if (xx.first != par) {
DFS(xx.first, p);
dp[p] = max(dp[p], ara[p] + dp[xx.first] - xx.second);
}
}
}
void DFS1(long long int p, long long int par, long long int prev) {
prev += ara[p];
ans = max(ans, prev);
ans = max(ans, dp[p]);
long long int mx1 = 0, mx2 = 0;
long long int id1, id2;
id1 = -1, id2 = -1;
for (auto xx : ad[p]) {
if (xx.first != par) {
long long int tk = dp[xx.first] - xx.second;
ans = max(ans, prev + dp[xx.first] - xx.second);
if (tk > mx1) {
mx2 = mx1, id2 = id1;
mx1 = tk, id1 = xx.first;
} else if (tk > mx2)
mx2 = tk, id2 = xx.first;
}
}
ans = max(ans, mx1 + mx2 + ara[p]);
for (auto xx : ad[p]) {
if (xx.first != par) {
if (xx.first == id1) {
long long int tk = 0ll;
tk = max(tk, max(prev - xx.second, mx2 + ara[p] - xx.second));
DFS1(xx.first, p, tk);
} else {
long long int tk = 0ll;
tk = max(tk, max(prev - xx.second, mx1 + ara[p] - xx.second));
DFS1(xx.first, p, tk);
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int a, b, c, i, j, k, q, p, x, y, ct, ct1, m, l, r, x1, y1, h, sum1,
in, z, mid, n, mx;
char ch;
long long int d;
string str1, str2, str;
bool bl, bl1;
int t, cs = 1;
cin >> n;
for (int i = 1; i <= n; i++) cin >> ara[i];
for (int i = 1; i < n; i++) {
cin >> p >> q >> x;
ad[p].push_back({q, x});
ad[q].push_back({p, x});
}
DFS(1, -1);
DFS1(1, -1, 0);
cout << ans << '\n';
}
| 10 | CPP |
def sort(array):
less = []
equal = []
greater = []
if len(array) > 1:
pivot = array[0]
for x in array:
if x < pivot:
less.append(x)
if x == pivot:
equal.append(x)
if x > pivot:
greater.append(x)
# Don't forget to return something!
return sort(less)+equal+sort(greater) # Just use the + operator to join lists
# Note that you want equal ^^^^^ not pivot
else: # You need to hande the part at the end of the recursion - when you only have one element in your array, just return the array.
return array
equation = input().replace('+', ' ').split()
sortd = sort(equation)
res = ''
for i in range(0,len(sortd)):
if(i == len(sortd) - 1):
res = res + sortd[i]
else:
res = res + sortd[i] + '+'
print(res) | 7 | PYTHON3 |
from math import sqrt
n, m = map(int, input().split())
cnt = 0
for a in range (int(sqrt(n))+ 1):
b = n - a*a
cnt += (a + b*b == m)
print(cnt)
| 7 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int m,h;
cin>>m;
for(int i=1;i<n;i++){
cin>>h;
m=max(m,h);
if(m-1>h){
puts("No");
return 0;
}
}
puts("Yes");
return 0;
} | 0 | CPP |
n=int(input())
l=list(map(int,input().split()))
if len(l)==1 or l==sorted(l):
print("yes")
print(1,1)
elif l==sorted(l,reverse=True):
print("yes")
print(1,n)
else:
c1=0
c2=0
for i in range(1,n-1):
#print(i)
if l[i]>l[i-1] and l[i]>=l[i+1]:
pos1=i
c1=c1+1
#print(i,c1)
elif l[i] <= l[i - 1] and l[i] < l[i + 1]:
pos2 = i
c2 = c2 + 1
#print(i,c2)
if c1==1 and c2==1 and l[pos1-1]<=l[pos2] and l[pos2+1]>=l[pos1] and pos2>pos1:
print("yes")
print(pos1+1,pos2+1)
elif c1==1 and c2==0 and l[n-1]>=l[pos1-1]:
print("yes")
print(pos1+1,n)
elif c1 == 0 and c2 == 1 and l[0] <= l[pos2 +1]:
print("yes")
print(1,pos2+1)
else:
print("no")
| 8 | PYTHON3 |
l,r = map(int, (input().split(' ')))
if l != r:
print(2)
else:
print(l) | 7 | PYTHON3 |
n,c = map(int,input().split())
lst = list(map(int,input().split()))
lst.remove( max(lst) )
s = sum(lst)
if s <= c:
print("YES")
else:
print("NO") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
int const N = 1e6 + 10, M = 1e7 + 1, oo = 1e9;
const int mod = oo + 7;
const long long OO = 3e18;
string s, t;
int app[26], ke[2][N], mt[N][26];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> s >> t;
int n = s.size(), m = t.size();
int l = 0;
for (int i = 0; i < n; i++) {
if (l == m) {
ke[0][i] = ke[0][i - 1];
continue;
}
if (i) ke[0][i] = ke[0][i - 1];
if (s[i] == t[l]) {
ke[0][i]++;
app[s[i] - 'a'] = 1;
l++;
} else if (!app[s[i] - 'a']) {
cout << "No\n";
return 0;
}
}
if (l != m) {
cout << "No\n";
return 0;
}
memset(app, 0, sizeof app);
l = 0;
memset(mt, -1, sizeof mt);
for (int i = n - 1; i > -1; i--) {
if (l == m) {
ke[1][i] = ke[1][i + 1];
continue;
}
for (int j = 0; j < 26; j++) mt[i][j] = mt[i + 1][j];
ke[1][i] = ke[1][i + 1];
if (s[i] == t[m - l - 1]) {
app[s[i] - 'a'] = 1;
mt[i][s[i] - 'a'] = i;
ke[1][i]++;
l++;
} else if (!app[s[i] - 'a']) {
cout << "No\n";
return 0;
}
}
if (l != m) {
cout << "No\n";
return 0;
}
for (int i = 0; i < n; i++) {
if (!app[s[i] - 'a']) {
cout << "No\n";
return 0;
}
}
for (int i = 0; i < n; i++) {
if (mt[i][s[i] - 'a'] == -1 || i == mt[i][s[i] - 'a']) continue;
int l = 0, r = ke[1][mt[i][s[i] - 'a']];
if (mt[i][s[i] - 'a'] - 1 >= 0) l = ke[0][i];
if (l + r < m) {
cout << "No\n";
return 0;
}
}
cout << "Yes\n";
return 0;
}
| 10 | CPP |
for i in range(int(input())):
a,b,c,d=tuple(map(int,input().split()))
print(a,c,c,sep=" ") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7f7f7f7f;
const int N = 1e5 + 10;
const long long mod = 1e9 + 7;
const double PI = 3.14;
int read() {
char ch = getchar();
int x = 0, f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int random(int n) { return (long long)rand() * rand() % n; }
int a[N];
void solve() {
int n = read();
for (int i = 1; i <= n; i++) {
a[i] = read();
}
for (int i = 1; i <= n; i++) {
if (a[i] % 2 == 0) {
printf("1\n%d\n", i);
return;
}
for (int j = i + 1; j <= n; j++) {
if ((a[i] + a[j]) % 2 == 0) {
printf("2\n%d %d\n", i, j);
return;
}
}
}
cout << -1 << endl;
}
int main() {
int t = read();
while (t--) {
solve();
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<int> b;
int s;
void func(long long int n) {
while (n > 0) {
int j = n % 2;
if (j == 1) s++;
b.push_back(j);
n = n / 2;
}
}
int main() {
long long int n, k, i, j, l;
s = 0;
cin >> n >> k;
func(n);
if (s > k) {
cout << "NO" << endl;
} else if (s == k) {
long long int f = 1;
cout << "YES" << endl;
for (i = 0; i < b.size(); i++) {
for (j = 0; j < b[i]; j++) {
cout << f << " ";
}
f = f * 2;
}
} else {
for (i = b.size() - 1; i > 0 && s < k; i--) {
if (b[i] + s <= k) {
b[i - 1] = b[i - 1] + 2 * b[i];
s = s + b[i];
b[i] = 0;
} else {
l = k - s;
b[i - 1] = b[i - 1] + 2 * l;
s = s + l;
b[i] = b[i] - l;
}
}
if (s != k) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
long long int f = 1;
for (i = 0; i < b.size(); i++) {
for (j = 0; j < b[i]; j++) {
cout << f << " ";
}
f = f * 2;
}
}
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)2e9;
const long long inf = (long long)2e18;
const long double eps = (long double)1e-8;
const long long mod = (long long)1e9 + 7;
const long long MAXN = (long long)1e5 + 1;
const long long MAXC = (long long)1e6 + 1;
const long long MAXE = (long long)1000;
const long long MAXLOG = 21;
const long long maxlen = (long long)1e5;
const long long asci = (long long)256;
const long long block = 480;
const long double PI = acos(-1);
const long double e = 2.7182818284;
template <class T>
istream &operator>>(istream &in, vector<T> &arr) {
for (T &cnt : arr) {
in >> cnt;
}
return in;
};
void solve() {
long long n, l, r;
cin >> n >> l >> r;
l--, r--;
vector<long long> a;
long long i = 0;
for (; i < n - 1; ++i) {
if (l >= 2 * (n - i - 1))
l -= 2 * (n - i - 1), r -= 2 * (n - i - 1);
else
break;
}
while (a.size() <= r && i < n) {
for (long long j = i + 1; j < n; ++j) {
a.push_back(i);
a.push_back(j);
}
++i;
}
if (i == n) a.push_back(0);
for (; l <= r; ++l) {
cout << a[l] + 1 << " ";
}
cout << "\n";
}
int main() {
srand(time(0));
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout.precision(30);
long long t;
cin >> t;
while (t--) solve();
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, a[100000];
cin >> n;
map<long long int, long long int> s;
map<long long int, long long int> used;
map<long long int, long long int> start;
map<long long int, long long int> ans;
map<long long int, long long int> last;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
last[a[i]] = i;
start.insert(make_pair(a[i], i));
if (s[a[i]] > 0) {
used[a[i]] = min((i + 1) - s[a[i]], used[a[i]]);
s[a[i]] = i + 1;
} else {
s[a[i]] = i + 1;
used.insert(make_pair(a[i], 1000001));
}
}
for (auto it = used.begin(); it != used.end(); it++) {
if (it->second == 1000001) {
ans.insert(make_pair(it->first, 0));
} else {
bool ok = false;
long long int now = start[it->first];
while (now < n) {
if (a[now] != it->first) {
break;
}
if (now == last[it->first]) {
ok = true;
break;
}
now += it->second;
}
if (ok) {
ans.insert(make_pair(it->first, it->second));
}
}
}
cout << ans.size() << endl;
for (auto it = ans.begin(); it != ans.end(); it++) {
cout << it->first << " " << it->second << "\n";
}
}
| 8 | CPP |
def solve():
n = int(input())
n //= 2
print(8*n*(n+1)*(2*n+1)//6)
t = int(input())
for x in range(t):
solve() | 9 | PYTHON3 |
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int MOD = 100000007;
int dp[1001][1001];
int main(){
int r, c, a1, a2, b1, b2;
cin >> r >> c >> a1 >> a2 >> b1 >> b2;
dp[0][0] = 1;
for(int i = 0; i < r; ++i){ dp[i][0] = 1; }
for(int i = 0; i < c; ++i){ dp[0][i] = 1; }
for(int i = 1; i < r; ++i){
for(int j = 1; j < c; ++j){
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
}
}
int xpos, xneg, ypos, yneg;
if(a1 <= b1){
xpos = b1 - a1;
xneg = r - b1 + a1;
}else{
xpos = r - a1 + b1;
xneg = a1 - b1;
}
if(a2 <= b2){
ypos = b2 - a2;
yneg = c - b2 + a2;
}else{
ypos = c - a2 + b2;
yneg = a2 - b2;
}
int answer = dp[min(ypos, yneg)][min(xpos, xneg)];
if(xpos == xneg){ answer = (answer * 2) % MOD; }
if(ypos == yneg){ answer = (answer * 2) % MOD; }
cout << answer << endl;
return 0;
} | 0 | CPP |
n = int(input())
h = ['W','B']
for i in range(n):
e = []
for j in range(n):
e.append(h[(i+j)%2])
print(''.join(e))
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> roads[1001];
vector<int> c;
int counts[1001];
int main() {
int n, m, k;
cin >> n >> m >> k;
int maxCity;
int maxCount = 0;
int unUsed[n];
for (int i = 0; i < n; i++) {
unUsed[i] = 0;
}
for (int i = 0; i < k; i++) {
int a;
cin >> a;
c.push_back(a);
unUsed[a - 1] = 1;
maxCity = a;
}
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
roads[a].push_back(b);
roads[b].push_back(a);
}
for (int j = 0; j < c.size(); j++) {
bool visited[n + 1];
for (int i = 0; i < n + 1; i++) visited[i] = false;
queue<int> q;
visited[c[j]] = true;
q.push(c[j]);
while (q.size() > 0) {
int s = q.front();
q.pop();
unUsed[s - 1] = 1;
counts[c[j]]++;
if (counts[c[j]] > maxCount) {
maxCount = counts[c[j]];
maxCity = c[j];
}
for (int i = 0; i < roads[s].size(); i++) {
if (!visited[roads[s][i]]) {
visited[roads[s][i]] = true;
q.push(roads[s][i]);
}
}
}
}
int used = 0;
for (int i = 0; i < n; i++) {
if (unUsed[i] == 0) used++;
}
counts[maxCity] += used;
long long res = 0;
for (int i = 0; i < n + 1; i++) {
res += counts[i] * (counts[i] - 1) / 2;
}
res -= m;
cout << res;
}
| 7 | CPP |
import math
def prime2(x):
cnt = 0
while x % 2 == 0:
x //= 2
cnt += 1
return cnt
def prime5(x):
cnt = 0
while x % 5 == 0:
x //= 5
cnt += 1
return cnt
N = int(input())
A = [input() for _ in range(N)]
D = [[0] * 3 for _ in range(N)]
M2 = 0
M5 = 0
Md = 0
cnt = 0
for x in A:
t = x.find(".")
d = 9
if t != -1:
for i in range(t):
x = x.rstrip("0")
d -= (len(x) - t - 1)
x = x.replace(".", "")
p2 = prime2(int(x))
p5 = prime5(int(x))
n = min(p2, p5)
p2 -= n
p5 -= n
d += n
D[cnt] = [p2, p5, d]
cnt += 1
M2 = max(M2, p2)
M5 = max(M5, p5)
Md = max(Md, d)
Md += 1
M = min(M2, M5) + 1
L = [[[0] * M for _ in range(2)] for _ in range(Md)]
ans = 0
for i in range(N):
p2, p5, d = D[i]
if p2 == 0:
n = 1
t = p5
else:
n = 0
t = p2
for j in range(Md):
for k in range(M):
if d + j + min(t, k) >= 18:
ans += L[j][1 - n][k]
if d + j >= 18:
ans += L[j][n][k]
L[d][n][min(t, M - 1)] += 1
print(ans)
| 0 | PYTHON3 |
t = int(input())
while t > 0:
n = int(input())
# s = input()
# n, k, z = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m1, m2 = min(a), min(b)
ans = 0
for i in range(n):
a1 = a[i]-m1
a2 = b[i]-m2
ans += max(a1,a2)
print(ans)
t -= 1 | 8 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
string S;
int K;
int N;
int dp[110][5][2];
int main()
{
cin>>S>>K;
N = S.length();
dp[0][0][1] = 1;
for(int i = 0; i < N; i ++)
{
for(int j = 0; j <= K; j ++)
{
int Num = S[i] - '0';
if(Num == 0)
{
dp[i + 1][j][0] += dp[i][j][0];
dp[i + 1][j][1] += dp[i][j][1];
dp[i + 1][j + 1][0] += (dp[i][j][0] * 9);
}
else
{
dp[i + 1][j][0] += (dp[i][j][0] + dp[i][j][1]);
dp[i + 1][j + 1][0] += (dp[i][j][0] * 9);
dp[i + 1][j + 1][0] += (dp[i][j][1] * (Num - 1));
dp[i + 1][j + 1][1] += dp[i][j][1];
}
}
}
cout<<dp[N][K][0] + dp[N][K][1]<<endl;
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
bool find(vector<long long int> A, long long int B) {
int start = 0, end = A.size() - 1, mid = (start + end) / 2;
while (start <= end) {
mid = (start + end) / 2;
if (A[mid] > B) {
end = mid - 1;
} else if (A[mid] < B) {
start = mid + 1;
} else if (A[mid] == B) {
return 1;
}
}
return 0;
}
int ways(vector<long long int> A) {
int i = A.size() - 1;
long long int count = 0;
while (i > 0) {
long long int temp = A[i] / A[i - 1];
count++;
if (temp % 2 == 1 || find(A, temp)) {
A.pop_back();
i--;
} else
A[i] = temp;
}
return count;
}
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n;
cin >> n;
long long int val = 0;
vector<long long int> A;
map<long long int, vector<long long int>> B;
for (int j = 0; j < n; j++) {
int a;
cin >> a;
if (a % 2 == 0) {
A.push_back(a);
long long int temp = 0;
while (a % 2 == 0) {
a /= 2;
temp++;
}
if (B.find(a) == B.end())
B[a] = {temp};
else
B[a].push_back(temp);
}
}
for (auto it = B.begin(); it != B.end(); it++) {
vector<long long int> temp = it->second;
sort(temp.begin(), temp.end());
int j = 0;
while (j < temp.size() - 1) {
if (temp[j + 1] != temp[j]) val += (temp[j + 1] - temp[j]);
j++;
}
val += temp[0];
}
cout << val << endl;
}
return 0;
}
| 8 | CPP |
from sys import stdin
from collections import defaultdict
t = int(stdin.readline())
for _ in range(t):
n, x, m = list(map(int, stdin.readline().rstrip().split(" ")))
currentRange = [x, x]
for _ in range(m):
l, r = list(map(int, stdin.readline().rstrip().split(" ")))
if currentRange[1] < l or currentRange [0] > r:
continue
else:
currentRange[0] = min(currentRange[0], l)
currentRange[1] = max(currentRange[1], r)
print(currentRange[1] - currentRange[0] + 1) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, len, k, ans, q, ss, b[200], c[10];
char a[200];
while (~scanf("%d%d", &n, &k)) {
ans = 0;
for (int i = 0; i < n; i++) {
ss = 0;
q = 0;
memset(c, 0, sizeof(c));
scanf("%d", &b[i]);
while (b[i]) {
c[b[i] % 10] = 1;
b[i] /= 10;
}
for (q = 0; q <= k; q++) {
if (c[q]) {
ss++;
}
}
if (ss == k + 1) {
ans++;
}
}
printf("%d\n", ans);
}
return 0;
}
| 7 | CPP |
from math import sqrt
x1, y1, r1 = map(float, input().split())
x2, y2, r2 = map(float, input().split())
d = sqrt((x1 - x2)**2 + (y1 - y2)**2)
g = max(r1 - r2, r2 - r1)
if d < g:
print(0)
if d == g:
print(1)
if d > g:
if d < r1 + r2: print(2)
if d == r1 + r2: print(3)
if d > r1 + r2: print(4)
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int q; cin >> q;
while(q--){
int n,m; cin >> n >> m;
vector<pair<int,int>> v(m);
for(int i=0;i<m;i++){
cin >> v[i].second >> v[i].first;
}
sort(v.begin(), v.end());
if((2*n-m)%2){
printf("NO\n");
continue;
}
bool ok=true;
for(int i=0;i<m;){
if(i+1<m and v[i].first==v[i+1].first){
i+=2; continue;
}
if(i+1==m){
ok=false; break;
}
int dif=v[i+1].first-v[i].first;
if(dif%2==1 and v[i+1].second!=v[i].second){
ok=false; break;
}
if(dif%2==0 and v[i+1].second==v[i].second){
ok=false; break;
}
if(i+2<m and v[i+1].first==v[i+2].first){
ok=false; break;
}
i+=2;
}
if(ok){
printf("YES\n");
}
else{
printf("NO\n");
}
}
} | 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const double eps = 1e-10;
template <typename A, typename B>
inline void chmin(A &a, B b) {
if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
if (a < b) a = b;
}
class Union_find {
private:
vector<int> par;
vector<int> rank;
int n;
public:
Union_find(int a) {
n = a;
for (int i = 0; i < n; i++) {
par.push_back(i);
rank.push_back(0);
}
}
int find(int x) {
if (par[x] == x) {
return x;
} else {
return par[x] = find(par[x]);
}
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return;
if (rank[x] < rank[y]) {
par[x] = y;
} else {
par[y] = x;
if (rank[x] == rank[y]) rank[x]++;
}
}
bool same(int x, int y) { return find(x) == find(y); }
};
class LazySegTree {
private:
int n;
vector<ll> node, lazy;
vector<bool> lazyFlag;
public:
LazySegTree(vector<ll> v) {
int sz = v.size();
n = 1;
while (n < sz) n *= 2;
node.resize(2 * n - 1, 0);
lazy.resize(2 * n - 1, 0);
lazyFlag.resize(2 * n - 1, false);
for (int i = 0; i < (sz); i++) node[i + n - 1] = v[i];
for (int i = n - 2; i >= 0; i--)
node[i] = node[2 * i + 1] + node[2 * i + 2];
}
void eval(int k, int l, int r) {
if (lazyFlag[k]) {
node[k] += lazy[k] * (r - l);
if (r - l > 1) {
lazy[2 * k + 1] += lazy[k];
lazy[2 * k + 2] += lazy[k];
lazyFlag[2 * k + 1] = lazyFlag[2 * k + 2] = true;
}
lazy[k] = 0;
lazyFlag[k] = false;
}
}
void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
if (r < 0) r = n;
eval(k, l, r);
if (b <= l || r <= a) return;
if (a <= l && r <= b) {
lazy[k] += x;
lazyFlag[k] = true;
eval(k, l, r);
} else {
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
node[k] = node[k * 2 + 1] + node[k * 2 + 2];
}
}
ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0) r = n;
eval(k, l, r);
if (b <= l || r <= a) return 0;
if (a <= l && r <= b) return node[k];
return query(a, b, k * 2 + 1, l, (l + r) / 2) +
query(a, b, k * 2 + 2, (l + r) / 2, r);
}
};
class Bucket {
private:
int n, bs, bn;
vector<ll> data;
vector<ll> bucket, lazy;
vector<bool> lazyFlag;
public:
Bucket(vector<ll> v, int sz) {
data = v;
n = v.size();
bs = sz;
bn = (n + bs - 1) / bs;
data.resize(bn * bs, (ll)1e18);
bucket.assign(bn, (ll)1e18);
lazy.assign(bn, 0);
lazyFlag.assign(bn, 0);
for (int i = 0; i < (bn); i++) {
ll minx = (ll)1e18;
for (int j = 0; j < (bs); j++) {
chmin(minx, data[i * bs + j]);
}
bucket[i] = minx;
}
}
void eval(int k) {
if (lazyFlag[k]) {
lazyFlag[k] = false;
for (int i = (bs * k); i < (bs * (k + 1)); i++) {
data[i] = lazy[k];
}
lazy[k] = 0;
}
}
void update(int s, int t, int x) {
for (int k = 0; k < (bn); k++) {
int l = k * bs, r = (k + 1) * bs;
if (r <= s || t <= l) continue;
if (s <= l && r <= t) {
lazyFlag[k] = true;
bucket[k] = x;
lazy[k] = x;
} else {
eval(k);
for (int i = (max(s, l)); i < (min(t, r)); i++) {
data[i] = x;
}
bucket[k] = (ll)1e18;
for (int i = (l); i < (r); i++) {
chmin(bucket[k], data[i]);
}
}
}
}
ll query(int s, int t) {
ll res = (ll)1e18;
for (int k = 0; k < (bn); k++) {
int l = k * bs, r = (k + 1) * bs;
if (r <= s || t <= l) continue;
if (s <= l && r <= t) {
chmin(res, bucket[k]);
} else {
eval(k);
for (int i = (max(s, l)); i < (min(t, r)); i++) {
chmin(res, data[i]);
}
}
}
return res;
}
};
bool itsLucky(ll n) {
while (n) {
if (n % 10 != 4 && n % 10 != 7) {
return false;
}
}
return true;
}
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < (n); i++) {
cout << (char)('a' + i % 4);
}
cout << endl;
}
| 8 | CPP |
x,*l=open(0)
print(int(x.split()[0])-len({*''.join(l[1::2]).split()})) | 0 | PYTHON3 |
n, k = (int(x) for x in input().split())
array = list(map(int, input().split()))
array.sort()
if k == 0:
if array[0] >= 2:
print(array[0]-1)
else:
print(-1)
exit()
if k == n:
print(array[k-1])
exit()
if array[k-1] != array[k]:
print(array[k-1])
else:
print(-1)
| 9 | PYTHON3 |
m,n=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
s=[l[i+m-1]-l[i]for i in range((n-m)+1)]
print(min(s))
| 7 | PYTHON3 |
#78B
x,y,z=map(int,input().split())
print((x-z)//(z+y)) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m;
int group = 0;
int *arr = NULL;
cin >> m;
arr = new int[m];
for (int i = 0; i < m; i++) {
cin >> arr[i];
}
for (int i = 0; i < m; i++) {
if (arr[i] == arr[i + 1])
continue;
else
group++;
}
cout << group;
delete[] arr;
return 0;
}
| 7 | CPP |
t = int(input())
for case in range(t):
ans = - 1
n, x = [int(s) for s in input().split(' ')]
a = [int(s) for s in input().split(' ')]
if sum(a) % x != 0:
ans = n
else:
for i in range(n // 2 + 1):
if a[i] % x != 0:
ans = n - i - 1
break
elif a[-(i + 1)] % x != 0:
ans = n - i - 1
break
print(ans) | 7 | PYTHON3 |
def sol(n,m,k,arr):
for i in range(n-1):
if m<0:
print("NO")
return
m+=arr[i]-max(0,(arr[i+1]-k))
if m<0:
print("NO")
else:
print('YES')
t = int(input())
for _ in range(t):
n, m, k = map(int, input().split())
arr = list(map(int, input().split()))
sol(n,m,k,arr)
| 8 | PYTHON3 |
# https://codeforces.com/problemset/problem/50/A
import math
x, y = map(int, input().split(" "))
print(math.floor((x*y)/2))
| 7 | PYTHON3 |
n = input()
array = input().split()
maximum = 0
limit = len(array)
i = 0
while i < limit:
j = i
counting = 0
while j < limit:
counting ^= int(array[j])
if maximum < counting:
maximum = counting
j += 1
i += 1
print(maximum)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> vec;
vector<pair<int, int> > vp;
pair<int, int> ar[600005];
int no[5000];
int main() {
int n, m, q, w;
cin >> n >> m;
for (int i = 1; i < n + 1; i++) {
cin >> q >> w;
no[q] = 1, no[w] = 1;
}
cout << n - 1 << endl;
for (int i = 1; i < n + 1; i++) {
if (no[i] == 0) {
for (int j = 1; j < n + 1; j++) {
if (i == j) continue;
cout << i << ' ' << j << endl;
}
return 0;
}
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct v {
int vx, vy;
};
struct Rule {
bool operator()(const v& a, const v& b) {
if (a.vx != b.vx) return a.vx < b.vx;
return a.vy < b.vy;
}
};
map<long long, int> mapp;
int top = 0;
vector<v> vxy[200005];
int main() {
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) {
int x, vx, vy;
scanf("%d%d%d", &x, &vx, &vy);
long long speed = vy - (long long)a * vx;
if (!mapp.count(speed)) mapp[speed] = ++top;
v tmp;
tmp.vx = vx;
tmp.vy = vy;
vxy[mapp[speed]].emplace_back(tmp);
}
long long ans = 0;
for (int i = 1; i <= top; i++) {
long long cnt = vxy[i].size(), curr = cnt * (cnt - 1);
int anss = 0;
sort(vxy[i].begin(), vxy[i].end(), Rule());
for (int j = 0; j < vxy[i].size(); j++) {
if (j == 0 || ((vxy[i][j].vx == vxy[i][j - 1].vx) &&
(vxy[i][j].vy == vxy[i][j - 1].vy)))
anss++;
else {
curr -= (long long)anss * (anss - 1);
anss = 1;
}
}
curr -= (long long)anss * (anss - 1);
ans += curr;
}
printf("%lld\n", ans);
return 0;
}
| 10 | CPP |
s=input()
r=0
if len(s)< 7:
print("NO")
else:
for i in range(len(s)-1):
if s[i] == s[i+1]:
r+=1
else:
r=0
if r >= 6:
print("YES")
break
if r <6:
print("NO") | 7 | PYTHON3 |
ovels = ['a','e','i','o','u','y']
a = input().lower()
new_a = list(filter(lambda x : x not in ovels,a))
for i in new_a:
print('.' + i,end='')
print()
| 7 | PYTHON3 |
entrada=input().split(" ")
entrada=int(entrada[0])*int(entrada[1])
print(entrada//2)
| 7 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,k;
cin >> n >> k;
cout << min(n%k,abs((n%k)-k)) << endl;
} | 0 | CPP |
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 5 15:23:27 2020
@author: jion
"""
n,k = [int(x) for x in input().split()]
for _ in range(k):
if n % 10 == 0:
n = n // 10
else:
n -= 1
print(n) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline void chmin(A& a, B b) {
if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A& a, B b) {
if (a < b) a = b;
}
template <class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>& p) {
ost << "{" << p.first << "," << p.second << "}";
return ost;
}
template <class T>
ostream& operator<<(ostream& ost, const vector<T>& v) {
ost << "{";
for (long long i = 0; i < v.size(); i++) {
if (i) ost << ",";
ost << v[i];
}
ost << "}";
return ost;
}
vector<pair<long long, long long> > ans;
void solve(vector<long long> D, long long off) {
if (D.size() == 0) {
return;
}
if (D.size() == 1) {
for (long long i = 0; i <= D[0]; i++) {
for (long long j = i + 1; j <= D[0]; j++) {
ans.emplace_back(i + off, j + off);
}
}
return;
}
vector<long long> DD;
for (long long i = 1; i + 1 < D.size(); i++) DD.push_back(D[i] - D[0]);
solve(DD, off + D[0]);
long long num;
if (DD.size())
num = DD.back() + 1;
else
num = 1;
for (long long i = 0; i < (D[0]); i++) {
for (long long j = i + 1; j <= D.back(); j++) {
ans.emplace_back(i + off, j + off);
}
}
}
signed main() {
long long N;
scanf("%lld", &N);
vector<long long> D(N);
for (long long i = 0; i < (N); i++) scanf("%lld", &D[i]);
solve(D, 0);
printf("%lld\n", (long long)ans.size());
for (auto& p : ans) printf("%lld %lld\n", p.first + 1, p.second + 1);
return 0;
}
| 10 | CPP |
def main():
s = input()
vogais = "aeiou"
pares = "02468"
cont = 0
for c in s:
if c.isalpha() and c not in vogais:
continue
if c.isnumeric() and c in pares:
continue
cont += 1
print(cont)
if __name__ == "__main__":
main()
| 7 | PYTHON3 |
n = int(input())
A = [int(i) for i in input().split()]
B = [1] + [0] * (n - 1)
for i in range(1, n):
if A[i] >= A[i-1]:
B[i] = B[i-1] + 1
else:
B[i] = 1
print(max(B))
| 7 | PYTHON3 |
def INT():
return int(input())
def lis():
return [int(x) for x in input().split()]
def S():
return str(input())
left = S()
right = S()
if left[::] == right[::-1]:
print("YES")
else:
print("NO")
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, k;
cin >> n >> k;
long long int x = 0, ans = 0;
long long int a[n];
for (long long int i = 0; i < n; i++) {
cin >> a[i];
long long int res = a[i];
x = 0;
while (res > 0) {
if (res % 10 == 4 || res % 10 == 7) {
x++;
}
res = res / 10;
}
if (x <= k) {
ans++;
}
}
cout << ans;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxm = 2e6 + 9;
const int maxn = 2e6 + 9;
const int N = 150 + 9;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int base = 131;
const double eps = 1e-4;
int n, K, s;
int dp[2][N][N * N], a[N];
int now, pre;
int ans = 0;
int read() {
int a = 1, b = 0;
char c = getchar();
while (c > '9' || c < '0') {
if (c == '-') a = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
b = (b << 1) + (b << 3) + (c ^ '0');
c = getchar();
}
return a * b;
}
void print(int x) {
if (x < 0) putchar('-'), x = -x;
if (x > 9) print(x / 10);
putchar(x % 10 + '0');
}
int main() {
int tmp;
n = read(), K = read(), s = read();
for (int i = (1); i <= (n); ++i) a[i] = read();
for (int i = (1); i <= (K); ++i) ans += a[i];
now = 0;
pre = 1;
for (int i = (0); i <= (min(n * n, s)); ++i) dp[now][1][i] = a[1];
swap(now, pre);
for (int i = (2); i <= (n); ++i) {
for (int j = (1); j <= (min(i, K)); ++j) {
for (int k = (0); k <= (min(s, n * n)); ++k) {
dp[now][j][k] = inf;
if (i > j) dp[now][j][k] = dp[pre][j][k];
if (k - (i - j) >= 0)
dp[now][j][k] =
min(dp[now][j][k], dp[pre][j - 1][k - (i - j)] + a[i]);
if (j == K && (k == s || k == n * n)) ans = min(ans, dp[now][j][k]);
}
}
swap(now, pre);
}
print(ans);
return 0;
}
| 10 | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.