iidai/codenet huggingface dataset:
Language: Python

I = input
s = I()*2
print(['No', 'Yes'][I() in s])


Example test case(s):
input: vanceknowledgetoad
advance

output: Yes
Language: Python

N, K = map(int, input().split())
score = list(map(int, input().split()))
mae = 0
usiro = K
for i in range(N-K):
    if score[mae] < score[usiro]:
        print('Yes')
    else:
        print('No')
    mae += 1
    usiro += 1


Example test case(s):
input: 5 3
96 98 95 100 20

output: Yes
No
Language: Python

N = str(input())

print("ABC"+N)


Example test case(s):
input: 100

output: ABC100
Language: Python

import math


def keta(s):
    if len(s) < 2:
        return int(s)
    n = sum(map(int, s))
    return keta(str(n))


def main():
    N = input()

    if keta(N) % 9 == 0:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Example test case(s):
input: 123456789

output: Yes
Language: Python

x = int(input())
a = int(input())
b = int(input())

print((x-a) % b)


Example test case(s):
input: 1234
150
100

output: 84
Language: Python

n = int(input())
r = 0
for ii in range(n):
    if (ii+1) % 3 != 0 and (ii+1) % 5 != 0:
        r += (ii+1)
print(r)


Example test case(s):
input: 15

output: 60
Language: Python

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False


def main():
    N = I()
    s = [0] * N
    t = [0] * N

    for i in range(N):
        s[i], t[i] = map(str, input().split())
        t[i] = int(t[i])

    X = input()
    xi = 0

    for i in range(N):
        if s[i] == X:
            xi = i
            break

    ans = 0

    for i in range(N):
        if xi < i:
            ans += t[i]

    print(ans)


if __name__ == '__main__':
    main()


Example test case(s):
input: 3
dwango 2
sixth 5
prelims 25
dwango

output: 30
Language: Python

n = int(input())

if n >= 1000:
    print('ABD')
else:
    print('ABC')


Example test case(s):
input: 999

output: ABC
Language: Python

W, H, x, y, r = map(int, input().split())

if x >= r and (W - r) >= x:
    if y >= r and (H - r) >= y:
        print('Yes')
    else:
        print('No')
else:
    print('No')


Example test case(s):
input: 5 4 2 2 1

output: Yes
Language: Python

N = int(input())
H = list(map(int, list(input().split())))

count_best, count_tmp = 0, 0

for i in range(N-1):
    if H[i] >= H[i+1]:
        count_tmp += 1
    else:
        if count_tmp > count_best:
            count_best = count_tmp

        count_tmp = 0

if count_tmp > count_best:
    count_best = count_tmp

print(count_best)


Example test case(s):
input: 5
10 4 8 7 3

output: 2
Language: Python

from itertools import chain
import numpy as np
import networkx as nx

X = iter(open(0).readlines())
h, w = map(int, next(X).split())
C = np.zeros((10, 10), dtype=int)
for i in range(10):
    for j, c in enumerate(map(int, next(X).split())):
        C[i, j] = c
A = np.zeros((h, w), dtype=int)
for i in range(h):
    for j, a in enumerate(map(int, next(X).split())):
        A[i, j] = a

G = nx.DiGraph(C)
d = {}
for i in range(10):
    if i == 1:
        continue
    d[i] = nx.shortest_path_length(G, i, 1, weight='weight')

s = 0
for a in chain.from_iterable(A):
    if a == -1 or a == 1:
        continue
    s += d[a]
print(s)


Example test case(s):
input: 2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8

output: 12
Language: Python

n, k = map(int, input().split())
a = [i for i in input()]
c = [0]*n
for i in range(1, n):
    if a[i] == "C" and a[i-1] == "A":
        c[i] = c[i-1]+1
    else:
        c[i] = c[i-1]
for w in range(k):
    l, r = map(int, input().split())
    print(c[r-1]-c[l-1])


Example test case(s):
input: 8 3
ACACTACG
3 7
2 3
1 8

output: 2
0
3
Language: Python

from collections import deque
from itertools import product, permutations, combinations
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))


def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def read_col(H):

    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_map_as(H, replace={'#': 1, '.': 0}, pad=None):

    if pad is None:
        ret = []
        for _ in range(H):
            ret.append([replace[s] for s in read()[:-1]])

    else:
        ret = [[pad] * (W + 2)]
        for _ in range(H):
            ret.append([pad] + [replace[s] for s in read()[:-1]] + [pad])
        ret.append([pad] * (W + 2))

    return ret


