code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
K, N = map(int, input().split())
A = list(map(int, input().split()))
import numpy as np
a = np.array(A)
D = np.diff(a)
D = np.append(D, a[0] + K - a[-1])
print(K - max(D))
|
s = input()
p = input()
if p in s + s:
print('Yes')
else:
print('No')
| 0 | null | 22,505,625,030,660 | 186 | 64 |
S,T = [input() for _ in range(2)]
print("Yes") if S==T[:-1] else print("No")
|
n = int(input())
n_l = list(map(int, input().split()))
VORDER = 10 ** 18
ans = 1
if 0 in n_l:
ans = 0
else:
for i in n_l:
ans = i * ans
if ans > VORDER:
ans = -1
break
print(ans)
| 0 | null | 18,862,960,395,580 | 147 | 134 |
H,W,*L = open(0).read().split()
H,W = map(int, (H,W))
dp = [[0]*W for i in range(H)]
for i in range(1,H):
if L[i][0]!=L[i-1][0]:
dp[i][0] = dp[i-1][0]+1
else:
dp[i][0] = dp[i-1][0]
for j in range(1,W):
if L[0][j]!=L[0][j-1]:
dp[0][j] = dp[0][j-1]+1
else:
dp[0][j] = dp[0][j-1]
for i in range(1,H):
for j in range(1,W):
if L[i][j]!=L[i-1][j] and L[i][j]!=L[i][j-1]:
dp[i][j] = min(dp[i-1][j],dp[i][j-1])+1
elif L[i][j]!=L[i-1][j]:
dp[i][j] = min(dp[i-1][j]+1,dp[i][j-1])
elif L[i][j]!=L[i][j-1]:
dp[i][j] = min(dp[i-1][j],dp[i][j-1]+1)
else:
dp[i][j] = min(dp[i-1][j],dp[i][j-1])
if L[0][0]=='.':
ans = (dp[H-1][W-1]+1)//2
else:
ans = (dp[H-1][W-1]+2)//2
print(ans)
|
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
dp = [[float("inf")] * w for i in range(h)]
dp[0][0] = 1 if s[0][0] == "#" else 0
d = [(-1, 0), (0, -1)]
for i in range(h):
for j in range(w):
if i == 0 and j == 0:
pass
else:
m = float("inf")
for k in d:
x = i + k[0]
y = j + k[1]
if 0 <= x < h and 0 <= y < w:
if s[i][j] == "#" and s[x][y] == ".":
m = dp[x][y] + 1
else:
m = dp[x][y]
dp[i][j] = min(dp[i][j], m)
print(dp[h - 1][w - 1])
| 1 | 49,294,783,855,820 | null | 194 | 194 |
from sys import stdin,stdout
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()
import math
from collections import Counter,defaultdict
n=IN()
a=LI()
ans=0
for i in range(n):
ans^=a[i]
for i in range(n):
print(ans^a[i],end=" ")
|
# ????????? str ?????????????????????????????????????????????????????????????????°??????
# ?????\????±??????????str????¨??????\???????????????
str = list(input())
str = "".join(str)
# ?????\???????????°p????¨??????\???????????????
p = int(input())
# p??????????????????????????????????????????
orderList = [0 for i in range(p)]
for i in range(0, p):
orderList[i] = list(input())
orderList[i] = "".join(orderList[i]).split()
if orderList[i][0] == "print":
print("{0}".format(str[int(orderList[i][1]):int(orderList[i][2]) + 1]))
elif orderList[i][0] == "reverse":
str = str[0:int(orderList[i][1])] + str[-len(str) + int(orderList[i][2]):-len(str) + int(orderList[i][1]) - 1:-1] + str[int(orderList[i][2]) + 1:]
elif orderList[i][0] == "replace":
str = str[:int(orderList[i][1])] + orderList[i][3] + str[int(orderList[i][2]) + 1:]
| 0 | null | 7,333,540,134,012 | 123 | 68 |
score = list(map(int,input().split()))
taka = score[0]
aoki = score[2]
while taka > 0:
aoki -= score[1]
if aoki <= 0:
print('Yes')
break
taka -= score[3]
if aoki > 0:
print('No')
|
print('NYoe s'['111'in''.join(str(len({*t.split()}))for t in open(0))[1:]::2])
| 0 | null | 16,070,819,458,672 | 164 | 72 |
tmp = input()
array = tmp.split(' ')
a = int(array[0])
b = int(array[1])
print(str(a*b) + " " + str((a*2)+(b*2)))
|
def solve(n):
if n <= 1:
print(1)
return
a, b = 1, 1
for _ in range(2, n + 1):
c = a + b
b = a
a = c
print(c)
if __name__ == "__main__":
n = int(input())
solve(n)
| 0 | null | 148,545,229,600 | 36 | 7 |
def insertionSort(A, n, g):
local_cnt = 0
for i in range(g, n):
# print(i, local_cnt)
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
# print(i, j, local_cnt)
A[j + g] = A[j]
j -= g
local_cnt += 1
A[j + g] = v
return A, local_cnt
def shellSort(A, n):
cnt = 0
m = 1
G = []
h = 1
while (h < n // 3):
h = h * 3 + 1
m += 1
# print(f'm: {m}')
while True:
G.append(h)
if h == 1:
break
h //= 3
# print(f'G: {G}')
for i in range(m):
ans = insertionSort(A, n, G[i])
# print(ans)
A = ans[0]
cnt += ans[1]
return m, G, A, cnt
n = int(input())
A = [int(input()) for _ in range(n)]
m, G, A, cnt = shellSort(A, n)
print(m)
print(' '.join(str(g) for g in G))
print(cnt)
for a in A:
print(a)
|
#!/usr/bin/env python3
def construct_gs(n):
gs = []
g = 1
while g <= n:
gs.append(g)
g = 3 * g + 1
return gs[::-1]
def shell_sort(xs, n):
global cnt
cnt = 0
gs = construct_gs(n)
m = len(gs)
def insertion_sort(g):
global cnt
for i in range(g, n):
v = xs[i]
j = i - g
while j >= 0 and xs[j] > v:
xs[j + g] = xs[j]
j = j - g
cnt += 1
xs[j + g] = v
for g in gs:
insertion_sort(g)
return m, gs, cnt, xs
def main():
n = int(input())
xs = [int(input()) for _ in range(n)]
m, gs, cnt, xs = shell_sort(xs, n)
print(m)
print(" ".join(map(str, gs)))
print(cnt)
for x in xs:
print(x)
if __name__ == '__main__':
main()
| 1 | 30,551,480,580 | null | 17 | 17 |
import sys
def input():
return sys.stdin.readline()[:-1]
n = int(input())
plus, minus = [], []
for _ in range(n):
s = input()
mi, cur = 0, 0
for i in range(len(s)):
if s[i] == "(":
cur += 1
else:
cur -= 1
mi = min(mi, cur)
if cur >= 0:
plus.append((mi, cur))
else:
minus.append((mi, cur))
plus.sort(key=lambda x: -x[0])
minus.sort(key=lambda x: x[0] - x[1])
res = plus + minus
cur = 0
for m, t in res:
if cur + m < 0:
print("No")
exit()
cur += t
if cur != 0:
print("No")
exit()
print("Yes")
|
N = int(input())
pl = []
mi = []
for i in range(N):
_m = 0
_t = 0
s = input()
for c in s:
if c == ")":
_t -= 1
_m = min(_m, _t)
else:
_t += 1
if _t > 0:
pl.append([-_m, -_t]) # sortの調整のために負にしている
else:
mi.append([- _t + _m, _m, _t])
pl = sorted(pl)
mi = sorted(mi)
#import IPython;IPython.embed()
if len(pl) == 0:
if mi[0][0] == 0:
print("Yes")
else:
print("No")
exit()
if len(mi) == 0:
print("No")
exit()
tot = 0
for m, nt in pl:
if tot - m < 0: # これはひくではないのでは?
print("No")
exit()
else:
tot -= nt
for d, m, nt in mi:
if tot + m <0:
print("No")
exit()
else:
tot += nt
if tot != 0:
print("No")
else:
print("Yes")
# どういう時できるか
# で並べ方
# tot, minの情報が必要
# totが+のものはminとtotを気をつける必要がある
# minがsum以上であればどんどん足していけばいい.
# なのでminが大きい順にsortし,totの大きい順にsort
# その次はtotがminusの中ではminが小さい順に加える
# 合計が0になる時Yes,それ意外No.
| 1 | 23,734,416,557,390 | null | 152 | 152 |
a, b, c = map(int, raw_input().split(" "))
cnt = 0
for i in range(a, b + 1) :
if (c % i == 0) :
cnt += 1
print cnt
|
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)
| 0 | null | 34,072,431,217,160 | 44 | 215 |
# -*- coding: utf-8 -*-
r, c = map(int, raw_input().split())
mat = {}
for i in range(1, r+1):
col = map(int, raw_input().split())
for j in range(1, c+1):
mat[(i, j)] = col[j-1]
for i in range(1, r+1):
mat[(i, c+1)] = 0
for j in range(1, c+1):
mat[(i, c+1)] += mat[(i, j)]
for j in range(1, c+2):
mat[(r+1, j)] = 0
for i in range(1, r+1):
mat[(r+1, j)] += mat[(i, j)]
for i in range(1, r+2):
buf = ""
for j in range(1, c+1):
buf += str(mat[(i, j)]) +" "
buf += str(mat[(i, c+1)])
print buf
|
ln = input().split()
print(ln[1]+ln[0])
| 0 | null | 52,163,985,517,120 | 59 | 248 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
NUM = [0] * 500000
for x in range(1,101):
for y in range(1,101):
for z in range(1,101):
nya = x**2 + y**2 + z**2 + x*y + y*z + z*x
NUM[nya] += 1
n = I()
for i in range(1,n+1):
print(NUM[i])
|
def main():
r = int(input())
print(r**2)
if __name__ == "__main__":
main()
| 0 | null | 76,601,687,786,122 | 106 | 278 |
def main():
N = int(input())
ans = 0
for n in range(1, N + 1):
d = N // n
ans += d * (d + 1) / 2 * n
print(int(ans))
if __name__ == '__main__':
main()
|
A, B = map(int,input().split())
import math
c = math.gcd(A,B)
d = (A*B) / c
print(int(d))
| 0 | null | 62,182,826,008,732 | 118 | 256 |
import math
r = float(input())
S = r*r*math.pi
l = 2*r*math.pi
print("{:.5f} {:.5f}".format(S,l))
|
from collections import deque
import sys
input = sys.stdin.readline
_ = int(input())
S = [int(i) for i in input().strip().split()]
_ = int(input())
T = [int(i) for i in input().strip().split()]
ans = 0
for t in T:
if t in S:
ans += 1
print(ans)
| 0 | null | 350,351,938,802 | 46 | 22 |
n = int(input())
print(n*(1+n+n*n))
|
# vim: fileencoding=utf-8
import math
def main():
a = int(input())
res = a + math.pow(a, 2) + math.pow(a, 3)
print(int(res))
if __name__ == "__main__":
main()
| 1 | 10,227,571,671,928 | null | 115 | 115 |
#!/usr/bin/env python
letters = []
for i in range(26):
letters.append(chr(i + 97) + " : ")
contents = []
while True:
try:
text = input()
except EOFError:
break
contents.append(text)
#65-90 uppercase
#97-122lowercase
i = 0
for y in letters:
value = 0
for text in contents:
for x in text:
if x.isupper():
x = x.lower()
if x in y:
value += 1
elif x.islower():
if x in y:
value += 1
letters[i] = letters[i] + str(value)
i += 1
for x in letters:
print(x)
|
s = ""
while True:
try:
s += input().lower()
except:
break
dic = {}
orda = ord("a")
ordz = ord("z")
for c in s:
if orda <= ord(c) <= ordz:
try:
dic[c] += 1
except:
dic[c] = 1
for i in range(orda,ordz + 1):
c = chr(i)
try:
print("%s : %d" % (c, dic[c]))
except:
print("%s : %d" % (c, 0))
| 1 | 1,676,084,139,272 | null | 63 | 63 |
n = int(input())
R = []
for i in range(n):
R.append(int(input()))
minv = R[0]
maxv = R[1] - R[0]
for r in R[1:]:
maxv = max(maxv, r - minv)
minv = min(minv, r)
print(maxv)
|
N = int(input())
maxv = -2*10**10
minv = int(input())
for i in range(N-1):
_ = int(input())
maxv = max(maxv,_-minv)
minv = min(minv,_)
print(maxv)
| 1 | 14,006,675,700 | null | 13 | 13 |
m,n=map(int,raw_input().split())
if m>n:print'a > b'
elif m<n:print'a < b'
else:print'a == b'
|
def solve(k):
v = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
v = list(map(int, v.split(",")))
return v[k-1]
k = int(input())
print(solve(k))
| 0 | null | 25,286,261,228,788 | 38 | 195 |
def check(h):
if h > 1:
return 2*(check(h//2))+1
elif h==1:
return 1
print(check(int(input())))
|
n=int(input())
cnt=0
ans=0
while(n>=1):
ans+=2**cnt
n//=2
cnt+=1
print(ans)
| 1 | 80,428,801,936,208 | null | 228 | 228 |
import collections
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = []
for i in range(q):
bci = list(map(int, input().split()))
bc.append(bci)
d = collections.Counter(a)
ans = sum(a)
for i in range(q):
b, c = bc[i]
num = (c-b)*d[b]
ans += num
print(ans)
d[c] += d[b]
d[b] = 0
|
import array
N = int(input())
A = array.array('L', list(map(int, input().split())))
MAX = 10**5+1
X = array.array('L', [0]) * MAX
Y = array.array('L', range(MAX))
for i in range(len(A)): X[A[i]] += 1
Q = int(input())
cur = sum(array.array('L', (X[i]*Y[i] for i in range(len(X)))))
for i in range(Q):
[b, c] = list(map(int, input().split()))
cur = cur - X[b]*b + X[b]*c
print(cur)
X[c] += X[b]
X[b] = 0
| 1 | 12,202,256,290,210 | null | 122 | 122 |
ac = 0
wa = 0
tle = 0
re = 0
n = int(input())
for i in range(n):
testcase = input()
if testcase == 'AC':
ac += 1
elif testcase == 'WA':
wa += 1
elif testcase == 'TLE':
tle += 1
elif testcase == 'RE':
re += 1
print('AC x', ac)
print('WA x', wa)
print('TLE x', tle)
print('RE x', re)
|
a = 0
b = 0
c = 0
d = 0
N = int(input())
S = []
for i in range(N):
S.append(input())
for j in range(N):
if S[j] == 'AC':
a += 1
elif S[j] == 'WA':
b += 1
elif S[j] == 'TLE':
c += 1
elif S[j] == 'RE':
d += 1
print('AC x', a)
print('WA x', b)
print('TLE x', c)
print('RE x', d)
| 1 | 8,737,510,735,070 | null | 109 | 109 |
class process:
def __init__(self, name, time):
self.name = name
self.time = time
def queue(q, ps):
time = 0
while len(ps) != 0:
p = ps.pop(0)
if p.time > q:
p.time -= q
time += q
ps.append(p)
else:
time += p.time
print p.name + " " + str(time)
if __name__ == "__main__":
L = map(int, raw_input().split())
N = L[0]
q = L[1]
processes = []
for i in range(N):
L = raw_input().split()
processes.append(process(L[0], int(L[1])))
queue(q, processes)
|
def Queue(l, nowtime, sec):
if len(l) == 1:
print(l[0][0], nowtime + l[0][1])
return [], 0
else:
tl = l.pop(0)
if tl[1] <= sec:
nowtime += tl[1]
print(tl[0], nowtime)
return l, nowtime
else:
nowtime += sec
l.append([tl[0], tl[1] - sec])
return l, nowtime
if __name__ == '__main__':
N, sec = input().split()
N, sec = int(N), int(sec)
lists = list()
for i in range(N):
obj, times = input().split()
lists.append([obj, int(times)])
now = 0
while lists:
lists, now = Queue(lists, now, sec)
| 1 | 42,396,472,060 | null | 19 | 19 |
# coding: utf-8
def main():
N = int(input())
A = list(map(int, input().split()))
B = [[a, i + 1] for i, a in enumerate(A)]
B.sort()
for i, j in B:
if i == N:
print(j)
else:
print(j, "", end='')
if __name__ == "__main__":
main()
|
import sys
import numpy as np
import numba
from numba import jit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@jit
def main(n, a):
ans = np.zeros(n)
for i, j in enumerate(a):
ans[j-1] = i+1
for i in ans:
print(int(i), end=' ')
n = int(readline())
a = np.array(readline().split(), np.int64)
main(n,a)
| 1 | 180,826,438,911,820 | null | 299 | 299 |
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
MOD = 10 ** 4 + 7
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
print(min(A - 1, N - B) + 1 + (B - A - 1) // 2)
|
n,a,b = map(int,input().split())
if (a+b) % 2 == 0:
print(b - (a+b)//2)
else:
if a <= n-b+1:
b -= a
print(a + b-(1+b)//2)
else:
a += n-b+1
print(n-b+1 + n - (n+a)//2)
| 1 | 109,692,243,356,960 | null | 253 | 253 |
import bisect
from collections import deque
import math
n, d, A = map(int, input().split())
xh = []
for _ in range(n):
x, h = map(int, input().split())
xh.append([x, h])
xh.sort(key=lambda x: x[0])
monster_x = []
monster_hp = []
for i in range(n):
monster_x.append(xh[i][0])
monster_hp.append(xh[i][1])
dist = 2 * d
ans = 0
damage = 0
cum_damage = [0] * (n + 1)
for i in range(n):
cum_damage[i + 1] += cum_damage[i]
damage = cum_damage[i + 1] * A
if damage < monster_hp[i]:
min_attack_num = math.ceil((monster_hp[i] - damage) / A)
index = bisect.bisect_right(monster_x, monster_x[i] + dist)
cum_damage[i + 1] += min_attack_num
if index < n:
t = min(index + 1, n)
cum_damage[t] -= min_attack_num
ans += min_attack_num
print(ans)
|
firstLine = input()
numOfPoints, limitDisatnce = list(map(int,firstLine.split(' ')))[0], list(map(int,firstLine.split(' ')))[1]
points = []
for i in range(0, numOfPoints):
cordinate = list(map(int,input().split(' ')))
points.append(cordinate)
count = 0
for i in range(0, len(points)):
distance = (points[i][0] ** 2) + (points[i][1] ** 2)
if (limitDisatnce ** 2) >= distance:
count = count + 1
print(count)
| 0 | null | 44,227,498,230,898 | 230 | 96 |
n,m = map(int, input().split())
l = n - m
if l== 0:
print('Yes')
else:
print('No')
|
def main():
n,m = map(int,input().split())
if n == m:
print('Yes')
else:
print('No')
main()
| 1 | 83,210,378,398,318 | null | 231 | 231 |
from functools import lru_cache
h,w= map(int, input().split())
maze = [[-1 for i in range(w)] for j in range(h)]
ans = 0
for i in range(h):
maze[i] = input()
INF = 10000
@lru_cache(None)
def dfs(y,x,flg,cnt):
if y == h-1 and x ==w-1:
if flg ==1:
cnt+=1
return cnt
ans = [INF]
for (ny, nx) in [(y+1, x), (y, x+1)]:
if 0 <= nx < w and 0 <= ny < h:
if maze[ny][nx] != maze[y][x]:
if flg == 0: ans.append(dfs(ny,nx,1,cnt))
else: ans.append(dfs(ny,nx,0,cnt+1))
else:
ans.append(dfs(ny,nx,flg,cnt))
return(min(ans))
print(dfs(0,0,(0 if maze[0][0]=='.' else 1),0))
|
H,W=list(map(int,input().split()))
l=[list(input()) for i in range(H)]
inf=10**9
DP=[[inf]*W for i in range(H)]
DP[0][0]=0 if l[0][0]=="." else 1
for i in range(H):
for j in range(W):
if i>0:
DP[i][j]=min(DP[i][j],DP[i-1][j]+1) if l[i-1][j] == "." and l[i][j]=="#" else min(DP[i][j],DP[i-1][j])
if j>0:
DP[i][j]=min(DP[i][j],DP[i][j-1]+1) if l[i][j-1] == "." and l[i][j]=="#" else min(DP[i][j],DP[i][j-1])
print(DP[H-1][W-1])
| 1 | 49,317,607,688,420 | null | 194 | 194 |
n = int(input())
s = input()
prev = ""
ans = ""
for i in range(n):
if s[i] == prev:
continue
prev = s[i]
ans += s[i]
print(len(ans))
|
n = int(input())
s = input()
temp = ''
cnt = 0
for i in s:
if i != temp:
cnt += 1
temp = i
print(cnt)
| 1 | 169,956,260,739,412 | null | 293 | 293 |
import math
n,a,b=map(int,input().split())
mod=10**9+7
c1=1
c2=1
for i in range(n-a+1,n+1):
c1*=i
c1%=mod
for j in range(1,a+1):
c1*=pow(j,mod-2,mod)
c1%=mod
for i in range(n-b+1,n+1):
c2*=i
c2%=mod
for j in range(1,b+1):
c2*=pow(j,mod-2,mod)
c2%=mod
ans=pow(2,n,mod)-1
print((ans-c1-c2)%mod)
|
s = int(input())
mod = 10**9+7
import numpy as np
if s == 1 or s == 2:
print(0)
elif s == 3:
print(1)
else:
array = np.zeros(s+1)
array[0] = 1
for i in range(3, s+1):
array[i] = np.sum(array[:i-2]) % mod
print(int(array[s]))
| 0 | null | 34,669,855,867,640 | 214 | 79 |
# import itertools
import math
# import sys
# import numpy as np
# K = int(input())
# S = input()
# n, *a = map(int, open(0))
A, B, H, M = map(int, input().split())
# H = list(map(int, input().split()))
# Q = list(map(int, input().split()))
# S = input()
# d = sorted(d.items(), key=lambda x:x[0]) # keyでsort
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement([i for i in range(1, M + 1)], N))
# print(a[0][0])
# print(conditions[0])
kakudo_H = (H * 60 + M) / 720 * 360
kakudo_M = M / 60 * 360
print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(abs(kakudo_H - kakudo_M)))))
|
import math
a, b, h, m = map(int, input().split())
rad1 = (2 * math.pi) * ((h * 60 + m) / 720)
rad2 = (2 * math.pi) * (m / 60)
x = abs(rad2 - rad1)
ans = math.sqrt(a * a + b * b - 2 * a * b * math.cos(x))
print(ans)
| 1 | 20,059,088,665,242 | null | 144 | 144 |
from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 8)
h,n=map(int,input().split())
ab=[tuple(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda abi:(abi[1]/abi[0],abi[0]))
@lru_cache(maxsize=None)
def dp(i):
if i<=0:
return 0
else:
ans=float('inf')
for a,b in ab:
val=b+dp(i-a)
if val<ans:
ans=val
else:
break
return ans
print(dp(h))
|
h,n=map(int,input().split())
magic=[list(map(int,input().split())) for _ in range(n)]
dp=[10**9]*(h+10**5)
#dp[i]:敵の体力をi減らすのに必要な魔力の最小値
dp[0]=0
for i in range(h):
for damage,cost in magic:
dp[i+damage]=min(dp[i+damage],dp[i]+cost)
ans=10**9
for i in range(10**5):
ans=min(ans,dp[i+h])
print(ans)
| 1 | 81,361,943,387,090 | null | 229 | 229 |
k,n=map(int,input().split())
a=[int(i)for i in input().split()]
distance=[a[i+1]-a[i] for i in range(n-1)]
distance.append(a[0]+k-a[-1])
print(sum(distance)-max(distance))
|
import sys
N, X, M = map(int, input().split())
if N == 1: #例外
print(X)
sys.exit()
ans = 0
ans += X - (X%M) #XがMより大きい場合、超過分を先に計上する。
X %= M #これで 0 <= X <= M-1 が成り立つようにできた。
def fun(x): #問題の関数を用意(いちいち中身を書いていると面倒くさいため)
return (x * x) % M
appear_set = {X} #すでに現れた数を格納する
i_0 = 1 #今までに調べた個数。現在は「X」の1つだけ。
x = X #このxに何度も関数funを作用させる
sum_0 = x #現在までの和
# ①:すでに出現したことのある数が現れるまで、ループを回す。
# この途中で目標回数Nに到達するなら、その時点で答えを出力する(31-33行目)。
while fun(x) not in appear_set: #次のxが初めて現れる数なら続ける。
x = fun(x) #xにfunを作用
appear_set.add(x) #xを「現れたものリスト」に格納
sum_0 += x #和の更新
i_0 += 1 #調べた個数の更新
if i_0 == N: #目標回数に到達したら、その時点で答えを出力して終了。
print(ans + sum_0)
sys.exit()
# 現在、xには系列に初めて現れた最後の数が入っている。
# 次の数であるfun(x)は、前に現れたことのある数。したがって、ここからループが始まる。
# 整理のため、ここまでの和を計上し、残り回数も減らしておく。
ans += sum_0
N -= i_0
# ②:ループの性質を調べるため、もう一度ループを回したい。
# 欲しいものは3つ。
# 1.ループ1週の和
# 2.ループの途中までの和を記録した配列。
# 3.ループの長さ
# 以下、先ほどと異なる部分を中心に説明する。
x = fun(x) # 次の数へ行く(ループの最初の数)
appear_set_2 = {x}
sum_1 = x # 欲しいもの1。ループ1周の和を記録する。
sum_list = [0,x] # 欲しいもの2。i番目の要素がi番目までの数までの和を示すよう、この後要素を追加する。
i_1 = 1 # すでに調べた個数をカウントする。現在は「x」の1個だけ。
# このi_1が、最終的にループの長さ(欲しいもの3)になる。
# 以下、60行目以外の処理は先ほどと同様。
while fun(x) not in appear_set_2:
x = fun(x)
appear_set_2.add(x)
sum_1 += x
sum_list.append(sum_1) #途中までの和を記録。
i_1 += 1
# ③:上で求めた3つの情報(一周の和sum_1, 途中までの和の記録sum_list, ループ長i_1)
# を使って答えを求める。
ans += sum_1 * (N // i_1) + sum_list[(N % i_1)]
print(ans)
| 0 | null | 23,056,352,003,080 | 186 | 75 |
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**5)
def geta(fn=lambda s: s.decode()):
return map(fn, readline().split())
def gete(fn=lambda s: s.decode()):
return fn(readline().rstrip())
def main():
s, t = geta()
print(t + s)
if __name__ == "__main__":
main()
|
l = input().split()
ans = l[1] + l[0]
print(ans)
| 1 | 103,161,520,398,428 | null | 248 | 248 |
set = raw_input().split()
if int(set[0]) < int(set[1]) < int(set[2]):
print 'Yes'
else:
print 'No'
|
s = input()[::-1]
l = [0 for i in range(2019)]
l[0] = 1
a, b = 0, 1
ans = 0
for i in s:
a += int(i) * b
a %= 2019
b *= 10
b %= 2019
l[a] += 1
for i in l:
ans += i * (i - 1) // 2
print(ans)
| 0 | null | 15,741,900,115,382 | 39 | 166 |
k, n = map(int, input().split())
a = list(map(int, input().split()))
a += [k + a[0]]
print(k - max([a[i + 1] - a[i] for i in range(n)]))
|
S=input()
N=len(S)+1
LEFT=[0]
RIGHT=[0]
left=0
right=0
for i in range(N-1):
if S[i]==">":
left=0
else:
left+=1
LEFT+=[left]
for i in range(N-2,-1,-1):
if S[i]=="<":
right=0
else:
right+=1
RIGHT+=[right]
ans=0
for i in range(N):
ans+=max(LEFT[i],RIGHT[N-1-i])
print(ans)
| 0 | null | 99,730,137,116,892 | 186 | 285 |
x1, x2, y1, y2 = map(float, input().split())
ans = ((x1 - y1)**2 + (x2 - y2)**2)**0.5
print("{:.5f}".format(ans))
|
N, K = map(int,input().split())
ans = 0
while K <= N+1:
ans += ((N+1)*(N+2) - (N-K+1)*(N-K+2) - K*(K+1)) // 2 + 1
K += 1
print(ans % (10 ** 9 + 7))
| 0 | null | 16,693,278,946,600 | 29 | 170 |
a = list(map(int,input().split()))
if(a[0] < a[1] and a[1] < a[2]): print("Yes")
else: print("No")
|
from functools import lru_cache
h,w= map(int, input().split())
maze = [[-1 for i in range(w)] for j in range(h)]
ans = 0
for i in range(h):
maze[i] = input()
INF = 10000
@lru_cache(None)
def dfs(y,x,flg,cnt):
if y == h-1 and x ==w-1:
if flg ==1:
cnt+=1
return cnt
ans = [INF]
for (ny, nx) in [(y+1, x), (y, x+1)]:
if 0 <= nx < w and 0 <= ny < h:
if maze[ny][nx] != maze[y][x]:
if flg == 0: ans.append(dfs(ny,nx,1,cnt))
else: ans.append(dfs(ny,nx,0,cnt+1))
else:
ans.append(dfs(ny,nx,flg,cnt))
return(min(ans))
print(dfs(0,0,(0 if maze[0][0]=='.' else 1),0))
| 0 | null | 24,752,793,579,482 | 39 | 194 |
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
P = int(1e9+7)
ans = 0
kaizyo = [0]
kaizyo_inv = [0]
tmp = 1
for i in range(1, N+1):
tmp = (tmp*i) % P
kaizyo.append(tmp)
kaizyo_inv.append(pow(tmp, P - 2, P))
def comb(n, r):
if n < r or n == 0:
return 0
elif n == r or r == 0:
return 1
else:
return kaizyo[n] * kaizyo_inv[r] * kaizyo_inv[n - r]
combs=[comb(i, K - 1)%P for i in range(N+1)]
for i, a in enumerate(A):
ans = (ans + a * combs[i]) % P
ans = (ans - a * combs[N - i - 1]) % P
print(ans)
|
N, K = [int(_) for _ in input().split()]
s = 0
e = 0
ans = 0
MOD = 10 ** 9 + 7
for i in range(N+1):
s += i
e += N - i
if i + 1 >= K:
ans += e - s + 1
ans %= MOD
print(ans)
| 0 | null | 64,810,003,821,888 | 242 | 170 |
def popcount(x):
return bin(x).count("1")
def solve(n):
if n == 0:
return 0
return 1+solve(n % popcount(n))
N = int(input())
X = input()
num_x = int(X, 2)
p_cnt = X.count('1')
if p_cnt == 1:
for i in range(N):
if X[i] == '1':
print(0)
elif i == N-1:
print(2)
else:
print(1)
exit()
r0_p = num_x % (p_cnt+1)
r0_m = num_x % (p_cnt-1)
for i in range(N):
if X[i] == '0':
c_p_cnt = p_cnt+1
r = (r0_p + pow(2, (N - 1 - i), c_p_cnt)) % c_p_cnt
else:
c_p_cnt = p_cnt-1
if c_p_cnt == 0:
print(0)
continue
r = (r0_m- pow(2, (N - 1 - i), c_p_cnt)) % c_p_cnt
print(1 + solve(r % c_p_cnt))
|
n,m,x = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
ans = 10**9
for i in range(2 ** n):
skill = [0] * m
overTen = False
money = 0
for j in range(n):
if ((int(bin(i)[2:]) >> j) & 1):
money += a[j][0]
for h in range(m):
skill[h] += a[j][h+1]
for k in skill:
if k >= x:
overTen = True
else:
overTen = False
break
if overTen == True:
if money < ans:
ans = money
if ans == 10**9:
print(-1)
else:
print(ans)
| 0 | null | 15,180,026,385,378 | 107 | 149 |
n = int(input())
s = 0
a = 1
b = 1
while a*b < n:
while a*b < n and b <= a:
if a == b:
s += 1
else:
s += 2
b += 1
a += 1
b = 1
print(s)
|
n=int(input())
ans=0
for a in range(1,n):
x=(n-1)//a
ans+=x
print(ans)
| 1 | 2,632,351,405,476 | null | 73 | 73 |
a, b = map(int, input().split())
if a < b:
print('a < b')
elif a == b:
print('a == b')
else:
print('a > b')
|
i = input()
i = i.split(" ")
i = list(map(int,i))
if i[0] < i[1]:
print("a < b")
elif i[0] > i[1]:
print("a > b")
elif i[0] == i[1]:
print("a == b")
| 1 | 353,494,907,768 | null | 38 | 38 |
class Combination:
def __init__(self, n_max, mod=10**9+7):
# O(n_max + log(mod))
self.mod = mod
f = 1
self.fac = fac = [f]
for i in range(1, n_max+1):
f = f * i % mod
fac.append(f)
f = pow(f, mod-2, mod)
self.facinv = facinv = [f]
for i in range(n_max, 0, -1):
f = f * i % mod
facinv.append(f)
facinv.reverse()
# "n 要素" は区別できる n 要素
# "k グループ" はちょうど k グループ
def __call__(self, n, r): # self.C と同じ
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def C(self, n, r):
if not 0 <= r <= n: return 0
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def P(self, n, r):
if not 0 <= r <= n: return 0
return self.fac[n] * self.facinv[n-r] % self.mod
def H(self, n, r):
if (n == 0 and r > 0) or r < 0: return 0
return self.fac[n+r-1] * self.facinv[r] % self.mod * self.facinv[n-1] % self.mod
def rising_factorial(self, n, r): # 上昇階乗冪 n * (n+1) * ... * (n+r-1)
return self.fac[n+r-1] * self.facinv[n-1] % self.mod
def stirling_first(self, n, k): # 第 1 種スターリング数 lru_cache を使うと O(nk) # n 要素を k 個の巡回列に分割する場合の数
if n == k: return 1
if k == 0: return 0
return (self.stirling_first(n-1, k-1) + (n-1)*self.stirling_first(n-1, k)) % self.mod
def stirling_second(self, n, k): # 第 2 種スターリング数 O(k + log(n)) # n 要素を区別のない k グループに分割する場合の数
if n == k: return 1 # n==k==0 のときのため
return self.facinv[k] * sum((-1)**(k-m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k+1)) % self.mod
def balls_and_boxes_3(self, n, k): # n 要素を区別のある k グループに分割する場合の数 O(k + log(n))
return sum((-1)**(k-m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k+1)) % self.mod
def bernoulli(self, n): # ベルヌーイ数 lru_cache を使うと O(n**2 * log(mod))
if n == 0: return 1
if n % 2 and n >= 3: return 0 # 高速化
return (- pow(n+1, self.mod-2, self.mod) * sum(self.C(n+1, k) * self.bernoulli(k) % self.mod for k in range(n))) % self.mod
def faulhaber(self, k, n): # べき乗和 0^k + 1^k + ... + (n-1)^k
# bernoulli に lru_cache を使うと O(k**2 * log(mod)) bernoulli が計算済みなら O(k * log(mod))
return pow(k+1, self.mod-2, self.mod) * sum(self.C(k+1, j) * self.bernoulli(j) % self.mod * pow(n, k-j+1, self.mod) % self.mod for j in range(k+1)) % self.mod
def lah(self, n, k): # n 要素を k 個の空でない順序付き集合に分割する場合の数 O(1)
return self.C(n-1, k-1) * self.fac[n] % self.mod * self.facinv[k] % self.mod
def bell(self, n, k): # n 要素を k グループ以下に分割する場合の数 O(k**2 + k*log(mod))
return sum(self.stirling_second(n, j) for j in range(1, k+1)) % self.mod
# x * x が選ばれ、かつそれ以外はすべて x 以下が選ばれる場合の数
N, K = map(int, input().split())
A = sorted(map(int, input().split()))
ans_max = ans_min = 0
mod = 10**9+7
comb = Combination(101010)
for i, a in enumerate(A):
ans_max += a * comb.C(i, K-1)
ans_min += a * comb.C(N-1-i, K-1)
ans = (ans_max - ans_min) % mod
print(ans)
|
n,k=map(int,input().split())
A=list(map(int,input().split()))
MOD=10**9+7
ans=0
L=[1]*(n+1)
Linv=[1]*(n+1)
inv=[0]+[1]*n
for i in range(2,n+1):
L[i]=(L[i-1]*i)%MOD
inv[i]=(MOD-inv[MOD%i]*(MOD//i))%MOD
Linv[i]=(Linv[i-1]*inv[i])%MOD
def cmb(n,k):
return (((L[n]*Linv[k])%MOD)*Linv[n-k])%MOD
A.sort()
for j in range(n-k+1):
ans+=((A[-1-j]-A[j])*cmb(n-1-j,k-1))%MOD
if ans>=0:
print(ans%MOD)
else:
print(MOD+ans)
| 1 | 96,044,528,322,912 | null | 242 | 242 |
#!usr/bin/env python3
import sys
import re
def main():
s = sys.stdin.readline() # haystack
p = sys.stdin.readline() # needle
s = s.strip('\n') * 2
p = p.strip('\n')
if len(re.findall((p), s)) > 0:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
|
N,*P = map(int, open(0).read().split())
m = P[0]
ans = 0
for x in P:
if x <= m:
m = x
ans += 1
print(ans)
| 0 | null | 43,470,085,137,668 | 64 | 233 |
a,b,n=map(int,input().split())
x=min(n,b-1)
print(int((a*x/b)//1))
|
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353
def ddprint(x):
if DBG:
print(x)
a,b,c = inm()
k = inn()
x = 0
while b<=a:
b *= 2
x += 1
while c<=b:
c *= 2
x += 1
print('Yes' if x<=k else 'No')
| 0 | null | 17,421,142,264,860 | 161 | 101 |
while True:
m, f, r = map(int, input().strip().split())
if m == f == r == -1: break
if m == -1 or f == -1 or m + f < 30:
print('F')
elif m + f >= 80:
print('A')
elif m + f >= 65:
print('B')
elif m + f >= 50:
print('C')
elif m + f >= 30:
print('C' if r >= 50 else 'D')
|
N = int(input())
a = []
for i in range(10):
for j in range(10):
a.append(i * j)
print("Yes") if N in a else print("No")
| 0 | null | 80,889,026,259,294 | 57 | 287 |
while 1:
n,x=map(int,input().split())
if n+x==0:break
print(sum([1 for i in range(3,n+1)for j in range(2,x-i)if x-i-j<j<i]))
|
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = 10**20
MOD = 1000000007
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def resolve():
N = I()
A = LI()
# color_number[i][j]: [0, i)でj番目に多い色の人数
color_number = [[0, 0, 0] for _ in range(N)]
for i in range(N-1):
if A[i] in color_number[i]:
idx = color_number[i].index(A[i])
else:
idx = -1
for j in range(3):
if j==idx:
color_number[i+1][j] = color_number[i][j] + 1
else:
color_number[i+1][j] = color_number[i][j]
ans = 1
for i in range(N):
ans *= color_number[i].count(A[i])
ans %= MOD
print(ans)
if __name__ == '__main__':
resolve()
| 0 | null | 65,584,171,302,660 | 58 | 268 |
N=int(input())
A=list(map(int,input().split()))
mul=1
if 0 in A:print("0")
else:
for i in range(N):
mul*=A[i]
if mul>pow(10,18):
print("-1")
break
elif i==N-1:print(mul)
|
def main():
n = int(input())
a = list(map(int, input().split()))
ans = 1
if 0 in a:
print(0)
return
else:
flag = True
for i in a:
ans *= i
if ans > (10 ** 18):
print(-1)
return
print(ans)
main()
| 1 | 16,055,267,869,348 | null | 134 | 134 |
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
good = [True]*N
for _ in range(M):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
if H[a] >= H[b]:
good[b] = False
if H[a] <= H[b]:
good[a] = False
print(good.count(True))
|
n,m = map(int, input().split())
ans = 0
#辺を取り除くことはabのセットとなっている要素から取り除くことと等価。頂点を消すのではない。
h_list = list(map(int, input().split()))
c = 0
max_list = [0]*(n+1)
for i in range(m):
a,b = map(int, input().split())
max_list[a] = max(max_list[a],h_list[b-1])
max_list[b] = max(max_list[b],h_list[a-1])
for i in range(1,n+1):
if h_list[i-1] > max_list[i]:
ans += 1
print(ans)
| 1 | 25,051,936,747,696 | null | 155 | 155 |
n=int(input())
if(n>=30):
print('Yes')
else:
print('No')
|
x = int(input())
print('Yes' if x>= 30 else 'No')
| 1 | 5,715,103,539,560 | null | 95 | 95 |
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left, bisect_right
N,D,A=map(int, sys.stdin.readline().split())
XH=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
XH.sort()
bit=[ 0 for _ in range(N+1) ]
#BIT 関数は全て1-indexed
def add(a,w):
while a<=N:
bit[a]+=w
a+=a&-a
def sum(a):
ret=0
while 0<a:
ret+=bit[a]
a-=a&-a
return ret
#区間[l,r]に一律wを加える
def range_add(l,r,w):
add(l,w)
add(r+1,w*-1)
#a番目のモンスターの体力を取得
def get_value(a):
return sum(a)
X=[float("-inf")]
H=[float("-inf")]
for x,h in XH:
X.append(x)
H.append(h)
for i in range(1,N+1):
if i==1:
add(i,H[i])
else:
add(i,H[i]-H[i-1]) #区間に対する更新を行うため、値の差分をBITに持つ
ans=0
for i in range(1,N+1):
h=get_value(i)
if h<=0: #モンスターの体力がゼロ以下だったら何もしない
pass
else:
x=X[i]
pos=bisect_right(X,x+2*D)-1 #攻撃範囲の一番右側を二分探索で決定
if h%A==0: #hがAで割り切れる場合
cnt=h/A
range_add(i,pos,A*cnt*-1)
else:
cnt=h/A+1 #hをAで割って余りが出る場合は攻撃回数を+1する
range_add(i,pos,A*cnt*-1)
ans+=cnt
print ans
|
from bisect import bisect_right
N,D,A=map(int,input().split())
X,H=[None]*N,{}
for i in range(N):
X[i],H[X[i]]=map(int,input().split())
X.sort()
f=[0]*N
ans=i=0
while i<N:
if i>0:
f[i]+=f[i-1]
if f[i]*A<H[X[i]]:
k=-((f[i]*A-H[X[i]])//A)
f[i]+=k
ans+=k
j=bisect_right(X,X[i]+(D<<1))
if j<N:
f[j]-=k
i+=1
print(ans)
| 1 | 82,141,745,877,308 | null | 230 | 230 |
# ALDS1_2_C.
# バブルソートと選択ソートの安定性。
from math import sqrt, floor
class card:
def __init__(self, _str):
# S3とかH8をもとに初期化。
self.kind = _str # 出力用。
self.suit = _str[0]
self.value = int(_str[1])
def cardinput():
# カードの配列からオブジェクトの配列を生成。
a = input().split()
cards = []
for i in range(len(a)):
cards.append(card(a[i]))
return cards
def show(a):
# 配列の中身を出力する。
_str = ""
for i in range(len(a) - 1):
_str += a[i].kind + " "
_str += a[len(a) - 1].kind
print(_str)
def bubble_sort(a):
# aをバブルソートする(交換回数をreturnする)。
count = 0
for i in range(1, len(a)):
k = i - 1
while k >= 0:
# a[i]を前の数と交換していき、前の方が小さかったら止める。
if a[k].value > a[k + 1].value:
a[k], a[k + 1] = a[k + 1], a[k]
count += 1
else: break
k -= 1
return count
def selection_sort(a):
# 選択ソート。その番号以降の最小値を順繰りにもってくる。
# 交換回数は少ないが比較回数の関係で結局O(n^2)かかる。
count = 0
for i in range(len(a)):
# a[i]からa[len(a) - 1]のうちa[j]が最小っていうjを取る。
# このときiとjが違うならカウントする。
# というかa[i]とa[j]が違う時カウントでしたね。
minj = i
for j in range(i, len(a)):
if a[j].value < a[minj].value: minj = j
if a[i].value > a[minj].value: count += 1; a[i], a[minj] = a[minj], a[i]
return count
def main():
N = int(input())
cards = cardinput()
# バブルソートは安定。同じvalueなら団子のようにくっつくから。
# 選択ソートは交換が飛び越えるので不安定。よって、
# バブルの結果と比較すれば安定か不安定かが分かる。
_copy = [cards[i] for i in range(N)]
bubble_sort(cards)
selection_sort(_copy)
show(cards)
print("Stable")
show(_copy)
is_stable = True
for i in range(N):
for j in range(i + 1, N):
if _copy[i].value != _copy[j].value: continue
if _copy[i].suit != cards[i].suit: is_stable = False; break
if is_stable: print("Stable")
else: print("Not stable")
if __name__ == "__main__":
main()
|
#!/usr/bin/env python3
import sys
from itertools import chain
YES = "Yes" # type: str
NO = "No" # type: str
def solve(H: int, N: int, A: "List[int]"):
if H <= sum(A):
return YES
else:
return NO
def main():
tokens = chain(*(line.split() for line in sys.stdin))
H = int(next(tokens)) # type: int
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
answer = solve(H, N, A)
print(answer)
if __name__ == "__main__":
main()
| 0 | null | 38,929,397,791,550 | 16 | 226 |
n,a,b=map(int,input().split())
mod=10**9+7
def pow(x, n):
ans = 1
while(n > 0):
if(bin(n & 1) == bin(1)):
ans = ans*x%mod
x = x*x%mod
n = n >> 1
return ans
N=pow(2,n)
def comb(c,d):
x=1
for i in range(d):
x=x*(c-i)%mod
y=1
for i in range(d):
y=y*(i+1)%mod
return x*pow(y,mod-2)%mod
A=comb(n,a)
B=comb(n,b)
print((N-A-B-1)%mod)
|
from functools import reduce
n, a, b = map(int, input().split(" "))
MOD = 10**9 + 7
def comb(n, r, mod=float("inf")):
c = 1
m = 1
r = min(n - r, r)
for i in range(r):
c = c * (n - i) % mod
m = m * (i + 1) % mod
return c * pow(m, mod - 2, mod) % mod
print((pow(2, n, MOD) - comb(n, a, MOD) - comb(n, b, MOD) - 1) % MOD)
| 1 | 66,084,763,613,722 | null | 214 | 214 |
def solve():
N = int(input())
flag = False
for i in range(9):
for j in range(9):
if((i+1)*(j+1) == N):
print("Yes")
flag = True
if flag:
break
else:
print("No")
if __name__ == "__main__":
solve()
|
nums = [int(e) for e in input().split()]
if (nums[2]+nums[4])<=nums[0] and (nums[3]+nums[4])<=nums[1] and (nums[2]-nums[4])>=0 and (nums[3]-nums[4])>=0:
print("Yes")
else:
print("No")
| 0 | null | 80,519,492,735,680 | 287 | 41 |
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
def mycol(data,col):
return [ row[col] for row in data ]
def mysort(data,col,reverse=False):
data.sort(key=lambda x:x[col],reverse=revese)
return data
def mymax(data):
M = -1*float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M,m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m,M)
return m
def mycount(ls,x):
# lsはソート済みであること
l = bisect_left(ls,x)
r = bisect_right(ls,x)
return (r-l)
def mydictvaluesort(dictionary):
return sorted( dictionary.items(), key=lambda x:x[1] )
def mydictkeysort(dictionary):
return sorted( dictionary.items(), key=lambda x:x[0] )
def myoutput(ls,space=True):
if space:
if len(ls)==0:
print(" ")
elif type(ls[0])==str:
print(" ".join(ls))
elif type(ls[0])==int:
print(" ".join(map(str,ls)))
else:
print("Output Error")
else:
if len(ls)==0:
print("")
elif type(ls[0])==str:
print("".join(ls))
elif type(ls[0])==int:
print("".join(map(str,ls)))
else:
print("Output Error")
def I():
return int(input())
def MI():
return map(int,input().split())
def RI():
return list(map(int,input().split()))
def CI(n):
return [ int(input()) for _ in range(n) ]
def LI(n):
return [ list(map(int,input().split())) for _ in range(n) ]
def S():
return input()
def MS():
return input().split()
def RS():
return list(input())
def CS(n):
return [ input() for _ in range(n) ]
def LS(n):
return [ list(input()) for _ in range(n) ]
# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())
n,k = MI()
a = RI()
L = max(a)
def mycheck(l):
count = 0
for i in range(n):
count += a[i]//l
return count <= k
lb = 0
ub = L
for i in range(100):
# print(ub,lb)
mid = (lb+ub)/2
# print(mid)
flag = mycheck(mid)
# print(flag)
if flag:
ub = mid
else:
lb = mid
ans = ceil(lb)
print(ans)
|
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
A=list(map(float, input().split()))
low=0
high=10**9+1
while high-low!=1:
mid=(high+low)//2
cut_temp=0
ans=-1
for a in A:
cut_temp+=-(-a//mid)-1
if cut_temp>K:
low=mid
else:
high=mid
print(high)
| 1 | 6,544,274,286,368 | null | 99 | 99 |
listA=[]
listOP=[]
listB=[]
count=0
while True:
a,op,b=input().split()
listA.append(int(a))
listOP.append(op)
listB.append(int(b))
if op=="?":
del listA[len(listA)-1]
del listOP[len(listOP)-1]
del listB[len(listB)-1]
break
#入力パートここまで。計算出力パートここから
while count<=len(listA)-1:
if listOP[count]=="+":
print(listA[count]+listB[count])
elif listOP[count]=="-":
print(listA[count]-listB[count])
elif listOP[count]=="*":
print(listA[count]*listB[count])
elif listOP[count]=="/":
print(listA[count]//listB[count])
else:
print("ERROR")
count+=1
|
def solve(a, op, b):
if op == '+':
return a + b
elif op == '-':
return a - b
elif op == '*':
return a * b
elif op == '/':
return a // b
return None
if __name__ == '__main__':
while True:
a, op, b = input().split()
if op == '?': break
print(solve(int(a), op, int(b)))
| 1 | 673,438,894,002 | null | 47 | 47 |
l=map(int,raw_input().split())
a=l[0]
b=l[1]
c=l[2]
if a<b<c:
print 'Yes'
else:
print 'No'
|
a,b,c=map(int,raw_input().split())
if a<b<c: print "Yes"
else: print "No"
| 1 | 393,175,675,970 | null | 39 | 39 |
def fib2(n):
a1, a2 = 1, 0
while n > 0:
a1, a2 = a1 + a2, a1
n -= 1
return a1
n = int(input())
print(fib2(n))
|
#C
A, B =map(int,input().split())
import math
price=[]
for i in range(10100):
if math.floor(i*0.08)==A and math.floor(i*0.1)==B:
price.append(i)
if len(price)==0:
print(-1)
else:
print(sorted(price)[0])
| 0 | null | 28,435,187,450,528 | 7 | 203 |
import sys,math
#DEBUG=True
DEBUG=False
if DEBUG:
f=open("202007_2nd/C_input.txt")
else:
f=sys.stdin
# Find the number of triples of integers (x,y,z) such that
# (x+y)**2 + (y+z)**2 + (x+z)**2 = 2*N
N=int(f.readline().strip())
ans=[0 for _ in range(N)]
I=int(math.sqrt(N))
for __ in range(I):
A2=N-((__+1)**2)
if A2<=0:
break
I2=int(math.sqrt(A2))
for ___ in range(I2):
A3=A2-((___+1)**2)
if A3<=0:
break
I3=int(math.sqrt(A3))
for ____ in range(I3):
tmp=((__+___+2)**2)+((___+____+2)**2)+((__+____+2)**2)
if tmp<=2*N:
ans[int(tmp/2)-1]+=1
else:
break
for _ in range(N):
print(ans[_])
f.close()
|
n=int(input())
ans = [0] * 100000
for x in range(1,101):
for y in range(1,101):
for z in range(1,101):
ans[x*x+y*y+z*z+x*y+y*z+z*x]+=1
for i in range(1,n+1):
print(ans[i])
| 1 | 7,971,402,304,740 | null | 106 | 106 |
r, g, b = list(map(int, input().split()))
k = int(input())
count = 0
while r >= g:
g *= 2
count += 1
while g >= b:
b *= 2
count += 1
if k >= count:
print('Yes')
else:
print('No')
|
a,b,c,k=map(int,open(0).read().split())
#while k:k-=1;t=a<b;b*=2-t;c*=1+t
while k:k-=1;exec(f'{"bc"[a<b]}*=2')
#while k:k-=1;exec('%c*=2'%'bc'[a<b])
#while k:k-=1;vars()['bc'[a<b]]*=2
print('NYoe s'[b<c::2])
| 1 | 6,894,114,014,788 | null | 101 | 101 |
import itertools
N,K = map(int,input().split())
A = list(map(int,input().split()))
for i in range(K):
TEMP = [0]*(N+1)
for j in range(N):
TEMP[max(0,j-A[j])] +=1
TEMP[min(N,j+A[j]+1)] -=1
A = list(itertools.accumulate(TEMP))
if A[0] == N and A[N-1] == N:
break
A.pop()
print(*A)
|
import sys
from numba import njit
readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
@njit(cache=True)
def solve(n, k, a):
if k == 0:
return a
b = [0]*n
for _ in range(k):
for i in range(n):
if i > a[i]:
b[i-a[i]] += 1
else:
b[0] += 1
if i + a[i] + 1 < n:
b[i + a[i] + 1] -= 1
for i in range(n-1):
b[i+1] += b[i]
a[i] = 0
a[-1] = 0
b, a = a, b
if min(a) >= n:
break
return a
solve(0, 0, [0, 1, 2])
n, k = nm()
a = nl()
print(*solve(n, k, a))
| 1 | 15,411,146,271,916 | null | 132 | 132 |
if __name__ == '__main__':
from statistics import pstdev
while True:
# ??????????????\???
data_count = int(input())
if data_count == 0:
break
scores = [int(x) for x in input().split(' ')]
# ?¨??????????????¨????
result = pstdev(scores)
# ???????????????
print('{0:.8f}'.format(result))
|
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)
| 0 | null | 51,264,183,281,830 | 31 | 247 |
import sys
import fractions
input = sys.stdin.readline
mod = 10 ** 9 + 7
N = int(input().strip())
A = list(map(int, input().strip().split(" ")))
lcm = 1
for a in A:
lcm = a // fractions.gcd(a, lcm) * lcm
ans = 0
for a in A:
ans += lcm // a
print(ans % mod)
|
import math
x1, y1, x2, y2 = map(float, raw_input().split())
L = math.sqrt((x1-x2)**2 + (y1-y2)**2)
print L
| 0 | null | 43,859,985,263,600 | 235 | 29 |
while True:
k=map(int,raw_input().split(" "))
if k[0]==k[1]==0:
break
ct=0
a=0
b=0
c=0
max=k[0]
sum=k[1]
a=max+1
while True:
a-=1
b=a-1
c=sum-a-b
if not a>c:
print ct
break
while b>c:
if c>0:
ct+=1
b-=1
c+=1
|
while(True):
i=0
a=list(map(int,input().split()))
if(a[0]==0 and a[1]==0):
break
for x in range(2,a[0]):
sum=a[1]-x
for y in range(1,x):
if (sum-y<a[0]+1 and sum-y>x):
i+=1
print(i)
| 1 | 1,293,183,372,892 | null | 58 | 58 |
N = int(input())
A = list(map(int, input().split()))
A.sort()
result = 1
for i in range(N):
result *= A[i]
if result > 10**18:
result = -1
break
print(result)
|
n = int(input())
l = list(map(int, input().split()))
l.sort()
c = 1
i = 0
while i < n:
c *= l[i]
i += 1
if c > 1000000000000000000:
break
if c <= 1000000000000000000:
print(c)
else:
print(-1)
| 1 | 16,269,185,938,546 | null | 134 | 134 |
tmp = map(int, raw_input().split())
tmp.sort()
for i in tmp:
print i,
|
s = input()
t = ''
for i in range(0, len(s)):
if s[i] == '?':
t += 'D'
else:
t += s[i]
print(t)
| 0 | null | 9,369,976,941,740 | 40 | 140 |
def insert_sort(A, n, g, cnt):
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j -= g
cnt += 1
A[j+g] = v
return cnt
def shellSort(A, n):
cnt = 0
G = []; h = 0
while h <= n:
if 3 * h + 1 <= n:
h = 3 * h + 1
G.append(h)
else: break
G = sorted(G, reverse=True)
m = len(G)
for i in range(m):
cnt = insert_sort(A, n, G[i], cnt)
return m, cnt, G
A = []
n = int(input())
for i in range(n):
A.append(int(input()))
m, cnt, G = shellSort(A, n)
print(m)
for i in range(m):
if i == m - 1:
print(G[i])
else:
print(G[i], end=" ")
print(cnt)
for i in A:
print(i)
|
while True:
n, x = map(int, input().split())
if n == 0 and x == 0:
break
c = 0
for i in range(1, int(x/3)+2):
for j in range(i+1, int(x/2)+2):
k = x - i - j
if k <= j:
break
elif k <= n:
c += 1
print(c)
| 0 | null | 658,926,877,880 | 17 | 58 |
import math
def koch(n, h, i, j, k):
if n == 0:
return
sx = (h*2+j)/3
sy = (i*2+k)/3
tx = (h+j*2)/3
ty = (i+k*2)/3
ux = (tx-sx)*math.cos(math.pi/3) - (ty-sy)*math.sin(math.pi/3) + sx
uy = (tx-sx)*math.sin(math.pi/3) + (ty-sy)*math.cos(math.pi/3) + sy
koch(n-1, h, i, sx, sy)
print sx, sy
koch(n-1, sx, sy, ux, uy)
print ux, uy
koch(n-1, ux, uy, tx, ty)
print tx, ty
koch(n-1, tx, ty, j, k)
n = input()
px = float(0)
py = float(0)
qx = float(100)
qy = float(0)
print px, py
koch(n, px, py, qx, qy)
print qx, qy
|
from functools import lru_cache
def popcnt(x):
return bin(x).count("1")
@lru_cache(maxsize=None)
def rec(n):
if n == 0:
return 0
else:
return rec(n % popcnt(n)) + 1
n = int(input())
x = int(input(), 2)
# 事前計算
cnt = popcnt(x)
init_big = x % (cnt + 1)
if cnt == 1:
init_small = 0
else:
init_small = x % (cnt - 1)
# 差分計算
result = []
for i in range(n):
if not (x >> i) & 1:
result.append((init_big + pow(2, i, cnt + 1)) % (cnt + 1))
elif x == 1 << i or cnt - 1 == 0:
result.append("x")
else:
result.append((init_small - pow(2, i, cnt - 1)) % (cnt - 1))
ans = []
for x in result[::-1]:
if x == "x":
ans.append(0)
else:
ans.append(rec(x) + 1)
print(*ans, sep="\n")
| 0 | null | 4,183,860,272,688 | 27 | 107 |
n=int(input())
a=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))
d={}
for i in range(2**n):
c=0
for j in range(n):
if (i>>j)&1:
c+=a[j]
d[c]=1
for i in range(q):
if m[i] in d:
print("yes")
else:
print("no")
|
n = int(input())
a = list(map(int,input().split()))
m = int(input())
q = list(map(int,input().split()))
cand = []
for i in range(2**n):
tmp = 0
for j in range(n):
if(i>>j)&1:
tmp += a[j]
if tmp not in cand:
cand.append(tmp)
for i in q:
print('yes' if i in cand else 'no')
| 1 | 99,839,732,402 | null | 25 | 25 |
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
A, B = M()
if A < 2*B:
print(0)
else:
print(A-2*B)
|
import math
a,b,C=map(float,input().split())
C*=math.pi/180
print('%.8f'%(a*b*math.sin(C)/2))
print('%.8f'%(a+b+(a*a+b*b-2*a*b*math.cos(C))**.5))
print('%.8f'%(b*math.sin(C)))
| 0 | null | 83,387,938,777,052 | 291 | 30 |
from collections import defaultdict
N,P=map(int,input().split())
S=input()
if P==2 or P==5:
ans=0
for i in range(N):
if int(S[i])%P==0:
ans+=i+1
print(ans)
else:
d=defaultdict(int)
a=0
for i in range(N):
a+=int(S[N-i-1])*pow(10,i,P)
a%=P
d[a]+=1
ans=d[0]
for v in d.values():
ans+=v*(v-1)//2
print(ans)
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N, P = map(int, readline().split())
S = [int(i) for i in readline().strip()[::-1]]
ans = 0
if P == 2 or P == 5:
for i, s in enumerate(S):
if s % P == 0:
ans += N - i
print(ans)
exit()
a = {}
a[0] = 1
t = 0
x = 1
for s in S:
t += s * x
t %= P
if t in a:
a[t] += 1
else:
a[t] = 1
x *= 10
x %= P
ans = 0
for v in a.values():
ans += v * (v-1) // 2
print(ans)
if __name__ == "__main__":
main()
| 1 | 58,152,573,696,000 | null | 205 | 205 |
N = int(input())
S = str(input())
cnt = 0
for i in range(N-2):
if S[i]=='A' and S[i+1]=='B' and S[i+2]=='C':
cnt += 1
print(cnt)
|
N=int(input())
S=input()
count=0
for i in range(N):
if S[i]=='A' and i!=N-1:
if S[i+1]=='B' and i!=N-2:
if S[i+2]=='C':
count+=1
print(count)
| 1 | 99,498,148,880,328 | null | 245 | 245 |
r = int(input())
s = r*r
print(int(s))
|
r = int(input())
S = int(r**2)
print(S)
| 1 | 145,755,067,750,420 | null | 278 | 278 |
N = int(input())
X = int(input(),2)
def popcount(n):
return bin(n).count('1')
def f(n):
if n== 0:
return 1
count = 1
while n!=0:
n = n%popcount(n)
count += 1
return count
X_popcount = popcount(X)
X_mod_p = X%(X_popcount+1)
if X_popcount != 1:
X_mod_m = X%(X_popcount-1)
for i in range(N):
X_i = X ^ (1<<(N-i-1))
if X_i == 0:
ans = 0
elif X>>(N-i-1)&1 == 1:
if X_popcount == 1:
ans = 1
else:
ans = f((X_mod_m-pow(2, N-i-1, X_popcount-1))%(X_popcount-1))
else:
ans = f((X_mod_p+pow(2, N-i-1, X_popcount+1))%(X_popcount+1))
print(ans)
|
def solve():
N = int(input())
X = input()
X_10 = int(X,2)
r = X.count("1")
r0 = r-1
r1 = r+1
ans = []
s0 = X_10 % r0 if r != 1 else None
s1 = X_10 % r1
for i in range(N):
if X[i] == '0':
ans.append(f((s1 + pow(2,N-1-i,r1)) % r1))
else:
if r0 == 0:
ans.append(0)
else:
ans.append(f((s0 - pow(2,N-1-i,r0)) % r0))
print(*ans, sep='\n')
def f(N):
cnt = 1
while N != 0:
N = N % popcount(N)
cnt += 1
return cnt
def popcount(N):
b = bin(N)
cnt = 0
for i in range(2,len(b)):
if b[i] == '1':
cnt += 1
return cnt
if __name__ == '__main__':
solve()
| 1 | 8,289,153,025,828 | null | 107 | 107 |
import math
A,B,N = map(int,input().split())
if N >= B:
N = B - 1
print(math.floor(A*N/B) - A * math.floor(N/B))
|
a, b, n = [int(x) for x in input().split()]
n = min(n,b-1)
x = max(0,n-a-a-a-a)
s = -a
for i in range(x,n+1):
s = max(s,(a*i//b)-a*(i//b))
print(s)
| 1 | 28,145,167,823,612 | null | 161 | 161 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import breadth_first_order, depth_first_order, shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
import sys
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
stdin = sys.stdin
ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
max_ = 10 ** 18
N = ni()
A = na()
A.sort()
ans = 1
for i in range(N):
ans *= A[i]
if ans > max_:
ans = -1
break
print(ans)
|
N = int(input())
A = map(int,input().split())
ans = 1
for x in A:
ans *= x
if ans > 10**18:
ans = 10**18+1
print(-1 if ans > 10**18 else ans)
| 1 | 16,206,350,427,680 | null | 134 | 134 |
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()))
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
p = p[:x]
q = q[:y]
l = p + q + r
l.sort(reverse = True)
print(sum(l[:x+y]))
|
''' 1.降序排列,选出x个红苹果,y个绿苹果
2.使用c个无色苹果去更新这x+y个苹果中的小值,直到最小也比无色苹果的大为止'''
nums = [int(i) for i in input().split()]
x = nums[0]
y = nums[1]
a = nums[2]
b = nums[3]
c = nums[4]
redApples = [int(i) for i in input().split()]
greenApples = [int(i) for i in input().split()]
colorless = [int(i) for i in input().split()]
redApples.sort(reverse=True)
greenApples.sort(reverse=True)
colorless.sort(reverse=True)
redApples = redApples[:x]
greenApples = greenApples[:y]
res = redApples+greenApples
res.sort(reverse=True)
currIndex = len(res)-1
for i in range(len(colorless)):
if colorless[i] <= res[currIndex]:
break
res[currIndex] = colorless[i]
currIndex -= 1
if currIndex < 0:
break
print(sum(res))
| 1 | 44,637,286,854,030 | null | 188 | 188 |
t = list(input())
t.reverse()
tmptmp = "P"
for i in range(len(t)):
if i == 0:
tmp = t[i]
continue
if tmp == "?" and tmptmp != "D":
t[i-1] = "D"
elif tmp == "?" and tmptmp == "D" and t[i] != "D":
t[i-1] = "D"
elif tmp == "?" and tmptmp == "D" and t[i] == "D":
t[i-1] = "P"
tmptmp = t[i-1]
tmp = t[i]
t.reverse()
if len(t) > 1:
if t[0] == "?" and t[1] == "D":
t[0] = "P"
elif t[0] == "?" and t[1] == "P":
t[0] = "D"
if len(t) == 1:
t[0] = "D"
t = "".join(t)
print(t)
|
def solve():
K,X = [int(input_elem) for input_elem in input().split()]
if K*500 >= X:
print("Yes")
else:
print("No")
if __name__ == "__main__":
solve()
| 0 | null | 58,459,763,605,052 | 140 | 244 |
A_int_list = list(map(int, input().split()))
if 22 <= sum(A_int_list):
print('bust')
else:
print('win')
|
a_1, a_2, a_3 = map(int, input().split())
print('bust' if a_1+a_2+a_3 >= 22 else 'win')
| 1 | 118,684,175,133,380 | null | 260 | 260 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
WHITE = 0
GRAY = 1
BLACK = 2
def dbg_record(records):
for index, record in enumerate(records):
print("???????????????: %d" % index)
if isinstance(record, dict):
print("??\??????: %d" % record.get("visit", -1))
print("?????????: %d" % record.get("leave", -1))
else:
print("?????????")
print("")
def dfs(matrix):
def internal_dfs(node_id, current_time):
if state[node_id] == WHITE:
# ?¨??????????
state[node_id] = GRAY
stack.append(node_id)
records[node_id] = {"visit": current_time} # ?¨??????????????¨????
# ?¬?????¨????????????¨?????§????????????????????¢???
next_id = None
for index in range(len(matrix)):
if matrix[node_id][index] == 1 and state[index] == WHITE:
next_id = index
break
if next_id is not None:
return internal_dfs(next_id, current_time + 1)
elif 0 < len(stack):
# ?¬?????¨????????????¨?????§?????????????????????????????????????????°?????????
return internal_dfs(stack.pop(), current_time + 1)
elif state[node_id] == GRAY:
# ????????????
# ?¬?????¨????????????¨?????§????????????????????¢???
next_id = None
for index in range(len(matrix)):
if matrix[node_id][index] == 1 and state[index] == WHITE:
next_id = index
break
if next_id is not None:
stack.append(node_id)
return internal_dfs(next_id, current_time)
elif 0 < len(stack):
# ?¬?????¨????????????¨?????§?????????????????????????????????????????°?????????
state[node_id] = BLACK
records[node_id]["leave"] = current_time # ????????????????¨????
return internal_dfs(stack.pop(), current_time + 1)
else: # ??????????§????????????£???????????¨??? (node_id should be 0)
state[node_id] = BLACK
records[node_id]["leave"] = current_time
return current_time
elif state[node_id] == BLACK:
print("Black!!")
state = [WHITE] * len(matrix) # White, Gray, Black
records = [None] * len(matrix) # Save time when the node is processed
stack = []
current_time = 0
while True:
node_id = None
for index, record in enumerate(records):
if record is None:
node_id = index
break
if node_id is None:
break
else:
current_time = internal_dfs(node_id, current_time + 1)
return records
if __name__ == "__main__":
# ??????????????????
# lines = [
# "6",
# "1 2 2 3",
# "2 2 3 4",
# "3 1 5",
# "4 1 6",
# "5 1 6",
# "6 0",
# ]
lines = sys.stdin.readlines()
# Create n * n matrix
dimension = int(lines[0])
matrix = []
for x in range(dimension):
matrix.append([0] * dimension)
# Set edge info
for index, line in enumerate(lines[1:]):
for edge in [int(x) for x in line.strip().split(" ")[2:]]:
matrix[index][edge - 1] = 1
records = dfs(matrix)
for index, line in enumerate(records):
if line is not None:
print("%d %d %d" % (index + 1, line.get("visit", -1), line.get("leave", -1)))
else:
print("%d None None" % (index + 1))
|
N = int(input())
Adj = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
u = list(map(int, input().split()))
if u[1] > 0:
for k in u[2: 2+u[1]]:
Adj[u[0] - 1][k - 1] = 1
color = [0] * N #1: visited, 0: not visited, 2: completed
s = [0] * N # start
f = [0] * N # finish
time = 0
def DFS(u):
global time
color[u-1] = 1
time += 1
s[u-1] = time
for i in range(1, N+1):
if Adj[u-1][i-1] == 1 and color[i-1] == 0:
DFS(i)
color[u-1] = 2
time += 1
f[u-1] = time
for i in range(1, N+1):
if color[i-1] == 0:
DFS(i)
for i in range(N):
print('{} {} {}'.format(i+1, s[i], f[i]))
| 1 | 2,774,348,050 | null | 8 | 8 |
import sys
def gcd(a,b):
r= b % a
while r != 0:
a,b = r,a
r = b % a
return a
def lcm(a,b):
return int(a*b/gcd(a,b))
for line in sys.stdin:
a,b = sorted(map(int, line.rstrip().split(' ')))
print("{} {}".format(gcd(a,b),lcm(a,b)))
|
import sys
for l in sys.stdin:
x,y=map(int, l.split())
m=x*y
while x%y:x,y=y,x%y
print "%d %d"%(y,m/y)
| 1 | 755,906,622 | null | 5 | 5 |
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
n = I()
a = LI()
dic = collections.Counter(a)
als = 0
exl = [0 for _ in range(n+1)]
for key, value in dic.items():
if value >= 3:
choice = (value)*(value-1)//2
choice1 = (value-1)*(value-2)//2
als += choice
exl[key] = choice1 - choice
elif value == 2:
choice = (value)*(value-1)//2
als += choice
exl[key] = -choice
for ball in a:
choices = als + exl[ball]
print(choices)
main()
|
N, M, X = map(int, input().split())
BOOKS = [tuple(map(int, input().split())) for _ in range(N)]
INF = 10 ** 8
ans = INF
for selection in range(1 << N):
price = 0
values = [0] * M
for i in range(N):
if selection & (1 << i):
x = BOOKS[i]
price += x[0]
for j in range(M):
values[j] += x[j+1]
if all(v >= X for v in values):
ans = min(ans, price)
if ans == INF:
print(-1)
else:
print(ans)
| 0 | null | 35,164,501,428,058 | 192 | 149 |
x = input()
while x !='0':
x_list = list(x)
#print(x_list)
#print("{0}".format(len(x_list)))
sum = 0
for i in range(len(x_list)):
sum += int(x_list[i])
print(sum)
x = input()
|
import sys
def main():
for x in sys.stdin:
if x == "0\n":
break
else:
X = list(x)
total = 0
for i in range(len(X) - 1):
total += int(X[i])
print(total)
if __name__ == "__main__":
main()
| 1 | 1,588,817,437,832 | null | 62 | 62 |
a, b = input().split()
a = int(a)
b = int(b.replace(".",""))
c = a * b
ans = c//100
print(ans)
|
X, K, D = map(int, input().split())
if X - K * D >= 0:
ans = abs(X - K * D)
elif X + K * D <= 0:
ans = abs(X + K * D)
else:
n = int(abs(X - K * D) / (2 * D))
ans = min(abs(X - K * D + n * 2 * D), abs(X - K * D + (n + 1) * 2 * D))
print(ans)
| 0 | null | 10,917,445,069,230 | 135 | 92 |
n = input()
if n[-1]== "2" or n[-1]== "4" or n[-1]== "5" or n[-1]== "7" or n[-1]== "9":
print("hon")
elif n[-1]== "3":
print("bon")
else:
print("pon")
|
n = input()
c = n[-1]
if c in "24579":
print("hon")
elif c in "0168":
print("pon")
else:
print("bon")
| 1 | 19,406,248,238,300 | null | 142 | 142 |
N=int(input())
S=input()
ans=""
for i in range(len(S)):
ans+=chr(ord("A")+(ord(S[i])-ord("A")+N)%26)
print(ans)
|
def insert(S, string):
S.add(string)
def find(S, string):
if string in S:
print 'yes'
else:
print 'no'
n = input()
S = set()
for i in range(n):
tmp1, tmp2 = map(str, raw_input().split())
if tmp1 == 'insert':
insert(S, tmp2)
elif tmp1 == 'find':
find(S, tmp2)
else:
print 'error!'
| 0 | null | 67,123,595,903,650 | 271 | 23 |
def main():
_ = int(input())
num_tuple = tuple(map(int, input().split()))
count = 0
for i, num in enumerate(num_tuple):
if ((i+1)*num) % 2 == 1:
count += 1
print(count)
if __name__ == '__main__':
main()
|
n = int(input())
a = list(map(int, input().split()))
ans = 0
for num in range(1, n+1, 2):
if a[num-1] % 2 != 0:
ans += 1
print(ans)
| 1 | 7,707,349,106,028 | null | 105 | 105 |
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N,S = MI()
A = [0] + LI()
mod = 998244353
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
for j in range(S+1):
if j >= A[i]:
dp[i][j] = 2*dp[i-1][j] + dp[i-1][j-A[i]]
dp[i][j] %= mod
else:
dp[i][j] = 2*dp[i-1][j]
dp[i][j] %= mod
print(dp[-1][-1])
|
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
dp = [[0] * (S + 1) for _ in range(N + 1)]
dp[0][0] = 1
for i, a in enumerate(A):
for j in range(S + 1):
dp[i + 1][j] += 2 * dp[i][j]
dp[i + 1][j] %= MOD
if j + a <= S:
dp[i + 1][j + a] += dp[i][j]
dp[i + 1][j + a] %= MOD
print(dp[-1][-1] % MOD)
| 1 | 17,748,625,259,960 | null | 138 | 138 |
n=int(input())
s=[str(input()) for _ in range(n)]
from collections import Counter
results = Counter(s)
max_num = results.most_common()[0][1]
max_key_list = [kv[0] for kv in results.items() if kv[1] == max_num]
for i in sorted(max_key_list):
print(i)
|
N = int(input())
S = [input() for i in range(N)]
d = {}
m = 0
for i in S:
if i in d:
d[i] += 1
if d[i] > m:
m = d[i]
else:
d[i] = 1
d = dict(sorted(d.items(), reverse=True))
a = {}
for i in d.keys():
if m <= d[i]:
a[i] = 0
a = sorted(a)
for i in a:
print(i)
| 1 | 69,707,431,815,580 | null | 218 | 218 |
INF = int(1e18)
def merge(A, left, mid, right):
n1 = mid - left
n2 = right - mid
L = [A[left + i] for i in range(n1)]
R = [A[mid + i] for i in range(n2)]
L.append(INF)
R.append(INF)
i, j = 0, 0
count = 0
for k in range(left, right):
count += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return count
def merge_sort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2
c1 = merge_sort(A, left, mid)
c2 = merge_sort(A, mid, right)
c = merge(A, left, mid, right)
return c + c1 + c2
else:
return 0
if __name__ == '__main__':
n = int(input())
A = list(map(int, input().split()))
c = merge_sort(A, 0, n)
print(" ".join(map(str, A)))
print(c)
|
def main():
n = input()
A = map(int,raw_input().split())
c = mergeSort(A,0,n)
for i in range(n-1):
print A[i],
print A[-1]
print c
def merge(A,left,mid,right):
n1 = mid - left
n2 = right - mid
L = [A[left+i] for i in range(n1)]
L += [float("inf")]
R = [A[mid+i] for i in range(n2)]
R += [float("inf")]
i = 0
j = 0
for k in range(left,right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return i+j
def mergeSort(A,left,right):
if left+1 < right:
mid = (left+right)/2
k1 = mergeSort(A,left,mid)
k2 = mergeSort(A,mid,right)
k3 = merge(A,left,mid,right)
return k1+k2+k3
else:
return 0
if __name__ == "__main__":
main()
| 1 | 111,039,011,682 | null | 26 | 26 |
n, m, k = map(int, input().split(" "))
a = [0]+list(map(int, input().split(" ")))
b = [0]+list(map(int, input().split(" ")))
for i in range(1, n+1):
a[i] += a[i - 1]
for i in range(1, m+1):
b[i] += b[i - 1]
j,mx= m,0
for i in range(n+1):
if a[i]>k:
break
while(b[j]>k-a[i]):
j-=1
if (i+j>mx):
mx=i+j
print(mx)
|
n,m,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
def make_sumlist(book_list):
sumnum=0
container=[0]
for i in book_list:
container.append(sumnum+i)
sumnum+=i
return container
total_a=make_sumlist(a)
total_b=make_sumlist(b)
# print(n,m,k)
# print(total_a)
# print(total_b)
#r個読めるか
def readable(r):
#全部読んでも無理
if r>n+m:
return False
if r==0:
return True
max_book=100000000000
for a_n in range(max(0,r-m),min(n,r)+1):
b_n=r-a_n
# print(a_n,b_n)
book_sum=total_a[a_n]+total_b[b_n]
# print(book_sum)
max_book=min(max_book,book_sum)
if max_book<=k:
return True
return False
def nibuntansaku(start,end):
if start==end:
return start
middle=(start+end)//2+1
if readable(middle):
start=middle
else:
end=middle-1
return nibuntansaku(start,end)
print(nibuntansaku(0,k))
| 1 | 10,800,729,019,238 | null | 117 | 117 |
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
S = "abcdefghijk"
# q = [("", -1)]
ans = 0
def dfs(a, mx):
# q = [(cur, mx)]
# while q:
# a, mx = q.pop()
if len(a) == N:
print(a)
return
for c in range(len(S[:mx+2])):
t = a
t += S[:mx+2][c]
dfs(t, max(c, mx))
dfs("", -1)
|
n1 = input()
A = map(int, raw_input().split())
n2 = input()
q = map(int, raw_input().split())
list = set()
def solve(i,m):
if m == 0:
return True
if i >= n1 or m > sum(A):
return False
res = solve(i+1,m) or solve(i+1,m-A[i])
return res
for m in q:
if solve(0,m):
print "yes"
else:
print "no"
| 0 | null | 26,384,827,574,810 | 198 | 25 |
mountains = []
for x in range(10):
mountains.append(int(raw_input()))
mountains.sort()
print(mountains[-1])
print(mountains[-2])
print(mountains[-3])
|
x = list(map(int, input().split()))
print(x[2], x[0], x[1])
| 0 | null | 18,935,958,427,896 | 2 | 178 |
array = [int(input()) for i in range(10)]
array.sort()
for i in range(9,6,-1):
print(array[i])
|
def solve(n):
ret = []
while n > 26:
if n % 26 == 0:
ret = [26] + ret
n = (n - 26) // 26
else:
ret = [n % 26] + ret
n = n // 26
ret = [n] + ret
return ret
n = int(input())
ans = ''.join([chr(ord('a') + i - 1) for i in solve(n)])
print(ans)
| 0 | null | 6,004,768,995,314 | 2 | 121 |
N=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(N-1):
if a[i]>=a[i+1]:
ans+=a[i]-a[i+1]
a[i+1]=a[i]
print(ans)
|
import sys
input = sys.stdin.readline
n = int(input())
L = [int(x) for x in input().split()]
cnt = 0
def Merge(S, l, m, r):
global cnt
cnt += r - l
L = S[l:m] + [float('inf')]
R = S[m:r] + [float('inf')]
i, j = 0, 0
for k in range(l, r):
if L[i] < R[j]:
S[k] = L[i]
i += 1
else:
S[k] = R[j]
j += 1
return
def MergeSort(S, l, r):
if r - l > 1:
m = (l + r) // 2
MergeSort(S, l, m)
MergeSort(S, m, r)
Merge(S, l, m, r)
return
MergeSort(L, 0, n)
print(*L)
print(cnt)
| 0 | null | 2,313,787,816,000 | 88 | 26 |
a,b=map(str, input().split())
print(b,a,sep="")
|
K=int(input())
S=input()
if len(S)<=K:
print(S)
else:
for i in range(K):
print(S[i],end="")
print("...")
| 0 | null | 61,172,552,329,658 | 248 | 143 |
n=int(input())
s,t=input().split()
ans=''
for i in range(2*n):
ans=ans+(s[i//2] if i%2==0 else t[(i-1)//2])
print(ans)
|
n=int(input())
li = input().split()
a=''
for i in range(n):
a+=li[0][i]+li[1][i]
print(a)
| 1 | 112,539,901,089,760 | null | 255 | 255 |
import statistics
while True:
n = int(input())
if n == 0: break
s = list(map(int, input().split()))
print(statistics.pstdev(s))
|
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
d = abs(A-B)
if d-(V-W)*T<=0:
print("YES")
else:
print("NO")
| 0 | null | 7,620,411,182,630 | 31 | 131 |
text = input()
ab = text.split()
a = int(ab[0])
b = int(ab[1])
if(a<b):
print("a < b")
elif(a>b):
print("a > b")
else:
print("a == b")
|
# encoding:utf-8
input = map(int, raw_input().split())
a, b = input
if a == b:
print("a == b")
elif a > b:
print("a > b")
else:
print("a < b")
| 1 | 360,250,930,170 | null | 38 | 38 |
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for _ in range(n):
s = input()
if s == "AC":
ac += 1
elif s == "WA":
wa += 1
elif s == "TLE":
tle += 1
elif s == "RE":
re += 1
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))
|
N = int(input())
print(N + N**2 + N**3)
| 0 | null | 9,452,768,802,078 | 109 | 115 |
while True:
l=list(input())
if l==["0"]:
break
print(sum(map(int,l)))
|
while True:
total = 0
x = input()
if x == "0": break
for c in x:
total += int(c)
print(total)
| 1 | 1,573,260,782,844 | null | 62 | 62 |
#A1 ~ Aiまでの和 O(logN)
def BIT_query(BIT,idx):
res_sum = 0
while idx > 0:
res_sum += BIT[idx]
idx -= idx&(-idx)
return res_sum
#Ai += x O(logN)
def BIT_update(BIT,idx,x):
while idx <= n:
BIT[idx] += x
idx += idx&(-idx)
return
alps = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
s = list(input())
char_hd_d = {}
for alp in alps:
char_hd_d[alp] = [0]*(n+1)
for i, si in enumerate(s):
BIT_update(char_hd_d[si], i+1, 1)
q = int(input())
ansl = []
for _ in range(q):
command, a, b = input().split()
if command == '1':
i = int(a)
c = b
i_char = s[i-1]
BIT_update(char_hd_d[i_char], i, -1)
BIT_update(char_hd_d[c], i, 1)
s[i-1] = c
else:
l,r = int(a),int(b)
cnt = 0
for alp in alps:
if BIT_query(char_hd_d[alp], r) - BIT_query(char_hd_d[alp], l-1) > 0:
cnt += 1
ansl.append(cnt)
for a in ansl:
print(a)
|
#ABC157E
n = int(input())
s = list(input())
q = int(input())
bits = [[0 for _ in range(n+1)] for _ in range(26)]
sl = []
for alp in s:
alpord = ord(alp) - 97
sl.append(alpord)
#print(bits) #test
#print(sl) #test
#print('クエリ開始') #test
def query(pos):
ret = [0] * 26
p = pos
while p > 0:
for i in range(26):
ret[i] += bits[i][p]
p -= p&(-p)
return ret
def update(pos, a, x):
r = pos
while r <= n:
bits[a][r] += x
r += r&(-r)
for i in range(n):
update(i+1, sl[i], 1)
#print(bits) #test
for _ in range(q):
quer, xx, yy = map(str, input().split())
if quer == '1':
x = int(xx)
y = ord(yy) - 97
if sl[x-1] == y:
continue
else:
update(x, sl[x-1], -1)
update(x, y, 1)
sl[x-1] = y
#print('クエリ1でした') #test
#print(bits) #test
#print(sl) #test
else:
x = int(xx)
y = int(yy)
cnt1 = query(y)
cnt2 = query(x-1)
#print('クエリ2です') #test
#print(cnt1) #test
#print(cnt2) #test
ans = 0
for i in range(26):
if cnt1[i] - cnt2[i] > 0:
ans += 1
print(ans)
| 1 | 62,256,174,361,700 | null | 210 | 210 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.