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
|
---|---|---|---|---|---|---|
# coding:utf-8
import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools
#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]
N = int(input())
ans = 0
if(N%2==0):
ans = N//2
else:
ans = (N+1)//2
print(ans/N)
| a, b = input().split()
b = b.replace('.', '')
print(int(a)*int(b)//100)
| 0 | null | 97,055,622,989,222 | 297 | 135 |
A, B, C, K = [int(v) for v in input().split()]
s = 0
while K:
if A and K:
if K >= A:
K -= A
s += A
A -= A
else:
s += K
K -= K
if B and K:
if K >= B:
K -= B
else:
K -= K
if C and K:
if K >= C:
K -= C
s -= C
C -= C
else:
s -= K
K -= K
print(s) | A, B, C, K=map(int, input().split())
if A>=K:
print(K)
elif A+B>=K>A:
print(A)
elif A+B+C>=K>A+B:
print(A-(K-A-B))
| 1 | 21,805,635,622,396 | null | 148 | 148 |
from sys import stdin,stdout #
import math #
import heapq #
#
t = 1 #
def aint(): #
return int(input().strip()) #
def lint(): #
return list(map(int,input().split())) #
def fint(): #
return list(map(int,stdin.readline().split())) #
#
########################################################
def f(n):
if n==0:
return 0
# print(n)
N=n
cnt=0
while(N):
cnt+=N&1
N>>=1
return f(n%cnt)+1
def main():
n=aint()
x=input()
c=x.count("1")
if(c==0):
for i in range(n):
print("1")
return
elif(c==1):
for i in range(n):
if(x[i]=="1"):
print(0)
elif x[i]=="0":
if x[n-1]=="1"or i==(n-1):
print("2")
else:
print(1)
return
mod1=c+1
mod2=c-1
mul1=1
mul2=1
rem1=0
rem2=0
for i in range(n-1,-1,-1):
if(x[i]=='1'):
rem1=(rem1+mul1)%mod1
rem2=(rem2+mul2)%mod2
mul1=(2*mul1)%mod1
mul2=(2*mul2)%mod2
ans=[]
mul1=1
mul2=1
# print(mod1,mod2)
# print(rem1,rem2)
for i in range(n-1,-1,-1):
if(x[i]=='0'):
# print("At index",i,"val",(rem1+mul1)%mod1)
ans.append(f((rem1+mul1)%mod1)+1)
else:
# print("At index",i,"val",(rem2-mul2)%mod2)
ans.append(f((rem2-mul2)%mod2)+1)
mul1=(2*mul1)%mod1
mul2=(2*mul2)%mod2
# print("Ans:")
for i in range(n-1,-1,-1):
print(ans[i])
return
#t=int(input())
########################################################
for i in range(t): #
#print("Case #"+str(i+1)+":",end=" ") #
main() # | x=int(input())
a=x
i=0
j=0
if 500<= x:
while i*500<x:
i+=1
i-=1
x-=500*i
if 5<=x:
while j*5<x:
j+=1
j-=1
if i==0 and j==0:
print(0)
elif a%500==0:
print(a//500 * 1000)
else:
print(1000*i+5*j)
| 0 | null | 25,594,073,834,352 | 107 | 185 |
n,m,k = map(int,input().split())
if n >= k:
print(n-k,m)
else:
if m - (k-n) < 0:
m = 0
else:
m -= k - n
print(0,m) | import sys
import math
import numpy as np
import functools
import operator
import collections
import itertools
X=int(input())
ans=1
for i in range(1,100000):
if (X*i)%360==0:
print(ans)
sys.exit()
ans+=1 | 0 | null | 58,897,276,982,940 | 249 | 125 |
a = list(map(int, input().split()))
s = a[0] + a[1] + a[2]
if s >= 22: print('bust')
else: print('win') | A=list(map(int,input().split()))
if A[0]+A[1]+A[2]<=21:
print("win")
else:
print("bust") | 1 | 118,893,751,152,352 | null | 260 | 260 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
def segfunc(x, y):
return min(x, y)
ide_ele = float('inf')
class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.tree = [ide_ele] * 2 * self.num
# 配列の値を葉にセット
for i in range(n):
self.tree[self.num + i] = init_val[i]
# 構築していく
for i in range(self.num - 1, 0, -1):
self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, k, x):
k += self.num
self.tree[k] = x
while k > 1:
self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
k >>= 1
def query(self, l, r):
res = self.ide_ele
l += self.num
r += self.num
while l < r:
if l & 1:
res = self.segfunc(res, self.tree[l])
l += 1
if r & 1:
res = self.segfunc(res, self.tree[r - 1])
l >>= 1
r >>= 1
return res
# 最短手数k回でクリアできるとすると、
# 1 ~ M の内1つをk回選んで合計をNにする
N, M = getNM()
S = input()
trap = set()
for i in range(len(S)):
if S[i] == '1':
trap.add(i)
# これABC011 123引き算と同じでは
# 案1 dpを使う
# dp[i]: iマスに止まる時の最短手順
# dp[i]の時 dp[i + 1] ~ dp[i + M]についてmin(dp[i] + 1, dp[i + j])を見ていく
# 決まったらdpを前から見ていき最短手順がdp[i] - 1になるものを探す(辞書順)
# → M <= 10 ** 5より多分無理
# セグ木使えばいける?
# dp[i] = dp[i - M] ~ dp[i - 1]の最小値 + 1
# dp[i - M] ~ dp[i - 1]の最小値はlogNで求められるので全体でNlogN
dp = [float('inf')] * (N + 1)
dp[0] = 0
seg = SegTree([float('inf')] * (N + 1), segfunc, ide_ele)
seg.update(0, 0)
# dp[i]をレコード
for i in range(1, N + 1):
# もしドボンマスなら飛ばす(float('inf')のまま)
if i in trap:
continue
# dp[i - M] ~ dp[i - 1]の最小値をサーチ
min_t = seg.query(max(0, i - M), i)
seg.update(i, min_t + 1)
dp[i] = min_t + 1
# goalに到達できないなら
if dp[-1] == float('inf'):
print(-1)
exit()
# 何回の試行で到達できるかをグルーピング
dis = [[] for i in range(dp[-1] + 1)]
for i in range(len(dp)):
if dp[i] == float('inf'):
continue
dis[dp[i]].append(i)
# ゴールから巻き戻っていく
now = dp[-1]
now_index = N
ans = []
# 辞書順で1 4 4 < 3 3 3なので
# 一番前にできるだけ小さい数が来るようにする
for i in range(now, 0, -1):
# dp[i] - 1回で到達できる
# 現在地点からMマス以内
# で最も現在地点から遠いところが1つ前のマス
index = bisect_left(dis[i - 1], now_index - M)
# サイコロの目を決める
ans.append(now_index - dis[i - 1][index])
# 現在地点更新
now_index = dis[i - 1][index]
for i in ans[::-1]:
print(i) | n, m = map(int, input().split())
S = list(map(int, input()))[::-1]
L = []
now = 0
while now < n:
if n - now <= m:
L.append(n - now)
break
for i in range(m, 0, -1):
if not S[now+i]:
now += i
L.append(i)
break
else:
print(-1)
exit()
print(*L[::-1]) | 1 | 139,182,854,864,710 | null | 274 | 274 |
N = int(input())
A = list(map(int,input().split()))
def selectSort(A, N):
sw = 0
for i in range(N):
minj = i
for j in range(i, N):
if A[j] < A[minj]:
minj = j
if A[i] != A[minj]:
A[i], A[minj] = A[minj], A[i]
sw += 1
return str(sw)
sw = selectSort(A, N)
print(" ".join(map(str, A)))
print(sw) | def selectionSort(A, N):
count = 0
for i in range(N - 1):
minValue = 100
minIndex = 0
for j in range(i, N):
if A[j] < minValue:
minValue = A[j]
minIndex = j
if minIndex != i:
temp = A[i]
A[i] = minValue
A[minIndex] = temp
count = count + 1
for i in range(N):
print A[i],
print
print count
N = input()
A = map(int, raw_input().split())
selectionSort(A, N) | 1 | 22,480,478,720 | null | 15 | 15 |
X=int(input())
x=100
ans=0
while x<X:
x=101*x//100
ans+=1
print(ans)
| n = int(input())
title = []
length = []
for i in range(n):
a, b = input().split()
title.append(a)
length.append(int(b))
i = title.index(input())
print(sum((length[i+1:]))) | 0 | null | 62,363,639,201,468 | 159 | 243 |
def Judgement(x,y,z):
if z-x-y>0 and (z-x-y)**2-4*x*y>0:
return 0
else:
return 1
a,b,c=map(int,input().split())
ans=Judgement(a,b,c)
if ans==0:
print("Yes")
else:
print("No") | n = int(input())
x = map(float, input().strip().split())
y = map(float, input().strip().split())
d = tuple(map(lambda x,y:abs(x-y), x, y))
print(sum(d))
print(sum(map(pow, d, [2]*n))**0.5)
print(sum(map(pow, d, [3]*n))**(1/3))
print(max(d)) | 0 | null | 25,844,779,895,538 | 197 | 32 |
def main():
TaroScore = HanaScore = 0
n = int(input())
for _ in range(n):
[Taro, Hana] = list(input().lower().split())
lenT = len(Taro)
lenH = len(Hana)
lenMin = min(lenT, lenH)
if Taro == Hana:
TaroScore += 1
HanaScore += 1
else:
for i in range(lenMin+1):
if Taro == '':
HanaScore += 3
break
elif Hana == '':
TaroScore += 3
break
elif ord(Taro[0]) > ord(Hana[0]):
TaroScore += 3
break
elif ord(Taro[0]) < ord(Hana[0]):
HanaScore += 3
break
else:
Taro = Taro[1:]
Hana = Hana[1:]
print(TaroScore, HanaScore)
if __name__ == '__main__':
main()
| n = int(input())
numlist = map(int, input().split())
numarr = list(numlist)
isevenList = [i for i in numarr if i % 2 == 0]
answerList = []
for i in isevenList:
if i % 3 == 0 or i % 5 == 0:
answerList.append("APPROVED")
else:
answerList.append("DENIED")
if "DENIED" in answerList:
print("DENIED")
else:
print("APPROVED") | 0 | null | 35,289,056,612,768 | 67 | 217 |
n = int(input())
a = list(map(int, input().split()))
b = sorted(enumerate(a), key=lambda x:x[1])
c = [b[i][0]+1 for i in range(n)]
d = [str(x) for x in c]
e = " ".join(d)
print(e) | N = int(input())
list = input().split()
answer = [0] * N
for i in range(N):
answer[int(list[i]) - 1] = str(i + 1)
print(' '.join(answer))
| 1 | 181,020,241,620,338 | null | 299 | 299 |
Spades = 0
Hearts = 1
Clovers = 2
Diamonds = 3
Cards = [[Spades, Hearts, Clovers, Diamonds] for j in range(13)]
for i in range(4):
for j in range(13):
Cards[j][i] = True
n = input()
for i in range(n):
Input = raw_input().split()
Numb = int(Input[1])
if Input[0] == 'S':
Mark = Spades
if Input[0] == 'H':
Mark = Hearts
if Input[0] == 'C':
Mark = Clovers
if Input[0] == 'D':
Mark = Diamonds
Cards[Numb - 1][Mark] = False
for i in range(4):
for j in range(13):
if Cards[j][i]:
if i == Spades:
print 'S', j + 1
if i == Hearts:
print 'H', j + 1
if i == Clovers:
print 'C', j + 1
if i == Diamonds:
print 'D', j + 1 | n = int(input())
cards = [[0 for i in range(13)] for j in range(4)]
for i in range(n):
Input = input().split()
if Input[0] == "S":
cards[0][int(Input[1])-1]= 1
if Input[0] == "H":
cards[1][int(Input[1]) - 1] = 1
if Input[0] == "C":
cards[2][int(Input[1]) - 1] = 1
if Input[0] == "D":
cards[3][int(Input[1]) - 1] = 1
for i in range(4):
for j in range(13):
if cards[i][j] == 0:
if i == 0:
print("S",j+1)
if i == 1:
print("H",j+1)
if i == 2:
print("C", j + 1)
if i == 3:
print("D", j + 1) | 1 | 1,022,687,802,252 | null | 54 | 54 |
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
sys.setrecursionlimit(100000000)
def input(): return sys.stdin.readline().rstrip()
N = int(input())
def f(x):
ans = set()
i = 1
while i * i <= x:
if x % i == 0:
ans.add(i)
i += 1
for i in ans.copy():
ans.add(x // i)
return ans
ans = set()
for K in f(N) | f(N - 1):
if K == 1:
continue
n = N
while n % K == 0:
n //= K
if n % K == 1:
ans.add(K)
print(len(ans))
| n = int(input())
if n==2:print(1);exit()
a = [n]
for i in range(2,int(n**0.5+1)):
if n%i==0:
a.append(i)
if i!=n//i:
a.append(n//i)
cnt =0
for v in a:
s = n
while v<=s and s%v==0:
s = s//v
if s%v==1: cnt += 1
b = [n-1]
m = n-1
for i in range(2,int(m**0.5+1)):
if m%i==0:
b.append(i)
if i!=m//i:
b.append(m//i)
print(cnt + len(b)) | 1 | 41,489,738,594,820 | null | 183 | 183 |
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
def solve(N: int, K: int):
NL = list(map(int, N))
useMaxDigits = [[0 for i in range(K+1)] for j in range((len(N)+1))]
noUseMaxDigits = [[0 for i in range(K+1)]
for j in range((len(N)+1))]
useMaxDigits[0][0] = 1
for digit in range(1, len(N)+1):
D = NL[digit-1]
# Use Max continueingly
if D != 0:
for i in range(1, K+1):
useMaxDigits[digit][i] = useMaxDigits[digit-1][i-1]
for i in range(0, K+1):
noUseMaxDigits[digit][i] = useMaxDigits[digit-1][i]
else:
for i in range(0, K+1):
useMaxDigits[digit][i] = useMaxDigits[digit-1][i]
# Use non max
for i in range(0, K+1):
# if use zero
noUseMaxDigits[digit][i] += noUseMaxDigits[digit-1][i]
for i in range(1, K+1):
noUseMaxDigits[digit][i] += noUseMaxDigits[digit-1][i-1]*9
for i in range(1, K+1):
noUseMaxDigits[digit][i] += useMaxDigits[digit -
1][i-1]*max(0, D-1)
print(useMaxDigits[-1][-1]+noUseMaxDigits[-1][-1])
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 = next(tokens) # type: int
K = int(next(tokens)) # type: int
solve(N, K)
if __name__ == '__main__':
main()
|
[X,Y] = list(map(int,input().split()))
n = (-1*X+2*Y)//3
m = (2*X-Y)//3
if (X+Y)%3 !=0:
print(0)
elif n<0 or m<0:
print(0)
else:
MAXN = (10**6)+10
MOD = 10**9 + 7
f = [1]
for i in range(MAXN):
f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod
print(nCr(n+m,n,10**9 + 7))
| 0 | null | 113,124,994,312,692 | 224 | 281 |
class CircleInaRectangle:
def __init__(self, W, H, x, y, r):
if 0 <= x - r and 0 <= y - r and x + r <= W and y + r <= H:
print "Yes"
else:
print "No"
if __name__ == "__main__":
W, H, x, y, r = map(int, raw_input().split())
CircleInaRectangle(W, H, x, y, r) | N = int(input())
A = list(map(int,input().split()))
M = 10**6
import math
setwise = A[0]
for i in range(1,N):
setwise = math.gcd(setwise,A[i])
PrimeFactorss = [[] for _ in range(M+1)]
for i in range(2, M+1):
if len(PrimeFactorss[i]) == 0:
for x in range(i, M+1, i):
PrimeFactorss[x].append(i)
num_list = [0]*(M+1)
for i in range(N):
num_list[A[i]] += 1
pairwise = [0]*(M+1)
n=M
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
primes.difference_update(range(i*2, n+1, i))
primes=list(primes)
for i in primes:
for j in range(i,M+1,i):
if num_list[j]==1:
pairwise[i] += 1
ans = 0
for i in pairwise:
if i>1:
ans += 1
break
if setwise == 1 and ans == 0:
print("pairwise coprime")
elif setwise == 1:
print("setwise coprime")
else:
print("not coprime")
| 0 | null | 2,296,596,534,960 | 41 | 85 |
def isok(arg):
if arg < 0:
return False
count = 0
for i in range(n):
count += max(0,-(-(a[i]*f[i]-arg)//f[i]))
if count <= k:
return True
else:
return False
def bisect(ng, ok):
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if isok(mid):
ok = mid
else:
ng = mid
return ok
n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse = True)
print(bisect(-1,10**12))
| import sys
input = sys.stdin.readline
R, L, K = map(int, input().split())
V = [0]*(R*L)
for _ in range(K):
r, c, v = map(int, input().split())
V[(c-1)*R+(r-1)] = v
A, B, C, D = [[0]*(R+1) for _ in range(4)]
for i in range(L):
for j in range(R):
A[j] = max(A[j-1],B[j-1],C[j-1],D[j-1])
v = V[i*R+j]
if v != 0:
D[j], C[j], B[j] = max(C[j]+v,D[j]), max(B[j]+v,C[j]), max(A[j]+v,B[j])
print(max(A[-2],B[-2],C[-2],D[-2])) | 0 | null | 85,025,301,461,488 | 290 | 94 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
# import decimal
# from decimal import Decimal
# decimal.getcontext().prec = 10
# from heapq import heappush, heappop, heapify
# import math
# from math import gcd
# import itertools as it
# import collections
# from collections import deque
def inp():
return int(input())
def inps():
return input().rstrip()
def inpl():
return list(map(int, input().split()))
def _debug(obj):
print(obj, file=sys.stderr)
# ---------------------------------------
X = inp()
for i in range(-120, 120):
for j in range(-120, 120):
if i**5 - j**5 == X:
print(i, j)
sys.exit() | def main():
S = input()
if "7" in S:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| 0 | null | 29,871,846,841,618 | 156 | 172 |
def main():
print("ACL" * int(input()))
if __name__ == '__main__':
main()
| a = int(input())
if a == 1:
print("ACL")
elif a == 2:
print("ACLACL")
elif a == 3:
print("ACLACLACL")
elif a == 4:
print("ACLACLACLACL")
else:
print("ACLACLACLACLACL") | 1 | 2,196,043,230,820 | null | 69 | 69 |
N = int(input())
S = str(input())
cnt = 0
for i in range(N-2):
if S[i]=='A' and S[i+1]=='B' and S[i+2]=='C':
cnt += 1
print(cnt) | K=int(input())
l=list(input())
c=0
for i in range(K-2):
if l[i]=="A":
if l[i+1]=="B":
if l[i+2]=="C":
c+=1
print(c) | 1 | 99,225,939,168,220 | null | 245 | 245 |
s = input()
count = 1; memo = 0; x = 0
for i in range(1, len(s)):
if s[i-1] == "<" and s[i] == ">":
x += count*(count-1)//2
memo = count
count = 1
elif s[i-1] == ">" and s[i] == "<":
x += count*(count-1)//2+max(count, memo)
memo = 0
count = 1
else:
count += 1
else:
if s[-1] == "<":
x += count*(count+1)//2
else:
x += count*(count-1)//2+max(count, memo)
print(x) | #! /usr/bin/env python3
import sys
import numpy as np
from itertools import groupby
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)
S = readline().decode().rstrip()
cnt = [0] * (len(S) + 1)
for i in range(len(S)):
if S[i] == '<':
cnt[i + 1] = max(cnt[i + 1], cnt[i] + 1)
for i in range(len(S) - 1, -1, -1):
if S[i] == '>':
cnt[i] = max(cnt[i], cnt[i + 1] + 1)
print(sum(cnt)) | 1 | 156,350,198,329,090 | null | 285 | 285 |
a, b, c, k = map(int, input().split())
ans = 0
if a >= k:
ans = k * 1
else:
ans = a * 1 + max(0, (k - a)) * 0 + max(0, (k - a - b)) * (-1)
print(ans)
| a,b,c,k=[int(i) for i in input().split()]
if a>=k:
print(k)
elif a+b>=k:
print(a)
else:
print(a-(k-a-b)) | 1 | 21,826,003,475,708 | null | 148 | 148 |
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)
INF = 10 ** 9
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353
n = I()
A = LI()
S = sorted([(A[k], k + 1) for k in range(n)], reverse=True)
ans = 0
dp = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(n):
for j in range(n):
if i and i <= S[i + j - 1][1]:
dp[i][j] = max(dp[i][j], dp[i - 1][j] + S[i + j - 1][0] * abs(i - S[i + j - 1][1]))
if j and S[i + j - 1][1] <= n - j + 1:
dp[i][j] = max(dp[i][j], dp[i][j - 1] + S[i + j - 1][0] * abs(n - j + 1 - S[i + j - 1][1]))
if i + j == n:
ans = max(ans, dp[i][j])
break
print(ans)
| n = int(raw_input())
a = map(int, raw_input().split())
print " ".join(map(str, a))
for i in range(1, n):
v = a[i]
j = i -1
while j >= 0 and a[j] > v:
a[j+1] = a[j]
j-=1
a[j+1] = v
print " ".join(map(str, a))
| 0 | null | 16,908,467,341,600 | 171 | 10 |
from itertools import combinations_with_replacement as H
N, M, Q = map(int, input().split())
ans = 0
query = [list(map(int, input().split())) for _ in range(Q)]
for A in H(list(range(1, M+1)), N):
acc = 0
for j in range(Q):
a, b, c, d = query[j]
if A[b - 1] - A[a - 1] == c:
acc += d
ans = max(ans, acc)
print(ans)
| list_len = int(input().rstrip())
num_list = list(map(int, input().rstrip().split()))
for i in range(list_len):
v = num_list[i]
j = i - 1
while j >= 0 and num_list[j] > v:
num_list[j + 1] = num_list[j]
j -= 1
num_list[j+1] = v
output_str = ' '.join(map(str, num_list))
print(output_str) | 0 | null | 13,792,587,352,622 | 160 | 10 |
N=int(input())
#N=5
n=N//2
print(1-n/N) | letters = input()
num = int(input())
for i in range(num):
order = input().split()
a = int(order[1])
b = int(order[2])
if order[0] == 'print':
print(letters[a:b+1])
if order[0] == 'reverse':
p = letters[a:b+1]
p = p[::-1]
letters = letters[:a] + p + letters[b+1:]
if order[0] == 'replace':
letters = letters[:a] + order[3] + letters[b+1:]
| 0 | null | 89,745,693,839,518 | 297 | 68 |
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
mod = 10 ** 9 + 7
N, K = MI()
def num(self):
return (-2 * pow(self, 3) + 3 * N * pow(self, 2) + (3 * N + 8) * self) // 6
ans = num(N + 1) - num(K - 1)
print(ans % mod) | import os
import sys
import numpy as np
def solve(inp):
r, c, k = inp[:3]
items = np.zeros((r + 1, c + 1), dtype=np.int64)
rrr = inp[3::3]
ccc = inp[4::3]
vvv = inp[5::3]
for r_, c_, v in zip(rrr, ccc, vvv):
items[r_, c_] = v
dp = np.zeros((r + 1, c + 1, 4), dtype=np.int64)
for i in range(1, r + 1):
for j in range(1, c + 1):
v = items[i, j]
dp[i, j] = np.maximum(dp[i, j - 1], dp[i - 1, j, 3])
if v > 0:
dp[i, j, 1:] = np.maximum(dp[i, j, 1:], dp[i, j, :-1] + v)
return dp[-1, -1, -1]
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
cc = CC('my_module')
cc.export('solve', '(i8[:],)')(solve)
cc.compile()
exit()
if os.name == 'posix':
# noinspection PyUnresolvedReferences
from my_module import solve
else:
from numba import njit
solve = njit('(i8[:],)', cache=True)(solve)
print('compiled', file=sys.stderr)
inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print(ans)
| 0 | null | 19,361,477,613,892 | 170 | 94 |
MOD = 10 ** 9 + 7
n, k = map(int, input().split())
ans = 0
for x in range(k, n + 2):
p = x * (x - 1) // 2
q = x * (x - 1) // 2 + (n - x + 1) * x
ans += q - p + 1
print(ans % MOD)
| n,k=map(int,input().split())
mod=10**9+7
c=0
for i in range(k,n+2):
min=(1/2)*i*(i-1)
max=(1/2)*i*(2*n+1-i)
c+=max-min+1
print(int(c%mod)) | 1 | 32,997,364,064,860 | null | 170 | 170 |
N,M = tuple(map(int,input().split()))
# matchlist = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
#最大のグループの大きさを出す
friendlist = list(range(N))
# [所属先,[所属メンバー]]
gplist = [[i] for i in range(N)]
def getgroup(a):
A = friendlist[a]
if A == a:
return a
else:
return getgroup(A)
def match(ab):
A = getgroup(ab[0])
B = getgroup(ab[1])
if A==B:
return
elif len(gplist[A])<len(gplist[B]):
gplist[B].extend(gplist[A])
friendlist[A] = B
else:
gplist[A].extend(gplist[B])
friendlist[B] = A
for i in range(M):
# print(friendlist)
# print(gplist)
match(tuple(map(lambda x:int(x)-1,input().split())))
# print(friendlist)
# print(gplist)
print(max([len(item) for item in gplist])) | #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,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
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
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', '')
# UnionFind
class UnionFind():
def __init__(self, n):
self.nodes=[-1] * n # nodes[x]: 負なら、絶対値が木の要素数
def get_root(self, x):
# nodes[x]が負ならxが根
if self.nodes[x] < 0:
return x
# 根に直接つなぎ直しつつ、親を再帰的に探す
else:
self.nodes[x]=self.get_root(self.nodes[x])
return self.nodes[x]
def unite(self, x, y):
root_x=self.get_root(x)
root_y=self.get_root(y)
# 根が同じなら変わらない
# if root_x == root_y:
# pass
if root_x != root_y:
# 大きい木の方につないだほうが計算量が減る
if self.nodes[root_x] < self.nodes[root_y]:
big_root=root_x
small_root=root_y
else:
small_root=root_x
big_root=root_y
self.nodes[big_root] += self.nodes[small_root]
self.nodes[small_root]=big_root
def main():
N,M = MI()
uf=UnionFind(N)
get_root, unite, nodes=uf.get_root, uf.unite, uf.nodes
for _ in range(M):
A,B = MI()
unite(A-1,B-1)
ans = 0
for i in range(N):
ans = max(ans, -nodes[get_root(i)])
print(ans)
if __name__ == '__main__':
main() | 1 | 3,955,210,637,520 | null | 84 | 84 |
n = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(n):
for j in range(i+1, n):
for k in range(j+1, n):
if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
pass
elif L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[k] + L[i] > L[j]:
ans += 1
print(ans) | n = int(input())
l = list(map(int, input().split()))
def judge(l, i, j, k):
a = l[i]
b = l[j]
c = l[k]
if a != b and b != c and c != a:
if a + b > c and b + c > a and c + a > b:
return 1
else:
return 0
else:
return 0
cnt = 0
for i in range(n - 2):
for j in range(i + 1, n - 1):
for k in range(j + 1, n):
cnt += judge(l, i, j, k)
print(cnt) | 1 | 4,992,191,137,220 | null | 91 | 91 |
import math
x1,y1,x2,y2=input().split()
x1=float(x1)
y1=float(y1)
x2=float(x2)
y2=float(y2)
r=math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
print(r) | # -*- coding: utf-8 -*-
# ITP1_10_A
import math
pos = list(map(float, input().split()))
x = abs(pos[2] - pos[0])
y = abs(pos[3] - pos[1])
print(math.sqrt(x**2 + y**2))
| 1 | 159,599,213,340 | null | 29 | 29 |
n = int(input())
s, t = map(str, input().split())
sl = list(s)
tl = list(t)
a = []
for i in range(n):
a.append(s[i])
a.append(t[i])
print(''.join(a)) | length = int(input())
first_string, second_string = input().split()
first_list = list(first_string)
second_list = list(second_string)
result_list = []
for i in range(length):
result_list.append(first_list[i])
result_list.append(second_list[i])
result = "".join(result_list)
print(result)
| 1 | 111,569,133,959,262 | null | 255 | 255 |
N, M, X = map(int, input().split())
book_lists = [list(map(int, input().split())) for _ in range(N)]
max_cost = 10**5*12+1
min_cost = max_cost
for i in range(1, 2**N):
score_list = [0 for _ in range(M)]
cost = 0
for j in range(N):
if i >> j & 1:
cost += book_lists[j][0]
for k in range(M):
score_list[k] += book_lists[j][k+1]
if min(score_list) >= X:
min_cost = min(cost, min_cost)
print(min_cost if not min_cost == max_cost else -1)
| n , m , x = map(int, input().split())
a = list(list(map(int, input().split())) for _ in range(n))
c = []
for i in range(n):
c.append(a[i][0])
a[i].pop(0)
ans = 1000000000
# bit全探索
for i in range(1 << n):
score = [0] * m
tmp = 0
for j in range(n):
if (i >> j) % 2 == 1:
tmp += c[j]
for k in range(m):
score[k] += a[j][k]
if min(score) >= x:
ans = min(ans , tmp)
if(ans == 1000000000):
print(-1)
else:
print(ans)
| 1 | 22,243,479,214,620 | null | 149 | 149 |
N, K = map(int, input().split())
MOD = 10 ** 9 + 7
ans = 1
for i in range(K, N + 1):
ans += i * (2 * N - i + 1) // 2 % MOD - i * (i - 1) // 2 % MOD + 1
ans %= MOD
print(ans) | l = input().split()
print(l.index('0')+1)
| 0 | null | 23,288,065,299,350 | 170 | 126 |
import math
N = int(input())
max_D = int(2 + math.sqrt(N))
count = []
ans = 1
for i in range(2, max_D):
if N % i == 0:
count.append(0)
while N % i == 0:
N = N // i
count[-1] += 1
if N < i:
ans = 0
break
l = len(count)
for i in range(l):
E = 2*count[i]
j = 0
while j * (j + 1) <= E:
j += 1
ans += j - 1
print(ans) | def II(): return int(input())
N=II()
d=2
ans=0
while d*d<=N:
if N%d!=0:
d+=1
continue
z=d
while N%z==0:
ans+=1
N//=z
z*=d
while N%d==0:
N//=d
if N!=1:
ans+=1
print(ans) | 1 | 16,869,774,931,744 | null | 136 | 136 |
import math
def sieve_of_erastosthenes(num):
is_prime = [True for i in range(num+1)]
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(num**0.5) + 1):
if not is_prime[i]:
continue
for j in range(i * 2, num + 1, i):
is_prime[j] = False
return [i for i in range(num + 1) if is_prime[i]]
N = int(input())
A = [int(i) for i in input().split()]
ans = math.gcd(A[0], A[1])
tmp = math.gcd(A[0], A[1])
for i in range(2, N):
ans = math.gcd(ans, A[i])
if ans > 1:
print('not coprime')
exit()
maxA = max(A)
l = sieve_of_erastosthenes(maxA)
B = [False for i in range(maxA+1)]
for i in range(N):
B[A[i]] = True
flag = False
for each in l:
tmp = each
counter = 0
while True:
if B[tmp]:
counter += 1
tmp += each
if tmp > maxA:
break
if counter > 1:
flag = True
break
if flag:
print('setwise coprime')
else:
print('pairwise coprime') | from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
Ones = A.count(1)
R = max(A)
nums = [0]*(R+1)
# 素因数テーブルの作成
D = [0]*(R+1)
for i in range(2, R+1):
if D[i]:
continue
n = i
while n < R+1:
if D[n] == 0:
D[n] = i
n += i
# 素因子をカウント
for a in A:
tmp = a
while tmp > 1:
prime_factor = D[tmp]
nums[prime_factor] += 1
while tmp%prime_factor == 0:
tmp //= prime_factor
y = max(nums)
if y < 2:
print('pairwise coprime')
elif y-Ones < N:
print('setwise coprime')
else:
print('not coprime') | 1 | 4,097,285,139,288 | null | 85 | 85 |
import math
def main():
r = int(input())
print(math.pi *r *2)
if __name__ == "__main__":
main() | R = int(input())
print(R * 6.28318530717958623200)
| 1 | 31,278,391,903,360 | null | 167 | 167 |
n = int(input())
t = 0
for _ in range(n):
d1,d2 = map(int, input().split())
if d1 != d2: t = 0
else: t += 1
if t == 3:
print("Yes")
exit()
print("No") | n = int(input())
a = list(map(int,input().split()))
d = {}
for i in range(1,n+1):
if i not in d:
d[i] = 0
for i in range(len(a)):
d[a[i]] += 1
for i in range(1,n+1):
print(d[i]) | 0 | null | 17,425,889,800,638 | 72 | 169 |
h = []
w = []
while True:
a,b = map(int, raw_input().split())
h.append(a)
w.append(b)
if a == 0 and b == 0:
break
for h,w in zip(h,w):
if h == 0 and w == 0:
break;
else:
r = "#"
for x in xrange(w-1):
r = r + "#"
for x in xrange(h):
print r
print | n=int(input())
if n%2==0:
print(int((n/2)-1))
else:
print(int((n-1)/2))
| 0 | null | 77,418,788,979,520 | 49 | 283 |
x,y = map(int,input().split())
if x > 3:
x = 4
if y > 3:
y = 4
ans = 0
if x == y == 1:
ans += 400000
ans += (8-x-y)*100000
print(ans) | import itertools
N, K = map(int, input().split())
p = list(map(int, input().split()))
pos = [(p[i]+1)/2 for i in range(N)]
pos_acum = list(itertools.accumulate(pos))
ans = pos_acum[K-1]
for i in range(N-K):
ans = max(ans, pos_acum[K+i]-pos_acum[i])
print(ans) | 0 | null | 107,450,546,546,088 | 275 | 223 |
from itertools import groupby
S=input()
T=groupby(S)
s=0
total=0
keys=[]
groups=[]
for key,group in T:
keys.append(key)
groups.append(len(list(group)))
if keys[0]==">":
total+=sum([i for i in range(groups[0]+1)])
if keys[-1]=="<":
total+=sum([i for i in range(groups[-1]+1)])
for i in range(len(keys)-1):
if keys[i]=="<":
if groups[i]<=groups[i+1]:
total+=sum([j for j in range(groups[i])])
total+=sum([j for j in range(groups[i+1]+1)])
else:
total+=sum([k for k in range(groups[i]+1)])
total+=sum([k for k in range(groups[i+1])])
print(total) | t1, t2 = (int(x) for x in input().split())
a1, a2 = (int(x) for x in input().split())
b1, b2 = (int(x) for x in input().split())
if a1 < b1:
a1, b1 = b1, a1
a2, b2 = b2, a2
if a1 * t1 + a2 * t2 > b1 * t1 + b2 * t2:
print(0)
exit()
elif a1 * t1 + a2 * t2 == b1 * t1 + b2 * t2:
print("infinity")
exit()
d1 = (a1 - b1) * t1
d2 = (b2 - a2) * t2
k = d1 // (d2 - d1)
if d1 % (d2 - d1) == 0:
print(2 * k)
else:
print(2 * k + 1)
| 0 | null | 143,686,353,610,880 | 285 | 269 |
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
iA = [(i, A[i]) for i in range(N)]
iA.sort(key=lambda t: t[1], reverse=True)
dp = [[0]*(N+1) for _ in range(N+1)]
for i in range(N):
for j in range(N):
if i+j<N:
idx, v = iA[i+j]
dp[i+1][j] = max(dp[i+1][j], dp[i][j]+v*abs(idx-i))
dp[i][j+1] = max(dp[i][j+1], dp[i][j]+v*abs(N-1-j-idx))
ans = 0
for i in range(N+1):
ans = max(ans, dp[i][N-i])
print(ans) | from sys import stdin
from math import ceil
inp = lambda : stdin.readline().strip()
n, x, t = [int(x) for x in inp().split()]
print(ceil(n/x)*t) | 0 | null | 18,924,199,625,098 | 171 | 86 |
A,B,C=[int(s) for s in input().split()]
X=int(input())
count=0
while A>=B:
B*=2
count+=1
while B>=C:
C*=2
count+=1
if count<=X:
print('Yes')
else:
print('No')
| def main():
A, B, C = map(int, input().split())
K = int(input())
while K > 0 and A >= B:
B *= 2
K -= 1
while K > 0 and B >= C:
C *= 2
K -= 1
if A < B < C:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | 1 | 6,851,760,380,100 | null | 101 | 101 |
def main():
n = int(input())
if n < 10 or n % 2 == 1:
print(0)
else:
ans = 0
i = 10
while i <= n:
ans += n // i
i *= 5
print(ans)
if __name__ == '__main__':
main()
| H,N=map(int,input().split())
list=[]
for i in map(int,input().split()):
list.append(i)
if H - sum(list) <= 0:
print('Yes')
else:
print('No')
| 0 | null | 97,353,495,721,536 | 258 | 226 |
A, B = [int(_) for _ in input().split()]
print(A * B)
| n = input().split(" ")
print(int(n[0]) * int(n[1])) | 1 | 15,839,742,423,868 | null | 133 | 133 |
from collections import deque
V = int(input())
edge = [[] for _ in range(V)]
for _ in range(V):
u, _, *v = map(lambda x: int(x)-1, input().split())
edge[u] = sorted(v)
dist = [-1] * V
dist[0] = 0
que = deque([0])
while len(que):
v = que.popleft()
for c in edge[v]:
if dist[c] == -1:
dist[c] = dist[v] + 1
que.append(c)
for i, d in enumerate(dist):
print(i+1, d) | from collections import deque
from collections import defaultdict
n = int(input())
graph = defaultdict(list)
for i in range(n):
u, k, *v = map(int, input().split())
for v in v:
graph[u].append(v)
ans = [-1] * (n + 1)
q = deque([1])
ans[1] = 0
while q:
c = q.popleft()
for v in graph[c]:
if ans[v] == -1:
ans[v] = ans[c] + 1
q.append(v)
for i in range(1, n + 1):
print(i, ans[i])
| 1 | 3,914,922,500 | null | 9 | 9 |
#!python3
iim = lambda: map(int, input().rstrip().split())
def resolve():
n, m = iim()
C = list(iim())
dp = [n] * (n + 1)
dp[0] = 0
for co in C:
for i in range(co, n+1):
dp[i] = min(dp[i], dp[i-co] + 1)
print(dp[n])
if __name__ == "__main__":
resolve()
| # DPL_1_A - コイン問題
import sys
N, M = map(int, sys.stdin.readline().strip().split()) # N払う コイン種類M 枚
c = list(map(int, sys.stdin.readline().strip().split()))
# dp 初期化
dp = [[float('inf')] * (N + 1) for _ in range(M + 1)]
for i in range(len(dp)):
dp[i][0] = 0
for m in range(M):
for n in range(N + 1):
dp[m + 1][n] = min(dp[m + 1][n], dp[m][n])
next_n = n + c[m]
if next_n <= N:
dp[m + 1][next_n] = min(dp[m + 1][n] + 1, dp[m][next_n])
# for i in range(len(dp)):
# print(dp[i])
print(dp[-1][-1])
| 1 | 139,070,582,970 | null | 28 | 28 |
n = int(input())
S = list(map(int, input().split()))
cnt = 0
def merge(left, mid, right):
global cnt
n1 = mid - left
n2 = right - mid
L = S[left:left+n1]
R = S[mid:mid+n2]
L.append(10e10)
R.append(10e10)
for j in range(n2):
R[j] = S[mid+j]
x = 0
y = 0
for k in range(left, right):
cnt += 1
if L[x] < R[y]:
S[k] = L[x]
x += 1
else:
S[k] = R[y]
y += 1
def mergesort(left, right):
if left+1 < right:
mid = (left + right)//2
mergesort(left, mid)
mergesort(mid, right)
merge(left, mid, right)
mergesort(0, n)
print(*S)
print(cnt)
| INFTY=1000000000
n=int(input())
A=list(map(int,input().split()))
def merge(A,left,mid,right):
cnt=0
n1=mid-left
n2=right-mid
L=[A[left+i] for i in range(n1)]
R=[A[mid+i] for i in range(n2)]
L.append(INFTY)
R.append(INFTY)
i=0
j=0
for k in range(left,right):
cnt+=1
if L[i]<=R[j]:
A[k]=L[i]
i+=1
else:
A[k]=R[j]
j+=1
return cnt
def mergeSort(A,left,right):
if left+1<right:
mid=(left+right)//2
cnt1=mergeSort(A,left,mid)
cnt2=mergeSort(A,mid,right)
return merge(A,left,mid,right)+cnt1+cnt2
return 0
cnt=mergeSort(A,0,n)
print(' '.join(map(str,A)))
print(cnt)
| 1 | 113,919,842,610 | null | 26 | 26 |
#!/usr/bin/python3
import bisect
n = int(input())
s = input()
q = int(input())
idxs = [ [] for i in range(26) ]
sl = [ s[i] for i in range(n) ]
for i in range(n):
idxs[ord(s[i]) - ord('a')].append(i + 1)
#print(idxs)
qs = []
for i in range(q):
qs.append(input())
for qi in qs:
(op, x, y) = qi.split()
if op == '1':
j = int(x)
c = y
oc = sl[j - 1]
if oc != c:
sl[j - 1] = c
idx = bisect.bisect_left(idxs[ord(oc) - ord('a')], j)
del idxs[ord(oc) - ord('a')][idx]
idx = bisect.bisect_left(idxs[ord(c) - ord('a')], j)
idxs[ord(c) - ord('a')].insert(idx, j)
elif op == '2':
l = int(x)
r = int(y)
c = 0
for i in range(26):
il = bisect.bisect_left(idxs[i], l)
ir = bisect.bisect_right(idxs[i], r)
if il < ir:
c += 1
print(c)
| import sys
import bisect
input = sys.stdin.readline
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-2):
for j in range(i+1, N-1):
l = L[i] + L[j]
p = bisect.bisect_left(L, l)
# print(p)
ans += p - j - 1
print(ans) | 0 | null | 117,595,618,811,320 | 210 | 294 |
from collections import Counter
def prime_factorization(n):
A = []
while n % 2 == 0:
n //= 2
A.append(2)
i = 3
while i * i <= n:
if n % i == 0:
n //= i
A.append(i)
else:
i += 2
if n != 1:
A.append(n)
return A
n = int(input())
A = list(Counter(prime_factorization(n)).values())
ans = 0
e = 1
while True:
cnt = 0
for i in range(len(A)):
if A[i] >= e:
A[i] -= e
cnt += 1
if cnt == 0:
break
ans += cnt
e += 1
print(ans)
| import math
N = int(input())
n = math.ceil(N/1000)
print(1000*n-N) | 0 | null | 12,619,539,568,338 | 136 | 108 |
S = input()
T = input()
Ns = len(S)
Nt = len(T)
ans = 0
for i in range(Ns - Nt + 1):
tmp = 0
for j in range(Nt):
if S[i + j] == T[j]:
tmp += 1
ans = max(ans, tmp)
print(Nt - ans) | D=int(input())
C=list(map(int, input().split()))
S=[list(map(int,input().split())) for i in range(D)]
T=[]
for i in range(D):
T.append(int(input()))
def dissat(day):
dissat = 0
for i in range(26):
if T[day-1]-1 == i:
continue
dissat += C[i]*(day-lastdays[i])
return dissat
def last(day):
lastdays[T[day-1]-1] = day
sat = 0
lastdays = [0]*26
# main
for i in range(D):
# dayi
last(i)
sat += S[i][T[i]-1] - dissat(i+1)
print(sat)
| 0 | null | 6,883,710,713,826 | 82 | 114 |
import sys
import math
from collections import defaultdict
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid_int(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
R, C, K = NMI()
grid = make_grid_int(R, C, 0)
for i in range(K):
r_, c_, v_, = NMI()
grid[r_ - 1][c_ - 1] = v_
dp = [[[0 for _ in range(C + 2)] for _ in range(R + 2)] for _ in range(4)]
for i in range(R + 1):
for j in range(C + 1):
for k in range(4):
a = dp[k][i][j]
try:
v = grid[i][j]
except:
v = 0
if k == 3:
dp[0][i + 1][j] = max(a, dp[0][i + 1][j])
continue
dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j])
dp[k][i][j + 1] = max(a, dp[k][i][j + 1])
dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1])
print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))
if __name__ == "__main__":
main() | import sys
import copy
R, C, K = map(int, input().split())
item = [[0] * (C + 1) for _ in range(R + 1)] # dp配列と合わせるために, 0行目, 0列目を追加している.
for s in sys.stdin.readlines():
r, c, v = map(int, s.split())
r -= 1
c -= 1
item[r][c] = v
dp0 = [[0] * (C+1) for r in range(R+1)]
dp1 = [[0] * (C+1) for r in range(R+1)]
dp2 = [[0] * (C+1) for r in range(R+1)]
dp3 = [[0] * (C+1) for r in range(R+1)]
for r in range(R):
for c in range(C):
dp3[r][c] = max(dp3[r][c], dp2[r][c] + item[r][c])
dp2[r][c] = max(dp2[r][c], dp1[r][c] + item[r][c])
dp1[r][c] = max(dp1[r][c], dp0[r][c] + item[r][c])
dp1[r][c+1] = max(dp1[r][c], dp1[r][c+1])
dp2[r][c+1] = max(dp2[r][c], dp2[r][c+1])
dp3[r][c+1] = max(dp3[r][c], dp3[r][c+1])
dp0[r+1][c] = max(dp0[r+1][c], dp1[r][c])
dp0[r+1][c] = max(dp0[r+1][c], dp2[r][c])
dp0[r+1][c] = max(dp0[r+1][c], dp3[r][c])
ans = max(dp0[R-1][C-1], dp1[R-1][C-1])
ans = max(ans, dp3[R-1][C-1])
ans = max(ans, dp2[R-1][C-1])
print(ans) | 1 | 5,577,356,913,370 | null | 94 | 94 |
n,x,y = map(int,input().split())
l= [0]*n
for i in range(1,n+1):
for j in range(i+1,n+1):
k = min(abs(j-i),abs(x-i)+1+abs(j-y))
l[k] += 1
for k in range(1,n):
print(l[k]) | N, X, Y = [int(x) for x in input().split()]
counter = [0] * N
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
d = min(abs(i - j), abs(i - X) + abs(j - Y) + 1, abs(i - Y) + abs(j - X) + 1)
counter[d] += 1
for i in range(1, N):
print(counter[i]) | 1 | 44,245,994,653,110 | null | 187 | 187 |
x, y = map(int,input().split())
print((max(4-x, 0) + max(4-y, 0) + 4*max(3-x-y, 0)) * 100000) | x,y = map(str,input().split())
a = {'1':300000,'2':200000,'3':100000}
if int(x) > 3 or int(y) > 3:
if int(x) <= 3:
print(a[x])
elif int(y) <= 3:
print(a[y])
else:
print(0)
else:
if x == y == '1':
print(1000000)
else:
print(a[x]+a[y]) | 1 | 140,736,680,411,780 | null | 275 | 275 |
n = int(input())
al = []
bl = []
for _ in range(n):
a, b = map(int, input().split())
al.append(a)
bl.append(b)
al.sort()
bl.sort()
if n%2 == 1:
print(bl[n//2] - al[n//2] + 1)
else:
print(bl[n//2-1]-al[n//2]+bl[n//2]-al[n//2-1]+1) | D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
t = [int(input()) for i in range(D)]
last = [0]*26
S = 0
for d in range(1, D+1):
# last更新
for j in range(26):
if j == t[d-1]-1:
last[j] = d
# plus部分
S += s[d-1][t[d-1]-1]
# minus部分
m = 0
for j in range(26):
m += c[j] * (d-last[j])
S -= m
print(S) | 0 | null | 13,488,321,429,040 | 137 | 114 |
H, N = map(int, input().split())
A = [int(x) for x in input().split()]
AA = sum(A)
if AA >= H:
print("Yes")
else:
print("No")
| n = int(input())
a = list(map(int, input().split()))
def num_left(pos):
if pos % 2 == 0:
return (n - pos) // 2 + 1
else:
return (n - pos - 1) // 2 + 1
d = [{} for i in range(n)]
for i in range(n):
if i < 2:
d[i][0] = 0
d[i][1] = a[i]
else:
left = num_left(i + 2)
#print("i = ", i, left)
j = i - 2
while j >= 0:
max_count = max(d[j].keys())
if max_count + left + 1 < n // 2:
break
else:
for count, v in d[j].items():
#print(count, v)
if count + left + 1 >= n // 2:
if count + 1 in d[i]:
d[i][count + 1] = max(d[i][count + 1], v + a[i])
else:
d[i][count + 1] = v + a[i]
j -= 1
if 1 + left >= n // 2:
d[i][0] = 0
best = None
for i in range(n):
for count, result in d[i].items():
if count == n // 2:
if best is None:
best = result
else:
best = max(best, result)
#print(d)
print(best)
| 0 | null | 57,883,607,606,052 | 226 | 177 |
H, N = map(int, input().split())
AB = []
INF = 10**8 + 1
dp = [INF]*(H+1)
dp[0] = 0
for _ in range(N):
a, b = map(int, input().split())
AB.append((a, b))
for i in range(1, H+1):
for j in range(N):
dp[i] = min(dp[i], dp[max(0, i - AB[j][0])] + AB[j][1])
print(dp[-1]) | import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline
class UnionFind:
def __init__(self, n: int):
self.n = n
self.parents = [-1] * n
def find(self, x: int):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x: int, y: int):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[y] < self.parents[x]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x: int):
return -self.parents[self.find(x)]
def same(self, x: int, y: int):
return self.find(x) == self.find(y)
def members(self, x: int):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def solve():
N, K = map(int, rl().split())
P = list(map(lambda n: int(n) - 1, rl().split()))
C = list(map(int, rl().split()))
uf = UnionFind(N)
for i in range(N):
uf.union(i, P[i])
roop_scores = defaultdict(int)
for i in range(N):
roop_scores[uf.find(i)] += C[i]
ans = -(10 ** 18)
K -= 1
for s in range(N):
cur = P[s]
tmp = C[cur]
ans = max(ans, tmp)
roop_size = uf.size(s)
roop_score = roop_scores[uf.find(s)]
roop_cnt = K // roop_size
if roop_cnt and 0 < roop_score:
tmp += roop_score * roop_cnt
rem = K % roop_size
ans = max(ans, tmp)
while rem:
cur = P[cur]
tmp += C[cur]
ans = max(ans, tmp)
rem -= 1
continue
cnt = min(roop_size, K)
while cnt:
cur = P[cur]
tmp += C[cur]
ans = max(ans, tmp)
cnt -= 1
print(ans)
if __name__ == '__main__':
solve()
| 0 | null | 43,350,763,010,350 | 229 | 93 |
n = int(input())
count_taro = 0
count_hanako = 0
for i in range(n):
taro,hanako = map(str, input().split())
if taro > hanako:
count_taro += 3
if hanako > taro:
count_hanako += 3
if hanako == taro:
count_hanako += 1
count_taro += 1
print(count_taro, count_hanako)
| import copy
import random
import sys
import time
from collections import deque
t1 = time.time()
readline = sys.stdin.buffer.readline
global NN
NN = 26
def evaluate(D, C, S, out, k):
score = 0
last = [0 for _ in range(NN)]
for d in range(len(out)):
last[out[d]] = d + 1
for i in range(NN):
score -= (d + 1 - last[i]) * C[i]
score += S[d][out[d]]
for d in range(len(out), min(D, len(out) + k)):
for i in range(NN):
score -= (d + 1 - last[i]) * C[i]
return score
def compute_score(D, C, S, out):
score = 0
last = [0 for _ in range(NN)]
for d in range(len(out)):
p = out[d]
last[p] = d + 1
last[out[d]] = d + 1
for i in range(NN):
score -= (d + 1 - last[i]) * C[i]
score += S[d][out[d]]
return score
def solve(D, C, S, k):
out = deque()
for _ in range(D):
max_score = -10 ** 8
best_i = 0
for i in range(NN):
out.append(i)
score = evaluate(D, C, S, out, k)
if max_score < score:
max_score = score
best_i = i
out.pop()
out.append(best_i)
return out, score
# 1箇所ランダムに変える
def random_change(D, C, S, out, score):
new_out = copy.deepcopy(out)
d = random.randrange(0, D)
new_out[d] = random.randrange(0, NN)
new_score = compute_score(D, C, S, new_out)
if new_score > score:
score = new_score
out = new_out
return out, score
def random_change0(D, C, S, out, score):
new_out = copy.deepcopy(out)
d = random.randrange(0, 10)
new_out[d] = random.randrange(0, NN)
new_score = compute_score(D, C, S, new_out)
if new_score > score:
score = new_score
out = new_out
return out, score
# N箇所ランダムに変える
def random_changeN(D, C, S, out, score, N):
new_out = copy.deepcopy(out)
for _ in range(N):
d = random.randrange(0, D)
new_out[d] = random.randrange(0, NN)
new_score = compute_score(D, C, S, new_out)
if new_score > score:
score = new_score
out = new_out
return out, score
# 2つswap
def random_swap2(D, C, S, out, score):
d1 = random.randrange(0, D - 1)
d2 = random.randrange(d1 + 1, min(d1 + 16, D))
new_out = copy.deepcopy(out)
new_out[d1], new_out[d2] = out[d2], out[d1]
new_score = compute_score(D, C, S, out)
if new_score > score:
score = new_score
out = new_out
return out, score
# 3つswap
def random_swap3(D, C, S, out, score):
d1 = random.randrange(0, D - 1)
d2 = random.randrange(d1 + 1, min(d1 + 8, D))
d3 = random.randrange(max(d1 - 8, 0), d1 + 1)
new_out = copy.deepcopy(out)
new_out[d1], new_out[d2], new_out[d3] = out[d2], out[d3], out[d1]
new_score = compute_score(D, C, S, out)
if new_score > score:
score = new_score
out = new_out
return out, score
def random_swap0(D, C, S, out, score):
d1 = random.randrange(0, 6)
d2 = random.randrange(6, 13)
new_out = copy.deepcopy(out)
new_out[d1], new_out[d2] = out[d2], out[d1]
new_score = compute_score(D, C, S, out)
if new_score > score:
score = new_score
out = new_out
return out, score
def main():
D = int(readline())
C = list(map(int, readline().split()))
S = [list(map(int, readline().split())) for _ in range(D)]
# ランダムな初期値
# out = [random.randrange(0, NN) for _ in range(D)]
# 貪欲法で初期値を決める
max_score = -10 ** 8
max_k = 0
for k in range(6):
out, score = solve(D, C, S, k)
if score > max_score:
max_score = score
max_out = out
max_k = k
# # local minimumを避けるため,outを少し変える
out = max_out
score = max_score
out, score = solve(D, C, S, max_k)
out[0] = random.randrange(NN)
for cnt in range(10 ** 10):
out, score = random_changeN(D, C, S, out, score, N=1)
out, score = random_swap3(D, C, S, out, score)
t2 = time.time()
if t2 - t1 > 1.85:
break
ans = [str(i + 1) for i in out]
print("\n".join(ans))
main()
| 0 | null | 5,849,115,753,248 | 67 | 113 |
def insertionSort(n, A, g):
global cnt
for i in range(g, n):
temp = A[i]
j = i - g
while j >= 0 and A[j] > temp:
A[j + g] = A[j]
j -= g
cnt += 1
A[j + g] = temp
return A
def shellSort(A, n):
global m
global G
h = 1
while True:
if h > n:
break
G.append(h)
h = 3 * h + 1
G.reverse()
m =len(G)
for i in range(m):
insertionSort(n, A, G[i])
if __name__ == "__main__":
n = int(input())
A = [int(input()) for i in range(n)]
G = []
m = 0
cnt = 0
shellSort(A, n)
print(m)
print(*G)
print(cnt)
for i in range(n):
print(A[i]) | for i in range(1, 10):
for j in range(1, 10):
print(i, end="")
print("x", end="")
print(j, end="")
print("=", end="")
print(i*j) | 0 | null | 15,363,970,480 | 17 | 1 |
k = int(input())
a,b = map(int,input().split())
x = (b // k) * k
if a <= x <= b :
print('OK')
else :
print('NG') | K = int(input())
A, B = map(int, input().split(" "))
if B//K - ((A-1)//K)>0:
print('OK')
else:
print('NG') | 1 | 26,523,543,903,660 | null | 158 | 158 |
word, num = input(), 0
while True:
sentence = input()
if sentence=="END_OF_TEXT":
break
word_list = sentence.lower().replace(".", " ").split()
for i in word_list:
if word==i:
num += 1
print(num)
| import sys
input = sys.stdin.buffer.readline
def main():
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
l = (A1-B1)*T1 + (A2-B2)*T2
if l == 0:
print("infinity")
elif l > 0:
if A1 > B1:
print(0)
else:
d = (B1-A1)*T1
if d%l == 0:
ans = 2*(d//l)
else:
ans = 1+2*(d//l)
print(ans)
else:
l *= -1
if B1 > A1:
print(0)
else:
d = (A1-B1)*T1
if d%l == 0:
ans = 2*(d//l)
else:
ans = 1+2*(d//l)
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 66,636,259,797,572 | 65 | 269 |
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') | import numpy as np
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
if V <= W:
print("NO")
elif np.abs(A - B) / (V - W) <= T: print("YES")
else:
print("NO") | 1 | 15,091,463,506,560 | null | 131 | 131 |
import sys
from collections import deque
def m():
s=sys.stdin.readlines()
q=int(s[0].split()[1])
f=lambda x,y:(x,int(y))
d=deque(f(*e.split())for e in s[1:])
t,a=0,[]
while d:
k,v=d.popleft()
if v>q:v-=q;t+=q;d.append([k,v])
else:t+=v;a+=[f'{k} {t}']
print('\n'.join(a))
if'__main__'==__name__:m()
| from collections import Counter
N = int(input())
A = list(map(int, input().split()))
L = [a+i for a, i in enumerate(A, 1)]
R = [a-i for a, i in enumerate(A, 1)]
ans = 0
R_c = Counter(R)
for l in L:
ans += R_c[l]
print(ans) | 0 | null | 12,942,651,560,922 | 19 | 157 |
n = int(input())
x = int(input(),2)
def popcount(l):
return bin(l).count("1")
def count(l):
res = 0
while l != 0:
p = popcount(l)
l %= p
res += 1
return res
m = popcount(x)
x_plus = x%(m+1)
if m != 1:
x_minus = x%(m-1)
else:
x_minus = 1
lis_plus = [0]*n
lis_minus = [0]*n
for i in range(n):
if i == 0:
lis_plus[i] = 1%(m+1)
if m != 1:
lis_minus[i] = 1%(m-1)
else:
lis_plus[i] = lis_plus[i-1]*2%(m+1)
if m != 1:
lis_minus[i] = lis_minus[i-1]*2%(m-1)
for i in range(n):
if (x >> (n-i-1)) & 1:
if m == 1:
print(0)
else:
print(count((x_minus - lis_minus[-i-1])%(m-1)) + 1)
else:
print(count((x_plus + lis_plus[-i-1])%(m+1)) + 1) |
import sys
input = sys.stdin.readline
N,K = map(int,input().split())
MOD = 998244353
dp = [0 for _ in range(N+1)]
dp[1] = 1
R = [tuple(map(int,input().split())) for _ in range(K)]
S = [0 for _ in range(K)]
for i in range(2, N+1):
s = 0
for k in range(K):
S[k] += dp[max(0, i - R[k][0])] - dp[max(0, i - R[k][1] - 1)]
S[k] %= MOD
s = (s + S[k]) % MOD
dp[i] = s
print(dp[N]) | 0 | null | 5,406,013,363,520 | 107 | 74 |
a= int(input())
h = a//3600
m = (a%3600)//60
s = (a%3600)%60
print('%d:%d:%d' % (h, m, s))
| xy = list(map(int,input().split()))
prise = 0
for i in xy:
if i == 1:
prise += 300000
elif i == 2:
prise += 200000
elif i == 3:
prise += 100000
if sum(xy) == 2:
prise += 400000
print(prise) | 0 | null | 70,391,999,067,610 | 37 | 275 |
n=int(input())
s,t=input().split()
a=str()
for i in range(n):
a=a+s[i]+t[i]
print(a) | import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
for a in A:
if a % 2 == 0:
if not (a % 3 == 0 or a % 5 == 0):
print("DENIED")
break
else:
print("APPROVED")
| 0 | null | 90,463,625,426,020 | 255 | 217 |
s = input()
t = input()
ans = 0
for i in range(len(s) - len(t) + 1):
count = 0
for j in range(len(t)):
if s[i + j] == t[j]:
count += 1
if ans <= count:
ans = count
print(len(t) - ans) | s=str(input())
t=str(input())
ans=0
for i in range(0,len(s)-len(t)+1):
tmp=0
for j in range(len(t)):
if s[i+j]==t[j]:
tmp=tmp+1
ans=max(ans,tmp)
print(len(t)-ans) | 1 | 3,633,482,470,432 | null | 82 | 82 |
s = input()
h = 'hi'
if s == h or s == h * 2 or s == h * 3 or s == h * 4 or s == h * 5:
print('Yes')
else:
print('No') | from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
d=defaultdict(int)
for i in range(n):
d[i-a[i]]+=1
ans=0
for i in range(n):
ans+=d[i+a[i]]
print(ans) | 0 | null | 39,612,487,974,082 | 199 | 157 |
N = int(input())
S = input()
plus = N % 26
result = ''
for c in S:
next = ord(c) + plus
result += chr(next - 26) if next > 90 else chr(next)
print(result)
| N=int(input())
S=input()
ans=""
for x in S:
if ord("Z")<ord(x)+N:
ans+=chr(ord(x)+N-26)
else:
ans+=chr(ord(x)+N)
print(ans)
| 1 | 134,292,587,848,210 | null | 271 | 271 |
from collections import deque
n=int(input())
arr=[[] for _ in range(n)]
for i in range(n-1):
a,b=map(int,input().split())
arr[a-1].append([b-1,i])
arr[b-1].append([a-1,i])
que=deque([0])
ans=[0]*(n-1)
par=[0]*n
par[0]=-1
while que:
x=que.popleft()
p=par[x]
color=1
for tup in arr[x]:
if p==color:
color+=1
if ans[tup[1]]==0:
ans[tup[1]]=color
par[tup[0]]=color
color+=1
que.append(tup[0])
print(max(ans))
print(*ans,sep='\n') | import sys
L,R,d = map(int, sys.stdin.readline().split())
# L=5
# R=10
# d=2
result = 0
for index in range(L,R+1):
if index % d == 0:
result += 1
print(result)
| 0 | null | 71,418,086,982,720 | 272 | 104 |
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
N = int(input())
N_div = make_divisors(N)[1:]
N1_div = make_divisors(N-1)[1:]
ans = len(N1_div)
for i in N_div:
n = N
while n % i == 0:
n //= i
if n % i == 1:
ans += 1
print(ans) | N=int(input())
def make_divisors(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return (lower_divisors + upper_divisors[::-1])[1:]
F = make_divisors(N)
count = 0
for f in F:
n = N
while 1:
if n % f != 0:
n = n % f
else:
n = n // f
if n < f:
break
if n == 1: count += 1
print(count + len(make_divisors(N-1))) | 1 | 41,464,849,156,640 | null | 183 | 183 |
import math
x = int(input())
ans = 0
y = 100
while y < x:
y += y//100
ans += 1
print(ans) | x=int(input())
cnt=0
money = 100
while(1):
cnt += 1
money += money//100
if money >= x:
print(cnt)
quit() | 1 | 26,908,209,348,672 | null | 159 | 159 |
a, b = map(int, input().split())
c, d = map(int, input().split())
print(1 if c != a else 0) | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
M1, D1 = MAP()
M2, D2 = MAP()
print(0 if M1==M2 else 1)
| 1 | 124,683,481,156,010 | null | 264 | 264 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
#DP[i] = i までの魔法でモンスターの体力を減らすため消耗する魔力の最小値
dp = [0] * 20001
for i in range(h):
dp[i] = min(dp[i-a] + b for a, b in ab)
print(dp[h-1])
| h,n=map(int,input().split())
a=[]
b=[]
for _ in range(n):
x,y=map(int,input().split())
a.append(x)
b.append(y)
a_=max(a)
dp=[10**8]*(h+1+a_)
dp[0]=0
for i in range(1,len(dp)):
for j in range(n):
if 0<=i-a[j]<=len(dp)-1-a[j]:
dp[i]=min(dp[i],dp[i-a[j]]+b[j])
print(min(dp[h:])) | 1 | 81,068,334,511,558 | null | 229 | 229 |
import math;
n,x,t=list(map(int,input().split()))
print(math.ceil(n/x)*t) | _n = int(raw_input())
_a = [int(x) for x in raw_input().split()]
for i in range(1, _n):
print(" ".join([str(x) for x in _a]))
key = _a[i]
j = i - 1
while j >= 0 and _a[j] > key:
_a[j+1] = _a[j]
j -= 1
_a[j+1] = key
print(" ".join([str(x) for x in _a])) | 0 | null | 2,128,677,100,018 | 86 | 10 |
def main():
N = int(input())
S = str(input())
ans = ''
alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
for i in range(len(S)):
c = alphabet.index(S[i]) + N
if c > 25:
c = c - 26
ans = ans + alphabet[c]
print(ans)
main() | N=int(input())
lis=[chr(i) for i in range(97, 97+26)]
ans=''
while N>0:
N-=1
ans+=lis[N%26]
N=N//26
print(ans[::-1]) | 0 | null | 73,406,245,940,742 | 271 | 121 |
HP, n = map(int,input().split())
a = list(map(int,input().split()))
count = 0
for i in a:
count += i
if count >= HP:
print("Yes")
else:
print("No") | from collections import Counter
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
ans = sum(A)
num = Counter(A)
for i in range(Q):
b,c = map(int,input().split())
ans += (c-b)*num[b]
num[c] += num[b]
num[b] = 0
print(ans) | 0 | null | 45,178,178,373,090 | 226 | 122 |
#! /usr/bin/env python
# -*- coding : utf-8 -*-
input()
seq = [int(x) for x in input().split()]
for i in range(0, len(seq)):
key = seq[i]
j = i - 1
assert isinstance(i, int)
while j >= 0 and seq[j] > key:
seq[j + 1] = seq[j]
j -= 1
seq[j + 1] = key
print(' '.join(map(str,seq))) | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
s,t = input().split()
print(''.join([s[i] + t[i] for i in range(n)])) | 0 | null | 56,087,913,266,780 | 10 | 255 |
n = int(input())
L = list(map(int,input().split(' ')))
L.sort()
ans = 0
for i in range(n-2):
for j in range(i+1,n-1):
for k in range(j+1,n):
if L[i]==L[j]:
continue
if L[j]==L[k]:
continue
if L[i]+L[j] <= L[k]:
continue
ans+=1
print(ans)
| n, x, m = map(int, input().split())
def solve(n, x, m):
if n == 1:
return x
arr = [x]
for i in range(1, n):
x = x*x % m
if x in arr:
rem = n-i
break
else:
arr.append(x)
else:
rem = 0
sa = sum(arr)
argi = arr.index(x)
roop = arr[argi:]
nn, r = divmod(rem, len(roop))
return sa + nn*sum(roop) + sum(roop[:r])
print(solve(n, x, m)) | 0 | null | 3,891,010,528,992 | 91 | 75 |
n = int(input())
x = input().split()
a = list(map(int, x))
b = []
for i in range(n):
b.append(a[n - 1 - i])
for output in b[:n - 1]:
print(output, end=' ')
print(b[n - 1])
| input()
print(*reversed([int(e) for e in input().split()])) | 1 | 978,235,997,020 | null | 53 | 53 |
n = int(input())
d1 = [0] * n
d2 = [0] * n
for i in range(n):
d1[i], d2[i] = map(int,input().split())
for i in range(n-2):
if d1[i] == d2[i] and d1[i+1] == d2[i+1] and d1[i+2] == d2[i+2]:
print('Yes')
break
else:
print('No') | N=int(input())
f=0
for i in range(N):
a,b=map(int,input().split())
if a==b:
f+=1
else:
f=0
if f==3:
print('Yes')
break
else:
print('No') | 1 | 2,497,116,364,192 | null | 72 | 72 |
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
import math
#from math import gcd
inf = 10**17
#mod = 10**9 + 7
N,M,L = map(int, input().split())
dp = [[inf]*N for _ in range(N)]
for i in range(N):
dp[i][i] = 0
for _ in range(M):
a,b,c = map(int, input().split())
dp[a-1][b-1] = c
dp[b-1][a-1] = c
#kを経由してiからjに行く行き方を考える
#これで上手く行くのは与えられた辺の和しか考えていないため
for k in range(N):
for i in range(N):
for j in range(N):
if dp[i][j] > dp[i][k] + dp[k][j]:
dp[i][j] = dp[j][i] = dp[i][k]+dp[k][j]
dp2 = [[inf]*N for _ in range(N)]
for i in range(N):
for j in range(N):
if dp[i][j] <= L:
dp2[i][j] = dp2[j][i] = 1
for k in range(N):
for i in range(N):
for j in range(N):
if dp2[i][j] > dp2[i][k] + dp2[k][j]:
dp2[i][j] = dp2[j][i] = dp2[i][k]+dp2[k][j]
q = int(input())
for _ in range(q):
s, t = map(int, input().split())
if dp2[s-1][t-1] == inf:
print(-1)
else:
print(dp2[s-1][t-1]-1)
if __name__ == '__main__':
main() |
from scipy.sparse.csgraph import floyd_warshall as fw
N, M, L = map(int, input().split())
# 町間の道の長さのマトリックスを初期値無限で作成
S = [[float("INF") for i in range(N)] for i in range(N)]
# 町間の道の長さ情報をマトリックスに入力
for i in range(M):
a, b, c = map(int,input().split())
S[a-1][b-1] = c
S[b-1][a-1] = c
# ワーシャルフロイド法で最短距離のマップを生成
Sf = fw(S)
T = [[float("INF")for i in range(N)] for i in range(N)]
# 町間を補給なしで通行可能な場合は1、不可能な場合はINFとしてマトリックスを作成
# (町間距離がタンク容量より大きい場合は通行不可)
for i in range(N):
for j in range(N):
if Sf[i][j] <= L:
T[i][j] = 1
# ワーシャルフロイド法で町間移動可否のマップを生成
# すぐ上のfor文で、補給なしで移動できない町間の移動コストはINFにしたが、
# この処理で複数回の補給を行えば移動できる距離を
Tf = fw(T)
for i in range(int(input())):
a, b = map(int, input().split())
if Tf[a-1][b-1] != float("INF"):
print(int(Tf[a-1][b-1])-1)
else:
print(-1)
| 1 | 173,877,082,959,800 | null | 295 | 295 |
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() | INPUT = input().split()
D = int(INPUT[0])
T = int(INPUT[1])
S = int(INPUT[2])
if D/S <= T:
print("Yes")
else:
print("No") | 0 | null | 1,830,047,155,682 | 23 | 81 |
n = int(input())
maximum_profit = -10**9
r0 = int(input())
r_min = r0
for i in range(1, n):
r1 = int(input())
if r0 < r_min:
r_min = r0
profit = r1 - r_min
if profit > maximum_profit:
maximum_profit = profit
r0 = r1
print(maximum_profit) | # encoding=utf-8
n = int(raw_input())
min = int(raw_input())
keep = int(raw_input())
diff = keep - min
if keep > min:
keep = min
n = n - 2
for i in range(n):
v = int(raw_input())
if v - keep > diff:
diff = v - keep
min = keep
elif keep > v:
keep = v
print diff | 1 | 12,738,289,960 | null | 13 | 13 |
n = int(input())
if n % 2 == 1:
print(0)
exit()
cnt = 0
x = 1
while n > 5**x:
cnt += n//5**x//2
x += 1
print(cnt) | import sys
n = input()
a = []
flag = {}
for j in range(1, 14):
flag[('S',j)] = 0
flag[('H',j)] = 0
flag[('C',j)] = 0
flag[('D',j)] = 0
for i in range(n):
temp = map(str, raw_input().split())
a.append((temp[0],temp[1]))
#print a[i][0]
#print a[i][1]
card = ['S', 'H', 'C', 'D']
#print card
for egara in card:
for i in range(n):
if(a[i][0] == egara):
for j in range(1,14):
if(int(a[i][1]) == j):
flag[(egara, j)] = 1
for egara in card:
for j in range(1,14):
if(flag[(egara, j)] == 0):
sys.stdout.write(egara)
sys.stdout.write(' ')
sys.stdout.write(str(j))
print
exit(0) | 0 | null | 58,607,363,185,888 | 258 | 54 |
a, b, c, k = map(int, input().split())
_sum = 0
if a > k:
_sum += k
else:
k -= a
_sum += a
if b > k:
b = 0
else:
k -= b
if c > k:
_sum -= k
else:
_sum -= c
print (_sum) | a,b,c,k = map(int,input().split())
s=0
s += k if a > k else a
s -= (k-a-b) if k > a+b else 0
print(s) | 1 | 21,795,466,127,732 | null | 148 | 148 |
import sys
def solve():
input = sys.stdin.readline
S = list(input().strip("\n"))
K = int(input())
N = len(S)
head, tail, joint = 0, 0, 0
inside = 0
if S[0] == S[N-1]: #ジョイント部を考える必要がある場合
isInitial = True
current = S[0]
currentLength = 1
for i in range(1, N):
if S[i] == current: currentLength += 1
else:
if isInitial:
head = currentLength // 2
isInitial = False
else: inside += currentLength // 2
current = S[i]
currentLength = 1
if isInitial: #全て同じ文字の場合
totalLength = N * K
print(totalLength // 2)
else:
tail = currentLength // 2
for i in range(N):
if S[i] == current: currentLength += 1
else:
joint = currentLength // 2
break
print(head + tail + joint * (K - 1) + inside * K)
else:
current = S[0]
currentLength = 1
for i in range(1, N):
if S[i] == current: currentLength += 1
else:
inside += currentLength // 2
current = S[i]
currentLength = 1
inside += currentLength // 2
print(inside * K)
#print(head, tail, joint, inside)
return 0
if __name__ == "__main__":
solve() | s = input()
k = int(input())
if len(set(s)) == 1:
print((len(s)*k)//2)
exit()
ss = s + s
shoko = 0
prev = ''
cnt = 0
for i in range(len(s)):
if s[i] == prev:
cnt += 1
else:
shoko += cnt // 2
cnt = 1
prev = s[i]
shoko += cnt // 2
kosa = 0
prev = ''
cnt = 0
for i in range(len(ss)):
if ss[i] == prev:
cnt += 1
else:
kosa += cnt // 2
cnt = 1
prev = ss[i]
kosa += cnt // 2
kosa -= shoko
print(shoko + (k-1)*kosa) | 1 | 174,861,767,108,700 | null | 296 | 296 |
import sys
N, K = map(int, sys.stdin.readline().split())
P = list(map(int, sys.stdin.readline().split()))
P.sort()
print(sum(P[0:K])) | # -*- coding: utf-8 -*-
# input
a, b = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
o = 0
for i in range(b):
o = o+x[i]
print(o)
| 1 | 11,654,511,200,260 | null | 120 | 120 |
a = int(input())
print(2*(22/7)*a) | r = int(input())
print(2 * r * 3.1415926535897932) | 1 | 31,445,752,250,168 | null | 167 | 167 |
import sys
if __name__ == "__main__":
n,m = map(int,input().split())
c = list(map(int,input().split()))
INF = 10**18
dp = [INF]*(n+1)
dp[0] = 0
for i in c:
for j in range(i,n+1):
dp[j] = min(dp[j],dp[j-i]+1)
print(dp[-1])
| #!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
x1, y1, x2, y2 = map(float, sys.stdin.readline().split())
print(round(((x2-x1)**2 + (y2-y1)**2) ** 0.5, 6))
| 0 | null | 150,724,182,710 | 28 | 29 |
import sys
input = sys.stdin.buffer.readline
H, W, K = map(int, input().split())
B = {}
for _ in range(K):
r, c, v = map(int, input().split())
B[(r, c)] = v
dp = [[0]*(W+1) for _ in range(4)]
for i in range(1, H+1):
for j in range(1, W+1):
if (i, j) in B:
v = B[(i, j)]
dp[0][j] = max(dp[0][j-1], dp[0][j], dp[1][j], dp[2][j], dp[3][j])
dp[1][j] = max(dp[1][j-1], dp[0][j]+v)
dp[2][j] = max(dp[2][j-1], dp[1][j-1]+v)
dp[3][j] = max(dp[3][j-1], dp[2][j-1]+v)
else:
dp[0][j] = max(dp[0][j-1], dp[0][j], dp[1][j], dp[2][j], dp[3][j])
dp[1][j] = dp[1][j-1]
dp[2][j] = dp[2][j-1]
dp[3][j] = dp[3][j-1]
print(max(dp[i][-1] for i in range(4)))
| W, H, x, y, r = [int(temp) for temp in input().split()]
if r <= x <= (W - r) and r <= y <= (H - r) : print('Yes')
else : print('No') | 0 | null | 3,016,411,032,700 | 94 | 41 |
N = int(input())
S = []
for x in range(N):
S += [input()]
S_set = set(S)
print(len(S_set))
| import collections
N=int(input())
P=[input() for i in range(N)]
c=collections.Counter(P)
print(len(c)) | 1 | 30,345,896,906,006 | null | 165 | 165 |
def isprime(n):
divider = 2
while divider ** 2 <= n:
if n % divider == 0:
return False
divider += 1
return True
result = 0
n = int(input())
for n in range(n):
result += isprime(int(input()))
print(result) | def is_prime(n):
# ?´???°??????
if n == 2:
return True
elif n < 2 or n & 1 == 0:
return False
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return False
return True
N = int(input())
cnt = 0
for i in range(N):
e = int(input())
if is_prime(e):
cnt += 1
print(cnt) | 1 | 10,798,206,532 | null | 12 | 12 |
S, T = input().split()
A, B = map(int, input().split())
U = input()
if U == S: A -= 1
else: B -= 1
print(A, B) | import sys
from collections import Counter
H,W,m = map(int,input().split())
h_ls = [0] * H
w_ls = [0] * W
bombers = [(0,0) for _ in range(m)]
for i in range(m):
h,w = map(int,input().split())
h_ls[h-1] += 1
w_ls[w-1] += 1
bombers[i] = (h-1,w-1)
h_max = max(h_ls)
h_counter = Counter(h_ls)
# Couter使ってみる
h_max_args = [0]*h_counter[h_max]
next_ind = 0
for i in range(H):
if h_ls[i] == h_max:
h_max_args[next_ind] = i
next_ind += 1
w_max = max(w_ls)
w_counter = Counter(w_ls)
w_max_args = [0]*w_counter[w_max]
next_ind = 0
for i in range(W):
if w_ls[i] == w_max:
w_max_args[next_ind] = i
next_ind += 1
bombers = set(bombers)
for h in h_max_args:
for w in w_max_args:
if not (h,w) in bombers:
print(w_max+h_max)
sys.exit()
print(w_max+h_max-1)
| 0 | null | 38,512,885,119,306 | 220 | 89 |
import sys
S,T = input().split()
if not ( S.islower() and T.islower() ): sys.exit()
if not ( 1 <= len(S) <= 100 and 1 <= len(S) <= 100 ): sys.exit()
print(T,S,sep='') | n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
if i == 0:
continue
if a[i-1] > a[i]:
ans += a[i-1] - a[i]
a[i] += a[i-1] - a[i]
print(ans)
| 0 | null | 54,139,850,789,858 | 248 | 88 |
N=int(input());M=N//500;M*=1000;X=500*(N//500);N-=X;M+=(N//5)*5;print(M) | N = int(input())
a500 = N //500
N = N - 500 *a500
a5 = N//5
res = 1000*a500 +5*a5
print(res) | 1 | 42,810,139,662,122 | null | 185 | 185 |
# 筐体の手が'k'回前と同じ場合, その回は勝てないが, 'k'回後は勝てる
# 筐体が出した各回の手をメモ, ただし'k'回前と同じ場合のみ ’-1’をメモする
# 勝ち手が'k'回前と同じ場合は加算なし, それ以外('-1'を含む)は勝ち点を加算
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
ans = 0
memo = []
for i in range(n):
if i < k or t[i] != memo[i-k]:
memo.append(t[i])
if t[i] == 'r': ans += p
elif t[i] == 's': ans += r
else: ans += s
else:
memo.append('-1')
print(ans)
| n,k=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
t=""
count=0
for i in range(n):
if i>k-1:
if T[i]=="r":
if t[i-k]!="p":
t=t+"p"
count+=P
else:
t=t+" "
if T[i]=="s":
if t[i-k]!="r":
t=t+"r"
count+=R
else:
t=t+" "
if T[i]=="p":
if t[i-k]!="s":
t=t+"s"
count+=S
else:
t=t+" "
else:
if T[i]=="r":
t=t+"p"
count+=P
if T[i]=="p":
t=t+"s"
count+=S
if T[i]=="s":
t=t+"r"
count+=R
print(count) | 1 | 106,340,234,274,652 | null | 251 | 251 |
import math
n=int(input())
l=0
summ=0
for i in range(1,n+1):
for j in range(1,n+1):
for k in range(1,n+1):
ans=math.gcd(i,j,)
ans=math.gcd(ans,k)
summ+=ans
print(summ) | k = int(input())
sum = 0
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
for a in range(1, k + 1):
for b in range(1, k + 1):
ab_gcd = gcd(a, b)
for c in range(1, k + 1):
abc_gcd = gcd(c, ab_gcd)
sum += abc_gcd
print(sum)
| 1 | 35,541,290,222,640 | null | 174 | 174 |
a_1,a_2,a_3=map(int,input().split())
if a_1+a_2+a_3<=21:
print('win')
else:
print('bust') | a_1, a_2, a_3 = map(int, input().split())
print('bust' if a_1+a_2+a_3 >= 22 else 'win') | 1 | 118,647,759,064,228 | null | 260 | 260 |
N = int(input())
As = list(map(int, input().split()))
ans = 0
tall = int(As[0])
for A in As:
if(tall > A):
ans += tall - A
else:
tall = A
print(ans) | n=int(input())
a = list(map(int, input().split()))
ans = 0
temp = a[0]
for i in a[1:]:
if temp > i:
ans += (temp - i)
temp = max(temp, i)
print(ans) | 1 | 4,569,686,089,180 | null | 88 | 88 |
n, x, m = map(int,input().split())
amari = [0]*m
v = [x]
cnt = 0
while True:
xn_1 = x**2%m
cnt += 1
if x == 0:
break
amari[x] = xn_1
if amari[xn_1]:
break
v.append(xn_1)
x = xn_1
#print(v)
if 0 in v:
ans = sum(v)
else:
ind = v.index(xn_1)
rooplen = len(v) - ind
ans = sum(v[0:ind])
l = n-ind
if rooplen:
ans += (l//rooplen)*sum(v[ind:])
nokori = l - rooplen*(l//rooplen)
ans += sum(v[ind:ind+nokori])
#print(v)
print(ans) | n, x, m = map(int, input().split())
v = list(range(m))
p = [-1 for _ in range(m)]
a = x
p[a - 1] = 0
s = [x]
l, r = n, n
for i in range(n):
a = a ** 2 % m
if p[a - 1] >= 0:
l, r = p[a - 1], i + 1
break
else:
s.append(a)
p[a - 1] = i + 1
ans = sum(s[:l])
if l != r:
b = (n - 1 - i) // (r - l) + 1
c = (n - 1 - i) % (r - l)
ans += b * sum(s[l:r]) + sum(s[l:l + c])
print(ans)
| 1 | 2,784,425,937,024 | null | 75 | 75 |
rst = []
N = int(input())
S = input()
tmp_val = ''
for i in S:
if tmp_val != i:
rst.append(i)
tmp_val = i
print(len(rst)) | from math import *
def distance (p,n,x,y):
dis = 0.0
if p == "inf":
for i in range(0,n) :
if dis < abs(x[i]-y[i]):
dis = abs(x[i]-y[i])
else :
for i in range(0,n) :
dis += abs(x[i]-y[i])**p
dis = dis ** (1.0/p)
return dis
if __name__ == '__main__' :
n = int(input())
x = map(int,raw_input().split())
y = map(int,raw_input().split())
print distance(1,n,x,y)
print distance(2,n,x,y)
print distance(3,n,x,y)
v = distance('inf',n,x,y)
print "%.6f" % v | 0 | null | 85,323,007,503,552 | 293 | 32 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.