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 = int(input())
x = 100000
for i in range(n):
x = x * 1.05
if x % 1000 != 0:
x=x+1000-(x%1000)
print(int(x))
| if __name__ == '__main__':
n,m = map(int,input().split())
A = [-1 for _ in range(n)]
B = []
for i in range(m):
x,y = map(int,input().split())
B.append([x,y])
flg = True
for a in B:
x = a[0]
y = a[1]
if A[x-1] == -1:
A[x-1] = y
else:
if A[x-1] != y:
flg = False
break
ans = 0
if flg:
#穴埋め
for i,j in enumerate(A):
if j == -1:
if i == 0 and len(A) != 1:
A[i] = 1
else:
A[i] = 0
tmp = ""
for k in range(n):
tmp += str(A[k])
tmp = str(int(tmp))
if len(tmp) == n :
ans = int(tmp)
else:
ans = -1
else:
ans = -1
print(ans)
| 0 | null | 30,316,468,438,762 | 6 | 208 |
def create_sums(ns):
if len(ns) == 0:
return set()
s = create_sums(ns[1:])
return {e + ns[0] for e in s} | s | {ns[0]}
def run_set():
_ = int(input()) # flake8: noqa
ns = [int(i) for i in input().split()]
sums = create_sums(ns)
_ = int(input()) # flake8: noqa
for q in (int(j) for j in input().split()):
if q in sums:
print("yes")
else:
print("no")
if __name__ == '__main__':
run_set()
| n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = list(input().split())
for i in range(m):
B[i] = int(B[i])
def solve(x,y):
if x==n:
S[y] = 1
else:
solve(x+1,y)
if y+A[x] < 2001:
solve(x+1,y+A[x])
S = [0 for i in range(2001)]
solve(0,0)
for i in range(m):
if S[B[i]] == 1:
print("yes")
else:
print("no")
| 1 | 102,502,385,258 | null | 25 | 25 |
import math
x1,y1,x2,y2=map(float,input().split())
x2=x2-x1
y2=y2-y1
x1,y1=0,0
dis=(x2**2+y2**2)
print(math.sqrt(dis)) | import math
if __name__ == '__main__':
x1, y1, x2, y2 = [float(i) for i in input().split()]
d = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
print("{0:.5f}".format(d)) | 1 | 162,654,839,540 | null | 29 | 29 |
n,m,l = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(n)]
b = [list(map(int,input().split())) for _ in range(m)]
c = [[0 for _ in range(l)] for __ in range(n)]
for i in range(n):
for j in range(l):
c[i][j] = sum([a[i][k]*b[k][j] for k in range(m)])
for ci in c:
print(*ci)
| n,m,l = map(int,raw_input().split())
a = [map(int,raw_input().split()) for _ in range(n)]
b = [map(int,raw_input().split()) for _ in range(m)]
c = [[0 for i in range(l)] for j in range(n)]
for i in range(n):
for j in range(l):
s = 0
for k in range(m):
s += a[i][k] * b[k][j]
c[i][j] = s
for i in range(n):
print ' '.join(map(str,c[i])) | 1 | 1,404,719,229,882 | null | 60 | 60 |
#
# 9d
#
def main():
s = input()
q = int(input())
for i in range(q):
l = list(input().split())
a = int(l[1])
b = int(l[2])
if l[0] == "print":
print(s[a:b+1])
elif l[0] == "reverse":
s = s[0:a] + s[a:b+1:][::-1] + s[b+1:]
elif l[0] == "replace":
s = s[0:a] + l[3] + s[b+1:]
else:
pass
if __name__ == '__main__':
main()
| def main():
n = int(input())
ans = 0
for a in range(1, n):
for b in range(1, n):
c = n - a * b
if c <= 0:
break
ans += 1
return ans
if __name__ == '__main__':
print(main())
| 0 | null | 2,355,168,833,600 | 68 | 73 |
def main():
import collections
N, P = map(int, input().split())
S = input()[::-1]
ans = 0
if P == 2 or P == 5:
for i, s in enumerate(S):
if int(s) % P == 0:
ans += N - i
else:
mod = [0] * P
mod[0] = 1
current = 0
X = 1
for s in S:
current = (current + int(s) * X) % P
ans += mod[current]
mod[current] += 1
X = X * 10 % P
print(ans)
if __name__ == '__main__':
main() | #!/usr/bin/env python3
import numpy as np
from collections import Counter
YEAR = 2019
def solve(S: str):
# S の各桁を modYear 計に修正する
mod_year = np.arange(1, 10)
mod_s = []
for Si in map(int, reversed(S)):
mod_s.append(mod_year[Si - 1])
mod_year = (mod_year * 10) % YEAR
# print(mod_s)
# mod_s を累積和にする
cum_sum = 0
cum_sums = [cum_sum]
for x in mod_s:
cum_sum = (cum_sum + x) % YEAR
cum_sums.append(cum_sum)
# 場合分けの数を足し合わせる
answer = 0
for _, num in Counter(cum_sums).items():
answer += (num * (num - 1)) // 2 # 1 の時0なので場合分けはいらない
return answer
def main():
S = input().strip()
answer = solve(S)
print(answer)
if __name__ == "__main__":
main()
| 0 | null | 44,486,066,156,742 | 205 | 166 |
x, y, z = map(int, input().split())
answerList = [z, x, y]
for i in range(len(answerList)):
print(answerList[i], end=' ') | n = list(map(int,input().split()))
m = []
for i in range(2):
m.append(n[0])
n.pop(0)
n.append(m[0])
n.append(m[1])
print(*n) | 1 | 38,068,864,966,200 | null | 178 | 178 |
n, x = map(int, input().split())
if x <= n*500:
print("Yes")
else:
print("No") | # -*- Coding: utf-8 -*-
nums = int(input())
a = [int(input()) for i in range(nums)]
minv = a[0]
maxv = -2000000000
for i in range(1, nums):
maxv = max(maxv, a[i] - minv)
minv = min(minv, a[i])
print(maxv)
| 0 | null | 48,894,757,405,760 | 244 | 13 |
A, B, K = map(int, input().split())
print(max(0, A-K), end=" ")
K = max(0, K-A)
print(max(0, B-K))
| n=int(input())
a=[int(i) for i in input().split()]
a.sort()
prod=1
for i in a:
prod*=i
if prod>10**18:
break
if prod>10**18:
print(-1)
else:
print(prod)
| 0 | null | 60,085,072,628,218 | 249 | 134 |
# ========== //\\ //|| ||====//||
# || // \\ || || // ||
# || //====\\ || || // ||
# || // \\ || || // ||
# ========== // \\ ======== ||//====||
# code
# 1 -> 1,2 2,1 3,
# 2 -> 1,1
def solve():
n = int(input())
cnt = 0
for i in range(1, n + 1):
k = n // i
if n % i:
cnt += k
else:
cnt += max(0, k - 1)
print(cnt)
return
def main():
t = 1
# t = int(input())
for _ in range(t):
solve()
if __name__ == "__main__":
main() | a, b, k = map(int, input().split())
print(a - min(a, k), b - min(b, k - min(a, k))) | 0 | null | 53,314,224,715,190 | 73 | 249 |
numbers = input().split(" ")
num = numbers.index("0")
print(num + 1) | x = list(map(int, input().split()))
ans = 0
for i in range(5):
if x[i] == 0:
ans = i+1
print(ans) | 1 | 13,459,754,884,480 | null | 126 | 126 |
n,k = map(int,input().split())
sunuke = []
for _ in range(k):
d = input()
tmp = [int(s) for s in input().split()]
for i in range(len(tmp)):
sunuke.append(tmp[i])
print(n - len(set(sunuke))) | import sys
def main():
input = sys.stdin.buffer.readline
n = int(input())
ab = [map(int, input().split()) for _ in range(n)]
a, b = [list(i) for i in zip(*ab)]
new_a = sorted(a)
new_b = sorted(b)
if n % 2 == 1:
min_m = new_a[(n + 1) // 2 - 1]
max_m = new_b[(n + 1) // 2 - 1]
print((max_m - min_m) + 1)
else:
min_m = (new_a[n // 2 - 1] + new_a[n // 2])
max_m = (new_b[n // 2 - 1] + new_b[n // 2])
print((max_m - min_m) + 1)
if __name__ == '__main__':
main()
| 0 | null | 20,937,961,401,568 | 154 | 137 |
N1=int(input())
array1=input().split()
N2=int(input())
array2=input().split()
c=0
for n2 in range(N2):
if array2[n2] in array1:
c+=1
print(c)
| n = input()
S = raw_input().split()
q = input()
T = raw_input().split()
s = 0
for i in T:
if i in S:
s+=1
print s | 1 | 67,638,924,660 | null | 22 | 22 |
n, m = map(int, input().split())
a =[[0 for i in range(m)]for j in range(n)]
for i in range(n):
a[i] = list(map(int, input().split()))
b = [0 for j in range(m)]
for j in range(m):
b[j] = int(input())
c = [0 for i in range(n)]
for i in range(n):
for j in range(m):
c[i] += a[i][j] * b[j]
print(c[i]) | n,m=map(int, input().split())
a=[list(map(int, input().split())) for i in range(n)]
b=[int(input()) for j in range(m)]
for i in range(n):
sum=0
for j in range(m):
sum+=a[i][j]*b[j]
print(sum)
| 1 | 1,158,538,897,184 | null | 56 | 56 |
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math
import sys
# import numpy as np
ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
n = int(input())
s = [0] * n
t = [0] * n
for i in range(n):
s[i], t[i] = input().split()
t[i] = int(t[i])
x = input()
idx = s.index(x)
ans = 0
for i in range(idx+1, n):
ans += t[i]
print(ans)
if __name__ == '__main__':
main() | n=int(input())
s=[]
t=[]
flag=0
ans=0
for i in range(n):
ss,tt=map(str,input().split())
s.append(ss)
t.append(int(tt))
x=input()
for i in range(n):
if s[i]==x:
flag=1
continue
if flag == 1:
ans+=t[i]
print(ans) | 1 | 97,418,218,132,968 | null | 243 | 243 |
x,y=map(int,input().split())
t=2*y-4*x
c=y-t
if t<0 or c<0 or t%4!=0 or c%2!=0:
print("No")
else:
print("Yes")
| 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 | 8,280,799,854,368 | 127 | 74 |
n = int(input())
print(int(sum([k*(n//k+1)*(n//k)/2 for k in range(1,n+1)]))) | from typing import List
# 人iの証言を人jに対する証言をリストで格納。1:正直者, 0:不親切, -1:言及なし
def io_info() -> List[List[int]]:
N = int(input())
res = [[-1] * N for _ in range(N)]
for n in range(N):
a = int(input())
for _ in range(a):
x, y = map(int, input().split())
res[n][x-1] = y
return res
def main():
infos = io_info()
n = len(infos)
ans = 0
for i in range(1 << n):
d = [0] * n
for j in range(n):
# iのj+1ビット目が1かどうか,d[j]が正直なら1を割り当てる
if (i >> j) & 1:
d[j] = 1
ok = True
for j in range(n):
if d[j]:
for k in range(n):
if infos[j][k] == -1: continue
if infos[j][k] != d[k]: ok = False
if ok: ans = max(ans, bin(i).count("1"))
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 66,653,244,847,490 | 118 | 262 |
K = int(input())
seven = [0]*K
seven[0] = 7%K
for i in range(1,K):
seven[i] = (10*seven[i-1]+7)%K
for i in range(K):
if seven[i] == 0:
print(i+1)
exit()
print(-1) | K = int(input())
s = 7
flg = False
cnt = 0
for i in range(K+1):
cnt += 1
if s % K == 0:
flg = True
break
s *= 10
s %= K
s += 7
if flg:
print(cnt)
else:
print(-1)
| 1 | 6,153,611,619,098 | null | 97 | 97 |
x,k,d=map(int,input().split())
x=abs(x)
if k>=round(x/d):
if (k-round(x/d))%2==0:
print(abs(x-d*round(x/d)))
else:
print(d-abs(x-d*round(x/d)))
else:
print(x-d*k) | r, c, k = map(int, input().split())
rcv = [list(map(int, input().split())) for i in range(k)]
area = [[0] * (c+1) for i in range(r+1)]
for a, b, v in rcv:
area[a-1][b-1] = v
# dp[i][j][k]: その行でiまで拾っており、
# j行k列目に到達時点の最大スコア
dp = [[[-1] * (c+1) for i in range(r+1)] for j in range(4)]
dp[0][0][0] = 0
for rr in range(r+1):
for cc in range(c+1):
for i in range(4):
# 取って右
if i+1<4 and cc<c and area[rr][cc]>0:
dp[i+1][rr][cc+1] = max(dp[i+1][rr][cc+1],
dp[i][rr][cc]+area[rr][cc])
# 取って下
if i+1<4 and rr<r and area[rr][cc]>0:
dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
dp[i][rr][cc]+area[rr][cc])
# 取らずに右
if cc<c:
dp[i][rr][cc+1] = max(dp[i][rr][cc+1],
dp[i][rr][cc])
# 取らずに下
if rr<r:
dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
dp[i][rr][cc])
# ans: r行c列目の最大値(iは問わず)
ans = max([dp[i][r][c] for i in range(4)])
print(ans)
| 0 | null | 5,431,940,224,220 | 92 | 94 |
x1,y1,x2,y2=map(float, input().split())
if x1<x2:
x1,x2=x2,x1
if y1<y2:
y1,y2=y2,y1
n=((x1-x2)**2+(y1-y2)**2)**(1/2)
print(n)
| import math
str = input().split(' ')
x1 = float(str[0])
x2 = float(str[1])
y1 = float(str[2])
y2 = float(str[3])
result = (x1-y1)*(x1-y1) + (x2-y2)*(x2-y2)
result = math.sqrt(result) if result != 0 else 0
print('%.6f'%result) | 1 | 162,270,573,660 | null | 29 | 29 |
def solve(string):
return str(max(map(len, string.split("S"))))
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
| 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 | 2,632,698,004,680 | 90 | 41 |
n, m = map(int, input().split())
if n%2 == 1:
a = 1
b = n+1
ans = []
for i in range(m):
a += 1
b -= 1
ans.append((a, b))
else:
a = 1
b = n+1
S = set()
ans = []
for i in range(m):
a += 1
b -= 1
r = min(b-a, n-(b-a))
if r in S or r == n//2:
b -= 1
r = min(b-a, n-(b-a))
ans.append((a, b))
S.add(r)
for i in range(m):
print(*ans[i])
| import itertools
n = int(input())
l = list(map(int, input().split( )))
pettern = 0
for v in itertools.combinations(l, 3):
if v[0] != v[1] and v[1] != v[2] and v[2] != v[0]:
if v[0]+v[1] > v[2] and v[1]+v[2] > v[0] and v[2]+v[0] > v[1]:
pettern += 1
print(pettern)
| 0 | null | 16,983,925,825,382 | 162 | 91 |
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
s=input()
ans=n
for i in range(1,n):
if s[i]==s[i-1]:
ans-=1
print(ans) | s = input()
x = 7
if s == "SUN":
pass
elif s == "SAT":
x = x - 6
elif s == "FRI":
x = x - 5
elif s == "THU":
x = x - 4
elif s == "WED":
x = x - 3
elif s == "TUE":
x = x - 2
elif s == "MON":
x = x - 1
print(x)
| 0 | null | 151,933,175,769,822 | 293 | 270 |
def insertionSort(A, n, g):
global cnt
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt+=1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
g = 1
G = [1]
m = 1
for i in range(1,101):
tmp = G[i-1]+(3)**i
if tmp <= n:
m = i+1
G.append(tmp)
g += 1
else:
break
G.reverse()
print(m) # 1行目
print(" ".join(list(map(str,G)))) # 2行目
for i in range(0,m):
insertionSort(A, n, G[i])
print(cnt) # 3行目
for i in range(0,len(A)):
print(A[i]) # 4行目以降
cnt = 0
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A,n)
| n,k = map(int,input().split())
li = list(map(int,input().split()))
if n==k:
ans = 0
for i in li:
ans += i*0.5+0.5
print(ans)
exit()
K = sum(li[:k])
ans = K
t = 0
for i in range(n-k):
K += li[i+k] - li[i]
if K > ans:
ans = K
t = i
ans = 0
for i in range(k):
ans += li[t+i+1]*0.5 + 0.5
print(ans) | 0 | null | 37,237,022,524,388 | 17 | 223 |
X,Y=map(int,input().split())
if Y%2 == 0:
if X*2 <= Y and Y <= X*4:
print("Yes")
else:
print("No")
else:
print("No") | X,Y=map(int,input().split())
print("Yes" if Y%2==0 and 2*X<=Y<=4*X else "No") | 1 | 13,830,946,176,608 | null | 127 | 127 |
n = int(input())
s = input()
if n%2 != 0 or s[:n//2] != s[n//2:]:
print("No")
else:
print("Yes") | # 駅1、2、3
# 管理状況はAAB,ABA、BBA,BBBなど、長さ3の文字列で表される
# AとBの駅の間にはバスを運行することにした
# バスが運行することになる組み合わせが存在するかどうか判定し、yes,noで出力
s = input('')
if s == 'AAA' or s == 'BBB':
print('No')
else:
print('Yes') | 0 | null | 100,782,144,787,360 | 279 | 201 |
[n,k] = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
for i in range(k,n):
if A[i-k]<A[i]:
print('Yes')
else:
print('No')
| def main():
N, K = (int(x) for x in input().split())
scores = [int(x) for x in input().split()]
first, last = 0, K-1
while last < N-1:
last += 1
if scores[first] < scores[last]: print('Yes')
else: print('No')
first += 1
if __name__ == '__main__':
main() | 1 | 7,171,592,014,560 | null | 102 | 102 |
N = int(input())
def divisor(n):
if n==1:return []
ret = [n]
for i in range(2,n+1):
if i*i==n:
ret.append(i)
elif i*i > n:
break
elif n%i==0:
ret.append(i)
ret.append(n//i)
ret.sort()
return ret
ans = len(divisor(N-1))
for k in divisor(N):
M = N
while M%k==0:
M//=k
if M%k==1:
ans += 1
print(ans) | import sys
def input():
return sys.stdin.readline()[:-1]
def main():
N = int(input())
P = []
for k in range(1,1+int((N-1)**(1/2))):
if (N-1)%k == 0:
P.append((N-1)//k)
P.append(k)
P = set(P)
ans = len(P)
for k in range(2,1+int(N**(1/2))):
if N%k == 0:
t = N//k
while t%k == 0:
t //= k
if t%k == 1:
ans += 1
print(ans)
if __name__ == '__main__':
main()
| 1 | 41,523,611,843,508 | null | 183 | 183 |
N, M = map(int, input().split())
s = []
c = []
for i in range(M):
si, ci = map(int, input().split())
s.append(si-1)
c.append(ci)
answer = [-1] * N
valid = True
for i in range(M):
if answer[s[i]] != -1 and answer[s[i]] != c[i]:
valid = False
break
answer[s[i]] = c[i]
if answer[0] == 0 and N != 1:
valid = False
if valid:
if N == 1 and answer[0] == -1:
answer[0] = 0
elif answer[0] == -1:
answer[0] = 1
for i in range(N):
if answer[i] == -1:
answer[i] = 0
print(int(''.join(map(lambda x: str(x), answer))))
else:
print(-1) | n,m=map(int,input().split())
d={}
ind=[0]*n
for i in range(n):
d[i+1]='*'
for j in range(m):
s,c=map(int,input().split())
if ind[s-1]==0:
d[s]=c
ind[s-1]=1
else:
if d[s]!=c:
print(-1)
exit(0)
ans=''
if n>=2:
if d[1]==0:
print(-1)
exit(0)
for k in range(n):
if k==0:
if n>=2:
if d[k+1]=='*':
ans+='1'
else:
ans+=str(d[k+1])
else:
if d[k+1]=='*':
ans+='0'
else:
ans+=str(d[k+1])
else:
if d[k+1]=='*':
ans+='0'
else:
ans+=str(d[k+1])
print(ans) | 1 | 60,582,185,648,560 | null | 208 | 208 |
H, W = input().split(' ')
H = int(H)
W = int(W)
if H==1 or W ==1:
print(1)
elif (H%2)==0 and (W%2)==0:
print(int((H/2) * W))
elif (H%2)==1 and (W%2)==0:
print(int((W/2) * H))
elif (H%2)==0 and (W%2)==1:
print(int((H/2) * W))
elif (H%2)==1 and (W%2)==1:
print(int((H*W//2)+1)) | import math
a,b,c = [float(s) for s in input().split()]
r = c * math.pi / 180
h = math.sin(r) * b
s = a * h / 2
x1 = a
y1 = 0
if c == 90:
x2 = 0
else:
x2 = math.cos(r) * b
y2 = h
d = math.sqrt((math.fabs(x1 - x2) ** 2) + (math.fabs(y1 - y2) ** 2))
l = a + b + d
print(s)
print(l)
print(h) | 0 | null | 25,520,818,027,702 | 196 | 30 |
def solve():
N = int(input())
A = list(map(int, input().split()))
total = 0
for a in A:
total ^= a
ans = []
for a in A:
ans.append(total^a)
return ans
print(*solve())
| N = int(input())
A = list(map(int,input().split()))
B = [0 for _ in range(N//2)]
for i in range(0,N,2):
B[i//2] = A[i]^A[i+1]
tot = 0
for i in range(N//2):
tot = tot^B[i]
X = [0 for _ in range(N)]
for i in range(N//2):
y = tot^B[i]
X[2*i]=A[2*i+1]^y
X[2*i+1]=A[2*i]^y
print(*X) | 1 | 12,602,814,906,712 | null | 123 | 123 |
palavra= input()
tam= len(palavra)
if palavra[tam-1]=='s':
print(palavra+'es')
else:
print(palavra+'s') | if __name__ == '__main__':
# ??????????????\???
word = input()
texts = []
while True:
raw_input = input()
if raw_input == 'END_OF_TEXT':
break
texts.append(raw_input.lower())
# ?????????????¨??????°???????????????
match_count = 0
for line in texts:
for w in line.split(' '):
if w == word.lower():
match_count += 1
# ???????????????
print(match_count) | 0 | null | 2,112,358,445,272 | 71 | 65 |
class Dice():
def __init__(self, a, b, c, d, e, f):
"""面の数字とindexを一致させるために0を挿入"""
self.s = [0, a, b, c, d, e, f]
def rotate(self, dir):
if dir == "N":
self.s[0] = self.s[1] #s[0]に一時的にs[1]を保持
self.s[1] = self.s[2]
self.s[2] = self.s[6]
self.s[6] = self.s[5]
self.s[5] = self.s[0]
return
elif dir == "W":
self.s[0] = self.s[1]
self.s[1] = self.s[3]
self.s[3] = self.s[6]
self.s[6] = self.s[4]
self.s[4] = self.s[0]
return
elif dir == "S":
self.s[0] = self.s[1]
self.s[1] = self.s[5]
self.s[5] = self.s[6]
self.s[6] = self.s[2]
self.s[2] = self.s[0]
return
elif dir == "E":
self.s[0] = self.s[1]
self.s[1] = self.s[4]
self.s[4] = self.s[6]
self.s[6] = self.s[3]
self.s[3] = self.s[0]
return
elif dir == "R":
self.s[0] = self.s[2]
self.s[2] = self.s[3]
self.s[3] = self.s[5]
self.s[5] = self.s[4]
self.s[4] = self.s[0]
return
elif dir == "L":
self.s[0] = self.s[2]
self.s[2] = self.s[4]
self.s[4] = self.s[5]
self.s[5] = self.s[3]
self.s[3] = self.s[0]
return
else:
return
dice = Dice(*list(map(int, input().split())))
for _ in range(int(input())):
t, s = map(int, input().split())
while dice.s[1] != t:
dice.rotate("S")
if dice.s[1] != t:
dice.rotate("E")
while dice.s[2] != s:
dice.rotate("R")
print(dice.s[3])
| inp = [i for i in input().split()]
n = int(input())
array = [[i for i in input().split()] for i in range(n)]
for i2 in range(n):
fuck =""
for i in range(1,33):
if (i<=20 and i%5==0) or i==22 or i==27 or i==28:
s = "N"
else:
s = "E"
if s == "E":
a = []
a.append(inp[3])
a.append(inp[1])
a.append(inp[0])
a.append(inp[5])
a.append(inp[4])
a.append(inp[2])
inp = a
if inp[0] == array[i2][0] and inp[1] == array[i2][1] and inp[2] != fuck:
print(inp[2])
fuck = inp[2]
elif s == "N":
a = []
a.append(inp[1])
a.append(inp[5])
a.append(inp[2])
a.append(inp[3])
a.append(inp[0])
a.append(inp[4])
inp = a
if inp[0] == array[i2][0] and inp[1] == array[i2][1] and inp[2] != fuck:
print(inp[2])
fuck = inp[2] | 1 | 251,009,989,330 | null | 34 | 34 |
a, b, c = (int(x) for x in input().split())
tmp = 0
for i in range(2):
if a > b:
tmp = a
a = b
b = tmp
if b > c:
tmp = b
b = c
c = tmp
if a > c:
tmp = a
a = c
c = tmp
print(a, b, c)
| xs=map(int,input().split())
print(' '.join(map(str, sorted(xs)))) | 1 | 413,698,079,620 | null | 40 | 40 |
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
dAl = defaultdict(int)
dAr = defaultdict(int)
for i in range(N):
L = (i + 1) + A[i]
R = (i + 1) - A[i]
dAl[L] += 1
dAr[R] += 1
# dictの中を見る
ans = 0
for k, v in dAl.items():
ans += v * dAr[k]
print(ans) | import sys
input=sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
from collections import defaultdict
def main():
n=II()
A=LI()
X=defaultdict(int)
Y=defaultdict(int)
for i,v in enumerate(A):
X[i+v]+=1
Y[i-v]+=1
ans=0
for k,v in X.items():
ans+=v*Y[k]
print(ans)
if __name__=="__main__":
main()
| 1 | 25,952,436,828,990 | null | 157 | 157 |
A, B = map(str, input().split())
A=int(A)
B=int(B[0]+B[2]+B[3])
print(A*B//100) | n = int(input())
w = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
s = {}
s["a"] = 0
ans = [s]
for i in range(2, n+1):
new_s = {}
for t in s.items():
for j in range(1, i):
if t[0][-1] == w[j-1]:
for k in range(t[1] + 2):
new_s[t[0] + w[k]] = max(t[1], k)
ans.append(new_s)
s = new_s
answer = sorted(ans[n-1].keys())
for x in answer:
print(x)
| 0 | null | 34,492,946,578,180 | 135 | 198 |
def resolve():
l=float(input())
print(l**3/27)
resolve() | N = int(input())
A = list(map(int, input().split()))
i = 0
for i in range(len(A)):
if (A[i] % 2 == 0):
if A[i] % 3 != 0 and A[i] % 5 != 0:
print('DENIED')
exit()
else:
continue
else:
continue
print('APPROVED') | 0 | null | 58,013,229,986,532 | 191 | 217 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
answer = N - sum(A)
if N >= sum(A):
print(answer)
else:
print('-1') | n, m = map(int, input().split())
a = list(map(int, input().split()))
for time in a:
n -= time
if n<0:
n = -1
break
print(n) | 1 | 32,029,374,299,808 | null | 168 | 168 |
def main():
l, r, d = map(int, input().split())
res = r // d - (l-1) // d
print(res)
if __name__ == '__main__':
main()
| S = int(input())
s = (S % 60)
m = (S % 3600 // 60)
h = (S // 3600)
print(h, ':', m, ':', s, sep='')
| 0 | null | 3,913,011,669,000 | 104 | 37 |
n,m,k = map(int, input().split())
g = [[] for i in range(n+1)]
f = [0]*(n+1)
b = []
for i in range(m):
u, v = map(int, input().split())
g[u].append(v)
g[v].append(u)
f[u] += 1
f[v] += 1
for i in range(k):
b.append(map(int, input().split()))
count = 0
renketu_list = [-1]*(n+1)
renketu_size = [0]
stack = []
for i in range(1, n+1):
if renketu_list[i] == -1:
count += 1
renketu_list[i] = count
renketu_size.append(1)
while len(g[i]) > 0:
stack.append(g[i].pop())
while len(stack) > 0:
v=stack.pop()
if renketu_list[v] == -1:
renketu_list[v] = count
renketu_size[count] += 1
while len(g[v])>0:
stack.append(g[v].pop())
s = [0] * (n+1)
for i in range(1, n+1):
s[i] += renketu_size[renketu_list[i]] - f[i] - 1
for i in range(k):
u, v = b[i]
if renketu_list[u] == renketu_list[v]:
s[u] -= 1
s[v] -= 1
print(" ".join(list(map(str, s[1:]))))
| #bubble
N=int(input())
A=[int(i) for i in input().split()]
fl=1
C=0
while fl==1:
fl=0
for j in range(N-1):
if A[N-1-j]<A[N-2-j]:
t=A[N-1-j]
A[N-1-j]=A[N-2-j]
A[N-2-j]=t
C+=1
fl=1
for j in range(N):
A[j]=str(A[j])
print(" ".join(A))
print(C) | 0 | null | 31,041,185,978,080 | 209 | 14 |
a1=input()
a2=[i for i in a1.split()]
a3,a4=[a2[i] for i in (0,1)]
A,B=int(a3),int(a4)
print(max(0,A-2*B)) | import sys
n,m,x=map(int,input().split())
ac=[[0]*(m+1) for i in range(n)]
a=[[0]*m for i in range(0,n)]
c=[0 for i in range(n)]
for i in range(n):
ac[i]=list(map(int,input().split()))
c[i]=ac[i][0]
a[i]=ac[i][1:m+1]#sliceは上限+1を:の右に代入
cheap=[]
kaukadouka=[0 for i in range(n)]
def kau(i):
global a,x,kaukadouka,cheap,c
rikaido=[0 for i in range(m)]#初期化
for j in range(i+1,n):
kaukadouka[j]=0
if i>=n:
sys.exit()
kaukadouka[i]=1
for j in range(n):
for k in range(m):
rikaido[k]+=kaukadouka[j]*a[j][k]
value=0
if min(rikaido)>=x:
for j in range(n):
value+=c[j]*kaukadouka[j]
cheap.append(value)
if i<n-1:
kau(i+1)
kawanai(i+1)
def kawanai(i):
global kaukadouka
for j in range(i,n):
kaukadouka[j]=0
if i>=n:
sys.exit()
#print('i=',i,'のとき買わないで')
#print('->',kaukadouka)
if i<n-1:
kau(i+1)
kawanai(i+1)
kau(0)
kawanai(0)
if len(cheap)>0:
#print(cheap)
print(min(cheap))
else:
print('-1') | 0 | null | 94,631,675,182,890 | 291 | 149 |
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(H, W, K, Si):
Si = [[int(i) for i in S] for S in Si]
ans = H + W
for i in range(2 ** (H - 1)):
h_border = bin(i).count('1')
w_border = 0
white_counts = [0] * (h_border + 1)
choco_w = 0
for w in range(W):
choco_w += 1
wc_num = 0
tmp_count = [0] * (h_border + 1)
for h in range(H):
white_counts[wc_num] += Si[h][w]
tmp_count[wc_num] += Si[h][w]
if i >> h & 1:
wc_num += 1
if max(white_counts) > K:
if choco_w == 1:
break # 1列の時点で > K の場合は条件を達成できない
w_border += 1
white_counts = tmp_count
choco_w = 1
else:
ans = min(ans, h_border + w_border)
print(ans)
if __name__ == '__main__':
H, W, K = map(int, input().split())
Si = [input() for _ in range(H)]
solve(H, W, K, Si)
# # test
# from random import randint
# from func import random_str
#
# H, W, K = 10, 1000, randint(1, 100)
# Si = [random_str(W, '01') for _ in range(H)]
# print(H, W, K)
# for S in Si:
# print(S)
# solve(H, W, K, Si)
|
def main():
n, m, x = map(int, input().split(" "))
ca =[]
a = []
c = []
INF = 1e7
ans = INF
for i in range(n):
ca.append(list(map(int, input().split(" "))))
for i in range(n):
c.append(ca[i][0])
a.append(ca[i][1:])
for i in range(1<<n):
a_sum = [0]*m
c_sum = 0
for j in range(n):
if i >> j & 1 == 1:
for k in range(m):
a_sum[k] += a[j][k]
c_sum += c[j]
if min(a_sum) >= x and c_sum < ans:
ans = c_sum
if ans == INF:
print(-1)
else:
print(ans)
if __name__ == "__main__":
main() | 0 | null | 35,594,583,993,980 | 193 | 149 |
from sys import stdin
for x in sorted([int(l) for l in stdin],reverse=True)[0:3]:
print(x) | height = [int(input()) for i in range(10)]
sort = sorted(height, reverse=True)
for i in range(3):
print(sort[i]) | 1 | 34,786,078 | null | 2 | 2 |
import heapq
N, D, A = map(int, input().split(" "))
proc_que = []
for _ in range(N):
x, h = map(int, input().split(" "))
heapq.heappush(proc_que, (x, h))
damaged = 0
ans = 0
while len(proc_que) > 0:
x, h = heapq.heappop(proc_que)
if h > 0:
# monster
num_bomb_use = max(0, (h - damaged + A - 1) // A)
ans += num_bomb_use
damaged += num_bomb_use * A
heapq.heappush(proc_que, (x + 2 * D + 1, -num_bomb_use * A))
else:
# damaged end
damaged += h
print(ans) | import sys
def input():
return sys.stdin.readline().strip()
n, d, a = map(int, input().split())
x = []
h = {} # x:h
for _ in range(n):
i, j = map(int, input().split())
x.append(i)
h[i] = j
x.sort()
x.append(x[-1] + 2*d + 1)
# attackで累積和を用いる
ans = 0
attack = [0 for _ in range(n+1)]
for i in range(n):
attack[i] += attack[i-1]
if attack[i] >= h[x[i]]:
continue
if (h[x[i]] - attack[i]) % a == 0:
j = (h[x[i]] - attack[i]) // a
else:
j = (h[x[i]] - attack[i]) // a + 1
attack[i] += a * j
ans += j
# 二分探索で、x[y] > x[i] + 2*d、を満たす最小のyを求める
# start <= y <= stop
start = i + 1
stop = n
k = stop - start + 1
while k > 1:
if x[start + k//2 - 1] <= x[i] + 2*d:
start += k//2
else:
stop = start + k//2 - 1
k = stop - start + 1
attack[start] -= a * j
print(ans) | 1 | 82,377,804,549,830 | null | 230 | 230 |
from sys import stdin
A, B, C = [int(_) for _ in stdin.readline().rstrip().split()]
K = int(stdin.readline().rstrip())
for i in range(K):
if not B > A:
B *= 2
elif not C > B:
C *= 2
if A < B < C:
print("Yes")
else:
print("No") | import itertools
A,B,C = list(map(int, input().split()))
K = int(input())
ans = False
for p in itertools.product(['a','b','c'], repeat=K):
A0,B0,C0 = A,B,C
for e in p:
if e == 'a':
A0 = 2*A0
elif e == 'b':
B0 = 2*B0
else:
C0 = 2*C0
if A0 < B0 < C0 :
ans = True
break
print('Yes' if ans else 'No')
| 1 | 6,864,719,063,012 | null | 101 | 101 |
import sys
d={}
for e in sys.stdin.readlines()[1:]:
c,g=e.split()
if'i'==c[0]:d[g]=0
else:print(['no','yes'][g in d])
| import sys
n = int(input())
A = [int(e)for e in sys.stdin]
cnt = 0
G = [int((2.5**i-1)/1.5)for i in range(15,0,-1)]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
for g in G:
insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print(*A,sep='\n')
| 0 | null | 51,818,203,400 | 23 | 17 |
import sys
a, b, c = map(int, sys.stdin.readline().split())
if(a < b < c):
print("Yes")
else:
print("No") | a, b, c = map(int, input().split())
if(a < b & b < c) :
print("Yes")
else :
print("No")
| 1 | 382,107,484,708 | null | 39 | 39 |
S = input()
if "RRR" in S :
print("3")
elif "RR" in S :
print("2")
elif "R" in S :
print("1")
else :
print("0") | S = input()
a = "RRR"
b = "RR"
c = "R"
if a == S:
print(3)
elif b in S:
print(2)
elif c in S:
print(1)
else:
print(0) | 1 | 4,871,816,889,030 | null | 90 | 90 |
def main():
n, k = list(map(int, input().split()))
mod = 1000000007
N = list(range(n + 1))
mn = [0] * (n + 1)
mx = [0] * (n + 1)
mx[0] = n
for i in range(1, n + 1):
mn[i] = mn[i - 1] + N[i]
mx[i] = mx[i - 1] + N[n - i]
ans = 0
for a, b in zip(mn[k - 1:], mx[k - 1:]):
ans += b - a + 1
ans %= mod
print(ans)
if __name__ == '__main__':
main()
| #abc149-d
n,k=map(int,input().split())
s,p,r=map(int,input().split())
f={'s':s,'p':p,'r':r}
t=str(input())
ans=0
for i in range(k):
a=i+k
last=t[i]
ans+=f[last]
while a<n-k:
if t[a]==last:
if t[a+k]==last:
if last=='s':
last='r'
else:
last='s'
else:
if last=='s':
if t[a+k]=='r':
last='p'
else:
last='r'
elif last=='r':
if t[a+k]=='s':
last='p'
else:
last='s'
else:
if t[a+k]=='r':
last='s'
else:
last='r'
else:
last=t[a]
ans+=f[last]
a+=k
if a<n:
if t[a]!=last:
ans+=f[t[a]]
print(ans) | 0 | null | 70,114,180,830,692 | 170 | 251 |
s = input()
for x in s:
print('x', end='')
print() | import math
a,b,x = map(int,input().split())
if x <= a*a*b/2:
print(math.atan((a*b*b/2/x))*180/math.pi)
else:
print(math.atan((a*a*b-x)/(a**3)*2)*180/math.pi) | 0 | null | 117,871,425,413,820 | 221 | 289 |
import math
x1,y1,x2,y2 = (float(x) for x in input().split())
print(round(math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2), 8))
| x1, y1, x2, y2 = map(float, input().split())
print('%.8f' % (((x2 - x1)**2 + (y2 - y1)**2))**0.5)
| 1 | 154,787,855,650 | null | 29 | 29 |
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
s = input()
n = len(s)
a = [None]*n
c = 0
v = 1
for i in range(n-1, -1, -1):
c = (c + v*int(s[i])) % 2019
a[i] = c
v *= 10
v %= 2019
from collections import Counter
cc = Counter(a)
ans = 0
for k,v in cc.items():
ans += v*(v-1)//2
ans += cc[0]
print(ans) | from collections import Counter
MOD = 2019
S = input()[::-1]
X = [0]
for i in range(len(S)):
X.append((X[-1]+int(S[i])*pow(10, i, MOD))%MOD)
C = Counter(X)
ans = 0
for v in C.values():
ans += v*(v-1)//2
print(ans) | 1 | 30,975,220,524,772 | null | 166 | 166 |
n = int(input())
dictionary = {}
for i in range(n):
a = input().split()
if a[0] == "insert":
dictionary[a[1]] = 0
if a[0] == "find":
if a[1] in dictionary:
print("yes")
else:
print("no") | # coding: utf-8
# Here your code !
N=int(input())
dict={}
for i in range(N):
a,b=input().split()
if a=="insert":
dict[b]=i
else:
if b in dict:
print("yes")
else:
print("no") | 1 | 78,970,591,348 | null | 23 | 23 |
n,r=map(int,input().split())
res = r
if n < 10:
res += 100 * (10 - n)
print(res) | N,R = list(map(int,input().split()))
ans=R
if N < 10:
ans += 100*(10-N)
print(ans) | 1 | 63,499,391,854,170 | null | 211 | 211 |
import fractions
N = int(input())
A = list(map(int,input().split()))
MOD = 10** 9 + 7
lcm = 1
for a in A:
lcm = a // fractions.gcd(a,lcm) * lcm
print(sum(lcm//a for a in A)%MOD) | from collections import defaultdict as dict
n, p = map(int, input().split())
s = input()
a = []
for x in s:
a.append(int(x))
def solve():
l = [0]*p
ans = 0
for x in a:
l_ = [0] * p
for i in range(p):
l_[(i * 10 + x) % p] += l[i]
l, l_ = l_, l
l[x % p] += 1
ans += l[0]
print(ans)
if p <= 5:
solve()
exit()
x = 0
mem = dict(int)
mem[0] = 1
ans = 0
a.reverse()
d = 1
for y in a:
x += d*y
x %= p
d = (d * 10) % p
ans += mem[x]
mem[x] += 1
# print(mem)
print(ans) | 0 | null | 72,699,835,658,070 | 235 | 205 |
import math
N,M,X = map(int,input().split())
#a[i][0]:price of the i-th book
a = [[] for i in range(N)]
for i in range(N):
a[i] = list(map(int,input().split()))
def is_greater(b):
for i in b:
if i < X:
return False
return True
cost = math.inf
for i in range(2**N):
b = [0]*(M+1)
for j in range(N):
if ((i >> j)&1):
for k in range(M+1):
b[k] += a[j][k]
if b[0] < cost and is_greater(b[1:]):
cost = b[0]
if cost == math.inf:
print(-1)
else:
print(cost) | def generate_G(n):
h = 1
G = []
while h <= n:
G.append(h)
h = 3 * h + 1
G.reverse()
return G
def insertion_sort(A, n, g):
global count
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j + g] = A[j]
j -= g
count += 1
A[j + g] = v
def shell_sort(A, n):
G = generate_G(n)
print(len(G))
print(' '.join(map(str, G)))
for g in G:
insertion_sort(A, n, g)
def main():
global count
# input
n = int(input())
A = [int(input()) for _ in range(n)]
# sort
shell_sort(A, n)
# output
print(count)
for a in A:
print(a)
if __name__ == "__main__":
count = 0
main()
| 0 | null | 11,222,584,940,178 | 149 | 17 |
n, x, m = map(int, input().split())
mn = min(n, m)
S = set()
A = []
sum_9 = 0 # sum of pre + cycle
for _ in range(mn):
if x in S: break
S.add(x)
A.append(x)
sum_9 += x
x = x*x % m
if len(A) >= mn:
print(sum_9)
exit()
pre_len = A.index(x)
cyc_len = len(A) - pre_len
nxt_len = (n - pre_len) % cyc_len
cyc_num = (n - pre_len) // cyc_len
pre = sum(A[:pre_len])
cyc = sum_9 - pre
nxt = sum(A[pre_len: pre_len + nxt_len])
print(pre + cyc * cyc_num + nxt)
| N, K = map(int, input().split())
MOD = 998244353
move = []
for _ in range(K):
L, R = map(int, input().split())
move.append((L, R))
dp = [0]*(N+1)
dp[0] = 1
dp[1] = -1
for i in range(1, N+1):
dp[i] += dp[i-1]
for l, r in move:
if i - l >= 0:
dp[i] += dp[i-l]
if i - r - 1 >= 0:
dp[i] -= dp[i-r-1]
dp[i] %= MOD
print(dp[N-1]) | 0 | null | 2,732,412,048,522 | 75 | 74 |
import sys
for line in sys.stdin:
H, W = map(int, line.split())
if H == 0 and W == 0:
break
for _ in range(H):
print( '#' * W )
print("") | while True:
a=[int(x) for x in input().split()]
if a[0]==a[1]==0:
break
else:
for i in range(a[0]):
print("#"*a[1])
print("") | 1 | 783,052,758,672 | null | 49 | 49 |
#coding:utf-8
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
def search_banpei(array, target, cnt):
tmp = array[len(array)-1]
array[len(array)-1] = target
n = 0
while array[n] != target:
n += 1
array[len(array)-1] = tmp
if n < len(array) - 1 or target == tmp:
cnt += 1
return cnt
def linear_search():
cnt = 0
for t in T:
for s in S:
if t == s:
cnt += 1
break
def linear_banpei_search():
cnt = 0
for target in T:
cnt = search_banpei(S, target, cnt)
return cnt
cnt = linear_banpei_search()
print(cnt)
| def linearSearch(S,t):
L = S + [t]
i = 0
while L[i] != t: i += 1
if i == len(L)-1: return 0
else : return 1
if __name__=='__main__':
n=int(input())
S=list(map(int,input().split()))
q=int(input())
T=list(map(int,input().split()))
cnt = 0
for t in T: cnt += linearSearch(S,t)
print(cnt) | 1 | 63,981,780,842 | null | 22 | 22 |
1
2
3
from math import pi
r = float(input())
print('{:.6f} {:.6f}'.format(pi*r**2, 2*pi*r)) | import math
r = float(input())
print('%.5f' % (r * r * math.pi), '%.5f' % (2 * math.pi * r)) | 1 | 646,537,452,572 | null | 46 | 46 |
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
def main():
N = I()
s = S()
R = s.count("R")
G = s.count("G")
B = s.count("B")
dup = 0
for i in range(N):
for k in range(i+1, N):
if (i + k) % 2 == 0:
j = (i + k) // 2
if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
dup += 1
print(R * G * B - dup)
main()
| A,B,C,D,E=map(int,input().split())
if A==0 :
print(1)
elif B==0:
print(2)
elif C==0:
print(3)
elif D==0:
print(4)
else :
print(5)
| 0 | null | 24,802,074,201,030 | 175 | 126 |
n,k = map(int,input().split())
L = list(map(int,input().split()))
ok = 0
ng = 10**9
while abs(ok-ng) > 1:
mid = (ok+ng)//2
cur = 0
for i in range(n):
cur += L[i]//mid
if cur > k:
ok = mid
elif cur <= k:
ng = mid
K = [mid-1, mid, mid+1]
P = []
for i in range(3):
res = 0
if K[i] > 0:
for j in range(n):
res += (L[j]-1)//K[i]
if res <= k:
P.append(K[i])
print(min(P))
|
import numpy as np
def main():
k,x = map(int, input().split())
if k*500 >= x:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| 0 | null | 52,121,934,060,060 | 99 | 244 |
from sys import stdin
import numpy as np
def main():
#入力
readline=stdin.readline
n,k=map(int,readline().split())
A=np.array(list(map(int,readline().split())),dtype=np.int64)
A=np.sort(A)[::-1]
F=np.array(list(map(int,readline().split())),dtype=np.int64)
F=np.sort(F)
l=-1
r=10**12
while l<r-1:
x=(l+r)//2
A_after=np.minimum(x//F,A)
cnt=(A-A_after).sum()
if cnt<=k: r=x
else: l=x
print(r)
if __name__=="__main__":
main() | import sys
from functools import reduce
from math import gcd
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10 ** 9 + 7
N = int(readline())
A = list(map(int,readline().split()))
lcm = reduce(lambda x,y:x*y//gcd(x,y),A)
ans = 0
coef = sum(pow(x,mod-2,mod) for x in A)
ans = lcm * coef % mod
print(ans) | 0 | null | 126,079,154,217,338 | 290 | 235 |
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
if n: return [0 for _ in range(n)]
else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
if n: return ["" for _ in range(n)]
else: return sinput().split()
def adj(n): return [[] for _ in range(n)]
class unionfind():
def __init__(self, n):
self.n = n
# 中身が負の数なら根であり、数字の絶対値はグループ数
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0: return x
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x,y = self.find(x), self.find(y)
if x == y: return
if self.parents[x] > self.parents[y]: x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x): return -self.parents[self.find(x)]
def same(self, x, y): return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self): return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self): return len(self.roots())
n,m,k = imap()
uf = unionfind(n)
f,ng,anss = iarr(n),iarr(n),iarr(n)
for i in range(m):
a,b = imap()
a,b = a-1,b-1
f[a] += 1
f[b] += 1
uf.union(a,b)
for i in range(n):
anss[i] = uf.size(i) - f[i] - 1
for i in range(k):
c,d = imap()
c,d = c-1,d-1
if uf.same(c,d):
anss[c] -= 1
anss[d] -= 1
print(*anss)
| from queue import deque
n, m, k = map(int, input().split())
friends = [[] for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
friends[a].append(b)
friends[b].append(a)
checked = [False] * n
groups = []
for i in range(n):
if checked[i]:
continue
checked[i] = True
que = deque([i])
group = [i]
while que:
now = que.popleft()
friends_now = friends[now]
for friend in friends_now:
if checked[friend] == False:
checked[friend] = True
group.append(friend)
que.append(friend)
groups.append(group)
# print(groups)
D = dict()
for i in range(len(groups)):
for j in groups[i]:
D[j] = i
# print(D)
block = [0] * n
for _ in range(k):
c, d = map(int, input().split())
c -= 1
d -= 1
if D[c] == D[d]:
block[c] += 1
block[d] += 1
for i in range(n):
group_i = D[i]
print(len(groups[group_i]) - block[i] - len(friends[i]) - 1) | 1 | 61,812,023,766,272 | null | 209 | 209 |
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
def resolve():
import sys
input = sys.stdin.readline
n = int(input().rstrip())
s_list = [input().rstrip() for _ in range(n)]
from collections import Counter
c = Counter(s_list)
max_count = c.most_common()[0][1]
words = [word for word, count in c.most_common() if count == max_count]
words.sort()
print("\n".join(words))
if __name__ == "__main__":
resolve()
| n,m=[int(x) for x in input().split()]
A=[[0 for i in range(m)] for i in range(n)]
vector=[0 for i in range(m)]
result=[0 for i in range(n)]
for i in range(n):
A[i]=[int(x) for x in input().split()]
for i in range(m):
vector[i]=int(input())
for i in range(n):
for j in range(m):
result[i] += A[i][j]*vector[j]
for _ in result:
print(_) | 0 | null | 35,700,932,685,810 | 218 | 56 |
import sys
N,M,L=map(int, sys.stdin.readline().split())
d=[ [ float("inf") for j in range(N+1) ] for i in range(N+1) ]
for _ in range(M):
a,b,c=map(int, sys.stdin.readline().split())
d[a][b]=c
d[b][a]=c
d[a][a]=0
d[b][b]=0
for k in range(1,N+1):
for i in range(1,N+1):
for j in range(1,N+1):
d[i][j]=min(d[i][j], d[i][k]+d[k][j])
e=[ [ float("inf") for j in range(N+1) ] for i in range(N+1) ]
for i in range(1,N+1):
for j in range(i,N+1):
if i==j:
e[i][j]=0
e[j][i]=0
elif d[i][j]<=L:
e[i][j]=1
e[j][i]=1
for k in range(1,N+1):
for i in range(1,N+1):
for j in range(1,N+1):
e[i][j]=min(e[i][j], e[i][k]+e[k][j])
Q=input()
for _ in range(Q):
s,t=map(int, sys.stdin.readline().split())
if e[s][t]==float("inf"):
print -1
else:
print e[s][t]-1
| n,m,l = map(int,input().split())
g = [[float('inf')]*n for _ in range(n)]
for _ in range(m):
a,b,c = map(int,input().split())
a-=1
b-=1
g[a][b] = c
g[b][a] = c
for k in range(n):
for i in range(n):
for j in range(n):
g[i][j] = min(g[i][j],g[i][k] + g[k][j])
h = [[float('inf')]*n for _ in range(n)]
for i in range(n):
for j in range(n):
if g[i][j]<=l:
h[i][j] = 1
for k in range(n):
for i in range(n):
for j in range(n):
h[i][j] = min(h[i][j],h[i][k] + h[k][j])
Q = int(input())
for _ in range(Q):
s,t = map(int,input().split())
s -=1
t-=1
if h[s][t] ==float('inf'):
print(-1)
else:
print(h[s][t]-1)
| 1 | 173,071,349,507,830 | null | 295 | 295 |
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
# 方針:各文字列の出現回数を数え、出現回数が最大なる文字列を昇順に出力する
# Counter(リスト) は辞書型のサブクラスであり、キーに要素・値に出現回数という形式
# Counter(リスト).most_common() は(要素, 出現回数)というタプルを出現回数順に並べたリスト
S = Counter(S).most_common()
max_count = S[0][1] # 最大の出現回数
# 出現回数が最も多い単語を集計する
l = [s[0] for s in S if s[1] == max_count]
# 昇順にソートして出力
for i in sorted(l):
print(i) | A, V = map(int,input().split())
B, W = map(int,input().split())
T = int(input())
if (V <= W):
print("NO")
elif(T < abs(A - B)/(V-W)):
print("NO")
else:
print("YES")
| 0 | null | 42,515,184,408,418 | 218 | 131 |
# coding: utf-8
#Problem Name: Debt Hell
#ID: tabris
#Mail: [email protected]
n = float(raw_input())
dept = 100000
for i in range(int(n)):
dept *= 1.05
if not (dept/1000).is_integer():
dept /= 1000
dept = __import__('math',fromlist=['floor']).floor(dept)*1000+1000
print int(dept) | import math
result = 100000
for i in range(int(input())):
result *= 1.05
result = math.ceil(result/1000)*1000
print(result) | 1 | 1,141,573,018 | null | 6 | 6 |
x = input()
print(int(x)*int(x)*int(x)) | # coding: utf-8
i = input()
j = int(i) ** 3
print(j) | 1 | 279,342,381,472 | null | 35 | 35 |
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353
def ddprint(x):
if DBG:
print(x)
n = inn()
a = inl()
acc = [0]*(n+1)
for i in range(n-1,-1,-1):
acc[i] = acc[i+1]+a[i]
#ddprint(acc)
x = 0
for i in range(n-1):
#ddprint(f"{x=} {i=} {acc[i+1]}")
x = (x+a[i]*acc[i+1])%R
print(x)
| # abc161_b.py
# https://atcoder.jp/contests/abc161/tasks/abc161_b
# B - Popular Vote /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点
# 問題文
# N種類の商品に対して人気投票を行いました。商品 i は Ai票を得ています。
# この中から人気商品 M個を選びます。ただし、得票数が総投票数の 14M未満であるような商品は選べません。
# 人気商品 M個を選べるなら Yes、選べないなら No を出力してください。
# 制約
# 1≤M≤N≤100
# 1≤Ai≤1000
# Aiは相異なる
# 入力は全て整数
# 入力
# 入力は以下の形式で標準入力から与えられる。
# N M
# A1 ... AN
# 出力
# 人気商品 M個を選べるなら Yes、選べないなら No を出力せよ。
# 入力例 1
# 4 1
# 5 4 2 1
# 出力例 1
# Yes
# 総投票数は 12です。1 位の得票数は 5なので、これを選ぶことができます。
# 入力例 2
# 3 2
# 380 19 1
# 出力例 2
# No
# 総投票数は 400です。
# 2,3 位の得票数は総得票数の 14×2 未満なので、これらを選ぶことはできず、人気商品 2個を選べません。
# 入力例 3
# 12 3
# 4 56 78 901 2 345 67 890 123 45 6 789
# 出力例 3
# Yes
global FLAG_LOG
FLAG_LOG = False
def log(value):
# FLAG_LOG = True
# FLAG_LOG = False
if FLAG_LOG:
print(str(value))
def calculation(lines):
# S = lines[0]
# N = int(lines[0])
N, M = list(map(int, lines[0].split()))
values = list(map(int, lines[1].split()))
# values = list(map(int, lines[2].split()))
# values = list()
# for i in range(N):
# values.append(int(lines[i]))
# valueses = list()
# for i in range(N):
# valueses.append(list(map(int, lines[i+1].split())))
values.sort()
values = values[::-1]
log(f'values[M-1]=[{values[M-1]}]')
log(f'1/(4*M)=[{1/(4*M)}]')
if values[M-1]/sum(values) < 1/(4*M):
result = 'No'
else:
result = 'Yes'
return [result]
# 引数を取得
def get_input_lines(lines_count):
lines = list()
for _ in range(lines_count):
lines.append(input())
return lines
# テストデータ
def get_testdata(pattern):
if pattern == 1:
lines_input = ['4 1', '5 4 2 1']
lines_export = ['Yes']
if pattern == 2:
lines_input = ['3 2', '380 19 1']
lines_export = ['No']
if pattern == 3:
lines_input = ['12 3', '4 56 78 901 2 345 67 890 123 45 6 789']
lines_export = ['Yes']
return lines_input, lines_export
# 動作モード判別
def get_mode():
import sys
args = sys.argv
global FLAG_LOG
if len(args) == 1:
mode = 0
FLAG_LOG = False
else:
mode = int(args[1])
FLAG_LOG = True
return mode
# 主処理
def main():
import time
started = time.time()
mode = get_mode()
if mode == 0:
lines_input = get_input_lines(2)
else:
lines_input, lines_export = get_testdata(mode)
lines_result = calculation(lines_input)
for line_result in lines_result:
print(line_result)
# if mode > 0:
# print(f'lines_input=[{lines_input}]')
# print(f'lines_export=[{lines_export}]')
# print(f'lines_result=[{lines_result}]')
# if lines_result == lines_export:
# print('OK')
# else:
# print('NG')
# finished = time.time()
# duration = finished - started
# print(f'duration=[{duration}]')
# 起動処理
if __name__ == '__main__':
main()
| 0 | null | 21,354,019,180,270 | 83 | 179 |
import sys
if __name__ == "__main__":
n, m = map(lambda x: int(x), input().split())
coins = list(map(lambda x: int(x), input().split()))
table = [sys.maxsize] * (n + 2)
table[0] = 0
for i in range(n + 1):
for coin in coins:
if (i + coin <= n):
table[i + coin] = min(table[i + coin], table[i] + 1)
print(table[n])
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
15 6
1 2 7 8 12 50
output:
2
"""
import sys
def solve():
rec[0] = 0
for i in range(c_num):
for j in range(coins[i], money + 1):
rec[j] = min(rec[j], rec[j - coins[i]] + 1)
return rec
if __name__ == '__main__':
_input = sys.stdin.readlines()
money, c_num = map(int, _input[0].split())
coins = list(map(int, _input[1].split()))
# assert len(coins) == c_num
rec = [float('inf')] * (money + 1)
ans = solve()
print(ans.pop()) | 1 | 143,367,356,340 | null | 28 | 28 |
x=int(input())
print(x**2) | N = int(input())
A = list(map(int, input().split()))
if N%2==0:
dp = [[0]*2 for _ in range(N)]
dp[0][0] = A[0]
dp[1][1] = A[1]
for i in range(2, N):
if i==2:
dp[i][0] = dp[i-2][0]+A[i]
else:
dp[i][0] = dp[i-2][0]+A[i]
dp[i][1] = max(dp[i-3][0]+A[i], dp[i-2][1]+A[i])
print(max(dp[N-2][0], dp[N-1][1]))
else:
dp = [[0]*3 for _ in range(N)]
dp[0][0] = A[0]
dp[1][1] = A[1]
dp[2][2] = A[2]
for i in range(2, N):
if i==2:
dp[i][0] = dp[i-2][0]+A[i]
elif i==3:
dp[i][0] = dp[i-2][0]+A[i]
dp[i][1] = max(dp[i-2][1]+A[i], dp[i-3][0]+A[i])
else:
dp[i][0] = dp[i-2][0]+A[i]
dp[i][1] = max(dp[i-3][0]+A[i], dp[i-2][1]+A[i])
dp[i][2] = max(dp[i-4][0]+A[i], dp[i-3][1]+A[i], dp[i-2][2]+A[i])
print(max(dp[N-3][0], dp[N-2][1], dp[N-1][2])) | 0 | null | 91,535,458,288,808 | 278 | 177 |
from numpy import zeros, int64
from numba import njit
R, C, K, *RCV = map(int64, open(0).read().split())
V = zeros((R + 1, C + 1), int64)
for r, c, v in zip(*[iter(RCV)] * 3):
V[r][c] = v
@njit
def main():
dp = zeros((R + 1, C + 1, 4), int64)
for i in range(1, R + 1):
for j in range(1, C + 1):
vij = V[i][j]
for k in range(4):
dp[i][j][k] = max(
dp[i][j - 1][k],
dp[i - 1][j][3]
)
for k in range(3, 0, -1):
dp[i][j][k] = max(
dp[i][j][k],
vij + dp[i][j][k - 1]
)
print(dp[R][C][3])
main() | import sys
r=int(input())
print(r*r) | 0 | null | 75,696,645,389,650 | 94 | 278 |
import sys
def main():
n = int(sys.stdin.readline())
i = 1
while i <= n:
x = i
if x % 3 == 0:
print(' {}'.format(i), end='')
else:
while x > 1:
if int(x) % 10 == 3:
print(' {}'.format(i), end='')
break
x /= 10
i += 1
print()
return
if __name__ == '__main__':
main()
| # Aizu Problem ITP_1_5_D: Structured Programming
#
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
res = []
def CHECK_NUM2(n, i):
x = i
if x % 3 == 0:
res.append(i)
else:
while True:
if x % 10 == 3:
res.append(i)
break
x //= 10
if x == 0:
break
i += 1
if i <= n:
CHECK_NUM(n, i)
def CHECK_NUM(n, i):
while True:
x = i
if x % 3 == 0:
res.append(i)
else:
while True:
if x % 10 == 3:
res.append(i)
break
x //= 10
if x == 0:
break
i += 1
if i > n:
break
def call(n):
CHECK_NUM(n, 1)
n = int(input())
#n=1000
call(n)
print(' ' + ' '.join([str(r) for r in res])) | 1 | 931,880,214,672 | null | 52 | 52 |
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_sums, b_sums = [0], [0]
for i in range(n):
a_sums.append(a_sums[i] + a[i])
for i in range(m):
b_sums.append(b_sums[i] + b[i])
ans = 0
j = m
for i in range(n + 1):
if a_sums[i] > k:
break
while a_sums[i] + b_sums[j] > k:
j -= 1
ans = max(ans, i + j)
print(ans) | import bisect
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
time = 0
cnt = 0
C = []
SA =[0]
SB =[0]
for a in A:
SA.append(SA[-1] + a)
for b in B:
SB.append(SB[-1] + b)
for x in range(N+1):
L = K - SA[x]
if L < 0:
break
y_max = bisect.bisect_right(SB, L) - 1
C.append(y_max + x)
print(max(C)) | 1 | 10,770,661,003,760 | null | 117 | 117 |
n = int(input())
s = list(input())
ans = ''
for i in s:
ascii_code = (ord(i) + n)
if ascii_code >= 91:
ascii_code -= 26
ans += chr(ascii_code)
print(ans)
| word = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n = int(input())
s = input()
answer = ''
for i in range(len(s)):
iti = word.find(s[i])
if iti + n + 1 > len(word):
answer += word[iti+n-len(word)]
else:
answer += word[iti+n]
print(answer) | 1 | 134,734,181,240,558 | null | 271 | 271 |
i = list(map(int, input().split()))
a = i[0]
b = i[1]
print('{0} {1} {2:.5f}'.format(a // b, a % b, float(a / b))) | n = int(input())
points = []
seen = []
find_time = []
end_time = []
for _ in range(n):
input_text = list(map(int, input().split()))
u, k, v_list = input_text[0], input_text[1], input_text[2:]
seen.append(False)
points.append(v_list)
find_time.append(0)
end_time.append(0)
count = [0]
def dfs(graph, v, count):
seen[v] = True
find_time[v] = count[0]
for next_v in graph[v]:
if seen[next_v - 1]:
continue
count[0] += 1
dfs(graph, next_v - 1, count)
count[0] += 1
end_time[v] = count[0]
for index, seen_point in enumerate(seen):
if seen_point:
pass
else:
count[0] += 1
dfs(points, index, count)
# print(find_time)
# print(end_time)
count = 1
for f, e in zip(find_time, end_time):
print(count, f, e)
count += 1
| 0 | null | 296,278,844,960 | 45 | 8 |
midScore =[0]*50
finScore = [0]*50
reScore = [0]*50
personNum = 0
while True:
m,f,r = map(int,input().split())
midScore[personNum] = m
finScore[personNum] = f
reScore[personNum] = r
personNum += 1
if m is f is r is -1:
break
for person in range(personNum):
totalScore = midScore[person] + finScore[person]
if midScore[person] is finScore[person] is reScore[person] is -1:
pass
elif midScore[person] == -1 or finScore[person] == -1:
print("F")
elif 80<=totalScore:
print("A")
elif 65<=totalScore<80:
print("B")
elif 50<=totalScore<65:
print("C")
elif 30<=totalScore<50:
if 50<=reScore[person]:
print("C")
else:
print("D")
elif totalScore<30:
print("F")
| while True :
h,w = map(int,raw_input().split())
if h==0 and w==0:
break
else :
for i in range(h):
print '#'*w
print'' | 0 | null | 1,000,611,199,340 | 57 | 49 |
def factorization(n):
arr = []
tmp = n
for i in range(2, int(-(-n**0.5//1))+1):
if tmp % i == 0:
cnt = 0
while tmp % i == 0:
cnt += 1
tmp //= i
arr.append([i, cnt])
if tmp != 1:
arr.append([tmp, 1])
if arr == [] and n != 1:
arr.append([n, 1])
return arr
n = int(input())
c = factorization(n)
ans = 0
for k, v in c:
cnt = 1
while v >= cnt:
v -= cnt
cnt += 1
ans += (cnt - 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,878,481,227,048 | null | 136 | 136 |
tmp = input().split(" ")
N = int(tmp[0])
R = int(tmp[1])
if N >= 10:
print(R)
else:
ans = R + 100 * (10 - N)
print(int(ans)) | n, r= input().split()
n, r= int(n), int(r)
eq=r
if n < 10:
eq=0
eq= r+(100*(10-n))
print(eq)
| 1 | 63,168,951,936,260 | null | 211 | 211 |
A = input()
A = list(A.split())
sum = 0
for i in A:
sum += int(i)
if sum >= 22:
print('bust')
else:
print('win') | v = sum(map(int,list(input().split())))
if(v > 21):
print('bust')
else:
print('win')
| 1 | 118,670,428,426,568 | null | 260 | 260 |
n = map(int, raw_input().split())
n.sort()
print n[0],
print n[1],
print n[2] | x=list(map(int, input().split()))
x.sort()
print(x[0],x[1],x[2]) | 1 | 422,160,113,088 | null | 40 | 40 |
def main():
N = input_int()
S = input()
count = 1
for i in range(1, N):
if S[i-1] != S[i]:
count += 1
print(count)
def input_int():
return int(input())
def input_int_tuple():
return map(int, input().split())
def input_int_list():
return list(map(int, input().split()))
main()
| N = int(input())
S = list(input())
S.append("test")
i = 0
while N > 0:
if S[i] == S[i+1]:
S.pop(i)
i = i - 1
i = i + 1
N = N - 1
print(len(S)-1)
| 1 | 169,996,559,413,632 | null | 293 | 293 |
if __name__ == "__main__":
while True:
nums = map( int, raw_input().split())
H = nums[0]
W = nums[1]
if H == 0:
if W == 0:
break
s = ""
j = 0
while j < W:
s += "#"
j += 1
i = 0
while i < H:
print s
i += 1
print | N, K = map(int, input().split())
count = 1
while N >= K:
N //= K
count +=1
print(count) | 0 | null | 32,585,932,816,180 | 49 | 212 |
num = raw_input()
num_list = raw_input().split()
num_list = map(int, num_list)
count = 0
def bubble_sort(num_list, count):
flag = True
i = 0
while flag:
flag = False
for j in range(len(num_list)-1, i, -1):
if num_list[j-1] > num_list[j]:
temp = num_list[j]
num_list[j] = num_list[j-1]
num_list[j-1] = temp
count += 1
flag = True
i += 1
return count
count = bubble_sort(num_list, count)
num_list = map(str, num_list)
print " ".join(num_list)
print count | n = int(input())
ll = list(map(int, input().split()))
def bubble_sort(a, n):
flag = True
count = 0
while flag:
flag = False
for i in range(n-2, -1, -1):
if a[i] > a[i+1]:
a[i], a[i+1] = a[i+1], a[i]
flag = True
count += 1
print(" ".join(map(str, a)))
print(count)
bubble_sort(ll, n)
| 1 | 16,718,100,062 | null | 14 | 14 |
import sys
input = sys.stdin.readline
class UnionFind():
def __init__(self, N):
self.N = N
self.r = [-1] * (N+1)
def root(self, x):
if (self.r[x] < 0):
return x
else:
self.r[x] = self.root(self.r[x])
return self.r[x]
def unite(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return False
if self.r[x] > self.r[y]:
x, y = y, x
self.r[x] += self.r[y]
self.r[y] = x
return True
def size(self, x):
return -self.r[self.root(x)]
def same(self, x, y):
return self.root(x) == self.root(y)
def main():
N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
A, B = map(lambda i: int(i)-1, input().split())
uf.unite(A, B)
ans = 0
for i in range(N):
ans = max(ans, uf.size(i))
print(ans)
main() | # UnionFind: https://note.nkmk.me/python-union-find/
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
def find(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.root[x] > self.root[y]:
x, y = y, x
self.root[x] += self.root[y]
self.root[y] = x
def is_same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.root[self.find(x)]
n, m = map(int, input().split())
friends = UnionFind(n)
for i in range(m):
a, b = map(int, input().split())
friends.unite(a, b)
print(max(friends.size(i) for i in range(n))) | 1 | 3,902,976,460,512 | null | 84 | 84 |
s,t = input().split()
a,b = map(int,input().split())
A = input()
if A == s:print(a-1,b)
else:print(a,b-1) | import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)
N, K = map(int, input().split())
MOD = 10 ** 9 + 7
# 階乗、Combinationコンビネーション(numpyを使う)
def cumprod(arr, MOD):
L = len(arr)
Lsq = int(L**.5+1)
arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
for n in range(1, Lsq):
arr[:, n] *= arr[:, n-1]
arr[:, n] %= MOD
for n in range(1, Lsq):
arr[n] *= arr[n-1, -1]
arr[n] %= MOD
return arr.ravel()[:L]
def make_fact(U, MOD):
x = np.arange(U, dtype=np.int64)
x[0] = 1
fact = cumprod(x, MOD)
x = np.arange(U, 0, -1, dtype=np.int64)
x[0] = pow(int(fact[-1]), MOD-2, MOD)
fact_inv = cumprod(x, MOD)[::-1]
return fact, fact_inv
U = 10**6
fact, fact_inv = make_fact(N * 2 + 10, MOD)
fact, fact_inv = fact.tolist(), fact_inv.tolist()
def mod_comb_k(n, k, mod):
return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod
ans = 0
for i in range(N):
if K < i:
continue
if N - 1 <= K:
ans = mod_comb_k(N + N - 1, N - 1, MOD)
break
if i == 0:
ans += 1
continue
a = int(mod_comb_k(N - 1, i, MOD)) * int(mod_comb_k(N, i, MOD))
a %= MOD
ans += a
ans %= MOD
'''
a = int(fact[N]) * int(fact_inv[i]) % MOD * int(fact_inv[N - 1])
a = a * int(fact[N-1]) % MOD * int(fact_inv[i]) % MOD * \
int(fact_inv[N-i-1]) % MOD
ans = (a + ans) % MOD
'''
print(ans)
| 0 | null | 69,596,619,471,112 | 220 | 215 |
s = input()
t = input()
ls = len(s)
lt = len(t)
ret = lt
for i in range(ls+1 - lt):
diff = 0
for j in range(lt):
diff += (t[j] != s[i+j])
if diff == 0:
ret = diff
break
if diff < ret:
ret = diff
print(ret) | s = input()
t = input()
ans = 1001
if len(s)-len(t)==0:
temp = 0
for j in range(len(t)):
if s[j]!=t[j]:
temp+=1
ans = min(ans, temp)
else:
for i in range(len(s)-len(t)):
temp = 0
for j in range(len(t)):
if s[i+j]!=t[j]:
temp+=1
ans = min(ans, temp)
print(ans) | 1 | 3,661,303,675,172 | null | 82 | 82 |
A = int(input())
B = int(input())
lis = [1, 2, 3]
x = lis.index(A)
y = lis.index(B)
lis[x] = 0
lis[y] = 0
ans = sum(lis)
print(ans) | c= '123'
a= str(input())
b= str(input())
c= c.replace(a, '')
c= c.replace(b, '')
print(c) | 1 | 110,739,193,160,020 | null | 254 | 254 |
while(1):
H, W = map(int, input().split())
if H == 0 and W == 0:
break
for i in range(H):
for j in range(W):
print("#", end='')
print("\n", end='')
print("\n", end='') | import math
from functools import reduce
n, m = input().split()
a = list(map(int, input().split()))
b =[0]*int(n)
for i in range(len(a)):
b[i] = a[i]//2
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
c = 0
x = lcm_list(b)
for i in range(int(n)):
if (x // b[i]) % 2 == 0:
c = -1
break
else:
continue
if c == -1:
print(0)
else:
print(math.floor(((int(m)/x)+1)/2))
| 0 | null | 51,430,200,625,988 | 49 | 247 |
n, p = map(int, input().split())
s = list(map(int, input()))
ans = 0
if p == 2 or p == 5:
for i, x in enumerate(s):
if (p == 2 and not x % 2) or (p == 5 and (x == 0 or x == 5)):
ans += i+1
print(ans)
exit()
s.reverse()
cum = [0] * (n+1)
for i in range(n):
cum[i+1] = (cum[i] + s[i] * pow(10, i, p)) % p
t = [0] * p
for x in cum: t[x] += 1
for x in t:
ans += x * (x-1) // 2
print(ans)
| # -*- coding: utf-8 -*-
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
k_max = 10100
score = [-10**18-1] * N
for i in range(N):
score_i = [-10**18-1] * k_max # iからスタートしてK回操作する場合の累積和
score_i[0] = C[P[i]-1]
index = P[i]-1
for k in range(1, K):
if index == i:
# 既に進んだことがあるマスの場合
loop_score = score_i[k-1] # 1ループで増えるスコア
if loop_score > 0:
loop_num = k # ループする要素数はk(indexが0 ~ k-1)
tmp_score = [-10**18-1] * k_max
tmp_score[0] = (K//k -1) * loop_score
# print("loop_score", loop_score)
# print("tmp_score", tmp_score)
tmp_index = index
# print("loop_num + K%k + 1", loop_num + K%k + 1)
for j in range (1, loop_num + K%k + 1):
tmp_score[j] = tmp_score[j-1] + C[P[tmp_index]-1]
tmp_index = P[tmp_index]-1
# print("max(tmp_score)", max(tmp_score))
score_i[k] = max(tmp_score)
break
score_i[k] = score_i[k-1] + C[P[index]-1]
index = P[index]-1
score[i] = max(score_i)
print(max(score)) | 0 | null | 31,683,404,072,960 | 205 | 93 |
N, R = list(map(int, input().split()))
if N >= 10:
print(R)
else:
ans = 100 * (10 - N) + R
print(ans) | N = int(input())
XL = [list(map(int, input().split())) for x in range(N)]
XL = sorted(XL, key=lambda x: x[0]+x[1])
cnt = 0
prev_right = -10**9+10
for x, l in XL:
left = x - l
right = x + l
if left >= prev_right:
cnt += 1
prev_right = right
print(cnt)
| 0 | null | 76,872,393,562,090 | 211 | 237 |
#!python3
import sys
iim = lambda: map(int, input().rstrip().split())
def popcnt2(n):
a = (
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
)
ans = 0
while n:
ans += a[n&0xff]
n >>= 8
return ans
def resolve():
N = int(input())
S = list(input())
Q = int(input())
ln = N.bit_length() + 1
c0 = ord('a')
smap = [1<<(i-c0) for i in range(c0, ord('z')+1)]
T = [None] * ln
T[0] = [smap[ord(S[i])-c0] for i in range(N)]
if N&1:
T[0].append(0)
N += 1
t0, n2 = T[0], N
for i in range(1, ln):
n1 = n2 = n2 >> 1
if n2 & 1:
n2 += 1
ti = T[i] = [0] * n2
for j in range(n1):
j2 = j << 1
d1, d2 = t0[j2], t0[j2+1]
ti[j] = d1 | d2
t0 = ti
#for ti in T:
# print(len(ti), ti)
ans = []
for cmd, i, j in (line.split() for line in sys.stdin):
i = int(i) - 1
if cmd == "1":
if S[i] == j:
continue
S[i] = j
t0 = T[0]
t0[i] = smap[ord(j)-c0]
for i1 in range(1, ln):
ti = T[i1]
j1 = i >> 1
ti[j1] = t0[i] | t0[i^1]
i, t0 = j1, ti
#for ti in T:
# print(len(ti), ti)
elif cmd == "2":
j = int(j) - 1
d1 = 0
for i1 in range(ln):
ti = T[i1]
if not i < j :
if i == j:
d1 |= ti[i]
break
if i & 1:
d1 |= ti[i]
i += 1
if j & 1 == 0:
d1 |= ti[j]
j -= 1
i >>= 1; j >>=1
ans.append(popcnt2(d1))
print(*ans, sep="\n")
if __name__ == "__main__":
resolve()
| import sys
# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math
# from numba import jit
# from scipy import
# import numpy as np
# import networkx as nx
# import matplotlib.pyplot as plt
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
class SegmentTree:
def __init__(self, array, operator, identity):
self.identity = identity
self.operator = operator
self.array_size = len(array)
self.tree_height = (self.array_size - 1).bit_length()
self.tree_size = 2 ** (self.tree_height + 1)
self.leaf_start_index = 2 ** self.tree_height
self.tree = [self.identity] * self.tree_size
for i in range(self.array_size):
x = 1 << (ord(array[i]) - 96)
self.tree[self.leaf_start_index + i] = x
for i in range(self.leaf_start_index - 1, 0, -1):
self.tree[i] = self.operator(self.tree[i << 1], self.tree[i << 1 | 1])
def update(self, index, val):
x = 1 << (ord(val) - 96)
cur_node = self.leaf_start_index + index
self.tree[cur_node] = x
while cur_node > 1:
self.tree[cur_node >> 1] = self.operator(self.tree[cur_node], self.tree[cur_node ^ 1])
cur_node >>= 1
def query(self, begin, end):
if begin < 0:
begin = 0
elif begin > self.array_size:
return self.identity
if end > self.array_size:
end = self.array_size
elif end < 1:
return self.identity
res = self.identity
left = begin + self.leaf_start_index
right = end + self.leaf_start_index
while left < right:
if left & 1:
res = self.operator(res, self.tree[left])
left += 1
if right & 1:
right -= 1
res = self.operator(res, self.tree[right])
left >>= 1
right >>= 1
return res
def main():
from operator import or_
n = int(input())
s = input()
q = int(input())
seg = SegmentTree(s, or_, 0)
for i in range(q):
q1, q2, q3 = readline().split()
q1, q2 = int(q1), int(q2)
if q1 == 1:
seg.update(q2-1, q3.rstrip("\n"))
else:
q3 = int(q3)
print(bin(seg.query(q2-1, q3)).count("1"))
if __name__ == '__main__':
main()
| 1 | 62,422,708,461,180 | null | 210 | 210 |
import math
n = int(input())
a = list(map(int, input().split()))
nmax = 10**6
check = [0]*(nmax + 5)
for i in a:
check[i] += 1
pairwise = True
for i in range(2, nmax + 5):
cnt = 0
for j in range(i, nmax + 5, i):
cnt += check[j]
if cnt > 1:
pairwise = False
if pairwise == True:
print('pairwise coprime')
exit()
x = 0
for i in a:
x = math.gcd(x,i)
if x == 1:
print('setwise coprime')
else:
print('not coprime')
| #ABC177E
N = int(input())
#N = 1000000
A = list(map(int, input().split()))
#A = [i+1 for i in range(1000000)]
p = {2*i+1: 1 for i in range(1, 500)}
for i in range(3, 1000, 2):
for j in p:
if j != i:
if j % i == 0:
p[j] = 0
L = [2]
for i in p:
if p[i] == 1:
L.append(i)
def gcd(x, y):
k, l = x, y
while l:
k, l = l, k % l
return k
g = A[0]
i = 0
nn = len(L)
while i < N:
g = gcd(g, A[i])
if g == 1:
break
i += 1
if g > 1:
print("not coprime")
else:
D = {}
m = 0
for i in A:
pnt = 0
x = i
for j in L:
cnt = False
while x % j == 0:
cnt = True
x //= j
if cnt:
if j in D:
D[j] += 1
if D[j] == 2:
m = 2
break
else:
D[j] = 1
pnt += 1
if pnt == nn and x != 1:
if x in D:
D[x] += 1
if D[x] == 2:
m = 2
else:
D[x] = 1
break
if x == 1:
break
if m >= 2:
break
if D == {}:
print("pairwise coprime")
else:
if m > 1:
print("setwise coprime")
else:
print("pairwise coprime") | 1 | 4,100,940,737,792 | null | 85 | 85 |
import math
a = int(input())
b = int(input())
n = int(input())
dum = max(a,b)
ans = n/dum
print(math.ceil(ans)) | numbers = []
n = raw_input()
numbers = n.split(" ")
for i in range(2):
numbers[i] = int(numbers[i])
if numbers[0] > numbers[1]:
print "a > b"
elif numbers[0] < numbers[1]:
print "a < b"
elif numbers[0] == numbers[1]:
print "a == b" | 0 | null | 44,656,110,720,522 | 236 | 38 |
# coding: utf-8
# Your code here!
n=int(input())
sum=0
min=1000001
max=-1000001
table=list(map(int,input().split(" ")))
for i in table:
sum+=i
if max<i:
max=i
if min>i:
min=i
print(str(min)+" "+str(max)+" "+str(sum))
| def main():
n = int(input())
numbers = list(map(int, input().split()))
ans1 = min(numbers)
ans2 = max(numbers)
ans3 = sum(numbers)
print(ans1, ans2, ans3)
if __name__=="__main__":
main() | 1 | 719,979,586,028 | null | 48 | 48 |
N,K,C = map(int,input().split())
S = list(input())
F = []
maru = 0
last = -10**9
span = C
for i in range(N):
if S[i]=="o" and span >= C:
maru += 1
last = i
F.append([maru,last])
span = 0
else:
span += 1
F.append([maru,last])
#print(F)
s = S[::-1]
maru = 0
last = 10**9
span = C
E = []
for i in range(N):
if s[i] == "o" and span >= C:
maru += 1
last = N-1-i
E.append([maru,last])
span = 0
else:
E.append([maru,last])
span += 1
E = E[::-1]
#print(E)
F = [[0,-10**9]] + F + [[0,10**9]]
E = [[0,-10**9]] + E + [[0,10**9]]
#print(F)
#print(E)
ans = []
for i in range(1,N+1):
cnt = F[i-1][0] + E[i+1][0]
if S[i-1] == "o":
if E[i+1][1] - F[i-1][1] < C:
cnt -= 1
if cnt == K-1:
ans.append(i)
#print(F[i-1],E[i+1],cnt)
for i in range(len(ans)):
print(ans[i]) | n, k, c = map(int, input().split())
s = input()
l = len(s) - 1
i = 0
lb = []
le = []
while i < len(s) and len(lb) < k:
if s[i] == 'o':
lb.append(i)
i += c + 1
continue
i += 1
while l > -1 and len(le) < k:
if s[l] == 'o':
le.append(l)
l -= (c + 1)
continue
l -= 1
le.sort()
for j in range(0, len(lb)):
if lb[j] == le[j]:
print(lb[j]+1) | 1 | 40,407,314,565,728 | null | 182 | 182 |
a = int(input())
b = 0
for i in str(a):
if i=="7":
b+=1
if b>0:
print("Yes")
else:
print("No") | N, M = map(int, input().split())
C = [-1] * 3
for i in range(M):
s, c = map(int, input().split())
if C[s - 1] == -1:
C[s - 1] = c
else:
if C[s - 1] != c:
print(-1)
exit()
if N == 1 and (M == 0 or (M == 1 and C[0] == 0)):
print(0)
exit()
for i in range(10 ** (N - 1), 10 ** N):
si = str(i)
flg = True
for j in range(N):
if C[j] != -1 and si[j] != str(C[j]):
flg = False
break
if flg:
print(i)
exit()
print(-1)
| 0 | null | 47,616,340,247,598 | 172 | 208 |
n, m = map(int,input().split())
par = [-1 for i in range(n + 1)]
par[0] = 0
def find(x):
if (par[x] < 0):
return x
else:
x = par[x]
return find(x)
def unit(x, y):
if (find(x) == find(y)):
pass
else:
x = find(x)
y = find(y)
if (x > y):
x, y = y, x
s = par[y]
par[y] = x
par[x] = par[x] + s
for i in range(m):
a, b = map(int,input().split())
unit(a, b)
par.sort()
print(-par[0])
| # -*- 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 functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(buff_readline())
def read_int_n():
return list(map(int, buff_readline().split()))
def read_float():
return float(buff_readline())
def read_float_n():
return list(map(float, buff_readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
class UnionFind():
def __init__(self):
self.__table = {}
self.__size = defaultdict(lambda: 1)
self.__rank = defaultdict(lambda: 1)
def __root(self, x):
if x not in self.__table:
self.__table[x] = x
elif x != self.__table[x]:
self.__table[x] = self.__root(self.__table[x])
return self.__table[x]
def same(self, x, y):
return self.__root(x) == self.__root(y)
def union(self, x, y):
x = self.__root(x)
y = self.__root(y)
if x == y:
return False
if self.__rank[x] < self.__rank[y]:
self.__table[x] = y
self.__size[y] += self.__size[x]
else:
self.__table[y] = x
self.__size[x] += self.__size[y]
if self.__rank[x] == self.__rank[y]:
self.__rank[x] += 1
return True
def size(self, x):
return self.__size[self.__root(x)]
def num_of_group(self):
g = 0
for k, v in self.__table.items():
if k == v:
g += 1
return g
@mt
def slv(N, M, AB):
uf = UnionFind()
p = set()
for a, b in AB:
uf.union(a, b)
p.add(a)
p.add(b)
ans = 1
for c in p:
ans = max(ans, uf.size(c))
return ans
def main():
N, M = read_int_n()
AB = [read_int_n() for _ in range(M)]
print(slv(N, M, AB))
if __name__ == '__main__':
main()
| 1 | 3,935,384,734,830 | null | 84 | 84 |
# https://atcoder.jp/contests/abc145/tasks/abc145_d
X, Y = map(int, input().split())
if (2*Y- X) % 3 or (2*X- Y) % 3:
print(0)
exit()
x = (2*Y - X) // 3
y = (2*X - Y) // 3
if x < 0 or y < 0:
print(0)
exit()
n = x + y
r = x
mod = 10**9 + 7
f = 1
for i in range(1, n + 1):
f = f*i % mod
fac = f
f = pow(f, mod-2, mod)
facinv = [f]
for i in range(n, 0, -1):
f = f*i % mod
facinv.append(f)
facinv.append(1)
print(fac * facinv[r] * facinv[n - r] % mod) |
N=int(input())
A_list=sorted(list(map(int, input().split())), reverse=True)
ans=1
if 0 in A_list:
print(0)
exit()
else:
for a in A_list:
ans*=a
if ans>1e+18:
print(-1)
exit()
print(ans)
| 0 | null | 83,016,840,011,820 | 281 | 134 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.