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
|
---|---|---|---|---|---|---|
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
a,b = input().split()
b = b[:-3] + b[-2:]
ans = int(a) * int(b)
ans = ans // 100
print(ans)
| from math import gcd
a,b = map(int,input().split())
lcm = a*b/gcd(a,b)
print(int(lcm)) | 0 | null | 64,926,373,700,784 | 135 | 256 |
n=int(input())
if n%10==7:
print("Yes")
exit()
n//=10
if n%10==7:
print("Yes")
exit()
n//=10
if n%10==7:
print("Yes")
exit()
print("No") | s=input()
s_list=list(s)
s_list.append('0')
for i in range(len(s)):
if s_list[i]=='?':
if s_list[i+1]=='D':
if s_list[i-1]=='P':
s_list[i]='D'
else:
s_list[i]='P'
elif s_list[i+1]=='?':
if s_list[i-1]=='P':
s_list[i]='D'
else :
s_list[i]='P'
else :
s_list[i]='D'
s_list.pop()
a="".join(s_list)
print(a) | 0 | null | 26,461,477,745,120 | 172 | 140 |
import sys
import functools
def minmaxsum(*t):
(x,y,z),e=t
if x > e:
x=e
if y < e:
y = e
z += e
return (x,y,z)
input()
m,x,s = functools.reduce(minmaxsum,map(int,input().split()),(1000000,-1000000,0\
))
print(m,x,s) | import math
a, b, x = [int(n) for n in input().split()]
v = a**2 * b /2
#print(v, x)
if v == x:
theta = math.atan(b/a)
elif v > x:
theta = math.atan(a*(b**2)/(2*x))
elif v < x:
theta = math.atan(2/a*(b-x/a**2))
print(math.degrees(theta))
| 0 | null | 81,887,360,625,216 | 48 | 289 |
# -*- coding:utf-8 -*-
def solve():
import math
a, b, x = list(map(int, input().split()))
if x > a*a*b/2:
s = x/a
# a*b-s = a*h*(1/2)
h = (a*b-s)*2/a
theta = math.atan2(h, a)
ans = math.degrees(theta)
print(ans)
else:
s = x/a
h = (s*2)/b
theta = math.atan2(h, b)
ans = 180-90-math.degrees(theta)
print(ans)
if __name__ == "__main__":
solve()
| r=input().split()
a=int(r[0])
b=int(r[1])
if a>=b:
ans=""
for i in range(a):
ans+=str(b)
print(int(ans))
else:
ans=""
for i in range(b):
ans+=str(a)
print(int(ans)) | 0 | null | 124,077,688,536,580 | 289 | 232 |
result = []
while True:
m, f, r = map(int, input().split())
if (m, f, r) == (-1, -1, -1):
break
if m == -1 or f == -1:
result.append('F')
continue
if m + f >= 80:
result.append('A')
if 80 > m + f >= 65:
result.append('B')
if 65 > m + f >= 50:
result.append('C')
if 50 > m + f >= 30:
result.append(['D', 'C'][r >= 50])
if 30 > m + f:
result.append('F')
for r in result:
print(r) | N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
import numpy as np
A0 = [0] + A
B0 = [0] + B
AA = np.cumsum(A0)
BB = np.cumsum(B0)
ans = 0
jmax = M
for i in range(0, N+1):
a = AA[i]
if a > K:
break
for j in range(jmax, -1, -1):
b = BB[j]
# print(a, b)
if a + b <= K:
ans = max(ans, i+j)
# print('ok')
break
jmax = j
print(ans) | 0 | null | 6,039,531,393,920 | 57 | 117 |
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal #変換後の末尾桁を0や0.01で指定
#Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########
n,k=map(int,input().split())
P=list(map(int,input().split()))
P=[i-1 for i in P]
C=list(map(int,input().split()))
ans=-inf
for i in range(n):
now=i
total=0
roop= 0
po=deque([0])
for kai in range(1,k+1):
now=P[now]
total += C[now]
roop+=1
po.append(total)
ans=max(ans, total)
if now == i:
la= kai;break
else: continue
if total<0 : continue
po=list(po)
ans=max(ans, total* (k//roop) + max(po[:k%roop+1]), total*(k//roop-1) + max(po))
#print(total, roop,po ,ans)
print(ans) | s = input()
k = int(input())
ans = 0
soui = 0
moji = s[0]
for i in range(1,len(s)):
if s[i] == s[i-1] and soui == 0:
ans += 1
soui = 1
elif soui == 1:
soui = 0
flag = 0
a = 0
b = 0
while s[0] == s[a] and a != len(s)-1:
a += 1
while s[len(s)-1-b] == s[len(s)-1] and b != len(s)-1:
b += 1
if s[0] == s[len(s)-1]:
flag = 1
for i in range(len(s)):
if moji != s[i]:
break
elif i == len(s)-1:
flag = 2
if flag == 1:
print((k*ans)-((k-1)*((a//2)+(b//2)-((a+b)//2))))
elif flag == 2:
print((k*len(s))//2)
else:
print(k*ans)
| 0 | null | 90,107,013,180,948 | 93 | 296 |
# coding: utf-8
# Your code here!
class dice(object):
def __init__(self, arr):
self.top = arr[0]
self.side_s = arr[1]
self.side_e = arr[2]
self.side_w = arr[3]
self.side_n = arr[4]
self.bottom = arr[5]
def roll(self, s):
if s=='S':
tmp = self.bottom
self.bottom = self.side_s
self.side_s = self.top
self.top = self.side_n
self.side_n = tmp
elif s=='E':
tmp = self.bottom
self.bottom = self.side_e
self.side_e = self.top
self.top = self.side_w
self.side_w = tmp
elif s=='W':
tmp = self.bottom
self.bottom = self.side_w
self.side_w = self.top
self.top = self.side_e
self.side_e = tmp
elif s=='N':
tmp = self.bottom
self.bottom = self.side_n
self.side_n = self.top
self.top = self.side_s
self.side_s = tmp
s = input().split()
# s = '1 2 4 8 16 32'.split()
dice = dice(s)
arr = input()
for a in arr:
dice.roll(a)
# print(type(dice))
print(dice.top)
| class Dice(object):
def __init__(self, List):
self.face = List
def n_spin(self, List):
temp = List[0]
List[0] = List[1]
List[1] = List[5]
List[5] = List[4]
List[4] = temp
def s_spin(self, List):
temp = List[0]
List[0] = List[4]
List[4] = List[5]
List[5] = List[1]
List[1] = temp
def e_spin(self, List):
temp = List[0]
List[0] = List[3]
List[3] = List[5]
List[5] = List[2]
List[2] = temp
def w_spin(self, List):
temp = List[0]
List[0] = List[2]
List[2] = List[5]
List[5] = List[3]
List[3] = temp
dice = Dice(map(int, raw_input().split()))
command = list(raw_input())
for c in command:
if c == "N":
dice.n_spin(dice.face)
elif c == "S":
dice.s_spin(dice.face)
elif c == "E":
dice.e_spin(dice.face)
elif c == "W":
dice.w_spin(dice.face)
print dice.face[0] | 1 | 232,325,772,742 | null | 33 | 33 |
N = int(input())
r = (N +2-1)//2
print(r)
| import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
N = I()
print(int(N/2) if N%2==0 else int(N/2)+1)
main()
| 1 | 59,119,135,263,000 | null | 206 | 206 |
n, m = map(int, raw_input().split())
c = map(int, raw_input().split())
INF = 1000000000
t = [INF] * (n + 1)
t[0] = 0
for i in range(m):
for j in range(c[i], n + 1):
t[j] = min([t[j], t[j - c[i]] + 1])
print(t[n]) | import math
x = int(input())
n = 100
y = 0
while x > n:
# 小数点以下切り捨て
n += n // 100
y += 1
print(y) | 0 | null | 13,704,569,404,732 | 28 | 159 |
import sys
N = int(sys.stdin.readline().rstrip())
sec = []
for _ in range(N):
x, l = map(int, sys.stdin.readline().rstrip().split())
sec.append((x - l, x + l))
sec = sorted(sec, key=lambda x: x[1])
r = -float("inf")
ans = 0
for s, t in sec:
if r <= s:
ans += 1
r = t
print(ans) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
L,R,d= map(int, readline().split())
print(R//d-(L-1)//d) | 0 | null | 48,559,680,248,592 | 237 | 104 |
import sys
input = sys.stdin.buffer.readline
def main():
N,K = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse=True)
l,r = -1,max(a)*max(f)+1
while r-l>1:
mid = (r+l)//2
count = 0
for cost,dif in zip(a,f):
if mid >= cost*dif:
continue
rest = cost*dif-mid
count += -(-rest//dif)
if count <= K:
r = mid
else:
l = mid
print(r)
if __name__ == "__main__":
main()
| n, k = map(int, input().split())
a_nums = list(map(int, input().split()))
f_point = sum(a_nums[:k])
for i in range(n - k):
if a_nums[i] < a_nums[i + k]:
print("Yes")
else:
print("No") | 0 | null | 85,711,438,867,222 | 290 | 102 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
n = I()
ans = 0
N = 10**7 + 1
prime = [True] * N
prime[1] = False
n_yaku = [1] * N
min_prime = [1] * N
for i in range(2, N):
if not prime[i]:
continue
n_yaku[i] = 2
min_prime[i] = i
num = i + i
while num < N:
min_prime[num] = i
prime[num] = False
num += i
for i in range(2, N):
if prime[i]:
continue
j = i
cnt = 0
while j % min_prime[i] == 0:
# print('j: ', j)
# print('prime: ', min_prime[i])
j //= min_prime[i]
cnt += 1
n_yaku[i] = n_yaku[j] * (cnt + 1)
ans = 0
for i in range(1, n+1):
ans += i * n_yaku[i]
print(ans)
main()
| import math
def S(i):
return ((i * (i+1)) // 2)
N = int(input())
ans = 0
sqrt_N = math.floor(math.sqrt(N))
for K in range(1, N+1, 1):
if((N // K) < sqrt_N):
break
# 個別に足す
ans += S(N // K) * K
for NdivK in range(1, sqrt_N, 1):
# [N // K]が等しいKの区間を求める
Kbegin = N // (NdivK + 1)
Kend = N // NdivK
ans += (S(NdivK) * (S(Kend) - S(Kbegin)))
print(ans) | 1 | 10,950,109,138,500 | null | 118 | 118 |
import sys
# input = sys.stdin.readline
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
s = [input() for _ in range(n)]
def bracket(x):
# f: final sum of brackets '(':+1, ')': -1
# m: min value of f
f = m = 0
for i in range(len(x)):
if x[i] == '(':
f += 1
else:
f -= 1
m = min(m, f)
# m <= 0
return f, m
def func(l):
# l = [(f, m)]
l.sort(key=lambda x: -x[1])
v = 0
for fi, mi in l:
if v + mi >= 0:
v += fi
else:
return -1
return v
l1 = []
l2 = []
for i in range(n):
fi, mi = bracket(s[i])
if fi >= 0:
l1.append((fi, mi))
else:
l2.append((-fi, mi - fi))
v1 = func(l1)
v2 = func(l2)
if v1 == -1 or v2 == -1:
ans = 'No'
else:
ans = 'Yes' if v1 == v2 else 'No'
print(ans)
| import sys
from functools import reduce
n=int(input())
s=[input() for i in range(n)]
t=[2*(i.count("("))-len(i) for i in s]
if sum(t)!=0:
print("No")
sys.exit()
st=[[t[i]] for i in range(n)]
for i in range(n):
now,mi=0,0
for j in s[i]:
if j=="(":
now+=1
else:
now-=1
mi=min(mi,now)
st[i].append(mi)
now2=sum(map(lambda x:x[0],filter(lambda x:x[1]>=0,st)))
v,w=list(filter(lambda x:x[1]<0 and x[0]>=0,st)),list(filter(lambda x:x[1]<0 and x[0]<0,st))
v.sort(reverse=True,key=lambda z:z[1])
w.sort(key=lambda z:z[0]-z[1],reverse=True)
#print(now2)
for vsub in v:
if now2+vsub[1]<0:
print("No")
sys.exit()
now2+=vsub[0]
for wsub in w:
if now2+wsub[1]<0:
print("No")
sys.exit()
now2+=wsub[0]
print("Yes") | 1 | 23,648,649,925,308 | null | 152 | 152 |
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
for i in range(1, N+1):
A[i] += A[i-1]
i = N
total = 0
ans = 0
for j in range(M+1):
total += B[j]
while i >= 0 and A[i]+total > K:
i -= 1
if A[i]+total <= K:
ans = max(ans, i+j)
print(ans) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')
INF = 10**9 + 7
def main():
N = in_n()
arms = [tuple()] * N
for i in range(N):
x, l = in_nn()
arms[i] = (x - l, x + l)
arms.sort(key=lambda x: x[1])
# print(arms)
r_max = -INF
count = 0
for i in range(N):
l, r = arms[i]
if r_max <= l:
r_max = r
count += 1
print(count)
if __name__ == '__main__':
main()
| 0 | null | 50,279,971,539,640 | 117 | 237 |
a=int(input())
hours=a//3600
minutes_num=a%3600
minutes=minutes_num//60
seconds=a%60
print(str(hours)+":"+str(minutes)+":"+str(seconds))
| S = int(input());print('{0}:{1}:{2}'.format(S//3600, S%3600//60, S%60))
| 1 | 332,822,908,000 | null | 37 | 37 |
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) | # D - String Equivalence
def dfs(s, mx):
if len(s)==n:
print(s)
return
for c in range(ord('a'),ord(mx)+1):
dfs(s+chr(c),(chr(ord(mx)+1) if ord(mx)==c else mx))
n=int(input())
dfs('','a')
| 0 | null | 40,476,236,457,860 | 162 | 198 |
a,b,k = map(int,input().split())
if a < k:
print(max(0,a-k),max(0,b+a-k))
else:
print(max(0,a-k),b)
| x, y = map(int, input().split())
money = [300000, 200000, 100000]
if x == 1 and y == 1:
print(1000000)
elif x <= 3 and y <= 3:
print(money[x - 1] + money[y - 1])
elif x <= 3:
print(money[x - 1])
elif y <= 3:
print(money[y - 1])
else:
print(0) | 0 | null | 122,446,845,901,024 | 249 | 275 |
K=int(input())
d=list(map(str,input().split()))
D=[]
for i in range(len(d[0])):
D.append(d[0][i])
if len(D)<=K:
print(''.join(D))
else:
print(d[0][0:K]+'...') | # 146A
S = input()
if S == 'SUN':
answer = (7)
elif S == 'MON':
answer = (6)
elif S == 'TUE':
answer = (5)
elif S == 'WED':
answer = (4)
elif S == 'THU':
answer = (3)
elif S == 'FRI':
answer = (2)
elif S == 'SAT':
answer = (1)
print(answer) | 0 | null | 75,973,381,550,852 | 143 | 270 |
def roll(l, command):
'''
return rolled list
l : string list
command: string
'''
res = []
i = -1
if command =='N':
res = [l[i+2], l[i+6], l[i+3], l[i+4], l[i+1], l[i+5]]
if command =='S':
res = [l[i+5], l[i+1], l[i+3], l[i+4], l[i+6], l[i+2]]
if command =='E':
res = [l[i+4], l[i+2], l[i+1], l[i+6], l[i+5], l[i+3]]
if command =='W':
res = [l[i+3], l[i+2], l[i+6], l[i+1], l[i+5], l[i+4]]
return res
faces = input().split()
commands = list(input())
for command in commands:
faces = roll(faces, command)
print(faces[0])
| # -*- coding: utf-8 -*-
from sys import stdin
class Dice:
def __init__(self,dicelist):
self.dice_list = dicelist
def roll(self, direction):
work = list(self.dice_list)
if (direction == 'N'):
self.dice_list[0] = work[1]
self.dice_list[1] = work[5]
self.dice_list[2] = work[2]
self.dice_list[3] = work[3]
self.dice_list[4] = work[0]
self.dice_list[5] = work[4]
elif (direction == 'E'):
self.dice_list[0] = work[3]
self.dice_list[1] = work[1]
self.dice_list[2] = work[0]
self.dice_list[3] = work[5]
self.dice_list[4] = work[4]
self.dice_list[5] = work[2]
elif (direction == 'S'):
self.dice_list[0] = work[4]
self.dice_list[1] = work[0]
self.dice_list[2] = work[2]
self.dice_list[3] = work[3]
self.dice_list[4] = work[5]
self.dice_list[5] = work[1]
elif (direction == 'W'):
self.dice_list[0] = work[2]
self.dice_list[1] = work[1]
self.dice_list[2] = work[5]
self.dice_list[3] = work[0]
self.dice_list[4] = work[4]
self.dice_list[5] = work[3]
def getTop(self):
return self.dice_list[0]
dice_list = list(map(int, stdin.readline().rstrip().split()))
dice = Dice(dice_list)
rolls = stdin.readline().rstrip()
for roll in rolls:
dice.roll(roll)
else:
print(dice.getTop())
| 1 | 233,736,734,300 | null | 33 | 33 |
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C
# Stable Sort
# Result:
# Modifications
# - modify inner loop start value of bubble_sort
# This was the cause of the previous wrong answer.
# - improve performance of is_stable function
import sys
ary_len = int(sys.stdin.readline())
ary_str = sys.stdin.readline().rstrip().split(' ')
ary = map(lambda s: (int(s[1]), s), ary_str)
# a is an array of tupples whose format is like (4, 'C4').
def bubble_sort(a):
a_len = len(a)
for i in range(0, a_len):
for j in reversed(range(i + 1, a_len)):
if a[j][0] < a[j - 1][0]:
v = a[j]
a[j] = a[j - 1]
a[j - 1] = v
# a is an array of tupples whose format is like (4, 'C4').
def selection_sort(a):
a_len = len(a)
for i in range(0, a_len):
minj = i;
for j in range(i, a_len):
if a[j][0] < a[minj][0]:
minj = j
if minj != i:
v = a[i]
a[i] = a[minj]
a[minj] = v
def print_ary(a):
vals = map(lambda s: s[1], a)
print ' '.join(vals)
def is_stable(before, after):
length = len(before)
for i in range(0, length):
for j in range(i + 1, length):
if before[i][0] == before[j][0]:
v1 = before[i][1]
v2 = before[j][1]
for k in range(0, length):
if after[k][1] == v1:
v1_idx_after = k
break
for k in range(0, length):
if after[k][1] == v2:
v2_idx_after = k
break
if v1_idx_after > v2_idx_after:
return False
return True
def run_sort(ary, sort_fn):
ary1 = list(ary)
sort_fn(ary1)
print_ary(ary1)
if is_stable(ary, ary1):
print 'Stable'
else:
print 'Not stable'
### main
run_sort(ary, bubble_sort)
run_sort(ary, selection_sort) | N = int(input())
C = input().split()
B = C[:]
S = C[:]
# bubble sort
flag = 1
while(flag):
flag = 0
for x in range(1, N):
if B[x][1:] < B[x-1][1:]:
B[x], B[x-1] = B[x-1], B[x]
flag = 1
# sectionSot
for x in range(0,N):
minj = x
for j in range(x,N):
if S[j][1:] < S[minj][1:]:
minj = j
if minj != x:
S[x], S[minj] = S[minj], S[x]
for i in range(1, N):
v = C[i]
j = i - 1
while(j >=0 and C[j][1:] > v[1:]):
C[j+1] = C[j]
j -= 1
C[j+1] = v
if(C == B):
print(" ".join(b for b in B))
print("Stable")
else:
print(" ".join(b for b in B))
print("Not stable")
if(C == S):
print(" ".join(b for b in S))
print("Stable")
else:
print(" ".join(b for b in S))
print("Not stable") | 1 | 25,156,654,370 | null | 16 | 16 |
def main():
input()
x, y = [list(map(int, input().split())) for _ in range(2)]
for p in (1, 2, 3):
distance = (sum(map(lambda i: i ** p, [abs(xi - yi) for xi, yi, in zip(x, y)]))) ** (1/p)
print('{:.5f}'.format(distance))
distance = max([abs(xi - yi) for xi, yi in zip(x, y)])
print('{:.5f}'.format(distance))
if __name__ == '__main__':
main()
| n, k = map(int, input().split())
price = sorted(list(map(int, input().split())))
min_price = 0
for i in range(k) :
min_price += price[i]
print(min_price) | 0 | null | 5,954,987,048,990 | 32 | 120 |
#173 A
N = int(input())
print(1000 - (N % 1000)) if N % 1000 != 0 else print(0) | h, w = map(int, input().split())
s = []
for _ in range(h):
s.append(input())
dp = [[h*w for i in range(w+1)] for j in range(h+1)]
dp[0][1] = 0
dp[1][0] = 0
for i in range(h):
for j in range(w):
# print("i", i, "j", j, "s[i][j]", s[i][j])
# print(s[i][j] == '#' and (i == 0 or s[i-1][j] == '.'))
#前の道が("."またはグリッド外)かつ現在地が#の場合に1を加える
#前の道が"#"であればまとめて変換できるので何も加えない
dp[i+1][j+1] = min(
dp[i][j+1] + (s[i][j] == '#' and (i == 0 or s[i-1][j] == '.')),
dp[i+1][j] + (s[i][j] == '#' and (j == 0 or s[i][j-1] == '.'))
)
print(dp[-1][-1])
| 0 | null | 29,045,235,694,980 | 108 | 194 |
from decimal import Decimal
def main():
a, b = input().split(" ")
a = int(a)
b = Decimal(b)
print(int(a*b))
if __name__ == "__main__":
main() | n=int(input())
rootn=int(n**(0.5))+1
m=10**20
for i in range(1,rootn):
if n/i==n//i:
m=min(m,i+n//i)
print(m-2) | 0 | null | 89,326,653,616,160 | 135 | 288 |
S = input()
if S == 'AAA' or S == 'BBB':
print('No')
else:
print('Yes') | def sep():
return map(int,input().strip().split(" "))
def lis():
return list(sep())
s=input()
from collections import Counter
c=Counter(s)
if len(c.keys())>=2:
print("Yes")
else:
print("No") | 1 | 54,803,396,899,552 | null | 201 | 201 |
x,y=map(int, input().split())
def gcd(x,y):
if x < y:
x,y = y,x
while y > 0:
r = x % y
x = y
y = r
return x
print(str(gcd(x,y))) | N, M = map(int, input().split())
A = list(map(int, input().split()))
memory = [10**6 for _ in range(N + 1)]
flg = [False for _ in range(N + 1)]
memory[0] = 0
flg[0] = True
for a in A:
m = 0
while m < len(memory) and m + a < len(memory):
if flg:
memory[m + a] = min(memory[m] + 1, memory[m + a])
flg[m + a] = True
m += 1
print(memory[-1])
| 0 | null | 76,451,331,230 | 11 | 28 |
"""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)
| #A
N=input()
hon=["2","4","5","7","9"]
pon=["0","1","6","8"]
if N[-1] in hon:
print('hon')
elif N[-1] in pon:
print('pon')
else:
print('bon') | 1 | 19,225,376,361,450 | null | 142 | 142 |
def solve(n):
ans = 0
for i in range(1, n+1):
m = n // i
ans += m * (m+1) * i // 2
return ans
n = int(input())
print(solve(n)) | n = int(input())
a = []
for _ in range(n):
a.append(list(map(int,input().split())))
d = [[a[i][0]-a[i][1],a[i][0]+a[i][1]] for i in range(n)]
d = sorted(d, key = lambda x: x[1])
#print(d)
b = [-100000000000000000]
c = [0]
for i in range(n):
for j in range(len(b)):
if d[i][0] >= b[j]:
b = [d[i][1]]
c = [c[j] + 1]
break
#print(b)
#print(c)
print(max(c))
| 0 | null | 50,624,057,956,612 | 118 | 237 |
ct=0
def merge(A,left,mid,right):
global ct
n1=mid-left
n2=right-mid
l=[A[left+i] for i in xrange(n1)]
r=[A[mid+i] for i in xrange(n2)]
l.append(float('inf'))
r.append(float('inf'))
i=0
j=0
for k in xrange(left,right):
ct+=1
if l[i]<=r[j]:
A[k]=l[i]
i=i+1
else:
A[k]=r[j]
j=j+1
def mergesort(A,left,right):
if left+1<right:
mid=(left+right)/2
mergesort(A,left,mid)
mergesort(A,mid,right)
merge(A,left,mid,right)
n=input()
s=map(int,raw_input().split())
mergesort(s,0,n)
i=0
s=map(str,s)
print(" ".join(s))
print(ct) | N = int(input())
A = set(map(int, input().split()))
if len(A) == N:
print('YES')
else:
print('NO') | 0 | null | 36,884,873,486,540 | 26 | 222 |
# E - Active Infants
N = int(input())
A = list(map(int,input().split()))
dp = [[] for _ in range(N+1)]
dp[0].append(0)
for i in range(N):
A[i] = [A[i],i+1]
A.sort(reverse=True)
for M in range(1,N+1):
Ai,i = A[M-1]
# x=0
dp[M].append(dp[M-1][0]+Ai*(N-(M-1)-i))
# 1<=x<=M-1
for x in range(1,M):
dp[M].append(max(dp[M-1][x-1]+Ai*(i-x),dp[M-1][x]+Ai*(N-(M-x-1)-i)))
# x=M
dp[M].append(dp[M-1][M-1]+Ai*(i-M))
print(max(dp[N])) | print('NYoe s'['111'in''.join(str(len({*t.split()}))for t in open(0))[1:]::2]) | 0 | null | 18,019,375,602,012 | 171 | 72 |
def yumiri(L, n):
for i in range(len(L)):
if L[i] > n:
return i - 1
def parunyasu(a, b, p, q):
reans = ans
rd1, rq1, d1, nd1, nq1, q1, newans = naobou(a, q, reans)
rd2, rq2, d2, nd2, nq2, q2, newans = naobou(b, p, newans)
if reans <= newans:
t[d1 - 1] = q1
t[d2 - 1] = q2
return newans
else:
ayaneru(rd2, rq2, d2, nd2, nq2)
ayaneru(rd1, rq1, d1, nd1, nq1)
return reans
def ayaneru(rd, rq, d, nd, nq):
ZL[rd].insert(rq, d)
del ZL[nd][nq + 1]
def naobou(d, q, ans):
newans = ans
rd = t[d - 1] - 1
rq = yumiri(ZL[rd], d)
newans += SUMD[ZL[rd][rq] - ZL[rd][rq - 1] - 1] * c[rd]
newans += SUMD[ZL[rd][rq + 1] - ZL[rd][rq] - 1] * c[rd]
newans -= SUMD[ZL[rd][rq + 1] - ZL[rd][rq - 1] - 1] * c[rd]
del ZL[rd][rq]
nd = q - 1
nq = yumiri(ZL[nd], d)
newans += SUMD[ZL[nd][nq + 1] - ZL[nd][nq] - 1] * c[nd]
newans -= SUMD[d - ZL[nd][nq] - 1] * c[nd]
newans -= SUMD[ZL[nd][nq + 1] - d - 1] * c[nd]
ZL[nd].insert(nq + 1, d)
newans -= s[d - 1][rd]
newans += s[d - 1][nd]
return rd, rq, d, nd, nq, q, newans
def rieshon():
ans = 0
for i in range(D):
ans += s[i][t[i] - 1]
for j in range(26):
if t[i] - 1 == j:
L[j] = 0
ZL[j].append(i + 1)
else:
L[j] += 1
ans -= L[j] * c[j]
for i in range(26):
ZL[i].append(D + 1)
return ans
import time
import random
startTime = time.time()
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
L = [0] * 26
ZL = [[0] for _ in range(26)]
SUMD = [0] * (D + 1)
for i in range(1, D + 1):
SUMD[i] = SUMD[i - 1] + i
RD = [0] * 26
t = [0] * D
for i in range(D):
RD[0] += 1
ma = s[i][0] + RD[0] * c[0]
man = 0
for j in range(1, 26):
RD[j] += 1
k = s[i][j] + RD[j] * c[j]
if k > ma:
ma = k
man = j
t[i] = man + 1
RD[man] = 0
ans = rieshon()
while time.time() - startTime < 1.8:
l = random.randrange(min(D - 1, 13)) + 1
d = random.randrange(D - l) + 1
p = t[d - 1]
q = t[d + l - 1]
if p == q: continue
ans = parunyasu(d, d + l, p, q)
for i in range(D):
print(t[i])
| from time import time
import random
start = time()
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
def cal_score(t):
S = 0
last = [-1] * 26
score = 0
for d in range(D):
S += s[d][t[d]]
last[t[d]] = d
for i in range(26):
S -= c[i] * (d - last[i])
score += max(10 ** 6 + S, 0)
return score
def main():
t = [random.randint(0, 25) for _ in range(D)]
score = cal_score(t)
while time()-start + 0.2 < 2:
d = random.randint(0, D-1)
q = random.randint(0, 25)
old = t[d]
t[d] = q
new_score = cal_score(t)
if new_score < score:
t[d] = old
else:
score = new_score
return t
if __name__ == "__main__":
ans = main()
for t in ans:
print(t+1) | 1 | 9,665,622,275,012 | null | 113 | 113 |
from itertools import accumulate
def bisect(ng, ok, judge, eps=1):
while abs(ng-ok) > eps:
m = (ng+ok)//2
if judge(m):
ok = m
else:
ng = m
return ok
N,M = map(int,input().split())
A = sorted(map(int,input().split()))
acc = [0]+list(accumulate(A))
def judge(p):
j = N
cnt = 0
for al in A:
while j > 0 and al+A[j-1] >= p:
j -= 1
cnt += N-j
return cnt <= M
p = bisect(0, A[-1]*2+1, judge)
j = N
cnt = 0
res = 0
nv = 0
max2 = lambda x,y: x if x > y else y
for al in A:
while j > 0 and al+A[j-1] >= p:
j -= 1
cnt += N-j
res += (N-j)*al + acc[-1]-acc[j]
if j > 0:
nv = max2(nv, al+A[j-1])
res += nv*(M-cnt)
print(res) | n=int(input())
cards = [[s+" "+str(n) for n in range(1,14)] for s in ["S","H","C","D"]]
for _ in range(n):
suit,num =input().split()
if suit=="S":
cards[0][int(num)-1]=0
elif suit=="H":
cards[1][int(num)-1]=0
elif suit=="C":
cards[2][int(num)-1]=0
elif suit=="D":
cards[3][int(num)-1]=0
for s in cards:
for n in s:
if n!=0:
print(n) | 0 | null | 54,468,901,918,660 | 252 | 54 |
import math
a,b = map(int,input().split())
gcd = math.gcd(a,b)
lcm = (a*b) // gcd
print(lcm) | from math import gcd
A,B = [int(i) for i in input().split()]
print(A*B//gcd(A,B))
| 1 | 113,499,204,977,400 | null | 256 | 256 |
import sys
input = sys.stdin.readline
a, b, c = map(int, input().split())
check = c - a - b
if check ** 2 > 4 * a * b and check > 0:
ans = 'Yes'
else:
ans = 'No'
print(ans)
| # -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
def solve():
n, k = [int(x) for x in input().split()]
R, S, P = [int(x) for x in input().split()]
s = input()
ans = 0
b = []
for i in range(n):
e = s[i]
if i < k or s[i] != s[i-k] or s[i-k] == b[i-k]:
if e == 'r':
ans += P
b.append('p')
elif e == 'p':
ans += S
b.append('s')
elif e == 's':
ans += R
b.append('r')
else:
b.append(e)
print(ans)
t = 1
# t = int(input())
for case in range(1,t+1):
ans = solve()
"""
R s
S p
P r
"""
| 0 | null | 79,138,500,231,940 | 197 | 251 |
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
total=0
for i in range(m):
if a[i]>=(sum(a)/(4*m)):
total+=1
if total==m:
print("Yes")
else:
print("No") | n,m = map(int,input().split())
v1 = [ list(map(int,input().split())) for i in range(n) ]
v2 = [ int(input()) for i in range(m) ]
for v in v1:
print( sum([ v[i] * v2[i] for i in range(m) ])) | 0 | null | 19,992,926,358,720 | 179 | 56 |
n,k = map(int,input().split())
mod = 10**9+7
from itertools import accumulate
N = list(range(n+1))
N_acc = [0]+list(accumulate(N))
ans = 0
for i in range(k,n+2):
ans += ((N_acc[-1]-N_acc[-i-1])-N_acc[i]+1)%mod
print(ans%mod) | a=int(input())
b=list(map(int,input().split()))
b.sort()
c=0
for i in range(a-1):
if b[i]==b[i+1]:
c=c+1
if c==0:
print("YES")
else:
print("NO") | 0 | null | 53,407,256,619,460 | 170 | 222 |
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
N = int(readline())
dp = [0] * 47
dp[0] = 1
dp[1] = 1
for i in range(2,N+1):
dp[i] = dp[i-1] + dp[i-2]
print(dp[N])
if __name__ == '__main__':
main()
| f = [1, 1] + [0] * (int(input()) - 1)
for i in range(2, len(f)):f[i] = f[i - 2] + f[i - 1]
print(f[-1])
| 1 | 2,295,470,022 | null | 7 | 7 |
def az15():
n = input()
xs = map(int,raw_input().split())
xs.reverse()
for i in range(0,len(xs)):
print xs[i],
az15() | import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
n, k = inm()
a = sorted(inl())
print(sum(a[:k])) | 0 | null | 6,300,211,283,520 | 53 | 120 |
N = int(input())
D = list(map(int,input().split()))
cnt = 0
for i in range(N):
cnt += D[i]**2
tot = 0
for i in range(N):
tot += D[i]
tot = tot**2
tot -= cnt
print(tot//2) | import re
import sys
INF=10000000000000
sys.setrecursionlimit(10**6)
def merge(A,left,mid,right):
count=0
L=A[left:mid]
R=A[mid:right]
L.append(INF)
R.append(INF)
i=0
j=0
for k in range(left,right):
if(L[i] <= R[j]):
A[k] = L[i]
i+=1
count+=1
else:
A[k] = R[j]
j+=1
count+=1
return count
def mergeSort(A,left,right):
count=0
if(left+1<right):
mid=(left+right)//2
count+=mergeSort(A, left, mid)
count+=mergeSort(A, mid, right)
count+=merge(A, left, mid, right)
return count
count=0
n=int(input())
s=list(map(int,input().split()))
count=mergeSort(s, 0, n)
print(re.sub("[\[\]\,]","",str(s)))
print(count)
| 0 | null | 84,413,397,071,368 | 292 | 26 |
n,k = map(int,input().split())
A = list(map(int,input().split()))
c = 0
from collections import Counter
d = Counter()
d[0] = 1
ans = 0
r = [0]*(n+1)
for i,x in enumerate(A):
if i>=k-1:
d[r[i-(k-1)]]-=1#ここで範囲kからはみ出たものの数を減らす
c = (c+x-1)%k
ans += d[c]
d[c] += 1
r[i+1] = c
print(ans) | N = int(input())
S = ["*"]*(N+1)
S[1:] = list(input())
Q = int(input())
q1,q2,q3 = [0]*Q,[0]*Q,[0]*Q
for i in range(Q):
tmp = input().split()
q1[i],q2[i] = map(int,tmp[:2])
if q1[i] == 2:
q3[i] = int(tmp[2])
else:
q3[i] = tmp[2]
class BIT:
def __init__(self, n, init_list):
self.num = n + 1
self.tree = [0] * self.num
for i, e in enumerate(init_list):
self.update(i, e)
#a_kにxを加算
def update(self, k, x):
k = k + 1
while k < self.num:
self.tree[k] += x
k += (k & (-k))
return
def query1(self, r):
ret = 0
while r > 0:
ret += self.tree[r]
r -= r & (-r)
return ret
#通常のスライスと同じ。lは含み、rは含まない
def query2(self, l, r):
return self.query1(r) - self.query1(l)
s_pos = [BIT(N+1,[0]*(N+1)) for _ in range(26)]
for i in range(1,N+1):
s_pos[ord(S[i]) - ord("a")].update(i,1)
alphabets = [chr(ord("a") + i) for i in range(26)]
for i in range(Q):
if q1[i] == 1:
s_pos[ord(S[q2[i]]) - ord("a")].update(q2[i],-1)
S[q2[i]] = q3[i]
s_pos[ord(q3[i]) - ord("a")].update(q2[i],1)
else:
ans = 0
for c in alphabets:
if s_pos[ord(c) - ord("a")].query2(q2[i],q3[i]+1) > 0:
ans += 1
print(ans)
| 0 | null | 99,534,118,236,832 | 273 | 210 |
def main():
H,W,M = map(int,input().split())
s = []
h_cnt = [0 for i in range(H)]
w_cnt = [0 for i in range(W)]
for i in range(M):
h,w = map(int,input().split())
s.append([h-1,w-1])
h_cnt[h-1] += 1
w_cnt[w-1] += 1
h_m,w_m = max(h_cnt), max(w_cnt)
h_mp,w_mp = [],[]
for i in range(H):
if h_cnt[i] == h_m:
h_mp.append(i)
for i in range(W):
if w_cnt[i] == w_m:
w_mp.append(i)
f = 0
for i in range(M):
if h_cnt[s[i][0]] == h_m and w_cnt[s[i][1]] == w_m:
f += 1
if len(w_mp)*len(h_mp)-f<1:
print(h_m+w_m-1)
else:
print(h_m+w_m)
if __name__ == "__main__":
main()
| #from random import randint
import numpy as np
def f(h,w,m,ins):
yp = np.zeros(h,dtype=np.int32)
xp = np.zeros(w,dtype=np.int32)
s = set()
for hi,wi in ins:
s.add((hi-1,wi-1))
yp[hi-1] += 1
xp[wi-1] += 1
ypm = yp.max()
xpm = xp.max()
yps = np.where(yp == ypm)[0].tolist()
xps = np.where(xp == xpm)[0].tolist()
ans = yp[yps[0]]+xp[xps[0]]
for ypsi in yps:
for xpsi in xps:
if not (ypsi,xpsi) in s:
return ans
return ans-1
if __name__ == "__main__":
if False:
while True:
h,w = randint(1,10**5*3),randint(10**5,10**5*3)
m = randint(1,min(h*w,10**5*3))
ins = [(randint(1,h),randint(1,w)) for i in range(m)]
ans = f(h,w,m,ins)
print(ans)
else:
h,w,m = map(int,input().split())
ans = f(h,w,m,[list(map(int,input().split())) for i in range(m)])
print(ans)
| 1 | 4,722,452,393,888 | null | 89 | 89 |
h, w, n = map(int, open(0))
print(0 - -n // max(h, w))
| div = 0
mod = 0
h = int(input())
w = int(input())
n = int(input())
if h > w:
div = n // h
mod = n % h
else:
div = n // w
mod = n % w
if mod > 0:
print(div+1)
else:
print(div) | 1 | 88,931,081,071,790 | null | 236 | 236 |
import math
K = int(input())
sum = 0
for i in range(1,K+1):
for j in range(1,K+1):
temp = math.gcd(i,j)
for k in range(1,K+1):
sum+=math.gcd(temp,k)
print (sum) | n = int(input())
a , b = input().split()
ans = ""
for i in range(n):
ans += a[i]
ans += b[i]
print(ans)
| 0 | null | 73,575,822,148,142 | 174 | 255 |
import sys
input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]
tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007
#+++++
def main():
#a = int(input())
#b , c = tin()
s = input()
if s[0] == '>':
s = '<' + s
if s[-1] == '<':
s = s + '>_'
else:
s = s + '_'
dd = []
pre = '<'
count = [1,0]
for c in s[1:]:
if c == '<' and pre == '<':
count[0] += 1
elif c == '>' and pre == '>':
count[1] += 1
elif c == '>' and pre == '<':
pre = '>'
count[1] = 1
elif c == '<' and pre == '>':
pre = '<'
dd.append(count)
count=[1,0]
else:
dd.append(count)
ret_sum = 0
for l, r in dd:
ret_sum += (r*(r+1)//2) + (l*(l+1)//2) - min(r,l)
print(ret_sum)
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text=clipboard.get()
input_l=input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform =='ios':
if input_method==input_methods[0]:
ic=input_clipboard()
input = lambda : ic.__next__()
elif input_method==input_methods[1]:
sys.stdin=open('inputFile.txt')
else:
pass
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret) | import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N =I()
_P= LI()
#AB = [LI() for _ in range(N)]
#A,B = zip(*AB)
P = np.array(_P)
#C = np.zeros(N + 1)
def main():
# count = 1
# # if (len(P)==1):
# # return count
# min_array =[P[0]]
# for i in range(1,N):
# if (P[i]<=min_array[i-1]):
# count += 1
# if P[i-1]>P[i]:
# min_array.append(P[i])
# else:
# min_array.append(P[i-1])
# return count
# print(min_array)
Q = np.minimum.accumulate(P)
count = np.count_nonzero(P <= Q)
return count
print(main())
# if ans:
# print('Yes')
# else:
# print('No') | 0 | null | 120,607,622,939,920 | 285 | 233 |
S = input()
hi = []
for i in range(5):
hi.append("hi"*(i+1))
print("Yes" if S in hi else "No") | S = str(input())
ans = 'Yes'
from collections import Counter
SC = Counter(list(S))
h,i = 0,0
for a,b in SC.items():
if a == 'h':
h = b
elif a == 'i':
i = b
else:
ans = 'No'
break
if h == i:
for i in range(0,len(S)-1,2):
if S[i]+S[i+1] != 'hi':
ans = 'No'
break
else:
ans = 'No'
print(ans) | 1 | 53,408,296,631,620 | null | 199 | 199 |
L = int(input())
L = L/3
V=1
for i in range (3):
V*=L
print (V)
| import sys
l = int(input())
print((l / 3)**3)
| 1 | 47,159,152,528,278 | null | 191 | 191 |
n = int(input())
s = [input() for _ in range(n)]
d = {}
for i in s:
if i not in d:
d[i] = 1
else:
d[i] += 1
m = max(d.values())
l = []
for i in d.keys():
if d[i] == m:
l.append(i)
l_s = sorted(l)
for i in l_s:
print(i) | N = int(input())
D = {}
for i in range(N):
S = input()
M = D.get(S)
if M == None:
D.update([(S, 1)])
else:
D.update([(S, M+1)])
E = list(D.keys())
F = list(D.values())
MA = max(F)
I = [i for i,x in enumerate(F) if x == MA]
ans =[]
for i in I:
ans.append(E[i])
ans = sorted(ans)
print('\n'.join(ans)) | 1 | 70,336,538,672,622 | null | 218 | 218 |
import sys
input = sys.stdin.readline
from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [0]
for a in A:
b = (B[-1] + (a-1)) % K
B.append(b)
ans = 0
dic = {}
for i, b in enumerate(B):
if b in dic:
dic[b].append(i)
else:
dic[b] = deque()
dic[b].append(i)
while len(dic[b]) > 0 and dic[b][0] <= i - K:
dic[b].popleft()
ans += len(dic[b])-1
print(ans) | x1, y1, x2, y2 = map(float,input().split())
a=((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
print(a)
| 0 | null | 69,172,500,195,088 | 273 | 29 |
N = int(input())
A_list = map(int, input().split())
# [活発度, もとの番号] のリストを降順に並べる
A_list = [[A, index] for index, A in enumerate(A_list)]
A_list.sort(reverse=True)
# print(A_list)
dp = [[0 for i in range(N+1)] for j in range(N+1)]
# print(dp)
for left in range(0, N):
for right in range(0, N - left):
# print(f'left, righte: { left, right }')
# print(A_list[left + right - 1][0])
activity = A_list[left + right][0]
distance_from_left = A_list[left + right][1] - left
# print(f'distance_from_left: { distance_from_left }')
distance_from_right = (N - 1 - right) - A_list[left + right][1]
# print(f'distance_from_right: { distance_from_right }')
dp[left + 1][right]\
= max(dp[left + 1][right],
dp[left][right] + activity * distance_from_left)
dp[left][right + 1]\
= max(dp[left][right + 1],
dp[left][right] + activity * distance_from_right)
# print('dp---')
# print(dp)
# print('---dp')
# print(dp)
dp_list = [flatten for inner in dp for flatten in inner]
print(max(dp_list)) | # -*- coding: utf-8 -*-
N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#-----
# A_index[i] = ( value of A , index of A)
A_index = [ (A_list[i], i) for i in range(len(A_list)) ]
A_index.sort(reverse=True)
# dp[left][right] = score
dp = [ [0]*(N+1) for _ in range(N+1) ]
for L in range(N):
for R in range(N-L):
i = L + R
append_L = dp[L][R] + A_index[i][0] * abs(L - A_index[i][1])
append_R = dp[L][R] + A_index[i][0] * abs((N-1-R) - A_index[i][1])
dp[L+1][R] = max(dp[L+1][R], append_L)
dp[L][R+1] = max(dp[L][R+1], append_R)
ans = max( [ dp[i][N-i] for i in range(N+1)] )
print(ans)
| 1 | 33,660,717,920,452 | null | 171 | 171 |
N = int(input())
P = list(map(int,input().split()))
n = float("INF")
count = 0
for i in P:
if n >= i:
n = i
count += 1
print(count) | n = int(input())
p = list(map(int, input().split()))
ans = 1
p_min = p[0]
for i in range(1,n):
if p_min >= p[i]:
ans += 1
p_min = min(p_min, p[i])
print(ans) | 1 | 85,397,709,063,872 | null | 233 | 233 |
import bisect
n=int(input())
lis=list(map(int, input().split()))
lis.sort()
out=0
for i in range(n):
for j in range(1+i,n):
out+=bisect.bisect_left(lis,lis[i]+lis[j])-j-1
print(out) | n = int(input())
A = list(map(int, input().split()))
dp = [0] * (n+1)
dp[2] = max(A[0], A[1])
s = A[0]
for i, a in enumerate(A, 1):
if i <= 2:
continue
if i%2: # 奇数
dp[i] = max(dp[i-1], a+dp[i-2])
s += a
else: # 偶数
dp[i] = max(a+dp[i-2], s)
print(dp[-1]) | 0 | null | 104,599,435,538,660 | 294 | 177 |
a, b = input().split()
print(sorted([a*int(b), b*int(a)])[0])
| # Comparing Strings
a, b = map(int, input().split())
a, b = min(a, b), max(a, b)
ans = ''.join([str(a) for e in range(b)])
print(ans)
| 1 | 84,583,115,234,760 | null | 232 | 232 |
alphabetlist=['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']
N=int(input())
S=[0 for i in range(0,N)]
string=''
for i in range(0,N):
string+='a'
print(string)
digit=N-1
while True:
if digit!=0:
if S[digit]==max(S[0:digit])+1:
digit-=1
else:
S[digit]+=1
for j in range(digit+1,N):
S[j]=0
digit=N-1
if S[0]==1:
break
string=[0 for i in range(0,N)]
for i in range(0,N):
string[i]=alphabetlist[S[i]]
print(''.join(string))
else:
break | def DFS(word,N):
if len(word)==n:print(word)
else:
for i in range(N+1):
DFS(word+chr(97+i),N+1 if i==N else N)
n=int(input())
DFS("",0) | 1 | 52,351,936,646,852 | null | 198 | 198 |
S = input()
T = input()
s = len(S)
t = len(T)
ans1 = 10000000
for i in range(s - t + 1):
ans = 0
for j in range(t):
if T[j] != S[i + j]:
ans += 1
ans1 = min(ans, ans1)
print(ans1)
| from itertools import combinations
N = int(input())
nums = list(map(int,input().split()))
tcount = 0
numset = set(nums)
comb = combinations(numset,3)
for i in list(comb):
a = i[0]
b = i[1]
c = i[2]
if(a+b>c and b+c>a and a+c>b):
tcount += nums.count(a)*nums.count(b)*nums.count(c)
print(tcount)
| 0 | null | 4,425,440,318,362 | 82 | 91 |
n = list(input())
tmp = 0
for i in n:
tmp += int(i) % 9
ans = "Yes" if tmp % 9 == 0 else "No"
print(ans)
| N = input()
answer = 0
for keta in N:
answer = (answer + int(keta))%9
if not answer:
print("Yes")
else:
print("No")
| 1 | 4,453,587,948,628 | null | 87 | 87 |
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A
# Stack
# Result:
import sys
class Stack:
def __init__(self):
self.store = []
def push(self, item):
self.store.append(item)
def pop(self):
if self.is_empty():
return None
return self.store.pop()
def is_empty(self):
if len(self.store) == 0:
return True
else:
return False
def __str__(self):
"""Show top to bottom"""
val = ''
for e in reversed(self.store):
val += str(e) + ' '
return val
def calculate(stack, func):
v2 = stack.pop()
v1 = stack.pop()
return func(v1, v2)
items = sys.stdin.readline().rstrip().split(' ')
stack = Stack()
for e in items:
if e == '+':
v = calculate(stack, lambda v1, v2: v1 + v2)
elif e == '-':
v = calculate(stack, lambda v1, v2: v1 - v2)
elif e == '*':
v = calculate(stack, lambda v1, v2: v1 * v2)
else:
# numbers
v = int(e)
stack.push(v)
print stack.pop() | s = input().split()
stack = []
for a in s:
if a == '+':
stack.append(stack.pop() + stack.pop())
elif a == '-':
stack.append(-(stack.pop() - stack.pop()))
elif a == '*':
stack.append(stack.pop() * stack.pop())
else:
stack.append(int(a))
print(stack[0]) | 1 | 37,074,458,576 | null | 18 | 18 |
from sys import stdin
def gcd(a, b):
while b != 0:
a, b = b, a%b
return a
def lcm(a, b):
return (a * b) // gcd(a, b)
readline = stdin.readline
num = int(readline())
d = list(map(int, readline().split()))
k = 1
MOD = 1000000007
ans = 0
for a in d:
k = lcm(k, a)
for a in d:
ans += k // a
print(ans % MOD) | def main_1_11_A():
values = list(map(int, input().split()))
query = input()
dice = Dice(values)
for d in query:
dice.roll(d)
def main_1_11_B():
values = list(map(int, input().split()))
n = int(input())
for _ in range(n):
t_value, s_value = map(int, input().split())
print(_B(values, t_value, s_value))
def _B(values, t_value, s_value):
"""
????????¢?????????????????¨??????
??´??¢???????????¢?????????????????§???????????????????????¨?????????
??????????????????????????¢???????¢??????????
"""
def rot_n(dice, n):
for _ in range(n):
dice.roll("N").roll("E").roll("S")
return dice
def make_dices():
# ?????¢???TOP?????????
return [
Dice(values),
Dice(values).roll("N"),
Dice(values).roll("N").roll("N"),
Dice(values).roll("N").roll("N").roll("N"),
Dice(values).roll("E"),
Dice(values).roll("W"),
]
dices = (
make_dices() +
list(map(lambda dice: rot_n(dice, 1), make_dices())) +
list(map(lambda dice: rot_n(dice, 2), make_dices())) +
list(map(lambda dice: rot_n(dice, 3), make_dices()))
)
for dice in dices:
# print(dice)
for d in ("E" * 4 + "W" * 4 + "S" * 4 + "N" * 4):
dice.roll(d)
#print(d, (dice.top_value, dice.south_value), (t_value, s_value))
if (dice.top_value, dice.south_value) == (t_value, s_value):
return dice.east_value
class Dice:
def __init__(self, values):
self.values = values
# top, bottom, direction 4
self.t = 1
self.b = 6
self.w = 4
self.e = 3
self.n = 5
self.s = 2
def __repr__(self):
labels = {
"t": self.t,
"b": self.b,
"w": self.w,
"e": self.e,
"n": self.n,
"s": self.s,
}
return "<%s (%s, %s)>" % (self.__class__, self.values, labels)
def roll(self, direction):
if direction == "E":
after_lables = self.t, self.b, self.e, self.w
self.e, self.w, self.b, self.t = after_lables
elif direction == "W":
after_lables = self.t, self.b, self.e, self.w
self.w, self.e, self.t, self.b = after_lables
elif direction == "S":
after_lables = self.t, self.b, self.n, self.s
self.s, self.n, self.t, self.b = after_lables
elif direction == "N":
after_lables = self.t, self.b, self.n, self.s
self.n, self.s, self.b, self.t = after_lables
return self
@property
def top_value(self):
return self.values[self.t - 1]
@property
def south_value(self):
return self.values[self.s - 1]
@property
def east_value(self):
return self.values[self.e - 1]
if __name__ == "__main__":
# main_1_11_A()
main_1_11_B() | 0 | null | 44,093,889,298,190 | 235 | 34 |
a, b, c = map(int, input().split())
if 4*a*b < (c-a-b)**2 and (c-a-b)>0:
print('Yes')
else:
print('No') | import math
n = int(input())
s = 0
for i in range(1,n+1):
for j in range(1,n+1):
for k in range(1,n+1):
s += math.gcd(math.gcd(i,j),k)
print(s)
| 0 | null | 43,555,060,647,098 | 197 | 174 |
A, B = map(int, input().split())
if A == B:
print('Yes')
else:
print('No') | A = int(input())
if A >= 30:
print('Yes')
else:
print('No') | 0 | null | 44,484,564,294,940 | 231 | 95 |
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n):
if p[i] - x >= 0:
p[i] = 2 * (p[i] - x)
else:
p[i] = (x - p[i]) * 2 - 1
p = sorted(p)
i = 0
while i in p:
i += 1
if i % 2 == 0:
j = round(i / 2) + x
else:
j = x - round((i + 1) / 2)
print(j) | n = input()
a = [int(x) for x in input().split()]
print(' '.join(str(x) for x in a[::-1])) | 0 | null | 7,528,649,924,988 | 128 | 53 |
def main():
N = int(input())
ans = 0
for x in range(1, N + 1):
# x(1+2+3+...+e)
e = N // x
ans += x * e * (1 + e) // 2
print(ans)
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inpl():
return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------
N = int(read())
ans = 0
for i in range(1, N+1):
n = N // i
ans += 0.5 * n * (2*i + i * (n-1))
print(int(ans))
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
| 1 | 10,965,055,552,682 | null | 118 | 118 |
N=int(input())
c=str(input())
num_R = c.count("R")
num_W = 0
ans = []
if num_R >= num_W:
ans.append(num_R)
else:
ans.append(num_W)
#print(ans)
for i in range(len(c)):
if c[i] == "R":
num_R -= 1
else:
num_W += 1
if num_R >= num_W:
ans.append(num_R)
else:
ans.append(num_W)
#print(ans)
print(min(ans))
| n,k =map(int, input().split())
h = list(map(int, input().split()))
# n = int(input())
# s = [map(int, input()) for i in range(3)]
count = 0
for i in range (0,n):
if h[i] < k:
count+=1
print(n-count)
| 0 | null | 92,967,658,378,858 | 98 | 298 |
n = int(input())
ans = sum(x for x in range(1, n+1) if x % 3 != 0 and x % 5 != 0)
print(ans)
| n = int(input())
sum = (1 + n) * n // 2
sho_3 = n // 3
sho_5 = n // 5
sho_15 = n // 15
s_3 = (sho_3 * 3 + 3) * sho_3 // 2
s_5 = (sho_5 * 5 + 5) * sho_5 // 2
s_15 = (sho_15 * 15 + 15) * sho_15 // 2
print(sum - s_3 - s_5 + s_15)
| 1 | 35,050,779,965,350 | null | 173 | 173 |
cnt = int(input())
print("ACL" * cnt) | N, K = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
p.sort()
ans = 0
for i in range(K):
ans += p[i]
print(ans)
| 0 | null | 6,923,589,197,800 | 69 | 120 |
INF = 10**12
def warshall_floyd(d,n):
#d[i][j]: iからjへの最短距離
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
def main():
n,m,l = map(int, input().split())
d = [ [INF]*(n) for _ in range(n) ]
for _ in range(m):
a,b,c = map(int, input().split())
d[a-1][b-1] = c
d[b-1][a-1] = c
warshall_floyd(d, n)
d2 = [ [INF]*(n) for _ in range(n) ]
for i in range(n):
for j in range(n):
if d[i][j] <= l:
d2[i][j] = 1
warshall_floyd(d2,n)
ans = []
q = int(input())
for _ in range(q):
s,t = map(int, input().split())
dist = d2[s-1][t-1]
if dist == INF: dist = 0
ans.append(dist-1)
for a in ans:
print(a)
if __name__ == "__main__":
main() | from collections import Counter
n = int(input())
A = list(map(int, input().split()))
P = [i+a+1 for i,a in enumerate(A)]
Q = [j-a+1 for j,a in enumerate(A)]
cQ = Counter(Q)
ans = 0
for p in P:
ans += cQ[p]
print(ans) | 0 | null | 99,854,645,866,992 | 295 | 157 |
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if a[0]*t[0]+a[1]*t[1]==b[0]*t[0]+b[1]*t[1]:
print('infinity')
elif a[0]*t[0]+a[1]*t[1]>b[0]*t[0]+b[1]*t[1]:
if a[0]*t[0]>b[0]*t[0]:
print(0)
elif a[0]*t[0]==b[0]*t[0]:
print(1)
else:
n=t[0]*(b[0]-a[0])
m=t[0]*(a[0]-b[0])+t[1]*(a[1]-b[1])
q=n//m
if n%m==0:
print(2*q)
else:
print(2*q+1)
else:
if a[0]*t[0]<b[0]*t[0]:
print(0)
elif a[0]*t[0]==b[0]*t[0]:
print(1)
else:
n=-t[0]*(b[0]-a[0])
m=-t[0]*(a[0]-b[0])-t[1]*(a[1]-b[1])
q=n//m
if n%m==0:
print(2*q)
else:
print(2*q+1) | H,W = map(int,input().split())
if(H == 1 or W == 1):
print("1")
elif((H*W)%2 == 0):
print(str((H*W)//2))
else:
print(str((H*W)//2+1)) | 0 | null | 91,540,271,191,260 | 269 | 196 |
# coding: utf-8
N = list(map(int,list(input())))
sN = sum(N)
if sN%9 ==0:
print("Yes")
else:
print("No")
| if __name__ == "__main__":
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
ans = 0
for i in T:
if i in S:
ans += 1
print(ans) | 0 | null | 2,235,826,923,538 | 87 | 22 |
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) | m={"S":[], "D":[], "H":[], "C":[]}
for i in range(int(input())):
mark, num=input().split()
m[mark].append(int(num))
for j in ["S", "H", "C", "D"]:
nai=set(range(1,14))-set(m[j])
for k in nai:
print(j, k) | 1 | 1,047,999,970,348 | null | 54 | 54 |
n=int(input())
n=n-1
a=[]
q=n//26
r=n%26
a.insert(0,r)
while q>=26:
q=q-1
r=q%26
a.insert(0,r)
q=q//26
a.insert(0,q-1)
b=[]
for i in range(len(a)):
x=int(a[i])
if x<0:
x=0
else:
x=chr(x+97)
b.append(x)
c="".join(b)
print(c) | def solve():
H,N = map(int,input().split())
ap = []
mp = []
for _ in range(N):
a,b = map(int,input().split())
ap.append(a)
mp.append(b)
ap_max = max(ap)
dp = [[float('inf')] * (H+ap_max+1) for _ in range(N+1)]
for i in range(N+1):
dp[i][0] = 0
for i in range(N):
for sum_h in range(H+ap_max+1):
dp[i+1][sum_h] = min(dp[i][sum_h-ap[i]] + mp[i], dp[i][sum_h])
dp[i+1][sum_h] = min(dp[i+1][sum_h-ap[i]] + mp[i], dp[i][sum_h])
ans = float('inf')
for sum_h in range(H, H+ap_max+1):
ans = min(ans,dp[N][sum_h])
print(ans)
if __name__ == '__main__':
solve() | 0 | null | 46,723,122,611,410 | 121 | 229 |
n=int(input())
s=input()
ans=0
for i in range(n-1):
if s[i]!=s[i+1]:
ans+=1
ans+=1
print(ans) | import sys
N = int(input())
p = list(map(int, input().split()))
for i in range(N):
if p[i] == 0:
print(0)
sys.exit()
product = 1
for i in range(N):
product = product * p[i]
if product > 10 ** 18:
print(-1)
sys.exit()
break
print(product) | 0 | null | 93,457,267,755,870 | 293 | 134 |
x1,y1,x2,y2 = map(float,input().split())
distance = ( (x1 - x2)**2 + (y1 - y2)**2 )**(1/2)
print('{}'.format(distance))
| import math
x1,y1,x2,y2=map(float,input().split())
A=abs(y1-y2)
B=abs(x1-x2)
C=math.sqrt(A**2+B**2)
print(f'{C:.8f}')
| 1 | 156,164,309,540 | null | 29 | 29 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
S = input()
n = 0
for s in S:
n += int(s)
if n%9 == 0:
print("Yes")
else:
print("No")
if __name__=='__main__':
main() | # -*- coding: utf-8 -*-
N, K = map(int, input().split())
kukan = list()
for i in range(K):
l, r = map(int, input().split())
kukan.append((l, r))
dp = [0] * (N+1)
dp[1] = 1
dp_sum = [0] * (N+1)
dp_sum[1] = 1
for i in range(0, N+1):
for j in range(K):
from_l = i - kukan[j][1]
from_r = i - kukan[j][0]
if from_r < 0:
continue
else:
from_l = max(1, from_l)
dp[i] += dp_sum[from_r] - dp_sum[from_l - 1]
dp[i] %= 998244353
dp_sum[i] = dp[i] + dp_sum[i-1]
print(dp[N] % 998244353) | 0 | null | 3,528,397,487,010 | 87 | 74 |
N = int(input())
zoro_count = 0
zoro = False
for n in range(N):
dn1,dn2 = map(int, input().split())
if dn1 == dn2:
zoro_count += 1
else:
zoro_count = 0
if zoro_count >= 3:
zoro = True
if zoro:
print('Yes')
else:
print('No') | def InsertSort(A, n, g, cnt):
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j -= g
cnt += 1
A[j+g] = v
return cnt
def ShellSort(A, n):
cnt = 0
G = [1]
h = G[0]
while True:
h = h*3 + 1
if h > n:
break
G.append(h)
print(len(G))
print(' '.join(reversed(list(map(str, G)))))
for h in reversed(G):
cnt = InsertSort(A, n, h, cnt)
print(cnt)
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
ShellSort(A, n)
for num in A:
print(num)
| 0 | null | 1,278,677,169,448 | 72 | 17 |
import itertools
N, M, Q = map(int, input().split())
a = []
b = []
c = []
d = []
for q in range(Q):
aq, bq, cq, dq = map(int, input().split())
a.append(aq)
b.append(bq)
c.append(cq)
d.append(dq)
max_answer = 0
for A in itertools.combinations_with_replacement(range(1, M + 1), N):
# print(A)
answer = 0
for i in range(Q):
# print(a[i], b[i], c[i], d[i])
if A[b[i]-1] - A[a[i]-1] == c[i]:
answer += d[i]
# print(answer)
if max_answer < answer:
max_answer = answer
print(max_answer) | # -*- coding: utf-8 -*-
from itertools import combinations_with_replacement
def main():
n, m, q = map(int, input().split())
xs = []
for i in range(q):
xs.append(list(map(int, input().split())))
max = 0
for suretu in combinations_with_replacement(range(1, m + 1), n):
wa = 0
for x in xs:
a, b, c, d = x
if suretu[b - 1] - suretu[a - 1] == c:
wa += d
if wa > max:
max = wa
print(max)
if __name__ == "__main__":
main()
| 1 | 27,577,383,796,328 | null | 160 | 160 |
N = int(input())
A = list(map(int,input().split()))
cnt = 0
for i in range(N):
minj = i
for j in range(i+1,N):
if A[j] < A[minj]:
minj = j
if i != minj:
A[i],A[minj] = A[minj],A[i]
cnt += 1
print(*A)
print(cnt)
| from collections import deque
def main():
n = int(input())
_next = [[] for _ in range(n)]
for _ in range(n):
u, k, *v = map(lambda s: int(s) - 1, input().split())
_next[u] = v
queue = deque()
queue.append(0)
d = [-1] * n
d[0] = 0
while queue:
u = queue.popleft()
for v in _next[u]:
if d[v] == -1:
d[v] = d[u] + 1
queue.append(v)
for i, v in enumerate(d, start=1):
print(i, v)
if __name__ == '__main__':
main()
| 0 | null | 11,711,749,786 | 15 | 9 |
from collections import deque
N,U,V = map(int, input().split())
U,V = U-1, V-1
E = [[] for _ in range(N)]
for _ in range(N-1):
a,b = map(int, input().split())
a,b = a-1, b-1
E[a].append(b)
E[b].append(a)
def BFS(root):
D = [ 0 for _ in range(N) ]
visited = [False for _ in range(N)]
willSearch = [ False for _ in range(N)]
Q = deque()
Q.append(root)
willSearch[root] = True
while len(Q) > 0:
now = Q.pop()
visited[now] = True
for nx in E[now]:
if visited[nx] or willSearch[nx]:
continue
willSearch[nx] = True
D[nx] = D[now] + 1
Q.append(nx)
return D
UD = BFS(U)
VD = BFS(V)
#print(UD)
#print(VD)
#初手で青木くんのPOINTにしか行けないケース
if E[U] == [V]:
print(0)
exit(0)
ans=0
for i in range(N):
if UD[i]<=VD[i]:
ans=max(ans,VD[i]-1)
print(ans) | # coding: utf-8
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
H, W, K = lr()
S = np.array([list(map(int, sr())) for _ in range(H)])
Scum = np.cumsum(S, axis=1)
INF = 10 ** 10
answer = INF
for pattern in range(1<<H-1):
cnt = 0
Tcum = Scum.copy()
for i in range(H-1):
if pattern>>i & 1: # 切れ目
cnt += 1
else:
Tcum[i+1] += Tcum[i]
prev = -1
w = 0
Tcum = Tcum.tolist()
while w < W:
cut = False
for i in range(H):
if Tcum[i][w] - (Tcum[i][prev] if prev >= 0 else 0) > K:
cut = True
break
if cut:
if prev == w - 1: # 1列でKをオーバー
break
cnt += 1
prev = w - 1
else:
w += 1
else:
answer = min(answer, cnt)
print(answer)
| 0 | null | 82,712,256,348,898 | 259 | 193 |
class Dice(object):
def __init__(self, s1, s2, s3, s4, s5, s6):
self.s1 = s1
self.s2 = s2
self.s3 = s3
self.s4 = s4
self.s5 = s5
self.s6 = s6
def east(self):
prev_s6 = self.s6
self.s6 = self.s3
self.s3 = self.s1
self.s1 = self.s4
self.s4 = prev_s6
def west(self):
prev_s6 = self.s6
self.s6 = self.s4
self.s4 = self.s1
self.s1 = self.s3
self.s3 = prev_s6
def north(self):
prev_s6 = self.s6
self.s6 = self.s5
self.s5 = self.s1
self.s1 = self.s2
self.s2 = prev_s6
def south(self):
prev_s6 = self.s6
self.s6 = self.s2
self.s2 = self.s1
self.s1 = self.s5
self.s5 = prev_s6
def rotate(self):
prev_s2 = self.s2
self.s2 = self.s4
self.s4 = self.s5
self.s5 = self.s3
self.s3 = prev_s2
def top(self):
return self.s1
def front(self):
return self.s2
def right(self):
return self.s3
s1, s2, s3, s4, s5, s6 = map(int, input().split())
dice = Dice(s1, s2, s3, s4, s5, s6)
q = int(input())
for i in range(q):
t, f = map(int, input().split())
flag = False
for j in range(6):
if j % 2 == 0:
dice.north()
else:
dice.west()
for k in range(4):
dice.rotate()
if dice.top() == t and dice.front() == f:
flag = True
break
if flag:
break
print(dice.right()) | def right(a,b,a1,a2,a3,a4,a5,a6):
b1=a6
b2=a5
b3=a4
b4=a3
b5=a2
b6=a1
if a>b:
tmp_a=a
a=b
b=tmp_a
if [a,b]==[a1,a2]:
right_side=[a3,b3]
elif [a,b]==[a1,a3]:
right_side=[a5,b5]
elif [a,b]==[a1,a4]:
right_side=[a2,b2]
elif [a,b]==[a1, a5]:
right_side=[a4,b4]
elif [a,b]==[a2, a3]:
right_side=[a1,b1]
elif [a, b]==[a2, a4]:
right_side=[a6,b6]
elif [a,b]==[a2,a6]:
right_side=[a3,b3]
elif [a,b]==[a3, a5]:
right_side=[a1,b1]
elif [a,b]==[a3, a6]:
right_side=[a5,b5]
elif [a, b]==[a4, a5]:
right_side=[a6,b6]
elif [a,b]==[a4,a6]:
right_side=[a2,b2]
elif [a,b]==[a5,a6]:
right_side=[a4,b4]
return right_side
initial=list( map(int,input().split()))
num_of_q=int(input())
for i in range(0, num_of_q):
a=list(map(int, input().split()))
flag=0
if a[0]>a[1]:
flag=1
answer=right(*a,*initial)
print(answer[flag])
| 1 | 255,079,961,410 | null | 34 | 34 |
val = [int(i) for i in input().split()]
result = 0
for i in range(val[0], val[1] + 1):
if val[2] % i == 0:
result += 1
print(result)
| x=int(input())
a=x//500
rem=x%500
b=rem//5
ans=a*1000+b*5
print(ans) | 0 | null | 21,589,124,667,100 | 44 | 185 |
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
def read_values():
return map(int, input().split())
def read_index():
return map(lambda x: x - 1, map(int, input().split()))
def read_list():
return list(read_values())
def read_lists(N):
return [read_list() for n in range(N)]
def functional(N, mod):
F = [1] * (N + 1)
for i in range(N):
F[i + 1] = (i + 1) * F[i] % mod
return F
INV = dict()
def inv(a, mod):
if a in INV:
return INV[a]
i = pow(a, mod - 2, mod)
INV[a] = i
return i
def C(F, a, b, mod):
return F[a] * inv(F[a - b], mod) * inv(F[b], mod) % mod
def main():
N, K = read_values()
mod = 10 ** 9 + 7
F = functional(5 * 10 ** 5, mod)
res = 0
if N <= K:
res = C(F, 2 * N - 1, N - 1, mod)
else:
for k in range(K + 1):
res += C(F, N, k, mod) * C(F, N - 1 , k, mod) % mod
print(res % mod)
if __name__ == "__main__":
main() | #coding:utf-8
#1_9_A 2015.4.12
w = input().lower()
c = 0
while True:
t = input().split()
if 'END_OF_TEXT' in t:
break
for word in t:
if w == word.lower():
c += 1
print(c) | 0 | null | 34,275,541,781,150 | 215 | 65 |
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**5)
def geta(fn=lambda s: s.decode()):
return map(fn, readline().split())
def gete(fn=lambda s: s.decode()):
return fn(readline().rstrip())
def main():
a, b, c = geta(int)
print("win" if sum([a, b, c]) <= 21 else "bust")
if __name__ == "__main__":
main() | A1, A2, A3 = map(int, input().split())
ans = A1 + A2 + A3
if ans > 21:
print('bust')
else:
print('win') | 1 | 118,441,903,960,468 | null | 260 | 260 |
dicpos = {}
dicneg = {}
N = int(input())
for i in range(N):
buf = [0]
for s in input():
if s=="(":
buf.append(buf[-1] + 1)
else:
buf.append(buf[-1] - 1)
low = min(buf)
last = buf[-1]
if last>0:
if low in dicpos:
dicpos[low].append(last)
else:
dicpos[low] = [last]
else:
if low-last in dicneg:
dicneg[low-last].append(-last)
else:
dicneg[low-last] = [-last]
neg_sorted = sorted(dicneg.items(), key=lambda x:x[0], reverse=True)
pos_sorted = sorted(dicpos.items(), key=lambda x:x[0], reverse=True)
#print(neg_sorted)
#print(pos_sorted)
summ = 0
flag = 0
for i in pos_sorted:
if flag == 1:
break
for j in i[1]:
if summ + i[0] < 0:
flag = 1
print("No")
break
summ += j
summ2 = 0
if flag == 0:
for i in neg_sorted:
if flag == 1:
break
for j in i[1]:
if summ2 + i[0] < 0:
flag = 1
print("No")
break
summ2 += j
if flag == 0:
if summ == summ2:
print("Yes")
else:
print("No") | n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
for i in range(10 ** (n - 1) - (n == 1), 10 ** n):
is_ok = True
for s, c in sc:
s -= 1
if int(str(i)[s]) != c:
is_ok = False
if is_ok:
print(i)
exit()
print(-1) | 0 | null | 42,473,696,017,280 | 152 | 208 |
def main():
n = input()
A = []
for i in xrange(n):
A.append(map(int,raw_input().split()))
c,d = bfs(n,A)
for i in xrange(n):
if c[i] == -1:
print i+1, -1
else:
print i+1, d[i]
def bfs(n,A):
color = [-1]*n
d = [-1]*n
Q = []
d[0] = 0
Q.append(0)
while(True):
if len(Q)==0:
break
u = Q.pop(0)
for i in A[u][2:]:
if color[i-1] == -1:
color[i-1] = 0
d[i-1] = d[u]+1
Q.append(i-1)
color[u] = 1
return color, d
if __name__ == '__main__':
main() | N = int(input())
E = [[] for _ in range(N+1)]
for _ in range(N):
tmp = list(map(int, input().split()))
if tmp[1] == 0:
continue
E[tmp[0]] = tmp[2:]
cnt = [0 for _ in range(N+1)]
q = [1]
while q:
cp = q.pop(0)
for np in E[cp]:
if cnt[np] != 0:
continue
cnt[np] = cnt[cp] + 1
q.append(np)
for ind, cost in enumerate(cnt):
if ind == 0:
continue
if ind == 1:
print(ind, 0)
else:
if cost == 0:
print(ind, -1)
else:
print(ind, cost)
| 1 | 3,977,215,970 | null | 9 | 9 |
A, B = [int(_) for _ in input().split()]
print(A * B)
| A, B = input().split()
A = int(A)
B = round(float(B) * 100)
ans = (A * B) // 100
print(int(ans)) | 1 | 15,881,559,933,308 | null | 133 | 133 |
def is_prime(x):
if x <= 1:
return False
i = 2
while i * i <= x:
if x % i == 0:
return False
i += 1
return True
cnt = 0
for _ in range(int(input())):
if is_prime(int(input())):
cnt += 1
print(cnt) | def is_prime(x):
if x == 2:
return True
if (x < 2) or (x%2 == 0):
return False
return all(x%i for i in xrange(3, int(x**(0.5) + 1), 2))
N = input()
print sum(is_prime(input()) for i in range(N)) | 1 | 10,481,742,378 | null | 12 | 12 |
N, K = map(int, input().split())
p = list(map(int, input().split()))
# サイコロ(1...p)の期待値は(1+p)/2
cum_sum = [0]
for i in range(0, N):
cum_sum.append(cum_sum[i] + (1 + p[i]) / 2)
# print(cum_sum)
# 調べる区間は[1,...,K],...,[N-K+1,...N]
ans = 0
for i in range(1, N - K + 2):
temp = cum_sum[i + K - 1] - cum_sum[i - 1]
# print(temp)
ans = max(ans, temp)
print(ans)
| N, K = map(int, input().split())
p = list(map(int, input().split()))
def calc(x):
return (x+1)/2
pe = []
for i in range(N):
pe.append(calc(p[i]))
cs = [pe[0]] + [0]*(N-1)
for i in range(1, N):
cs[i] = pe[i] + cs[i-1]
ans = cs[K-1]
for i in range(K, N):
wa = cs[i] - cs[i-K]
ans = max(ans, wa)
print(ans)
| 1 | 74,982,214,508,242 | null | 223 | 223 |
n = int(input())
A = [[] for i in range(n)]
for i in range(n):
A[i] = list(map(int, input().split()))
f_inf = float("inf")
B = [[f_inf for i in range(2)] for j in range(n)]
B[0][1] = 0
for i in range(n):
B[i][0] = i+1
def dbs(a):
global order
l = len(A[a-1])-2
if l:
for i in range(l):
depth = B[a-1][1]+1
b = A[a-1][i+2]
if not b in order or depth < B[b-1][1]:
B[b-1][1] = depth
order.append(b)
dbs(b)
order = [1]
dbs(1)
for i in range(n):
if B[i][1] == f_inf:
B[i][1] = -1
print(" ".join(map(str, B[i])))
| import queue
N=int(input())
M=[input().split()[2:]for _ in[0]*N]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while q.qsize()>0:
u=q.get()
for v in M[u]:
v=int(v)-1
if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[i])
| 1 | 4,026,650,780 | null | 9 | 9 |
INF = 10**18
N,M = map(int,input().split())
C = list(map(int,input().split()))
dp = [INF for _ in range(N+1)]
dp[0] = 0
for i in range(M):
for j in range(N+1):
if j-C[i] >= 0:
dp[j] = min(dp[j],dp[j-C[i]]+1)
print(dp[N])
|
N,M = map(int, input().split())
C = list(map(int, input().split()))
C.sort()
dp = [[float("inf") for _ in range(N+1)] for _ in range(M+1)]
dp[0][0] = 0
#i番目までのコインを使えるときに、j円を作る場合の、コインの最小枚数を求める
for i in range(M):
for j in range(N+1):
# i番目を使えない場合
if C[i] > j:
dp[i+1][j] = dp[i][j]
else:
dp[i+1][j] = min(dp[i][j], dp[i+1][j - C[i]] + 1)
print(dp[-1][-1])
| 1 | 139,005,160,782 | null | 28 | 28 |
a = input()
if a == "RSR":
print(1)
else :
print(a.count("R"))
| #!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys
INF = float('inf')
def solve(S: str):
return sum([S == "RRR", "RR" in S, "R" in S])
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = next(tokens) # type: str
print(f'{solve(S)}')
if __name__ == '__main__':
main()
| 1 | 4,875,296,506,548 | null | 90 | 90 |
import types
_atcoder_code = """
# Python port of AtCoder Library.
__version__ = '0.0.1'
"""
atcoder = types.ModuleType('atcoder')
exec(_atcoder_code, atcoder.__dict__)
_atcoder_dsu_code = """
import typing
class DSU:
'''
Implement (union by size) + (path compression)
Reference:
Zvi Galil and Giuseppe F. Italiano,
Data structures and algorithms for disjoint set union problems
'''
def __init__(self, n: int = 0):
self._n = n
self.parent_or_size = [-1] * n
def merge(self, a: int, b: int) -> int:
assert 0 <= a < self._n
assert 0 <= b < self._n
x = self.leader(a)
y = self.leader(b)
if x == y:
return x
if -self.parent_or_size[x] < -self.parent_or_size[y]:
x, y = y, x
self.parent_or_size[x] += self.parent_or_size[y]
self.parent_or_size[y] = x
return x
def same(self, a: int, b: int) -> bool:
assert 0 <= a < self._n
assert 0 <= b < self._n
return self.leader(a) == self.leader(b)
def leader(self, a: int) -> int:
assert 0 <= a < self._n
if self.parent_or_size[a] < 0:
return a
self.parent_or_size[a] = self.leader(self.parent_or_size[a])
return self.parent_or_size[a]
def size(self, a: int) -> int:
assert 0 <= a < self._n
return -self.parent_or_size[self.leader(a)]
def groups(self) -> typing.List[typing.List[int]]:
leader_buf = [self.leader(i) for i in range(self._n)]
result = [[] for _ in range(self._n)]
for i in range(self._n):
result[leader_buf[i]].append(i)
return list(filter(lambda r: r, result))
"""
atcoder.dsu = types.ModuleType('atcoder.dsu')
exec(_atcoder_dsu_code, atcoder.dsu.__dict__)
dsu = atcoder.dsu
#c
# from atcoder import dsu
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ds = dsu.DSU(n)
for i in ab:
ds.merge(i[0]-1,i[1]-1)
s = ds.groups()
print(len(s)-1) | class UnionFind():
# 作りたい要素数nで初期化
# 使用するインスタンス変数の初期化
def __init__(self, n):
self.n = n
# root[x]<0ならそのノードが根かつその値が木の要素数
# rootノードでその木の要素数を記録する
self.root = [-1]*(n+1)
# 木をくっつける時にアンバランスにならないように調整する
self.rnk = [0]*(n+1)
# ノードxのrootノードを見つける
def Find_Root(self, x):
if(self.root[x] < 0):
return x
else:
# ここで代入しておくことで、後の繰り返しを避ける
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
# 木の併合、入力は併合したい各ノード
def Unite(self, x, y):
# 入力ノードのrootノードを見つける
x = self.Find_Root(x)
y = self.Find_Root(y)
# すでに同じ木に属していた場合
if(x == y):
return
# 違う木に属していた場合rnkを見てくっつける方を決める
elif(self.rnk[x] > self.rnk[y]):
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
# rnkが同じ(深さに差がない場合)は1増やす
if(self.rnk[x] == self.rnk[y]):
self.rnk[y] += 1
# xとyが同じグループに属するか判断
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
# ノードxが属する木のサイズを返す
def Count(self, x):
return -self.root[self.Find_Root(x)]
n,m = map(int,input().split())
uf = UnionFind(n)
for i in range(m):
a,b = map(int,input().split())
a -= 1
b -= 1
uf.Unite(a,b)
s = set()
for i in range(n):
s.add(uf.Find_Root(i))
print(len(s)-1) | 1 | 2,320,241,310,270 | null | 70 | 70 |
a,b=map(int,input().split())
x=a%b
while x>0:
a=b
b=x
x=a%b
print(b)
|
x,y=map(int,input().split())
a=1
while a!=0:
if x>y:
a=x%y
else:
a=y%x
x=y
y=a
print(x)
| 1 | 8,366,390,190 | null | 11 | 11 |
i = raw_input().strip().split()
a = int(i[0])
b = int(i[1])
c = int(i[2])
if a < b and b < c:
print "Yes"
else:
print "No" | n = input().split()
n_int = list(map(int,n))
a = n_int[0]
b = n_int[1]
c = n_int[2]
if a < b < c:
print("Yes")
else:
print("No") | 1 | 383,505,165,182 | null | 39 | 39 |
x, y = list(map(int, input().split()))
a = 4 * x - y
b = y - 2 * x
if (a % 2 == 0 and a >= 0) and (b % 2 == 0 and b >= 0):
print('Yes')
else:
print('No') | X, Y = map(int, input().split())
x = 2*X-1/2*Y
y = -X + 1/2*Y
if x.is_integer() and y.is_integer() == True:
if x >= 0 and y >= 0:
print('Yes')
else:
print('No')
else:
print('No') | 1 | 13,800,758,333,820 | null | 127 | 127 |
a = int(input())
alist = list(map(int, input().split()))
mod = 10**9+7
total = sum(alist)
sumlist = []
ans = 0
for i in range(len(alist)-1):
total -= alist[i]
ans += alist[i]*(total)
print(ans%mod) | N = int(input())
num_list = [int(i) for i in input().split()]
result = 0
mod = 10 ** 9 + 7
right = sum(num_list)
for number in num_list:
#A*B + A * C = A*(B+C)で計算
right -= number
result += (number * right) % mod
print(result % mod) | 1 | 3,805,586,526,390 | null | 83 | 83 |
a, b = [int(i) for i in input().split(" ")]
num1 = a // b
num2 = a % b
num3 = "{:.8f}".format(a / b)
print(num1, num2, num3) | a,b = map(int, input().split())
print(f"{a//b} {a%b} {a/b:.5f}")
| 1 | 593,431,327,838 | null | 45 | 45 |
def func(K, X):
YEN = 500
ans = 'Yes' if YEN * K >= X else 'No'
return ans
if __name__ == "__main__":
K, X = map(int, input().split())
print(func(K, X))
| a,b,c,d=map(float,input().split())
e=(c-a)**2
f=(d-b)**2
print(f"{(e+f)**(1/2):.8f}")
| 0 | null | 49,342,308,882,368 | 244 | 29 |
a,b = list(map(int, input().split()))
print('%i %i %10.8f' %(a//b, a%b, a/b)) | import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
def solve(X):
s = 0
for i in range(N):
if A[i]*F[i]>X:
s += math.ceil((A[i]*F[i]-X)/F[i])
# print(X, s)
return s <= K
if sum(A) <= K:
print(0)
else:
l, r = 0, 10**12+10
while l+1<r:
mid = (l+r)//2
if solve(mid):
r = mid
else:
l = mid
print(r) | 0 | null | 82,712,214,664,508 | 45 | 290 |
pi = 3.14159265358979
r = float(raw_input())
print '%.6f %.6f'%(pi*r*r, 2*pi*r) | import math
r = float(raw_input())
print "%.5f %.5f" %(r**2*math.pi, 2*r*math.pi) | 1 | 639,470,732,900 | null | 46 | 46 |
import math
R=int(input())
l=2*math.pi*R
print(l) | N = int(input())
S = input()
if N % 2 == 1:
print("No")
else:
if S[:N // 2] == S[N // 2:]:
print("Yes")
else:
print("No")
| 0 | null | 89,042,956,241,700 | 167 | 279 |
def resolve():
N,K = map(int,input().split())
A = list(map(int,input().split()))
F= list(map(int,input().split()))
A.sort()
F.sort(reverse = True)
AF = list(zip(A,F))
if sum(A)<=K:
print(0)
return
l = 0
r = max([i*j for i,j in AF])
center =0
while l < r-1:
center = (l+r)//2
score =sum([max(0,a-center//f) for a,f in AF])
if score > K:
l = center
else:
r = center
print(r)
if __name__ == "__main__":
resolve() | from sys import stdin
input = stdin.readline
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
set_m = set([])
for i in range(2 ** n):
tmp = 0
for j in range(n):
if (i >> j) & 1:
tmp += A[j]
set_m.add(tmp)
for i in m:
if i in set_m:
print("yes")
else:
print("no")
| 0 | null | 82,218,751,496,860 | 290 | 25 |
from itertools import permutations
from math import factorial
N = int(input())
data = []
for _ in range(N):
x, y = map(int, input().split())
data.append((x,y))
res = 0
for a in permutations(data,N):
x0, y0 = a[0]
for x, y in a[1:]:
res += ((x-x0)**2 + (y-y0)**2)**(0.5)
x0, y0 = x, y
print(res/factorial(N)) | # coding: utf-8
count = int(input())
num = input().rstrip().split(" ")
min,max = int(num[0]),int(num[0])
sum = 0
for i in range(count):
sum = sum + int(num[i])
if int(min) > int(num[i]):
min = int(num[i])
if int(max) < int(num[i]):
max = int(num[i])
print(str(min) + " " + str(max) + " " + str(sum)) | 0 | null | 74,504,702,942,628 | 280 | 48 |
n, k = map(int, input().split())
lp = list(map(int, input().split()))
le = [(p + 1) / 2 for p in lp]
e = sum(le[:k])
m = e
for i in range(n - k):
e -= le[i]
e += le[k + i]
m = max(m, e)
print(m)
| import math
num1, num2 = map(int, input().split())
print(num1 * num2 // math.gcd(num1, num2)) | 0 | null | 94,523,840,933,590 | 223 | 256 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.