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
|
---|---|---|---|---|---|---|
n=int(input())
f=[0]*45
def Fib(n):
if n==0:
return 1
elif n==1:
return 1
else:
if f[n]!=0:
return f[n]
else:
f[n]=Fib(n-1)+Fib(n-2)
return f[n]
print(Fib(n))
|
memo = {}
def fib(n):
"""
:param n: non-negative integer
:return: n-th fibonacci number
"""
if n == 0 or n == 1:
return 1
try:
return memo[n]
except KeyError:
pass
res = fib(n-1) + fib(n-2)
memo[n] = res
return res
n = int(input())
print(fib(n))
| 1 | 2,030,206,530 | null | 7 | 7 |
x,n = map(int,input().split())
if n == 0:
print(x)
else:
p = list(map(int,input().split()))
k = [i for i in range(-200,201)]
for i in range(n):
if p[i] in set(k):
k.remove(p[i])
minimum = 99999
ans = 0
for i in range(len(k)):
if abs(k[i] - x ) < minimum :
minimum = abs(k[i] - x)
ans = k[i]
print(ans)
|
X, N = map(int, input().split()) #6,5
p = list(map(int, input().split())) #[4,7,10,6,5]
q = [(abs(X-i),i) for i in range(0,102) if not i in p]
q.sort()
print(q[0][1])
| 1 | 14,059,931,948,370 | null | 128 | 128 |
import math
import sys
import collections
import bisect
readline = sys.stdin.readline
def main():
n = int(readline().rstrip())
s = readline().rstrip()
cnt = 0
for i in range(1000):
x = str(i).zfill(3)
a = s[:-1].find(x[0])
if a != -1:
b = s[a + 1: -1].find(x[1])
if b != -1:
c = s[a + b + 2:].find(x[2])
if c != -1:
cnt += 1
print(cnt)
if __name__ == '__main__':
main()
|
import sys
n=int(input())
d=list(map(int,input().split()))
if d[0]!=0:
print(0)
sys.exit(0)
if n==1:
print(1)
sys.exit(0)
for i in range(1,n):
if d[i]==0:
print(0)
sys.exit(0)
dist=[0]*(n)
for i in range(1,n):
dist[d[i]]+=1
if dist[1]==0:
print(0)
sys.exit(0)
ans=1
mod=998244353
bef=dist[1]
total=dist[1]+1
for i in range(2,n):
for j in range(dist[i]):
ans=ans*bef
ans=ans%mod
total+=dist[i]
bef=dist[i]
if total==n:
break
if ans==0:
break
print(ans)
#print(dist)
| 0 | null | 141,698,077,405,686 | 267 | 284 |
from collections import deque
n=int(input())
que=deque()
for i in range(n):
command=input()
if command=="deleteFirst":
que.popleft()
elif command=="deleteLast":
que.pop()
else:
command,num=command.split()
num=int(num)
if command=="insert":
que.appendleft(num)
else:
if num in que:
que.remove(num)
print(*que,sep=" ")
|
from collections import deque
q = deque()
for i in range(int(input())):
command_line = input().split(" ")
command = command_line[0]
arg = ""
if len(command_line) > 1: arg = command_line[1]
if command == "insert":
q.appendleft(arg)
elif command == "delete":
try:
q.remove(arg)
except ValueError:
pass
elif command == "deleteFirst":
q.popleft()
else:
q.pop()
print(" ".join(q))
| 1 | 49,879,733,508 | null | 20 | 20 |
import math
a,b,c,d = map(int,input().split())
def death_time(hp,atack):
if hp%atack == 0:
return hp/atack
else:
return hp//atack + 1
takahashi_death = death_time(a,d)
aoki_death = death_time(c,b)
if aoki_death<=takahashi_death:
print("Yes")
else:
print("No")
|
n = int(input())
ab=[list(map(int,input().split())) for i in range(n)]
import math
from collections import defaultdict
d = defaultdict(int)
zerozero=0
azero=0
bzero=0
for tmp in ab:
a,b=tmp
if a==0 and b==0:
zerozero+=1
continue
if a==0:
azero+=1
continue
if b==0:
bzero+=1
continue
absa=abs(a)
absb=abs(b)
gcd = math.gcd(absa,absb)
absa//=gcd
absb//=gcd
if a*b >0:
d[(absa,absb)]+=1
else:
d[(absa,-absb)]+=1
found = defaultdict(int)
d[(0,1)]=azero
d[(1,0)]=bzero
ans=1
mod=1000000007
for k in list(d.keys()):
num = d[k]
a,b=k
if b>0:
bad_ab = (b,-a)
else:
bad_ab = (-b,a)
if found[k]!=0:
continue
found[bad_ab] = 1
bm=d[bad_ab]
if bm == 0:
mul = pow(2,num,mod)
if k==bad_ab:
mul = num+1
else:
mul = pow(2,num,mod) + pow(2,bm,mod) -1
ans*=mul
ans+=zerozero
ans-=1
print(ans%mod)
| 0 | null | 25,449,069,999,210 | 164 | 146 |
n,m = map(int,input().split())
v1 = [ input().split() for _ in range(n) ]
v2 = [ int(input()) for _ in range(m) ]
l = [sum(map(lambda x,y:int(x)*y,v,v2)) for v in v1 ]
print(*l,sep="\n")
|
A=map(int,raw_input().split(" "))
vec=A[0]
col=A[1]
def zero(n):
zerolist=list()
for i in range(n):
zerolist+=[0]
return(zerolist)
A=list()
for i in range(vec):
A+=[zero(col)]
for i in range(vec):
k=map(int,raw_input().split(" "))
for j in range(col):
A[i][j]=k[j]
#ok
v=zero(col)
for i in range(col):
v[i]=int(raw_input())
k=0
for i in range(vec):
for j in range(col):
k+=A[i][j]*v[j]
print k
k=0
| 1 | 1,138,639,056,128 | null | 56 | 56 |
"""AtCoder."""
n = int(input()[-1])
s = None
if n in (2, 4, 5, 7, 9):
s = 'hon'
elif n in (0, 1, 6, 8):
s = 'pon'
elif n in (3,):
s = 'bon'
print(s)
|
print("pphbhhphph"[int(input())%10]+"on")
| 1 | 19,219,939,235,878 | null | 142 | 142 |
import sys
ff = sys.stdin
while True :
a, b = map(int, ff.readline().split())
if (a == 0) & (b == 0) :
break
if a < b : print(a, b)
else : print(b, a)
|
D,T,S = (int(x) for x in input().split())
if D/S <= T:
print('Yes')
else:
print('No')
| 0 | null | 2,007,851,174,880 | 43 | 81 |
w = input().lower()
c = 0
while True:
t = input()
if t == "END_OF_TEXT":
break
t = t.lower()
t = t.rstrip().split()
c += t.count(w)
print(c)
|
[H, N] = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
a = sum(A)
if H > a:
print('No')
else:
print('Yes')
| 0 | null | 40,035,366,537,332 | 65 | 226 |
def main():
input()
A = list(map(int, input().split()))
cusum = [0] * len(A)
cusum[-1] = A[-1]
if A[0] > 1:
print(-1)
return
for i in range(len(A)-2, -1, -1):
cusum[i] = cusum[i+1] + A[i]
pre_node = 1
ans = 1
for i in range(1, len(A)):
node = (pre_node - A[i-1]) * 2
if node < A[i]:
print(-1)
return
pre_node = min(node, cusum[i])
ans += pre_node
print(ans)
if __name__ == '__main__':
main()
|
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
ln = len(bin(max(a))) -2
cnt = [0] * ln
for x in a:
for shift in range(ln):
cnt[shift] += (x>>shift)%2
# print(cnt)
res = 0
for i in range(ln):
now = cnt[i] * (n-cnt[i])
res += now*pow(2,i)
res %= mod
print(res)
| 0 | null | 70,782,791,733,314 | 141 | 263 |
n = int(input())
mod = 10 ** 9 + 7
dp = [[[0 for _ in range(2)] for _ in range(2)] for _ in range(n)]
dp[0][0][0] = 8
dp[0][0][1] = 1
dp[0][1][0] = 1
dp[0][1][1] = 0
for i in range(n-1):
for j in range(2):
dp[i+1][0][0] = (dp[i][0][0] * 8) % mod
dp[i+1][0][1] = (dp[i][0][0] + dp[i][0][1] * 9) % mod
dp[i+1][1][0] = (dp[i][0][0] + dp[i][1][0] * 9) % mod
dp[i+1][1][1] = (dp[i][0][1] + dp[i][1][0] + dp[i][1][1] * 10) % mod
print((dp[-1][-1][-1]) % mod)
|
K = int(input())
S = input()
s = len(S)
L = []
mod = 10 ** 9 + 7
N = 2 * 10**6
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
def cmb(n, r):
return fac[n] * ( finv[r] * finv[n-r] % mod ) % mod
for i in range(2, N + 1):
fac.append( ( fac[-1] * i ) % mod )
inv.append( mod - ( inv[mod % i] * (mod // i) % mod ) )
finv.append( finv[-1] * inv[-1] % mod )
for i in range(K+1):
L.append( cmb(i+s-1, s-1) * pow(25, i, mod) % mod )
ans = []
for i, x in enumerate(L):
if i == 0:
ans.append(x)
else:
ans.append( ( ans[i-1]*26%mod + x ) % mod )
print(ans[K])
| 0 | null | 7,964,700,576,430 | 78 | 124 |
def main():
N = int(input())
# 桁数を求める
n_digit = 0
idx = 0
while True:
n_digit += 1
n_str = 26 ** n_digit
if idx + 1 <= N <= idx + n_str:
idx += 1
break
else:
idx += n_str
k = N - idx
ans = ''
for i in range(n_digit):
ans += chr(ord('a') + k % 26)
k //= 26
print(ans[::-1])
if __name__ == '__main__':
main()
|
N=int(input())
alpha='abcdefghijklmnopqrstuvwxyz'
ans=''
while 26<N:
s=(N-1)%26
ans=alpha[s]+ans
N=int(N-1)//26
ans=alpha[N-1]+ans
print(ans)
| 1 | 11,877,220,998,370 | null | 121 | 121 |
n = list(map(int, input()))
dp = (0, 1)
for i in n:
dp = (min(dp[0] + i, dp[1] + 10 - i), min(dp[0] + i + 1, dp[1] + 9 - i))
print(dp[0])
|
###綺麗になったよ!!!!!
def y_solver(tmp):
l=len(tmp)
rev=tmp[::-1]+"0"
ans=0
next_bit=0
kuri_cal=0
for i in range(l-1):
num=int(rev[i])+next_bit
next_num=int(rev[i+1])
if (num<5) or (num==5 and next_num<5):
ans+=(kuri_cal+num)
kuri_cal=0
next_bit=0
else:
kuri_cal+=10-num
next_bit=1
last=int(tmp[0])+next_bit
ans+=kuri_cal+min(last,11-last)
return ans
n=input()
ans=y_solver(n)
print(ans)
| 1 | 70,575,104,852,800 | null | 219 | 219 |
S = input()
#print(S.count("R"))
con = S.count("R")
if con == 1:
print(1)
elif con == 3:
print(3)
elif con == 2:
for j in range(3):
if S[j] =="R":
if S[j+1] =="R":
print(2)
break
else:
print(1)
break
elif con == 0:
print(0)
|
import math
def factorization(n):
arr=[]
temp=n
for i in range(2,int(math.sqrt(n))):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp//=i
arr.append([i,cnt])
if temp!=1:
arr.append([temp,1])
if arr==[]:
arr.append([n,1])
return arr
n=int(input())
if n==1:
print(0)
exit()
ans=0
for i in factorization(n):
if i[1]>=3:
cnt=1
while i[1]-cnt>cnt:
ans+=1
i[1]-=cnt
cnt+=1
if i[1]!=0:
ans+=1
else:
ans+=1
print(ans)
| 0 | null | 10,939,539,217,540 | 90 | 136 |
S = list(input())
T = list(input())
diff = len(S)-len(T)
count, best = 0, 0
for i in range(diff+1):
s = S[i:]
#print('s')
#print(s)
count = 0
for j,k in zip(s,T):
if j == k:
count += 1
if count > best:
best = count
print(len(T)-best)
|
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
"""
要素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が属するグループと要素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):
"""
要素xが属するグループのサイズ(要素数)を返す
"""
return -self.parents[self.find(x)]
def same(self, x, y):
"""
要素x, yが同じグループに属するかどうかを返す
"""
return self.find(x) == self.find(y)
def members(self, x):
"""
要素xが属するグループに属する要素をリストで返す
"""
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
"""
すべての根の要素をリストで返す
"""
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
"""
グループの数を返す
"""
return len(self.roots())
def all_group_members(self):
"""
{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
"""
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
N, M = map(int, input().split())
A_B = [list(map(int, input().split())) for i in range(M)]
uf = UnionFind(N)
for i in range(M):
x = A_B[i][0] - 1
y = A_B[i][1] - 1
uf.union(x, y)
ans = 1
for i in range(N):
ans = max(ans, uf.size(i))
print(ans)
return
if __name__ == '__main__':
main()
| 0 | null | 3,804,058,035,362 | 82 | 84 |
a,b=map(int,input().split())
print("safe" if a>b else "unsafe")
|
nums = [int(e) for e in input().split()]
if nums[0] > nums[1]:
print("safe")
else:
print("unsafe")
| 1 | 29,127,247,486,298 | null | 163 | 163 |
A, B = [int(_) for _ in input().split()]
print(A * B)
|
#template
def inputlist(): return [int(j) for j in input().split()]
#template
A,B = inputlist()
print(A*B)
| 1 | 15,906,720,890,780 | null | 133 | 133 |
def main():
a = int(input())
print((a+a**2+a**3))
if __name__ == "__main__":
main()
|
a = int(input())
ans = a*(1+a*(1+a))
print(ans)
| 1 | 10,211,069,116,622 | null | 115 | 115 |
# AOJ ITP1_10_D
import math
def intinput():
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
return a
def main():
n = int(input())
x = intinput()
y = intinput()
sum_1 = 0
sum_2 = 0
sum_3 = 0
MD_INFTY = 0
for i in range(n):
MD_INFTY = max(MD_INFTY, abs(x[i] - y[i]))
sum_1 += abs(x[i] - y[i])
sum_2 += abs(x[i] - y[i]) ** 2
sum_3 += abs(x[i] - y[i]) ** 3
MD_1 = sum_1
MD_2 = math.sqrt(sum_2)
MD_3 = sum_3 ** (1 / 3)
print(MD_1); print(MD_2); print(MD_3); print(float(MD_INFTY))
if __name__ == "__main__":
main()
|
import math
n = input()
x = map(float,raw_input().split(' '))
y = map(float,raw_input().split(' '))
d1,d2,d3,d4 = 0.0,0.0,0.0,0.0
for i in range(0,n):
d1 += abs(x[i]-y[i])
d2 += abs(x[i]-y[i])**2.0
d3 += abs(x[i]-y[i])**3.0
if d4 < abs(x[i]-y[i]):
d4 = abs(x[i]-y[i])
print d1
print math.sqrt(d2)
print d3**(1.0/3)
print d4
| 1 | 213,058,383,240 | null | 32 | 32 |
X = int(input())
prime_under_X = []
for i in range(2, int(X ** 0.5) + 1):
flg = True
for j in range(len(prime_under_X)):
if i % prime_under_X[j] == 0:
flg = False
break
if flg:
prime_under_X.append(i)
while True:
flg = True
for j in range(len(prime_under_X)):
if X % prime_under_X[j] == 0:
flg = False
break
if flg:
print(X)
break
X = X + 1
|
from sys import stdin
import math
N = int(stdin.readline().rstrip())
for i in range(1, 50000):
if math.floor(i * 1.08) == N:
print(i)
exit()
print(":(")
| 0 | null | 115,759,628,324,672 | 250 | 265 |
N=int(input())
L=[]
# xでソート
#でソート
#min, max
for i in range(N):
x,y=map(int, input().split())
L.append([x+y,x-y])
L=sorted(L)
ans=abs(L[0][0]-L[-1][0])
L=sorted(L, key=lambda x: x[1])
ans=max(ans, abs(L[0][1]-L[-1][1]))
print(ans)
|
if __name__ == '__main__':
A = list(map(int,input().split()))
print(A.index(0)+1)
| 0 | null | 8,462,844,855,076 | 80 | 126 |
while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
count = 0
start = n if n < x else x
for a in range(start, 0, -1):
if a >= x:
continue
for b in range(a - 1, 0, -1):
if a + b >= x:
continue
for c in range(b - 1, 0, -1):
if a + b + c == x:
count += 1
print(count)
|
NX = input().split()
n = int(NX[0])
x = int(NX[1])
while n!=0 or x!=0:
out = 0
for ii in range(n-2):
i = ii+1 #i:1~n-2
for jj in range(n-1-i):
j = jj+1+i #j:i+1~i+1+n-2-i=i+1~n-1
for kk in range(n-j):
k = kk+1+j #k:j+1~n-j+j+1 =
if k !=i and k!=j and i+j+k == x:
out = out+1
print(out)
NX = input().split()
n = int(NX[0])
x = int(NX[1])
| 1 | 1,287,954,566,208 | null | 58 | 58 |
n = int(input())
X = []
Y = []
for _ in range(n):
x, y = map(int, input().split())
X.append(x+y)
Y.append(x-y)
a, b, c, d = max(X), min(X), max(Y), min(Y)
print(max(abs(a-b), abs(c-d)))
|
a, b=map(int, input().split())
s=a*b
m=a+a+b+b
print(s, m)
| 0 | null | 1,869,922,710,748 | 80 | 36 |
import collections
N = int(input())
S = []
for i in range(N):
s = input()
S.append(s)
c = collections.Counter(S)
values, counts = zip(*c.most_common())
print(len(values))
|
while True:
try:
a = raw_input()
temp = a.split()
x = int(temp[0]) + int(temp[1])
c = str(x)
print len(c)
except:
break
| 0 | null | 15,258,568,762,358 | 165 | 3 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
N = int(readline())
cnt = 0
ans = -1
for _ in range(N):
x, y = map(int, readline().split())
if x == y:
cnt += 1
ans = max(ans, cnt)
else:
cnt = 0
if ans >=3:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
|
n = int(input())
s = 0
b = False
for _ in range(n):
w = input().split()
if w[0] == w[1]:
s += 1
if s == 3:
b = True
break
else:
s = 0
print('Yes' if b else 'No')
| 1 | 2,509,350,158,942 | null | 72 | 72 |
S, T = input().split()
A, B = input().split()
U = input()
if S==U:
print(int(A)-1,end=" ")
print(int(B))
else:
print(int(A),end=" ")
print(int(B)-1)
|
def main():
s, t = input().split()
a, b = map(int, input().split())
u = input()
if u == s:
a -= 1
else:
b -= 1
print(a, b)
if __name__ == '__main__':
main()
| 1 | 71,642,346,353,462 | null | 220 | 220 |
def fibonacci(n):
a, b = 1, 0
for _ in range(0, n):
a, b = b, a + b
return b
n=int(input())
n+=1
print(fibonacci(n))
|
N=int(input())
c=0;
while N-26**c>=0:
N-=26**c
c+=1
d=[0]*(c-1)
i=0
for i in range(c):
d.insert(c-1,N%26)
N=(N-d[i])//26
i+=1
e=[]
s=''
for i in range(2*c-1):
e.append(chr(97+d[i]))
s+=e[i]
print(s[c-1:2*c-1])
| 0 | null | 5,999,646,764,498 | 7 | 121 |
def resolve():
import math as m
N = int(input())
nn = m.ceil(N / 1.08)
if m.floor(nn * 1.08) == N:
print(nn)
else:
print(":(")
resolve()
|
from math import ceil
def main():
n = int(input())
min_value = n * 100 / 108
max_value = (n + 1) * 100 / 108
candidate = ceil(min_value)
if candidate < max_value:
print(candidate)
else:
print(":(")
if __name__ == "__main__":
main()
| 1 | 125,937,631,072,576 | null | 265 | 265 |
# -*- coding: utf-8 -*-
import math
x = int(input())
def is_prime(n):
if n == 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return True
return False
while is_prime(x):
x += 1
print(x)
|
x = int(input())
def isprime(s):
if s>2 and s%2==0:
return False
else:
flg = True
for i in range(3, s//2+1, 2):
if s%i == 0:
flg = False
break
return flg
for i in range(x, 10**6):
if isprime(i) == True:
print(i)
break
| 1 | 105,777,214,675,412 | null | 250 | 250 |
N=int(input())
A = list(map(int, input().split()))
money=1000
stock=0
if A[0]<A[1]:
stock=int(money/A[0])
money=money-A[0]*stock
for i in range(1,N-1):
if A[i-1]<A[i]:
money=money+A[i]*stock
stock=0
if A[i]<A[i+1]:
stock=int(money/A[i])
money=money-A[i]*stock
money=money+A[N-1]*stock
print(money)
|
# 7
# 100 130 130 130 115 115 150
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
m = 1000
kabu = 0
buy = True
buy_val = 100000
for i in range(len(a)):
if i == len(a)-1:
m += kabu * a[i]
kabu = 0
elif not buy and a[i] > a[i+1]:
m += kabu * a[i]
kabu=0
buy=True
elif buy and a[i] < a[i+1]:
kabu=int(m/a[i])
m -= kabu * a[i]
buy=False
print(m)
| 1 | 7,353,295,690,976 | null | 103 | 103 |
n = int(input())
shou500 = n//500
shou5 = (n-shou500*500)//5
print(shou500*1000+shou5*5)
|
i = int(input())
a = 0
a += (i // 500) * 1000
i = i % 500
a += (i // 5) * 5
print(a)
| 1 | 42,514,790,363,902 | null | 185 | 185 |
H = []
while True:
try:
H.append(input())
except EOFError:
break
H.sort()
print(H[-1])
print(H[-2])
print(H[-3])
|
x=int(input())
print(1 if x%100<=(x//100)*5 else 0)
| 0 | null | 63,836,943,051,572 | 2 | 266 |
def resolve():
A, B = list(map(int, input().split()))
import math
for i in range(1, math.ceil(100/0.08)+1):
if math.floor(i*0.08) == A and math.floor(i*0.1) == B:
print(i)
return
print(-1)
if '__main__' == __name__:
resolve()
|
S = input()
ans = ''.join(set(S))
if len(ans) == 1:
print('No')
else:
print('Yes')
| 0 | null | 55,335,822,805,692 | 203 | 201 |
def inner_prod(v0, v1):
ans = 0
for x0, x1 in zip(v0, v1):
ans += x0 * x1
return ans
def vector_add(v0, v1):
return [x0 + x1 for x0, x1 in zip(v0, v1)]
def vector_mul(vector, scaler):
return [scaler * x for x in vector]
def matrix_mul(matrix, vector):
ans = []
for row in matrix:
ans.append(inner_prod(row, vector))
return ans
def koch(p0, p1, max_depth, depth=0):
from math import sin, cos, pi
if depth == max_depth:
return []
R = [[cos(pi / 3), -sin(pi / 3)], [sin(pi / 3), cos(pi / 3)]]
p2 = vector_add(vector_mul(p0, 2 / 3), vector_mul(p1, 1 / 3))
p3 = vector_add(vector_mul(p0, 1 / 3), vector_mul(p1, 2 / 3))
p4 = vector_add(p2, matrix_mul(R, vector_add(p3, vector_mul(p2, -1))))
return [
koch(p0, p2, max_depth, depth + 1),
p2,
koch(p2, p4, max_depth, depth + 1),
p4,
koch(p4, p3, max_depth, depth + 1),
p3,
koch(p3, p1, max_depth, depth + 1),
]
def dfs_print(array):
if not array:
return
if isinstance(array[0], int) or isinstance(array[0], float):
print(*array)
else:
for child in array:
dfs_print(child)
n = int(input())
result = [[0, 0], koch([0, 0], [100, 0], n), [100, 0]]
dfs_print(result)
|
import math
def Koch(Px, Py, Qx, Qy, n) :
if n == 0 :
return
else :
Ax = (2 * Px + Qx) / 3
Ay = (2 * Py + Qy) / 3
Bx = (Px + 2 * Qx) / 3
By = (Py + 2 * Qy) / 3
Cx = Ax + (Bx - Ax) * math.cos(math.pi/3) - (By - Ay) * math.sin(math.pi/3)
Cy = Ay + (Bx - Ax) * math.sin(math.pi/3) + (By - Ay) * math.cos(math.pi/3)
Koch(Px, Py, Ax, Ay, n-1)
print(Ax, Ay)
Koch(Ax, Ay, Cx, Cy, n-1)
print(Cx, Cy)
Koch(Cx, Cy, Bx, By, n-1)
print(Bx, By)
Koch(Bx, By, Qx, Qy, n-1)
n = int(input())
print(0, 0.00000000)
Koch(0.00000000, 0.00000000, 100.00000000, 0.00000000, n)
print(100.00000000, 0.00000000)
| 1 | 127,333,232,202 | null | 27 | 27 |
while True:
h, w = map(int, raw_input().split())
if h == 0 and w == 0:
break
else:
result = list()
for i in range(h):
result.append(['#' for j in range(w)])
for i in range(1, h - 1):
for j in range(1, w - 1):
result[i][j] = '.'
for i in result:
print("".join(j for j in i))
print("")
|
while 1:
x = list(raw_input())
if int(x[0]) == 0:
break
sum = 0
for n in x:
sum += int(n)
print sum
| 0 | null | 1,214,464,589,540 | 50 | 62 |
def solve():
A,B,C,K = [int(i) for i in input().split()]
ans = 0
ans += min(A, K)
if K-A-B > 0:
ans -= (K-A-B)
print(ans)
if __name__ == "__main__":
solve()
|
import math
x1,y1,x2,y2=map(float,input().split())
a=(x2-x1)**2+(y2-y1)**2
l=math.sqrt(a)
print(f'{l:.8f}')
| 0 | null | 10,989,646,459,428 | 148 | 29 |
# -*- coding: utf-8 -*-
#https://mathtrain.jp/tyohukuc
n, m, k = map(int,input().split())
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 998244353
N = n+1 # N は必要分だけ用意する
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
ans = 0
beki = [1,m-1]
for i in range(2,N+1):
beki.append(((beki[-1]*(m-1)) % p))
for x in range(k+1):
ans += m * beki[n-x-1] %p * cmb(n-1,x,p) %p
ans = ans % p
print(ans)
|
M=998244353
n,m,k=map(int,input().split())
a,c=0,1
for i in range(k+1):
a+=c*m*pow(m-1,n+~i,M)
c=c*(n+~i)*pow(i+1,-1,M)%M
print(a%M)
| 1 | 23,166,122,849,028 | null | 151 | 151 |
def main():
x, k, d = map(int, input().split())
x = abs(x)
if k % 2 == 1:
x = abs(x-d)
k -= 1
if x > d*k:
print(x-d*k)
else:
print(min(x % (2*d), abs(x % (2*d)-2*d)))
main()
|
X,K,D=map(int, input().split())
if 0<abs(X)<K*D:
a=X//D
K-=a
if K%2==0:
ans=X-D*a
else:
ans=X-D*(a+1)
else:
ans=abs(X)-K*D
print(abs(ans))
| 1 | 5,221,387,845,718 | null | 92 | 92 |
A, B, C, D, E = map(int, input().split())
L = (C - A) * 60 + (D - B)
print(L - E)
|
s=input()
n=len(s)+1
mountain=[0,0]
count=[0,0]
sum=0
for i in range(n-1):
if s[i]=="<":
mountain[1]+=1
else:
if mountain[1]>0:
sum+=(mountain[0]*(mountain[0]-1)+mountain[1]*(mountain[1]+1))//2+max([0,mountain[0]-count[1]])
count=mountain
mountain=[1,0]
else:
mountain[0]+=1
sum+=(mountain[0]*(mountain[0]-1)+mountain[1]*(mountain[1]+1))//2+max([0,mountain[0]-count[1]])
print(sum)
| 0 | null | 87,052,424,566,240 | 139 | 285 |
from queue import Queue
k = int(input())
q = Queue()
for i in range(1, 10):
q.put(i)
for i in range(k):
x = q.get()
if x % 10 != 0:
num = 10 * x + (x % 10) - 1
q.put(num)
num = 10 * x + (x % 10)
q.put(num)
if x % 10 != 9:
num = 10 * x + (x % 10) + 1
q.put(num)
print(x)
|
from collections import deque
k = int(input())
ans=[]
# q = deque([[1],[2],[3],[4],[5],[6],[7],[8],[9]])
q = deque([1,2,3,4,5,6,7,8,9])
while q:
a = q.popleft()
ans.append(a)
if len(ans) > k:
break
tmp = int(str(a)[-1])
if tmp-1 >= 0:
q.append(10*a + tmp-1)
q.append(10*a + tmp)
if tmp+1 <= 9:
q.append(10*a + tmp+1)
print(ans[k-1])
| 1 | 39,818,274,770,788 | null | 181 | 181 |
ans = 0
for i in xrange(input()):
n = int(raw_input())
if n <= 1:
continue
j = 2
while j*j <= n:
if n%j == 0:
break
j += 1
else:
ans += 1
print ans
|
c = 0
while True:
try:
n = int(input())
except EOFError:
break
c += 1
for i in range(2, int(n ** 0.5 + 1)):
if n % i == 0:
c -= 1
break
print(c)
| 1 | 10,418,543,020 | null | 12 | 12 |
Suits = ['S', 'H', 'C', 'D']
Taro = []
Missing = []
n = int(input())
for i in range(n):
Taro.append(input())
for j in range(52):
card = Suits[j//13] + ' ' + str(j % 13 + 1)
if card not in Taro:
Missing.append(card)
if Missing != []:
print('\n'.join(Missing))
|
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
from math import gcd
def main(given=sys.stdin.readline):
input = lambda: given().rstrip()
LMIIS = lambda: list(map(int,input().split()))
II = lambda: int(input())
XLMIIS = lambda x: [LMIIS() for _ in range(x)]
YN = lambda c : print('Yes') if c else print('No')
MOD = 10**9+7
A,B = LMIIS()
print(A*B//gcd(A,B))
if __name__ == '__main__':
main()
| 0 | null | 57,127,523,948,220 | 54 | 256 |
n = input()
dict_ = set()
for _ in xrange(n):
cmd, str_ = raw_input().split()
if cmd == "insert":
dict_.add(str_)
elif cmd == "find":
if str_ in dict_:
print "yes"
else:
print "no"
|
string = input()
n = int(input())
for _ in range(n):
query = input().split()
if query[0] == 'replace':
op, a, b, p = query
a, b = int(a), int(b)
string = string[:a] + p + string[b + 1:]
elif query[0] == 'reverse':
op, a, b = query
a, b = int(a), int(b)
string = string[:a] + ''.join(reversed(string[a:b + 1])) + string[b + 1:]
elif query[0] == 'print':
op, a, b = query
a, b = int(a), int(b)
print(string[a: b + 1])
| 0 | null | 1,093,971,832,272 | 23 | 68 |
while True:
a,b = list(map(int, input().split()))
if (a == 0) and (b == 0):
break
elif (a < b):
print(str(a) + " " + str(b))
else :
print(str(b) + " " + str(a))
|
def check(P,k,staffList):
i = 0
for _ in range(k):
staffNum = 0
while(staffNum + staffList[i]<= P):
staffNum += staffList[i]
i += 1
if i == n:
return n
return i
def getMaxP(n,k,staffList):
# Pが増えれば,入れられる個数は単純増加するので,二部探索によりPの最小値を求められる
left = 0
right = 100000*10000
while right-left>1:
mid = (left+right)//2
staffNum = check(mid,k,staffList)
if staffNum >= n :
right = mid
else:
left = mid
return right
if __name__ == "__main__":
n,k = map(int,input().split())
staffList = [int(input()) for _ in range(n)]
# 特定の最大積載量でどれだけ積めるのかを計算する
P = getMaxP(n,k,staffList)
print(P)
| 0 | null | 300,796,494,192 | 43 | 24 |
c=0
for _ in[0]*int(input()):
x=int(input())
if 2 in[x,pow(2,x,x)]:c+=1
print(c)
|
def main():
mod = 10**9+7
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(key=lambda x: -abs(x))
kouho = []
minus = 0
last_plus = None
last_minus = None
if k == 1:
print(max(a))
return
for i in range(k):
kouho.append(a[i])
if a[i] >= 0:
last_plus = a[i]
if a[i] < 0:
minus += 1
last_minus = a[i]
if minus % 2 == 0:
ans = 1
for i in kouho:
ans = ans*i % mod
print(ans)
return
change_plus = None
change_minus = None
if last_plus != None:
# マイナスを追加する
for i in range(k, n):
if a[i] <= 0:
change_plus = a[i]
break
if last_minus != None:
# マイナスを追加する
for i in range(k, n):
if a[i] >= 0:
change_minus = a[i]
break
# print(kouho)
#print(last_plus, change_plus)
#print(last_minus, change_minus)
if change_plus == None and change_minus == None:
ans = 1
for i in range(k):
ans = ans*a[-i-1] % mod
elif change_plus == None:
ans = change_minus
for i in kouho:
ans = ans*i % mod
ans = ans*pow(last_minus, mod-2, mod) % mod
elif change_minus == None:
ans = change_plus
for i in kouho:
ans = ans*i % mod
ans = ans*pow(last_plus, mod-2, mod) % mod
else:
if abs(change_plus*last_minus) < abs(change_minus*last_plus):
ans = change_minus
for i in kouho:
ans = ans*i % mod
ans = ans*pow(last_minus, mod-2, mod) % mod
else:
ans = change_plus
for i in kouho:
ans = ans*i % mod
ans = ans*pow(last_plus, mod-2, mod) % mod
print(ans)
main()
| 0 | null | 4,689,793,557,952 | 12 | 112 |
def resolve():
N, A, B = [int(i) for i in input().split()]
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
print(min(A, N - B + 1) + ((B - A) // 2))
resolve()
|
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)
| 1 | 109,752,722,673,540 | null | 253 | 253 |
import numpy as np
from numba import njit
from numba.types import i8
ni8 = np.int64
MOD = 998244353
@njit((i8[:,::-1], i8[:], i8, i8), cache=True)
def solve(lr, dp, n, k):
acc_dp = np.ones_like(dp)
for i in range(1, n):
val = 0
for j in range(k):
a = i - lr[j, 0]
if a < 0:
continue
b = i - lr[j, 1] - 1
val += acc_dp[a] - (acc_dp[b] if b >= 0 else 0)
dp[i] = val % MOD
acc_dp[i] = (acc_dp[i - 1] + dp[i]) % MOD
return dp[n - 1]
def main():
f = open(0)
n, k = [int(x) for x in f.readline().split()]
lr = np.fromstring(f.read(), ni8, sep=' ').reshape((-1, 2))
dp = np.zeros(n, ni8)
dp[0] = 1
ans = solve(lr, dp, n, k)
print(ans)
main()
|
M=998244353
f=lambda:[*map(int,input().split())]
n,k=f()
lr=[f() for _ in range(k)]
dp=[0]*n
dp[0]=1
S=[0]
for i in range(1,n):
S+=[S[-1]+dp[i-1]]
for l,r in lr:
dp[i]+=S[max(i-l+1,0)]-S[max(i-r,0)]
dp[i]%=M
print(dp[-1])
| 1 | 2,727,581,803,662 | null | 74 | 74 |
S = input()
N = len(S)
ans = [0] * (N+1)
for i in range(N):
if S[i] == '<':
ans[i+1] = ans[i] + 1
for i in range(N-1, -1, -1):
if S[i] == '>' and ans[i] <= ans[i+1]:
ans[i] = ans[i+1]+1
print(sum(ans))
|
def solve():
import collections
N = int(input())
A = [int(i) for i in input().split()]
counter = collections.Counter(A)
combis = {}
total = 0
for k,v in counter.items():
combi = v * (v-1) // 2
combis[k] = combi
total += combi
for i in range(N):
cnt = counter[A[i]]
if cnt > 1:
combi = (cnt-1) * (cnt-2) // 2
else:
combi = 0
print(total - combis[A[i]] + combi)
if __name__ == "__main__":
solve()
| 0 | null | 101,765,329,233,792 | 285 | 192 |
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import defaultdict
def resolve():
N = ir()
A = sorted([[i+1, d] for i, d in enumerate(lr())], key=lambda x: x[1])[::-1]
dp = defaultdict(lambda: -float('inf'))
dp[0, 0] = 0
for x in range(N):
for y in range(N-x):
i, d = A[x+y]
dp[x+1, y] = max(dp[x, y]+d*(i-x-1), dp[x+1, y])
dp[x, y+1] = max(dp[x, y]+d*(N-y-i), dp[x, y+1])
ans = 0
for i in range(N+1):
ans = max(ans, dp[i, N-i])
print(ans)
resolve()
|
N = int(input())
A = list(map(int, input().split()))
if N == 0 and A[0] == 1:
print(1)
exit(0)
elif A[0] > 0:
print(-1)
exit(0)
X = [0] * (N+1)
X[-1] = A[-1]
for i in range(N,0,-1):
X[i-1] = X[i] + A[i-1]
#print(X)
wk = 2
ans = 1
for i in range(1,N+1):
#print(i,X[i])
if 0 <= A[i] <= wk:
ans += min(wk,X[i])
wk -= A[i]
wk *= 2
else:
print(-1)
exit(0)
print(ans)
| 0 | null | 26,428,517,823,498 | 171 | 141 |
H ,W = map(int,input().split())
from collections import deque
S = [input() for i in range(H)]
directions = [[0,1],[1,0],[-1,0],[0,-1]]
counter = 0
#インデックス番号 xが行番号 yが列番号
for x in range(H):
for y in range(W):
if S[x][y]=="#":
continue
que = deque([[x,y]])
memory = [[-1]*W for _ in range(H)]
memory[x][y]=0
while True:
if len(que)==0:
break
h,w = que.popleft()
for i,k in directions:
x_new,y_new = h+i,w+k
if not(0<=x_new<=H-1) or not(0<=y_new<=W-1) :
continue
elif not memory[x_new][y_new]==-1 or S[x_new][y_new]=="#":
continue
memory[x_new][y_new] = memory[h][w]+1
que.append([x_new,y_new])
counter = max(counter,max(max(i) for i in memory))
print(counter)
|
def solve():
N, M = map(int, input().split())
S = input()
ans = []
visited = [False]*(N+1)
visited[-1] = True
now = N
while True:
i = min(M,now)
visited[now-i] = True
while S[now-i]=='1':
i -= 1
if visited[now-i]==True:
return [-1]
visited[now-i] = True
ans.append(i)
if now-i==0:
return ans[::-1]
now -= i
print(*solve())
| 0 | null | 116,751,224,405,180 | 241 | 274 |
import math
H,A=map(int,input().split())
if H<=A:
print(1)
else:
print(math.ceil(H/A))
|
while True:
a, b = map(int, input().split())
if a == 0 and b == 0:
break;
for i in range(0, a):
if i % 2 == 0:
print(("#." * int((b + 1) / 2))[:b])
else:
print((".#" * int((b + 1) / 2))[:b])
print("")
| 0 | null | 38,826,591,901,010 | 225 | 51 |
n = int(input())
a = [int(i)-1 for i in input().split()]
ans = 0
for i in range(n):
if a[i] != (i - ans):
ans += 1
print(ans if ans != n else -1)
|
import math
def main():
n = input()
p1 = [0., 0.]
p2 = [100., 0.]
a = [p1,p2]
a = rec(a,n)
for item in a:
print item[0], item[1]
def rec(a,n):
if n == 0:
return a
else:
n -= 1
b = []
for i in range(len(a)-1):
p1 = a[i]
p2 = a[i+1]
b += koch(p1,p2)
b.append(a[-1])
return rec(b,n)
def koch(p1,p2):
s = [p1[0]+(p2[0]-p1[0])/3., p1[1]+(p2[1]-p1[1])/3.]
t = [p1[0]+2.*(p2[0]-p1[0])/3., p1[1]+2.*(p2[1]-p1[1])/3.]
st = [t[0]-s[0],t[1]-s[1]]
u = [s[0]+(st[0]-math.sqrt(3)*st[1])/2., s[1]+(math.sqrt(3)*st[0]+st[1])/2.]
return [p1,s,u,t]
if __name__ == "__main__":
main()
| 0 | null | 57,266,637,420,860 | 257 | 27 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = []
T = {"mi":0, "pu":0, "zero":0}
for i in range(N):
if A[i] < 0:
T["mi"] += 1
elif A[i] == 0:
T["zero"] += 1
else:
T["pu"] += 1
mod = 10**9+7
for i in range(N):
if A[i] < 0:
B.append([A[i]*(-1), 1])
else:
B.append([A[i], 0])
A.sort()
B.sort(reverse=True)
ans = 1
c = 0
for i in range(K):
ans *= B[i][0]
ans %= mod
c += B[i][1]
if c % 2 == 0:
print(ans)
elif K > T["pu"]+T["mi"]:
print(0)
elif T["mi"] == 1 and K > T["pu"]:
ans = 1
for i in range(N):
ans *= A[i]
ans %= mod
if T["zero"] != 0:
ans = 0
print(ans)
elif T["pu"] == 1 and K > T["mi"]:
ans = 1
for i in range(N):
ans *= A[i]
ans %= mod
if T["zero"] != 0:
ans = 0
print(ans)
elif T["pu"] == 0:
ans = 1
A.reverse()
for i in range(K):
ans *= A[i]
ans %= mod
if T["zero"] != 0:
ans = 0
print(ans)
elif N == K:
ans = 1
for i in range(N):
ans *= A[i]
ans %= mod
print(ans)
else:
change1 = B[K-1][1]
change2 = (change1 + 1)%2
chindex1 = K-1
chindex2 = -1
for i in range(K-1, -1, -1):
if B[i][1] == change2:
chindex2 = i
break
afterindex1 = -1
afterindex2 = -1
for i in range(K, N):
if B[i][1] == change2:
afterindex1 = i
break
for i in range(K, N):
if B[i][1] == change1:
afterindex2 = i
break
result1 = 0
result2 = 0
if chindex1 >= 0 and afterindex1 >= 0:
ans = 1
for i in range(N):
if i <= K-1 or i == afterindex1:
if i != chindex1:
ans *= B[i][0]
ans %= mod
result1 = ans
if chindex2 >= 0 and afterindex2 >= 0:
ans = 1
for i in range(N):
if i <= K-1 or i == afterindex2:
if i != chindex2:
ans *= B[i][0]
ans %= mod
result2 = ans
if result1 == 0 and result2 == 0:
print(0)
elif result1 == 0:
print(result2)
elif result2 == 0:
print(result1)
elif B[afterindex1][0]*B[chindex2][0] - B[afterindex2][0]*B[chindex1][0] > 0:
print(result1)
else:
print(result2)
|
n = int(input())
s = [ i for i in input().split()]
cnt = 0
for i in range(n-1):
minj = i
for j in range(i+1,n):
if int(s[j]) < int(s[minj]):
minj = j
if i != minj:
cnt += 1
s[i],s[minj] = s[minj],s[i]
print(' '.join(s))
print(cnt)
| 0 | null | 4,780,089,053,760 | 112 | 15 |
def main():
x = int(input())
ans=int(x/500)*1000
x-=int(x/500)*500
ans+=int(x/5)*5
print(ans)
main()
|
X = int(input())
A = X // 500
B = X % 500
C = B // 5
ans = A * 1000 + C * 5
print(ans)
| 1 | 42,694,653,557,842 | null | 185 | 185 |
N = int(input())
digits = list(map(int,str(N)))
if sum(digits) % 9 == 0:
print('Yes')
else:
print('No')
|
N = map(int,input().split())
if (sum(N) % 9 == 0 ):
print('Yes')
else:
print('No')
| 1 | 4,424,634,834,880 | null | 87 | 87 |
# coding: UTF-8
import sys
import numpy as np
# f = open("input.txt", "r")
# sys.stdin = f
s = str(input())
t = str(input())
ans = 0
for i, j in zip(s,t):
if i != j:
ans += 1
print(ans)
|
k = int(input())
a, b = map(int, input().split(" "))
ngflag = True
while(a <= b):
if a % k == 0:
print("OK")
ngflag = False
break
a += 1
if ngflag:
print("NG")
| 0 | null | 18,423,410,415,648 | 116 | 158 |
def main():
h,n=map(int,input().split())
dp=[10**9]*(h+1)
dp[h]=0
for i in range(n):
a,b=map(int,input().split())
for j in range(h,0,-1):
nxt=j-a
if nxt<0:
nxt=0
if dp[nxt]>dp[j]+b:
dp[nxt]=dp[j]+b
print(dp[0])
main()
|
n = int(input())
A = list(map(int, input().split()))
x = 1000
for i in range(n-1):
if A[i] < A[i+1]:
q, x = divmod(x, A[i])
x += q*A[i+1]
print(x)
| 0 | null | 44,457,974,438,052 | 229 | 103 |
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n = int(input())
ans = float("inf")
for i in range(1, n+1):
if n%i==0:
ans = min(ans, i+n//i)
if i*i>n:
break
print(ans-2)
|
n = int(input())
ans = float('inf')
for i in range(1, int(n**0.5)+1):
if n%i == 0:
j = n//i
ans = min(ans, i-1+j-1)
print(ans)
| 1 | 161,730,814,022,358 | null | 288 | 288 |
A=list(map(int,input().split()))
B=0
B=A[0]+A[1]+A[2]
if B>=22:
print("bust")
else:
print("win")
|
s="ACL"*int(input())
print(s)
| 0 | null | 60,644,526,235,990 | 260 | 69 |
'''
Created on 2020/08/20
@author: harurun
'''
def main():
import sys
pin=sys.stdin.readline
A,B,M=map(int,pin().split())
a=list(map(int,pin().split()))
b=list(map(int,pin().split()))
ans=min(a)+min(b)
for _ in [0]*M:
x,y,c=map(int,pin().split())
t=a[x-1]+b[y-1]-c
if t<ans:
ans=t
print(ans)
return
main()
|
from sys import stdin
input = lambda: stdin.readline().rstrip()
na, nb, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min_a = min_b = 10**9
for i in range(na):
min_a = min(min_a, a[i])
for i in range(nb):
min_b = min(min_b, b[i])
ans = min_a + min_b
for i in range(m):
x, y, c = map(int, input().split())
x -= 1
y -= 1
ans = min(ans, a[x] + b[y] - c)
print(ans)
| 1 | 54,008,803,625,166 | null | 200 | 200 |
import math
d = int(input())
class point:
def __init__(self, arg_x, arg_y):
self.x = arg_x
self.y = arg_y
p1 = point(0, 0)
p2 = point(100, 0)
def koch(d, p1, p2):
pi = math.pi
cos60 = math.cos(pi/3)
sin60 = math.sin(pi/3)
if d == 0:
return
else:
s = point((2*p1.x + 1*p2.x)/3, (2*p1.y + 1*p2.y)/3)
t = point((1*p1.x + 2*p2.x)/3, (1*p1.y + 2*p2.y)/3)
u = point(s.x + cos60*(t.x-s.x) - sin60*(t.y-s.y), s.y + sin60*(t.x-s.x) + cos60*(t.y-s.y))
koch(d-1, p1, s)
print(s.x, s.y)
koch(d-1, s, u)
print(u.x, u.y)
koch(d-1, u, t)
print(t.x, t.y)
koch(d-1, t, p2)
print(p1.x, p1.y)
koch(d, p1, p2)
print(p2.x, p2.y)
|
primeornot=[True]*(10**5*2)
for i in range(2,10**5):
if primeornot[i]==True:
j=2*i
while j<10**5*2:
primeornot[j]=False
j+=i
x=int(input())
for i in range(x,10**5*2):
if primeornot[i]==True:
print(i)
break
| 0 | null | 53,146,703,009,440 | 27 | 250 |
N, K = map(int, input().split())
if N >= K:
print(min(N - (N // K) * K, ((N + K) // K) * K - N))
else:
print(min(N, K - N))
|
N, K = map(int, input().split(' '))
rst = 0
rst = min(N % K, abs(N % K - K))
print(rst)
| 1 | 39,363,827,714,728 | null | 180 | 180 |
print("YNeos"["".join(input().split("hi"))!=""::2])
|
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque
n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
num_r = s.count('R')
num_g = s.count('G')
num_b = s.count('B')
num_ng = 0
for i in range(n):
for j in range(i+1,n):
k = j+(j-i)
if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
num_ng += 1
print(num_r*num_g*num_b-num_ng)
| 0 | null | 44,663,982,322,048 | 199 | 175 |
S = int(input())
a = (S // 2) + (S % 2)
print(int(a))
|
n = int(input())
ans = [0]*10**5
for i in range(1,int(n**0.5)):
for j in range(1,int(n**0.5)):
for k in range(1,int(n**0.5)):
res = i**2 + j**2 + k**2 +i*j + j*k + k*i
ans[res-1] += 1
for i in range(n):
print(ans[i])
| 0 | null | 33,753,585,136,442 | 206 | 106 |
# 10-Structured_Program_I-Print_a_Frame.py
# ?????¬???????????????
# ??\????????????????????????H cm ?????? W cm ???????????????????????°?????????????????????????????????
# ##########
# #........#
# #........#
# #........#
# #........#
# ##########
# ?????????????????? 6 cm ?????? 10 cm ???????????¨??????????????????
# Input
# ??\???????????°????????????????????????????§???????????????????????????????????????????????????¢????????\????????¨????????§??????
# H W
# H, W ?????¨?????? 0 ?????¨????????\?????????????????¨????????????
# ????????????????????¨??????????????\???????????¶??????3 ??? H, W ??? 100 ??§??????
# Output
# ?????????????????????????????????????????? H cm ?????? W cm ?????????????????????????????????
# ?????????????????????????????????????????????????????\??????????????????
# Constraints
# H, W ??? 300
# Sample Input
# 3 4
# 5 6
# 3 3
# 0 0
# Sample Output
# ####
# #..#
# ####
# ######
# #....#
# #....#
# #....#
# ######
# ###
# #.#
# ###
# a = []
# a = [ *map(int,input().split() ) ]
H=[]
W=[]
while 1:
temp = input().split()
H.append( int(temp[0]) )
W.append( int(temp[1]) )
if H[-1]==0 and W[-1]==0:
break;
for i in range( len(H) ):
for j in range( H[i] ):
#???????¨???°????§?
if j==0 or j==H[i]-1: #?????????????????????????????????
for k in range( W[i] ):
print("#",end="")
else:
print("#",end="")
for k in range(W[i]-2):
print(".",end="")
print("#",end="")
print("")
#???????¨???°?????????
if i !=len(H)-1:
print("")
|
def my_pow(base, n, mod):
if n == 0:
return 1
x = base
y = 1
while n > 1:
if n % 2 == 0:
x *= x
n //= 2
else:
y *= x
n -= 1
x %= mod
y %= mod
return x * y % mod
N = int(input())
D = list(map(int, input().split()))
dmax = max(D)
MOD = 998244353
cnt = [0] * (10 ** 5 + 1)
for d in D:
cnt[d] += 1
if D[0] or cnt[0] != 1:
print(0)
exit()
ans = cnt[0]
for i in range(1, dmax + 1):
now = my_pow(cnt[i - 1], cnt[i], MOD)
ans *= now
ans %= MOD
print(ans)
| 0 | null | 78,155,004,912,192 | 50 | 284 |
n, p = map(int, input().split())
s = [int(i) for i in input()]
p_cnt = 0
if p == 2 or p == 5:
for i in range(n):
if s[i] % p == 0:
p_cnt += i+1
else:
s = s[::-1]
div_dic = dict(zip(range(p), [0] * p))
tmp = 0
for i in range(n):
tmp += s[i] * pow(10, i, p)
tmp %= p
div_dic[tmp] += 1
for v in div_dic.values():
p_cnt += v * (v - 1)
p_cnt //= 2
p_cnt += div_dic.get(0)
print(p_cnt)
|
n = int(input())
S = list(map(int, input().split()))
count = 0
def merge(A, left, mid, right):
global count
n1 = mid - left
n2 = right - mid
L = A[left: left + n1]
R = A[mid: mid + n2]
L.append(float('inf'))
R.append(float('inf'))
i = j = 0
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
count += 1
def merge_sort(A, left, right):
if (left + 1) < right:
mid = (left + right) // 2
merge_sort(A, left, mid)
merge_sort(A, mid, right)
merge(A, left, mid, right)
merge_sort(S, 0, n)
print(*S)
print(count)
| 0 | null | 28,995,100,405,540 | 205 | 26 |
n, d, a = map(int, input().split())
xh = []
for _ in range(n):
x, h = map(int, input().split())
xh.append((x, h))
xh.sort(key=lambda x:x[0])
def bisect(x):
ok = n
ng = -1
while abs(ok-ng)>1:
mid = (ok+ng)//2
if xh[mid][0]>x:
ok = mid
else:
ng = mid
return ok
out = [0]*(n+1)
ans = 0
accu = 0
for ind, (x, h) in enumerate(xh):
accu -= out[ind]
h -= accu
if h<=0:
continue
ans += (h+a-1)//a
accu += ((h+a-1)//a)*a
out[bisect(x+2*d)] += ((h+a-1)//a)*a
print(ans)
|
import sys
from bisect import bisect_left
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, D, A, *XH = map(int, read().split())
monster = [0] * N
for i, (x, h) in enumerate(zip(*[iter(XH)] * 2)):
monster[i] = (x, (h + A - 1) // A)
monster.sort()
pos = []
damage = []
idx = 0
cur_damage = 0
for x, h in monster:
while idx < len(pos) and pos[idx] < x:
cur_damage -= damage[idx]
idx += 1
if h > cur_damage:
pos.append(x + 2 * D)
damage.append(h - cur_damage)
cur_damage += h - cur_damage
print(sum(damage))
return
if __name__ == '__main__':
main()
| 1 | 82,159,469,732,958 | null | 230 | 230 |
#coding: utf-8
#ALDS1_1A
import sys
n=int(raw_input())
a=map(int,raw_input().split())
for i in xrange(n):
print a[i],
print
for i in xrange(1,n):
v=a[i]
j=i-1
while j>=0 and a[j]>v:
a[j+1]=a[j]
j-=1
a[j+1]=v
for k in xrange(n):
print a[k],
print
|
while True:
H, W = map(int, raw_input().split())
if H == W == 0:
break
for i in range(H):
if i == 0 or i == H -1:
print "#" * W
else:
print "#" + "."*(W-2) + "#"
print
| 0 | null | 410,136,907,940 | 10 | 50 |
n = int(input().strip())
a = list(map(int, input().split()))
cnt = [0 for i in range(10**5)]
a = sorted(a)
s = sum(a)
for i in range(n):
cnt[a[i]-1] += 1
q = int(input().strip())
for i in range(q):
b, c = map(int, input().split())
s += c * cnt[b - 1] - b * cnt[b - 1]
cnt[c - 1] += cnt[b - 1]
cnt[b - 1] = 0
print(s)
|
n = int(input())
arr = list(map(int, input().split()))
s = sum(arr)
d = dict()
for i in arr:
if (i not in d):
d[i] = 1
else:
d[i] += 1
q = int(input())
for i in range(q):
b, c = map(int, input().split())
if (b in d):
s -= b * d[b]
s += c * d[b]
if (c not in d):
d[c] = d[b]
else:
d[c] += d[b]
d.pop(b)
print(s)
| 1 | 12,192,791,472,088 | null | 122 | 122 |
N = int(input())
if N % 2 == 1:
print(0)
else:
cnt = 0
for i in range(0,30):
tmp = 10*(5**i)
a = N // tmp
cnt += a
print(cnt)
|
NNN = list(map(int,input().split()))
print('Yes'if NNN[1]*NNN[2]>=NNN[0] else 'No')
| 0 | null | 59,509,035,451,108 | 258 | 81 |
import sys
i=1
for line in sys.stdin:
a=int(line)
if a == 0:
break
else:
print 'Case {0}: {1}'.format(i, a)
i+=1
|
if __name__ == '__main__':
current_no = 1
while True:
input_num = int(input())
if input_num != 0:
print('Case {0}: {1}'.format(current_no, input_num))
current_no += 1
else:
break
| 1 | 484,237,530,352 | null | 42 | 42 |
import numpy as np
A,B,N = map(int,input().split())
if B <= N:
x = B-1
print(int(np.floor(A*x/B)))
else:
print(int(np.floor(A*N/B)))
|
import math
A, B, N = map(int, input().split())
x = 0
if N < B:
x = N
else:
x = B - 1
print(math.floor(A * x / B) - A * math.floor(x / B))
| 1 | 28,278,280,000,444 | null | 161 | 161 |
n,k = map(int,input().split())
l = list(map(int,input().split()))
l.sort()
x,y=0,10**9
while y>x+1:
m = (x+y)//2
c=0
for i in l:
c+=(i-1)//m
if c<=k:
y=m
else:
x=m
print(y)
|
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
def f(length, ls):
cur = 0
for a in ls:
if a%length == 0:
cur += a//length - 1
else:
cur += a//length
if cur <= K:
return True
else:
return False
ok, ng = max(A), 0
while abs(ok - ng) > 1:
z = (ok+ng)//2
if f(z, A) == True:
ok = z
else:
ng = z
print(ok)
| 1 | 6,542,250,167,222 | null | 99 | 99 |
import math
def isPrime(number):
for i in range(2,math.floor(math.sqrt(number))+1):
if number%(i)==0:
return False
return True
N=int(input())
numbers=[]
for i in range(N):
numbers.append(int(input()))
pass
count=0
for number in numbers:
if isPrime(number):
count+=1
print(count)
|
N=int(raw_input())
s=[int(raw_input()) for x in range(N)]
def is_prime(n):
i = 2
while i * i <=n:
if n % i == 0:
return False
i += 1
return True
a=filter(is_prime,s)
print len(a)
| 1 | 9,949,304,560 | null | 12 | 12 |
N = int(input())
for x in range(N+1):
if int(x*1.08) == N:
print(x)
break
else:
print(':(')
|
n=int(input())
for i in range(46298):
if int(i*1.08)==n:
print(i)
break
else:
print(":(")
| 1 | 125,217,219,601,440 | null | 265 | 265 |
import sys
import math
from collections import defaultdict
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 main():
N, X, M = NMI()
A = []
A_ID = {}
break_flag = False
start = 0
end = N
for i in range(M):
if i == 0:
A.append(X)
A_ID[X] = 0
else:
x = A[-1]**2 % M
if x not in A_ID:
A.append(x)
A_ID[x] = i
else:
A.append(x)
start = A_ID[x]
end = i
break_flag = True
if break_flag:
break
if N < start+1:
print(sum(A[:N]))
exit()
ans = sum(A[:start])
lp = sum(A[start:end])
gap = end - start
lp_n = (N - start) // gap
rem = (N - start) % gap
ans += lp * lp_n + sum(A[start: start + rem])
print(ans)
if __name__ == "__main__":
main()
|
data = int(input())
if data>=30:
print("Yes")
else:
print("No")
| 0 | null | 4,298,150,652,430 | 75 | 95 |
def main():
A,B,M=map(int,input().split())
a=[int(_) for _ in input().split()]
b=[int(_) for _ in input().split()]
ans=min(a)+min(b)
for m in range(M):
x,y,c=map(int,input().split())
ans=min(ans,a[x-1]+b[y-1]-c)
print(ans)
main()
|
print(2**(len(bin(int(input())))-2)-1)
| 0 | null | 66,767,763,358,126 | 200 | 228 |
N = int(input())
array = [0]*N
for i in range(N):
if (i+1) % 3 == 0 or (i+1) % 5 == 0:
continue
else:
array[i] = i+1
print( sum(array) )
|
N = int(input())
count = 0
for i in range(1,N+1):
if (i % 3 == 0) or (i % 5 == 0):
pass
else:
count += i
print(count)
| 1 | 34,731,861,253,440 | null | 173 | 173 |
N=input()
N=list(N)
N=map(lambda x: int(x),N)
if sum(N)%9==0:
print("Yes")
else:
print("No")
|
sentence = input().lower()
ans = input().lower()
doublesentence = sentence + sentence
print("Yes" if ans in doublesentence else "No")
| 0 | null | 3,047,986,722,390 | 87 | 64 |
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx): return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
toret = {}
for tup in temp:
toret[tup[0]] = tup[1]
return toret
def sortDictWithKey(passedDic):
return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
x,y,a,b,c = MAP()
p = LIST()
q = LIST()
r = LIST()
p = sorted(p)[::-1]
q = sorted(q)[::-1]
r = sorted(r)[::-1]
p = p[:x]
q = q[:y]
new = p+q+r
# print(new)
new = sorted(new)[::-1]
print(sum(new[:x+y]))
|
x, y, a, b, c = map(int, input().split())
red = list(map(int, input().split()))
green = list(map(int, input().split()))
colorless = list(map(int, input().split()))
red.sort(reverse = True)
green.sort(reverse = True)
colorless.sort(reverse = True)
ret = red[:x] + green[:y]
ret.sort()
for i in range(len(colorless)):
if ret[i] < colorless[i]:
ret[i] = colorless[i]
else:
break
print(sum(ret))
| 1 | 44,508,870,281,472 | null | 188 | 188 |
N = int(input())
S = list(input())
R = []
G = []
for i in range(N):
if S[i] == "R":
R.append(i)
elif S[i] == "G":
G.append(i)
r = len(R)
g = len(G)
ans = r * g * (N - r - g)
for i in R:
for j in G:
a = 2 * i - j
b = 2 * j - i
c = i + j
if 0 <= a < N and S[a] == "B":
ans -= 1
if 0 <= b < N and S[b] == "B":
ans -= 1
if c % 2 == 0 and S[c//2] == "B":
ans -= 1
print(ans)
|
N = int(input())
S = input()
total = S.count('R') * S.count('G') * S.count('B')
cnt = 0
for i in range(N):
for j in range(i+1,N):
k = 2 * j - i
if k >= N:
break
if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
cnt += 1
print(total-cnt)
| 1 | 35,975,744,766,130 | null | 175 | 175 |
S = input()
N = int(input())
for i in range(N):
operate = input().split()
if operate[0] == "replace":
n = int(operate[1])
m = int(operate[2])+1
left_str = S[:n]
right_str = S[m:]
center_str = operate[3]
S = left_str + center_str + right_str
elif operate[0] == "reverse":
n = int(operate[1])
m = int(operate[2])+1
left_str = S[:n]
center_str = S[n:m]
right_str = S[m:]
center_str = center_str[::-1]
S = left_str + center_str + right_str
elif operate[0] == "print":
n = int(operate[1])
m = int(operate[2])+1
left_str = S[:n]
center_str = S[n:m]
right_str = S[m:]
print(center_str)
|
import os, sys, re, math
A = [int(n) for n in input().split()]
print('win' if sum(A) <= 21 else 'bust')
| 0 | null | 60,216,434,996,890 | 68 | 260 |
N,M=map(int, input().split())
if N in [0,1]:n=0
else:
n=N*(N-1)/2
if M in [0,1]:m=0
else:
m=M*(M-1)/2
print(int(n+m))
|
n = int(input())
c0 = 0
c1 = 0
c2 = 0
c3 = 0
for _ in range(n):
s = input()
if s == 'AC':
c0 += 1
elif s == 'WA':
c1 += 1
elif s == 'TLE':
c2 += 1
elif s == 'RE':
c3 += 1
print('AC x', c0)
print('WA x', c1)
print('TLE x', c2)
print('RE x', c3)
| 0 | null | 27,283,792,118,880 | 189 | 109 |
import sys
import numpy as np
n, k = map(int,input().split())
a = np.array(sorted(list(map(int, input().split()))))
f = np.array(sorted(list(map(int, input().split())), reverse=True))
asum = a.sum()
l,r = 0, 10**13
while l != r:
mid = (l+r)//2
can = (asum - np.minimum(mid//f, a).sum()) <= k
if can:
r = mid
else:
l = mid +1
print(l)
|
n = int(input())
s = input()
if len(s) % 2 == 1:
print('No')
else:
mid = len(s)//2
if s[:mid] == s[mid:]:
print('Yes')
else:
print('No')
| 0 | null | 156,092,431,775,368 | 290 | 279 |
floor = [
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
]
s = '####################'
n = int(input())
for c in range(n):
(b,f,r,v) = [int(x) for x in input().split()]
if 1 > b > 5 and 1 > f > 4 and 1 > r > 10:
break
floor[b-1][f-1][r-1] += v
for z in range(4):
for i in range(len(floor[z])):
for v in floor[z][i]:
print(end=' ')
print(v, end='')
print()
if not z == 3:
print(s)
|
n = int(input())
buffer = []
i = 0
while i<n:
b,f,r,v = map(int,input().split())
buffer.append([b,f,r,v])
i = i + 1
room = []
for h in range(15):
if h == 3 or h == 7 or h == 11:
room.append(['**']*10)
else:
room.append([0]*10)
for y in range(n):
if buffer[y][0] == 1:
room[buffer[y][1]-1][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1][buffer[y][2]-1]
elif buffer[y][0] == 2:
room[buffer[y][1]-1+4][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1+4][buffer[y][2]-1]
elif buffer[y][0] == 3:
room[buffer[y][1]-1+8][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1+8][buffer[y][2]-1]
elif buffer[y][0] == 4:
room[buffer[y][1]-1+12][buffer[y][2]-1] = buffer[y][3] + room[buffer[y][1]-1+12][buffer[y][2]-1]
for x in range(15):
if x == 3 or x == 7 or x == 11:
print("####################")
else:
for y in range(10):
print(" "+str(room[x][y]), end = "")
print()
| 1 | 1,113,531,175,466 | null | 55 | 55 |
n=int(input())
m=[];M=[]
for i in range(n):
a,s=map(int,input().split())
m.append(a);M.append(s)
m.sort();M.sort()
if n%2:
print(M[n//2]-m[n//2]+1)
else:
print(M[n//2]+M[n//2-1]-m[n//2]-m[n//2-1]+1)
|
print(int(input())*3.1415*2)
| 0 | null | 24,451,138,501,310 | 137 | 167 |
# -*- coding: utf-8 -*-
def get_input() -> tuple:
"""
標準入力を取得する.
Returns:\n
tuple: 標準入力
"""
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
return N, K, A
def main(N: int, K: int, A: list) -> None:
"""
メイン処理.
Args:\n
N (int): 学期数(2 <= N <= 200000)
K (int): 直近何回分までの点数を考慮するか(1 <= K <= N - 1)
A (list): i学期の期末テストの点数
"""
# 求解処理
for i in range(K, N):
if A[i] > A[i - K]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
# 標準入力を取得
N, K, A = get_input()
# メイン処理
main(N, K, A)
|
n = int(input())
s = input()
A = list(map(int,s.split()))
flag = 1
cnt = 0
while(flag == 1):
flag = 0
for j in range(n-1,0,-1):
if A[j] < A[j-1]:
tmp = A[j]
A[j] = A[j-1]
A[j-1] = tmp
flag = 1
cnt += 1
for k in range(0,len(A)-1):
print(A[k],end=" ")
print(A[len(A)-1])
print (cnt)
| 0 | null | 3,514,995,066,518 | 102 | 14 |
N,K=map(int,input().split())
H=[int(h) for h in input().split()]
H=sorted(H)
cnt=0
for i in range(1,len(H)+1):
if H[-i]>=K:
cnt+=1
else:
print(cnt)
exit()
print(cnt)
|
import sys
N,K = map(int,input().split())
array_hight = list(map(int,input().split()))
if not ( 1 <= N <= 10**5 and 1 <= K <= 500 ): sys.exit()
count = 0
for I in array_hight:
if not ( 1 <= I <= 500): sys.exit()
if I >= K:
count += 1
print(count)
| 1 | 178,791,797,619,318 | null | 298 | 298 |
while 1:
x=raw_input()
if x=='0':break
sum=0
for i in x:
sum+=int(i)
print sum
|
while True:
s = input()
if s == '0':break
print(sum(int(c) for c in s))
| 1 | 1,553,066,467,486 | null | 62 | 62 |
import itertools
n, k = map(int, input().split())
lis = list(map(int,input().split()))
exlis = []
for i in lis:
a = (1+i)/2
exlis.append(a)
nlis = list(itertools.accumulate(exlis))
ans = nlis[k-1]
for j in range(n-k):
tmp = nlis[j+k] - nlis[j]
ans = max(ans, tmp)
print(ans)
|
N, K = map(int, input().split())
P = list(map(int, input().split()))
pos = 0
n = m = sum(P[0:K])
for i in range(1,N):
if i+K > N:
break
n = n - P[i-1] + P[K-1+i]
if n > m:
pos = i
m = n
print((sum(P[pos:pos+K]) + K) / 2)
| 1 | 75,015,816,715,392 | null | 223 | 223 |
N,T = list(map(int,input().split()))
A =[list(map(int,input().split())) for i in range(N)]
A.sort(key = lambda x:x[0])
INF = float("inf")
DP = [[-INF]*(T+3001) for i in range(N+1)]
DP[0][0] = 0
for i in range(N):
for j in range(T):
DP[i+1][j] = max(DP[i+1][j],DP[i][j])
DP[i+1][j+A[i][0]] = max(DP[i+1][j+A[i][0]],DP[i][j+A[i][0]],DP[i][j]+A[i][1])
score = 0
for i in range(N):
for j in range(T+A[i][0]):
score = DP[i+1][j] if DP[i+1][j]>score else score
print(score)
|
#145_E
n, t = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
#dp1[i][j] ... 1~iでj分以内の最大値
#dp2[i][j] ... i~nでj分以内の最大値
dp1 = [[0 for _ in range(t)] for _ in range(n+1)]
dp2 = [[0 for _ in range(t)] for _ in range(n+2)]
for i in range(1, n+1):
a, b = ab[i-1]
for j in range(1, t):
if j - a >= 0:
dp1[i][j] = max(dp1[i-1][j], dp1[i-1][j-a] + b)
else:
dp1[i][j] = dp1[i-1][j]
for i in range(n, 0, -1):
a, b = ab[i-1]
for j in range(1, t):
if j - a >= 0:
dp2[i][j] = max(dp2[i+1][j], dp2[i+1][j-a] + b)
else:
dp2[i][j] = dp2[i+1][j]
ans = 0
for i in range(1, n+1):
b = ab[i-1][1]
for j in range(0, t):
x = dp1[i-1][j] + dp2[i+1][t-j-1] + b
ans = max(ans, x)
print(ans)
| 1 | 151,459,879,149,152 | null | 282 | 282 |
#!/usr/bin/env python3
import sys
from itertools import chain
# import numpy as np
# from itertools import combinations as comb
# from bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
MOD = 1000000007 # type: int
OFFSET = 10 ** 100
def k_in_n(k, n):
"""0〜n までの数からちょうど k 個の数を選ぶ時の最大最小"""
minimum = (k * (k - 1)) // 2
maximum = (k * (2 * n - k + 1)) // 2
return (minimum, maximum)
def solve(N: int, K: int):
keep = None # まだ加算されていない範囲
answer = 0
for k in range(K, N + 2):
if keep is None:
keep = k_in_n(k, N)
else:
minmax = k_in_n(k, N)
if minmax[0] + OFFSET <= keep[1]:
keep[0] -= OFFSET
keep[1] = minimum[1]
else:
answer = (answer + keep[1] - keep[0] + 1) % MOD
keep = minmax
if keep is not None:
answer = (answer + keep[1] - keep[0] + 1) % MOD
return answer
def main():
tokens = chain(*(line.split() for line in sys.stdin))
# N, K = map(int, input().split())
# N, K = input().strip()
# N, K = int(input())
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
answer = solve(N, K)
print(answer)
if __name__ == "__main__":
main()
|
from sys import stdin
import math
from functools import reduce
k,n = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
l = 0
for i in range(n-1):
l = max([l, a[i+1] - a[i]])
l = max([l, a[0]+k-a[n-1]])
print(k-l)
| 0 | null | 38,222,921,303,220 | 170 | 186 |
#155_B
n = int(input())
a = list(map(int, input().split()))
judge = True
for i in range(n):
if a[i]%2 == 0:
if a[i]%3 != 0 and a[i]%5 != 0:
judge = False
break
if judge:
print('APPROVED')
else:
print('DENIED')
|
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")
| 1 | 69,358,953,388,868 | null | 217 | 217 |
l = []
while True:
i = str(input())
if i == '0':
break
else:
l.append(i)
t = 0
for i in l:
t += 1
print('Case '+str(t)+': '+i)
|
case_index = 0
while True:
case_index += 1
n = int(raw_input())
if 0 == n:
break
print 'Case %d: %d'%(case_index, n)
| 1 | 475,045,732,612 | null | 42 | 42 |
x,y=map(int,input().split())
print(str(min(x,y))*max(x,y))
|
# 初期入力
from copy import copy
K = int(input())
#
lunlun_start =["1","2","3","4","5","6","7","8","9"]
lunlun_roop =copy(lunlun_start)
lunlun =[]
ans =copy(lunlun_start)
x=""
while len(ans) <K:
#for i in range(1,10):
lunlun =[]
for i in lunlun_roop:
if i[-1] =="0":
lunlun.append(i+"0")
lunlun.append(i+"1")
elif i[-1] =="9":
lunlun.append(i+"8")
lunlun.append(i+"9")
else:
x =int(i+i[-1])-1
lunlun.append((str(x) ))
x +=1
lunlun.append((str(x) ))
x +=1
lunlun.append((str(x) ))
if len(lunlun) >K:
break
lunlun_roop =copy(lunlun)
ans.extend(lunlun)
print(ans[K-1])
| 0 | null | 62,088,393,041,438 | 232 | 181 |
def abc154d_dice_in_line():
n, k = map(int, input().split())
p = list(map(lambda x: (int(x)+1)*(int(x)/2)/int(x), input().split()))
ans = sum(p[0:k])
val = ans
for i in range(k, len(p)):
val = val - p[i-k] + p[i]
ans = max(ans, val)
print(ans)
abc154d_dice_in_line()
|
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
n=int(input())
A=list(map(int, input().split()))
ans = 0
mod = 10**9 + 7
for i in range(60):
q = sum(map(lambda x:((x >> i) & 0b1),A))
ans += q*(n-q)*pow(2, i, mod)
ans = ans % mod
print(ans)
if __name__=='__main__':
main()
| 0 | null | 98,824,143,484,926 | 223 | 263 |
n = input()
s, t = map(str, input().split())
for i in range(int(n)): print(s[i]+t[i], end = '')
|
H=int(input())
if H==1:
print(1)
else:
i=1
count=1
while H//2!=1:
i*=2
count+=i
H=H//2
i*=2
count+=i
print(count)
| 0 | null | 96,176,501,914,262 | 255 | 228 |
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
n,k = LI()
r,s,p = LI()
t = list(S())
ans = 0
for i in t[:k]:
if i=="r":
ans += p
elif i == "s":
ans += r
elif i == "p":
ans += s
for i in range(k,n):
if t[i]=="r":
if t[i-k]=="r":
t[i] = ""
else:
ans += p
elif t[i]=="s":
if t[i-k]=="s":
t[i] = ""
else:
ans += r
elif t[i]=="p":
if t[i-k]=="p":
t[i] = ""
else:
ans += s
print(ans)
main()
|
mod = 1000000007
n = int(input())
ans = pow(10, n, mod) - 2*pow(9, n, mod) + pow(8, n, mod)
print(ans % mod)
| 0 | null | 55,303,615,264,128 | 251 | 78 |
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import time
import math
def gcd(a,b):
if(a%b==0):return(b)
return (gcd(b,a%b))
N=int(input())
A=list(map(int,input().split()))
A=[[A[i],i] for i in range(N)]
A.sort(reverse=True)
dp=[[0 for i in range(N+1)] for _ in range(N+1)]
for n in range(N):
a,p=A[n]
for x in range(1,n+2):
y=n+1-x
dp[x][y]=max(dp[x][y],dp[x-1][y]+round(abs(x-1 - p))*a)
for y in range(1,n+2):
x=n+1-y
dp[x][y]=max(dp[x][y],dp[x][y-1]+round(abs(N-y - p))*a)
#print(dp)
print(max([dp[x][y] for x in range(N+1) for y in range(N+1) if x+y==N]))
|
def count(s1,s2):
cnt = 0
for i in range(len(s2)):
if s1[i] != s2[i]:
cnt += 1
return cnt
S1 = input()
S2 = input()
mmin = len(S2)
for i in range(len(S1)-len(S2)+1):
k = count(S1[i:len(S2)+i],S2)
if k < mmin:
mmin = k
print(mmin)
| 0 | null | 18,695,148,328,900 | 171 | 82 |
MOD = 10**9 + 7
def modpow(a: int, p: int, mod: int) -> int:
# return a**p (mod MOD) O(log p)
res = 1
while p > 0:
if p & 1 > 0:
res = res * a % mod
a = a**2 % mod
p >>= 1
return res
def comb(N, x):
numerator = 1
for i in range(N-x+1, N+1):
numerator = numerator * i % MOD
denominator = 1
for j in range(1, x+1):
denominator = denominator * j % MOD
d = modpow(denominator, MOD-2, MOD)
return numerator * d
n,a,b=map(int,input().split())
ans = (modpow(2,n,MOD)-1 - comb(n,a) - comb(n,b)) % MOD
print(ans)
|
M = 10**9 + 7
n,a,b = map(int, input().split())
def modinv(n):
return pow(n, M-2, M)
def comb(n, r):
num = denom = 1
for i in range(1,r+1):
num = (num*(n+1-i))%M
denom = (denom*i)%M
return num * modinv(denom) % M
print((pow(2, n, M) - comb(n, a) - comb(n, b) - 1) % M)
| 1 | 65,834,453,278,528 | null | 214 | 214 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.