code1 stringlengths 16 427k | code2 stringlengths 16 427k | similar int64 0 1 | pair_id int64 6.82M 181,637B ⌀ | question_pair_id float64 101M 180,471B ⌀ | code1_group int64 2 299 | code2_group int64 2 299 |
|---|---|---|---|---|---|---|
import sys
n=input()
house=[[[],[],[]],[[],[],[]],[[],[],[]],[[],[],[]]]
for i in range(4):
for j in range(3):
for k in range(10):
house[i][j].append(0)
for i in range(n):
b,f,r,v=map(int,raw_input().split())
house[b-1][f-1][r-1]+=v
for i in range(4):
for j in range(3):
for k... | from collections import deque
n = int(input())
dlist = deque()
for i in range(n):
code = input().split()
if code[0] == "insert":
dlist.insert(0,code[1])
if code[0] == "delete":
try:
dlist.remove(code[1])
except:
continue
if code[0] == "deleteFirst":
... | 0 | null | 570,681,522,178 | 55 | 20 |
s = input()
n = len(s)
s_re =s[::-1]
s_first = s[:(n-1)//2]
s_first_re = s_first[::-1]
s_second = s[(n+3)//2-1:]
s_second_re = s_second[::-1]
print(['No','Yes'][s == s_re and s_first==s_first_re and s_second == s_second_re]) | S=list(input())
N=len(S)
x=0
for i in range(int((N-1)/2)):
if S[i]!=S[-(i+1)]:
print("No")
break
elif i==int((N-1)/2)-1:
x+=1
import math
if x==1:
S_l=S[:int((N-1)/2)]
for i in range(int(math.ceil(len(S_l)/2))):
if S_l[i]!=S_l[-(i+1)]:
print("No")
... | 1 | 46,242,536,162,804 | null | 190 | 190 |
import sys
from collections import Counter
n = int(input())
D = list(map(int,input().split()))
if D[0] != 0 or D.count(0) != 1:
print(0)
sys.exit()
D = Counter(D)
L = sorted(D.items())
pk = 0
pv = 1
ans = 1
for i,j in L:
if i == 0:
continue
if i != pk+1:
print(0)
break
ans *=... | x = int(input())
if x%100 == 0 or x%101 == 0 or x%102 == 0 or x%103 == 0 or x%104 == 0 or x%105 == 0:
print (1)
else:
for i in range(100000):
if 100*i <= x <= 105*i:
print (1)
exit ()
else:
print (0)
| 0 | null | 141,118,376,269,650 | 284 | 266 |
import math
mod = 1000000007
n = int(input())
zero = 0
dic = {}
dic[(0, 1.5)] = 0
dic[(1.5, 0)] = 0
for i in range(n):
ai, bi = map(int, input().split())
idx = (ai, bi)
if ai < 0:
ai, bi = -ai, -bi
if idx == (0, 0):
zero += 1
elif idx[0] == 0:
dic[(0, 1.5)] += 1
elif idx... | #!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L(): return sys.stdin.readline().split()... | 0 | null | 12,546,220,579,080 | 146 | 85 |
import math
a,b,h,m = map(int,input().split())
ans_cos = math.cos(math.pi*(60*h-11*m)/360)
ans = math.sqrt(a**2+b**2-2*a*b*ans_cos)
print(ans) | import numpy as np
H,W = input().split()
H,W=int(H),int(W)
P=[0]*H
for i in range(H):
P[i] = input()
dp=np.zeros((H,W),dtype='u8')
if P[0][0]=='#':
dp[0][0]=1
else:
dp[0][0]=0
def DP(y,x):
global dp
if 0<=x<=W-1 and 0<=y<=H-1:
return dp[y][x]
else:
return 9999999
for l in ran... | 0 | null | 34,471,414,592,408 | 144 | 194 |
def main():
import sys
input = sys.stdin.readline
from collections import Counter
class BIT:
def __init__(self,n):
self.size = n
self.tree = [Counter([]) for _ in range(n+1)]
def change(self,i,x,y):
while i <= self.size:
if x in se... | def main():
k=int(input())
s=7
for i in range(10**6):
if s%k == 0:
print(i+1)
break
s = (s*10+7)%k
else:
print(-1)
if __name__ == "__main__":
main() | 0 | null | 34,216,858,439,192 | 210 | 97 |
from sys import stdin
import sys
import math
from functools import reduce
import itertools
n,k = [int(x) for x in stdin.readline().rstrip().split()]
h = [int(x) for x in stdin.readline().rstrip().split()]
if k<n:
h.sort()
print(sum(h[:n-k]))
else:
print(0) | n, k = map(int, input().split())
H = list(map(int, input().split()))
H.sort(reverse=True)
H = H[k:]
print(sum(H))
| 1 | 79,352,556,418,308 | null | 227 | 227 |
k=int(input())
count=1
num=7
for _ in range(k):
if num%k == 0:
print(count)
break
else:
count += 1
num = (num % k)*10 + 7
else:
print(-1) | i = count = 0
a = b = c = ''
line = input()
while line[i] != ' ':
a = a + line[i]
i += 1
i += 1
while line[i] != ' ':
b = b + line[i]
i += 1
i += 1
while i < len(line):
c = c + line[i]
i += 1
a = int(a)
b = int(b)
c = int(c)
while a <= b:
if c%a == 0:
count += 1
a ... | 0 | null | 3,372,757,337,310 | 97 | 44 |
#####
# B #
#####
N = input()
sum = sum(map(int,N))
if sum % 9 == 0:
print('Yes')
else:
print('No')
| X,K,D = map(int,input().split())
X = abs(X)
ans = 0
if (X // D) >= K:
ans = X - (K * D)
elif (X // D) % 2 == 0:
if K % 2 == 0:
ans = X % D
else:
ans = abs((X % D) - D)
else:
if K % 2 ==1:
ans = X % D
else:
ans = abs((X % D) - D)
print(ans) | 0 | null | 4,867,885,962,240 | 87 | 92 |
import math
T_1, T_2 = map(int, input().split())
A_1, A_2 = map(int, input().split())
B_1, B_2 = map(int, input().split())
ans = 0
if T_1 * A_1 + T_2 * A_2 == T_1 * B_1 + T_2 * B_2:
print("infinity")
else:
# 速いほうをAと仮定
if T_1 * A_1 + T_2 * A_2 < T_1 * B_1 + T_2 * B_2:
A_1, A_2, B_1, B_2 = B_1, B_2, A... |
#atcoder
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
d1=a1-b1
d2=a2-b2
if d1*d2>0:
print(0)
else:
if d1>0 and d2<0:
plus=d1*t1+d2*t2
if plus>0:
print(0)
elif plus==0:
print("infinity")
elif plus<0:
... | 1 | 131,433,790,532,010 | null | 269 | 269 |
import sys
def main():
input = sys.stdin.buffer.readline
a, b, c = map(int, input().split())
print("Yes" if 4 * a * b < (c - a - b) ** 2 and c - a - b > 0 else "No")
if __name__ == "__main__":
main()
| a, b, c = map(int, input().split())
d = c - a - b
if d >= 0 and d * d > 4 * a * b:
print("Yes")
else:
print("No")
| 1 | 51,638,245,923,744 | null | 197 | 197 |
while 1:
H, W = map(int, raw_input().split())
if H == W == 0:
break
for i in range(H):
if i % 2 == 0:
if W % 2 == 0:
print "#." * (W/2)
else:
print "#." * (W/2) + "#"
else:
if W % 2 == 0:
print ".#" * (W/2)
else:
print ".#" * (W/2) + "."
print "" | a=["#." * (300//2),".#" * (300//2)]*(300//2)
while True:
[h,w] = map(int, input().split())
if h==0 and w==0:
break
t = map(lambda x: x[0:w], (a[0:h]))
for i in t:
print(i)
print() | 1 | 871,410,022,980 | null | 51 | 51 |
s = []
while True:
x = int(input())
if x == 0:
break
s.append(x)
for (i,num) in enumerate(s):
print('Case {0}: {1}'.format(i+1,num))
| i = 1
while True :
x = input()
if (x == 0) :
exit()
print "Case %d: %d" % (i, x)
i += 1 | 1 | 473,549,601,860 | null | 42 | 42 |
n=int(input())
s=input()
ans=''
for i in s:
if ord(i)+n>ord('Z'):
ans+=chr(ord(i)+n-26)
else:
ans+=chr(ord(i)+n)
print(ans) | N, M, Q = map(int, input().split())
G = []
for i in range(Q):
a, b, c, d = map(int, input().split())
G.append([a, b, c, d])
ans = 0
def dfs(s):
global ans
if len(s) == N:
now = 0
for a, b, c, d in G:
if s[b - 1] - s[a - 1] == c:
now += d
ans = max(a... | 0 | null | 80,870,809,184,230 | 271 | 160 |
def insertionsort(A, n, g, cnt):
for i in range(g, n):
v = A[i]
j = i - g
while (j >= 0 and A[j] > v):
A[j + g] = A[j]
j = j - g
cnt += 1
A[j + g] = v
return cnt
A = []
n = int(raw_input())
for i in range(n):
A.append(int(raw_input()))
cnt = 0
G = [1]
while G[-1] * 3 + 1 < n:
G.append(G[-1] * 3... | def insert(A,n,g):
global cnt
for i in range(g,n):
v = a[i]
j = i-g
while(j>=0 and A[j]>v):
A[j+g] = A[j]
j = j-g
cnt+= 1
A[j+g] = v
def shell(A,n):
global cnt
cnt = 0
G = []
h = 1
while h <= n:
G.append(h)
... | 1 | 30,539,211,538 | null | 17 | 17 |
S = input()
N = len(S)
s = S[:(N-1)//2]
t = S[(N+3)//2-1:]
if s == t[::-1] and s == s[::-1] and t == t[::-1]:
ans = "Yes"
else:
ans = "No"
print(ans) | # B - Homework
# N M
N, M = map(int, input().split())
my_list = list(map(int, input().split(maxsplit=M)))
if N < sum(my_list):
answer = -1
else:
answer = N - sum(my_list)
print(answer)
| 0 | null | 39,248,626,948,750 | 190 | 168 |
t=0
h=0
for i in range(int(input())):
l=input().split()
if l[0]==l[1]:
t+=1
h+=1
elif l[0]>l[1]: t+=3
else: h+=3
print(t,h) | import sys
# C - Walking Takahashi
X, K, D = map(int, input().split())
if D * K <= abs(X):
print(abs(X) - D * K)
else:
distance = abs(X) % D
# 残りの移動回数
count = K - (abs(X) // D)
if count % 2 == 1:
print(abs(D - distance))
else:
print(distance) | 0 | null | 3,594,879,507,000 | 67 | 92 |
n=int(input())
a=list(map(int,input().split()))
q=int(input())
b=[0]*q
c=[0]*q
for i in range(q):
b[i],c[i]=map(int,input().split())
N=[0]*(10**5)
s=0
for i in range(n):
N[a[i]-1]+=1
s+=a[i]
for i in range(q):
s+=(c[i]-b[i])*N[b[i]-1]
N[c[i]-1]+=N[b[i]-1]
N[b[i]-1]=0
print(s) | from collections import Counter
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
ans = sum(A)
num = Counter(A)
for i in range(Q):
b,c = map(int,input().split())
ans += (c-b)*num[b]
num[c] += num[b]
num[b] = 0
print(ans) | 1 | 12,211,831,540,590 | null | 122 | 122 |
import sys
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
def input():
return sys.stdin.readline().strip()
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(co... | import sys,math,collections
from collections import defaultdict
#from itertools import permutations,combinations
def file():
sys.stdin = open('input.py', 'r')
sys.stdout = open('output.py', 'w')
def get_array():
l=list(map(int, input().split()))
return l
def get_2_ints():
a,b=map(int, input().split())
return... | 0 | null | 51,890,360,774,740 | 242 | 105 |
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
# N に向かうことを考える
A_to_N_dis = N - B + 1
A_to_N = A + A_to_N_dis
tmp_ans = (N - A_to_N) // 2 + A_to_N_dis
# 1に向かうことを考える
B_to_1_dis = A - 1 + 1
B_to_1 = B - B_to_1_dis
ans = (B_to_1 - 1) // 2 + B_to_1_dis... | N,A,B = map(int,input().split())
if A%2 != 0 and B%2 == 0:
ans = (B-A-1)//2 + min(A-1,N-B) + 1
elif A%2 == 0 and B%2 != 0:
ans = (B-A-1)//2 + min(A-1,N-B) + 1
else:
ans = (B-A)//2
print(ans) | 1 | 109,255,326,801,544 | null | 253 | 253 |
import sys
sys.setrecursionlimit(300000)
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s... | import sys
while True:
a,b = map(int, raw_input().split())
if a ==0 and b == 0:
break
for i in range(a):
for j in range(b):
if i == 0 or i == a-1 or j == 0 or j == b-1:
sys.stdout.write("#")
else:
sys.stdout.write(".")
print
... | 0 | null | 4,332,730,295,310 | 105 | 50 |
import math
while 1:
n = int(input())
if n == 0:
break
s = list(map(int,input().split()))
m = sum(s) / len(s)
x = 0
for i in range(n):
x += (s[i] -m )**2 / n
a = math.sqrt(x)
print(a) | A, B, C = list(map(int, input().split()))
K = int(input())
res = 0
while True:
if B <= A:
B *= 2
res += 1
else:
break
while True:
if C <= B:
C *= 2
res += 1
else:
break
if res <= K:
print("Yes")
else:
print("No") | 0 | null | 3,518,217,370,966 | 31 | 101 |
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
res = 0
for i in range(h):
for j in range(w):
if s[i][j] == "#":
continue
dist = [[-1] * w for _ in range(h)]
dist[i][j] = 0
d = de... | h, w = map(int, input().split())
s = [input() for _ in range(h)]
def bfs(x, y):
q = []
dp = {}
def qpush(x, y, t):
if 0 <= x < w and 0 <= y < h and s[y][x] != '#' and (x, y) not in dp:
q.append((x, y))
dp[(x, y)] = t
qpush(x, y, 0)
while len(q) > 0:
(x, y) =... | 1 | 94,887,866,046,740 | null | 241 | 241 |
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read
inp = sys.stdin.buffer.readline
from itertools import accumulate
def resolve():
N, K = map(int, inp().split())
A = list(map(int, inp().split()))
for _ in range(K):
imos_table = [0]*(N+1)
for i, a in enumerate(A):
... | X = int(input())
A = 0
B = 0
if X >= 500:
A = X // 500
X = X % 500
if X >= 5:
B = X // 5
X = X % 5
print(A * 1000 + B * 5) | 0 | null | 28,971,497,058,882 | 132 | 185 |
m, d = input().split(' ')
M, D = input().split(' ')
if D == '1':
print(1)
else:
print(0) | import sys
import math
stdin = sys.stdin
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
def ns(): return stdin.readline().rstrip() # ignore trailing spaces
N = ni()
AB_array = [na() for _ in range(N)]
# print(AB_array)
plus_dic = {}
minus_dic = {}
ans = 1
fish_count =... | 0 | null | 72,880,778,345,078 | 264 | 146 |
i = 0
while True:
i += 1
num = raw_input()
if num == "0":
break
print "Case %d: %s" % (i,num) | s=1
while True:
i=input()
if i=='0': break
print('Case '+str(s)+':', i)
s+=1
| 1 | 482,686,239,904 | null | 42 | 42 |
import sys
while True:
height, width = map(int, raw_input().split())
if height == 0 and width == 0:
break
for i in range(height):
for j in range(width):
if j % 2 == 0 and i % 2 == 0: #even n, even n
sys.stdout.write("#")
elif j % 2 != 0 and i % 2 == 0:... | class D_Linked_List:
class Node:
def __init__(self, key, next = None, prev = None):
self.next = next
self.prev = prev
self.key = key
def __init__(self):
self.nil = D_Linked_List.Node(None)
self.nil.next = self.nil
self.nil.prev = self.nil
... | 0 | null | 465,741,136,982 | 51 | 20 |
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.rea... | X = int(input())
q,mod = divmod(X,100)
if 5*q<mod:
print(0)
else:
print(1) | 0 | null | 81,720,609,925,734 | 176 | 266 |
print(int(input())*3.141592*2) | x=float(input())
p=2*3.14*x
A="dlfnsdfjsdjfsdfjsdfnksdkjnfjksndfkjnskjfkjsdkjfnskjdfknsdkjfskdnfkjsdn"
print(p) | 1 | 31,496,280,015,548 | null | 167 | 167 |
N = int(input())
slist = []
tlist = []
from itertools import accumulate
for _ in range(N):
s, t = input().split()
slist.append(s)
tlist.append(int(t))
cum = list(accumulate(tlist))
print(cum[-1]-cum[slist.index(input())])
| from collections import deque
if __name__ == '__main__':
n, q = map(int, input().split())
Q = deque()
for i in range(n):
name, time = input().split()
Q.append([name, int(time)])
sum = 0
while Q:
qt = Q.popleft()
if qt[1] <= q:
sum += qt[1]
print(qt[0], sum)
else:
sum += q
qt[1] -= q
Q... | 0 | null | 48,320,184,401,580 | 243 | 19 |
def main():
match_count = int(input())
matches = [input().split() for i in range(match_count)]
taro_result = [3 if match[0] > match[1] else 1 if match[0] == match[1] else 0 for match in matches]
print('%d %d' % (sum(taro_result), sum(3 if item == 0 else 1 if item == 1 else 0 for item in taro_resul... | n=int(input())
T,H=0,0
for i in range(n):
t_card,h_card=input().split()
if t_card>h_card:
T+=3
elif t_card<h_card:
H+=3
else:
T+=1
H+=1
print(str(T)+" "+str(H)) | 1 | 1,962,141,457,682 | null | 67 | 67 |
n,m=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i in a:
if i>=sum(a)*(1/(4*m)):
c+=1
if c>=m:
print('Yes')
else:
print('No') | n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [x for x in a if x >= sum(a)/4/m]
if len(b)>=m:
print("Yes")
else:
print("No")
| 1 | 38,603,367,031,230 | null | 179 | 179 |
a, b, c = (int(x) for x in input().split())
tmp = 0
for i in range(2):
if a > b:
tmp = a
a = b
b = tmp
if b > c:
tmp = b
b = c
c = tmp
if a > c:
tmp = a
a = c
c = tmp
print(a, b, c)
| a = map(int, raw_input().split())
for i in range(len(a)):
point = a[i:].index(min(a[i:])) + i
temp = a[i];
a[i] = a[point]
a[point] = temp
print '%s %s %s' % (str(a[0]), str(a[1]), str(a[2])) | 1 | 413,803,592,112 | null | 40 | 40 |
def main():
n = int(input())
print((n+1)//2)
if __name__ == "__main__":
main() | import math
n = int(input())
paper = math.ceil(n/2)
print(paper) | 1 | 59,107,920,923,140 | null | 206 | 206 |
n = int(input())
AC,WA,TLE,RE = 0,0,0,0
for x in range(n):
s = input()
if s == 'AC':
AC = AC + 1
elif s == 'WA':
WA = WA + 1
elif s == 'TLE':
TLE = TLE + 1
elif s == 'RE':
RE = RE + 1
print('AC x ' + str(AC))
print('WA x ' + str(WA))
print('TLE x ' + str(TLE))
prin... | #B
N=int(input())
C=[input() for i in range(N)]
AC=C.count('AC')
WA=C.count('WA')
TLE=C.count('TLE')
RE=C.count('RE')
print('AC x {}\nWA x {}\nTLE x {}\nRE x {}'.format(AC, WA, TLE, RE)) | 1 | 8,632,159,014,512 | null | 109 | 109 |
#ごり押し
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra
import numpy as np
from collections import Counter
N, X, Y = map(int, input().split())
start = list(range(0, N-1)) + list(range(1, N)) + [X-1, Y-1]
end = list(range(1, N)) + list(range(0, N-1)) + [Y-1, X-1]
cost = [1] * len(start)
... | n = float(input())
print(n * n * n / 27) | 0 | null | 45,437,859,347,520 | 187 | 191 |
import math
r = float(input())
print("%.5f %.5f" % (math.pi*r *r, 2*math.pi*r))
| import sys
from bisect import bisect_left
input = sys.stdin.readline
def main():
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for a in range(N - 2):
for b in range(a + 1, N - 1):
x = bisect_left(L, L[a] + L[b])
ans += (x - 1 - b)
prin... | 0 | null | 85,882,196,630,760 | 46 | 294 |
N = int(input())
ans = [0] * (N+1)
for i in range(N+1):
if i % 3 != 0 and i % 5 != 0 and i % 15 != 0:
ans[i] = ans[i-1] + i
else:
ans[i] = ans[i-1]
print(ans[-1])
| class Combination():
def __init__(self, n, mod=10**9+7):
self.mod = mod
self.fac = [1]*(n+1)
for i in range(1,n+1):
self.fac[i] = self.fac[i-1] * i % self.mod
self.invfac = [1]*(n+1)
self.invfac[n] = pow(self.fac[n], self.mod - 2, self.mod)
for i in range(... | 0 | null | 29,005,863,767,300 | 173 | 151 |
from collections import defaultdict
from math import gcd
mod = 10 ** 9 + 7
n = int(input())
fishes = defaultdict(int)
zero_zero = 0
zero = 0
inf = 0
for _ in range(n):
a, b = map(int, input().split())
if a == 0 and b == 0:
zero_zero += 1
elif a == 0:
zero += 1
elif b == 0:
in... | from collections import defaultdict
from math import gcd
n = int(input())
zeros = 0
d = defaultdict(lambda: [0, 0])
for _ in range(n):
a, b = map(int, input().split())
if a == 0 and b == 0:
zeros += 1
continue
g = gcd(a, b)
a, b = a // g, b // g
if a == 0:
b = 1
if b ==... | 1 | 20,811,846,224,272 | null | 146 | 146 |
n,m=map(int,input().split())
H=list(map(int,input().split()))
ans = [1]*n
for i in range(m):
a,b=map(int,input().split())
if H[a-1]>H[b-1]:
ans[a-1] *= 1
ans[b-1] *= 0
elif H[a-1]<H[b-1]:
ans[a-1] *= 0
ans[b-1] *= 1
else:
ans[a-1] *= 0
ans[b-1] *= 0
print(sum(ans)) | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdi... | 1 | 25,167,086,490,590 | null | 155 | 155 |
n,a,b = map(int, input().split())
MOD = 10 ** 9 + 7
def comb(n, k):
nCk = 1
for i in range(n - k + 1, n + 1):
nCk *= i
nCk %= MOD
for i in range(1, k + 1):
nCk *= pow(i, MOD - 2, MOD)
nCk %= MOD
return nCk
print((((pow(2,n,MOD)-1-comb(n,a))%MOD)-comb(n,b))%MOD) | #!/usr/bin/env python3
import collections as cl
import sys
def comb(n, r, mod=10 ** 9 + 7):
r = min(r, n-r)
upper = 1
for i in range(n, n-r, -1):
upper = (upper * i) % mod
lower = 1
for i in range(1, r+1):
lower = (lower * i) % mod
lower_inv = pow(lower, mod - 2, mod)
... | 1 | 65,963,944,273,162 | null | 214 | 214 |
#!/usr/bin/env python3
import sys
import numpy as np
import numba
from numba import i8
input = sys.stdin.buffer.readline
mod = 998244353
def I():
return int(input())
def MI():
return map(int, input().split())
@numba.njit((i8, i8[:]), cache=True)
def main(N, LR):
L, R = LR[::2], LR[1::2]
K = len(L... | n, k = map(int, input().split())
lr = [list(map(int, input().split())) for _i in range(k)]
mod = 998244353
dp = [0]*(n+1)
dp[1] = 1
for p in range(2, n+1):
for i, j in lr:
dp[p] += dp[max(p-i, 0)] - dp[max(p-j-1, 0)]
dp[p] %= mod
dp[p] += dp[p-1]
print((dp[n]-dp[n-1])%mod) | 1 | 2,741,182,764,968 | null | 74 | 74 |
a,b = input().split()
x = int(a) * b
y = int(b) * a
l = []
l.append(x)
l.append(y)
l = sorted(l)
print(min(l)) | a,b = input().split()
t = a*int(b)
q = b*int(a)
if t < q:
print(t)
else:
print(q) | 1 | 84,299,904,114,342 | null | 232 | 232 |
a = int(input())
ans = "Yes" if a>= 30 else "No"
print(ans) | a=int(input(''))
if a>=30:
print('Yes')
else:
print('No') | 1 | 5,795,259,950,672 | null | 95 | 95 |
X,Y=map(int, input().split())
v = [300000, 200000, 100000]
x = 0
y = 0
if X <= 3:
x = int(v[X-1])
if Y <= 3:
y = int(v[Y-1])
print(int(x + y + ((X==1) & (Y==1)) * 400000))
| x, y = map(int, input().split())
ans = max(4 - x, 0) + max(4 - y, 0)
print(ans * 10**5 if ans != 6 else 10**6)
| 1 | 140,655,156,244,242 | null | 275 | 275 |
def examE():
N, K = LI()
A = LI()
sumA = [0]*(N+1)
for i in range(1,N+1):
sumA[i] = sumA[i-1]+A[i-1]
d = defaultdict(int)
ans = 0
#連想配列 先頭からの番号 余分な量
que = deque()
for i,a in enumerate(sumA):
#K番目以降は一番左のやつ消していく
if que and que[0][0] <= (i-K):
d[que.p... | import collections
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=[0]
for i in range(n):
m.append((m[-1]+a[i]))
for i in range(n+1):
m[i]-=i
m[i]%=k
ans=0
dict=collections.defaultdict(int)
for i in range(1,n+1):
x=m[i]
if i<=k-1:
dict[m[i-1]]+=1
else:
dict[m[i-1]]+=1
dict[m[i-k... | 1 | 137,509,528,224,860 | null | 273 | 273 |
k,n=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
dm=0
for i in range(n):
dis=(a[i]-a[i-1])%k
dm=max(dm,dis)
print(k-dm)
| K,N=map(int,input().split())
A=[int(i) for i in input().split()]
dlist=[]
for i in range(1,N):
d=A[i]-A[i-1]
dlist.append(d)
dlist.append(A[0]+K-A[N-1])
print(K-max(dlist)) | 1 | 43,169,672,171,100 | null | 186 | 186 |
# -*- coding: utf-8 -*-
import sys
rectangle = []
h,w = 1,1
while not(h == 0 and w == 0):
h,w = map(int, input().split())
if not(h == 0 and w == 0):
rectangle.append([h,w])
for rec in rectangle:
row_count = 1
display = []
for row in range(rec[0]):
col_count = 0
if (row_co... | integer = int(input())
string = input()
if len(string) > integer:
print(string[:integer] + '...')
else:
print(string) | 0 | null | 10,260,159,851,332 | 51 | 143 |
n,k=map(int,input().split())
mod=10**9+7
def inv(x):
return pow(x,mod-2,mod)
N=2*10**5
Fact=[0 for i in range(N+1)]
Finv=[0 for i in range(N+1)]
Fact[0]=1
for i in range(N):
Fact[i+1]=(Fact[i]*(i+1))%mod
Finv[N]=inv(Fact[N])
for i in range(N-1,-1,-1):
Finv[i]=((i+1)*Finv[i+1])%mod
def C(a,b):
return (Fa... | N,A,B = list(map(int,input().split()))
if (B-A)%2 == 0:
print((B-A)//2)
exit()
A1 = A
B1 = B
A2 = A
B2 = B
count1 = N-B1
ans1 = 0
A1 += (N-B1)
B1 = N
if (B1-A1)%2 == 0:
ans1 = count1+(B1-A1)//2
else:
ans1 = count1+1+(B1-A1)//2
count2 = A2-1
ans2 = 0
B2 -= (A2-1)
A2 = 1
if (B2-A2)%2 == 0:
ans2 = cou... | 0 | null | 88,147,187,358,008 | 215 | 253 |
class card:
def __init__(self, types, value):
self.types = types
self.value = value
def bubbleSort(A, N):
for i in range(0, N):
for j in range(N - 1, i, -1):
if A[j].value < A[j - 1].value:
exchange(A, j - 1, j)
printCards(A)
print "Stable"
def selec... | n=int(input())
num_list1=list(map(str,input().split()))
num_list2=[]
input_list=[]
for k in num_list1:
num_list2.append(k)
input_list.append(k)
def bubble(num_list):
i=0
flag=True
while flag:
flag=False
for j in range(len(num_list)-1,i,-1):
if int(num_list[j-1][1])>int... | 1 | 26,246,237,060 | null | 16 | 16 |
from functools import reduce
from collections import deque
def operate(dq, op):
if op[0] == 'i':
dq.appendleft(int(op[7:]))
else:
k = op[6]
if k == 'F':
dq.popleft()
elif k == 'L':
dq.pop()
else:
try:
dq.remove(int(op[... | from collections import Counter
n = int(input())
s = Counter([input() for _ in range(n)])
before = 0
ans = []
s = s.most_common()
for i in range(len(s)):
if before == 0: before = s[i][1]
elif before != s[i][1]: break
ans.append(s[i][0])
for i in sorted(ans): print(i) | 0 | null | 34,850,109,342,382 | 20 | 218 |
z = input()
a = list(map(int, z.split()))
cnt = 0
for i in range(a[0], a[1] + 1, 1):
if a[2] % i == 0:
cnt += 1
print(cnt) | N = input()
flag = False
for i in range(len(N)):
if N[i] =="7":
flag =True
if flag:
print ("Yes")
else :
print ("No") | 0 | null | 17,575,980,713,412 | 44 | 172 |
count = int(input())
lists = []
for i in range(count):
new = input()
lists.append(new)
ac_count = lists.count('AC')
wa_count = lists.count('WA')
tle_count = lists.count('TLE')
re_count = lists.count('RE')
print("AC x " + str(ac_count))
print("WA x " + str(wa_count))
print("TLE x " + str(tle_count))
print("RE x "... | N = int(input())
ansAC = 0
ansWA = 0
ansTLE = 0
ansRE = 0
for i in range(N):
S = input()
if S == "AC":
ansAC += 1
elif S == "TLE":
ansTLE += 1
elif S == "WA":
ansWA += 1
elif S == "RE":
ansRE += 1
print("AC x " + str(ansAC))
print("WA x " + str(ansWA))
print("TLE x " + str(ansTLE))
print("RE... | 1 | 8,734,230,086,052 | null | 109 | 109 |
n = int(input())
songs = []
for _ in range(n):
s, t = input().split()
t = int(t)
songs.append((s, t))
x = input()
ans = 0
flag = False
for s, t in songs:
if flag:
ans += t
if s == x:
flag = True
print(ans)
| N = int(input())
l = []
for _ in range(N):
s, t = input().split()
t = int(t)
l.append([s, t])
X = input()
ans = 0
found = False
for s in l:
if found:
ans += s[1]
continue
if s[0] == X:
found = True
print(ans) | 1 | 96,891,513,519,852 | null | 243 | 243 |
from collections import defaultdict
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
# 素因数分解、リストで返す
#############################################################
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f... | # coding:UTF-8
import sys
from math import factorial
MOD = 10 ** 9 + 7
INF = 10000000000
# 素数列挙
def primeNumList(n):
d = [d for d in range(0, n+1)]
if n < 2:
return [[],d]
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n ** 0.5) + 1):
... | 1 | 4,108,537,544,272 | null | 85 | 85 |
import sys
list = map(int,sys.stdin.readline().split())
list.sort()
print(' '.join(map(str,list))) | a = input()
print('Yes' if input() in a+a else 'No') | 0 | null | 1,091,056,319,938 | 40 | 64 |
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
H,W = map(int, input().split())
s = [None for _ in range(H)]
for i in range(H):
s[i] = input()
dp = [[0]*(W+1) for _ in range(H+1)]
if s[0][0] == '#':
dp[1][1] += 1
for i in range(... | N = int(input())
S = input()
judge = [1]*N
for i in range(1,N):
if S[i-1] == S[i]:
judge[i] = 0
print(sum(judge)) | 0 | null | 109,760,907,393,100 | 194 | 293 |
m,d = map(int,input().split())
m2,d2 = map(int,input().split())
print(1 if m != m2 else 0) | M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())
print(1 if M1 != M2 else 0) | 1 | 124,848,624,332,082 | null | 264 | 264 |
n,x,t = map(int,input().split())
if n % x ==0:
print(int(n/x*t))
else:
print(int((n//x+1)*t))
| import math
#入力:N,M(int:整数)
def input2():
return map(int,input().split())
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
return list(map(int,input().split()))
n,x,t=input2()
ans=(math.ceil(n/x))*t
print(ans) | 1 | 4,199,224,910,530 | null | 86 | 86 |
def lcm(x, y):
from fractions import gcd
return (x * y) // gcd(x, y)
a,b = map(int,input().split())
print(lcm(a,b)) | A,B = map(int,input().split())
def gcd(a, b):
if b==0:
return a
return gcd(b, a%b)
print(A*B//gcd(A,B)) | 1 | 113,232,944,524,518 | null | 256 | 256 |
#!/usr/bin/env python3
def solve(a,b):
str1 = str(a)*b
str2 = str(b)*a
if str1 < str2:
return str1
else:
return str2
def main():
a,b = map(int,input().split())
print(solve(a,b))
return
if __name__ == '__main__':
main()
| x, y = map(int, input().split())
if(x < y):
for i in range(0, y):
print(x, end = '')
else:
for i in range(0, x):
print(y, end = '')
| 1 | 84,259,474,647,968 | null | 232 | 232 |
def chess(h,w):
o = ""
for i in range(h):
if i%2:
if w%2: o+= ".#"*(w/2)+".\n"
else: o+= ".#"*(w/2)+"\n"
else:
if w%2: o+= "#."*(w/2)+"#\n"
else: o+= "#."*(w/2)+"\n"
print o
while 1:
h,w=map(int,raw_input().split())
if h==w==0:break
... | #!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
return sys.stdin.readline()[:-1]
def sort_zip(a:list, b:list):
z = zip(a, b)
z = sorted(z)
a, b = zip(*z)
a = list(a)
b = list(b)
return a, b
... | 0 | null | 4,972,284,574,388 | 51 | 110 |
n = int(input())
l = list(map(int,input().split()))
p=l[0]
s=0
for i in l[1:]:
s+= max(0,p-i)
p=max(p,i)
print(s) | n=int(input())
a=list(map(int,input().split()))
b=a[0]
ans=0
for n in range(n):
if a[n]>b:
b=a[n]
else:
ans+=b-a[n]
print(ans) | 1 | 4,563,315,213,788 | null | 88 | 88 |
# -*- coding: utf-8 -*-
def input_int():
return int(input())
def answer():
n = input_int()
count = 0
for a in range(1, n):
b = (n - 1) // a
if b >= a:
count += (b - a) * 2
count += 1
else:
continue
print(count)
answer() | N=int(input())
def num_divisors_table(n):
table=[0]*(n+1)
for i in range(1,n+1):
for j in range(i,n+1,i):
table[j]+=1
return table
l=num_divisors_table(N-1)
print(sum(l)) | 1 | 2,628,383,545,748 | null | 73 | 73 |
a = str(input().split())
b = list(a)
if b[4] == b[5] and b[7] == b[6]:
print("Yes")
else :
print("No") | S = input()
if S[2] == S[3] and S[-2] == S[-1]:
print('Yes')
else:
print('No') | 1 | 41,805,110,074,376 | null | 184 | 184 |
from itertools import permutations
def main():
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
A = [i for i in range(1, N+1)]
As = list(permutations(A))
for i in range(len(As)):
a = As[i]
for j in range(len(a)):
if a[j] != P... | import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
c = [i for i in range(1,n+1)]
v = list(itertools.permutations(c,n))
a = v.index(p)
b = v.index(q)
print(abs(a-b)) | 1 | 100,602,384,886,772 | null | 246 | 246 |
import sys
input = sys.stdin.readline
def main():
n = int(input())
stick = list(map(int, input().split()))
total = sum(stick)
mid = total // 2
cum = 0
midi = 0
for i, block in enumerate(stick):
cum += block
if cum >= mid:
midi = i
break
l1 = c... | N = input()
print("Yes" if "7" in N else "No") | 0 | null | 88,035,093,945,360 | 276 | 172 |
n, m = map(int, input().split())
d = {"1": -1, "2": -1, "3": -1}
for _ in range(m):
s, c = input().split()
if d[s] == -1:
d[s] = int(c)
elif d[s] != int(c):
print(-1)
exit()
n = str(4 - n)
if n != "3" and d["1"] == 0:
print(-1)
elif n == "1":
if d["1"] == -1:
d["1"] =... | import sys
N,M = map(int,input().split())
s = []
c = []
for i in range(M):
S,C = map(int,input().split())
s.append(S)
c.append(C)
for i in range(10**(N+1)):
st = str(i)
if len(st) == N and all([st[s[j]-1] == str(c[j]) for j in range(M)]):
print(st)
sys.exit()
print(-... | 1 | 60,967,920,170,818 | null | 208 | 208 |
n = input()
xi = map(int, raw_input().split())
print ("%d %d %d") %(min(xi), max(xi), sum(xi)) | n = int(input())
a = input().split()
min = int(a[0])
max = int(a[0])
sum = 0
for i in a:
if min > int(i):
min = int(i)
if max < int(i):
max = int(i)
sum += int(i)
print("{0} {1} {2}".format(min, max, sum)) | 1 | 723,257,894,998 | null | 48 | 48 |
a,b,k = map(int, input().split())
if k > a and k >= a+b:
print( 0 , 0 )
elif k < a :
print(a-k , b)
elif k == a:
print(0 , b)
elif k>a and k < a+b:
print(0 , b-(k-a))
| n,*a=map(int,open(0).read().split())
b=[0]*n
for i in range(n):
b[a[i]-1]=str(i+1)
print(' '.join(b)) | 0 | null | 142,753,624,444,828 | 249 | 299 |
import sys
from collections import deque
def LS():
return list(input().split())
S = deque(input())
Q = int(input())
rev = 0
for i in range(Q):
A = LS()
if A[0] == "1":
rev += 1
rev %= 2
else:
if A[1] == "1":
if rev == 0:
S.appendleft(A[2])
... | x, n = map(int, input().split())
p = list(map(int, input().split()))
l = [i - x for i in p]
m = [0]
for i in range(1, 101):
m.append(-i)
m.append(i)
for i in range(201):
if (m[i] in l) == True:
continue
if (m[i] in l) == False:
print(x + m[i])
break | 0 | null | 35,665,357,322,140 | 204 | 128 |
H,W,K = map(int,input().split())
S = [input() for _ in range(H)]
ans = 10**10
for i in range(2**(H-1)): # iはbit
rel = [0 for h in range(H)]
a,b = 0,0
for h in range(H-1):
if i>>h&1:
b += 1
rel[h+1] = b
a += b
cnt = [0 for j in range(b+1)]
for w in range(W):
... | h = int(input())
sumn = 0
i,k = 0,1
while k <= h:
sumn+=k
i+=1
k = 2**i
print(sumn) | 0 | null | 64,276,696,237,952 | 193 | 228 |
values = input()
W, H, x, y, r = [int(x) for x in values.split()]
flag = True
if x - r < 0 or x + r > W:
flag = False
if y - r < 0 or y + r > H:
flag = False
if flag:
print('Yes')
else:
print('No') | m,d=map(int,input().split())
n,e=map(int,input().split())
print(1 if m!=n else 0) | 0 | null | 62,401,031,189,248 | 41 | 264 |
n = input()
S = map(int,raw_input().split())
q = input()
T = map(int,raw_input().split())
ans = 0
for t in T:
if t in S:
ans+=1
print ans | s=input()
k=int(input())
n=len(s)
ans=0
tmp=0
x=s[0]
ss=[]
for i in range(n):
if x==s[i]:
tmp+=1
else:
ss.append(tmp)
tmp=1
x=s[i]
if tmp>0:
ss.append(tmp)
if len(ss)==1:
print(n*k//2)
else:
if s[0]==s[-1]:
ans=(-(ss[0]//2)-(ss[-1]//2)+(ss[0]+ss[-1])//2)*(k-1)
for i in ss:
ans+=i//2*... | 0 | null | 87,361,692,417,732 | 22 | 296 |
h, w = map(int, input().split())
s_list = [] # h, w
dp_dict = {}
for i in range(h):
s = input()
temp_list = []
for temp in s:
if temp == "#":
temp_list.append(1)
else:
temp_list.append(0)
s_list.append(temp_list)
def search(x, y, black):
res = 0
if (x, ... | import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10**7)
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa... | 0 | null | 29,645,530,656,270 | 194 | 114 |
N = int(input())
eList = ['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']
n = N
mod = N
numList = []
while n > 0:
n, mod = divmod(n,26)
if mod != 0:
numList.insert(0, mod - 1)
else:
numList.insert(0, 25)
n -= 1
ans =''
for num in numList:
an... | N=int(input())
S=input()
x="Yes"
if N%2==1:
print("No")
else:
for i in range(0,N//2):
if S[i]!=S[i+N//2]:
x="No"
break
print(x) | 0 | null | 79,597,720,733,960 | 121 | 279 |
import math
H, W, K = map(int, input().split())
S = [list(map(lambda x: int(x=='1'), input())) for _ in range(H)]
def cal_min_vert_div(hs):
cnt = 0
n_h_div = len(hs)
n_white = [0]*n_h_div
for i in range(W):
for j in range(n_h_div):
n_white[j] += hs[j][i]
if n_white[j] >... | inputted = list(map(int, input().split()))
K = inputted[0]
X = inputted[1]
total = 500 * K;
answer = 'Yes' if total >= X else 'No';
print(answer);
| 0 | null | 73,341,284,338,570 | 193 | 244 |
import fractions
from functools import reduce
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def lcm(*numbers):
return reduce(lcm_base, numbers, 1)
N,M=map(int,input().split())
A=[int(i)//2 for i in input().split()]
q=lcm(*A)
#print(q)
for i in A:
#print(i)
if q//i%2==0:
print(... | def main():
from fractions import gcd
from math import ceil
n, m, *a = map(int, open(0).read().split())
b = [0 for _ in range(n)]
a.sort()
for i, j in enumerate(a):
c = 0
while j % 2 == 0:
c += 1
j = j // 2
a[i] = j
b[i] = c
if len(s... | 1 | 102,142,022,786,816 | null | 247 | 247 |
a = sum(list(map(int, input().split())))
if a >+ 21:
print('bust')
else:
print('win') | N, K = map(int, input().split())
A = list(map(int, input().split()))
A_neg = []
A_pos = []
for i in range(N):
if A[i] <= 0:
A_neg.append(-A[i])
else:
A_pos.append(A[i])
A_neg.sort(reverse=True)
A_pos.sort(reverse=True)
ans = 1
if K == N:
for i in range(N):
ans *= (A[i]%1000000007)
ans %= 1000... | 0 | null | 64,364,192,217,020 | 260 | 112 |
def dfs(lst):
global ans
if len(lst) > n:
return
lowest = 1
if lst != []:
lowest = lst[-1]
for i in range(lowest, m+1):
lst.append(i)
dfs(lst)
lst.pop()
if len(lst) == n:
cnt = 0
for i in range(q):
a, b, c, d = ab[i]
... | a,b,c = list(map(int,input().split()))
d = c-a-b
if d <= 0:
print("No")
else:
if d**2 > 4*a*b:
print("Yes")
else:
print("No") | 0 | null | 39,916,728,702,678 | 160 | 197 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.