code1 stringlengths 16 427k | code2 stringlengths 16 427k | similar int64 0 1 | pair_id int64 2 181,637B ⌀ | question_pair_id float64 3.71M 180,629B ⌀ | code1_group int64 1 299 | code2_group int64 1 299 |
|---|---|---|---|---|---|---|
import math
import sys
sys.setrecursionlimit(10**9)
def comb(n, r): # 普通のcombination計算
if r < 0 or r > n:
return 0
else:
n1 = math.factorial(n)
n21 = math.factorial(n - r)
n22 = math.factorial(r)
ans = n1 // (n21 * n22)
return ans
"""
solve(i, k, smaller)
:= ... | N = int(input())
x = N // 100
y = N % 100
if y <= 5 * x:
print(1)
else:
print(0) | 0 | null | 101,213,204,357,720 | 224 | 266 |
a,b,c=map(int, input().split())
#たこ焼きが余るかの場合分け
if a%b==0:
Q=a//b
#ちょうど焼ききる
else:
Q=a//b+1
#余る
print(Q*c)#回数×時間
#完了
| N,X,T = map(int, input().split())
nf = float(N/X)
ni = int(N/X)
d = nf - ni
if d == 0:
ans = ni * T
else:
ans = (ni + 1) * T
print(ans) | 1 | 4,309,874,646,330 | null | 86 | 86 |
from functools import lru_cache
@lru_cache(maxsize=None)
def fib(n):
if n < 2:
return n
return fib(n-1) + fib(n-2)
class Fibonacci(object):
memo = [1, 1]
def get_nth(self, n):
if n < len(Fibonacci.memo):
return Fibonacci.memo[n]
# print('fib({0}) not found'.forma... | n = int(input().strip())
if n <= 1:
print(1)
raise SystemExit
prev1 = 1
prev2 = 1
for i in range(2, n+1):
fib = prev2 + prev1
prev2, prev1 = prev1, fib
print(fib) | 1 | 2,045,248,260 | null | 7 | 7 |
x = list(map(int,input().split()))
y = list(map(int,input().split()))
z = list(map(int,input().split()))
n = int(input())
for i in range(n):
b = int(input())
if b in x:
x[x.index(b)] = 'T'
if b in y:
y[y.index(b)] = 'T'
if b in z:
z[z.index(b)] = 'T'
if x[0] == 'T' and x[1] == 'T... | a = []
for _ in range(3):
a += list(map(int, input().split()))
n = int(input())
for _ in range(n):
b = int(input())
if b in a:
i = a.index(b)
a[i] = 0
if sum(a[0:3]) == 0 or sum(a[3:6]) == 0 or sum(a[6:]) == 0 \
or sum(a[0::3]) == 0 or sum(a[1::3]) == 0 or sum(a[2::3]) == 0 \
or sum(... | 1 | 60,125,664,331,040 | null | 207 | 207 |
N,D = map(int, input().split())
cnt = 0
for _ in range(N):
X,Y = map(int, input().split())
cnt += X*X + Y*Y <= D*D
print(cnt) | m = []
for _ in range(10):
r = int(input())
m.append(r)
m.sort()
print (m[9]);
print (m[8]);
print (m[7]); | 0 | null | 2,973,565,138,332 | 96 | 2 |
n = int(input())
n3 = n**3
print(n3) | import sys
x = int(sys.stdin.read())
print(x ** 3) | 1 | 274,990,610,908 | null | 35 | 35 |
N = int(input())
A = list(map(int,input().split()))
for a in A:
if a%2==0 and a%3!=0 and a%5!=0:
print("DENIED")
exit()
print("APPROVED") | D = int(input())
C = list(map(int, input().split()))
S = list(list(map(int, input().split())) for i in range(D))
T = list(int(input()) for i in range(D))
manzoku = 0
yasumi= [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
#1日目
for day in range(D):
yasumi = list(map(lambda x: x + 1, yasu... | 0 | null | 39,654,850,775,750 | 217 | 114 |
N, M = map(int, input().split())
l = [[] for _ in range(N)]
for i in range(M):
p, s = input().split()
l[int(p) - 1].append(s)
correct = 0
penalty = 0
for ll in l:
if 'AC' not in ll:
continue
correct += 1
penalty += ll.index('AC')
print(correct, penalty) | N,M=map(int,input().split())
L=[list(input().split()) for i in range(M)]
W=[0]*N
A=[0]*N
a=0
w=0
for i in range(M):
if L[i][1]=="AC":
A[int(L[i][0])-1]=1
elif L[i][1]=="WA" and A[int(L[i][0])-1]==0:
W[int(L[i][0])-1]+=1
#for i in A:
#a+=i
#for i in W:
#w+=i
for i in range(N):
if A[i]>0:
a+=1... | 1 | 93,347,661,863,358 | null | 240 | 240 |
# coding:UTF-8
import sys
def resultSur97(x):
return x % (1000000000 + 7)
if __name__ == '__main__':
# ------ 入力 ------#
# 1行入力
n = int(input()) # 数字
# a = input() # 文字列
# aList = list(map(int, input().split())) # スペース区切り連続数字
# aList = input().split() # スペース区切り連続文字列
# ... | class Card:
def __init__(self, s):
self.suit = s[0]
self.value = int(s[1])
def __lt__(self, another_card):
return self.value < another_card.value
def __repr__(self):
return self.suit + str(self.value)
def bubble_sort(A):
n = len(A)
A = A[:]
for i in range(n):
... | 0 | null | 1,745,146,906,800 | 80 | 16 |
n, m, x = map(int, input().split())
#n,m,x,i,j,l,money,k,o
books = []
for i in range(n):
books.append(list(map(int, input().split())))
ans = 10 ** 10000
import itertools
for i in range(n+1):
for j in itertools.combinations(books, i):#j:組み合わせ
l = [0] * m
money = 0
for k in j:
... | n, m, x = map(int, input().split())
bk = [list(map(int, input().split())) for _ in range(n)]
pr = 10 ** 7
for i in range(2 ** n):
ef = [0] * (m + 1)
for j in range(n):
if i >> j & 1:
ef = [p + q for (p, q) in zip(ef, bk[j])]
for k in range(1, m + 1):
if ef[k] < x:
bre... | 1 | 22,188,290,006,038 | null | 149 | 149 |
def resolve():
n, k = map(int,input().split())
a = 10**9+7
ans =0
for K in range(k,n+2):
ans += n*K - K**2 + K + 1
ans %= a
print(ans)
resolve() | N = int(input())
A = list(map(int, input().split()))
rng = [[A[N], A[N]]]
for i in range(N - 1, -1, -1):
merged = (rng[-1][0] + 1) // 2 + A[i]
nonmerged = rng[-1][1] + A[i]
rng.append([merged, nonmerged])
if rng[-1][0] > 1:
print(-1)
exit()
rng.reverse()
prev_non_leaf = 1
ans = 1
for i in range(1,... | 0 | null | 26,035,537,670,270 | 170 | 141 |
s = input()
sa = s[:len(s)//2]
if len(s)%2 == 0:
sb = s[len(s)//2:]
if len(s)%2 == 1:
sb = s[len(s)//2+1:]
sbr = sb[::-1]
cnt = 0
for i in range(len(sa)):
if sa[i] != sbr[i]:
cnt+=1
print(cnt) | S = input()
import math
half = int(math.ceil(len(S)//2))
count = 0
for a,b in zip(S[:half], S[:-half-1:-1]):
if a != b: count += 1
print(count)
| 1 | 120,095,545,256,676 | null | 261 | 261 |
k,x=[int(_) for _ in input().split()]
print('Yes' if k*500>=x else 'No') | a, b = (int(x) for x in input().split())
if 500 * a < b:
print("No")
else:
print("Yes") | 1 | 98,417,955,303,570 | null | 244 | 244 |
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x... | H,N=map(int,input().split())
deathblows=map(int,input().split())
if sum(deathblows) >= H:
print('Yes')
else:
print('No') | 0 | null | 82,439,235,628,668 | 234 | 226 |
N,K = map(int,input().split())
tmp = 1
for i in range(1,40):
if N >= K**i:
tmp = i+1
else:
print(tmp)
break
| import math
A, B, C = map(int, input().split())
K = int(input())
count = 0
ab = int(math.log2(A/B)+1)
bc = int(math.log2((B*(2**ab))/C)+1)
if ab + bc <= K:
print('Yes')
else:
print('No')
| 0 | null | 35,417,622,899,440 | 212 | 101 |
print("aA"[input()<"a"]) | s = input()
output = s.islower()
if output == True:
print("a")
else:
print("A") | 1 | 11,258,695,279,010 | null | 119 | 119 |
a,b = input().split()
if 500 * int(a) >= int(b):
print('Yes')
else:
print('No') | import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
k, x = map(int, input().split())
if x <= k * 500:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | 1 | 97,834,983,423,310 | null | 244 | 244 |
def main():
k = int(input())
s = input()
s_len = len(s)
if s_len <= k:
print(s)
else:
s = s[0:k] + '...'
print(s)
main() | X=int(input())
p=[True for _ in range(0,200000+1)]
p[0]=False
p[1]=False
for i in range(2,200000+1):
if p[i]==False:
continue
for j in range(2,200000//i):
p[i*j]=False
while p[X]==False:
X+=1
print(X)
| 0 | null | 62,454,019,529,408 | 143 | 250 |
N = int(input())
S, T = input().split()
L = [S[i]+T[i] for i in range(N)]
print(*L, sep="") | r = int(input())
print(r*2*314/100) | 0 | null | 71,553,967,113,798 | 255 | 167 |
a,b,c,d=map(int,input().split(' '))
if a>=0:
if d<=0:
ans=a*d
else:
x=b
y=d
ans=b*d
elif a<=0 and b>=0:
if c>=0:
x=b
y=d
ans=b*d
elif c<=0 and d>=0:
ans=max(a*c,b*d)
else:
ans=a*c
else:
if c>=0:
ans=b*c
else:
ans=a*c
print(ans) | import math
def S(i):
return ((i * (i+1)) // 2)
N = int(input())
ans = 0
sqrt_N = math.floor(math.sqrt(N))
for K in range(1, N+1, 1):
if((N // K) < sqrt_N):
break
# 個別に足す
ans += S(N // K) * K
for NdivK in range(1, sqrt_N, 1):
# [N // K]が等しいKの区間を求める
Kbegin = N // (NdivK + 1)
Kend =... | 0 | null | 7,033,567,360,612 | 77 | 118 |
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)
from collections import deque
# スペース区切りの整数の入力
N, K = map(int, input().split())
#配列の入力
data = list(map(int, input().split()))
data.sort()
ans = 0
for i in range(K):
ans += data[i]
print(ans)
| n, m, k = map(int, input().split())
friendships = [[] for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
friendships[a-1].append(b-1)
friendships[b-1].append(a-1)
blockships = [[] for _ in range(n)]
for _ in range(k):
c, d = map(int, input().split())
blockships[c-1].append(d-1)
blockship... | 0 | null | 36,478,038,038,012 | 120 | 209 |
''' 1.降序排列,选出x个红苹果,y个绿苹果
2.使用c个无色苹果去更新这x+y个苹果中的小值,直到最小也比无色苹果的大为止'''
nums = [int(i) for i in input().split()]
x = nums[0]
y = nums[1]
a = nums[2]
b = nums[3]
c = nums[4]
redApples = [int(i) for i in input().split()]
greenApples = [int(i) for i in input().split()]
colorless = [int(i) for i in input().split()]
redApp... | x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p = sorted(p,reverse=True)
q = sorted(q,reverse=True)
r = sorted(r,reverse=True)
lis = p[:x]
lis.extend(q[:y])
lis = sorted(lis)
#print(lis)
ans = []
lr = len(r)
for i in ran... | 1 | 44,844,425,339,340 | null | 188 | 188 |
input()
d=[abs(s-t)for s,t in zip(*[list(map(int,input().split()))for _ in'12'])]
f=lambda n:sum(s**n for s in d)**(1/n)
print(f(1),f(2),f(3),max(d),sep='\n')
| n,t = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
a.sort()
DP = [[0 for i in range(t+3001)] for j in range(n+1)]
for i in range(1,n+1):
for j in range(1,t+3001):
if j-a[i-1][0] >= 0:
DP[i][j] = max(DP[i-1][j],DP[i-1][j-a[i-1][0]]+a[i-1][1])
else:
DP[i][j] = DP[i... | 0 | null | 76,232,273,795,300 | 32 | 282 |
#!/usr/bin/env python3
N, K, S = map(int, input().split())
if S < 10**9:
Ret = [S]*K + [S+1]* (N-K)
else:
Ret = [S]*K + [1]* (N-K)
print(*Ret)
| N, K, S=map(int, input().split())
A=[str(S)]*K
if S==10**9:
B=["1"]*(N-K)
else:
B=[str(S+1)]*(N-K)
ans=A+B
print(" ".join(ans))
| 1 | 91,454,477,260,048 | null | 238 | 238 |
input()
C = [[x[0], x[1]] for x in list(input().split())]
D = C.copy()
N = len(C)
# バブルソート
for i in range(0, N-1, 1):
for j in range(N-1, i, -1):
if C[j][1] < C[j-1][1]:
tmp = C[j]
C[j] = C[j-1]
C[j-1] = tmp
# 選択ソート
for i in range(0, N-1, 1):
minj = i
for j in r... | import numpy as np
from numba import jit
@jit('i4[:](i4,i4,i4[:])',cache = True)
def solve(n,k,A):
l,r=0,0
for i in range(k):
B=np.zeros(n+1,dtype=np.int64)
for x,y in enumerate(list(A)):
l=max(0,x-y)
r=min(n,x+y+1)
B[l]+=1
B[r]-=1
A=np.cu... | 0 | null | 7,829,514,543,552 | 16 | 132 |
# 16-Character-Sum_of_Numbers.py
# ??°?????????
# ?????????????????°???????????????????¨??????????????????°?????????????????????????????????
# Input
# ?????°??????????????????????????\?????¨??????????????????????????????????????????????????????????????´??° x ?????????????????§?????????????????????
# x ??? 1000 ?????\... | x = input()
while 1:
sum_x = 0
if x == "0":
break
for c in x:
sum_x += int(c)
print(sum_x)
x = input() | 1 | 1,609,754,856,608 | null | 62 | 62 |
k,n = map(int, input().split())
A = list(map(int, input().split()))
ans = 10**6
for i in range(n-1):
if ans > k - (A[i+1] - A[i]):
ans = k - (A[i+1] - A[i])
if ans > A[-1] - A[0]:
ans = A[-1] - A[0]
print(ans) | K, N = map(int, input().split())
A = tuple(map(int, input().split()))
maxd = K - A[-1] + A[0]
for i in range(1, N):
d = A[i] - A[i-1]
maxd = max(maxd, d)
ans = K - maxd
print(ans) | 1 | 43,393,398,211,710 | null | 186 | 186 |
#!/usr/bin/env python3
import sys
from itertools import chain
def solve(N: int, K: int, H: "List[int]"):
H = sorted(H, reverse=True)
return sum(H[K:])
def main():
tokens = chain(*(line.split() for line in sys.stdin))
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
H = [... | N,K = map(int,input().split())
H = list(map(int,input().split()))
H = sorted(H)[::-1]
H = H[K:N]
print(str(sum(H))) | 1 | 78,997,720,051,008 | null | 227 | 227 |
# n,k = map(int,input().split())
# A = list(map(int,input().split()))
# c = 0
# from collections import Counter
# d = Counter()
# d[0] = 1
# ans = 0
# r = [0]*(n+1)
# for i,x in enumerate(A):
# if i>=k-1:
# d[r[i-(k-1)]]-=1#ここで範囲kからはみ出たものの数を減らす
# c = (c+x-1)%k
# ans += d[c]
# d[c] += 1
# r[i... | #
import sys
import math
import numpy as np
import itertools
n = int(input())
# n行の複数列ある数値をそれぞれの配列へ
a, b = [0]*n, [0]*n
for i in range(n): a[i], b[i] = map(int, input().split())
#print(a,b)
a.sort()
b.sort()
if n % 2 == 0:
t = a[n//2-1] + a[n//2]
s = b[n//2-1] + b[n//2]
print(s-t+1)
else:
t = a[n//... | 0 | null | 77,054,696,972,960 | 273 | 137 |
s=input()
t=input()
print(["No","Yes"][t[:-1]==s]) | n = int(input())
dic = {}
ma = 1
for i in range(n):
wo = input()
if(wo in dic):
dic[wo] += 1
if(dic[wo] > ma):
ma = dic[wo]
else:
dic.update({wo:1})
ans = []
for i in dic.keys():
if(dic[i] == ma):
ans.append(i)
ans.sort()
for j in ans:
print(j)
| 0 | null | 45,785,592,636,828 | 147 | 218 |
t,T,a,A,b,B=map(int, open(0).read().split())
x,y=(a-b)*t,(A-B)*T
if x+y==0:
r="infinity"
else:
s,t=divmod(-x, x+y)
r=0 if s<0 else s*2+(1 if t else 0)
print(r) | def main():
# input
import math
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
x = (a1-b1)*t1
y = (a2-b2)*t2
diff = x+y
if x == -y:
print("infinity")
return
elif x*y>0 or abs(x)>abs(y):
print(0)
... | 1 | 131,306,519,964,482 | null | 269 | 269 |
n,k,s = map(int,input().split())
if s != 10**9:
ans_ls = [s+1] * n
for i in range(k):
ans_ls[i] = s
ans_ls = list(map(str,ans_ls))
else:
ans_ls = [1] * n
for i in range(k):
ans_ls[i] = s
ans_ls = list(map(str,ans_ls))
print(' '.join(ans_ls))
| def insertionSort(At, Nt):
for i in range(Nt):
v = At[i]
j = i - 1
while j >= 0 and At[j] > v:
A[j + 1] = A[j]
j = j - 1
A[j + 1] = v
print(" ".join(map(str,At)))
return At
if __name__ == '__main__':
N = int(input())
A = list(map(int, input().split()))
A = insertionSort(A, N)
#print(" ".join(map(... | 0 | null | 45,421,996,203,456 | 238 | 10 |
S , T = input().split()
A , B =map(int,input().split())
U = input()
mydict = {S:A, T:B}
mydict[U] -= 1
print ( str( mydict[S] ) + " " +str( mydict[T] ) )
| def main():
s, t = map(str, input().split())
a, b = map(int, input().split())
u = str(input())
if s == u:
print(a-1, b)
else:
print(a, b-1)
if __name__ == "__main__":
main()
| 1 | 71,815,333,818,774 | null | 220 | 220 |
N = int(input())
A = list(map(int,input().split()))
li = [0] * (N + 1)
total = 0
for i in A:
li[i] += 1
for i in li[1:]:
total += i * (i - 1) // 2
for i in A:
j = li[i]
print(total - (j * (j - 1) // 2) + ((j - 1) * (j - 2) // 2)) | N=int(input())
A=list(map(int,input().strip().split()))
l=[0 for n in range(N)]
for e in A:
l[e-1]+=1
count=0
for n in range(N):
if l[n]>=2:
count+=l[n]*(l[n]-1)//2
for n in range(N):
print(count-l[A[n]-1]+1) | 1 | 48,102,456,284,638 | null | 192 | 192 |
def main():
a,b,c=map(int,input().split())
k = int(input())
for i in range(k):
if a < b < c:
break
elif a >= b:
b *= 2
elif b >= c:
c *= 2
if a < b < c:
print('Yes')
else:
print('No')
main() | a, b, c = map(int, input().split())
k = int(input())
cnt = 0
while not (a < b < c):
cnt += 1
if a >= b:
b *= 2
elif b >= c:
c *= 2
if cnt > k:
print("No")
exit(0)
print("Yes") | 1 | 6,957,994,300,840 | null | 101 | 101 |
n,a,b = map(int, input().split())
g = n//(a+b)
k = n-(a+b)*g
if k >= a:
print(a+a*g)
else:
print(a*g + k) | s = input()
if s[0]==s[1] and s[0]==s[2]:
print("No")
else:
print("Yes")
| 0 | null | 55,540,973,600,660 | 202 | 201 |
from collections import deque
k = int(input())
deq = deque()
for i in range(1, 10):
deq.append(i)
for idx in range(k):
ret = deq.popleft()
# retの右に1つ付け加えてできるルンルン数を追加
residue = ret % 10
if residue != 0:
deq.append(ret * 10 + residue - 1)
deq.append(ret * 10 + residue)
if resi... | #!/usr/bin/env python3
import sys
import math
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 1000000007 # type: int
def solve(N: int, A: "List[int]", B: "List[int]"):
# 直交するイワシは選べない。
# 順にイワシを見て、直行するものをグループにする。
# 先に単純な整数比へ変換しておく(有... | 0 | null | 30,650,875,644,030 | 181 | 146 |
n, m = map(int, input().split())
if(n < m):
for i in range (m):
print(n, end = '')
else:
for i in range (n):
print(m, end = '') | # -*- coding: utf-8 -*-
import io
import sys
import math
def solve(a,b):
# implement process
s = str(min(a,b))
n = max(a,b)
return s * n
def main():
# input
a,b = map(int, input().split())
# process
ans = str( solve(a,b) )
# output
print(ans)
return ans
... | 1 | 84,212,602,569,072 | null | 232 | 232 |
n=int(input())
a=list(map(int,input().split()))+[0]
b=[0]*(n+1)
b[0]=1-a[0]
r=sum(a)-a[0]-a[1]
for i in range(1,n+1):
b[i]=min(r,b[i-1]*2-a[i])
r-=a[i+1]
if any(i<0 for i in b):print(-1)
else:print(sum(a)+sum(b)) | #!/usr/bin/env python3
T = list(input())
cnt = 0
for i in range(len(T)):
if T[i] == '?':
T[i] = 'D'
print(''.join(T))
| 0 | null | 18,527,875,225,508 | 141 | 140 |
x = int(input())
c = 0
bank = 100
while bank < x:
bank += bank//100
c += 1
print(c) | n, k = map(int, input().split())
p = list(map(int, input().split()))
pp = sorted(p)
ans = sum(pp[:k])
print(ans)
| 0 | null | 19,230,872,456,838 | 159 | 120 |
N = int(input())
a = list(map(int,input().split()))
flag = True
for a_i in a:
if a_i%2==0:
if not (a_i%3==0 or a_i%5==0):
flag=False
print("APPROVED" if flag else "DENIED")
| from sys import stdin
def main():
n = int(input())
a = list(map(int, input().split()))
flag = True
for i in range(n):
if (a[i] % 2 == 0):
if a[i] % 3 == 0 or a[i] % 5 == 0:
flag = True
else:
flag = False
break
if fl... | 1 | 69,072,483,097,178 | null | 217 | 217 |
n, a, b = map(int, input().split())
mod = 10**9+7
ans = pow(2, n, mod)-1
modp = mod # 素数であることが前提
max_r = 10 ** 7 # 必要分だけ用意する 10**7が限度
factinv = [1, 1] + [0]*max_r # factinv[n] = ((n!)^(-1) mod modp)
inv = [0, 1] + [0]*max_r # factinv 計算用
fact = {}
def cmb(n, r, p):
assert ... | print("A" if input().isupper() else "a") | 0 | null | 38,696,222,640,754 | 214 | 119 |
n,m,q = map(int,input().split())
A = [0]*q
B = [0]*q
C = [0]*q
D = [0]*q
for i in range(q):
a,b,c,d = map(int,input().split())
A[i] = a
B[i] = b
C[i] = c
D[i] = d
walist = []
for i in range(2**(n+m-1)):
if bin(i).count("1") == n:
wa = 0
seq = []
value = 1
for ... | import itertools
N, M, Q = map(int, input().split())
l = [i for i in range(1, M+1)]
qus = []
As = []
for _ in range(Q):
b = list(map(int, input().split()))
qus.append(b)
for v in itertools.combinations_with_replacement(l, N):
a = list(v)
A = 0
for q in qus:
pre = a[q[1]-1] - a[q[0]-1]
... | 1 | 27,398,230,677,190 | null | 160 | 160 |
N = int(input())
A = map(int, input().split())
B = [3 if i == 0 else 0 for i in range(N + 1)]
MOD = 1000000007
ans = 1
for a in A:
ans = ans * B[a] % MOD
if ans == 0:
break
else:
B[a] -= 1
B[a + 1] += 1
print(ans)
| MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
def main():
n = int(input())
a = list(map(int,input().split()))
cnt = [0] * (n + 1)
cnt[0] = 3
ans = 1
for num in a:
ans *= cnt[num]
ans %= MOD
cnt[num] -=... | 1 | 130,415,031,572,000 | null | 268 | 268 |
n = int(input())
nums = [0]*n
a = int(n**0.5)+1
for x in range(1,a):
for y in range(1,a):
if x**2 + y**2 + x*y > n: break
for z in range(1,a):
s = x**2 + y**2 + z**2 + x*y + y*z + z*x
if s <= n: nums[s-1] += 1
print(*nums, sep="\n") | S = input()
S_len = len(S)
print("x" * S_len) | 0 | null | 40,376,743,759,550 | 106 | 221 |
import copy
s = list(input())
n = len(s)
s2 = copy.deepcopy(s)
la = s[-1]
for i in range(n):
if s[i] == la:
s2.append(la)
else:
break
n2 = len(s2)
k = int(input())
if n2 == 2*n:
print(n*k//2)
exit()
count = 0
for i in range(n2-n+1,n2):
if s2[i] == s2[i-1]:
s2[i] = "1"
... | import sys
s = input()
k = int(input())
n = len(s)
all_same = True
for i in range(n-1):
if s[i] != s[i+1]:
all_same = False
if all_same:
print((n*k)//2)
sys.exit()
head_same = 1
for i in range(n-1):
if s[i] == s[i+1]:
head_same += 1
else:
break
tail_same = 1
for i in range(n-... | 1 | 174,548,656,276,850 | null | 296 | 296 |
N, K = [int(a) for a in input().split()]
num_count = (N-N%K)//K
ans = min(abs(N - num_count*K), abs(N - (num_count+1)*K))
if num_count > 0:
ans = min(abs(N - (num_count-1)*K), ans)
print(ans) | N, K = map(int, input().split())
if N >= K:
print(min(N - (N // K) * K, ((N + K) // K) * K - N))
else:
print(min(N, K - N))
| 1 | 39,228,454,533,060 | null | 180 | 180 |
N = [int(c) for c in input()]
dp = 0,1
for n in N:
a = min(dp[0]+n,dp[1]+10-n)
b = min(dp[0]+n+1,dp[1]+10-(n+1))
dp = a,b
print(dp[0]) | n = input()
a, b = 0, 100
for i in n:
j = int(i)
a, b = min(a+j,b+j), min(a+11-j,b+9-j)
if j == 0:
b = a+100
print(min(a,b)) | 1 | 71,005,235,556,390 | null | 219 | 219 |
S = input()
S_inv = S[-1::-1]
counter = 0
for i in range(len(S)//2):
if S[i]!=S_inv[i]:
counter +=1
print(counter)
| S=list(input())
T=S.copy()
T.reverse()
count=0
for i in range(len(S)):
if S[i]!=T[i]:count+=1
print(count//2) | 1 | 120,156,040,953,938 | null | 261 | 261 |
n=int(input())
a=[]
b=[]
for i in range(n):
ai,bi=map(int,input().split())
a.append(ai)
b.append(bi)
a.sort()
b.sort()
if n%2==0:
n2=n//2
ca=(a[n2-1]+a[n2])
cb=(b[n2-1]+b[n2])
c=cb-ca+1
else:
n2=(n-1)//2
ca=a[n2]
cb=b[n2]
c=cb-ca+1
print(c)
| N = int(input())
S = str(input())
alpha = ['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']
answer = ''
for i in range(len(S)):
num = alpha.index(S[i])+N
if num > 25:
num -= 26
answer += alpha[num]
print(answer) | 0 | null | 75,942,878,450,080 | 137 | 271 |
def main():
X, Y, A, B, C = map(int, input().split())
*P, = map(int, input().split())
*Q, = map(int, input().split())
*R, = map(int, input().split())
P.sort(reverse=True)
Q.sort(reverse=True)
ans = sum(sorted(P[:X] + Q[:Y] + R, reverse=True)[:X + Y])
print(ans)
if __name__ == '__main... | x,y,a,b,c=map(int,input().split())
plist=list(map(int,input().split()))
qlist=list(map(int,input().split()))
rlist=list(map(int,input().split()))
plist.sort()
qlist.sort()
rlist.sort(reverse=True)
pgensen=plist[a-x:]
qgensen=qlist[b-y:]
tmplist=pgensen+qgensen
tmplist.sort()
replacesum=0
for i in range(min(x+y,len... | 1 | 44,577,737,335,780 | null | 188 | 188 |
N, K = map(int, input().split())
answer = 0
while N // (K ** answer) >= 1:
answer += 1
print(answer) | N, K = map(int, input().split())
for i in range(1000000):
if K ** (i - 1) <= N < K ** i:
print(i)
break
| 1 | 64,467,091,153,450 | null | 212 | 212 |
N = input()
Y = int(N)
a = Y%10
if a==3:
print("bon")
elif a==0:
print("pon")
elif a==1:
print("pon")
elif a==6:
print("pon")
elif a==8:
print("pon")
elif a==2:
print("hon")
elif a==4:
print("hon")
elif a==5:
print("hon")
elif a==7:
print("hon")
else:
print("hon")
| n = int(input()[-1])
if n in [2, 4, 5, 7, 9]:
print("hon")
elif n == 3:
print("bon")
else:
print("pon") | 1 | 19,240,660,567,648 | null | 142 | 142 |
n = int(input())
a = [[i for i in input().split()] for i in range(n)]
taroup = 0
hanakop = 0
for i in range(n):
array =[]
array.append(a[i][0])
array.append(a[i][1])
array.sort()
if array[1] == a[i][0] and array[1] != a[i][1]:
taroup += 3
elif array[1] == a[i][1] and array[1] != a[i][0... | n=int(input())
t=0
h=0
for i in range(n):
a,b=map(str,input().split())
if a<b:
h+=3
elif a>b:
t+=3
else:
t+=1
h+=1
print("{} {}".format(t,h)) | 1 | 2,020,504,136,180 | null | 67 | 67 |
N,M = map(int,input().split())
A = [int(x) for x in input().split()]
if N - sum(A) >= 0 :
print(N-sum(A))
else :
print("-1") | N, M = map(int, input().split())
data = list(map(int, input().split()))
if N - sum(data) >= 0:
print(N-sum(data))
else:
print(-1)
| 1 | 31,745,724,378,056 | null | 168 | 168 |
import random
s = input()
num = random.randint(0,len(s)-3)
print(s[num:num+3]) | l=[]
for mark in ["S","H","C","D"]:
for i in range(1,14):
l.append(mark+" "+str(i))
n=input()
for i in range(int(n)):
l.remove(input())
for i in l:
print(i) | 0 | null | 7,868,016,545,452 | 130 | 54 |
import sys
sys.setrecursionlimit(10**9)
def main():
n, x, t = map(int, input().split())
if n % x == 0:
print((n//x)*t)
else:
print((n//x+1)*t)
return
if __name__ == "__main__":
main() | n, k = [int(i) for i in input().split()]
cnt = 0
if n == 0:
print(1)
exit()
while n != 0:
n = n // k
cnt += 1
print(cnt) | 0 | null | 34,140,840,799,780 | 86 | 212 |
N = int(input())
P = list(map(int,input().split()))
mini = N+1
cnt = 0
for i in P:
if mini > i:
cnt += 1
mini = i
print(cnt) | n = int(input())
p = list(map(int, input().split()))
m = p[0]
ans = 0
for i in p:
if (m >= i):
ans += 1
m = min(i,m)
print(ans) | 1 | 85,276,813,330,238 | null | 233 | 233 |
def num2alpha(num):
if num<=26:
return chr(96+num)
elif num%26==0:
return num2alpha(num//26-1)+chr(122)
else:
return num2alpha(num//26)+chr(96+num%26)
print(num2alpha(int(input()))) | from sys import setrecursionlimit
setrecursionlimit(10 ** 6)
N = int(input())
Gb = [ [] for _ in range(N) ]
Gu = [ [] for _ in range(N) ]
Es = {}
for n in range(N - 1):
a, b = map(lambda x: int(x) - 1, input().split())
Es[f'{a:06}{b:06}'] = None
Gb[a].append(b)
Gb[b].append(a)
Gu[a].append(b)
... | 0 | null | 73,888,547,584,510 | 121 | 272 |
N = int(input())
l = []
for i in range(N):
l.append([int(x) for x in input().split()])
xlim = []
ylim = []
def cha(a):
return [a[0]-a[1],a[0]+a[1]]
for i in range(N):
ylim.append(cha(l[i])[1])
xlim.append(cha(l[i])[0])
xlim.sort()
ylim.sort()
print(max(xlim[-1]-xlim[0],ylim[-1]-ylim[0])) | s = input()
n = len(s)
t = input()
m = len(t)
c_max = 0
for i in range(n - m + 1):
c = 0
for j in range(m):
if s[i + j] == t[j]:
c += 1
if c > c_max:
c_max = c
print(m - c_max) | 0 | null | 3,594,799,540,498 | 80 | 82 |
s = input()
p = input()
s += s
ans = "No"
for i in range(len(s)//2):
if s[i] == p[0]:
for j in range(len(p)):
if s[i+j] != p[j]:
break
if j == len(p)-1:
ans = "Yes"
print(ans)
| s = input()
p = input()
flag = False
for i in range(len(s)):
t = s[i:] + s[:i]
if p in t :
flag = True
break
if flag :
print("Yes")
else :
print("No") | 1 | 1,715,054,999,302 | null | 64 | 64 |
X=int(input())
for A in range(1000):
for B in range(-100, 1000):
if A**5 - B**5 == X:
ans = (A,B)
print(*ans) | #@ /usr/bin/env python3.4
import sys
list = sys.stdin.readlines()
for i in list:
num = i[:-1].split(' ', 2)
print(len(str(int(num[0])+int(num[1])))) | 0 | null | 12,872,180,557,554 | 156 | 3 |
# Aizu Problem ITP_1_11_A: Dice I
#
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
def do_roll(dice, roll):
d1, d2, d3, d4, d5, d6 = dice
if roll == 'E':
return [d4, d2, d1, d6, d5, d3]
elif roll == 'W':
... | N = int(input())
G = [[] for n in range(N)]
vc = N*[0]
ec = (N-1)*[0]
h = 1
for n in range(N-1):
a,b = map(int,input().split())
G[a-1].append((b-1,n))
for v,g in enumerate(G):
t = 1
for b,i in g:
if vc[v]==t:
t+=1
vc[b] = t
ec[i] = t
h = max(h,t)
t+=1
print(h)
for n in range(N-1):
... | 0 | null | 68,391,311,268,302 | 33 | 272 |
s= input()
x = "x" * len(s)
print(x) | h, w, k = map(int, input().split())
s = [input() for _ in range(h)]
a = [[0]*w for _ in range(h)]
cnt = 1
later = []
for i in range(h):
if '#' not in s[i]: continue
later.append(i)
fst = True
for j in range(w):
if not fst and s[i][j] == '#':
cnt += 1
if fst and s[i][j] == '#'... | 0 | null | 108,165,974,710,880 | 221 | 277 |
top = 0
def push(x):
global top
L.append(x)
top += 1
def pop():
global top
x = L.pop(top)
top -= 1
return x
L = [0]
S = input().split()
for i in S:
if i == "+":
a = pop()
b = pop()
push(a + b)
elif i == "-":
a = pop()
b = pop()
push(b ... | symbol = list(input().split())
stack = []
while len(symbol) > 0:
x = symbol.pop(0)
if x.isdigit():
stack.append(int(x))
else:
a,b = stack.pop(),stack.pop()
if x == "+":
stack.append(b + a)
elif x == "-":
stack.append(b - a)
elif x == "*":
... | 1 | 36,714,991,700 | null | 18 | 18 |
def main():
N, S = map(int, input().split())
A = tuple(map(int, input().split()))
MOD = 998244353
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
# morau
for i, a in enumerate(A):
dp[i][0] = pow(2, i, MOD)
for j in range(S+1):
if j >= a:
... | N, S = map(int, input().split())
MOD = 998244353
A = list(map(int, input().split()))
dp = [[0]*(S+1) for i in range(N+1)]
dp[0][0] = 1
for i, a in enumerate(A, 1):
for s in range(S+1):
dp[i][s] = 2*dp[i-1][s]
if a <= s:
dp[i][s] += dp[i-1][s-a]
dp[i][s] %= MOD
print(dp[-1][-1]) | 1 | 17,793,621,205,818 | null | 138 | 138 |
N = int(input())
A = list(map(int, input().split()))
numbers = []
s = A[0]
for i in range(1, N):
s = s ^ A[i]
for i in range(N):
numbers.append(s ^ A[i])
print(*numbers)
| N = int(input())
A = list(map(int, input().split()))
t = 0
for c in A:
t ^= c
ans = []
for b in A:
ans.append(t^b)
print(*ans) | 1 | 12,493,932,093,258 | null | 123 | 123 |
import sys
import math
def be_able_to_convey(w, k, p):
counter = 0
cur_weight = 0
for wi in w:
if wi > p:
return False
cur_weight += wi
if(cur_weight > p):
cur_weight = wi
counter += 1
if(counter >= k):
return False
return True
#fin = open("test.txt", "r")
fin = sys.stdin
n, k = map(int,... | N, K = map(int, input().split())
W = []
for i in range(N):
W.append(int(input()))
def f(N, K, W, p):
cnt = 0
k = 1
c_k = 0
for w in W:
if c_k + w <= p:
c_k = c_k + w
cnt = cnt + 1
elif k < K and w <= p:
k = k + 1
c_k = w
c... | 1 | 86,252,255,830 | null | 24 | 24 |
while True:
num = int(input())
if num == 0:
break
data = list(map(int, input().split()))
datasqr = [i ** 2 for i in data]
print("%lf" % (sum(datasqr) / num - (sum(data) / num) ** 2) ** 0.5)
| import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): ... | 0 | null | 37,190,337,789,972 | 31 | 222 |
n=int(input())
if n!=0:
ans1=n//500
sub=n-(ans1*500)
ans2=sub//5
print((ans1*1000)+(ans2*5))
else:
print(0) | x, y = map(int, input().split())
a = []
for i in range(0, x+1):
a.append(2 * i + 4 * (x - i))
print("Yes" if y in a else "No") | 0 | null | 28,145,576,506,880 | 185 | 127 |
N = int(input())
D = list(map(int, input().split()))
M = 998244353
from collections import Counter
if D[0] != 0:
print(0)
exit(0)
cd = Counter(D)
if cd[0] != 1:
print(0)
exit(0)
tmp = sorted(cd.items(), key=lambda x: x[0])
ans = 1
for kx in range(2, max(D)+1):
# print(tmp)
# for kx in range(2, len(t... | import queue
N = int(input())
tree = [[]for _ in range(N+1)]
for i in range(1,N):
a,b = map(int,input().split())
tree[a].append( [b,i])
tree[b].append([a,i])
que = queue.Queue()
node = [-1]*(N+1)
edge = [-1]*N
que.put(1)
node[1] = 1
maxi = 1
start = 0
color = [[] for _ in range(N+1)]
node[1] = 0
while(Tr... | 0 | null | 145,809,144,614,980 | 284 | 272 |
from math import ceil
def enum_divisor(n):
res = []
for i in range(1, int(n ** 0.5) + 1):
if n % i != 0:
continue
res.append(i)
if i * i != n:
res.append(n // i)
return res
ans = 0
n = int(input())
for x in enum_divisor(n):
if x == 1:
continue
... | import sys
from math import sqrt
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(MI())
def LIN(n: int):
return [I() for _ in range(n)]
inf = float("inf")
mod = 10 ** 9 ... | 1 | 41,299,759,502,430 | null | 183 | 183 |
S = input()
print("ABC" if S == "ARC" else "ARC") | n,k=map(int,input().split())
P=list(map(int,input().split()))
for i in range(n):
P[i]-=1
C=list(map(int,input().split()))
ANS=-float('inf')
for i in range(n):
snp=P[i]
r=C[snp]
L=[r]
c=0
np=P[snp]
while True:
if c==k-1:
ANS=max(max(L),ANS)
break
if np==sn... | 0 | null | 14,651,947,393,742 | 153 | 93 |
n = int(input())
print(n^1) | from math import inf
n = int(input())
A = list(map(int, input().split()))
dp = [[-inf] * 3 for _ in range(n + 1)]
k = 1 + n % 2
dp[0][0] = 0
for i in range(n):
for j in range(k + 1):
if j < k:
dp[i + 1][j + 1] = dp[i][j]
now = dp[i][j]
if (i + j) % 2 == 0:
now += ... | 0 | null | 20,276,117,655,766 | 76 | 177 |
import sys
def solve():
input = sys.stdin.readline
S = list(input().strip("\n"))
K = int(input())
N = len(S)
head, tail, joint = 0, 0, 0
inside = 0
if S[0] == S[N-1]: #ジョイント部を考える必要がある場合
isInitial = True
current = S[0]
currentLength = 1
for i in range(1, N):
... | #!/usr/bin/env python
# coding: utf-8
# In[8]:
S = input()
K = int(input())
# In[10]:
cnt = 0
ans = 0
tmp = S[0]
fcnt = 0
for s in S:
if tmp == s:
cnt += 1
tmp = s
else:
ans += cnt//2
if fcnt == 0:
fcnt = cnt
cnt = 1
tmp = s
if fcnt == 0:
fc... | 1 | 174,838,110,788,680 | null | 296 | 296 |
x = int(input())
t = x // 500
print(1000 * t + 5 * ((x - 500 * t) // 5)) | def atc_160b(X: int) -> int:
return X // 500 * 1000 + X % 500 // 5 * 5
X_input = int(input())
print(atc_160b(X_input))
| 1 | 42,528,587,290,060 | null | 185 | 185 |
a,b = map(int,input().split())
ans = ""
k = min(a,b)
l = max(a,b)
for i in range(l):
ans += str(k)
print(ans) | r=input().split()
a=int(r[0])
b=int(r[1])
if a>=b:
ans=""
for i in range(a):
ans+=str(b)
print(int(ans))
else:
ans=""
for i in range(b):
ans+=str(a)
print(int(ans)) | 1 | 84,324,804,021,860 | null | 232 | 232 |
def A():
S = input()
if(S[-1] == 's'):
S += 'es'
else:
S += 's'
print(S)
A() | if __name__ == '__main__':
s = str(input())
if s[-1] != 's':
print(f'{s}s')
else:
print(f'{s}es') | 1 | 2,380,790,847,008 | null | 71 | 71 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.