code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
arr = list(map(int,input().split()))
print(int(arr[0])*int(arr[1]))
|
n = int(input())
cards = [[0 for i in range(13)] for j in range(4)]
for i in range(n):
Input = input().split()
if Input[0] == "S":
cards[0][int(Input[1])-1]= 1
if Input[0] == "H":
cards[1][int(Input[1]) - 1] = 1
if Input[0] == "C":
cards[2][int(Input[1]) - 1] = 1
if Input[0] == "D":
cards[3][int(Input[1]) - 1] = 1
for i in range(4):
for j in range(13):
if cards[i][j] == 0:
if i == 0:
print("S",j+1)
if i == 1:
print("H",j+1)
if i == 2:
print("C", j + 1)
if i == 3:
print("D", j + 1)
| 0 | null | 8,406,342,715,890 | 133 | 54 |
x = input().strip()
if x[-1] == 's':
x += "es"
else:
x += 's'
print(x)
|
a=input()
b=list(a)
if b[-1]=="s":
print(a+"es")
else:
print(a+"s")
| 1 | 2,373,413,097,732 | null | 71 | 71 |
N,M = map(int,input().split())
print(("No","Yes")[N == M])
|
a= list(map(int,input().split()))
n=a[0]
m=a[1]
if n==m:
print("Yes")
else:
print("No")
| 1 | 83,199,560,424,418 | null | 231 | 231 |
n=int(input())
print(sum(i*(n//i*(n//i+1))//2 for i in range(1,n+1)))
|
n = int(input())
ans = 0
for a in range(1, n + 1):
num = n // a
ans += num * (num + 1) // 2 * a
print(ans)
| 1 | 11,049,293,068,160 | null | 118 | 118 |
H, M = map(int, input().split())
A = list(map(int, input().split()))
for i in A:
H -= i
if H < 0:
print("-1")
else:
print(H)
|
import numpy as np
N, M = map(int, input().split())
A = []
A = map(int, input().split())
dif = N - sum(A)
if dif >= 0:
print(dif)
else:
print('-1')
| 1 | 32,063,470,552,740 | null | 168 | 168 |
N, M, K = map(int, input().split(' '))
A_ls = [0] + list(map(int, input().split(' ')))
for i in range(len(A_ls) - 1):
A_ls[i + 1] += A_ls[i]
B_ls = [0] + list(map(int, input().split(' ')))
for i in range(len(B_ls) - 1):
B_ls[i + 1] += B_ls[i]
b_cnt,result = M, 0
for a_cnt in range(N + 1):
if A_ls[a_cnt] > K:
break
while A_ls[a_cnt] + B_ls[b_cnt] > K:
b_cnt -= 1
result = max(result, a_cnt + b_cnt)
print(result)
|
import sys
from collections import defaultdict, Counter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def prime_factorize(n):
a = Counter()
while n % 2 == 0:
a[2] += 1
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a[f] += 1
n //= f
else:
f += 2
if n != 1:
a[n] += 1
return a
def main():
N, *A = map(int, read().split())
lcm_prime = Counter()
for a in A:
for p, n in prime_factorize(a).items():
if lcm_prime[p] < n:
lcm_prime[p] = n
l = 1
for p, n in lcm_prime.items():
l = l * pow(p, n, MOD) % MOD
ans = 0
for a in A:
ans = (ans + pow(a, MOD - 2, MOD)) % MOD
ans = ans * l % MOD
print(ans)
return
if __name__ == '__main__':
main()
| 0 | null | 49,070,561,276,102 | 117 | 235 |
n = input()
data = [int(i) for i in input().split(' ')]
def insertion_sort(raw_list):
for i, v in enumerate(raw_list):
if i == 0:
continue
j = i - 1
while j >= 0 and v < raw_list[j]:
raw_list[j+1] = v
raw_list[j+1] = raw_list[j]
j -= 1
raw_list[j+1] = v
print(' '.join([str(i) for i in raw_list]))
return raw_list
print(' '.join([str(i) for i in data]))
insertion_sort(data)
#print(' '.join([str(i) for i in insertion_sort(data)]))
|
a, b, c, d = map(int,input().split())
while True:
c = c - b
a = a - d
if c <= 0:
print('Yes')
break
elif a <= 0:
print('No')
break
else:
pass
| 0 | null | 14,753,795,014,402 | 10 | 164 |
s=input()
a=len(s)
if s[a-1]=='s':
print(s+'es')
else :
print(s+'s')
|
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline
def main():
n=int(input())
ans=0
for i in range(1,n):
if (i!=n-i and i<n-i):
ans+=1
elif i>n-1:
break
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 78,157,984,774,932 | 71 | 283 |
A,B=input().split()
A=int(A)
B=int(100*float(B)+0.1)
print(int(A*B/100))
|
lst=[int (x) for x in input().split(' ')]
print(lst[0]*lst[1])
| 1 | 15,814,870,502,860 | null | 133 | 133 |
s = int(input())
a = []
a.append(1)
a.append(0)
a.append(0)
for i in range(3,s+1):
a.append(sum(a)-a[i-1]-a[i-2])
ans = a[-1] % (10**9 + 7)
print(ans)
|
def main():
W,H,x,y,r=map(int,input().split())
if x<=0 or y<=0:
print('No')
elif W>=2*r and H>=2*r and W>=x+r and H>=y+r:
print('Yes')
else:
print('No')
if __name__=='__main__':
main()
| 0 | null | 1,888,141,833,490 | 79 | 41 |
from collections import namedtuple
Card = namedtuple('Card', 'suit value')
def BubbleSort(C):
for i in range(len(C)):
for j in range(len(C)-1,i,-1):
if C[j].value < C[j-1].value:
C[j],C[j-1] = C[j-1],C[j]
def SelectionSort(C):
for i in range(len(C)):
mini = i
for j in range(i,len(C)):
if C[j].value < C[mini].value:
mini = j
C[i],C[mini] = C[mini],C[i]
def checkStable(C0, C1):
result = True
for i in range(1,10):
f0 = [x.suit for x in list(filter(lambda c: c.value==i,C0))]
f1 = [x.suit for x in list(filter(lambda c: c.value==i,C1))]
if f0!=f1:
result = False
return result
if __name__=='__main__':
N = int(input())
Co = list(map(lambda X: Card(X[0],int(X[1])), map(list, input().split())))
Cb,Cs = [Co[:] for _ in range(2)]
for C, Sort in zip([Cb,Cs], [BubbleSort, SelectionSort]):
Sort(C)
print(*["".join([X.suit,str(X.value)]) for X in C])
print("Stable" if checkStable(Co,C) else "Not stable")
|
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 18 10:01:05 2017
@author: syaga
"""
if __name__ == "__main__":
N = int(input())
C = list(input().split())
D = C[:]
# Bunbble Sort
for i in range(0, N):
for j in range(N-1, i, -1):
if int(C[j][1]) < int(C[j-1][1]):
temp = C[j]
C[j] = C[j-1]
C[j-1] = temp
print(" ".join(C))
print("Stable")
# Selection Sort
for i in range(0, N):
minj = i
for j in range(i, N):
if int(D[j][1]) < int(D[minj][1]):
minj = j
temp = D[i]
D[i] = D[minj]
D[minj] = temp
print(" ".join(D))
flag = 0
for (i, j) in zip(C, D):
if i != j:
flag = 1
break
if flag == 1:
print("Not stable")
else:
print("Stable")
| 1 | 25,339,051,078 | null | 16 | 16 |
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def readInt():return int(input())
def readIntList():return list(map(int,input().split()))
def readStringList():return list(input())
def readStringListWithSpace():return list(input().split())
def readString():return input()
x = readInt()
print("Yes" if x >= 30 else "No")
|
#!/usr/bin/env python3
def main():
if int(input()) >= 30:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
| 1 | 5,740,067,243,934 | null | 95 | 95 |
#In[]:
x = int(input())
money = 100
year = 0
while True:
money += money//100
year += 1
if money >= x:
print(year)
break
|
#a = list(map(int,input().split()))
#b = list(map(int,input().split()))
a = int(input())
x = int(100)
count= 0
while a > x:
count+=1
x += x//100
print(count)
| 1 | 27,032,361,986,102 | null | 159 | 159 |
num = []
while True:
l = map(int, raw_input().split())
if l[0] == l[1] == l[2] == -1:
break
if l[0]*l[1] < 0:
num.append("F")
else:
sum = l[0] + l[1]
if sum >= 80:
num.append("A")
elif sum >= 65:
num.append("B")
elif sum >= 50:
num.append("C")
elif sum >= 30:
if l[2] >= 50:
num.append("C")
else:
num.append("D")
else:
num.append("F")
for i in range(len(num)):
print num[i]
|
import sys
a = sys.stdin.readlines()
for i in range(len(a)):
b = a[i].split()
m =int(b[0])
f =int(b[1])
r =int(b[2])
if m*f < 0 :
print "F"
elif m==-1 and f==-1 and r==-1:
break
else:
if m+f >= 80:
print "A"
elif 80 > m+f >=65:
print "B"
elif 65 > m+f >=50:
print "C"
elif 50 > m+f >=30 and r < 50:
print "D"
elif 50 > m+f >=30 and r >= 50:
print "C"
elif 30 > m+f:
print "F"
| 1 | 1,214,987,503,356 | null | 57 | 57 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
A = list(map(int, readline().split()))
if sum(A) >= 22:
print("bust")
else:
print("win")
if __name__ == '__main__':
main()
|
print("\n".join(["%dx%d=%d"%(i,j,i*j)for i in range(1,10)for j in range(1,10)]))
| 0 | null | 59,209,556,642,302 | 260 | 1 |
num = (1,0,0)
for _ in range(int(input()) - 2):
num = (num[1],num[2],num[0]+num[2])
print(num[2]%(10**9+7))
|
S = int(input())
MOD = 10 ** 9 + 7
DP = [0] * (2000+1)
DP[0]
DP[3]=1
for i in range(4,2001):
DP[i]=DP[i-1]+DP[i-3]
print(DP[S]%(10**9+7))
| 1 | 3,311,771,017,500 | null | 79 | 79 |
import sys
N = int(input())
result = 0
for a in range(1, N):
if N % a == 0:
b_count = N // a - 1
else:
b_count = N // a
result += b_count
print(result)
|
import math
N = int(input())
A = [0]*(N)
for i in range(0,N):
A[i] = math.floor((N-1)/(i+1))
print(sum(A))
| 1 | 2,602,563,346,460 | null | 73 | 73 |
n = int(input())
S = input()
distinct = 1
for i in range(1, len(S)):
if S[i-1] != S[i]:
distinct += 1
print(distinct)
|
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)
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 171,042,633,492,612 | 293 | 294 |
s, t = input().split()
a, b = map(int, input().split())
u = input()
if s == u:
print(str(a-1)+" "+str(b))
else:
print(str(a)+" "+str(b-1))
|
a = input()
a = int(a)
print(a*a*a)
| 0 | null | 36,026,908,296,566 | 220 | 35 |
class Dice:
def __init__(self, eyes):
self._eyes = ['dummy'] + eyes
@property
def eye(self):
return self._eyes[1]
def roll(self, direction):
old = self._eyes
new = ['dummy'] * 7
if direction == 'N':
new[1] = old[2]
new[2] = old[6]
new[3] = old[3]
new[4] = old[4]
new[5] = old[1]
new[6] = old[5]
elif direction == 'S':
new[1] = old[5]
new[2] = old[1]
new[3] = old[3]
new[4] = old[4]
new[5] = old[6]
new[6] = old[2]
elif direction == 'W':
new[1] = old[3]
new[2] = old[2]
new[3] = old[6]
new[4] = old[1]
new[5] = old[5]
new[6] = old[4]
elif direction == 'E':
new[1] = old[4]
new[2] = old[2]
new[3] = old[1]
new[4] = old[6]
new[5] = old[5]
new[6] = old[3]
else:
raise ValueError('NEWS箱推し')
self._eyes = new
eyes = input().split()
dice = Dice(eyes)
direction_text = input()
for d in direction_text:
dice.roll(d)
print(dice.eye)
|
S = input()
if len(S)//2 * "hi" == S:
print("Yes")
else:
print("No")
| 0 | null | 26,517,425,679,954 | 33 | 199 |
import sys
sys.setrecursionlimit(10**7)
n = int(input())
def dfs(s):
if len(s) == n:
print(s)
return 0
for x in map(chr, range(97, ord(max(s))+2)):
dfs(s+x)
dfs('a')
|
# 使えるのは、'a' ~ 今まで使われた次の文字
n = int(input())
def dfs(cnt,s):
if cnt == n:
print(s)
return
biggest = 'a'
c = 0
while c < len(s):# 最後はどこまで?
if s[c] == biggest:
biggest = chr(ord(biggest)+1)
c += 1
else:
c += 1
#print(c)
for i in range(0,ord(biggest) - ord('a')+1):
sc = chr(ord('a') + i)
#print(sc)
s += sc
dfs(cnt + 1, s)
s = s[:-1]
dfs(0,"")
| 1 | 52,277,181,922,980 | null | 198 | 198 |
import numpy as np
from numba import *
N = int(input())
length = np.array(input().split(), np.int64)
length = np.sort(length)
def calc(length):
cnt = 0
for i in range(N):
for j in range(i + 1, N):
for k in range(j + 1, N):
l1, l2, l3 = length[i], length[j], length[k]
if (l1 != l2 and l1 != l3 and l2 != l3):
if (l1 + l2 > l3):
cnt += 1
return (cnt)
ans = calc(length)
print(ans)
|
N = int(input())
L = list(map(int, input().split()))
c = 0
for i in range(N):
for j in range(i+1,N):
for k in range(j+1,N):
if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]:
if L[i] + L[j] + L[k] > 2 * max(L[i],L[j],L[k]):
c +=1
print(c)
| 1 | 5,048,294,691,642 | null | 91 | 91 |
N = input()
if (N[-1] == str(3)):
print('bon')
elif(int(N[-1]) == 0 or int(N[-1]) == 1 or int(N[-1]) == 6 or int(N[-1]) == 8 ):
print('pon')
else:
print('hon')
|
n=list(map(int,input()))
if n[-1] in [2,4,5,7,9]:
print('hon')
elif n[-1] in [0,1,6,8]:
print('pon')
else:
print('bon')
| 1 | 19,443,127,541,930 | null | 142 | 142 |
S = input()
length =len(S)
S = list(S)
count = 0
for i in range(length):
if S[i] == '?':
S[i] = 'D'
answer = "".join(S)
print(answer)
|
t = input()
ans = t
tem = ''
if '?' in t :
if len(t) == 1 :
ans = 'D'
elif len(t) == 2 :
if t[0] == '?' and t[1] == '?' :
ans = 'PD'
elif t[0] == '?' and t[1] == 'D':
ans = 'PD'
elif t[0] == '?' and t[1] == 'P':
ans ='DP'
elif t[1] == '?' and t[0] == 'P':
ans = 'PD'
elif t[1] == '?' and t[0] == 'D':
ans = 'DD'
else:
for i in range(0,len(t)):
if i == 0 :
if t[i] == '?' and t[i+1] == 'P':
ans = 'D'
elif t[i] == '?' :
ans = 'P'
else :
ans = t[i]
elif i == len(t)-1 :
if t[i] == '?' :
ans += 'D'
else:
ans += t[i]
else:
if t[i] == '?':
if ans[i-1] == 'P':
ans += 'D'
elif t[i+1] == 'D' or t[i+1] == '?':
ans += 'P'
else:
ans += 'D'
else:
ans += t[i]
print(ans)
| 1 | 18,481,026,402,802 | null | 140 | 140 |
X, Y = list(map(int, input().split()))
crane = 2*X - Y/2
turtle = Y/2 - X
print(['No', 'Yes'][crane >= 0 and turtle >= 0 and abs(crane) + abs(turtle) > 0 and Y % 2 == 0])
|
x,y=map(int,input().split())
a=(y-2*x)//2
b=x-a
if y%2==0 and a>=0 and b>=0:
print("Yes")
else:
print("No")
| 1 | 13,846,274,646,942 | null | 127 | 127 |
Ans=[]
i=0
while True:
l=input().split()
m=int(l[0])
f=int(l[1])
r=int(l[2])
if m==-1 and f==-1 and r==-1:
break
elif m==-1 or f==-1:
Ans.append("F")
elif m+f>=80:
Ans.append("A")
elif m+f>=65 and m+f<80:
Ans.append("B")
elif m+f>=50 and m+f<65:
Ans.append("C")
elif m+f>=30 and m<50:
if r>=50:
Ans.append("C")
else:
Ans.append("D")
else:
Ans.append("F")
i+=1
m=0
while m<i:
print(Ans[m])
m=m+1
|
while True:
z=list(map(int,input().split()))
if z == [-1,-1,-1]:
break
if z[0]==-1 or z[1]==-1:
print('F')
elif z[0]+z[1]>=80:
print('A')
elif z[0]+z[1] >=65:
print('B')
elif z[0]+z[1] >=50 or z[2] >=50:
print('C')
elif z[0]+z[1] >=30 :
print('D')
else :
print("F")
| 1 | 1,203,497,590,130 | null | 57 | 57 |
from collections import deque
s = list(input())
moji = deque(s)
is_forward = True
q = int(input())
for i in range(q):
query = input()
if query[0] == "1":
is_forward = is_forward ^ 1
elif query[0] == "2":
_, f, c = query.split()
f = int(f)
f %= 2
is_end = f ^ is_forward
if is_end:
moji.append(c)
else:
moji.appendleft(c)
if is_forward == False:
moji = list(moji)[::-1]
print("".join(moji))
|
s = input()
q = int(input())
count = 0
a = []
b = []
for _ in range(q):
Q = list(map(str, input().split()))
if Q[0] == "1":
count += 1
else:
if (int(Q[1])+count)%2 == 1:
a.append(Q[2])
else:
b.append(Q[2])
a = "".join(a[::-1])
b = "".join(b)
s = a + s + b
if count%2 == 1 and count != 0:
s = s[::-1]
print("".join(s))
| 1 | 57,482,415,057,906 | null | 204 | 204 |
from queue import Queue
def isSafe(row, col):
return row >= 0 and col >= 0 and row<h and col<w and mat[row][col] != '#'
def bfs(row, col):
visited = [[False]*w for _ in range(h)]
que = Queue()
dst = 0
que.put([row, col, 0])
visited[row][col] = True
moves = [[-1, 0],[1, 0], [0, -1], [0, 1]]
while not que.empty():
root = que.get()
row, col, dst = root
for nrow, ncol in moves:
row2 = row + nrow
col2 = col + ncol
if isSafe(row2, col2) is True and visited[row2][col2] is False:
visited[row2][col2] = True
que.put([row2, col2, dst+1])
return dst
h, w = map(int, input().split())
mat = [input() for _ in range(h)]
ans = 0
for row in range(h):
for col in range(w):
if mat[row][col] == '.':
ans = max(ans, bfs(row, col))
print(ans)
|
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(H, W, Ss):
Ss = ['#' + S + '#' for S in Ss]
Ss = ['#' * (W + 2)] + Ss + ['#' * (W + 2)]
# for S in Ss:
# print(S)
ans = 0
for i in range(1, H + 1):
for j in range(1, W + 1):
if Ss[i][j] == '#':
continue
visited = [[-1] * (W + 2) for _ in range(H + 2)]
now = 0
visited[i][j] = now
q = deque([(i, j, now)])
while q:
x, y, n = q.popleft()
# for v in visited:
# print(v)
# input()
if Ss[x + 1][y] == '.' \
and visited[x + 1][y] < 0:
q.append((x + 1, y, n + 1))
visited[x + 1][y] = n + 1
if Ss[x - 1][y] == '.' \
and visited[x - 1][y] < 0:
q.append((x - 1, y, n + 1))
visited[x - 1][y] = n + 1
if Ss[x][y + 1] == '.' \
and visited[x][y + 1] < 0:
q.append((x, y + 1, n + 1))
visited[x][y + 1] = n + 1
if Ss[x][y - 1] == '.' \
and visited[x][y - 1] < 0:
q.append((x, y - 1, n + 1))
visited[x][y - 1] = n + 1
ans = max(ans, max([max(v) for v in visited]))
print(ans)
if __name__ == '__main__':
H, W = map(int, input().split())
Ss = [input() for _ in range(H)]
solve(H, W, Ss)
| 1 | 94,652,205,525,512 | null | 241 | 241 |
# coding=utf-8
while True:
x, y = map(int, raw_input().rstrip().split())
if x + y:
print '{} {}'.format(*sorted([x, y]))
else:
break
|
ab=list(map(int,input().split()))
a=ab[0]
b=ab[1]
if a<10 and b<10:
print(a*b)
else:
print(-1)
| 0 | null | 79,592,140,925,430 | 43 | 286 |
import sys
import collections
S=collections.deque(input())
Q=int(input())
rev=0
for _ in range(Q):
fields=next(sys.stdin).split()
T,F,C=(fields+['',''])[:3]
if T=='1':
rev^=1
elif (rev and F=='1') or (not rev and F=='2'):
S.append(C)
else:
S.appendleft(C)
if rev:
print(''.join(reversed(S)))
else:
print(''.join(S))
|
s = input()
sgn = 1
Q = int(input())
L = '' #sgn=-1
R = '' #sgn=1
for _ in range(Q):
i = input()
if i[0] == '1':
sgn*=-1
else:
if i[2] == '1':
if sgn == 1:
L += i[4]
else:
R += i[4]
else:
if sgn == 1:
R += i[4]
else:
L += i[4]
if sgn == -1:
s = s[::-1]
R = R[::-1]
print(R + s +L)
else:
L = L[::-1]
print(L + s + R)
| 1 | 57,215,414,919,152 | null | 204 | 204 |
n = list(input())
ans = 0
for i in n:
ans += int(i)
ans = ans%9
print('Yes' if ans == 0 else 'No')
|
import math
INF=float('inf')
ans1='pairwise coprime'
ans2='setwise coprime'
ans3='not coprime'
n=int(input())
A=list(map(int,input().split()))
P=[0]*(10**6+1)
for i in A:
P[i]+=1
pairwise=True
for i in range(2,10**6+1):
cnt=0
for j in range(i,10**6+1,i):
cnt+=P[j]
if cnt>1:
pairwise=False
break
if pairwise:
print(ans1)
exit()
g=math.gcd(A[0],A[1])
for i in A:
g=math.gcd(g,i)
if g==1:
print(ans2)
else:
print(ans3)
| 0 | null | 4,251,001,265,344 | 87 | 85 |
H, W, K = map(int, input().split())
S = [list(input()) for _ in range(H)]
res = float('inf')
for i in range(2**(H-1)):
c = bin(i).count('1')
cnt = c
sum_l = [0] * (c+1)
j = 0
flag = True
while j < W:
tmp = sum_l.copy()
pos = 0
for k in range(H):
if S[k][j] == '1':
tmp[pos] += 1
if (i >> k) & 1:
pos += 1
if max(tmp) <= K:
sum_l = tmp.copy()
j += 1
flag = False
else:
if flag:
cnt = float('inf')
break
cnt += 1
flag = True
sum_l = [0] * (c+1)
res = min(res, cnt)
print(res)
|
l = list(map(int, input().split()))
for i in range(5):
if l[i] == 0:
print(i + 1)
| 0 | null | 30,880,551,765,830 | 193 | 126 |
n = int(input())
mydict = {}
answer_list = []
for i in range(n) :
query, wd = input().split()
if query == "insert" :
mydict[wd] = 1
else :
if wd in mydict.keys() : answer_list.append("yes")
else : answer_list.append("no")
for i in answer_list :
print(i)
|
dice_init = input().split()
dicry = {'search':"152304",'hittop':'024135', 'hitfront':'310542'}
num = int(input())
def dicing(x):
global dice
dice = [dice[int(c)] for c in dicry[x]]
for _ in range(num):
dice = dice_init
top, front = map(int, input().split())
while True:
if int(dice[0]) == top and int(dice[1]) == front:
break
elif int(dice[0]) == top:
dicing('hittop')
elif int(dice[1]) == front:
dicing('hitfront')
else:
dicing('search')
print(dice[2])
| 0 | null | 166,303,263,222 | 23 | 34 |
alist = list(map(int, input().split()))
print(alist.index(0)+1)
|
a,b,c,d,e=map(int,input().split())
print(15-a-b-c-d-e)
| 1 | 13,296,769,944,118 | null | 126 | 126 |
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
a, b = inm()
print(a * b)
|
if __name__ == "__main__":
a,b = map(int, input().split(" "))
print(a*b)
| 1 | 15,882,762,740,854 | null | 133 | 133 |
from math import sqrt
N = int(input())
# Cが固定されAxBを入れ替えるときは省略したい
def make_divisors(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divisors[::-1]
ans = 0
""" for C in range(1,N):
ans += len(make_divisors(N-C)) """
for A in range(1,N):
ans += (N-1)//A
print(ans)
|
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1
for i in range(N):
ai = A[i]
for j in range(S + 1):
here = dp[i][j]
# aiがTに含まれない
dp[i + 1][j] += here
# aiがTに含まれるが, Uに含まれない
dp[i + 1][j] += here
dp[i + 1][j] %= MOD
# aiがUに含まれる
if j + ai <= S:
dp[i + 1][j + ai] += dp[i][j]
dp[i + 1][j + ai] %= MOD
print(dp[N][S])
| 0 | null | 10,171,418,091,692 | 73 | 138 |
H,W = map(int, input().split())
if H == 1 or W == 1:
print(1)
else:
t = H * W
print(t // 2) if t % 2 == 0 else print((t // 2) + 1)
|
import sys
import math
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
H,W= LI()
if H == 1 or W == 1:
print(1)
else:
ans = (H*W+1)/2
print(int(ans))
| 1 | 51,014,108,225,792 | null | 196 | 196 |
from collections import deque
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def bfs(field, sx, sy, seen):
queue = deque([(sx, sy)])
seen[sx][sy] += 1
while queue:
x, y = queue.popleft()
for dx, dy in [(-1, 0), (0, 1), (1, 0), (0, -1)]:
nx = x + dx
ny = y + dy
if seen[nx][ny] == -1 and field[nx][ny] != "#":
seen[nx][ny] = seen[x][y] + 1
queue.append((nx, ny))
return seen[x][y]
def main():
H,W = map(int, readline().split())
c = ["#" * (W + 2)]
for _ in range(H):
c.append("#" + readline().strip() + "#")
c.append("#" * (W + 2))
ans = 0
for sx in range(1,H+1):
for sy in range(1,W+1):
if c[sx][sy] == ".":
seen = [[-1] * (W + 2) for i in range(H+2)]
dist = bfs(c, sx, sy, seen)
ans = max(ans, dist)
print(ans)
if __name__ == "__main__":
main()
|
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
h, w = LI()
s = SRL(h)
ans = []
for i in range(h):
for j in range(w):
if s[i][j] == "#":
continue
v = [[-1] * w for _ in range(h)]
q = deque()
q.append((i, j))
v[i][j] = 1
goal = tuple()
while q:
r, c = q.popleft()
for x, y in ((1, 0), (-1, 0), (0, -1), (0, 1)):
if r + x < 0 or r + x > h - 1 or c + y < 0 or c + y > w - 1 or s[r + x][c + y] == "#" or v[r + x][c + y] > 0:
continue
v[r + x][c + y] = v[r][c] + 1
q.append((r + x, c + y))
ans.append(max(chain.from_iterable(v)) - 1)
print(max(ans))
| 1 | 94,416,990,231,152 | null | 241 | 241 |
r=float(input())
a=r*r*(3.141592653589)
b=(r+r)*(3.141592653589)
print(f"{a:.6f} {b:.6f}")
|
import sys
import math
#r = map(int,input().split())
r = float(input())
print ('%.5f %.5f'% (r**2*math.pi, 2*r*math.pi))
| 1 | 642,824,095,508 | null | 46 | 46 |
from collections import deque
import sys
n = int(input())
deq = deque()
for _ in range(n):
cmd = input()
if cmd[0] == "i":
deq.appendleft(cmd[7:])
elif cmd[6] == "F":
deq.popleft()
elif cmd[6] == "L":
deq.pop()
else:
try:
deq.remove(cmd[7:])
except:
pass
print(" ".join(deq))
|
N = int(input())
S = list(map(int,input().split()))
ans = 0
for x in range(N-1):
for y in range(x+1,N):
ans += S[x]*S[y]
print(ans)
| 0 | null | 83,896,687,565,860 | 20 | 292 |
def resolve():
n,m = map(int,input().split())
print('Yes' if n==m else 'No')
resolve()
|
def main():
n, m = map(int, input().split())
print('Yes') if n <= m else print('No')
if __name__ == '__main__':
main()
| 1 | 83,246,931,473,088 | null | 231 | 231 |
n=int(input())
a=[]
while n>26:
n=n-1
a.append(chr(ord('a') + n%26))
n=n//26
n=n-1
a.append(chr(ord('a') + n%26))
a.reverse()
print("".join(a))
|
inp = input().split()
A = int(inp[0])
B = int(inp[1].replace('.',''))
print(A*B//100)
| 0 | null | 14,149,763,027,530 | 121 | 135 |
def solve(a, op, b):
if op == '+':
return a + b
elif op == '-':
return a - b
elif op == '*':
return a * b
elif op == '/':
return a // b
return None
if __name__ == '__main__':
while True:
a, op, b = input().split()
if op == '?': break
print(solve(int(a), op, int(b)))
|
list = input().split()
stack = []
for i in list:
if ( i.isdigit() ):
stack.append(int(i))
elif (i == '+'):
stack.append(stack.pop() + stack.pop())
elif (i == '*'):
stack.append(stack.pop() * stack.pop())
elif (i == '-'):
stack.append( (-1)*stack.pop() + stack.pop())
print(stack.pop())
| 0 | null | 357,296,633,584 | 47 | 18 |
n,k = map(int, input().split())
ans = 0
for i in range(k,n+2):
a = (i-1)*i//2
ans += n*i-2*a+1
print(ans%(10**9+7))
|
a = []
for i in range(10):
a.append(int(raw_input()))
a.sort()
a.reverse()
for i in range(3):
print a[i]
| 0 | null | 16,452,967,341,888 | 170 | 2 |
import sys
def insertionSort(A, n, g):
for i in range(g, n):
global cnt
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 shellSort(A, n):
global m
global G
for i in range(0, m):
insertionSort(A, n, G[i])
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
if n == 1:
print(1)
print(1)
print(0)
print(A[0])
sys.exit()
t = n - 1
G = []
G.append(t)
while t != 1:
t = t//2
G.append(t)
m = len(G)
cnt = 0
shellSort(A, n)
print(m)
print(' '.join(map(str, G)))
print(cnt)
for i in range(n):
print(A[i])
|
N = int(input())
S = [input() for i in range(N)]
ans = len(set(S))
print(ans)
| 0 | null | 15,050,247,482,800 | 17 | 165 |
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
N,u,v = MI()
Graph = [[] for _ in range(N+1)]
for i in range(N-1):
a,b = MI()
Graph[a].append(b)
Graph[b].append(a)
dist_T = [-1]*(N+1) # uからの最短距離
dist_A = [-1]*(N+1) # vからの最短距離
dist_T[u] = 0
dist_A[v] = 0
from collections import deque
q1 = deque([u])
q2 = deque([v])
while q1:
n = q1.pop()
for d in Graph[n]:
if dist_T[d] == -1:
dist_T[d] = dist_T[n] + 1
q1.appendleft(d)
while q2:
n = q2.pop()
for d in Graph[n]:
if dist_A[d] == -1:
dist_A[d] = dist_A[n] + 1
q2.appendleft(d)
ans = 0
for i in range(1,N+1):
if dist_T[i] < dist_A[i]:
ans = max(ans,dist_A[i]-1)
print(ans)
|
import sys
input = sys.stdin.readline
I=lambda:int(input())
MI=lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))
from collections import deque
res=0
INF=10**9
N,u,v=MI()
G=[[] for _ in [0]*(N+1)]
for i in range(N-1):
a,b=MI()
G[a].append(b)
G[b].append(a)
def bfs(a):
q=deque()
q.append(a)
d=[INF]*(N+1)
d[a]=0
res=0
while q:
r=q.popleft()
for nr in G[r]:
if d[nr]==INF:
q.append(nr)
d[nr]=d[r]+1
res+=1
return d
aoki=bfs(v)
taka=bfs(u)
m=0
for i in range(1,N+1):
if taka[i]<aoki[i]:
m=max(aoki[i],m)
print(m-1)
| 1 | 117,410,641,799,370 | null | 259 | 259 |
count = 0
def merge(data, left, mid, right):
global count
n1 = mid - left
n2 = right - mid
L = []
R = []
for i in range(n1):
L.append(data[left+i])
for i in range(n2):
R.append(data[mid+i])
L.append(float('inf'))
R.append(float('inf'))
i = 0
j = 0
for k in range(left, right):
count += 1
if L[i] <= R[j]:
data[k] = L[i]
i += 1
else:
data[k] = R[j]
j += 1
def merge_sort(data, left, right):
if left + 1 < right:
mid = (left + right) / 2
merge_sort(data, left, mid)
merge_sort(data, mid, right)
merge(data, left, mid, right)
def main():
num = raw_input()
num_list = raw_input().split()
num_list = map(int, num_list)
merge_sort(num_list, 0, len(num_list))
num_list = map(str, num_list)
print " ".join(num_list)
print count
if __name__ == '__main__':
main()
|
import sys
input = sys.stdin.readline
def marge(A, left, right, mid):
cnt = 0
n1 = mid - left
n2 = right - mid
L = [0] * (n1 + 1)
R = [0] * (n2 + 1)
for i in range(n1):
L[i] = A[left + i]
for i in range(n2):
R[i] = A[mid + i]
L[n1] = 10 ** 9 + 1
R[n2] = 10 ** 9 + 1
i = 0
j = 0
for k in range(left, right):
cnt += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return cnt
def margesort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2
cnt1 = margesort(A, left, mid)
cnt2 = margesort(A, mid, right)
return cnt1 + cnt2 + marge(A, left, right, mid)
return 0
def main():
n = int(input())
A = list(map(int, input().split()))
cnt = margesort(A, 0, n)
print(' '.join(list(map(str, A))))
print(cnt)
if __name__ == '__main__': main()
| 1 | 110,748,193,540 | null | 26 | 26 |
def roll(inst):
global u, s, e, w, n, d
if inst == 'N':
u, s, n, d = s, d, u, n
elif inst == 'E':
u, e, w, d = w, u, d, e
elif inst == 'S':
u, s, n, d = n, u, d, s
elif inst == 'W':
u, e, w, d = e, d, u, w
u, s, e, w, n, d = map(int, input().split())
q = int(input())
for i in range(q):
u1, s1 = map(int, input().split())
if u1 == u:
pass
elif u1 == s:
roll('N')
elif u1 == e:
roll('W')
elif u1 == w:
roll('E')
elif u1 == n:
roll('S')
elif u1 == d:
roll('N')
roll('N')
if s1 == s:
print(e)
elif s1 == e:
print(n)
elif s1 == n:
print(w)
elif s1 == w:
print(s)
|
n=input()
b=0
e=len(n)-1
c=0
while(b<=e):
if(n[b]==n[e]):
b+=1
e-=1
elif(n[b]!=n[e]):
c+=1
b+=1
e-=1
print(c)
| 0 | null | 60,375,193,877,632 | 34 | 261 |
import sys
import heapq
from decimal import Decimal
input = sys.stdin.readline
x = int(input())
for i in range(-1000,1000):
for j in range(-1000,1000):
if i**5 - j**5 == x:
print(i,j)
exit(0)
|
X=int(input())
A=0
B=0
for i in range(-120,120):
for k in range(-120,120):
if i**5==X+k**5:
A=i
B=k
break
print(A,B)
| 1 | 25,535,582,243,560 | null | 156 | 156 |
n = int(input())
card = ['' for i in range(n)]
score1 = 0
score2 = 0
def win(score):
score += 3
return score
def draw(score):
score += 1
return score
for i in range(n):
card[i] = [j for j in input().split()]
for i in range(n):
if card[i][0] == card[i][1]:
score1 = draw(score1)
score2 = draw(score2)
else:
if card[i][0] > card[i][1]:
score1 = win(score1)
else:
score2 = win(score2)
print(score1,score2)
|
n = int(input())
taro = 0
hanako = 0
for i in range(n):
animals = input().split()
taro_animal = animals[0]
hanako_animal = animals[1]
if taro_animal > hanako_animal:
taro += 3
elif taro_animal < hanako_animal:
hanako +=3
else:
taro += 1
hanako += 1
print(taro, hanako)
| 1 | 1,984,445,392,160 | null | 67 | 67 |
from _collections import deque
from _ast import Num
def parser():
while 1:
data = list(input().split(' '))
for number in data:
if len(number) > 0:
yield (number)
input_parser = parser()
def gw():
global input_parser
return next(input_parser)
def gi():
data = gw()
return int(data)
MOD = int(1e9 + 7)
import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/abc145/tasks/abc145_e
# E - All-you-can-eat
"""
DP1[i][j] =the maximum sum of deliciousness of dishes, which are chosen from 1st- to i-th dishes,
such that he can finish them in j minutes
still WA!!!
"""
t1 = gi()
t2 = gi()
a1 = gi()
a2 = gi()
b1 = gi()
b2 = gi()
if a1 < b1:
a1, b1 = b1, a1
a2, b2 = b2, a2
#print(a1, a2, b1, b2)
d1 = (a1 - b1) * t1
d2 = (a2 - b2) * t2
net = d1 + d2
def run():
if d1 == 0 or net == 0:
print('infinity')
return
elif net > 0:
print(0)
return
d = abs(net)
ans = 0
p2 = (d1 // d)
if (d1 % d == 0):
ans = 2 * p2
else:
ans = 2 * p2 + 1
print(ans)
run()
|
T1,T2=map(int,input().split())
a,b=map(int,input().split())
c,d=map(int,input().split())
e=T1*a
f=T1*c
if e>f:
g=e-f
e=T2*b
f=T2*d
if e>f:
print(0)
else:
h=f-e
if g==h:
print("infinity")
elif g>h:
print(0)
else:
k=h-g
if k>g:
print(1)
elif (g/k)%1!=0:
print(1+(g//k)*2)
else:
print((g//k)*2)
elif e<f:
g=f-e
e=T2*b
f=T2*d
if e<f:
print(0)
else:
h=e-f
if g==h:
print("infinity")
elif g>h:
print(0)
else:
k=h-g
if k>g:
print(1)
elif (g/k)%1!=0:
print(1+(g//k)*2)
else:
print((g//k)*2)
| 1 | 131,790,901,824,374 | null | 269 | 269 |
n, k = map(int, input().split())
mod = 10 ** 9 + 7
inv = pow(2, mod - 2) % mod
def calc(b, e, c):
global mod
global inv
res = (e + b) % mod
res = ((res * c) % mod ) * inv
return res % mod
ans = 0
for i in range(k, n + 2):
min_val = calc(0, i - 1, i)
max_val = calc(n - i + 1, n, i)
ans += (max_val - min_val + 1) % mod
ans %= mod
print(ans)
|
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter
import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(readline())
def read_int_n():
return list(map(int, readline().split()))
def read_float():
return float(readline())
def read_float_n():
return list(map(float, readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def ep(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.perf_counter()
ret = f(*args, **kwargs)
e = time.perf_counter()
ep(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, U, V, AB):
g = defaultdict(list)
for a, b in AB:
g[a].append(b)
g[b].append(a)
def dfs(u):
s = [u]
d = {u: 0}
while s:
u = s.pop()
for v in g[u]:
if v in d:
continue
d[v] = d[u] + 1
s.append(v)
return d
du = dfs(U)
dv = dfs(V)
ans = 0
for v in sorted(du.keys()):
if du[v] < dv[v]:
ans = max(ans, dv[v] - 1)
return ans
def main():
N, U, V = read_int_n()
AB = [read_int_n() for _ in range(N-1)]
print(slv(N, U, V, AB))
if __name__ == '__main__':
main()
| 0 | null | 75,193,508,449,230 | 170 | 259 |
def main():
K: int = int(input())
S: str = 'ACL'
print(S*K)
if __name__ == "__main__":
main()
|
a, b, c, k = map(int, input().split())
if k - a <= 0:
print(k)
elif k - a > 0 and k - a - b <= 0:
print(a)
else:
s = k - a - b
print(a - s)
| 0 | null | 12,015,159,323,200 | 69 | 148 |
n = int(input())
m = list(map(int, input().split()))
count = 0
for i in range(n-1):
minj =i
for j in range(i+1, n):
if m[j] < m[minj]:
minj = j
if m[i] != m[minj]:
m[i], m[minj] = m[minj], m[i]
count += 1
print(" ".join(str(x) for x in m))
print(count)
|
N = int(raw_input())
num_list = map(int, raw_input().split())
c = 0
for i in range(0,N,1):
flag =0
minj =i
for j in range(i,N,1):
if num_list[j] < num_list[minj]:
minj = j
flag = 1
c += flag
num_list[i], num_list[minj] = num_list[minj], num_list[i]
print " ".join(map(str,num_list))
print c
| 1 | 19,991,198,920 | null | 15 | 15 |
from itertools import combinations
if __name__ == '__main__':
# ??????????????\???
num1 = int(input())
A = [int(x) for x in input().split(' ')]
num2 = int(input())
M = [int(x) for x in input().split(' ')]
#A = [1, 5, 7, 10, 21]
#pick = 4
#M = [2, 4, 17, 8]
# ????????????
results = ['no' for x in range(len(M))] # M?????¨??????????´?????????????????????????????????§????????????????????±???(no)??¨????????????
for p in range(1, len(A)+1): # A????????????1????????¨????????°?????????????????¢????????????
combi = combinations(A, p) # n??????????????¢??????????????´????????¨?????????????????????
for choice in combi:
total = sum(choice)
while total in M:
i = M.index(total)
results[i] = 'yes'
M[i] = 'Done'
# ???????????????
for txt in results:
print(txt)
|
import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
S = sys.stdin.buffer.readline().decode().rstrip()
N = len(S)
# ピッタリ払う
dp0 = [INF] * (N + 1)
# 1 多く払う
dp1 = [INF] * (N + 1)
dp0[0] = 0
dp1[0] = 1
for i, c in enumerate(S):
dp0[i + 1] = min(dp0[i] + int(c), dp1[i] + 10 - int(c))
dp1[i + 1] = min(dp0[i] + int(c) + 1, dp1[i] + 10 - int(c) - 1)
# print(dp0)
# print(dp1)
print(dp0[-1])
| 0 | null | 35,316,857,562,080 | 25 | 219 |
#!/usr/bin/env python3
def main():
x = int(input())
lank: int = 0
if 400 <= x <= 599:
lank = 8
elif x <= 799:
lank = 7
elif x <= 999:
lank = 6
elif x <= 1199:
lank = 5
elif x <= 1399:
lank = 4
elif x <= 1599:
lank = 3
elif x <= 1799:
lank = 2
else:
lank = 1
print(lank)
if __name__ == "__main__":
main()
|
X = int(input())
if ((2000-X)%200) == 0:
print((2000-X)//200)
else:
print((2000-X)//200+1)
| 1 | 6,658,093,637,882 | null | 100 | 100 |
h = int(input())
w = int(input())
n = int(input())
x = max(h, w)
cnt = 0
cur = 0
while cur < n:
cur += x
cnt+=1
print(cnt)
|
H = int(input())
W = int(input())
N = int(input())
a = max(H, W)
print(N // a + min(1, N % a))
| 1 | 88,697,415,639,976 | null | 236 | 236 |
class Solution(object):
def is_hitachi_string(self, string):
if len(string) == 0:
print 'No'
return
hi_str = 'hi'
hi_idx = 0
for idx in xrange(len(string)):
if idx > 9:
print 'No'
return
if string[idx] != hi_str[hi_idx]:
print 'No'
return
hi_idx = (hi_idx + 1) % 2
if hi_idx == 0:
print 'Yes'
else:
print 'No'
if __name__ == '__main__':
sol = Solution()
string = raw_input()
sol.is_hitachi_string(string)
|
def bunsan(n,S): #Sはリスト
ave = sum(S)/n
D = 0
for i in range(n):
D += (S[i] - ave)**2
return (D/n)**(1/2)
while True:
n = int(input())
if n == 0:
break
S = list(map(int,input().split()))
print(bunsan(n,S))
| 0 | null | 26,580,167,146,286 | 199 | 31 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
R,C,K = map(int,readline().split())
board = [[0]*C for _ in range(R)]
for _ in range(K):
r,c,v = map(int,readline().split())
board[r-1][c-1] = v
dp0 = [[0]*C for _ in range(R)]
dp1 = [[0]*C for _ in range(R)]
dp2 = [[0]*C for _ in range(R)]
dp3 = [[0]*C for _ in range(R)]
for i in range(R):
for j in range(C):
if dp1[i][j] < dp0[i][j]+board[i][j]:
dp1[i][j] = dp0[i][j]+board[i][j]
if j>0:
if dp0[i][j] < dp0[i][j-1]:
dp0[i][j] = dp0[i][j-1]
if dp1[i][j] < dp1[i][j-1]:
dp1[i][j] = dp1[i][j-1]
if dp2[i][j] < dp2[i][j-1]:
dp2[i][j] = dp2[i][j-1]
if dp3[i][j] < dp3[i][j-1]:
dp3[i][j] = dp3[i][j-1]
if dp1[i][j] < dp0[i][j-1]+board[i][j]:
dp1[i][j] = dp0[i][j-1]+board[i][j]
if dp2[i][j] < dp1[i][j-1]+board[i][j]:
dp2[i][j] = dp1[i][j-1]+board[i][j]
if dp3[i][j] < dp2[i][j-1]+board[i][j]:
dp3[i][j] = dp2[i][j-1]+board[i][j]
if i>0:
if dp0[i][j] < dp0[i-1][j]:
dp0[i][j] = dp0[i-1][j]
if dp0[i][j] < dp1[i-1][j]:
dp0[i][j] = dp1[i-1][j]
if dp0[i][j] < dp2[i-1][j]:
dp0[i][j] = dp2[i-1][j]
if dp0[i][j] < dp3[i-1][j]:
dp0[i][j] = dp3[i-1][j]
if dp1[i][j] < dp0[i-1][j]+board[i][j]:
dp1[i][j] = dp0[i-1][j]+board[i][j]
if dp1[i][j] < dp1[i-1][j]+board[i][j]:
dp1[i][j] = dp1[i-1][j]+board[i][j]
if dp1[i][j] < dp2[i-1][j]+board[i][j]:
dp1[i][j] = dp2[i-1][j]+board[i][j]
if dp1[i][j] < dp3[i-1][j]+board[i][j]:
dp1[i][j] = dp3[i-1][j]+board[i][j]
print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))
|
#E_Picking Goods
R,C,K = map(int,input().split())
A = [[0 for j in range(C)] for i in range(R)]
varr = [[[0 for j in range(C)] for i in range(R)] for k in range(4)]
for inputk in range(K):
r,c,v = map(int,input().split())
A[r-1][c-1] = v
for i in range(R):
for j in range(C):
for k in range(2,-1,-1):
if varr[k][i][j] >= 0:
if varr[k+1][i][j] < varr[k][i][j] + A[i][j]:
varr[k+1][i][j] = varr[k][i][j] + A[i][j]
for kk in range(0,4):
if varr[kk][i][j] >= 0:
if i +1 < R :
if varr[0][i + 1][j] < varr[kk][i][j]:
varr[0][i + 1][j] = varr[kk][i][j]
if j +1 < C :
if varr[kk][i][j + 1] < varr[kk][i][j]:
varr[kk][i][j + 1] = varr[kk][i][j]
ans = 0
for k in range (4):
if ans < varr[k][R-1][C-1]:
ans = varr[k][R-1][C-1]
print(ans)
| 1 | 5,509,196,601,428 | null | 94 | 94 |
a,b = map(int,(input().split()))
result = a - (b * 2)
if result <= 0:
result = 0
print(result)
|
from itertools import product
for i, j in product(range(1, 10), repeat=2):
print('{}x{}={}'.format(i, j, i * j))
| 0 | null | 83,476,373,568,186 | 291 | 1 |
n = int(raw_input())
S = map(int,raw_input().split())
q = int(raw_input())
T = map(int,raw_input().split())
C = 0
for i in T:
for j in S:
if i == j:
C += 1
break
print C
|
n = input()
S = list(map(int,input().split()))
n = input()
T = list(map(int,input().split()))
count = 0
for i in T:
if i in S:
count+= 1
print(count)
| 1 | 68,359,914,882 | null | 22 | 22 |
# 写経
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, u, v = map(int, readline().split())
m = map(int, read().split())
AB = zip(m, m)
graph = [[] for _ in range(n + 1)]
for a, b in AB:
graph[a].append(b)
graph[b].append(a)
def dfs(v):
dist = [-1] * (n + 1)
# 初期化
stack = [v]
# 初期位置を記憶
dist[v] = 0
# 初期位置の距離を0に
while stack:
# stackの中身がなくなるまで頑張る
v = stack.pop()
# stackから1つ要素を取り出す
dw = dist[v] + 1
# その要素の周りを考えるので、距離としてはその要素の距離に1を加えたものを考える
for w in graph[v]:
# 考えている要素に対して隣接している点に対して
if dist[w] >= 0:
# もし今まで訪れたことがあったら無視
continue
dist[w] = dw
# 訪れたことがなかったら距離を更新
stack.append(w)
# 訪れたことがないところだったらstackに訪れる点リストとして保存
return dist
answer = 0
du, dv = dfs(u), dfs(v)
for u, v in zip(du[1:], dv[1:]):
if v - u > 0:
x = v - 1
if answer < x:
answer = x
print(answer)
|
import collections
n,u,v=map(int,input().split())
g=[[] for _ in range(n+1)]
for _ in range(n-1):
a,b=map(int,input().split())
g[a].append(b)
g[b].append(a)
q=collections.deque()
q.append((v,0))
checked=[0]*(n+1)
dist1=[0]*(n+1)
while len(q)!=0:
tv,td=q.popleft()
checked[tv]=1
dist1[tv]=td
for tu in g[tv]:
if checked[tu]==1:
continue
q.append((tu,td+1))
q=collections.deque()
q.append((u,0))
checked=[0]*(n+1)
dist2=[0]*(n+1)
while len(q)!=0:
tv,td=q.popleft()
checked[tv]=1
dist2[tv]=td
for tu in g[tv]:
if checked[tu]==1:
continue
q.append((tu,td+1))
ans=0
for tv in range(1,n+1):
if dist1[tv]>dist2[tv]:
ans=max(ans,dist1[tv]-1)
print(ans)
| 1 | 117,301,603,760,892 | null | 259 | 259 |
n = int(input())
a = []
for i in range(n):
temp = []
temp_temp = []
temp.append(int(input()))
for j in range(temp[0]):
temp_temp.append(list(map(int,input().split())))
temp.append(temp_temp)
a.append(temp)
ans = 0
for i in range(2**n):
ans_t = 0
id_list =list(bin(i))[2:]
id_list = [int(x) for x in id_list]
while len(id_list) != n:
id_list.insert(0,0)
for j in range(n):
flag = 0
if id_list[j] == 0:
continue
else:
for k in range(a[j][0]):
if id_list[a[j][1][k][0]-1] != a[j][1][k][1]:
flag = 1
break
if flag == 1:
ans_t = 0
break
else:
ans_t += 1
if ans_t > ans:
ans = ans_t
print(ans)
|
N = int(input())
syougen = [ [] for _ in range(N) ]
for i in range(N):
num = int(input())
for j in range(num):
x, y = map(int, input().split())
syougen[i].append([x, y])
#print(syougen)
ans = 0
for bit in range(1 << N):
break_flag = 0
for i in range(N):
if (bit >> i) & 1:
for j in range(len(syougen[i])):
if ((bit>>(syougen[i][j][0]-1))&1) != syougen[i][j][1]:
break_flag = 1
break
if break_flag == 1:
break
if i == N-1:
ans = max(ans, bin(bit).count("1"))
print(ans)
| 1 | 122,246,814,856,542 | null | 262 | 262 |
from collections import deque
n = int(input())
d = deque()
cmd = ['com', 0]
for i in range(n):
cmd = input().split()
if cmd[0] == 'insert':
d.appendleft(int(cmd[1]))
elif cmd[0] == 'delete':
try:
d.remove(int(cmd[1]))
except ValueError:
pass
elif cmd[0] == 'deleteFirst':
d.popleft()
elif cmd[0] == 'deleteLast':
d.pop()
print(*list(d))
|
n = int(input())
if (n % 2 == 1):
count = (n // 2) + 1
else:
count = n // 2
print("{:.10f}".format(count/n))
| 0 | null | 88,966,911,752,952 | 20 | 297 |
alps = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
if n == 1:
print('a')
exit()
ansl = []
curr_n = n
for i in range(15, -1, -1):
if n <= pow(26,i):
continue
val = curr_n//pow(26,i)
ansl.append(val)
curr_n -= val*pow(26,i)
for j in range(100):
for i in range(len(ansl)-1):
if ansl[i+1] == 0:
ansl[i+1] = 26
ansl[i] -= 1
ans = ''
for a in ansl:
if a == 0: continue
ans += alps[a-1]
print(ans)
|
a = list(map(int, input().split()))
sum_a = sum(a)
if sum_a >= 22:
print('bust')
else:
print('win')
| 0 | null | 65,088,746,289,700 | 121 | 260 |
n = int(input())
s = input()
ans = ''
for i in s:
next_number = ord(i)+n
if next_number > 90:
next_number -= 26
ans += chr(next_number)
else:
ans += chr(next_number)
print(ans)
|
N = int(input())
S = input()
char = ''
for i in range(len(S)):
char += chr((ord(S[i]) + N - 65) % 26 + 65)
print(char)
| 1 | 134,520,920,426,712 | null | 271 | 271 |
import math
def prime(num):
array=[]
tmp=int(math.sqrt(n))+1
for i in range(2,tmp):
while num % i == 0:
num/=i
array.append(i)
# リストが空なら入力(num)は素数
if array==[]:
return [num]
else:
if num>1:
array.append(int(num))
return array
n=int(input())
P=prime(n)
P=sorted(P)
num=n
if 1 in P:
print(0)
else:
ans=0
tmp=0
for i in range(0,len(P)):
if i==0:
tmp=P[i]
elif P[i]==P[i-1]:
tmp*=P[i]
else:
tmp=P[i]
num=n
if num%tmp==0:
num/=tmp
ans+=1
print(ans)
|
def prime_factorize(n):
'''
素因数分解のリストを返す。n == 1のとき[]になるので注意。
:param n:int
素因数分解する自然数
:return: list
素因数分解した結果。
例
n : 10
primes : [[2, 1], [5, 1]]
'''
primes = []
for i in range(2, int(n ** (1 / 2)) + 1):
if n % i != 0:
continue
num = 0
while n % i == 0:
num += 1
n //= i
primes.append([i, num])
if n != 1:
primes.append([n, 1])
return primes
N = int(input())
prime_list = prime_factorize(N)
ans = 0
for _, e in prime_list:
now = 1
work = e
while work >= now:
work -= now
now += 1
ans += 1
print(ans)
| 1 | 16,912,016,913,252 | null | 136 | 136 |
xy = [map(int,input().split()) for i in range(2)]
x,y = [list(j) for j in zip(*xy)]
if (y[0] + 1) == y[1] :
ans = 0
else:
ans = 1
print(ans)
|
day1=input().rstrip().split()
day2=input().rstrip().split()
if int(day2[1])==1:
print(1)
else:
print(0)
| 1 | 123,902,215,810,758 | null | 264 | 264 |
N = int(input())
A_list = list(map(int, input().split()))
for i in range(N):
if A_list[i] % 2 == 0:
if A_list[i] % 3 == 0 or A_list[i] % 5 == 0:
continue
else:
print("DENIED")
exit()
if i == N-1:
print("APPROVED")
|
n = int(input())
s = input()
if n%2 != 0 or s[:n//2] != s[n//2:]:
print("No")
else:
print("Yes")
| 0 | null | 107,755,143,376,628 | 217 | 279 |
ans = []
while True:
tmp = input().split()
a, b = map(int, [tmp[0], tmp[2]])
op = tmp[1]
if op == "?":
break
if op == "+":
ans.append(a + b)
if op == "-":
ans.append(a - b)
if op == "*":
ans.append(a * b)
if op == "/":
ans.append(a // b)
print("\n".join(map(str, ans)))
|
S = str(input())
ans = 'Yes'
from collections import Counter
SC = Counter(list(S))
h,i = 0,0
for a,b in SC.items():
if a == 'h':
h = b
elif a == 'i':
i = b
else:
ans = 'No'
break
if h == i:
for i in range(0,len(S)-1,2):
if S[i]+S[i+1] != 'hi':
ans = 'No'
break
else:
ans = 'No'
print(ans)
| 0 | null | 27,107,367,934,522 | 47 | 199 |
import numpy as np
n=int(input())
d_i = list(map(int, input().split()))
d=np.array(d_i)
out=0
for i in range(1,n):
a=d_i.pop(0)
d_i.append(a)
out+=np.dot(d,np.array(d_i))
print(int(out/2))
|
str = list(input())
q = int(input())
for i in range(q):
s = list(input().split())
s[1] = int(s[1])
s[2] = int(s[2])
if s[0] == 'print':
print(''.join(str[s[1]:s[2]+1]))
elif s[0] == 'reverse':
str[s[1]:s[2]+1] = ''.join(reversed(str[s[1]:s[2]+1]))
elif s[0] == 'replace':
str[s[1]:s[2]+1:1] = s[3]
| 0 | null | 84,949,973,936,770 | 292 | 68 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N = readline().strip()
if N.count('7') > 0:
print('Yes')
else:
print('No')
return
if __name__ == '__main__':
main()
|
r = int(input())
pi = 3.14159265358979323846
print(2*pi*r)
| 0 | null | 32,884,034,352,512 | 172 | 167 |
def main():
from collections import deque
N, M, K = map(int, input().split())
f = [set() for _ in range(N + 1)]
b = [set() for _ in range(N + 1)]
for _ in range(M):
i, j = map(int, input().split())
f[i].add(j)
f[j].add(i)
for _ in range(K):
i, j = map(int, input().split())
b[i].add(j)
b[j].add(i)
visited = [False] * (N + 1)
ans = [0] * (N + 1)
for i in range(1, N+1):
if visited[i]:
continue
visited[i] = True
link = {i}
todo = deque([i])
while len(todo) != 0:
c = todo.pop()
for p in f[c]:
if not(visited[p]):
link.add(p)
todo.append(p)
visited[p] = True
for j in link:
ans[j] = len(link) - len(link & f[j]) - len(link & b[j]) - 1
print(*ans[1:])
if __name__ == '__main__':
main()
|
from math import sqrt
def eratosthenes(x):
prime = []
for i in range(2, int(sqrt(x)) + 1):
if x % i == 0:
prime.append(i)
while x % i == 0:
x //= i
return prime
N = int(input())
prime = eratosthenes(N)
ans = 0
for x in prime:
i = 1
while N % x**i == 0:
ans += 1
N //= x**i
i += 1
while N % x == 0:
N //= x
if N > 1:
ans += 1
print(ans)
| 0 | null | 39,391,953,032,032 | 209 | 136 |
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
def make_divisors(n: int):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors, upper_divisors[::-1]
def resolve():
import sys
input = sys.stdin.readline
n = int(input().rstrip())
lower_divisors, _ = make_divisors(n)
print(min(lower_divisor + (n // lower_divisor) - 2 for lower_divisor in lower_divisors))
if __name__ == "__main__":
resolve()
|
A = []
b = []
row = 0
col = 0
row, col = map(int, raw_input().split())
A = [[0 for i in range(col)] for j in range(row)]
for i in range(row):
r = map(int, raw_input().split())
for index, j in enumerate(r):
A[i][index] = j
for i in range(col):
b.append(int(raw_input()))
for i in A:
ret = 0
for j,k in zip(i,b):
ret += j*k
print ret
| 0 | null | 81,434,144,101,092 | 288 | 56 |
import sys
A,B,C,D = map(int,input().split())
while True:
C -= B
if C <= 0:
print("Yes")
sys.exit()
A -= D
if A <= 0:
print("No")
sys.exit()
|
n=int(input())
A=set()
for i in range(n):
x,y=input().split()
if x == 'insert':
A.add(y)
else:
print('yes'*(y in A)or'no')
| 0 | null | 14,871,010,098,758 | 164 | 23 |
def main():
N,M=map(int,input().split())
S=input()
c,l=N,[]
while c>0:
for i in range(M,0,-1):
if i<=c and S[c-i]=='0':
l+=[i]
c-=i
break
else:
l=[-1]
break
print(*l[::-1])
main()
|
#146_F
n, m = map(int, input().split())
s = input()[::-1]
ans = []
flg = True
cur = 0
while cur < n and flg:
for to in range(cur + m, cur, -1):
if to > n:
continue
if s[to] == '0':
ans.append(to - cur)
cur = to
break
if to == cur + 1:
flg = False
if flg:
print(*ans[::-1])
else:
print(-1)
| 1 | 139,061,063,466,640 | null | 274 | 274 |
import math
import itertools
from statistics import mean
n = int(input())
p = [list(map(int,input().split())) for i in range(n)]
ans = []
for v in itertools.permutations(p):
length = 0
for i in range(n-1):
length += math.sqrt((v[i+1][0] - v[i][0])**2 + (v[i+1][1] - v[i][1])**2)
ans.append(length)
print(mean(ans))
|
import itertools
import math
n = int(input())
x = []
num = []
for i in range(n):
x.append([int(t) for t in input().split()])
num.append(i)
s = 0
for i in itertools.permutations(num):
i = list(i)
#print(x,i)
for j in range(n-1):
s += math.sqrt((x[i[j]][0] - x[i[j+1]][0])**2 + (x[i[j]][1] - x[i[j+1]][1])**2)
#print(s)
s /= math.factorial(n)
print(s)
| 1 | 148,525,562,724,612 | null | 280 | 280 |
N, M = map(int, input().split())
corret_list = [False] * (N+1)
wa_number = [0] * (N+1)
true_ans = 0
penalty = 0
for _ in range(M):
P, S = input().split()
P = int(P)
if S == 'AC':
if not corret_list[P]:
true_ans += 1
corret_list[P] = True
continue
else:
continue
else:
if not corret_list[P]:
wa_number[P] += 1
continue
for i in range(len(corret_list)):
if corret_list[i]:
penalty += wa_number[i]
print(true_ans, penalty)
|
N = int(input())
lst = []
for i in range(N):
lst.append(input().split())
X = input()
index = 0
for i in range(N):
if lst[i][0] == X:
index = i
break
ans = 0
for i in range(index + 1, N):
ans += int(lst[i][1])
print(ans)
| 0 | null | 94,758,530,829,440 | 240 | 243 |
from itertools import accumulate
n, m, *a = map(int, open(0).read().split())
a = [-x for x in a]
a.sort()
acc = list(accumulate(a))
l, r = 0, 2 * 10 ** 5 + 1
while r - l > 1:
mid = (l + r) // 2
border = n - 1
cnt = 0
for x in a:
while x + a[border] > -mid:
border -= 1
if border < 0:
break
if border < 0:
break
cnt += border + 1
if cnt >= m:
break
if cnt >= m:
l = mid
else:
r = mid
ans = tot = 0
border = n - 1
for x in a:
while x + a[border] > -l:
border -= 1
if border < 0:
break
if border < 0:
break
ans += acc[border] + x * (border + 1)
tot += border + 1
ans += l * (tot - m)
print(-ans)
|
h,n=map(int,input().split())
a=[]
b=[]
for i in range(n):
aa,bb=map(int,input().split())
a.append(aa)
b.append(bb)
inf=10**10
f=h+max(a)+1
dp=[f*[inf]for _ in range(n+1)]
dp[0][0]=0
for i in range(1,n+1):
dp[i]=dp[i-1]
for j in range(f):
if j+a[i-1]<f:
dp[i][j+a[i-1]]=min(dp[i][j+a[i-1]],dp[i][j]+b[i-1])
for j in range(f-1,0,-1):
dp[i][j-1]=min(dp[i][j-1],dp[i][j])
print(dp[-1][h])
| 0 | null | 94,947,631,034,748 | 252 | 229 |
w,h,x,y,r=[int(i) for i in raw_input().split()]
if x-r<0 or x+r>w or y-r<0 or y+r>h:
print 'No'
else :
print 'Yes'
|
from collections import deque
S = deque(input())
n = int(input())
Q = [list(map(str, input().split())) for _ in range(n)]
flg = True
for q in Q:
if q[0] == "1":
flg = not flg
else:
F = int(q[1])
if not flg:
F = 3 - F
if F == 1:
S.appendleft(q[2])
if F == 2:
S.append(q[2])
if not flg:
S.reverse()
print("".join(S))
| 0 | null | 28,880,378,980,498 | 41 | 204 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
#mod = 10 ** 9 + 7
mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N, M = MAP()
a = LIST()
A = sorted([x//2 for x in a], reverse=True)
b = A[0]
cnt = 0
while b%2 == 0:
b //= 2
cnt += 1
for x in A:
if x%pow(2, cnt) or (x//pow(2, cnt))%2 == 0:
print(0)
exit()
lcm = A[-1]
for x in A:
lcm = lcm*x//gcd(lcm, x)
r = lcm//A[0]
n = M//A[0]
#2p+1が1<=2p+1<=n の範囲で rの倍数となるpの個数
if r%2 == 0:
print(0)
else:
print(n//r - n//(2*r))
|
import math
from functools import reduce
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm(*numbers):
return reduce(lcm_base, numbers, 1)
def div2_n(x):
n = 0
while x % 2 == 0:
if x % 2 == 0:
n += 1
x >>= 1
return n
n, m = map(int, input().split())
a = list(map(int, input().split()))
a2 = [i//2 for i in a]
n0 = div2_n(a2[0])
for i in range(1,n):
if div2_n(a2[i]) != n0:
print(0)
exit()
a2_l = lcm(*a2)
print(m//a2_l - m//(a2_l*2))
| 1 | 101,796,021,123,890 | null | 247 | 247 |
#ITP1_10-D Distance2
n = int(input())
x = [float(x) for x in input().split(" ")]
y = [float(x) for x in input().split(" ")]
d1=0.0
for i in range(n):
d1 += abs(x[i]-y[i])
print(d1)
d2=0.0
for i in range(n):
d2 += (x[i]-y[i])**2
print(d2**(1/2))
d3=0.0
for i in range(n):
d3 += abs((x[i]-y[i])**3)
print(d3**(1/3))
d_inf=0.0
for i in range(n):
if abs(x[i]-y[i])>d_inf:
d_inf = abs(x[i]-y[i])
print(d_inf)
|
n = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
diff = []
total1 = 0
total2 = 0
total3 = 0
for i in range(n):
diff.append(abs(X[i] - Y[i]))
total1 += diff[i]
total2 += diff[i] ** 2
total3 += diff[i] ** 3
print("{0:.6f}" . format(total1))
print("{0:.6f}" . format(total2 ** 0.5))
print("{0:.6f}" . format(total3 ** (1 / 3)))
print("{0:.6f}" . format(max(diff)))
| 1 | 211,668,332,480 | null | 32 | 32 |
# coding: utf-8
# Your code here!
num = int(input())
a=0
b=0
for _ in range(num):
input2 = input().split()
if input2[0]>input2[1]:
a=a+3
elif input2[0]<input2[1]:
b=b+3
else:
a=a+1
b=b+1
print(a,b)
|
n = int(input())
r = s = 0
for i in range(n):
a, b = input().split()
if a > b:
r += 3
elif a < b:
s += 3
else:
r += 1; s += 1
print(r,s)
| 1 | 1,988,025,500,960 | null | 67 | 67 |
h, n = map(int, input().split())
a = list(map(int, input().split()))
a_sum = sum(a)
if h <= a_sum:
print('Yes')
else:
print('No')
|
def main():
N = int(input())
def sum_num(num):
div = N // num
ret = num * int(div * ((1 + div) / 2))
return (ret)
ans = 0
for i in range(1, N + 1):
ans += sum_num(i)
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 44,732,631,664,348 | 226 | 118 |
# import math
# from fractions import gcd
# import numpy as np
# import scipy as scp
# 入力の受け取り
k,x = map(int,input().split())
if k * 500 >= x:
ans = "Yes"
else:
ans = "No"
print(ans)
|
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
#BC=[]
#for i in range(Q):
# BC.append(list(map(int,input().split())))
A_sum=sum(A)
A_count=Counter(A)
for i in range(Q):
B,C=(map(int,input().split()))
A_sum+=(C-B)*A_count[B]
A_count[C]+=A_count[B]
A_count[B]=0
print(A_sum)
| 0 | null | 55,047,985,395,210 | 244 | 122 |
import math
x1,y1,x2,y2=[float(x) for x in input().split(' ')]
dis=math.sqrt((y2 - y1)**2 + (x2-x1)**2)
print("{:.4f}".format(dis))
|
from math import sin, cos, radians
a, b, ang = map(int, input().split())
ang = radians(ang)
area = a * b * sin(ang) / 2
c = (a ** 2 + b ** 2 - 2 * a * b * cos(ang)) ** 0.5
circ = a + b + c
height = area * 2 / a
print("%lf\n%lf\n%lf" % (area, circ, height))
| 0 | null | 169,898,048,342 | 29 | 30 |
N, M, K = map(int, input().split())
table = [-1]*N
def union(x, y):
global table
x, y = find(x), find(y)
if x==y:
return False
else:
if table[x]>table[y]:
x, y = y, x
table[x] += table[y]
table[y] = x
return True
def find(x):
if table[x]<0:
return x
else:
table[x] = find(table[x])
return table[x]
def rank(x):
return table[find(x)]
friend = [[] for _ in range(N)]
block = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
friend[a-1].append(b-1)
friend[b-1].append(a-1)
union(a-1, b-1)
for _ in range(K):
c, d = map(int, input().split())
block[c-1].append(d-1)
block[d-1].append(c-1)
ans = [""]*N
for i in range(N):
tmp = abs(rank(i)) - len(friend[i]) - 1
cnt = 0
for b in block[i]:
if find(i)==find(b):
cnt += 1
ans[i] = str(tmp - cnt)
print(" ".join(ans))
|
import sys
def input(): return sys.stdin.readline().rstrip()
class UnionFind():
def __init__(self, n):
self.n=n
self.parents=[-1]*n # 親(uf.find()で経路圧縮して根)の番号。根の場合は-(そのグループの要素数)
def find(self,x):
#グループの根を返す
if self.parents[x]<0:return x
else:
self.parents[x]=self.find(self.parents[x])
return self.parents[x]
def unite(self,x,y):
#要素x,yのグループを併合
x,y=self.find(x),self.find(y)
if x==y:return
if self.parents[x]>self.parents[y]:#要素数の大きい方をxに
x,y=y,x
self.parents[x]+=self.parents[y]
self.parents[y]=x #要素数が大きい方に併合
def size(self,x):
#xが属するグループの要素数
return -self.parents[self.find(x)]
def same(self,x,y):
#xとyが同じグループ?
return self.find(x)==self.find(y)
def members(self,x):
#xと同じグループに属する要素のリスト
root=self.find(x)
return [i for i in range(self.n) if self.find(i)==root]
def main():
n,m,k=map(int,input().split())
AB=[tuple(map(int,input().split())) for i in range(m)]
CD=[tuple(map(int,input().split())) for i in range(k)]
un=UnionFind(n)
friend=[[] for _ in range(n)]
for a,b in AB:
un.unite(a-1,b-1)
friend[a-1].append(b-1)
friend[b-1].append(a-1)
blockc=[0]*n
for c,d in CD:
if un.same(c-1,d-1):
blockc[c-1]+=1
blockc[d-1]+=1
for i in range(n):
print(un.size(i)-1-blockc[i]-len(friend[i]))
if __name__=='__main__':
main()
| 1 | 61,355,181,397,252 | null | 209 | 209 |
from collections import defaultdict, deque
N, u, v = map(int, input().split())
way = defaultdict(list)
for _ in range(N-1):
a, b = map(int, input().split())
way[a].append(b)
way[b].append(a)
seen1 = [-1]*N
seen2 = [-1]*N
seen1[u-1] = 0
seen2[v-1]= 0
queue = deque([u])
while queue:
q = queue.popleft()
for i in way[q]:
if seen1[i-1]==-1:
queue.append(i)
seen1[i-1] = seen1[q-1]+1
queue = deque([v])
while queue:
q = queue.popleft()
for i in way[q]:
if seen2[i-1]==-1:
queue.append(i)
seen2[i-1] = seen2[q-1]+1
#print(way)
#print(seen1)
#print(seen2)
for i in range(N):
if seen1[i]>=seen2[i]:
seen2[i] = -1
print(max(seen2)-1)
|
A, B, M = map(int, input().split())
price_A = list(map(int, input().split()))
price_B = list(map(int, input().split()))
ans = min(price_A)+min(price_B)
for m in range(M):
x, y, c = map(int, input().split())
p1 = price_A[x-1] + price_B[y-1] - c
if p1 <= ans: ans=p1
print(ans)
| 0 | null | 85,461,210,987,072 | 259 | 200 |
mark = ["S","H","C","D"]
numbers = ["1","2","3","4","5","6","7","8","9","10","11","12","13"]
cardlist = {}
for m in mark:
for n in numbers:
key = m + " " + n
cardlist[key] = 0
n = int(input())
for _ in range(n):
card = input()
cardlist[card] = 1
for card in cardlist:
if cardlist[card] == 0:
print(card)
|
import sys
n = int(input()) # ?????£?????????????????????????????°
pic_list = ['S', 'H', 'C', 'D']
card_dict = {'S':[], 'H':[], 'C':[], 'D':[]} # ?????£?????????????????\?????????????????°
lost_card_dict = {'S':[], 'H':[], 'C':[], 'D':[]} # ?¶??????????????????\?????????????????°
# ?????????????¨??????\???????????????
for i in range(n):
pic, num = input().split()
card_dict[pic].append(int(num))
# ?¶???????????????????????¨??????\????¨????
for pic in card_dict.keys():
for j in range(1, 14):
if not j in card_dict[pic]:
lost_card_dict[pic].append(j)
# ?????????????????????
for pic in card_dict.keys():
lost_card_dict[pic] = sorted(lost_card_dict[pic])
# ?¶????????????????????????????
for pic in pic_list:
for k in range(len(lost_card_dict[pic])):
print(pic, lost_card_dict[pic][k])
| 1 | 1,043,798,447,198 | null | 54 | 54 |
n=int(input())
r=[int(input()) for i in range(n)]
maxv=r[1]-r[0]
minv=r[0]
for i in range(1,n):
maxv=max(maxv,r[i]-minv)
minv=min(minv,r[i])
print(maxv)
|
# coding: utf-8
# Here your code !
import math
prof = 0
d = int(input())
li =[int(input()) for i in range(d)]
max=float("-inf")
min=li[0]
for j in range(1,d):
if li[j]-min>max:
max=li[j]-min
if li[j]<min:
min=li[j]
print(max)
| 1 | 13,189,548,750 | null | 13 | 13 |
import sys
stdin=sys.stdin
ip=lambda: int(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()
a,b=lp()
print(max(0,a-2*b))
|
n=int(input())
while(n!=0):
digit=n%10
if(digit==7):
flag=1
break
else:
flag=0
n=n//10
if(flag==1):
print("Yes")
else:
print("No")
| 0 | null | 100,390,383,136,670 | 291 | 172 |
import os, sys, re, math
r = int(input())
print(r * r)
|
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
n,m = readInts()
base = []
if n == 1 and m == 0:
print(0)
exit()
elif n == 2 and m == 0:
print(10)
exit()
elif n == 3 and m == 0:
print(100)
exit()
if n >= 1:
base.append('1')
if n >= 2:
base.append('0')
if n == 3:
base.append('0')
dic = defaultdict(int)
for i in range(m):
s,c = readInts()
s -= 1
if dic[s] != 0:
if int(base[s]) == c:
pass
else:
print(-1)
exit()
else:
dic[s] = 1
base[s] = str(c)
if s == 0 and c == 0 and n >= 2:
print(-1)
exit()
print(*base,sep='')
| 0 | null | 102,976,545,802,008 | 278 | 208 |
import sys
nyuukyosha = []
for tou in range(4):
nyuukyosha.append([])
for kai in range(3):
nyuukyosha[tou].append([])
for heya in range(10):
nyuukyosha[tou][kai].append(0)
n = int(raw_input())
for i in range(n):
data = map(int, raw_input().split())
a = data[0] - 1
b = data[1] - 1
c = data[2] - 1
nyuukyosha[a][b][c] += data[3]
for tou in range(4):
for kai in range(3):
for heya in range(10):
sys.stdout.write(" {:}".format(nyuukyosha[tou][kai][heya]))
print("")
if tou < 3:
print("####################")
|
data = []
for i in xrange(4):
tou = []
data.append(tou)
for j in xrange(3):
kai = [0 for k in xrange(10)]
tou.append(kai)
n = int(raw_input())
for i in xrange(n):
b,f,r,v = map(int, raw_input().split(" "))
data[b-1][f-1][r-1] = max(0, data[b-1][f-1][r-1] + v)
for tou in data:
if not tou is data[0]:
print "#" * 20
for kai in tou:
print " " + " ".join(map(str, kai))
| 1 | 1,102,543,274,852 | null | 55 | 55 |
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 10**9
for i in range(M):
x, y, c = map(int, input().split())
if ans > a[x-1] + b[y-1] - c:
ans = a[x-1] + b[y-1] - c
if min(a) + min(b) < ans:
ans = min(a) + min(b)
print(ans)
|
def main():
N = int(input())
l = []
for i in range(N):
l.append(str(input()))
s_l = set(l)
print(len(s_l))
main()
| 0 | null | 42,128,136,740,210 | 200 | 165 |
N,K=map(int, input().split())
d=list(map(int,input().split()))
ans=0
for i in range(N):
if d[i]>=K:
ans=ans+1
print(ans)
|
a,b,c=map(int,input().split())
if a>b:
a,b = b,a
if c<a:
a,b,c = c,a,b
if c<b:
a,b,c = a,c,b
print(a,b,c)
| 0 | null | 89,932,517,578,400 | 298 | 40 |
a,b=map(int,input().split())
x=''
if a<b:
for i in range(b):
x+=str(a)
elif a>b:
for i in range(a):
x+=str(b)
elif a==b:
for i in range(a):
x+=str(a)
print(x)
|
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys
INF = float('inf')
def solve(S: str, T: str):
return T+S
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = next(tokens) # type: str
T = next(tokens) # type: str
print(f'{solve(S, T)}')
if __name__ == '__main__':
main()
| 0 | null | 93,957,903,395,478 | 232 | 248 |
n,m = map(int, input().split())
l = n - m
if l== 0:
print('Yes')
else:
print('No')
|
N,K = map(int,input().split())
A = list(map(int,input().split()))
if K==0:
high = max(A)
else:
low = 0
high = 10**9
while high-low>1:
mid = (high+low)//2
cnt = 0
for i in range(N):
if A[i]%mid==0:
cnt += A[i]//mid-1
else:
cnt += A[i]//mid
if K>=cnt:
high = mid
else:
low = mid
print(high)
| 0 | null | 44,808,046,066,850 | 231 | 99 |
x1, y1, x2, y2 = map(float, raw_input().split())
print ((x1-x2)**2 + (y1-y2)**2)**0.5
|
a, b, c, d = [float(temp) for temp in input().split()]
from math import sqrt
dis = sqrt((c - a) ** 2 + (d - b) ** 2)
print('%0.5f'%dis)
| 1 | 156,039,038,212 | null | 29 | 29 |
n,k=map(int,input().split())
h=list(map(int,input().split()))
if n<=k:
print(0)
exit()
h.sort()
if k==0:
print(sum(h))
else:
print(sum(h[:-k]))
|
N, K = map(int, input().split())
h = list(map(int, input().split()))
h = sorted(h)
if K == 0:
print(sum(h))
else:
print(sum(h[:-K]))
| 1 | 78,722,505,790,012 | null | 227 | 227 |
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 += 1
print(count)
|
import sys
#UnionFindTreeクラスの定義
class UnionFind():
#クラスコンストラクタ
#selfはインスタンス自身
def __init__(self, n):
#親ノードを-1に初期化する
self.parents = [-1] * n
#根を探す(再帰関数)
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
#xとyの木を併合する
def union(self, x, y):
#x,yの根をX,Yとする
X = self.find(x)
Y = self.find(y)
#根が同じなら結合済み
if X == Y:
return
#ノード数が多い方をXとする
if self.parents[X] > self.parents[Y]:
X, Y = Y, X
#XにYのノード数を足す
self.parents[X] += self.parents[Y]
#Yの根をXとする
self.parents[Y] = X
N, M = map(int, input().split())
info = [tuple(map(int, s.split())) for s in sys.stdin.readlines()]
#UnionFindインスタンスの生成
uf = UnionFind(N)
for a, b in info:
#インデックスを調整し、a,bの木を結合
a -= 1; b -= 1
uf.union(a, b)
ans = min(uf.parents)
print(-ans)
| 0 | null | 2,275,269,389,120 | 44 | 84 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.