def grid_dijkstra(grid, si: int, sj: int):

    from heapq import heappop, heappush
    H = len(grid)
    W = len(grid[0])
    D = [[-1] * W for _ in [0] * H]
    que = [(0, si, sj)]
    while que:
        c, i, j = heappop(que)
        if D[i][j] != -1:
            continue
        D[i][j] = c
        for di, dj in product([-2, -1, 0, 1, 2], repeat=2):
            ni, nj = i + di, j + dj
            if not (0 <= ni < H and 0 <= nj < W) or D[ni][nj] != -1 or ni == nj == 0 or grid[ni][nj] == 1:
                continue
            if (di == 0 and abs(dj) == 1) or (dj == 0 and abs(di) == 1):
                nc = c
            else:
                nc = c + 1
            heappush(que, (nc, ni, nj))
    return D


MOD = 10**9 + 7
INF = 2**31


H, W = ints()
si, sj = mina(*ints())
ti, tj = mina(*ints())

S = read_map_as(H)
D = [[-1] * W for _ in [0] * H]
que = deque([(0, si, sj)])
while que:
    c, i, j = que.popleft()
    if D[i][j] != -1:
        continue
    D[i][j] = c
    for di, dj in product([-2, -1, 0, 1, 2], repeat=2):
        ni, nj = i + di, j + dj
        if not (0 <= ni < H and 0 <= nj < W) or D[ni][nj] != -1 or ni == nj == 0 or S[ni][nj] == 1:
            continue
        if (di == 0 and abs(dj) == 1) or (dj == 0 and abs(di) == 1):
            que.appendleft((c, ni, nj))
        else:
            que.append((c + 1, ni, nj))

print(D[ti][tj])


Example test case(s):
input: 4 4
1 1
4 4
..#.
..#.
.#..
.#..

output: 1
Language: Python

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
s = sum(a)/(4*m)
if a[m-1] >= s:
    print('Yes')
else:
    print('No')


Example test case(s):
input: 4 1
5 4 2 1

output: Yes
Language: Python

a, b = map(int, input().split())

if a % 3 == 0 or b % 3 == 0 or (a + b) % 3 == 0:
    print('Possible')
else:
    print('Impossible')


Example test case(s):
input: 4 5

output: Possible
Language: Python

n = int(input())
p = [int(x) for x in input().split()]
p_copy = p[:]

p.sort()

count = 0
for i in range(n):
    if p[i] != p_copy[i]:
        count += 1

if count == 0 or count == 2:
    print("YES")
else:
    print("NO")


Example test case(s):
input: 5
5 2 3 4 1

output: YES
Language: Python

N = int(input())
capacity_list = [int(input()) for _ in range(5)]
capacity_list.sort()
bottle_neck = capacity_list[0]
print(4+int((N+bottle_neck-1)/bottle_neck))


Example test case(s):
input: 5
3
2
4
3
5

output: 7
Language: Python

n = int(input())
ls = [list(map(int, input().split())) for i in range(n)]
ls = sorted(ls, key=lambda x: sum(x), reverse=True)
taka = sum([ls[i][0] for i in range(0, len(ls), 2)])
aoki = sum([ls[i][1] for i in range(1, len(ls), 2)])

print(taka-aoki)


Example test case(s):
input: 3
10 10
20 20
30 30

output: 20
Language: Python

n = int(input())
F = [tuple(map(int, input().split())) for _ in range(n)]
P = [tuple(map(int, input().split())) for _ in range(n)]
ans = -10 ** 18

for i in range(1, 2**10):
    tmp = 0
    lst = [0]*n
    for j in range(10):
        if (i >> j) & 1:
            for k in range(n):
                lst[k] += F[k][j]
    for k in range(n):
        tmp += P[k][lst[k]]
    ans = max(ans, tmp)


print(ans)


Example test case(s):
input: 1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2

output: 8
Language: Python

X, N = list(map(int, input().split()))
p = list(map(int, input().split()))

p.sort()

candidates = {}
for i in range(-1, 102):

    if i in p:
        continue

    if not (abs(X-i) in candidates.keys()):
        candidates[abs(X-i)] = [i]
    else:
        candidates[abs(X-i)].append(i)

smallest = min(candidates.keys())

minNum = min(candidates[smallest])

