Dataset Viewer
Auto-converted to Parquet
id
stringlengths
10
10
dataset
stringclasses
1 value
language
stringclasses
1 value
code
stringlengths
26
3.54k
test_IO
list
s752993784
codenet
Python
s = list(input()) mods = [0]*(len(s)) countRemainder = [0] * 2019 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 cnt = sum( int(countRemainder[i] * (countRemainder[i] - 1) / 2) for i in range(2019) ) print(cnt)
[ { "input": "1817181712114\n", "output": "3\n" } ]
s199418121
codenet
Python
A, B = input().split() A = int(A) B = int(B.replace(".", "")) print(A * B // 100)
[ { "input": "198 1.10\n", "output": "217\n" } ]
s537584449
codenet
Python
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)
[ { "input": "15\n", "output": "6\n" } ]
s043545989
codenet
Python
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")
[ { "input": "3\n1 2 3\n", "output": "Yes\n" } ]
s609392609
codenet
Python
n = int(input()) t = list(map(int, input().split())) m = int(input()) for _ in range(m): p, x = map(int, input().split()) s = sum(x if j == p-1 else t[j] for j in range(len(t))) print(s)
[ { "input": "3\n2 1 4\n2\n1 1\n2 3\n", "output": "6\n9\n" } ]
s310981504
codenet
Python
a, b = map(int, input().split()) if a <= b: print(a) else: print(a-1)
[ { "input": "5 5\n", "output": "5\n" } ]
s419623944
codenet
Python
N, R = map(int, input().split()) if N >= 10: print(R) else: print(R+100*(10-N))
[ { "input": "2 2919\n", "output": "3719\n" } ]
s546174362
codenet
Python
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))
[ { "input": "3 3\n2 13 8\n", "output": "9\n" } ]
s908812767
codenet
Python
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 else: return False elif color[v] == -1: color[v] = 0 if color[i] else 1 elif color[v] == color[i]: return False else: continue dfs(v) return True if __name__ == '__main__': n = int(input()) V = {} for _ 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]) color = {i: -1 for i in range(1, n+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
[ { "input": "3\n1 2 2\n2 3 1\n", "output": "0\n0\n1\n" } ]
s251858505
codenet
Python
print(sum(map(lambda x, y: x == y, input(), input())))
[ { "input": "CSS\nCSR\n", "output": "2\n" } ]
s504709360
codenet
Python
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[: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)
[ { "input": "atcoder\n", "output": "atcoderb\n" } ]
s785944322
codenet
Python
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)
[ { "input": "30 100\n", "output": "100\n" } ]
s170274782
codenet
Python
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[:i+1]) + sum(groundlis[i:N+1]) ans.append(count) print(max(ans))
[ { "input": "5\n3 2 2 4 1\n1 2 2 2 1\n", "output": "14\n" } ]
s662673721
codenet
Python
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)
[ { "input": "10\n", "output": "5\n" } ]
s539244923
codenet
Python
n, k = map(int, input().split()) print(n+k if k % n == 0 else k-n)
[ { "input": "4 12\n", "output": "16\n" } ]
s790754864
codenet
Python
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): ans = 0 if N - K + 1 < i else fact(R+1, i)*fact(K-1, i-1) print(int(ans) % mod)
[ { "input": "5 3\n", "output": "3\n6\n1\n" } ]
s636719275
codenet
Python
s = input() t = input() def check(a, b): return sum(i != j for i, j in zip(a, b)) 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)
[ { "input": "cabacc\nabc\n", "output": "1\n" } ]
s240532461
codenet
Python
N, L = map(int, input().split()) aji = [L+i-1 for i in range(1, N+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))
[ { "input": "5 2\n", "output": "18\n" } ]
s828550015
codenet
Python
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)): pq[i] = max(pq[i], r[i]) print(sum(pq))
[ { "input": "1 2 2 2 1\n2 4\n5 1\n3\n", "output": "12\n" } ]
s225615697
codenet
Python
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]))
[ { "input": "3\n2 2 4\n", "output": "4 0 4\n" } ]
s846046431
codenet
Python
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')
[ { "input": "4 1\n5 4 2 1\n", "output": "Yes\n" } ]
s462546732
codenet
Python
a, b = input().split(" ") a = int(a) b = int(b) if a <= b: print(a) else: print(a-1)
[ { "input": "5 5\n", "output": "5\n" } ]
s131946120
codenet
Python
n = int(input()) print(len({input() for _ in range(n)}))
[ { "input": "4\n10\n8\n8\n6\n", "output": "3\n" } ]
s016605598
codenet
Python
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))
[ { "input": "4\n1 4 2\n2\n1 1 -8\n2\n", "output": "4 2\n1 -3\n" } ]
s441028271
codenet
Python
(a, b, c, k) = list(map(int, input().split())) if k % 2 == 0: print(a-b) else: print(b-a)
[ { "input": "1 2 3 1\n", "output": "1\n" } ]
s269975433
codenet
Python
from itertools import combinations_with_replacement import sys def LI(): return map(int, sys.stdin.readline().rstrip().split()) N, M, Q = LI() Q_groups = [[*LI()] for _ in range(Q)] max_score = 0 for p in combinations_with_replacement(range(1, M + 1), r=N): temp_score = sum(q[3] for q in Q_groups if p[q[1] - 1] - p[q[0] - 1] == q[2]) max_score = max(max_score, temp_score) print(max_score)
[ { "input": "3 4 3\n1 3 3 100\n1 2 2 10\n2 3 2 10\n", "output": "110\n" } ]
s949655009
codenet
Python
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) elif 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))))
[ { "input": "575\n", "output": "4\n" } ]
s316832655
codenet
Python
a, b, c = map(int, input().split()) print(int((a*b)/2))
[ { "input": "3 4 5\n", "output": "6\n" } ]
s103029464
codenet
Python
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])
[ { "input": "3\n1 0 0\n", "output": "1\n1\n" } ]
s759547301
codenet
Python
S = input() if S == 'Sunny': print('Cloudy') if S == 'Cloudy': print('Rainy') if S == 'Rainy': print('Sunny')
[ { "input": "Sunny\n", "output": "Cloudy\n" } ]
s961772658
codenet
Python
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])
[ { "input": "a\n", "output": "b\n" } ]
s018260659
codenet
Python
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')
[ { "input": "10\n", "output": "Yes\n" } ]
s826716211
codenet
Python
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] != '?': break t_i += 1 else: break first -= 1 end -= 1 else: print('UNRESTORABLE') exit(0) ans = copy.deepcopy(S_d) for t_i, i in enumerate(range(first, end+1)): ans[i] = T[t_i] ans = ''.join(ans).replace('?', 'a') print(ans) if __name__ == '__main__': solve()
[ { "input": "?tc????\ncoder\n", "output": "atcoder\n" } ]
s353603279
codenet
Python
X = int(input()) h = X // 500 a = (X % 500) // 5 y = h * 1000 + a * 5 print(y)
[ { "input": "1024\n", "output": "2020\n" } ]
s663509070
codenet
Python
import math N, D = map(int, input().split()) mat = [[int(x) for x in input().split()] for _ in range(N)] 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)
[ { "input": "3 2\n1 2\n5 5\n-2 8\n", "output": "1\n" } ]
s000375264
codenet
Python
X, t = map(int, input().split()) answer = X - t if X > t else 0 print(answer)
[ { "input": "100 17\n", "output": "83\n" } ]
s522872163
codenet
Python
X, A = list(map(int, input().split())) if X < A: print(0) else: print(10)
[ { "input": "3 5\n", "output": "0\n" } ]
s997947249
codenet
Python
N, K = map(int, input().split()) if N % K == 0: print(0) else: print(1)
[ { "input": "7 3\n", "output": "1\n" } ]
s451465602
codenet
Python
n = int(input()) h = n // 3600 n %= 3600 m = n // 60 n %= 60 s = n print(f"{str(h)}:{str(m)}:{s}")
[ { "input": "46979\n", "output": "13:2:59\n" } ]
s760938927
codenet
Python
h, w, ka = map(int, input().split()) mat = [list(input()) for _ 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)
[ { "input": "2 3 2\n..#\n###\n", "output": "5\n" } ]
s621701371
codenet
Python
s = input() q = int(input()) qs = [input().split() for _ 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)
[ { "input": "a\n4\n2 1 p\n1\n2 2 c\n1\n", "output": "cpa\n" } ]
s875904659
codenet
Python
def bubbleSort(cards): n = len(cards) for i in range(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(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")
[ { "input": "5\nH4 C9 S4 D2 C3\n", "output": "D2 C3 H4 S4 C9\nStable\nD2 C3 S4 H4 C9\nNot stable\n" } ]
s706119740
codenet
Python
candy = sorted(map(int, input().split())) print("Yes" if candy[0]+candy[1] == candy[2] else "No")
[ { "input": "10 30 20\n", "output": "Yes\n" } ]
s636592395
codenet
Python
N = int(input()) A = list(map(int, input().split())) def main(): A.sort() ans = A[-1] - A[0] print(ans) if __name__ == "__main__": main()
[ { "input": "4\n1 4 6 3\n", "output": "5\n" } ]
s137613418
codenet
Python
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 = list(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(1 << (n+1)): ss = {li[i] for i in range(n) if (bit & (1 << i))} s.append(ss) return s def factorial(n): return 1 if n == 1 else 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')
[ { "input": "5\n2 6 1 4 5\n", "output": "YES\n" } ]
s028530838
codenet
Python
x = input() if x.islower(): print("a") else: print("A")
[ { "input": "B\n", "output": "A\n" } ]
s273727373
codenet
Python
N = int(input()) A = list(map(int, input().split())) B = list(A) for count, i in enumerate(A, start=1): B[i-1] = count print(*B)
[ { "input": "3\n2 3 1\n", "output": "3 1 2\n" } ]
s404600540
codenet
Python
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()
[ { "input": "20 30 70 90\n3\n", "output": "150\n" } ]
s922746568
codenet
Python
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)
[ { "input": "4\nRRGB\n", "output": "1\n" } ]
s267172486
codenet
Python
h, a = map(int, input().strip().split()) ans = h // a ama = h % a if ama != 0: ans += 1 print(ans)
[ { "input": "10 4\n", "output": "3\n" } ]
s616346400
codenet
Python
def atc_079a(input_value: str) -> str: n = 3 for i in range(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))
[ { "input": "1118\n", "output": "Yes\n" } ]
s430322735
codenet
Python
n = int(input()) lst = [] pair = 0 for _ 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(list(range(tmp_cnt + 1))) tmp_cnt = 0 pre = i print(cnt)
[ { "input": "3\nacornistnt\npeanutbomb\nconstraint\n", "output": "1\n" } ]
s761121328
codenet
Python
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)
[ { "input": "4\n20 11 9 24\n", "output": "26 5 7 22\n" } ]
s031917494
codenet
Python
print('Christmas'+' Eve'*abs(int(input())-25))
[ { "input": "25\n", "output": "Christmas\n" } ]
s952264435
codenet
Python
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")
[ { "input": "41 2\n5 6\n", "output": "30\n" } ]
s986062252
codenet
Python
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) return a if b == 0 else 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)
[ { "input": "3 2\nacp\nae\n", "output": "6\n" } ]
s923405856
codenet
Python
while True: n = int(input()) if n == 0: break res = -1111111111 s = 0 for _ in range(n): a = int(input()) s = max(s + a, a) res = max(s, res) print(res)
[ { "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" } ]
s534639230
codenet
Python
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()
[ { "input": "4\n0 1 1 2\n", "output": "2\n" } ]
s817205687
codenet
Python
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)
[ { "input": "2 50\n6 10\n", "output": "2\n" } ]
s287369394
codenet
Python
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)
[ { "input": "2\n3 5 2\n4 5\n", "output": "9\n" } ]
s058944700
codenet
Python
import numpy as np n, k = map(int, input().split()) if n > k: tmp = n % k ans = k - tmp if tmp >= k - tmp else tmp elif n < k: ans = k - n if n >= k - n else n else: ans = 0 print(ans)
[ { "input": "7 4\n", "output": "1\n" } ]
s185068963
codenet
Python
a, b, c = map(int, input().split()) print("Yes" if a + b >= c else "No")
[ { "input": "50 100 120\n", "output": "Yes\n" } ]
s764169243
codenet
Python
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()
[ { "input": "3\n2 1 3\n", "output": "9\n" } ]
s768331281
codenet
Python
N, L = map(int, input().split()) S = [input().rstrip() for _ in range(N)] print(''.join(sorted(S)))
[ { "input": "3 3\ndxx\naxx\ncxx\n", "output": "axxcxxdxx\n" } ]
s993625131
codenet
Python
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)
[ { "input": "ATCODER\n", "output": "3\n" } ]
s315467749
codenet
Python
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 in [S[-1], 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)
[ { "input": "5\n1 2 3 4 5\n3\n3 4 1\n", "output": "3\n" } ]
s060838372
codenet
Python
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)
[ { "input": "3 1\nABC\n", "output": "aBC\n" } ]
s695100304
codenet
Python
n = int(input()) x = list(map(int, input().split())) x.reverse() print(*x)
[ { "input": "5\n1 2 3 4 5\n", "output": "5 4 3 2 1\n" } ]
s831456551
codenet
Python
A, B = map(int, input().split()) print(A*B)
[ { "input": "2 5\n", "output": "10\n" } ]
s951065247
codenet
Python
N, A, B, C = map(int, input().split()) l = [int(input()) for _ 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))
[ { "input": "5 100 90 80\n98\n40\n30\n21\n80\n", "output": "23\n" } ]
s542358243
codenet
Python
N = int(input()) if N % 9 == 0: print('Yes') else: print('No')
[ { "input": "123456789\n", "output": "Yes\n" } ]
s031459110
codenet
Python
N = int(input()) c = input() num_w = c.count("W") num_r = N - num_w comp = "R"*num_r + "W"*num_w ans = sum(bool(c[i] != comp[i]) for i in range(num_r)) ans = min(num_w, num_r, ans) print(ans)
[ { "input": "4\nWWRR\n", "output": "2\n" } ]
s681105182
codenet
Python
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()
[ { "input": "5\n6 9 4 2 11\n", "output": "11 6\n" } ]
s838619850
codenet
Python
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 = sum(bool(T[j] != S_2[j]) for j in range(M)) ans = min(ans, cnt) print(ans)
[ { "input": "cabacc\nabc\n", "output": "1\n" } ]
s087080706
codenet
Python
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:])))
[ { "input": "5 3 3\n1 2 4\n", "output": "1\n" } ]
s733189960
codenet
Python
def main(): n = int(input()) sdic = {} for _ in range(n): s = list(sorted(input().strip())) s = ''.join(s) if s in sdic: sdic[s] += 1 else: sdic[s] = 1 ans = sum(v*(v-1)//2 for v in sdic.values()) print(ans) if __name__ == '__main__': main()
[ { "input": "3\nacornistnt\npeanutbomb\nconstraint\n", "output": "1\n" } ]
s855969677
codenet
Python
s = input() if s == 'RRR': print(3) elif s == 'SSS': print(0) elif s in ['RRS', 'SRR']: print(2) else: print(1)
[ { "input": "RRS\n", "output": "2\n" } ]
s238775098
codenet
Python
n = int(input()) res = 0 for _ in range(n): x, u = list(input().split()) res += float(x) * 380000 if u == "BTC" else int(x) print(res)
[ { "input": "2\n10000 JPY\n0.10000000 BTC\n", "output": "48000.0\n" } ]
s101447419
codenet
Python
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()
[ { "input": "4\n3 1 3 2\n", "output": "1\n" } ]
s060251920
codenet
Python
def main(): a, b = map(int, input().split()) print(a*b) main()
[ { "input": "2 5\n", "output": "10\n" } ]
s960572618
codenet
Python
a, b, c = input().strip().split() if a == b == c: print("Yes") else: print("No")
[ { "input": "2 2 2\n", "output": "Yes\n" } ]
s091400419
codenet
Python
a, b = map(int, input().split()) lst = [a+b, a-b, a*b] print(max(lst))
[ { "input": "-13 3\n", "output": "-10\n" } ]
s764356857
codenet
Python
A, B = map(int, input().split()) min = B * 10 max = (B+1) * 10 - 1 ans = next((i for i in range(min, max+1) if int(i * 0.08) == A), -1) print(ans)
[ { "input": "2 2\n", "output": "25\n" } ]
s280552889
codenet
Python
N = int(input()) if N % 2 == 0: print(N//2) else: print(N//2+1)
[ { "input": "5\n", "output": "3\n" } ]
s827462150
codenet
Python
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]))
[ { "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" } ]
s225521100
codenet
Python
N, K = map(int, input().split()) A = [0 for _ in range(N)] for _ in range(K): d = int(input()) AA = list(map(int, input().split())) for j in range(d): A[AA[j] - 1] = 1 n = sum(bool(A[i] == 0) for i in range(N)) print(n)
[ { "input": "3 2\n2\n1 3\n1\n3\n", "output": "1\n" } ]
s683277023
codenet
Python
n, k = map(int, input().split()) li = sorted(map(int, input().split())) tmp = li[:k] print(sum(tmp))
[ { "input": "5 3\n50 100 80 120 80\n", "output": "210\n" } ]
s208095748
codenet
Python
A, B, C = map(int, input().split()) if B < C: print(0) elif A * C < B: print(C) else: print(B//A)
[ { "input": "2 11 4\n", "output": "4\n" } ]
s500828884
codenet
Python
n, a, b = map(int, input().split()) print(min(n * a, b))
[ { "input": "7 17 120\n", "output": "119\n" } ]
s975943078
codenet
Python
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 = {} 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()
[ { "input": "5 4\n1 4 2 3 5\n", "output": "4\n" } ]
s205112814
codenet
Python
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)
[ { "input": "4 2\n1 3\n2 4\n", "output": "2\n" } ]
s214672212
codenet
Python
nums = list(map(int, input().split(" "))) nums.sort(reverse=True) print(nums[0]*10+nums[1]+nums[2])
[ { "input": "1 5 2\n", "output": "53\n" } ]
s197514717
codenet
Python
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]))
[ { "input": "1 5 2\n", "output": "53\n" } ]
s267613210
codenet
Python
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 = [A[i+1]-A[i] for i in range(len(A)-1)] dist.append(K+A[0]-A[-1]) maxv = max(dist) print(sum(dist) - maxv) if __name__ == '__main__': main()
[ { "input": "20 3\n5 10 15\n", "output": "10\n" } ]
s813548165
codenet
Python
N = int(input()) S, T = input().split() char_lists = [] for i, char in enumerate(S): char_lists.extend((char, T[i])) print("".join(char_lists))
[ { "input": "2\nip cc\n", "output": "icpc\n" } ]
s869207096
codenet
Python
n = int(input()) s = input() cnt = 1 + sum(bool(s[i] != s[i+1]) for i in range(n-1)) print(cnt)
[ { "input": "10\naabbbbaaca\n", "output": "5\n" } ]
s025428739
codenet
Python
A, B = map(int, input().split()) lst = [A + B, A - B, A * B] print(max(lst))
[ { "input": "-13 3\n", "output": "-10\n" } ]
s491954463
codenet
Python
n, m = list(map(int, input().split())) a = [] b = [] for _ 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))
[ { "input": "4 3\n1 2\n2 3\n1 4\n", "output": "2\n2\n1\n1\n" } ]
s575946485
codenet
Python
a = [int(input()) for _ in range(5)] dic = { i: 0 if str(a[i])[-1] == "0" else int(str(a[i])[-1]) - 10 for i in range(5) } 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)
[ { "input": "29\n20\n7\n35\n120\n", "output": "215\n" } ]
s747093551
codenet
Python
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')
[ { "input": "3 2 10 20\n8 15 13\n16 22\n", "output": "No War\n" } ]
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
6