language
stringclasses 5
values | dataset
stringclasses 1
value | code
stringlengths 26
25k
| id
stringlengths 10
10
| test_IO
listlengths 1
1
|
---|---|---|---|---|
Python | codenet | s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0
m = 1
mod = 0
for i in range(len(s)):
mod += int(s[len(s) - i - 1]) * m
mod %= 2019
m *= 10
m %= 2019
countRemainder[mod] += 1
countRemainder[0] += 1
for i in range(2019):
cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)
print(cnt)
| s752993784 | [
{
"input": "1817181712114\n",
"output": "3\n"
}
] |
Python | codenet | A, B = input().split()
A = int(A)
B = int(B.replace(".", ""))
print(A * B // 100)
| s199418121 | [
{
"input": "198 1.10\n",
"output": "217\n"
}
] |
Python | codenet | a = int(input())
def func(a):
digits = []
temp = a
while temp != 0:
digits.append(temp % 10)
temp = int(temp/10)
result = sum(digits)
if result == 1:
print('10')
else:
print(result)
func(a)
| s537584449 | [
{
"input": "15\n",
"output": "6\n"
}
] |
Python | codenet | import collections
N = int(input())
a = list(map(int, input().split()))
B = collections.Counter(a)
k = list(B.keys())
v = list(B.values())
if len(B) == 3 and k[0] ^ k[1] ^ k[2] == 0 and v[0] == v[1] == v[2]:
print("Yes")
elif len(B) == 2 and 0 in k and (v[0] == 2*v[1] or v[1] == 2*v[0]):
print("Yes")
elif len(B) == 1 and 0 in k:
print("Yes")
else:
print("No")
| s043545989 | [
{
"input": "3\n1 2 3\n",
"output": "Yes\n"
}
] |
Python | codenet | n = int(input())
t = list(map(int, input().split()))
m = int(input())
for i in range(m):
p, x = map(int, input().split())
s = 0
for j in range(len(t)):
if j == p-1:
s += x
else:
s += t[j]
print(s)
| s609392609 | [
{
"input": "3\n2 1 4\n2\n1 1\n2 3\n",
"output": "6\n9\n"
}
] |
Python | codenet | a, b = map(int, input().split())
if a <= b:
print(a)
else:
print(a-1)
| s310981504 | [
{
"input": "5 5\n",
"output": "5\n"
}
] |
Python | codenet | N, R = map(int, input().split())
if N >= 10:
print(R)
else:
print(R+100*(10-N))
| s419623944 | [
{
"input": "2 2919\n",
"output": "3719\n"
}
] |
Python | codenet | N, M = map(int, input().split())
*A, = map(int, input().split())
A = sorted(A)
while M:
A[-1] //= 2
M -= 1
i = -2
while M and (-N <= i and A[i] >= A[-1]):
A[i] //= 2
M -= 1
i -= 1
A.sort()
print(sum(A))
| s546174362 | [
{
"input": "3 3\n2 13 8\n",
"output": "9\n"
}
] |
Python | codenet | import sys
sys.setrecursionlimit(100000)
def dfs(i):
for v, w in V.get(i, []):
if (w % 2) == 0:
if color[v] == -1:
color[v] = color[i]
elif color[v] == color[i]:
continue
elif color[v] != color[i]:
return False
else:
if color[v] == -1:
color[v] = 0 if color[i] else 1
elif color[v] == color[i]:
return False
elif color[v] != color[i]:
continue
dfs(v)
return True
if __name__ == '__main__':
n = int(input())
V = {}
color = {}
for i in range(1, n):
u, v, w = map(int, input().split())
if not V.get(u, False):
V[u] = [[v, w]]
else:
V[u].append([v, w])
if not V.get(v, False):
V[v] = [[u, w]]
else:
V[v].append([u, w])
for i in range(1, n+1):
color[i] = -1
while True:
i = 0
for j in range(1, n+1):
if color[j] == -1:
i = j
color[i] = 0
break
if i == 0:
for j in range(1, n+1):
print(color[j])
break
else:
if not dfs(i):
print('No')
break
| s908812767 | [
{
"input": "3\n1 2 2\n2 3 1\n",
"output": "0\n0\n1\n"
}
] |
Python | codenet | print(sum(map(lambda x, y: x == y, input(), input())))
| s251858505 | [
{
"input": "CSS\nCSR\n",
"output": "2\n"
}
] |
Python | codenet | s = input()
if len(s) < 26:
for i in range(26):
c = chr(ord("a")+i)
if c not in s:
print(s+c)
exit()
else:
for i in reversed(range(1, 26)):
if s[i-1] < s[i]:
s1 = s[0:i-1]
for j in range(26):
c = chr(ord("a")+j)
if c > s[i-1] and c not in s1:
print(s1+c)
exit()
print(-1)
| s504709360 | [
{
"input": "atcoder\n",
"output": "atcoderb\n"
}
] |
Python | codenet | import sys
input = sys.stdin.readline
a, b = map(int, input().split())
if a >= 13:
print(b)
elif a >= 6:
print(int(b/2))
else:
print(0)
| s785944322 | [
{
"input": "30 100\n",
"output": "100\n"
}
] |
Python | codenet | N = int(input())
A = []
for _ in range(2):
s = list(map(int, input().split()))
A.append(s)
ans = []
count = 0
for i in range(N):
baselis = A[0]
groundlis = A[1]
count = 0
count = count + sum(baselis[0:i+1]) + sum(groundlis[i:N+1])
ans.append(count)
print(max(ans))
| s170274782 | [
{
"input": "5\n3 2 2 4 1\n1 2 2 2 1\n",
"output": "14\n"
}
] |
Python | codenet | import sys
input = sys.stdin.readline
n = int(input())
ans = 10 ** 18
for i in range(1, int(n ** (1 / 2)) + 2):
if n % i != 0:
continue
j = n // i
ans = min(ans, i + j - 2)
print(ans)
| s662673721 | [
{
"input": "10\n",
"output": "5\n"
}
] |
Python | codenet | n, k = map(int, input().split())
print(n+k if k % n == 0 else k-n)
| s539244923 | [
{
"input": "4 12\n",
"output": "16\n"
}
] |
Python | codenet | import math
N, K = (int(x) for x in input().split())
R = N - K
mod = 10**9 + 7
def fact(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(1, K+1):
if N - K + 1 < i:
ans = 0
else:
ans = fact(R+1, i)*fact(K-1, i-1)
print(int(ans) % mod)
| s790754864 | [
{
"input": "5 3\n",
"output": "3\n6\n1\n"
}
] |
Python | codenet | s = input()
t = input()
def check(a, b):
s = 0
for i, j in zip(a, b):
s += i != j
return s
ans = 10**6
for i in range(len(s)):
a = s[i:]
if len(a) >= len(t):
ans = min(ans, check(t, a[:len(t)]))
print(ans)
| s636719275 | [
{
"input": "cabacc\nabc\n",
"output": "1\n"
}
] |
Python | codenet | N, L = map(int, input().split())
aji = []
for i in range(1, N+1):
aji.append(L+i-1)
if min(aji) >= 0:
aji.pop(aji.index(min(aji)))
elif max(aji) <= 0:
aji.pop(aji.index(max(aji)))
else:
aji.pop(aji.index(min(aji, key=abs)))
print(sum(aji))
| s240532461 | [
{
"input": "5 2\n",
"output": "18\n"
}
] |
Python | codenet | x, y, a, b, c = map(int, input().split())
p = sorted([int(i) for i in input().split()], reverse=True)[:x]
q = sorted([int(i) for i in input().split()], reverse=True)[:y]
r = sorted([int(i) for i in input().split()], reverse=True)
pq = sorted(p+q)
for i in range(min(x+y, a+b, c)):
if pq[i] < r[i]:
pq[i] = r[i]
print(sum(pq))
| s828550015 | [
{
"input": "1 2 2 2 1\n2 4\n5 1\n3\n",
"output": "12\n"
}
] |
Python | codenet | n = int(input())
a = list(map(int, input().split()))
m1 = int(sum([a[i] * ((-1)**i) for i in range(n)]) / 2)
result = str(m1)
m = [None] * n
m[0] = m1
for i in range(1, n):
m[i] = a[i-1] - m[i-1]
print(' '.join([str(x*2) for x in m]))
| s225615697 | [
{
"input": "3\n2 2 4\n",
"output": "4 0 4\n"
}
] |
Python | codenet | import sys
N, M = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))
A.sort(reverse=True)
S = sum(A)
for a in A[:M]:
if a/S - 1/(4*M) < 0:
print('No')
break
else:
print('Yes')
| s846046431 | [
{
"input": "4 1\n5 4 2 1\n",
"output": "Yes\n"
}
] |
Python | codenet | a, b = input().split(" ")
a = int(a)
b = int(b)
if a <= b:
print(a)
else:
print(a-1)
| s462546732 | [
{
"input": "5 5\n",
"output": "5\n"
}
] |
Python | codenet | n = int(input())
print(len(set([input() for _ in range(n)])))
| s131946120 | [
{
"input": "4\n10\n8\n8\n6\n",
"output": "3\n"
}
] |
Python | codenet | import heapq
const = 0
left = []
right = []
q = int(input())
cnt = 0
left_sum = 0
right_sum = 0
for _ in range(q):
t = list(map(int, input().split()))
if t[0] == 1:
a, b = t[1:]
const += b
if cnt % 2 == 0:
if not right:
heapq.heappush(left, -a)
left_sum += a
cnt += 1
continue
c = heapq.heappop(right)
right_sum -= c
if a <= c:
heapq.heappush(left, -a)
heapq.heappush(right, c)
left_sum += a
right_sum += c
else:
heapq.heappush(left, -c)
heapq.heappush(right, a)
left_sum += c
right_sum += a
else:
c = heapq.heappop(left)
left_sum += c
if a <= -c:
heapq.heappush(left, -a)
heapq.heappush(right, -c)
left_sum += a
right_sum -= c
else:
heapq.heappush(left, c)
heapq.heappush(right, a)
left_sum -= c
right_sum += a
cnt += 1
else:
tmp = -left[0]
print(tmp, const - left_sum + right_sum + tmp * (cnt % 2))
| s016605598 | [
{
"input": "4\n1 4 2\n2\n1 1 -8\n2\n",
"output": "4 2\n1 -3\n"
}
] |
Python | codenet | (a, b, c, k) = list(map(int, input().split()))
if k % 2 == 0:
print(a-b)
else:
print(b-a)
| s441028271 | [
{
"input": "1 2 3 1\n",
"output": "1\n"
}
] |
Python | codenet | from itertools import combinations_with_replacement
import sys
def LI(): return map(int, sys.stdin.readline().rstrip().split())
N, M, Q = LI()
Q_groups = []
for _ in range(Q):
Q_groups.append([*LI()])
max_score = 0
for p in combinations_with_replacement(range(1, M + 1), r=N):
temp_score = 0
for q in Q_groups:
if p[q[1] - 1] - p[q[0] - 1] == q[2]:
temp_score += q[3]
max_score = max(max_score, temp_score)
print(max_score)
| s269975433 | [
{
"input": "3 4 3\n1 3 3 100\n1 2 2 10\n2 3 2 10\n",
"output": "110\n"
}
] |
Python | codenet | strn = input()
n = int(strn)
shichigolist = ["3", "5", "7"]
shichigo = [[] for _ in range(len(strn))]
for i in range(len(strn)):
if i == 0:
for j in shichigolist:
shichigo[i].append(j)
else:
for j in shichigo[i-1]:
for k in shichigolist:
shichigo[i].append(j+k)
target = len(strn)-1
for i in range(len(strn)):
for j in shichigo[i][:]:
if i == target:
if int(j) > n:
shichigo[target].remove(j)
elif j.count("3") == 0 or j.count("5") == 0 or j.count("7") == 0:
shichigo[target].remove(j)
else:
if j.count("3") == 0 or j.count("5") == 0 or j.count("7") == 0:
shichigo[i].remove(j)
print(sum([len(shichigo[i]) for i in range(len(strn))]))
| s949655009 | [
{
"input": "575\n",
"output": "4\n"
}
] |
Python | codenet | a, b, c = map(int, input().split())
print(int((a*b)/2))
| s316832655 | [
{
"input": "3 4 5\n",
"output": "6\n"
}
] |
Python | codenet | N = int(input())
A = list(map(int, input().split()))
B = [0] * N
for i in range(N - 1, -1, -1):
tmp_sum = 0
for j in range((i + 1) * 2 - 1, N, i + 1):
tmp_sum += B[j]
tmp_sum %= 2
B[i] = tmp_sum ^ A[i]
print(sum(B))
print(*[i + 1 for i, b in enumerate(B) if b == 1])
| s103029464 | [
{
"input": "3\n1 0 0\n",
"output": "1\n1\n"
}
] |
Python | codenet | S = input()
if S == 'Sunny':
print('Cloudy')
if S == 'Cloudy':
print('Rainy')
if S == 'Rainy':
print('Sunny')
| s759547301 | [
{
"input": "Sunny\n",
"output": "Cloudy\n"
}
] |
Python | codenet | s = input()
alphabets = ["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 i in range(len(alphabets)):
if alphabets[i] == s:
print(alphabets[i+1])
| s961772658 | [
{
"input": "a\n",
"output": "b\n"
}
] |
Python | codenet | N = int(input())
cnt = 1
while cnt <= 9:
if N % cnt == 0 and 1 <= N/cnt <= 9:
print('Yes')
break
else:
cnt += 1
else:
print('No')
| s018260659 | [
{
"input": "10\n",
"output": "Yes\n"
}
] |
Python | codenet | import copy
def solve():
S_d = list(input())
T = list(input())
end = len(S_d) - 1
first = end - len(T) + 1
while first >= 0:
t_i = 0
for s_i in range(first, end+1):
if T[t_i] != S_d[s_i] and S_d[s_i] != '?':
break
t_i += 1
else:
break
first -= 1
end -= 1
else:
print('UNRESTORABLE')
exit(0)
ans = copy.deepcopy(S_d)
t_i = 0
for i in range(first, end+1):
ans[i] = T[t_i]
t_i += 1
ans = ''.join(ans).replace('?', 'a')
print(ans)
if __name__ == '__main__':
solve()
| s826716211 | [
{
"input": "?tc????\ncoder\n",
"output": "atcoder\n"
}
] |
Python | codenet | X = int(input())
h = X // 500
a = (X % 500) // 5
y = h * 1000 + a * 5
print(y)
| s353603279 | [
{
"input": "1024\n",
"output": "2020\n"
}
] |
Python | codenet | import math
N, D = map(int, input().split())
mat = []
for d in range(N):
mat.append([int(x) for x in input().split()])
c = 0
for i in range(len(mat)-1):
for j in range(i+1, len(mat)):
dist = math.sqrt(sum([(x-y)**2 for x, y in zip(mat[i], mat[j])]))
if int(dist) == dist:
c += 1
print(c)
| s663509070 | [
{
"input": "3 2\n1 2\n5 5\n-2 8\n",
"output": "1\n"
}
] |
Python | codenet | X, t = map(int, input().split())
if X > t:
answer = X - t
elif X <= t:
answer = 0
print(answer)
| s000375264 | [
{
"input": "100 17\n",
"output": "83\n"
}
] |
Python | codenet | X, A = list(map(int, input().split()))
if X < A:
print(0)
else:
print(10)
| s522872163 | [
{
"input": "3 5\n",
"output": "0\n"
}
] |
Python | codenet | N, K = map(int, input().split())
if N % K == 0:
print(0)
else:
print(1)
| s997947249 | [
{
"input": "7 3\n",
"output": "1\n"
}
] |
Python | codenet | n = int(input())
h = int(n / 3600)
n %= 3600
m = int(n / 60)
n %= 60
s = int(n)
print(str(h) + ":" + str(m) + ":" + str(s))
| s451465602 | [
{
"input": "46979\n",
"output": "13:2:59\n"
}
] |
Python | codenet | h, w, ka = map(int, input().split())
mat = [list(input()) for i in range(h)]
ans = 0
for i in range(2**(h+w)):
b = bin(i)[2:].zfill(h+w)
rs = b[:h]
cs = b[h:]
ct = 0
for l in range(h):
for k in range(w):
if mat[l][k] == '#' and rs[l] == '0' and cs[k] == '0':
ct += 1
if ct == ka:
ans += 1
print(ans)
| s760938927 | [
{
"input": "2 3 2\n..#\n###\n",
"output": "5\n"
}
] |
Python | codenet | s = input()
q = int(input())
qs = [input().split() for i in range(q)]
n = False
left = right = ""
for operation in qs:
if operation[0] == '1':
n = not n
if operation[0] == '2':
t, f, c = operation
f = int(f)
if n:
f = 1 if f != 1 else 2
if f == 1:
left = c+left
elif f == 2:
right += c
s = left+s+right
print(s[::-1] if n else s)
| s621701371 | [
{
"input": "a\n4\n2 1 p\n1\n2 2 c\n1\n",
"output": "cpa\n"
}
] |
Python | codenet | def bubbleSort(cards):
n = len(cards)
for i in range(0, n):
for j in range(n-1, i, -1):
if int(cards[j][1]) < int(cards[j-1][1]):
cards[j], cards[j-1] = cards[j-1], cards[j]
print(" ".join(map(str, cards)))
def selectionSort(cards):
n = len(cards)
for i in range(0, n):
mini = i
for j in range(i, n):
if int(cards[j][1]) < int(cards[mini][1]):
mini = j
if mini != i:
cards[i], cards[mini] = cards[mini], cards[i]
print(" ".join(map(str, cards)))
n = int(input())
cards = input().split(" ")
cards2 = list(cards)
bubbleSort(cards)
print("Stable")
selectionSort(cards2)
if " ".join(map(str, cards2)) == " ".join(map(str, cards)):
print("Stable")
else:
print("Not stable")
| s875904659 | [
{
"input": "5\nH4 C9 S4 D2 C3\n",
"output": "D2 C3 H4 S4 C9\nStable\nD2 C3 S4 H4 C9\nNot stable\n"
}
] |
Python | codenet | candy = sorted(map(int, input().split()))
print("Yes" if candy[0]+candy[1] == candy[2] else "No")
| s706119740 | [
{
"input": "10 30 20\n",
"output": "Yes\n"
}
] |
Python | codenet | N = int(input())
A = list(map(int, input().split()))
def main():
A.sort()
ans = A[-1] - A[0]
print(ans)
if __name__ == "__main__":
main()
| s636592395 | [
{
"input": "4\n1 4 6 3\n",
"output": "5\n"
}
] |
Python | codenet | import sys
import math
from collections import defaultdict
from collections import deque
def load(vtype=int):
return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
return [vtype(v) for v in input().strip().split(seplator)]
def exit():
import sys
sys.exit(0)
def perm_sub(li, used):
if len(li) == len(used):
return [deque()]
k = []
for i in range(len(li)):
if i in used:
continue
used.add(i)
sub_list = perm_sub(li, used)
for sub in sub_list:
sub.appendleft(li[i])
k.extend(sub_list)
used.discard(i)
return k
def perm_li(li):
return perm_sub(li, set())
def perm_n(n):
return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
return sep.join([str(e) for e in li])
def li2n(li):
n, base = 0, 1
for i in range(len(li)-1, -1, -1):
n += li[i] * base
base *= 10
return n
def sli2ili(li):
return [int(s) for s in li]
def prime_list(n):
li = [i for i in range(2, n+1)]
for i in range(len(li)):
if li[i] >= int(math.sqrt(n)):
break
if li[i] == -1:
continue
for j in range(i+1, len(li)):
if li[j] % li[i] == 0:
li[j] = -1
return [n for n in li if n != -1]
def gcd(a, b):
a, b = max(a, b), min(a, b)
while True:
r = a % b
if r == 0:
return b
a, b = b, r
def lcm(a, b):
return int(a * b / gcd(a, b))
def all_subset(li):
s = []
n = len(li)
for bit in range(0, (1 << (n+1))):
ss = set()
for i in range(0, n):
if (bit & (1 << i)):
ss.add(li[i])
s.append(ss)
return s
def factorial(n):
if n == 1:
return 1
return n * factorial(n-1)
def mCn(m, n):
def factorial_ntimes(m, n):
r = 1
while n:
r *= m
m -= 1
n -= 1
return r
return int(factorial_ntimes(m, n) / factorial(n))
n = load()
A = load_list()
if n == len(set(A)):
print('YES')
else:
print('NO')
| s137613418 | [
{
"input": "5\n2 6 1 4 5\n",
"output": "YES\n"
}
] |
Python | codenet | x = input()
if x.islower():
print("a")
else:
print("A")
| s028530838 | [
{
"input": "B\n",
"output": "A\n"
}
] |
Python | codenet | N = int(input())
A = list(map(int, input().split()))
B = list(A)
count = 1
for i in A:
B[i-1] = count
count += 1
print(*B)
| s273727373 | [
{
"input": "3\n2 3 1\n",
"output": "3 1 2\n"
}
] |
Python | codenet | def main():
q, h, s, d = map(int, input().split())
n = int(input())
min_1 = min(q*4, h*2, q*2+h, s)
min_2 = min(min_1*2, d)
print((n % 2)*min_1 + (n // 2)*min_2)
if __name__ == '__main__':
main()
| s404600540 | [
{
"input": "20 30 70 90\n3\n",
"output": "150\n"
}
] |
Python | codenet | n = int(input())
s = input()
r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')
ans = r_cnt * g_cnt * b_cnt
for i in range(n):
for d in range(n):
j = i + d
k = j + d
if k >= n:
break
if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
ans -= 1
print(ans)
| s922746568 | [
{
"input": "4\nRRGB\n",
"output": "1\n"
}
] |
Python | codenet | h, a = map(int, input().strip().split())
ans = h // a
ama = h % a
if ama != 0:
ans += 1
print(ans)
| s267172486 | [
{
"input": "10 4\n",
"output": "3\n"
}
] |
Python | codenet | def atc_079a(input_value: str) -> str:
n = 3
for i in range(0, len(input_value) + 1 - n):
for j in range(1, n):
if input_value[i] != input_value[i + j]:
break
if j == n - 1:
return "Yes"
return "No"
input_value = input()
print(atc_079a(input_value))
| s616346400 | [
{
"input": "1118\n",
"output": "Yes\n"
}
] |
Python | codenet | n = int(input())
lst = []
pair = 0
for i in range(n):
st = ''.join(sorted(list(input())))
lst.append(st)
lst = sorted(lst)
lst += ['end']
pre = ''
tmp_cnt = 0
cnt = 0
for i in lst:
if i == pre:
tmp_cnt += 1
else:
cnt += sum([j for j in range(tmp_cnt + 1)])
tmp_cnt = 0
pre = i
print(cnt)
| s430322735 | [
{
"input": "3\nacornistnt\npeanutbomb\nconstraint\n",
"output": "1\n"
}
] |
Python | codenet | N = int(input())
A = list(map(int, input().split()))
s = A[0] ^ A[1]
for i in range(2, N):
s = s ^ A[i]
B = [0]*N
for i in range(N):
B[i] = s ^ A[i]
L = [str(a) for a in B]
L = " ".join(L)
print(L)
| s761121328 | [
{
"input": "4\n20 11 9 24\n",
"output": "26 5 7 22\n"
}
] |
Python | codenet | print('Christmas'+' Eve'*abs(int(input())-25))
| s031917494 | [
{
"input": "25\n",
"output": "Christmas\n"
}
] |
Python | codenet | N, M = map(int, input().split())
A = map(int, input().split())
A_sum = sum(A)
print(N - A_sum if N - A_sum >= 0 else "-1")
| s952264435 | [
{
"input": "41 2\n5 6\n",
"output": "30\n"
}
] |
Python | codenet | from sys import stdin
def il(func=int): return list(map(func, stdin.readline().rstrip().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]
def gcd(a, b):
if a < b:
return gcd(b, a)
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
return a * b // gcd(a, b)
n, m = il()
s = input()
t = input()
aa = gcd(n, m)
bb = lcm(n, m)
cc = aa // bb
for i in range(aa):
if s[n//aa*i] != t[m//aa*i]:
print(-1)
exit()
print(bb)
| s986062252 | [
{
"input": "3 2\nacp\nae\n",
"output": "6\n"
}
] |
Python | codenet | while True:
n = int(input())
if n == 0:
break
res = -1111111111
s = 0
for i in range(n):
a = int(input())
s = max(s + a, a)
res = max(s, res)
print(res)
| s923405856 | [
{
"input": "7\n-5\n-1\n6\n4\n9\n-6\n-7\n13\n1\n2\n3\n2\n-2\n-1\n1\n2\n3\n2\n1\n-2\n1\n3\n1000\n-200\n201\n0\n",
"output": "19\n14\n1001\n"
}
] |
Python | codenet | from collections import Counter
def solve():
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
if D[0] != 0:
print(0)
return
cnt = Counter(D)
if cnt[0] > 1:
print(0)
return
res = 1
for i in range(1, max(D)+1):
if cnt[i-1] == 1:
continue
res *= cnt[i-1]**cnt[i] % mod
res %= mod
print(res)
solve()
| s534639230 | [
{
"input": "4\n0 1 1 2\n",
"output": "2\n"
}
] |
Python | codenet | from functools import reduce
import math
def lcm(x, y):
return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm, numbers, 1)
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [a // 2 for a in A]
count_div_2 = None
for a in A:
cnt = 0
while a % 2 == 0:
a //= 2
cnt += 1
if count_div_2 is None:
count_div_2 = cnt
elif cnt != count_div_2:
print(0)
exit()
my_lcm = lcm_list(A)
if my_lcm > M:
print(0)
exit()
tmp = M // my_lcm
ans = (tmp + 1) // 2
print(ans)
| s817205687 | [
{
"input": "2 50\n6 10\n",
"output": "2\n"
}
] |
Python | codenet | N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
ans = 0
for i in range(N):
d = min(A[i], B[i])
ans += d
A[i] -= d
B[i] -= d
d = min(A[i + 1], B[i])
ans += d
A[i + 1] -= d
B[i] -= d
print(ans)
| s287369394 | [
{
"input": "2\n3 5 2\n4 5\n",
"output": "9\n"
}
] |
Python | codenet | import numpy as np
n, k = map(int, input().split())
if n > k:
tmp = n % k
if tmp >= k - tmp:
ans = k - tmp
else:
ans = tmp
elif n < k:
if n >= k - n:
ans = k - n
else:
ans = n
else:
ans = 0
print(ans)
| s058944700 | [
{
"input": "7 4\n",
"output": "1\n"
}
] |
Python | codenet | a, b, c = map(int, input().split())
print("Yes" if a + b >= c else "No")
| s185068963 | [
{
"input": "50 100 120\n",
"output": "Yes\n"
}
] |
Python | codenet | import sys
input = sys.stdin.buffer.readline
def main():
class SegmentTree:
def __init__(self, size, default):
self.size = 2**(size-1).bit_length()
self.default = default
self.seg = [default]*(2*self.size-1)
def segfunc(self, x, y):
return max(x, y)
def update(self, k, x):
k += self.size-1
self.seg[k] = x
while k:
k = (k-1)//2
self.seg[k] = self.segfunc(self.seg[2*k+1], self.seg[2*k+2])
def query(self, p, q):
if q <= p:
return self.default
p += self.size-1
q += self.size-2
ret = self.default
while q-p > 1:
if p & 1 == 0:
ret = self.segfunc(ret, self.seg[p])
if q & 1 == 1:
ret = self.segfunc(ret, self.seg[q])
q -= 1
p = p//2
q = (q-1)//2
ret = self.segfunc(self.segfunc(ret, self.seg[p]), self.seg[q])
return ret
def seg_print(self):
print(self.seg)
N = int(input())
a = list(map(int, input().split()))
ans = [i+1 for i in range(N)]
left_seg = SegmentTree(N, 0)
for i, num in enumerate(a):
ans[num-1] *= i + 1 - left_seg.query(0, num)
left_seg.update(num-1, i+1)
right_seg = SegmentTree(N, 0)
for i, num in enumerate(a[::-1]):
ans[num-1] *= i + 1 - right_seg.query(0, num)
right_seg.update(num-1, i+1)
print(sum(ans))
if __name__ == "__main__":
main()
| s764169243 | [
{
"input": "3\n2 1 3\n",
"output": "9\n"
}
] |
Python | codenet | N, L = map(int, input().split())
S = [input().rstrip() for _ in range(N)]
print(''.join(sorted(S)))
| s768331281 | [
{
"input": "3 3\ndxx\naxx\ncxx\n",
"output": "axxcxxdxx\n"
}
] |
Python | codenet | S = list(input())
count = 0
record = 0
for i in range(len(S)):
if S[i] == "A" or S[i] == "C" or S[i] == "G" or S[i] == "T":
count += 1
else:
if count > record:
record = count
count = 0
if count > record:
record = count
print(record)
| s993625131 | [
{
"input": "ATCODER\n",
"output": "3\n"
}
] |
Python | codenet | n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
ans = 0
for i in T:
if i == S[-1] or i == S[0]:
ans += 1
else:
left = 0
right = n-1
while right-left > 1:
mid = (left+right)//2
if S[mid] == i:
ans += 1
break
elif S[mid] < i:
left = mid
else:
right = mid
print(ans)
| s315467749 | [
{
"input": "5\n1 2 3 4 5\n3\n3 4 1\n",
"output": "3\n"
}
] |
Python | codenet | N, K = map(int, input().split())
S = list(input())
if S[K-1] == "A":
S[K-1] = "a"
elif S[K-1] == "B":
S[K-1] = "b"
else:
S[K-1] = "c"
ans = "".join(S)
print(ans)
| s060838372 | [
{
"input": "3 1\nABC\n",
"output": "aBC\n"
}
] |
Python | codenet | n = int(input())
x = list(map(int, input().split()))
x.reverse()
print(*x)
| s695100304 | [
{
"input": "5\n1 2 3 4 5\n",
"output": "5 4 3 2 1\n"
}
] |
Python | codenet | A, B = map(int, input().split())
print(A*B)
| s831456551 | [
{
"input": "2 5\n",
"output": "10\n"
}
] |
Python | codenet | N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
def dfs(cur, a, b, c):
if cur == N:
return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else 10 ** 9
no_add = dfs(cur + 1, a, b, c)
add_a = dfs(cur + 1, a + l[cur], b, c) + 10
add_b = dfs(cur + 1, a, b + l[cur], c) + 10
add_c = dfs(cur + 1, a, b, c + l[cur]) + 10
return min(no_add, add_a, add_b, add_c)
print(dfs(0, 0, 0, 0))
| s951065247 | [
{
"input": "5 100 90 80\n98\n40\n30\n21\n80\n",
"output": "23\n"
}
] |
Python | codenet | N = int(input())
if N % 9 == 0:
print('Yes')
else:
print('No')
| s542358243 | [
{
"input": "123456789\n",
"output": "Yes\n"
}
] |
Python | codenet | N = int(input())
c = input()
num_w = c.count("W")
num_r = N - num_w
comp = "R"*num_r + "W"*num_w
ans = 0
for i in range(num_r):
if c[i] != comp[i]:
ans += 1
ans = min(num_w, num_r, ans)
print(ans)
| s031459110 | [
{
"input": "4\nWWRR\n",
"output": "2\n"
}
] |
Python | codenet | import sys
sys.setrecursionlimit(10**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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7
def main():
N = II()
a_li = LI()
a_li.sort()
n = a_li[-1]
dif = INF
prev_dif = dif
for a in a_li[:-1]:
dif = min(abs(n/2 - a), dif)
if dif != prev_dif:
r = a
prev_dif = dif
print(n, r)
main()
| s681105182 | [
{
"input": "5\n6 9 4 2 11\n",
"output": "11 6\n"
}
] |
Python | codenet | S = input()
T = input()
N = len(S)
M = len(T)
ans = M
for i in range(N-M+1):
S_2 = S[i:i+M]
cnt = 0
for j in range(M):
if T[j] != S_2[j]:
cnt += 1
ans = min(ans, cnt)
print(ans)
| s838619850 | [
{
"input": "cabacc\nabc\n",
"output": "1\n"
}
] |
Python | codenet | from bisect import bisect
n, m, x = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
ans = 0
i = bisect(a, x)
print(min(len(a[:i]), len(a[i:])))
| s087080706 | [
{
"input": "5 3 3\n1 2 4\n",
"output": "1\n"
}
] |
Python | codenet | def main():
n = int(input())
sdic = {}
for _ in range(n):
s = [_s for _s in sorted(input().strip())]
s = ''.join(s)
if s in sdic:
sdic[s] += 1
else:
sdic[s] = 1
ans = 0
for k, v in sdic.items():
ans += v*(v-1)//2
print(ans)
if __name__ == '__main__':
main()
| s733189960 | [
{
"input": "3\nacornistnt\npeanutbomb\nconstraint\n",
"output": "1\n"
}
] |
Python | codenet | s = input()
if s == 'RRR':
print(3)
elif s == 'SSS':
print(0)
elif s == 'RRS' or s == 'SRR':
print(2)
else:
print(1)
| s855969677 | [
{
"input": "RRS\n",
"output": "2\n"
}
] |
Python | codenet | n = int(input())
res = 0
for _ in range(n):
x, u = list(input().split())
if u == "BTC":
res += float(x) * 380000
else:
res += int(x)
print(res)
| s238775098 | [
{
"input": "2\n10000 JPY\n0.10000000 BTC\n",
"output": "48000.0\n"
}
] |
Python | codenet | import collections
def main():
n = int(input())
v = list(map(int, input().split()))
ve = []
vo = []
for i in range(n//2):
ve.append(v[2*i])
vo.append(v[2*i+1])
ce = collections.Counter(ve)
co = collections.Counter(vo)
ans = n
if ce.most_common()[0][0] != co.most_common()[0][0]:
ans = n-ce.most_common()[0][1]-co.most_common()[0][1]
elif len(ce) == 1 and len(co) == 1:
ans = n-ce.most_common()[0][1]
elif len(ce) == 1:
ans = n-ce.most_common()[0][1]-co.most_common()[1][1]
elif len(co) == 1:
ans = n-ce.most_common()[1][1]-co.most_common()[0][1]
else:
ans = min(n-ce.most_common()[0][1]-co.most_common()[1]
[1], n-ce.most_common()[1][1]-co.most_common()[0][1])
print(ans)
if __name__ == "__main__":
main()
| s101447419 | [
{
"input": "4\n3 1 3 2\n",
"output": "1\n"
}
] |
Python | codenet | def main():
a, b = map(int, input().split())
print(a*b)
main()
| s060251920 | [
{
"input": "2 5\n",
"output": "10\n"
}
] |
Python | codenet | a, b, c = input().strip().split()
if a == b and b == c:
print("Yes")
else:
print("No")
| s960572618 | [
{
"input": "2 2 2\n",
"output": "Yes\n"
}
] |
Python | codenet | a, b = map(int, input().split())
lst = [a+b, a-b, a*b]
print(max(lst))
| s091400419 | [
{
"input": "-13 3\n",
"output": "-10\n"
}
] |
Python | codenet | A, B = map(int, input().split())
min = B * 10
max = (B+1) * 10 - 1
ans = -1
for i in range(min, max+1):
if int(i * 0.08) == A:
ans = i
break
print(ans)
| s764356857 | [
{
"input": "2 2\n",
"output": "25\n"
}
] |
Python | codenet | N = int(input())
if N % 2 == 0:
print(N//2)
else:
print(N//2+1)
| s280552889 | [
{
"input": "5\n",
"output": "3\n"
}
] |
Python | codenet | import numpy as np
n = int(input())
A = np.zeros(n)
x, y, z = 1, 1, 1
while x**2 + y**2 + z**2 + x*y + y*z + z*x <= n:
while x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x <= n:
while x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x <= n:
i = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
A[i - 1] += 1
z += 1
z = 1
y += 1
y, z = 1, 1
x += 1
for i in range(n):
print(int(A[i]))
| s827462150 | [
{
"input": "20\n",
"output": "0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n"
}
] |
Python | codenet | N, K = map(int, input().split())
A = []
for i in range(N):
A.append(0)
for i in range(K):
d = int(input())
AA = list(map(int, input().split()))
for j in range(d):
A[AA[j] - 1] = 1
n = 0
for i in range(N):
if A[i] == 0:
n += 1
print(n)
| s225521100 | [
{
"input": "3 2\n2\n1 3\n1\n3\n",
"output": "1\n"
}
] |
Python | codenet | n, k = map(int, input().split())
li = list(map(int, input().split()))
li.sort()
tmp = li[:k]
print(sum(tmp))
| s683277023 | [
{
"input": "5 3\n50 100 80 120 80\n",
"output": "210\n"
}
] |
Python | codenet | A, B, C = map(int, input().split())
if B < C:
print(0)
elif A * C < B:
print(C)
else:
print(B//A)
| s208095748 | [
{
"input": "2 11 4\n",
"output": "4\n"
}
] |
Python | codenet | n, a, b = map(int, input().split())
print(min(n * a, b))
| s500828884 | [
{
"input": "7 17 120\n",
"output": "119\n"
}
] |
Python | codenet | import sys
from bisect import bisect_left
def solve():
input = sys.stdin.readline
N, K = map(int, input().split())
A = [(int(a) % K) - 1 for a in input().split()]
sum_A = [0 for _ in range(N + 1)]
count = 0
modK = dict()
modK[0] = [0]
for i in range(N):
sum_A[i + 1] = (sum_A[i] + A[i]) % K
if sum_A[i+1] not in modK:
modK[sum_A[i+1]] = [i + 1]
else:
modK[sum_A[i+1]].append(i+1)
for key in modK:
lenK = len(modK[key])
for i, a in enumerate(modK[key]):
count += bisect_left(modK[key], a + K, i, lenK) - i - 1
print(count)
return 0
if __name__ == "__main__":
solve()
| s975943078 | [
{
"input": "5 4\n1 4 2 3 5\n",
"output": "4\n"
}
] |
Python | codenet | n, m = map(int, input().split())
gate_cond = [[int(x) for x in input().split()] for _ in range(m)]
max_under_th = max([l[0] for l in gate_cond])
min_upper_th = min([l[1] for l in gate_cond])
if min_upper_th - max_under_th >= 0:
print(min_upper_th - max_under_th + 1)
else:
print(0)
| s205112814 | [
{
"input": "4 2\n1 3\n2 4\n",
"output": "2\n"
}
] |
Python | codenet | nums = list(map(int, input().split(" ")))
nums.sort(reverse=True)
print(nums[0]*10+nums[1]+nums[2])
| s214672212 | [
{
"input": "1 5 2\n",
"output": "53\n"
}
] |
Python | codenet | ABC = list(map(int, input().split()))
A = ABC[0]
B = ABC[1]
C = ABC[2]
print(max([10*A+B+C, 10*B+C+A, 10*C+A+B]))
| s197514717 | [
{
"input": "1 5 2\n",
"output": "53\n"
}
] |
Python | codenet | import sys
def input(): return sys.stdin.readline().rstrip()
def input_nums(): return list(map(int, input().split()))
def main():
K, N = input_nums()
A = input_nums()
dist = []
for i in range(len(A)-1):
dist.append(A[i+1]-A[i])
dist.append(K+A[0]-A[-1])
maxv = max(dist)
print(sum(dist) - maxv)
if __name__ == '__main__':
main()
| s267613210 | [
{
"input": "20 3\n5 10 15\n",
"output": "10\n"
}
] |
Python | codenet | N = int(input())
S, T = input().split()
char_lists = []
for i, char in enumerate(S):
char_lists.append(char)
char_lists.append(T[i])
print("".join(char_lists))
| s813548165 | [
{
"input": "2\nip cc\n",
"output": "icpc\n"
}
] |
Python | codenet | n = int(input())
s = input()
cnt = 1
for i in range(n-1):
if s[i] == s[i+1]:
continue
else:
cnt += 1
print(cnt)
| s869207096 | [
{
"input": "10\naabbbbaaca\n",
"output": "5\n"
}
] |
Python | codenet | A, B = map(int, input().split())
lst = []
lst.append(A+B)
lst.append(A-B)
lst.append(A*B)
print(max(lst))
| s025428739 | [
{
"input": "-13 3\n",
"output": "-10\n"
}
] |
Python | codenet | n, m = list(map(int, input().split()))
a = []
b = []
for i in range(m):
a1, b1 = list(map(int, input().split()))
a.append(a1)
b.append(b1)
for i in range(1, n+1):
print(a.count(i)+b.count(i))
| s491954463 | [
{
"input": "4 3\n1 2\n2 3\n1 4\n",
"output": "2\n2\n1\n1\n"
}
] |
Python | codenet | a = [int(input()) for i in range(5)]
dic = {}
for i in range(5):
if str(a[i])[-1] == "0":
dic.update({i: 0})
else:
dic.update({i: int(str(a[i])[-1]) - 10})
min_num = [i for i in dic if dic[i] == min(dic.values())][0]
a_sum = sum(a)
dic.pop(min_num)
print(abs(sum(dic.values())) + a_sum)
| s575946485 | [
{
"input": "29\n20\n7\n35\n120\n",
"output": "215\n"
}
] |
Python | codenet | N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
print('No War' if max(max(x), X) < min(min(y), Y) else 'War')
| s747093551 | [
{
"input": "3 2 10 20\n8 15 13\n16 22\n",
"output": "No War\n"
}
] |