print(minNum)


Example test case(s):
input: 6 5
4 7 10 6 5

output: 8
Language: Python

from math import factorial as f

N = int(input())

primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
divs = []
for i in range(1, 101):
    tmp = [0 for _ in range(len(primes))]
    for j in range(len(primes)):
        p = primes[j]
        tmp[j] = 0
        while (i//p == i/p):
            i = i//p
            tmp[j] += 1
    divs.append(tmp)


divsum = [0 for _ in range(len(primes))]
for i in range(1, N+1):
    for j in range(len(primes)):
        divsum[j] += divs[i-1][j]


def num(n):
    return len(list(filter(lambda x: x >= n-1, divsum)))


ans = 0


ans += num(75)


ans += num(15)*(num(5)-1)


ans += num(25)*(num(3)-1)


ans += num(5) * (num(5)-1) * (num(3)-2) // 2
print(int(ans))


Example test case(s):
input: 9

output: 0
Language: Python

a, b, c, d, e = map(int, input().split())
print(15-a-b-c-d-e)


Example test case(s):
input: 0 2 3 4 5

output: 1
Language: Python

N = input()
if N == 0:
    print('Yes')
else:
    N = str(N)
    L = list(N)
    L = [int(s) for s in L]
    X = sum(L)
    if X % 9 == 0:
        print('Yes')
    else:
        print('No')


Example test case(s):
input: 123456789

output: Yes
Language: Python

from math import floor
from heapq import heappush, heappop
n, m = map(int, input().split())
a = []
for i in map(int, input().split()):
    heappush(a, -i)


def dis(x, y): return x // 2**y


for _ in range(m):
    heappush(a, -dis(-heappop(a), 1))
print(-sum(a))


Example test case(s):
input: 3 3
2 13 8

output: 9
Language: Python

import math

N = input()
XS = [int(i) for i in input().split()]

m = 9999999999
for i in range(1, 101):
    c = sum([(x - i) ** 2 for x in XS])
    if m > c:
        m = c

print(m)


Example test case(s):
input: 2
1 4

output: 5
Language: Python

n = int(input())
res = []
for i in range(n):
    a = input()
    res.append(a)
print(len(set(res)))


Example test case(s):
input: 3
apple
orange
apple

output: 2
Language: Python

N, M = map(int, input().split())

a = N * (N - 1) // 2
b = M * (M - 1) // 2

print(a + b)


Example test case(s):
input: 2 1

output: 1
Language: Python

d, g = list(map(int, input().split()))
pc = [list(map(int, input().split())) for _ in range(d)]

ans = float("inf")

for bit in range(1 << d):
    count = 0
    sum = 0
    nokori = set(range(1, d + 1))

    for i in range(d):
        if bit & (1 << i):
            sum += pc[i][0] * (i + 1) * 100 + pc[i][1]
            count += pc[i][0]
            nokori.discard(i + 1)

    if sum < g:
        use = max(nokori)
        n = min(pc[use-1][0], -(-(g - sum) // (use * 100)))
        count += n
        sum += n * use * 100

    if sum >= g:
        ans = min(ans, count)
print(ans)


Example test case(s):
input: 2 700
3 500
5 800

output: 3
Language: Python

a, b = map(int, input().split())


x = [a + b]

x.append(a - b)

x.append(a * b)
print(max(x))


Example test case(s):
input: 3 1

output: 4
Language: Python

n = int(input())
for i in range(1, 10 ** 5):
    if i * i > n:
        print((i-1) * (i-1))
        exit()


Example test case(s):
input: 10

output: 9
Language: Python

n = int(input())
s = input()

left = 0
for i in s:
    if i == ")":
        left += 1
    else:
        break

left1 = 0
right1 = 0

for i in range(left, n):
    if s[i] == "(":
        right1 += 1
    elif right1 > 0:
        right1 -= 1
    else:
        left1 += 1

left1 += left
for i in range(right1):
    s += ")"
for i in range(left1):
    s = "(" + s

print(s)


Example test case(s):
input: 3
())

output: (())
Language: Python

R = int(input())
G = int(input())
print(G*2-R)


Example test case(s):
input: 2002
2017

output: 2032
Language: Python

import bisect

N = int(input())
arr = [111, 222, 333, 444, 555, 666, 777, 888, 999]
ans_idx = bisect.bisect_left(arr, N)
print(arr[ans_idx])


Example test case(s):
input: 111

output: 111
Language: Python

import numpy
n = int(input())
a = []
for i in range(2):
    a.append(list(map(int, input().split())))
a[1] = a[1][::-1]
res_0 = numpy.cumsum(a[0])
res_1 = numpy.cumsum(a[1])
ans = 0
for i in range(n):
    check = res_0[i] + res_1[n-1-i]
    ans = max(ans, check)
print(ans)


Example test case(s):
input: 5
3 2 2 4 1
1 2 2 2 1

output: 14
Language: Python

N = int(input())
a = list(map(int, input().split()))
a.sort()

s = [ai for ai in a[N::2]]
print(sum(s))


Example test case(s):
input: 2
5 2 8 5 1 5

output: 10
Language: Python

n = int(input())
print(n**3)


Example test case(s):
input: 2

output: 8
Language: Python

N, T = map(int, input().split())
L = [[int(l) for l in input().split()] for _ in range(N)]

dp = [[0]*T for _ in range(N+1)]

for i in range(N):
    for j in range(T):
        if j < L[i][0]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-L[i][0]]+L[i][1])

