_id
stringlengths 2
5
| partition
stringclasses 2
values | text
stringlengths 5
289k
| language
stringclasses 1
value | meta_information
dict | title
stringclasses 1
value |
---|---|---|---|---|---|
d8601 | test | import sys
readline = sys.stdin.readline
def ceil(a, b):
return -(-a//b)
def main():
N = int(readline())
inp = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
scr_t, scr_a = 0, 0
for t, a in inp:
if t >= scr_t and a >= scr_a:
scr_t = t
scr_a = a
elif t < scr_t and a >= scr_a:
scr_t = t * ceil(scr_t, t)
scr_a = scr_t * a // t
elif a < scr_a and t >= scr_t:
scr_a = a * ceil(scr_a, a)
scr_t = scr_a * t // a
else:
if t / a >= scr_t / scr_a:
scr_a = a * ceil(scr_a, a)
scr_t = scr_a * t // a
else:
scr_t = t * ceil(scr_t, t)
scr_a = scr_t * a // t
print((scr_t + scr_a))
def __starting_point():
main()
__starting_point() | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc046/tasks/arc062_a"
} | |
d8602 | test | import sys, math
from itertools import combinations as c, product as p
from collections import deque
sys.setrecursionlimit(10**9)
INF = float('inf')
MOD = 10**9 + 7
#MOD = 998244353
def si(): return input()
def ii(): return int(input())
def fi(): return float(input())
def lstr(): return input().split()
def lint(): return list(map(int, input().split()))
def lintdec(): return list(map(lambda x:int(x) - 1, input().split()))
def lnstr(n): return [input() for _ in range(n)]
def lnint(n): return [int(input()) for _ in range(n)]
def lint_list(n): return [lint() for _ in range(n)]
############################################################
S = si()
print('yes' if len(set(S)) == len(S) else 'no') | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc063/tasks/abc063_b"
} | |
d8603 | test | n=int(input())
s=input()
cnt=s[1:].count("E")
ans=cnt
for i in range(1,n):
if s[i-1]=="W":
cnt+=1
if s[i]=="E":
cnt-=1
ans=min(ans,cnt)
print(ans) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc098/tasks/arc098_a"
} | |
d8604 | test | n,m = map(int, input().split())
c = [0 for _ in range(n)]
for i in range(m):
a,b = map(int, input().split())
c[a-1] += 1
c[b-1] += 1
for j in range(n):
print(c[j]) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc061/tasks/abc061_b"
} | |
d8605 | test | N = int(input())
s = []
for i in range(N):
s.append(int(input()))
S = sum(s)
if S%10 != 0:
print(S)
else:
b = True
for j in range(N):
if s[j]%10 == 0:
continue
else:
b = False
if b:
print(0)
else:
s.sort()
for k in range(N):
if s[k]%10 != 0:
print(S-s[k])
break | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc063/tasks/arc075_a"
} | |
d8606 | test | #
# abc096 b
#
import sys
from io import StringIO
import unittest
from collections import Counter
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """6
aabbca"""
output = """2"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """10
aaaaaaaaaa"""
output = """1"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """45
tgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir"""
output = """9"""
self.assertIO(input, output)
def resolve():
N = int(input())
S = input()
ans = 0
for i in range(1, N-1):
x = Counter(S[0:i])
y = S[i:]
tmp = 0
for j in list(x.keys()):
if j in y:
tmp += 1
ans = max(ans, tmp)
print(ans)
def __starting_point():
# unittest.main()
resolve()
__starting_point() | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc098/tasks/abc098_b"
} | |
d8607 | test | s=input()
if s=='Sunny':
print('Cloudy')
if s=='Cloudy':
print('Rainy')
if s=='Rainy':
print('Sunny')
| PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc141/tasks/abc141_a"
} | |
d8608 | test | n, a, b = (int(n) for n in input().split())
print(min(n * a, b)) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc080/tasks/abc080_a"
} | |
d8609 | test | n, m = list(map(int, input().split()))
ans = (1900 * m + 100 * (n - m)) * (2 ** m)
print(ans)
| PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc078/tasks/arc085_a"
} | |
d8610 | test | S = input()
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for a in alphabet:
if a not in S:
print(a)
return
print('None')
| PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc071/tasks/abc071_b"
} | |
d8611 | test | n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
ans1 = y[n//2]
ans2 = y[n//2-1]
for i in x :
if i < ans1 :
print(ans1)
else :
print(ans2)
| PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc094/tasks/arc095_a"
} | |
d8612 | test | n=int(input())
a=[int(i) for i in input().split()]
a.sort()
count=0
def get_num(a):
count=1
taishou = a.pop()
while a!=[]:
second=a.pop()
if taishou==second:
count+=1
else:
a.append(second)
break
if count==1:
return taishou,0
elif count==2 or count==3:
return taishou,1
else:
return taishou,2
one=0
two=0
while a!=[] and (one==0 or two==0):
hen,length=get_num(a)
if length==1:
if one==0:
one=hen
else:
two=hen
elif length==2:
if one==0:
one=hen
two=hen
else:
two=hen
print((one*two))
| PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc071/tasks/arc081_a"
} | |
d8613 | test | n=int(input())
d,x=map(int,input().split())
for i in range(n):
t=int(input())
x+=(d+t-1)//t
print(x) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc092/tasks/abc092_b"
} | |
d8614 | test | a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a + 1):
for j in range(b + 1):
maisuuOf50 = (x - i * 500 - j * 100) / 50
if 0 <= maisuuOf50 <= c:
ans += 1
print(ans)
| PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc087/tasks/abc087_b"
} | |
d8615 | test | # 3 つの整数 A , B , C が与えられます。
# 整数 C が A 以上 かつ B 以下であるかを判定してください。
A,B,C = map(int,input().split())
if C >= A and C <= B:
print('Yes')
else:
print('No') | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc061/tasks/abc061_a"
} | |
d8616 | test | n,x=list(map(int,input().split()))
y = [int(input()) for i in range(n)]
y.sort()
c = 0
for i in range(n):
if c < x:
c +=y[i]
elif c > x:
print((i-1))
return
d = sum(y)
print((((x-d)//y[0])+n))
| PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc095/tasks/abc095_b"
} | |
d8617 | test | n=int(input())
string_list=[input() for i in range(n)]
count = len(set(string_list))
print(count) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc164/tasks/abc164_c"
} | |
d8618 | test | n = int(input())
a = list(map(int, input().split()))
ans = 0
t = 400
while t < 3201:
for i in a:
if i >= t-400 and i < t:
ans += 1
break
t += 400
s = 0
for i in a:
if i >= 3200: s += 1
if ans == 0: print(1, s)
else: print(ans, ans+s) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc064/tasks/abc064_c"
} | |
d8619 | test | s = input()
print(s.count("o")*100+700) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc095/tasks/abc095_a"
} | |
d8620 | test | # 入力
a, b = input().split()
# 出力
# a = 'H' のときatくんは正直者
if a == 'H' and b == 'H':
print('H')
elif a == 'D' and b == 'H':
print('D')
elif a == 'H' and b =='D':
print('D')
elif a == 'D' and b == 'D':
print('H') | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc056/tasks/abc056_a"
} | |
d8621 | test |
S = input()
a = int(S[0])
b = int(S[1])
c = int(S[2])
d = int(S[3])
if a+b+c+d==7:
print('{}+{}+{}+{}=7'.format(a,b,c,d))
elif a+b+c-d==7:
print('{}+{}+{}-{}=7'.format(a,b,c,d))
elif a+b-c+d==7:
print('{}+{}-{}+{}=7'.format(a,b,c,d))
elif a+b-c-d==7:
print('{}+{}-{}-{}=7'.format(a,b,c,d))
elif a-b+c+d==7:
print('{}-{}+{}+{}=7'.format(a,b,c,d))
elif a-b+c-d==7:
print('{}-{}+{}-{}=7'.format(a,b,c,d))
elif a-b-c-d==7:
print('{}-{}-{}-{}=7'.format(a,b,c,d))
elif a-b-c+d==7:
print('{}-{}-{}+{}=7'.format(a,b,c,d)) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc079/tasks/abc079_c"
} | |
d8622 | test | def i_input(): return int(input())
def i_map(): return list(map(int, input().split()))
def i_list(): return list(map(int, input().split()))
def i_row(N): return [int(input()) for _ in range(N)]
def i_row_list(N): return [list(map(int, input().split())) for _ in range(N)]
n = i_input()
aa=i_list()
shain=[0]*n
for a in aa:
shain[a-1]+=1
for s in shain:
print(s)
| PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc163/tasks/abc163_c"
} | |
d8623 | test | x=int(input())
ans=0
a=0
for i in range(1,x+1):
a+=i
ans+=1
if a>=x:
print(ans)
break | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc056/tasks/arc070_a"
} | |
d8624 | test | n = input()
print("Yes" if n[0] == n[1] == n[2] or n[1] == n[2] == n[3] else "No") | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc079/tasks/abc079_a"
} | |
d8625 | test | n = int(input())
a_list = sorted([int(x) for x in input().split()])
b_list = sorted([int(x) for x in input().split()])
c_list = sorted([int(x) for x in input().split()])
import bisect
sum = 0
for b in b_list:
b_num = bisect.bisect_left(a_list,b)
c_num = bisect.bisect_right(c_list,b)
sum += b_num*(len(c_list)-c_num)
print(sum) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc077/tasks/arc084_a"
} | |
d8626 | test | x,y=input().split()
if ord(x)<ord(y):print('<')
elif ord(x)>ord(y):print('>')
else:print('=') | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc078/tasks/abc078_a"
} | |
d8627 | test | # 愚直
h, w = map(int, input().split())
table = [list(input()) for _ in range(h)]
for i in range(h):
for j in range(w):
if table[i][j] == ".":
num = 0
for y in [-1, 0, 1]:
for x in [-1, 0, 1]:
if 0 <= i + y < h and 0 <= j + x < w:
if table[i + y][j + x] == "#":
num += 1
table[i][j] = str(num)
for t in table:
print("".join(t)) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc075/tasks/abc075_b"
} | |
d8628 | test | def solve():
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ret = 0
A_cusum = [0]
A_border_index = 0 # 超えるときのindex
for a_ in A:
A_end = A_cusum[-1]
if A_end+a_ > K:
break
A_cusum.append(A_end+a_)
A_border_index = len(A_cusum)-1
ret = A_border_index
B_cusum = [0]
B_border_index = 0
while A_border_index >= 0 and B_border_index < M:
while B_border_index < M:
B_end = B_cusum[-1]
b_ = B[B_border_index]
if A_cusum[A_border_index]+B_end+b_ > K:
break
B_cusum.append(B_end+b_)
B_border_index += 1
ret = max(ret, A_border_index+B_border_index)
A_border_index -= 1
print(ret)
solve() | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc172/tasks/abc172_c"
} | |
d8629 | test | a,b,c,x,y = list(map(int,input().split()))
if (a + b) <= 2 * c:
print((a * x + b * y))
else:
max_c = max(x,y)
min_c = min(x,y)
AB = 2 * c * max_c
if x > y:
SP = ((x - min_c) * a) + (2 * c * min_c)
else:
SP = ((y - min_c) * b) + (2 * c * min_c)
print((min(AB,SP)))
| PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc095/tasks/arc096_a"
} | |
d8630 | test | N = int(input())
mod = 1000000007
from collections import Counter
Y = Counter()
for i in range(2, N+1):
M = i
for j in range(2,i+1):
while M % j == 0:
Y[j] += 1
M //= j
def product(X):
res = 1
for x in X:
res *= x + 1
res %= mod
return res
ans = product(Y.values())
print(ans) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc052/tasks/arc067_a"
} | |
d8631 | test | x=int(input())
m=-1000
if 1<=x<=3:
print((1))
return
else:
for b in range(2,x+1):
for p in range(2,11):
if x>=b**p:
m=max(m,b**p)
print(m)
| PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc097/tasks/abc097_b"
} | |
d8632 | test | N = int(input())
ds = []
mochidan = 0
for i in range(N):
ds.append(int(input()))
while ds:
tmp = max(ds)
ds = [j for j in ds if j < tmp]
mochidan += 1
print(mochidan) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc085/tasks/abc085_b"
} | |
d8633 | test | s = input()
first_a_index = s.index('A')
last_z_index = len(s) - list(reversed(s)).index('Z')
print(last_z_index - first_a_index) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc053/tasks/abc053_b"
} | |
d8634 | test | n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
cnt = cnt | a[i]
j = 0
ans = 0
while 1:
if (cnt >> j & 1 == 0):
ans += 1
j += 1
else:
break
print(ans) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc081/tasks/abc081_b"
} | |
d8635 | test | N = int(input())
# N!を(10^9+7)で割った余りを求める
# N!そのものを求める必要はなく、
# x = i*x (mod 10^9+7) と更新していけばよい
M = 10**9 + 7
s = 1
for i in range(1, N+1):
s *= i
s %= M
print(s) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc055/tasks/abc055_b"
} | |
d8636 | test | N = int(input())
ans = int(N*(N+1)/2)
print(ans) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc043/tasks/abc043_a"
} | |
d8637 | test | def main():
N = int(input())
A = list(map(int, input().split()))
alice = 0
bob = 0
A.sort(reverse=True)
for i, a in enumerate(A):
if i%2 == 0:
alice += a
else:
bob += a
print((alice - bob))
def __starting_point():
main()
__starting_point() | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc088/tasks/abc088_b"
} | |
d8638 | test | N, M = [int(n) for n in input().split()]
submit = []
AC = [0] * N
WA = [0] * N
for i in range(M):
p, s = [n for n in input().split()]
p = int(p)
if AC[p-1] == 1:
continue
if s == 'AC':
AC[p-1] = 1
elif s == 'WA':
WA[p-1] += 1
pen = [x*y for x, y in zip(AC, WA)]
print(sum(AC), sum(pen)) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc151/tasks/abc151_c"
} | |
d8639 | test | n, k = map(int, input().split())
H = list(map(int, input().split()))
H.sort(reverse=True)
print(sum(H[k:])) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc153/tasks/abc153_c"
} | |
d8640 | test | n = int(input())
k = int(input())
x = list(map(int,input().split()))
ans = 0
for i in range(n):
ans += 2*min(k-x[i],x[i])
print(ans) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc074/tasks/abc074_b"
} | |
d8641 | test | a = int(input())
b = int(input())
c = int(input())
d = int(input())
sum = (min(a, b) + min(c, d))
print(sum) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc092/tasks/abc092_a"
} | |
d8642 | test | n = int(input())
a = [int(x) for x in input().split()]
a.sort()
mod = 10 ** 9 + 7
def p(p):
ans = 1
for i in range(p):
ans *= 2
ans %= mod
return ans
if n % 2 == 1:
res = True
for i in range(n):
if a[i] != ((i + 1) // 2) * 2:
res = False
if res:
print(p(n // 2))
else:
print(0)
else:
res = True
for i in range(n):
if a[i] != (i // 2) * 2 + 1:
res = False
if res:
print(p(n // 2))
else:
print(0) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc050/tasks/arc066_a"
} | |
d8643 | test | n, a, b = map(int, input().split())
ans = 0
for i in range(1, n + 1):
val = 0
for c in str(i):
val += int(c)
if a <= val <= b:
ans += i
print(ans) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc083/tasks/abc083_b"
} | |
d8644 | test | N = input()
print("ABC"+N) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc068/tasks/abc068_a"
} | |
d8645 | test | a,b=map(int,input().split())
if a>b:
print(a-1)
else:
print(a) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc096/tasks/abc096_a"
} | |
d8646 | test | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: sample
# CreatedDate: 2020-10-10 20:29:20 +0900
# LastModified: 2020-10-10 20:37:38 +0900
#
import os
import sys
# import numpy as np
# import pandas as pd
def main():
N = int(input())
A = [0]
visited = [0]*(N+1)
for _ in range(N):
A.append(int(input()))
i = 1
cnt = 0
while visited[i] == 0:
if i == 2:
print(cnt)
return
cnt += 1
visited[i] = 1
i = A[i]
print((-1))
def __starting_point():
main()
__starting_point() | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc065/tasks/abc065_b"
} | |
d8647 | test | n=int(input())
d=dict()
for _ in range(n):
hoge=int(input())
if d.get(hoge,0)==0:
d[hoge]=1
else:
d[hoge]+=1
ans=0
for i in d.values():
if i%2==1:
ans+=1
print(ans) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc073/tasks/abc073_c"
} | |
d8648 | test | n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
from collections import Counter
dic=Counter(a)
dic=sorted(list(dic.items()),key=lambda x:x[1])
ans=0
cnt=0
l=max(len(dic)-k,0)
for i in dic:
if cnt==l:
break
ans=ans+i[1]
cnt=cnt+1
print(ans)
| PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc081/tasks/arc086_a"
} | |
d8649 | test | N = int(input())
T = 0
X = 0
Y = 0
for i in range(N):
t, x, y = list(map(int, input().split()))
dt = t - T
dx = abs(X - x)
dy = abs(Y - y)
dis = dx + dy
if dt < dis:
print("No")
break
if (dt - dis) % 2 == 1:
print("No")
break
T = t
X = x
Y = y
else:
print("Yes")
| PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc086/tasks/arc089_a"
} | |
d8650 | test | a, b = map(int, input().split())
print(((a + b) + (2 - 1)) // 2) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc082/tasks/abc082_a"
} | |
d8651 | test | import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def LIST() : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
def dfs(j):
if j not in finish:
finish.add(j)
for k in L[j]:
dfs(k)
N,M=MAP()
s=list()
L=[[] for _ in range(N)]
for i in range(M):
a,b=MAP()
a-=1
b-=1
L[a].append(b)
L[b].append(a)
s.append([a,b])
ans=0
for i in range(M):
a,b=s[i]
L[a].remove(b)
L[b].remove(a)
finish=set()
dfs(a)
if len(finish)!=N:
ans+=1
L[a].append(b)
L[b].append(a)
print(ans) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc075/tasks/abc075_c"
} | |
d8652 | test | import bisect,collections,copy,heapq,itertools,math,string
import sys
def I():
#1 line 1 int
return int(sys.stdin.readline().rstrip())
def LI():
#1 line n int
return list(map(int,sys.stdin.readline().rstrip().split()))
def S():
#1 line 1 string
return sys.stdin.readline().rstrip()
def LS():
#1 line n strings
return list(sys.stdin.readline().rstrip().split())
xs=LI()
if xs[0] == xs[1]:
print(xs[2])
elif xs[0] == xs[2]:
print(xs[1])
else:
print(xs[0]) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc075/tasks/abc075_a"
} | |
d8653 | test | a, b, c, d, e, f = map(int, input().split())
s = set()
for i in range(30 // a + 1):
for j in range(30 // b + 1):
if 0 < (a * i + b * j) * 100 <= f:
s = s | {a * i + b * j}
s2 = set()
for i in range(3000 // c + 1):
for j in range(3000 // d + 1):
if c * i + d * j <= f:
s2 = s2 | {c * i + d * j}
ans = []
for i in s:
for j in s2:
if i * 100 + j <= f and j <= i * e:
ans.append([j / i * -1, i * 100 + j, j])
ans.sort()
print(ans[0][1], ans[0][2]) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc074/tasks/arc083_a"
} | |
d8654 | test | a = input()
print(f"{a[0]}{len(a[1:-1])}{a[-1]}") | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc069/tasks/abc069_b"
} | |
d8655 | test | a = input()
b = input()
if a[:: -1] == b:
print("YES")
else:
print("NO") | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc077/tasks/abc077_a"
} | |
d8656 | test | import sys
stdin=sys.stdin
ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()
yp=lambda:print('Yes')
np=lambda:print('No')
s=list(sp())
k=ip()
ans=set()
alpa=list(set(s))
alpa.sort()
ch=0
siyou=[]
for i in range(len(alpa)):
if i<=2:
siyou.append(alpa[i])
else:
break
for x in siyou:
for i in range(len(s)):
if s[i]==x:
st=''
for y in range(i,i+5):
if y<len(s):
st+=s[y]
ans.add(st)
if len(ans)>k:
break
ans=list(ans)
ans.sort()
print(ans[k-1])
| PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc097/tasks/arc097_a"
} | |
d8657 | test | def main():
w, h, n = list(map(int, input().split()))
x_min = 0
x_max = w
y_min = 0
y_max = h
for _ in range(n):
x, y, a = list(map(int, input().split()))
if a == 1:
x_min = max(x_min, x)
elif a == 2:
x_max = min(x_max, x)
elif a == 3:
y_min = max(y_min, y)
else:
y_max = min(y_max, y)
print((
(x_max - x_min) * (y_max - y_min)
if x_min < x_max and y_min < y_max else 0
))
def __starting_point():
main()
__starting_point() | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc047/tasks/abc047_b"
} | |
d8658 | test | def LIHW(h):
return [list(map(int, input().split())) for _ in range(h)]
N = int(input())
X = LIHW(N-1)
for i in range(N-1):
time = [0]*N
time[i] = X[i][1]+X[i][0]
for j in range(i+1, N-1):
if time[j-1] <= X[j][1]:
time[j] = X[j][1]+X[j][0]
else:
if (time[j-1]-X[j][1]) % X[j][2] == 0:
time[j] = time[j-1] + X[j][0]
else:
time[j] = time[j-1] + X[j][0]+X[j][2] - \
((time[j-1]-X[j][1]) % X[j][2])
print(time[j])
print(0) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc084/tasks/abc084_c"
} | |
d8659 | test | H, W = map(int, input().split())
for _ in range(H):
C = input()
print(C)
print(C) | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc049/tasks/abc049_b"
} | |
d8660 | test | def N():
return int(input())
def L():
return list(map(int,input().split()))
def NL(n):
return [list(map(int,input().split())) for i in range(n)]
mod = pow(10,9)+7
#import numpy as np
import sys
import math
import collections
n =N()
a = L()
s = set()
for i in range(n):
if a[i] in s:
print("NO")
return
s.add(a[i])
print("YES") | PYTHON | {
"starter_code": "",
"url": "https://atcoder.jp/contests/abc154/tasks/abc154_c"
} | |
d8661 | test | for _ in range(int(input())):
n = int(input())
wt = list(map(int, input().split()))
count = {}
for x in wt:
if x not in count:
count[x] = 0
count[x] += 1
k = 0
for s in range(101):
temp = 0
temp2 = 0
for x in count:
if (s - x) in count:
if (s - x) == x:
temp2 += count[x] // 2
else:
temp += min(count[x], count[s -x])
k = max(k, temp//2 + temp2)
print(k)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1399/C"
} | |
d8662 | test | import sys
def main():
#n = iinput()
#k = iinput()
#m = iinput()
#n = int(sys.stdin.readline().strip())
#n, k = rinput()
#n, m = rinput()
#m, k = rinput()
#n, k, m = rinput()
#n, m, k = rinput()
#k, n, m = rinput()
#k, m, n = rinput()
#m, k, n = rinput()
#m, n, k = rinput()
#n, t = map(int, sys.stdin.readline().split())
#q = list(map(int, sys.stdin.readline().split()))
#q = linput()
n, x = list(map(int, sys.stdin.readline().split()))
if n < 3:
print(1)
return 0
print((n - 2 + x - 1) // x + 1)
for i in range(int(sys.stdin.readline().strip()) ):
main()
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1426/A"
} | |
d8663 | test | from string import ascii_lowercase
t = int(input())
for _ in range(t):
n, m = [int(x) for x in input().split()]
s = input()
count = {x : 0 for x in ascii_lowercase}
errors = [int(x) for x in input().split()]
errors = sorted(errors)
e_idx = 0
for j, c in enumerate(s):
while e_idx < m and errors[e_idx] <= j:
e_idx += 1
count[c] += (m - e_idx) + 1
print(*[count[c] for c in ascii_lowercase])
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1311/C"
} | |
d8664 | test | t=int(input())
for nt in range(t):
a,b,c=map(int,input().split())
print (max(0,abs(a-b)+abs(b-c)+abs(a-c)-4)) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1272/A"
} | |
d8665 | test | def read_int():
return int(input())
def read_ints():
return list(map(int, input().split(' ')))
t = read_int()
for case_num in range(t):
n = read_int()
a = list(read_ints())
cnt = [0 for i in range(101)]
even = 0
for ai in a:
cnt[ai] += 1
if ai % 2 == 0:
even += 1
odd = n - even
if even % 2 == 0:
print('YES')
else:
ok = False
for i in range(1, 100):
if cnt[i] > 0 and cnt[i + 1] > 0:
ok = True
break
print('YES' if ok else 'NO')
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1360/C"
} | |
d8666 | test | import sys
input = sys.stdin.readline
import heapq
def dijkstra(n, s, edges):
hq = [(0, s)]
cost = [float('inf')] * n
cost[s] = 0
while hq:
c, v = heapq.heappop(hq)
if c > cost[v]:
continue
for d, u in edges[v]:
tmp = d + cost[v]
if tmp < cost[u]:
cost[u] = tmp
heapq.heappush(hq, (tmp, u))
return cost
def main():
n, m, k = map(int, input().split())
edges = [[] for _ in range(n)]
xy = []
for _ in range(m):
x, y, t = map(int,input().split())
x -= 1
y -= 1
edges[x].append((t, y))
edges[y].append((t, x))
xy.append((x, y))
dist = [[] for _ in range(n)]
for i in range(n):
dist[i] = dijkstra(n, i, edges)
ab = [list(map(int, input().split())) for _ in range(k)]
ans = 10 ** 20
for x, y in xy:
tmp = 0
for a, b in ab:
a -= 1
b -= 1
tmp += min(dist[a][b], dist[a][x] + dist[b][y], dist[a][y] + dist[b][x])
ans = min(ans, tmp)
print(ans)
main() | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1433/G"
} | |
d8667 | test | for _ in range(int(input())):
n = int(input())
bits = ['1']
while int(''.join(bits), 3) < n:
bits.append('1')
for i in range(len(bits)):
bits[i] = '0'
if int(''.join(bits), 3) < n:
bits[i] = '1'
print(int(''.join(bits), 3))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1249/C1"
} | |
d8668 | test | for _ in range(int(input())):
n = int(input())
P = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
if ans[i] == 0:
now = i
cnt = 0
cll = []
while True:
now = P[now] - 1
cnt += 1
cll.append(now)
if now == i:
break
for u in cll:
ans[u] = cnt
print(' '.join(list(map(str, ans)))) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1249/B2"
} | |
d8669 | test | from queue import deque
n, m = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
used = set(arr)
q = deque()
for i in range(n):
q.append([arr[i] - 1, 1, -1])
q.append([arr[i] + 1, 1, 1])
ret = []
s = 0
while m:
x, l, dr = q.popleft()
a = x + dr
if not a in used:
q.append([a, l + 1, dr])
if not x in used:
used.add(x)
ret.append(x)
m -= 1
s += l
print(s)
print(*ret) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1283/D"
} | |
d8670 | test | import sys
input = sys.stdin.readline
t = int(input())
out = []
for _ in range(t):
n = int(input())
pos = []
for __ in range(n):
pos.append(tuple(map(int, input().split())))
pos.sort()
currX = 0
currY = 0
s = ''
works = True
for x, y in pos:
if currX > x:
works = False
break
else:
s += 'R' * (x - currX)
currX = x
if currY > y:
works = False
break
else:
s += 'U' * (y - currY)
currY = y
if works:
out.append('YES')
out.append(s)
else:
out.append('NO')
print('\n'.join(out))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1294/B"
} | |
d8671 | test | import sys
def read_int():
return int(sys.stdin.readline())
def read_ints():
return list(map(int, sys.stdin.readline().split(' ')))
t = read_int()
for case_num in range(t):
n, s = read_ints()
a = [0] + [int(i) for i in str(n)]
ds = sum(a)
cost = 0
idx = len(a) - 1
radix = 1
while ds > s:
if a[idx] > 0:
cost += (10 - a[idx]) * radix
ds -= a[idx]
a[idx] = 0
ds += 1
a[idx - 1] += 1
i = idx - 1
while a[i] >= 10:
a[i - 1] += 1
a[i] -= 10
ds -= 9
i -= 1
radix *= 10
idx -= 1
print(cost)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1409/D"
} | |
d8672 | test | for _ in range(int(input())):
n=int(input())
s=list(map(int,input().split()))
l=s.index(1)
r=n-s[::-1].index(1)
ans=0
for i in range(l,r):
ans+=1-s[i]
print(ans) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1433/B"
} | |
d8673 | test | n = int(input())
for i in range(n):
l, ch = map(int, input().split())
for j in range(l):
print(chr(j % ch + ord('a')), end='')
print()
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1092/A"
} | |
d8674 | test | from fractions import Fraction
import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
# sys.setrecursionlimit(200000)
# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def tinput():
return input().split()
def rinput():
return list(map(int, tinput()))
def rlinput():
return list(rinput())
# mod = int(1e9)+7
def factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
# ----------------------------------------------------
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
for _ in range(iinput()):
n = iinput()
a = rlinput()
moves = 0
i = 0
j = n-1
prev = 0
ans1 = 0
ans2 = 0
while i <= j:
temp = 0
f = False
while i<=j and i < n and temp <= prev:
temp += a[i]
f = True
i += 1
ans1 += temp
if f:
moves += 1
prev = temp
temp = 0
f = False
while j >= i and j > 0 and temp <= prev:
temp += a[j]
f = True
j -= 1
ans2 += temp
if f:
moves += 1
prev = temp
print(moves,ans1,ans2)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1352/D"
} | |
d8675 | test | import sys
input = sys.stdin.readline
rInt = lambda: int(input())
mInt = lambda: list(map(int, input().split()))
rLis = lambda: list(map(int, input().split()))
t = int(input())
for _ in range(t):
n, k = mInt()
a = rLis()
b = rLis()
a.sort()
b.sort(reverse = True)
for i in range(k):
if a[i] < b[i]:
a[i] = b[i]
print(sum(a))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1353/B"
} | |
d8676 | test | n, c = list(map(int, input().split()))
a = [int(ai) for ai in input().split()]
b = [int(bi) for bi in input().split()]
dpa, dpb = [0] * n, [0] * n
dpa[1], dpb[1] = a[0], c + b[0]
for i in range(1, n - 1):
dpa[i + 1], dpb[i + 1] = min(dpa[i], dpb[i]) + a[i], min(dpa[i] + c, dpb[i]) + b[i]
print(*(min(dpa[i], dpb[i]) for i in range(n)))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1249/E"
} | |
d8677 | test | #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
t = I()
for _ in range(t):
n,k = LI()
f = 1
p = 1
while f <= k:
f += p
p += 1
f -= p
p -= 2
k -= f
p = n-p
k = n-k
ans = "a"*(p-2)+"b"+"a"*(k-p+1)+"b"+"a"*(n-k-1)
print(ans)
return
#Solve
def __starting_point():
solve()
__starting_point() | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1328/B"
} | |
d8678 | test | import bisect
def solve(n,x_coords,y_coords,k,ans):
x_coords.sort()
dp = []
for i in range(n):
x = x_coords[i]
index = bisect.bisect(x_coords,x+k)-1
dp.append(index-i+1)
dp_max = []
for i in reversed(dp):
if not dp_max:
dp_max.append(i)
else:
dp_max.append(max(dp_max[-1],i))
dp_max.reverse()
max_val = 0
for i in range(n):
x = x_coords[i]
index = bisect.bisect(x_coords,x+k)-1
val = index-i+1
if index+1 < n:
val += dp_max[index+1]
max_val = max(max_val,val)
ans.append(str(max_val))
def main():
t = int(input())
ans = []
for i in range(t):
n,k = list(map(int,input().split()))
x_coords = list(map(int,input().split()))
y_coords = list(map(int,input().split()))
solve(n,x_coords,y_coords,k,ans)
print('\n'.join(ans))
main()
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1409/E"
} | |
d8679 | test | import sys
from heapq import *
input = sys.stdin.readline
quer, m = list(map(int, input().split()))
vals = list(range(m))
q = []
for v in vals:
heappush(q, v)
out = []
for _ in range(quer):
nex = int(input()) % m
vals[nex] += m
heappush(q, vals[nex])
new = heappop(q)
while vals[new % m] != new:
new = heappop(q)
out.append(new)
heappush(q, new)
print('\n'.join(map(str,out)))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1294/D"
} | |
d8680 | test | def read_int():
return int(input())
def read_ints():
return list(map(int, input().split(' ')))
t = read_int()
for case_num in range(t):
n, x, y = read_ints()
d = y - x
for i in range(n - 1, 0, -1):
if d % i == 0:
d //= i
l = min(n - (i + 1), (x - 1) // d)
ans = [x - l * d + i * d for i in range(n)]
print(' '.join(map(str, ans)))
break
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1409/C"
} | |
d8681 | test | import time
import random
l = list(map(int, input().split()))
assert len(l) == l[0] + 1
l = l[1:]
l.sort()
v = [0 for i in range(10 ** 4)]
for i in range(4 * 10**5):
v[random.randrange(0, len(v))] = random.randrange(-1000, 1000)
print(' '.join(map(str, l)))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/784/F"
} | |
d8682 | test | for _ in range(int(input())):
n = int(input())
ar = list(map(int, input().split()))
a, b = 0, 0
for elem in ar:
if elem % 2 == 0:
a = 1
else:
b = 1
if sum(ar) % 2 == 1:
print('YES')
elif a == 1 == b:
print('YES')
else:
print('NO') | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1296/A"
} | |
d8683 | test | T = int(input())
for _ in range(T):
n = int(input())
if n <= 3:
print(-1)
else:
left = []
for i in range(1, n + 1, 2):
left.append(i)
right = []
right.append(4)
right.append(2)
for i in range(6, n + 1, 2):
right.append(i)
right.reverse()
for i in left:
right.append(i)
for i in right:
print(i, end = " ")
print("") | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1352/G"
} | |
d8684 | test |
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
od=0
ev=0
for i in range(n):
if(i&1):
if(a[i]%2==0):
od+=1
else:
if(a[i]&1):
ev+=1
if(od!=ev):
print(-1)
else:
print(od) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1367/B"
} | |
d8685 | test | n = int(input())
a = list(map(int, input().split()))
g = [list() for _ in range(n)]
for _ in range(n-1):
u,v = list(map(int, input().split()))
g[u-1].append(v-1)
g[v-1].append(u-1)
st = [x*2-1 for x in a] + [0]
p = [-1]*n
q = [0]
while q:
v = q.pop()
for x in g[v]:
if x == p[v]: continue
p[x] = v
q.append(x)
seen = [0]*n
q = [0]
while q:
v = q[-1]
if seen[v]:
q.pop()
if st[v] > 0:
st[p[v]] += st[v]
else:
for x in g[v]:
if x == p[v]: continue
q.append(x)
seen[v] = 1
seen = [0]*n
q = [0]
while q:
v = q.pop()
for x in g[v]:
if x == p[v]: continue
c = st[v]
if st[x] > 0: c -= st[x]
if c > 0: st[x] += c
q.append(x)
print(*st[:n])
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1324/F"
} | |
d8686 | test | for testcase in range(int(input())):
n = int(input())
cnt2, cnt3 = 0, 0
while n % 2 == 0:
n //= 2
cnt2 += 1
while n % 3 == 0:
n //= 3
cnt3 += 1
if n > 1 or cnt3 < cnt2:
print(-1)
continue
print(2 * cnt3 - cnt2)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1374/B"
} | |
d8687 | test | import sys
def countR(ip):
c=0
for i in ip:
if(i=='R'):
c+=1
return c
def countB(ip):
c=0
for i in ip:
if(i=='B'):
c+=1
return c
def countG(ip):
c=0
for i in ip:
if(i=='G'):
c+=1
return c
# sys.stdin.readline()
t=int(sys.stdin.readline())
x='RGB'*680
y='GBR'*680
z='BRG'*680
for i in range(t):
n,k=list(map(int,sys.stdin.readline().strip().split()))
a=sys.stdin.readline().strip()
xk=x[:k]
yk=y[:k]
zk=z[:k]
# print(k,xk,zk)
# xc=[]
# yc=[]
# zc=[]
# xc.append(countR(xk))
# xc.append(countG(xk))
# xc.append(countB(xk))
# yc.append(countR(yk))
# yc.append(countG(yk))
# yc.append(countB(yk))
# zc.append(countR(zk))
# zc.append(countG(zk))
# zc.append(countB(zk))
op=2001
for j in range(n-k+1):
b=a[j:j+k]
# print(len(b),xc,zc)
# bc=[]
# bc.append(countR(b))
# bc.append(countG(b))
# bc.append(countB(b))
xd=0
yd=0
zd=0
# print(a,b,xc,yc,zc,bc)
for jj in range(len(b)):
if(b[jj]!=xk[jj]):
xd+=1
if(b[jj]!=yk[jj]):
yd+=1
if(b[jj]!=zk[jj]):
zd+=1
# print(a,b,xd,yd,zd,z)
op=min(op,xd,yd,zd)
print(op)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1196/D1"
} | |
d8688 | test | for i in range(int(input())):
n=int(input())
l1=list(map(int,input().split()))
type1=0
type2=0
ans=0
for item in l1:
if item%3==0:
ans+=1
elif item%3==1:
type1+=1
else :
type2+=1
x=min(type1,type2)
ans+=x
type1-=x
type2-=x
ans+=(type1//3+type2//3)
print(ans) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1176/B"
} | |
d8689 | test | q = int(input())
for qi in range(q):
n = int(input())
a = list(map(int, input().split()))
used = [False] * n
for t in range(n):
for i in range(len(a) - 1, 0, -1):
if used[i]:
continue
if a[i] < a[i - 1]:
a[i], a[i - 1] = a[i - 1], a[i]
used[i] = True
print(' '.join(str(x) for x in a)) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1256/B"
} | |
d8690 | test | '''input
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
'''
import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
from heapq import heappush as hpush
from heapq import heappop as hpop
mod=10**9+7
def ri(flag=0):
if flag==0:
return [int(i) for i in sys.stdin.readline().split()]
else:
return int(sys.stdin.readline())
for _ in range(ri(1)):
n = ri(1)
a= ri()
idx = a.index(1)
check1 = 1
check2 =1
for i in range(n):
if a[(idx+i)%n] == i+1:
pass
else:
check1=0
a=a[::-1]
idx = a.index(1)
for i in range(n):
if a[(idx+i)%n] == i+1:
pass
else:
check2=0
if check1==1 or check2==1:
print("YES")
else:
print("NO") | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1203/A"
} | |
d8691 | test | q = int(input())
for z in range(q):
n, k = map(int, input().split())
x = n // k
n -= x * k
m = min(k // 2, n)
print(x * k + m) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1283/B"
} | |
d8692 | test | t=int(input())
for i in range (t):
n,k=map(int,input().split())
if n-k+1>0 and (n-k+1)%2==1:
print("YES")
print(*([1]*(k-1)), n-k+1)
elif n-k*2+2>0 and (n-k*2+2)%2==0:
print("YES")
print(*([2]*(k-1)), n-k*2+2)
else:
print("NO") | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1352/B"
} | |
d8693 | test | from sys import stdin,stdout
import sys
import math
t=int(stdin.readline())
for i in range(t):
a=list(map(int,stdin.readline().split()))
print(sum(a)//2)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1196/A"
} | |
d8694 | test | t = int(input())
def gcd(a,b):
if b == 0:
return a
return gcd(b,a%b)
for _ in range(t):
n,k = map(int,input().split())
s = input()
occ = [0] * 26
for i in s:
occ[ord(i)-97] += 1
occ.sort()
occ.reverse()
for l in range(1,n+1):
cycle = gcd(l,k)
need = l//cycle
su = 0
for i in occ:
su += i//need
if su*need >= l:
wyn = l
print(wyn) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1367/E"
} | |
d8695 | test | from sys import stdin
c=int(stdin.readline().strip())
for cas in range(c):
n,m=list(map(int,stdin.readline().strip().split()))
s=list(map(int,stdin.readline().strip().split()))
sm=0
ans=[]
ind=-1
for i in range(n):
if m==1:
ind=i
break
sm+=s[i]
if sm%2!=0:
ans.append(i+1)
sm=0
m-=1
if ind==-1:
print("NO")
continue
sm=sum(s[ind::])
if sm%2!=0:
ans.append(n)
print("YES")
print(*ans)
else:
print("NO")
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1196/B"
} | |
d8696 | test | class Solution:
def reverseBits(self, n: int) -> int:
rev = ''
for i in reversed(bin(n)[2:]):
rev = rev + i
rev = rev + '0'*(32-len(rev))
return int(rev, 2) | PYTHON | {
"starter_code": "\nclass Solution:\n def reverseBits(self, n: int) -> int:\n ",
"url": "https://leetcode.com/problems/reverse-bits/"
} | |
d8697 | test | class Solution:
def generate(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
res = [[1]]
for i in range(1,numRows):
res.append(list(map(lambda x, y : x + y, res[-1]+[0], [0]+res[-1])))
return res[:numRows]
| PYTHON | {
"starter_code": "\nclass Solution:\n def generate(self, numRows: int) -> List[List[int]]:\n ",
"url": "https://leetcode.com/problems/pascals-triangle/"
} | |
d8698 | test | # Enter your code here. Read input from STDIN. Print output to STDOUT
import re
n=int(input())
ar=[]
for i in range(0,n):
s=input()
t=re.search(r"^[a-zA-Z][\w-]*@[a-zA-Z0-9]+\.[a-zA-Z]{1,3}$",s)
if t:
ar.append(s)
ar.sort()
print(ar)
| PYTHON | {
"starter_code": "\ndef fun(s):\n # return True if s is a valid email, else return False\n\ndef filter_mail(emails):\n return list(filter(fun, emails))\n\nif __name__ == '__main__':\n n = int(input())\n emails = []\n for _ in range(n):\n emails.append(input())\n\nfiltered_emails = filter_mail(emails)\nfiltered_emails.sort()\nprint(filtered_emails)",
"url": "https://www.hackerrank.com/challenges/validate-list-of-email-address-with-filter/problem"
} | |
d8699 | test | # Enter your code here. Read input from STDIN. Print output to STDOUT
def sqr(a):
return a*a*a
n=int(input())
if(n==0):
print("[]")
elif(n==1):
print("[0]")
else:
ar=[0]*n
ar[0]=0
ar[1]=1
for i in range(2,n):
ar[i]=ar[i-1]+ar[i-2]
ar=list(map(sqr,ar))
print(ar)
| PYTHON | {
"starter_code": "\ncube = lambda x: # complete the lambda function \n\ndef fibonacci(n):\n # return a list of fibonacci numbers\n\nif __name__ == '__main__':\n n = int(input())\n print(list(map(cube, fibonacci(n))))",
"url": "https://www.hackerrank.com/challenges/map-and-lambda-expression/problem"
} | |
d8700 | test | # Enter your code here. Read input from STDIN. Print output to STDOUT
xml_str=""
n=int(input())
for i in range(0,n):
tmp_str=input()
xml_str=xml_str+tmp_str
import xml.etree.ElementTree as etree
tree = etree.ElementTree(etree.fromstring(xml_str))
root=tree.getroot()
ar=[]
def cnt_node(node):
return max( [0] + [cnt_node(child)+1 for child in node])
cnt=cnt_node(root)
print(cnt)
| PYTHON | {
"starter_code": "\nimport xml.etree.ElementTree as etree\n\nmaxdepth = 0\ndef depth(elem, level):\n global maxdepth\n # your code goes here\n\nif __name__ == '__main__':\n n = int(input())\n xml = \"\"\n for i in range(n):\n xml = xml + input() + \"\\n\"\n tree = etree.ElementTree(etree.fromstring(xml))\n depth(tree.getroot(), -1)\n print(maxdepth)",
"url": "https://www.hackerrank.com/challenges/xml2-find-the-maximum-depth/problem"
} |