code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
debt=100000
week=input()
for i in range(week):
debt=debt*1.05
if debt%1000!=0:
debt=int(debt/1000)*1000+1000
print debt
|
S=input()
N=len(S)+1
A=[0]*N
B=[0]*N
for k in range(N-1):
if S[k]=="<":
A[k+1]=A[k]+1
for k in range((N-1)-1,-1,-1):
if S[k]==">":
B[k]=B[k+1]+1
print(sum(map(lambda x:max(A[x],B[x]),range(N))))
| 0 | null | 78,342,944,080,730 | 6 | 285 |
import math
X = int(input())
V = 100
cnt = 0
while V < X:
V = V * 101 // 100
cnt += 1
print(cnt)
|
LARGE = 10 ** 9 + 7
def solve(n, k):
# singular cases
if k == 0:
return 1
elif k == 1:
return n * (n - 1)
# pow
pow_mod = [1] * (n + 1)
for i in range(n):
pow_mod[i + 1] = pow_mod[i] * (i + 1) % LARGE
pow_mod_inv = [1] * (n + 1)
pow_mod_inv[-1] = pow(pow_mod[-1], LARGE - 2, LARGE)
for i in range(n - 1, 0, -1):
pow_mod_inv[i] = pow_mod_inv[i + 1] * (i + 1) % LARGE
res = 0
for i in range(min(k, n - 1) + 1):
# find where to set 0
pick_zeros = pow_mod[n] * pow_mod_inv[i] * pow_mod_inv[n - i] % LARGE
# how to assign ones
assign_ones = pow_mod[n - 1] * pow_mod_inv[i] * pow_mod_inv[n - 1 - i] % LARGE
res += pick_zeros * assign_ones
res %= LARGE
return res
def main():
n, k = map(int, input().split())
res = solve(n, k)
print(res)
def test():
assert solve(3, 2) == 10
assert solve(200000, 1000000000) == 607923868
assert solve(15, 6) == 22583772
if __name__ == "__main__":
test()
main()
| 0 | null | 46,934,601,717,730 | 159 | 215 |
def resolve():
n,k = map(int,input().split())
print(min(n-k*(n//k),abs(n-k*(n//k)-k)))
resolve()
|
mod = 10 ** 9 + 7
x, y = map(int, input().split())
if (x + y) % 3 != 0 or x * 2 < y or y * 2 < x:
print(0)
exit()
l = [1]
for i in range(1, (x + y) // 3 + 100):
l.append(l[-1] * i % mod)
def comb(n, r, m):
return l[n] * pow(l[r], m - 2, m) * pow(l[n - r], m - 2, m) % m
a, b = y - (x + y) // 3, x - (x + y) // 3
print(comb(a + b, a, mod) % mod)
| 0 | null | 94,941,632,824,380 | 180 | 281 |
def resolve():
n, k = map(int,input().split())
a = 10**9+7
ans =0
for K in range(k,n+2):
ans += n*K - K**2 + K + 1
ans %= a
print(ans)
resolve()
|
N = int(input())
n = 0
if not N%2:
s = 5
N = N//2
while N>=s:
n += N//s
s *= 5
print(n)
| 0 | null | 74,299,690,674,282 | 170 | 258 |
h1,m1,h2,m2,k = list(map(int,input().split()))
h_m = (h2 - h1)*60
m = m2 - m1
tz = h_m + m
print(tz-k)
|
X,Y=map(int,input().split())
a=[]
for i in range(0,X+1):
if i*2+(X-i)*4==Y:
a.append('Yes')
else:
continue
if 'Yes' in a:
print('Yes')
else:
print('No')
| 0 | null | 15,895,167,617,120 | 139 | 127 |
n = int(input())
count = 0
if n%2==0:
for i in range(int(n/2)-1):
count += int((n-1)/(i+1))
count += int(n/2)
else:
for i in range(int(n/2)):
count += int((n-1)/(i+1))
count += int(n/2)
print(count)
|
W, H, x, y, r = map(int, input().split())
if x - r < 0:
#left
print("No")
elif x + r > W:
#right
print("No")
elif y - r < 0:
print("No")
elif y + r > H:
print("No")
else:
print("Yes")
| 0 | null | 1,539,438,729,180 | 73 | 41 |
a = list(map(int, input().split()))
HP = a[0]
x = []
for i in range(a[1]):
x1, y1 = [int(i) for i in input().split()]
x.append((x1, y1))
max_tup = max(x, key=lambda x: x[0]) #最高攻撃力の呪文を記憶
max_a = max_tup[0] #その攻撃力を記録
#1次元 横:与えるダメージ 中身:最小魔力
dp = [10**10] * (HP + max_a) #DP表はHP+最高攻撃力
dp[0] = 0
for i in range(1, len(dp)):
for a, b in x:
if i >= a:
dp[i] = min(dp[i],dp[i - a] + b )
print(min(dp[HP:]))
|
n=int(input())
s=input()
ans=0
for i in range(1000):
i=str(i).zfill(3)
a=0
for c in s:
if c==i[a]:
a+=1
if a==3:
ans+=1
break
print(ans)
| 0 | null | 104,713,009,974,470 | 229 | 267 |
n=int(input())
a=list(map(int,input().split()))
ans=float('inf')
s=sum(a)
res=0
for i in range(n):
res+=a[i]
s-=a[i]
ans=min(ans,abs(s-res))
print(ans)
|
N = int(input())
A = list(map(int, input().split()))
B = []
R = 0
L = sum(A)
for i in range(N):
B.append(abs(L-R))
R += A[i]
L -= A[i]
print(min(B))
| 1 | 142,070,290,084,470 | null | 276 | 276 |
S = int(input())
s = S%60
m = (S-s)/60%60
h = S/3600%24
answer = str(int(h))+":"+str(int(m))+":"+str(s)
print(answer)
|
s = input()
t = input()
ans = []
for i in range(0, len(s) - len(t) + 1):
score = 0
# sをtと同じ文字列分、切り取る
u = s[i:i + len(t)]
for j in range(len(t)):
# 切り取った文字列のsとtが同じかどうか比較する
if u[j] != t[j]:
score += 1
ans.append(score)
print(min(ans))
| 0 | null | 2,005,997,757,820 | 37 | 82 |
n,k=map(int,input().split())
a=list(map(int,input().split()))
current=[0]
dic={}
dic[0]=1
ans=0
for i in range(n):
current.append((current[-1]+a[i]-1)%k)
if i>=k-1:
dic[current[-k-1]]-=1
if current[-1] in dic:
ans+=dic[current[-1]]
dic[current[-1]]+=1
else:
dic[current[-1]]=1
print(ans)
|
from collections import defaultdict
import numpy as np
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
A = np.array(A)
A %= K
A = A.cumsum()
tmp = np.arange(N + 1)
B = (A - tmp) % K
ans = 0
d = defaultdict(int)
for i in range(min(K, N + 1)):
x = B[i]
ans += d[x]
d[x] += 1
if N > K:
for i in range(K, N + 1):
x = B[i]
y = B[i - K]
d[y] -= 1
ans += d[x]
d[x] += 1
print(ans)
| 1 | 137,958,022,172,220 | null | 273 | 273 |
def fibonacciDP(i):
if i == 0:
return 1
elif i == 1:
return 1
else:
if dp[i-1] is None and dp[i-2] is None:
dp[i-1] = fibonacciDP(i-1)
dp[i-2] = fibonacciDP(i-2)
elif dp[i-1] is None:
dp[i-1] = fibonacciDP(i-1)
elif dp[i-2] is None:
dp[i-2] = fibonacciDP(i-2)
return dp[i-1]+ dp[i-2]
def fibonacci(i):
if i == 0:
return 1
elif i == 1:
return 1
else:
return fibonacci(i-1)+fibonacci(i-2)
n = int(input())
dp = [None]*n
print(fibonacciDP(n))
|
n = int(input())
dp = [0 for _ in range(45)]
def fib_dp(n):
dp[0] = 1
dp[1] = 1
for i in range(2, n+1):
dp[i] = dp[i-1] + dp[i-2]
return dp[n]
print(fib_dp(n))
| 1 | 2,135,780,802 | null | 7 | 7 |
print((int(input())+1)//2)
|
N = int(input().rstrip())
r = (N + 1) / 2
print(int(r))
| 1 | 58,916,107,015,976 | null | 206 | 206 |
N = int(input())
A = [int(c) for c in input().split()]
l = [0]*N
for i in range(N):
l[A[i]-1] = i+1
print(' '.join(map(str, l)))
|
X = input()
ans = 'Yes' if int(X) >= 30 else 'No'
print(ans)
| 0 | null | 92,825,621,286,610 | 299 | 95 |
x = int(input())
if x == 2:
print(2)
exit()
for i in range(1000000):
for j in range(2, x+i):
if (x+i) % j == 0:
break
if j == x+i-1:
print(x+i)
exit()
|
from math import *
n=int(input())
f=0
for i in range(n,100009):
c=0
for j in range(1,i+1):
if(i%j==0):
c=c+1
if(c>=3):
break
if(c==2):
print(i)
f=1
exit()
| 1 | 105,363,802,821,400 | null | 250 | 250 |
n,m = map(int,input().split())
tbl=[[] for i in range(n)]
for i in range(n):
tbl[i] = list(map(int,input().split()))
tbl2=[[]*1 for i in range(m)]
for i in range(m):
tbl2[i] = int(input())
for k in range(n):
x=0
for l in range(m):
x +=tbl[k][l]*tbl2[l]
print("%d"%(x))
|
N, D, A = map(int, input().split())
X = [0] * N
for i in range(N):
x, h = map(int, input().split())
X[i] = (x, h)
X = sorted(X)
from collections import deque
q = deque()
ans = 0
total = 0
for i in range(N):
x, h = X[i]
while (len(q) > 0 and q[0][0] < x):
total -= q[0][1]
q.popleft()
h -= total
if h > 0:
num = (h + A - 1) // A
ans += num
damage = num * A
total += damage
q.append((x + 2 * D, damage))
print(ans)
| 0 | null | 41,913,543,846,706 | 56 | 230 |
h,a = map(int,input().split())
h -= 1
print(1 + h // a)
|
import math
H,A=map(int,input().split())
print(math.ceil(H/A))
| 1 | 76,989,938,226,690 | null | 225 | 225 |
from collections import deque
k = int(input())
count = 0
que = deque([1,2,3,4,5,6,7,8,9])
while que:
q = que.popleft()
count +=1
if count == k:
print(q)
exit()
tmp = q%10
if tmp == 0:
for i in range(0,2):
nq = q*10+i
que.append(nq)
elif tmp == 9:
for i in range(8,10):
nq = q*10+i
que.append(nq)
else:
for i in range(tmp-1, tmp+2):
nq = q * 10 + i
que.append(nq)
|
import sys
sys.setrecursionlimit(10000000)
def dfs(s):
if len(s)==11:
return
if s!="":
a.append(int(s))
for c in "0123456789":
if s=="" and c=="0":continue
if s!="":
if abs(ord(c)-ord(s[-1]))<=1:
dfs(s+c)
else:
dfs(s+c)
k=int(input())
a=[]
dfs("")
a=list(set(a))
a.sort()
print(a[k-1])
| 1 | 40,054,511,393,792 | null | 181 | 181 |
from collections import deque
n = int(input())
q = deque()
for i in range(n):
c = input()
if c[0] == 'i':
q.appendleft(c[7:])
elif c[6] == ' ':
try:
q.remove(c[7:])
except:
pass
elif c[6] == 'F':
q.popleft()
else:
q.pop()
print(*q)
|
X,N=map(int,input().split())
P=[int(x) for x in input().split()]
index=0
while(1):
if X-index not in P:
print(X-index)
break
if X+index not in P:
print(X+index)
break
index+=1
| 0 | null | 7,096,953,066,880 | 20 | 128 |
n, m = map(int, input().split())
*C, = map(int, input().split())
# n, m = 15, 6
# C = [1, 2, 7, 8, 12, 50]
# DP[i][j]=i種類以内でj円払う最小枚数
inf = 10**10
DP = [[inf for j in range(n+1)] for i in range(m+1)]
DP[0][0] = 0
for i in range(m):
for j in range(n+1):
if j < C[i]:
DP[i+1][j] = DP[i][j]
else:
DP[i+1][j] = min(DP[i][j], DP[i+1][j-C[i]]+1)
print(DP[m][n])
|
n=int(input())
m=10**12
for i in range(1,10**6+1):
if n%i==0:
m=min(m,i+(n//i))
print(m-2)
| 0 | null | 80,491,191,417,470 | 28 | 288 |
mtheight = []
for i in xrange(0,10):
mtheight.append(input())
mtheight.sort()
for i in xrange(0,3):
print mtheight[9 - i]
|
while True:
x,y = [int(i) for i in input().split()]
if x == 0 and y == 0:
break
if x>y:
print(str(y) + " " + str(x))
else:
print(str(x) + " " + str(y))
| 0 | null | 255,934,010,978 | 2 | 43 |
N, *A = map(int, open(0).read().split())
cur = 0
for i in range(N):
if A[i] == cur + 1:
cur += 1
if cur == 0:
print(-1)
else:
print(N - cur)
|
N = int(input())
A = list(map(int,input().split()))
B = [0]*N
for i in range(N):
B[A[i]-1] = i+1
print(" ".join(map(str,B)))
| 0 | null | 147,638,508,777,782 | 257 | 299 |
n = int(input())
R = [int(input()) for i in range(n)]
minv = float('inf')
maxv = -float('inf')
for r in R:
maxv = max(maxv, r-minv)
minv = min(minv, r)
print(maxv)
|
N = int(input())
es = [[] for _ in range(N)]
connected = [0] * N
for i in range(N-1):
a,b = map(int, input().split())
a,b = a-1, b-1
connected[a] += 1
connected[b] += 1
es[a].append((b, i))
es[b].append((a, i))
ans = [0] * (N-1)
used = [False] * (N-1)
q = []
q.append((0, 0))
while q:
curr, pc = q.pop()
nxt_es_color = 1
for nxt, es_num in es[curr]:
if used[es_num]:
continue
if nxt_es_color == pc:
nxt_es_color += 1
ans[es_num] = nxt_es_color
used[es_num] = True
q.append((nxt, ans[es_num]))
nxt_es_color += 1
print(max(connected))
print(*ans, sep="\n")
| 0 | null | 68,008,154,167,250 | 13 | 272 |
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
b = 0
tb = 0
for i in range(M):
if tb + B[i] > K:
break
tb += B[i]
b = i+1
ans = [0, b]
m = b
a = 0
ta = 0
for i in range(N):
if ta + A[i] > K:
break
a = i+1
ta += A[i]
while True:
if ta + tb > K:
if b == 0:break
b -= 1
tb -= B[b]
else:
if a + b > m:
m = a + b
ans = [a, b]
break
print(ans[0]+ans[1])
|
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,787,155,063,802 | null | 117 | 117 |
def resolve():
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x, y, c = [], [], []
dis = []
for i in range(M):
xt, yt, ct = list(map(int, input().split()))
dis.append(a[xt-1] + b[yt-1] - ct)
x.append(xt)
y.append(yt)
c.append(ct)
a.sort()
b.sort()
dis.sort()
ans = min(a[0] + b[0], dis[0])
print(ans)
return
resolve()
|
n=int(input())
if n%10==3:
print("bon")
elif n%10==0 or n%10==1 or n%10==6 or n%10==8:
print("pon")
else:
print("hon")
| 0 | null | 36,630,625,193,578 | 200 | 142 |
A, B = [int(_) for _ in input().split()]
aa = [int(i * 0.08) for i in range(1, 10000)]
bb = [int(i * 0.1) for i in range(1, 10000)]
for i, a, b in zip(range(1, 10000), aa, bb):
if (a, b) == (A, B):
print(i)
exit()
print(-1)
|
import math
a,b=map(int,input().split())
ast=math.ceil(a*12.5)
aend=math.ceil((a+1)*12.5)-1
bst=b*10
bend=(b+1)*10-1
flag=0
for i in range(bst,bend+1):
if ast<=i<=aend:
print(i)
flag=1
break
if flag==0:
print(-1)
| 1 | 56,530,771,667,596 | null | 203 | 203 |
def main():
A, B, C, K = map(int, input().split())
result = A if K >= A else K
K -= A
if K <= 0:
print(result)
return
K -= B
if K <= 0:
print(result)
return
result -= K
print(result)
main()
|
A, B, C, K = map(int, input().split())
# 1:A枚, 0:B枚, -1:C枚, K枚を選ぶ
A = min(A, K)
B = min(K - A, B)
C = min(K - A - B, C)
assert A + B + C >= K
#print(A, B, C)
print(A - C)
| 1 | 21,928,130,155,682 | null | 148 | 148 |
def counter(a, b, c):
count = 0
for n in range(a, b+1):
if c % n == 0:
count += 1
print(count)
a, b, c = list(map(int, input().split()))
counter(a, b, c)
|
"""
○ 角速度 = θ / t [rad/s]
・時針
ω = θ / t
= math.radians(360) / (12 * 60 * 60) [rad/s]
・分針
ω = θ / t
= math.radians(360) / (60 * 60) [rad/s]
"""
import math
def colon():
# 入力
A, B, H, M = map(int, input().split())
# 時針と分針の角速度
angular_velocity_h = math.radians(360) / (12 * 60 * 60)
angular_velocity_m = math.radians(360) / (60 * 60)
# 0時を基準に時針が何度傾いたか
radian_h = angular_velocity_h * ((H * 60 * 60) + (M * 60))
# 0時を基準に分針が何度傾いたか
radian_m = angular_velocity_m * (M * 60)
# 時針と分針の間の角度
radian_hm = abs(radian_h - radian_m)
if radian_hm > math.pi:
radian_hm = 2 * math.pi - radian_hm
elif radian_hm == math.pi:
return A + B
elif math.pi > radian_hm:
pass
# 端点の距離
distance = math.sqrt((A**2 + B**2) - (2 * A * B * math.cos(radian_hm)))
# 戻り値
return distance
result = colon()
print(result)
| 0 | null | 10,369,410,254,400 | 44 | 144 |
N = int(input())
X = list(map(int, input().split()))
HP = []
for p in range(1, 101, 1):
P = [p] * len(X)
delta = sum([(i - j) ** 2 for (i, j) in zip(X, P)])
HP.append(delta)
print(min(HP))
|
week = int(input())
debt = 100000
for i in range(week):
debt += debt * 0.05
thousand = int(debt / 1000)
coin = debt - thousand * 1000
if 0 < coin:
thousand += 1
debt = thousand * 1000
print(debt)
| 0 | null | 32,787,103,116,720 | 213 | 6 |
n, m = map(int, input().split())
a = map(int, input().split())
res = n - sum(a)
if res < 0:
print(-1)
else:
print(res)
|
import math
r = input()
s = r * r * math.pi
l = 2 * r * math.pi
print "%.6f %.6f" %(s, l)
| 0 | null | 16,303,914,918,270 | 168 | 46 |
A,B = map(int,input().split())
print(A*B,2*(A+B))
|
from collections import deque
import itertools
h, w = map(int, input().split())
g = [input() for _ in range(h)]
# x,yはスタートの座標
def bfs(x, y):
# 最初は全て未訪問なので-1で初期化
d = [[-1] * w for _ in range(h)]
# スタート地点への距離は0
d[x][y] = 0
q = deque([(x, y)])
while q:
tx, ty = q.popleft()
# 右、上、左、下
for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
nx, ny = tx + dx, ty + dy
# グリッドの範囲(縦方向, 横方向)内、通路(壁ではない)、未訪問(== -1)の場合
if 0 <= nx < h and 0 <= ny < w and g[nx][ny] == '.' and d[nx][ny] < 0:
d[nx][ny] = d[tx][ty] + 1
q.append((nx, ny))
# 最終的なdを平坦化して最大値を返す
return max(list(itertools.chain.from_iterable(d)))
# 全てのマスについて
max_count = 0
for x in range(h):
for y in range(w):
# スタートが通路であるかチェックする必要がある
if g[x][y] == ".":
max_count = max(max_count, bfs(x, y))
print(max_count)
| 0 | null | 47,449,173,357,180 | 36 | 241 |
import collections
MOD = 998244353
def main():
N = int(input())
D = [int(_) for _ in input().split()]
Dmax = max(D)
cc = collections.Counter(D)
if D[0] != 0: return 0
if cc[0] != 1: return 0
for i in range(Dmax+1):
if cc[i] == 0: return 0
output = 1
for i in sorted(cc.keys()):
if i in (0, 1): continue
output *= pow(cc[i-1], cc[i], MOD)
output %= MOD
return output
if __name__ == '__main__':
print(main())
|
import numpy as np
import sys
input = sys.stdin.readline
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
res = np.min(a) + np.min(b)
for i in range(M):
x,y,c = map(int,input().split())
x-=1
y-=1
res = min(res,(a[x]+b[y]-c))
print(res)
| 0 | null | 104,273,548,792,420 | 284 | 200 |
n,m=map(int,raw_input().split())
A=[]
b=[]
for i in range(n):
A.append(map(int,raw_input().split()))
for i in range(m):
b.append(input())
for i in range(n):
sum=0
for j in range(m):
sum+=A[i][j]*b[j]
print('%d'%sum)
|
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
N, K = map(int, readline().split())
digit = 0
cur = 0
while cur < N:
digit += 1
cur = K ** digit - 1
print(digit)
if __name__ == '__main__':
main()
| 0 | null | 32,838,786,390,340 | 56 | 212 |
while True:
H,W = map(int,raw_input().split())
if (H,W) == (0,0):
break
for k in range(H):
if k==0 or k==H-1:
print "#"*W
else:
print "#" + "." * (W-2) + "#"
print ""
|
while True:
h,w = map(int,raw_input().split())
if h == 0 and w == 0:
break
print "#" * w
for a in range(h-2):
print "#" + "."*(w-2) + "#"
print "#" * w
print ""
| 1 | 827,167,473,870 | null | 50 | 50 |
n = int(input())
X_MAX = 50001
for x in range(X_MAX):
if int(x * 1.08) == n:
print(x)
exit()
print(":(")
|
n = int(input())
from decimal import Decimal
def calc(n):
for i in range(60000):
if int(Decimal(i) * Decimal('1.08')) == n:
return i
return ':('
print(calc(n))
| 1 | 125,543,910,967,440 | null | 265 | 265 |
x = raw_input().split()
y = map(int,x)
a = y[0]
b = y[1]
c = a*b
d = (a+b)*2
print c, d
|
w,h = map(int, raw_input().split())
print(str(w*h) + ' ' + str((w+h)*2))
| 1 | 305,243,080,960 | null | 36 | 36 |
N,K=map(int,input().split())
*A,=map(int,input().split())
def C(x):
return sum([(A[i]-.5)//x for i in range(N)]) <= K
def binary_search2(func, n_min, n_max):
left,right=n_min,n_max
while right-left>1:
middle = (left+right)//2
y_middle = func(middle)
if y_middle: right=middle
else: left=middle
return right
print(binary_search2(C, 0, max(A)+1))
|
inp = [int(a) for a in input().split()]
X = inp[0]
N = inp[1]
if N == 0:
print(X)
else:
P = [int(b) for b in input().split()]
found = 0
num = 0
answer = X
while(found == 0):
if not (X - num in P):
found = 1
answer = X - num
elif not (X + num in P):
found = 1
answer = X + num
num += 1
print(answer)
| 0 | null | 10,203,931,801,892 | 99 | 128 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())
def main():
T1, T2 = in_nn()
A1, A2 = in_nn()
B1, B2 = in_nn()
if A1 > B1:
A1, B1 = B1, A1
A2, B2 = B2, A2
da1 = T1 * A1
da2 = T2 * A2
db1 = T1 * B1
db2 = T2 * B2
if da1 == db1:
if db1 == db2:
ans = "infinity"
else:
ans = 1
else:
if da1 + da2 == db1 + db2:
ans = "infinity"
elif da1 + da2 < db1 + db2:
ans = 0
else:
d1 = db1 - da1
d2 = (da1 + da2) - (db1 + db2)
ans = 1 + (d1 // d2) * 2
if d1 % d2 == 0:
ans -= 1
print(ans)
if __name__ == '__main__':
main()
|
# A - A?C
# 'ABC'には'ARC'を、'ARC'には'ABC'を返す
S = str(input())
if S == 'ABC':
print('ARC')
elif S == 'ARC':
print('ABC')
| 0 | null | 77,914,877,592,200 | 269 | 153 |
x=input()
if ((x>='A') and (x<='Z')):
print('A')
elif (x>='a') and (x<='z'):
print('a')
|
a = input()
if a >= 'a':
print("a")
else:
print("A")
| 1 | 11,376,791,786,878 | null | 119 | 119 |
a, b, c, d = map(int,input().split(" "))
Ns = [a*c, a*d, b*c, b*d]
print(sorted(Ns)[-1])
|
n = int(input())
A = [(a, i) for i, a in enumerate(map(int, input().split()))]
A.sort(reverse=True)
dp = [[0]*(n+1) for _ in range(n+1)]
ans = 0
for L in range(n+1):
for R in range(n+1):
if n <= L+R-1:
continue
a, i = A[L+R-1]
if 0 <= R-1:
dp[L][R] = max(dp[L][R], dp[L][R-1]+abs((n-R)-i)*a)
if 0 <= L-1:
dp[L][R] = max(dp[L][R], dp[L-1][R]+abs(i-(L-1))*a)
ans = max(ans, dp[L][R])
print(ans)
| 0 | null | 18,494,508,552,630 | 77 | 171 |
from _collections import deque
from _ast import Num
def parser():
while 1:
data = list(input().split(' '))
for number in data:
if len(number) > 0:
yield (number)
input_parser = parser()
def gw():
global input_parser
return next(input_parser)
def gi():
data = gw()
return int(data)
MOD = int(1e9 + 7)
import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/abc145/tasks/abc145_e
# E - All-you-can-eat
"""
DP1[i][j] =the maximum sum of deliciousness of dishes, which are chosen from 1st- to i-th dishes,
such that he can finish them in j minutes
still WA!!!
"""
t1 = gi()
t2 = gi()
a1 = gi()
a2 = gi()
b1 = gi()
b2 = gi()
if a1 < b1:
a1, b1 = b1, a1
a2, b2 = b2, a2
#print(a1, a2, b1, b2)
d1 = (a1 - b1) * t1
d2 = (a2 - b2) * t2
net = d1 + d2
def run():
if d1 == 0 or net == 0:
print('infinity')
return
elif net > 0:
print(0)
return
d = abs(net)
ans = 0
p2 = (d1 // d)
if (d1 % d == 0):
ans = 2 * p2
else:
ans = 2 * p2 + 1
print(ans)
run()
|
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from functools import reduce, lru_cache
import collections, heapq, itertools, bisect
import math, fractions
import sys, copy
sys.setrecursionlimit(1000000)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
def divisors(N):
divs = set([1, N])
i = 2
while i ** 2 <= N:
if N % i == 0:
divs.add(i)
divs.add(N//i)
i += 1
return sorted(list(divs))
def is_ok(N, K):
if K <= 1:
return False
while N % K == 0:
N //= K
return N % K == 1
def main():
N = I()
ans = 0
for divisor in divisors(N-1):
if is_ok(N, divisor):
ans += 1
for divisor in divisors(N):
if is_ok(N, divisor):
ans += 1
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 86,499,319,291,322 | 269 | 183 |
input_lists = list(input().split(' '))
result = [input_lists[-1]]
result += input_lists[0:-1]
result = ' '.join(result)
print(result)
|
from collections import deque
import sys
N, u, v = map(int, input().split())
u -= 1; v -= 1
edge = [[] for _ in range(N)]
for s in sys.stdin.readlines():
A, B = map(lambda x: int(x) - 1, s.split())
edge[A].append(B)
edge[B].append(A)
INF = float('inf')
# Aoki
pathV = [INF] * N
pathV[v] = 0
q = deque()
q.append((v, 0))
while q:
p, d = q.popleft()
nd = d + 1
for np in edge[p]:
if pathV[np] > nd:
pathV[np] = nd
q.append((np, nd))
# Takahashi
ans = 0
pathU = [INF] * N
pathU[u] = 0
q = deque()
q.append((u, 0))
while q:
p, d = q.popleft()
nd = d + 1
if len(edge[p]) == 1:
ans = max(ans, pathV[p] - 1)
for np in edge[p]:
if pathU[np] > nd and pathV[np] > nd:
pathU[np] = nd
q.append((np, nd))
print(ans)
| 0 | null | 78,022,863,897,498 | 178 | 259 |
import sys
# input = sys.stdin.buffer.readline
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getlist():
return list(map(int, input().split()))
import math
import bisect
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15
def main():
n, k = getlist()
nums = getlist()
acc = {0: [0]}
tmp = 0
for i, num in enumerate(nums):
tmp += num
tmp %= k
tgt = ((tmp - i -1 + k) % k)
if tgt not in acc:
acc[tgt] = [i+1]
else:
acc[tgt].append(i+1)
# acc.append(tmp-i-1)
# cnt = Counter(acc)
ans = 0
for v in acc.values():
for j, cur in enumerate(v):
ins = bisect.bisect_left(v, cur+k)
# print(ins, j)
ans += ins - j - 1
# ans += ((v-1) * v) // 2
# print(acc)
print(ans)
if __name__ == '__main__':
main()
"""
9999
3
2916
"""
|
import sys
def main():
input = sys.stdin.buffer.readline
n, m = map(int, input().split())
a_list = list(map(int, input().split()))
for a in a_list:
n -= a
if n < 0:
break
print(n if n >= 0 else -1)
if __name__ == '__main__':
main()
| 0 | null | 85,159,118,173,272 | 273 | 168 |
n = int(input())
t_p = 0
h_p = 0
for i in range(n):
taro, hana = [i for i in input().split()]
if taro > hana:
t_p += 3
elif taro == hana:
t_p += 1
h_p += 1
else:
h_p += 3
print(f'{t_p} {h_p}')
|
n=input()
if n=='ABC':
print('ARC')
else:
print('ABC')
| 0 | null | 13,090,186,846,268 | 67 | 153 |
from sys import stdin
from collections import deque
n = int(input())
d = [-1] * (n + 1)
G = [0] + [list(map(int, input().split()[2:])) for _ in range(n)]
d[1] = 0
dq = deque([1])
while len(dq) != 0:
v = dq.popleft()
for c in G[v]:
if d[c] == -1 :
d[c] = d[v] + 1
dq.append(c)
for i, x in enumerate(d[1:], start=1):
print(i, x)
|
n, a, b = map(int, input().split())
MOD = 10 ** 9 + 7
def nCk(n, k):
num = 1
for i in range(n, n - k, -1):
num *= i
num %= MOD
tmp = 1
for i in range(1, k + 1):
tmp *= i
tmp %= MOD
num *= pow(tmp, MOD - 2, MOD)
return num
ans = pow(2, n, MOD) - 1
ans -= nCk(n, a)
ans -= nCk(n, b)
print(ans % MOD)
| 0 | null | 33,152,294,268,240 | 9 | 214 |
k = int(input())
ans = "ACL" * k
print(ans)
|
N=int(input())
u="ACL"
print(u*N)
| 1 | 2,221,295,410,920 | null | 69 | 69 |
# l = open('input.txt').readline()
l = input()
k = 0
S1, S2 = [], []
for i in range(len(l)):
if l[i] == '\\':
S1.append(i)
elif l[i] == '/' and S1:
j = S1.pop()
a = i - j
k += i - j
while S2 and S2[-1][0] > j:
a += S2.pop()[1]
S2.append((j, a))
print(k)
print(len(S2), *(a for j, a in S2))
|
S=input()
sum_a = 0
index = []
area = []
pos = []
for i,s in enumerate(S):
if(s=="\\"):
index.append(i)
if(s=="/" and index):
tmp = i - index[-1]
sum_a += tmp
pop = index.pop()
while pos and pop < pos[-1]:
tmp += area.pop()
pos.pop()
pos += [pop]
area += [tmp]
print(sum_a)
print(len(area),*(area))
| 1 | 61,716,596,850 | null | 21 | 21 |
print('YNeos'[len({*input()})<2::2])
|
n,k=map(int,input().split())
a=list(map(int,input().split()))
town=[0]*n
info=[1]
now=1
while town[now-1]==0:
town[now-1]+=1
now=a[now-1]
info.append(now)
loop_list=list(info[info.index(now):-1])
loop_len=len(loop_list)
before_loop_list=list(info[:info.index(now)])
#print(town)
#print(info)
if k<len(before_loop_list):
print(before_loop_list[k])
else:
print(loop_list[((k-len(before_loop_list))%loop_len)])
| 0 | null | 38,976,310,752,092 | 201 | 150 |
def kaibun(lst):
k = len(lst)//2 + len(lst)%2
for i in range(1,k+1):
if lst[i-1] != lst[-i]:
return False
return True
S = list(input())
N = len(S)
if kaibun(S) and kaibun(S[:(N-1)//2]) and kaibun(S[(N+3)//2-1:]):
print('Yes')
else:
print('No')
|
n,t = map(int,input().split())
l = []
for i in range(n):
a,b = map(int,input().split())
l.append([a,b])
l.sort(key=lambda x:x[0])
dp = [[0 for i in range(t)] for i in range(n+1)]
al = []
for i in range(n):
a,b = l[i]
for j in range(t):
if dp[i][j] == 0:
if j == 0:
if j + a < t:
dp[i+1][j+a] = max(dp[i][j+a],b)
else:
al.append(b)
else:
if j + a < t:
dp[i+1][j+a] = max(dp[i][j+a],dp[i][j]+b)
else:
al.append(dp[i][j]+b)
dp[i+1][j] = max(dp[i+1][j],dp[i][j])
if len(al) > 0:
print(max(max(dp[n]),max(al)))
else:
print(max(dp[n]))
| 0 | null | 98,717,197,650,044 | 190 | 282 |
def main():
N, M = map(int, input().split())
C = list(map(int, input().split()))
INF = 10**10
"""
使い回さない方
dp = [[INF]*(N+1) for _ in range(M+1)]
dp[0][0] = 0
for i in range(M):
for y in range(N+1):
if C[i] > y:
dp[i+1][y] = dp[i][y]
else:
dp[i+1][y] = min(dp[i][y], dp[i+1][y-C[i]]+1)
print(min([dp[j][N] for j in range(1, M+1)]))
"""
""" 使い回す方 """
dp = [INF]*(N+1)
dp[0] = 0
for i in range(M):
for y in range(N+1):
if C[i] <= y:
dp[y] = min(dp[y], dp[y-C[i]]+1)
print(dp[N])
if __name__ == "__main__":
main()
|
n = str(input())
k = int(input())
l = len(n)
def f(dig, under, num):
if num > l - dig: return 0
if num == 0: return 1
if dig == l-1:
if under: return int(n[dig])
else: return 9
if under:
if n[dig] == '0':
res = f(dig+1, True, num)
#print(dig, under, num, res, 'aaa')
return res
else:
res = f(dig+1, False, num)
if int(n[dig]) > 1:
res += (int(n[dig])-1) * f(dig+1, False, num-1)
res += f(dig+1, True, num-1)
#print(dig, under, num, res, 'bbb')
return res
else:
res = f(dig+1, False, num)
res += 9 * f(dig+1, False, num-1)
#print(dig, under, num, res, 'ccc')
return res
ans = f(0, True, k)
print(ans)
| 0 | null | 38,161,005,299,620 | 28 | 224 |
N=int(input())
Ai=list(map(int,input().split()))
# ans=[]
ans=[0]*N
# for i in range(1,N+1):
# a=Ai.index(i)+1
# ans.append(str(a))
for i in range (N):
ans[Ai[i]-1]=str(i+1)
print(' '.join(ans))
|
#それぞれの桁を考えた時にその桁を一つ多めに払うのかちょうどで払うのかで場合分けする
n=[int(x) for x in list(input())]#それぞれの桁にアクセスするためにイテラブルにする
k=len(n)
#それぞれの桁を見ていくが、そのままと一つ多い状態から引く場合と二つあることに注意
dp=[[-1,-1] for _ in range(k)]
dp[0]=[min(1+(10-n[0]),n[0]),min(1+(10-n[0]-1),n[0]+1)]
for i in range(1,k):
dp[i]=[min(dp[i-1][1]+(10-n[i]),dp[i-1][0]+n[i]),min(dp[i-1][1]+(10-n[i]-1),dp[i-1][0]+n[i]+1)]
print(dp[k-1][0])
| 0 | null | 125,321,290,732,240 | 299 | 219 |
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]
counter = Counter(A)
counter_sum = sum(k*v for k, v in counter.items())
for b, c in BC:
counter[c] += counter[b]
counter_sum -= b * counter[b]
counter_sum += c * counter[b]
counter[b] = 0
print(counter_sum)
|
def main():
import sys
from collections import Counter
input = sys.stdin.readline
input()
a = Counter(map(int, input().split()))
ans = sum(k * v for k, v in a.items())
for _ in range(int(input())):
b, c = map(int, input().split())
if b in a:
ans += (c - b) * a[b]
print(ans)
a[c] = a[c] + a[b] if c in a else a[b]
del a[b]
else:
print(ans)
if __name__ == "__main__":
main()
| 1 | 12,296,200,158,738 | null | 122 | 122 |
a, b = map(int, input().split())
def base10to(n, b):
if (int(n/b)):
return base10to(int(n/b), b) + str(n%b)
return str(n%b)
print(len(base10to(a,b)))
|
#coding:utf-8
class Combination:
def __init__(self,N,P=10**9+7):
if N > 10**7:
self.fact = lambda x: x * self.fact(x-1) % P if x > 2 else 2
self.perm = lambda x, r: x * self.perm(x-1,r-1) % P if r > 0 else 1
self.cmb = lambda n,r: (self.perm(n,min(n-r,r)) * pow(self.fact(min(n-r,r)) ,P-2 ,P) % P) if r > 0 else 1
else:
self.__fact = [1] * (N+1)
self.__inv = [1] * (N+1)
self.__inv_fact = [1] * (N+1)
for i in range(2,N+1):
self.__fact[i] = self.__fact[i-1] * i % P
self.__inv[i] = - self.__inv[P%i] * (P//i) % P
self.__inv_fact[i] = self.__inv_fact[i-1] * self.__inv[i] % P
self.fact = lambda n: self.__fact[n]
self.perm = lambda n,r: self.__fact[n] * self.__inv_fact[n-r] % P
self.cmb = lambda n,r: (self.__fact[n] * self.__inv_fact[n-r] * self.__inv_fact[r] % P) if r > 0 else 1
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
input = lambda: given().rstrip()
LMIIS = lambda: list(map(int,input().split()))
II = lambda: int(input())
XLMIIS = lambda x: [LMIIS() for _ in range(x)]
YN = lambda c : print('Yes') if c else print('No')
MOD = 10**9+7
from collections import deque
n,k = LMIIS()
cmb = Combination(2*n)
ans = 1
for i in range(1,min(n,k+1)):
ans = (ans + cmb.cmb(n,i) * cmb.cmb(n-1,i)) % MOD
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 65,757,812,976,672 | 212 | 215 |
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import itertools
def main():
n = int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
permutations = list(itertools.permutations(range(1,n+1)))
a = permutations.index(P)
b = permutations.index(Q)
print(abs(a-b))
if __name__=="__main__":
main()
|
d,t,s=list(map(int,input().split()))
if(t*s<d):
print("No")
else:
print("Yes")
| 0 | null | 51,806,163,332,782 | 246 | 81 |
# 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():
h, w, k = list(map(int,ipti().split()))
s = [list(input()) for i in range(h)]
empty_row = []
exist_row = []
berry_id = 1
for row in range(h):
is_empty = True
for col in range(w):
if s[row][col] == "#":
s[row][col] = berry_id
berry_id += 1
is_empty = False
if is_empty:
empty_row.append(row)
else:
exist_row.append(row)
# まず空ではない行を埋める
for row in range(h):
if row in exist_row:
berry_col = deque()
for col in range(w):
if s[row][col] != ".":
berry_col.append(col)
first = 0
fill_id = 0
while berry_col:
last = berry_col.popleft()
fill_id = s[row][last]
for j in range(first, last+1):
s[row][j] =fill_id
first = last + 1
for j in range(first, w):
s[row][j] = fill_id
for row in empty_row:
is_filled = False
for row2 in range(row+1, h):
if row2 in exist_row:
for col in range(w):
s[row][col] = s[row2][col]
is_filled = True
break
if not is_filled:
for row2 in range(row-1, -1 , -1):
if row2 in exist_row:
for col in range(w):
s[row][col] = s[row2][col]
is_filled = True
break
for row in range(h):
print(*s[row])
if __name__ == '__main__':
main()
|
import bisect
H,W,K=map(int,input().split())
s=[""]*H
ans=[[0]*W for _ in range(H)]
St=[0]*H#i行目にイチゴがあるか?
St2=[]
for i in range(H):
s[i]=input()
if "#" in s[i]:
St[i]=1
St2.append(i)
a=1
#i行目,aからスタートして埋める
for i in range(H):
if St[i]==1:
flag=0
for j in range(W):
if s[i][j]=="#":
if flag==0:
flag=1
else:
a+=1
ans[i][j]=a
a+=1
for i in range(H):
k=bisect.bisect_left(St2,i)
#近いところを参照したいけど参照したいけど,端での処理が面倒
if k!=0:
k-=1
if St[i]==0:
ans[i]=ans[St2[k]]
for i in range(H):
print(" ".join(map(str, ans[i])))
| 1 | 143,308,896,159,780 | null | 277 | 277 |
from sys import stdin
for l in stdin:
a,b=map(int,l.split())
print(len(str(a+b)))
|
import math
digit = []
while True:
try:
a,b =raw_input().split()
c = int(a)+int(b)
digit.append(int(math.log10(c) + 1))
except:
break
for i in range(0,len(digit)):
print digit[i]
| 1 | 119,588,282 | null | 3 | 3 |
A, B = map(int, input().split())
lb_a = int(-(-A // 0.08))
ub_a = int(-(-(A + 1) // 0.08) - 1)
lb_b = int(-(-B // 0.1))
ub_b = int(-(-(B + 1) // 0.1) - 1)
if ub_b < lb_a or ub_a < lb_b:
print(-1)
else:
print(max(lb_a, lb_b))
|
A, B = [int(i) for i in input().split()]
# たかだか1250円
for i in range(1300):
a = (i * 8) // 100
b = i //10
if A == a and B == b:
print(i)
exit()
print(-1)
| 1 | 56,402,712,781,910 | null | 203 | 203 |
N, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
s = 0
for i in h:
if i >= k:
s += 1
print(s)
|
n, k = map(int, input().split(' '))
h = list(map(int, input().split(' ')))
ans = 0
for i in h:
if i >= k:
ans += 1
print(ans)
| 1 | 178,575,700,589,688 | null | 298 | 298 |
x, k, d = map(int, input().split())
cur = x
numTimes = x // d
if numTimes == 0:
cur -= d
k -= 1
else:
numTimes = min(abs(numTimes), k)
if x < 0:
numTimes *= -1
cur -= numTimes * d
k -= numTimes
if k % 2 == 0:
print(abs(cur))
else:
result = min(abs(cur - d), abs(cur + d))
print(result)
|
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]))
| 0 | null | 2,647,650,901,142 | 92 | 21 |
print(-int(input())%1000)
|
import math
n = int(input())
if n%1000 == 0:
print(0)
else:
print(1000 - n%1000)
| 1 | 8,400,344,235,518 | null | 108 | 108 |
N = int(input())
syougen = [ [] for _ in range(N) ]
for i in range(N):
num = int(input())
for j in range(num):
x, y = map(int, input().split())
syougen[i].append([x, y])
#print(syougen)
ans = 0
for bit in range(1 << N):
break_flag = 0
for i in range(N):
if (bit >> i) & 1:
for j in range(len(syougen[i])):
if ((bit>>(syougen[i][j][0]-1))&1) != syougen[i][j][1]:
break_flag = 1
break
if break_flag == 1:
break
if i == N-1:
ans = max(ans, bin(bit).count("1"))
print(ans)
|
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
#import random
def I():
return int(input())
def MI():
return map(int,input().split())
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i)-1 for i in input().split()]
def StoI():
return [ord(i)-97 for i in input()]
def ItoS(nn):
return chr(nn+97)
def show(*inp,end='\n'):
if show_flg:
print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()
show_flg=False
#show_flg=True
n,m=LI()
## Segment Tree ##
## Initializer Template ##
# Range Sum: sg=SegTree(n,0)
# Range Minimum: sg=SegTree(n,inf,min,inf)
class SegTree:
def __init__(self,n,init_val=0,function=lambda a,b:a+b,ide=0):
self.n=n
self.ide_ele=ide_ele=ide
self.num=num=2**(n-1).bit_length()
self.seg=seg=[self.ide_ele]*2*self.num
self.segfun=segfun=function
#set_val
for i in range(n):
self.seg[i+self.num-1]=init_val
#built
for i in range(self.num-2,-1,-1) :
self.seg[i]=self.segfun(self.seg[2*i+1],self.seg[2*i+2])
def update(self,k,x):
k += self.num-1
self.seg[k] = x
while k:
k = (k-1)//2
self.seg[k] = self.segfun(self.seg[k*2+1],self.seg[k*2+2])
def query(self,p,q):
if q<=p:
return self.ide_ele
p += self.num-1
q += self.num-2
res=self.ide_ele
while q-p>1:
if p&1 == 0:
res = self.segfun(res,self.seg[p])
if q&1 == 1:
res = self.segfun(res,self.seg[q])
q -= 1
p = p//2
q = (q-1)//2
if p == q:
res = self.segfun(res,self.seg[p])
else:
res = self.segfun(self.segfun(res,self.seg[p]),self.seg[q])
return res
def __str__(self):
# 生配列を表示
rt=self.seg[self.num-1:self.num-1+self.n]
return str(rt)
s=[int(i) for i in input()]
def dp(b,m): # N log (N)
N=len(b)-1
n=N+1
sg=SegTree(n,inf,min,inf)
sg.update(0,0)
dp=[0]+[inf]*(N)
for i in range(N):
if b[i+1]==1:
continue
dp[i+1]=sg.query(max(i-m+1,0),i+1)+1
sg.update(i+1,dp[i+1])
#show(seg)
show(sg)
return dp
dp1=dp(s,m)
step=dp1[n]
if step==inf:
print(-1)
exit()
dp2=dp(s[::-1],m)[::-1]
show(dp1,'dp1')
move=[0]
ans=[]
j=1
for i in range(step,0,-1): # N
while j<=n and dp2[j]!=i-1:
j+=1
move.append(j)
for i in range(len(move)-1):
ans.append(move[i+1]-move[i])
print(*ans)
| 0 | null | 130,294,137,445,378 | 262 | 274 |
import collections
n = int(input())
num_list = list(map(int, input().split()))
all = 0
c = collections.Counter(num_list)
for i in c:
all += c[i]*(c[i]-1)//2
for k in range(n):
print(all - c[num_list[k]] + 1)
|
import collections
N=int(input())
A=list(map(int,input().split()))
B=collections.Counter(A)
C=sum([x*(x-1)//2 for x in B.values()])
for i in A:
temp=B[i]
print(C-(temp*(temp-1)//2-(temp-1)*(temp-2)//2))
| 1 | 47,835,712,666,392 | null | 192 | 192 |
#(身長)ー(番号)=ー(身長)ー(番号)はありえない、身長=0にならないから
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
AB = defaultdict(int)
_AB = defaultdict(int)
for i,a in enumerate(A):
AB[i+1+A[i]]+=1
_AB[-A[i]+i+1]+=1
ans = 0
for key,val in AB.items():
ans += val*_AB[key]
print(ans)
|
import collections
cc = collections.Counter()
count = 0
n = raw_input()
for i,e in enumerate(map(int, raw_input().split())):
count += cc[e - i]
cc[-e- i] +=1
print count
| 1 | 25,858,128,710,742 | null | 157 | 157 |
import sys
def solve(a, b):
for i in range(1, 10000):
if int(i * 0.08) == a and int(i * 0.1) == b:
return i
return -1
def main():
input = sys.stdin.buffer.readline
a, b = map(int, input().split())
print(solve(a, b))
if __name__ == "__main__":
main()
|
a,b = map(int,input().split())
if a%2 == 0:
a_list = [int(a/0.08) + i for i in range(13)]
else:
a_list = [int(a/0.08) + i for i in range(1,13)]
b_list = [int(b/0.1) + j for j in range(10)]
com = set(a_list) & set(b_list)
if len(com) == 0:
print(-1)
elif len(com) != 0:
if int(min(com)*0.08) != a or int(min(com)*0.1) != b:
print(-1)
else:
print(min(com))
| 1 | 56,375,145,777,114 | null | 203 | 203 |
N=int(input())
A=list(map(int,input().split()))
total=sum(A)
cost=total
cumulative=0
for i in range(N):
cumulative+=A[i]
cost=min(cost,abs(cumulative-(total-cumulative)))
print(cost)
|
N=int(input())
A=list(map(int,input().split()))
ans=0
tree=1
node=sum(A)
flag=0
for i in A:
ans+=i
node-=i
if i>tree:
ans=-1
break
tree-=i
if tree<node:
ans+=tree
else:
ans+=node
tree=2*tree
print(ans)
| 0 | null | 80,131,890,060,028 | 276 | 141 |
given = input()
target = given*2
keyword = input()
if keyword in target:
print("Yes")
else:
print("No")
|
print((lambda x,y:'Yes'if y in x else'No')(input()*2,input()))
| 1 | 1,763,397,864,466 | null | 64 | 64 |
s = input()
left_index = []
puddles = []
for i in range(len(s)):
if s[i] == "\\":
left_index.append(i)
elif s[i] == "/" and len(left_index) > 0:
left = left_index.pop()
puddle = i - left
while len(puddles) > 0 and puddles[-1][0] > left:
puddle += puddles.pop()[1]
puddles.append([left, puddle])
ans = [p[1] for p in puddles]
print(sum(ans))
if len(ans): print(len(ans), " ".join(map(str, ans)))
else : print(len(ans))
|
# -*- coding: utf-8 -*-
# ALDS1_3_D_Areas on the Cross-Section Diagram
from collections import deque
def make_h_list(slope):
"""
入力データから高さのリストを作る
"""
h_list =deque([0])
for s in slope:
d = 0
if s == "\\":
d = -1
elif s == "/":
d = 1
h_list.append(h_list[-1] + d)
return h_list
def trim_edge(h_list, left=True):
"""
水溜りの境界を探す
"""
if left:
while h_list:
h = h_list.popleft()
if h not in h_list:
continue
if h_list[0] - h < 0:
h_list.appendleft(h)
return h_list
else:
while h_list:
h = h_list.pop()
if h not in h_list:
continue
if h_list[-1] - h < 0:
h_list.append(h)
return h_list
def make_w_list(h_list):
"""
水たまりのリストを作る
"""
w_list = []
water = []
h_list = trim_edge(h_list)
while h_list:
h = h_list.popleft()
if not water:
water.append(h)
elif water[0] == h:
water.append(h)
w_list.append(water)
water = []
h_list.appendleft(h)
h_list = trim_edge(h_list)
else:
water.append(h)
if water[0] < water[-1]:
water.pop(0)
return w_list
def calc_area(water):
"""
面積計算
"""
h = water[0]
s = 0
for i in range(len(water) - 1):
s += (water[i+1] - h) + (water[i+1] - water[i]) / 2
return abs(int(s))
in_data = str(input())
h_list = make_h_list(in_data)
h_list = trim_edge(h_list, left=False)
if type(h_list) != None:
w_list = make_w_list(h_list)
a_list = [calc_area(water) for water in w_list]
else:
a_list = []
print(sum(a_list))
print(len(a_list), *a_list)
| 1 | 55,756,127,168 | null | 21 | 21 |
i=1
for i in range(9):
i+=1
print(f'1x{i}={1*i}')
for i in range(9):
i+=1
print(f'2x{i}={2*i}')
for i in range(9):
i+=1
print(f'3x{i}={3*i}')
for i in range(9):
i+=1
print(f'4x{i}={4*i}')
for i in range(9):
i+=1
print(f'5x{i}={5*i}')
for i in range(9):
i+=1
print(f'6x{i}={6*i}')
for i in range(9):
i+=1
print(f'7x{i}={7*i}')
for i in range(9):
i+=1
print(f'8x{i}={8*i}')
for i in range(9):
i+=1
print(f'9x{i}={9*i}')
|
def multi():
for i in range(1, 10):
for j in range(1, 10):
print(str(i) + "x" + str(j) + "=" + str(i * j))
if __name__ == '__main__':
multi()
| 1 | 76,960 | null | 1 | 1 |
k=int(input())
print("ACL"*k)
|
n = int(input())
word = 'ACL'
print(word * n)
| 1 | 2,191,215,165,490 | null | 69 | 69 |
moto = input()
num = int(input())
for i in range(num):
order = input().split()
if order[0] == "print":
m,n=int(order[1]),int(order[2])
print(moto[m:n+1])
elif order[0] == "reverse":
m,n=int(order[1]),int(order[2])
moto = moto[:m]+moto[m:n+1][::-1]+moto[n+1:]
elif order[0] == "replace":
m,n,l=int(order[1]),int(order[2]),order[3]
moto = moto[:m]+order[3]+moto[n+1:]
|
m=str(raw_input())
n=[int(i) for i in m]
n.insert(0,0)
l=len(n)
ans=0
for i in range(l-1,-1,-1):
current=n[i]
if(current<5):
ans+=current
elif(current==5):
ans+=current
if(n[i-1]>=5):
n[i-1]+=1
else:
ans+=10-current
n[i-1]+=1
print ans
| 0 | null | 36,601,925,686,820 | 68 | 219 |
N = int(input())
cnt = 0
for a in range(1, N):
for b in range(a, N, a):
cnt += 1
print(cnt)
|
import re
def find_a_word(w, t):
list = []
for e in map(lambda x: re.split(r'\s|,|\.', x.lower()), t):
list.extend(e)
return list.count(w.lower())
if __name__ == '__main__':
w = input()
t = []
while True:
i = input()
if i == 'END_OF_TEXT':
break
else:
t.append(i)
print(find_a_word(w, t))
| 0 | null | 2,215,126,007,722 | 73 | 65 |
import numpy as np
a,b,h,m = map(int,input().split())
pos1 = [b*np.sin(np.radians(6*m)),b*np.cos(np.radians(6*m))]
pos2 = [a*np.sin(np.radians(30*h+m*(360/(12*60)))),a*np.cos((np.radians(30*h+m*(360/(12*60)))))]
d = ((pos1[0]-pos2[0])**2+(pos1[1]-pos2[1])**2)**0.5
print(d)
#print(pos1)
#print(pos2)
|
import math
rad = math.pi/180
A, B, H, M = map(int, input().split())
x = 6*M*rad
y = (60*H + M) * 0.5 * rad
print(math.sqrt(A**2 + B**2 -2*A*B*math.cos(x-y)))
| 1 | 20,233,944,420,832 | null | 144 | 144 |
# -*- coding: utf-8 -*-
def main():
S = input()
week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
for i, name in enumerate(week):
if name == S:
ans = 7 - i
print(ans)
if __name__ == "__main__":
main()
|
A, B = input().split()
C = B + A
print(C)
| 0 | null | 117,771,102,972,682 | 270 | 248 |
x = int(input())
dp = [0]*200000
for j in range(6):
dp[100+j] += 1
def max_sum():
global dp
for i in range(x):
if dp[i] > 0:
for j in range(6):
dp[i+100+j] += 1
return
max_sum()
print(min(dp[x], 1))
|
N,K=map(int,input().split())
P=list(map(lambda x: (int(x)+1)/2,input().split()))
s=tmp=sum(P[:K])
for i in range(K,N):
tmp=tmp-P[i-K]+P[i]
s=max(s,tmp)
print(s)
| 0 | null | 101,016,207,140,240 | 266 | 223 |
n,k,c = map(int, input().split())
s = input()
# 計算途中はi=0~n-1日とする
# [a,b] i日までで、限界まで働くとa回働けてb日まで働けない
pre = [[0,0] for i in range(n)]
if s[0]=='o':
pre[0]=[1,c]
for j in range(c):
if 1+j < n:
pre[1+j] = pre[0] + []
for i in range(1,n):
if pre[i]==[0,0]:
if s[i]=='o':
pre[i][0]=pre[i-1][0]+1
pre[i][1]+=i+c
for j in range(c):
if i+j+1<n:
pre[i+j+1]=pre[i]+[]
else:
pre[i]=pre[i-1]+[]
# i日以降で限界まで働くとa回働ける
post = [0 for i in range(n)]
if s[-1]=='o':
post[-1]=1
for j in range(c):
if 0 <= n-1-j-1 < n:
post[-1-j-1] = post[-1]
for i in range(1,n):
if post[n-i-1]==0:
if s[n-i-1]=='o':
post[n-i-1]=post[n-i]+1
for j in range(c):
if 0<=n-i-1-j-1<n:
post[n-i-1-j-1]=post[n-i-1]
else:
post[n-i-1]=post[n-i]
# 0日、n+1日を追加。iを1~n日にする
pre = [[0,0]]+pre+[[0,0]]
post = [0]+post+[0]
# i日に休んだときに、働く回数がkに到達するか調べる
ans = []
for i in range(1,n+1):
if s[i-1]=='o':
work, rest = pre[i-1]
day = min(max(rest,i)+1,n+1)
work = work + post[day]
if work<k:
ans.append(i)
for i in range(len(ans)):
print(ans[i])
|
a,b,m = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
disc = [[]]*m
for i in range(m):
disc[i] = list(map(int,input().split()))
mina = 100000
minb = 100000
for i in range(a):
mina = min(mina,al[i])
for i in range(b):
minb = min(minb,bl[i])
total = mina+minb
for i in range(m):
total = min(total,al[disc[i][0]-1]+bl[disc[i][1]-1]-disc[i][2])
print(total)
| 0 | null | 47,288,109,228,448 | 182 | 200 |
a = int(input())
ans = "Yes" if a>= 30 else "No"
print(ans)
|
s = int(input())
if s >= 30:
print("Yes")
else:
print("No")
| 1 | 5,767,809,926,912 | null | 95 | 95 |
from collections import defaultdict
n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
s = [0] * (n + 1)
for i in range(n):
s[i + 1] = (s[i] + a[i]) % k
mp = defaultdict(int)
ans = 0
for i in range(n + 1):
ans += mp[s[i]]
mp[s[i]] += 1
if i >= k - 1:
mp[s[i - k + 1]] -= 1
print(ans)
|
N = int(input())
if N % 1000 == 0:
ans = 0
else:
ans = 1000 - (N % 1000)
print(ans)
| 0 | null | 73,263,592,837,020 | 273 | 108 |
def resolve():
N = int(input())
g = {}
edges_to_idx = {}
edges = []
for i in range(N-1):
a, b = list(map(int, input().split()))
g.setdefault(a-1, [])
g[a-1].append(b-1)
g.setdefault(b-1, [])
g[b-1].append(a-1)
edges_to_idx.setdefault("{}-{}".format(a-1, b-1), i)
edges_to_idx.setdefault("{}-{}".format(b-1, a-1), i)
edges.append((a-1, b-1))
nodes = [(None, 0)]
colors = [None for _ in range(N-1)]
maxdeg = 0
while nodes:
prevcol, node = nodes.pop()
maxdeg = max(maxdeg, len(g[node]))
idx = 0
for col in range(1, len(g[node])+1):
if col == prevcol:
continue
nxt = g[node][idx]
coloridx = edges_to_idx["{}-{}".format(node, nxt)]
if colors[coloridx] is not None:
idx += 1
if idx >= len(g[node]):
break
nxt = g[node][idx]
coloridx = edges_to_idx["{}-{}".format(node, nxt)]
colors[coloridx] = col
nodes.append((col, nxt))
idx += 1
if idx >= len(g[node]):
break
print(maxdeg)
for col in colors:
print(col)
if '__main__' == __name__:
resolve()
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
def dfs(curr, pare, pare_c, k, color_dic):
curr_c = pare_c
for chi in g[curr]:
if chi == pare: continue
curr_c = curr_c%k + 1
color_dic[(curr,chi)] = curr_c
dfs(chi, curr, curr_c, k, color_dic)
n = int(input())
g = [ [] for _ in range(n+1)]
gl = []
for i in range(n-1):
a, b = map(int, input().split())
g[a].append(b)
g[b].append(a)
gl.append((a,b))
k = 0
for node in g:
k = max(len(node),k)
color_dic = {}
dfs(1, -1, 0, k, color_dic)
print(k)
for edge in gl:
print(color_dic[edge])
| 1 | 136,229,577,353,168 | null | 272 | 272 |
n=input()
print':'.join(map(str,[n/3600,n%3600/60,n%60]))
|
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,m = inpl()
s = list(input())[::-1]
res = []
now = 0
while now != n:
nex = min(now + m, n)
while s[nex] == '1':
nex -= 1
if nex == now:
print(-1)
quit()
res += [nex - now]
now = nex
print(*res[::-1])
| 0 | null | 69,848,968,335,572 | 37 | 274 |
n, k = map(int, input().split())
ans = 0
for i in range(k, n+2):
l = (i*(i-1))*0.5
h = (i*(2*n-i+1))*0.5
ans += (h-l+1)
print(int(ans) % (10**9+7))
|
n,k=map(int,input().split())
M=[n]*(n+1)
m=[0]*(n+1)
for i in range(1,n+1):
M[i]=M[i-1]+n-i
m[i]=m[i-1]+i
mod=10**9+7
ans=0
for i in range(k-1,n+1):
tmp=M[i]-m[i]+1
ans=(ans+tmp)%mod
ans=ans%mod
print(ans)
| 1 | 33,280,080,011,040 | null | 170 | 170 |
if __name__ == "__main__":
n, m = map(int, input().split())
c = list(map(int, input().split()))
c = sorted(c)
dp = [[0] * (n + 1)] * m
for i in range(n + 1):
dp[0][i] = i
for i in range(1, m):
for j in range(n + 1):
dp[i][j] = dp[i - 1][j]
if j - c[i] >= 0:
dp[i][j] = min(dp[i][j], dp[i][j - c[i]] + 1)
print(dp[m-1][n])
|
import sys,collections
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
Ac = collections.Counter(A)
def num_combi2(n):
combi = n*(n-1)//2
return combi
def sub_combi2(n):
c_before = n*(n-1)//2
c_after =(n-1)*(n-2)//2
return c_after - c_before
all_combi = 0
for val in Ac.values():
all_combi += num_combi2(val)
for i in range(N):
print(all_combi + sub_combi2(Ac[A[i]]))
| 0 | null | 23,831,339,829,700 | 28 | 192 |
import math
import numpy as np
N = int(input())
ARR = list(map(int,input().split()))
def calculate(n,arr):
maxValue = max(arr)
if maxValue == 0:
maxNum = 1
else:
maxNum = math.ceil(math.log(maxValue,2))
arr = np.array(arr)
oneArray = [0]*(maxNum+1)
zeroArray = [0]*(maxNum+1)
for i in range(maxNum+1):
s = (arr >> i) & 1
a = np.count_nonzero(s)
oneArray[i] = a
zeroArray[i] = n - a
finalResult = 0
for i in range(maxNum + 1):
finalResult += 2**i * oneArray[i] * zeroArray[i]
print(finalResult % (10**9 + 7))
calculate(N, ARR)
|
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
B=[[] for i in range(n)]
for i in range(n):
B[i]= [((A[i]>>(59-j))) & 1 for j in range(60)]
B[i] = [0]*(60-len(B[i]))+B[i]
TB=[[0]*n for i in range(60)]
for i in range(60):
TB[i] = [B[j][i] for j in range(n)]
# import numpy as np
#print(TB)
ans=0
for i in range(60):
now=TB[i]
q=sum(now)
ans+= ((pow(2,59-i,mod)* (q*(n-q)))%mod)%mod
ans%=mod
print((ans)%mod)
| 1 | 123,058,677,432,528 | null | 263 | 263 |
a,b,m = map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
x = []
y = []
c = []
for i in range(m):
xs,ys,cs = map(int,input().split())
x.append(xs)
y.append(ys)
c.append(cs)
ans1 = 10**10
for j in range(m):
if ans1 >= a[x[j]-1] + b[y[j]-1] - c[j]:
ans1 = a[x[j]-1] + b[y[j]-1] - c[j]
ans2 = min(a)+min(b)
print(min(ans1,ans2))
|
n, m = map(int, input().split())
mat = [map(int,input().split()) for i in range(n)]
vec = [int(input()) for i in range(m)]
for row in mat:
print(sum([a*b for (a,b) in zip(row, vec)]))
| 0 | null | 27,634,574,681,138 | 200 | 56 |
N = int(input())
A = [0]*N
B = [0]*N
for i in range(N): A[i],B[i] = map(int,input().split())
A.sort()
B.sort()
sorted_A = A
sorted_B = B
if N % 2 != 0:
center_A = sorted_A[N//2]
center_B = sorted_B[N//2]
print(center_B - center_A + 1)
else:
center_A = (sorted_A[N//2-1] + sorted_A[N//2]) / 2
center_B = (sorted_B[N//2-1] + sorted_B[N//2]) / 2
print(int((center_B - center_A)*2 + 1))
|
def root(x):
if F[x] < 0:
return x
else:
F[x] = root(F[x])
return F[x]
def unite(x, y):
x = root(x)
y = root(y)
if x == y:
return
if x > y:
x, y = y, x
F[x] += F[y]
F[y] = x
N, M = map(int, input().split())
F = [-1] * N
for m in range(M):
a, b = map(int, input().split())
unite(a - 1, b - 1)
ans = 0
for f in F:
ans = min(ans, f)
print(-ans)
| 0 | null | 10,718,820,368,348 | 137 | 84 |
l = []
for i in range(int(input())): l.append(input())
print(len(set(l)))
|
inputs = input().split()
a = int(inputs[0])
b = inputs[1]
b = 100 * int(b[0]) + 10 * int(b[2]) + int(b[3])
print(a * b // 100)
| 0 | null | 23,395,382,748,022 | 165 | 135 |
a, b = map(int, input().split())
print(a*b,2*(a+b))
|
num = map(int, raw_input().split(' '))
print num[0] * num[1], 2 * (num[0] + num[1])
| 1 | 306,875,725,368 | null | 36 | 36 |
while True:
m = map(int,raw_input().split())
if m[0] == 0 and m[1] == 0:
break
if m[0] >= m[1]:
print m[1],m[0]
else:
print m[0],m[1]
|
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
X = int(readline())
def enum_primes(n):
flag_num = (n + 1) // 2
prime_flag = [True] * flag_num
for num in range(3, int(n ** 0.5) + 1, 2):
idx = (num - 1) // 2 - 1
if prime_flag[idx]:
for j in range(idx + num, flag_num, num):
prime_flag[j] = False
primes = [2]
temp = [(i + 1) * 2 + 1 for i in range(flag_num) if prime_flag[i]]
primes.extend(temp)
return primes
primes = enum_primes(10 ** 6)
for prime in primes:
if prime >= X:
return print(prime)
if __name__ == '__main__':
main()
| 0 | null | 53,299,870,805,500 | 43 | 250 |
#!/usr/bin/env python3
n = int(input())
matrix = []
while n > 0:
values = [int(x) for x in input().split()]
matrix.append(values)
n -= 1
official_house = [[[0 for z in range(10)] for y in range(3)] for x in range(4)]
Min = 0
Max = 9
for b, f, r, v in matrix:
num = official_house[b - 1][f - 1][r - 1]
if Min >= num or Max >= num:
official_house[b - 1][f - 1][r - 1] += v
for i in range(4):
for j in range(3):
print('',' '.join(str(x) for x in official_house[i][j]))
if 3 > i:
print('#' * 20)
|
# -*- coding: utf-8 -*-
class residence(object):
def __init__(self):
one = [0] * 10
two = [0] * 10
three = [0] * 10
self.all = [one, two, three]
residences = [ ]
for i in xrange(4):
residences.append(residence())
n = int(raw_input())
for i in xrange(n):
b, f, r, v = map(int, raw_input().split())
residences[b-1].all[f-1][r-1] += v
for i, residence in enumerate(residences):
for floor in residence.all:
print '',
for index, num in enumerate(floor):
if index == len(floor) - 1:
print num
else:
print num,
if i != len(residences) - 1:
print '####################'
| 1 | 1,101,951,025,088 | null | 55 | 55 |
k = int(input())
from collections import deque
q = deque() # FIFOキューの作成
for i in range(1,10):
q.append(str(i))
for i in range(k-1):
a = q.popleft()
last = int(a[-1:])
if last == 0:
q.append(a+"0")
q.append(a + "1")
elif last ==9:
q.append(a+"8")
q.append(a + "9")
else:
q.append(a + str(last - 1))
q.append(a + str(last ))
q.append(a + str(last + 1))
print(q.popleft())
|
from collections import deque
K = int(input())
if K <= 10:
print(K)
else:
cnt = 9
l = deque(list(range(1,10)))
while True:
a = l.popleft()
a1 = a% 10
if a1 != 0:
a2 = a*10 + a1 - 1
cnt += 1
if cnt == K:
print(a2)
break
l.append(a2)
a2 = a*10 + a1
cnt += 1
if cnt == K:
print(a2)
break
l.append(a2)
if a1 != 9:
a2 = a*10 + a1 + 1
cnt += 1
if cnt == K:
print(a2)
break
l.append(a2)
| 1 | 39,915,337,941,500 | null | 181 | 181 |
n,k=map(int,input().split())
mi = min(n-1,k)
di = 10**9+7
def pow_k(x,i):
if i==0:
return 0
K=1
while i>1:
if i % 2 != 0:
K = (K*x)%di
x = (x*x)%di
i //= 2
return (K * x)%di
lis = [i for i in range(n+1)]
lisr = [i for i in range(n+1)]
lis[0]=1
for i in range(1,n+1):
lis[i]=(lis[i-1]*lis[i])%di
lisr[i] = pow_k(lisr[i],di-2)
lisr[0]=1
for i in range(1,n+1):
lisr[i]=(lisr[i-1]*lisr[i])%di
#print(lis,lisr)
su = 1
for i in range(1,mi+1):
pl = ((((lis[n-1]*lisr[i])%di)*lisr[n-1-i])%di)
plu = (pl*((((lis[n]*lisr[i])%di)*lisr[n-i])%di))%di
su+=plu
su%=di
print(su)
|
class Cmb:
def __init__(self, N, mod=10**9+7):
self.fact = [1,1]
self.fact_inv = [1,1]
self.inv = [0,1]
""" 階乗を保存する配列を作成 """
for i in range(2, N+1):
self.fact.append((self.fact[-1]*i) % mod)
self.inv.append((-self.inv[mod%i] * (mod//i))%mod)
self.fact_inv.append((self.fact_inv[-1]*self.inv[i])%mod)
""" 関数として使えるように、callで定義 """
def __call__(self, n, r, mod=10**9+7):
if (r<0) or (n<r):
return 0
r = min(r, n-r)
return self.fact[n] * self.fact_inv[r] * self.fact_inv[n-r] % mod
n,k = map(int,input().split())
mod = 10**9+7
c = Cmb(N=n)
ans = 0
for l in range(min(k+1, n)):
tmp = c(n,l)*c(n-1, n-l-1)
ans += tmp%mod
print(ans%mod)
| 1 | 67,200,229,921,418 | null | 215 | 215 |
n = int(input())
m = (n + 1) // 2
print(m)
|
moto = input()
num = int(input())
for i in range(num):
order = input().split()
if order[0] == "print":
m,n=int(order[1]),int(order[2])
print(moto[m:n+1])
elif order[0] == "reverse":
m,n=int(order[1]),int(order[2])
moto = moto[:m]+moto[m:n+1][::-1]+moto[n+1:]
elif order[0] == "replace":
m,n,l=int(order[1]),int(order[2]),order[3]
moto = moto[:m]+order[3]+moto[n+1:]
| 0 | null | 30,471,616,276,572 | 206 | 68 |
# -*- coding: utf-8
a = int(input())
b = list(map(int,input().split()))
s = 0
for i in range(a):
s +=b[i]
tr = 0
for i in range(a):
tr += b[i]**2
a2 = s**2-tr
a = a2//2
a %= 10**9+7
print(a)
|
a=[int(x) for x in input().split(" ")]
print(a.index(0)+1)
| 0 | null | 8,601,296,364,440 | 83 | 126 |
n = int(input())
MOD = 1000000007
def mod(n):
return n % MOD
def modpow(a, n): #mod(a**n)を高速で求める
res = 1
digit = len(str(bin(n))) - 2
for i in range(digit):
if (n >> i) & 1:
res *= mod(a)
res = mod(res)
a = mod(a**2)
return mod(res)
ans = modpow(10, n)
ans -= 2*modpow(9, n)
ans += modpow(8, n)
print(mod(ans))
|
n=int(input())
mod=1000000007
print((pow(10,n,mod)-2*pow(9,n,mod)+pow(8,n,mod))%mod)
| 1 | 3,156,369,022,180 | null | 78 | 78 |
n = input()
n = int(n)
if(n==2):
print(1)
elif(n%2==0):
print(int(n/2))
else:
print(int(n/2)+1)
|
n,k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9 + 7
a.sort(reverse = True)
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
return modinv
comb = Combination(100010)
ans = 0
for i in range(n-k+1):
ans += a[i] * comb(n-i-1, k-1)
ans %= mod
a = a[::-1]
for i in range(n-k+1):
ans -= a[i] * comb(n-i-1, k-1)
ans %= mod
print(ans)
| 0 | null | 77,598,582,699,990 | 206 | 242 |
k=int(input())
A=[0]*k
f=0
for i in range(k):
if i==0:
A[i]=7%k
else:
A[i]=(10*A[i-1]+7)%k
if A[i]==0:
f=1
print(i+1)
exit()
if not f:
print(-1)
|
k=int(input())
se=0
for i in range(k):
se=se*10
se+=7
i+=1
if se%k==0:
print(i)
exit()
se%=k
print('-1')
| 1 | 6,133,909,883,100 | null | 97 | 97 |
#!/usr/bin/env python3
import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
N = int(readline())
print(math.ceil(N / 2) / N)
if __name__ == '__main__':
main()
|
n=int(input())
if n%2==1:
x=((n//2)+1)/n
print(x)
else:
print(1/2)
| 1 | 177,451,004,635,202 | null | 297 | 297 |
N = int(input())
XY = []
points = []
for i in range(N):
points.append(i)
x, y = list(map(int, input().split()))
XY.append((x, y))
import math
import itertools
count = math.factorial(N)
line = 0
for pp in itertools.permutations(points, N):
i = 0
while i < N - 1:
i1, i2 = pp[i], pp[i + 1]
t = ((XY[i1][0] - XY[i2][0]) ** 2 + (XY[i1][1] - XY[i2][1]) ** 2) ** 0.5
line += t
i += 1
ans = line / count
print(ans)
|
a = input().split()
b = input().split()
if int(a[0])<int(b[0]):
print(1)
else:
print(0)
| 0 | null | 136,005,619,034,140 | 280 | 264 |
x = int(input())
if x == 1:
print("0")
elif x == 0:
print("1")
|
a = int(input())
if a == 1:
print(0)
else:
print(1)
| 1 | 2,910,154,696,850 | null | 76 | 76 |
import sys, fractions
[[print("{} {}".format(int(fractions.gcd(t[0], t[1])), int(t[0] * t[1] / fractions.gcd(t[0], t[1])))) for t in [[int(y) for y in x.split()]]] for x in sys.stdin]
|
def swap(a, b):
a = a ^ b
b = a ^ b
a = a ^ b
def gcd(x, y):
if(x < y):
swap(x, y)
mod = x % y
if mod == 0:
return y
else:
return gcd(y, mod)
def lcm(x, y):
return x * y / gcd(x, y)
while True:
try:
(a, b) = map(int ,raw_input().split())
except EOFError:
break
print gcd(a, b), lcm(a, b)
| 1 | 510,233,570 | null | 5 | 5 |
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import defaultdict
from collections import Counter
import bisect
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def main():
N = S()
K = I()
dig = len(N)
if dig < K:
print(0)
exit()
ans = 0
for i in range(dig):
if K == 0:
ans += 1
break
if int(N[i]) == 0:
continue
if dig - i - 1 >= K:
ans += combinations_count(dig - i - 1, K) * pow(9, K)
if dig - i - 1 >= K - 1:
ans += (int(N[i]) - 1) * combinations_count(dig - i - 1, K - 1) * pow(9, K - 1)
if i == dig - 1:
ans += 1
K -= 1
print(ans)
if __name__ == "__main__":
main()
|
s=input()
w=['SUN','MON','TUE','WED','THU','FRI','SAT',]
w=w[::-1]
for i in range(7):
if w[i]==s:
print(i+1)
break
| 0 | null | 104,309,350,468,162 | 224 | 270 |
a,b=map(int,input().split())
if a<b:
(a,b)=(b,a)
while b!=0:
(a,b)=(b,a%b)
print(a)
|
a, b = map(int, input().rstrip().split(" "))
if a > b:
A = a
B = b
else:
A = b
B = a
GCD = 1
while True:
A, B = B, A%B
if B == 0:
break
print (str(A))
| 1 | 8,641,322,578 | null | 11 | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.