used = []
B = dp[N][T-1]
j = T-1
for i in range(N-1, -1, -1):
    if B == dp[i][j]:
        continue
    B -= L[i][1]
    used.append(i)
    j -= L[i][0]

ans = dp[N][T-1]
c = 0
for i in range(N):
    if i in used:
        continue
    c = max(c, L[i][1])

print(ans+c)


Example test case(s):
input: 2 60
10 10
100 100

output: 110
Language: Python

n = int(input())
x = list(map(int, input().split()))
ans = 10**10
for i in range(101):
    tmp = [abs(i - x[j])**2 for j in range(n)]
    if sum(tmp) < ans:
        ans = sum(tmp)

print(ans)


Example test case(s):
input: 2
1 4

output: 5
Language: Python

N = int(input())
L = list(map(int, input().split()))

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            a = L[i]
            b = L[j]
            c = L[k]
            if a == b or b == c or c == a:
                continue
            if a+b > c and b+c > a and c+a > b:
                ans += 1

print(ans)


Example test case(s):
input: 5
4 4 9 7 5

output: 5
Language: Python

import sys
from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    S = SI()
    C = Counter(S)

    return 'Yes' if C['R'] > n - C['R'] else 'No'


print(main())


Example test case(s):
input: 4
RRBR

output: Yes
Language: Python

input = list(map(str, input().split()))
num = ''.join(input)

if (int(num) % 4 == 0):
    print('YES')
else:
    print('NO')


Example test case(s):
input: 4 3 2

output: YES
Language: Python

a, b = input().split()
if a < b:
    print("<")
elif a > b:
    print(">")
else:
    print("=")


Example test case(s):
input: A B

output: <
Language: Python

import math
N = int(input())
sqN = int(math.sqrt(N))
for i in range(sqN):
    if N % (sqN-i) == 0:
        print(int(N/(sqN-i)+sqN-i)-2)
        break


Example test case(s):
input: 10

output: 5
Language: Python

n = int(input())
a = list(map(int, input().split()))
below = 0
for i in range(n):
    below += 1/a[i]
print(1/below)


Example test case(s):
input: 2
10 30

output: 7.5
Language: Python

N = int(input())
A = [int(x) for x in input().split()]
ans = abs(A[-1])
A = [0]+A+[0]
diff = [0 for x in range(N)]
for i in range(1, N+1):
    dif = abs(A[i]-A[i-1])+abs(A[i]-A[i+1])-abs(A[i-1]-A[i+1])
    ans += abs(A[i]-A[i-1])
    diff[i-1] = dif

for i in range(N):
    print(ans-diff[i])


Example test case(s):
input: 3
3 5 -1

output: 12
8
10
Language: Python

s = list(str(input()))
s.sort()
if s[0] == s[1] and s[0] != s[2] and s[2] == s[3]:
    print("Yes")
else:
    print("No")


Example test case(s):
input: ASSA

output: Yes
Language: Python

A, B = map(int, input().split())

if (A+B) % 2 == 1:
    print('IMPOSSIBLE')
