code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
|---|---|---|---|---|---|---|
import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
N,K = LI()
A = LI()
c = 0
d = collections.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
c = (c + x - 1) % K
ans += d[c]
d[c] += 1
r[i+1] = c
print(ans)
if __name__ == '__main__':
main()
|
import random
d=int(input())
C=[int(i) for i in input().split()]
s=[[int(i) for i in input().split()] for q in range(d)]
sco=0
L=[0 for i in range(26)]
ans=[]
#calc
for i in range(d):
mayou=random.choice(range(26))
est=s[i][mayou]+C[mayou]*(i+1-L[mayou])
ans.append(mayou)
L[mayou]=i+1
#print(mayou+1) #output
sco=est
##以下表示
"""
L=[0 for i in range(26)]
for q in range(d):
t=ans[q]
sco+=s[q][t]
L[t]=q+1
for i in range(26):
if L[i]!=-1:
sco-=C[i]*(q+1-L[i])
print(sco)
"""
m=1000000
for que in range(m):
newsco=sco
dn,q=random.choice(range(1,d)),random.choice(range(1,27))
dn-=1
q-=1
old=ans[dn]
ans[dn]=q
now=dn
cnt=1
while now!=0 and ans[now]!=old:
now-=1
cnt+=1
now=dn
while now!=d and ans[now]!=old:
newsco-=cnt*C[old]
now+=1
cnt+=1
newsco-=s[dn][old]
newsco+=s[dn][q]
now=dn
cnt=1
while now!=0 and ans[now]!=q:
now-=1
cnt+=1
now=dn
while now!=d and ans[now]!=q:
newsco+=cnt*C[q]
now+=1
cnt+=1
#print(newsco)
if newsco>sco:
sco=newsco
#print(newsco)
else:
ans[dn]=old
for ele in ans:
print(ele+1)
| 0
| null | 73,339,591,769,818
| 273
| 113
|
from collections import defaultdict
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
S = [0] * (N+1)
T = [0] * (N+1)
for i in range(N):
S[i+1] = (S[i] + A[i])%K
T[i+1] = (S[i+1] - (i+1))%K
rest = defaultdict(int)
for i in range(N+1):
if i < K:
ans += rest[T[i]]
rest[T[i]] += 1
else:
rest[T[i-K]] -= 1
ans += rest[T[i]]
rest[T[i]] += 1
print(ans)
|
from sys import stdin, setrecursionlimit
def main():
input = stdin.buffer.readline
print(int(input()) ** 2)
if __name__ == "__main__":
setrecursionlimit(10000)
main()
| 0
| null | 140,772,684,564,860
| 273
| 278
|
n = int(input())
A = list()
for i in range(0, n):
A.append(int(input()))
G = [1] # G[0]????????¨?????????
cnt = 0
# G[i] = 3*Gi-1 + 1
for i in range(1, 100):
h = 4**i + 3*2**(i-1) + 1
if(h > n): # h???n?¶???????????????§?????????4n+3*2n-1+1
m = i
break
else:
G.append(h)
for g in reversed(G):
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 = j - g
cnt += 1
A[j+g] = v
print(m)
print(" ".join(str(x) for x in reversed(G)))
print(cnt)
print("\n".join(str(x) for x in A))
|
_ = input()
S = input()
count = 0
for i in range(len(S)-2):
if S[i] + S[i+1] + S[i+2] == 'ABC':
count += 1
print(count)
| 0
| null | 49,400,391,691,178
| 17
| 245
|
n = int(input())
a = list(map(int, input().split()))
c = 1
ans = 0
for i in range(n):
if a[i] == c:
c += 1
else:
ans += 1
if c>1:
print(ans)
else:
print(-1)
|
N = int(input())
D = list(map(int, input().split()))
from itertools import combinations
ans = 0
for i , j in combinations(D,2):
ans += i*j
print(ans)
| 0
| null | 141,991,909,207,720
| 257
| 292
|
import sys
from io import StringIO
import unittest
import os
import math
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
# 0 = 1桁目
def digit_val(number, n) -> int:
return number // 10 ** n % 10
def max_digit_val(number) -> int:
return number // 10 ** int(math.log10(number)) % 10
def min_digit_val(number) -> int:
return number // 10 ** 0 % 10
def int_len(number) -> int:
return int(math.log10(number) + 1)
# 実装を行う関数
def resolve(test_def_name=""):
n = int(input())
# 対象となる数字の一覧を作成(1~20万の数字かつ、0を含まない数字)
target_list = []
ignore_cnt = 0
for i in range(1, n + 1):
ignore_cnt += 1
if ignore_cnt == 10:
ignore_cnt = 0
continue
target_list.append(i)
# 先頭X で末尾Y という数字がいくつ存在するか・・というカウンタを作成。
cnt_dict = {}
for i in target_list:
if int_len(i) == 1:
# 1桁目の場合は最初桁と最後桁が同じ
cnt_dict[i * 10 + i] = cnt_dict.get(i * 10 + i, 0) + 1
else:
val = max_digit_val(i) * 10 + min_digit_val(i)
cnt_dict[val] = cnt_dict.get(val, 0) + 1
# 使用できるパターンを足し込みしていく。
ans = 0
for i in target_list:
if int_len(i) == 1:
ans += cnt_dict.get(i * 10 + i, 0)
else:
val = min_digit_val(i) * 10 + max_digit_val(i)
ans += cnt_dict.get(val, 0)
print(ans)
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve(sys._getframe().f_back.f_code.co_name)
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """25"""
output = """17"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """1"""
output = """1"""
self.assertIO(test_input, output)
def test_input_3(self):
test_input = """100"""
output = """108"""
self.assertIO(test_input, output)
def test_input_4(self):
test_input = """2020"""
output = """40812"""
self.assertIO(test_input, output)
def test_input_5(self):
test_input = """200000"""
output = """400000008"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def tes_t_1original_1(self):
test_input = """データ"""
output = """データ"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
|
# C gacha
N = int(input())
goods = set()
cnt = 0
for i in range(N):
S = input()
if S not in goods:
goods.add(S)
cnt += 1
print(cnt)
| 0
| null | 58,255,463,453,500
| 234
| 165
|
n, m = map(int, input().split(' '))
A = []
i = 0
while i < n:
a = list(map(int, input().split(' ')))
A.append(a)
i += 1
x = []
j = 0
while j < m:
x.append(int(input()))
j += 1
ans = ''
p = 0
while p < n:
q = 0
a0 = 0
while q < m:
a0 += A[p][q] * x[q]
q += 1
ans += str(int(a0)) + '\n'
p += 1
print(ans[:-1])
|
n,m = [int(x) for x in input().split( )]
a = [[0 for x in range(m)] for y in range(n)]
b = []
for i in range(n):
retsu = [int(x) for x in input().split( )]
a[i] = retsu
for j in range(m):
b.append(int(input()))
answer = []
for i in range(n):
value = 0
for j in range(m):
value += a[i][j]*b[j]
answer.append(value)
for ans in answer:
print(ans)
| 1
| 1,162,984,349,912
| null | 56
| 56
|
# Stable Sort
length = int(input())
cards = input().rstrip().split()
cards1 = [card for card in cards]
cards2 = [card for card in cards]
def value(n):
number = n[1:]
return int(number)
def char(cards):
charSets = [[] for i in range(10)]
for i in range(length):
char = cards[i][:1]
val = value(cards[i])
# print('絵柄: ' + char + ', 数字: ' + str(val))
charSets[val].append(char)
return charSets
def bubble(cards):
for i in range(length):
j = length - 1
while j > i:
if value(cards[j]) < value(cards[j - 1]):
cards[j], cards[j - 1] = cards[j - 1], cards[j]
j -= 1
return cards
def selection(cards):
# count = 0
for i in range(length):
minj = i
for j in range(i, length):
if value(cards[j]) < value(cards[minj]):
minj = j
#if minj != i:
# count += 1
cards[i], cards[minj] = cards[minj], cards[i]
return cards
def stable(cards1, cards2):
if char(cards1) == char(cards2):
return 'Stable'
else:
return 'Not stable'
c = cards
b = bubble(cards1)
s = selection(cards2)
print(' '.join(b))
print(stable(c, b))
print(' '.join(s))
print(stable(c, s))
|
import sys
# input = sys.stdin.readline
def main():
N = int(input())
S = input()
if N %2 ==1:
print("No")
exit()
else:
half = int(N/2)
if S[0:half] *2== S:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| 0
| null | 73,079,398,931,792
| 16
| 279
|
n,m=map(int,input().split())
s=input()
x=n
a=[]
while x!=0:
for i in range(min(m,x),0,-1):
if s[x-i]=="0":a.append(i);break
if i==1:print(-1);exit()
x-=i
print(*a[::-1])
|
import copy
H, W, K, = list(map(int, input().split()))
C = [0] * H
for i in range(H):
C[i] = input()
C[i] = [1 if(C[i][j] == "#") else 0 for j in range(W)]
h = 2 ** H
w = 2 ** W
ans = 0
for i in range(2 ** H):
w = 2 ** W
for j in range(2 ** W):
D = copy.deepcopy(C)
for k in range(H):
for l in range(W):
if(bin(h)[k + 3] == "1" or bin(w)[l + 3] == "1"):
D[k][l] = 0
ans += (sum(map(sum, D)) == K)
w += 1
h += 1
print(ans)
| 0
| null | 74,027,854,962,784
| 274
| 110
|
N, X, M = map(int, input().split())
ans = 0
flag = [0]*(10**5 + 2)
lst = [X]
for i in range(N):
X = (X**2)%M
if flag[X] == 1:
break
flag[X] = 1
lst.append(X)
preindex = lst.index(X)
preloop = lst[:preindex]
loop = lst[preindex:]
loopnum = (N - len(preloop))//len(loop)
loopafternum = (N - len(preloop))%len(loop)
ans = sum(preloop) + sum(loop)*loopnum + sum(loop[:loopafternum])
print(ans)
|
N,X,M=map(int,input().split())
a=[0]*(M)
A=X%M
a[A]=1
ans=A
Ans=[A]
flag=0
for i in range(N-1):
A=A*A%M
if A==0:
break
if a[A]==1:
flag=1
break
a[A]=1
ans+=A
Ans.append(A)
if flag==1:
for num in range(len(Ans)):
if A==Ans[num]:
break
n=len(Ans)-num
b=sum(Ans[:num])
x=(N-num)//n
y=(N-num)%n
Sum=b+(ans-b)*(x)+sum(Ans[num:y+num])
else:
Sum=sum(Ans)
print(Sum)
| 1
| 2,840,460,591,628
| null | 75
| 75
|
# -*- coding: utf-8 -*-
#mitsui f
import sys
import math
import collections
#sys.setrecursionlimit(100000)
#n=int(input())
tmp = input().split()
t1,t2 = list(map(lambda a: int(a), tmp))
tmp = input().split()
a1,a2 = list(map(lambda a: int(a), tmp))
tmp = input().split()
b1,b2 = list(map(lambda a: int(a), tmp))
if(a1*t1+a2*t2==b1*t1+b2*t2):
print("infinity")
sys.exit()
diff=(a1*t1+a2*t2)-(b1*t1+b2*t2)
if(diff>0):
c1=a1-b1
c2=a2-b2
else:
c1=b1-a1
c2=b2-a2
if(c1>0):
print("0")
sys.exit()
diff=c1*t1+c2*t2
pitch=c1*t1*-1
ans=pitch//diff*2+1
if(pitch%diff==0):
ans-=1
print(ans)
|
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)
| 1
| 131,125,907,404,932
| null | 269
| 269
|
def resolve():
X = int(input())
m = 100
cnt = 0
while m < X:
m += m//100
cnt += 1
print(cnt)
if '__main__' == __name__:
resolve()
|
s = input()
n = len(s)
t = [0]*(n+1)
tmp=0
for i in range(n):
tmp+=1
if s[i]=="<":
t[i]=tmp-1
t[i+1]=tmp
else:
tmp=0
tmp=0
for j in range(n)[::-1]:
tmp+=1
if s[j]==">":
t[j+1]=max(tmp-1,t[j+1])
t[j]=max(tmp,t[j])
else:
tmp=0
#print(t)
print(sum(t))
| 0
| null | 91,628,849,880,480
| 159
| 285
|
print(int(int(input()) == 0))
|
K = ord(input())
print(chr(K+1))
| 0
| null | 47,496,895,905,788
| 76
| 239
|
#!/usr/bin/env python
def main():
N = int(input())
d = list(map(int, input().split()))
cumSum = [0] * N
cumSum[0] = d[0]
for i in range(1, N):
cumSum[i] = cumSum[i-1] + d[i]
ans = 0
for i in range(N-1):
ans += d[i] * (cumSum[N-1] - cumSum[i])
print(ans)
if __name__ == '__main__':
main()
|
n = int(input())
oi = list(map(int,input().split()))
total = 0
for i in range(n-1):
for j in range(i+1,n):
total += oi[i]*oi[j]
print(total)
| 1
| 168,361,867,608,142
| null | 292
| 292
|
n = int(input())
p = []
for i in range(n):
x,y = map(int,input().split())
p.append([x,y])
q = []
r = []
for i in range(n):
q.append(p[i][0]+p[i][1])
r.append(p[i][0]-p[i][1])
q.sort()
r.sort()
ans = max(abs(q[-1]-q[0]),abs(r[-1]-r[0]))
print(ans)
|
n = int(input())
plus,minus = [],[]
for i in range(n):
a,b = map(int,input().split())
plus.append(a+b)
minus.append(a-b)
plus.sort()
minus.sort()
print(max(plus[-1]-plus[0],minus[-1]-minus[0]))
| 1
| 3,423,169,629,296
| null | 80
| 80
|
#!/usr/bin/env python3
def main():
n = int(input())
ls = []
for i in range(n):
p = list(map(int, input().split()))
np = (p[0] + p[1], p[0] - p[1])
ls.append(np)
minx = float("inf")
miny = float("inf")
maxx = -float("inf")
maxy = -float("inf")
for i in range(len(ls)):
x, y = ls[i]
minx = min(minx, x)
miny = min(miny, y)
maxx = max(maxx, x)
maxy = max(maxy, y)
print(max(maxx - minx, maxy - miny))
main()
|
#!/usr/bin/env python3
import sys
import math
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def generate_primes(n):
if n < 2:
return []
is_prime_array = [True] * (n + 1)
is_prime_array[0], is_prime_array[1] = False, False
for i in range(2, n+1):
if is_prime_array[i]:
k = 2 * i
while k < n + 1:
is_prime_array[k] = False
k += i
return list(filter(lambda i: is_prime_array[i], range(n+1)))
def main():
N = II()
if N <= 1:
print(0)
exit()
max_prime = math.ceil(N**0.5)
primes = generate_primes(max_prime)
es = [0] * len(primes)
for i in range(len(primes)):
while N % primes[i] == 0:
N /= primes[i]
es[i] += 1
ans = 0
if int(N) != 1:
ans += 1
for i in range(len(es)):
k = 1
while es[i] - k >= 0:
es[i] -= k
k += 1
ans += 1
print(ans)
main()
| 0
| null | 10,209,557,398,980
| 80
| 136
|
import itertools
n, x, y = map(int, input().split())
k = [0] * n
for v in itertools.combinations(list(range(1,n+1)), 2):
k[min(abs(v[1]-v[0]),abs(x-min(v))+1+abs(y-max(v)))] += 1
for item in k[1:]:
print(item)
|
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
n, x, y = map(int, input().split())
x -= 1
y -= 1
dis = defaultdict(int)
for i1 in range(n):
for i2 in range(i1+1, n):
d = min(abs(i2-i1), abs(x-i1)+abs(y-i2)+1, abs(x-i2)+abs(y-i1)+1)
dis[d] += 1
for k1 in range(1, n):
print(dis[k1])
if __name__ == '__main__':
main()
| 1
| 44,354,811,894,158
| null | 187
| 187
|
import sys
input = sys.stdin.readline
def main():
n,a,b = [int(i) for i in input().strip().split()]
if (b-a) % 2 == 0:
print(abs(b - a) // 2)
else:
ans = min(a - 1, n - b) + 1 + (b - a - 1) // 2
print(ans)
return
if __name__ == "__main__":
main()
|
N = int(input())
As = list(map(int, input().split()))
height = 1
step = 0
for i in range(N):
if As[i] < height:
step += height - As[i]
else:
height = As[i]
print(step)
| 0
| null | 56,803,525,805,380
| 253
| 88
|
while True:
x, y = map(int, raw_input().split())
if x==0 and y==0:
break
if x<y:
print '%d %d' %(x, y)
else:
print '%d %d' %(y, x)
|
import math
daviations = []
while True:
num = int(input())
if num == 0:
break
scores = input().split()
for i in range(num):
scores[i] = float(scores[i])
avr = sum(scores) / num
daviation = 0
for a in scores:
disp = (a - avr)**2/num
daviation += disp
daviations.append(round(math.sqrt(daviation),8))
for b in daviations:
print(b)
| 0
| null | 362,990,216,812
| 43
| 31
|
import sys
input = sys.stdin.readline
# from collections import deque
def linput(_t=int):
return list(map(_t, input().split()))
def gcd(n,m):
while m: n,m = m, n%m
return n
def lcm(n,m): return n*m//gcd(n,m)
def main():
# N = int(input())
# vA = [int(input()) for _ in [0,]*N]
h,m,H,M,K = linput()
res = 60*H + M - 60*h - m - K
print(res)
# print(("No","Yes")[res%2])
# print(*vR, sep="\n")
main()
|
h1, m1, h2, m2, k = map(int, input().split())
st = h1 * 60 + m1
ed = h2 * 60 + m2
ans = ed - st - k
if ans < 0:
ans = 0
print(ans)
| 1
| 18,165,863,370,172
| null | 139
| 139
|
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
from math import ceil
t1, t2 = li()
a1, a2 = li()
b1, b2 = li()
# 交互になる
if (b1 - a1) * t1 + (b2 - a2) * t2 == 0:
print('infinity')
# 高橋君が先を行く
elif (b1 - a1) * t1 + (b2 - a2) * t2 < 0:
# ずっと高橋君の方が速い
if (b1 - a1) * t1 < 0 and (b2 - a2) * t2 < 0:
print(0)
# T2分間は追いつかれる
elif (b1 - a1) * t1 < 0 and (b2 - a2) * t2 > 0:
print(0)
# T1分間は追いつかれる
else:
cross = ceil((b1-a1)*t1 / ((a1-b1)*t1 + (a2-b2)*t2)) - 1
#print(((b1-a1)*t1 + (b2-a2)*t2) * (cross+1) + (a1-b1)*t1)
if ((a1-b1)*t1 + (a2-b2)*t2) * (cross+1) + (a1-b1)*t1 == 0:
print(2* (cross+ 1))
else:
print(2 * cross + 1)
# 高橋君が遅れる
else:
# ずっと高橋君のほうが遅い
if (b1 - a1) * t1 > 0 and (b2 - a2) * t2 > 0:
print(0)
# T2分間は追い上げる
elif (b1 - a1) * t1 > 0 and (b2 - a2) * t2 < 0:
print(0)
# T1分間は追い上げる
else:
cross = ceil((b1-a1)*t1 / ((a1-b1)*t1 + (a2-b2)*t2)) - 1
#print(((a1-b1)*t1 + (a2-b2)*t2) * (cross+1) + (a1-b1)*t1)
if ((a1-b1)*t1 + (a2-b2)*t2) * (cross+1) + (a1-b1)*t1 == 0:
print(2 * (cross + 1))
else:
print(2 * cross + 1)
|
T1,T2 = list(map(int,input().split()))
A1,A2 = list(map(int,input().split()))
B1,B2 = list(map(int,input().split()))
a1 = A1*T1
a2 = A2*T2
b1 = B1*T1
b2 = B2*T2
if a1+a2 < b1+b2:
a1,b1 = b1,a1
a2,b2 = b2,a2
#print(a1,a2,b1,b2)
if a1+a2 == b1+b2:
print('infinity')
else:
if a1 > b1:
print(0)
else:
c = (b1-a1)/((a1+a2)-(b1+b2))
print(int(c)*2 if c.is_integer() else int(c)*2+1)
| 1
| 131,028,398,157,020
| null | 269
| 269
|
L = int(input())
k = L/3
print(k**3)
|
L = int(input())
L /= 3
L **= 3
print(L)
| 1
| 46,996,217,473,230
| null | 191
| 191
|
n,k=map(int,input().split())
w=[0]*n
for i in range(n):
w[i] = int(input())
def hantei(w,a,k):
tumu=a
daime=1
for ww in w:
if ww<=tumu:
tumu-=ww
else:
tumu=a
daime+=1
if ww<=tumu:
tumu-=ww
else:
return False
if daime >k:
return False
else:
return True
right= max(w)*n +1
left = min(w)
while left<right:
mid = (left+right)//2
if hantei(w,mid,k):
right=mid
else:
left=mid+1
print(left)
|
def allocation():
n, k = map(int, input().split())
w = []
for i in range(n):
w.append(int(input()))
# 最大積載量pを算出
min = 0
max = 100000000000
while min + 1 != max:
mid =(min + max) // 2
if check(n, k, w, mid):
max = mid
else:
min = mid
print(max)
def check(n, k, w, p):
t = 0
now = 0
for i in range(n):
if (w[i] > p):
return False
if (now + w[i] > p):
t += 1
now = w[i]
else:
now += w[i]
if now > 0:
t += 1
if t > k:
return False
else:
return True
if __name__ == '__main__':
allocation()
| 1
| 82,951,275,232
| null | 24
| 24
|
ans = ["1","2","3"]
a,b = input(),input()
ans.remove(a)
ans.remove(b)
print(ans[0])
|
A = int(input())
B = int(input())
if A+B == 3:
print(3)
elif A+B == 4:
print(2)
else:
print(1)
| 1
| 110,121,315,730,778
| null | 254
| 254
|
a=list(map(int,input().split()))
k=int(input())
while a[0]>=a[1]:
k-=1
a[1]*=2
while a[1]>=a[2]:
k-=1
a[2]*=2
if k>=0:
print("Yes")
else:
print("No")
|
arr = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
arr1 = list(map(int,arr.split(", ") ))
k = int(input())
print(arr1[k-1])
| 0
| null | 28,337,674,060,160
| 101
| 195
|
N,K=map(int,input().split())
D=[0]*(K+1)
D[K]=1
mod=10**9+7
for i in range(K,0,-1):
D[i]=pow(K//i,N,mod)
for j in range(2*i,K+1,i):
D[i]=(D[i]-D[j])%mod
c=0
for i in range(len(D)):
c+=D[i]*i
print(c%mod)
|
def check(x, A, K):
import math
sumA = 0
for a in A:
if a > x:
sumA += math.ceil(a / x) - 1
if sumA <= K:
return True
else:
return False
def resolve():
_, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
ok = max(A) # maxVal when minimize
ng = -1 # maxVal when maximize
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if mid > 0 and check(mid, A, K):
ok = mid
else:
ng = mid
print(ok)
resolve()
| 0
| null | 21,652,328,884,718
| 176
| 99
|
a= list(map(int,input().split()))
n=a[0]
m=a[1]
if n==m:
print("Yes")
else:
print("No")
|
def main():
n ,m = map(int, input().split(" "))
if n == m:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| 1
| 83,488,192,482,338
| null | 231
| 231
|
MOD = 998244353
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]
def main():
N, S = ZZ()
A = ZZ()
dp = [[0] * (S+1) for _ in range(N + 1)]
dp[0][0] = 1
for i in range(N):
for j in range(S+1):
dp[i+1][j] += 2*dp[i][j]
if A[i] <= j <= S: dp[i+1][j] += dp[i][j-A[i]]
dp[i+1][j] %= MOD
print(dp[N][S])
return
if __name__ == '__main__':
main()
|
N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [[0 for j in range(S+1)] for i in range(N+1)]
dp[0][0] = 1
for i in range(N):
for j in range(S+1):
dp[i+1][j] += 2*dp[i][j]
dp[i+1][j] %= mod
if j + A[i] <= S:
dp[i+1][j+A[i]] += dp[i][j]
dp[i+1][j+A[i]] %= mod
print(dp[N][S])
| 1
| 17,612,531,098,812
| null | 138
| 138
|
N, K, S = map(int ,input().split())
if N == K:
A = [S] * N
elif S == 10**9:
A = [S]*K + [1]*(N-K)
elif K == 0:
A = [S+1] * N
elif S == 1:
A = [1]*K + [2]*(N-K)
else:
A = [S+1] * N
x = S // 2
y = S - x
for i in range(K+1):
if i%2 == 0:
A[i] = x
else:
A[i] = y
print(' '.join(map(str, A)))
|
a = int(input())
b = int(input())
ab = a + b
if ab == 3:
print(3)
elif ab == 4:
print(2)
else:
print(1)
| 0
| null | 100,955,150,431,760
| 238
| 254
|
import sys
from copy import copy
def main():
length = int(sys.stdin.readline())
given_cards = []
for i in range(length):
given_cards.append(sys.stdin.readline().strip())
cards = []
for i in ('S ', 'H ', 'C ', 'D '):
for j in range(13):
cards.append(i + str(j + 1))
for card in copy(cards):
if card in given_cards:
del cards[cards.index(card)]
for card in cards:
print(card)
return
if __name__ == '__main__':
main()
|
X = int(input())
for i in range(X, 9999999999999999):
flag = 1
for j in range(2, X//2 +1):
if i % j == 0:
flag = -1
break
if X == 2:
print(2)
break
elif X == 3:
print(3)
break
elif flag == 1:
print(i)
break
| 0
| null | 53,597,928,931,170
| 54
| 250
|
moji = input()
if moji.isupper() == True:
print("A")
else:
print("a")
|
r, c = map(int, input().split())
matrix = [list(map(int, input().split())) for _ in range(r)]
for i in range(r):
matrix[i].append(sum(matrix[i]))
matrix.append(list(map(sum, zip(*matrix))))
# matrix.append([sum(i) for i in zip(*matrix)])
for row in matrix:
print(' '.join(str(e) for e in row))
| 0
| null | 6,340,003,837,676
| 119
| 59
|
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
As = [0] * (n + 1)
Bs = [0] * (m + 1)
for i in range(n):
As[i + 1] = A[i] + As[i]
for i in range(m):
Bs[i + 1] = B[i] + Bs[i]
l = 0
r = n + m + 1
while r - l > 1:
p = (l + r) // 2
best = min(
As[i] + Bs[p - i] for i in range(p + 1)
if min(i, n) + min(p - i, m) == p
)
if best <= k:
l = p
else:
r = p
print(l)
|
N,K = map(int,input().split())
cc = list(map(int,input().split()))
memo = []
aa = ['.']*N
a = 1
while aa[a-1] == '.':
memo.append(a)
aa[a-1] = 'v'
a = cc[a-1]
if len(memo)>K:
print(memo[K])
else:
b = memo.index(a)
m = len(memo)-b
mm = (K-b) % m
del memo[:b]
print(memo[mm])
| 0
| null | 16,720,291,062,944
| 117
| 150
|
# import matplotlib.pyplot as plt
import math
def lcm(x, y):
if x > y:
z = x
else:
z = y
while(True):
if((z % x == 0) and (z % y == 0)):
lcm = z
break
z += 1
return lcm
X = int(input())
print(int(lcm(X, 360) / X))
|
[print("YES" if x[0] + x[1] == x[2] else "NO") for x in [sorted([x * x for x in [int(i) for i in input().split(" ")]]) for _ in range(int(input()))]]
| 0
| null | 6,516,275,620,930
| 125
| 4
|
n = int(input())
lst = []
for i in range(n):
x,l = map(int,input().split())
if x-l < 0:
# [右端の位置,左端の位置]
lst.append([x+l,0])
else:
lst.append([x+l,x-l])
lst.sort()
# [[6, 0], [7, 1], [12, 6], [105, 95]]
# 最初のロボットの選択
now = lst[0][0]
cnt = 1
idx = 1
for i in range(idx,n):
if now <= lst[i][1]:
now = lst[i][0]
cnt += 1
idx = i + 1
print(cnt)
|
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
A = []
for i in range(N):
x,l = X[i]
A.append((x-l,x+l))
B1 = sorted(A,key=lambda x:x[1])
B1 = [(B1[i][0],B1[i][1],i) for i in range(N)]
B2 = sorted(B1,key=lambda x:x[0])
hist = [0 for _ in range(N)]
cnt = 0
i = 0
for k in range(N):
if hist[k]==0:
r = B1[k][1]
hist[k] = 1
cnt += 1
while i<N:
l,j = B2[i][0],B2[i][2]
if hist[j]==1:
i += 1
continue
if l<r:
hist[j] = 1
i += 1
else:
break
print(cnt)
| 1
| 90,057,480,475,750
| null | 237
| 237
|
H,A=map(int,input().split())
if 1<=H<=10000 and 1<=A<=10000:
print(H//A+1 if H%A!=0 else int(H/A))
|
H,A = map(int,input().split())
b = H // A
c = H % A
if c != 0:
b += 1
print(b)
| 1
| 76,661,599,305,282
| null | 225
| 225
|
N=input()
ans=0
for i in range(1,int(N)+1):
if i%15==0:
pass
elif i%5==0:
pass
elif i%3==0:
pass
else:
ans=ans+i
print(ans)
|
N = int(input())
A = list(map(int, input().split()))
temp = 0
for a in A:
temp ^= a
ans =[]
for a in A:
ans.append(temp^a)
print(*ans)
| 0
| null | 23,845,156,449,490
| 173
| 123
|
# ????????????????????°????±???????????????°??????
import sys
import itertools
def main():
while True:
data = sys.stdin.readline().strip().split(' ')
n = int(data[0])
x = int(data[1])
if n == 0 and x == 0:
break
cnt = 0
for i in itertools.combinations(range(1, n+1), 3):
if sum(i) == x:
cnt += 1
print(cnt)
if __name__ == '__main__':
main()
|
max = [0,0,0]
for a in range(10):
s = int(input())
if max[0] < s:
max[2] = max[1]
max[1] = max[0]
max[0] = s
elif max[1] < s:
max[2] = max[1]
max[1] = s
elif max[2] < s:
max[2] = s
for a in max:
print(a)
| 0
| null | 651,724,310,260
| 58
| 2
|
a, b = map(int, input().split())
if a <= 2 * b:
x = 0
else:
x = a - 2 * b
print(int(x))
|
import itertools
n = int(input())
town = [list(map(int, input().split())) for _ in range(n)]
x = 1
for i in range(1, n+1):
x *= i
l = []
for j in range(n):
l.append(j)
ans = 0
for a in itertools.permutations(l, n):
newl = a
length = 0
for b in range(n-1):
length += ((town[newl[b]][0] - town[newl[b+1]][0])**2 + (town[newl[b]][1] - town[newl[b+1]][1])**2)**(1/2)
ans += length
print(ans/x)
| 0
| null | 157,509,312,072,100
| 291
| 280
|
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
C_A = Counter(A)
S = 0
for ca in C_A:
S += ca * C_A[ca]
Q = int(input())
for q in range(Q):
b, c = map(int,input().split())
S += (c - b) * C_A[b]
C_A[c] += C_A[b]
C_A[b] = 0
print(S)
|
#akash mandal: jalpaiguri government engineering college
import sys,math
def ii(): return int(input())
def mii(): return map(int,input().split())
def lmii(): return list(mii())
def main():
A,B,C=mii()
print("Yes" if B*C>=A else "No")
if __name__=="__main__":
main()
| 0
| null | 7,808,269,184,310
| 122
| 81
|
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 main():
n=int(input())
a=list(map(int,input().split()))
mod=pow(10,9)+7
lcma={}
for ai in a:
f=factorization(ai)
for fi in f:
if fi[0] in lcma:
lcma[fi[0]]=max(lcma[fi[0]],fi[1])
else:
lcma[fi[0]]=fi[1]
l=1
for k,v in lcma.items():
l*=pow(k,v,mod)
l%=mod
ans=0
for ai in a:
ans+=l*pow(ai,mod-2,mod)
ans%=mod
print(ans)
main()
|
n = int(input())
Building = [[[0 for r in range(11)] for f in range(4)] for b in range(5)]
for i in range(n):
b, f, r, v = map(int, input().split())
Building[b][f][r] += v
for b in range(1, 5):
for f in range(1, 4):
for r in range(1, 11):
print(" " + str(Building[b][f][r]), end = "")
print()
if b != 4:
print("####################")
| 0
| null | 44,304,604,534,342
| 235
| 55
|
n = int(input())
ans = 0
for a in range(1,n):
for b in range(1,n):
c = n-a*b
if c <= 0:
break
ans += 1
print(ans)
|
#from collections import deque
#from heapq import heapify, heappop, heappush
#from bisect import insort
#from math import gcd
#from decimal import Decimal
#mod = 1000000007
#mod = 998244353
#N = int(input())
#N, K = map(int, input().split())
#A = list(map(int, input().split()))
#flag = True
#for k in range(N):
#ans = 0
#print(ans)
#print('Yes')
#print('No')
N = int(input())
ans = 0
#N, K = map(int, input().split())
#A = list(map(int, input().split()))
#flag = True
for B in range(1, N+1):
ans += N//B
if N%B == 0:
ans -= 1
#ans = 0
print(ans)
#print('Yes')
#print('No')
| 1
| 2,568,043,280,892
| null | 73
| 73
|
N = int(input())
ans = 0
for i in range(1, 1+N):
if not (i%3 == 0 or i%5 == 0):
ans += i
print(ans)
|
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
def count_bigger_x(x):
cnt = 0
piv = N-1
for a in A:
while piv >= 0 and a + A[piv] >= x:
piv -= 1
cnt += N - piv - 1
return cnt
def is_ok(x):
cnt = count_bigger_x(x)
return cnt >= M
def bisect(ng, ok):
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
x = bisect(2 * A[-1] + 1, 2 * A[0] - 1)
ans = 0
piv = N-1
for a in A:
while piv >= 0 and a + A[piv] >= x:
piv -= 1
ans += (N - piv - 1) * a
ans *= 2
ans -= 1 * x * (count_bigger_x(x) - M)
print(ans)
| 0
| null | 71,529,096,348,062
| 173
| 252
|
def main():
from collections import defaultdict
from math import gcd
import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7
n = int(input())
fishes = defaultdict(int)
zero_zero = 0
zero = 0
inf = 0
for _ in range(n):
a, b = map(int, input().split())
if a == 0 and b == 0:
zero_zero += 1
elif a == 0:
zero += 1
elif b == 0:
inf += 1
else:
div = gcd(a, b)
a //= div
b //= div
if b < 0:
a *= -1
b *= -1
key = (a, b)
fishes[key] += 1
def get_bad_pair(fish):
a, b = fish
if a < 0:
a *= -1
b *= -1
return (-b, a)
ans = 1
counted_key = set()
for fish_key, count in fishes.items():
if fish_key in counted_key:
continue
bad_pair = get_bad_pair(fish_key)
if bad_pair in fishes:
pair_count = fishes[bad_pair]
pattern = pow(2, count, mod) + pow(2, pair_count, mod) - 1
counted_key.add(bad_pair)
else:
pattern = pow(2, count, mod)
ans = ans * pattern % mod
ans *= pow(2, zero, mod) + pow(2, inf, mod) - 1
if zero_zero:
ans += zero_zero
ans -= 1
print(ans % mod)
if __name__ == "__main__":
main()
|
from collections import deque
class SegmentTree():
def __init__(self,n,ide_ele,merge_func,init_val):
self.n=n
self.ide_ele=ide_ele
self.merge_func=merge_func
self.val=[0 for i in range(1<<n)]
self.merge=[0 for i in range(1<<n)]
self.parent=[-1 for i in range(1<<n)]
deq=deque([1<<(n-1)])
res=[]
while deq:
v=deq.popleft()
res.append(v)
if not v&1:
gap=(v&-v)//2
self.parent[v-gap]=v
deq.append(v-gap)
self.parent[v+gap]=v
deq.append(v+gap)
for v in res[::-1]:
if v-1<len(init_val):
self.val[v-1]=init_val[v-1]
self.merge[v-1]=self.val[v-1]
if not v&1:
gap=(v&-v)//2
self.merge[v-1]=self.merge_func(self.merge[v-1],self.merge[v-gap-1],self.merge[v+gap-1])
def update(self,id,x):
self.val[id]=x
pos=id+1
while pos!=-1:
if pos&1:
self.merge[pos-1]=self.val[pos-1]
else:
gap=(pos&-pos)//2
self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[pos+gap-1],self.merge[pos-gap-1])
pos=self.parent[pos]
def cnt(self,k):
lsb=(k)&(-k)
return (lsb<<1)-1
def lower_kth_merge(self,nd,k):
res=self.ide_ele
id=nd
if k==-1:
return res
while True:
if not id%2:
gap=((id)&(-id))//2
l=id-gap
r=id+gap
cnt=self.cnt(l)
if cnt<k:
k-=cnt+1
res=self.merge_func(res,self.val[id-1],self.merge[l-1])
id=r
elif cnt==k:
res=self.merge_func(res,self.val[id-1],self.merge[l-1])
return res
else:
id=l
else:
res=self.merge_func(res,self.val[id-1])
return res
def upper_kth_merge(self,nd,k):
res=self.ide_ele
id=nd
if k==-1:
return res
while True:
if not id%2:
gap=((id)&(-id))//2
l=id-gap
r=id+gap
cnt=self.cnt(r)
if cnt<k:
k-=cnt+1
res=self.merge_func(res,self.val[id-1],self.merge[r-1])
id=l
elif cnt==k:
res=self.merge_func(res,self.val[id-1],self.merge[r-1])
return res
else:
id=r
else:
res=self.merge_func(res,self.val[id-1])
return res
def query(self,l,r):
id=1<<(self.n-1)
while True:
if id-1<l:
id+=((id)&(-id))//2
elif id-1>r:
id-=((id)&(-id))//2
else:
res=self.val[id-1]
if id%2:
return res
gap=((id)&(-id))//2
L,R=id-gap,id+gap
#print(l,r,id,L,R)
left=self.upper_kth_merge(L,id-1-l-1)
right=self.lower_kth_merge(R,r-id)
return self.merge_func(res,left,right)
ide_ele=0
def seg_func(*args):
res=ide_ele
for val in args:
res|=val
return res
def popcount(x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
return x & 0x0000007f
import sys
input=sys.stdin.readline
N=int(input())
S=input().rstrip()
init_val=[1<<(ord(S[i])-97) for i in range(N)]
test=SegmentTree(19,ide_ele,seg_func,init_val)
for _ in range(int(input())):
t,l,r=input().split()
t,l=int(t),int(l)
if t==1:
val=ord(r)-97
test.update(l-1,1<<val)
else:
r=int(r)
res=test.query(l-1,r-1)
print(popcount(res))
| 0
| null | 41,769,120,549,380
| 146
| 210
|
N=int(input())
S=input()
if S[0:N//2]==S[N//2:N]:
print("Yes")
else:
print("No")
|
N = int(input())
ans = ""
while N > 0:
N -= 1
N, digit = divmod(N, 26)
ans += chr(ord('a') + digit)
print(ans[::-1])
| 0
| null | 79,392,724,639,552
| 279
| 121
|
N = int(input())
A = list(map(int, input().split()))
t = [-1] * (N + 1)
t[0] = 1000
for i in range(N):
k = t[i] // A[i]
y = t[i] % A[i]
for j in range(i, N):
t[j + 1] = max(t[j + 1], k * A[j] + y)
print(t[N])
|
N = int(input())
A = [int(i) for i in input().split()]
possess = 1000
for i in range(N-1):
if A[i] < A[i+1]:
stock = possess//A[i]
possess = possess % A[i] + A[i+1] * stock
print(possess)
| 1
| 7,335,914,906,540
| null | 103
| 103
|
def main():
K = int(input())
ans = False
if K % 2 == 0:
print(-1)
exit()
cnt = 7 % K
for i in range(1, K+1):
if cnt == 0:
ans = True
print(i)
exit()
cnt = (10 * cnt + 7) % K
if ans == False:
print(-1)
exit()
main()
|
N=int(input())
S=input()
print(bytes((s-65+N)%26+65 for s in S.encode()).decode())
| 0
| null | 70,207,430,682,180
| 97
| 271
|
N = int(input())
edge = [[] for _ in range(N+1)]
d = [0] * (N+1)
f = [0] * (N+1)
for i in range(N):
t = list(map(int, input().split()))
for j in range(t[1]):
edge[t[0]].append(t[j+2])
#print(1)
def dfs(v, t):
if d[v] == 0:
d[v] = t
t += 1
else:
return t
for nv in edge[v]:
t = dfs(nv, t)
if f[v] == 0:
f[v] = t
t += 1
return t
t = 1
for i in range(1,1+N):
if d[i] == 0:
t = dfs(i, t)
for i in range(1,1+N):
print(i, d[i], f[i])
|
for i in range(1, 100000):
num = int(input())
if num == 0:
break
print('Case ' + str(i) + ':', num)
| 0
| null | 239,531,031,542
| 8
| 42
|
import math
h=int(input())
print(2**(math.floor(math.log2(h))+1)-1)
|
h = int(input())
for i in range(100):
if 2**i > h:
print(2**i - 1)
exit()
| 1
| 80,178,957,742,300
| null | 228
| 228
|
while 1:
numbers = [i for i in raw_input()]
if numbers[0] == '0': break
print sum(map(int,numbers))
|
while True:
n = input()
if n == '0':
break
print(sum([int(x) for x in list(n)]))
| 1
| 1,574,972,380,322
| null | 62
| 62
|
seq = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input(""))
print(seq[k-1])
|
x=int(input())
i=0
ans=0
while(True):
i+=x
ans+=1
if(i%360==0):
print(ans)
break
| 0
| null | 31,645,775,423,108
| 195
| 125
|
st = str(input())
q = int(input())
com = []
for i in range(q):
com.append(input().split())
for k in com:
if k[0] == "print":
print(st[int(k[1]):int(k[2])+1])
elif k[0] == "reverse":
s = list(st[int(k[1]):int(k[2])+1])
s.reverse()
ss = "".join(s)
st = st[:int(k[1])] + ss + st[int(k[2])+1:]
else:
st = st[:int(k[1])] + k[3] + st[int(k[2])+1:]
|
def main():
m = list(input())
q = int(input())
A = []
for _ in range(q):
A.append(input().split())
for x in range(q):
if A[x][0] == "print":
A[x][1] = int(A[x][1])
A[x][2] = int(A[x][2])
for y in range(A[x][1], A[x][2] + 1):
if y != A[x][2]:
print(m[y], end = "")
else:
print(m[y])
elif A[x][0] == "reverse":
A[x][1] = int(A[x][1])
A[x][2] = int(A[x][2])
hoge = []
for y in range(A[x][1], A[x][2] + 1):
hoge.append(m[y])
hoge = hoge[::-1]
i = 0
for y in range(A[x][1], A[x][2] + 1):
m[y] = hoge[i]
i += 1
elif A[x][0] == "replace":
A[x][1] = int(A[x][1])
A[x][2] = int(A[x][2])
fuga = list(A[x][3])
j = 0
for y in range(A[x][1], A[x][2] + 1):
m[y] = fuga[j]
j += 1
if __name__ == "__main__":
main()
| 1
| 2,065,812,321,414
| null | 68
| 68
|
import sys
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
flagN = [False]*N
numN = [0]*N
if N > 1:
numN[0] = 1
for sc in SC:
s, c = sc[0], sc[1]
if flagN[s-1] == False:
flagN[s-1] = True
numN[s-1] = c
elif numN[s-1] == c:
continue
else:
print(-1)
sys.exit()
if N != 1 and numN[0] == 0:
print(-1)
sys.exit()
ans = ''
for n in numN:
ans += str(n)
print(ans)
|
while True:
string = input()
if string == "-":
break
else:
s = 0
for i in range(int(input())):
s += int(input())
s = s % len(string)
print(string[s:len(string)] + string[0:s])
| 0
| null | 31,548,572,997,328
| 208
| 66
|
L = int(input())
LL = L*L*L
print(LL/27)
|
l = int(input())
a = l/3
print(a*a*a)
| 1
| 47,080,148,414,318
| null | 191
| 191
|
K, N = map(int, input().split())
A = [int(x) for x in input().split()]
mx = A[0] + K - A[-1]
for i in range(len(A) - 1):
dis = A[i + 1] - A[i]
if dis > mx:
mx = dis
print(K - mx)
|
K, N = map(int, input().split())
A = list(map(int, input().split()))
a_old = A[0]
ma = A[0] + K - A[-1]
for a in A[1:]:
ma = max(ma, a - a_old)
a_old = a
print(K-ma)
| 1
| 43,325,837,497,250
| null | 186
| 186
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
X, Y, A, B, C, *PQR = map(int, read().split())
P = PQR[:A]
Q = PQR[A : A + B]
R = PQR[A + B :]
P.sort(reverse=True)
Q.sort(reverse=True)
vec = P[:X] + Q[:Y] + R
vec.sort(reverse=True)
ans = sum(vec[: X + Y])
print(ans)
return
if __name__ == '__main__':
main()
|
# :20
import sys
def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()
INF = float('inf')
x, y, a, b, c = LI()
p = sorted(LI())[::-1][:x]
q = sorted(LI())[::-1][:y]
r = sorted(LI())[::-1][:x+y]
# print(p, q, r)
bucket = []
bucket += [[i, 'p'] for i in p]
bucket += [[i, 'q'] for i in q]
bucket += [[i, 'r'] for i in r]
bucket = sorted(bucket, key=lambda x: x[0])
# print(bucket)
d = {'p': 0, 'q': 0}
ans = 0
cnt = 0
while cnt < x + y:
if bucket[-1][1] == 'p' and d[bucket[-1][1]] < x:
ans += bucket.pop()[0]
d['p'] += 1
cnt += 1
elif bucket[-1][1] == 'q' and d[bucket[-1][1]] < y:
ans += bucket.pop()[0]
d['q'] += 1
cnt += 1
else:
ans += bucket.pop()[0]
cnt += 1
print(ans)
| 1
| 45,174,380,170,740
| null | 188
| 188
|
MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
print(0)
exit()
D_2 = [0]*(max(D)+1)
for i in D:
D_2[i] += 1
if D_2[0] != 1:
print(0)
exit()
ans = 1
for i in range(1,max(D)+1):
ans *= D_2[i-1]**D_2[i]
ans %= MOD
print(ans)
|
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)
| 0
| null | 84,379,475,945,738
| 284
| 128
|
from bisect import bisect_left
N=int(input())
A=sorted(list(map(int,input().split())))
cnt=0
for i in range(N-1):
for j in range(i+1,N):
a=bisect_left(A,A[i]+A[j])
if j<a:
cnt+=a-j-1
print(cnt)
|
L = input().split()
L.reverse()
print(*L, sep="")
| 0
| null | 137,077,864,411,520
| 294
| 248
|
A, V = [int(x) for x in input().split()]
B, W = [int(x) for x in input().split()]
T = int(input())
if W >= V:
print('NO')
elif abs(A - B) <= (V - W) * T:
print('YES')
else:
print('NO')
|
n=int(input())
list=list(map(int, input().split()))
def pair(parameter):
pairedList = []
for iterater1 in range(len(parameter)):
for iterater2 in range(iterater1+1,len(parameter)):
pairedList.append([parameter[iterater1],parameter[iterater2]])
return pairedList
pairings = pair(list)
count=0
add=0
for i in pairings:
x=i[0]*i[1]
add+=x
print(add)
| 0
| null | 91,966,547,721,708
| 131
| 292
|
a = raw_input().lower()
s = 0
while True:
b = raw_input()
if b == 'END_OF_TEXT':
break
b = b.split()
b = map(str.lower,b)
s += b.count(a)
print s
|
N=int(input())
from math import gcd
from functools import reduce
l=list(map(int,input().split()))
sw=0
c=[0]*1000001
for i in l:
c[i]+=1
if all(sum(c[i::i])<=1 for i in range(2,1000001)):
print("pairwise coprime")
elif reduce(gcd,l)==1:
print("setwise coprime")
else:
print("not coprime")
| 0
| null | 2,924,480,216,700
| 65
| 85
|
#!/usr/bin/env python3
import sys
def solve(N: int, R: int):
if N >= 10:
print(R)
if N < 10:
print(R + 100*(10-N))
return
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
R = int(next(tokens)) # type: int
solve(N, R)
if __name__ == '__main__':
main()
|
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=math.floor,math.ceil
from collections import deque
Yes=lambda b:print('Yes')if b else print('No');YES=lambda b:print('YES')if b else print('NO')
is_even=lambda x:True if x%2==0 else False
def main():
n,r = ints()
if n>=10:
print(r)
else:
print(r+100*(10-n))
if __name__ == '__main__':
main()
| 1
| 63,421,475,258,528
| null | 211
| 211
|
import math
a,b,c=map(float,input().split())
h=b*math.sin(c/180.0*math.pi)
ad=a-b*math.cos(c/180.0*math.pi)
d=(h*h+ad*ad)**0.5
l = a + b + d
s = a * h / 2.0
print('{0:.6f}'.format(s))
print('{0:.6f}'.format(l))
print('{0:.6f}'.format(h))
|
n=int(input())
s='*'+input()
r=s.count('R')
g=s.count('G')
b=s.count('B')
cnt=0
for i in range(1,n+1):
for j in range(i,n+1):
k=2*j-i
if k>n:
continue
if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
cnt+=1
print(r*g*b-cnt)
| 0
| null | 18,224,310,332,008
| 30
| 175
|
n = int(input())
b = range(1, n)
a = b[::2]
print(1 - (len(a) / n))
|
#A
import math
n = int(input())
print((math.ceil(n / 2)) / n)
| 1
| 177,576,332,556,128
| null | 297
| 297
|
digitsStr = input()
honlist = ["2","4","5","7","9"]
ponList = ["0","1","6","8"]
if digitsStr[-1] == '3':
print('bon')
elif digitsStr[-1] in honlist:
print('hon')
elif digitsStr[-1] in ponList:
print('pon')
|
N = input().rstrip()
N = int(N[-1])
A = {2,4,5,7,9}
B = {0,1,6,8}
if N in A:
print("hon")
elif N in B:
print("pon")
else:
print("bon")
| 1
| 19,374,941,277,640
| null | 142
| 142
|
n=int(input())
s,t=input().split()
a=str()
for i in range(n):
a=a+s[i]+t[i]
print(a)
|
x = int(input())
x_ = divmod(x, 100)
if 5*x_[0] >= x_[1]:
print(1)
else:
print(0)
| 0
| null | 119,061,746,657,658
| 255
| 266
|
from collections import *
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
p.sort(reverse=True)
q=list(map(int,input().split()))
q.sort(reverse=True)
r=list(map(int,input().split()))
r.sort(reverse=True)
r=r+p[:x]+q[:y]
r.sort(reverse=True)
r=r[:x+y]
print(sum(r))
|
from collections import deque
s=deque(list(input()))
flag=0
for i in range(int(input())):
dir=input().split()
if int(dir[0])==1:flag+=1
else:
if int(dir[1])==1:
if flag%2==0:s.appendleft(dir[2])
else:s.append(dir[2])
else:
if flag%2==0:s.append(dir[2])
else:s.appendleft(dir[2])
s=list(s)
if flag%2==1:s.reverse()
print(*s,sep='')
| 0
| null | 51,195,691,572,142
| 188
| 204
|
def readinput():
n=int(input())
sList=[]
for _ in range(n):
sList.append(input())
return n,sList
def main(n,sList):
keihin={}
for s in sList:
if s in keihin:
keihin[s]+=1
else:
keihin[s]=1
return len(keihin)
if __name__=='__main__':
n,sList=readinput()
ans=main(n,sList)
print(ans)
|
N = int(input())
s = [0] * N
for i in range(N):
s[i] = input()
d = set()
for v in s:
d.add(v)
print(len(d))
| 1
| 30,465,434,547,762
| null | 165
| 165
|
import itertools
a,b,c=map(int, input().split())
l = [input() for i in range(a)]
ans = 0
Ans = 0
for i in itertools.product((1,-1),repeat=a):
for j in itertools.product((1,-1),repeat=b):
for k in range(a):
for m in range(b):
if i[k] == j[m] == 1 and l[k][m] == '#':
ans += 1
if ans == c:
Ans += 1
ans = 0
print(Ans)
|
n,k,s=map(int,input().split())
a=[s]*k
b=[3]*(n-k)+[s]*k
p=max(s//2-1,1)
for i in range(n-k):
if i%p==0:
a.append(s-1)
else:
a.append(2)
if s!=2 and s!=1:
print(*a)
else:
print(*b)
| 0
| null | 49,841,648,861,440
| 110
| 238
|
import sys
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
a = a1 * t1 + a2 * t2
b = b1 * t1 + b2 * t2
ha = a1 * t1
hb = b1 * t1
if a == b or ha == hb:
print ("infinity")
sys.exit(0)
if a > b:
a, b = b, a
ha, hb = hb, ha
gap = b - a
hgap = ha - hb
if hgap < 0:
print (0)
sys.exit(0)
ans = 2 * (hgap // gap) + (1 if hgap % gap > 0 else 0)
print (ans)
|
if __name__ == "__main__":
while True:
h,w = map(int,input().split())
if w is not 0 or h is not 0:
for i in range(w):
print("#",end="")
print("")
for i in range(h-2):
print("#",end="")
for j in range(w-2):
print(".",end="")
print("#",end="")
print("")
for i in range(w):
print("#",end="")
print("")
print("")
else:
break
| 0
| null | 65,924,794,719,804
| 269
| 50
|
def dictionary():
n = int(input())
s = set()
for i in range(n):
command, value = input().split()
if command == 'insert':
s.add(value)
elif command == 'find':
if value in s:
print('yes')
else:
print('no')
if __name__ == '__main__':
dictionary()
|
N, M = map(int, input().split())
A = list(map(int, input().split()))
m = 0
for a in A:
if a >= sum(A) / (4 * M):
m += 1
print('Yes') if m >= M else print('No')
| 0
| null | 19,280,573,245,770
| 23
| 179
|
array_str = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'
array = array_str.split(', ')
k = int(input())
print(array[k - 1])
|
from sys import stdin
while True:
h, w = (int(n) for n in stdin.readline().rstrip().split())
if h == w == 0:
break
for cnt in range(h):
print(('#.' * ((w + 2) // 2))[cnt % 2: w + cnt % 2])
print()
| 0
| null | 25,374,381,211,218
| 195
| 51
|
import math
def KochCurve(p1,p2,n):
if n==0:
return
s = [(2*p1[0]+p2[0])/3,(2*p1[1]+p2[1])/3]
t = [(p1[0]+2*p2[0])/3,(p1[1]+2*p2[1])/3]
u = [(p1[0]+p2[0])/2+((-1)*math.sqrt(3))*(p2[1]-p1[1])/6,(p1[1]+p2[1])/2+(math.sqrt(3))*(p2[0]-p1[0])/6]
KochCurve(p1,s,n-1)
print(f"{'{:.9f}'.format(s[0])} {'{:.9f}'.format(s[1])}")
KochCurve(s,u,n-1)
print(f"{'{:.9f}'.format(u[0])} {'{:.9f}'.format(u[1])}")
KochCurve(u,t,n-1)
print(f"{'{:.9f}'.format(t[0])} {'{:.9f}'.format(t[1])}")
KochCurve(t,p2,n-1)
p1 = [0,0]
p2 = [100,0]
n = int(input())
print(f"{'{:.9f}'.format(p1[0])} {'{:.9f}'.format(p1[1])}")
KochCurve(p1,p2,n)
print(f"{'{:.9f}'.format(p2[0])} {'{:.9f}'.format(p2[1])}")
|
N = int(input())
from math import sin, cos, pi
th = pi/3
def koch(d, p1, p2):
if d == 0:
return
s = [0, 0]
t = [0, 0]
u = [0, 0]
s[0] = (2 * p1[0] + p2[0])/3
s[1] = (2 * p1[1] + p2[1])/3
t[0] = (2 * p2[0] + p1[0])/3
t[1] = (2 * p2[1] + p1[1])/3
u[0] = (t[0] - s[0]) * cos(th) - (t[1] - s[1]) * sin(th) + s[0]
u[1] = (t[0] - s[0]) * sin(th) + (t[1] - s[1]) * cos(th) + s[1]
koch(d-1, p1, s)
print(*s)
koch(d-1, s, u)
print(*u)
koch(d-1, u, t)
print(*t)
koch(d-1, t, p2)
p_start = [0.0, 0.0]
p_end = [100.0, 0.0]
print(*p_start)
koch(N, p_start, p_end)
print(*p_end)
| 1
| 128,625,076,650
| null | 27
| 27
|
import heapq
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ans=[]
for i in range(x):
ans.append(p[i])
for j in range(y):
ans.append(q[j])
ans.sort()
heapq.heapify(ans)
for j in range(c):
min_a=heapq.heappop(ans)
if min_a<=r[j]:
heapq.heappush(ans,r[j])
else:
heapq.heappush(ans,min_a)
break
print(sum(ans))
|
X, Y, A, B, C = map(int, input().split())
Ap = list(map(int, input().split()))
Bq = list(map(int, input().split()))
Cr = list(map(int, input().split()))
Ap.sort()
Bq.sort()
print(sum(sorted(Ap[A-X:] + Bq[B-Y:] + Cr)[C:]))
| 1
| 44,511,249,488,480
| null | 188
| 188
|
N = int(input())
As = list(map(int, input().split()))
P = 10**9 + 7
rlt = 0
pw = 1
for i in range(61):
c0 = 0
c1 = 0
for j in range(N):
a = As[j]
if a % 2 == 0:
c0 += 1
else:
c1 += 1
As[j] = a//2
rlt += c0*c1*pw % P
rlt %= P
pw *= 2
print(rlt)
|
A, B, C = map(int, input().split())
if A+B+C > 21:
print('bust')
else:
print('win')
| 0
| null | 120,715,239,846,300
| 263
| 260
|
s = input()
n = len(s)
c = 0
for i in range(int((n - 1)/2)):
if (s[i] != s[n - 1 - i]):
c = 1
x = int((n - 1)/2)
for i in range(x):
if (s[i] != s[x - 1 - i]):
c = 1
if (c == 1):
print("No")
else:
print("Yes")
|
n,m = map(int,input().split())
A = list(map(int,input().split()))
s = sum(A)
d = s * (1/(4*m))
t = sum(a >= d for a in A)
print('Yes' if t >= m else 'No')
| 0
| null | 42,377,829,612,202
| 190
| 179
|
s,t = input().split()
print("".join(map(str,[t,s])))
|
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
S, T = input().split()
print(T+S)
| 1
| 102,916,190,024,860
| null | 248
| 248
|
n = int(input())
m = (n + 1) // 2
print(m)
|
import sys
N = int(input()) + 1
ans = N // 2
print(ans)
| 1
| 59,076,423,541,632
| null | 206
| 206
|
import math
a,b=map(float,input().split())
a=int(a)
b=round(b*100)
print((a*b)//100)
|
a,b=map(str,input().split())
a=int(a)
b=100*int(b[0])+10*int(b[2])+1*int(b[3]) #bを100倍した値(整数)に直す
print((a*b)//100)
| 1
| 16,434,678,794,160
| null | 135
| 135
|
def gcd(a, b):
if (a == 0):
return b
return gcd(b%a, a)
def lcm(a, b):
return (a*b)//gcd(a, b)
n = int(input())
numbers = list(map(int, input().split()))
l = numbers[0]
for i in range(1, n):
l = lcm(l, numbers[i])
ans = 0
for i in range(n):
ans += l//numbers[i]
MOD = 1000000007
print(ans%MOD)
|
# C Traveling Salesman around Lake
K, N = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
before = A[0]
for i in range(1, len(A)):
ans = max(ans, A[i] - before)
before = A[i]
ans = max(ans, A[0] + K - A[N-1])
print(K - ans)
| 0
| null | 65,818,798,372,250
| 235
| 186
|
import math
n = int(input())
print(360*n//math.gcd(360,n)//n)
|
cnt = 0
pos = 360
muki = int(input())
while pos != 0:
pos += muki
pos %= 360
cnt += 1
print(cnt)
| 1
| 13,077,404,146,238
| null | 125
| 125
|
S=[]
T=[]
n=int(input())
s=input().split()
for i in range(n):
S.append(s[i])
q=int(input())
t=input().split()
for j in range(q):
T.append(t[j])
cnt=0
for i in range(q):
for j in range(n):
if T[i]==S[j]:
cnt+=1
break
print(cnt)
|
n = int(input())
wa = 0
m = 0
l = list(map(int, input().split()))
for i in range(n):
m = max(l[i], m)
if m > l[i]:
wa += m - l[i]
print(wa)
| 0
| null | 2,309,055,934,560
| 22
| 88
|
def main():
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
d = abs(A - B)
s = V - W
print('YES' if T * s >= d else 'NO')
if __name__ == '__main__':
main()
|
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
d=abs(a-b)
if v<=w:
print("NO")
exit()
if d<=t*(v-w):
print("YES")
else:
print("NO")
| 1
| 15,221,075,946,860
| null | 131
| 131
|
N = int(input())
S = list(input() for _ in range(N))
X = []
for s in S:
l,r = 0,0
for c in s:
if c == ")":
if r > 0:
r -= 1
else:
l += 1
else:
r += 1
X.append([l,r])
X.sort(key = lambda x:x[0])
Y = []
L = 0
for p,q in X:
if p > L:
print("No")
quit()
if q >= p:
L -= p
L += q
else:
Y.append([p,q])
Y.sort(key = lambda x:-x[1])
for a,b in Y:
if a > L:
print("No")
quit()
L -= a
L += b
if L:
print("No")
else:
print("Yes")
|
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")
def yes():
print("Yes") # type: str
def no():
print("No") # type: str
def solve(N: int, S: "List[str]"):
def f(s):
ans = [0]*(len(s)+1)
m = 0
for i, c in enumerate(s):
if c == "(":
m += 1
else:
m -= 1
ans[i] = m
return min(*ans), m, s
# 数値化(最小値, 到達値)
T = [f(s) for s in S]
front = []
back = []
for a, b, s in T:
if b >= 0:
front.append((a, b, s))
else:
back.append((a, b, s))
front.sort(key=lambda x: x[0], reverse=True)
back.sort(key=lambda x: min(0, x[0]-x[1]), reverse=True)
# print(front)
# print(back)
m = 0
for ma, mb, s in front+back[::-1]:
if m + ma < 0:
no()
# print("負", s)
return
m += mb
if m == 0:
yes()
else:
# print("非零到達")
no()
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = [next(tokens) for _ in range(N)] # type: "List[str]"
solve(N, S)
if __name__ == '__main__':
main()
| 1
| 23,647,111,797,190
| null | 152
| 152
|
def alp(c):
return chr(c+64)
def Base10to(n,k):
if(int(n/k)):
if n%k ==0 and n/k==1:
return str(alp(26))
elif n%k ==0:
return Base10to(int((n/k)-1),k)+str(alp(26))
else:
return Base10to(int(n/k),k)+str(alp(n%k))
return str(alp(n%k))
n = int(input())
k = 26
ans = Base10to(n,k)
print(ans.lower())
|
import math
def solve():
N = int(input())
lowercase = 'abcdefghijklmnopqrstuvwxyz'
ans = ''
for i in range(len(str(N))):
if N == 0:
break
j = N % 26
N -= 1
N = N // 26
ans = lowercase[j - 1] + ans
print(ans)
if __name__ == '__main__':
solve()
| 1
| 11,763,426,942,300
| null | 121
| 121
|
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *
input = sys.stdin.readline
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]
inf = float('inf')
mod = 1000000007
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
def main():
D = inputInt()
C = inputList()
S = []
for i in range(D):
s = inputList()
S.append(s)
ans1 = []
ans2 = []
ans3 = []
ans4 = []
ans5 = []
for i in range(D):
bestSco1 = 0
bestSco2 = 0
bestSco3 = 0
bestSco4 = 0
bestSco5 = 0
bestI1 = 1
bestI2 = 1
bestI3 = 1
bestI4 = 1
bestI5 = 1
for j,val in enumerate(S[i]):
if j == 0:
tmpAns = ans1 + [j+1]
tmpSco = findScore(tmpAns, S, C)
if bestSco1 < tmpSco:
bestSco5 = bestSco4
bestI5 = bestI4
bestSco4 = bestSco3
bestI4 = bestI3
bestSco3 = bestSco2
bestI3 = bestI2
bestSco2 = bestSco1
bestI2 = bestI1
bestSco1 = tmpSco
bestI1 = j+1
else:
tmpAns1 = ans1 + [j+1]
tmpAns2 = ans2 + [j+1]
tmpAns3 = ans3 + [j+1]
tmpAns4 = ans4 + [j+1]
tmpAns5 = ans5 + [j+1]
tmpSco1 = findScore(tmpAns1, S, C)
tmpSco2 = findScore(tmpAns2, S, C)
tmpSco3 = findScore(tmpAns3, S, C)
tmpSco4 = findScore(tmpAns4, S, C)
tmpSco5 = findScore(tmpAns5, S, C)
if bestSco1 < tmpSco1:
bestSco5 = bestSco4
bestI5 = bestI4
bestSco4 = bestSco3
bestI4 = bestI3
bestSco3 = bestSco2
bestI3 = bestI2
bestSco2 = bestSco1
bestI2 = bestI1
bestSco1 = tmpSco1
bestI1 = j+1
if bestSco1 < tmpSco2:
bestSco5 = bestSco4
bestI5 = bestI4
bestSco4 = bestSco3
bestI4 = bestI3
bestSco3 = bestSco2
bestI3 = bestI2
bestSco2 = bestSco1
bestI2 = bestI1
bestSco1 = tmpSco1
bestI1 = j+1
if bestSco1 < tmpSco3:
bestSco5 = bestSco4
bestI5 = bestI4
bestSco4 = bestSco3
bestI4 = bestI3
bestSco3 = bestSco2
bestI3 = bestI2
bestSco2 = bestSco1
bestI2 = bestI1
bestSco1 = tmpSco1
bestI1 = j+1
if bestSco1 < tmpSco4:
bestSco5 = bestSco4
bestI5 = bestI4
bestSco4 = bestSco3
bestI4 = bestI3
bestSco3 = bestSco2
bestI3 = bestI2
bestSco2 = bestSco1
bestI2 = bestI1
bestSco1 = tmpSco1
bestI1 = j+1
if bestSco1 < tmpSco5:
bestSco5 = bestSco4
bestI5 = bestI4
bestSco4 = bestSco3
bestI4 = bestI3
bestSco3 = bestSco2
bestI3 = bestI2
bestSco2 = bestSco1
bestI2 = bestI1
bestSco1 = tmpSco1
bestI1 = j+1
ans1.append(bestI1)
ans2.append(bestI2)
ans3.append(bestI3)
ans4.append(bestI4)
ans5.append(bestI5)
for i in ans1:
print(i)
def findScore(ans, S, C):
scezhu = [inf for i in range(26)]
sco = 0
for i,val in enumerate(ans):
tmp = S[i][val-1]
scezhu[val-1] = i
mins = 0
for j,vol in enumerate(C):
if scezhu[j] == inf:
mins = mins + (vol * (i+1))
else:
mins = mins + (vol * ((i+1)-(scezhu[j]+1)))
tmp -= mins
sco += tmp
return sco
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
main()
|
import random
import copy
def evaluateSatisfaction(d, c, s, ans):
score = 0
last = [-1 for i in range(26)]
for i in range(d):
score += s[i][ans[i]]
last[ans[i]] = i
for j in range(26):
if j != ans[i] or True:
score -= c[j]*(i - last[j])
return score
def valuationFunction(d,c,s,contestType,day,last):
return s[day][contestType]
def Input():
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(d)]
#s[3][25] = contest(25+1) of day(3+1)
return d, c, s
def evolution(d, c, s, ans):
score_before = evaluateSatisfaction(d, c, s, ans)
ans_after = copy.copy(ans)
idx1 = random.randint(0,d-1)
idx2 = random.randint(0,d-1)
tmp = ans_after[idx1]
ans_after[idx1] = ans_after[idx2]
ans_after[idx2] = tmp
score_after = evaluateSatisfaction(d,c,s,ans_after)
if score_after > score_before:
return ans_after
else:
return ans
if __name__ == "__main__":
d, c, s = Input()
#print("val =", evaluateSatisfaction(d, c, s, [1, 17, 13, 14, 13]))
#calc start
ans = [0 for i in range(d)]
last = [-1 for i in range(26)]
for i in range(d):
evalValueList = [0 for j in range(26)]
for j in range(26):
evalValueList[j] = valuationFunction(d, c, s, j,i,last)
max_idx = 0
max = evalValueList[0]
for j in range(26):
if (max < evalValueList[j]):
max_idx = j
max = evalValueList[j]
ans[i] = max_idx
last[ans[i]] = i
for i in range(100):
ans = evolution(d, c, s, ans)
#print(evaluateSatisfaction(d,c,s,ans))
for x in ans:
print(x+1)
| 1
| 9,653,671,674,400
| null | 113
| 113
|
s = raw_input()
if s == "ARC":
print "ABC"
else:
print "ARC"
|
def main():
arg = input().rstrip()
ans = 'ABC' if arg == 'ARC' else 'ARC'
print(ans)
if __name__ == '__main__':
main()
| 1
| 24,131,495,375,728
| null | 153
| 153
|
h,a=map(int,input().split())
for i in range(1,10001):
if a*i >= h:
print(i)
break
|
#
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A):
for a in A: print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
N,K = MI()
A=LI_()
ans = 0
before = defaultdict(int)
*cumsum,=accumulate(A)
for i,a in enumerate(cumsum):
cumsum[i] = a%K
# print(cumsum)
for i,a in enumerate(cumsum):
if i >= K:
before[cumsum[i-K]]-=1
ans += before[a]
before[a]+=1
ans += cumsum[:K-1].count(0)
print(ans)
if __name__ == '__main__':
main()
| 0
| null | 107,264,845,196,444
| 225
| 273
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))
def main():
n, m, l = map(int, input().split())
d = [[float("inf") for _ in range(n)] for _ in range(n)]
for i in range(n):
d[i][i] = 0
for _ in range(m):
a, b, c = map(int, input().split())
d[a-1][b-1] = c
d[b-1][a-1] = c
for k in range(n):
for i in range(n):
for j in range(n):
if d[i][j] > d[i][k] + d[k][j]:
d[i][j] = d[i][k] + d[k][j]
dl = [[float("inf") for _ in range(n)] for _ in range(n)]
for i in range(n):
d[i][i] = 0
for i in range(n):
for j in range(i+1, n):
if i != j and d[i][j] <= l:
dl[i][j] = 1
dl[j][i] = 1
for k in range(n):
for i in range(n):
for j in range(n):
if dl[i][j] > dl[i][k] + dl[k][j]:
dl[i][j] = dl[i][k] + dl[k][j]
q = int(input())
for _ in range(q):
s, t = map(int, input().split())
if dl[s-1][t-1] == float("inf"):
print(-1)
else:
print(dl[s-1][t-1] - 1)
if __name__ == '__main__':
main()
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
S = readline().strip()
N = len(S)
if (
S == S[::-1]
and S[: (N - 1) // 2] == S[: (N - 1) // 2][::-1]
and S[(N + 1) // 2 :] == S[(N + 1) // 2 :][::-1]
):
print('Yes')
else:
print('No')
return
if __name__ == '__main__':
main()
| 0
| null | 109,863,561,708,850
| 295
| 190
|
n = int(input())
s = input()
cnt = 0
for i in range(10):
a = s.find(str(i))
if a == -1:
continue
for j in range(10):
b = s.find(str(j), a + 1)
if b == -1:
continue
for k in range(10):
c = s.find(str(k), b + 1)
if c != -1:
cnt += 1
print(cnt)
|
def resolve():
N = int(input())
S = str(input())
cnt = 0
for i in range(1000):
c = [int(i / 100), int(i / 10) % 10, int(i % 10)]
f = 0
for j in range(N):
if S[j] == ('0' + str(c[f])) or S[j] == str(c[f]):
f += 1
if f == 3:
break
if f == 3:
cnt += 1
print(cnt)
return
resolve()
| 1
| 128,576,876,289,760
| null | 267
| 267
|
N = int(input())
A = [int(x) for x in input().split()]
# M以下の整数の素因数分解を高速に
# 前処理O(MloglogM)
# 一計算O(logK)
def mae_syori(M):
D = [0] * (M + 1)
for i in range(2, M+1):
if D[i] != 0: continue
# print(i, list(range(i*2, M + 1, i)))
for j in range(i*2, M+1, i):
if D[j] == 0:
D[j] = i
return D
def p_bunkai(K):
assert 2 <= K <= len(D)-1
k = K
ret = []
while True:
if k == 1:
break
if D[k] == 0:
ret.append((k, 1))
break
else:
p = D[k]
count = 0
while k % p == 0:
count += 1
k //= p
ret.append((p, count))
return ret
# 最大公約数
# ユークリッドの互除法
def my_gcd(a, b):
if b == 0:
return a
else:
return my_gcd(b, a%b)
c_gcd = A[0]
for a in A:
c_gcd = my_gcd(c_gcd, a)
if c_gcd == 1:
max_A = max(A)
D = mae_syori(max_A)
yakusu = set()
ok = True
for a in A:
if a == 1: continue
p_bunkai_result = p_bunkai(a)
p_list = [p[0] for p in p_bunkai_result]
for p in p_list:
if p not in yakusu:
yakusu.add(p)
else:
ok = False
if not ok:
break
if ok:
print('pairwise coprime')
else:
print('setwise coprime')
else:
print('not coprime')
|
import sys
def gcd(a, b):
while b:
a, b = b, a % b
return a
def is_prime_MR(n):
d = n - 1
d = d // (d & -d)
L = [2, 7, 61] if n < 1 << 32 else [
2, 3, 5, 7, 11, 13, 17
] if n < 1 << 48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
for a in L:
t = d
y = pow(a, t, n)
if y == 1:
continue
while y != n - 1:
y = y * y % n
if y == 1 or t == n - 1:
return 0
t <<= 1
return 1
def find_factor_rho(n):
m = 1 << n.bit_length() // 8
for c in range(1, 99):
def f(x):
return (x * x + c) % n
y, r, q, g = 2, 1, 1, 1
while g == 1:
x = y
for i in range(r):
y = f(y)
k = 0
while k < r and g == 1:
ys = y
for i in range(min(m, r - k)):
y = f(y)
q = q * abs(x - y) % n
g = gcd(q, n)
k += m
r <<= 1
if g == n:
g = 1
while g == 1:
ys = f(ys)
g = gcd(abs(x - ys), n)
if g < n:
if is_prime_MR(g):
return g
elif is_prime_MR(n // g):
return n // g
return find_factor_rho(g)
def prime_factor(n):
i = 2
ret = {}
rhoFlg = 0
while i * i <= n:
k = 0
while n % i == 0:
n //= i
k += 1
if k:
ret[i] = k
i += i % 2 + (3 if i % 3 == 1 else 1)
if i == 101 and n >= 2**20:
while n > 1:
if is_prime_MR(n):
ret[n], n = 1, 1
else:
rhoFlg = 1
j = find_factor_rho(n)
k = 0
while n % j == 0:
n //= j
k += 1
ret[j] = k
if n > 1:
ret[n] = 1
if rhoFlg:
ret = {x: ret[x] for x in sorted(ret)}
return ret
input = sys.stdin.buffer.readline
N = int(input())
A = list(map(int, input().split()))
g = 0
for a in A:
g = gcd(g, a)
if g > 1:
print('not coprime')
exit()
X = [0] * 1001001
for a in A:
for p in prime_factor(a):
if X[p]:
print('setwise coprime')
exit()
X[p] = 1
print('pairwise coprime')
| 1
| 4,132,247,942,046
| null | 85
| 85
|
letter = input()
if letter.isupper() == True:
print("A")
else:
print("a")
|
import numpy as np
N = int(input())
A = list(map(int, input().split()))
cum_A = np.cumsum(A)
ans = 10 ** 18
for i in range(N):
left = cum_A[i]
right = cum_A[-1] - cum_A[i]
ans = min(ans, abs(left - right))
print(ans)
| 0
| null | 77,154,471,740,922
| 119
| 276
|
T = input()
count = 0
for c in T:
count += 1
if c == '?' and T[count-1] == 'D':
c = 'P'
print(c, end="")
elif c == '?':
c = 'D'
print(c, end="")
else:
print(c, end="")
|
import sys
input = sys.stdin.readline
t = list(input())
t.pop()
n = len(t)
res = 0
for i in range(n):
if t[i] == '?':
t[i] = 'D'
print(''.join(t))
| 1
| 18,535,499,871,740
| null | 140
| 140
|
a,b,c=map(int,input().split())
if (a==b and b==c) or (a!=b and b!=c and c!=a):
print("No")
else:
print("Yes")
|
A,B,C = map(int,input().split())
if A==B and B==C and A==C:
print ("No")
elif A!=B and B!=C and A!=C:
print ("No")
else :
print ("Yes")
| 1
| 67,829,391,893,252
| null | 216
| 216
|
import math
from functools import reduce
K = int(input())
def gcd(*numbers):
return reduce(math.gcd, numbers)
out = 0
for a in range(1,K+1):
for b in range(1,K+1):
for c in range(1,K+1):
out += gcd(a,b,c)
print(out)
|
import array
N = int(input())
A = array.array('L', list(map(int, input().split())))
MAX = 10**5+1
X = array.array('L', [0]) * MAX
Y = array.array('L', range(MAX))
for i in range(len(A)): X[A[i]] += 1
Q = int(input())
cur = sum(array.array('L', (X[i]*Y[i] for i in range(len(X)))))
for i in range(Q):
[b, c] = list(map(int, input().split()))
cur = cur - X[b]*b + X[b]*c
print(cur)
X[c] += X[b]
X[b] = 0
| 0
| null | 23,782,326,251,110
| 174
| 122
|
import sys
K = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip('\n')
# ## COMBINATION (MOD) ###
N_MAX = 10**6 # 問題サイズに合わせて変えておく
MOD = 10**9 + 7
inv = [0] * (N_MAX + 2)
inv[0] = 0 # 逆元テーブル計算用テーブル
inv[1] = 1
for i in range(2, N_MAX + 2):
q, r = divmod(MOD, i)
inv[i] = -inv[r] * q % MOD
# K 文字追加
ans = 0
ln = len(S)
p = pow(26, K, MOD)
for i in range(1, K + 2):
ans += p % MOD
ans %= MOD
# pre
p = p * (ln + i - 1) * inv[i] * 25 * inv[26] % MOD
# suf
# s2 = (s2 * inv[26]) % MOD
print(ans)
|
k = int(input())
s = input()
L = len(s)
mod = 10**9+7
MAX = 2*10**6
fact = [1]*(MAX+1)
for i in range(1, MAX+1):
fact[i] = (fact[i-1]*i) % mod
inv = [1]*(MAX+1)
for i in range(2, MAX+1):
inv[i] = inv[mod % i]*(mod-mod//i) % mod
fact_inv = [1]*(MAX+1)
for i in range(1, MAX+1):
fact_inv[i] = fact_inv[i-1] * inv[i] % mod
def comb(n, k):
if n < k:
return 0
return fact[n] * fact_inv[n-k] * fact_inv[k] % mod
p25 = [1]*(k+1)
p26 = [1]*(k+1)
for i in range(k):
p25[i+1] = p25[i]*25%mod
p26[i+1] = p26[i]*26%mod
ans = 0
for p in range(k+1):
chk = p25[p]*comb(L-1+p,L-1)%mod
chk *= p26[k-p]%mod
ans += chk
ans %= mod
print(ans)
| 1
| 12,819,372,281,998
| null | 124
| 124
|
n = input()
l = map(int,raw_input().split())
print min(l), max(l), sum(l)
|
n,m,l=map(int,input().split())
A = [tuple(map(int,input().split())) for _ in range(n)]
B = [tuple(map(int,input().split())) for _ in range(m)]
BT = tuple(map(tuple,zip(*B)))
for a in A:
temp=[]
for b in BT:
temp.append(sum([x*y for (x,y) in zip(a,b)]))
print(*temp)
| 0
| null | 1,094,359,366,624
| 48
| 60
|
n = int(input())
added_strings = set()
for i in range(n):
com, s = input().split()
if com == 'insert':
added_strings.add(s)
elif com == 'find':
print('yes' if (s in added_strings) else 'no')
|
s=input()
if s=="RSR":
print("1")
else:
ans=s.count("R")
print(ans)
| 0
| null | 2,485,107,871,302
| 23
| 90
|
#coding: utf-8
string = str(input())
X = 0
li = []
for a in range(len(string)):
if string[a] == " ":
li.append(string[X:a])
X = a+1
li.append(string[X:])
for aa in range(len(li)):
li[aa] = int(li[aa])
h1 = li[0]
m1 = li[1]
h2 = li[2]
m2 = li[3]
k = li[4]
Time = (h2 * 60 + m2) - (h1 * 60 + m1) - k
print(int(Time))
|
h1, m1, h2, m2, K = map(int, input().split())
h = h2-(h1+1)
m = m2+60-m1
m += 60*h
m -= K
print(m)
| 1
| 18,155,453,796,798
| null | 139
| 139
|
s = input()
if s[0]==s[1]:
print("No")
elif s[2] != s[3]:
print("No")
elif s[4] != s[5]:
print("No")
else:
print("Yes")
|
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()
def main():
S = input()
print("Yes" if S[2]==S[3] and S[4]==S[5] else "No")
main()
| 1
| 42,001,826,059,170
| null | 184
| 184
|
W, H, x, y, r = list(map(int, input().split()))
x_right = x + r
x_left = x - r
y_up = y + r
y_down = y - r
if x_right <= W and x_left >= 0 and y_up <= H and y_down >= 0:
print("Yes")
else:
print("No")
|
W, H, x, y, r = map(int, input().split())
if (2*r <= (x+r) <= W) & (2*r <= (y+r) <= H):
print('Yes')
else:
print('No')
| 1
| 461,482,381,008
| null | 41
| 41
|
n = int(input())
table = list(map(int, input().split()))
data_max = max(table)
data_min = min(table)
data_sum = sum(table)
print(data_min, data_max, data_sum)
|
input()
list=[int(i) for i in input().split()]
print(min(list),max(list),sum(list))
| 1
| 732,121,753,018
| null | 48
| 48
|
def resolve():
a = int(input())
print(a+a*a+a*a*a)
if '__main__' == __name__:
resolve()
|
from bisect import bisect_left,insort_left
n=int(input())
s=list(input())
lindex=[[] for _ in range(26)]
for i in range(n):
lindex[ord(s[i])-97].append(i)
q=int(input())
for i in range(q):
q1,q2,q3=input().split()
if q1=='1':
q2=int(q2)-1
idx=bisect_left(lindex[ord(s[q2])-97],q2)
if s[q2]!=q3:
del lindex[ord(s[q2])-97][idx]
insort_left(lindex[ord(q3)-97],q2)
s[q2]=q3
else:
l=int(q2)-1
r=int(q3)-1
cnt=0
for j in range(26):
if len(lindex[j])==0:
continue
idx=bisect_left(lindex[j],l)
if len(lindex[j])>idx and lindex[j][idx]<=r:
cnt+=1
print(cnt)
| 0
| null | 36,476,147,487,392
| 115
| 210
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.