code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
178,025B
⌀ | question_pair_id
float64 27.1M
177,113B
⌀ | code1_group
int64 1
297
| code2_group
int64 1
297
|
---|---|---|---|---|---|---|
h,w=map(int, input().split())
s=[list(input()) for _ in range(h)]
dx=[1,0]
dy=[0,1]
dp=[[10**9]*(w) for _ in range(h)]
if s[0][0]=='#':
dp[0][0]=1
else:
dp[0][0]=0
for i in range(h):
for j in range(w):
for d in range(2):
new_i=i+dx[d]
new_j=j+dy[d]
if h<=new_i or w<=new_j:
continue
add=0
if s[new_i][new_j]=='#' and s[i][j]=='.':
add=1
dp[new_i][new_j]=min(dp[new_i][new_j], dp[i][j]+add)
print(dp[-1][-1])
|
a = int(input())
print(1 / 2 if a % 2 == 0 else (a + 1) / (2 * a))
| 0 | null | 113,625,022,318,532 | 194 | 297 |
n=int(input())
a=[int(j) for j in input().split()]
p=[0]*n
d=[0]*n
for i in range(n):
p[i]=a[i]+p[i-2]
if (i&1):
d[i]=max(p[i-1],a[i]+d[i-2])
else:
d[i]=max(d[i-1],a[i]+d[i-2])
print(d[-1])
|
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF = float("inf")
import bisect
N = int(input())
a = [0] + list(map(int, input().split()))
o = [a[2*i+1] for i in range(N//2)]
o = list(itertools.accumulate(o))
dp = [0 for i in range(N+1)]
dp[0] = dp[1] = 0
dp[2] = max(a[1], a[2])
if N > 2: dp[3] = max([a[1], a[2], a[3]])
if N > 3:
for i in range(4, N+1):
if i % 2 == 0:
dp[i] = max(dp[i-2] + a[i], o[(i-3)//2] + a[i-1])
else:
dp[i] = max([dp[i-2] + a[i], dp[i-3] + a[i-1], o[(i-2)//2] ])
print(dp[N])
| 1 | 37,295,511,165,532 | null | 177 | 177 |
n1,n2,n3 = map(int,input().split(" "))
list1 = [list(map(int,input().split(" "))) for _ in range(n1)]
list2 = [list(map(int,input().split(" "))) for _ in range(n2)]
mat = [[0 for _ in range(n3)] for _ in range(n1)]
for i in range(n1):
for j in range(n2):
for k in range(n3):
mat[i][k] += list1[i][j] * list2[j][k]
for m in mat:
print(*m)
|
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import accumulate
def main():
n=int(input())
A=[int(_) for _ in input().split()]
A=list(accumulate(A))
min_A=100000000000
for a in A:
min_A=min(min_A,abs(A[-1]/2-a))
print(int(min_A*2))
if __name__=='__main__':
main()
| 0 | null | 71,459,949,672,160 | 60 | 276 |
n = int(input())
print('Yes' if any(i*j == n for i in range(1, 10) for j in range(1, 10)) else 'No')
|
N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [0] * (S+1)
dp[0] = 1
for a in A:
for j in range(S, -1, -1):
if j-a >= 0:
dp[j] = dp[j]*2 + dp[j-a]
else:
dp[j] = dp[j]*2
print(dp[S]%mod)
| 0 | null | 89,189,863,890,820 | 287 | 138 |
def main():
N = int(input())
print(N + N * N + N * N * N)
if __name__ == '__main__':
main()
# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
# while abs(ok - ng) > 1:
# mid = (ok + ng) // 2
# if func(mid):
# ok = mid
# else:
# ng = mid
# return ok
|
n = int(input())
a,b = divmod(n,2)
print(a+b)
| 0 | null | 34,669,407,365,690 | 115 | 206 |
T=input()
print(T.replace('?','D'))
|
def convert(s):
# initialization of string to ""
new = ""
# traverse in the string
for x in s:
new += x
# return string
return new
s=input()
n=len(s)
a=[]
for i in range(n):
if s[i]=='P':
a.append('P')
else:
a.append('D')
print(convert(a))
| 1 | 18,537,895,828,800 | null | 140 | 140 |
#!/usr/bin/env python3
import sys
from itertools import chain
# floor(A x / B) - A * floor(x / B)
#
# x = B * x1 + x2 : (x2 < B) とする
#
# = floor(A (B*x1+x2) / B) - A floor((B*x1+x2) / B)
# = A x1 + floor(A x2 / B) - A x1
# = floor(A x2 / B)
def solve(A: int, B: int, N: int):
if N >= B:
x2 = B - 1
else:
x2 = N
return (A * x2) // B
def main():
tokens = chain(*(line.split() for line in sys.stdin))
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
N = int(next(tokens)) # type: int
answer = solve(A, B, N)
print(answer)
if __name__ == "__main__":
main()
|
from itertools import combinations_with_replacement as cr
n,m,q=map(int,input().split())
s=[list(map(int,input().split()))for i in range(q)]
f=0
for i in cr([i for i in range(1,m+1)],n):
e=0
for a,b,c,d in s:
if i[b-1]-i[a-1]==c:
e+=d
if f<e:f=e
print(f)
| 0 | null | 27,802,389,321,652 | 161 | 160 |
N=int(input())
A=list(map(int,input().split()))
d=dict()
for i in range(N):
if A[i] not in d:
d[A[i]]=0
d[A[i]]+=1
x=sum(x*(x-1)//2 for x in d.values())
for i in range(N):
y=d[A[i]]
print(x-y*(y-1)//2+(y-1)*(y-2)//2)
|
from collections import Counter
input()
a = list(map(int, input().split()))
c = Counter(a)
d = {i: (i * (i - 1)) // 2 for i in set(c.values())}
s = sum(d[i] for i in c.values())
for k in d:
d[k] = s - d[k] + ((k - 1) * (k - 2) // 2)
d[1] = s
for i in a:
print(d[c[i]])
| 1 | 47,942,702,597,180 | null | 192 | 192 |
for i in range(1,10):
for j in range(1,10):
print(i,"x",j,"=",i*j,sep="")
j+=1
i+=1
|
for i in range(1, 10):
for ii in range(1, 10):
print('{}x{}={}'.format(i, ii, i*ii))
| 1 | 627,480 | null | 1 | 1 |
t=list(map(int,input().split()))
print(max(t[0]*t[2],t[0]*t[3],t[1]*t[2],t[1]*t[3]))
|
def main():
a, b, c, d = map(int, input().split())
ans = max([a * c, b * d, a * d, b * c])
print(ans)
if __name__ == "__main__":
main()
| 1 | 3,048,981,704,626 | null | 77 | 77 |
x, n = map(int,input().split())
L = list(map(int,input().split()))
if n == 0 or x not in L:
print(x)
exit()
for i in range(102):
if (x-i) not in L:
print(x-i)
break
elif (x+i) not in L:
print(x+i)
break
|
x,n = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
for i in range(x+1):
if x - i not in p:
ans = x - i
break
elif x + i not in p:
ans = x + i
break
print(ans)
| 1 | 14,020,214,391,000 | null | 128 | 128 |
import math
#n個からr個とるときの組み合わせの数
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
S = int(input())
ans = 0
mod = 10 ** 9 + 7
for i in range(1,S // 3 + 1): #長さiの数列のとき
x = S - 3 * i #3を分配後の余り
ans += (combinations_count(x + i - 1, i - 1)) % mod #重複組み合わせを足す
ans %= mod
print(ans)
|
s=int(input())
a=1
mod=10**9+7
x=s//3
y=s%3
ans=0
while x>=1:
xx=1
for i in range(1,x):
xx*=i
xx%=mod
yy=1
for j in range(1,1+y):
yy*=j
yy%=mod
fx=pow(xx,mod-2,mod)
fy=pow(yy,mod-2,mod)
xxyy=1
for k in range(1,x+y):
xxyy*=k
xxyy%=mod
ans+=(xxyy*fx*fy)%mod
x-=1
y+=3
print(ans%mod)
| 1 | 3,291,664,006,500 | null | 79 | 79 |
num_list = list(map(int, input().split()))
num = num_list[0]
distance = num_list[1]
res = 0
for i in range(num):
nmb_list = list(map(int, input().split()))
if(nmb_list[0]*nmb_list[0]+nmb_list[1]*nmb_list[1] <= distance*distance):
res += 1
print(res)
|
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
import math
n, d = map(int, input().split())
cnt = 0
for i in range(n):
x, y = map(int, input().split())
dis = math.sqrt(x ** 2 + y ** 2)
if dis <= d:
cnt += 1
print(cnt)
| 1 | 5,886,000,887,488 | null | 96 | 96 |
a, b, c, k = map(int, input().split())
sum = 0
rest_k = k
if rest_k <= a:
sum += rest_k
rest_k = 0
else:
sum += a
rest_k -= a
if rest_k <= b:
rest_k = 0
else:
rest_k -= b
sum -= rest_k
print(sum)
|
def Qb():
a, b, c, k = map(int, input().split())
ra = min(k, a)
k -= ra
k -= b
rc = 0 if k <= 0 else -(min(k, c))
print(ra + rc)
if __name__ == '__main__':
Qb()
| 1 | 21,739,059,981,016 | null | 148 | 148 |
import sys
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(10**6)
INF = 10**20
def mint():
return map(int,input().split())
def lint():
return map(int,input().split())
def judge(x, l=['Yes', 'No']):
print(l[0] if x else l[1])
S = input()
N = len(S)+1
L = [0]*N
R = [0]*N
for i in range(N-1):
L[i+1] = L[i]+1 if S[i]=='<' else 0
for i in range(N-2,-1,-1):
R[i] = R[i+1]+1 if S[i]=='>' else 0
ans = [max(l,r) for l,r in zip(L,R)]
print(sum(ans))
|
N,K = map(int,input().split())
count = N//K
N = abs( N - count*K )
N_2 = abs( N - K )
print( N if N <= N_2 else N_2 )
| 0 | null | 97,645,815,444,740 | 285 | 180 |
s = input()
l = len(s)
ss = ""
for x in range(l):
ss = ss+'x'
print(ss)
|
for i in range(len(input()) - 1):print("x",end="")
print("x")
| 1 | 72,723,617,510,402 | null | 221 | 221 |
r, c = map(int, input().split(' '))
matrix = []
total_cols = [0 for i in range(c+1)]
for i in range(r):
rows = list(map(int, input().split(' ')));
total = sum(rows)
rows.append(total)
total_cols = [ total_cols[i] + x for i, x in enumerate(rows) ]
matrix.append(rows)
matrix.append(total_cols)
for row in matrix:
print(' '.join([str(i) for i in row]))
|
import numpy as np
N,K=map(int,input().split())
a = np.array([int(x) for x in input().split()])
val=sum(a[:K])
max_val=val
for i in range(N-K):
val+=a[K+i]
val-=a[i]
max_val=max(val,max_val)
print(max_val/2+K*0.5)
| 0 | null | 38,357,474,650,546 | 59 | 223 |
n = int(input())
tmp = 0
import sys
for i in range(n):
d = list(map(int,input().split()))
if d[0] == d[1]:
tmp += 1
#check
if tmp == 3:
print('Yes')
sys.exit()
else:
tmp = 0
print('No')
|
import math
n = int(input())
mod = 1000000007
all = pow(10, n, mod)
s1 = 2 * pow(9, n, mod) % mod
s2 = pow(8, n, mod) % mod
ans = int(all - s1 + s2)%mod
if ans < 0:
ans += mod
print(ans%mod)
| 0 | null | 2,871,093,182,400 | 72 | 78 |
#E
H,N=map(int,input().split())
A=[0 for i in range(N)]
dp=[float("inf") for i in range(10**4+1)]
dp[0]=0
for i in range(N):
a,b=map(int,input().split())
A[i]=a
for j in range(10**4+1):
if j+a>10**4:
break
dp[j+a]=min(dp[j]+b,dp[j+a])
if H+max(A)>10**4:
print(min(dp[H:]))
else:
print(min(dp[H:H+max(A)]))
|
h, n = map(int, input().split())
magics = [list(map(int, input().split())) for _ in range(n)]
max_a = max(a for a,b in magics)
dp = [0] * (h+max_a)
for i in range(1,h+max_a):
dp[i] = min(dp[i-a]+b for a, b in magics)
print(dp[h])
| 1 | 80,986,412,921,778 | null | 229 | 229 |
if __name__ == '__main__':
try:
count = []
result = 0
T = int(input())
for _ in range(T):
x, y = map(int, input().split())
count.append([x, y])
for i in range(T-2):
if count[i][0] == count[i][1] and count[i+1][0] == count[i+1][1] and count[i+2][0] == count[i+2][1]:
print("Yes")
exit(0)
print("No")
except Exception:
pass
|
L=list(map(int,input().split()))
a=L[0]
b=L[1]
c=L[2]
d=L[3]
print(max(a*c,b*d,a*d,b*c))
| 0 | null | 2,759,809,927,520 | 72 | 77 |
S = input()
count = 0
for a, b in zip(S, reversed(S)):
if a != b:
count += 1
print(count // 2)
|
from collections import deque
n=int(input())
ab=[[] for _ in range(n+1)]
for i in range(n-1):
a,b=map(int,input().split())
ab[a].append([b,i])
que=deque()
que.append(1)
visited=[0]*(n)
ans=[0]*(n-1)
while que:
x=que.popleft()
k=1
for j in ab[x]:
if visited[x-1]!=k:
ans[j[1]]+=k
visited[j[0]-1]+=k
k+=1
que.append(j[0])
else:
ans[j[1]]+=(k+1)
visited[j[0]-1]+=(k+1)
k+=2
que.append(j[0])
print(max(ans))
for l in ans:
print(l)
| 0 | null | 128,202,550,238,630 | 261 | 272 |
K = int(input())
id = 1
cnt = 7
while cnt < K:
cnt = cnt * 10 + 7
id += 1
visited = [0] * K
while True:
remz = (cnt % K)
if remz == 0:
break
visited[remz] += 1
if visited[remz] > 1:
id = -1
break
cnt = remz * 10 + 7
id += 1
print(id)
|
def solve(l):
e = l.pop()
if e == '*':
return solve(l) * solve(l)
elif e == '+':
return solve(l) + solve(l)
elif e == '-':
return - solve(l) + solve(l)
else:
return int(e)
formula = input().split()
print(solve(formula))
| 0 | null | 3,037,462,867,960 | 97 | 18 |
def make_divisors(n):
div=[n]
for i in range(2,-int(-n**0.5//1)):
if n%i==0:
div.append(i)
div.append(n//i)
if n%(n**0.5)==0:
div.append(int(n**0.5))
div.sort()
return div
n=int(input())
if n>2:
ans=make_divisors(n-1)
else:
ans=[]
for i in make_divisors(n):
a=n
while a%i==0:
a=a//i
if a%i==1:
ans.append(i)
print(len(ans))
|
def Qc():
x, n = map(int, input().split())
if 0 < n:
p = list(map(int, input().split()))
for i in range(101):
if x - i not in p:
print(x - i)
exit()
if x + i not in p:
res = x + 1
print(x + i)
exit()
else:
# 整数列がなにもない場合は自分自身が含まれていない最近値になる
print(x)
exit()
if __name__ == "__main__":
Qc()
| 0 | null | 27,786,943,286,762 | 183 | 128 |
N = int(input())
li = list(map(int, input().split()))
an = 1
mi = li[0]
for i in range(1,N):
if mi >= li[i]:
an += 1
mi = li[i]
print(an)
|
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
C = input()
print(chr(ord(C) + 1))
if __name__ == '__main__':
main()
| 0 | null | 88,459,151,528,092 | 233 | 239 |
import sys
input = sys.stdin.readline
def main():
N = int(input())
A = list(map(int, input().split()))
mid = sum(A) / 2
x = 0
near_length = 0
for a in A:
x += a
if x >= mid:
if x - mid > abs(x - a - mid):
near_length = abs(x - a)
else:
near_length = x
break
ans = int(abs(mid-near_length) * 2)
print(ans)
if __name__ == "__main__":
main()
|
import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
def input():
return sys.stdin.readline().strip()
def main():
N = int(input())
A = list(map(int, input().split()))
cumsum = np.cumsum(A)
half = sum(A) // 2
ans = INF
for i in range(N - 1):
left = cumsum[i]
right = cumsum[-1] - cumsum[i]
cost = abs(half - left) + abs(right - half)
if cost < ans:
ans = cost
print(ans)
if __name__ == "__main__":
main()
| 1 | 141,772,027,692,580 | null | 276 | 276 |
#!/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(money - coins[i] + 1):
rec[j + coins[i]] = min(rec[j + coins[i]], rec[j] + 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[-1])
|
x, n = map(int, input().split())
p = list(map(int, input().split()))
n = list(i for i in range(-1, 110) if i not in p)
diff = 110
ans = 0
for i in n:
if diff > abs(x-i):
diff = abs(x-i)
ans = i
print(ans)
| 0 | null | 7,086,122,424,810 | 28 | 128 |
nn = int(input())
number_of_match = [0 for _ in range(10005)]
for xx in range(1,105):
xxxx = xx**2
for yy in range(1,105):
yyyy = yy**2
xxyy = xx*yy
for zz in range(1,105):
result = xxxx + yyyy + (zz)**2 + xxyy + (yy)*(zz) + (zz)*(xx)
if result < 10005:
number_of_match[result] += 1
for i in range(1,nn+1):
print(number_of_match[i])
|
import itertools
N = int(input())
tbl = [0]*N
for x in range(1,N):
for y in range(1,N):
for z in range(1,N):
p = x*x + y*y + z*z + x*y + y*z + z*x
if p > N:
break
tbl[p-1] += 1
for i in range(N):
print(tbl[i])
| 1 | 7,981,305,993,410 | null | 106 | 106 |
import math
while 1:
n = input()
if n == 0:
break
x = map(float,raw_input().split())
m = float(sum(x)/n)
s = 0
for i in x:
s += (i-m) ** 2
print math.sqrt(s/n)
|
N = int(input())
for i in range(N):
l = list(map(int,input().split()))
l.sort()
if l[0]*l[0]+l[1]*l[1] == l[2]*l[2]: print("YES")
else: print("NO")
| 0 | null | 95,439,297,278 | 31 | 4 |
import math
a = float(input())
area = a * a * math.pi
cir = (a * 2) * math.pi
print(area,cir)
|
# coding: utf-8
# Here your code !
import math
r = float(input())
print("{0:.7f} {1:.7f}".format((r ** 2) * math.pi,2 * math.pi * r))
| 1 | 637,318,405,580 | null | 46 | 46 |
n = int( raw_input( ) )
dic = {}
output = []
for i in range( n ):
cmd, word = raw_input( ).split( " " )
if "insert" == cmd:
dic[ word ] = True
elif "find" == cmd:
try:
dic[ word ]
output.append( "yes" )
except KeyError:
output.append( "no" )
print( "\n".join( output ) )
|
def main():
n = int(input())
d = set([])
for i in range(n):
command, string = input().split()
if (command == 'insert'):
d.add(string)
elif (command == 'find'):
if string in d:
print('yes')
else:
print('no')
if __name__ == "__main__":
main()
| 1 | 79,795,984,548 | null | 23 | 23 |
import math
a,b,h,m=map(int,input().split())
f=h / 12 * 360 - m / 60 * 360 + m / 60 / 12 * 360
theta=math.radians(f)
print(math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(theta)))
|
import math
a, b, h, m = map(int, input().split())
ang = h * 30 - m * 5.5
ans = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(ang)))
print(ans)
| 1 | 20,158,286,015,578 | null | 144 | 144 |
import math
a, b, c = map(int, input().split())
c = math.radians(c)
S = 1 / 2 * (a * b * math.sin(c))
c2 = math.sqrt(a*a + b*b - 2*a*b*math.cos(c))
H = a + b + c2
h = b * math.sin(c)
print(S,H,h)
|
import math
a,b,C = map(int,input().split())
C = math.radians(C)
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C))
S = 1/2*a*b*math.sin(C)
L = a+b+c
h = b * math.sin(C)
print('{0:.5f}\n{1:.5f}\n{2:.5f}'.format(S,L,h))
| 1 | 166,793,303,260 | null | 30 | 30 |
import sys
def input():
return sys.stdin.readline().rstrip()
def dfs(c, n, G, ans):
count = c
for i, flag in enumerate(G[n]):
if flag == 1 and ans[i][0] == 0:
count += 1
ans[i][0] = i + 1
ans[i][1] = count
ans[i][2] = dfs(count, i, G, ans)
count = ans[i][2]
else:
return count + 1
def main():
n = int(input())
G = [[0] * n for _ in range(n)]
ans = [[0] * 3 for _ in range(n)]
for i in range(n):
u, k, *v = map(int, input().split())
for j in range(k):
G[u-1][v[j]-1] = 1
count = 1
for i in range(n):
if ans[i][0] == 0:
ans[i][0] = i + 1
ans[i][1] = count
ans[i][2] = dfs(count, i, G, ans)
count = ans[i][2] + 1
for i in range(n):
print(*ans[i])
if __name__ == '__main__':
main()
|
def dfs():
tt = 0
for u in range(N):
if colors[u] == WHITE:
tt = dfs_visit(u, tt)
def dfs_visit(u, tt):
tt += 1
colors[u] = GLAY
d[u] = tt
for v in range(N):
if adjacency_list[u][v] == 1 and colors[v] == WHITE:
tt = dfs_visit(v, tt)
tt += 1
colors[u] = BLACK
f[u] = tt
return tt
N = int(input())
adjacency_list = [[0 for j in range(N)] for i in range(N)]
for _ in range(N):
u, k, *v = map(int, input().split())
for i in v:
adjacency_list[u-1][i-1] = 1
WHITE = 0
GLAY = 1
BLACK = 2
colors = [WHITE for _ in range(N)]
d = [0 for _ in range(N)]
f = [0 for _ in range(N)]
dfs()
for i in range(N):
print("{} {} {}".format(i+1, d[i], f[i]))
| 1 | 3,045,930,342 | null | 8 | 8 |
from sys import stdin
def ip(): return [int(i) for i in stdin.readline().split()]
def sp(): return [str(i) for i in stdin.readline().split()]
s = str(input())
c = 0
for i in s:
c += int(i)
if (c % 9) == 0: print("Yes")
else: print("No")
|
print('Yes' if '7' in input() else ('No'))
| 0 | null | 19,458,697,297,158 | 87 | 172 |
#!/usr/bin/env python3
from functools import reduce
mod = 10**9 + 7
n, k, *a = map(int, open(0).read().split())
a.sort(key=lambda x: abs(x))
ans = reduce(lambda a, b: (a * b) % mod, a[-k:])
c = a[-k:]
j = sum(i < 0 for i in c) % 2
if j:
c = a[-k:]
neg = [i for i in c if i < 0]
pos = [i for i in c if i > 0]
b = sorted(a[:n - k])
if b == []:
print(ans)
exit()
if neg == []:
if pos[0] * b[0] < 0:
ans = ans * pow(pos[0], mod - 2, mod) * b[0] % mod
else:
ans = reduce(lambda a, b: (a * b) % mod, a[:k])
elif pos == []:
if neg[0] * b[-1] < 0:
ans = ans * pow(neg[0], mod - 2, mod) * b[-1] % mod
else:
ans = reduce(lambda a, b: (a * b) % mod, a[:k])
elif pos[0] * b[-1] < neg[0] * b[0] and pos[0] * b[0] < 0:
ans = ans * pow(pos[0], mod - 2, mod) * b[0] % mod
elif 0 > b[-1] * neg[0]:
ans = ans * pow(neg[0], mod - 2, mod) * b[-1] % mod
else:
ans = reduce(lambda a, b: (a * b) % mod, a[:k])
print(ans)
|
#!/usr/bin/env python3
import sys
from itertools import chain
# floor(A x / B) - A * floor(x / B)
#
# x = B * x1 + x2 : (x2 < B) とする
#
# = floor(A (B*x1+x2) / B) - A floor((B*x1+x2) / B)
# = A x1 + floor(A x2 / B) - A x1
# = floor(A x2 / B)
def solve(A: int, B: int, N: int):
if N >= B:
x2 = B - 1
else:
x2 = N
return (A * x2) // B
def main():
tokens = chain(*(line.split() for line in sys.stdin))
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
N = int(next(tokens)) # type: int
answer = solve(A, B, N)
print(answer)
if __name__ == "__main__":
main()
| 0 | null | 18,709,942,404,750 | 112 | 161 |
X, Y = map(int, input().split())
Z = X * 4 - Y
if Z % 2 == 0 and X * 2 >= Z >= 0:
print('Yes')
else:
print('No')
|
N = int(input())
S = input()
ans = 0
for i in range(1000):
s = ["0", "0", "0"]
s[0] = str(i // 100)
s[1] = str((i//10) % 10)
s[2] = str(i % 10)
ind = 0
cnt = 0
while cnt < 3 and ind < N:
if S[ind] == s[cnt]:
cnt += 1
ind += 1
if cnt == 3:
ans += 1
print(ans)
| 0 | null | 71,446,304,702,010 | 127 | 267 |
N, K=input().split()
hp=input().split()
j = sorted([int(x) for x in hp])
print(sum([j[x] for x in range(int(N) - int(K))])) if int(K) < int(N) else print(0)
|
N, K = map(int, input().split())
H = sorted(list(map(int, input().split())))
print(sum(H[:N - K]) if not N <= K else 0)
| 1 | 79,049,645,899,170 | null | 227 | 227 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 + 7
factorial = [1]
inverse = [1]
for i in range(1, n+1):
factorial.append(factorial[-1] * i % mod)
inverse.append(pow(factorial[-1], mod - 2, mod))
def comb(n, r, mod):
if n < r or r < 0: return 0
elif r == 0: return 1
return factorial[n] * inverse[r] * inverse[n - r] % mod
a.sort()
mini = 0
for i in range(n-1):
mini += a[i] * comb(n-i-1, k-1, mod)
mini %= mod
a.sort(reverse=True)
maxi = 0
for i in range(n-1):
maxi += a[i] * comb(n-i-1, k-1, mod)
maxi %= mod
print((maxi-mini)%mod)
|
s=input()
num=ord(s)
print(chr(num+1))
| 0 | null | 93,823,500,581,238 | 242 | 239 |
ptn=["23542","14631",
"12651","15621",
"13641","32453"]
def rNO(d):
global ptn
for i,e in enumerate(ptn):
if d in e:
return i
return 0
dice = list(input().split(" "))
n = int(input())
for i in range(n):
q = input().split()
for i,e in enumerate(dice):
if e == q[0] :
q1 = i + 1
if e == q[1]:
q2 = i + 1
qq=str(q1) + str(q2)
ans = rNO(qq)
print(dice[ans])
|
def roll(i):
global u, s, e, w, n, d
if i == 'N':
u, s, n, d = s, d, u, n
elif i == 'E':
u, e, w, d = w, u, d, e
elif i == 'S':
u, s, n, d = n, u, d, s
elif i == 'W':
u, e, w, d = e, d, u, w
u, s, e, w, n, d = input().split()
q = int(input())
for i in range(q):
u1, s1 = input().split()
if u1 == s:
roll('N')
elif u1 == e:
roll('W')
elif u1 == w:
roll('E')
elif u1 == n:
roll('S')
elif u1 == d:
roll('N')
roll('N')
if s1 == s:
print(e)
elif s1 == e:
print(n)
elif s1 == n:
print(w)
elif s1 == w:
print(s)
| 1 | 251,280,491,868 | null | 34 | 34 |
n, m = map(int, input().split())
d = list(map(int, input().split()))
dp = [10000 for i in range(n + 1)]
dp[0] = 0
for i in range(0, n + 1):
if dp[i] < 10000:
for j in d:
if i + j <= n:
dp[i + j] = min(dp[i] + 1, dp[i + j])
print(dp[n])
|
#!/usr/bin/env python3
N, M, L = [int(s) for s in input().split()]
edge = [[int(s) for s in input().split()] for _ in range(M)]
dist = [[10 ** 10] * N for _ in range(N)]
graph = [[] for _ in range(N)]
Q = int(input())
for i, j, w in edge:
dist[i - 1][j - 1] = w
dist[j - 1][i - 1] = w
for k in range(N):
for i in range(N):
for j in range(N):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
for i in range(N):
for j in range(N):
dist[i][j] = 1 if dist[i][j] <= L else 10 ** 10
for k in range(N):
for i in range(N):
for j in range(N):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
for _ in range(Q):
s, t = [int(a) - 1 for a in input().split()]
print(dist[s][t] - 1 if dist[s][t] < 10**10 else -1)
| 0 | null | 86,664,916,141,220 | 28 | 295 |
import sys
input = sys.stdin.readline
def main():
N, K, S = map(int, input().split())
if S == 10 ** 9:
ans = [S] * K + [1] * (N - K)
else:
ans = [S] * K + [10 ** 9] * (N - K)
print(" ".join(map(str, ans)))
if __name__ == "__main__":
main()
|
n, k, s = map(int, input().split())
ans = []
if s == 10 ** 9:
ans = [1] * n
else:
ans = [10 ** 9] * n
for i in range(k):
ans[i] = s
for i in ans:
print(i)
| 1 | 90,922,251,369,440 | null | 238 | 238 |
S = input()
List1= []
List2 = []
n1 = 0
n2 = 0
for i in range(0,len(S),2):
List1.append(S[i])
for i in range(1,len(S),2):
List2.append(S[i])
n1 = List1.count("h")
n2 = List2.count("i")
if n1 == len(List1) and n2 == len(List2) and n1 == n2:
print("Yes")
else:
print("No")
|
def merge(a, left, mid, right):
INF = int(1e+11)
l = a[left:mid]
r = a[mid:right]
l.append(INF)
r.append(INF)
i = 0
j = 0
ans = 0
for k in range(left, right):
ans += 1
if l[i] <= r[j]:
a[k] = l[i]
i += 1
else:
a[k] = r[j]
j += 1
return ans
def merge_sort(a, left, right):
ans = 0
if left + 1 < right:
mid = (left + right) // 2
ans += merge_sort(a, left, mid)
ans += merge_sort(a, mid, right)
ans += merge(a, left, mid, right)
return ans
def print_list_split_whitespace(s):
for x in s[:-1]:
print(x, end=" ")
print(s[-1])
n = int(input())
s = [int(x) for x in input().split()]
ans = merge_sort(s, 0, len(s))
print_list_split_whitespace(s)
print(ans)
| 0 | null | 26,785,283,718,448 | 199 | 26 |
#!/usr/bin/env python3
import sys
from typing import NamedTuple, List
class Game(NamedTuple):
c: List[int]
s: List[List[int]]
def solve(D: int, c: "List[int]", s: "List[List[int]]", t: "List[int]"):
from functools import reduce
ans = [0]
lasts = [0] * 26
adjust = 0
sum_c = sum(c)
daily_loss = sum_c
for day, tt in enumerate(t, 1):
a = s[day-1][tt-1]
adjust += day * c[tt-1] - lasts[tt-1] * c[tt-1]
lasts[tt-1] = day
a -= daily_loss
a += adjust
ans.append(ans[-1]+a)
daily_loss += sum_c
return ans[1:]
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
D = int(next(tokens)) # type: int
c = [int(next(tokens)) for _ in range(26)] # type: "List[int]"
s = [[int(next(tokens)) for _ in range(26)] for _ in range(D)] # type: "List[List[int]]"
t = [int(next(tokens)) for _ in range(D)] # type: "List[int]"
print(*solve(D, c, s, t), sep="\n")
def test():
import doctest
doctest.testmod()
if __name__ == '__main__':
#test()
main()
|
D = int(input())
clist = list(map(int, input().split()))
slist = [list(map(int, input().split())) for _ in range(D)]
tlist = [int(input()) for _ in range(D)]
zlist = []
dlist = [0] * 26
ans = 0
'''
print(sum(clist))
print('--------------')
print(slist[0][0])
print(slist[1][16])
print(clist[16])
print('--------------')
'''
for i in range(D):
#print(slist[i],tlist[i]-1)
zlist.append(clist[tlist[i]-1] * ((i+1) - dlist[tlist[i]-1]))
dlist[tlist[i]-1] = i+1
ans += slist[i][tlist[i]-1] - ((i+1) * sum(clist)) + sum(zlist)
print(ans)
| 1 | 9,969,753,495,170 | null | 114 | 114 |
#B問題
ans = 0
n, k = map(int, input().split())
P = list(map(int, input().split()))
for i in range(k):
ans += min(P)
P.remove(min(P))
print(ans)
|
elements = input()
vector_1 = list(map(float,input().split()))
vector_2 = list(map(float,input().split()))
for i in range(1,4):
minkowski = sum([abs(a-b)**i for (a,b) in zip(vector_1,vector_2)])**(1/i)
print("{0:.7f}".format(minkowski))
minkowski_inf=max([abs(a-b) for (a,b) in zip(vector_1,vector_2)])
print("{0:.7f}".format(minkowski_inf))
| 0 | null | 5,897,579,482,608 | 120 | 32 |
n = int(input())
a = list(map(int, input().split()))
count = 1
for i in a:
if i == count:
count += 1
if count == 1:
print(-1)
else:
print(n - count + 1)
|
A, B = map(int, input().split())
print("{}".format(A*B if (A < 10 and B < 10) else -1))
| 0 | null | 136,771,378,559,828 | 257 | 286 |
n,m=map(int,input().split());a=sorted(map(int,input().split()),reverse=True)
print('NYoe s'[all([1 if i>=sum(a)/(4*m) else 0 for i in a[:m]])::2])
|
n,m =map(int,input().split())
a = list(map(int,input().split()))
cnt=0;s=0;
for i in range(n):
s += a[i]
for i in a:
if i *4*m>=s: cnt +=1
if cnt >= m:
print("Yes")
break
else:
print("No")
| 1 | 38,806,945,578,932 | null | 179 | 179 |
size = int(input())
element = list(map(int,input().split()))
print(" ".join(map(str,element)))
for i in range(1,len(element)):
v = element[i]
j = i-1
while j >=0 and element[j] > v:
element[j+1] = element[j]
j -=1
element[j+1] = v
print(" ".join(map(str,element)))
|
N=int(input())
arr=list(map(int,input().split()))
print(' '.join(map(str,arr)))
for key in range(1,len(arr)):
temp=arr[key]
i=key-1
while i>=0 and arr[i]>temp:
arr[i+1]=arr[i]
i-=1
arr[i+1]=temp
print(' '.join(map(str,arr)))
| 1 | 6,212,203,150 | null | 10 | 10 |
b=0
n=input()
for i in range(1, int(n)+1):
if i%3==0 and i%5==0:
a="FizzBuzz"
elif i%3==0:
a="Fizz"
elif i%5==0:
a="Buzz"
else:
b=b+i
print(b)
|
import numpy as np
def cumsum(x):
return list(np.cumsum(x))
def cumsum_number(N,K,x):
ans=[0]*(N-K+1)
number_cumsum = cumsum(x)
number_cumsum.insert(0,0)
for i in range(N-K+1):
ans[i]=number_cumsum[i+K]-number_cumsum[i]
return ans
"""
int #整数
float #小数
#for
for name in fruits: #fruitの頭から操作
print(name)
#リスト
list0 = [] #リスト生成
list0 = [1,2,3,4] #初期化
list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0]
list1= [i for i in range(10)] #>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list1 = list(map(int, input().split())) # 複数の入力をリストに入れる
number=[int(input()) for i in range(int(input()))] #複数行の入力をリストに
list1 = list1 + [6, 7, 8] #リストの追加
list2.append(34) #リストの追加 最後に()内が足される
list.insert(3,10) #リストの追加 任意の位置(追加したい位置,追加したい値)
len(list4) #リストの要素数
max(sa) #list saの最小値
list5.count(2) #リスト(文字列も可)内の2の数
list1.sort() #並び替え小さい順
list1.sort(reverse=True) #並び替え大きい順
set(list1) #list1内の重複している要素を削除し、小さい順に並べる
sum([2,3, ,3]) #リストの合計
abs(a) #aの絶対値
max(a,b) min(a,b) #最大値 最小値
text1 = text1.replace("34","test") #text1内の"34"を"test"に書き換える(文字列内の文字を入れ替える)
exit(0) #強制終了
cumsum(リスト) #累積和をリストで返す
cumsum_number(N,K,x) #N個の数が含まれるリストx内のK個からなる部分和をリストで返す
"""
N=int(input())
ans=0
for j in range(N):
if (j+1)%3!=0 and (j+1)%5!=0:
ans += j+1
print(ans)
| 1 | 34,806,558,348,332 | null | 173 | 173 |
md = list(map(int,input().split()))
mmd = list(map(int,input().split()))
if md[0] != mmd[0]:
print(1)
else:
print(0)
|
X, Y = map(int, input().split())
X1, Y1 = map(int, input().split())
if Y1 == 1:
print("1")
else:
print("0")
| 1 | 123,949,132,858,100 | null | 264 | 264 |
num_a = ord("A")
num_z = ord("Z")
N = int(input())
S = input()
ans = ""
for char in S:
tmp = N + ord(char)
if tmp > num_z:
ans += chr(tmp-26)
else:
ans += chr(tmp)
print(ans)
|
N = int(input())
S = input()
for s in S:
print(chr(65+(ord(s)+N-65)%26),end="")
| 1 | 134,421,316,350,452 | null | 271 | 271 |
s = input()
t = input()
c = 0
for i in range(len(s)):
if not s[i] == t[i]:
c += 1
print(c)
|
s=input()
t=input()
count=0
if s==t:
print(0)
else:
for i in range(0,len(s)):
if s[i]!=t[i]:
count+=1
print(count)
| 1 | 10,598,849,583,240 | null | 116 | 116 |
n = input()
d = [0 for i in range(n)]
f = [0 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
color = [0 for i in range(n)]
tt = [0]
WHITE = 0
GRAY = 1
BLACK = 2
def dfs_visit(u):
color[u] = GRAY
tt[0] = tt[0] + 1
d[u] = tt[0]
for v in range(n):
if M[u][v] == 0:
continue
if color[v] == WHITE:
dfs_visit(v)
color[u] == BLACK
tt[0] = tt[0] + 1
f[u] = tt[0]
def dfs():
for u in range(n):
if color[u] == WHITE:
dfs_visit(u)
for u in range(n):
print "%d %d %d" %(u + 1, d[u], f[u])
### MAIN
for i in range(n):
G = map(int, raw_input().split())
for j in range(G[1]):
M[G[0]-1][G[2+j]-1] = 1
dfs()
|
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
mod = 10**9+7
def comb(n, k):
c = 1
for i in range(k):
c *= n - i
c %= mod
d = 1
for i in range(1, k + 1):
d *= i
d %= mod
return (c * pow(d, mod - 2, mod)) % mod
x,y = map(int, input().split())
if (x + y) % 3 != 0:
print(0)
exit()
n = (x + y) // 3
x -= n
y -= n
if x < 0 or y < 0:
print(0)
exit()
print(comb(x + y, x))
| 0 | null | 74,806,304,095,972 | 8 | 281 |
from statistics import mean
import math
ans = []
while 1:
n = int(input())
if n == 0: break
l = list(map(int, input().split()))
m = mean(l)
print("{0:.8f}".format(math.sqrt(sum([(s - m) ** 2 for s in l]) / n)))
|
while True:
n=int(input())
if n==0:break
s=list(map(float,input().split()))
print((sum(map(lambda x: x*x,s))/n-(sum(s)/n)**2)**.5)
| 1 | 188,739,857,670 | null | 31 | 31 |
n, k = map(int,input().split())
w = [0]*n
for i in range(n):
w[i] = int(input())
minP = max(max(w), sum(w)//k)
maxP = sum(w)
left = minP
right = maxP
while left < right:
mid = (left + right) // 2
load = 0
cnt_track = 1
flag = 1
for i in range(n):
load += w[i]
if load > mid:
load = w[i]
cnt_track += 1
if cnt_track > k:
flag = 0
break
if flag:
right = mid
else:
left = mid + 1
print(left)
|
'''
Search - Allocation
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_D
Algorythm
Referenced #1670532 Solution for ALDS1_4_D: Allocation by Chris_Kobayashi
1. Decide the searching point -> (top of the range + bottom of the range) / 2
2. Check whether it is possible to load all of the luggage to the trugs
in the weight limit of the searching point
3. If it is possible, then move the top to the searching point
If it is impossible, then move the bottom to the searching point + 1
4. Continue 1~4 as long as the top is greater than bottom
Range
Serching the maximum loading capacity(MLC) number
between the maximam weight item num and the total weight num
top: total weight num
.
.
. <- search the num point
.
.
bottom: maximam weight item num
Why?
A1. Why not "bot = sp" but "bot = sp + 1"?
Q1. for example
top = 5
bot = 3
sp = (5 + 3) / 2 = 4
...
bot = sp
sp = (5 + 4) / 2 = 4
...
bot = sp
...for inf
A2. Why the top is total weight and bot is max weight?
Q2. Sure it is ok "top = 99999999, bot = 0".
But, MLC never pass the total weight
and the limit never be lower than the max.
So, it is the most effective range.
Note
1. This program contains the idea below
- Using "binary search" idea
- The appropriate range
2. To be the python program more fast
- Using int(raw_input()) instead of input()
- To rewrite the processings for the function is more fast
'''
# input
n, k = map(int,raw_input().split())
w = []
for i in xrange(n):
w.append(int(raw_input()))
def tempf(sp):
tk = 0 # temp index of the trugs
weight = 0 # temp total weight of a trug
# check whether it is possible to load all of the luggage
# to the trugs in the weight limit of the searching point
for tw in w:
if weight + tw <= sp:
weight += tw
else:
tk += 1
if tk >= k:
# when impossible, then raise the bottom
return False
weight = tw
else:
# when possible, then lowering the top
return True
# initial searching range
top = sum(w) # the top of the searching range
bot = max(w) # the bottom of the searching range
# searching until there is no serching range
while top > bot:
sp = (top + bot) / 2 # the searching point
if tempf(sp):
top = sp
else:
bot = sp + 1
# output MLC
print top
| 1 | 89,819,986,112 | null | 24 | 24 |
a, b = map(int, input().split())
d = a // b
r = a % b
f = float(a / b)
print('{0} {1} {2:0.5f}'.format(d, r, f))
|
x = input()
a, b = [int(z) for z in x.split()]
x = a // b
y = a % b
z = ('{:.5f}'.format(a / b))
print('{} {} {}'.format(x, y, z))
| 1 | 605,856,068,600 | null | 45 | 45 |
L, R, d = map(int,input().split())
ans = 0
while L <= R:
if L % d == 0:
ans += 1
L += 1
print(ans)
|
L,R,d = list(map(int, input().split()))
count = 0
for i in range(L,R+1):
count += (i%d == 0)
print(count)
| 1 | 7,633,792,281,760 | null | 104 | 104 |
X=int(input())
for i in range(1,180):
if (i*360%X==0):
print((i*360)//X)
exit()
|
# 入力
D, T, S = input().split()
# 以下に回答を記入
D = int(D)
T = int(T)
S = int(S)
if T * S >= D:
print('Yes')
else:
print('No')
| 0 | null | 8,395,036,254,190 | 125 | 81 |
import sys
X,Y = map(int,input().split())
if Y %2 == 1:
print("No")
sys.exit()
if (X * 2 <= Y) and (X * 4 >= Y):
print("Yes")
else:
print("No")
|
#!usr/bin/env python3
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations
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)
mod = 1000000007
def solve():
x = I()
if 599 >= x >= 400:
print(8)
elif 799 >= x >= 600:
print(7)
elif 999 >= x >= 800:
print(6)
elif 1199 >= x >= 1000:
print(5)
elif 1399 >= x >= 1200:
print(4)
elif 1599 >= x >= 1400:
print(3)
elif 1799 >= x >= 1600:
print(2)
elif 1999 >= x >= 1800:
print(1)
return
# Solve
if __name__ == "__main__":
solve()
| 0 | null | 10,290,809,634,940 | 127 | 100 |
import sys
input = sys.stdin.buffer.readline
import numpy as np
D = int(input())
c = np.array(input().split(), dtype=np.int32)
s = np.array([input().split() for _ in range(D)], dtype=np.int32)
last = np.zeros(26, dtype=np.int32)
ans = []
point = 0
for i in range(D):
down = (i+1-last)*c
loss = down * 3 + s[i,:]
idx = np.argmax(loss)
ans.append(idx+1)
point += s[i, idx] - down.sum()
last[idx] = i+1
for i in range(D):
print(ans[i])
|
import random
import time
def down_score(d, c, last_d, score):
sum = 0
for i in range(26):
sum = sum + c[i]*(d-last_d[i])
return int(score - sum)
def main():
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
start = time.time()
last_d = [0 for i in range(26)]
ans = []
score1 = 0
for i in range(D):
max = 0
idx = 0
for j in range(26):
if max < (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] != 0:
max = s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2
idx = j
elif max == (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] * (i-last_d[j])*(i-last_d[j]+1)/2 > c[idx]* (i-last_d[idx])*(i-last_d[idx]+1)/2 and c[j] != 0:
idx = j
last_d[idx] = i+1
score1 += s[i][idx]
score1 = down_score(i+1,c,last_d,score1)
ans.append(idx)
while time.time() - start < 1.9:
last_d = [0 for i in range(26)]
score2 = 0
tmp1 = 0
tmp2 = 1
tmp3 = 2
#2値入れ替え
if random.randint(0,1):
d1 = random.randint(0,D-35)
d2 = random.randint(d1+1,d1+17)
d3 = random.randint(d2+1,d2+17)
tmp1 = ans[d1]
tmp2 = ans[d2]
tmp3 = ans[d3]
if random.randint(0,1):
ans[d1] = tmp2
ans[d2] = tmp1
ans[d3] = tmp3
else:
ans[d1] = tmp1
ans[d2] = tmp3
ans[d3] = tmp2
#3値入れ替え
else:
d1 = random.randint(0,D-17)
d2 = random.randint(d1+1,d1+8)
d3 = random.randint(d2+1,d2+8)
tmp1 = ans[d1]
tmp2 = ans[d2]
tmp3 = ans[d3]
if random.randint(0,1):
ans[d1] = tmp2
ans[d2] = tmp3
ans[d3] = tmp1
else:
ans[d1] = tmp3
ans[d2] = tmp1
ans[d3] = tmp2
for i in range(D):
score2 += s[i][ans[i]]
last_d[ans[i]] = i+1
score2 = down_score(i+1, c, last_d, score2)
if score1 > score2:
ans[d1] = tmp1
ans[d2] = tmp2
ans[d3] = tmp3
else:
score1 = score2
for i in range(D):
print(ans[i]+1)
if __name__ == "__main__":
main()
"""
100762870
"""
| 1 | 9,724,219,552,050 | null | 113 | 113 |
import math
A, B, H, M = map(int, input().split())
print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(abs(30*H + 0.5*M - 6*M)))))
|
for x in range(9):
x = x + 1
for y in range(9):
y = y + 1
print(x.__str__() + 'x' + y.__str__() + '=' + (x * y).__str__() )
| 0 | null | 9,998,127,660,320 | 144 | 1 |
while(True):
h, w = map(int, input().split())
if w == 0 and h == 0:
break
print('#' * w)
for i in range(0, h - 2):
print('#' + '.' * (w - 2) + '#')
print('#' * w)
print()
|
while 1:
H, W=map(int, raw_input().split())
if H==0 and W==0:
break
for i in range(H):
L=list("#"*W)
if i==0 or i==(H-1):
s="".join(L)
print s
else:
for j in range(1, W-1):
L[j]="."
s="".join(L)
print s
print ""
| 1 | 822,702,999,346 | null | 50 | 50 |
N, P = map(int, input().split())
S = [int(s) for s in input()]
if P == 2 or P == 5:
print(sum(i for i, s in enumerate(S, 1) if s % P == 0))
quit()
C = [0] * P
tens = 1
cur = 0
for s in reversed(S):
cur = (cur + s * tens) % P
C[cur] += 1
tens = (tens * 10) % P
print(C[0] + sum(c * (c - 1) // 2 for c in C))
|
n, p = map(int, input().split())
s = input()
a = []
c = 0
if p == 2:
b = [0]*n
for i in range(n):
if int(s[i])%2 == 0:
b[i] += 1
for i in range(n):
if b[i] == 1:
c += i+1
elif p == 5:
b = [0]*n
for i in range(n):
if int(s[i])%5 == 0:
b[i] += 1
for i in range(n):
if b[i] == 1:
c += i+1
else:
b = [0]*p
b[0] = 1
d = [1]
a.append(int(s[-1])%p)
for i in range(n-1):
d.append(d[-1]*10%p)
for i in range(1, n):
a.append((int(s[-i-1])*d[i]+a[i-1])%p)
for i in range(n):
b[a[i]] += 1
for i in range(p):
c += int(b[i]*(b[i]-1)/2)
print(c)
| 1 | 58,313,979,272,688 | null | 205 | 205 |
def resolve():
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]
a = [0] * 100001
for i in A:
a[i] += i
ans = sum(a)
for b, c in BC:
if a[b] == 0:
print(ans)
continue
move = a[b] // b
a[b] = 0
a[c] += c * move
ans += (c - b) * move
print(ans)
if __name__ == "__main__":
resolve()
|
import collections
N=int(input())
A=list(map(int,input().split()))
X=collections.Counter(A)
Q=int(input())
ans=sum(A)
for i in range(Q):
B,C=map(int,input().split())
ans+=(C-B)*X[B]
print(ans)
X[C]+=X[B]
X[B]=0
| 1 | 12,218,838,942,794 | null | 122 | 122 |
g = list(input())
sum, d, r, p = 0, 0, 0, 0
f = 0
lake_list = []
for c in g:
if c == "\\":
if f == 0:
f, d, r = 1, 1, 1
else:
d += 1
r += (1 + (d-1))
elif c == "_":
if f == 1:
r += d
else:
if f == 1:
d -= 1
r += d
if d == 0:
f = 0
sum += r
lake_list.append([p, r])
r = 0
p += 1
d, r, p = 0, 0, len(g)-1
f = 0
g.reverse()
for c in g:
if c == "/":
if f == 0:
f, d, r = 1, 1, 1
pr = p
else:
d += 1
r += (1 + (d-1))
elif c == "_":
if f == 1:
r += d
else:
if f == 1:
d -= 1
r += d
if d == 0:
if [pr, r] not in lake_list:
sum += r
lake_list.append([pr, r])
f = 0
r = 0
p -= 1
lake_list.sort()
print(sum)
print(len(lake_list), end="")
i = 0
while i != len(lake_list):
print(" {}".format(lake_list[i][1]), end="")
i += 1
print()
|
s1 = [] #/????????????????????§??????????????????
s2 = [] #??????????°´??????????????¢??????[????????????\???????????????????°´??????????????¢???]?????¢??§????????§??????????????????
su = 0 #?????¢???
st = list(input()) #??\?????????????????????????´????????????????
for i in range(len(st)): #???????????????????????????????????£????????¢????¨????
if st[i] == '\\':
s1.append(i)
elif st[i] == '/' and len(s1) != 0:
left = s1.pop()
su += i - left
area = 0
while len(s2) != 0 and left < s2[-1][0]:
area += s2.pop()[1]
s2.append([left,area + i -left])
print(su)
print(' '.join([str(len(s2))] + [str(i[1]) for i in s2]))
| 1 | 59,585,209,532 | null | 21 | 21 |
def L():
return list(map(int, input().split()))
import math
[n,k]=L()
print(math.floor(math.log(n,k))+1)
|
def base10toK_base(num, K):
if num // K:
return base10toK_base(num//K, K) + str(num % K)
return str(num % K)
N, K = map(int, input().split())
ans = len(base10toK_base(N, K))
print(ans)
| 1 | 64,078,662,914,298 | null | 212 | 212 |
k, m = list(map(int, input().split()))
if 500 * k >= m:
print('Yes')
elif 500 * k < m:
print('No')
else:
print('No')
|
from collections import deque
n = int(input())
d = [-1]*n
d[0] = 0
M = []
for i in range(n):
adj = list(map(int,input().split()))
if adj[1] == 0:
M += [[]]
else:
M += [adj[2:]]
Q = deque([0])
while Q != deque([]):
u = Q.popleft()
for i in range(len(M[u])):
v = M[u][i]-1
if d[v] == -1:
d[v] = d[u] + 1
Q.append(v)
for i in range(n):
print(i+1,d[i])
| 0 | null | 49,315,839,111,072 | 244 | 9 |
def main():
N = int(input())
S = input()
print(S.count("ABC"))
if __name__ == "__main__":
main()
|
import itertools
n = int(input())
for i in itertools.count():
if (i * 1000) >= n:
break
print(i * 1000 - n)
| 0 | null | 53,619,947,225,594 | 245 | 108 |
n = int(input())
for i in range(1,10):
if n // i == n/i and n//i in range(1,10):
print('Yes')
break
else:
print('No')
|
a = list(set([i*j for i in range(1,10) for j in range(1, 10)]))
n = int(input())
print('Yes' if n in a else 'No')
| 1 | 159,291,527,888,900 | null | 287 | 287 |
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)]
print(*S,sep="")
"""
import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限
r = int(input())
print(r*r)
|
n = int(input())
txt = input()
print(txt[:n]+"..." if bool(txt[n:]) else txt)
| 0 | null | 82,555,578,042,938 | 278 | 143 |
def main():
a, b, c, d = map(int, input().split())
print(max(a*c, b*d, a*d, b*c))
main()
|
a,b = map(int,input().split())
d=(a-a%b)/b
r=a%b
f=a/b
print(f"{d} {r} {f:.5f}")
| 0 | null | 1,820,575,396,580 | 77 | 45 |
#!/usr/bin/env python3
a = list(map(int, input().split()))
if len(a) - len(set(a)) == 1:
print('Yes')
else:
print('No')
|
def resolve():
N = int(input())
if N % 2 == 1:
return print(0)
ans = 0
tmp = N // 2
while tmp:
tmp //= 5
ans += tmp
print(ans)
if __name__ == "__main__":
resolve()
| 0 | null | 92,614,472,542,060 | 216 | 258 |
N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
L = [[0 for i in range(S+1)] for j in range(N+1)]
L[0][0] = 1
for j, a in enumerate(A):
for i in range(S+1):
if i < a:
L[j+1][i] = (2 * L[j][i]) % mod
else:
L[j+1][i] = (2 * L[j][i] + L[j][i-a]) % mod
print(L[N][S])
|
nums = list(input().split())
for i, j in enumerate(nums):
if j == '0':
print(i+1)
| 0 | null | 15,597,533,521,450 | 138 | 126 |
x = int(input())
j = 8
for low in range(400, 2000, 200):
if low <= x < low + 200:
print(j)
break
j -= 1
|
s = input()
cnt = 0
if s == 'RSR':
cnt = 1
else:
for i in range(3):
if s[i] == 'R':
cnt += 1
print(cnt)
| 0 | null | 5,767,706,924,480 | 100 | 90 |
def check(k, W, p):
s = 0
count = 1
for w in W:
if s + w > p:
count += 1
s = 0
s += w
return count <= k
n, k = map(int, input().split())
W = [int(input()) for _ in range(n)]
right = sum(W)
left = max(right // k, max(W)) - 1
while right - left > 1:
p = (left + right) // 2
if check(k, W, p):
right = p
else:
left = p
print(right)
|
INF = 10**18
N,M = map(int,input().split())
C = list(map(int,input().split()))
dp = [INF for _ in range(N+1)]
dp[0] = 0
for i in range(M):
for j in range(N+1):
if j-C[i] >= 0:
dp[j] = min(dp[j],dp[j-C[i]]+1)
print(dp[N])
| 0 | null | 112,609,992,092 | 24 | 28 |
cnt = 0
def merge(A,left,mid,right):
'''n1 = mid - left
n2 = right - mid
L = []
R = []
for i in range(0,n1):
L.append(A[left+i])
for i in range(0,n2):
R.append(A[mid+i])
L.append(1000000001)
R.append(1000000001)
'''
L = A[left:mid]+[1000000001]
R = A[mid:right]+[1000000001]
i = 0
j = 0
global cnt
for k in range(left,right):
cnt += 1
if L[i] <= R[j]:
A[k]=L[i]
i += 1
else:
A[k] = R[j]
j += 1
def mergeSort(A,left,right):
if left+1 < right:
mid = (left+right)//2
mergeSort(A,left,mid)
mergeSort(A,mid,right)
merge(A,left,mid,right)
if __name__ == '__main__':
n = (int)(input())
a = list(map(int,input().split()))
mergeSort(a,0,n)
print(*a)
print(cnt)
|
INF = 10000000000
def merge(A,left,mid,right):
n1 = mid - left
n2 = right - mid
L = A[left:mid] + [INF]
R = A[mid:right] + [INF]
for i in range(n1):
L[i] = A[left + i]
for i in range(n2):
R[i] = A[mid + i]
i = 0
j = 0
cnt = 0
for k in range(left,right):
cnt += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return cnt
def mergeSort(A,left,right):
if left+1 < right:
mid = ( left + right ) // 2
cnt_l = mergeSort(A,left,mid)
cnt_r = mergeSort(A,mid,right)
return merge(A,left,mid,right)+cnt_l+cnt_r
return 0
if __name__ == '__main__':
num = int(input())
A = [int(i) for i in input().split()]
left = 0
right = len(A)
count = mergeSort(A,left,right)
print(" ".join(map(str,A)))
print(count)
| 1 | 112,339,598,930 | null | 26 | 26 |
from math import floor
A, B, N = map(int, input().split())
i = min(B - 1, N)
f_i = floor(A * i / B) - A * floor(i / B)
print(f_i)
|
A,B,N = map(int, input().split())
if N >= B:
ans = (A//B)*(B-1) + (A%B)*(B-1)//B
else:
ans = (A//B)*N + (A%B)*N//B
print(ans)
| 1 | 28,117,523,011,260 | null | 161 | 161 |
n = input()
m = len(n)
n = int(n)
if n%2==1:
print(0)
else:
if m==1:
print(0)
else:
ans = 0
i = 1
while True:
ans_plus=n//(2*5**i)
if ans_plus==0:
break
ans += ans_plus
i += 1
print(ans)
|
def main():
n = int(input())
if n % 2 == 0 and n >= 10:
m = n // 2
k = 5
m5 = 0
while k <= m:
m5 += m // k
k *= 5
else:
m5 = 0
print(m5)
if __name__ == '__main__':
main()
| 1 | 116,101,513,362,560 | null | 258 | 258 |
def gcd(a, b):
while b:
a, b = b, a % b
return a
def div_ceil(x, y): return (x + y - 1) // y
N, M = map(int, input().split())
*A, = map(int, input().split())
A = list(set([a // 2 for a in A]))
L = A[0]
for a in A[1:]:
L *= a // gcd(L, a)
for a in A:
if (L // a) % 2 == 0:
ans = 0
break
else:
ans = div_ceil(M // L, 2)
print(ans)
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
6
1 2 2 3
2 2 3 4
3 1 5
4 1 6
5 1 6
6 0
output:
1 1 12
2 2 11
3 3 8
4 9 10
5 4 7
6 5 6
"""
import sys
UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2
def dfs(v_init):
global timer
# init the first node of overall graph iterations(times >= 1)
stack = list()
stack.append(v_init)
d_time[v_init] += timer
# init end
while stack:
current = stack[-1]
v_table = adj_table[current]
visited[current] = VISITED_IN_STACK
# if adj is None, current's adj(s) have been all visited
adj = v_table.pop() if v_table else None
if adj:
if visited[adj] is UNVISITED:
visited[adj] = VISITED_IN_STACK
timer += 1
d_time[adj] += timer
stack.append(adj)
else:
stack.pop()
visited[current] = POPPED_OUT
timer += 1
f_time[current] += timer
return None
def dfs_init():
global timer
for v in range(v_num):
if visited[v + 1] == UNVISITED:
dfs(v + 1)
timer += 1
if __name__ == '__main__':
_input = sys.stdin.readlines()
v_num = int(_input[0])
vertices = map(lambda x: x.split(), _input[1:])
# config length = (v_num + 1)
# stack = []
visited = [UNVISITED] * (v_num + 1)
d_time, f_time = ([0] * (v_num + 1) for _ in range(2))
adj_table = tuple([] for _ in range(v_num + 1))
for v_info in vertices:
v_index, adj_num, *adj_list = map(int, v_info)
# assert len(adj_list) == adj_num
adj_table[v_index].extend(sorted(adj_list, reverse=True))
# timing start from 1
timer = 1
dfs_init()
for index, time_info in enumerate(zip(d_time[1:], f_time[1:]), 1):
print(index, *time_info)
| 0 | null | 51,169,367,582,368 | 247 | 8 |
n = int(input())
i = 1
ans = 0
while (i <= n):
total = sum(j for j in range(i, n+1, i))
ans += total
i += 1
print(ans)
|
N=1000;print(lambda f,n:f(f,n))(lambda f,n:n==0 and 100*N or(lambda x:x%N>0 and x-x%N+N or x)(f(f,n-1)*105/100),input())
| 0 | null | 5,548,686,946,268 | 118 | 6 |
A = int(input())
B = int(input())
abc = {1, 2, 3}
ab = {A, B}
print(list(abc-ab)[0])
|
from itertools import combinations as comb
def get_ans(m, n):
ans = 0
for nums in comb(list(range(1, min(m+1,n-2))), 3):
if sum(nums) == n:
ans += 1
print(ans)
while True:
m, n = (int(x) for x in input().split())
if m==0 and n==0:
quit()
get_ans(m, n)
| 0 | null | 55,829,474,235,030 | 254 | 58 |
X,Y=map(int,input().split())
b=0
for i in range(X+1):
if 4*(i)+2*(X-i)==Y:
b+=1
if not b==0:
print("Yes")
else:
print("No")
|
n = input()
print n*n*n
| 0 | null | 7,007,383,636,700 | 127 | 35 |
from collections import deque
n, m = map(int ,input().split())
graph = [[] for _ in range(n)]
for i in range(m):
a,b = map(int, input().split())
graph[a-1].append(b-1)
graph[b-1].append(a-1)
v = [0]*n
ans = 0
for i in range(n):
if v[i] == 0:
ans += 1
q = deque()
q.append(i)
v[i] = 1
while q:
node = q.popleft()
for j in graph[node]:
if v[j] == 0:
q.append(j)
v[j] = 1
print(ans-1)
|
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
class UnionFind:
def __init__(self, N: int):
"""
N:要素数
root:各要素の親要素の番号を格納するリスト.
ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.
rank:ランク
"""
self.N = N
self.root = [-1] * N
self.rank = [0] * N
def __repr__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def find(self, x: int):
"""頂点xの根を見つける"""
if self.root[x] < 0:
return x
else:
while self.root[x] >= 0:
x = self.root[x]
return x
def union(self, x: int, y: int):
"""x,yが属する木をunion"""
# 根を比較する
# すでに同じ木に属していた場合は何もしない.
# 違う木に属していた場合はrankを見てくっつける方を決める.
# rankが同じ時はrankを1増やす
x = self.find(x)
y = self.find(y)
if x == y:
return
elif self.rank[x] > self.rank[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rank[x] == self.rank[y]:
self.rank[y] += 1
def same(self, x: int, y: int):
"""xとyが同じグループに属するかどうか"""
return self.find(x) == self.find(y)
def count(self, x):
"""頂点xが属する木のサイズを返す"""
return - self.root[self.find(x)]
def members(self, x):
"""xが属する木の要素を列挙"""
_root = self.find(x)
return [i for i in range(self.N) if self.find == _root]
def roots(self):
"""森の根を列挙"""
return [i for i, x in enumerate(self.root) if x < 0]
def group_count(self):
"""連結成分の数"""
return len(self.roots())
def all_group_members(self):
"""{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す"""
return {r: self.members(r) for r in self.roots()}
N,M=MI()
uf=UnionFind(N)
for _ in range(M):
a,b=MI()
a-=1
b-=1
uf.union(a,b)
cnt=uf.group_count()
print(cnt-1)
main()
| 1 | 2,277,801,532,878 | null | 70 | 70 |
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
s=input()
lns=len(s)
lst=[0]*(lns+1)
start=[]
if s[0]=="<":
start.append(0)
for i in range(lns-1):
if s[i]==">" and s[i+1]=="<":
start.append(i+1)
if s[lns-1]==">":
start.append(lns)
for i in start:
d=deque([[i,0],[i,1]])
while d:
now,lr=d.popleft()
# print(now)
if now-1>=0 and lr==0 and s[now-1]==">":
lst[now-1]=max(lst[now-1],lst[now]+1)
d.append([now-1,0])
if now+1<=lns and lr==1 and s[now]=="<":
lst[now+1]=max(lst[now+1],lst[now]+1)
d.append([now+1,1])
# print(lst)
# print(start)
# print(lst)
print(sum(lst))
|
s=input()
n=len(s)
a=[0]*(n+1)
for i in range(n):
if s[i]=="<":
a[i+1]=a[i]+1
for i in reversed(range(n)):
if s[i]==">":
a[i]=max(a[i+1]+1,a[i])
print(sum(a))
| 1 | 156,712,753,572,292 | null | 285 | 285 |
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return map(int,input().split())
def onem(): #Nとかの取得
return int(input())
def s(x): #圧縮
a = []
if len(x) == 0:
return []
aa = x[0]
su = 1
for i in range(len(x)-1):
if aa != x[i+1]:
a.append([aa,su])
aa = x[i+1]
su = 1
else:
su += 1
a.append([aa,su])
return a
def jo(x): #listをスペースごとに分ける
return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
return max(map(max,x))
def In(x,a): #aがリスト(sorted)
k = bs.bisect_left(a,x)
if k != len(a) and a[k] == x:
return True
else:
return False
def pow_k(x, n):
ans = 1
while n:
if n % 2:
ans *= x
x *= x
n >>= 1
return ans
"""
def nibu(x,n,r):
ll = 0
rr = r
while True:
mid = (ll+rr)//2
if rr == mid:
return ll
if (ここに評価入れる):
rr = mid
else:
ll = mid+1
"""
n = onem()
a = l()
aa = [[a[i],i] for i in range(n)]
aa.sort(reverse = True)
dp = [[0 for i in range(n+1)] for j in range(n+1)]
for i in range(1,n+1):
on = aa[i-1]
for j in range(i+1):
if j-1 >= 0:
dp[i-j][j] = max(dp[i-j][j-1] + on[0] * abs(on[1] - (n-1 - (j - 1))),dp[i-j][j])
"""
if i == 1:
print(dp[i-j][j-1] + on[0] * abs(on[1] - j),dp[i-j][j])
"""
if i-j-1 >= 0:
#dp[i-j][j] = max(dp[i-j][j],dp[i-j-1][j] + on[0] * abs(on[1] - (n-1 - (i-j))))
dp[i-j][j] = max(dp[i-j][j],dp[i-j-1][j] + on[0] * abs(on[1] - (i-j-1)))
"""
if i == 1:
print(on,(n-1 - (i-j)),n-1,i-j)
print(dp[i-j-1][j],on[0] * abs(on[1] - (n-1 - (i-j))))
print(dp[i-j][j],dp[i-j-1][j] + on[0] * abs(on[1] - (i-j-1)))
"""
ma = 0
for i in range(n+1):
ma = max(ma,dp[n-i][i])
print(ma)
|
import sys
sys.setrecursionlimit(10**7)
def dfs(x):
if seen[x-1]==0:
uni[cnt].add(x)
seen[x-1]=1
for i in fri[x-1]:
dfs(i)
n,m,k=map(int,input().split())
fri=[[] for i in range(n)]
blk=[set() for i in range(n)]
for i in range(m):
a,b=map(int,input().split())
fri[a-1].append(b)
fri[b-1].append(a)
for i in range(k):
c,d=map(int,input().split())
blk[c-1].add(d)
blk[d-1].add(c)
seen=[0 for i in range(n)]
uni=[]
cnt=0
for i in range(1,n+1):
if seen[i-1]==0:
uni.append(set())
dfs(i)
cnt+=1
seq=[0 for i in range(n)]
for unii in uni:
for j in unii:
cj=len(unii)-len(fri[j-1])-len(unii&blk[j-1])-1
seq[j-1]=cj
print(*seq)
| 0 | null | 47,499,474,400,028 | 171 | 209 |
n = int(input())
mod=10**9+7
if n==1:
print(0)
else:
print(((10**n)-(9**n)-(9**n)+(8**n))%mod)
|
n = int(input())
mod = 10 ** 9 + 7
ans = (pow(10, n, mod) - pow(9, n, mod)) * 2 - (pow(10, n, mod) - pow(8, n, mod))
ans %= mod
print(ans)
| 1 | 3,208,163,614,644 | null | 78 | 78 |
n = int(input())
cif = [[0]*10 for i in range(10)]
for i in range(1, n+1):
s = str(i)
f = int(s[0])
r = int(s[-1])
cif[f][r] += 1
res = 0
for i in range(10):
for j in range(10):
res += cif[i][j]*cif[j][i]
print(res)
|
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools
sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
arr = []
temp = n
if n == 1:
return arr
for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
# a^n
def power(a, n, mod):
x = 1
while n:
if n & 1:
x *= a % mod
n >>= 1
a *= a % mod
return x % mod
# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
if n == 0:
return 1
a = n
tmp = n - 1
while (tmp >= l):
a = a * tmp % mod
tmp -= 1
return a
# Union Find
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = 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())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
# 約数生成
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
inf = 10 ** 18
mod = 10 ** 9 + 7
n,k = lr()
a = lr()
a.sort()
a1 = [0]
for num in a:
a1.append(a1[-1]+num)
def sumArea(l,r):
return a1[r]-a1[l]
N = n+1
inv_t = [0]+[1]
for i in range(2,N):
inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]
def moddiv(a, b):
return a*inv_t[b]%mod
if k == 1:
print(0)
sys.exit()
else:
ans = 0
cdp = [1 for i in range(n-k+1)]
for i in range(n-k):
cdp[i+1] = moddiv(cdp[i]*(k-1+i)%mod, i+1)
for i in range(k,n+1):
tmp = (sumArea(i-1,n)-sumArea(0,n-i+1))%mod
tmp = (tmp*cdp[i-k])%mod
ans = (ans+tmp)%mod
print(ans)
| 0 | null | 91,015,258,908,236 | 234 | 242 |
N = int(input())
A = [int(i) for i in input().split()]
def bubbleSort(A, N):
count = 0
flag = 1
while flag:
flag = 0
for i in range(N-1, 0, -1):
if A[i] < A[i-1]:
tmp = A[i]
A[i] = A[i-1]
A[i-1] = tmp
flag = 1
count += 1
return A, count
A, count = bubbleSort(A, N)
print(' '.join([str(i) for i in A]))
print(count)
|
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
a,b = input().split()
b = b[:-3] + b[-2:]
ans = int(a) * int(b)
ans = ans // 100
print(ans)
| 0 | null | 8,307,223,665,004 | 14 | 135 |
num500, total = map(int, input().split())
print('Yes' if num500 * 500 >= total else 'No')
|
import math
ans = 0
N,D = map(int,input().split())
for i in range(N):
x,y = map(int,input().split())
if math.sqrt(abs(x)**2 + abs(y)**2) <= D:
ans += 1
print(ans)
| 0 | null | 52,192,746,308,822 | 244 | 96 |
s=input()
n=len(s)
l=[[0,0] for i in range(n+1)]
ri,le=0,0
for i in range(n):
l[i][0]=le
l[-1-i][1]=ri
if "<"==s[i]:le+=1
else:le=0
if ">"==s[-1-i]:
ri+=1
else:ri=0
l[n][0]=le
l[0][1]=ri
print(sum(max(a,s) for a,s in l))
|
S=input()
N=len(S)
count=[0]*(N+1)
i=0
while i<N:
if S[i]=='<':
count[i+1]=count[i]+1
i+=1
S=S[::-1]
count=count[::-1]
i=0
while i<N:
if S[i]=='>':
count[i+1]=max(count[i+1],count[i]+1)
i+=1
print(sum(count))
| 1 | 157,025,614,916,320 | null | 285 | 285 |
N = int(input())
A = sorted(list(map(int,input().split())))
ans = A[0]
if ans == 0:
print(ans)
exit()
else:
for i in range(1,N):
ans = ans * A[i]
if ans > 10**18:
ans = -1
break
print(ans)
|
c=input()
o=ord(c)
o+=1
ans=chr(o)
print(ans)
| 0 | null | 53,969,036,055,488 | 134 | 239 |
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
IronMan = sorted(p)
CaptainAmerica = sorted(q)
for i in range(X):
r.append(IronMan.pop())
for i in range(Y):
r.append(CaptainAmerica.pop())
SpiderMan = sorted(r)[::-1]
print(sum(SpiderMan[:X+Y]))
|
# Next Alphabet
C = input()
from string import ascii_lowercase as alp
ans = alp[alp.index(C) + 1]
print(ans)
| 0 | null | 68,526,213,603,058 | 188 | 239 |
ab = [int(x) for x in input().split()]
a, b = ab[0], ab[1]
print(a // b)
print(a % b)
print("{0:f}".format(a / b))
|
x,y=map(int,raw_input().split())
print "%d %d %f" % (x/y,x%y,float(x)/y)
| 1 | 595,545,578,170 | null | 45 | 45 |
N ,D = map(int , input().split())
sum = 0
for i in range(N):
a,b = map(int , input().split())
if(((a ** 2 + b ** 2)**(1/2)) <= D):
sum += 1
print(sum)
|
def main():
N, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for a in A:
if (a[0]**2 + a[1]**2)**0.5 <= D:
cnt += 1
print(cnt)
if __name__ == '__main__':
main()
| 1 | 5,945,445,046,750 | null | 96 | 96 |
import sys
import bisect
import math
import itertools
# \n
def input():
return sys.stdin.readline().rstrip()
def dist(Z1, Z2):
x1, y1 = Z1
x2, y2 = Z2
return (x1 - x2) ** 2 + (y1 - y2) ** 2
def middle(X1, X2, X3):
x1, y1 = X1
x2, y2 = X2
x3, y3 = X3
alpha = x1 - x2
beta = y1 - y2
gamma = x2 - x3
delta = y2 - y3
div = (alpha * delta - beta * gamma) * 2
if div == 0:
return 60000, 60000
div = 1 / div
upper = x1 ** 2 + y1 ** 2 - x2 ** 2 - y2 ** 2
lower = x2 ** 2 + y2 ** 2 - x3 ** 2 - y3 ** 2
a = div * (delta * upper - beta * lower)
b = div * (-gamma * upper + alpha * lower)
return a, b
def main():
NN, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
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 ** 5 + 10
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)
sup = 0
inf = 0
for i in range(NN - K + 1):
c = cmb(NN-i-1, K - 1, mod)
inf += c*A[i]
inf %=mod
sup += c*A[-i-1]
sup %=mod
print((sup-inf)%mod )
if __name__ == "__main__":
main()
|
a,b = map(int,input().split())
import math
gc = math.gcd(a,b)
ans = int(a*b/gc)
print(ans)
| 0 | null | 104,863,791,579,140 | 242 | 256 |
import sys
line = input()
if(line[2]==line[3] and line[4]==line[5]):
print("Yes")
sys.exit()
print("No")
|
def resolve():
s = str(input())
if s[2]==s[3] and s[4]==s[5]:
print('Yes')
else:
print('No')
a = resolve()
| 1 | 41,937,458,386,768 | null | 184 | 184 |
import math
A,B,H,M = map(int,input().split())
t1 = (30*H+M/2)*math.pi/180
x1 = A*math.cos(t1)
y1 = A*math.sin(t1)
t2 = M*math.pi/30
x2 = B*math.cos(t2)
y2 = B*math.sin(t2)
d = ((x1-x2)**2+(y1-y2)**2)**0.5
print(d)
|
import math
A, B, H, M = list(map(lambda n: int(n), input().split(" ")))
thetaM = 6 * M
thetaH = 30 * H + 0.5 * M
theta = math.radians(180 - abs(abs(thetaH - thetaM) - 180))
print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(theta)))
| 1 | 20,011,577,802,790 | null | 144 | 144 |
while True:
try:
x = map(int, raw_input().split(' '))
if x[0] < x[1]:
m = x[1]
n = x[0]
else:
m = x[0]
n = x[1]
# m is greatrer than n
while n !=0:
m,n = n,m % n
print m,x[0]*x[1]/m
except EOFError:
break
|
#mathモジュールをインポートする
import math
try:
while True:
a,b = map(int,input().split())
#最小公約数
num1 = math.gcd(a,b)
#最大公倍数
num2 = int(a * b / num1)
print(str(num1) + " " + str(num2))
#EOFErrorをひろいコードを終了する
except EOFError:
pass
| 1 | 577,274,280 | null | 5 | 5 |
'''
Created on 2020/08/20
@author: harurun
'''
def main():
import itertools
import sys
pin=sys.stdin.readline
pout=sys.stdout.write
perr=sys.stderr.write
N=int(pin())
S=[]
T=[]
for _ in [0]*N:
s,t=pin().split()
S.append(s)
T.append(int(t))
U=list(itertools.accumulate(T))
X=pin()[:-1]
print(sum(T)-U[S.index(X)])
return
main()
|
n = int(input())
ans = 0
music = {}
for i in range(n):
a, b = input().split()
ans += int(b)
music[a] = ans
print(ans-music[input()])
| 1 | 97,010,794,276,698 | null | 243 | 243 |
def print_list(ele_list):
print(" ".join(map(str, ele_list)))
def insertion_sort(ele_list):
len_ele_list = len(ele_list)
print_list(ele_list)
for i in range(1, len_ele_list):
key = ele_list[i]
j = i - 1
while j >= 0 and ele_list[j] > key:
ele_list[j+1] = ele_list[j]
j -= 1
ele_list[j+1] = key
print_list(ele_list)
N = int(input())
ele_list = list(map(int, input().split()))
insertion_sort(ele_list)
|
def bubbleSort(A, N):
flag = 1
i = 0
swapnum = 0
while flag:
flag = 0
for j in range(N-1, i, -1):
if A[j] < A[j-1]:
temp = A[j-1]
A[j-1] = A[j]
A[j] = temp
swapnum += 1
flag = 1
i = i + 1
return swapnum
def showlist(A):
for i in range(len(A)):
if i==len(A)-1:
print(A[i])
else:
print(A[i], end=' ')
N = eval(input())
A = list(map(int, input().split()))
swapnum = bubbleSort(A, N)
showlist(A)
print(swapnum)
| 0 | null | 11,996,771,710 | 10 | 14 |
from collections import Counter
N, P = map(int, input().split())
Ss = input()
if P == 2 or P == 5:
ans = 0
for i, S in enumerate(Ss):
if int(S)%P == 0:
ans += i+1
else:
As = [0]
A = 0
D = 1
for S in Ss[::-1]:
S = int(S)
A = (A + S*D) % P
As.append(A)
D = D*10 % P
cnt = Counter()
ans = 0
for A in As:
ans += cnt[A]
cnt[A] += 1
print(ans)
|
def main():
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:
mods = [0] * P
mods[0] = 1
current = 0
x = 1
for s in S:
current = (current + x * int(s)) % P
ans += mods[current % P]
mods[current % P] += 1
x = x * 10 % P
print(ans)
if __name__ == '__main__':
main()
| 1 | 58,203,855,857,910 | null | 205 | 205 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.