else:
    print((A+B)//2)


Example test case(s):
input: 2 16

output: 9
Language: Python

N = int(input())
Hs = list(map(int, input().split()))

ans = 0
maxH = 0
for H in Hs:
    if maxH <= H:
        ans += 1
        maxH = H

print(ans)


Example test case(s):
input: 4
6 5 6 8

output: 3
Language: Python

h, w = map(int, input().split())
l = []
for _ in range(h):
    a = list(map(str, input()))
    l.append(a)

tmp = 0

for i in range(h):
    for j in range(w):
        if l[i][j] == "#":
            if j < tmp:
                print("Impossible")
                exit()
            else:
                tmp = j


print("Possible")


Example test case(s):
input: 4 5
##...
.##..
..##.
...##

output: Possible
Language: Python

n = int(input())

if n % 1000 == 0:
    print(0)
else:
    print(1000 - n % 1000)


Example test case(s):
input: 1900

output: 100
Language: Python

def solver():
    N = int(input())
    action = []
    for i in range(N):
        action.append(list(map(int, input().split())))

    dp = [[0 for _ in range(3)] for _ in range(N)]

    for i in range(3):
        dp[0][i] = action[0][i]

    for i in range(1, N):
        dp[i][0] = max(dp[i-1][1] + action[i][0], dp[i-1][2] + action[i][0])
        dp[i][1] = max(dp[i-1][0] + action[i][1], dp[i-1][2] + action[i][1])
        dp[i][2] = max(dp[i-1][0] + action[i][2], dp[i-1][1] + action[i][2])
    print(max(dp[N-1]))


solver()


Example test case(s):
input: 3
10 40 70
20 50 80
30 60 90

output: 210
Language: Python

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ope = [list(map(int, input().split())) for _ in range(m)]
ope = sorted(ope, key=lambda x: x[1], reverse=True)
j = 0
for i in range(n):
    if a[i] < ope[j][1]:
        a[i] = ope[j][1]
        ope[j][0] -= 1
        if ope[j][0] == 0:
            j += 1
            if j == len(ope):
                break
    else:
        break
print(sum(a))


Example test case(s):
input: 3 2
5 1 4
2 3
1 5

output: 14
Language: Python

R = int(input())

if R < 1200:
    print("ABC")
elif R < 2800:
    print("ARC")
else:
    print("AGC")


Example test case(s):
input: 1199

output: ABC
Language: Python

A, B = [int(x) for x in input().split()]
if A < 10 and B < 10:
    print(A*B)
else:
    print(-1)


Example test case(s):
input: 2 5

output: 10
Language: Python

from operator import itemgetter


n, k = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n)]

info = sorted(info, key=itemgetter(1), reverse=True)

selected = info[0:k]
selected_only = []
selected_chohuku = []
unselected_only = []
memo = {}
for t, d in selected:
    if t not in memo:
        memo[t] = 1
        selected_only.append(d)
    else:
        selected_chohuku.append(d)

cnt_type = len(memo)
for t, d in info[k:]:
    if t not in memo:
        memo[t] = 1
        unselected_only.append(d)


sum_select = sum(selected_chohuku) + sum(selected_only)
ans = cnt_type*cnt_type + sum_select

unselected_only = unselected_only[::-1]
for i in range(min(len(selected_chohuku), len(unselected_only))):
    cnt_type += 1
    sum_select += unselected_only[-1]
    sum_select -= selected_chohuku[-1]
    del unselected_only[-1]
    del selected_chohuku[-1]
    tmp = cnt_type*cnt_type + sum_select
    ans = max(ans, tmp)
print(ans)


Example test case(s):
input: 5 3
1 9
1 7
2 6
2 5
3 1

output: 26
Language: Python

H = int(input())

count = 0


def dfs(h):
    if h == 1:
        return 1

    return dfs(h // 2) * 2 + 1


print(dfs(H))


Example test case(s):
input: 2

output: 3
Language: Python

A, B = map(int, input().split())
S = list(input())
if S[A] == '-' and S.count('-') == 1:
    print("Yes")
else:
    print("No")


Example test case(s):
input: 3 4
269-6650

output: Yes
Language: Python

n, k = map(int, input().split())
if k % 2 == 1:
    print((n//k)**3)
else:
    print((n//k)**3+((n+k//2)//k)**3)


Example test case(s):
input: 3 2

output: 9
Language: Java

import java.util.Scanner;

public class s780275612 {
    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int intA = sc.nextInt();

        double dbAncer = Math.pow(intA, 3);
        int intAncer = (int) dbAncer;
        System.out.println(intAncer);
    }
}


Example test case(s):
input: 2

output: 8