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
|
---|---|---|---|---|---|---|
n,k = map(int, input().split())
for i in range(50):
if n < pow(k,i):
print(i)
exit() | x, y = map(int,input().split())
if (y%2 == 1):
print("No")
else:
if (y < x*2):
print("No")
elif (y > x*4):
print("No")
else:
print("Yes") | 0 | null | 39,122,868,434,880 | 212 | 127 |
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7
N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
X,Y = list(map(int,input().split()))
if (X+Y)%3 != 0:
print(0)
exit()
N = (X+Y)//3
K = min(2*N-X,X-N)
print(cmb(N,K,mod)) | X,Y=map(int,input().split())
mod = 10**9+7
if 2*X < Y or 2*Y < X:print(0)
elif (X+Y) % 3 != 0:print(0)
else:
n = (X+Y) // 3
X,Y=X-n,Y-n
factorial=[1 for i in range(X+Y+1)]
for i in range(1,X+Y+1):
if i==1:factorial[i]=1
else:factorial[i] = factorial[i-1]*i % mod
print(factorial[X+Y]*pow(factorial[X]*factorial[Y],-1,mod)%mod) | 1 | 149,689,403,794,980 | null | 281 | 281 |
S=str(input())
ans=''
for i in range(3):
ans+=S[i]
print(ans) | H,W,N=[int(input()) for i in range(3)]
print(min((N+H-1)//H,(N+W-1)//W)) | 0 | null | 51,660,673,253,732 | 130 | 236 |
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N,K = MI()
p = LI()
p.sort()
print(sum(p[i] for i in range(K)))
| N,K = map(int,input().split())
P = list(map(int,input().split()))
P.sort()
ans = sum(P[0:K])
print(ans) | 1 | 11,570,255,521,930 | null | 120 | 120 |
n = int(input())
s, t = input().split()
combination_of_letters = ''
for i in range(n):
combination_of_letters += s[i] + t[i]
print(combination_of_letters) | n= int(input())
list=input()
strlist=list.split(' ')
output=''
for i in range(n):
output=output+strlist[0][i]+strlist[1][i]
print(output)
| 1 | 111,994,523,933,732 | null | 255 | 255 |
# -*- coding: utf-8 -*-
import sys
def top_k_sort(data, k=3, reverse=True):
data.sort(reverse=True)
return data[:k]
def main():
data = []
for line in sys.stdin:
data.append(int(line))
for h in top_k_sort(data):
print(h)
if __name__ == '__main__':
main() | N=10
A=[int(input()) for i in range(N)]
A.sort(reverse=True)
for i in range(3):
print(A[i]) | 1 | 12,618,352 | null | 2 | 2 |
n = int(input())
a, b = map(int, input().split())
i = 0
ans = "NG"
while i <= b:
if i >= a and i % n == 0:
ans = "OK"
i += n
print(ans)
| k = int(input())
a, b = map(int, input().split())
x = 0
while True:
x += k
if a <= x <= b:
print('OK')
break
if x > b:
print('NG')
break | 1 | 26,422,505,019,120 | null | 158 | 158 |
N = int(input())
S = str(input())
cnt = 0
for i in range(N-2):
if S[i]=='A' and S[i+1]=='B' and S[i+2]=='C':
cnt += 1
print(cnt) | x,n=map(int,input().split())
p=set(list(map(int,input().split())))
if x not in p :
print(x)
exit()
i=1
while True:
if x-i not in p:
print(x-i)
exit()
if x+i not in p:
print(x+i)
exit()
i+=1
| 0 | null | 56,596,216,560,860 | 245 | 128 |
k, x = map(int, input().split())
if x <= k * 500: print('Yes')
else: print('No') | #ライブラリの読み込み
import math
#入力値の格納
k,x = map(int,input().split())
#判定
if k * 500 >= x:
text = "Yes"
else:
text = "No"
#表示
print(text)
| 1 | 97,987,633,139,792 | null | 244 | 244 |
k=int(input())
s=input()
l=len(s)
if l<=k:
print(s)
else:
s=list(s)
t=[]
for i in range(k):
t.append(s[i])
t.append('...')
print(''.join(t))
| K = int(input())
S = input()
print(S[:K]+"..." if len(S) > K else S) | 1 | 19,728,980,209,720 | null | 143 | 143 |
n = 0
while n == 0:
m = map(int,raw_input().split())
if m[0] + m[1] + m[2] == -3:
break
if m[0] == -1 or m[1] == -1:
print "F"
else:
for i in xrange(2):
if m[i] == -1:
m[i] = 0
k = m[0] + m[1]
if k >= 80:
print "A"
elif k >= 65:
print "B"
elif k >= 50:
print "C"
elif k >= 30:
if m[2] >= 50:
print "C"
else:
print "D"
elif k < 30:
print "F" | while True:
x = []
x = input().split( )
y = [int(s) for s in x]
if sum(y) == -3:
break
if y[0] == -1 or y[1] == -1:
print("F")
elif y[0] + y[1] < 30:
print("F")
elif y[0] + y[1] >= 30 and y[0] + y[1] <50:
if y[2] >= 50:
print("C")
else:
print("D")
elif y[0] + y[1] >= 50 and y[0] + y[1] <65:
print("C")
elif y[0] + y[1] >= 65 and y[0] + y[1] <80:
print("B")
elif y[0] + y[1] >= 80:
print("A")
| 1 | 1,237,164,978,038 | null | 57 | 57 |
a, b = map(int, input().split())
if a >= 10 or b >= 10:
print(-1)
else:
print(a*b) | a,b = map(int, input().split())
if a > 9 or b > 9: print(-1)
else: print(a*b) | 1 | 158,045,256,847,100 | null | 286 | 286 |
print(int(input())**2) | fib = [1]*100
for i in range(2,100):
fib[i] = fib[i-1] + fib[i-2]
print(fib[int(input())])
| 0 | null | 72,298,833,819,540 | 278 | 7 |
dice = [int(i) for i in input().split()]
n = int(input())
for _ in range(n):
face = list(map(int, input().split()))
if face in [[dice[0], dice[1]], [dice[1], dice[5]], [dice[5], dice[4]], [dice[4], dice[0]]]:
print(dice[2])
elif face in [[dice[0], dice[2]], [dice[2], dice[5]], [dice[5], dice[3]], [dice[3], dice[0]]]:
print(dice[4])
elif face in [[dice[0], dice[4]], [dice[4], dice[5]], [dice[5], dice[1]], [dice[1], dice[0]]]:
print(dice[3])
elif face in [[dice[0], dice[3]], [dice[3], dice[5]], [dice[5], dice[2]], [dice[2], dice[0]]]:
print(dice[1])
elif face in [[dice[1], dice[2]], [dice[2], dice[4]], [dice[4], dice[3]], [dice[3], dice[1]]]:
print(dice[0])
elif face in [[dice[1], dice[3]], [dice[3], dice[4]], [dice[4], dice[2]], [dice[2], dice[1]]]:
print(dice[5])
| x = int(input())
a = 1
flag = True
while flag:
upper = a**5-x
b = a
while True:
if b**5 == upper:
flag = False
a -= 1
break
if b**5<upper:
break
b -= 1
a += 1
print(a,b) | 0 | null | 12,886,387,657,610 | 34 | 156 |
s = input()
n = len(s)
t = input()
m = len(t)
c_max = 0
for i in range(n - m + 1):
c = 0
for j in range(m):
if s[i + j] == t[j]:
c += 1
if c > c_max:
c_max = c
print(m - c_max) | def bubbleSort(A):
N = len(A)
for i in range(N):
for j in range(N - 1, i, -1):
if A[j][1] < A[j - 1][1]:
A[j], A[j - 1] = A[j - 1], A[j]
return A
def selectionSort(A):
N = len(A)
for i in range(N):
min_i = i
for j in range(i, N):
if A[j][1] < A[min_i][1]:
min_i = j
if min_i != i:
A[i], A[min_i] = A[min_i], A[i]
return A
def is_stable(A, B):
for i in range(len(B) - 1):
if B[i][1] == B[i + 1][1]:
if A.index(B[i]) > A.index(B[i + 1]):
return False
return True
N = int(input())
A = list(input().split())
B = bubbleSort(A[:])
print(*B)
if is_stable(A, B):
print('Stable')
else:
print('Not stable')
S = selectionSort(A[:])
print(*S)
if is_stable(A, S):
print('Stable')
else:
print('Not stable') | 0 | null | 1,870,519,601,088 | 82 | 16 |
class Element:
def __init__(self, x):
self.x = x
self.lh = None
self.rh = None
class MyDeque:
def __init__(self):
self.top = self.tail = None
def insert(self, x):
elm = Element(x)
if self.top is None:
self.top = self.tail = elm
else:
elm.rh = self.top
self.top.lh = self.top = elm
def delete(self, x):
elm = self.top
while elm is not None:
if elm.x == x:
if elm.lh is None and elm.rh is None:
self.top = self.tail = None
else:
if elm.lh is None:
self.top = elm.rh
else:
elm.lh.rh = elm.rh
if elm.rh is None:
self.tail = elm.lh
else:
elm.rh.lh = elm.lh
break
elm = elm.rh
def delete_first(self):
if self.top is self.tail:
self.top = self.tail = None
else:
self.top = self.top.rh
self.top.lh = None
def delete_last(self):
if self.top is self.tail:
self.top = self.tail = None
else:
self.tail = self.tail.lh
self.tail.rh = None
def print_que(self):
elm = self.top
q=[]
while elm is not None:
q.append(elm.x)
elm = elm.rh
print(*q)
from sys import stdin
que = MyDeque()
N = int(input())
for _ in range(N):
cmd = stdin.readline().strip().split()
if cmd[0] == 'insert':
que.insert(cmd[1])
#que.print_que()
elif cmd[0] == 'delete':
que.delete(cmd[1])
#que.print_que()
elif cmd[0] == 'deleteFirst':
que.delete_first()
#que.print_que()
elif cmd[0] == 'deleteLast':
que.delete_last()
#que.print_que()
que.print_que()
| # coding: utf-8
# Your code here!
#一時保存
def count(target):
num=0
for i in range(N):
temp=target//F[i]
num+=max(A[i]-temp,0)
return num
N,K=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
ok=10**16+1
ng=0
if count(0)<=K:
print(0)
exit()
while ok-ng>1:
mid=(ok+ng)//2
if count(mid)>K:
ng=mid
else:
ok=mid
ng=0
while ok-ng>1:
mid=(ok+ng)//2
if count(mid)>K:
ng=mid
else:
ok=mid
print(ok)
| 0 | null | 82,621,554,289,080 | 20 | 290 |
if __name__ == '__main__':
from statistics import pstdev
while True:
# ??????????????\???
data_count = int(input())
if data_count == 0:
break
scores = [int(x) for x in input().split(' ')]
# ?¨??????????????¨????
result = pstdev(scores)
# ???????????????
print('{0:.8f}'.format(result)) | import heapq
INFTY = 10**4
N,X,Y = map(int,input().split())
G = {i:[] for i in range(1,N+1)}
for i in range(1,N):
G[i].append(i+1)
G[i+1].append(i)
G[X].append(Y)
G[Y].append(X)
dist = [[INFTY for _ in range(N+1)] for _ in range(N+1)]
for i in range(N+1):
dist[i][i] = 0
for i in range(1,N+1):
hist = [0 for _ in range(N+1)]
heap = [(0,i)]
hist[i] = 1
while heap:
d,x = heapq.heappop(heap)
if d>dist[i][x]:continue
hist[x] = 1
for y in G[x]:
if hist[y]==0:
if dist[i][y]>d+1:
dist[i][y] = d+1
heapq.heappush(heap,(d+1,y))
C = {k:0 for k in range(1,N)}
for i in range(1,N):
for j in range(i+1,N+1):
C[dist[i][j]] += 1
for k in range(1,N):
print(C[k]) | 0 | null | 22,022,210,107,238 | 31 | 187 |
n = int(input())
graph = [[] for _ in range(n)]
for i in range(n - 1):
a, b = map(int, input().split())
graph[a - 1].append((b - 1, i))
graph[b - 1].append((a - 1, i))
ans = [0] * (n - 1)
from collections import deque
d = deque()
d.append([0, -1])
while d:
point, prev = d.popleft()
color = 1 if prev != 1 else 2
for a, index in graph[point]:
if ans[index] == 0:
ans[index] = color
d.append([a, color])
color += 1 if prev != color + 1 else 2
print(max(ans))
print(*ans, sep='\n') | s = input()
if s=='AAA' or s=='BBB' : print('No')
else : print('Yes') | 0 | null | 95,687,232,016,110 | 272 | 201 |
N = input()
if (int( N )%2) == 0:
print( int(int(N) / 2 -1) )
else:
print( int((int(N)-1)/2) ) | name= list(map(str,input()))
print(name[0],name[1],name[2], sep="") | 0 | null | 84,226,740,456,030 | 283 | 130 |
N = int(input())
D = [input().split() for i in range(N)]
cnt=0
for i in range(N):
if D[i][0] == D[i][1]:
cnt+=1
if cnt == 3:
print("Yes")
exit()
else:
cnt=0
print("No") | n = int(input())
c = 0
for i in range(1,n):
if (i%2==1):
c+=1
print("{0:.10f}".format(1-(c/n)))
| 0 | null | 89,700,399,642,778 | 72 | 297 |
x1, y1, x2, y2 = map(float,input().split())
print(f'{((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5:8f}')
| N = int(input())
S = input()
A = []
x = 0
for i in range(N):
A.append(S[i])
for i in range(N):
if i != N - 1:
if A[i + 1] == A[i]:
x += 1
print(len(A) - x)
| 0 | null | 84,759,431,584,178 | 29 | 293 |
def main():
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for answer in calc(n, x, y):
print("{:.6f}".format(answer))
def calc(n, x, y):
ret = []
patterns = [1, 2, 3]
for pattern in patterns:
sum = 0
for i in range(0, n):
sum += (abs(x[i] - y[i])) ** pattern
ret.append(sum ** (1 / pattern))
last = 0
for i in range(0, n):
last = max(last, abs(x[i] - y[i]))
ret.append(last)
return ret
if __name__ == "__main__":
main()
| N = int(input())
print("ACL"*N)
| 0 | null | 1,209,553,345,678 | 32 | 69 |
N, M, Q = map(int, input().split())
L = list(tuple(map(int, input().split())) for _ in range(Q))
ans = 0
A = []
def dfs():
global A, ans
if len(A) == N:
res = sum(t[3] for t in L if A[t[1]-1] - A[t[0]-1] == t[2])
ans = max(ans, res)
else:
for a in range(A[-1] if A else 1, M + 1):
A.append(a)
dfs()
A.pop()
dfs()
print(ans)
| n,m,l=map(int, input().split())
A=[ [ int(a) for a in input().split() ] for i in range(n) ]
B=[ [ int(b) for b in input().split() ] for i in range(m) ]
Bt=[ list(x) for x in zip(*B) ]
for a in A:
print(" ".join(map(str, [ sum([ x*y for x,y in zip(a,b) ]) for b in Bt ]))) | 0 | null | 14,533,614,138,540 | 160 | 60 |
N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N-2):
for j in range(i, N-1):
for k in range(j, N):
a, b, c = L[i], L[j], L[k]
if a == b or b == c or c == a:
continue
elif a+b>c and b+c>a and c+a>b:
cnt+=1
print(cnt)
| N,K = map(int,input().split())
list1 ={i for i in range(1,N+1)}
list2 = set()
for i in range(K):
NN = int(input())
MM = map(int,input().split())
for j in MM:
list2.add(j)
ans = list1 -list2
print(len(ans)) | 0 | null | 14,895,347,956,958 | 91 | 154 |
class Dice(object):
def __init__(self,List):
self.face=List
def n_spin(self,List):
temp=List[0]
List[0]=List[1]
List[1]=List[5]
List[5]=List[4]
List[4]=temp
def s_spin(self,List):
temp=List[0]
List[0]=List[4]
List[4]=List[5]
List[5]=List[1]
List[1]=temp
def e_spin(self,List):
temp=List[0]
List[0]=List[3]
List[3]=List[5]
List[5]=List[2]
List[2]=temp
def w_spin(self,List):
temp=List[0]
List[0]=List[2]
List[2]=List[5]
List[5]=List[3]
List[3]=temp
dice = Dice(map(int,raw_input().split()))
command = list(raw_input())
for k in command:
if k=='N':
dice.n_spin(dice.face)
elif k=='S':
dice.s_spin(dice.face)
elif k=='E':
dice.e_spin(dice.face)
else:
dice.w_spin(dice.face)
print dice.face[0] | class Dice:
def __init__(self, ls):
self.ls = ls
self.now = 0
def roll(self, direction):
if direction == 'E': pat = [5, 2, 0, 3]
elif direction == 'N': pat = [5, 4, 0, 1]
elif direction == 'W': pat = [5, 3, 0, 2]
elif direction == 'S': pat = [5, 1, 0, 4]
tmp = self.ls[pat[0]]
for i in range(4):
try:
self.ls[pat[i]] = self.ls[pat[i+1]]
except(IndexError):
pass
self.ls[pat[-1]] = tmp
def top(self):
return self.ls[self.now]
dice = Dice(list(input().rstrip().split()))
for cmd in list(input().rstrip()):
dice.roll(cmd)
print(dice.top())
| 1 | 233,154,298,930 | null | 33 | 33 |
r,c = map(int,raw_input().split())
matrix = []
for i in range(r):
matrix.append(map(int,raw_input().split()))
a = [0 for j in range(c)]
matrix.append(a)
for i in range(r):
sum = 0
for j in range(c):
sum += matrix[i][j]
matrix[i].append(sum)
for j in range(c):
sum = 0
for i in range(r):
sum += matrix[i][j]
matrix[r][j] = sum
sum = 0
for j in range(c):
sum += matrix[r][j]
matrix[r].append(sum)
for i in range(r):
for j in range(c):
print matrix[i][j],
print matrix[i][c]
for j in range(c + 1):
print matrix[r][j], | def readinput():
n,k=map(int,input().split())
lr=[]
for _ in range(k):
l,r=map(int,input().split())
lr.append((l,r))
return n,k,lr
def main(n,k,lr):
lrs=sorted(lr,key=lambda x:x[0])
MOD=998244353
dp=[0]*(n+1)
dp[1]=1
for i in range(1,n):
#print(i)
if dp[i]==0:
continue
skip=False
for l,r in lrs:
for j in range(l,r+1):
#print('i+j: {}'.format(i+j))
if i+j>n:
skip=True
break
dp[i+j]=(dp[i+j]+dp[i])%MOD
#print(dp)
if skip:
break
return dp[n]
def main2(n,k,lr):
lrs=sorted(lr,key=lambda x:x[0])
MOD=998244353
dp=[0]*(n+1)
ruiseki=[0]*(n+1)
dp[1]=1
ruiseki[1]=1
for i in range(2,n+1):
for l,r in lrs:
if i-l<1:
break
dp[i]+=ruiseki[i-l]-ruiseki[max(1,i-r)-1]
dp[i]=dp[i]%MOD
ruiseki[i]=(ruiseki[i-1]+dp[i])%MOD
return dp[n]
if __name__=='__main__':
n,k,lr=readinput()
ans=main2(n,k,lr)
print(ans)
| 0 | null | 2,029,805,340,868 | 59 | 74 |
def selection_sort(seq):
l = len(seq)
cnt = 0
for i in range(l):
mi = i
for j in range(i+1, l):
if seq[j] < seq[mi]:
mi = j
if i is not mi:
seq[i], seq[mi] = seq[mi], seq[i]
cnt += 1
return seq, cnt
n = int(input())
a = list(map(int, input().split()))
sorted_a, num_swap = selection_sort(a)
print(' '.join(map(str, sorted_a)))
print(num_swap) | #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でやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
a,b = readInts()
print(a*b if (1 <= a <= 9 and 1 <= b <= 9) else '-1')
| 0 | null | 78,985,366,868,268 | 15 | 286 |
class Dice:
def __init__(self, d1, d2, d3, d4, d5, d6):
self.d1 = d1
self.d2 = d2
self.d3 = d3
self.d4 = d4
self.d5 = d5
self.d6 = d6
def S(self):
tmp = self.d1
self.d1 = self.d5
self.d5 = self.d6
self.d6 = self.d2
self.d2 = tmp
def N(self):
tmp = self.d1
self.d1 = self.d2
self.d2 = self.d6
self.d6 = self.d5
self.d5 = tmp
def E(self):
tmp = self.d1
self.d1 = self.d4
self.d4 = self.d6
self.d6 = self.d3
self.d3 = tmp
def W(self):
tmp = self.d1
self.d1 = self.d3
self.d3 = self.d6
self.d6 = self.d4
self.d4 = tmp
def output(self):
print(self.d1)
d1, d2, d3, d4, d5, d6 = map(int, input().split())
dice = Dice(d1, d2, d3, d4, d5, d6)
M = input()
for i in range(len(M)):
if M[i] == 'S':
dice.S()
elif M[i] == 'N':
dice.N()
elif M[i] == 'E':
dice.E()
elif M[i] == 'W':
dice.W()
dice.output()
| def rotate(dice,d):
if d == "N":
temp = dice[0]
dice[0] = dice[1]
dice[1] = dice[5]
dice[5] = dice[4]
dice[4] = temp
elif d == "E":
temp = dice[0]
dice[0] = dice[3]
dice[3] = dice[5]
dice[5] = dice[2]
dice[2] = temp
elif d == "W":
temp = dice[0]
dice[0] = dice[2]
dice[2] = dice[5]
dice[5] = dice[3]
dice[3] = temp
elif d == "S":
temp = dice[0]
dice[0] = dice[4]
dice[4] = dice[5]
dice[5] = dice[1]
dice[1] = temp
return dice
dice = input().split()
dArr = list(input())
for i in range(len(dArr)):
dice = rotate(dice,dArr[i])
print(dice[0]) | 1 | 240,176,337,258 | null | 33 | 33 |
n = int(input())
x, y = [list(map(float,input().split()))for i in range(2)]
print("%.6f"%sum([abs(x[i]-y[i])for i in range(n)]))
print("%.6f"%pow(sum([abs(x[i]-y[i])**2 for i in range(n)]), 1/2))
print("%.6f"%pow(sum([abs(x[i]-y[i])**3 for i in range(n)]), 1/3))
print(*max([abs(x[i]-y[i])] for i in range(n)))
| n = int(input())
x = [float(s) for s in input().split()]
y = [float(s) for s in input().split()]
xy = [abs(xi-yi) for xi,yi in zip(x,y)]
D = lambda p:sum([xyi**p for xyi in xy])**(1/p)
print(D(1.0))
print(D(2.0))
print(D(3.0))
print(max(xy)) | 1 | 222,015,207,744 | null | 32 | 32 |
from collections import Counter
N, M = [int(_) for _ in input().split()]
wa = Counter()
ac = set()
for i in range(M):
p, s = input().split()
p = int(p)
if p in ac: continue
if s == 'WA':
wa[p] += 1
else:
ac.add(p)
wa_cnt = 0
for v in ac:
wa_cnt += wa[v]
print(len(ac), wa_cnt)
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
????§???¢
????§???¢????????? a, b ??¨?????????????§? C ?????????
??????????§???¢?????¢??? S?????¨????????? L,
a ???????????¨????????¨???????????? h
????±???????????????°?????????????????????????????????
"""
import math
a, b, C = map(float,input().strip().split())
theta = math.radians(C) # ?????????????????¢??????
h = math.sin(theta) * b
S = a * h / 2
a1 = math.cos(theta) * b
a2 = a - a1
x = math.sqrt((h * h) + (a2 * a2))
L = a + b + x
print(S)
print(L)
print(h) | 0 | null | 46,785,190,620,224 | 240 | 30 |
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
if A[0]==1:
if N==0:
pass
else:
print(-1)
exit()
elif A[0]>1:
print(-1)
exit()
limit=[1]
for a in A[1:]:
limit.append(limit[-1]*2-a)
A=A[::-1]
limit=limit[::-1]
ans=A[0]
temp=A[0]
for i in range(len(limit)-1):
a=limit[i+1]
b=temp
x=b-a
y=a-x
if x<0:
x=0
y=temp
elif y<0:
print(-1)
exit()
temp=x+y+A[i+1]
ans+=temp
print(ans) | N = int(input())
A = list(map(int, input().split()))
B = [0] *(N+1)
B[0] = 1
ans = 0
for i in range(1, N+1):
B[i] = (B[i-1] - A[i-1])*2
if B[i] <= 0:
ans = -1
break
if B[N] < A[N]:
ans = -1
if ans == 0:
check = 0
for j in range(N, 0, -1):
check += A[j]
if check < B[j]:
ans += check
else:
last = j
for k in range(1, last+1):
ans += B[k]
break
ans += 1
if N == 0 and A[0] == 1:
ans = 1
print(ans)
| 1 | 18,813,251,991,132 | null | 141 | 141 |
N = input()
if N.count('7') > 0:
print("Yes")
else:
print('No')
| N=input()
i=0
while 1:
for a in N:
if a=="7":
print("Yes")
i=1
break
if i==1:
break
print("No")
break
| 1 | 34,443,189,143,232 | null | 172 | 172 |
#!/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):
return sum(S[i] != S[-(1 + i)] for i in range(len(S)//2))
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
print(f'{solve(S)}')
if __name__ == '__main__':
main()
| S = input()
N = len(S)
K = int(input())
dp = [[[0 for _ in range(5)] for _ in range(2)] for _ in range(N+1)]
dp[0][0][0] = 1
"""
遷移
dp[i][1][j] -> dp[i+1][1][j] : i-1桁目までに0以外の数字がj個あり、i桁目に0を入れた
dp[i][1][j] -> dp[i+1][1][j+1] : i-1桁目までに0以外の数字がj個あり、i桁目に0以外を入れた
dp[i][0][j] -> dp[i+1][1][j] : i-1桁目がSと一致していて、i-1桁目までに0以外の数字がj個あり、までに0以外の数字がj個あり、i桁目に0を入れた
dp[i][0][j] -> dp[i+1][1][j] : i-1桁目がSと一致していて、i-1桁目までに0以外の数字がj個あり、までに0以外の数字がj個あり、i桁目に0以外を入れた
dp[i][0][j] -> dp[i+1][0][j+?] : i桁目までSと一致。i桁目が0以外なら、?=1
"""
for i in range(N):
for k in range(4):
for j in range(10):
if j == 0:
# i桁目に0をあてた
dp[i+1][1][k] += dp[i][1][k]
else:
# i桁目に0以外をあてた
dp[i+1][1][k+1] += dp[i][1][k]
if j < int(S[i]):
if j == 0:
dp[i+1][1][k] += dp[i][0][k]
else:
dp[i+1][1][k+1] += dp[i][0][k]
elif j == int(S[i]):
if j == 0:
dp[i+1][0][k] += dp[i][0][k]
else:
dp[i+1][0][k+1] += dp[i][0][k]
print(dp[-1][0][K] + dp[-1][1][K])
| 0 | null | 97,759,777,966,172 | 261 | 224 |
mod = 10**9+7
def main():
n = int(input())
a = list(map(int, input().split()))
wa = sum(a)%mod
ans = 0
for i in range(n):
wa -= a[i]%mod
ans += (a[i]*wa)
ans %= mod
print(ans)
if __name__ == "__main__":
main() | import numpy as np
MOD = 10**9+7
N = int(input())
A = np.array(list(map(int, input().split())))
A = A % MOD
AS = []
s = 0
for a in range(len(A)):
s = (s + A[a]) % MOD
AS.append(s)
AS = np.array(AS)
s = 0
for i in range(len(A)-1):
s = (A[i] * ((AS[N-1]-AS[i])) % MOD + s) % MOD
print(s) | 1 | 3,790,249,501,500 | null | 83 | 83 |
h = -1
w = -1
while (h != 0) and (w != 0):
input = map(int, raw_input().split(" "))
h = input[0]
w = input[1]
if (h == 0 and w == 0):
break
i = 0
j = 0
line = ""
while j < w:
line += "#"
j += 1
while i < h:
print line
i += 1
print "" | while True:
a, b = map(int, input().split())
if a or b:
for i in range(0, a):
for j in range(0, b):
print("#", end = '')
print()
print()
else:
break
| 1 | 768,368,703,200 | null | 49 | 49 |
a,b=map(int,input().split())
def gcd(x, y):
while y:
x, y = y, x % y
return x
l=gcd(a,b)
print(int(a*b/l))
| weatherS = input()
serial = 0
dayBefore = ''
for x in weatherS:
if dayBefore != 'R':
if x == 'R':
serial = 1
else:
if x == 'R':
serial += 1
dayBefore = x
print(serial) | 0 | null | 58,898,864,113,714 | 256 | 90 |
N=int(input())
L=list(map(int,input().split()))
L.sort()
from bisect import bisect_left
ans = 0
for i1 in range(N-2):
for i2 in range(i1+1,N-1):
l1,l2 = L[i1],L[i2]
#th = bisect_left(L[i2+1:],l1+l2)
#print(l1,l2,L[i2+1:],(l2-l1+1)*(-1),th)
th = bisect_left(L,l1+l2)
ans += max(th-i2-1,0)
print(ans) | import math
N, M = map(int, input().split())
A_list = list(map(int, input().split()))
cnt = 0
A_sum = sum(A_list)
for i in range(N):
if A_list[i] >= math.ceil(A_sum/4/M):
cnt += 1
if cnt >= M:
print("Yes")
else:
print("No")
| 0 | null | 105,602,757,555,262 | 294 | 179 |
# import math
# import statistics
a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
# c.append(i)
# e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#g = [input() for _ in range(a)]
f.sort()
count=1
ans=[0 for i in range(a)]
for i in range(len(f)-1):
if f[i]==f[i+1]:
count+=1
else:
ans[f[i]-1]=count
count=1
if count>=1:
ans[f[-1]-1]=count
for i in ans:
print(i) | n,k=map(int,input().split())
count=1
subk=k
while subk<=n:
subk*=k
count+=1
print(count) | 0 | null | 48,621,733,595,940 | 169 | 212 |
s = int(input())
mod = 10**9+7
dp = [0]*(s+1)
dp[0] = 1
for i in range(1,s+1):
for j in range(0,(i-3)+1):
dp[i] += dp[j]
dp[i] %= mod
print(dp[s]) | from collections import deque
N, M, K = map(int, input().split())
G = [[] for i in range(N)]
NG = [set() for i in range(N)]
for _ in range(M):
A, B = map(int, input().split())
G[A - 1].append(B - 1)
G[B - 1].append(A - 1)
NG[A - 1].add(B - 1)
NG[B - 1].add(A - 1)
for _ in range(K):
A, B = map(int, input().split())
NG[A - 1].add(B - 1)
NG[B - 1].add(A - 1)
C = [-1] * N
CNT = [0] * N
c = 0
for i in range(N):
if C[i] >= 0: continue
Q = [i]
C[i] = c
CNT[c] += 1
while Q:
x = Q.pop()
for y in G[x]:
if C[y] == -1:
C[y] = C[x]
CNT[C[y]] += 1
Q.append(y)
c +=1
Y = [0] * N
for i in range(N):
Y[i] = CNT[C[i]] - 1
for i in range(N):
for j in NG[i]:
if C[i] == C[j]:
Y[i] -= 1
print(*Y)
| 0 | null | 32,270,972,197,108 | 79 | 209 |
def main():
N, P = map(int, input().split())
*s, = map(int, input())
if P in {2, 5}:
ans = 0
for i, x in enumerate(reversed(s), start=0):
if x % P == 0:
ans += N - i
print(ans)
return
ans = 0
total = 0
coef = 1
ctr = [0] * P
ctr[0] = 1
for x in reversed(s):
total = (total + x * coef) % P
coef = coef * 10 % P
ans += ctr[total]
ctr[total] += 1
print(ans)
if __name__ == '__main__':
main()
| import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N = I()
print(sum((i*(N//i)*(N//i+1)//2) for i in range(1,N+1)))
| 0 | null | 34,601,542,866,748 | 205 | 118 |
x = int(raw_input())
print (x**3) | cube = input()
print(cube**3) | 1 | 278,170,843,170 | null | 35 | 35 |
import sys
from collections import defaultdict
def solve():
input = sys.stdin.readline
N = int(input())
sDict = defaultdict(int)
maxCount = 0
for i in range(N):
s = input().strip("\n")
sDict[s] += 1
maxCount = max(maxCount, sDict[s])
maxS = []
for key in sDict:
if sDict[key] == maxCount:
maxS.append(key)
maxS.sort()
print(*maxS, sep="\n")
return 0
if __name__ == "__main__":
solve() | n = int(input())
d = {}
for i in range(n):
s = input()
if s in d:
d[s] += 1
else:
d[s] = 1
mx = max(d.values())
ans = ['']
for k, v in d.items():
if v == mx:
ans.append(k)
ans.sort()
print(*ans, sep='\n')
| 1 | 69,723,264,083,990 | null | 218 | 218 |
x, y = input().split()
prizes = {'1': 300000, '2': 200000, '3': 100000}
ans = prizes.get(x, 0) + prizes.get(y, 0)
if x == y == '1':
ans += 400000
print(ans)
| X, Y = map(int, input().split())
if X == 1 and Y == 1:
print(1000000)
else:
ans = 0
if X == 1:
ans += 300000
elif X == 2:
ans += 200000
elif X == 3:
ans += 100000
if Y == 1:
ans += 300000
elif Y == 2:
ans += 200000
elif Y == 3:
ans += 100000
print(ans)
| 1 | 141,228,032,540,402 | null | 275 | 275 |
from itertools import permutations as perm
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
comb = list(perm(range(1, N+1)))
def find(x):
for i, n in enumerate(comb):
if x == n:
return i
a = find(P)
b = find(Q)
ans = abs(a - b)
print(ans) | a,b,c=map(int,input().split())
print(['No','Yes'][4*a*b<(c-a-b)**2 and a+b<c]) | 0 | null | 75,690,441,444,618 | 246 | 197 |
H = int(input())
def battle(h):
if h == 1:
return 1
else:
return 2*battle(h//2)+1
print(battle(H))
| T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
# 必ずB1の方を大きくする必要がある
if A1 > B1:
B1, A1 = A1, B1
B2, A2 = A2, B2
P = T1*(A1-B1) # Pは負の値
Q = T2*(A2-B2)
if P + Q == 0:
print("infinity")
exit()
elif P + Q < 0: # 出会う位置まで戻ってこれなかった
print(0)
exit()
elif P + Q > 0: # 限られた数だけあえる
if (-P % (P + Q)) == 0:
print(2*(-P // (P+Q)))
else:
print(2*(-P // (P+Q))+1)
| 0 | null | 105,329,353,851,810 | 228 | 269 |
h = int(input())
w = int(input())
n = int(input())
print(min(-(-n//h),-(-n//w))) | input_list = []
for i in range(0, 3):
input_list.append(int(input()))
h = input_list[0]
w = input_list[1]
n = input_list[2]
temp_num = 0
if w <= h:
temp_num = h
else:
temp_num = w
answer = 0
if n % temp_num == 0:
answer = int(n / temp_num)
else:
answer = (n // temp_num) + 1
print(answer) | 1 | 88,862,924,966,738 | null | 236 | 236 |
a,b,c,d=map(int,input().split())
for i in range(a, 0, -d):
c=c-b
a=a-d
if c<=0:
print("Yes")
else:
print("No") | class Battle:
def __init__(self, A, B, C, D):
self.A = A
self.B = B
self.C = C
self.D = D
def result(self):
while self.A > 0 or self.C > 0:
self.C -= self.B
if self.C <= 0:
return "Yes"
self.A -= self.D
if self.A <= 0:
return "No"
def atc_164b(ABCD: str) -> str:
A, B, C, D = map(int, ABCD.split(" "))
battle = Battle(A, B, C, D)
return battle.result()
ABCD_input = input()
print(atc_164b(ABCD_input))
| 1 | 29,750,543,576,794 | null | 164 | 164 |
class HashTable:
def __init__(self, size = 1000003):
self.size = size
self.hash_table = [None] * size
def _gen_key(self, val):
raw_hash_val = hash(val)
h1 = raw_hash_val % self.size
h2 = 1 + (raw_hash_val % (self.size - 1))
for i in range(self.size):
candidate_key = (h1 + i * h2) % self.size
if not self.hash_table[candidate_key] or self.hash_table[candidate_key] == val:
return candidate_key
def insert(self, val):
key = self._gen_key(val)
self.hash_table[key] = val
def search(self, val):
key = self._gen_key(val)
if self.hash_table[key]:
print('yes')
else:
print('no')
import sys
n = int(sys.stdin.readline())
simple_dict = HashTable()
ans = ''
for i in range(n):
operation = sys.stdin.readline()
if operation[0] == 'i':
simple_dict.insert(operation[7:])
else:
simple_dict.search(operation[5:]) | n = int(input())
lst = []
for i in range(n):
tmp = input().split()
lst.append(tmp)
d = {}
for i in range(n):
if lst[i][0] == 'insert':
d[lst[i][1]] = d.get(lst[i][1], 0) + 1
elif lst[i][0] == 'find':
print('yes') if lst[i][1] in d else print('no')
| 1 | 74,352,331,050 | null | 23 | 23 |
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0]*(n+1)
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def same_check(self, x, y):
return self.find(x) == self.find(y)
N, M = map(int, input().split())
A = [0]*M
B = [0]*M
uf = UnionFind(N)
for i in range(M):
A[i], B[i] = map(int, input().split())
uf.union(A[i], B[i])
cnt = 0 #新しく作った橋の数
for j in range(1,N):
if uf.same_check(j, j+1) == False:
uf.union(j,j+1)
cnt+=1
print(cnt)
#print(uf.par[1:])
#print(uf.rank[1:]) | l=input().split()
r=int(l[0])
c=int(l[1])
# for yoko
i=0
b=[]
while i<r:
a=input().split()
q=0
su=0
while q<c:
b.append(int(a[q]))
su+=int(a[q])
q=q+1
b.append(su)
i=i+1
# for tate
#x=0
#d=b[0]+b[c+1]+b[2*(c+1)]+b[3*(c+1)]
#x<c+1
x=0
while x<c+1:
d=0
z=0
while z<r:
d+=b[x+z*(c+1)]
z+=1
b.append(d)
x=x+1
# for output
# C=[]
# y=0 (for gyou)
# z=0 (for yoko)
C=[]
y=0
while y<r+1:
z=0
Ans=str(b[y*(c+1)+z])
while z<c:
z+=1
Ans=Ans+" "+str(b[y*(c+1)+z])
C.append(Ans)
y+=1
for k in C:
print(k)
| 0 | null | 1,823,843,304,760 | 70 | 59 |
S,T=map(str,input().strip().split())
A,B=map(int,input().strip().split())
U=input()
if U==S:
print("{} {}".format(A-1,B))
else:
print("{} {}".format(A,B-1)) | a = input().split()
b = list(map(int, input().split()))
c = input()
if a[0]==c:
print(b[0]-1, b[1])
else:
print(b[0], b[1]-1) | 1 | 71,733,760,211,524 | null | 220 | 220 |
while True:
H, W = map(int, input().split())
if not(H or W):
break
print(('#' * W + '\n') * H) | s = int(input())
c = s // 500
d = s % 500
e = d //5
h = c*1000 + e*5
print(h) | 0 | null | 21,813,762,691,228 | 49 | 185 |
s, w = map(int, input().split())
print('safe') if s > w else print('unsafe') | N = int(input())
S = input()
S = list(S)
ans = ""
for i in range(N-1):
if S[i]==S[i+1]:
ans+=S[i]
print(N-len(ans)) | 0 | null | 99,360,127,468,140 | 163 | 293 |
s = input()
if s.endswith('s'):
s += 'es'
else:
s += 's'
print(s) | S = input()
print(S + 's') if S[-1] != 's' else print(S + 'es') | 1 | 2,358,521,915,570 | null | 71 | 71 |
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left, bisect_right
N,D,A=map(int, sys.stdin.readline().split())
XH=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
XH.sort()
bit=[ 0 for _ in range(N+1) ]
#BIT 関数は全て1-indexed
def add(a,w):
while a<=N:
bit[a]+=w
a+=a&-a
def sum(a):
ret=0
while 0<a:
ret+=bit[a]
a-=a&-a
return ret
#区間[l,r]に一律wを加える
def range_add(l,r,w):
add(l,w)
add(r+1,w*-1)
#a番目のモンスターの体力を取得
def get_value(a):
return sum(a)
X=[float("-inf")]
H=[float("-inf")]
for x,h in XH:
X.append(x)
H.append(h)
for i in range(1,N+1):
if i==1:
add(i,H[i])
else:
add(i,H[i]-H[i-1]) #区間に対する更新を行うため、値の差分をBITに持つ
ans=0
for i in range(1,N+1):
h=get_value(i)
if h<=0: #モンスターの体力がゼロ以下だったら何もしない
pass
else:
x=X[i]
pos=bisect_right(X,x+2*D)-1 #攻撃範囲の一番右側を二分探索で決定
if h%A==0: #hがAで割り切れる場合
cnt=h/A
range_add(i,pos,A*cnt*-1)
else:
cnt=h/A+1 #hをAで割って余りが出る場合は攻撃回数を+1する
range_add(i,pos,A*cnt*-1)
ans+=cnt
print ans
| import numpy as np
a,b=map(int,input().split())
print(max(a-2*b,0)) | 0 | null | 124,633,681,893,628 | 230 | 291 |
import sys
for i in sys.stdin:
lst = i.split(' ')
lst = map(int, lst)
lst.sort()
n = 1
maxn = 1
while n*n <= lst[0]:
if lst[0]%n == 0 and lst[1]%(lst[0]/n) == 0:
print lst[0]/n
break
elif lst[0]%n == 0 and lst[1]%n == 0:
maxn = n
n = n+1
else:
print maxn
sys.exit(0) | a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if abs(a - b) - (v - w)*t <= 0:
print("YES")
else:
print("NO") | 0 | null | 7,628,878,601,878 | 11 | 131 |
while True:
a, op, b = map(str, input().split())
if op =='?':
break
a = int(a)
b = int(b)
if op =='+':
print(a+b)
elif op == '-':
print(a-b)
elif op == '*':
print(a*b)
elif op == '/':
print(a//b)
| n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [0]
bb = [0]
for i in range(n):
aa.append(aa[-1]+a[i])
for i in range(m):
bb.append(bb[-1]+b[i])
c = m
ans = 0
for i in range(n+1):
u = k - aa[i]
for j in range(c, -1, -1):
if bb[j] <= u:
ans = max(ans, i+j)
c = j
break
print(ans) | 0 | null | 5,669,248,650,818 | 47 | 117 |
N = int(input())
s = [input() for i in range(N)]
'''
for v in ["AC", "WA", "TLE", "RE"]:
print("{0} x {1}".format(v, s.count(v)))
'''
print("AC x",s.count("AC"))
print("WA x",s.count("WA"))
print("TLE x",s.count("TLE"))
print("RE x",s.count("RE")) | 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 x " + str(ansRE)) | 1 | 8,699,857,157,992 | null | 109 | 109 |
from collections import deque
def main():
doubly_liked_list = deque()
n = int(input())
for i in range(n):
command = input()
if command == 'deleteFirst':
doubly_liked_list.popleft()
elif command == 'deleteLast':
doubly_liked_list.pop()
else:
command = command.split()
if command[0] == 'insert':
doubly_liked_list.appendleft(int(command[1]))
elif command[0] == 'delete':
try:
doubly_liked_list.remove(int(command[1]))
except:
pass
print(*doubly_liked_list)
if __name__ == "__main__":
main()
| num = input()
num_list = []
num_list = num.split()
if int(num_list[0]) == int(num_list[1]):
print('a','b',sep=' == ')
elif int(num_list[0]) > int(num_list[1]):
print('a','b',sep=' > ')
else:
print('a','b',sep=' < ') | 0 | null | 204,430,309,538 | 20 | 38 |
while True:
m,f,r=list(map(int,input().split()))
if m==f==r==-1: break
s=m+f
print('F' if m*f<0 or s<30 else 'D' if 30<=s<50 and r<50 else 'C' if 50<=s<65 or 30<=s<50 and 50<=r else 'B' if 65<=s<80 else 'A') | while True:
m, f, v = [int(n) for n in input().split()]
if m == f == v == -1:
break
sum = m + f
if m == -1 or f == -1:
print("F")
elif 80 <= sum:
print("A")
elif 65 <= sum < 80:
print("B")
elif 50 <= sum < 65:
print("C")
elif 30 <= sum < 50:
if 50 <= v:
print("C")
else:
print("D")
else:
print("F") | 1 | 1,223,193,066,832 | null | 57 | 57 |
from math import ceil
n=int(input())
flag=True
xceil=ceil(n/1.08)
xfloor=int(n/1.08)
for i in range(xfloor,xceil+1):
if int(i*1.08)==n:
print(i)
flag=False
break
if flag:
print(":(") | n=int(input())
res=0
for i in range(1,n+1):
if int(i*1.08)==n:
res=i
if res != 0:
print(res)
else:
print(":(") | 1 | 126,222,705,538,492 | null | 265 | 265 |
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, heapify
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 = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N = INT()
A = LIST()
LR = [[A[-1], A[-1]]]
for b in A[::-1][1:]:
LR.append([-(-LR[-1][0]//2)+b, LR[-1][1]+b])
LR = LR[::-1]
if LR[0][0] <= 1 <= LR[0][1]:
pass
else:
print(-1)
exit()
ans = 1
tmp = 1
for i, (L, R) in enumerate(LR[1:], 1):
tmp = min(2*tmp-A[i], R-A[i])
ans += tmp+A[i]
print(ans) | # coding: utf-8
def areas_calc(strings):
stack1 = []
stack2 = []
total_m = 0
for i, s in enumerate(strings):
if s == "\\":
stack1.append(i)
elif s == "_":
continue
elif s == '/':
if len(stack1) > 0:
previous_i = stack1.pop()
m = i - previous_i
total_m += m
while len(stack2) > 0:
stacked_i, stacked_m = stack2.pop()
if previous_i < stacked_i:
m += stacked_m
else:
stack2.append((stacked_i, stacked_m))
stack2.append((previous_i, m))
break
else:
stack2.append((previous_i, m))
print(total_m)
k = len(stack2)
for_output = [str(k)] + [str(m) for i, m in stack2]
print(' '.join(for_output))
if __name__ == "__main__":
areas_calc(input())
| 0 | null | 9,467,096,298,888 | 141 | 21 |
L = int(input())
a = L/3
m = a*a*a
print(m) | from decimal import Decimal
L = int(input())
w = Decimal(L / 3)
d = Decimal(L / 3)
h = Decimal(L / 3)
ans = Decimal(w * d * h)
print(ans) | 1 | 46,701,479,184,810 | null | 191 | 191 |
n=map(int,raw_input().split())
if n[0]<=n[1]<=n[2]:
a=n[0]
b=n[1]
c=n[2]
elif n[0]<=n[2]<=n[1]:
a=n[0]
b=n[2]
c=n[1]
elif n[1]<=n[0]<=n[2]:
a=n[1]
b=n[0]
c=n[2]
elif n[1]<=n[2]<=n[0]:
a=n[1]
b=n[2]
c=n[0]
elif n[2]<=n[0]<=n[1]:
a=n[2]
b=n[0]
c=n[1]
else:
a=n[2]
b=n[1]
c=n[0]
print a,b,c | N=int(input())
alist=list(map(int,input().split()))
a2list=[]
for i in range(N):
a2list.append((alist[i],i))
a2list.sort(reverse=True)
#print(a2list)
dp=[]
for i in range(N+1):
dp.append([0]*(N+1))
#print(dp)
for i in range(1,N+1):
aa,ii=a2list[i-1]
for j1 in range(i+1):
j2=i-j1
if j1==0:
dp[j1][j2]=dp[j1][j2-1]+aa*abs((N-1)-(j2-1)-ii)
elif j2==0:
dp[j1][j2]=dp[j1-1][j2]+aa*abs(ii-(j1-1))
else:
dp[j1][j2]=max(dp[j1][j2-1]+aa*abs((N-1)-(j2-1)-ii),dp[j1-1][j2]+aa*abs(ii-(j1-1)))
#print(dp)
answer=0
for i in range(N):
answer=max(answer,dp[i][N-i])
#print(dp[i][N-i])
print(answer) | 0 | null | 17,092,916,914,502 | 40 | 171 |
while 1:
h,w = map(int,raw_input().split())
if h==w==0: break
print ("#"*w+"\n")*h | a,b,c=map(int,raw_input().split())
if a+b >= c:
print "No"
else:
ans1 = 4 * a * b;
ans2 = (c - a - b) * (c - a - b)
if ans1 < ans2:
print "Yes"
else:
print "No" | 0 | null | 26,171,556,419,260 | 49 | 197 |
a, b = map(int, input().split())
c = []
if a > b:
a, b = b, a
if b%a == 0:
print(a)
else:
while True:
for i in range(a):
x = i + 2
#print(a, x)
if a%x == 0:
if b%x == 0:
c.append(x)
a = a//x
b = b//x
#print(c)
break
elif b%(a//x) == 0:
c.append(a//x)
a = x
b = b//(a//x)
#print(c)
break
#if x%1000 == 0:
#print(x)
if x > a**0.5:
break
if x > a**0.5:
break
s = 1
for j in c:
s = s * j
print(s)
| ss=str(input())
a=int(ss.count("R"))
if ss=="RSR":
a=1
print(a)
| 0 | null | 2,416,794,448,138 | 11 | 90 |
def gcd(a,b):
if b == 1:
return 1
elif b == 0:
return a
else:
return gcd(b,a%b)
a,b = map(int, raw_input().split(' '))
if a > b:
print gcd(a,b)
else:
print gcd(b,a) | a, b = map(int, input().rstrip().split(" "))
if a > b:
A = a
B = b
else:
A = b
B = a
GCD = 1
while True:
A, B = B, A%B
if B == 0:
break
print (str(A)) | 1 | 8,071,453,740 | null | 11 | 11 |
# -*- coding: utf-8 -*-
class dice_class:
def __init__(self, list):
self.num = list
def roll(self, s):
for i in s:
if i == 'E':
self.rollE()
elif i == 'N':
self.rollN()
elif i == 'S':
self.rollS()
elif i == 'W':
self.rollW()
def rollE(self):
self.num = [self.num[3], self.num[1], self.num[0], self.num[5], self.num[4], self.num[2]]
def rollN(self):
self.num = [self.num[1], self.num[5], self.num[2], self.num[3], self.num[0], self.num[4]]
def rollS(self):
self.num = [self.num[4], self.num[0], self.num[2], self.num[3], self.num[5], self.num[1]]
def rollW(self):
self.num = [self.num[2], self.num[1], self.num[5], self.num[0], self.num[4], self.num[3]]
if __name__ == "__main__":
dice = dice_class(map(int, raw_input().split()))
s = str(raw_input())
dice.roll(s)
print dice.num[0] | while(True):
H, W = map(int, input().split())
if(H == W == 0):
break
first = False
for i in range(H):
print("#" * W)
print() | 0 | null | 499,632,724,328 | 33 | 49 |
# -*- coding: utf-8 -*-
a, v = map(int,input().split())
b, w = map(int,input().split())
t = int(input())
if a == b:
print("YES")
exit()
if v <= w:
print("NO")
exit()
#print(b-a, w-v, t*(w-v))
if a < b:
if (b - a) <= t * (v - w): #(b - a) // (w - v) <= t
print("YES")
else:
print("NO")
elif a > b:
if (a - b) <= t * (v - w): #(a - b) // (v - w) <= t
print("YES")
else:
print("NO")
| a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())
ans = "NO"
if a > b: a,b = a*(-1), b*(-1)
if a == b: ans = "YES"
elif a < b:
if v > w and (b-a) <= (v-w)*t: ans = "YES"
print(ans) | 1 | 15,160,846,477,152 | null | 131 | 131 |
MOD = int(1e9) + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(60):
cnt = 0
for j in range(n):
if a[j] >> i & 1 == 1:
cnt += 1
ans += (cnt * (n-cnt) * (2**i)) % MOD
ans %= MOD
print(ans)
| N = int(input())
p = [list(map(int,input().split())) for _ in range(N)]
z = []
w = []
for i in range(N):
z.append(p[i][0] + p[i][1])
w.append(p[i][0] - p[i][1])
print(max(max(z)-min(z),max(w)-min(w))) | 0 | null | 63,544,217,505,720 | 263 | 80 |
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
q = int(input())
dict_A = Counter(A)
sum_list = sum(A)
for i in range(q):
b, c = map(int, input().split())
if b not in dict_A:
print(sum_list)
else:
b_num = dict_A[b]
dict_A[c] += dict_A[b]
dict_A[b] = 0
sum_list = sum_list + (c - b) * b_num
print(sum_list)
| n = int(input())
a = list(map(int, input().split()))
s = sum(a)
q = int(input())
l = [0] * 100000
for i in a:
l[i-1] += 1
for i in range(q):
x,y = map(int, input().split())
hoge = l[x-1]
s -= hoge*x
s += hoge*y
l[y-1] += hoge
l[x-1] = 0
print(s)
| 1 | 12,081,014,266,592 | null | 122 | 122 |
from collections import deque
def main():
n, m = map(int, input().split())
adj = [[] for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
adj[a - 1].append(b - 1)
adj[b - 1].append(a - 1)
ans = 0
visited = [False] * n
for i in range(n):
if visited[i]:
continue
q = deque()
q.append(i)
cnt = 1
visited[i] = True
while q:
u = q.popleft()
for v in adj[u]:
if not visited[v]:
q.append(v)
cnt += 1
visited[v] = True
ans = max(ans, cnt)
print(ans)
if __name__ == "__main__":
main()
| n,m = map(int,input().split())
a = [1]*(n+1)
b = [0]*(n+1)
for i in range(m):
x,y = map(int,input().split())
u = x
while a[u]==0:
u = b[u]
v = y
while a[v]==0:
v = b[v]
if u!=v:
b[v] = u
b[y] = u
b[x] = u
a[u] += a[v]
a[v] = 0
print(max(a)) | 1 | 4,020,789,219,090 | null | 84 | 84 |
s = input()
n = len(s)
l = 0
r = 0
ans = 0
for i in range(n):
if '<' == s[i]:
if r != 0:
M = max(l,r)
m = min(l,r)
ans += M*(M+1)//2 + m*(m-1)//2
r = 0
l = 0
l += 1
if '>' == s[i]:
r += 1
M = max(l,r)
m = min(l,r)
ans += M*(M+1)//2 + m*(m-1)//2
print(ans) | n, k = map(int, input().split())
q, count = n, 0
while(q >= k):
r = q%k; q = q//k
count += 1
print(count+1) | 0 | null | 110,082,683,688,600 | 285 | 212 |
N, M, L = map(int, raw_input().split())
nm = [map(int, raw_input().split()) for n in range(N)]
ml = [map(int, raw_input().split()) for m in range(M)]
for n in range(N):
col = [0] * L
for l in range(L):
for m in range(M):
col[l] += nm[n][m] * ml[m][l]
print ' '.join(map(str, col)) | n,m,l=map(int, input().split())
a=[]
b=[]
for i in range(n):
a.append(list(map(int, input().split())))
for j in range(m):
b.append(list(map(int, input().split())))
for i in range(n):
ci=[0]*l
for k in range(l):
for j in range(m):
ci[k]+=a[i][j]*b[j][k]
print(*ci)
| 1 | 1,443,710,619,428 | null | 60 | 60 |
def main():
H, N = map(int, input().split(' '))
A = input().split(' ')
total = 0
for i in A:
total += int(i)
if total >= H:
print('Yes')
else:
print('No')
main()
| n,k,c=map(int,input().split())
s=input()
def greedy_work(days,rest,plan):
day_count=0
go=[0]*n
while day_count < days:
if plan[day_count]=='o':
go[day_count]=1
day_count += rest+1
else:
day_count += 1
return(go)
front = greedy_work(n,c,s)
back = greedy_work(n,c,s[::-1])
back = back[::-1]
if front.count(1)==k:
for i in range(n):
if front[i]==1 and back[i]==1:
print(i+1) | 0 | null | 59,192,053,786,280 | 226 | 182 |
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import print_function,division
from itertools import combinations
import time
import sys
import io
import re
import math
start = time.clock()
i = 0
def enum_sum_numbers(sets, s_range, r):
for cmb in combinations(sets,r):
yield sum(cmb)
if r <=s_range:
for s in enum_sum_numbers(sets,s_range, r+1):
yield s
sys.stdin.readline()
a=[int(s) for s in sys.stdin.readline().split()]
sys.stdin.readline()
ms=[int(s) for s in sys.stdin.readline().split()]
sets={s for s in enum_sum_numbers(a,len(a),1)}
for m in ms:
print('yes' if m in sets else 'no') | #!/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, A: int, B: int, U: str):
return f"{A-(S==U)} {B-(T==U)}"
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
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
U = next(tokens) # type: str
print(f'{solve(S, T, A, B, U)}')
if __name__ == '__main__':
main()
| 0 | null | 36,260,405,542,640 | 25 | 220 |
(h,n),*c=[[*map(int,i.split())]for i in open(0)]
d=[0]*20002
for i in range(h):d[i]=min(d[i-a]+b for a,b in c)
print(d[h-1]) | import sys
input = sys.stdin.buffer.readline
H, N = map(int, input().split())
A = [tuple(map(int, line.split())) for line in sys.stdin.buffer.readlines()]
INF = 1 << 30
dp = [INF]*(H+1)
dp[H] = 0
for i in range(N):
a, b = A[i]
for h in range(H, -1, -1):
x = h-a if h-a > 0 else 0
if dp[x] > dp[h]+b:
dp[x] = dp[h]+b
print(dp[0])
| 1 | 81,372,703,516,256 | null | 229 | 229 |
a, b = map(int, input().split())
ans = 0
if a >= b:
for i in range(a):
ans += b * 10**i
else:
for i in range(b):
ans += a * 10**i
print(ans) | import math
r = float(input())
pi = float(math.pi)
print("{0:.8f} {1:.8f}".format(r*r*pi,r * 2 * pi)) | 0 | null | 42,348,154,293,042 | 232 | 46 |
N,X,Y=map(int,input().split())
distance=[0]*N
for i in range(1,N):
for j in range(i+1,N+1):
k=min(j-i,abs(j-X)+abs(i-Y)+1,abs(j-Y)+abs(i-X)+1)
distance[k]+=1
print(*distance[1:],sep="\n") | while 1:
H , W = map(int, raw_input().split())
if H == 0 and W == 0:
break
for l in range(0,H):
print '#' * W
print | 0 | null | 22,298,921,935,460 | 187 | 49 |
from decimal import Decimal as D
a,b=map(str,input().split())
print(int(D(a)*D(b))) | o = ['unsafe','safe']
s,w = map(int,input().split())
f = 0
if w >= s:
f = 0
else:
f = 1
print(o[f]) | 0 | null | 22,728,500,444,600 | 135 | 163 |
N,R = map(int,input().split())
print(R + 100*(10-N)) if N < 10 else print(R) | li1 = []
li2 = []
ans = 0
for i, s in enumerate(input()):
if s == "\\":
li1.append(i)
elif s == "/" and li1:
j = li1.pop()
c = i - j
ans += c
while li2 and li2[-1][0] > j:
c += li2[-1][1]
li2.pop()
li2.append((j, c))
print(ans)
if li2:
print(len(li2), *list(zip(*li2))[1])
else:
print(0)
| 0 | null | 31,908,640,110,710 | 211 | 21 |
from collections import defaultdict
N=int(input())
*A,=map(int,input().split())
mod = 10**9+7
count = defaultdict(int)
count[0] = 3
ans = 1
for i in range(N):
ans *= count[A[i]]
ans %= mod
count[A[i]] -= 1
count[A[i]+1] += 1
print(ans) | def solve():
N = int(input())
A = list(map(int, input().split()))
MOD = 1000000007
color = [0] * N
can_use = [0] * (N + 1)
can_use[0] = 3
for i in range(N):
color[i] = can_use[A[i]]
can_use[A[i]] -= 1
can_use[A[i] + 1] += 1
ans = 1
for c in color:
ans = ans * c % MOD
print(ans)
if __name__ == '__main__':
solve()
| 1 | 130,060,624,972,800 | null | 268 | 268 |
S = input()
if S.count("hi")*2 == len(S):
print("Yes")
else:
print("No") | K = int(input())
S = input()
if len(S) <= K:
print(S)
else:
print("{0}...".format(S[0:K])) | 0 | null | 36,422,611,729,488 | 199 | 143 |
def dist(X, Y, p):
return sum(abs(x - y) ** p for x, y in zip(X,Y)) ** (1.0 / p)
n = input()
X = map(int, raw_input().split())
Y = map(int, raw_input().split())
for i in [1, 2, 3]:
print dist(X, Y, i)
print max(map(lambda xy: abs(xy[0] - xy[1]), zip(X, Y))) | import sys
read = sys.stdin.read
readline = sys.stdin.readline
count = 0
l, r, d= [int(x) for x in readline().rstrip().split()]
#print(l,r,d)
for i in range(l,r+1):
if i % d == 0:
count += 1
print(count)
| 0 | null | 3,887,736,256,348 | 32 | 104 |
N = int(input())
E = [[] for _ in range(N+1)]
for _ in range(N):
tmp = list(map(int, input().split()))
if tmp[1] == 0:
continue
E[tmp[0]] = tmp[2:]
cnt = [0 for _ in range(N+1)]
q = [1]
while q:
cp = q.pop(0)
for np in E[cp]:
if cnt[np] != 0:
continue
cnt[np] = cnt[cp] + 1
q.append(np)
for ind, cost in enumerate(cnt):
if ind == 0:
continue
if ind == 1:
print(ind, 0)
else:
if cost == 0:
print(ind, -1)
else:
print(ind, cost)
| N = int(input())
if N%2 == 1 :
print(0)
exit()
n = 0
i = 0
for i in range(1,26) :
n += N//((5**i)*2)
print(n) | 0 | null | 57,774,113,524,680 | 9 | 258 |
from sys import stdin
input = stdin.readline
def Judge(S, T):
ls = len(S)
lt = len(T)
m = 0
for i in range(ls-lt+1):
tmp = 0
for j in range(lt):
if S[i+j] == T[j]:
tmp += 1
if m < tmp:
m = tmp
return lt - m
S = input().strip()
T = input().strip()
print(Judge(S, T)) | s = input()
t = input()
sl = len(s)
tl = len(t)
ans = 1001
for i in range(sl-tl+1):
cnt = 0
for sv, tv in zip(s[i:i+tl], t):
if sv != tv:
cnt += 1
ans = min(cnt, ans)
print(ans)
| 1 | 3,681,115,061,430 | null | 82 | 82 |
# Papers, Please
N = int(input())
A = list(map(int, input().split()))
for Ai in A:
if Ai % 2 == 1:
continue
else:
if Ai % 3 != 0 and Ai % 5 != 0:
print("DENIED")
exit()
print("APPROVED") | n = int(input())
a = list(map(int, input().split()))
def f():
for i in range(n):
if a[i] % 2 == 0:
if a[i] % 3 != 0 and a[i] % 5 != 0:
return "DENIED"
return "APPROVED"
print(f()) | 1 | 68,754,686,635,518 | null | 217 | 217 |
a1,a2,a3=map(int,input().split())
ans=a1+a2+a3
if ans>=22:
print("bust")
else:
print("win") | N = int(input())
A_ = input().split()
A = [int(i) for i in A_]
S = 0
a = A[0]
for i in range(len(A)-1):
if a > A[i+1]:
S += a-A[i+1]
else:
a = A[i+1]
print(S) | 0 | null | 61,795,012,822,090 | 260 | 88 |
class DoublyLinkedList:
def __init__(self):
self.nil = self.make_node(None)
self.nil['next'] = self.nil
self.nil['prev'] = self.nil
def make_node(self, k):
return {'key':k, 'next':None,'prev':None}
def insert(self, key):
x = self.make_node(key)
x['next'] = self.nil['next']
self.nil['next']['prev'] = x
self.nil['next'] = x
x['prev'] = self.nil
def listSearch(self,key):
cur = self.nil['next']
while cur['key'] != None and cur['key'] != key:
cur = cur['next']
return cur
def delete(self, k):
self.delete_node(self.listSearch(k))
def delete_node(self,x):
if x['key'] == None: return
x['prev']['next'] = x['next']
x['next']['prev'] = x['prev']
def deleteFirst(self):
self.delete_node(self.nil['next'])
def deleteLast(self):
self.delete_node(self.nil['prev'])
def printList(self):
x = self.nil['next']
while True:
if x['key'] == None:
break
else:
print x['key'],
x = x['next']
print
def main():
N = int(raw_input())
commands = []
for i in xrange(N):
commands.append(raw_input())
d = DoublyLinkedList()
for c in commands:
a = c[0]
if a == 'i':
d.insert(int(c[7:]))
else:
if c[6] == 'F':
d.deleteFirst()
elif c[6] == 'L':
d.deleteLast()
else:
d.delete(int(c[7:]))
d.printList()
return 0
main() | from collections import deque
q = deque()
for i in range(int(input())):
command_line = input().split(" ")
command = command_line[0]
arg = ""
if len(command_line) > 1: arg = command_line[1]
if command == "insert":
q.appendleft(arg)
elif command == "delete":
try:
q.remove(arg)
except ValueError:
pass
elif command == "deleteFirst":
q.popleft()
else:
q.pop()
print(" ".join(q)) | 1 | 51,745,567,510 | null | 20 | 20 |
import sys
readline = sys.stdin.readline
N,X,Y = map(int,readline().split())
G = [[] for i in range(N)]
for i in range(N - 1):
G[i].append(i + 1)
G[i + 1].append(i)
G[X - 1].append(Y - 1)
G[Y - 1].append(X - 1)
ans = [0] * N
from collections import deque
for i in range(N):
q = deque([])
q.append([i, -1, 0])
seen = set()
while q:
v, parent,cost = q.popleft()
if v in seen:
continue
seen.add(v)
ans[cost] += 1
for child in G[v]:
if child == parent:
continue
q.append([child, i, cost + 1])
for i in range(1, N):
print(ans[i] // 2)
|
def search(start, N, X, Y):
dist = [0 for _ in range(N)]
if start <= X:
for i in range(X):
dist[i] = abs(start - i)
for i in range(Y, N):
dist[i] = (X - start) + 1 + (i - Y)
for i in range(X, (Y - X) // 2 + X + 1):
dist[i] = (i - start)
for i in range((Y - X) // 2 + X + 1, Y):
dist[i] = (X - start) + 1 + (Y - i)
elif start >= Y:
for i in range(Y, N):
dist[i] = abs(start - i)
for i in range(X):
dist[i] = (start - Y) + 1 + (X - i)
for i in range(X, (Y - X) // 2 + X):
dist[i] = (start - Y) + 1 + (i - X)
for i in range((Y - X) // 2 + X, Y):
dist[i] = (start - i)
else:
toX = min(start - X, Y - start + 1)
toY = min(Y - start, start - X + 1)
dist[start] = 0
for i in range(X):
dist[i] = (X - i) + toX
for i in range(Y, N):
dist[i] = toY + (i - Y)
for i in range(X, start):
dist[i] = min(start - i, Y - start + 1 + i - X)
for i in range(start + 1, Y):
dist[i] = min(i - start, start - X + 1 + Y - i)
return dist
def main():
N, X, Y = [int(n) for n in input().split(" ")]
#N, X, Y = 10, 3, 8
X = X - 1
Y = Y - 1
lenD = []
for i in range(N):
d = search(i, N, X, Y)
lenD.append(d)
kcounter = [0 for _ in range(N - 1)]
for i in range(N):
for j in range(i + 1, N):
k = lenD[i][j]
kcounter[k - 1] += 1
for k in kcounter:
print(k)
main() | 1 | 43,988,732,551,588 | null | 187 | 187 |
#もらうDP + 累積和
n, k = map(int, input().split())
mod = 998244353
li = []
for _ in range(k):
l, r = map(int, input().split())
li.append((l, r))
li.sort()
dp = [0]*(2*n+1)
s = [0] * (2*n+1)
dp[1] = 1
s[1] = 1
for i in range(2, n+1):
for t in li:
l, r = t
dp[i] += s[max(i-l, 0)]
dp[i] -= s[max(i-r-1, 0)]
dp[i] %= mod
s[i] = s[i-1] + dp[i]
s[i] %= mod
print(dp[i]%mod) | M=998244353
f=lambda:[*map(int,input().split())]
n,k=f()
lr=[f() for _ in range(k)]
dp=[0]*n
dp[0]=1
S=[0]
for i in range(1,n):
S+=[S[-1]+dp[i-1]]
for l,r in lr:
dp[i]+=S[max(i-l+1,0)]-S[max(i-r,0)]
dp[i]%=M
print(dp[-1]) | 1 | 2,722,454,426,120 | null | 74 | 74 |
name= list(map(str,input()))
print(name[0],name[1],name[2], sep="") | str = input()
print(str[0]+str[1]+str[2]) | 1 | 14,684,310,820,640 | null | 130 | 130 |
def sample(n):
return n * n * n
n = input()
x = sample(n)
print x | import sys
num = map(int,raw_input().split())
if num[0] < num[1]:
print "a < b"
elif num[0] == num[1]:
print "a == b"
elif num[0] > num[1]:
print "a > b" | 0 | null | 325,926,110,040 | 35 | 38 |
N, M = list(map(int,input().split()))
e = True
c = [-1 for i in range(N)]
for i in range(M):
si, ci = list(map(int,input().split()))
if c[si-1]>-1 and c[si-1]!=ci:
e = False
c[si-1] = ci
if e and (N==1 or c[0]!=0):
print(max(0 if N==1 else 1, c[0]),end="")
for i in range(1,N):
print(max(0,c[i]),end="")
print()
else:
print(-1) | from itertools import product
def max2(x,y):
return x if x > y else y
N = int(input())
data = [[] for _ in range(N)]
res = 0
for i in range(N):
for _ in range(int(input())):
data[i].append(tuple(map(int, input().split())))
for a in product((0,1), repeat=N):
flg = False
for i in range(N):
for x, y in data[i]:
x -= 1
if a[i] == 1:
if a[x] != y:
flg = True
break
if flg:
break
if i == N-1:
res = max2(res, sum(a))
print(res)
| 0 | null | 91,115,236,088,942 | 208 | 262 |
n = int(input())
d = set()
for _ in range(n):
command = input()
if 'i' == command[0]:
_, word = command.split()
d.add(word)
else:
_, word = command.split()
print('yes' if word in d else 'no') | N = input()
K = int(input())
# K = 1の時の組み合わせを求める関数
def func_1(N):
Nm = int(N[0])
return Nm + 9 * (len(N) - 1)
# K = 2の時の組み合わせを求める関数
def func_2(N):
#NはStringなので
#print(N[0])
Nm = int(N[0])
m = len(N)
#if m == 1:
# print("0")
#print((Nm-1)*(m-1)*9)
#print((m - 1) * (m - 2) * 9 * 9 / 2)
x = int(N) - Nm * pow(10, m-1)
#print(x)
#print(1)
#print(func_1(str(x)))
return int((Nm-1)*(m-1)*9+(m-1)*(m-2)*9*9/2+func_1(str(x)))
def func_3(N):
#print("OK")
Nm = int(N[0])
m = len(N)
# if m == 1 or m == 2:
# print("0")
return int(pow(9,3)*(m-1)*(m-2)*(m-3)/6+(Nm-1)*(m-1)*(m-2)*9*9/2+func_2(str(int(N)-Nm*(10**(m-1)))))
if K == 1:
print(func_1(N))
elif K == 2:
print(func_2(N))
elif K == 3:
print(func_3(N)) | 0 | null | 38,240,069,619,360 | 23 | 224 |
#coding:utf-8
import math
def isPrime(n):
if n == 2:
return True
elif n % 2 == 0:
return False
else:
for i in range(3,math.ceil(math.sqrt(n))+1,2):
if n % i == 0:
return False
return True
n = int(input())
c = 0
for i in range(n):
if isPrime(int(input())):
c += 1
print(c) | #!/usr/bin/env python3
def next_line():
return input()
def next_int():
return int(input())
def next_int_array_one_line():
return list(map(int, input().split()))
def next_int_array_multi_lines(size):
return [int(input()) for _ in range(size)]
def next_str_array(size):
return [input() for _ in range(size)]
def main():
n = next_int()
ar = next_int_array_one_line()
num = [0] * 100001
for a in ar:
num[a] += 1
q = next_int()
res = 0
for i in range(len(num)):
res += num[i] * i
for i in range(q):
b, c = map(int, input().split())
res += (c-b) * num[b]
num[c] += num[b]
num[b] = 0
print(res)
if __name__ == '__main__':
main()
| 0 | null | 6,074,212,084,122 | 12 | 122 |
import math
a = list(map(int, input().strip().split()))
for i in a:
if a[i] == 0:
o = i
break
else:
pass
print(o+1) | import math
X=int(input())
print(360//math.gcd(360, X)) | 0 | null | 13,217,258,792,348 | 126 | 125 |
import random
D = int(input())
C = list(map(int,input().split()))
S = []
for i in range(D):
S.append(list(map(int,input().split())))
t = []
for i in range(D):
#t.append(int(random.uniform(0,26)))
t.append(int(input()))
lastds = [0]*26
ans = 0
satisfaction = 0
#initial
for d in range(D):
lastds[t[d]-1] = d+1
satisfaction += S[d][t[d]-1]
for i in range(26):
satisfaction -= C[i] * (d+1-lastds[i])
print(satisfaction) | D = int(input())
c = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(D)]
T = [int(input()) for i in range(D)]
SUM = 0
last = [0] * 28
for d in range(1, D + 1):
i = T[d - 1]
SUM += S[d - 1][i - 1]
SU = 0
last[i] = d
for j in range(1, 27):
SU += (c[j - 1] * (d - last[j]))
SUM -= SU
print(SUM) | 1 | 10,032,038,136,000 | null | 114 | 114 |
def main():
a,b,c=map(int,input().split())
if a<b<c:
print('Yes')
else:
print('No')
if __name__=='__main__':
main()
| S = input()
L = S.split()
a = L[0]
b = L[1]
c = L[2]
a = int(a)
b = int(b)
c = int(c)
if a < b < c:
print('Yes')
else :
print('No') | 1 | 388,829,658,972 | null | 39 | 39 |
x=int(input())
for a in range(-200,200):
for b in range(-200,200):
if a**5 - b**5 == x:
print(a,b)
break
else:
continue
break
| x=int(input())
for a in range(-200,200,1):
for b in range(-200,200,1):
if a**5 - b**5 == x:
print(a,b)
exit() | 1 | 25,471,773,879,772 | null | 156 | 156 |
def fibonacci(n):
a, b = 1, 0
for _ in range(0, n):
a, b = b, a + b
return b
n=int(input())
n+=1
print(fibonacci(n))
| import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
n, *a = map(int, read().split())
a.sort()
a = tuple(a)
TorF = [0] * (a[-1] + 1)
for ae in a:
TorF[ae] = 1
for i1 in range(n - 1):
a1 = a[i1]
if TorF[a1]:
m = a[-1] // a1 + 1
for i2 in range(2, m):
TorF[a1 * i2] = 0
if a[i1 + 1] == a[i1]:
TorF[a[i1]] = 0
r = sum(TorF)
print(r)
if __name__ == '__main__':
main() | 0 | null | 7,146,404,929,170 | 7 | 129 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.