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
|
---|---|---|---|---|---|---|
while True:
ans = 0
x = raw_input()
if x == "0":
break
for i in x:
ans += int(i)
print ans
|
x=int(input())
if x<100:
print("0")
exit()
while 1:
tm=(str(x)[-2:])
if int(tm) > 5:
x-=105
else:
print("1")
exit()
if x<100:
print("0")
exit()
| 0 | null | 64,403,864,989,490 | 62 | 266 |
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def main():
F = [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]
K = II()
print(F[K-1])
if __name__ == '__main__':
main()
|
suuretu=[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]
K=int(input())
ans=suuretu[K-1]
print(ans)
| 1 | 50,227,736,088,768 | null | 195 | 195 |
import heapq
X,Y,A,B,C = map(int,input().split())
qa = list(map(int,input().split()))
qb = list(map(int,input().split()))
r = list(map(int,input().split()))
qa.sort(reverse=True)
qb.sort(reverse=True)
r.sort(reverse=True)
qa_ans = qa[:X]
qb_ans = qb[:Y]
heapq.heapify(qa_ans)
heapq.heapify(qb_ans)
for i in range(C):
r_max = r[i]
qa_min = heapq.heappop(qa_ans)
qb_min = heapq.heappop(qb_ans)
if (r_max>qa_min) or (r_max>qb_min):
if qa_min >qb_min:
heapq.heappush(qa_ans,qa_min)
heapq.heappush(qb_ans,r_max)
else:
heapq.heappush(qa_ans,r_max)
heapq.heappush(qb_ans,qb_min)
else:
heapq.heappush(qa_ans, qa_min)
heapq.heappush(qb_ans, qb_min)
break
print(sum(qa_ans)+sum(qb_ans))
|
a,b,c,d=map(float,input().split())
e=(c-a)**2
f=(d-b)**2
print(f"{(e+f)**(1/2):.8f}")
| 0 | null | 22,328,989,219,040 | 188 | 29 |
import math
from collections import defaultdict,deque
#from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()
"""========main code==============="""
n=ii()
s=ip()
ans=1
for i in range(1,n):
if(s[i]!=s[i-1]):
ans+=1
print(ans)
|
def ra(a): #圧縮された要素を非保持
ll,l=[],1
for i in range(len(a)-1):
if a[i]==a[i+1]:
l+=1
else:
ll.append(l)
l=1
ll.append(l)
return ll
n=input()
print(len(ra(input())))
| 1 | 169,475,170,380,252 | null | 293 | 293 |
N = int(input())
aaa = list(map(int, input().split()))
i = 1
ans = 0
for a in aaa:
if a == i:
i += 1
else:
ans += 1
print(ans if ans != N else -1)
|
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
def main2():
numbers=[]
N = int(input())
numbers=list(map(int,input().split()))
n=1
#条件が1<=n<=200kのため1から順に数えてlist内を調査した場合の最大値+1をnに記入
for x in numbers:
if x ==n:
n+=1
#条件から+1まで数えてしまうため、nを+1して調整
answer = N - n +1
if answer==N:
answer=-1
print(answer)
def main():
numbers=[]
n = int(input())
numbers=list(map(int,input().split()))
buffer=[0]
for i in range(1,n+1):
search_range=numbers[i-1:]
out_range=len(numbers[:i-1])
if i not in search_range and len(buffer)==1:
print(-1)
exit()
elif i not in search_range or i==n:
break
else:
index=search_range.index(i)
buffer.append(index-sum(buffer))
print(sum(buffer))
if __name__=="__main__":
main2()
| 1 | 114,770,365,645,892 | null | 257 | 257 |
import math
a, b, c = map(int, input().split())
PI = 3.1415926535897932384
c = math.radians(c)
print('{:.5f}'.format(a * b * math.sin(c) / 2))
A = a - b * math.cos(c)
B = b * math.sin(c)
print('{:.5f}'.format(math.sqrt(A * A + B * B) + a + b))
print('{:.5f}'.format(B))
|
import math
a,b,C=map(float,input().split())
S=a*b*math.sin(math.pi*C/180)/2
c=math.sqrt(a**2+b**2-2*a*b*math.cos(math.pi*C/180))
L=a+b+c
h=2*S/a
print(f'{S:.5f}')
print(f'{L:.5f}')
print(f'{h:.5f}')
| 1 | 166,163,406,504 | null | 30 | 30 |
a,b,c,d=map(int,input().split())
prd=[a*c,a*d,b*c,b*d]
if (a<0<b or c<0<d) and max(prd)<0:
print(0)
else:
print(max(prd))
|
s = str(input())
t = str(input())
ans = len(t)
for i in range(len(s) - len(t) + 1):
tmp_ans = 0
for j in range(len(t)):
if s[i+j] != t[j]:
tmp_ans += 1
ans = min(ans, tmp_ans)
print(ans)
| 0 | null | 3,340,650,783,182 | 77 | 82 |
heights = []
for _ in range(10):
heights.append(int(input()))
heights.sort()
print(heights[9])
print(heights[8])
print(heights[7])
|
import sys
height_li = []
for i in range(10):
height_li.append(int(input()))
for i in range(3):
print(sorted(height_li,reverse=True)[i])
| 1 | 23,088,160 | null | 2 | 2 |
import sys
input = sys.stdin.readline
def read():
S = input().strip()
return S,
def solve(S):
N = len(S)
ans = 0
for i in range(N//2):
if S[i] != S[N-i-1]:
ans += 1
return ans
if __name__ == '__main__':
inputs = read()
print(solve(*inputs))
|
import sys
K = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip('\n')
# ## COMBINATION (MOD) ###
N_MAX = 10**6 # 問題サイズに合わせて変えておく
MOD = 10**9 + 7
inv = [0] * (N_MAX + 2)
inv[0] = 0 # 逆元テーブル計算用テーブル
inv[1] = 1
for i in range(2, N_MAX + 2):
inv[i] = -inv[MOD % i] * (MOD // i) % MOD
# K 文字追加
ans = 0
ln = len(S)
p1 = 1
p2 = 1
s2 = pow(26, K, MOD)
for i in range(1, K + 2):
ans += (p1 * p2 * s2) % MOD
ans %= MOD
# print(p1, p2, s2)
# pre
p1 = (p1 * (ln + i - 1) * inv[i]) % MOD
p2 = (p2 * 25) % MOD
# suf
s2 = (s2 * inv[26]) % MOD
print(ans)
| 0 | null | 66,376,118,447,420 | 261 | 124 |
while True:
x, y, z = map(int, input().split())
if x == -1 and y == -1 and z == -1:
break
if x == -1 or y == -1:
print ('F')
elif x + y >= 80:
print ('A')
elif 65 <= x+y < 80:
print ('B')
elif 50 <= x+y < 65 or (30 <= x+y < 50 and z >= 50):
print ('C')
elif 30 <= x+y < 50:
print ('D')
elif x + y < 30:
print ('F')
|
from collections import defaultdict
n,*L=map(int,open(0).read().split())
mod=10**9+7
d=defaultdict(lambda:[0,0])
gcd=lambda x,y:x if y==0 else gcd(y,x%y)
two=[1]*(n+1)
for i in range(n):
two[i+1]=(two[i]*2)%mod
zero=0
for a,b in zip(*[iter(L)]*2):
if a==b==0:
zero+=1
continue
if a==0:
d[(0,1)][0]+=1
elif b==0:
d[(0,1)][1]+=1
else:
g=gcd(a,b)
a//=g
b//=g
if a*b>0:
d[(a,b)][0]+=1
else:
d[(abs(b),abs(a))][1]+=1
ans=1
for (_,_),(x,y) in d.items():
ans*=(two[x]+two[y]-1)%mod
ans%=mod
print((ans+zero+mod-1)%mod)
| 0 | null | 11,013,687,470,250 | 57 | 146 |
[n, m] = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [int(input()) for i in range(m)]
d = [sum([a[i][j]*b[j] for j in range(m)]) for i in range(n)]
for i in range(n):
print(d[i])
|
# (c) midandfeed
n, m = [int(x) for x in input().split()]
a = []
b = []
for _ in range(n):
z = [int(x) for x in input().split()]
a.append(z)
for _ in range(m):
b.append(int(input()))
for i in range(n):
ans = 0
for j in range(m):
ans += a[i][j]*b[j]
print(ans)
| 1 | 1,161,747,838,658 | null | 56 | 56 |
N = int(input())
p = 1
for i in range(1,int(N**0.5+1)):
if N%i == 0:
p = i
print(p+N//p-2)
|
import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N = I()
for i in range(int(N**.5),0,-1):
if N % i == 0:
print(i+(N//i)-2)
exit()
| 1 | 161,893,485,900,340 | null | 288 | 288 |
input = list(map(int, input().split()))
if input[0] > input[1]:
print("safe")
else:
print("unsafe")
|
import sys
input = sys.stdin.readline
"""
"""
s, w = map(int, input().split())
if w >= s:
print("unsafe")
else:
print("safe")
| 1 | 29,182,393,170,280 | null | 163 | 163 |
s=list(input())
n=len(s)
if list(s[::-1])==list(s[:]) and list(s[(n-1)//2-1::-1])==list(s[:(n-1)//2]) and list(s[:(n+3)//2-2:-1])==list(s[(n+3)//2-1:]):
print("Yes")
else:
print("No")
|
H,N= map(int, input().split())
list = list(map(int, input().split())) #Aiを入力
for i in list:
H=H-i
if H<=0:
print('Yes')
else:
print('No')
| 0 | null | 62,266,248,870,940 | 190 | 226 |
from itertools import product
def makelist(BIT):
LIST, tmp = [], s[0]
for i, bi in enumerate(BIT, 1):
if bi == 1:
LIST.append(tmp)
tmp = s[i]
elif bi == 0:
tmp = [t + sij for t, sij in zip(tmp, s[i])]
else:
LIST.append(tmp)
return LIST
def solve(LIST):
CNT, tmp = 0, [li[0] for li in LIST]
if any(num > k for num in tmp):
return h * w
for j in range(1, w):
cal = [t + li[j] for t, li in zip(tmp, LIST)]
if any(num > k for num in cal):
CNT += 1
tmp = [li[j] for li in LIST]
else:
tmp = cal
return CNT
h, w, k = map(int, input().split())
s = [[int(sij) for sij in input()] for _ in range(h)]
ans = h * w
for bit in product([0, 1], repeat=(h - 1)):
numlist = makelist(bit)
ans = min(ans, solve(numlist) + sum(bit))
print(ans)
|
import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
H, W, K = NMI()
choco = [SI() for _ in range(H)]
ans = 100000
for case in range(2**(H-1)):
groups = [[0]]
for i in range(H-1):
if (case >> i) & 1:
groups[-1].append(i+1)
else:
groups.append([i+1])
white = [0] * len(groups)
is_badcase = False
cut = len(groups) - 1
for w in range(W):
diff = [0] * len(groups)
for gi, group in enumerate(groups):
for h in group:
if choco[h][w] == "1":
white[gi] += 1
diff[gi] += 1
if max(white) <= K:
is_cont = True
continue
if max(diff) > K:
is_badcase = True
break
cut += 1
white = diff[:]
continue
if not is_badcase:
ans = min(ans, cut)
print(ans)
if __name__ == "__main__":
main()
| 1 | 48,624,331,911,288 | null | 193 | 193 |
S = input()
def is_kaibun(s):
return s[:len(s)//2] == s[:(len(s)-1)//2:-1]
flg = is_kaibun(S) and is_kaibun(S[:len(S)//2]) and is_kaibun(S[:len(S)//2:-1])
print('Yes' if flg else 'No')
|
s = input()
n = len(s)
if s != s[::-1]:
print("No")
elif s[0:(n-1)//2] != s[(n-1)//2-1::-1]:
print("No")
elif s[(n+3)//2-1:n] != s[n-1:(n+3)//2-2:-1]:
print("No")
else:
print("Yes")
| 1 | 46,271,515,989,608 | null | 190 | 190 |
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(M)]
buy = [min(a)+min(b)]
for i in range(M):
C = a[c[i][0]-1]+b[c[i][1]-1]-c[i][2]
buy.append(C)
print(min(buy))
|
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 999999
for i in range(M):
x, y, c = map(int, input().split())
if x <= A and y <= B:
d = a[x - 1] + b[y - 1] - c
if d < ans:
ans = d
if (min(a) + min(b)) < ans:
ans = min(a) + min(b)
print(ans)
| 1 | 54,243,460,105,170 | null | 200 | 200 |
def find(A):
increase = []
for i in range(len(A)-1):
if A[i] <= A[i+1]:
increase += [1]
else:
increase += [0]
increase += [0]
val = 1000
hold = 0
for i in range(len(increase)):
if i==0:
if increase[i] == 1:
hold = val//A[i]
val -= A[i]*hold
else:
if increase[i] == 1:
if increase[i-1] == 0:
hold = val//A[i]
val -= A[i]*hold
else:
if increase[i-1] == 1:
val += A[i]*hold
hold = 0
return val
N = input()
A = list(map(int,input().strip().split()))
print(find(A))
|
input()
print(*reversed([int(e) for e in input().split()]))
| 0 | null | 4,120,824,110,640 | 103 | 53 |
def binary_search(*, ok, ng, func):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if func(mid):
ok = mid
else:
ng = mid
return ok
def main():
N, K = map(int, input().split())
*A, = sorted(map(int, input().split()))
*F, = sorted(map(int, input().split()), reverse=True)
def is_ok(score):
rest = K
for a, f in zip(A, F):
exceed = max(0, a * f - score)
if exceed:
need = (exceed + f - 1) // f
if need > a or need > rest:
return False
rest -= need
return True
ans = binary_search(ok=10 ** 12, ng=-1, func=is_ok)
print(ans)
if __name__ == '__main__':
main()
|
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
def sub(x):
val = 0
for aa,ff in zip(a,f):
val += max(0, aa - (x//ff))
return val<=k
if sub(0):
ans = 0
else:
l = 0
r = sum(aa*ff for aa,ff in zip(a,f))
while l+1<r:
m = (l+r)//2
if sub(m):
r = m
else:
l = m
ans = r
print(ans)
| 1 | 165,183,181,616,002 | null | 290 | 290 |
n,t = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort() # 食べるのが早い順にソート
# ナップザック問題に落とし込む
dp = [[0 for i in range(t+1)]for j in range(n+1)]
for i in range(n):
ti,vi = ab[i]
for j in range(t+1):
# 食べたほうがよい(t秒以内かつ満足度が上がるならば)
if j + ti <= t:
dp[i+1][j+ti] = max(dp[i+1][j+ti],dp[i][j]+vi)
# 食べなかった場合の最高値を更新
dp[i+1][j] = max(dp[i][j],dp[i+1][j])
ma = 0
for i in range(n):
# 最後にi番目の皿を食べることができる
ma = max(ma,dp[i][t-1]+ab[i][1])
print(ma)
|
n, t = map(int, input().split())
ab = [tuple(map(int, input().split())) for i in range(n)]
m, d = 0, [0] * t
for a, b in sorted(ab):
m = max(m, b+d[t-1])
for l in range(t-1,a-1,-1):
if(b+d[l-a] > d[l]):
d[l] = b+d[l-a]
print(m)
| 1 | 151,621,504,613,630 | null | 282 | 282 |
import sys
def main():
N = int(sys.stdin.readline().rstrip())
S = sys.stdin.readline().rstrip()
cnt = 0
for i in range(10):
pos_1 = S.find(str(i))
if pos_1 == -1 or pos_1 > N - 3:
continue
for j in range(10):
pos_2 = S[pos_1 + 1:].find(str(j))
if pos_2 == -1 or pos_2 > N - 2:
continue
for k in range(10):
pos_3 = S[pos_1 + 1 + pos_2 + 1:].find(str(k))
if pos_3 != -1:
cnt += 1
print(cnt)
main()
|
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
""" どのパワー以上の組み合わせまで握手するのか二分探索で調べる
同じパワーとなる組み合わせに注意 """
N, M = lr()
A = np.array(lr())
A.sort()
def check(x):
# x以上の幸福度で握手した時、M回以下だとTrueを返す
Y = np.searchsorted(A, x - A)
return N*N - Y.sum() <= M
ok = 10 ** 6; ng = 0
while abs(ng-ok) > 1:
mid = (ok+ng) // 2
if check(mid):
ok = mid
else:
ng = mid
Acum = np.zeros(N+1, np.int64)
Acum[1:] = A.cumsum()
Y = np.searchsorted(A, ok-A)
answer = (Acum[-1] - Acum[Y]).sum() + (A * (N-Y)).sum()
answer += ng * (M - (N-Y).sum())
print(answer)
# 24
| 0 | null | 118,733,749,362,998 | 267 | 252 |
import math
import collections
n, k = map(int, input().split())
W = collections.deque()
for i in range(n):
W.append(int(input()))
left = max(math.ceil(sum(W) / k), max(W))
right = sum(W)
center = (left + right) // 2
# print('------')
while left < right:
i = 1
track = 0
# print(center)
for w in W:
# if center == 26:
# print('track: ' + str(track))
track += w
if track > center:
track = w
i += 1
if i > k:
left = center + 1
break
else:
right = center
center = (left + right) // 2
print(center)
|
n,k=map(int, input().split())
w=[0]*n
for i in range(n):
w[i]=int(input())
def delivable(m):
loading=0
track_num=1
for i in range(n):
if w[i] > m:
return False
break
else:
loading += w[i]
if loading > m:
loading=w[i]
track_num += 1
if track_num <= k:
return True
else:
return False
r=1000000000
l=min(w)-1
while r-l > 1:
m=(r+l)//2
if delivable(m):
r=m
else:
l=m
print(r)
| 1 | 87,377,382,528 | null | 24 | 24 |
n, m = map(int, input().split())
a = 1
b = m + 1
while a < b:
print(a, b)
a += 1
b -= 1
a = m + 2
b = 2 * m + 1
while a < b:
print(a, b)
a += 1
b -= 1
|
n,m = map(int,input().split())
if n%2 ==1:
for i in range(1,m+1):
print(i,n-i)
else:
left_end = 1+m if m%2 == 1 else m
left_start = left_end//2
right_start = left_end+m//2
for i in range(1,m+1):
if i%2 == 1:
print(left_start,left_start+i)
left_start-=1
else:
print(right_start,right_start+i)
right_start-=1
| 1 | 28,627,407,471,280 | null | 162 | 162 |
N,K = map(int,input().split())
LR = []
for _ in range(K): LR.append(list(map(int,input().split())))
MOD = 998244353
dp = [0]*(N+1)
dp[0] = 1
for i in range(N):
for L,R in LR:
if i+L<N: dp[i+L] += dp[i]
if i+R+1<N: dp[i+R+1] -= dp[i]
if i>0: dp[i+1] = (dp[i+1]+dp[i])%MOD
print(dp[-1])
|
def solve(l, r, i):
if i - l < 1:
return 0
return dp[i - l] - dp[max(i - r - 1, 0)]
n, k = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(k)]
MOD = 998244353
dp = [0] * (n + 1)
dp[1] = 1
for i in range(2, n + 1):
tmp = 0
for l, r in lr:
tmp += solve(l, r, i)
tmp = tmp % MOD
dp[i] = (dp[i - 1] + tmp) % MOD
print(tmp)
| 1 | 2,682,519,821,448 | null | 74 | 74 |
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
s=input()
a="abcdefghijklmnopqrstuvwxyz"
print(a[a.index(s)+1])
|
import math
n = int(input())
ans = 0
if n== 0:
print(0)
exit()
if n%2 == 1:
print(0)
else:
for j in range(1,100):
if n//((5**j)*2) == 0:
break
ans += n//((5**j)*2)
print(ans)
| 0 | null | 104,615,498,011,138 | 239 | 258 |
import sys
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)
def main():
m, d = na()
n, s = na()
if s == 1:
print(1)
else:
print(0)
if __name__ == '__main__':
main()
|
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
end = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if d1 == end[m1-1]:
print(1)
else:
print(0)
| 1 | 124,462,123,272,760 | null | 264 | 264 |
# 解説を見て解き直し
N, K = [int(x) for x in input().split()]
ranges = [tuple(int(x) for x in input().split()) for _ in range(K)]
ranges.sort()
p = 998244353
dp = [0] * (N + 1)
dpsum = [0] * (N + 1)
dp[1] = 1
dpsum[1] = 1
for i in range(2, N + 1):
for l, r in ranges:
rj = i - l
lj = max(1, i - r) # 1以上
if rj <= 0: continue
dp[i] += dpsum[rj] - dpsum[lj - 1]
dp[i] %= p
dpsum[i] = dpsum[i - 1] + dp[i]
dpsum[i] %= p
print(dp[N])
|
S = input()
for i in range(len(S)):
print("x",end ="")
| 0 | null | 37,670,011,095,120 | 74 | 221 |
s_ = int(input())
print("%d:%d:%d" % (s_//3600, s_//60%60, s_%60))
|
a = input()
a = int(a)
h = a//3600
m = (a-3600*h)//60
s = (a-3600*h-60*m)
print(str(h)+':'+str(m)+':'+str(s))
| 1 | 334,868,488,610 | null | 37 | 37 |
n=int(input())
a=list(map(int,input().split()))
for i in a:
if i%2==0:
if i%3!=0 and i%5!=0:
print('DENIED')
exit()
print('APPROVED')
|
n = list(map(int,input().split()))
a = list(map(int,input().split()))
ans = 'APPROVED'
for i in a:
if i % 2 == 0:
if i % 3 != 0 and i % 5 != 0:
ans = 'DENIED'
break
print(ans)
| 1 | 69,257,161,917,850 | null | 217 | 217 |
s = input()
ans = "No"
if s[2]==s[3] and s[4]==s[5] :
ans = "Yes"
print(ans)
|
s = input()
ans = 'Yes'
if s[2] != s[3]:
ans = 'No'
if s[4] != s[5]:
ans = 'No'
print(ans)
| 1 | 41,990,001,770,948 | null | 184 | 184 |
import sys,math
input = sys.stdin.readline
A,B,C,D=list(map(int,input().split()))
if math.ceil(C/B) <= math.ceil(A/D):
print('Yes')
else:
print('No')
|
a,b,c,d=map(int,input().split())
while(1):
c -= b
if c <= 0:
print("Yes")
break
a -= d
if a <= 0:
print("No")
break
| 1 | 29,750,432,906,044 | null | 164 | 164 |
n = int(input())
a = [int(x) for x in input().split()]
for i in a:
if i%2==0:
if i%3!=0 and i%5!=0:
print("DENIED")
exit()
print("APPROVED")
|
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
a,b,c = map(int, input().split())
if a == b and a != c and b != c:
print("Yes")
elif a == c and a != b and c != b:
print("Yes")
elif b == c and a != b and a != c:
print("Yes")
else:
print("No")
| 0 | null | 68,591,543,113,492 | 217 | 216 |
x,n = map(int,input().split())
p = list(map(int,input().split()))
i = 0
ans = -1
while True:
temp1 = x - i
temp2 = x + i
if temp1 not in p:
ans = temp1
break
if temp2 not in p:
ans = temp2
break
i += 1
print(ans)
|
def main():
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
v = {0: 1}
n = [0]
r = 0
t = 0
for i, a in enumerate(A, 1):
if i >= K:
v[n[i - K]] -= 1
t += a
j = (t - i) % K
r += v.get(j, 0)
v[j] = v.get(j, 0) + 1
n.append(j)
return r
print(main())
| 0 | null | 75,541,232,937,732 | 128 | 273 |
import itertools
#再帰関数のときのRE予防
import sys
sys.setrecursionlimit(312467)
N = int(input())
List = []
def dfs(S):
List.append(S)
if len(S) < N:
for i in range(ord("a"), ord(max(S))+2):
dfs(S+[chr(i)])
return
dfs(["a"])
for i in List:
if len(i) == N:
print("".join(i))
elif len(i) > N:
break
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
N = int(input())
lst1 = [('a', 0)]
lst2 = []
for i in range(N - 1):
if i % 2 == 0: #lst1 -->lst2
lst2 = []
for s, t in lst1:
last = max(ord(s[i]) - ord('a'), t)
for j in range(last + 2):
lst2.append((s + chr(j + ord('a')), max(t, j)))
else:
lst1 = []
for s, t in lst2:
last = max(ord(s[i]) - ord('a'), t)
for j in range(last + 2):
lst1.append((s + chr(j + ord('a')), (max(t, j))))
if len(lst2) > len(lst1):
lst2.sort()
for s, t in lst2:
print (s)
else:
lst1.sort()
for s, t in lst1:
print (s)
| 1 | 52,171,562,633,440 | null | 198 | 198 |
H, N = map(int, input().split())
AB = []
INF = 10**8 + 1
dp = [INF]*(H+1)
dp[0] = 0
for _ in range(N):
a, b = map(int, input().split())
AB.append((a, b))
for i in range(1, H+1):
for j in range(N):
dp[i] = min(dp[i], dp[max(0, i - AB[j][0])] + AB[j][1])
print(dp[-1])
|
def main():
n = int(input())
A = []
B = []
for _ in range(n):
a, b = map(int, input().split())
A += [a]
B += [b]
A.sort()
B.sort()
if n % 2 == 0:
mid_pos = n // 2
mid_A = A[mid_pos - 1] + A[mid_pos]
mid_B = B[mid_pos - 1] + B[mid_pos]
cnt = mid_B - mid_A + 1
else:
mid_pos = (n + 1) // 2 - 1
mid_A = A[mid_pos]
mid_B = B[mid_pos]
cnt = mid_B - mid_A + 1
print(cnt)
if __name__ == "__main__":
main()
| 0 | null | 49,293,523,861,520 | 229 | 137 |
class CircleInaRectangle:
def __init__(self, W, H, x, y, r):
if 0 <= x - r and 0 <= y - r and x + r <= W and y + r <= H:
print "Yes"
else:
print "No"
if __name__ == "__main__":
W, H, x, y, r = map(int, raw_input().split())
CircleInaRectangle(W, H, x, y, r)
|
W,H,x,y,r = map(int ,raw_input().split())
#print ' '.join(map(str,[W,H,x,y,r]))
if x < W and 0 < x and 0<y and y < H and r <= x and r <= (H - x) :
print "Yes"
else:
print "No"
| 1 | 449,803,907,940 | null | 41 | 41 |
import collections
mod = 998244353
N = int(input())
D = list(map(int,input().split()))
if D[0] != 0 or 0 in D[1:]:
print(0)
exit()
Dep = collections.Counter(D)
values, counts = zip(*Dep.most_common())
#print(values)
#print(counts)
#print(Dep)
ans = 1
for i in range(1,len(values)):
if Dep[i-1] == 0:
ans = 0
ans *= pow(Dep[i-1],Dep[i], mod)
#print(i,Dep[i])
ans %= mod
print(ans)
|
N,A,B = map(int,input().split())
if A%2 != 0 and B%2 == 0:
ans = (B-A-1)//2 + min(A-1,N-B) + 1
elif A%2 == 0 and B%2 != 0:
ans = (B-A-1)//2 + min(A-1,N-B) + 1
else:
ans = (B-A)//2
print(ans)
| 0 | null | 132,497,307,594,472 | 284 | 253 |
cards = list(map(int, input().split()))
print('win' if sum(cards) <= 21 else 'bust')
|
a,b,c,d=list(map(int, input().split()))
prod=[]
prod.append(a*c)
prod.append(a*d)
prod.append(b*c)
prod.append(b*d)
print(max(prod))
| 0 | null | 60,886,512,792,996 | 260 | 77 |
n = int(input())
a = list(map(int, input().split()))
approved = True
for i in range(n):
if a[i] % 2 == 0 and (a[i] % 3 != 0 and a[i] % 5 != 0):
approved = False
break
print("APPROVED" if approved else "DENIED")
|
import math
from itertools import permutations
N=int(input())
XYlist=[]
indexlist=[i for i in range(N)]
for _ in range(N):
XYlist.append(tuple(map(int,input().split())))
ans=0
num=0
for indexes in permutations(indexlist,N):
for i in range(N-1):
ans+=math.sqrt((XYlist[indexes[i]][0]-XYlist[indexes[i+1]][0])**2+
(XYlist[indexes[i]][1]-XYlist[indexes[i+1]][1])**2)
num+=1
print(ans/num)
| 0 | null | 108,920,650,575,140 | 217 | 280 |
N = int(input())
A = list(map(int, input().split()))
dicA = {}
for i in range(1, N+1):
dicA[i] = A[i-1]
sort_dicA = sorted(dicA.items(), key=lambda x:x[1])
for i in range(N):
print(sort_dicA[i][0], end=' ')
|
n = int(input())
a = [int(x) for x in input().split()]
ans = [0] * n
for i in range(n):
ans[a[i]-1] = i+1
ans = [str(x) for x in ans]
print(" ".join(ans))
| 1 | 180,851,429,270,028 | null | 299 | 299 |
# Fast IO (be careful about bytestring, not on interactive)
import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
N = int(input())
sumList = []
subList = []
for _ in range(N):
x,y = map(int,input().split())
sumList.append(x + y)
subList.append(x - y)
print(max(max(sumList) - min(sumList),max(subList) - min(subList)))
|
n = int(input())
xy = []
for _ in range(n):
xy.append(list(map(int, input().split())))
tmp1 = []
tmp2 = []
for i in range(n):
tmp1.append([xy[i][0]+xy[i][1], xy[i][0], xy[i][1]])
tmp2.append([xy[i][0]-xy[i][1], xy[i][0], xy[i][1]])
tmp1.sort()
tmp2.sort()
ans = 0
if (tmp1[-1][2]-tmp1[0][2])*(tmp1[-1][1]-tmp1[0][1]) >= 0:
tmp = tmp1[-1][0]-tmp1[0][0]
ans = max(tmp, ans)
if (tmp2[-1][2]-tmp2[0][2])*(tmp2[-1][1]-tmp2[0][1]) <= 0:
tmp = tmp2[-1][0]-tmp2[0][0]
ans = max(tmp, ans)
print(ans)
| 1 | 3,424,701,992,998 | null | 80 | 80 |
def canLoad(n, k, p):
global w
load = 0
for i in range(n):
load += w[i]
if load <= p:
continue
k -= 1
if k == 0:
return False
load = w[i]
return True
def solve(n, k, pmin, pmax):
if pmin + 1 >= pmax:
return pmax
newp = (pmax + pmin) // 2
if canLoad(n, k, newp):
return solve(n, k, pmin, newp)
else:
return solve(n, k, newp, pmax)
n, k = map(int, input().split())
w = [0]*n
wsum = 0
wmax = 0
for i in range(n):
w[i] = int(input())
wsum += w[i]
if w[i] > wmax:
wmax = w[i]
# p の最小の候補は wmax と ceil(wsum/k) の最大値
pmin = max(wmax, wsum // k if wsum % k == 0 else wsum // k + 1)
pmax = wsum
p = pmin
if not canLoad(n, k, pmin):
p = solve(n, k, pmin, pmax)
print(p)
|
MAX = 100000
def check(p):
i = 0
for j in range(k):
s = 0
while s + T[i] <= p:
s = s + T[i]
i = i + 1
if i == n:
return n
return i
def solve():
left = 0
right = MAX * 10000
while (right - left > 1):
mid = (left + right) / 2
v = check(mid)
if v >= n:
right = mid
else:
left = mid
return right
n, k = map(int, raw_input().split())
T = []
for i in range(n):
T.append(input())
ans = solve()
print ans
| 1 | 85,973,722,652 | null | 24 | 24 |
from collections import defaultdict
iim = lambda: map(int, input().rstrip().split())
def resolve():
N = int(input())
A = list(iim())
ans = 0
dp = [0]*N
for i, ai in enumerate(A):
x = i + ai
if x < N:
dp[x] += 1
x = i - ai
if x >= 0:
ans += dp[x]
print(ans)
resolve()
|
X,Y=map(int,input().split())
mod=10**9+7
if (X+Y)%3!=0:
print(0);exit()
if X*2<Y or Y*2<X:
print(0);exit()
t=(X+Y)//3
f=[1]
for i in range(1,t+100):
f.append(f[-1]*i%mod)
def comb(a,b,m):
return f[a]*pow(f[b],m-2,m)*pow(f[a-b],m-2,m)%m
print(comb(t,X-t,mod))
| 0 | null | 87,887,806,175,002 | 157 | 281 |
n, k = map(int, input().split())
*a, = map(int, input().split())
for i, j in zip(a, a[k:]):
print('Yes' if i < j else 'No')
|
dic = {}
for b in range(1,5):
for f in range(1,4):
for r in range(1,11):
dic[(b,f,r)] = 0
n = int(raw_input())
for k in range(n):
b,f,r,v = map(int,raw_input().split())
dic[(b,f,r)] += v
j = 0
for b in range(1,5):
for f in range(1,4):
ls = []
for r in range(1,11):
ls.append(dic[(b,f,r)])
print ' ' + ' '.join(map(str,ls))
else:
if j < 3:
print '#'*20
j +=1
| 0 | null | 4,149,487,098,880 | 102 | 55 |
N = int(input())
def answer(N: int) -> str:
x = 0
for i in range(1, 10):
for j in range(1, 10):
if N == i * j:
x = 1
return 'Yes'
if x == 0:
return 'No'
print(answer(N))
|
n = int(input())
flg = False
for i in range(1, 10):
if n % i == 0 and 1 <= n // i < 10:
flg = True
break
print('Yes') if flg else print('No')
| 1 | 159,341,559,688,928 | null | 287 | 287 |
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)
|
N = int(input())
A = list(map(int, input().split()))
money = 1000
stock = 0
for day in range(N):
if day == N - 1:
money += stock * A[day]
stock = 0
elif A[day] == A[day+1]:
continue
elif A[day] < A[day+1]:
stock += money // A[day]
money = money % A[day]
elif A[day] > A[day+1]:
money += stock * A[day]
stock = 0
print(money)
| 0 | null | 41,724,990,306,792 | 224 | 103 |
N,K=map(int,input().split())
A=list(map(int,input().split()))
m,p,z=[],[],0
for a in A:
if a<0:
m.append(a)
elif a>0:
p.append(a)
else:
z+=1
m.sort()
p.sort()
mod=10**9+7
from functools import reduce
if (len(p) or K%2==0) and K<len(m)+len(p) or K==len(m)+len(p) and len(m)%2==0:
r=1
i,j=0,0
while i+j<K:
if i<len(m)-1 and i+j<K-1 and (j>=len(p)-1 or m[i]*m[i+1]>p[-j-1]*p[-j-2]):
r=r*m[i]*m[i+1]%mod
i+=2
else:
r=r*p[-j-1]%mod
j+=1
print(r)
elif z:
print(0)
else:
print(reduce(lambda x,y:x*y%mod,(m+p)[-K:]))
|
n = int(input())
a = sorted(list(map(int, input().split())))
q = int(input())
l = [0]*(10**5+10)
for i in a:
l[i] += 1
s = sum(a)
for _ in range(q):
b, c = map(int, input().split())
s += (c - b) * l[b]
l[c] += l[b]
l[b] = 0
print(s)
| 0 | null | 10,885,881,221,122 | 112 | 122 |
X , Y , Z = map(int,input().split())
tmp = 0
tmp = X
X = Y
Y = tmp
tmp = X
X = Z
Z = tmp
print( str( X ) + " " + str( Y ) + " " + str( Z ) )
|
import sys
sys.setrecursionlimit(1000000)
def make_adlist(n):
adlist = [[] for _ in range(n)]
for _ in range(n-1):
a, b = map(lambda x:int(x)-1, input().split())
adlist[a] += [b]
adlist[b] += [a]
return adlist
def dfs(adlist, s, dist, d):
for nxt in adlist[s]:
if dist[nxt] == -1:
dist[nxt] = d
dfs(adlist, nxt, dist, d+1)
def main():
n, u, v = map(int, input().split())
u -= 1
v -= 1
adlist = make_adlist(n)
t_dist = [-1]*n
t_dist[u] = 0
dfs(adlist, u, t_dist, 1)
a_dist = [-1]*n
a_dist[v] = 0
dfs(adlist, v, a_dist, 1)
ans = 0
for i in range(n):
if t_dist[i] < a_dist[i]:
ans = max(ans, a_dist[i]-1)
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 77,502,585,636,420 | 178 | 259 |
import math
a,b,n=map(int,input().split())
def f(x):
return math.floor(a*x/b)-a*(math.floor(x/b))
if n>=(b-1):
print(f(b-1))
else:
print(f(n))
|
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
N,K = LI()
A = LI()
for i in range(N):
A[i] -= 1
B = [0] # Aの累積和をKで割ったもの
for i in range(N):
B.append((B[-1]+A[i]) % K)
from collections import defaultdict
# 要素の個数がKを超えないことに注意
if N < K:
d = defaultdict(int)
for n in B:
d[n] += 1
ans = 0
for n in d.keys():
m = d[n]
ans += m*(m-1)//2
print(ans)
else:
d = defaultdict(int)
ans = 0
for i in range(N): # A[i]から始まる部分列を考える
if i == 0:
for j in range(K):
d[B[j]] += 1
ans += d[B[i]]-1
elif i <= N-K+1:
d[B[K+i-1]] += 1
d[B[i-1]] -= 1
ans += d[B[i]]-1
else:
d[B[i-1]] -= 1
ans += d[B[i]]-1
print(ans)
| 0 | null | 82,371,541,536,288 | 161 | 273 |
def main():
k = int(input())
s = input()
n = len(s)
def cmb1(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7
N = 2*10**6
fac = [1]*(N+1)
finv = [1]*(N+1)
for i in range(N):
fac[i+1] = fac[i] * (i+1) % mod
finv[-1] = pow(fac[-1], mod-2, mod)
for i in reversed(range(N)):
finv[i] = finv[i+1] * (i+1) % mod
def cmb1(n, r, mod):
if r <0 or r > n:
return 0
r = min(r, n-r)
return fac[n] * finv[r] * finv[n-r] % mod
def power(a, n, mod):
bi=str(format(n,"b")) #2進数
res=1
for i in range(len(bi)):
res=(res*res) %mod
if bi[i]=="1":
res=(res*a) %mod
return res
ans = 0
for i in range(k+1):
temp = power(25, i, mod)
temp *= cmb1(i+n-1, n-1, mod)
temp %= mod
temp *= power(26, k-i, mod)
temp %= mod
ans += temp
print(ans%mod)
if __name__ == '__main__':
main()
|
mod = 10**9 + 7
K = int(input())
S = input()
n = len(S)
tmp = pow(26, K, mod)
waru = pow(26, -1, mod)
ans = tmp
for i in range(1, K+1):
tmp = (tmp * 25 * waru)%mod
tmp = (tmp * (i + n -1) * pow(i, -1, mod))%mod
ans = (ans+tmp)%mod
print(ans%mod)
| 1 | 12,838,670,434,170 | null | 124 | 124 |
n = int(input())
max_div_num = 1
for i in range(2, int(n**(1/2) + 1)):
if n % i == 0:
max_div_num = i
x = max_div_num
y = n // max_div_num
print(x + y - 2)
|
N = int(input())
p = 1
for i in range(1,int(N**0.5+1)):
if N%i == 0:
p = i
print(p+N//p-2)
| 1 | 161,433,816,674,282 | null | 288 | 288 |
n,t = map(int,input().split())
L = []
for i in range(n):
a,b = map(int,input().split())
L.append([a,b])
dp1 = [[0 for i in range(t)] for i in range(n+1)]
dp2 = [[0 for i in range(t)] for i in range(n+1)]
for i in range(n):
a = L[i][0]
b = L[i][1]
for j in range(t):
if j-a >= 0:
dp1[i+1][j] = max(dp1[i][j], dp1[i][j-a]+b, dp1[i+1][j])
else:
dp1[i+1][j] = max(dp1[i][j],dp1[i+1][j])
for i in range(n):
a = L[n-i-1][0]
b = L[n-i-1][1]
if i == 0:
for j in range(a, t):
dp2[n-i-1][j] = b
else:
for j in range(t):
if j-a >= 0:
dp2[n-i-1][j] = max(dp2[n-i][j], dp2[n-i][j-a]+b,dp2[n-i-1][j])
else:
dp2[n-i-1][j] = max(dp2[n-i-1][j], dp2[n-i][j])
ans = 0
for i in range(1,n+1):
for j in range(t):
ans = max(ans, dp1[i-1][j]+dp2[i][t-1-j]+L[i-1][1])
print(ans)
|
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, T = mapint()
AB = [list(mapint()) for _ in range(N)]
AB.sort()
maxtime = AB[-1][0]
Bs = [b for a, b in AB]
dp = [0]*(T)
ans = 0
for n in range(N-1):
a, b = AB[n]
newdp = [0]*(T)
for i in range(T):
if a<=i and i-a<T:
newdp[i] = max(dp[i], dp[i-a]+b)
dp = newdp
ans = max(ans, max(dp)+max(Bs[n+1:]))
print(ans)
| 1 | 151,663,990,473,270 | null | 282 | 282 |
a = sum(list(map(int, input().split())))
if a >+ 21:
print('bust')
else:
print('win')
|
N = int(input())
S = [""] * N
T = [0] * N
for i in range(N):
s, t = input().split()
S[i] = s
T[i] = int(t)
X = input()
t = 0
for i in range(N):
t += T[i]
if S[i] == X:
break
print(sum(T) - t)
| 0 | null | 108,245,544,193,010 | 260 | 243 |
l = range(1, 10)
for i in ["%dx%d=%d" % (x, y, x*y) for x in l for y in l]:
print i
|
i=0
for i in range(1,10):
for j in range(1,10):
print(f'{i}x{j}={i*j}')
j+=1
i+=1
| 1 | 194,532 | null | 1 | 1 |
while True:
try:
a=input().split()
except:
break
b=int(a[0])+int(a[1])
print(len(str(b)))
|
from math import log10
while True:
try:
a, b = map(int, raw_input().split())
print(int(log10(a+b)) + 1)
except EOFError:
break
| 1 | 93,261,490 | null | 3 | 3 |
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N-K):
if A[i] < A[i+K]:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
|
a,b = map(int,(input().split()))
c = list(map(int,input().split()))
for i in range(a-b):
print("Yes" if c[i] < c[i+b] else "No")
| 1 | 7,178,641,630,358 | null | 102 | 102 |
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 8 20:45:37 2020
@author: liang
"""
def gcc(a,b):
if b == 0:
return a
return gcc(b, a%b)
A, B = map(int, input().split())
if A < B:
A ,B = B, A
print(A*B//gcc(A,B))
|
import math
a,b = map(int,input().split())
print(a*b//math.gcd(a,b))
| 1 | 113,778,012,466,680 | null | 256 | 256 |
import math
x = math.pi
r=int(input())
print(2*r*x)
|
n = input()
list = raw_input().split(" ")
list.reverse()
print " ".join(list)
| 0 | null | 16,131,399,839,312 | 167 | 53 |
n = int(input())
A = list(map(int,input().split()))
ans = [0]*n
for i in range(n):
ans[A[i] - 1] = str(i + 1)
Ans = ' '.join(ans)
print(Ans)
|
#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())
n = I()
A = readInts()
nya = []
for i in range(n):
nya.append((i+1,A[i]))
nya = sorted(nya,key = lambda x:x[1])
ans = []
for (idx,po) in nya:
ans.append(idx)
print(*ans)
| 1 | 180,941,399,631,072 | null | 299 | 299 |
from sys import stdin
def ip():
return stdin.readline().rstrip()
d,t,s=map(int,ip().split())
if d<=t*s:
print('Yes')
else:
print('No')
|
input_lists = list(input().split(' '))
result = [input_lists[-1]]
result += input_lists[0:-1]
result = ' '.join(result)
print(result)
| 0 | null | 20,743,998,154,878 | 81 | 178 |
D, T, S = [int(x) for x in input().split()]
print("Yes" if D <= (T * S) else "No")
|
a,b,c = map(int, input().split())
print('Yes' if a/c <= b else 'No')
| 1 | 3,530,501,583,630 | null | 81 | 81 |
S = input()
N = len(S)
counter = [0] * 2019
counter[0] = 1
T = 0
R = 1
for i in range(N):
T = (T + R * int(S[N - i - 1])) % 2019
R = 10 * R % 2019
counter[T] += 1
ans = 0
for i in range(2019):
m = counter[i]
ans += m * (m - 1) // 2
print(ans)
|
input()
a = input().split()
a.reverse()
print(" ".join(a))
| 0 | null | 15,900,277,163,452 | 166 | 53 |
n=int(input())
if n!=0:
ans1=n//500
sub=n-(ans1*500)
ans2=sub//5
print((ans1*1000)+(ans2*5))
else:
print(0)
|
p,q = input().split()
a = int(p)
b = int(q)
if a >= b *2:
print(a - 2*b)
else:
print(0)
| 0 | null | 104,665,105,724,996 | 185 | 291 |
def bubbleSort(A, N):
flag = 1
count = 0
while flag:
flag = 0
for j in xrange(N-1,0,-1):
if A[j] < A[j-1]:
tmp = A[j]
A[j] = A[j-1]
A[j-1] = tmp
flag += 1
count += 1
return A, count
def main():
N = int(raw_input())
A = map(int, raw_input().split())
new_A, count = bubbleSort(A, N)
print ' '.join(map(str,new_A))
print count
if __name__ == "__main__":
main()
|
def main():
X = int(input())
if X >=30: return "Yes"
return "No"
if __name__ == '__main__':
print(main())
| 0 | null | 2,924,275,615,510 | 14 | 95 |
a, b, n = map(int, input().split())
if b > n:
x = n
else:
x = b - 1
print(int(a * x / b) - a * int(x / b))
|
import sys
input = lambda: sys.stdin.readline().rstrip()
A,B,N = map(int, input().split())
def f(x):
return int(A*x/B) - A*int(x/B)
if N >= B-1:
print(f(B-1))
else:
print(f(N))
| 1 | 28,248,516,165,210 | null | 161 | 161 |
n, m = map(int, input().split())
c = list(map(int, input().split()))
INF = float("inf")
dp = [INF]*(n+1)
dp[0] = 0
for i in range(m):
for j in range(n+1):
if j + c[i] > n:
break
else:
dp[j + c[i]] = min(dp[j + c[i]], dp[j] + 1)
print(dp[n])
|
N = int(input())
memolist = [-1]*(N+1)
def fib(x):
if memolist[x] == -1:
if x == 0 or x == 1:
memolist[x] = 1
else:
memolist[x] = fib(x - 1) + fib(x - 2)
return memolist[x]
print(fib(N))
| 0 | null | 71,285,371,072 | 28 | 7 |
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
cur = 0
res = 0
for i in range(n-1):
cur = (cur + a[n-1-i]) % mod
tmp = (a[n-2-i] * cur) % mod
res = (res + tmp) % mod
print(res)
|
from math import gcd
from collections import defaultdict
n=int(input())
abd=defaultdict(int)
mod=10**9+7
wzero=0
azero=0
bzero=0
for i in range(n):
a,b=map(int,input().split())
if a==0 and b==0:
wzero+=1
elif a==0 and b!=0:
azero+=1
elif a!=0 and b==0:
bzero+=1
else:
g=gcd(a,b)
a=a//g
b=b//g
abd[(a,b)]+=1
liskey=list(abd.keys())
ans=1
for k in liskey:
if abd[k] != 0:
a,b=k
x=abd[(a,b)]+abd[(-a,-b)]
y=abd[(-b,a)]+abd[(b,-a)]
abd[(a,b)]=0
abd[(-a,-b)]=0
abd[(-b,a)]=0
abd[(b,-a)]=0
ans*=(2**x+2**y-1+mod)%mod
ans%=mod
ans*=(2**azero+2**bzero-1)
ans%=mod
ans=(ans+wzero)%mod
ans=(ans+mod-1)%mod
print(ans)
| 0 | null | 12,287,931,440,198 | 83 | 146 |
n = int(input())
a = list(map(int, input().split()))
dic = {}
ans = ''
for i in range(n):
dic[a[i]] = i+1
for i in range(n):
ans = ans + str(dic[i+1]) + ' '
print(ans)
|
N = int(input())
A = list(map(int, input().split()))
dic = {i:0 for i in range(1, N + 1)}
for i in range(N):
a = A[i]
dic[a] = i + 1
for i in range(1, N + 1):
print(dic[i], end="")
if i != N:
print(" ", end="")
print()
| 1 | 180,457,710,108,128 | null | 299 | 299 |
def solve():
N, K = list(map(int, input().split()))
if(N >= K):
tmp = N - ((N // K) * K)
ans = min(tmp, abs(abs(tmp) - K))
elif(N < K):
if(K <= 2*N):
ans = abs(N - K)
else:
ans = abs(N)
print(ans)
if __name__ == "__main__":
solve()
|
[N, K] = [int(i) for i in input().split()]
print(min(N%K, -N%K))
| 1 | 39,313,863,282,720 | null | 180 | 180 |
a,b=map(int,input().split())
c=a>b
print(str(b if c else a)*(a if c else b))
|
N = int(input())
*A, = map(int, input().split())
mod = 10**9 + 7
ans = 1
cnt = [0, 0, 0]
for a in A:
if a not in cnt:
ans = 0
break
ans = ans * cnt.count(a) % mod
cnt[cnt.index(a)] += 1
print(ans)
| 0 | null | 107,158,817,069,880 | 232 | 268 |
N=int(input())
count=0
#N未満の値がaで割り切れさえすればいい
for a in range(1,N):
count = count + (N-1)//a
print(count)
|
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():
s = S()
ans = not(len(set(list(s)))==1)
print("Yes" if ans else "No")
main()
| 0 | null | 28,670,432,159,778 | 73 | 201 |
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,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return map(int,input().split())
def onem(): #Nとかの取得
return int(input())
def s(x): #圧縮
a = []
if len(x) == 0:
return []
aa = x[0]
su = 1
for i in range(len(x)-1):
if aa != x[i+1]:
a.append([aa,su])
aa = x[i+1]
su = 1
else:
su += 1
a.append([aa,su])
return a
def jo(x): #listをスペースごとに分ける
return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
return max(map(max,x))
def In(x,a): #aがリスト(sorted)
k = bs.bisect_left(a,x)
if k != len(a) and a[k] == x:
return True
else:
return False
def pow_k(x, n):
ans = 1
while n:
if n % 2:
ans *= x
x *= x
n >>= 1
return ans
"""
def nibu(x,n,r):
ll = 0
rr = r
while True:
mid = (ll+rr)//2
if rr == mid:
return ll
if (ここに評価入れる):
rr = mid
else:
ll = mid+1
"""
n = onem()
a = l()
aa = [[a[i],i] for i in range(n)]
aa.sort(reverse = True)
dp = [[0 for i in range(n+1)] for j in range(n+1)]
for i in range(1,n+1):
on = aa[i-1]
for j in range(i+1):
if j-1 >= 0:
dp[i-j][j] = max(dp[i-j][j-1] + on[0] * abs(on[1] - (n-1 - (j - 1))),dp[i-j][j])
"""
if i == 1:
print(dp[i-j][j-1] + on[0] * abs(on[1] - j),dp[i-j][j])
"""
if i-j-1 >= 0:
#dp[i-j][j] = max(dp[i-j][j],dp[i-j-1][j] + on[0] * abs(on[1] - (n-1 - (i-j))))
dp[i-j][j] = max(dp[i-j][j],dp[i-j-1][j] + on[0] * abs(on[1] - (i-j-1)))
"""
if i == 1:
print(on,(n-1 - (i-j)),n-1,i-j)
print(dp[i-j-1][j],on[0] * abs(on[1] - (n-1 - (i-j))))
print(dp[i-j][j],dp[i-j-1][j] + on[0] * abs(on[1] - (i-j-1)))
"""
ma = 0
for i in range(n+1):
ma = max(ma,dp[n-i][i])
print(ma)
| 0 | null | 45,746,214,930,076 | 205 | 171 |
from itertools import permutations
import math
n = int(input())
x = []
y = []
for i in range(n):
xi, yi = map(int, input().split(' '))
x.append(xi)
y.append(yi)
l = [i for i in range(n)]
route = list(permutations(l))
length = 0
for ls in route:
for i in range(n-1):
length += math.sqrt((x[ls[i+1]]-x[ls[i]])**2+(y[ls[i+1]]-y[ls[i]])**2)
ans = length/math.factorial(n)
print(ans)
|
import itertools
import math
n = int(input())
l = []
for _ in range(n):
x, y = map(int, input().split())
l.append((x,y))
def d(a, b):
return ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5
ans = 0
for v in itertools.permutations(l):
s = 0
for i in range(n-1):
s += d(v[i], v[i+1])
ans += s
print(ans / math.factorial(n))
| 1 | 148,424,959,153,618 | null | 280 | 280 |
n,m = map(int,input().split())
c = list(map(int,input().split()))
i = 0
dp = [0] * 50001
for i in range(50001):
dp[i] = i
#金額ごとに最小枚数を出す
for i in range(2,n+1):
for j in range(m):
if i - c[j] >= 0:
dp[i] = min(dp[i], dp[i - c[j]] + 1)
print(dp[n])
|
import sys
input = sys.stdin.readline
def inpl():
return list(map(int, input().split()))
N, M = inpl()
coins = inpl()
dp = [i for i in range(N + 1)]
coins.sort()
for n in range(coins[1], N + 1):
for c in coins[1:]:
if c > n:
continue
dp[n] = min(dp[n], dp[n - c] + 1)
# print(dp[N])
print(dp[N])
| 1 | 140,901,995,780 | null | 28 | 28 |
mod = 1000000007
N, K = map(int, input().split())
pos = []
neg = []
A = list(map(int, input().split()))
for i in range(N):
if A[i] > 0:
pos.append(A[i])
else:
neg.append(A[i])
ans = 1
if len(pos) == 0:
if K % 2 == 0:
neg.sort(reverse=True)
else:
neg.sort()
for i in range(K):
ans = (ans * neg.pop()) % mod
elif N == K:
for i in pos:
ans = (ans * i) % mod
for i in neg:
ans = (ans * i) % mod
else:
pos.sort()
neg.sort(reverse=True)
if K % 2 == 1:
ans = pos.pop()
for i in range(K//2):
if len(pos) > 1 and len(neg) > 1:
if pos[-1] * pos[-2] > neg[-1] * neg[-2]:
for _ in range(2):
ans = ans * pos.pop() % mod
else:
for _ in range(2):
ans = ans * neg.pop() % mod
elif len(pos) > 1:
for _ in range(2):
ans = ans * pos.pop() % mod
else:
for _ in range(2):
ans = ans * neg.pop() % mod
print(ans)
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
def solve(N, K, A):
ans = 1
# K = N の場合は明らか
if K == N:
for i in range(K):
ans *= A[i]
ans %= MOD
# Ai の全ての数が負かつ K が奇数のとき、
elif max(A) < 0 and K % 2 == 1:
A.sort(reverse=True)
# 絶対値が小さい方から K 個の積
for i in range(K):
ans *= A[i]
ans %= MOD
# それ以外の場合、積は必ず非負
else:
# {Ai} を絶対値の降順にソート
A.sort(key=abs, reverse=True)
# 最初の K 個の積
sign = 1
for i in range(K):
ans *= A[i]
ans %= MOD
if A[i] < 0:
sign *= -1
elif A[i] == 0:
sign *= 0
# P が負の場合
if sign < 0:
small_nonneg = [a for a in A[K:] if a >= 0]
small_neg = [a for a in A[K:] if a < 0]
large_nonneg = [a for a in A[:K] if a >= 0]
large_neg = [a for a in A[:K] if a < 0]
if not small_neg or not large_nonneg:
ans *= max(small_nonneg)
ans %= MOD
ans *= pow(max(large_neg), MOD - 2, MOD)
ans %= MOD
elif not small_nonneg or not large_neg:
ans *= min(small_neg)
ans %= MOD
ans *= pow(min(large_nonneg), MOD - 2, MOD)
ans %= MOD
else:
if min(small_neg) * max(large_neg) > max(small_nonneg) * min(
large_nonneg
):
# (2) 正の数を 1 つ取り除き、負の数を 1 つ加える
ans *= min(small_neg)
ans %= MOD
ans *= pow(min(large_nonneg), MOD - 2, MOD)
ans %= MOD
else:
# (1) 負の数を 1 つ取り除き、非負の数を 1 つ加える
ans *= max(small_nonneg)
ans %= MOD
ans *= pow(max(large_neg), MOD - 2, MOD)
ans %= MOD
return ans
print(solve(N, K, A))
| 1 | 9,526,536,585,972 | null | 112 | 112 |
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
mod=10**9+7
MAX=10**5+100
g1=[1,1]
g2=[1,1]
for i in range(2,MAX+1):
num_1=g1[-1]*i%mod
g1.append(num_1)
g2.append(pow(num_1,mod-2,mod))
def cmb(n,r):
return g1[n]*g2[r]*g2[n-r]%mod
N,K = I()
A = l()
A.sort()
ans = 0
for i in range(N-K+1):
ans -= A[i]*cmb(N-i-1,K-1)
ans %= mod
A = A[::-1]
for i in range(N-K+1):
ans += A[i]*cmb(N-i-1,K-1)
ans %= mod
print(ans%mod)
|
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
def zaatsu(nums):
ref = list(set(copy.copy(nums)))
ref.sort()
dic = dict()
for i, num in enumerate(ref):
dic[num] = i
return [dic[num] for num in nums]
def solve():
n, d, a = getList()
li = []
for i in range(n):
li.append(getList())
li.sort()
ichi = [x[0] for x in li]
imos = [0] * n
cur = 0
ans = 0
for i, (x, h) in enumerate(li):
cur -= imos[i]
hp = h - cur * a
if hp <= 0:
continue
thr = hp // a
if hp % a != 0:
thr += 1
ans += thr
cur += thr
owari = bisect_right(ichi, x + 2 * d)
if owari != n:
imos[owari] += thr
print(ans)
def main():
n = getN()
for _ in range(n):
solve()
return
if __name__ == "__main__":
# main()
solve()
| 0 | null | 89,341,952,458,940 | 242 | 230 |
n = int(input())
c = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
a = int(str(i)[0])
b = int(str(i)[-1])
c[a][b] += 1
res = 0
for i in range(10):
for j in range(10):
res += c[i][j]*c[j][i]
print(res)
|
#https://mirucacule.hatenablog.com/entry/2020/04/27/090908
#https://drken1215.hatenablog.com/entry/2020/04/29/171300
S=str(input())[::-1]#逆順で格納
N=len(S)
counter=[0]*2019
counter[0]=1
ans=0
num,d=0,1
for c in S:
num += int(c) * d
num %= 2019
d *= 10
d %= 2019
counter[num]+=1
for i in counter:
ans += i*(i-1)//2
print(ans)
| 0 | null | 58,570,568,544,950 | 234 | 166 |
import sys
for i in sys.stdin:
h,w = map(int,i.strip().split())
if h==0 and w==0:
break
for i in range(h):
for j in range(w):
if (i+j) % 2 == 0:
print('#',end='')
else:
print('.',end='')
print()
print()
|
n = int(input())
print(sum(i for i in range(1, n + 1) if i % 3 != 0 and i % 5 != 0))
| 0 | null | 17,884,582,189,760 | 51 | 173 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
X, Y, A, B, C = getNM()
P = getList()
Q = getList()
R = getList()
P.sort()
Q.sort()
lista = P[-X:] + Q[-Y:] + R
lista.sort()
print(sum(lista[-(X + Y):]))
|
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
x,y,a,b,c=n1()
P=n1()
Q=n1()
R=n1()
P.sort()
Q.sort()
A=P[-x:]+Q[-y:]+R
A.sort()
print(sum(A[-x-y:]))
| 1 | 44,691,884,696,080 | null | 188 | 188 |
from itertools import accumulate
import numpy as np
MOD = 10 ** 9 + 7
def cumprod(A, mod=MOD):
L = len(A)
Lsq = int(L ** 0.5 + 1)
A = np.resize(A, Lsq ** 2).reshape((Lsq, Lsq))
for i in range(1, Lsq):
A[:, i] *= A[:, i - 1]
A[:, i] %= mod
for i in range(1, Lsq):
A[i] *= A[i - 1][-1]
A[i] %= mod
return A.ravel()[:L]
def make_fact_and_inv(U, mod=MOD):
"""
0~Nまでのサイズ(N+1)の階乗およびその逆元の配列を返す
"""
tmp = np.arange(U, dtype=np.int64)
tmp[0] = 1
fact = cumprod(tmp, mod)
tmp = np.arange(U, 0, -1, dtype=np.int64)
tmp[0] = pow(int(fact[-1]), mod - 2, mod)
inv = cumprod(tmp, mod)[::-1]
return fact, inv
fact, inv = make_fact_and_inv(2 * 10 ** 5 + 10)
def nCr(n, r, mod=MOD):
if r < 0 or r > n or n < 0:
return 0
return fact[n] * inv[r] % mod * inv[n - r] % mod
if __name__ == "__main__":
N, K = map(int, input().split())
ans = []
for i in range(min(N - 1, K) + 1):
val = nCr(N, i) * nCr(N - 1, i) % MOD
ans.append(val)
answer = 0
while ans:
answer = (answer + ans.pop()) % MOD
print(answer)
|
import sys
n, k = map(int, input().split())
P = int(1e9+7)
def cmb(n, r, P):
r = min(r, n - r)
inv_y = 1
for i in range(1, r + 1):
inv_y = (inv_y * i) % P
inv_y = pow(inv_y, P - 2, P)
x = 1
for i in range(n - r + 1, n + 1):
x = x * i % P
return (x * inv_y) % P
if k >= n:
print(cmb(2*n-1, n, P))
sys.exit()
if k == 1:
print((n * n - 1) % P)
sys.exit()
ans = 1
comb1 = 1
comb2 = 1
for i in range(1, k + 1):
iinv = pow(i, P-2, P)
comb1 = ((comb1 * (n - i)) * (iinv)) % P
comb2 = ((comb2 * (n - i + 1)) * (iinv)) % P
ans = (ans + comb1*comb2) % P
print(ans)
| 1 | 67,218,378,347,300 | null | 215 | 215 |
K = int(input())
S = input()
n = len(S)
MOD = 10 ** 9 + 7
MAX = 2 * 10 ** 6 + 5
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fac[i] = fac[i - 1] * i % MOD
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
def nCk(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
A = 0
for i in range(K + 1):
A1 = pow(26, K - i, MOD)
A2 = (pow(25, i, MOD) * nCk(i + n - 1, n - 1)) % MOD
A = (A + (A1 * A2) % MOD) % MOD
print(A % MOD)
|
import string
ab = string.ascii_lowercase
bc = ab[1:] + 'a'
c = input()
for a, b in zip(ab, bc):
if a == c:
print(b)
| 0 | null | 52,358,907,148,320 | 124 | 239 |
x=int(input())
if 0<=x<=1:
if x==1:
print("0")
else:
print("1")
|
#import time
def main():
N, K = map(int, input().split())
matrix = [list(map(int, input().split())) for i in range(2*K)]
sunuke = [0]*(N+1)
for i in range(K):
for j in matrix[2*i+1]:
sunuke[j] += 1
ans = sunuke.count(0) -1
return ans
if __name__ == '__main__':
#start = time.time()
print(main())
#elapsed_time = time.time() - start
#print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")
| 0 | null | 13,890,356,158,720 | 76 | 154 |
N = int(input())
alpha=list('abcdefghijklmnopqrstuvwxyz')
res=['']
for i in range(N):
tmp = []
for j in res:
for k in alpha[:len(set(list(j))) +1]:
tmp.append(j+k)
res = tmp
for i in res:
print(i)
|
#import sys
#input = sys.stdin.readline
import math
from collections import defaultdict,deque
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()
"""========main code==============="""
n=ii()
d=defaultdict(int)
for i in range(1,100):
for j in range(1,100):
for k in range(1,100):
w=i*i+j*j+k*k+i*j+i*k+j*k
d[w]+=1
for i in range(1,n+1):
print(d[i])
| 0 | null | 30,263,941,704,602 | 198 | 106 |
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
def geta(fn=lambda s: s.decode()):
return map(fn, readline().split())
def gete(fn=lambda s: s.decode()):
return fn(readline().rstrip())
# sys.setrecursionlimit(10**5)
def main():
h, a = geta(int)
print((h + a - 1) // a)
if __name__ == "__main__":
main()
|
n = int(input())
rooms = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for rec in range(n):
b, f, r, v = map(int, input().split())
rooms[b-1][f-1][r-1] += v
for i, b in enumerate(rooms):
for f in b:
print("",*f)
if i != 3:
print("####################")
| 0 | null | 38,817,944,989,790 | 225 | 55 |
H, W, M = map(int, input().split())
h_list = [0 for i in range(H)]
w_list = [0 for i in range(W)]
point = {}
for _ in range(M):
h, w = map(int, input().split())
h_list[h - 1] += 1
w_list[w - 1] += 1
point[(h - 1, w - 1)] = 1
hmax = 0
wmax = 0
hmap = {}
wmap = {}
for i, h in enumerate(h_list):
if hmax <= h:
hmax = h
hmap.setdefault(h, []).append(i)
for i, w in enumerate(w_list):
if wmax <= w:
wmax = w
wmap.setdefault(w, []).append(i)
# print(hmap)
# print(wmap)
# hmax = max(h_list)
# wmax = max(w_list)
h_index = h_list.index(hmax)
w_index = w_list.index(wmax)
for h in hmap[hmax]:
for w in wmap[wmax]:
if (h, w) not in point:
print(hmax + wmax)
exit(0)
print(hmax + wmax - 1)
|
H, W, M = list(map(int, input().split()))
h = [0] * H
w = [0] * W
hw = {}
for _ in range(M):
a, b = list(map(int, input().split()))
h[a - 1] += 1
w[b - 1] += 1
temp = "x" + str(a - 1) + "y" + str(b - 1)
hw[temp] = 1
hm = max(h)
wm = max(w)
hp = [i for i, v in enumerate(h) if v == hm]
wp = [i for i, v in enumerate(w) if v == wm]
for x in hp:
for y in wp:
temp = "x" + str(x) + "y" + str(y)
if temp not in hw:
print(hm + wm)
exit()
else:
print(hm + wm - 1)
| 1 | 4,693,651,119,002 | null | 89 | 89 |
import sys
import math
input = sys.stdin.readline
A, B = map(int, input().split())
X = A / 0.08
Y = B/0.1
for i in range(math.floor(min(X, Y)), math.ceil(max(X, Y)) + 1):
if int(i * 0.08) == A and int(i * 0.10) == B:
print(i)
exit()
print(-1)
|
#144_E
n, k = map(int, input().split())
a = sorted(list(map(int,input().split())))
f = sorted(list(map(int,input().split())))[::-1]
l, r = -1, 10 ** 12
while r - l > 1:
x = (r + l) // 2
res = 0
for i in range(n):
res += max(0, a[i] - x // f[i])
if res > k:
l = x
else:
r = x
print(r)
| 0 | null | 110,477,169,253,100 | 203 | 290 |
n=int(input())
l=[]
lis=[]
for _ in range(n):
a=int(input())
l.append(a)
li=[]
for _ in range(a):
c,d=map(int,input().split())
li.append([c,d])
lis.append(li)
ans=-1
for i in range(2**n-1,-1,-1):
mark=bin(i)[2:]
mark=(n-len(mark))*'0'+mark
s=0
record=[-1]*n
f=1
for j in range(n):
for k in range(l[j]):
number=lis[j][k][0]-1
hou=lis[j][k][1]
if int(mark[j])==1:
if record[number]==-1:
record[number]=hou
elif record[number]!=hou:f=0
if f==0:break
if f == 0: break
if f==1:
F=True
for i in range(n):
if record[i]!=-1:
if record[i]!=int(mark[i]):
F=False
break
if F==True:
print(mark.count('1'))
exit()
|
import sys
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse.csgraph import floyd_warshall
input = sys.stdin.readline
n, m, energy = map(int, input().split())
edges = [[float('INF')]*n for _ in range(n)]
for i in range(m):
a, b, c = map(int, input().split())
edges[a-1][b-1] = c
edges[b-1][a-1] = c
G = csgraph_from_dense(edges, null_value=float('INF'))
dist = floyd_warshall(G) # dist[i][j] = min_distance between i and j
L_edges = [[0]*n for _ in range(n)]
for i in range(n-1):
for j in range(i, n):
if dist[i][j] <= energy:
L_edges[i][j] = 1
L_edges[j][i] = 1
G = csgraph_from_dense(L_edges, null_value=0)
answers = floyd_warshall(G)
for i in range(n):
for j in range(n):
if answers[i][j] == float('INF'):
answers[i][j] = 0
answers[j][i] = 0
Q = int(input())
for i in range(Q):
s, t = map(int, input().split())
ans = answers[s-1][t-1] - 1
print(int(ans))
| 0 | null | 147,563,494,071,264 | 262 | 295 |
N = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(0, N, 2):
if a[i] % 2 == 1:
cnt += 1
print(cnt)
|
n = int(input())
a = 0
l = list(map(int, input().split()))
for i in range(n):
if i % 2 == 0:
if l[i] % 2 != 0:
a = a + 1
print(a)
| 1 | 7,822,944,124,320 | null | 105 | 105 |
n = int(input())
ascii_letters = 'abcdefghijklmnopqrstuvwxyz'
for i in range(1,15):
if n<=26**i:
order=i
n-=1
break
n-=26**i
for i in range(order):
print(ascii_letters[n//(26**(order-i-1))],end='')
n%=(26**(order-i-1))
print()
|
N=int(input())
N_26=[]
while N>0:
N-=1
N_mod=N%26
N=N//26
N_26.append(chr(97+N_mod))
print("".join(list(reversed(N_26))))
| 1 | 11,866,598,042,400 | null | 121 | 121 |
A, B, M=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c = [list(map(int, input().split())) for i in range(M)]
# とりあえず最小
minc=min(a)+min(b)
for v in c:
minc = min(minc, (a[v[0]-1]+b[v[1]-1]-v[2]))
print(minc)
|
A, B = map(int, input().split())
times = A * B
if A < B:
A, B = B, A
while B > 0:
temp = A % B
A = B
B = temp
print(int(times/A))
| 0 | null | 83,404,320,603,672 | 200 | 256 |
# -*- coding: utf-8 -*-
N=int(input())
As=list(map(int, input().split()))
k=0
k1=As[0]
g=0
for i in range(2,N+1):
if i%2==1:
k=max(k+As[i-1],g)
k1=k1+As[i-1]
if i%2==0:
g=max(k1,g+As[i-1])
#print(k,k1,g)
ans=g if N%2==0 else k
print(ans)
|
class UnionFind:
from typing import List, Set
def __init__(self, n):
self.n = n
self.parent = [-1] * n
def union(self, x, y) -> int:
x = self.leader(x)
y = self.leader(y)
if x == y:
return 0
if self.parent[x] > self.parent[y]:
x, y = y, x
self.parent[x] += self.parent[y]
self.parent[y] = x
return self.parent[x]
def same(self, x, y) -> bool:
return self.leader(x) == self.leader(y)
def leader(self, x) -> int:
if self.parent[x] < 0:
return x
else:
self.parent[x] = self.leader(self.parent[x])
return self.parent[x]
def size(self, x) -> int:
return -self.parent[self.leader(x)]
def groups(self) -> List[Set[int]]:
groups = dict()
for i in range(self.n):
p = self.leader(i)
if not groups.get(p):
groups[p] = set()
groups[p].add(i)
return list(groups.values())
n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
a, b = map(int, input().split())
uf.union(a-1, b-1)
print(len(uf.groups()) - 1)
| 0 | null | 19,888,456,826,910 | 177 | 70 |
k = int(input())
ans = 0
s = 7
for i in range(1, 10**6 + 1):
s %= k
if s == 0:
print(i)
exit()
s = s*10 +7
print(-1)
|
n = int(input())
a = [(int(x), i) for i, x in enumerate(input().split())]
a.sort(reverse=True)
aval, ai = zip(*a)
dp = [[0] * (n+1) for _ in range(n+1)]
for l in range(n):
for r in range(n):
if l + r >= n: break
dp[l+1][r] = max(dp[l+1][r], dp[l][r] + aval[l+r] * abs(ai[l+r]-l))
dp[l][r+1] = max(dp[l][r+1], dp[l][r] + aval[l+r] * abs(ai[l+r]-(n-r-1)))
print(max([dp[i][n-i] for i in range(n+1)]))
| 0 | null | 19,986,682,384,352 | 97 | 171 |
import sys
input()
rl = sys.stdin.readlines()
d = {}
for i in rl:
#c, s = i.split()
if i[0] == 'i':
#if c[0] == 'i':
d[i[7:]] = 0
#d[s] = 0
else:
if i[5:] in d:
#if s in d:
print('yes')
else:
print('no')
|
import itertools
import math
N = int(input())
L = [list(map(int,input().split())) for n in range(N)]
I = list(itertools.permutations(L))
sum = 0
for i in I:
for n in range(N-1):
sum += math.sqrt((i[n+1][0]-i[n][0])**2+(i[n+1][1]-i[n][1])**2)
print(sum/len(I))
| 0 | null | 74,029,016,696,088 | 23 | 280 |
n=int(input())
if n>=400 and n<=599:
print("8")
elif n>=600 and n<=799:
print("7")
elif n>=800 and n<=999:
print("6")
elif n>=1000 and n<=1199:
print("5")
elif n>=1200 and n<=1399:
print("4")
elif n>=1400 and n<=1599:
print("3")
elif n>=1600 and n<=1799:
print("2")
elif n>=1800 and n<=1999:
print("1")
|
def gcd(X,Y):
x = X
y = Y
if y > x:
x,y = y,x
while x % y:
x,y = y,x%y
return y
number = [int(i) for i in input().split()]
print(gcd(number[0],number[1]))
| 0 | null | 3,378,588,620,822 | 100 | 11 |
import bisect
n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
for i in range(n):
for j in range(i+1,n):
index=bisect.bisect_left(l,l[i]+l[j])
ans+=index-j-1
print(ans)
|
import bisect
n = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for a in range(0,n):
for b in range(a+1,n):
p = bisect.bisect_left(L, L[a]+L[b])
ans += max(p-(b+1),0)
print(ans)
| 1 | 172,233,336,218,880 | null | 294 | 294 |
#!/usr/bin/env python3
import sys
import itertools
def solve(N: int, P: "List[int]", Q: "List[int]"):
l = []
for i in range(N):
l.append(i+1)
p = 0
q = 0
c = 0
for i in itertools.permutations(l, N):
c += 1
t = list(i)
if t == P:
p = c
if t == Q:
q = c
if p != 0 and q != 0:
print(abs(q - p))
break
return
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
P = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
Q = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, P, Q)
if __name__ == '__main__':
main()
|
import math
def fact(n):
ans = 1
for i in range(2, n+1):
ans*= i
return ans
def comb(n, c):
return fact(n)//(fact(n-c)*c)
r = float(input())
print("%.20f"%(2.0*math.pi*r))
| 0 | null | 66,222,816,273,600 | 246 | 167 |
import math
(a, b, C) = [float(i) for i in input().split()]
S = 0.5 * a * b * math.sin(math.radians(C))
c = math.sqrt(a * a + b * b - 2 * a * b * math.cos(math.radians(C)))
print("%8f" %(S))
print("%8f" %(a + b + c))
print("%8f" %(S / a * 2))
|
import math
a,b,C=map(float,input().split())
S = a*b*math.sin(C*math.pi/180)/2
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C*math.pi/180))
h = 2*S/a
print("{:10f}".format(S))
print("{:10f}".format(a+b+c))
print("{:10f}".format(h))
| 1 | 176,251,897,600 | null | 30 | 30 |
from bisect import bisect_left
N = int(input())
S = input()
d = {"R": [], "G": [], "B": []}
for i in range(N):
d[S[i]].append(i)
def find(x, y, z):
total = len(z)
res = 0
for i in x:
for j in y:
if i > j:
continue
# Find k > j
k = bisect_left(z, j)
# Find k == 2 * j - i
k0 = bisect_left(z, 2 * j - i)
flag = int(k0 >= k and k0 < total and z[k0] == 2 * j - i)
res += total - k - flag
return res
ans = 0
ans += find(d["R"], d["G"], d["B"])
ans += find(d["R"], d["B"], d["G"])
ans += find(d["G"], d["R"], d["B"])
ans += find(d["G"], d["B"], d["R"])
ans += find(d["B"], d["R"], d["G"])
ans += find(d["B"], d["G"], d["R"])
print(ans)
|
N,K=map(int, input().split())
def change(N,shinsu):
keta=0
for i in range(10**9):
if N<shinsu**i:
keta+=i
break
ans=[0]*keta
check=0
for i in range(1,keta+1):
j=N//(shinsu**(keta-i))
ans[check]=j
check+=1
N-=(j)*(shinsu**(keta-i))
return ans
print(len(change(N,K)))
| 0 | null | 50,132,860,080,528 | 175 | 212 |
def main():
import sys
input = sys.stdin.readline
from collections import Counter
class BIT:
def __init__(self,n):
self.size = n
self.tree = [Counter([]) for _ in range(n+1)]
def change(self,i,x,y):
while i <= self.size:
if x in self.tree[i]:
self.tree[i][x] -= 1
if y not in self.tree[i]:
self.tree[i][y] = 0
self.tree[i][y] += 1
i += i&-i
def sum(self,i):
res = Counter([])
while i > 0:
res += self.tree[i]
i -= i&-i
return res
N = int(input())
st = BIT(N)
S = list(input())
Q = int(input())
for i in range(N):
st.change(i+1," ",S[i])
for _ in range(Q):
q,a,b = input().split()
if q == "1":
st.change(int(a),S[int(a)-1],b)
S[int(a)-1] = b
else:
res = st.sum(int(b)) - st.sum(int(a)-1)
ans = 0
for v in res.values():
if v > 0:
ans += 1
print(ans)
main()
|
import sys
from collections import Counter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N = int(readline())
S = readline().strip()
counter = Counter(S)
ans = counter['R'] * counter['G'] * counter['B']
for i in range(N):
for j in range(i + 1, (N + i + 1) // 2):
if 2 * j - i >= N:
break
if S[i] != S[j] and S[i] != S[2 * j - i] and S[j] != S[2 * j - i]:
ans -= 1
print(ans)
return
if __name__ == '__main__':
main()
| 0 | null | 49,157,133,588,300 | 210 | 175 |
# Can't Wait for Holiday
S = input()
if S == 'SUN':
a = 0
elif S == 'MON':
a = 1
elif S == 'TUE':
a = 2
elif S == 'WED':
a = 3
elif S == 'THU':
a = 4
elif S == 'FRI':
a = 5
elif S == 'SAT':
a = 6
answer = 7 - a
print(answer)
|
import collections
N, X, Y = [int(x) for x in input().split()]
c = collections.Counter()
for i in range(1, N + 1):
for j in range(i, N + 1):
if (i == X and j == Y) or (i == Y and j == X):
c[1] += 1
else:
c[min([j - i, abs(X - i) + 1 + abs(Y - j), abs(X - j) + 1 + abs(Y - i)])] += 1
for i in range(1, N):
print(c[i])
| 0 | null | 88,404,488,546,764 | 270 | 187 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.