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
|
---|---|---|---|---|---|---|
N = int(input())
cnt = 0
flg = False
for _ in range(N):
a, b = map(int, input().split())
if a != b:
cnt = 0
else:
cnt += 1
if cnt >= 3:
flg = True
if flg:
print('Yes')
else:
print('No')
|
S=str(input())
if S.isupper()==True:
print("A")
else:
print("a")
| 0 | null | 6,850,679,936,802 | 72 | 119 |
N,R = map(int,input().split())
print((R,R +100*(10-N))[N<=10])
|
import math
from numpy.compat.py3k import asstr
a, b = map(int, input().split())
ans = int(a * b / math.gcd(a, b))
print(str(ans))
| 0 | null | 87,976,432,430,012 | 211 | 256 |
# B - Battle
import sys
a,b,c,d = map(int,input().split())
while True:
if c - b <= 0:
print('Yes')
sys.exit()
c = c - b
if a - d <= 0:
print('No')
sys.exit()
a = a - d
|
t_hp, t_atk, a_hp, a_atk = map(int, input().split())
t_count = 0
a_count = 0
while a_hp > 0:
a_hp -= t_atk
t_count += 1
while t_hp > 0:
t_hp -= a_atk
a_count += 1
if t_count <= a_count:
print('Yes')
else:
print('No')
| 1 | 29,696,328,864,928 | null | 164 | 164 |
# -*- coding: utf-8 -*-
H, N = map(int, input().split(' '))
nums = [float('inf') for _ in range(H+1)]
nums[0] = 0
for _ in range(N):
a, b = map(int, input().split(' '))
for i in range(H + 1):
j = min(H, i+a)
nums[j] = min(nums[j], nums[i] + b)
print(nums[H])
|
H, N = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(N)]
dp = [0]*(H+1)
for i in range(1, H+1):
for j in range(N):
if j == 0:
if ls[j][0] <= i:
dp[i] = dp[i-ls[j][0]] + ls[j][1]
else:
dp[i] = ls[j][1]
else:
if ls[j][0] <= i:
dp[i] = min([dp[i], dp[i-ls[j][0]] + ls[j][1]])
else:
dp[i] = min([dp[i], ls[j][1]])
print(dp[H])
| 1 | 81,160,003,110,560 | null | 229 | 229 |
def p_is_smaller(p):
total = 0
number_of_track = 1
for w in W:
total += w
if total > p:
number_of_track += 1
if number_of_track > k:
return 1
total = w
return 0
if __name__ == "__main__":
n, k = map(int, input().split())
W = [int(input()) for _ in range(n)]
left, right = max(W), sum(W)
while right > left:
mid = (left + right) // 2
if p_is_smaller(mid):
left = mid + 1
else:
right = mid
print(right)
|
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): 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 LSS(): return input().split()
def resolve():
n, k = LI()
Q = [I() for _ in range(n)]
def can_stack(p):
s = 0
truck_num = 1
for i in Q:
if s+i<=p:
s += i
else:
truck_num += 1
s = i
return truck_num<=k
ng = max(Q)-1
ok = sum(Q)
while abs(ok-ng)>1:
m = (ng+ok)//2
if can_stack(m):
ok = m
else:
ng = m
print(ok)
# for i in range(20):
# print(i, can_stack(i))
if __name__ == '__main__':
resolve()
| 1 | 90,744,057,292 | null | 24 | 24 |
n = int(input())
ans = n // 2
ans += 1 if n % 2 != 0 else 0
print(ans)
|
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
k=abs(a-b)
if 0<=k<=(v-w)*t and v!=w:
print("YES")
else:
print("NO")
| 0 | null | 37,053,111,890,080 | 206 | 131 |
s=input()
print("A" if s.upper()==s else "a")
|
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
N = int(readline())
a = list(map(int,readline().split()))
s = 0
for ai in a:
s = s^ai
ans = []
for ai in a:
ans.append(s^ai)
print(' '.join(map(str,ans)))
| 0 | null | 11,940,891,875,780 | 119 | 123 |
X,Y,A,B,C=list(map(int,input().split()))
p=sorted(list(map(int,input().split())),reverse=True)
q=sorted(list(map(int,input().split())),reverse=True)
r=sorted(list(map(int,input().split())),reverse=True)
i=X-1
j=Y-1
k=0
ans=sum(p[:X])+sum(q[:Y])
while k<len(r):
if i>-1 and j>-1:
if p[i]<q[j]:
cmin=p[i]
i-=1
else:
cmin=q[j]
j-=1
if r[k]<=cmin:
break
ans+=r[k]-cmin
k+=1
elif i>-1:
cmin=p[i]
i-=1
if r[k]<=cmin:
break
ans+=r[k]-cmin
k+=1
elif j>-1:
cmin=q[j]
j-=1
if r[k]<=cmin:
break
ans+=r[k]-cmin
k+=1
else:
break
print(ans)
|
from time import time
from random import randint
from numba import njit
from numpy import int64
@njit('i8(i8[:], i8[:])', cache=True)
def func(s, x):
last = [0] * 26
score = 0
for i, v in enumerate(x, 1):
last[v] = i
c = 0
for j in range(26):
c += s[j] * (i - last[j])
score += s[i * 26 + v] - c
return score
def main():
start = time()
d, *s = map(int, open(0).read().split())
s = int64(s)
x = int64(([*range(26)] * 15)[:d])
M = func(s, x)
while time() - start < 1.5:
y = x.copy()
if randint(0, 1):
y[randint(0, d - 1)] = randint(0, 25)
elif randint(0, 1):
i=randint(0, d - 16)
j=randint(i + 1, i + 15)
y[i], y[j] = y[j], y[i]
else:
i = randint(0, d - 15)
j = randint(i + 1, i + 7)
k = randint(j + 1, j + 7)
if randint(0, 1):
y[i], y[j], y[k] = y[j], y[k], y[i]
else:
y[i], y[j], y[k] = y[k], y[i], y[j]
t = func(s, y)
if t > M:
M = t
x = y
print(*x + 1, sep='\n')
main()
| 0 | null | 27,431,240,346,822 | 188 | 113 |
n, m = map(int, input().split())
work = list(map(int, input().split()))
if n - sum(work) < 0:
print("-1")
else:
print(n - sum(work))
|
N=input()
n=N[-1]
if n=='3':
ans='bon'
elif n=='0' or n=='1' or n=='6' or n=='8':
ans='pon'
else:
ans='hon'
print(ans)
| 0 | null | 25,554,629,818,208 | 168 | 142 |
n = int(input())
ans = 0
music = {}
for i in range(n):
a, b = input().split()
ans += int(b)
music[a] = ans
print(ans-music[input()])
|
import math
N = float(input())
if(N%2==0):
print(1/2)
else:
print((math.floor(N/2)+1)/N)
| 0 | null | 137,425,165,901,600 | 243 | 297 |
N,P = map(int, input().split())
S = input()
if P == 2:
ans = 0
for i in range(N):
if int(S[i])%2 == 0:
ans += i+1
elif P == 5:
ans = 0
for i in range(N):
if S[i] == "0" or S[i] == "5":
ans += i+1
else:
L = [0]*P
num = 0
for i in range(N):
num += int(S[N-i-1])*pow(10, i, P)
num %= P
L[num] += 1
ans = L[0]
for i in range(P):
ans += L[i]*(L[i]-1)//2
print(ans)
|
import collections
n,p=map(int,input().split())
s=input()
arr=[int(s[i]) for i in range(len(s))]
if p==2 or p==5:
ans=0
for i in range(n):
if arr[i]%p==0:
ans+=i+1
print(ans)
else:
dic=collections.defaultdict(int)
match=[]
pows=[1]
for _ in range(n):
pows.append((pows[-1]*10)%p)
tmp=0
for i in range(n-1,-1,-1):
tmp+=arr[i]*pows[n-1-i]
tmp%=p
match.append(tmp)
dic[tmp]+=1
match=match[::-1]
ans=0
rem=0
rev=pow(10,p-2,p)
for i in range(n-1,-1,-1):
ans+=dic[rem]
rem+=arr[i]*pows[n-1-i]
rem%=p
dic[match[i]]-=1
print(ans)
| 1 | 58,439,080,422,970 | null | 205 | 205 |
def yes(N,M):
N+=1
print('YNeos'[M::N])
return
a,b=map(int,input().split())
if 500*a >= b:
yes(1,0)
else:
yes(1,1)
|
k, x = input().split()
K = int(k)
X = int(x)
result = 500 * K
if result >= X:
print("Yes")
else:
print("No")
| 1 | 98,011,953,380,528 | null | 244 | 244 |
import sys
a=[map(int,i.split())for i in sys.stdin]
for i,j in a:
c,d=i,j
while d:
if c > d:c,d = d,c
d%=c
print(c,i//c*j)
|
def solve(n,x):
count = 0
for i in range(1,n+1):
for j in range(i+1,n+1):
k = x - i - j
if j < k and k <= n:
count += 1
return count
while True:
n,x = map(int,input().split())
if n == x == 0:
break;
print(solve(n,x))
| 0 | null | 639,206,955,650 | 5 | 58 |
s = raw_input()
p = raw_input()
s3 = s + s + s
if p in s3:
print 'Yes'
else:
print 'No'
|
n = int(input())
l = list(map(int, input().split()))
s = 0
m = l[0]
for i in range(n):
if m >= l[i]:
m = l[i]
s += 1
print(s)
| 0 | null | 43,721,621,767,972 | 64 | 233 |
import sys
sys.setrecursionlimit(10**7)
import fileinput
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
for line in sys.stdin:
x, y = map(int, line.split())
print(gcd(x,y),lcm(x,y))
|
import sys
def gcm(a,b):
return gcm(b,a%b) if b else a
for s in sys.stdin:
a,b=map(int,s.split())
c=gcm(a,b)
print c,a/c*b
| 1 | 613,088,660 | null | 5 | 5 |
n = int(input())
A = list(map(int,input().split()))
data = [0]*3
ans = 1
mod = pow(10,9)+7
for i in A:
ans *= data.count(i)
ans %= mod
if ans == 0:
break
data[data.index(i)] += 1
print(ans)
|
N = int(input())
a_list = list(map(int, input().split()))
MOD = 10**9 + 7
cnts = [0,0,0]
sames = 0
ind = -1
res = 1
for a in a_list:
for i, cnt in enumerate(cnts):
if cnt == a:
sames += 1
ind = i
res *= sames
res %= MOD
cnts[ind] += 1
sames = 0
print(res)
| 1 | 130,575,509,911,682 | null | 268 | 268 |
def main():
N, M = map(int, input().split())
*G, = map(int, input())
ans = []
cur = N
ecur = cur - 1
while cur > 0:
ncur = cur
while (cur - ecur) <= M and ecur >= 0:
if G[ecur] == 0:
ncur = ecur
ecur -= 1
if ncur == cur:
print(-1)
return
ans.append(cur - ncur)
cur = ncur
ans.reverse()
print(*ans)
if __name__ == '__main__':
main()
|
N = int(input())
memo = [1]*(N+1)
for i in range(2,N+1):
tmp = i
while tmp <= N:
memo[tmp] += 1
tmp += i
ans = 0
for key,val in enumerate(memo):
ans += key*val
print(ans)
| 0 | null | 75,164,819,731,332 | 274 | 118 |
n,k=map(int,input().split());print(len([i for i in list(map(int,input().split())) if i>=k]))
|
n,k=map(int,input().split())
h=list(map(int,input().split()))
res=0
for i in range(n):
res += (h[i] >= k)
print(res)
| 1 | 179,103,236,228,228 | null | 298 | 298 |
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(500000)
MOD = 10**9+7
def input():
return sys.stdin.readline()[:-1]
def mi():
return map(int, input().split())
def ii():
return int(input())
def i2(n):
tmp = [list(mi()) for i in range(n)]
return [list(i) for i in zip(*tmp)]
@lru_cache(maxsize=None)
def f(x):
if x < 0:
return False
if (x%100==0) or (x%101==0) or (x%102==0) \
or (x%103==0) or (x%104==0) or (x%105==0):
return True
return f(x-100) or f(x-101) or f(x-102) \
or f(x-103) or f(x-104) or f(x-105)
def main():
X = ii()
print(1 if f(X) else 0)
if __name__ == '__main__':
main()
|
r = int(input())
print(r * 2 * 3.1415926535897932384626433)
| 0 | null | 79,540,361,253,728 | 266 | 167 |
import sys
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())
def main():
n, k = mi()
p = list(map(lambda x: int(x)-1, input().split()))
c = li()
ans = -10**18
for i in range(n):
v = i
cycle_cnt = 0
cycle_sum = 0
while True:
cycle_cnt += 1
cycle_sum += c[v]
v = p[v]
if v == i:
break
cnt = 0
tmp = 0
while True:
tmp += c[v]
cnt += 1
if cnt > k:
break
r = (k-cnt)//cycle_cnt
score = tmp+r*max(0, cycle_sum)
ans = max(ans, score)
v = p[v]
if v == i:
break
print(ans)
if __name__ == '__main__':
main()
|
# 公式解説を見てからやった
# 複数サイクルでき、1-K回移動可能
# N < 5000?多分、O(N * 2N)くらいで行けそうに見えるが。。。
def main(N,K,P,C):
# 一度計算したサイクル情報を一応キャッシュしておく。。。
# あんまり意味なさそう
cycleIDs = [ -1 for _ in range(N) ]
cycleInfs = []
# print(P)
ans = -1e10
cycleID = 0
for n in range(N):
v = n
currentCycleItemCnt = 0
currentCycleTotal = 0
if cycleIDs[v] != -1:
currentCycleItemCnt, currentCycleTotal = cycleInfs[ cycleIDs[v] ]
# print(currentCycleItemCnt, currentCycleTotal)
else:
while True:
# 全頂点について、属するサイクルを計算する
currentCycleItemCnt += 1
currentCycleTotal += C[v]
v = P[v]
if v == n:
# サイクル発見
cycleInfs.append( (currentCycleItemCnt, currentCycleTotal) )
cycleID += 1
break
# 一応、一度サイクルを計算した頂点については、
# その頂点の属するサイクルの情報をメモっておく。。。
cycleIDs[v] = cycleID
procCnt = 0
currentCycleSumTmp = 0
while True:
# 頂点vにコマが置かれた時の最高スコアを計算し、
# これまでの最高スコアを上回ったら、これまでの最高スコアを更新する
procCnt += 1
currentCycleSumTmp += C[v]
if K < procCnt:
break
cycleLoopCnt = 0
if procCnt < K and 0 < currentCycleTotal:
cycleLoopCnt = ( K - procCnt ) // currentCycleItemCnt
# print("v=", v, "currentCycleSumTmp=", currentCycleSumTmp, procCnt)
tmp = currentCycleSumTmp + cycleLoopCnt * currentCycleTotal
ans = max( ans, tmp )
v = P[v]
if v == n:
# サイクル終了
break
return ans
# print(ans)
if __name__ == "__main__":
N,K = map(int,input().split())
P = [ int(p)-1 for p in input().split() ]
C = list(map(int,input().split()))
ans=main(N,K,P,C)
print(ans)
| 1 | 5,370,735,998,708 | null | 93 | 93 |
n=int(input())
a_tmp=list(map(int,input().split()))
a=[]
for i in range(n):
a.append([a_tmp[i],i+1])
a.sort(key=lambda x:x[0])
for i in range(n):
print(a[i][1],end=" ")
|
N=int(input())
S=str(input())
flg = True
if len(S)%2 != 0:
print("No")
else:
for i in range(len(S)//2):
if S[i] != S[i+len(S)//2]:
print("No")
flg = False
if flg == True:
print("Yes")
| 0 | null | 163,550,023,816,362 | 299 | 279 |
def fib(n):
n1 = n2 = tmp = 1
for _ in range(n - 1):
tmp = n1 + n2
n1, n2 = n2, tmp
return tmp
print(fib(int(input())))
|
a,b=[],[]
for _ in range(int(input())):
x,y=map(int,input().split())
a+=[x-y]
b+=[x+y]
print(max(max(a)-min(a),max(b)-min(b)))
| 0 | null | 1,722,857,698,332 | 7 | 80 |
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
# import numpy as np
sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
s = input()
cnt = [0 for _ in range(2019)]
cnt[0] += 1
dec = 1
num = 0
for i in reversed(s):
num += int(i) * dec
num %= 2019
dec *= 10
dec %= 2019
cnt[num] += 1
ans = 0
for c in cnt:
ans += c * (c - 1) // 2
print(ans)
if __name__ == '__main__':
main()
|
from collections import Counter
n = int(input())
verdicts = Counter([input() for i in range(n)])
for verdict in ["AC", "WA", "TLE", "RE"]:
print(f"{verdict} x {verdicts[verdict]}")
| 0 | null | 19,608,678,923,626 | 166 | 109 |
s = input()
s_l = [0] * (len(s) + 1)
s_r = [0] * (len(s) + 1)
for i in range(len(s)):
if s[i] == '<':
s_l[i + 1] = s_l[i] + 1
for i in range(len(s)):
if s[- i - 1] == '>':
s_r[- i - 2] = s_r[- i - 1] + 1
ans = 0
for i, j in zip(s_l, s_r):
ans += max(i, j)
print(ans)
|
S = input().replace("><", "> <").split()
ans = 0
for s in S:
up = s.count("<")
down = len(s) - up
if up < down:
up -= 1
ans += up * (up+1) // 2 + down * (down+1) // 2
else:
down -= 1
ans += up * (up+1) // 2 + down * (down+1) // 2
print(ans)
| 1 | 156,438,594,703,986 | null | 285 | 285 |
n = int(input())
a = list(map(int,input().split()))
b = [2 ** i for i in range(n)]
c = {}
for i in range(2 ** n):
k = 0
k += i
v = 0
for j in range(n)[::-1]:
v += k // b[j] * a[j]
k %= b[j]
c[v] = 0
m = int(input())
a = list(map(int,input().split()))
for i in range(m):
try:
c[a[i]]
print("yes")
except:
print("no")
|
c = input()
l = list('abcdefghijklmnopqrstuvwxyz')
for i in range(0, len(l)):
if c == l[i]:
print(l[i+1])
else:
i+=1
| 0 | null | 45,880,617,916,412 | 25 | 239 |
n = input()
n = int(n)
l = []
for i in range(1, n+1):
if i % 3 == 0:
l.append(i)
else:
j = i
while j > 0:
if j % 10 == 3:
l.append(i)
break
else:
j //= 10
for p in l:
print(" " + str(p), end="")
print()
|
lst = []
num = int(input())
while num != 0:
lst.append(num)
num = int(input())
it = zip(range(len(lst)), lst)
for (c, v) in it:
print("Case " + str(c+1) + ": " + str(v))
| 0 | null | 697,476,624,080 | 52 | 42 |
#coding: utf-8
s = input()
q = int(input())
for i in range(q):
order = input().split(" ")
if order[0] == "print":
print(s[int(order[1]) : int(order[2])+1])
elif order[0] == "reverse":
r = s[int(order[1]) : int(order[2])+1]
r = r[::-1]
s = s[:int(order[1])] + r + s[int(order[2])+1:]
elif order[0] == "replace":
s = s[:int(order[1])] + order[3] + s[int(order[2])+1:]
|
A,B,C,K = map(int,input().split())
if K<=A:
Ans = K
elif K<=A+B:
Ans = A
elif K<=A+B+C:
Ans = A-(K-A-B)
else:
Ans = A-C
print(Ans)
| 0 | null | 11,976,492,413,324 | 68 | 148 |
n=int(input())
a=list(map(int,input().split()))
#R,B,Gの順に埋めていく
#R,B,Gの現在の数を保存する
cnt={'R':0,'B':0,'G':0}
ans=1
for i in range(n):
count=0
edi=0
for j in 'RBG':
if cnt[j]==a[i]:
count+=1
if edi==0:
cnt[j]+=1
edi=1
ans*=count
print(ans%(10**9+7))
|
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)
MOD = 1000000007 # type: int
def solve(N: int, K: int):
ret = 0
counts = [0] * (K + 1)
for i in range(1, K + 1)[::-1]:
c = K // i
cnt = pow(c, N, MOD)
j = 2
while i * j <= K:
cnt -= counts[i * j]
j += 1
ret += cnt * i
ret %= MOD
counts[i] = cnt
#print(counts)
print(ret)
return
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
K = int(next(tokens)) # type: int
solve(N, K)
if __name__ == '__main__':
main()
| 0 | null | 83,705,603,324,970 | 268 | 176 |
#!/usr/bin/python3
cmdvar_numlist=input()
cmdvar_spritd=cmdvar_numlist.split()
D,T,S=list(map(int,cmdvar_spritd))
if D/S<=T:
print("Yes")
else:
print("No")
|
a,b,c,d=map(float,input().split())
x=abs(a-c)
y=abs(b-d)
z=x**2+y**2
print(pow(z,0.5))
| 0 | null | 1,832,843,510,108 | 81 | 29 |
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [int(input()) for _ in range(m)]
for i in a:
c = 0
for j, k in zip(i, b):
c += j * k
print(c)
|
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)]
for i, ai in enumerate(a):
cnt = 0
for j, bj in enumerate(b):
cnt += ai[j] * bj
print(cnt)
| 1 | 1,136,768,959,088 | null | 56 | 56 |
from collections import OrderedDict
import sys
cnt = OrderedDict()
for i in range(ord('a'), ord('z') + 1):
cnt[chr(i)] = 0
S = sys.stdin.readlines()
for s in S:
s = s.lower()
for i in s:
if i in cnt:
cnt[i] += 1
for k, v in cnt.items():
print('{} : {}'.format(k, v))
|
import sys
alist = list('abcdefghijklmnopqrstuvwxyz')
r = {}
for al in alist:
r[al] = 0
line = sys.stdin.read().lower()
for i in range(len(line)):
if line[i] in r.keys():
r[line[i]] += 1
for k,v in r.items():
print("{} : {}".format(k, v))
| 1 | 1,651,522,900,022 | null | 63 | 63 |
s = input()
t = input()
counter = 0
for index, character in enumerate(s):
if t[index] != character:
counter += 1
print(counter)
|
dif_max = 1-10**9
min = 10**9
n_max = 0
n_max = int(raw_input())
price = [0]*n_max
for i in range(0, n_max):
price[i] = int(raw_input())
for i in range(0, n_max-1):
if min >= price[i]:
min = price[i]
if dif_max <= price[i+1] - min:
dif_max = price[i+1] - min
print dif_max
| 0 | null | 5,311,439,558,850 | 116 | 13 |
n = int(input())
def sieve1(n):
isPrime = [True] * (n+1)
isPrime[0] = False
isPrime[1] = False
for i in range(2*2, n+1, 2):
isPrime[i] = False
for i in range(3, n+1):
if isPrime[i]:
for j in range(i+i, n+1, i):
isPrime[j] = False
return isPrime
numOfDivisors = [2] * (n+1)
numOfDivisors[1] = 1
numOfDivisors[0] = 0
isPrime = sieve1(n)
for i in range(2, n+1):
if isPrime[i]:
for j in range(2*i, n+1, i):
x = j // i
numOfDivisors[j] += numOfDivisors[x] - 1
ans = 0
for k in range(1, n+1):
ans += numOfDivisors[k] * k
print (ans)
|
import sys
input = sys.stdin.readline
from bisect import *
def judge(x):
cnt = 0
for Ai in A:
cnt += N-bisect_left(A, x-Ai+1)
return cnt<M
def binary_search():
l, r = 0, 2*max(A)
while l<=r:
m = (l+r)//2
if judge(m):
r = m-1
else:
l = m+1
return l
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
border = binary_search()
acc = [0]*(N+1)
for i in range(N):
acc[i+1] = acc[i]+A[i]
cnt = 0
ans = 0
for Ai in A:
j = bisect_left(A, border-Ai+1)
cnt += N-j
ans += (N-j)*Ai+acc[N]-acc[j]
ans += (M-cnt)*border
print(ans)
| 0 | null | 59,459,492,360,772 | 118 | 252 |
import math
a,b,C = map(float,input().split())
C = math.pi* C / 180
area = (a * b * math.sin(C) / 2)
print(area)
print(a + b + math.sqrt(a**2 + b**2 - 2 * a * b* math.cos(C)))
print(area * 2 / a)
|
from collections import deque
n, m = map(int, input().split())
to = [[] for _ in range(n + 1)]
for i in range(m):
a, b = map(int, input().split())
to[a].append(b)
to[b].append(a)
q = deque([1])
dist = [-1] * (n + 1)
# print(to)
while q:
v = q.popleft()
for u in to[v]:
if dist[u] != -1:
continue
q.append(u)
dist[u] = v
print("Yes")
# print(dist)
for i in range(2, n + 1):
print(dist[i])
| 0 | null | 10,369,134,256,978 | 30 | 145 |
# coding: utf-8
import math
N, K = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
A.sort()
p = 10**9 + 7
facts = [1, 1]
for i in range(2, N+1):
facts.append((facts[i-1] * i) % p)
invs = [1 for i in range(N+1)]
invs[N] = pow(facts[N], p-2, p)
for i in range(N, 1, -1):
invs[i-1] = invs[i] * i % p
sum_max_s = 0
for i in range(K, N+1):
sum_max_s += A[i-1] * (facts[i-1] * invs[K-1] * invs[i-K] % p) % p
sum_min_s = 0
for i in range(1, N-K+2):
sum_min_s += A[i-1] * (facts[N-i] * invs[K-1] * invs[N-i-K+1] % p) % p
print(str(int(sum_max_s - sum_min_s) % p))
|
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools, bisect
import math, fractions
import sys, copy
def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def S(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
@lru_cache(maxsize=1024*1024)
def fact(n): return math.factorial(n)
def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return fact(n) // (fact(r) * fact(n-r))
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
INF = float("inf")
class FactInv:
def __init__(self, N, MOD=1000000007):
fact, inv = [1]*(N+1), [None]*(N+1)
for i in range(1, N+1): fact[i] = fact[i - 1] * i % MOD
inv[N] = pow(fact[N], MOD - 2, MOD)
for i in range(N)[::-1]: inv[i] = inv[i + 1] * (i + 1) % MOD
self.N, self.MOD, self.fact, self.inv = N, MOD, fact, inv
def perm(self, a, b):
if a > self.N or b > self.N: raise ValueError("\nPermutaion arguments are bigger than N\n N = {}, a = {}, b = {}".format(self.N, a, b))
return self.fact[a] * self.inv[a-b] % self.MOD
def comb(self, a, b):
if a > self.N or b > self.N: raise ValueError("\nCombination arguments are bigger than N\n N = {}, a = {}, b = {}".format(self.N, a, b))
return self.fact[a] * self.inv[b] * self.inv[a-b] % self.MOD
def main():
N, K = LI()
A = sorted(LI())
factinv = FactInv(N + 1)
ans = 0
for i, x in enumerate(A):
maxc = factinv.comb(i, K - 1) if i >= K - 1 else 0
minc = factinv.comb(len(A) - i - 1, K - 1) if len(A) - i - 1 >= K - 1 else 0
ans = (ans + x * (maxc - minc)) % MOD
print(ans % MOD)
if __name__ == '__main__':
main()
| 1 | 95,763,188,900,750 | null | 242 | 242 |
while True:
case=input().split()
x=int(case[0])
y=int(case[1])
if x==0 and y==0:
break
else:
if x<y:
print(x,y)
else:
print(y,x)
|
while True:
x, y = map(int, input().split())
if x == 0 and y == 0:
break
if x > y:
x, y = y, x
print(x, y)
| 1 | 524,857,470,720 | null | 43 | 43 |
S = input()
K = int(input())
ss = []
seq = 1
for a,b in zip(S,S[1:]):
if a==b:
seq += 1
else:
ss.append(seq)
seq = 1
ss.append(seq)
if len(ss)==1:
print(len(S)*K//2)
exit()
if S[0] != S[-1]:
ans = sum([v//2 for v in ss]) * K
print(ans)
else:
ans = sum([v//2 for v in ss[1:-1]]) * K
ans += (ss[0]+ss[-1])//2 * (K-1)
ans += ss[0]//2 + ss[-1]//2
print(ans)
|
class UnionFind():
"""unionFindツリー
FindとUnionがきも
https://note.nkmk.me/python-union-find/
"""
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N,M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
a,b = map(int, input().split())
a,b = a-1, b-1
uf.union(a,b)
print(uf.group_count() - 1)
| 0 | null | 88,785,636,779,102 | 296 | 70 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
def inp():
return int(input())
def inps():
return input().rstrip()
def inpl():
return list(map(int, input().split()))
def _debug(obj):
print(obj, file=sys.stderr)
# import decimal
# from decimal import Decimal
# decimal.getcontext().prec = 10
# from heapq import heappush, heappop, heapify
# import math
# from math import gcd
# import itertools as it
# import collections
# from collections import deque
# ---------------------------------------
mod = 10**9 +7
N, K = inpl()
ans = 0
for i in range(K, N + 2):
ans += (N + 1 - i) * i + 1
ans %= mod
print(ans)
|
import itertools
N, K = map(int, input().split())
num = []
for i in range(N+1):
num.append(i)
ans = 0
for i in range(K, N+2):
min_i = (i-1)*i//2
max_i = (2*N-i+1)*i//2
ans += max_i - min_i + 1
print(ans%(10**9+7))
| 1 | 33,032,305,813,240 | null | 170 | 170 |
x = int(input())
a,b = x//100, x%100
print(1 if a*5 >= b else 0)
|
x = input()
if len(x) < 3:
print(0)
exit()
k = int(x[0:-2])
x = int(x[-2:])
k -= x / 5
if x % 5 == 0 and k >= 0:
print(1)
elif k > 0:
print(1)
else:
print(0)
| 1 | 127,214,436,687,900 | null | 266 | 266 |
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
S = input()
if S[-1] == 's':
S += 'es'
else:
S += 's'
print(S)
resolve()
|
n=int(input())
s,t=map(str, input().split())
a=[]
for i in range(n):
a.append(s[i]+t[i])
a = "".join(a)
print(a)
| 0 | null | 57,263,648,153,282 | 71 | 255 |
N = input()
a = [input() for i in range(N)]
def smax(N,a):
smin = a[0]
smax = -10**9
for j in range(1,N):
smax = max(smax,a[j]-smin)
smin = min(smin,a[j])
return smax
print smax(N,a)
|
n=input()
min = None
max = None
cand=None
for x in xrange(n):
v = input()
# print "#### %s %s %s %s" % (str(max), str(min), str(cand), str(v))
if min is None:
min = v
# print "min is None"
continue
if min > v:
# print "min > v"
if (cand is None) or (cand < v-min):
# print "cand None"
cand = v-min
min = v
max = None
continue
elif (max is None) or (max < v):
# print "max is None"
max = v
if cand < max - min:
cand = max - min
continue
print cand
| 1 | 12,972,329,820 | null | 13 | 13 |
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, k = LI()
A = [0] + LI()
for i in range(1, n + 1):
A[i] = (A[i] + A[i - 1]) % k
for i in range(n + 1):
A[i] = (A[i] - i) % k
ans = 0
D = defaultdict(int)
for j in range(n, -1, -1):
ans += D[A[j]]
D[A[j]] += 1
if j + k - 1 < n + 1:
D[A[j + k - 1]] -= 1
if k == 1:
print(0)
else:
print(ans)
|
import sys, os
import collections
MOD = 10 ** 9 + 7
def solve(input_stream):
N, K = read_ints(input_stream)
numbers = [int(i) - 1 for i in input_stream.readline().strip().split()]
cumulative_sum = [0 for i in range(N + 1)]
mods = {}
ans = 0
for index, number in enumerate(numbers):
cumulative_sum[index + 1] = (cumulative_sum[index] + number) % K
queue = []
for index in range(N+1):
if cumulative_sum[index] not in mods:
mods[cumulative_sum[index]] = 0
ans += mods[cumulative_sum[index]]
mods[cumulative_sum[index]] += 1
queue.append(cumulative_sum[index])
if len(queue) == K:
target = queue.pop(0)
mods[target] -= 1
return [str(ans)]
def read_ints(input_stream):
return [i for i in map(int, input_stream.readline().strip().split())]
def read_int(input_stream):
return int(input_stream.readline().strip())
if __name__ == "__main__":
outputs = solve(sys.stdin)
for line in outputs:
print(line)
| 1 | 137,554,934,757,326 | null | 273 | 273 |
n = input()
Max = -4300000000
Min = input()
for i in range(n - 1):
IN_NOW = input()
Max = max(Max, (IN_NOW - Min))
Min = min(Min, IN_NOW)
print Max
|
n = input()
R = [input() for i in range(n)]
max = R[1] - R[0]
min = R[0]
for i in range(1,n):
if R[i] - min > max:
max = R[i] - min
if R[i] < min:
min = R[i]
print max
| 1 | 13,289,359,040 | null | 13 | 13 |
H,A = map(int,input().split())
b = H // A
c = H % A
if c != 0:
b += 1
print(b)
|
h, a = list(map(int, input().split(' ')))
ans = 0
while h > 0:
h -= a
ans += 1
print(ans)
| 1 | 77,109,291,222,070 | null | 225 | 225 |
# coding: utf-8
n = int(input())
scores = [0,0]
for i in range(n):
card = input().split()
first_card = card[0]
card.sort()
if (card[0] == card[1]):
scores[0] += 1
scores[1] += 1
elif(first_card == card[0]):
scores[1] += 3
else:
scores[0] += 3
print(scores[0], scores[1])
|
count = int(input())
point = {'taro': 0, 'hanako': 0}
for i in range(count):
(taro, hanako) = [s for s in input().split()]
if (taro > hanako) - (taro < hanako) == 0:
point['taro'] += 1
point['hanako'] += 1
elif (taro > hanako) - (taro < hanako) > 0:
point['taro'] += 3
else:
point['hanako'] += 3
print(point['taro'], point['hanako'])
| 1 | 2,007,262,728,280 | null | 67 | 67 |
while 1 :
a,op,b=raw_input().split()
ai=int(a)
bi=int(b)
if op=='?':break
elif op=='+':print ai+bi
elif op=='-':print ai-bi
elif op=='*':print ai*bi
elif op=='/':print ai/bi
|
a = [list(map(int, input().split())) for i in range(3)]
n =int(input())
for k in range(n):
b = int(input())
for i in range(3):
for j in range(3):
if a[i][j] == b:
a[i][j] = 0
row0 = a[0] == [0, 0, 0]
row1 = a[1] == [0, 0, 0]
row2 = a[2] == [0, 0, 0]
colum0 = [a[0][0], a[1][0], a[2][0]] == [0, 0, 0]
colum1 = [a[0][1], a[1][1], a[2][1]] == [0, 0, 0]
colum2 = [a[0][2], a[1][2], a[2][2]] == [0, 0, 0]
diag0 = [a[0][0], a[1][1], a[2][2]] == [0, 0, 0]
diag1 = [a[2][0], a[1][1], a[0][2]] == [0, 0, 0]
if row0 or row1 or row2 or colum0 or colum1 or colum2 or diag0 or diag1:
print('Yes')
break
else:
print('No')
| 0 | null | 30,447,865,542,080 | 47 | 207 |
from collections import defaultdict
(h,n),*ab = [list(map(int, s.split())) for s in open(0)]
mxa = max(a for a,b in ab)
dp = defaultdict(lambda: float('inf'))
dp[0] = 0
for i in range(1, h+mxa):
dp[i] = min(dp[i-a] + b for a,b in ab)
print(min(v for k,v in dp.items() if k>=h))
|
n = input()
if n == 0:
print(1)
elif n == 1:
print(1)
else:
fib = [0 for i in range(n + 1)]
fib[0] = 1
fib[1] = 1
for i in range(2, n + 1):
fib[i] = fib[i - 1] + fib[i - 2]
print(fib[n])
| 0 | null | 40,358,197,816,222 | 229 | 7 |
hoge = list(map(int, input().split()))
ret = sorted(hoge)
print(str(ret[0])+" "+str(ret[1])+" "+str(ret[2]))
|
x = input()
a, b, c = tuple(x.split())
a = int(a)
b = int(b)
c = int(c)
abc = sorted([a, b, c])
print(abc[0], abc[1], abc[2])
| 1 | 423,165,519,800 | null | 40 | 40 |
A, B, C, K=map(int, input().split())
if A>=K:
print(K)
elif A+B>=K>A:
print(A)
elif A+B+C>=K>A+B:
print(A-(K-A-B))
|
def main():
a, b, c, k = map(int, input().split())
if a + b >= k:
print(min(a, k))
else:
print(a-(k-a-b))
if __name__ == "__main__":
main()
| 1 | 21,987,256,563,118 | null | 148 | 148 |
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for a in range(N):
for b in range(a):
ab = L[a] + L[b]
r = bisect.bisect_left(L, ab)
l = a + 1
ans += max(r - l, 0)
print(ans)
|
kai = input()
num = len(kai)
ans = 0
n1 = int((num-1) / 2)
for i in range(n1):
if kai[i] != kai[-1*(i+1)]:
ans += 1
l1 = kai[0:n1]
for i in range(len(l1)):
if l1[i] != l1[-1*(i+1)]:
ans += 1
l2 = kai[n1+1:]
for i in range(len(l2)):
if l2[i] != l2[-1*(i+1)]:
ans += 1
if ans == 0:
print("Yes")
else:
print("No")
| 0 | null | 109,342,841,648,278 | 294 | 190 |
def main():
s = input()
if s[2] == s[3] and s[4] == s[5]:
print('Yes')
else:
print('No')
main()
|
# A - Duplex Printing
from math import ceil
print(ceil(int(input()) / 2))
| 0 | null | 50,406,504,849,792 | 184 | 206 |
index = int(input())
liststr = '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'
list = liststr.split(',')
print(int(list[index-1]))
|
k = input()
s = '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'
row = s.split(', ')
print(row[int(k)-1])
| 1 | 50,078,992,779,442 | null | 195 | 195 |
N = int(input())
S = input()
ris = [i for i, s in enumerate(S) if s == "R"]
gis = [i for i, s in enumerate(S) if s == "G"]
bis = [i for i, s in enumerate(S) if s == "B"]
all = len(ris) * len(gis) * len(bis)
cnt = 0
for i in range(N):
for j in range(i+1, N):
k = 2*j - i
if 0 <= k < N:
if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
cnt += 1
ans = all - cnt
print(ans)
|
N = int(input())
S = list(input())
R_list = [0]*N
G_list = [0]*N
B_list = [0]*N
for key,val in enumerate(S):
if val=='R':
R_list[key] = R_list[key-1]+1
G_list[key] = G_list[key-1]
B_list[key] = B_list[key-1]
elif val=='G':
R_list[key] = R_list[key-1]
G_list[key] = G_list[key-1]+1
B_list[key] = B_list[key-1]
elif val=='B':
R_list[key] = R_list[key-1]
G_list[key] = G_list[key-1]
B_list[key] = B_list[key-1]+1
ans = 0
for i in range(N-2):
for j in range(i+1,N-1):
if S[i]==S[j]:
continue
a=2*(j+1)-(i+1)-1
check = [S[i],S[j]]
if 'R' not in check:
ans += R_list[-1]-R_list[j]
if a<N and S[a]=='R':
ans -= 1
elif 'G' not in check:
ans += G_list[-1]-G_list[j]
if a<N and S[a]=='G':
ans -= 1
elif 'B' not in check:
ans += B_list[-1]-B_list[j]
if a<N and S[a]=='B':
ans -= 1
print(ans)
| 1 | 35,977,716,599,748 | null | 175 | 175 |
n,m=map(int,input().split())
l=[0]*n
w=0
c=0
ac=set()
for i in range(m):
p,s=map(str,input().split())
p=int(p)
if s=='WA':
l[p-1]+=1
else:
if p not in ac:
c+=1
w+=l[p-1]
ac.add(p)
print(c,w)
|
N,M = map(int,input().split())
ls2 = []
for i in range(M):
A,B = map(str,input().split())
ls = [int(A)-1,B]
ls2.append(ls)
Pena = 0
corr = 0
#ls3 = sorted(ls2, key=lambda x: x[0])
lsans = [[] for i in range(N)]
for i in range(M):
lsans[ls2[i][0]].append(ls2[i][1])
for i in range(N):
if 'AC' in lsans[i]:
for ans in lsans[i]:
if ans == 'WA':
Pena += 1
if ans == 'AC':
corr += 1
break
print(corr,Pena)
| 1 | 93,398,039,500,478 | null | 240 | 240 |
n,m=input().split()
if(n==m):
print("Yes\n")
else:
print("No\n")
|
from math import floor, ceil
def solve(X, D, lb, ub):
# min abs(X + t * D) (lb <= t <= ub) (lb, ub, t are int)
ts = [
lb,
ub,
max(min(floor(-X / D), ub), lb),
max(min(ceil(-X / D), ub), lb),
]
return min([abs(X + t * D) for t in ts])
X, K, D = map(int, input().split())
if K % 2 == 0:
ans = solve(X, D * 2, -(K // 2), +(K // 2))
else:
ans1 = solve(X + D, D * 2, -((K + 1) // 2), +((K - 1)) // 2)
ans2 = solve(X - D, D * 2, -((K - 1) // 2), +((K + 1)) // 2)
ans = min(ans1, ans2)
print(ans)
| 0 | null | 44,260,669,381,710 | 231 | 92 |
S = list(input())
K = int(input())
S.extend(S)
prev = ''
cnt = 0
for s in S:
if s == prev:
cnt += 1
prev = ''
else:
prev = s
b = 0
if K % 2 == 0:
b += 1
if K > 2 and S[0] == S[-1]:
mae = 1
while mae < len(S) and S[mae] == S[0]:
mae += 1
if mae % 2 == 1 and mae != len(S):
usiro = 1
i = len(S) - 2
while S[i] == S[-1]:
usiro += 1
i -= 1
if usiro % 2 == 1:
b = K // 2
if K % 2 == 0:
res = cnt * (K // 2) + (b - 1)
else:
res = cnt * (K // 2) + cnt // 2 + b
print(res)
|
N = int(input())
L = list(map(int, input().split()))
cnt = 0
for i in range(N - 2):
for j in range(i + 1, N - 1):
if L[i] != L[j]:
for k in range(j + 1, N):
if L[i] != L[k] and L[j] != L[k]:
M = [L[i], L[j], L[k]]
M.sort()
if M[2] < M[0] + M[1]:
cnt += 1
print(cnt)
| 0 | null | 90,518,056,309,768 | 296 | 91 |
N = int(input())
A = list(map(lambda x: int(x) - 1, input().split()))
C = [0] * N
for a in A:
C[a] += 1
def comb(n):
if n <= 1:
return 0
else:
return n * (n - 1) // 2
t = sum(list(map(comb, C)))
for a in A:
print(t - comb(C[a]) + comb(C[a] - 1))
|
import collections
import itertools
N = int(input())
A = list(map(int, input().split()))
ac = collections.Counter(A)
dp = [0] * (N+1)
dp2 = [0] * (N+1)
total = 0
for no, num in ac.items():
dp[no] = int(num*(num-1)/2)
dp2[no] = dp[no] - (num-1)
total += dp[no]
for k in range(1,N+1):
no = A[k-1]
print(int(total - dp[no] + dp2[no]))
| 1 | 47,572,215,786,460 | null | 192 | 192 |
N = int(input())
print(N + N**2 + N**3)
|
a = int(input())
print(a*(1+a*(1+a)))
| 1 | 10,268,590,402,266 | null | 115 | 115 |
# -*- coding: utf-8 -*-
list = map(int, raw_input().split())
a = list[0]
b = list[1]
print a*b ,
print 2*(a+b)
|
x = map(int, raw_input().split())
s = x[0] * x[1]
n = 2 * (x[0] + x[1])
print '%d %d' % (s, n)
| 1 | 307,707,711,072 | null | 36 | 36 |
n = int(input())
s = input()
if s[0:n // 2] ==s[n//2:]:
print('Yes')
else:
print('No')
|
n, m = map(int, input().split())
if n == m:
print('Yes')
elif n > m:
print('No')
| 0 | null | 114,835,174,475,110 | 279 | 231 |
# -*- coding: utf-8 -*-
a = [int(raw_input()) for _ in range(10)]
#print a
b = sorted(a, reverse=True)
#print b
for c in b[0:3]:
print c
|
mountain = [int(input()) for _ in range(10)]
mountain.sort()
for _ in -1, -2, -3 : print(mountain[_])
| 1 | 22,693,012 | null | 2 | 2 |
X = int(input())
wk = 0
cnt = 0
while True:
wk += X
cnt += 1
wk %= 360
if wk % 360 == 0:
break
print(cnt)
|
N = int(input())
a = list(map(int, input().split()))
cnt = 0
i = 1
while i <= N:
if a[i-1] % 2 == 1:
cnt += 1
i += 2
print(cnt)
| 0 | null | 10,493,798,963,908 | 125 | 105 |
A,B,K = map(int, open(0).read().split())
if K <= A:
print(A-K,B)
elif K >= A + B:
print(0,0)
else:
print(0,B-K+A)
|
import numpy as np
inp = input()
A, B, K = int(inp.split(' ')[0]), int(inp.split(' ')[1]), int(inp.split(' ')[2])
if K>A:
B = np.max([0, B-(K-A)])
A = np.max([0, A-K])
print(f'{A} {B}')
| 1 | 104,468,010,608,194 | null | 249 | 249 |
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
diff_dist = B - A
diff_v = V - W
flag = False
if diff_v == 0:
if diff_dist == 0:
flag = True
elif diff_dist == 0:
flag = True
else:
if diff_v > 0:
t = abs(diff_dist) / diff_v
if t <= T:
flag = True
if flag:
print('YES')
else:
print('NO')
|
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, v = M() # おに
b, w = M() # にげる
t = I()
ans = 'NO'
if v-w > 0:
b_hiku_a = abs(b - a)
v_hiku_w = v - w
if b_hiku_a <= t * (v-w):
ans = 'YES'
print(ans)
| 1 | 15,021,148,611,808 | null | 131 | 131 |
import sys
K=input()
if int(K)%2==0:
print(-1)
sys.exit()
S=int('7'*(len(K)))
ans=len(K)
K=int(K)
for i in range(10**6):
if S%K==0:
print(ans)
break
else:
S=(S*10)%K+7
ans+=1
else:
print(-1)
|
from collections import defaultdict
from collections import deque
from collections import Counter
import math
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
k = readInt()
n = 7
for i in range(10**6):
if n%k==0:
print(i+1)
exit()
else:
n = (n*10+7)%k
print(-1)
| 1 | 6,077,171,807,520 | null | 97 | 97 |
import sys
def solve():
input = sys.stdin.readline
N, M = map(int, input().split())
S = input().strip("\n")
now = N
ans = []
while now > 0:
for i in reversed(range(1, M+1)):
if now - i < 0: continue
elif S[now - i] == "0":
ans.append(i)
now -= i
break
else:
print(-1)
break
else:
A = [int(ans[-1 - i]) for i in range(len(ans))]
print(" ".join(map(str, A)))
return 0
if __name__ == "__main__":
solve()
|
import heapq
def main():
N, M = list(map(int, input().split(' ')))
S = input()
# 最短手数のdpテーブルを作る
T = S[::-1] # ゴールから逆順にたどる(最後に逆にする)
dp = [-1] * (N + 1)
que = [0] * M
for i, t in enumerate(T):
if i == 0:
dp[0] = 0
continue
if len(que) == 0:
print(-1)
return
index = heapq.heappop(que)
if t == '1':
continue
dp[i] = 1 + dp[index]
while len(que) < M:
heapq.heappush(que, i)
dp.reverse()
# 細切れに進んでいく
path = list()
target = dp[0] - 1
cnt = 0
for i in range(N + 1):
if dp[i] != target:
cnt += 1
else:
path.append(cnt)
cnt = 1
target -= 1
print(' '.join(map(str, path)))
if __name__ == '__main__':
main()
| 1 | 138,985,691,966,812 | null | 274 | 274 |
n,*aa = map(int, open(0).read().split())
from collections import Counter
c = Counter(aa)
for i in range(1,n+1):
print(c[i])
|
hoge = list(map(int, input().split()))
ret = sorted(hoge)
print(str(ret[0])+" "+str(ret[1])+" "+str(ret[2]))
| 0 | null | 16,362,851,419,070 | 169 | 40 |
a,b = list(map(int, input().split()))
print('%i %i %10.8f' %(a//b, a%b, a/b))
|
N = int(input())
A = list(map(int, input().split()))
iStock = 0
iMoney = 1000
for i in range(N-1):
if A[i] < A[i + 1]:
# A[i]Day 株購入 & A[i+1]Day 株売却
iStock = iMoney // A[i]
iMoney %= A[i]
iMoney += iStock * A[i+1]
print(iMoney)
| 0 | null | 3,990,857,483,792 | 45 | 103 |
N = int(input())
#print(N)
S = input()
count = 0
for i in range(N):
#print(S[i] , i)
if i == N-1:
break
else:
if S[i+1] != S[i]:
count += 1
if count == 0:
print(1)
else:
print(count+1)
|
import bisect
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
# ある値以上のAiがいくつあるかの情報を累積和で保持
num_A_or_more = [0]*(10**5)
for a in A:
num_A_or_more[a-1] += 1
for i in range(1, 10**5):
j = 10**5 - i
num_A_or_more[j-1] += num_A_or_more[j]
# x以上となる手の組み合わせがM種類以上あるかどうかを判定
def check(x):
count = 0
for a in A:
idx = max(x-a-1, 0)
if idx >= 10**5:
continue
count += num_A_or_more[idx]
return count>=M
# 2分探索でM種類以上の手の組み合わせがある満足度の最大値を求める
left = 0
right = 2*10**5 + 1
mid = (left + right) // 2
while right - left > 1:
if check(mid):
left = mid
else:
right = mid
mid = (left + right)//2
# これがM種類以上の手の組み合わせがある満足度の最大値
x = left
# 降順に並べなおして累積和を求めておく
rev_A = A[::-1]
accum_A = [rev_A[0]]
for i, a in enumerate(rev_A):
if i == 0:
continue
accum_A.append(accum_A[-1] + a)
ans = 0
count = 0
surplus = 2*10**5 # M種類を超えた場合は、一番小さくなる握手の組を最後に削る
for ai in rev_A:
idx = bisect.bisect_left(A, x-ai)
if idx == N:
break
ans += (N-idx)*ai + accum_A[N-idx-1]
count += N - idx
surplus = min(surplus, ai+A[idx])
print(ans - (count-M)*surplus)
| 0 | null | 139,526,226,574,240 | 293 | 252 |
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
N,M=map(int,input().split())
ans = 0
if N >= 2:
ans += len(list(itertools.combinations(range(N), 2)))
if M >= 2:
ans += len(list(itertools.combinations(range(M), 2)))
print(ans)
|
n,m = input().split()
n = int(n)
m = int(m)
print(int(n*(n-1)/2+m*(m-1)/2))
| 1 | 45,858,619,900,072 | null | 189 | 189 |
H = []
while True:
try:
H.append(input())
except EOFError:
break
H.sort()
print(H[-1])
print(H[-2])
print(H[-3])
|
# coding: utf-8
def getint():
return int(input().rstrip())
def main():
ls = []
num_of_mount = 10
num_of_top = 3
for i in range(num_of_mount):
ls.append(getint())
ls.sort(reverse=True)
for i in range(num_of_top):
print(ls[i])
if __name__ == '__main__':
main()
| 1 | 9,508,800 | null | 2 | 2 |
# nikkei2019-2-qualA - Sum of Two Integers
def main():
N = int(input())
ans = (N - 1) // 2
print(ans)
if __name__ == "__main__":
main()
|
a = int(input())
if a % 2 is 0:
print(a // 2 - 1)
else:
print(a // 2)
| 1 | 152,876,679,833,448 | null | 283 | 283 |
while True:
a, op, b = input().split()
if(op == '+'):
print(int(a) + int(b))
elif(op == '-'):
print(int(a) - int(b))
elif(op == '*'):
print(int(a) * int(b))
elif(op == '/'):
print(int(a) // int(b))
else:
break
|
mod=998244353
N,M,K=map(int,input().split())
MAX_N=N+1
Fact=[0 for i in range(MAX_N+1)]
Finv=[0 for i in range(MAX_N+1)]
Fact[0]=1
for i in range(MAX_N):
Fact[i+1]=(i+1)*Fact[i]
Fact[i+1]%=mod
Finv[-1]=pow(Fact[-1],mod-2,mod)
for i in range(MAX_N-1,-1,-1):
Finv[i]=(i+1)*Finv[i+1]
Finv[i]%=mod
def C(n,k):
return (Fact[n]*Finv[k]*Finv[n-k])%mod
'''
i in range(K+1)で総和を取る
隣り合うブロックの色が同じ色なのはi通り
隣り合うブロックの色が異なるのはN-1-i通り
|の選び方はN-1Ci
同じものをつなげてN-i個のブロックと見なせる
これに対してM*((M-1)のN-1-i)乗だけある
0<=i<=K
よりN-1-i>=N-1-K>=0
問題なし
'''
ans=0
for i in range(K+1):
ans+=(C(N-1,i)*M*pow(M-1,N-1-i,mod))%mod
ans%=mod
print(ans)
| 0 | null | 11,869,955,986,240 | 47 | 151 |
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools, bisect
import math, fractions
import sys, copy
def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def S(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
alphabets = "abcdefghijklmnopqrstuvwxyz"
sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
# nodeをリストに変換したらクソ遅かった
import pprint
class BalancingTree:
def __init__(self, n):
self.N = n
self.root = self.node(1<<n, 1<<n)
def __str__(self):
def debug_info(nd):
return (nd.value - 1, nd.left.value - 1 if nd.left else None, nd.right.value - 1 if nd.right else None)
def debug_node(nd):
v = debug_info(nd) if nd.value else ()
left = debug_node(nd.left) if nd.left else []
right = debug_node(nd.right) if nd.right else []
return [v, left, right]
return pprint.PrettyPrinter(indent=4).pformat(debug_node(self.root))
__repr__ = __str__
def append(self, v):# v を追加(その時点で v はない前提)
v += 1
nd = self.root
while True:
# v がすでに存在する場合に何か処理が必要ならここに書く
if v == nd.value:
return 0
else:
mi, ma = min(v, nd.value), max(v, nd.value)
if mi < nd.pivot:
nd.value = ma
if nd.left:
nd = nd.left
v = mi
else:
p = nd.pivot
nd.left = self.node(mi, p - (p&-p)//2)
break
else:
nd.value = mi
if nd.right:
nd = nd.right
v = ma
else:
p = nd.pivot
nd.right = self.node(ma, p + (p&-p)//2)
break
def leftmost(self, nd):
return self.leftmost(nd.left) if nd.left else nd
def rightmost(self, nd):
return self.rightmost(nd.right) if nd.right else nd
def find_l(self, v): # vより真に小さいやつの中での最大値(なければ-1)
v += 1
nd = self.root
prev = nd.value if nd.value < v else 0
while True:
if v <= nd.value:
if nd.left:
nd = nd.left
else:
return prev - 1
else:
prev = nd.value
if nd.right:
nd = nd.right
else:
return prev - 1
def find_r(self, v): # vより真に大きいやつの中での最小値(なければRoot)
v += 1
nd = self.root
prev = nd.value if nd.value > v else 0
while True:
if v < nd.value:
prev = nd.value
if nd.left:
nd = nd.left
else:
return prev - 1
else:
if nd.right:
nd = nd.right
else:
return prev - 1
def max(self):
return self.find_l((1<<self.N)-1)
def min(self):
return self.find_r(-1)
def delete(self, v, nd = None, prev = None): # 値がvのノードがあれば削除(なければ何もしない)
v += 1
if not nd:
nd = self.root
if not prev:
prev = nd
while v != nd.value:
prev = nd
if v <= nd.value:
if nd.left:
nd = nd.left
else:
return
else:
if nd.right:
nd = nd.right
else:
return
if (not nd.left) and (not nd.right):
if nd.value < prev.value:
prev.left = None
else:
prev.right = None
elif not nd.left:
if nd.value < prev.value:
prev.left = nd.right
else:
prev.right = nd.right
elif not nd.right:
if nd.value < prev.value:
prev.left = nd.left
else:
prev.right = nd.left
else:
nd.value = self.leftmost(nd.right).value
self.delete(nd.value - 1, nd.right, nd)
# v以下のものの中での最大値
def upper_bound(self, v):
upper = self.find_r(v)
return self.find_l(upper)
def lower_bound(self, v):
lower = self.find_l(v)
return self.find_r(lower)
def __contains__(self, v: int) -> bool:
return self.find_r(v - 1) == v
class node:
def __init__(self, v, p):
self.value = v
self.pivot = p
self.left = None
self.right = None
def main():
N = I()
s = S()
Q = I()
query = LR(Q)
trees = {ch: BalancingTree(25) for ch in alphabets}
for i, ch in enumerate(s):
trees[ch].append(i)
for q in query:
if q[0] == "1":
_, i, c = q
i = int(i) - 1
prev = s[i]
trees[prev].delete(i)
s[i] = c
trees[c].append(i)
else:
_, l, r = q
l, r = int(l) - 1, int(r) - 1
count = 0
for _, tree in trees.items():
first = tree.lower_bound(l)
if first != tree.root.value - 1 and first <= r:
count += 1
print(count)
if __name__ == '__main__':
main()
|
def update(i,x):
i += d-1
bit = ord(x)-97
seg[i] = 0 | (1<<bit)
while i > 0:
i = (i-1)//2
seg[i] = seg[i*2+1]|seg[i*2+2]
def find(a,b,k,l,r):
if r <= a or b <= l:
return 0
if a <= l and r <= b:
return seg[k]
c1 = find(a,b,2*k+1,l,(l+r)//2)
c2 = find(a,b,2*k+2,(l+r)//2,r)
return c1|c2
n = int(input())
s = input()
q = int(input())
d = 1
while d < n:
d *= 2
seg = [0]*(2*d-1)
for i in range(n):
update(i,s[i])
for i in range(q):
type,a,b = input().split()
if type == "1":
update(int(a)-1,b)
else:
part = find(int(a)-1,int(b),0,0,d)
print(bin(part).count("1"))
| 1 | 62,452,382,089,940 | null | 210 | 210 |
N = int(input())
music = []
for i in range(N):
music.append(input().split())
X = (input())
Time = 0
kama = False
for s,t in music:
if kama:
Time += int(t)
if s == X:
kama = True
print(Time)
|
a, b, c, k = map(int, input().split())
if k <= a:
print(int(k))
elif k <= a + b:
print(int(a))
else:
print(int(2*a + b - k))
| 0 | null | 59,563,396,848,362 | 243 | 148 |
def ok(p,w,k):
track= 1
weight= 0
flag= True
for i in w:
if i > p:
flag=False
break
elif weight+ i> p:
weight= i
track+= 1
else:
weight+= i
if track<=k and flag:
return True
else:
return False
n,k= map(int, input().split())
w=[]
for i in range(n):
w.append(int(input()))
l=0
h=10**11
while l+1 < h:
p= (l+h)//2
if ok(p,w,k):
h= p
else:
l= p
print(h)
|
def decode():
[n, k] = [int(x) for x in input().split(" ")]
ws = []
for _ in range(n):
ws.append(int(input()))
return n, k, ws
def check(k, ws, p):
sum_w = ws[0]
tr = 1
for w in ws[1:]:
if sum_w + w <= p:
sum_w += w
else:
sum_w = w
tr += 1
if tr > k:
return False
return True
if __name__ == '__main__':
n, k, ws = decode()
lo = max(ws)
hi = sum(ws)
while lo <= hi:
p = (lo + hi) // 2
if check(k, ws, p):
hi = p - 1
ans = p
else:
lo = p + 1
print(ans)
| 1 | 85,724,857,842 | null | 24 | 24 |
n=int(input())
T,H=0,0
for i in range(n):
t_card,h_card=input().split()
if t_card>h_card:
T+=3
elif t_card<h_card:
H+=3
else:
T+=1
H+=1
print(str(T)+" "+str(H))
|
n=int(input())
tp = 0
hp = 0
for _ in range(n):
taro,hanaco = input().split()
if taro == hanaco :
tp +=1
hp +=1
elif taro > hanaco :
tp += 3
else: hp += 3
print('{} {}'.format(tp,hp))
| 1 | 2,002,366,182,960 | null | 67 | 67 |
xs=map(int,input().split())
print(' '.join(map(str, sorted(xs))))
|
w=input().lower()
list=[]
while True:
s=input()
if s=="END_OF_TEXT":
break
c=s.lower().split().count(w)
list.append(c)
print(sum(list))
| 0 | null | 1,137,670,620,200 | 40 | 65 |
import sys
import collections
X = int(input())
Angle = 360
for i in range(1,10**9):
if Angle < (X*i):
Angle = Angle + 360
if (Angle / (X*i)) == 1:
print(i)
sys.exit()
|
from sys import stdin
import sys
import math
from functools import reduce
import itertools
n,m = [int(x) for x in stdin.readline().rstrip().split()]
x = list('a'*n)
for i in range(m):
a, b = [x for x in stdin.readline().rstrip().split()]
a = int(a) - 1
if x[a] == 'a' or x[a] == b:
x[a] = b
else:
print(-1)
sys.exit()
if x[0] == '0' and n != 1:
print(-1)
sys.exit()
if x[0] == 'a' and n > 1: x[0] = '1'
if x[0] == 'a' and n == 1: x[0] = '0'
for i in range(1,n):
if x[i] == 'a': x[i] = '0'
print(''.join(x))
| 0 | null | 36,765,906,771,902 | 125 | 208 |
def main():
N = int(input())
for i in range(1, 10):
if N // i < 10 and N % i == 0:
print('Yes')
return
print('No')
main()
|
N = int(input())
ans = 'No'
if N<=82:
for i in range(1,10):
if N%i==0 and len(str(N//i))==1:
ans = 'Yes'
print(ans)
| 1 | 159,397,061,161,942 | null | 287 | 287 |
MOD = 10 ** 9 + 7
N, K = map(int, input().split())
lst = [0] * (K + 1)
ans = 0
for i in range(K, 0, -1):
tmp = K // i
tmp = pow(tmp, N, MOD)
for j in range(2 * i, K + 1, i):
tmp -= lst[j]
ans += (i * tmp)
ans %= MOD
lst[i] = tmp
print (ans)
|
MOD = int(1e9+7)
def main():
N, K = map(int, input().split())
dp = [0] * (K+1)
ans = 0
for i in range(1, K+1)[::-1]:
tmp = pow(K//i, N, MOD)
for j in range(i*2, K+1, i):
tmp = (tmp - dp[j]) % MOD
dp[i] = tmp
ans = (ans + tmp * i) % MOD
print(ans)
if __name__ == "__main__":
main()
| 1 | 36,701,631,778,892 | null | 176 | 176 |
import sys
n = int(input())
dic =set()
t = sys.stdin.readlines()
for i in t:
i,op = i.split()
if i == 'insert':
dic.add(op)
else:
if op in dic:
print('yes')
else:
print('no')
|
n= int(input())
s= set()
for _ in range(n):
a,b= input().split()
if a=="insert":
s.add(b)
elif b in s:
print("yes")
else:
print("no")
| 1 | 78,683,284,538 | null | 23 | 23 |
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) - 1 for _ in range(D)]
def cal_score():
S = 0
last = [-1] * 26
score = 0
for d in range(D):
S += s[d][t[d]]
last[t[d]] = d
for i in range(26):
S -= c[i] * (d - last[i])
score += max(10 ** 6 + S, 0)
print(S)
if __name__ == "__main__":
cal_score()
|
import numpy as np
#基本入力
D = int(input())
c =list(map(int,input().split()))
s = []
for i in range(D):
s.append(list(map(int,input().split())))
t = []
for i in range(D):
t.append(int(input()))
#基本入力完了
#得点計算
c = np.array(c)
last_day = np.array([0]*26)
day_pulse = np.array([1]*26)
s = np.array(s)
t = np.array(t)
manzoku = 0
for day in range(1,D+1):
contest_number = t[day-1] #開催するコンテスト種類
manzoku += s[day-1,contest_number-1] #開催したコンテストによる満足度上昇
last_day += day_pulse #経過日数の計算
last_day[contest_number -1 ] = 0 #開催したコンテスト種類の経過日数を0に
manzoku -= sum(c*last_day) #開催していないコンテストによる満足度の減少
print(manzoku)
| 1 | 9,845,960,267,946 | null | 114 | 114 |
a, b = map(int, input().split())
sq = a * b
leng = a*2 + b*2
print('{} {}'.format(sq,leng))
|
import numpy as np
from numba import njit
N_ko, K_kai = map(int, input().split())
A_list = list(map(int, input().split()))
A = np.array(A_list, dtype=np.int64)
@njit
def cal_cumsum(A):
Light_length = np.zeros(N_ko, dtype=np.int64)
for i in range(N_ko):
left = max(0, i - A[i])
right = min(N_ko - 1, i + A[i])
Light_length[left] += 1
if (right + 1 < N_ko):
Light_length[right + 1] -= 1
Light_length = np.cumsum(Light_length)
return(Light_length)
for k in range(min(42, K_kai)):
A = cal_cumsum(A)
print(*A)
| 0 | null | 7,812,799,223,940 | 36 | 132 |
a,b,c=map(int, input().split(" "))
if a>c :
k=c
c=a
a=k
if c<b :
k=b
b=c
c=k
if b<a :
k=b
b=a
a=k
a,b,c=map(str,(a,b,c))
print(a+' '+b+' '+c)
|
a,b,c = map (int,input().split())
if b < a :
a , b = b , a
if c < a :
a , c = c , a
if c < b :
b , c = c , b
print(a,b,c)
| 1 | 417,060,849,380 | null | 40 | 40 |
N = int(input())
letters = 'zabcdefghijklmnopqrstuvwxy'
def solve(N):
md = N%26
l = letters[md]
if md==0: md=26
if N>26:
return solve((N-md)//26) + l
else:
return l
print(solve(N))
|
n=int(input())
n-=1
a='abcdefghijklmnopqrstuvwxyz'
a=list(a)
ans=''
for i in range(1,20):
if n<26**i:
for j in range(i):
ans+=a[n%26]
n//=26
break
else:
n-=26**i
print(ans[::-1])
| 1 | 11,966,127,770,080 | null | 121 | 121 |
n = int(input())
l = list(map(int,input().split()))
mod = 10**9+7
ones = [0]*60
ans = 0
for i in range(n):
x = l[i]
for j in range(60):
ones[j] += (x>>j)&1
ans = (ans + (n-1)*x)%mod
# print(ans)
for i in range(60):
ans = (ans - ones[i]*(ones[i]-1)*2**i)%mod
print(ans)
|
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
c=[0]*60
for aa in a:
for i in range(60):
if aa&(1<<i):c[i]+=1
ans=0
for i,cc in enumerate(c):
ans+=cc*(n-cc)*2**i
ans%=mod
print(ans)
| 1 | 122,479,788,515,536 | null | 263 | 263 |
def main():
a, b, c = map(int, input().split())
if a == b == c:
print('No')
elif a != b and b != c and c != a:
print('No')
else:
print('Yes')
if __name__ == '__main__':
main()
|
A, B, C = input().split()
S = A + B + C
ans = 'No'
for i in range(len(S)):
if S.count(S[i]) == 2:
ans = 'Yes'
break
print(ans)
| 1 | 68,245,155,351,620 | null | 216 | 216 |
import sys
def input(): return sys.stdin.readline().rstrip()
class mod_comb3:
def __init__(self,mod=10**9+7,n_max=1):
self.mod,self.n_max=mod,n_max
self.fact,self.inv,self.factinv=[1,1],[0,1],[1,1]
if 1<n_max:setup_table(n_max)
def comb(self,n,r):
if r<0 or n<r:return 0
if self.n_max<n:self.setup_table(n)
return self.fact[n]*(self.factinv[r]*self.factinv[n-r]%self.mod)%self.mod
def setup_table(self,t):
for i in range(self.n_max+1,t+1):
self.fact.append(self.fact[-1]*i%self.mod)
self.inv.append(-self.inv[self.mod%i]*(self.mod//i)%self.mod)
self.factinv.append(self.factinv[-1]*self.inv[-1]%self.mod)
self.n_max=t
def main():
n,k=map(int,input().split())
A=list(map(int,input().split()))
com=mod_comb3()
A.sort()
mod=10**9+7
max_a,min_a=0,0
for i in range(n):
max_a=(max_a+A[i]*com.comb(i,k-1))%mod
min_a=(min_a+A[i]*com.comb(n-i-1,k-1))%mod
print((max_a-min_a)%mod)
if __name__=='__main__':
main()
|
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
mod=10**9+7
ans=0
MOD=10**9+7
factorial = [1]
inverse = [1]
for i in range(1, n+2):
factorial.append(factorial[-1] * i % MOD)
inverse.append(pow(factorial[-1], MOD - 2, MOD))
# 組み合わせ計算
def nCr(n, r):
if n < r or r < 0:
return 0
elif r == 0:
return 1
return factorial[n] * inverse[r] * inverse[n - r] % MOD
for i in range(n-k+1):
ans-=a[i]*nCr(n-i-1,k-1)%mod
ans%=mod
a=a[::-1]
for i in range(n-k+1):
ans+=a[i]*nCr(n-i-1,k-1)%mod
ans%=mod
print(ans%mod)
| 1 | 95,490,465,257,132 | null | 242 | 242 |
X = int(input())
A = 0
f = 1
while f:
a = A ** 5
B = 0
while f:
b = B ** 5
if a <= X:
if a + b == X:
print(str(A)+" "+str(-B))
f = 0
elif a + b > X:
break
if a > X:
if a - b == X:
print(str(A)+" "+str(B))
f = 0
elif a - b < X:
break
B += 1
A += 1
|
import math
from math import gcd
INF = float("inf")
import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque
def main():
x = int(input())
for i in range(-120,120):
for j in range(-120,120):
if i**5 - j ** 5 == x:
print(i, j)
exit()
if __name__=="__main__":
main()
| 1 | 25,755,801,797,138 | null | 156 | 156 |
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right
MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 8)
N, A, B = map(int, input().split())
dis = B - A - 1
if dis % 2 == 0:
print(min((N - max(A, B) + 1) + (N - min(A, B) - (N - max(A, B) + 1)) // 2,
min(A, B) + ((max(A, B) - min(A, B) - 1) // 2)))
else:
print((dis + 1) // 2)
|
r = int(input())
n = (r*r) / 3.14
print(int(n / (1/3.14)))
| 0 | null | 127,525,227,884,740 | 253 | 278 |
N, *X = map(int, open(0).read().split())
ans = float("inf")
for x in range(min(X), max(X) + 1):
cur = 0
for j in range(N):
cur += (X[j] - x) ** 2
ans = min(ans, cur)
print(ans)
|
from collections import deque
def main():
N,M,*AB=map(int,open(0).read().split())
g=[[] for _ in range(N+1)]
for a,b in zip(*[iter(AB)]*2):
g[a].append(b)
g[b].append(a)
q=deque([1])
s=[0]*(N+1)
s[1]=1
while q:
u=q.popleft()
for v in g[u]:
if not s[v]:
s[v] = u
q.append(v)
print("Yes")
print("\n".join(map(str, s[2:])))
if __name__ == "__main__":
main()
| 0 | null | 42,813,034,598,080 | 213 | 145 |
n = int(input())
s = input()
num = n
for i in range(n-1,0,-1):
if s[i]==s[i-1]:
s = s[:i] + s[i+1:]
print(len(s))
|
ans=[]
while True:
try:
k,l=list(map(int,input().split(" ")))
init_k=k
init_l=l
#
while True:
if k%l==0:
gcd=l
tmp_1=init_k/gcd
tmp_2=init_l/gcd
lcm=gcd*tmp_1*tmp_2
break
else:
tmp=k%l
k=l
l=tmp
gcd=int(gcd)
lcm=int(lcm)
ans.append(str(gcd)+" "+str(lcm))
except:
break
for i in ans:
print(i)
| 0 | null | 85,056,557,508,112 | 293 | 5 |
import decimal
def main():
A, B = map(decimal.Decimal,input().split())
if A == 0:
return 0
else:
AB = A*B
return int(AB)
print(main())
|
a, b = input().split()
a = int(a)
if '.' in b:
i, f = b.split('.')
b = int(i) * 100 + int(f)
else:
b = int(b) * 100
ans = a * b // 100
print(ans)
| 1 | 16,512,197,905,884 | null | 135 | 135 |
#a = list(map(int, input().split(' ')))
a = input()
b = input()
if a == b[:-1]:
print('Yes')
else:
print('No')
|
name=input()
len_n=len(name)
name2=input()
len_n2=len(name2)
if name==name2[:-1] and len_n+1==len_n2:
print("Yes")
else:
print("No")
| 1 | 21,469,296,312,740 | null | 147 | 147 |
from collections import deque
def round_robin_scheduling(n, q, A):
sum = 0
while A:
head = A.popleft()
if head[1] <= q:
sum += head[1]
print(head[0], sum)
else:
sum += q
head[1] -= q
A.append(head)
if __name__ == '__main__':
n, q = map(int, input().split())
A = deque()
for i in range(n):
name, time = input().split()
A.append([name, int(time)])
round_robin_scheduling(n, q, A)
|
import sys
#import numpy as np
import copy
fline = input().rstrip().split(' ')
N, Q = int(fline[0]), int(fline[1])
list = []
for i in range(N):
tlist = []
line = input().split(' ')
tlist = [line[0], line[1]]
#print(tlist)
list.append(tlist)
#print(list)
current = 0
while len(list) != 0:
if int(list[0][1]) <= Q:
current += int(list[0][1])
print(list[0][0] + " " + str(current))
del list[0]
else:
list[0][1] = str((int)(list[0][1])-Q)
list.append(list[0])
del list[0]
current += Q
#print(list)
| 1 | 40,581,348,770 | null | 19 | 19 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(read())
lim = int(n ** 0.5)
fact = [1]
for i in range(2, lim + 1):
if (n % i == 0):
fact.append(i)
else:
pass
if (len(fact) == 1):
ans = n - 1
else:
tar = fact[-1]
ans = tar + int(n // tar) - 2
print(ans)
|
#!/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)
| 0 | null | 81,436,948,554,392 | 288 | 63 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import math
import sys
INF = float('inf')
YES = "Yes" # type: str
NO = "No" # type: str
def solve(N: int, M: int, A: "List[int]"):
t = sum(A)/4/M
return [YES, NO][len([a for a in A if a >= t]) < M]
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
print(f'{solve(N, M, A)}')
if __name__ == '__main__':
main()
|
a,b,m = input().split()
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc =[]
for i in range(int(m)):
xyc.append(input())
min = min(a) + min(b)
for i in xyc:
x,y,c = map(int, i.split())
if min > a[x-1] + b[y-1] - c :
min = a[x-1] + b[y-1] - c
print(min)
| 0 | null | 46,301,689,833,772 | 179 | 200 |
from sys import stdin
class Node:
def __init__(self, value: int):
self.value = value
self.previous_node = None
self.next_node = None
class LinkedList():
def __init__(self):
self.first = None
self.last = None
def delete_node(self, node: Node):
if node.next_node != None:
node.next_node.previous_node = node.previous_node
if node.previous_node != None:
node.previous_node.next_node = node.next_node
if node == self.first:
self.first = node.next_node
if node == self.last:
self.last = node.previous_node
def value_generator(self):
node = self.first
while node != None:
yield node.value
node = node.next_node
def insert(self, x: int):
node = Node(x)
node.next_node = self.first
if self.first != None:
self.first.previous_node = node
self.first = node
if self.last == None:
self.last = node
def delete(self, x: int):
target_node = self.first
while target_node != None and target_node.value != x:
target_node = target_node.next_node
if target_node != None:
self.delete_node(target_node)
def main():
linked_list = LinkedList()
insert,delete,delete_node = linked_list.insert,linked_list.delete,linked_list.delete_node
_ = int(stdin.readline())
for line in (line.split() for line in stdin.readlines()):
command = line[0]
if command == "insert":
insert(int(line[1]))
elif command == "delete":
delete(int(line[1]))
elif command == "deleteFirst":
delete_node(linked_list.first)
elif command == "deleteLast":
delete_node(linked_list.last)
print(*linked_list.value_generator())
main()
|
#!/usr/bin/env python3
def main():
import sys
input = sys.stdin.readline
A, B, N = map(int, input().split())
x = min(B - 1, N)
print((A * x) // B - A * (x // B))
if __name__ == '__main__':
main()
| 0 | null | 14,165,917,324,402 | 20 | 161 |
N = int(input())
M = []
for _ in range(N):
s, t = input().split()
M.append((s, int(t)))
X = input()
res = sum(map(lambda m: m[1], M))
for m in M:
res -= m[1]
if X == m[0]:
break
print(res)
|
import math
a, b, c = map(int, input().split())
l = []; d = int(math.sqrt(c)); e = 0
for i in range(1, d + 1):
if i * i == c: l += [i]
elif c % i == 0: l += [i, c // i]
for x in l:
if a <= x <= b: e += 1
print(e)
| 0 | null | 48,797,865,618,112 | 243 | 44 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.