solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
n = int(input())
for i in range(n):
k, m = map(int, input().split())
if k % 2 == m % 2 and m ** 2 <= k:
print("YES")
else:
print("NO") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int vec[26][200008];
int main() {
int n, m, ans, t;
int mark[28];
memset(vec, 0, sizeof(int) * 26 * 200008);
cin >> n;
string str, cp;
cin >> cp;
vec[cp[0] - 'a'][0]++;
for (int i = 1; i < cp.length(); i++) {
for (int j = 0; j < 26; j++) vec[j][i] = vec[j][i - 1];
vec[cp[i] - 'a'][i]++;
}
cin >> m;
while (m--) {
cin >> str;
ans = 0;
t = 0;
memset(mark, 0, sizeof(int) * 28);
for (int i = 0; i < str.length(); i++) {
mark[str[i] - 'a']++;
}
for (int i = 0; i < 26; i++) {
int sn = 0;
sn = lower_bound(vec[i], vec[i] + cp.length(), mark[i]) - vec[i];
if (sn > ans) ans = sn;
}
cout << ans + 1 << endl;
}
return 0;
}
| 8 | CPP |
import math
s=input()
c=0
if(len(s)==1):
print(0)
exit(0)
for i in range(len(s)):
if(s[i]=='1'):
c=c+1
if(c==1):
x=len(s)-1
x=math.ceil(x/2)
x=int(x)
print(x)
else:
x=len(s)-1
if(x%2==0):
x=math.ceil(x/2)
x=int(x)
print(x+1)
else:
x=math.floor(x/2)
x=int(x)
print(x+1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
stack<int> st;
string s;
ios_base::sync_with_stdio(false);
cin >> s;
int n = s.size() - 1;
int cnt = 0;
int id = -1;
for (__typeof((n)) i = (0); i <= (n); i++) {
if (s[i] == '(')
st.push(i);
else if (s[i] == ')' || s[i] == '#') {
if (st.empty()) {
cout << -1 << '\n';
return 0;
}
st.pop();
if (s[i] == '#') {
id = i;
cnt++;
}
}
}
int k = st.size();
while (!st.empty()) {
if (st.top() > id) {
cout << -1 << '\n';
return 0;
}
st.pop();
}
for (__typeof((cnt - 1)) i = (1); i <= (cnt - 1); i++) cout << 1 << " ";
cout << 1 + k << '\n';
return 0;
}
| 7 | CPP |
import sys
n = int(sys.stdin.readline())
i = 0
while n > 9:
n = sum(map(int, list(str(n))))
i += 1
sys.stdout.write(str(i) + '\n')
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> addr;
string op, str, type;
int n;
int main() {
ios::sync_with_stdio(false);
cin >> n;
addr.clear();
addr["void"] = 0;
while (n--) {
cin >> op >> str;
if (op[4] == 'd') {
cin >> type;
int d = 0;
string tmp = "";
for (int k = 0; k < str.length(); ++k) {
if (str[k] == '*') ++d;
if (str[k] == '&') --d;
if (str[k] != '*' && str[k] != '&') tmp += str[k];
}
if (addr.count(tmp) && addr[tmp] >= 0) {
d += addr[tmp];
addr[type] = d >= 0 ? d : -1;
} else
addr[type] = -1;
} else {
int d = 0;
string tmp = "";
for (int k = 0; k < str.length(); ++k) {
if (str[k] == '*') ++d;
if (str[k] == '&') --d;
if (str[k] != '*' && str[k] != '&') tmp += str[k];
}
if (addr.count(tmp) && addr[tmp] >= 0) {
d += addr[tmp];
if (d >= 0) {
cout << "void";
for (int k = 1; k <= d; ++k) cout << "*";
cout << endl;
} else
cout << "errtype" << endl;
} else
cout << "errtype" << endl;
}
}
return 0;
}
| 10 | CPP |
n = int(input())
s, k = 0, n // 2
a, b, c = k - 1, k + 1, n - 1
for i in range(k):
t = tuple(map(int, input().split()))
s += t[i] + t[k] + t[c - i]
s += sum(map(int, input().split()))
for i in range(k):
t = tuple(map(int, input().split()))
s += t[b + i] + t[k] + t[a - i]
print(s) | 7 | PYTHON3 |
t = int(input())
for i in range(t):
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_min = min(A)
B_min = min(B)
diff_A = [(A[j]-A_min) for j in range(n)]
diff_B = [(B[j]-B_min) for j in range(n)]
moves = 0
for j in range(n):
moves+= max(diff_A[j], diff_B[j])
print(moves)
| 8 | PYTHON3 |
#include <iostream>
using namespace std;
int n, d, x, a;
int main() {
cin>>n>>d>>x;
while(n--) {
cin>>a;
x += (d-1)/a + 1;
}
cout<<x;
return 0;
} | 0 | CPP |
a = int(input())
mat = [int(j) for j in input().split()]
m = int(input())
for i in range(m):
c, n = map(int, input().split())
if c != 1 and c != a:
mat[c-2] += n-1
mat[c] += mat[c-1] - n
mat[c-1] = 0
elif c == 1 and c != a:
mat[c] += mat[c-1] - n
mat[c-1] = 0
elif c == a and c != 0:
mat[c-2] += n-1
mat[c-1] = 0
else:
mat[c-1] = 0
for i in range(a):
print(mat[i])
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
inline void coutt(int a) {
if (a < 0) {
putchar('-');
a = -a;
}
if (a >= 10) {
coutt(a / 10);
}
putchar(a % 10 + '0');
}
int main() {
int n;
scanf("%d", &n);
priority_queue<int> q;
int currsz = n;
printf("1 ");
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
q.push(x);
while (q.top() == currsz) {
q.pop();
currsz--;
}
coutt(q.size() + 1);
printf(" ");
}
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string q;
cin >> n;
cin >> q;
vector<int> ind;
bool ch[26];
for (__typeof(26) i = 0; i < 26; i++) ch[i] = false;
ind.push_back(0);
ch[q[0] - 'a'] = true;
for (int i = 1; i < q.length() && ind.size() < n; i++) {
if (ch[q[i] - 'a'] == false) {
ch[q[i] - 'a'] = true;
ind.push_back(i);
}
}
if (ind.size() != n) {
cout << "NO\n";
return 0;
}
cout << "YES\n";
for (int i = 0; i < n - 1; i++) {
cout << q.substr(ind[i], ind[i + 1] - ind[i]) << "\n";
}
cout << q.substr(ind[n - 1], q.length() - ind[n - 1]) << endl;
return 0;
}
| 7 | CPP |
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))
n = ri()
a = rli()
b = []
if(n%2 == 1):
for i in range(0,n,2)[::-1]:
b.append(a[i])
for i in range(1,n,2):
b.append(a[i])
else:
for i in range(1,n+1,2)[::-1]:
b.append(a[i])
for i in range(0,n,2):
b.append(a[i])
print(" ".join(list(map(str, b))))
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1111111;
long long lx[N], rx[N], left[N];
long long n, x;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
vector<pair<long long, long long> > v;
cin >> n >> x;
bool sorted = true;
long long py = -1;
fill(lx, lx + N, 1e9);
for (long long i = (1); i <= (n); i++) {
long long y;
cin >> y;
lx[y] = min(lx[y], i);
rx[y] = max(rx[y], i);
if (y < py) {
sorted = false;
}
py = y;
v.push_back(make_pair(y, i));
}
for (long long y = (x); y >= (1); y--) {
lx[y] = min(lx[y], lx[y + 1]);
}
for (long long y = (1); y <= (x); y++) {
rx[y] = max(rx[y], rx[y - 1]);
}
if (sorted) {
cout << x * (x + 1) / 2 << "\n";
return 0;
}
sort(v.begin(), v.end());
long long l = 1, r = x, pos = -1;
for (auto p : v) {
l = p.first;
if (p.second < pos) break;
pos = p.second;
}
pos = n;
for (long long i = ((long long)(v).size() - 1); i >= (0); i--) {
r = v[i].first;
if (v[i].second > pos) break;
pos = v[i].second;
}
long long ans = 0;
for (long long bottom = (1); bottom <= (l); bottom++) {
long long right = rx[bottom - 1];
long long lo = r, hi = x;
while (lo < hi) {
long long mid = lo + (hi - lo) / 2;
if (lx[mid + 1] < right) {
lo = mid + 1;
} else {
hi = mid;
}
}
ans += x - lo + 1;
}
cout << ans << "\n";
return 0;
}
| 11 | CPP |
import sys
from collections import defaultdict
input = lambda : sys.stdin.readline().strip()
write = lambda x: sys.stdout.write(x)
n = int(input())
arr = sorted([(j, i + 1) for i, j in enumerate(map(int, input().split()))])
if n <= 3:
print(arr[0][1])
exit()
a1, a2, a3 = arr[0][0], arr[1][0], arr[2][0]
c1, c2, c3 = a3 - a2, a3 - a1, a2 - a1
flag = True
x = a2
for i in range(n):
if i == 0:
continue
if arr[i][0] != x:
flag = False
break
else:
x += c1
if flag:
print(arr[0][1])
exit()
flag = True
x = a1
for i in range(n):
if i == 1:
continue
if arr[i][0] != x:
flag = False
break
else:
x += c2
if flag:
print(arr[1][1])
exit()
flag = []
x = a1
for i in range(n):
if arr[i][0] != x:
flag.append(arr[i])
else:
x += c3
if len(flag) >= 2:
print(-1)
else:
print(flag[0][1]) | 10 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int many;
int t[300010];
int give;
int main() {
cin >> many;
for (int i = 1; i <= many; i++) cin >> t[i];
for (int i = many; i > 1; i--)
if (t[i] != t[1]) {
give = max(give, i - 1);
break;
}
for (int i = 1; i < many; i++)
if (t[i] != t[many]) {
give = max(give, many - i);
break;
}
cout << give;
return 0;
}
| 7 | CPP |
for i in range(int(input())):
a,b,c,d=map(int,input().split())
e=a-c-1
f=b-d-1
l=[c*b,d*a,e*b,f*a]
l.sort()
if c==0 and d==0 and b-1==0:
print((a-1)*b)
continue
if c==0 and d==0 and a-1==0:
print((b-1)*a)
continue
print(l[3]) | 7 | PYTHON3 |
def dividir(cadena):
if(len(cadena) % 2 == 1):
return cadena
a1 = dividir(cadena[ :len(cadena)//2])
a2 = dividir(cadena[len(cadena)//2: ])
if(a1 > a2):
return a2 + a1
else:
return a1 + a2;
def main():
a = input()
b = input()
respuesta = "NO"
if(a == b):
respuesta = "YES"
elif(dividir(a) == dividir(b)):
respuesta = "YES"
print(respuesta)
if __name__ == "__main__":
main() | 8 | PYTHON3 |
n,c,k = map(int,input().split())
t = sorted([int(input()) for i in range(n)])
ans = 0
j = 1
rimit = 0
for i in t:
if j<c and rimit>=i:
j+=1
else:
ans+=1
rimit=i+k
j=1
print(ans) | 0 | PYTHON3 |
n = int(input())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
a = sum(x)
b = sum(y)
if a >= b:
print('Yes')
exit()
if b > a:
print('No')
exit() | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long int n, m, kd[4 * ((int)1e5 + 5)], color[4 * ((int)1e5 + 5)],
lazy[4 * ((int)1e5 + 5)], c, x, y, v;
void init(long long int root, long long int bas, long long int son) {
if (bas == son) {
kd[root] = bas;
return;
}
init((root << 1), bas, ((bas + son) >> 1));
init(((root << 1) | 1), ((bas + son) >> 1) + 1, son);
}
long long int query(long long int root, long long int bas, long long int son,
long long int x, long long int y) {
if (son < x or y < bas) return 0;
if (x <= bas and son <= y) return color[root] + lazy[root] * (son - bas + 1);
if (kd[root]) {
lazy[(root << 1)] += lazy[root];
lazy[((root << 1) | 1)] += lazy[root];
kd[(root << 1)] = kd[root];
kd[((root << 1) | 1)] = kd[root];
lazy[root] = kd[root] = 0;
}
long long int ret =
query((root << 1), bas, ((bas + son) >> 1), x, y) +
query(((root << 1) | 1), ((bas + son) >> 1) + 1, son, x, y);
color[root] = color[(root << 1)] + color[((root << 1) | 1)] +
lazy[(root << 1)] * (((bas + son) >> 1) - bas + 1) +
lazy[((root << 1) | 1)] * (son - (((bas + son) >> 1) + 1) + 1);
if (kd[(root << 1)] == kd[((root << 1) | 1)] and kd[(root << 1)])
kd[root] = kd[(root << 1)];
return ret;
}
long long int update(long long int root, long long int bas, long long int son,
long long int x, long long int y, long long int v) {
if (son < x or y < bas) return color[root] + lazy[root] * (son - bas + 1);
if (x <= bas and son <= y and kd[root]) {
lazy[root] += abs(kd[root] - v);
kd[root] = v;
return color[root] + lazy[root] * (son - bas + 1);
}
if (kd[root]) {
lazy[(root << 1)] += lazy[root];
lazy[((root << 1) | 1)] += lazy[root];
kd[(root << 1)] = kd[root];
kd[((root << 1) | 1)] = kd[root];
lazy[root] = kd[root] = 0;
}
color[root] = update((root << 1), bas, ((bas + son) >> 1), x, y, v) +
update(((root << 1) | 1), ((bas + son) >> 1) + 1, son, x, y, v);
if (kd[(root << 1)] == kd[((root << 1) | 1)] and kd[(root << 1)])
kd[root] = kd[(root << 1)];
return color[root];
}
int main() {
cin >> n >> m;
init(1, 1, n);
for (int i = 1; i <= m; i++) {
cin >> c >> x >> y;
if (c == 1) {
cin >> v;
update(1, 1, n, x, y, v);
} else
cout << query(1, 1, n, x, y) << '\n';
}
return 0;
}
| 11 | CPP |
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
const int N = 103;
int n, m, k, nowx, nowy, ans[N][N];
int main(){
scanf("%d%d%d", &n, &m, &k); nowx = nowy = 1;
for(Rint i = 1;i <= k;i ++){
int x; scanf("%d", &x);
while(x --){
ans[nowx][nowy] = i;
if((nowx & 1) && nowy == m || !(nowx & 1) && nowy == 1) ++ nowx;
else if(nowx & 1) ++ nowy;
else -- nowy;
}
}
for(Rint i = 1;i <= n;i ++){
for(Rint j = 1;j <= m;j ++)
printf("%d ", ans[i][j]);
putchar('\n');
}
} | 0 | CPP |
a = int(input().strip())
b = input().strip().split()
b = [int(i) for i in b]
c = int(input().strip())
d = input().strip().split()
d = [int(i) for i in d]
k=[]
for i in b:
for j in d:
if j%i ==0:
k.append(j/i)
a=max(k)
c=0
for i in k:
if i==a:
c=c+1
print(c) | 7 | PYTHON3 |
num = int(float(input()))
words = []
for i in range(num):
words.append(str(input()))
if len(words[i]) > 10:
words[i] = words[i][0] + str(len(words[i]) - 2) + str(words[i][len(words[i])-1])
else:
pass
for j in range(len(words)):
print(words[j])
| 7 | PYTHON3 |
n = int(input())
lis = [list(map(int,input().split())) for i in range(n)]
cnt = 0
for i in range(n-1,-1,-1):
cnt += -(lis[i][0] + cnt)%lis[i][1]
print(cnt) | 0 | PYTHON3 |
import sys
input = sys.stdin.readline
def int_array():
return list(map(int, input().split()))
n, m = int_array(); a = int_array(); b = int_array();
for i in range(m):
b[i] = (b[i], i);
a.sort(); b.sort();
i = j = 0; ans = [];
while(i < n and j < m):
if a[i] <= b[j][0]:
i +=1;
else:
ans.append((b[j][1], i));
j += 1;
while (len(ans) < m):
ans.append((b[j][1], i));
j += 1;
ans.sort(); answer = [ans[i][1] for i in range(m)];
print(*answer) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int n, lim, a[N], mn[N], mx[N], suf[N];
long long ans;
int main() {
scanf("%d%d", &n, &lim);
for (int i = 1; i <= lim; i++) mn[i] = n + 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
mn[a[i]] = min(mn[a[i]], i);
mx[a[i]] = max(mx[a[i]], i);
}
int L = lim, R = 1, pre = mx[1];
for (int i = 1; i < lim; i++) {
pre = max(pre, mx[i]);
if (pre > mn[i + 1]) {
L = i;
break;
}
}
if (L == lim) {
cout << 1ll * lim * (lim + 1) / 2;
return 0;
}
pre = mn[lim];
for (int i = lim; i > 1; i--) {
pre = min(pre, mn[i]);
if (mx[i - 1] > pre) {
R = i;
break;
}
}
ans = lim - R + 2;
suf[lim] = mn[lim];
for (int i = lim - 1; i >= R; i--) suf[i] = min(suf[i + 1], mn[i]);
pre = mx[1];
for (int i = 1, j = R; i <= L; i++) {
pre = max(pre, mx[i]);
if (j <= i) j = i + 1;
while (j <= lim && pre > suf[j]) j++;
ans += lim - j + 2;
if (j == i + 1) ans--;
}
cout << ans;
}
| 11 | CPP |
string = input()
names = ["Danil", "Olya", "Slava", "Ann", "Nikita"]
number = 0
for name in names:
number += string.count(name)
if number == 1:
print("YES")
else:
print("NO")
| 7 | PYTHON3 |
t = int(input())
for _ in range(t):
n = int(input())
if n == 1:
print(-1)
elif n == 2:
print(57)
else:
tot = 3 + (n-1)*2
r = ''
if (tot % 3) == 0:
for _ in range(n-2):
r += '2'
r += '33'
else:
for _ in range(n-1):
r += '2'
r += '3'
print(r) | 7 | PYTHON3 |
n,k=map(int,input().split())
ans=0
while(n//(k**ans)>0):
ans+=1
print(ans) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long n, r[50005][6];
int main() {
long long t;
cin >> t;
while (t--) {
cin >> n;
for (long long i = 0; i < n; i++) {
for (long long j = 0; j < 5; j++) {
cin >> r[i][j];
}
}
long long ans = 0, x;
for (long long i = 1; i < n; i++) {
x = 0;
for (long long j = 0; j < 5; j++) {
if (r[i][j] < r[ans][j]) x++;
}
if (x > 2) ans = i;
}
for (long long i = 0; i < n; i++) {
x = 0;
if (i == ans) continue;
for (long long j = 0; j < 5; j++) {
if (r[i][j] < r[ans][j]) x++;
}
if (x > 2) {
ans = -2;
break;
}
}
cout << ans + 1 << endl;
}
return 0;
}
| 8 | CPP |
import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations
def eprint(*args):
print(*args, file=sys.stderr)
zz=1
#sys.setrecursionlimit(10**6)
if zz:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('all.txt','w')
def li():
return [int(x) for x in input().split()]
def gi():
return [x for x in input().split()]
def fi():
return int(input())
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
def gh():
sys.stdout.flush()
def graph(n,m):
for i in range(m):
x,y=mi()
a[x].append(y)
a[y].append(x)
def bo(i):
return ord(i)-ord('a')
t=1
def cnt(a,l):
#perm = permutations(a)
cc=0
dif=[0 for i in range(n+1)]
for i in range(n):
start=max(0,a[i]-l)
if a[i]-l>=n:
return 0
dif[start]+=1
dif[n]-=1
for i in range(1,n+1):
dif[i]+=dif[i-1]
ans=1
c=0
for i in range(n):
if dif[i]-c<0:
return 0
ans=(ans*(dif[i]-c)%p)%p
ans%=p
c+=1
return ans
while t>0:
t-=1
n,p=mi()
#If x>max(a) no solution
#So traverse from 0 to max(a)
a=li()
a.sort()
#dif=[0]
#for i in range(1,n):
# dif.append(a[i]-a[i-1])
#print(dif)
d=[]
dd=[]
for i in range(min(a),max(a)):
c=cnt(a,i)
#kk=cntz(a,i)
if c%p:
d.append(i)
print(len(d))
print(*d)
#print(len(dd))
#print(*dd)
| 11 | PYTHON3 |
n, x, y = map(int, input().split())
a = [int(d) for d in input().split()]
if x > y:
print(n)
else:
vypilivaemye = 0
for d in a:
if d <= x:
vypilivaemye += 1
print((vypilivaemye + 1) // 2) | 9 | PYTHON3 |
from sys import stdout, stdin
_input, _print = stdin.buffer.readline, stdout.write
_range, _int = range, int
def solution():
for _ in _range(_int(_input())):
n = _int(_input())
n += 1
e = [_int(i) for i in _input().split()]
keys = [0]*n
for i in e:
keys[i] += 1
ans = 0
b = 0
for i in _range(n):
if keys[i] != 0:
ans += (keys[i] + b) // i
b = (keys[i] + b) % i
print(ans)
solution()
| 8 | PYTHON3 |
def gcd(a,b):
while b: a, b = b, a%b
return a
t, w, s = [int(v) for v in input().split()]
com = gcd(w,s)
lcm = w*s//com
#print(com, lcm)
n = t//lcm
num = (n+1) * min(w,s) - 1
end = n*lcm+min(w,s)-1
if end > t:
num -= end-t
#print(end, 'is larger than', t)
g = gcd(num, t)
print("%d/%d" % (num//g, t//g))
| 9 | PYTHON3 |
def non_zero_check(lst):
l = len(lst)
count = 0
for i in lst:
if i == 0:
count += 1
if count == l:
return True
else:
return False
try:
nk = input()
numbers = input()
count = 0
temp = nk.split(" ")
n = int(temp[0])
k = int(temp[1])
temp = numbers.split(" ")
numbers = []
for i in temp:
numbers.append(int(i))
if(non_zero_check(numbers)):
print("0")
#raise SystemExit(0)
else:
k = numbers[k-1]
for i in numbers:
if i != 0 and i >= k:
count += 1
print(count)
except Exception as e:
print(e)
| 7 | PYTHON3 |
in1 = input().split()
in1 = list(map(int ,in1))
in2 = input()
n = len(in2)
li = list(in2)
cal = 0
for i in range(n):
if li[i] == '1':
cal = cal + in1[0]
elif li[i] == '2':
cal = cal + in1[1]
elif li[i] == '3':
cal = cal + in1[2]
else:
cal =cal + in1[3]
print(cal)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
int t[1000005];
char str[1000005];
int main(void) {
while (~scanf("%s", str)) {
int len = strlen(str), cnt = 0, i, pos = 0;
for (i = 0; i < len; i++) {
if (str[i] == 'F') {
cnt++;
t[cnt] = (i + 1) - cnt;
if (cnt == 2) {
pos = i;
}
}
}
if (cnt == 0) {
puts("0");
continue;
} else if (cnt == 1) {
printf("%d\n", t[1]);
continue;
}
int cur = 2;
for (i = pos; i < len; i++) {
if (str[i] == 'M') {
continue;
}
if (t[cur] == 0) {
cur++;
continue;
}
if (t[cur] <= t[cur - 1]) {
t[cur] = t[cur - 1] + 1;
}
cur++;
}
printf("%d\n", t[cnt]);
}
return 0;
}
| 10 | CPP |
text = input()
if text == text.upper():
print(text.lower())
elif text == text[0].lower() + text[1:].upper():
print(text[0].upper() + text[1:].lower())
else:
print(text) | 7 | PYTHON3 |
n = int(input())
a = list(map(int, input().split()))
inc_seq = []
last = 0
for i in range(len(a)):
if i == 0 or a[i] > a[i - 1]:
continue
else:
inc_seq.append((last, i - 1, a[i - 1]))
last = i
inc_seq.append((last, len(a)-1, a[-1]))
maxList = list(map(lambda x: x[1] - x[0] + 1, inc_seq))
i = 0
j = 1
while j < len(inc_seq):
try:
if (inc_seq[i][1] + 1 == inc_seq[j][0]) and (a[inc_seq[i][1] - 1]< a[inc_seq[j][0]]):
maxList.append(inc_seq[j][1] - inc_seq[i][0])
elif (inc_seq[i][1] + 1 == inc_seq[j][0]) and (a[inc_seq[i][1]]< a[inc_seq[j][0] + 1]):
maxList.append(inc_seq[j][1] - inc_seq[i][0])
except:
pass
i += 1
j += 1
print(max(maxList))
| 10 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 1e5 + 5, M = N;
void solve() {
long long n, m, t;
scanf("%lld %lld", &n, &t);
long long ar[n], res[n];
map<long long, long long> cnt;
map<long long, long long> color;
for (int i = 0; i < n; i++) {
scanf("%lld", &ar[i]);
cnt[ar[i]]++;
color[ar[i]] = 1;
}
for (int i = 0; i < n; i++) {
long long u = ar[i], v = t - ar[i];
if (cnt[u] > 0 && cnt[v] > 0) {
if (u == v && cnt[u] > 1) {
cnt[u]--;
res[i] = color[u];
if (color[u] == 1)
color[u] = 0;
else
color[u] = 1;
} else
res[i] = color[u], cnt[u] = 0;
if (u != v) {
cnt[u]--;
res[i] = color[u];
cnt[v]--;
if (color[u] == 1)
color[v] = 0;
else
color[u] = 1;
}
} else
res[i] = color[u];
}
for (int i = 0; i < n; i++) printf("%lld ", res[i]);
printf("\n");
}
int main() {
int t = 1;
scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
| 8 | CPP |
n=int(input())
a=list(map(int,input().split()))
coins = sum(a)
a.sort(reverse=True)
count =0
mine = 0
for i in a:
if mine>coins/2:
break
mine += i
count += 1
print(count) | 7 | PYTHON3 |
N = int(input())
rec = []
ma = 0
for i in range(N):
M = list(map(int, input().split()))
rec.append((M[1:]))
ma = max(ma, max(M[1:]))
num = 0
for i in range(N):
m = max(rec[i])
num += (ma - m) * len(rec[i])
print(num) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct data {
char s[55], t[55];
} d2[N], d[N];
char p[55];
int main() {
int n;
while (cin >> n) {
for (int i = 1; i <= n; i++) {
scanf("%s%s", d2[i].s, d2[i].t);
if (strcmp(d2[i].s, d2[i].t) > 0) {
strcpy(p, d2[i].s);
strcpy(d2[i].s, d2[i].t);
strcpy(d2[i].t, p);
}
}
int tn;
for (int i = 1; i <= n; i++) {
scanf("%d", &tn);
d[i] = d2[tn];
}
strcpy(p, d[1].s);
for (int i = 2; i <= n; i++) {
if (strcmp(d[i].s, p) > 0)
strcpy(p, d[i].s);
else if (strcmp(d[i].t, p) > 0)
strcpy(p, d[i].t);
else {
cout << "NO";
return 0;
}
}
cout << "YES";
}
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
double x, y;
cin >> x >> y;
int n;
double min_time;
cin >> n;
for (int i = 0; i < n; ++i) {
double first, second;
cin >> first >> second;
double distance =
sqrt((x - first) * (x - first) + (y - second) * (y - second));
double v;
cin >> v;
double time = (double)distance / (double)v;
if (i == 0) {
min_time = time;
continue;
}
if (time < min_time) min_time = time;
}
cout.precision(18);
cout << min_time << endl;
return 0;
}
| 7 | CPP |
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
vector<int> G[100000];
bool visited[100000][2],vis[100000];
int cnt=0,a[100000],b[100000];
typedef vector<int> vi;
vector<vi> group(100000);
void dfs(int v,int x){
visited[v][x]=true;
rep(i,G[v].size()){
if(visited[G[v][i]][1-x]) continue;
dfs(G[v][i],1-x);
}
}
void dfs2(int v){
group[cnt].pb(v);
vis[v]=true;
rep(i,G[v].size()){
if(vis[G[v][i]]) continue;
dfs2(G[v][i]);
}
}
int cnta[100001];
vector<int> vca,vcm;
int dp[100001];
int main(){
int V,E;
cin>>V>>E;
rep(i,E){
int a,b;
scanf("%d%d",&a,&b);
G[a-1].pb(b-1);
G[b-1].pb(a-1);
}
rep(i,V) if(!(visited[i][0]||visited[i][1])) dfs(i,0);
rep(i,V) if(visited[i][0]&&visited[i][1]){
printf("-1\n");
return 0;
}
rep(i,V) if(!vis[i]) dfs2(i),cnt++;
int ssum=0;
rep(i,cnt){
rep(j,group[i].size()){
if(visited[group[i][j]][0]) a[i]++;
else b[i]++;
}
if(a[i]<b[i]) swap(a[i],b[i]);
ssum+=b[i];
// cout<<a[i]<<" "<<b[i]<<endl;
}
rep(i,cnt) cnta[a[i]-b[i]]++;
rep1(i,100000) if(cnta[i]>0){
vca.pb(i);
vcm.pb(cnta[i]);
}
int n=vca.size();
rep(i,100001) dp[i]=-1;
dp[0]=0;
rep(i,n){
rep(j,100001){
if(dp[j]>=0){
dp[j]=vcm[i];
}else if(j<vca[i]||dp[j-vca[i]]<=0){
dp[j]=-1;
}else{
dp[j]=dp[j-vca[i]]-1;
}
}
}
long long ans=0;
rep(i,100001) if(dp[i]>=0){
long long si=ssum+i;
ans=max(ans,si*(V-si));
}
cout<<ans-E<<endl;
} | 0 | CPP |
#include <bits/stdc++.h>
int main() {
int a, b;
while (scanf("%d%d", &a, &b) == 2) {
if (((a) < (b) ? (a) : (b)) & 1)
printf("Akshat\n");
else
printf("Malvika\n");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int v[100010];
int v2[100010];
int main() {
int n;
while (~scanf("%d", &n)) {
int sz = 0, sz2 = 0;
v[0] = v2[0] = -1;
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
}
sort(a, a + n);
for (int i = 0; i < n; ++i) {
if (a[i] > v[sz]) {
v[++sz] = a[i];
} else if (a[i] > v2[sz2]) {
v2[++sz2] = a[i];
}
}
if (v[sz] == v2[sz2]) {
sz2--;
}
printf("%d\n", sz + sz2);
for (int i = 1; i <= sz; ++i) {
if (i > 1) printf(" ");
printf("%d", v[i]);
}
for (int i = sz2; i >= 1; --i) {
printf(" %d", v2[i]);
}
puts("");
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+55;
const int M=155;
int dp[N];
int a[N];
int main()
{
int n,k;
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>a[i];
dp[0]=1;
for(int i=1;i<=k;i++)
{
dp[i]=1;
for(int j=0;j<n;j++)
{
if(a[j]<=i)
dp[i]&=dp[i-a[j]]^1;
}
}
if(dp[k])
cout<<"Second\n";
else
cout<<"First\n";
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int sum = 0;
int a, b;
cin >> a >> b;
int c = a * a;
int k[a][a];
if (b == 1) {
int n = 1;
for (int i = 0; i < a; i++) {
for (int j = 0; j < a; j++) {
if (j == 0) sum += n;
k[i][j] = n;
n++;
}
}
cout << sum << endl;
for (int i = 0; i < a; i++) {
for (int j = 0; j < a; j++) {
cout << k[i][j] << " ";
}
cout << endl;
}
} else {
for (int i = 0; i < a; i++) {
for (int j = a - 1; j >= b - 1; j--) {
if (j == b - 1) sum += c;
k[i][j] = c--;
}
}
int n = 1;
for (int i = a - 1; i >= 0; i--) {
for (int j = 0; j < b - 1; j++) {
k[i][j] = n;
n++;
}
}
cout << sum << endl;
for (int i = 0; i < a; i++) {
for (int j = 0; j < a; j++) {
cout << k[i][j] << " ";
}
cout << endl;
}
}
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int getInt() {
int x;
scanf("%d", &x);
return x;
}
long long getLongLong() {
long long x;
scanf("%I64d", &x);
return x;
}
double getDouble() {
double x;
scanf("%lf", &x);
return x;
}
char getChar() {
char x;
scanf("%c", &x);
return x;
}
template <typename t>
t abs(t a) {
if (a >= 0) return a;
return -a;
}
vector<string> split(const string& s, char c) {
vector<string> v;
stringstream second(s);
string x;
while (getline(second, x, c)) v.emplace_back(x);
return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " ";
err(++it, args...);
}
void FastIO() {
ios::sync_with_stdio(0);
cin.tie(0);
}
const int Max = 2000010;
int ids[Max] = {0};
int n;
vector<int> a;
int main() {
n = getInt();
int x;
for (int i = 0; i < n; i++) {
x = getInt();
ids[x] = x;
}
for (int i = 1; i < Max; i++) {
if (ids[i] == i && i > 1) a.push_back(i);
ids[i] = max(ids[i], ids[i - 1]);
}
int ans = 0;
for (int i = 0; i < a.size(); i++) {
int up = a[i], prv = up, num;
for (int j = up + up - 1; j < Max; j += up) {
ans = max(ans, ids[j] - prv);
prv += up;
}
}
cout << ans << endl;
return 0;
}
| 8 | CPP |
for i in range(5):
a=input().split()
for j in range(5):
if a[j]=='1':
ans=abs(i-2)+abs(j-2)
print (ans) | 7 | PYTHON3 |
#include <bits/stdc++.h>
std::mt19937 rgn(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
namespace io {
template <typename T>
inline void read(T& a) {
int c = getchar(), sign = 0;
a = 0;
while (c < '0' || c > '9') sign += (c == '-'), c = getchar();
while (c >= '0' && c <= '9') a = (a << 1) + (a << 3) + c - 48, c = getchar();
if (sign & 1) a = -a;
}
template <typename T, typename... _T>
inline void read(T& a, _T&... argc) {
read(a);
read(argc...);
}
template <typename T>
inline void Write(T a) {
if (a > 9) Write(a / 10);
putchar(a % 10 + '0');
}
template <typename T>
inline void write(T a, char ch = ' ') {
if (a < 0) putchar('-'), a = -a;
Write(a);
putchar(ch);
}
template <typename T>
inline void Min(T& a, T b) {
if (a > b) a = b;
}
template <typename T>
inline void Max(T& a, T b) {
if (a < b) a = b;
}
template <typename T, typename... _T>
inline void Min(T& a, T b, _T... c) {
Min(a, b);
Min(a, c...);
}
template <typename T, typename... _T>
inline void Max(T& a, T b, _T... c) {
Max(a, b);
Max(a, c...);
}
} // namespace io
using namespace io;
const int maxn = 1e6 + 3;
const int N = 4e5 + 3;
const int mod = 1e9 + 7;
int n, m, q;
int dem[N], id[N], chot[N], a[N], b[N];
int k, h;
long long t[N + 3];
string s;
bool kt[N];
map<long long, int> maps;
vector<int> edge[N];
map<int, int>::iterator it;
template <typename T>
void answer(T x) {
cout << x;
exit(0);
}
void putstring(string x, char ch = ' ') {
for (char c : x) putchar(c);
putchar(ch);
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
int n;
cin >> n;
vector<long long> a(n);
long long sum = 0;
for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];
sum -= 1ll * n * (n - 1) / 2;
for (int pos = 2; pos <= n + 1; pos++) {
if ((sum + n - pos + 1) % n == 0) {
long long f = (sum + n - pos + 1) / n;
for (int i = 1; i < pos; i++) a[i] = f++;
f--;
for (int i = pos; i <= n; i++) a[i] = f++;
for (int i = 1; i <= n; i++) cout << a[i] << " ";
cout << "\n";
return 0;
}
}
assert(false);
}
| 12 | CPP |
for _ in range(int(input())):
s = input()
count,cnt = 0,0
even = 0
for i in s:
if i=='0':
cnt += 1
else:
if int(i)%2==0:
even =1
count+=int(i)
if count%3==0 and cnt>=1 and (even==1 or cnt>=2):
print("red")
elif cnt==len(s):
print("red")
else:
print("cyan")
| 7 | PYTHON3 |
for _ in range(int(input())):
h,m = map(int,input().split())
tot = 24*60
h1 = h*60+m
print(tot-h1) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vec(n);
for (int i = 0; i < n; ++i) cin >> vec[i];
int sum = accumulate(vec.begin(), vec.end(), 0);
if ((sum / 100) % 2 != 0) {
cout << "NO\n";
return 0;
}
sum /= 2;
int num_one = count(vec.begin(), vec.end(), 100);
int num_two = count(vec.begin(), vec.end(), 200);
int curr = 0;
while (curr <= sum && num_two > 0) {
curr += 200;
num_two--;
}
if (curr == sum) {
cout << "YES\n";
return 0;
}
if (curr > sum) curr -= 200;
while (curr != sum && num_one > 0) {
curr += 100;
num_one--;
}
if (curr == sum)
cout << "YES\n";
else
cout << "NO\n";
}
| 7 | CPP |
#include <bits/stdc++.h>
#define pa pair<int,int>
using namespace std;
priority_queue<pa> qwq;
int a[200005],b[200005],N;
int main(){
scanf("%d",&N);
long long ans=0;
for (int i=1;i<=N;i++)
scanf("%d",&b[i]);
for (int i=1;i<=N;i++){
scanf("%d",&a[i]);
qwq.push(make_pair(a[i],i));
}
while (!qwq.empty()){
pa now=qwq.top();
qwq.pop();
if (b[now.second]>now.first) {
puts("-1");
return 0;
}
if (b[now.second]==now.first) continue;
int Ned=now.first-b[now.second];
int tmp=a[now.second-1]+a[now.second+1];
if (now.second==1) tmp+=a[N];
if (now.second==N) tmp+=a[1];
if (tmp>Ned){
printf("-1\n");
return 0;
}
int tmp1=Ned/tmp;
ans+=tmp1;
a[now.second]-=tmp1*tmp;
now.first=a[now.second];
qwq.push(now);
}
cout<<ans;
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[200005];
long long rec(long long l, long long r) {
if (r - l <= 1) {
return 0;
}
long long mid = (l + r) / 2;
long long ans = 0;
ans += rec(l, mid);
ans += rec(mid + 1, r);
set<long long> L, R;
long long maxval = 0, ptr = mid;
for (long long i = (long long)(mid); i >= (long long)(l); i--) {
maxval = max(maxval, a[i]);
while (ptr + 1 <= r && a[ptr + 1] < maxval) {
ptr++;
R.insert(a[ptr]);
}
long long x = maxval - a[i];
ans += R.count(x);
}
maxval = 0;
ptr = mid + 1;
for (long long i = (long long)(mid + 1); i <= (long long)(r); i++) {
maxval = max(maxval, a[i]);
while (ptr - 1 >= l && a[ptr - 1] < maxval) {
ptr--;
L.insert(a[ptr]);
}
long long x = maxval - a[i];
ans += L.count(x);
}
return ans;
}
int main() {
cin >> n;
for (long long i = (long long)(1); i <= (long long)(n); i++) cin >> a[i];
cout << rec(1, n);
}
| 11 | CPP |
k = int(input())
b = [int(i) for i in input().split()]
if (k == 0): print(0)
elif (k > sum(b)): print(-1)
else:
b.sort()
s = 0
c = 0
for i in range(len(b) - 1, -1, -1):
s += b[i]
c += 1
if s >= k: break
print(c) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a[62], b[62], n, m;
unsigned long long s[62][62][2];
int CNT(unsigned long long x) {
int ret = 0;
while (x) {
ret++;
x -= (x & -x);
}
return ret;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
for (int i = 1; i <= m; i++) scanf("%d", b + i);
sort(a + 1, a + n + 1);
sort(b + 1, b + m + 1);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
int y = a[i] + b[j], J = m;
for (int I = 1; I <= n && J >= 1;) {
if (y - a[I] > b[J])
I++;
else if (y - a[I] < b[J])
J--;
else {
do s[i][j][0] |= (1llu << I), I++;
while (I <= n && a[I] == a[I - 1]);
do s[i][j][1] |= (1llu << J), J--;
while (J >= 1 && b[J] == b[J + 1]);
}
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
for (int k = 1; k <= n; k++) {
for (int l = 1; l <= m; l++) {
ans = max(
ans, CNT(s[i][j][0] | s[k][l][0]) + CNT(s[i][j][1] | s[k][l][1]));
if (ans == n + m) {
printf("%d\n", ans);
return 0;
}
}
}
}
}
printf("%d\n", ans);
return 0;
}
| 11 | CPP |
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
int N;
pi a[200000+9];
int main(){
scanf("%d", &N);
for(int i=0;i<N;i++){
scanf("%d %d", &a[i].second, &a[i].first);
}
sort(a, a+N);
for(int i=0;i<N;i++){
if(i)a[i].second += a[i-1].second;
if(a[i].second > a[i].first) return printf("No"), 0;
}
printf("Yes");
return 0;
}
| 0 | CPP |
#include<bits/stdc++.h>
using namespace std;
double dp[3000][3000];
double p[3000],ans;
int main(){
int n;
cin>>n;
for (int i =1;i<=n;i++){
cin>>p[i];
}
dp[0][0]=1;
for (int i = 1;i<=n;i++){
for (int j = 0;j<=i;j++){
dp[i][j] += dp[i-1][j]* (1-p[i]);
dp[i][j+1] += dp[i-1][j]*p[i];
}
}
for (int i = n;i>n/2;i--)
ans+=dp[n][i];
cout<<setprecision(1000000) <<ans;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, q;
vector<vector<int> > v2;
bool vx2[300001];
int total = 0;
int first = 0;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n >> q;
v2.resize(n + 1);
int cnt = 0;
memset(vx2, 0, sizeof vx2);
for (int i = 0; i < q; i++) {
int a, b;
cin >> a >> b;
if (a == 1) {
total++;
v2[b].push_back(cnt);
cnt++;
} else if (a == 2) {
for (int i = 0; i < v2[b].size(); i++) {
int c = v2[b][i];
if (!vx2[c]) total--;
vx2[c] = 1;
}
v2[b].clear();
} else {
while (b > first) {
if (!vx2[first]) total--;
vx2[first] = 1;
first++;
}
}
cout << total << endl;
}
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, m;
char s1[5005], s2[5005];
int dp[5005][5005];
int main() {
scanf("%s%s", s1 + 1, s2 + 1);
n = strlen(s1 + 1);
m = strlen(s2 + 1);
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
dp[i][j] = dp[i][j - 1];
if (s1[i] == s2[j]) {
dp[i][j] += dp[i - 1][j - 1] + 1;
if (dp[i][j] >= mod) dp[i][j] -= mod;
}
}
ans += dp[i][m];
if (ans >= mod) ans -= mod;
}
printf("%d\n", ans);
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n,ans=0;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
int j=i,tmp=0;
while(j) j/=10,tmp++;
if(tmp&1) ans++;
}
printf("%d\n",ans);
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
unsigned M[16][64][16][16];
unsigned X[16], Y[16], *A, *B, *C;
int main() {
unsigned q, n, e, i, j, k;
for (int n = 0; n <= 15; n++) {
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++) M[n][0][i][j] = (i < j ? j - i : i - j) < 2;
for (int e = 1; e <= 63; e++)
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
for (int k = 0; k <= n; k++)
M[n][e][i][j] =
(M[n][e][i][j] +
M[n][e - 1][i][k] * (long long unsigned)M[n][e - 1][k][j]) %
1000000007u;
}
long long unsigned x, y, z;
*(A = X) = 1;
B = Y;
for (cin >> q >> z; q--;) {
cin >> x >> y >> n;
if (y > z) y = z;
for (x = y - x, e = 0; x; x >>= 1, ++e)
if (x & 1) {
for (int i = 0; i <= n; i++) {
B[i] = 0;
for (int j = 0; j <= n; j++)
B[i] =
(B[i] + M[n][e][i][j] * (long long unsigned)A[j]) % 1000000007u;
}
C = A;
A = B;
B = C;
}
for (int i = n + 1; i <= 15; i++) A[i] = 0;
}
cout << A[0];
}
| 11 | CPP |
n, s = int(input()), input()
r = 0
for i in range(n):
if int(s[i]) % 2 == 0:
r += (i + 1)
print(r) | 7 | PYTHON3 |
n=int(input())
s=input()
l=[]
for i in range(n-1):
str1=s[i]+s[i+1]
l.append(str1)
x=set(l)
x=list(x)
ans=[]
for i in range(len(x)):
count=l.count(x[i])
ans.append(count)
max1=max(ans)
ind=ans.index(max1)
print(x[ind]) | 8 | PYTHON3 |
import math
import sys
from heapq import heappop
from heapq import heappush
from heapq import heapify
from bisect import insort
from sys import stdin,stdout
from collections import defaultdict
inp=lambda : int(stdin.readline())
sip=lambda : input()
mulip =lambda : map(int,input().split())
lst=lambda : list(map(int,stdin.readline().split()))
slst=lambda: list(sip())
arr2d= lambda x: [[int(j) for j in input().split()] for i in range(x)]
odds = lambda l: len(list(filter(lambda x: x%2!=0, l)))
evens = lambda l: len(list(filter(lambda x: x%2==0, l)))
mod = pow(10,9)+7
#-------------------------------------------------------
for _ in range(inp()):
n, m = mulip()
if m>n:
print(0)
else:
term = n//m
d = {}
i = 1
while(m<=n):
s = str(m*i)
l = int(s[-1])
if l not in d:
d[l] = l
i += 1
else:
break
dlen = len(d)
full_nd = term//dlen
part_nd = term%dlen
full_sum = full_nd*sum(d.values())
dlist = list(d.values())
part_sum = sum(dlist[:part_nd])
print(full_sum+part_sum)
| 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
char _;
mt19937 g1(time(0));
int randint(int a, int b) { return uniform_int_distribution<int>(a, b)(g1); }
long long randlong(long long a, long long b) {
return uniform_int_distribution<long long>(a, b)(g1);
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long fpow(long long b, long long exp, long long mod) {
if (exp == 0) return 1;
long long t = fpow(b, exp / 2, mod);
if (exp & 1) return t * t % mod * b % mod;
return t * t % mod;
}
long long divmod(long long i, long long j, long long mod) {
i %= mod, j %= mod;
return i * fpow(j, mod - 2, mod) % mod;
}
int len;
long long res, tot, other;
double lst;
map<double, int> cnt;
map<pair<double, double>, int> cnt2;
vector<double> v;
vector<pair<double, double>> v2;
pair<int, int> points[1000005];
vector<int> hori, vert;
int main() {
scanf("%d", &len);
for (int i = 1; i <= len; i++)
scanf(" %d %d", &points[i].first, &points[i].second);
for (int i = 1; i <= len; i++) {
for (int k = i + 1; k <= len; k++) {
if (points[k].second == points[i].second) {
hori.push_back(points[k].second);
continue;
} else if (points[k].first == points[i].first) {
vert.push_back(points[k].first);
continue;
}
double slope = (double)(points[k].second - points[i].second) /
(points[k].first - points[i].first);
double b = (double)points[k].second - slope * points[k].first;
v.push_back(slope);
cnt[slope]++;
v2.push_back(make_pair(slope, b));
cnt2[make_pair(slope, b)]++;
}
}
sort(hori.begin(), hori.end());
hori.erase(unique(hori.begin(), hori.end()), hori.end());
sort(vert.begin(), vert.end());
vert.erase(unique(vert.begin(), vert.end()), vert.end());
res += hori.size() * vert.size();
sort(v2.begin(), v2.end());
v2.erase(unique(v2.begin(), v2.end()), v2.end());
pair<double, double> lst2 = (v2.size() ? v2[0] : make_pair(1.0, 1.0));
for (int i = 1; i < v2.size(); i++) {
if (abs(v2[i].first - lst2.first) <= 1e-9 &&
abs(v2[i].second - lst2.second) <= 1e-9) {
cnt2[lst2] += cnt2[v2[i]];
cnt2.erase(v2[i]);
} else {
lst2 = v2[i];
}
}
vector<pair<pair<double, double>, int>> ok;
for (pair<pair<double, double>, int> check : cnt2) {
ok.push_back(check);
}
for (int i = 0; i < ok.size(); i++) {
while (cnt2.size() &&
abs(cnt2.begin()->first.first - ok[i].first.first) <= 1e-9) {
cnt2.erase(cnt2.begin());
}
pair<pair<double, double>, int> &check = ok[i];
long long add = (long long)(cnt2.size() + hori.size() + vert.size());
res += add;
}
printf("%lld\n", res);
}
| 9 | CPP |
def read():
n = int(input())
a = list(map(int, input().split()))
return n, a
def solve(n: int, a: list):
b = {}
for ai in a:
c = 0
while True:
q, r = divmod(ai, 2)
if r == 0:
c += 1
ai = q
else:
old = b.get(ai) if ai in b else 0
b[ai] = max(old, c)
break
total = 0
for value in b.values():
total += value
return total
for t in range(int(input())):
result = solve(*read())
print(result) | 8 | PYTHON3 |
n=int(input())
s=input()
if ('MM' in s) or ('CC' in s) or ('YY' in s):
print('No')
else:
if (s[0]=='?') or (s[-1]=='?'):
print('Yes')
else:
if '??' in s:
print('Yes')
else:
if ('C?C' in s) or ('M?M' in s) or ('Y?Y' in s):
print('Yes')
else:
print('No')
| 7 | PYTHON3 |
da = list(map(int,input().split()))
k = [[0 for i in range(2)]for j in range(10001)]
i = 0
su = 0
j = 0
while da[0] + da[1] != 0:
i = 0
su = 0
j = 0
for i in range(da[0]):
k[i][0],k[i][1] = map(int,input().split())
k = sorted(k,key = lambda x: x[1],reverse = True)
while j != i + 1:
if da[1] > k[j][0]:
da[1] -= k[j][0]
j += 1
elif da[1] <= k[j][0] and da[1] > 0:
su += (k[j][0] - da[1]) * k[j][1]
da[1] = 0
j += 1
else:
su += k[j][0] * k[j][1]
j += 1
print(su)
da = list(map(int,input().split()))
k = [[0 for i in range(2)]for j in range(10001)]
| 0 | PYTHON3 |
import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import (
accumulate, combinations, combinations_with_replacement, groupby,
permutations, product)
from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot,
log2, pi, radians, sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits
def inp():
return(int(input()))
def inlist():
return(list(map(int, input().split())))
def instr():
s = input()
return(list(s[:len(s)]))
def invr():
return(map(int, input().split()))
def def_value():
return 0
n = inp()
a = inlist()
target = sum(a) // 2
current = 0
a = sorted(a, reverse=True)
for i in range(n):
if target >= current + a[i]:
current += a[i]
if target == current:
print("YES")
else:
print("NO")
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p, t, res;
cin >> n;
p = sqrt(n);
if (p * p < n) {
p++;
}
t = (p * p - n) / p;
res = 4 * p - 2 * t;
cout << res;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int const mod = 1e9 + 7;
int const maxn = 2005;
inline void safe_mul(int& a, int b) { a = (a * 1LL * b) % mod; }
inline int mypow(int a, int b) {
int ans = 1;
int tmp = a;
while (b) {
if (b & 1) safe_mul(ans, tmp);
safe_mul(tmp, tmp);
b >>= 1;
}
return ans;
}
inline int inv(int x) { return mypow(x, mod - 2); }
int koef[maxn];
int a[maxn];
int main() {
ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
koef[0] = 1;
for (int i = 1; i < n; ++i) {
koef[i] = koef[i - 1];
safe_mul(koef[i], (k + i - 1) * 1LL * inv(i) % mod);
}
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < n; ++i) {
int ans = 0;
for (int j = 0; j <= i; ++j) ans = (ans + koef[j] * 1LL * a[i - j]) % mod;
cout << ans << " \n"[i == n - 1];
}
return 0;
}
| 9 | CPP |
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 13 16:13:20 2021
@author: kissz
"""
import sys
def generate_testcase():
import random
with open('in.txt','w') as f:
print(1,file=f)
print(200000,200000,500000,file=f)
data=[(i,i+1,random.randint(1, 1000000)) for i in range(1,200000)]+\
[(96012,176243,random.randint(1, 1000000))]
random.shuffle(data)
for row in data: print(*row,file=f)
#@profile
def main(input_fcn=sys.stdin.readline):
for _ in range(int(input_fcn())):
#eprint('new test')
n,m,k=map(int,input_fcn().split())
#eprint(n,m,k)
roads0=[(0,0)]*m
m0=0
roads1=[(0,0,0)]*m
m1=0
for _ in range(m):
s,d,lim=map(int,input_fcn().split())
if lim>k:
roads1[m1]=(lim-k,s,d)
m1+=1
else:
roads0[m0]=(k-lim,s,d)
m0+=1
roads1=sorted(roads1[:m1])
#eprint(roads0)
#eprint(roads1)
res=0
parent=[i for i in range(n+1)]
for i in range(m0):
_,s,d=roads0[i]
ps,pd=s,d
while parent[ps]!=ps:
ps=parent[ps]
while parent[pd]!=pd:
pd=parent[pd]
if ps!=pd:
parent[s]=ps
parent[d]=ps
parent[pd]=ps
else:
parent[s]=ps
parent[d]=ps
for i in range(m1):
mod,s,d = roads1[i]
ps,pd=s,d
while parent[ps]!=ps:
ps=parent[ps]
while parent[pd]!=pd:
pd=parent[pd]
if ps!=pd:
res+=mod
parent[s]=ps
parent[d]=ps
parent[pd]=ps
else:
parent[s]=ps
parent[d]=ps
#eprint(parent)
#eprint(res)
if not res:
if roads0: corr=min(roads0[i][0] for i in range(m0))
else: corr=1e30
#eprint('corr',corr)
if roads1: corr=min(corr,roads1[0][0])
#eprint('corr',corr)
res+= int(corr)
print(res)
if __name__=='__main__':
main()
else:
def eprint(*args):
print(*args,file=sys.stderr) | 16 | PYTHON3 |
n=int(input())
l=list(map(int, input().split()))
c1,c2=0,0
for i in range(n):
if(l[i]%2==0):
c1+=1
else:
c2+=1
print(min(c1,c2)) | 7 | PYTHON3 |
for _ in range(int(input())):
s = input()
f = True#alice
ans = []
for i in s:
t = i
if f:
f= False
if i == 'a': t = 'b'
else: t = 'a'
else:
f = True
if i == 'z': t = 'y'
else: t = 'z'
ans.append(t)
print(*ans, sep='') | 7 | PYTHON3 |
for t in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
a.reverse()
print(*a) | 7 | PYTHON3 |
n=int(input())
s=[int(x) for x in input().split()]
x=0
y=0
for i in s:
x+=i
if x==-1:
x=0
y+=1
print(y)
| 7 | PYTHON3 |
n, m = map(int, input().split())
i = 1
while m >= i:
m -= i
i += 1
if i == n+1:
i = 1
print(m)
| 7 | PYTHON3 |
from sys import stdin
t = int(stdin.readline().strip())
for i in range(t):
n = int(stdin.readline().strip())
print(int((n+1)//2))
#x,y,n = list(map(int, stdin.readline().strip().split(' ')))
| 7 | PYTHON3 |
#include <iostream>
using namespace std;
int main()
{
int a,b,c,k;
cin>>a>>b>>c>>k;
for(int i=0;i<k;i++)
{
if(a>=b)
b*=2;
else if(b>=c)
c*=2;
}
if(a<b&&b<c) cout<<"Yes";
else cout<<"No";
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int a[105];
while (cin >> n) {
int flag = 0;
memset(a, 0, sizeof(a));
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int x, y;
cin >> x >> y;
int sum = 0;
int sum2, pl = 0;
for (int i = 1; i <= n; i++) {
sum += a[i];
if (sum > y) {
flag = 3;
break;
} else if (sum >= x) {
sum2 = 0;
for (int j = i + 1; j <= n; j++) {
sum2 += a[j];
}
if (sum2 >= x && sum2 <= y) {
flag = 1;
pl = i + 1;
break;
} else if (sum2 < x) {
flag = 3;
break;
}
}
}
cout << pl << endl;
}
return 0;
}
| 7 | CPP |
n = int(input())
a = list(map(int, input().split()))
if n == 1:
print(a[0])
elif n == 2:
print(a[1] + (a[1]-a[0]))
else:
f = True
d = a[1]-a[0]
for i in range(1, n):
if (a[i] - a[i-1] != d):
f = False
if f:
print(a[-1]+d)
else:
print(a[-1]) | 20 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005, M = 205;
int n, m, fail[M];
char a[N][M], b[M][N];
int f[M][N];
void get_fail(int r) {
for (int i = 2, j = 0; i <= m; ++i) {
while (j > 0 && a[r][i] != a[r][j + 1]) j = fail[j];
if (a[r][i] == a[r][j + 1]) j++;
fail[i] = j;
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) scanf("%s", a[i] + 1);
for (int i = 1; i <= m; ++i) scanf("%s", b[i] + 1);
for (int k = 1; k <= n - m + 1; ++k) {
for (int l = 1; l <= m; ++l) {
get_fail(k + l - 1);
for (int i = 1, j = 0; i <= n; i++) {
while (j > 0 && b[l][i] != a[k + l - 1][j + 1]) j = fail[j];
if (b[l][i] == a[k + l - 1][j + 1]) j++;
if (j == m) {
f[l][i] = f[l - 1][i] + 1;
if (f[l][i] == m) {
printf("%d %d\n", k, i - m + 1);
return 0;
}
} else
f[l][i] = 0;
}
}
}
return 0;
}
| 7 | CPP |
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
if n % 2 == 0:
print('0')
else:
print(min(m // (n // 2 + 1) * k, min(a[::2])))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, T, tmp[20];
long long vl, fir, sec, up, ex[20], dp[2][20], g[20], bi[20], gi[20];
char str[20][13];
int main() {
int i, j, s, p, q, t;
scanf("%d", &t);
for (int tst = 0; tst < t; tst++) {
cin >> n >> vl;
for (i = 0; i < n; i++) scanf("%s", str[i]);
for (i = 0; i <= n; i++) {
if (i == 0)
ex[i] = 1;
else
ex[i] = ex[i - 1] * 10LL;
}
up = ex[n];
for (i = 0; i <= n; i++) g[i] = dp[0][i] = dp[1][i] = up + 1;
memset(gi, 0, sizeof(gi));
dp[0][n] = dp[1][n] = g[n] = 0;
memset(bi, 0, sizeof(bi));
bi[n] = 0;
for (i = n - 1; i >= 0; i--) {
T = 10;
for (j = 0; j < 10; j++)
if (str[i][j] != str[i][0]) break;
if (j >= 10)
T = 1;
else {
for (j = 0; j < 10; j++)
if (str[i][j] != str[i][j % 2]) break;
if (j >= 10)
T = 2;
else {
for (j = 0; j < 10; j++)
if (str[i][j] != str[i][j % 5]) break;
if (j >= 10) T = 5;
}
}
if (T < 10) {
dp[0][i] =
dp[0][i + 1] + ((vl / ex[n - 1 - i]) % 10) % T * ex[n - 1 - i];
if (dp[1][i + 1] == dp[0][i + 1])
dp[1][i] = dp[0][i + 1] +
(((vl / ex[n - 1 - i]) % 10) % T + T) * ex[n - 1 - i];
else
dp[1][i] =
dp[1][i + 1] + ((vl / ex[n - 1 - i]) % 10) % T * ex[n - 1 - i];
} else
dp[0][i] = dp[1][i] = vl % ex[n - i];
tmp[i] = T;
int id = vl / ex[n - 1 - i] % 10, dx = 0, ch;
for (j = 0; j < 10; j++) {
if (id == j) continue;
for (s = 0; s + id < 10 && s + j < 10; s++)
if (str[i][id + s] != str[i][s + j]) break;
if (dx < s) {
dx = s;
ch = j;
} else if (dx == s && ch > j)
ch = j;
}
if (dx > 0) {
gi[i] = (id + dx) * ex[n - 1 - i];
if (id + dx < 10 && ch + dx < 10)
if ((tmp[i + 1] < 10 || (dx == 1))) {
for (j = id + 1; j <= id + dx; j++)
if (str[i][j % 10] != str[i][id]) break;
if (j > id + dx) gi[i] += max(0LL, bi[i + 1] - ex[n - i - 1]);
}
gi[i] = min(gi[i], up);
} else {
gi[i] = gi[i + 1] + id * ex[n - 1 - i];
gi[i] = min(gi[i], (vl / ex[n - 1 - i] % 10 + 1) * ex[n - 1 - i]);
}
dx = 0;
for (j = 0; j < 10; j++) {
if (id == j) continue;
for (s = 0; s + id < 10; s++)
if (str[i][id + s] != str[i][(j + s) % 10]) break;
if (dx < s) dx = s;
}
if (dx > 0) {
if (id + dx < 10) {
g[i] = ((id + dx)) * ex[n - 1 - i];
if ((tmp[i + 1] < 10 || (dx == 1))) {
for (j = id + 1; j <= id + dx; j++)
if (str[i][j % 10] != str[i][id]) break;
if (j > id + dx) g[i] += max(0LL, bi[i + 1] - ex[n - i - 1]);
}
}
g[i] = min(g[i], up);
} else {
g[i] = gi[i + 1] + id * ex[n - 1 - i];
g[i] = min(g[i], (vl / ex[n - 1 - i] % 10 + 1) * ex[n - 1 - i]);
}
dx = 0;
for (j = 0; j < 10; j++) {
if (id == j) continue;
for (s = 0; s + id < 20 && j + s < 20; s++)
if (str[i][(id + s) % 10] != str[i][(j + s) % 10]) break;
if ((id + s >= 10) && dx < s) dx = s;
}
if (dx > 0) {
bi[i] = (id + dx) * ex[n - 1 - i];
if ((tmp[i + 1] < 10 || dx == 1)) {
for (j = id + 1; j <= id + dx; j++)
if (str[i][j % 10] != str[i][id]) break;
if (j > id + dx) bi[i] += max(0LL, bi[i + 1] - ex[n - 1 - i]);
}
bi[i] = min(bi[i], up);
}
}
long long ans;
if (tmp[0] == 10) {
if (gi[0] - vl == 265117212103370001LL) cout << "vl=" << vl << endl;
cout << gi[0] - vl << endl;
} else {
if (dp[0][0] < vl)
cout << up - vl << endl;
else
cout << max(gi[0] - vl, up - dp[1][0]) << endl;
}
}
return 0;
}
| 11 | CPP |
N=int(input())
A=list(map(int,input().split()))
f=0
for a in A:
f=f^a
print("Yes" if f==0 else "No") | 0 | PYTHON3 |
def main():
for t in range(int(input())):
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
rem = {}
for i in a:
if i % k not in rem:
rem[i % k] = 0
rem[i % k] += 1
maxAns = 0
if 0 in rem:
del rem[0]
for i in rem:
maxAns = max(maxAns, (rem[i] - 1) * k + (k - i))
if maxAns == 0:
print(0)
else:
print(maxAns + 1)
main() | 10 | PYTHON3 |
n = int(input())
cubes = list(map(int, input().split()))
last = [0] * n
while last != cubes:
last = cubes.copy()
for idx in range(n - 1, 0, -1):
if cubes[idx] < cubes[idx - 1]:
cubes[idx], cubes[idx - 1] = cubes[idx - 1], cubes[idx]
for itm in cubes:
print (itm, end = ' ') | 7 | PYTHON3 |
a = input().split('+')
n = 0
num = [0 for i in range(100000)]
for i in a:
n += 1
num[n] = int(i)
for i in range(1, n):
for j in range(i+1, n+1):
if num[i] > num[j]:
temp = num[i]
num[i] = num[j]
num[j] = temp
for i in range(1, n+1):
print(num[i], end='')
if i < n:
print('+', end='')
print()
| 7 | PYTHON3 |
def tot(v, k):
sol = 0
while v > 0:
sol += v
v = v // k
return sol
n, k = map(int, input().split())
lo, hi = 0, 10**9 - 1
while lo < hi:
mid = lo + (hi - lo) // 2
t = tot(mid, k)
# print(t, lo, hi)
if n > t:
lo = mid + 1
else:
hi = mid
print(lo)
| 8 | PYTHON3 |
n=int(input())
p=input().split()
q=input().split()
minus=0
for i in p[1:]:
for j in q[1:]:
if j==i:
minus+=1
minus+=2
if (len(p)+len(q)-minus)==n:
print("I become the guy.")
else:
print("Oh, my keyboard!") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long occ[30], pref[100010];
int main() {
int n, l, rightind, leftind;
char s[100010];
cin >> n;
memset(occ, 0, sizeof occ);
for (int i = 0; i < n; i++) {
cin >> (s + 1);
l = strlen(s + 1);
for (int j = 0; j < 26; j++) {
if (occ[j] && j + 'a' != s[1] && j + 'a' != s[l]) {
occ[j] = 1;
}
}
rightind = 1;
while (s[rightind + 1] == s[rightind]) {
rightind++;
}
leftind = l;
while (rightind != l && s[leftind] == s[leftind - 1]) {
leftind--;
}
leftind = l - leftind + 1;
if (s[1] == s[l]) {
if (rightind == l) {
occ[s[1] - 'a'] = (l + 1) * occ[s[1] - 'a'] + l;
} else {
occ[s[1] - 'a'] = rightind + leftind + 1;
}
} else {
occ[s[1] - 'a'] = ((occ[s[1] - 'a'] > 0) ? rightind + 1 : rightind);
occ[s[l] - 'a'] = ((occ[s[l] - 'a'] > 0) ? leftind + 1 : leftind);
}
for (int j = rightind + 1; j <= l - leftind + 1; j++) {
if (s[j] == s[j - 1]) {
pref[j] = pref[j - 1] + 1;
} else {
pref[j] = 1;
occ[s[j - 1] - 'a'] = max(occ[s[j - 1] - 'a'], pref[j - 1]);
}
}
}
long long cnt = 0;
for (int j = 0; j < 26; j++) {
cnt = max(cnt, occ[j]);
}
cout << cnt;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 5e3 + 10;
int v[N][N];
int sz[N];
int main() {
int n;
scanf("%d", &n);
set<pair<int, int>> sp;
int tot = 0;
int maxv = 0;
for (int i = 1; i <= n; i++) {
int a, x, y, m;
scanf("%d%d%d%d%d", &sz[i], &a, &x, &y, &m);
int o = 1;
v[i][1] = a;
tot += sz[i];
int cnt = 0;
while (o < sz[i]) {
int pre = a;
a = (1LL * a * x + y) % m;
if (pre > a) cnt++;
v[i][++o] = a;
}
maxv = max(maxv, cnt);
reverse(v[i] + 1, v[i] + sz[i] + 1);
sp.emplace(v[i][sz[i]], i);
}
printf("%d\n", maxv);
if (tot > 200000) return 0;
int pre = -1;
vector<pair<int, int>> ans;
while (!sp.empty()) {
auto iter = sp.lower_bound(make_pair(pre, -1));
if (iter == sp.end()) iter = sp.begin();
int val, o;
tie(val, o) = *iter;
sp.erase(iter);
ans.emplace_back(val, o);
pre = val;
sz[o]--;
if (sz[o] == 0) continue;
sp.emplace(v[o][sz[o]], o);
}
for (auto& p : ans) printf("%d %d\n", p.first, p.second);
return 0;
}
| 7 | CPP |
t = int(input())
while t > 0:
t -= 1
n = int(input())
ans = 0
while n != 1:
if n % 2 == 0:
n //= 2
ans += 1
elif n % 3 == 0:
n //= 3
ans += 2
elif n % 5 == 0:
n //= 5
ans += 3
else:
break
if n == 1:
print(ans)
else:
print(-1)
| 7 | PYTHON3 |
n=int(input())
s=input()
l=list(s)
if n==2:
print(s)
exit()
if n%2==0:
for i in range(0,n-2,2):
print(l[i],end='')
print(l[i+1],end='')
print('-',end='')
print(l[n-2],end='')
print(l[n-1],end='')
print()
else:
if n==3:
print(s)
else:
for i in range(0,n-3,2):
print(l[i],end='')
print(l[i+1],end='')
print('-',end='')
print(l[n-3],end='')
print(l[n-2],end='')
print(l[n-1],end='')
print() | 8 | PYTHON3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long n, k[100007], x[100007], cur, dp[100007], ended[100007], last, L, R,
mid;
vector<pair<long long, long long> > stek;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
cin >> n;
for (long long i = 0; i < n; i++) cin >> x[i];
for (long long i = 0; i < n; i++) cin >> k[i];
cur = 0;
dp[0] = 0;
ended[0] = 1e16;
for (long long i = 1; i < n; i++) {
while (stek.size() > 1) {
last = stek.size() - 1;
if (ended[last - 1] > (-dp[i - 1] + stek[last - 1].second) /
(k[i - 1] - stek[last - 1].first))
stek.pop_back();
else
break;
}
stek.push_back({k[i - 1], dp[i - 1]});
if (stek.size() > 1) {
last = stek.size() - 1;
ended[last - 1] = (-stek[last].second + stek[last - 1].second) /
(stek[last].first - stek[last - 1].first);
ended[last] = 1e16;
}
L = 0, R = stek.size();
while (R - L > 0) {
mid = (R + L) / 2;
if (x[i] > ended[mid])
L = mid + 1;
else
R = mid;
}
dp[i] = stek[L].first * x[i] + stek[L].second;
}
cout << dp[n - 1];
}
| 9 | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.