solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
n = I()
a = LI()
r = 0
c = 1
t = a[0]
for k in a[1:]:
if t < k:
c += 1
else:
if r < c:
r = c
c = 1
t = k
if r < c:
r = c
return r
print(main())
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> a(n, 0);
int cs = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
cs += a[i];
}
int d = 0, minn = 1000000;
for (int i = 0; i < n; i++) {
d = a[i];
minn = min(minn, abs(cs - 2 * d));
for (int j = (i + 1) % n; j != i; j = (j + 1) % n) {
d += a[j];
minn = min(minn, abs(cs - 2 * d));
}
}
cout << minn << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double eps = (1e-5);
int isGreater(long double x, long double y) {
if (abs(x - y) < eps) return 0;
if (x > y) return 1;
return -1;
}
const int MAX_N = 5e5 + 5;
vector<pair<int, int> > adj[MAX_N];
vector<vector<long long> > mem[MAX_N];
int n, k;
void clear() {
for (int i = 0; i < n; ++i) {
adj[i].clear();
mem[i].clear();
}
}
long long f(int u, int i, int minus, int p) {
if (i == (int)((adj[u]).size())) return 0;
long long &ret = mem[u][i][minus];
if (~ret) return ret;
ret = 0;
vector<long long> s;
for (auto e : adj[u]) {
int v = e.first;
if (v == p) continue;
ret += f(v, 0, 0, u);
s.push_back(f(v, 0, 1, u) + e.second - f(v, 0, 0, u));
}
sort(s.rbegin(), s.rend());
for (int j = 0; j < min(k - minus, (int)((s).size())); ++j) {
ret += max(0LL, s[j]);
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tc;
cin >> tc;
while (tc--) {
cin >> n >> k;
clear();
for (int i = 0; i < n - 1; ++i) {
int u, v, w;
cin >> u >> v >> w;
--u;
--v;
adj[u].push_back({v, w});
adj[v].push_back({u, w});
mem[u].push_back(vector<long long>(2, -1));
mem[v].push_back(vector<long long>(2, -1));
}
cout << f(0, 0, 0, -1) << '\n';
}
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> row, col;
vector<int> block_masks[11];
int sol[21];
struct State {
int r, l;
vector<int> c;
};
bool operator<(const State &a, const State &b) {
if (a.r != b.r) return a.r < b.r;
if (a.l != b.l) return a.l < b.l;
return a.c < b.c;
}
set<State> vis;
void modify(int mask, int d) {
for (int i = 0; i < m; ++i) {
if (mask & (1 << i)) {
col[i] += d;
}
}
}
bool check_cols(int r) {
for (int i = 0; i < m; ++i) {
if (col[i] < 0 || (n - r) / 2 < col[i]) {
return false;
}
}
return true;
}
bool solve(int r, int last) {
if (r >= n) {
return accumulate(col.begin(), col.end(), 0) == 0;
}
State s = {r, last, col};
if (vis.count(s)) {
return false;
}
vis.insert(s);
for (int mask : block_masks[row[r]]) {
int new_blocks = (mask ^ last) & mask;
modify(new_blocks, -1);
if (check_cols(r) && solve(r + 1, mask)) {
sol[r] = mask;
return true;
}
modify(new_blocks, +1);
}
return false;
}
int main() {
scanf("%d%d", &n, &m);
row.resize(n);
col.resize(m);
for (int i = 0; i < n; ++i) scanf("%d", &row[i]);
for (int i = 0; i < m; ++i) scanf("%d", &col[i]);
swap(n, m);
row.swap(col);
for (int i = 0; i < (1 << m); ++i) {
int in = 0, blocks = 0;
for (int j = 0; j < m; ++j) {
if (((i >> j) & 1)) {
blocks += !in;
in = 1;
} else {
in = 0;
}
}
block_masks[blocks].push_back(i);
}
if (solve(0, 0)) {
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
putchar((sol[j] & (1 << i)) ? '*' : '.');
}
putchar('\n');
}
} else {
assert(false);
}
return 0;
}
| 12 | CPP |
"""
question is if one even no. is present among odd numbers then pick that even no. and
if one odd no. is present among even no. then pick that odd no.
"""
n = int(input())
nos = list(map(int,input().split()))
counte = 0
counto = 0
for i in range(n):
if nos[i]%2 == 0:
a = i
counte += 1
else:
b = i
counto += 1
if counte == 1:
print(a+1)
else:
print(b+1) | 7 | PYTHON3 |
#!/usr/bin/env python3.9
def inverse_1_2x2(i, j):
''' inverse one '1' in square 2x2, cost 3 '''
res = []
fstr = '{} {} {} {} {} {}'
step_i, step_j = 1, 1
if i % 2 == 0:
step_i = -1
if j % 2 == 0:
step_j = -1
res.append(fstr.format(i+step_i, j+step_j, i+step_i, j, i, j))
res.append(fstr.format(i+step_i, j, i, j, i, j+step_j))
res.append(fstr.format(i, j, i, j+step_j, i+step_i, j+step_j))
return res
def inverse_2_2x2(i, j, x1, x2):
''' inverse two '1' in square 2x2, cost 4
1) xx oo
oo -> xo -> inverse_1
2) xo ox
ox -> oo -> inverse_1
'''
# x1, x2 = *ones # x2 bigger than x1
# x3_delta = (0, 0)
delta = x2[0] - x1[0], x2[1] - x1[1]
# if sum(delta) == 1:
if delta[0] == 0 or delta[1] == 0:
# variant 1: choose another neigh of x1
if x1[0] == i and x1[1] == j:
x3 = x1[0] + delta[1], x1[1] + delta[0]
else:
x3 = x1[0] - delta[1], x1[1] - delta[0]
else:
# variant 2: take down(i+1) neigh of x1
x3 = x1[0] + 1, x1[1]
res = []
fstr = '{} {} {} {} {} {}'
res.append(fstr.format(*x1, *x2, *x3))
res += inverse_1_2x2(*x3)
return res
def inverce_cell(i, j, a):
i -= 1
j -= 1
if a[i][j] == '1':
a[i][j] = '0'
else:
a[i][j] = '1'
def process_last_row(a):
res = []
fstr = '{} {} {} {} {} {}'
i = len(a) # last row
j = 1
while j < len(a[-1])-1:
if a[i-1][j-1] == '1':
res.append(fstr.format(i, j, i-1, j, i-1, j+1))
# inverce_cell(i, j, a)
inverce_cell(i-1, j, a)
inverce_cell(i-1, j+1, a)
j += 1
# i, j points to (-1, -2) cell
if a[i-1][j-1] == '1':
# num_ops += 1
if a[i-1][j] == '1':
# 11 -> L shape
res.append(fstr.format(i, j, i, j+1, i-1, j))
# inverce_cell(i, j, a)
# inverce_cell(i, j+1, a)
inverce_cell(i-1, j, a)
else:
# 10 -> Г shape
res.append(fstr.format(i, j, i-1, j, i-1, j+1))
# inverce_cell(i, j, a)
inverce_cell(i-1, j, a)
inverce_cell(i-1, j+1, a)
else:
if a[i-1][j] == '1':
# 01 -> ꓶ
res.append(fstr.format(i, j+1, i-1, j+1, i-1, j))
# inverce_cell(i, j+1, a)
inverce_cell(i-1, j+1, a)
inverce_cell(i-1, j, a)
return res
def process_last_col(a):
res = []
fstr = '{} {} {} {} {} {}'
j = len(a[0]) # last column
for i in range(1, len(a), 2):
if a[i-1][j-1] == '1' and a[i][j-1] == '1':
res.append(fstr.format(i, j, i, j-1, i+1, j-1))
res.append(fstr.format(i, j-1, i+1, j-1, i+1, j))
# inverce_cell(i, j, a)
# inverce_cell(i+1, j, a)
elif a[i-1][j-1] == '1':
res.append(fstr.format(i, j, i, j-1, i+1, j-1))
# inverce_cell(i, j, a)
inverce_cell(i, j-1, a)
inverce_cell(i+1, j-1, a)
elif a[i][j-1] == '1':
res.append(fstr.format(i, j-1, i+1, j-1, i+1, j))
inverce_cell(i, j-1, a)
inverce_cell(i+1, j-1, a)
# inverce_cell(i+1, j, a)
return res
for _ in range(int(input())):
n, m = list(map(int, input().split(' ')))
a = [list(input()) for _ in range(n)]
# num_ops = 0
out = []
if n % 2 == 1:
out += process_last_row(a)
# [print(*row) for row in a]
# print()
if m % 2 == 1:
# proceed only even num_cells
out += process_last_col(a)
# num_ops += len(col_ops)
# out += col_ops
# [print(*row) for row in a]
for blk_i in range(n//2):
i = 2*blk_i + 1
for blk_j in range(m//2):
j = 2*blk_j + 1
ones = [
(i+ii, j+jj)
for ii in range(2)
for jj in range(2)
if a[i+ii-1][j+jj-1] == '1'
]
if len(ones) == 1:
x1 = ones.pop()
out += inverse_1_2x2(*x1)
# num_ops += 3
elif len(ones) == 2:
out += inverse_2_2x2(i, j, *ones)
# num_ops += 4
elif len(ones) == 3:
x1, x2, x3 = ones
# print(x1, x2, x3)
out.append('{} {} {} {} {} {}'.format(*x1, *x2, *x3))
# num_ops += 1
elif len(ones) == 4:
x1, x2, x3, x4 = ones
out.append( '{} {} {} {} {} {}'.format(*x1, *x2, *x3))
out += inverse_1_2x2(*x4)
# num_ops += 4
# print(out)
print(len(out))
print('\n'.join(out))
| 7 | PYTHON3 |
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
N, Q = map(int, input().split())
uni = UnionFind(N)
for _ in range(Q):
t, u, v = map(int, input().split())
if t == 0:
uni.union(u,v)
else:
if uni.same(u,v):
print(1)
else:
print(0)
if __name__ == "__main__":
main() | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;
int Res[N], Frq[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int Arr[n + n + 2];
for (int i = 1; i <= n + n; i++) {
cin >> Arr[i];
Frq[Arr[i]]++;
}
int A = 0, B = 0;
for (int i = 10; i <= 99; i++) {
if (Frq[i] == 1)
A++;
else if (Frq[i] > 1)
B++;
}
if (A & 1)
cout << (B + A / 2) * (B + A / 2 + 1) << "\n";
else
cout << (B + A / 2) * (B + A / 2) << "\n";
int typ = 1;
for (int i = 1; i <= n + n; i++) {
if (Frq[Arr[i]] == 1) Res[i] = typ, typ = 3 - typ;
}
for (int i = 10; i <= 99; i++) {
if (Frq[i] > 1) {
for (int j = 1; j <= n + n; j++) {
if (Arr[j] == i) Res[j] = typ, typ = 3 - typ;
}
}
}
for (int i = 1; i <= n + n; i++) cout << Res[i] << " ";
cout << "\n";
return 0;
}
| 8 | CPP |
#include <stdio.h>
#include <set>
using namespace std;
set<unsigned int> hashList;
int make_face(char input)
{
int ret;
switch (input){
case 'R': ret = 0; break;
case 'G': ret = 1; break;
case 'B': ret = 2; break;
case 'C': ret = 3; break;
case 'M': ret = 4; break;
case 'Y': ret = 5; break;
}
return (ret);
}
unsigned int make_hash(int cube[])
{
int ret;
ret = 0;
for (int i = 0; i < 6; i++){
ret = ret * 6 + cube[i];
}
return (ret);
}
int rote_x(int cube[])
{
int temp;
temp = cube[1];
cube[1] = cube[3];
cube[3] = cube[4];
cube[4] = cube[2];
cube[2] = temp;
return (0);
}
int rote_y(int cube[])
{
int temp;
temp = cube[0];
cube[0] = cube[3];
cube[3] = cube[5];
cube[5] = cube[2];
cube[2] = temp;
return (0);
}
int rote_z(int cube[])
{
int temp;
temp = cube[0];
cube[0] = cube[4];
cube[4] = cube[5];
cube[5] = cube[1];
cube[1] = temp;
return (0);
}
int main(void)
{
int cube[6];
int ans;
int n;
while (1){
hashList.clear();
scanf("%d", &n);
if (n == 0){
break;
}
ans = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < 6; j++){
char str[20];
scanf("%s", str);
cube[j] = make_face(str[0]);
}
if (hashList.find(make_hash(cube)) != hashList.end()){
ans++;
continue;
}
for (int i = 0; i < 4; i++){
for (int j = 0; j < 4; j++){
for (int k = 0; k < 4; k++){
hashList.insert(make_hash(cube));
rote_x(cube);
}
rote_y(cube);
}
rote_z(cube);
}
}
printf("%d\n", ans);
}
return (0);
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, lis[111], dp[1 << 22], team[22], m;
char action[22];
int INF = 1e9 + 7;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> lis[i];
}
sort(lis, lis + n);
for (int i = 0; i < n / 2; i++) {
swap(lis[i], lis[n - 1 - i]);
}
cin >> m;
for (int i = m; i > 0; i--) {
cin >> action[i] >> team[i];
}
for (int mask = 1; mask < (1 << m); mask++) {
int cnt = __builtin_popcount(mask);
if (team[cnt] == 1) {
dp[mask] = -INF;
for (int i = 0; i < m; i++) {
if ((1 << i) & mask) {
if (action[cnt] == 'p') {
dp[mask] = max(dp[mask], lis[i] + dp[mask ^ (1 << i)]);
} else {
dp[mask] = max(dp[mask], dp[mask ^ (1 << i)]);
}
}
}
} else {
dp[mask] = INF;
for (int i = 0; i < m; i++) {
if ((1 << i) & mask) {
if (action[cnt] == 'p') {
dp[mask] = min(dp[mask], -lis[i] + dp[mask ^ (1 << i)]);
} else {
dp[mask] = min(dp[mask], dp[mask ^ (1 << i)]);
}
}
}
}
}
cout << dp[(1 << m) - 1];
}
| 11 | CPP |
for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
if n == 1:
print("YES")
continue
b = sorted(a)
c = sorted(a[1::2])
d = sorted(a[0::2])
e = [(c[(i-1)//2]-d[(i-1)//2])*(i%2)+d[i//2] for i in range(n)]
if b == e:
print("YES")
else:
print("NO")
| 9 | PYTHON3 |
t=input().split()
print(t[1]+t[0]) | 0 | PYTHON3 |
n=int(input());s=''
while n:s=str(n%2)+s;n=-(n//2)
print(s or 0) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, i, n, l, count = 0, count1 = 0, j;
string s, fin = "";
cin >> s;
cin >> k;
char ans[k];
l = s.size();
int f = 0;
for (i = 0; i < l; i++) {
if (s[i] == '?') count++;
if (s[i] == '*') {
count1++;
}
}
int rl = l - count - count1;
if (k < rl - count - count1)
cout << "Impossible";
else if (k > rl && count1 == 0)
cout << "Impossible";
else if (k <= rl) {
int t = rl - k;
int m = 0;
for (j = 0; j < l; j++) {
if ((s[j] == '*' || s[j] == '?') && t > 0) {
m--;
t--;
} else if (s[j] != '*' && s[j] != '?')
ans[m++] = s[j];
}
for (j = 0; j < k; j++) cout << ans[j];
} else {
f = 0;
for (i = 0; i < l; i++) {
if (s[i] == '?')
continue;
else if (s[i] == '*' && f != 1 && i > 0) {
for (j = 0; j < k - rl; j++) fin = fin + s[i - 1];
f = 1;
} else if (s[i] != '*')
fin = fin + s[i];
}
cout << fin;
}
}
| 9 | CPP |
palabra = input()
i = 0
while True:
if palabra[i].__contains__("a") or palabra[i].__contains__("A") or palabra[i].__contains__("e") or palabra[i].__contains__("E") or palabra[i].__contains__("i") or palabra[i].__contains__("I") or palabra[i].__contains__("o") or palabra[i].__contains__("O") or palabra[i].__contains__("u") or palabra[i].__contains__("U") or palabra[i].__contains__("y") or palabra[i].__contains__("Y"):
palabra = palabra.replace(palabra[i],"")
if i >= len(palabra) - 1:
break
else:
if i >= len(palabra) - 1:
break
else:
i = i + 1
palabra_definitiva = ""
for l in palabra:
palabra_definitiva = palabra_definitiva + "." + l.lower()
print (palabra_definitiva) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void _fill_int(int* p, int val, int rep) {
int i;
for (i = 0; i < rep; i++) p[i] = val;
}
int GETi() {
int i;
scanf("%d", &i);
return i;
}
template <class T>
T sqr(T val) {
return val * val;
}
signed long long N;
int okok(signed long long M) {
signed long long res = 0;
while (M % 2 == 0) {
res += M / 2;
M /= 2;
}
res += M * (M - 1) / 2;
return res == N;
}
void solve() {
int f, r, i, j, k, l, x, y;
vector<signed long long> res;
cin >> N;
for (i = 0; i < 61; i++) {
signed long long B = (1LL << (1 + i)) - 3;
signed long long C = 2 * N;
if (B > C) break;
double D = sqrt(B * (double)B + 8 * (double)N + 1e-9);
if (D - (signed long long)D <= 1e-9) {
signed long long B2 = (signed long long)D - B;
if (B2 % 2 == 0 && B2 % 4 != 0 && okok((B2 / 2) << i))
res.push_back((B2 / 2) << i);
}
}
sort(res.begin(), res.end());
res.erase(unique(res.begin(), res.end()), res.end());
if (res.empty())
printf("-1\n");
else
for (i = 0; i < res.size(); i++) cout << res[i] << endl;
return;
}
int main(int argc, char** argv) {
if (argc > 1) freopen(argv[1], "r", stdin);
solve();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, p, out[1010];
struct node {
int v, c;
};
vector<node> e[1010];
int t1[1010], t2[1010], r[1010], k;
void dfs(int i, int fa, int mi) {
if (e[i].size() == 0) {
t1[k] = fa;
t2[k] = i;
r[k] = mi;
k++;
return;
}
mi = min(e[i][0].c, mi);
dfs(e[i][0].v, fa, mi);
}
int main() {
while (cin >> n >> p) {
int u;
node a;
memset(out, 0, sizeof(out));
for (int i = 0; i <= n; i++) e[i].clear();
for (int i = 0; i < p; i++) {
scanf("%d%d%d", &u, &a.v, &a.c);
e[u].push_back(a);
out[u]++;
out[a.v]--;
}
k = 0;
for (int i = 1; i <= n; i++)
if (out[i] == 1) dfs(i, i, 99999999);
printf("%d\n", k);
for (int i = 0; i < k; i++) printf("%d %d %d\n", t1[i], t2[i], r[i]);
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int sz[55], d[55], S, dp[55][55][55][55], mp[55][55], n, m;
vector<int> e[55];
void dfs(int u, int fa) {
for (int v : e[u])
if (v != fa) dfs(v, u), sz[u] += sz[v];
}
int DP(int u, int pre, int s1, int s2) {
if (!s1 && !s2) return 0;
if (!s1) return 0x3f3f3f3f;
if (dp[u][pre][s1][s2] != -1) return dp[u][pre][s1][s2];
if (d[u] == 1) return dp[u][pre][s1][s2] = mp[u][pre] + DP(pre, u, s2, 0);
int tmp[55];
memset(tmp, 0, sizeof(tmp));
tmp[0] = 0x3f3f3f3f;
for (int v : e[u])
if (v != pre) {
for (int i = s1; i >= 0; i--)
for (int j = 0; j <= i; j++)
tmp[i] = max(tmp[i], min(tmp[i - j], DP(v, u, j, s1 + s2 - j)));
}
return dp[u][pre][s1][s2] = tmp[s1] + mp[pre][u];
}
int main() {
memset(dp, -1, sizeof(dp));
scanf("%d", &n);
for (int i = 1, u, v, w; i < n; i++)
scanf("%d%d%d", &u, &v, &w), e[u].push_back(v), e[v].push_back(u),
mp[u][v] = mp[v][u] = w, d[u]++, d[v]++;
scanf("%d%d", &S, &m);
for (int x; m--;) scanf("%d", &x), sz[x]++;
dfs(S, 0);
int ans = 0x3f3f3f3f;
for (int v : e[S]) ans = min(ans, DP(v, S, sz[v], sz[S] - sz[v]));
printf("%d\n", ans);
}
| 11 | CPP |
class Node:
def __init__(self):
self.parent = -1
self.left = -1
self.right = -1
def getDepth(u):
d = 0
while Nodes[u].parent != -1:
u = Nodes[u].parent
d += 1
return d
def printChildren(u):
c = Nodes[u].left
output_list = []
while c != -1:
output_list.append(c)
c = Nodes[c].right
return output_list
# ノードの情報を出力する。
def printNodes(u):
output_str = "node " + str(u) + ": parent = " + str(Nodes[u].parent) + ", depth = " + str(getDepth(u))
if -1 == Nodes[u].parent:
output_str = output_str + ", root, "
elif Nodes[u].left != -1:
output_str = output_str + ", internal node, "
else:
output_str = output_str + ", leaf, "
# output_str += printChildren(u)
print(output_str, "[{}]".format(", ".join(map(str, printChildren(u)))), sep="")
Nodes = []
for i in range(100000):
tmp_obj = Node()
Nodes.append(tmp_obj)
# 入力
n = int(input())
for tmp_count in range(n):
input_val = list(map(int, input().split()))
if 0 != input_val[1]:
# 最も左の子の情報
Nodes[input_val[0]].left = input_val[2]
# 親の情報
Nodes[input_val[2]].parent = input_val[0]
for i in range(input_val[1] - 1):
# 右の兄弟の情報
Nodes[input_val[i+2]].right = input_val[i+3]
# 親の情報
Nodes[input_val[i+3]].parent = input_val[0]
for i in range(n):
printNodes(i)
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
const double pi = acos(-1);
struct point {
double x, y;
};
int n;
double minR, maxR;
point p, v[N];
double dist(point A, point B) {
return sqrt(((A.x - B.x) * (A.x - B.x)) + ((A.y - B.y) * (A.y - B.y)));
}
double dist_to_seg(point A, point B, point C) {
if (B.x == C.x) {
if (A.y >= min(B.y, C.y) && A.y <= max(B.y, C.y))
return (((A.x - B.x) > 0) ? (A.x - B.x) : (-(A.x - B.x)));
return min(dist(A, B), dist(A, C));
}
if (B.y == C.y) {
if (A.x >= min(B.x, C.x) && A.x <= max(B.x, C.x))
return (((A.y - B.y) > 0) ? (A.y - B.y) : (-(A.y - B.y)));
return min(dist(A, B), dist(A, C));
}
double k = (B.y - C.y) / (B.x - C.x);
double crx = (k * B.x - B.y + A.x / k + A.y) / (k + 1 / k);
if (crx >= min(B.x, C.x) && crx <= max(B.x, C.x)) {
double cry = k * (crx - B.x) + B.y;
return (((k * A.x - A.y + B.y - k * B.x) > 0)
? (k * A.x - A.y + B.y - k * B.x)
: (-(k * A.x - A.y + B.y - k * B.x))) /
sqrt(k * k + 1);
}
return min(dist(A, B), dist(A, C));
}
int main() {
scanf("%d%lf%lf", &n, &p.x, &p.y);
for (int i = 1; i <= (n); i++) {
scanf("%lf%lf", &v[i].x, &v[i].y);
maxR = max(maxR, ((dist(p, v[i])) * (dist(p, v[i]))));
}
minR = ((dist_to_seg(p, v[1], v[n])) * (dist_to_seg(p, v[1], v[n])));
for (int i = 1; i <= (n - 1); i++)
minR = min(minR, ((dist_to_seg(p, v[i], v[i + 1])) *
(dist_to_seg(p, v[i], v[i + 1]))));
printf("%.11lf\n", pi * (maxR - minR));
return 0;
}
| 9 | CPP |
n, m = [int(x) for x in input().split()]
res = [0] * n
quant = []
for i in range(m):
s, d, c = [int(x) for x in input().split()]
res[d-1] = m + 1
quant.append((d-1,s-1,c,i+1))
quant.sort()
for q in quant:
d, s, c, i = q[0], q[1], q[2], q[3]
while c:
if res[s] == 0:
res[s] = i
c -= 1
if s == d:
exit(print('-1'))
s += 1
print(*res)
| 13 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
long long n, i, ans = 0;
cin >> n;
long long a;
map<long long, long long> m;
for (i = 0; i < n; i++) {
cin >> a;
m[a]++;
}
map<long long, long long>::iterator it;
for (it = m.begin(); it != m.end(); it++) ans += it->second / 2;
cout << ans / 2;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, a[1001];
char b[1001];
cin >> n;
if (n == 1) a[0] = 1;
if (n >= 2) {
a[0] = 1;
a[1] = 1;
}
for (j = 0; j <= n; j++) b[j] = 'o';
for (i = 2; i <= 16; i++) {
a[i] = a[i - 2] + a[i - 1];
}
for (j = 1; j <= 16; j++) {
b[a[j]] = 'O';
}
for (j = 1; j <= n; j++) cout << b[j];
return 0;
}
| 7 | CPP |
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;
typedef pair<int,int> P;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
int HP, HPm;
int H, W;
char G[100][100];
int D[256];
vector<P> v;
vector<int> p;
string solve() {
int x = 0;
int y = 0;
vector<int> damage;
for(int i = 0; i < v.size(); ++i) {
for(int j = 0; j < v[i].second; ++j) {
int nx = x + dx[v[i].first];
int ny = y + dy[v[i].first];
if(nx < 0 || nx >= W) break;
if(ny < 0 || ny >= H) break;
x = nx;
y = ny;
if(D[G[y][x]] > 0) damage.push_back(D[G[y][x]]);
}
}
vector<P> add;
for(int s = 0; s < (1<<p.size()); ++s) {
int sum = 0;
for(int i = 0; i < p.size(); ++i) {
if(s & (1<<i)) sum += p[i];
}
add.push_back(make_pair(sum, s));
}
sort(add.begin(), add.end());
int bit = (1<<p.size())-1;
for(int i = 0; i < damage.size(); ++i) {
if(HP <= damage[i]) {
if(damage[i] >= HPm) return "NO";
int need = damage[i] - HP + 1;
int j = distance(add.begin(), lower_bound(add.begin(), add.end(), make_pair(need, 0)));
while(j < add.size() && (add[j].second & bit) != add[j].second) ++j;
if(j == add.size()) return "NO";
bit = bit & ~add[j].second;
HP = min(HP + add[j].first, HPm);
}
HP -= damage[i];
}
return "YES";
}
int main() {
while(cin >> HP >> HPm && (HP || HPm)) {
v.clear();
p.clear();
fill(D,D+256,0);
cin >> H >> W;
for(int i = 0; i < H; ++i) {
for(int j = 0; j < W; ++j) {
cin >> G[i][j];
}
}
int T;
cin >> T;
for(int i = 0; i < T; ++i) {
char c; int d;
cin >> c >> d;
D[c] = d;
}
int S;
cin >> S;
for(int i = 0; i < S; ++i) {
char c; int n, d;
cin >> c >> n;
if(c == 'U') d = 3;
if(c == 'D') d = 1;
if(c == 'L') d = 2;
if(c == 'R') d = 0;
v.push_back(make_pair(d,n));
}
int P;
cin >> P;
for(int i = 0; i < P; ++i) {
int h;
cin >> h;
p.push_back(h);
}
cout << solve() << endl;
}
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct point {
double x, y, z;
point(double _x = 0, double _y = 0, double _z = 0) : x(_x), y(_y), z(_z){};
} p[900], q[900];
int sign(double x) {
if (fabs(x) < 1e-8) return 0;
return (x < 0) ? -1 : 1;
}
double dist(point a, point b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) +
(a.z - b.z) * (a.z - b.z));
}
double scalar(point a, point b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%lf%lf%lf", &p[i].x, &p[i].y, &p[i].z);
for (int i = 0; i < m; i++) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
point v1, v2;
if (a == 0 && b == 0) {
v1 = point(0, c, 0);
v2 = point(c, 0, 0);
} else if (a == 0 && c == 0) {
v1 = point(b, 0, 0);
v2 = point(0, 0, b);
} else if (b == 0 && c == 0) {
v1 = point(0, a, 0);
v2 = point(0, 0, a);
} else if (a == 0) {
v1 = point(0, c, -b);
v2 = point(1, c, -b);
} else if (b == 0) {
v1 = point(c, 0, -a);
v2 = point(c, 1, -a);
} else if (c == 0) {
v1 = point(b, -a, 0);
v2 = point(b, -a, 1);
} else {
v1 = point(b, -a, 0);
v2 = point(c, 0, -a);
}
for (int j = 0; j < n; j++) {
double a1 = scalar(v1, v1), b1 = scalar(v1, v2), c1 = scalar(v1, p[j]);
double a2 = scalar(v2, v1), b2 = scalar(v2, v2), c2 = scalar(v2, p[j]);
double x = (c1 * b2 - c2 * b1) / (a1 * b2 - a2 * b1);
double y = (c1 * a2 - c2 * a1) / (b1 * a2 - b2 * a1);
q[j] =
point(v1.x * x + v2.x * y, v1.y * x + v2.y * y, v1.z * x + v2.z * y);
}
random_shuffle(q, q + n);
point o = q[0];
double R = 0;
for (int j = 1; j < n; j++)
if (sign(dist(q[j], o) - R) > 0) {
o = q[j];
R = 0;
for (int k = 0; k < j; k++)
if (sign(dist(q[k], o) - R) > 0) {
o.x = (q[j].x + q[k].x) / 2;
o.y = (q[j].y + q[k].y) / 2;
o.z = (q[j].z + q[k].z) / 2;
R = dist(q[j], q[k]) / 2;
for (int t = 0; t < k; t++)
if (sign(dist(q[t], o) - R) > 0) {
double a1 = 2 * (scalar(v1, q[j]) - scalar(v1, q[k]));
double b1 = 2 * (scalar(v2, q[j]) - scalar(v2, q[k]));
double c1 = scalar(q[j], q[j]) - scalar(q[k], q[k]);
double a2 = 2 * (scalar(v1, q[k]) - scalar(v1, q[t]));
double b2 = 2 * (scalar(v2, q[k]) - scalar(v2, q[t]));
double c2 = scalar(q[k], q[k]) - scalar(q[t], q[t]);
double x = (c1 * b2 - c2 * b1) / (a1 * b2 - a2 * b1);
double y = (c1 * a2 - c2 * a1) / (b1 * a2 - b2 * a1);
o = point(v1.x * x + v2.x * y, v1.y * x + v2.y * y,
v1.z * x + v2.z * y);
R = dist(o, q[j]);
}
}
}
printf("%.10lf\n", R);
}
return 0;
}
| 11 | CPP |
#include <iostream>
int main(){
int n, x;
std::cin >> n >> x;
std::cout << n-x+1 << std::endl;
return 0;
} | 0 | CPP |
t = int(input())
for h in range(t):
s = input()
an = s[0::2]
ans = an + s[len(s) - 1]
print(ans)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double pii = 2 * pi;
const double eps = 1e-6;
const double inf = 1e15;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n, m, k;
cin >> n >> m >> k;
long long int a[n], b[n];
for (long long int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
}
sort(b, b + n, greater<long long int>());
map<long long int, long long int> q;
long long int sum = 0;
for (long long int i = 0; i < m * k; i++) {
q[b[i]]++;
sum += b[i];
}
long long int c = 0, d = 1;
cout << sum << "\n";
for (long long int i = 0; i < n; i++) {
if (q[a[i]] != 0) c++, q[a[i]]--;
if (c == m && d < k) {
cout << i + 1 << " ";
c = 0;
d++;
}
}
cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
string s1, s2;
cin >> s1 >> s2;
int dp[n][m];
int ans = INT_MIN;
for (int i = 0; i <= n - 1; i++) {
dp[i][0] = max(4 * (s1[i] == s2[0]) - 2, 0);
if (i - 1 >= 0) dp[i][0] = max(dp[i][0], dp[i - 1][0] - 1);
ans = max(ans, dp[i][0]);
}
for (int i = 0; i <= m - 1; i++) {
dp[0][i] = max(4 * (s1[0] == s2[i]) - 2, 0);
if (i - 1 >= 0) dp[0][i] = max(dp[0][i], dp[0][i - 1] - 1);
ans = max(ans, dp[0][i]);
}
for (int i = 1; i <= n - 1; i++) {
for (int j = 1; j <= m - 1; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - 1;
if (s1[i] == s2[j]) {
dp[i][j] = max(dp[i - 1][j - 1] + 2, dp[i][j]);
}
dp[i][j] = max(0, dp[i][j]);
ans = max(dp[i][j], ans);
}
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
for (int i = 1; i <= t; i++) {
solve();
}
}
| 10 | CPP |
n = int(input())
s = list(input())
s.append(' ')
ans = 0
l = -2
for c in s:
if c == 'x':
l += 1
else:
ans += max(l, 0)
l = -2
print(ans)
| 8 | PYTHON3 |
import sys
import math
import collections
import heapq
import queue
import itertools
import functools
import operator
import time
readline = sys.stdin.readline
IPS = lambda: readline().rstrip()
IP = lambda: int(readline().rstrip())
MP = lambda: map(int, readline().split())
LS = lambda: list(map(int, readline().split()))
def solve():
for _ in range(IP()):
n,x = MP()
arr = LS()
odd,even = 0,0
for elem in arr:
if elem&1: odd+=1
even = n-odd
if(even!=0 and odd!=0):
if(x==n):
if(odd&1): print("Yes")
else: print("No")
else: print("Yes")
else:
if(x&1==1 and odd!=0): print("Yes")
else: print("No")
if __name__ == "__main__":
solve() | 7 | PYTHON3 |
n,m=map(int,input().split(" "))
m1=0
m2=0
if(n%m==0):
temp=n/m
m1=int(temp*(temp-1)/2)*m
else:
r=n%m
t=int(n/m)
t1=t+1
a1=int((t1*(t1-1)/2)*r)
a2=int(t*(t-1)/2)*(m-r)
m1=a1+a2
k1=n-m
k2=k1+1
if(k1%2==0):
k1=int(k1/2)
else:
k2=int(k2/2)
x=k1*k2
m2=int(x)
print(m1,m2) | 8 | PYTHON3 |
def f(n):
if n % 2 == 1:
return n // 2
else:
return n // 2 - 1
lst = []
for i in range(int(input())):
lst.append(f(int(input())))
for i in lst:
print(i)
| 7 | PYTHON3 |
n=int(input())
a=[100,20,10,5,1]; j=0
while n!=0:
b=[bool(n>=i) for i in a]
for i in range(5):
if b[i]==True:
j+=n//a[i]
n-=(int(n/a[i]))*a[i]
break
print(j) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double pi = 3.1415926535897932384626;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
const int maxn = 1e5 + 5;
int n, vis[maxn];
struct node {
int x;
char ch;
string s;
bool operator<(const node &a) const {
if (x == a.x) return ch < a.ch;
return x < a.x;
}
} p[maxn];
vector<pair<int, int> > g1, g2;
int main() {
n = read();
for (int i = 1; i <= n; ++i) {
cin >> p[i].s;
int len = p[i].s.length();
for (int j = 0; j < len; ++j) {
if (p[i].s[j] == 'a' || p[i].s[j] == 'e' || p[i].s[j] == 'i' ||
p[i].s[j] == 'o' || p[i].s[j] == 'u') {
++p[i].x;
p[i].ch = p[i].s[j];
}
}
}
sort(p + 1, p + n + 1);
for (int i = 1; i < n; ++i) {
if (p[i].x == p[i + 1].x && p[i].ch == p[i + 1].ch) {
vis[i] = vis[i + 1] = 1;
g1.push_back(make_pair(i, i + 1));
++i;
}
}
int pos = 0;
p[0].x = 0;
for (int i = 1; i <= n; ++i) {
if (!vis[i]) {
if (p[pos].x == p[i].x) {
vis[i] = 1;
g2.push_back(make_pair(pos, i));
pos = 0;
} else
pos = i;
}
}
int k = min(g1.size(), g2.size());
int m = k + (g1.size() - k) / 2;
printf("%d\n", m);
for (int i = 0; i < k; ++i) {
cout << p[g2[i].first].s << ' ' << p[g1[i].first].s << '\n';
cout << p[g2[i].second].s << ' ' << p[g1[i].second].s << '\n';
}
for (int i = k; i + 1 < g1.size(); i += 2) {
cout << p[g1[i].first].s << ' ' << p[g1[i + 1].first].s << '\n';
cout << p[g1[i].second].s << ' ' << p[g1[i + 1].second].s << '\n';
}
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s, t, p;
cin >> s >> t >> p;
int n = s.length(), m = t.length();
if (n > m) {
cout << "NO\n";
return;
}
int j = 0;
for (int i = 0; i < m; i++) {
if (j < n && t[i] == s[j]) {
++j;
}
}
if (j != n) {
cout << "NO\n";
return;
}
vector<vector<int>> mp(3, vector<int>(26, 0));
for (char c : s) ++mp[0][c - 'a'];
for (char c : t) ++mp[1][c - 'a'];
for (char c : p) ++mp[2][c - 'a'];
for (int i = 0; i < 26; i++) {
if (mp[0][i] > mp[1][i]) {
cout << "NO\n";
return;
}
}
for (int i = 0; i < 26; i++) {
if (mp[0][i] + mp[2][i] < mp[1][i]) {
cout << "NO\n";
return;
}
}
cout << "YES\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int q;
cin >> q;
while (q--) {
solve();
}
return 0;
}
| 9 | CPP |
a,b=map(int,input().split())
print(int(a)*int(b)) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
struct qry {
int id, fa, x;
char ch;
} q[100000];
struct nod {
int ch[26], ct, mp;
nod() {
for (int i = 0; i < 26; i++) ch[i] = -1;
ct = 0;
mp = -1;
}
} cr[100100];
const long long M = 2000000063LL, R = 1629629681LL;
vector<int> tt[100100], tc[100100];
vector<pair<long long, int> > hp;
long long hsh[100000], pw[100000], rv[100000], tr[400400], tg[400400],
ct[100100], ans[100100];
int sz[100100], fd[100100], fa[100100][17], fa1[100000], tot = 0, lst[100100],
rt[100100];
int m1 = 1, m2 = 1, dp[100100], dep[100100], dfn[100100], fnd[100100], cnt = 1,
org[100100];
void dfs(int x, long long h) {
h %= M;
sz[x] = 1;
hp.push_back(make_pair(h, x));
for (int i = 0; i < 26; i++)
if (cr[x].ch[i] != -1) {
dp[cr[x].ch[i]] = dp[x] + 1;
dfs(cr[x].ch[i], h * 27 + i + 1);
sz[x] += sz[cr[x].ch[i]];
if (cr[x].mp == -1 || sz[cr[x].mp] < sz[cr[x].ch[i]])
cr[x].mp = cr[x].ch[i];
fa1[cr[x].ch[i]] = x;
}
}
void dfs1(int x) {
for (int i = 0; i < tt[x].size(); i++) {
dep[tt[x][i]] = dep[x] + 1;
hsh[tt[x][i]] = (tc[x][i] - 'a' + 1) * pw[dep[x]] + hsh[x];
hsh[tt[x][i]] %= M;
dfs1(tt[x][i]);
}
}
void mpt(int x) {
org[tot] = x;
dfn[x] = tot++;
if (cr[x].mp == -1) return;
rt[cr[x].mp] = rt[x];
mpt(cr[x].mp);
for (int i = 0; i < 26; i++)
if (cr[x].ch[i] != cr[x].mp && cr[x].ch[i] != -1) {
rt[cr[x].ch[i]] = cr[x].ch[i];
mpt(cr[x].ch[i]);
}
}
void add(int x, int t) {
while (x <= tot) {
ct[x] += t;
x += (x & -x);
}
}
long long query(int x) {
long long ans = 0;
while (x) {
ans += ct[x];
x -= (x & -x);
}
return ans;
}
void push_down(int i, int l, int r) {
if (tg[i] == 0) return;
int mid = (l + r) >> 1;
tr[i * 2] += tg[i] * (query(mid) - query(l));
tg[i * 2] += tg[i];
tr[i * 2 + 1] += tg[i] * (query(r) - query(mid));
tg[i * 2 + 1] += tg[i];
tg[i] = 0;
}
void push_up(int i) { tr[i] = tr[i * 2] + tr[i * 2 + 1]; }
void add(int i, int l, int r, int l0, int r0, int w) {
if (l >= l0 && r <= r0) {
tr[i] += w * (query(r) - query(l));
tg[i] += w;
return;
}
push_down(i, l, r);
int mid = (l + r) >> 1;
if (mid > l0) add(i * 2, l, mid, l0, r0, w);
if (mid < r0) add(i * 2 + 1, mid, r, l0, r0, w);
push_up(i);
}
void add(int i, int l, int r, int x, int w) {
if (r - l == 1) {
tr[i] += w;
return;
}
push_down(i, l, r);
int mid = (l + r) >> 1;
if (mid > x)
add(i * 2, l, mid, x, w);
else
add(i * 2 + 1, mid, r, x, w);
push_up(i);
}
long long query(int i, int l, int r, int x) {
if (r - l == 1) return tr[i];
push_down(i, l, r);
int mid = (l + r) >> 1;
if (mid > x)
return query(i * 2, l, mid, x);
else
return query(i * 2 + 1, mid, r, x);
}
int main() {
int n;
scanf("%d", &n);
pw[0] = 1;
rv[0] = 1;
for (int i = 1; i <= n; i++)
pw[i] = pw[i - 1] * 27LL, pw[i] %= M, rv[i] = rv[i - 1] * R, rv[i] %= M;
cr[0].ct = 1;
for (int i = 0; i < n; i++) {
char c[10];
scanf("%d%d%s", &q[i].id, &q[i].fa, c);
q[i].fa--;
q[i].x = (q[i].id == 1) ? m1++ : m2++;
q[i].ch = c[0];
if (q[i].id == 1) {
q[i].fa = fnd[q[i].fa];
if (cr[q[i].fa].ch[q[i].ch - 'a'] == -1) {
cr[q[i].fa].ch[q[i].ch - 'a'] = q[i].x;
fnd[q[i].x] = q[i].x;
cr[cr[q[i].fa].ch[q[i].ch - 'a']].ct = 1;
} else {
cr[cr[q[i].fa].ch[q[i].ch - 'a']].ct++;
fnd[q[i].x] = cr[q[i].fa].ch[q[i].ch - 'a'];
}
} else {
tt[q[i].fa].push_back(q[i].x);
tc[q[i].fa].push_back(q[i].ch);
fa[q[i].x][0] = q[i].fa;
}
}
fa1[0] = -1;
dfs(0, 0);
dfs1(0);
sort(hp.begin(), hp.end());
rt[0] = 0;
mpt(0);
for (int j = 1; j < 17; j++)
for (int i = 0; i < m2; i++) fa[i][j] = fa[fa[i][j - 1]][j - 1];
for (int i = 0; i < tot; i++) {
int j = i + 1;
for (int k = 0; k < (j & -j); k++) {
ct[j] += cr[org[i - k]].ct;
}
}
for (int i = 0; i < m2; i++) {
int y = i;
for (int j = 16; j >= 0; j--) {
int t = fa[y][j];
long long tmp = (hsh[i] - hsh[t]) * rv[dep[t]];
tmp %= M;
tmp += M;
tmp %= M;
vector<pair<long long, int> >::iterator it =
lower_bound(hp.begin(), hp.end(), make_pair(tmp, -1));
if (it < hp.end() && it->first == tmp) {
y = t;
lst[i] = it->second;
}
}
int now = lst[i];
while (now != -1) {
int t = rt[now];
add(1, 0, tot, dfn[t], dfn[now] + 1, 1);
now = fa1[t];
}
}
for (int i = n - 1; i >= 0; i--) {
ans[i] = tr[1];
if (q[i].id == 1) {
long long t = query(1, 0, tot, dfn[fnd[q[i].x]]) /
(query(dfn[fnd[q[i].x]] + 1) - query(dfn[fnd[q[i].x]]));
add(1, 0, tot, dfn[fnd[q[i].x]], -t);
add(dfn[fnd[q[i].x]] + 1, -1);
} else {
int now = lst[q[i].x];
while (now != -1) {
int t = rt[now];
add(1, 0, tot, dfn[t], dfn[now] + 1, -1);
now = fa1[t];
}
}
}
for (int i = 0; i < n; i++) printf("%I64d\n", ans[i]);
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline long long max(long long a, long long b) { return a > b ? a : b; }
inline long long min(long long a, long long b) { return a < b ? a : b; }
void scan(int &x) {
bool neg = false;
register int c;
x = 0;
c = getchar();
if (c == '-') {
neg = true;
c = getchar();
}
for (; (c > 47 && c < 58); c = getchar()) x = (x << 1) + (x << 3) + c - 48;
if (neg) x *= -1;
}
vector<int> data[100009];
long long frq[100009];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int t = 1;
while (t--) {
long long n;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
frq[a[i]]++;
}
int ans[n + 1];
for (int i = 0; i < n; i++) {
int req = n - a[i];
data[req].push_back(i);
if (frq[a[i]] % req != 0) {
cout << "Impossible" << endl;
return 0;
}
if (data[req].size() == req) {
for (auto u : data[req]) {
ans[u] = i + 1;
}
data[req].clear();
}
}
cout << "Possible" << endl;
for (int i = 0; i < n; i++) cout << ans[i] << " ";
cout << endl;
}
return 0;
}
| 8 | CPP |
#include<stdio.h>
int c[10][10];
int w,h;
int sx,sy;
bool done[10][10];
int nh;
int solve(int x,int y,int nd){
int res=0;
int i,j;
for(i=x+1;i<w;i++){
if(nd==nh&&i==sx&&y==sy)return 1;
if(done[i][y]&&c[i][y]==1){
done[i][y]=false;
res+=solve(i,y,nd+1);
done[i][y]=true;
break;
}
}
for(i=x-1;i>=0;i--){
if(nd==nh&&i==sx&&y==sy)return 1;
if(done[i][y]&&c[i][y]==1){
done[i][y]=false;
res+=solve(i,y,nd+1);
done[i][y]=true;
break;
}
}
for(i=y+1;i<h;i++){
if(nd==nh&&x==sx&&i==sy)return 1;
if(done[x][i]&&c[x][i]==1){
done[x][i]=false;
res+=solve(x,i,nd+1);
done[x][i]=true;
break;
}
}for(i=y-1;i>=0;i--){
if(nd==nh&&x==sx&&i==sy)return 1;
if(done[x][i]&&c[x][i]==1){
done[x][i]=false;
res+=solve(x,i,nd+1);
done[x][i]=true;
break;
}
}
return res;
}
int main(){
int i,j;
while(1){
nh=0;
scanf("%d %d",&w,&h);
if(w==0)return 0;
for(i=0;i<w;i++)for(j=0;j<h;j++)done[i][j]=true;
for(i=0;i<h;i++)for(j=0;j<w;j++){
scanf("%d",&c[j][i]);
if(c[j][i]==1)nh++;
if(c[j][i]==2){sx=j;sy=i;}
}
int ans=solve(sx,sy,0);
printf("%d\n",ans);
}
} | 0 | CPP |
n = eval(input())
for test in range(n):
ms = input()
s,m = tuple([int(i) for i in ms.split()])
mark = input()
mark = [int(i) for i in mark.split()]
total = sum(mark)
if m < total:
print(m)
else:
print(total)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
const int M = 505, MOD = 1e9 + 7;
ll dp[M][M], a[M], cb[M][M], pw[M][M];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
for (int i = 0; i < M; i++) {
cb[i][0] = 1;
}
for (int i = 1; i < M; i++) {
for (int j = 1; j < M; j++) {
cb[i][j] = (cb[i - 1][j - 1] + cb[i - 1][j]) % MOD;
}
}
for (int i = 0; i < M; i++) {
pw[i][0] = 1;
for (int j = 1; j < M; j++) {
pw[i][j] = pw[i][j - 1] * i % MOD;
}
}
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a[x]++;
}
dp[0][0] = 1;
for (int i = m; i > 0; i--) {
for (int c = m; c >= 0; c--) {
for (int s = m; s >= 0; s--) {
if (dp[c][s]) {
ll cur = dp[c][s];
dp[c][s] = 0;
for (int j = 0; s + j * i + c - 1 <= m; j++) {
int ns = s + j * i,
nc = c + j;
dp[nc][ns] = (dp[nc][ns]
+ cur * cb[nc][j] % MOD * pw[ns - (i - 1) * nc][a[i]]) % MOD;
}
}
}
}
}
ll ans = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= m; j++) {
int k = m - j - (i - 1);
ll cur = dp[i][j] * cb[i + k][k] % MOD;
if ((m - j) & 1) {
ans = (ans - cur + MOD) % MOD;
}
else {
ans = (ans + cur) % MOD;
}
}
}
cout << ans;
return 0;
} | 0 | CPP |
def buy(nomer, a, b):
if nomer == 0:
return a
else:
return b
n, a, b = map(int, input().split())
d = list(map(int, input().split()))
L = 0
R = n-1
sum = 0
OK = True
while L < R and OK:
if d[L] != 2 and d[R] != 2:
if d[L] != d[R]:
OK = False
break
else:
L += 1
R -= 1
continue
if d[L] == 2 and d[R] != 2:
sum += buy(d[R], a, b)
elif d[L] != 2 and d[R] == 2:
sum += buy(d[L], a, b)
elif d[L] == 2 and d[R] == 2:
sum += 2*min(a, b)
L += 1
R -= 1
if not OK:
print(-1)
else:
if L == R and d[L] == 2:
sum += min(a, b)
print(sum)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
const long long MAX_N = 450 + 100;
const long long MOD = 1e9 + 7;
using namespace std;
int main() {
int n, k;
cin >> n >> k;
cout << 3 * n + min(k - 1, n - k);
return 0;
}
| 8 | CPP |
# https://codeforces.com/group/WdWzpmNKmV/contest/275834/problem/D
from queue import Queue
n, q = input().split(' ')
n, q = int(n), int(q)
adjacents = [dict() for i in range(2*n)]
is_ground = [True for i in range(2*n)]
n_pairs = 0
def BFS(start, end):
ck = [False for i in range(2*n)]
found = False
q = Queue()
q.put(start)
ck[start] = True
while (not found) and (not q.empty()):
node = q.get()
for k, v in adjacents[node].items():
if (v == True) and (not ck[k]):
q.put(k)
ck[k] = True
if k == end:
found = True
return found
for i in range(2):
for j in range(n):
if i == 1:
adjacents[n+j][j] = True
else:
adjacents[j][n+j] = True
if j >= 1:
adjacents[i*n + j][i*n + j-1] = True
if j < n-1:
adjacents[i*n + j][i*n + j+1] = True
for i in range(q):
r, c = input().split(' ')
r, c = int(r)-1, int(c)-1
is_ground[r*n + c] = not is_ground[r*n + c]
pos = ((r+1)*n + c) % (2*n)
if is_ground[r*n + c]: # lava to ground
if not is_ground[pos]:
n_pairs -= 1
if c >= 1 and not is_ground[pos-1]:
n_pairs -= 1
if c < n-1 and not is_ground[pos+1]:
n_pairs -= 1
else: # ground to lava
if not is_ground[pos]:
n_pairs += 1
if c >= 1 and not is_ground[pos-1]:
n_pairs += 1
if c < n-1 and not is_ground[pos+1]:
n_pairs += 1
if n_pairs == 0:
print('Yes')
else:
print('No')
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 2;
const long long int inf = 1e16 + 9;
const long long int mod = 1e9 + 7;
int main() {
long long int n, i, j, k, temp, mxcnt = 0, ans = 1, mul = 0;
cin >> n;
if (n == 1) {
printf("1 0\n");
return 0;
}
temp = n;
set<long long int> second;
for (i = 2; n > 1; i++) {
long long int cnt = 0;
while (n % i == 0) {
cnt++;
n /= i;
}
if (cnt != 0) {
ans = ans * i;
second.insert(cnt);
}
mxcnt = max(mxcnt, cnt);
}
long long int moves = ceil(log2(mxcnt));
if (second.size() == 1) {
if (ceil(log2(mxcnt)) != floor(log2(mxcnt))) mul = 1;
} else
mul = 1;
cout << ans << " " << moves + mul << endl;
return 0;
}
| 8 | CPP |
import sys;input=sys.stdin.readline
from collections import defaultdict, deque
T, = map(int, input().split())
for _ in range(T):
N, M = map(int, input().split())
G = [set() for _ in range(N+1)]
es = []
ees = []
D = defaultdict(int)
in_cnt = defaultdict(int)
outs = defaultdict(int)
for _ in range(M):
t, x, y = map(int, input().split())
if t:
G[x].add(y)
in_cnt[y] += 1
ees.append((x, y))
else:
es.append((x, y))
res = []
queue = deque([i for i in range(1, N+1) if in_cnt[i] == 0])
v2i = dict()
# print(queue, N)
while len(queue) != 0:
v = queue.popleft()
res.append(v)
for v2 in G[v]:
in_cnt[v2] -= 1
if in_cnt[v2] == 0:
queue.append(v2)
if len(res) != N:
print("NO")
continue
print("YES")
for i in range(N):
v2i[res[i]] = i
for x, y in es:
if v2i[x] < v2i[y]:
print(x, y)
else:
print(y, x)
for x, y in ees:
print(x, y)
| 11 | PYTHON3 |
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n1;
cin>>n1;
for(int l=0;l<n1;++l){
int a[8],max=0,min=0,n;
cin>>n;
for(int i=0;i<8;++i){
a[i]=n%10;
n/=10;
}
sort(a,a+8);
for(int i=7;i>=0;--i){
max*=10;
max+=a[i];
}
for(int i=0;i<8;++i){
min*=10;
min+=a[i];
}
cout<<max-min<<endl;
}
} | 0 | CPP |
t = int(input())
a = input()
ans = ""
a = [int(x) for x in a.split()]
newa = sorted(a)
newa = newa[::-1]
ch = []
done = {}
for x in range(1,t+1):
if newa[x-1] not in ch:
done[newa[x-1]] = x
ch.append(newa[x-1])
for y in a:
ans += str(done[y]) + " "
print (ans)
| 7 | PYTHON3 |
a=input()
try:
d='ello'
j=0
k=True
s=a.index('h')
for i in range(s,len(a)):
if j==3 and a[i]=='o':
print('YES')
k=False
break
if a[i]==d[j]:
j+=1
if k:
print('NO')
except:
print('NO')
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
long long int A, B;
cin >> A >> B;
A = min(A, B);
long long int ans = 1;
int i;
for (i = 1; i <= A; i++) ans *= i;
cout << ans << "\n";
}
| 7 | CPP |
from collections import deque
def Bsearch(arr , x):
l ,r = 0 , len(arr) - 1
while l <= r :
mid = l + (r - l ) // 2
if arr[mid] < x :
l = mid + 1
elif arr[mid] > x :
r = mid - 1
else:
return mid + 1
if arr[l] > x :
return l + 1
else:
return r + 1
n = int(input())
l1 = list(map(int,input().split()))
m = int(input())
l2 = list(map(int,input().split()))
a = deque()
a.append(l1[0])
for i in range(1 , n):
a.append(a[-1] + l1[i])
a = sorted(a)
#print(a)
for i in range(m):
r = Bsearch(a , l2[i])
print(r)
| 8 | PYTHON3 |
a,b=input().split()
s=a[0]+b[0]
c=a[0]
for i in range(1,len(a)):
c+=a[i]
if c+b[0]<s:
s=c+b[0]
print(s) | 7 | PYTHON3 |
p, q, l, r = map(int, input().split())
a = [0] * p
b = [0] * p
c = [0] * q
d = [0] * q
e = [0] * 1001
for i in range(p):
a[i], b[i] = map(int, input().split())
for j in range(a[i], b[i] + 1):
e[i] += 1
for i in range(q):
c[i], d[i] = map(int, input().split())
n = 0
for k in range(l, r + 1):
exist = False
for i in range(p):
for j in range(q):
if max(a[i], c[j] + k) <= min(b[i], d[j] + k):
n += 1
exist = True
if exist:
break
if exist:
break
print(n)
| 8 | PYTHON3 |
n = int(input())
h = list(map(int, input().split()))
m = h[-1]
res = []
for x in h[::-1]:
res.append(str(max(0, m-x)))
m = max(m, x+1)
print (' '.join(res[::-1]))
| 8 | PYTHON3 |
t=int(input())
for _ in range(t):
n, x = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
count = [0, 0]
for num in a:
count[num%2]+=1
ans = 'No'
for odds in range(1, x+1, 2):
if count[1] >= odds and x-odds <= count[0]:
ans = 'Yes'
print(ans)
| 7 | PYTHON3 |
n=int(input())
for j in range(n):
g=1
x=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
for i in range(x):
if a[i]>x-i-1+g:
pass
else:
g=g+1
print(g) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
string s;
int N;
vector<int> ma, dot, und, let, dig;
int pre[(1 << 20)];
long long ans = 0;
int main() {
cin >> s;
N = s.length();
int i, j, k, l, u;
vector<int>::iterator it;
for (i = 0; i < N; ++i) {
if (s[i] == '@')
ma.push_back(i);
else if (s[i] == '.')
dot.push_back(i);
else if (s[i] == '_')
und.push_back(i);
else if (s[i] >= 'a' && s[i] <= 'z')
let.push_back(i);
else
dig.push_back(i);
}
for (i = 0; i < N; ++i) pre[i] = -1;
for (i = 0; i < dot.size(); ++i) {
k = dot[i];
for (j = k + 1; j < N; ++j) {
if (s[j] < 'a' || s[j] > 'z') {
pre[k] = j - 1;
break;
}
}
if (j == N) pre[k] = N - 1;
if (pre[k] == k) pre[k] = -1;
}
for (i = 0; i < N; ++i) {
if (s[i] < 'a' || s[i] > 'z') continue;
it = lower_bound(ma.begin(), ma.end(), i);
if (it == ma.end()) continue;
k = *it;
it = lower_bound(dot.begin(), dot.end(), i);
if (it == dot.end()) continue;
l = *it;
if (l < k + 2 || pre[l] == -1) continue;
it = lower_bound(ma.begin(), ma.end(), k + 1);
if (it != ma.end()) {
u = *it;
if (u < l) continue;
}
it = lower_bound(und.begin(), und.end(), k + 1);
if (it != und.end()) {
u = *it;
if (u < l) continue;
}
ans += pre[l] - l;
}
cout << ans << '\n';
return 0;
}
| 11 | CPP |
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int main() {
int q; cin >> q;
long a, b;
cin >> a >> a >> b;
multiset<long> alist;
alist.insert(a);
auto center = alist.begin();
int len = 1;
long sum = b;
for (int i = 1; i < q; i++) {
// cerr << "center " << *center << ' ' << sum << '\n';
int type; cin >> type;
if (type == 1) {
cin >> a >> b;
sum += abs(*center - a) + b;
alist.insert(a);
if (len%2 == 1 && a < *center)
center--;
else if (len%2 == 0 && a >= *center) {
long prev = *center;
center++;
sum -= *center - prev;
}
len++;
} else
cout << *center << ' ' << sum << '\n';
}
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
int t = i ^ j;
if (t >= j && t <= n && t < i + j) {
ans++;
}
}
}
cout << ans << endl;
return 0;
}
| 8 | CPP |
n = int(input())
l = list(map(int,input().split()))
d = {}
d.setdefault(l[0],1)
for i in range(1,n):
if l[i] in d.keys():
if l[i]-1 in d.keys():
d[l[i]] = max(d[l[i]-1]+1,d[l[i]])
else:
d[l[i]] = 1
else:
if l[i]-1 in d.keys():
d[l[i]] = d[l[i]-1]+1
else:
d[l[i]] = 1
a = 0
b = 0
for i,j in d.items():
if b<j:
b = j
a = i
print(b)
temp = a-b+1
for i in range(n):
if l[i]==temp:
print(i+1,end=" ")
temp+=1
if temp==a+1:
break
print() | 12 | PYTHON3 |
# takes only arrays of size 2 or more
def isSorted(a,start,end):
for i in range(start+1,end+1):
if a[i]<a[i-1]:
return False
return True
def maxSub(a,start,end):
if end-start==0:
return 1
if isSorted(a,start,end)==True:
return end-start+1
return max(maxSub(a, start, start + (end-start)//2), maxSub(a,(start+(end-start)//2)+1 , end))
n = int(input())
a = list(map(int,input().strip().split()))
print(maxSub(a,0,n-1))
| 7 | PYTHON3 |
#include"bits/stdc++.h"
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long N, M;
cin >> N >> M;
cout << abs((N - 2)*(M - 2)) << endl;
return 0;
} | 0 | CPP |
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the function below.
m=int(input())
s= str(input())
print(abs(s.count('1')- s.count('0'))) | 7 | PYTHON3 |
entrada = input()
entrada = input()
entrada =entrada.split(" ")
aux = "0"
cont = 0
for i in entrada:
if i == "0":
cont+=1
aux = "0"
elif aux == "0" or (aux == "3" and aux == "3"):
aux = i
else:
if aux == i:
cont+=1
aux = "0"
elif aux == "3":
if i == "2":
aux = "1"
elif i == "1":
aux = "2"
else:
if aux == "2":
aux = "1"
else:
aux = "2"
print(cont)
| 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int scores[n];
for (int i = 0; i < n; i++) {
cin >> scores[i];
}
int unique_numbers[601];
for (int i = 0; i < 601; i++) {
unique_numbers[i] = 0;
}
int cnt = 0;
for (int i = 0; i < n; i++) {
unique_numbers[scores[i]]++;
if (unique_numbers[scores[i]] == 1) {
if (scores[i] > 0) cnt++;
}
}
cout << cnt;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
map<int, string> CharMap;
void num2str() {
CharMap[0] = "0";
CharMap[1] = "1";
CharMap[2] = "2";
CharMap[3] = "3";
CharMap[4] = "4";
CharMap[5] = "5";
CharMap[6] = "6";
CharMap[7] = "7";
CharMap[8] = "8";
CharMap[9] = "9";
}
string to_string(long long n) {
string s = "";
while (n > 0) {
int x = n % 10;
n /= 10;
s = CharMap[x] + s;
}
return s;
}
long long pow1(long long x, long long y) {
if (y == 0) return 1;
long long temp = pow1(x, y / 2) % 1000000007;
if (y % 2 == 0)
return (temp * temp) % 1000000007;
else
return (((temp * temp) % 1000000007) * x) % 1000000007;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int d[1000005];
int main() {
int n, m, a, b, i;
num2str();
scanf("%d%d", &n, &m);
memset(d, 0, sizeof(d));
for (i = 0; i < m; i++) {
scanf("%d%d", &a, &b);
d[a]++;
d[b]++;
}
long long s = 0;
for (i = 1; i < n + 1; i++) {
s += 1LL * d[i] * (d[i] - 1) - 1LL * d[i] * (n - 1 - d[i]) +
1LL * (n - 1 - d[i]) * (n - 2 - d[i]);
}
cout << s / 6;
printf("\n");
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
string get(string a) {
vector<string> v;
a += a;
for (int i = 0; i < (4); ++i) v.push_back(a.substr(i, 4));
sort((v).begin(), (v).end());
return v[0];
}
char buf[50];
int main(void) {
set<string> S;
int n;
scanf("%d", &n);
for (int i = 0; i < (n); ++i) {
string a;
scanf("%s", buf);
a += string(buf);
scanf("%s", buf);
string tmp(buf);
reverse((tmp).begin(), (tmp).end());
a += tmp;
S.insert(get(a));
if (i < n - 1) scanf("%*s");
}
printf("%d\n", ((int)((S).size())));
return 0;
}
| 7 | CPP |
t = int(input())
for _ in range(t):
n = int(input())
while n > 1 and n % 2 == 0:
n //= 2
print("YES" if n > 1 else "NO")
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long maxm = -1e18;
long long minm = 1e18;
long long mod = 1e9 + 7;
long long mod1 = 1e9 + 9;
const long double Pi = 3.141592653;
long long int fact(long long int n) {
if (n == 0) {
return 1;
} else if (n == 1) {
return 1;
}
long long int res = 1;
for (long long int i = 2; i <= n; i++) res = res * i;
return res;
}
long long int nCr(long long int n, long long int r) {
return fact(n) / (fact(r) * fact(n - r));
}
bool cmp(pair<long long int, vector<long long int>> a,
pair<long long int, vector<long long int>> b) {
return (a.first > b.first);
}
bool isint(double n) {
long long int j = n;
double w = n - j;
if (w > 0) {
return false;
}
return true;
}
long long int count3(long long int x) {
long long int ret = 0;
while (x % 3 == 0) {
ret++;
x /= 3;
}
return ret;
}
int32_t main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
long long t = 1;
cin >> t;
vector<string> v;
v.push_back("1");
for (long long int i = 2; i <= 100; i++) {
bool c = true;
for (long long int j = 2; j * j <= i; j++) {
if (i % j == 0) {
v.push_back(to_string(i));
break;
}
}
}
while (t--) {
long long int n;
cin >> n;
string s;
cin >> s;
unordered_map<char, long long int> m;
for (long long int i = 0; i < s.size(); i++) {
m[s[i]]++;
}
for (long long int i = 0; i < v.size(); i++) {
unordered_map<char, long long int> m1;
for (long long int j = 0; j < v[i].size(); j++) {
m1[v[i][j]]++;
}
bool w = true;
for (auto it : m1) {
if (m.find(it.first) != m.end()) {
if (it.second > m[it.first]) {
w = false;
break;
}
} else {
w = false;
break;
}
}
long long int k = 0;
for (long long int x = 0; x < s.size(); x++) {
if (k == v[i].size()) {
break;
}
if (s[x] == v[i][k]) {
k++;
}
}
if (k != v[i].size()) {
w = false;
}
if (w) {
cout << v[i].size() << '\n';
cout << v[i] << '\n';
break;
}
}
}
return 0;
}
| 8 | CPP |
# https://codeforces.com/problemset/problem/1326/A
nb_cases = int(input())
for case in range(nb_cases):
n = int(input())
if n==1:
print(-1)
else:
print("2" + "9"*(n-1))
| 7 | PYTHON3 |
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>
using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
/* do your best */
int main() {
string s; cin >> s;
char cur = 'A';
lint ans = 0;
for (auto c : s) {
if (c <= cur) {
ans++;
}
cur = c;
}
cout << ans << endl;
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long T, all;
cin >> T >> all;
unsigned long long a[T], b[T], c[T];
unsigned long long sum_a = 0;
unsigned long long sum_b = 0;
unsigned long long i, j;
for (i = 0; i < T; i++) {
cin >> a[i] >> b[i];
sum_a += a[i];
sum_b += b[i];
c[i] = a[i] - b[i];
}
if (sum_b > all) {
cout << "-1";
} else if (sum_a <= all) {
cout << "0";
} else {
unsigned long long count = 0;
sort(c, c + T);
for (i = T - 1; i >= 0; i--) {
sum_a -= c[i];
if (sum_a <= all) {
count++;
break;
} else {
count++;
}
}
cout << count;
}
return 0;
}
| 9 | CPP |
count = int(input())
for i in range(0, count):
word = input()
if len(word) <= 10:
print(word)
else:
print(word[0] + str(len(word)-2) + word[-1]) | 7 | PYTHON3 |
#!/usr/bin/env python3
from sys import stdin
from math import floor
n=int(stdin.readline())
a=list(map(int,(stdin.readline().split())))
a.sort()
print(a[floor(n/2-0.1)]) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s; cin >> s;
int cntx = 0;
for(int i = 0; i < s.length(); i++)if(s[i]=='x')cntx++;
cout << (((15 - cntx)>=8) ? "YES" : "NO") << endl;
return 0;
} | 0 | CPP |
def win(n, x):
if n == 1:
return "Ayush"
deg = 0
for i in range(n-1):
a, b = map(int, input().split())
if a == x or b == x:
deg += 1
if deg == 1:
return "Ayush"
return ["Ayush", "Ashish"][n % 2]
t = int(input())
for i in range(t):
n, x = map(int, input().split())
print(win(n, x))
| 9 | PYTHON3 |
#include <stdio.h>
int main(void){
int n,x;
while(1){
scanf("%d",&n);
if(n==-1) break;
if(n<=10) x=1150;
else if(10<n&&n<=20) x=1150+125*(n-10);
else if(20<n&&n<=30) x=1150+1250+140*(n-20);
else x=1150+1250+1400+160*(n-30);
printf("%d\n",4280-x);
}
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t--) {
int n, m;
cin >> n >> m;
string ans = "";
if (n < (m - 1) / 2 || m < n - 1) {
cout << -1 << endl;
return 0;
}
while (m > 1 && n > 0 && n < m) {
ans += "110";
m -= 2, n--;
}
while (n && m) {
ans += "10";
n--, m--;
}
while (n) {
assert(n == 1);
ans = "0" + ans;
n--;
}
while (m) {
assert(m < 3);
ans += "1", m--;
}
cout << ans << endl;
}
return 0;
}
| 9 | CPP |
t=int(input())
for hh in range(0,t):
n,m=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
d=dict()
ans=0
for i in range(0,len(a)):
d[a[i]]=i+1
maxdepth=1
for i in range(0,len(b)):
pos=d[b[i]]
# print(pos,maxdepth)
if pos<=maxdepth:
ans+=1
else:
maxdepth=pos
ans+=2*(maxdepth-i-1)+1
# print(ans)
print(ans)
| 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<string> d(8);
for (auto& i : d) cin >> i;
cout << 90 << endl;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
cout << d[7-j][i];
}
cout << endl;
}
cout << 180 << endl;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
cout << d[7 - i][7 - j];
}
cout << endl;
}
cout << 270 << endl;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
cout << d[j][7-i];
}
cout << endl;
}
return 0;
} | 0 | CPP |
// クエリ先読みして出てくる単語を掌握
// グラフを張る
// 辞書順に全探索して実際に成立するか確かめる
#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;
int main() {
int n, f;
cin >> n >> f;
set<string>se;
vector<vector<string>>input(n);
for (int i = 0; i < n; i++) {
int m; cin >> m;
for (int j = 0; j < m; j++) {
string s;
cin >> s;
se.insert(s);
input[i].push_back(s);
}
}
vector<string>product;
for (auto s : se)product.push_back(s);
vector<vector<int>>graph(product.size(), vector<int>(product.size()));
for (int i = 0; i < n; i++) {
for (int j = 0; j < input[i].size(); j++) {
for (int k = j + 1; k < input[i].size(); k++) {
int a = 0;
for (int index = 0; index < product.size(); index++) {
if (product[index] == input[i][j])a = index;
}
int b = 0;
for (int index = 0; index < product.size(); index++) {
if (product[index] == input[i][k])b = index;
}
graph[a][b]++;
graph[b][a]++;
}
}
}
vector<vector<string>>ret;
for (int i = 0; i < product.size(); i++) {
for (int j = i + 1; j < product.size(); j++) {
if (graph[i][j] >= f) {
ret.push_back({ product[i],product[j] });
}
}
}
cout << ret.size() << endl;
for (auto x : ret)cout << x[0] << " " << x[1] << endl;
return 0;
}
| 0 | CPP |
t=int(input())
for j in range(t):
n=int(input())
ct,k=0,0
while n>1:
if not n%2:
n>>=1
elif not n%3:
n//=3
n*=2
elif not n%5:
n//=5
n*=4
else:
k+=1
print(-1)
break
ct+=1
if k==0:
print(ct)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
namespace mstd {
inline void qread(int &x) {
x = 0;
int f = 1;
static char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -f;
c = getchar();
}
while (isdigit(c)) x = (x * 10 + c - '0'), c = getchar();
x *= f;
}
inline void qread(long long &x) {
x = 0;
long long f = 1;
static char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -f;
c = getchar();
}
while (isdigit(c)) x = (x * 10 + c - '0'), c = getchar();
x *= f;
}
} // namespace mstd
const int maxn = 100100;
int f[maxn], n, m;
int size, head[maxn], sz[maxn];
int c[maxn], looker[maxn], tv[maxn], cnt, bl[maxn];
int ans[maxn], a[maxn], len;
int vt[maxn];
struct edge {
int next, to;
} e[maxn << 1];
inline void addedge(int next, int to) {
e[++size].to = to;
e[size].next = head[next];
head[next] = size;
}
void dfs1(int t, int fat) {
int i, j;
sz[t] = 1;
f[t] = fat;
tv[t] = ++cnt;
vt[cnt] = t;
for (i = head[t]; i; i = e[i].next) {
j = e[i].to;
if (j == fat) continue;
dfs1(j, t);
sz[t] += sz[j];
}
}
struct que {
int l, r, k, bh;
bool operator<(const que &ano) const {
if (bl[l] == bl[ano.l])
return (bl[l] & 1 ? 1 : -1) * r < (bl[l] & 1 ? 1 : -1) * ano.r;
else
return bl[l] < bl[ano.l];
}
} q[maxn];
inline void prework() {
int i, j;
for (i = 1; i <= m; i++)
q[i].r = tv[q[i].l] + sz[q[i].l] - 1, q[i].l = tv[q[i].l];
len = max(10, (int)sqrt(n));
for (i = 1; i <= m; i++) bl[i] = (i - 1) / len + 1;
sort(q + 1, q + m + 1);
}
inline void add(const int x) {
c[a[vt[x]]]++;
looker[c[a[vt[x]]]]++;
return;
}
inline void del(const int x) {
looker[c[a[vt[x]]]]--;
c[a[vt[x]]]--;
return;
}
int main() {
int i, j;
mstd::qread(n);
mstd::qread(m);
for (i = 1; i <= n; i++) mstd::qread(a[i]);
int t1, t2;
for (i = 1; i < n; i++)
mstd::qread(t1), mstd::qread(t2), addedge(t1, t2), addedge(t2, t1);
dfs1(1, 1);
for (i = 1; i <= m; i++)
mstd::qread(q[i].l), mstd::qread(q[i].k), q[i].bh = i;
prework();
int l = 1, r = 0;
for (i = 1; i <= m; i++) {
while (l < q[i].l) del(l++);
while (l > q[i].l) add(--l);
while (r < q[i].r) add(++r);
while (r > q[i].r) del(r--);
ans[q[i].bh] = looker[q[i].k];
}
for (i = 1; i <= m; i++) printf("%d\n", ans[i]);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
#define pb emplace_back
using namespace std;
const int maxn = 2e5;
int ans[maxn + 11],col[maxn + 11];
vector <int> edge[maxn + 11],ver[maxn + 11];
int cnt[5];
int R = 0 , B = 0;
void dfs(int x,int fa,int d) {
col[x] = d % 2;
if (d % 2 == 1) R++; else B++;
ver[d].pb(x);
for (auto v : edge[x]) {
if (v == fa) continue;
dfs(v , x , d + 1);
}
}
int main(){
int n;
scanf("%d" , &n);
for (int i = 1; i < n; i++) {
int u,v;
scanf("%d %d",&u,&v);
edge[u].pb(v);
edge[v].pb(u);
}
dfs(1 , 0 , 0);
if (R > B) {
swap(R , B);
for (int i = 1; i <= n; i++) col[i] ^= 1;
}
if (R <= n / 3) {
int l = 1; int r = 3;
for (int i = 1; i <= n; i++) {
if (col[i]) ans[i] = r , r += 3;
else {
if (l <= n) {
ans[i] = l;
l++; if (l % 3 == 0) l++;
}
else {
ans[i] = r , r += 3;
}
}
}
}
else {
cnt[1] = 1; cnt[2] = 2; cnt[3] = 3;
for (int i = 1; i <= n; i++) {
if (col[i]) {
if (cnt[1] <= n) ans[i] = cnt[1] , cnt[1] += 3;
else ans[i] = cnt[3] , cnt[3] += 3;
}
else {
if (cnt[2] <= n) ans[i] = cnt[2] , cnt[2] += 3;
else ans[i] = cnt[3] , cnt[3] += 3;
}
}
}
for (int i = 1; i <= n; i++) printf("%d " , ans[i]);
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
string tostr(int n) {
stringstream rr;
rr << n;
return rr.str();
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
string s;
cin >> s;
vector<int> a;
for (int(i) = 0; (i) < (s.length()); ++(i)) {
if (s[i] == '2' || s[i] == '3' || s[i] == '5' || s[i] == '7') {
a.push_back(s[i] - '0');
} else if (s[i] == '4') {
a.push_back(3);
a.push_back(2);
a.push_back(2);
} else if (s[i] == '6') {
a.push_back(5);
a.push_back(3);
} else if (s[i] == '8') {
a.push_back(7);
a.push_back(2);
a.push_back(2);
a.push_back(2);
} else if (s[i] == '9') {
a.push_back(7);
a.push_back(3);
a.push_back(3);
a.push_back(2);
}
}
sort(a.begin(), a.end(), greater<int>());
for (int(i) = 0; (i) < (a.size()); ++(i)) {
cout << a[i];
}
return 0;
}
| 9 | CPP |
n = int(input())
o = sum((n-i)*i for i in range(n))
o += n
print(o) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
scanf("%lld", &N);
long long ans = 1;
while (2 * ans - 1 < N) {
ans++;
}
printf("%lld\n", ans);
long long cnt = 0;
for (long long i = 1; i <= ans; i++) {
cout << "1"
<< " " << i << endl;
cnt++;
if (cnt == N) {
return 0;
}
}
if (cnt == N) return 0;
for (long long i = 2; i <= ans; i++) {
cout << ans << " " << i << endl;
cnt++;
if (cnt == N) {
return 0;
}
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
char s[MAXN];
int L[MAXN], R[MAXN];
int main() {
int n, a, b, t;
while (~scanf("%d%d%d%d%s", &n, &a, &b, &t, s)) {
int ans = 0;
vector<int> V1, V2;
L[0] = s[0] == 'w' ? b + 1 : 1;
if (L[0] <= t) ans = 1;
for (int i = 1; i < n; i++) {
L[i] = L[i - 1] + a + (s[i] == 'w' ? b + 1 : 1);
V1.push_back(L[i]);
if (L[i] <= t) {
ans = max(ans, i + 1);
}
}
R[0] = s[0] == 'w' ? b + 1 : 1;
for (int i = n - 1; i >= 1; i--) {
R[i] = R[(i + 1) % n] + a + (s[i] == 'w' ? b + 1 : 1);
V2.push_back(R[i]);
if (R[i] <= t) {
ans = max(ans, n - i + 1);
}
}
for (int i = 1; i < n; i++) {
if (L[i] + i * a > t) continue;
int left = t - L[i] - i * a + L[0];
int pos = upper_bound(V2.begin(), V2.end(), left) - V2.begin();
if (left >= 0) {
ans = max(ans, i + 1 + pos);
}
}
for (int i = n - 1; i >= 1; i--) {
if (R[i] + (n - i) * a > t) continue;
int left = t - R[i] - (n - i) * a + L[0];
int pos = upper_bound(V1.begin(), V1.end(), left) - V1.begin();
if (left >= 0) {
ans = max(ans, n - i + 1 + pos);
}
}
ans = min(ans, n);
printf("%d\n", ans);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
int comparetor(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int arr[200005], index[200005];
;
for (int i = 1; i <= n; i++) {
scanf("%d", &arr[i]);
index[arr[i]] = i;
}
int ans[200005] = {0};
int mn = 1000000000, mx = -1;
for (int i = 1; i <= n; i++) {
mn = min(index[i], mn);
mx = max(index[i], mx);
if (mx - mn + 1 == i) ans[i] = 1;
}
for (int i = 1; i <= n; i++) printf("%d", ans[i]);
printf("\n");
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[1000];
int i, j = 0, k, l, a[1000], m, n, t;
cin >> s;
l = strlen(s);
for (i = 0; i < l; i++) {
if ((i % 2) == 0) {
a[j] = (int)s[i];
j++;
}
}
for (m = 1; m < j; m++) {
for (n = 0; n < (j - m); n++) {
if (a[n] > a[n + 1]) {
t = a[n];
a[n] = a[n + 1];
a[n + 1] = t;
}
}
}
for (k = 0; k < j; k++) {
if (k == (j - 1)) {
cout << (char)a[k];
} else {
cout << (char)a[k] << '+';
}
}
cout << "\n";
return 0;
}
| 7 | CPP |
# cook your dish here
a, b, n = map(int, input().split())
s=str(a)
f=0
for i in range(10):
x=str(i)
s2=s
s2+=x
num=int(s2)
if(num)%b==0:
f=1
s=s2
break
if f==0:
print('-1')
else:
s=int(s)
s*=(10**(n-1))
print(s)
| 7 | PYTHON3 |
import sys
import queue
sys.setrecursionlimit(100000)
# global constant
INF = int(1e7+1)
MAX = 100005
# For testing
#sys.stdin = open("INP.txt", 'r')
#sys.stdout = open("OUT.txt", 'w')
# global variables
parents = []
ranks = []
size = []
n = 0
# classes
# functions
def init():
global parents, ranks, size
parents = [i for i in range(MAX)]
ranks = [0 for i in range(MAX)]
size = [1 for i in range(MAX)]
def findSet(u):
if(parents[u] != u):
parents[u] = findSet(parents[u])
return parents[u]
def unionSet(u, v):
up = findSet(u)
vp = findSet(v)
if up == vp:
return
if ranks[up] < ranks[vp]:
parents[up] = vp
elif ranks[vp] < ranks[up]:
parents[vp] = up
else:
ranks[vp] += 1
parents[up] = vp
# main function
def main():
global n
n, m = map(int, input().split())
init()
for i in range(m):
u, v = map(int, input().split())
u -= 1
v -= 1
unionSet(u, v)
M = {}
for i in range(n):
root = findSet(i)
if root not in M:
M[root] = 1
else:
M[root] += 1
ans = 1
if len(M) > 0:
for setSize in M.values():
ans *= max(1, 2**(setSize-1))
print(ans)
main()
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
int main() {
ll n,a,b;
cin>>n>>a>>b;
map<ll,ll>c;
for(ll i=0;i<n;i++){
ll x;
cin>>x;
x*=-1;
c[x]++;
}
ll ans=0;
auto itr=c.begin();
if(a<=itr->second){
ll ans1=(itr->first)*(-1)*a;
double A=a;
printf("%.9f\n",ans1/A);
ll lim=min(itr->second,b);
//cout << lim<<endl;
ll val=itr->second;
ll now=itr->second;
for(ll i=2;i<=a;i++){
now*=(val-i+1);
now/=i;
}
a++;
ans=now;
while(a<=lim){
now*=(val-a+1);
now/=a;
ans+=now;
a++;
}
cout <<ans;
return 0;
}
ll sum=0;
double num=a;
while(a>itr->second){
a-=itr->second;
sum+=(itr->first)*(-1)*(itr->second);
itr++;
//cout <<sum;
}
sum+=(itr->first)*(-1)*a;
printf("%.9f\n",sum/num);
ll now=1;
for(ll i=1;i<=a;i++){
now*=(itr->second-i+1);
now/=i;
}
cout<<now;
// your code goes here
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int pre[100005][20], suf[100005][20], mn[100005][20];
int a[100005], lg[100005], n, ans;
int getmn(int x, int y) {
if (x > y) return 1e9;
int k = lg[y - x + 1];
return min(mn[x][k], mn[y - (1 << k) + 1][k]);
}
int getmn1(int x, int y) {
if (x > y) return 1e9;
int k = lg[y - x + 1];
return min(pre[x][k], pre[y - (1 << k) + 1][k]);
}
int getmn2(int x, int y) {
if (x > y) return 1e9;
int k = lg[y - x + 1];
return min(suf[x][k], suf[y - (1 << k) + 1][k]);
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
mn[i][0] = a[i];
pre[i][0] = a[i] - i;
suf[i][0] = a[i] + i;
}
for (int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;
for (int j = 1; j < 17; j++) {
int bit = 1 << (j - 1);
for (int i = 1; i + (1 << j) - 1 <= n; i++) {
mn[i][j] = min(mn[i][j - 1], mn[i + bit][j - 1]);
pre[i][j] = min(pre[i][j - 1], pre[i + bit][j - 1]);
suf[i][j] = min(suf[i][j - 1], suf[i + bit][j - 1]);
}
}
int L = 1;
ans = 1e9;
for (int T = 1; T <= n; T++) {
for (; L <= T && T >= 2 * L - a[L]; L++)
;
int j = -1;
if (L <= T)
j = L;
else {
int l = T, r = n;
while (l <= r) {
int mid = (l + r) / 2;
if (getmn(T, mid) < T)
j = mid, r = mid - 1;
else
l = mid + 1;
}
if (j == -1) continue;
}
int x, y;
if (j <= T) {
x = getmn1(1, j - 1) + T;
y = min(getmn1(j, T) + T, getmn2(T + 1, n) - T);
} else {
x = min(getmn1(1, T) + T, getmn2(T + 1, j - 1) - T);
y = getmn2(j, n) - T;
}
ans = min(ans, max(x, y));
}
if (ans > 1e8)
puts("-1");
else
printf("%d", ans);
}
| 11 | CPP |
n= int(input(""))
if n==1:
print(-1)
else:
print(str(n)+" "+str(n))
| 7 | PYTHON3 |
# Anuneet Anand
def BS(A,x,l,h):
if h-l>0:
m = (l+h)//2
if x<A[m]:
return BS(A,x,l,m)
else:
return BS(A,x,m+1,h)
else:
if x>A[l]:
return h
else:
return l
n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = list(map(int,input().split()))
C = [1]
S = 0
for i in range(n):
S = S + A[i]
C.append(S+1)
C = list(set(C))
for i in range(m):
print(BS(C,B[i],0,len(C))) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, a, b, c, d;
cin >> t;
while (t--) {
cin >> a >> b >> c >> d;
cout << b << " " << c << " " << c << endl;
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long calculating(long long num, long long goal) {
long long past_numbers = ((num - 1) * num) / 2, last_number;
goal += past_numbers;
goal = goal * 2;
last_number = -1 + floor(sqrt(1 + 4 * goal));
last_number = last_number / 2;
if ((last_number * (last_number + 1)) / 2 - past_numbers < goal) {
last_number++;
}
last_number = (last_number * (last_number + 1)) / 2 - past_numbers;
return last_number;
}
long long substract(long long mayor, long long menor, long long min_mayor) {
long long compare = ((min_mayor - 1) * min_mayor) / 2, rpta;
compare = (compare + mayor - menor) * 2;
rpta = -1 + floor(sqrt(1 + 4 * compare));
rpta = rpta / 2;
if (mayor - (rpta * (rpta + 1)) / 2 + ((min_mayor - 1) * min_mayor) / 2 <=
menor)
;
else
rpta++;
return rpta;
}
int main() {
pair<long long, long long> best_pair = make_pair(1000000000, 2000000000);
long long students, length, height, area, area_student;
long double holderh, holderl;
cin >> students >> length >> height;
area_student = students * 6;
area = height * length;
if (area_student <= area) {
cout << area << endl;
cout << length << " " << height << endl;
return 0;
}
holderh = height;
holderl = length;
while (ceil(area_student / holderh) >= length and
holderh < sqrt(area_student)) {
if (ceil(area_student / holderh) * holderh <
best_pair.first * best_pair.second) {
best_pair.first = ceil(area_student / holderh);
best_pair.second = holderh;
}
holderh++;
}
holderh = height;
holderl = length;
while (ceil(area_student / holderl) >= height and
holderl < sqrt(area_student)) {
if (ceil(area_student / holderl) * holderl <
best_pair.first * best_pair.second) {
best_pair.first = holderl;
best_pair.second = ceil(area_student / holderl);
}
holderl++;
}
cout << best_pair.first * best_pair.second << endl;
cout << best_pair.first << " " << best_pair.second << endl;
return 0;
}
| 8 | CPP |
a, b = input().split()
a = int(a)
b = int(b)
c = b - 1
n = 10 ** (a - 1)
m = 0
if b < 0 or b > 9 * a:
print('-1 -1')
elif a == 1 and b == 0 :
print('0 0')
elif b == 0 and a > 1 :
print('-1 -1')
else :
for i in range(a):
if b >= 9:
m += 9 * (10 ** (a-1-i))
if 0 < b < 9:
m += b * (10 ** (a-1-i))
b = 0
break
if b <= 0:
break
b -= 9
for i in range(a-1):
if c >= 9:
n += 9 * (10 ** i)
if 0 < c < 9:
n += c * (10 ** i)
c = 0
break
if c <= 0:
break
c -= 9
if c > 0:
n += c*(10**(a-1))
print(n,m)
| 9 | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.