code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
def main():
n = int(input())
A = []
B = []
for _ in range(n):
a, b = map(int, input().split())
A += [a]
B += [b]
A.sort()
B.sort()
if n % 2 == 0:
mid_pos = n // 2
mid_A = A[mid_pos - 1] + A[mid_pos]
mid_B = B[mid_pos - 1] + B[mid_pos]
cnt = mid_B - mid_A + 1
else:
mid_pos = (n + 1) // 2 - 1
mid_A = A[mid_pos]
mid_B = B[mid_pos]
cnt = mid_B - mid_A + 1
print(cnt)
if __name__ == "__main__":
main()
| a,b=map(int, input().split())
if 1<=a*b and a*b<=81 and a<10 and b<10:
print(a*b)
else:
print(-1)
| 0 | null | 87,481,195,630,400 | 137 | 286 |
def s_in():
return input()
def n_in():
return int(input())
def l_in():
return list(map(int, input().split()))
class Interval():
def __init__(self, li):
self.li = li
self.n = len(li)
self.sum_li = [li[0]]
for i in range(1, self.n):
self.sum_li.append(self.sum_li[i-1] + li[i])
def sum(self, a, b=None):
if b is None:
return self.sum(0, a)
res = self.sum_li[min(self.n-1, b-1)]
if a > 0:
res -= self.sum_li[a-1]
return res
N = s_in()[::-1]
n = len(N)
dp1 = [0 for _ in range(n)]
dp1[0] = int(N[0])
# dp1[i] は i桁目を同じ値だけ使ったとしたときの最小値
dp2 = [0 for _ in range(n)]
dp2[0] = 10 - int(N[0])
# dp2[i] は i桁目を繰り上げたとしたときの最小値
for i, s in enumerate(N[1:]):
i += 1
m = int(s)
dp1[i] = min(dp1[i-1] + m, dp2[i-1] + (m+1))
dp2[i] = min(dp1[i-1] + (10-m), dp2[i-1] + (10-m-1))
# print(dp1)
# print( dp2)
print(min(dp1[n-1], dp2[n-1]+1))
| N = input()
INF = 10 ** 9
N = N[::-1] + '0'
dp = [[INF for _ in range(2)] for _ in range(len(N) + 1)]
dp[0][0] = 0
for i in range(len(N)):
for j in range(2):
x = int(N[i])
x += j
for k in range(10):
nexti = i + 1
nextj = 0
b = k - x
if b < 0:
nextj = 1
b += 10
dp[nexti][nextj] = min(dp[nexti][nextj], dp[i][j] + k + b)
print(dp[len(N)][0]) | 1 | 71,060,373,244,750 | null | 219 | 219 |
def main():
n, x, t = map(int, input().split())
if (n % x) == 0:
ans = (n // x) * t
else:
ans = (n // x + 1) * t
print(ans)
if __name__ == "__main__":
main()
| N,X,T = map(int, input().split())
if X >= N:
print(T)
elif N % X == 0:
print(N//X*T)
else:
print((N//X+1)*T) | 1 | 4,240,812,737,188 | null | 86 | 86 |
from collections import deque
s = input()
q = int(input())
deq = deque([s])
flag = 1
for i in range(q):
query = input().split()
if query[0]==str(1):
flag*=-1
if query[0]==str(2):
x = 1 if query[1]==str(1) else -1
if flag*x==1:
deq.appendleft(query[2])
else:
deq.append(query[2])
if flag==-1:
print(''.join(deq)[::-1])
else:
print(''.join(deq)) | s = input()
q = int(input())
count = 0
a = []
b = []
for _ in range(q):
Q = list(map(str, input().split()))
if Q[0] == "1":
count += 1
else:
if (int(Q[1])+count)%2 == 1:
a.append(Q[2])
else:
b.append(Q[2])
a = "".join(a[::-1])
b = "".join(b)
s = a + s + b
if count%2 == 1 and count != 0:
s = s[::-1]
print("".join(s)) | 1 | 57,392,506,863,218 | null | 204 | 204 |
n = list(map(int,input().split()))
a = list(map(int,input().split()))
for i in range(n[1],n[0]):
if a[i-n[1]] < a[i]:
print("Yes")
else:
print("No") | import fractions
a, b = map(int, input().split())
def lcm(a,b):
return (a*b)//fractions.gcd(a,b)
print(lcm(a,b)) | 0 | null | 60,357,355,041,372 | 102 | 256 |
n = int(input())
a = [0] + list(map(int,input().split()))
l = [0]*n
for i in a:
l[i-1] += i
for j in range(n):
l[j] = int(l[j]/(j+1))
for k in l:
print(k,end="\n") | n = int(input())
S = list(map(int, input().split()))
S = list(set(S))
q = int(input())
T = list(map(int, input().split()))
T = list(set(T))
C = 0
for i in range(len(S)):
if S[i] in T:
C += 1
print(C)
| 0 | null | 16,262,360,368,918 | 169 | 22 |
n=int(input())
if n==0:
p=0
print("%.9f"%p)
elif n&1:
p=(n//2)+1
print("%.9f"%(p/n))
else:
p=n//2
print("%.9f"%(p/n)) | a, b, m = map(int, input().split())
a_p = list(map(int, input().split()))
b_p = list(map(int, input().split()))
min_price = min(a_p) + min(b_p)
for i in range(m):
x, y, c = map(int, input().split())
min_price = min(min_price, a_p[x-1] + b_p[y-1] - c)
print(min_price) | 0 | null | 115,306,245,536,960 | 297 | 200 |
N=int(input())
s=set()
for _ in range(N):
S=input()
s|={S}
print(len(s))
| N = int(input())
P = tuple(map(int, input().split()))
count = 0
min_num = float('inf')
for i in P:
if i < min_num:
count += 1
min_num = i
print(count) | 0 | null | 58,124,228,739,664 | 165 | 233 |
n = int(input())
print(pow(n, 3)) | n = int(input())
s = input()
[print(chr((ord(s[i])+n-65)%26+65),end="") for i in range(len(s))]
| 0 | null | 67,430,339,056,740 | 35 | 271 |
X = int(input())
Y = X ** 3
print(Y) | INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
'''
一つの整数
'''
return int(input())
def inpl():
'''
一行に複数の整数
'''
return list(map(int, input().split()))
def inpl_str():
'''
一行に複数の文字
'''
return list(input().split())
n=inp()
a = inpl()
sorted_a = sorted(a,reverse=True)
place=dict()
for i in range(n):
if a[i] not in place:
place[a[i]]=[i+1]
else:
place[a[i]].append(i+1)
ans = 0
dp=[[-INF]*(n+1) for i in range(n+1)]
dp[0][0] = 0
for i in range(n):
if i!=0 and sorted_a[i] == sorted_a[i - 1]:
index += 1
else:
index = 0
for j in range(n):
_place = place[sorted_a[i]][index]
#右
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + sorted_a[i] * abs(n - (i - j) - _place))
#左
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + sorted_a[i] * abs(_place - j - 1))
print(max(dp[n]))
| 0 | null | 17,111,343,561,312 | 35 | 171 |
_ = input()
arr = list(map(int, input().split()))
min = arr[0]
max = arr[0]
sum = 0
for a in arr:
if a < min:
min = a
if max < a:
max = a
sum += a
print(min, max, sum) | a, b, c = [int(i) for i in raw_input().split()]
if a < b< c:
print "Yes"
else:
print "No" | 0 | null | 562,720,622,240 | 48 | 39 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in A:
N -= i
if N >= 0:
print(N)
else:
print(-1)
| data = {
'S': [int(x) for x in range(1,14)],
'H': [int(x) for x in range(1,14)],
'C': [int(x) for x in range(1,14)],
'D': [int(x) for x in range(1,14)]
}
count = int(input())
for c in range(count):
(s, r) = input().split()
r = int(r)
del data[s][data[s].index(r)]
for i in ('S', 'H', 'C', 'D'):
for v in data[i]:
print(i, v) | 0 | null | 16,444,786,402,520 | 168 | 54 |
import sys
#input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()
#import numpy as np
def main():
n,k=MI()
p=LI()
for i in range(n):
p[i]=p[i]/2+0.5
#print(p)
ans=sum(p[:k])
now=sum(p[:k])
for i in range(n-k):
now=now-p[i]+p[i+k]
ans=max(ans,now)
print(ans)
if __name__ == "__main__":
main()
| x,y = map(int,input().split())
def point(a):
if a == 1:
return 300000
elif a == 2:
return 200000
elif a == 3:
return 100000
else:
return 0
c = point(x)
b = point(y)
if x == 1 and y == 1:
print(1000000)
else:
print(c+b) | 0 | null | 107,525,441,282,350 | 223 | 275 |
n = int(input())
alist = list(map(int,input().split()))
numb = [0]*n
for i in range(n):
numb[alist[i]-1] = i+1
for i in range(n):
print(numb[i],end=(' ')) | import numpy as np
N,K=map(int,input().split())
a = np.array([int(x) for x in input().split()])
val=sum(a[:K])
max_val=val
for i in range(N-K):
val+=a[K+i]
val-=a[i]
max_val=max(val,max_val)
print(max_val/2+K*0.5) | 0 | null | 128,037,926,239,846 | 299 | 223 |
def solve():
X = [int(i) for i in input().split()]
for i in range(len(X)):
if X[i] == 0:
print(i+1)
break
if __name__ == "__main__":
solve() | X = list(map(int, input().split()))
if X[0] == 0:
print(1)
elif X[1] == 0:
print(2)
elif X[2] == 0:
print(3)
elif X[3] == 0:
print(4)
else:
print(5) | 1 | 13,555,143,285,278 | null | 126 | 126 |
All = [[[0 for x in range(10)] for y in range(3)] for z in range(4)]
N = int(input())
i = 0
while i < N:
b, f, r, v = map(int,input().split())
All[b-1][f-1][r-1] += v
i += 1
for x in range(4):
for y in range(3):
for z in range(10):
print(" {}".format(All[x][y][z]), end = "")
if z == 9:
print("")
if x != 3 and y == 2:
for j in range(20):
print("#", end = "")
print("") | from collections import deque
N = int(input())
A = [[] for i in range(N)]
B = []
for i in range(N-1):
a = list(map(int, input().split()))
A[a[0]-1].append([a[1]-1, 0])
A[a[1]-1].append([a[0]-1, 1])
B.append(a)
K = 0
D = {}
C = [0 for i in range(N)]
de = deque([[0, -1]])
while len(de):
n = de.pop()
C[n[0]] = 1
color = 1
for a in A[n[0]]:
if C[a[0]] == 1:
continue
if color == n[1]:
color += 1
if a[1] == 0:
D[str(n[0])+","+str(a[0])] = color
else:
D[str(a[0])+","+str(n[0])] = color
de.append([a[0], color])
K = max(K, color)
color += 1
print(K)
for b in B:
print(D[str(b[0]-1)+","+str(b[1]-1)]) | 0 | null | 68,542,865,900,040 | 55 | 272 |
import sys
string = str()
for line in sys.stdin:
string += line.lower()
alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for letter in alph:
sum = 0
n = -1
while True:
n = string.find(letter, n + 1)
if n == -1:
break
sum += 1
print("{} : {}".format(letter, sum)) | n = int(input())
x = [None]*n
y = [None]*n
for i in range(n):
x[i],y[i] = map(int,input().split())
#y=x+k1 <=> x-y=-k1
k1 = [0]*n
#y=-x+k2 <=> x+y=k2
k2 = [0]*n
for i in range(n):
k1[i] = -(x[i]-y[i])
k2[i] = x[i]+y[i]
print(max(max(k1)-min(k1),max(k2)-min(k2))) | 0 | null | 2,550,749,021,040 | 63 | 80 |
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)
| def resolve():
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]
a = [0] * 100001
for i in A:
a[i] += i
ans = sum(a)
for b, c in BC:
if a[b] == 0:
print(ans)
continue
move = a[b] // b
a[b] = 0
a[c] += c * move
ans += (c - b) * move
print(ans)
if __name__ == "__main__":
resolve() | 1 | 12,194,795,325,842 | null | 122 | 122 |
import sys
res = dict()
dll = [None] * 2000000
left = 0
right = 0
n = int(input())
for inpt in sys.stdin.read().splitlines():
i = inpt.split()
if i[0] == "insert":
x = int(i[1])
dll[left] = x
if(x in res):
res[x].add(left)
else:
res[x] = set([left])
left += 1
if i[0] == "delete":
x = int(i[1])
if(x in res):
ind = max(res[x])
dll[ind] = None
res[x].remove(ind)
if(len(res[x]) == 0):
del res[x]
if(ind == (left - 1)):
left = ind
if(ind == right):
right += 1
if i[0] == "deleteFirst":
left -= 1
x = dll[left]
res[x].remove(left)
if(len(res[x]) == 0):
del res[x]
dll[left] = None
if i[0] == "deleteLast":
right += 1
# print(dll[right:left])
ret = []
for x in dll[right:left]:
if(x is not None):
ret.append(str(x))
ret.reverse()
print(" ".join(ret)) | import sys
import numpy as np
i4 = np.int32
i8 = np.int64
u4 = np.uint32
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
from numba import njit
from numba.types import Array, int32, int64, uint32
cc = CC('my_module')
@njit
def get_factorization(n):
"""
nまでの割り切れる最小の素数を返す。
"""
sieve_size = (n - 1) // 2
sieve = np.zeros(sieve_size, u4)
for i in range(sieve_size):
if sieve[i] == 0:
value_at_i = i*2 + 3
for j in range(i, sieve_size, value_at_i):
if sieve[j] == 0:
sieve[j] = value_at_i
return sieve
@cc.export('solve', (Array(uint32, 1, 'C'),))
@njit('(u4[::-1],)', cache=True)
def solve(A):
a = np.sort(A)
p_max = a[-1]
p = get_factorization(p_max)
primes_num = 1
for i in range(p.shape[0]):
if i*2 + 3 == p[i]:
primes_num += 1
a_start = 0
while a[a_start] == 1:
a_start += 1
if a_start == a.shape[0]:
return 0
a = a[a_start:]
if len(a) > primes_num:
return 1
check = np.zeros(p_max + 1, u4)
for d in a:
if d & 1 == 0:
check[2] += 1
d //= 2
while d & 1 == 0:
d //= 2
prev = 2
while d > 1:
i = (d - 3) // 2
f = p[i]
if f > prev:
check[f] += 1
prev = f
d //= f
if check.max() > 1:
return 1
else:
return 0
cc.compile()
exit(0)
else:
from my_module import solve
def main(in_file):
stdin = open(in_file)
stdin.readline()
A = np.fromstring(stdin.readline(), u4, sep=' ')
ans = solve(A)
if ans:
g = np.gcd.reduce(A)
if g > 1:
ans = 2
else:
ans = 1
p = ['pairwise coprime', 'setwise coprime', 'not coprime']
print(p[ans])
main(0)
| 0 | null | 2,092,710,511,080 | 20 | 85 |
S = input()
ans = []
for i in range(len(S)+1):
if i <= 2 :
ans += S[i]
else:
print(''.join(ans))
exit()
| #
# 9c
#
def main():
T = H = 0
n = int(input())
for i in range(n):
t, h = input().split()
if t > h:
T += 3
elif t < h:
H += 3
else:
T += 1
H += 1
print(f"{T} {H}")
if __name__ == '__main__':
main()
| 0 | null | 8,422,021,665,724 | 130 | 67 |
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():
n = input()
k = ni()
l = len(n)
dp_true = [[0 for _ in range(k + 2)] for i in range(l + 1)]
dp_false = [[0 for i in range(k + 2)] for j in range(l + 1)]
dp_false[0][0] = 1
for i in range(l):
num = int(n[i])
for j in range(k + 1):
dp_true[i + 1][j] += dp_true[i][j]
dp_true[i + 1][j + 1] += dp_true[i][j] * 9
if num > 0:
dp_true[i + 1][j + 1] += dp_false[i][j] * (num - 1)
dp_true[i + 1][j] += dp_false[i][j]
if num > 0:
dp_false[i + 1][j + 1] += dp_false[i][j]
else:
dp_false[i + 1][j] += dp_false[i][j]
print(dp_true[l][k] + dp_false[l][k])
if __name__ == '__main__':
main()
| S=list(input())
n=len(S)
for i in range(n):
S[i]=int(S[i])
k=int(input())
dp0=[[0]*(n+1) for i in range(k+1)]
dp0[0][0]=1
s=0
for i in range(n):
if S[i]!=0:
s=s+1
if s==k+1:
break
dp0[s][i+1]=1
else:
dp0[s][i+1]=1
dp1=[[0]*(n+1) for i in range(k+1)]
for i in range(1,n+1):
if dp0[0][i]==0:
dp1[0][i]=1
for i in range(1,k+1):
for j in range(1,n+1):
if S[j-1]==0:
dp1[i][j]=dp0[i-1][j-1]*0+dp0[i][j-1]*0+dp1[i-1][j-1]*9+dp1[i][j-1]
else:
dp1[i][j]=dp0[i-1][j-1]*(S[j-1]-1)+dp0[i][j-1]+dp1[i-1][j-1]*9+dp1[i][j-1]
print(dp0[-1][-1]+dp1[-1][-1]) | 1 | 75,856,191,824,478 | null | 224 | 224 |
N=input()
if N.count("7"):
print("Yes")
else:
print("No") | import sys
input = sys.stdin.readline
N, M = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse = True)
sm = sum(a)
for i in range(M):
if a[i] < sm / 4 / M:
print("No")
break
else: print("Yes") | 0 | null | 36,358,268,451,912 | 172 | 179 |
import collections
n = int(input())
words = []
for i in range(n):
words.append(input())
c = collections.Counter(words)
values, counts = zip(*c.most_common())
nums = counts.count(max(counts))
xs = (list(values))[:nums]
xs.sort()
for x in xs:
print(x) | n = int(input())
moziretu={}
a=1
for i in range(n):
s=input()
if s in moziretu:
moziretu[s]=moziretu[s]+1
a=max(a,moziretu[s])
else:
moziretu[s]=1
ans=[k for k, v in moziretu.items() if v == a]
ans.sort()
for i in ans:
print(i) | 1 | 69,582,504,826,408 | null | 218 | 218 |
N, K = map(int, input().split())
start = sum(range(K))
end = sum(range(N-K+1, N+1))
count = 0
#print(start, end)
for k in range(K, N + 2):
count += end - start + 1
count %= 1000000007
start += k
end += (N-k)
print(count) | #!/usr/bin/env python3
while(True):
try:
a,b=map(int, input().split())
except EOFError:
break
#euclidian algorithm
r=a%b
x,y=a,b
while(r>0):
x=y
y=r
r=x%y
gcd=y
lcm=int(a*b/gcd)
print("{0} {1}".format(gcd, lcm)) | 0 | null | 16,449,411,703,078 | 170 | 5 |
# -*- coding: utf-8 -*-
# 標準入力を取得
L, R, d = list(map(int, input().split()))
# 求解処理
ans = R // d - (L - 1) // d
# 結果出力
print(ans)
| L, R, d = map(int, input().split())
if L%d == 0 or R%d == 0 :
print((R-L)//d + 1)
else:
print((R - L)//d) | 1 | 7,622,821,744,888 | null | 104 | 104 |
n, m = map(int, input().split())
a = list(map(int, input().split()))
dp = [0] + [float('inf')]*(n)
for i in range(m):
for j in range(a[i],n+1):
dp[j] = min(dp[j],dp[j-a[i]]+1)
print(dp[-1])
| a,b = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
ans = [10**9 for _ in range(a+1)]
ans[0] = 0
for i in range(a+1):
for j in l:
if i + j < a+1:
ans[i+j] = min(ans[i] + 1,ans[i+j])
print(ans[-1])
| 1 | 140,540,472,160 | null | 28 | 28 |
# coding:utf-8
import math
N=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
manh_dist=0.0
for i in range(0,N):
manh_dist=manh_dist+math.fabs(x[i]-y[i])
print('%.6f'%manh_dist)
eucl_dist=0.0
for i in range(0,N):
eucl_dist=eucl_dist+(x[i]-y[i])**2
eucl_dist=math.sqrt(eucl_dist)
print('%.6f'%eucl_dist)
mink_dist=0.0
for i in range(0,N):
mink_dist=mink_dist+math.fabs(x[i]-y[i])**3
mink_dist=math.pow(mink_dist,1.0/3)
print('%.6f'%mink_dist)
cheb_dist=0.0
for i in range(0,N):
if cheb_dist<math.fabs(x[i]-y[i]):
cheb_dist=math.fabs(x[i]-y[i])
print('%.6f'%cheb_dist) | def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
n,m=n1()
if n%2==0:
if m>=2:
e=n//2
s=1
l=e-s
c=0
while e>s and c<m:
print(s,e)
s+=1
e-=1
c+=1
e=n
s=n-l+1
while e>s and c<m:
print(s,e)
s+=1
e-=1
c+=1
else:
print(1,2)
else:
if m>=2:
e=n//2+1
s=1
l=e-s
c=0
while e>s and c<m :
print(s,e)
s+=1
e-=1
c+=1
e=n
s=n-l+1
while e>s and c<m:
print(s,e)
s+=1
e-=1
c+=1
else:
print(1,2) | 0 | null | 14,360,149,278,930 | 32 | 162 |
# -*- coding: utf-8 -*-
S = input()
ans = 0
for i in range(len(S)):
if S[i] == "R":
if ans == 0:
ans += 1
else:
if i > 0 and S[i] == S[i-1] == "R":
ans += 1
print(ans) | S = input()
zenzitsu = False
ans = 0
for i in range(len(S)):
if S[i] == "R":
if zenzitsu:
ans += 1
zenzitsu = True
else:
ans = 1
zenzitsu = True
else:
zenzitsu = False
print(ans) | 1 | 4,846,829,126,128 | null | 90 | 90 |
import math
a,b,x = map(int,input().split())
if x >= (a**2) * b / 2 :
theta = math.atan(2*(b-x/(a**2))/a)
print(math.degrees(theta))
else :
theta = math.pi/2-math.atan(2*x/((a*(b**2))))
print(math.degrees(theta)) | n,m = map(int,input().split())
coins = list(map(int,input().split()))
inf = float("inf")
dp = [inf]*(n+2)
dp[0]= 0
for i in range(1,n+1):
for coin in coins:
if i-coin>=0:
dp[i]= min(dp[i-coin]+1,dp[i])
print(dp[n])
| 0 | null | 81,330,883,757,596 | 289 | 28 |
s=input()
if s!="AAA" and s!="BBB":
print("Yes")
else:
print("No")
| n=int(input())
s=list()
for i in range(n):
s.append(input())
import collections
c=collections.Counter(s)
l=list()
max_=0
for cc in c.values():
max_=max(cc, max_)
for ca,cb in c.items():
if max_==cb:
l.append(ca)
l.sort()
for ll in l:
print(ll)
| 0 | null | 62,428,734,403,420 | 201 | 218 |
m,n,o=map(int,raw_input().split())
print'Yes'if m<n<o else'No' | a,b,c = input().split(' ')
a=int(a)
b=int(b)
c=int(c)
ret="Yes" if a<b<c else "No"
print(ret) | 1 | 399,685,729,432 | null | 39 | 39 |
N = int(input())
l = []
for _ in range(N):
A, B = map(int, input().split())
l.append((A, B))
t = N//2
tl = sorted(l)
tr = sorted(l, key=lambda x:-x[1])
if N%2:
print(tr[t][1]-tl[t][0]+1)
else:
a1, a2 = tl[t-1][0], tr[t][1]
a3, a4 = tl[t][0], tr[t-1][1]
print(a4-a3+a2-a1+1)
| def gcd(a, b):
if b == 0: return a
else: return gcd(b, a % b)
def lcm(a, m):
return a * b / gcd(a, b);
while True:
try:
a, b = map(int, raw_input().split())
print gcd(a, b), lcm(a, b)
except (EOFError):
break | 0 | null | 8,571,364,183,280 | 137 | 5 |
R = int(input())
print(2 * R * 3.14159265359) | import math as ma
r=int(input())
print(2*r*ma.pi) | 1 | 31,340,120,260,096 | null | 167 | 167 |
n = input()
a = list(map(int, input().split()))
b = sum(a)
sum = 0
for i in range(len(a)):
b -= a[i]
sum += a[i]*b
print(sum%(10**9+7)) | while True:
m, t, f = map( int, raw_input().split())
if m == -1 and t == -1 and f == -1:
break
if m == -1 or t == -1:
r = "F"
elif (m + t) >= 80:
r = "A"
elif (m + t) >= 65:
r = "B"
elif (m + t) >= 50:
r = "C"
elif (m + t) >= 30:
if f >= 50:
r = "C"
else:
r = "D"
else:
r = "F"
print r | 0 | null | 2,516,770,640,732 | 83 | 57 |
def insertion_sort(a, g, cnt):
for i in range(g, len(a)):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j+g] = a[j]
j = j - g
cnt += 1
a[j+g] = v
return cnt
n = int(input())
g = [1]
t = 1
cnt = 0
while 1:
t = 3 * t + 1
if t < n and len(g) < 100:
g += [t]
else:
g = g[::-1]
break
a = [int(input()) for _ in range(n)]
for i in range(0, len(g)):
cnt = insertion_sort(a, g[i], cnt)
print(len(g))
print(*g)
print(cnt)
for i in a: print(i)
| #!/usr/bin/env python3
def main():
a, b, c = map(int, input().split())
k = int(input())
for i in range(k):
if a < b < c:
break
elif a >= b:
b *= 2
elif b >= c:
c *= 2
if a < b < c:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
| 0 | null | 3,472,923,164,172 | 17 | 101 |
arr = list(map(int, input().split()))
print(arr.index(0) + 1) | L = int(input())
num = L / 3
print(num**3) | 0 | null | 30,229,540,085,888 | 126 | 191 |
# -*- coding: utf-8 -*-
# input
a, b = map(int, input().split())
x = list(map(int, input().split()))
print('Yes') if a <= sum(x) else print('No') | h,n= map(int, input().split())
a = list(map(int,input().split()))
for i in range(n):
h -= a[i]
print("Yes" if h <=0 else "No") | 1 | 77,933,842,712,920 | null | 226 | 226 |
N, K = map(int, input().split())
MOD = 10 ** 9 + 7
ans = 1
for i in range(K, N + 1):
ans += i * (2 * N - i + 1) // 2 % MOD - i * (i - 1) // 2 % MOD + 1
ans %= MOD
print(ans) | n = int(input())
s = input()
int_s = [int(i) for i in s]
pc = s.count('1')
def f(x):
bi = bin(x)
pc = bi.count('1')
cnt = 1
while True:
if x == 0:
break
x = x % pc
bi = bin(x)
pc = bi.count('1')
cnt += 1
return cnt
num_pl = 0
for i in range(n):
num_pl = (num_pl*2) % (pc+1)
num_pl += int_s[i]
num_mi = 0
for i in range(n):
if pc-1 <= 0:
continue
num_mi = (num_mi*2) % (pc-1)
num_mi += int_s[i]
ans = [0]*n
pc_pl, pc_mi = pc+1, pc-1
r_pl, r_mi = 1, 1
for i in range(n-1, -1, -1):
if int_s[i] == 0:
num = num_pl
num = (num+r_pl) % pc_pl
else:
num = num_mi
if pc_mi <= 0:
continue
num = (num-r_mi+pc_mi) % pc_mi
ans[i] = f(num)
r_pl = (r_pl*2) % pc_pl
if pc_mi <= 0:
continue
r_mi = (r_mi*2) % pc_mi
print(*ans, sep='\n') | 0 | null | 20,710,729,750,360 | 170 | 107 |
s=input()
a,b,c,d=0,0,0,0
for i in range(len(s)):
if s[i]==">":
c=0;b+=1
if b<=d:a+=b-1
else:a+=b
else:b=0;c+=1;a+=c;d=c
print(a) | import sys
sys.setrecursionlimit(1000000)
s=input()
#print(s)
l=[-1 for _ in range(len(s)+1)]
def aa(ix,v): #ixはlベース
# print(ix,v,l)
if (ix>= len(s) and v==1) or (ix==0 and v==0-1):
return
if v==1 and s[ix]=="<" and l[ix+1]<=l[ix]:
l[ix+1]=l[ix]+1
aa(ix+1,1)
elif v==-1 and s[ix-1]==">" and l[ix-1]<=l[ix]:
l[ix-1]=l[ix]+1
aa(ix-1,-1)
return
for i in range(0,len(s)):
if i ==0 and s[0]=="<":
l[0]=0
aa(i,1)
elif i==len(s)-1 and s[-1]==">":
l[-1]=0
aa(i+1,-1)
elif s[i]==">" and s[i+1]=="<":
l[i+1]=0
aa(i+1,1)
aa(i+1,-1)
print(sum(l))
| 1 | 156,542,027,424,704 | null | 285 | 285 |
import math
def main():
x1, y1, x2, y2 = map(float, input().split())
b = abs(x2 - x1)
h = abs(y2 - y1)
d = math.sqrt(b ** 2 + h ** 2)
print("{0:.8f}".format(d))
if __name__ == "__main__":
main() | n = int(input())
def fib(n):
dp = [0] * (n+1)
dp[0] = 1
dp[1] = 1
def fib_sub(n):
if dp[n] != 0:
return dp[n]
fibn1 = fib_sub(n-1)
fibn2 = fib_sub(n-2)
dp[n-1] = fibn1
dp[n-2] = fibn2
return fibn1 + fibn2
return fib_sub(n)
print(fib(n))
| 0 | null | 77,317,659,394 | 29 | 7 |
def main():
N = int(input())
CARD = tuple(input().split())
sort_ = []
for i in range(1, 10):
for s in CARD:
if str(i) in s:
sort_.append(s)
sort_ = tuple(sort_)
bsort = tuple(bubbleSort(list(CARD), N))
ssort = tuple(selectionSort(list(CARD), N))
for s in (bsort, ssort):
print(*s, sep=' ')
if s == sort_:
print('Stable')
else:
print('Not stable')
def bubbleSort(c, n):
flag = 1
while flag:
flag = 0
for i in range(1, n):
if c[i][1] < c[i-1][1]:
c[i], c[i-1] = c[i-1], c[i]
flag = 1
return c
def selectionSort(c, n):
for i in range(n):
minj = i
for j in range(i, n):
if c[j][1] < c[minj][1]:
minj = j
c[i], c[minj] = c[minj], c[i]
return c
main() | h, w, k = map(int, input().split())
s = [input() for _ in range(h)]
INF = 10 ** 20
ans = INF
for div in range(1 << (h - 1)):
id = []
g = 0
for i in range(h):
id.append(g)
if div >> i & 1:
g += 1
g += 1
c = [[0 for _ in range(w)] for _ in range(g)]
for i in range(h):
for j in range(w):
c[id[i]][j] += (s[i][j] == "1")
tmp_ans = g - 1
now = [0] * g
def add(j):
for i in range(g):
now[i] += c[i][j]
if now[i] > k:
return False
return True
for j in range(w):
if not add(j):
tmp_ans += 1
now = [0] * g
if not add(j):
tmp_ans = INF
break
# impossible = 0
# for j in range(w):
# if impossible:
# tmp_ans = INF
# break
# for i in range(g):
# if c[i][j] > k:
# impossible = 1
# break
# now[i] += c[i][j]
# if now[i] > k:
# now = [c[gi][j] for gi in range(g)]
# tmp_ans += 1
# continue
ans = min(ans, tmp_ans)
print(ans) | 0 | null | 24,312,344,739,350 | 16 | 193 |
def main():
N = int(input())
m = float("inf")
ans = 0
for i in [int(j) for j in input().split()]:
if i < m:
m = i
ans += 1
print(ans)
if __name__ == '__main__':
main() | N = int(input())
N_List = list(map(int,input().split()))
ct = 0
Current_Min = 2*(10**5) + 1
for i in range(N):
if N_List[i] <= Current_Min:
ct += 1
Current_Min = N_List[i]
print(ct) | 1 | 85,614,161,208,306 | null | 233 | 233 |
N = int(input())
A = [int(c) for c in input().split()]
l = [0]*N
for i in range(N):
l[A[i]-1] = i+1
print(' '.join(map(str, l)))
| n=int(input())
s=list(map(int,input().split()))
p=[0]*n
for i in range(n):
p[s[i]-1]=i+1
print(*p) | 1 | 180,397,692,981,990 | null | 299 | 299 |
# -*- coding:utf-8 -*-
n = int(input())
for i in range(2,n+1):
a = i // 10
a = a % 10
b = i // 100
b = b % 10
if i % 3 == 0:
print(' ',i,sep='',end='')
elif i % 10 == 3:
print(' ',i,sep='',end='')
elif a == 3:
print(' ',i,sep='',end='')
elif i // 100 == 3:
print(' ',i,sep='',end='')
elif i // 1000 == 3:
print(' ',i,sep='',end='')
elif i // 10000 == 3:
print(' ',i,sep='',end='')
elif b == 3:
print(' ',i,sep='',end='')
print('') | def call(n):
s = ""
for i in range(1,n+1):
if i%3 == 0:
s += " {0}".format(i)
else:
x = i
while x > 0:
if x%10 == 3:
s += " {0}".format(i)
break
x = x // 10
print(s)
m = int(input())
call(m) | 1 | 940,043,807,900 | null | 52 | 52 |
N,D = map(int, input().split())
cnt = 0
for _ in range(N):
X,Y = map(int, input().split())
cnt += X*X + Y*Y <= D*D
print(cnt) | j=0
N,D=map(int,input().split())
for i in range(N):
X,Y=map(int,input().split())
if (X**2+Y**2)**0.5<=D:
j=j+1
print(j) | 1 | 5,953,948,479,242 | null | 96 | 96 |
n, m = map(int, raw_input().split())
ans = []
aa = []
for i in range(n):
a = map(int, raw_input().split())
aa.append(a)
ans.append(0)
b = []
for i in range(m):
a = input()
b.append(a)
for i in range(n):
for j in range(m):
ans[i] += aa[i][j] * b[j]
for i in range(len(ans)):
print(ans[i]) | 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)) | 0 | null | 1,602,912,001,610 | 56 | 67 |
#keyence c subarry sum
n,k,s=map(int,input().split())
x=10**9
ans=[print(s) for _ in range(k)]
for i in range(n-k):
if s==x:
print(1)
else:
print(s+1) | n = int(input())
acl = "ACL" * n
print(acl)
| 0 | null | 46,540,430,967,560 | 238 | 69 |
n,k=map(int,input().split())
ans=[0 for _ in range(n*3)]
ans[1]=1
idou=[]
for _ in range(k):
a=list(map(int,input().split()))
idou.append(a)
mod=998244353
rui=[0 for _ in range(n+1)]
rui[1]=1
for i in range(2,n+1):
for g in idou:
x,y=g
left=max(0,i-y-1)
right=max(0,i-x)
ans[i]+=(rui[right]-rui[left])%mod
rui[i]+=((rui[i-1]+ans[i]))%mod
print(ans[n]%mod)
| import collections
hoge = collections.defaultdict(lambda: 'no')
num = int(input())
for _ in range(num):
command, key = input().split()
if command == 'insert':
hoge[key] = 'yes'
else:
print(hoge[key])
| 0 | null | 1,369,439,589,522 | 74 | 23 |
import sys
readline = sys.stdin.readline
INF = 10 ** 8
def main():
H, N = map(int, readline().rstrip().split())
dp = [INF] * (H + 1) # HPを減らすのに必要な最小のMP
dp[0] = 0
for _ in range(N):
hp, mp = map(int, readline().rstrip().split())
for i in range(H):
j = min(i+hp, H)
dp[j] = min(dp[j], dp[i] + mp)
print(dp[-1])
if __name__ == '__main__':
main() | N=input("").split(" ")
S=int(N[0])
W=int(N[1])
if S<=W:
print("unsafe")
else:
print("safe")
| 0 | null | 55,269,085,364,960 | 229 | 163 |
N = int(input())
ST = [list(map(str, input().split())) for _ in range(N)]
X = str(input())
ans = 0
flag = False
for s, t in ST:
if flag:
ans += int(t)
else:
if s == X:
flag = True
print (ans) | N = int(input())
X = []
for i in range(N):
X.append(input().split())
S = input()
flg = False
ans = 0
for x in X:
if flg:
ans += int(x[1])
if S == x[0]:
flg = True
print(ans) | 1 | 96,540,659,402,698 | null | 243 | 243 |
num = int(input(""))
val = list(map(int,input().split()))
val_sum = sum(val)
ans = 0
mod = 10**9 + 7
for i in range(num):
val_sum = val_sum - val[i]
ans = val[i] * val_sum + ans
print(ans%mod) | MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
S = sum(A) % MOD
ans = 0
for x in A:
S -= x
S %= MOD
ans += S * x
ans %= MOD
ans %= MOD
print(ans) | 1 | 3,820,987,714,368 | null | 83 | 83 |
s = str(input())
t = ''
for c in s:
if 65 <= ord(c) and ord(c) <= 90:
t += c.lower()
elif 97 <= ord(c) and ord(c) <= 122:
t += c.upper()
else:
t += c
print(t)
| import sys
def main():
sec = int(sys.stdin.readline())
hour = int(sec / 3600)
sec = sec % 3600
minute = int(sec / 60)
sec = sec % 60
print("{0}:{1}:{2}".format(hour,minute,sec))
return
if __name__ == '__main__':
main()
| 0 | null | 929,269,459,008 | 61 | 37 |
x = raw_input()
x = int(x)
x = x * x * x
print x | #! /usr/local/bin/python3
# coding: utf-8
print(int(input()) ** 3)
| 1 | 282,689,981,770 | null | 35 | 35 |
def f(x, m):
return (x**2) % m
N, X, M = map(int, input().split())
A = [X]
S = {X}
while True:
X = f(X, M)
if X in S:
break
else:
A.append(X)
S.add(X)
start = A.index(X)
l = len(A) - start
ans = sum(A[:start])
N -= start
ans += sum(A[start:]) * (N//l)
N %= l
ans += sum(A[start:start+N])
print(ans) | import sys
alphabets = range(ord('a'), ord('z') + 1)
dic = { chr(c): 0 for c in alphabets }
text = sys.stdin.read()
for c in text:
c = c.lower()
if ord(c) in alphabets:
dic[c] += 1
for c, n in sorted(dic.items()):
print(c, ":", n) | 0 | null | 2,254,069,452,650 | 75 | 63 |
# coding: utf-8
from math import sqrt
def solve(*args: str) -> str:
k = int(args[0])
l = 9*(k//7 if 0 == k % 7 else k)
if 0 == l % 2 or 0 == l % 5:
return '-1'
r = phi = l
for i in range(2, int(sqrt(l)+1)):
if 0 == r % i:
phi = phi*(i-1)//i
while 0 == r % i:
r //= i
if 1 < r:
phi = phi*(r-1)//r
D = set()
for d in range(1, int(sqrt(phi)+1)):
if 0 == phi % d:
D.add(d)
D.add(phi//d)
ret = -1
for m in sorted(D):
if 1 == pow(10, m, l):
ret = m
break
return str(ret)
if __name__ == "__main__":
print(solve(*(open(0).read().splitlines())))
| A, B, K = map(int, input().split())
a = max(0, A - K)
b = B
if K - A > 0:
b = max(0, B - K + A)
print(a, b)
| 0 | null | 55,303,958,037,968 | 97 | 249 |
numbers = [int(i) for i in input().split()]
D, S, T = numbers[0], numbers[1], numbers[2]
if D <= S*T:
print("Yes")
else:
print("No")
| # -*- coding: utf-8 -*-
def main():
import sys
input = sys.stdin.readline
a, b, c = map(int, input().split())
k = int(input())
count = 0
while a >= b:
b *= 2
count += 1
while b >= c:
c *= 2
count += 1
if count <= k:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| 0 | null | 5,198,308,913,620 | 81 | 101 |
def calc_divisor(x):
divisor = []
for i in range(1, int(x ** 0.5) + 1):
if x % i == 0:
divisor.append(i)
if i != x // i:
divisor.append(x // i)
return divisor
N = int(input())
ans = len(calc_divisor(N - 1)) - 1
cand = sorted(calc_divisor(N))[1:]
for k in cand:
x = N
while x % k == 0:
x //= k
if x % k == 1:
ans += 1
print(ans)
| N = int(input())
def divisor(n):
if n==1:return []
ret = [n]
for i in range(2,n+1):
if i*i==n:
ret.append(i)
elif i*i > n:
break
elif n%i==0:
ret.append(i)
ret.append(n//i)
ret.sort()
return ret
ans = len(divisor(N-1))
for k in divisor(N):
M = N
while M%k==0:
M//=k
if M%k==1:
ans += 1
print(ans) | 1 | 41,349,216,419,228 | null | 183 | 183 |
import sys
n = int(input())
command = sys.stdin.readlines()
Q = {}
for i in range(n):
a,b = command[i].split()
if a == "insert":
Q[b] = 0
else:
if b in Q.keys():
print("yes")
else:
print("no") | a,b,c,d=map(int,input().split())
for i in range(1001):
if i%2==0:
c-=b
if c<=0:
print("Yes")
exit(0)
else:
a-=d
if a<=0:
print("No")
exit(0)
| 0 | null | 14,773,647,769,328 | 23 | 164 |
n=input()
S=['S 1','S 2','S 3','S 4','S 5','S 6','S 7','S 8','S 9','S 10','S 11','S 12','S 13']
H=['H 1','H 2','H 3','H 4','H 5','H 6','H 7','H 8','H 9','H 10','H 11','H 12','H 13']
C=['C 1','C 2','C 3','C 4','C 5','C 6','C 7','C 8','C 9','C 10','C 11','C 12','C 13']
D=['D 1','D 2','D 3','D 4','D 5','D 6','D 7','D 8','D 9','D 10','D 11','D 12','D 13']
cards=[S,H,C,D]
for i in range(n):
exist=raw_input()
if 'S' in exist:
cards[0].remove(exist)
if 'H' in exist:
cards[1].remove(exist)
if 'C' in exist:
cards[2].remove(exist)
if 'D' in exist:
cards[3].remove(exist)
for j in range(4):
for i in cards[j]:
print i | n = int(input())
for i in range(1,n+1):
x = i
if x % 3 == 0:
print(' {}'.format(i), end='')
else:
while x:
if x % 10 == 3:
print(' {}'.format(i), end='')
break
else:
x //= 10
print('') | 0 | null | 984,685,058,562 | 54 | 52 |
from itertools import groupby
def main():
S = input()
K = int(input())
a = [len(tuple(s)) for _, s in groupby(S)]
ans = 0
if S[0] == S[-1] and K > 1:
if len(a) == 1:
ans = a[0] * K // 2
else:
ans = a[0] // 2 + a[-1] // 2 + (a[0] + a[-1]) // 2 * (K - 1)
ans += sum(n // 2 for n in a[1:-1]) * K
else:
ans += sum(n // 2 for n in a) * K
print(ans)
if __name__ == "__main__":
main() | def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#main code here!
s=SI()
k=I()
u=len(s)
seq=0
x=1
for i in range(u-1):
if s[i]==s[i+1]:
x+=1
else:
seq+=x//2
x=1
seq+=x//2
#print(seq)
a=1
for i in range(u-1):
if s[0]==s[i+1]:
a+=1
else:
break
b=1
for i in range(u-1):
if s[-1]==s[u-1-(1+i)]:
b+=1
else:
break
#print(a,b)
if x==u:
ans=(u*k)//2
else:
if s[0]!=s[-1]:
ans=(seq)*k
else:
ans=(seq)*k-(a//2+b//2-(a+b)//2)*(k-1)
print(ans)
if __name__=="__main__":
main()
| 1 | 175,003,901,638,638 | null | 296 | 296 |
# -*- coding:utf-8 -*-
h,w = map(int,input().split())
if h == 1 or w == 1:
print(1)
elif w %2 == 0:
print(h * w //2)
elif h % 2 == 0:
print(h * w //2)
else:
print(h*w//2+1) | H,W=map(int,input().split())
import sys
N=1
if W==1 or H==1:
print(1)
sys.exit()
if (W-1)%2==0:
N+=(W-1)//2
N+=(W-1)//2
elif (W-1)%2==1:
N+=(W-2)//2
N+=W//2
if H%2==0:
NN=N*(H//2)
elif H%2==1:
if (W-1)%2==0:
NN=N*((H-1)//2)+(W-1)//2+1
elif (W-1)%2==1:
NN=N*((H-1)//2)+(W-2)//2+1
print(NN) | 1 | 50,759,622,616,900 | null | 196 | 196 |
a, b = input().split()
print(sorted([a*int(b), b*int(a)])[0])
| a, b = map(int, input().split())
s1 = str(a)*b
s2 = str(b)*a
if s1<s2 :
print(s1)
else:
print(s2) | 1 | 84,637,833,065,280 | null | 232 | 232 |
a, b = map(int, raw_input().split())
print("%d %d %f" % (a//b, a%b, a/float(b))) | n=int(input())
m=int(n/1.08)
for i in range(-2,3):
if int((m+i)*1.08)==n:
print(m+i)
exit()
print(":(") | 0 | null | 63,181,964,371,326 | 45 | 265 |
num = int(input())
nums = input().split()
zero_flag = False
for item in nums:
if item == '0':
zero_flag = True
break
if zero_flag:
seki = 0
else:
seki = 1
for item in nums:
seki *= int(item)
if seki > 10**18:
seki = -1
break
print(seki) | a,b = map(int,input().split())
lis = list(map(int,input().split()))
lis.sort(reverse=True)
print(sum(lis[b:])) | 0 | null | 47,831,899,759,842 | 134 | 227 |
n, k, c = map(int, input().split())
s = input()
l = []
r = []
res = []
def fun(string, pos):
counter = 0
consec_counter = c + 1
res = []
while pos < n:
# print(pos)
if counter == k:
break
if consec_counter >= c and string[pos] == 'o':
counter += 1
consec_counter = 0
res.append(pos)
else:
consec_counter += 1
pos += 1;
# print(res)
return res
def invfun(string, pos):
counter = 0
consec_counter = c + 1
res = []
while pos >= 0:
if counter == k:
break
# print(pos)
if consec_counter >= c and string[pos] == 'o':
counter += 1
consec_counter = 0
res.append(pos)
else:
consec_counter += 1
pos -= 1;
# print(res)
return res
little_res = fun(s, 0)
lres = []
if len(little_res) == k:
lres = little_res
else:
exit()
little_res = invfun(s, n - 1)
rres = []
if len(little_res) == k:
rres = little_res
else:
exit()
# print(lres)
# print(rres)
for i in range(k):
if lres[i] == rres[k - 1 - i]:
print(lres[i] + 1)
| from collections import Counter, defaultdict, deque
import bisect
from sys import stdin, stdout
from itertools import repeat
import math
import random
# sys.stdin = open('input')
def inp():
re = map(int, raw_input().split())
if len(re) == 1:
return re[0]
return re
def inst():
return raw_input().strip()
def gcd(x, y):
while(y):
x, y = y, x % y
return x
def my_main():
n, k, c = inp()
st = inst()
front, end = [], []
def get(now, ans):
while now < n:
if len(ans) == k:
return
for i in range(now, n):
if st[i]=='o':
ans.append(i+1)
now = i+c+1
break
else:
break
get(0, front)
st = st[::-1]
get(0, end)
for i in range(len(end)):
end[i] = n-end[i]+1
end.sort()
if len(front)!=k or len(end)!=k:
return
ans = []
# print front, end
for i in range(k):
if front[i] == end[i]:
ans.append(front[i])
if ans:
print '\n'.join(map(str, ans))
my_main()
| 1 | 40,492,094,419,590 | null | 182 | 182 |
n, k = map(int, input().split()); m = 998244353; a = []
for i in range(k): a.append(list(map(int, input().split())))
b = [0]*n; b.append(1); c = [0]*n; c.append(1)
for i in range(1, n):
d = 0
for j in range(k): d = (d+c[n+i-a[j][0]]-c[n+i-a[j][1]-1])%m
b.append(d); c.append(c[-1]+d)
print(b[-1]%m) | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter
import sys
sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 1 << 60
def read_int():
return int(readline())
def read_int_n():
return list(map(int, readline().split()))
def read_float():
return float(readline())
def read_float_n():
return list(map(float, readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def ep(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.perf_counter()
ret = f(*args, **kwargs)
e = time.perf_counter()
ep(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, K, LR):
M = 998244353
memo = [0] *(N+2)
memo[1] = 1
memo[1+1] = -1
for i in range(1, N+1):
memo[i] += memo[i-1]
memo[i] %= M
for l, r in LR:
ll = min(N+1, i+l)
rr = min(N+1, i+r+1)
memo[ll] += memo[i]
memo[ll] %= M
memo[rr] -= memo[i]
memo[rr] %= M
return memo[N]
def main():
N, K = read_int_n()
LR = [read_int_n() for _ in range(K)]
print(slv(N, K, LR))
if __name__ == '__main__':
main()
| 1 | 2,717,210,450,620 | null | 74 | 74 |
W = input().lower()
count = 0
while True:
line = input()
if line == 'END_OF_TEXT':
break
for s in line.lower().split():
if s == W:
count += 1
print(count) | import sys
num = map(int, raw_input().split())
if num[0] < num[1]:
if num[1] < num[2]:
print "Yes"
else:
print "No"
else:
print "No" | 0 | null | 1,097,761,899,810 | 65 | 39 |
N = int(input())
S = [input() for _ in range(N)]
print('AC x ' + str(S.count('AC')))
print('WA x ' + str(S.count('WA')))
print('TLE x ' + str(S.count('TLE')))
print('RE x ' + str(S.count('RE'))) | n,m=map(int,input().split())
left=m//2
right=(m+1)//2
for i in range(left):
print(i+1,2*left+1-i)
for i in range(right):
print(2*left+1+i+1,2*left+1+2*right-i)
| 0 | null | 18,538,752,452,740 | 109 | 162 |
def main():
N = int(input())
if N % 1000 == 0: return 0
else: return 1000 - N % 1000
if __name__ == '__main__':
print(main())
| import bisect
def main():
n = int(input())
l = sorted(list(int(i) for i in input().split()))
cnt = 0
for i in range(n - 2):
a = l[i]
for j in range(i + 1, n-1):
b = l[j]
cnt += bisect.bisect_left(l, a+b)-(j+1)
print(cnt)
if __name__ == "__main__":
main()
| 0 | null | 90,423,409,022,660 | 108 | 294 |
M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())
if M1!=M2:
print('1')
else:
print('0')
| import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
M1, D1 = map(int, readline().split())
M2, D2 = map(int, readline().split())
if M1 != M2:
print('1')
else:
print('0')
if __name__ == '__main__':
main() | 1 | 124,433,739,710,500 | null | 264 | 264 |
#--Beginner
#1行1列
number, rate = map(int, input().split())
if (number < 10):
print(rate+(100*(10-number)))
elif (number >= 10):
print(rate)
| n, r = map(int, input().split())
print(r if n >= 10 else r + 1000 - (100 * n))
| 1 | 63,574,701,708,740 | null | 211 | 211 |
#座標はxは負の場合もあるの絶対値をとること
X, K, D = list(map(int, input().split()))
X = abs(X)
#K回繰り返すことを考慮すること
i = min(X//D, K) #移動回数が最小の方をとる
X = X - i*D
K = K - i
if K > 0:
if K % 2 == 1:
X = X - D
print(abs(X)) | from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
x,k,d = mi()
x = abs(x)
count = min(k,x//d)
k -= count
x -= d*count
if k % 2 == 0:
print(x)
else:
print(d-x) | 1 | 5,159,652,919,070 | null | 92 | 92 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
def main():
a, b, c = map(int, input().split())
x = ((c-a-b)**2-4*a*b > 0 ) and (c > a+b)
print('NYoe s'[x::2])
if __name__ == '__main__':
main() | from decimal import *
getcontext().prec=1000
a,b,c=map(int,input().split())
A=Decimal(a)**Decimal("0.5")
B=Decimal(b)**Decimal("0.5")
C=Decimal(c)**Decimal("0.5")
D= Decimal(10) ** (-100)
if A+B+D<C:
print("Yes")
else:
print("No") | 1 | 51,446,690,870,200 | null | 197 | 197 |
def main():
r = int(input())
print(r * r)
if __name__ == '__main__':
main()
| N = int(input())
print(N*N) | 1 | 145,357,745,541,128 | null | 278 | 278 |
S = input()
INC = '<'
DEC = '>'
icnt = 0
dcnt = 0
mode = DEC
ans = 0
for c in S:
if mode == DEC:
if c == DEC:
dcnt += 1
elif c == INC:
if icnt <= dcnt:
ans += (dcnt + 1) * dcnt // 2
else:
ans += icnt + dcnt * (dcnt - 1) // 2
icnt = 1
mode = INC
elif mode == INC:
if c == INC:
icnt += 1
elif c == DEC:
ans += icnt * (icnt - 1) // 2
dcnt = 1
mode = DEC
if mode == INC:
ans += (icnt + 1) * icnt // 2
elif mode == DEC:
if icnt <= dcnt:
ans += (dcnt + 1) * dcnt // 2
else:
ans += icnt + dcnt * (dcnt - 1) // 2
print(ans) | from itertools import groupby
s=input()
if s[0]=='>':
s='<'+s
g=groupby(s)
a=[]
for i,j in g:
a.append(len(list(j)))
def sum(n):
return n*(n+1)//2
x=0
if len(a)%2==1:
a+=[1]
for i in range(0,len(a),2):
x+=sum(min(a[i],a[i+1])-1)
x+=sum(max(a[i],a[i+1]))
print(x)
| 1 | 156,196,399,812,038 | null | 285 | 285 |
# 147 B
s = input()
k = s[::-1]
n = 0
for i in range(len(s)):
if s[i] != k[i]:
n += 1
# print(s[i])
print(n // 2)
| from sys import stdin, stdout # only need for big input
def solve():
s = input()
left = 0
right = len(s) - 1
count = 0
while left < right:
count += (s[left] != s[right])
left += 1
right -= 1
print(count)
def main():
solve()
if __name__ == "__main__":
main() | 1 | 120,532,524,915,010 | null | 261 | 261 |
N = input()
S = 0
for m in N:
S += int(m)
S %= 9
if S == 0:
print('Yes')
else:
print('No') | S= input()
T=input()
mi = 3000
for i in range(0,len(S)-len(T)+1):
c = 0
for j in range(0,len(T)):
#print(S[i+j]+":"+T[j])
if S[i+j] != T[j]:
c += 1
#print(c)
if mi > c:
mi = c
print(mi) | 0 | null | 4,072,825,642,602 | 87 | 82 |
import queue
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
ini = 0
if s[0][0] == '#':
ini = 1
dist = [[ini for _ in range(W)] for _ in range(H)]
start = (0,0)
qq = queue.Queue()
for i in range(H):
for j in range(W):
tgt = []
if j == 0:
pass
else:
if s[i][j-1] == '.' and s[i][j] == '#':
tgt.append(dist[i][j-1] + 1)
else:
tgt.append(dist[i][j-1])
if i == 0:
pass
else:
if s[i-1][j] == '.' and s[i][j] == "#":
tgt.append(dist[i-1][j] + 1)
else:
tgt.append(dist[i-1][j])
if i + j == 0:
continue
dist[i][j] = min(tgt)
print(dist[H-1][W-1])
| # coding: utf-8
H, W = list(map(int, input().split()))
S = []
for _ in range(H):
S.append(list(input()))
grid = [[0 for _ in range(W)] for _ in range(H)]
for h in range(1,H):
if S[h-1][0] == '#' and S[h][0] == '.':
grid[h][0] = grid[h-1][0] + 1
else:
grid[h][0] = grid[h-1][0]
for w in range(1,W):
if S[0][w-1] == '#' and S[0][w] == '.':
grid[0][w] = grid[0][w-1] + 1
else:
grid[0][w] = grid[0][w-1]
for w in range(1,W):
for h in range(1,H):
if S[h-1][w] == '#' and S[h][w] == '.':
next_h = grid[h-1][w] + 1
else:
next_h = grid[h-1][w]
if S[h][w-1] == '#' and S[h][w] == '.':
next_w = grid[h][w-1] + 1
else:
next_w = grid[h][w-1]
grid[h][w] = min([next_w, next_h])
if S[H-1][W-1] == '#':
grid[H-1][W-1] += 1
print(grid[H-1][W-1]) | 1 | 49,218,792,288,668 | null | 194 | 194 |
l = int(input())
ans = float(l ** 3 / 27)
print(ans) | def selectionSort(A, N):
count = 0
for i in range(N - 1):
minValue = 100
minIndex = 0
for j in range(i, N):
if A[j] < minValue:
minValue = A[j]
minIndex = j
if minIndex != i:
temp = A[i]
A[i] = minValue
A[minIndex] = temp
count = count + 1
for i in range(N):
print A[i],
print
print count
N = input()
A = map(int, raw_input().split())
selectionSort(A, N) | 0 | null | 23,579,720,205,884 | 191 | 15 |
def linearSearch(key, list, N):
l = list + [key]
i = 0
while l[i] != key:
i += 1
return int(i != N)
N1 = int(input())
arr1 = [int(n) for n in input().split()]
N2 = int(input())
arr2 = [int(n) for n in input().split()]
print(sum([linearSearch(key, arr1, N1) for key in arr2]))
| cnt = 0
x = int(input())
m = 100
for i in range(4000):
if m >= x:
print(i)
exit()
else:
m += m//100
| 0 | null | 13,563,078,917,750 | 22 | 159 |
a, b, c = map(int, raw_input().split(' '))
num = 0
for i in range(a,b+1):
if c % i == 0:
num = num + 1
print(num) | # -*- coding: utf-8 -*-
n, m= [int(i) for i in input().split()]
for i in range(0,m):
if n-2*i-1>n/2 or n%2==1:
print(i+1,n-i)
else:
print(i+1,n-i-1) | 0 | null | 14,600,081,972,630 | 44 | 162 |
f = lambda x: x if p[x]<0 else f(p[x])
N,M = map(int,input().split())
p = [-1]*N
for _ in range(M):
A,B = map(lambda x:f(int(x)-1),input().split())
if A==B: continue
elif A<B: A,B=B,A
p[A] += p[B]
p[B] = A
print(sum(i<0 for i in p)-1) | 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 = 10 ** 9 + 7
N = 2 * 10 ** 6 # 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)
X, Y = map(int, input().split())
#(1, 2)の回数をn, (2, 1)の回数をmとする。
n = (-X + 2 * Y) / 3
m = (-Y + 2 * X) / 3
#いけない場合を除外
if n % 1 != 0:
print(0)
quit()
elif m % 1 != 0:
print(0)
quit()
#n + m C nで答え
ans = cmb(int(n + m), int(n), p)
print(ans)
| 0 | null | 76,098,530,931,488 | 70 | 281 |
N = int(input())
As = list(map(int,input().split()))
if(N == 0):
if(As[0] == 1):
print(1)
else:
print(-1)
else:
flag = True
if(As[0] != 0):
flag = False
if(flag):
D = [[0]*3 for i in range(N+1)]
D[0] = [1,1,0] # mind maxD Ed
for i in range(1,N+1):
if(As[i] > 2*D[i-1][1]):
flag = False
break
else:
D[i][0] = max(0,D[i-1][0] - As[i])
D[i][1] = min(2*D[i-1][1] - As[i],1 << i)
D[i][2] = As[i]
if(flag):
D[N][1] = 0
maxcnt = 0
for i in range(N,-1,-1):
depthmax = D[i][1] + D[i][2]
maxcnt += depthmax
if(i > 0):
D[i-1][1] = min(D[i-1][1],depthmax)
print(maxcnt)
else:
print(-1)
| N = int(input())
A = [int(i) for i in input().split()]
L, R = [A[-1]], [A[-1]]
for i in range(1, N+1):
L.append((L[-1]+1)//2+A[-1-i])
R.append((R[-1]+A[-1-i]))
L = L[::-1]
R = R[::-1]
if L[0] >= 2:
print(-1)
exit()
ans = 1
p = 1
for i in range(1, N+1):
ans += min(p*2, R[i])
p = min(p*2, R[i])-A[i]
print(ans)
| 1 | 18,814,832,517,980 | null | 141 | 141 |
input()
s = set(map(int,input().split()))
n = int(input())
t = tuple(map(int,input().split()))
c = 0
for i in range(n):
if t[i] in s:
c += 1
print(c) | def main():
x, y = map(int, input().split())
mul_xy = x * y
while True:
x, y = y, x % y
if not y:
break
print(int(mul_xy / x))
if __name__ == '__main__':
main()
| 0 | null | 56,435,068,162,980 | 22 | 256 |
from collections import deque
H, W = [int(x) for x in input().split()]
field = []
for i in range(H):
field.append(input())
conn = [[[] for _ in range(W)] for _ in range(H)]
for i in range(H):
for j in range(W):
if field[i][j] == '.':
for e in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
h, w = i + e[0], j + e[1]
if 0 <= h < H and 0 <= w < W and field[h][w] == '.':
conn[i][j].append([h, w])
d = 0
for i in range(H):
for j in range(W):
l = 0
q = deque([[i, j]])
dist = [[-1 for _ in range(W)] for _ in range(H)]
dist[i][j] = 0
while q:
v = q.popleft()
for w in conn[v[0]][v[1]]:
if dist[w[0]][w[1]] == -1:
q.append(w)
dist[w[0]][w[1]] = dist[v[0]][v[1]] + 1
l = dist[w[0]][w[1]]
d = max(d, l)
print(d) | from collections import deque
import numpy as np
H,W = map(int,input().split())
maze = [input() for _ in range(H)]
ans = 0
for x in range(H):
for y in range(W):
if maze[x][y]=='#':
continue
dist = [[0]*W for i in range(H)]
Q = deque([[x,y]])
while Q:
h,w = Q.popleft()
for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:
h2,w2 = h+i,w+j
if 0<=h2<H and 0<=w2<W and dist[h2][w2]==0 and maze[h2][w2]!='#':
dist[h2][w2] = dist[h][w]+1
Q.append([h2,w2])
dist[x][y] = 0
ans = max(ans, np.max(dist))
print(ans) | 1 | 94,675,773,486,968 | null | 241 | 241 |
k = int(input())
s = str(input())
if len(s)>k:
print(s[:k]+"...")
else:
print(s[:k]) | def resolve():
x = int(input())
t = 0
pos = 100
while True:
pos += pos // 100
# print(t, pos)
t += 1
if pos >= x:
break
print(t)
resolve() | 0 | null | 23,430,681,078,830 | 143 | 159 |
stdin = [input() for i in range(3)]
line = stdin[0].split(' ')
A = int(line[0])
V = int(line[1])
line = stdin[1].split(' ')
B = int(line[0])
W = int(line[1])
T = int(stdin[2])
length = 0
if B > A:
length = B-A
else:
length = A-B
if (V-W)*T < length:
print('NO')
else:
print('YES') | A, V = list(map(int, input().split()))
B, W = list(map(int, input().split()))
T = int(input())
if A == B:
print("YES")
exit()
if V == W:
print("NO")
exit()
time = abs(A - B) / (V - W)
if 0 <= time and time <= T:
print("YES")
else:
print("NO")
| 1 | 15,233,808,133,128 | null | 131 | 131 |
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
def main():
t = input().strip()
s = []
# A = 0
ans = []
prevA = 0
for i in range(len(t)):
if t[i] == '\\':
s.append(i)
elif len(s) > 0 and t[i] == '/':
p = s.pop()
k = i - p
ans.append((p, k))
q = 0
while len(ans) > 0:
# print(ans)
g, h = ans[-1]
if g >= p:
q += h
ans.pop()
else:
break
# for j in range(len(ans) - len(s)):
# print('i: ', i)
# print('j: ', j)
# print('ans: ', ans)
# q += ans.pop()
# print('q: ', q)
if q != 0:
ans.append((p, q))
# elif len(s) > 0 and t[i] == '_':
# A += 1
v = 0
for i in range(len(ans)):
v += ans[i][1]
print(v)
print(len(ans), end='')
for i in range(len(ans)):
print(' {}'.format(ans[i][1]), end='')
print('')
if __name__ == '__main__':
main()
| # -*- coding: utf-8 -*-
l = input()
S1, S2 = [], []
sum = 0
n = len(l)
for i in range(n):
if l[i] == "\\":
S1.append(i)
elif l[i] == "/" and S1:
j = S1.pop()
a = i - j
sum += a
while S2 and S2[-1][0] > j:
a += S2.pop()[1]
S2.append([j, a])
print(sum)
print(len(S2), *(a for j, a in S2)) | 1 | 58,429,767,828 | null | 21 | 21 |
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
n,k=map(int,input().split())
A=sorted(list(map(int,input().split())))
F=sorted(list(map(int,input().split())),reverse=True)
# https://qiita.com/drken/items/97e37dd6143e33a64c8c#3-%E3%82%81%E3%81%90%E3%82%8B%E5%BC%8F%E4%BA%8C%E5%88%86%E6%8E%A2%E7%B4%A2%E3%81%AE%E3%81%95%E3%82%89%E3%81%AA%E3%82%8B%E5%88%A9%E7%82%B9
def is_ok(ind):
cnt=0
for i in range(n):
target=ind//F[i]
if target<A[i]:
cnt+=A[i]-target
if cnt<=k:
return True
else: return False
def bin_search_meguru():
"""
初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
まずis_okを定義すべし
ng, okは,とり得る最小の値-1,とり得る最大の値+1
"""
# 適当にいじる
ng = -1 # ind=0が条件を満たすこともあるため
ok = A[-1]*F[0]+1 # ind=len(a)-1が条件を満たさないこともあるため
# いじらない
# okとngのどちらが大きいかわからないことを考慮
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
val=bin_search_meguru()
print(val)
resolve() | from itertools import combinations
n,m,x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]
ans = float("inf")
for i in range(1, n+1):
for i1 in combinations(ca, i):
nums = [0]*(m+1)
for i2 in i1:
for i3 in range(m+1): nums[i3] += i2[i3]
if min(nums[1:]) >= x:
if nums[0] < ans: ans = nums[0]
if ans == float("inf"): print(-1)
else: print(ans) | 0 | null | 93,465,116,864,272 | 290 | 149 |
a=int(input())
b=0
c=int(a**(1/2))
for i in range(-1000,1000):
for j in range(-1000,1000):
if((i**5)-(j**5)==a):
b=1
break
if(b==1):
break
print(i,j) | N = int(input())
ans = 0
c = input()
redNum = c.count("R")
leftWhite = c.count("W", 0,redNum)
rightRed = c.count("R", redNum,N)
ans += min(leftWhite, rightRed)
if leftWhite > rightRed:
ans += (leftWhite - rightRed)
print(ans) | 0 | null | 15,821,109,638,148 | 156 | 98 |
s,t=map(str,input().split());print(t+s) | A = int(input())
B = int(input())
C = 6 - A - B
print(C) | 0 | null | 107,093,013,082,198 | 248 | 254 |
def resolve():
n = int(input())
s = input()
ans = ''
for i in s:
ans += chr(ord('A')+(ord(i)-ord('A')+n)%26)
print(ans)
resolve() | N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
P = [None] + P
C = [None] + C
all_max = C[1]
for st in range(1, N + 1):
p = P[st]
scores = [C[p]]
while p != st and len(scores) < K:
p = P[p]
scores.append(C[p])
num_elem = len(scores)
all_sum = sum(scores)
q, r = divmod(K, num_elem)
max_ = scores[0]
temp = scores[0]
max_r = scores[0]
temp_r = scores[0]
for x in range(1, num_elem):
if x < r:
temp_r += scores[x]
max_r = max(max_r, temp_r)
temp += scores[x]
max_ = max(max_, temp)
temp_max = scores[0]
if all_sum > 0 and q > 0:
if r > 0:
temp_max = max(all_sum * (q - 1) + max_, all_sum * q + max_r)
else:
temp_max = all_sum * (q - 1) + max_
else:
temp_max = max_
all_max = max(all_max, temp_max)
print(all_max)
| 0 | null | 69,998,576,924,432 | 271 | 93 |
n,m = map(int,input().split())
tbl=[[] for i in range(n)]
for i in range(n):
tbl[i] = list(map(int,input().split()))
tbl2=[[]*1 for i in range(m)]
for i in range(m):
tbl2[i] = int(input())
for k in range(n):
x=0
for l in range(m):
x +=tbl[k][l]*tbl2[l]
print("%d"%(x))
| from collections import Counter
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
result = []
for i in range(K):
result.append(T[i])
for j in range(K, N):
if result[j-K] == T[j]:
result.append("d")
else:
result.append(T[j])
result = Counter(result)
print(result["r"]*P+result["s"]*R+result["p"]*S)
| 0 | null | 53,734,010,069,698 | 56 | 251 |
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
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
def f(n):
for i in range(50,-1,-1):
if n>=(i*(i+1)//2):
return i
break
n=int(input())
cnt=0
alist=factorization(n)
for i in range(len(alist)):
cnt+=f(alist[i][1])
if n==1:
cnt=0
print(cnt) | n = int(input())
A = list(map(int,input().split()))
if 0 in A:
print(0)
exit()
A.sort(reverse=True)
cnt = A[0]
for a in A[1:]:
cnt *= a
if cnt > 10 ** 18:
cnt = -1
break
print(cnt) | 0 | null | 16,561,861,801,908 | 136 | 134 |
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
Ax = A1 * T1 + A2 * T2
Bx = B1 * T1 + B2 * T2
diff = abs(Ax - Bx)
if diff == 0:
print('infinity')
exit()
if not ((A1 * T1 > B1 * T1 and Ax < Bx) or (A1 * T1 < B1 * T1 and Ax > Bx)):
print(0)
exit()
ans = 2 * ((abs(B1 - A1) * T1) // diff)
if (abs(B1 - A1) * T1) % diff != 0:
ans += 1
print(ans)
| import sys
T1, T2, A1, A2, B1, B2 = map(int, sys.stdin.read().split())
a1, b1 = T1*A1, T1*B1
a2, b2 = T2*A2, T2*B2
sa, sb = a1+a2, b1+b2
if sa==sb:
print("infinity")
exit()
if sa < sb:
a1, a2, b1, b2, sa, sb = b1, b2, a1, a2, sb, sa
# 2*n-1 回以上出会うか
ok = 0
ng = 10**1800
a = 0
while ok+1 < ng:
c = (ok+ng)//2
if (c-1)*sa+a1 <= (c-1)*sb+b1:
if (c - 1) * sa + a1 == (c - 1) * sb + b1:
a = -1
ok = c
else:
ng = c
if ok > 10**1799:
print("a")
print("infinity")
else:
print(max(ok*2-1+a, 0))
| 1 | 131,580,547,886,808 | null | 269 | 269 |
N,K=map(int,input().split())
H=list(map(int,input().split()))
S=0
for h in H:
S+=h>=K
print(S) | n, k = list(map(int, input().split(' ')))
print(sum([tall >= k for tall in list(map(int, input().split(' ')))])) | 1 | 179,235,554,649,520 | null | 298 | 298 |
n = int(input())
A = [0]+list(map(int,input().split()))
d = {}
ans = 0
for i in range(1,n+1):
if i+A[i] not in d:
d[i+A[i]] = 1
else:
d[i+A[i]] += 1
if i-A[i] in d:
ans += d[i-A[i]]
print(ans) | from sys import maxsize
from itertools import product
n, k = map(int, input().split())
p = list(map(lambda x: int(x)-1, input().split()))
c = list(map(int, input().split()))
used = [0] * n
ss = []
for i in range(n):
if used[i]:
continue
now = i
s = []
while not used[now]:
used[now] = 1
s.append(c[now])
now = p[now]
ss.append(s)
res = -maxsize
for s in ss:
s_len = len(s)
cumsum = [0]
# 2周分の累積和
for i in range(2*s_len):
cumsum.append(cumsum[-1] + s[i%s_len])
max_sum = [-maxsize] * s_len
for i, j in product(range(s_len), repeat=2):
max_sum[j] = max(max_sum[j], cumsum[i+j] - cumsum[i])
for i in range(s_len):
if i > k:
continue
v = (k - i) // s_len
if i == 0 and v == 0:
continue
if cumsum[s_len] > 0:
res = max(res, max_sum[i] + cumsum[s_len] * v)
elif i > 0:
res = max(res, max_sum[i])
print(res)
| 0 | null | 15,757,535,943,028 | 157 | 93 |
#B
N = int(input())
A = list(sorted(map(int,input().split())))
ans=1
if A[0]==0:
print(0)
else:
for i in A:
ans*=i
if ans > 10**18:
ans =-1
break
print(ans) | # 解説を参考に作成
def solve():
N, M = map(int, input().split())
m = 0
# 奇数の飛び
oddN = M
oddN += (oddN + 1) % 2
for i in range(oddN // 2):
print(i + 1, oddN - i)
m += 1
if m == M:
return
# 偶数の飛び
for i in range(M):
print(oddN + i + 1, M * 2 + 1 - i)
m += 1
if m == M:
return
if __name__ == '__main__':
solve()
| 0 | null | 22,349,085,709,216 | 134 | 162 |
import sys
N, R = map(int, sys.stdin.buffer.read().split())
rate = R
if N < 10:
rate += 100 * (10 - N)
print(rate)
| a = str(input())
if a[0] == a[1] != a[2]:
print("Yes")
elif a[1] == a[2] != a[0]:
print("Yes")
elif a[0] == a[2] != a[1]:
print("Yes")
else:
print("No") | 0 | null | 58,801,687,224,980 | 211 | 201 |
# coding: utf-8
'''
S 1
H 3
H 7
C 12
D 8
'''
cards = ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10', 'S11', 'S12', 'S13',
'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9', 'H10', 'H11', 'H12', 'H13',
'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'C11', 'C12', 'C13',
'D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'D10', 'D11', 'D12', 'D13']
for _ in range(int(input())):
# suit, number = input().split()
suit, number = map(str, input().split())
cards.remove(suit + number)
for trump in cards:
print(trump[0], trump[1:])
| n=int(input())
lst=["1","2","3","4","5","6","7","8","9","10","11","12","13"]
#S_list=lst
#H_list=lst
#C_list=lst
#D_list=lst
S_list=["1","2","3","4","5","6","7","8","9","10","11","12","13"]
H_list=["1","2","3","4","5","6","7","8","9","10","11","12","13"]
C_list=["1","2","3","4","5","6","7","8","9","10","11","12","13"]
D_list=["1","2","3","4","5","6","7","8","9","10","11","12","13"]
for i in range(n):
Del=map(str,raw_input().split())
if Del[0]=="S":
S_list.remove(Del[1])
elif Del[0]=="H":
H_list.remove(Del[1])
elif Del[0]=="C":
C_list.remove(Del[1])
elif Del[0]=="D":
D_list.remove(Del[1])
S=map(int,S_list)
H=map(int,H_list)
C=map(int,C_list)
D=map(int,D_list)
#
for i in range(len(S)):
print "S "+str(S[i])
for i in range(len(H)):
print "H "+str(H[i])
for i in range(len(C)):
print "C "+str(C[i])
for i in range(len(D)):
print "D "+str(D[i]) | 1 | 1,028,618,825,312 | null | 54 | 54 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.