#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=1000000007
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]

#-------------------------code---------------------------#
# vsInput()

def Dist(x1,y1,x2,y2):
    return sqrt((x1-x2)**2 + (y2-y1)**2)

def Intersect(C1,C2):
    x1,y1,r1=C1
    x2,y2,r2=C2
    d=Dist(x1,y1,x2,y2)
    # print(C1,C2,d,r1,r2)
    return abs(r1-r2)<d<r1+r2

def inside(c1,c2):
    x1,y1,r1=c1
    x2,y2,r2=c2
    d=Dist(x1,y1,x2,y2)

    # print(d,r1,r2)

    return d+r1<=r2

def Check(circle,ring):
    inner=(ring[0],ring[1],ring[2])
    outer=(ring[0],ring[1],ring[3])

    if(inside(circle,inner) and not Intersect(circle,inner)): return True
    if(not inside(circle,outer) and not Intersect(circle,outer)): return True
    return False

Ring1=value()
Ring2=value()
x1,y1,r1,R1=Ring1
x2,y2,r2,R2=Ring2

ans=0

if(Check((x1,y1,r1),Ring2)):
    ans+=1
if(Check((x1,y1,R1),Ring2)):
    ans+=1
if(Check((x2,y2,r2),Ring1)):
    ans+=1
if(Check((x2,y2,R2),Ring1)):
    ans+=1

print(ans)


((x,y,r,R),(u,v,w,W))=[map(int,raw_input().split()) for _ in (1,2)]
d=(x-u)*(x-u)+(y-v)*(y-v)
def t(a,b,c):
  if c<=a and (a-c)*(a-c)>=d:return 1
  if c>=b and (c-b)*(c-b)>=d:return 1
  if (b+c)*(b+c)<=d:return 1
  return 0
print t(r,R,w)+t(r,R,W)+t(w,W,r)+t(w,W,R)


'''
Created on 2014/9/29

@author: Yeu-Chern Harn
'''
import sys
def p471C( N ):
    diffH = 0
    Hlim = N/2
    h = 1
    while h <= Hlim:
        rN = N - 2*h
        if rN % 3 == 0:
            rN = rN / 3
            if rN >= (h-1)*h/2:
                diffH = diffH + 1
            else:
                break
        h = h + 1;
    return diffH

def p471C_2(N):
    diffH = 0
    sumVal = 0
    card = 2
    while sumVal + card <= N:
        sumVal = sumVal + card
        rN = N - sumVal
        if rN % 3 == 0:
            diffH = diffH + 1
        card = card + 3
    return diffH

if __name__ == '__main__':
    iVal = int(raw_input())
    diffH = p471C(  iVal )
    print(diffH)


from fractions import Fraction as F
import math
import sys

fi = sys.stdin
fo = sys.stdout
fe = sys.stderr
exit = sys.exit

readline = raw_input

def readargs(tp=None):
    if tp is not None:
        return map(tp, readline().split())
    return readline.split()

def yesno(flag, yes='', no=''):
    if flag:
        print yes if yes else 'YES'
    else:
        print no if no else 'NO'

truefalse = lambda flag : yesno(flag, yes='TRUE', no='FALSE')

n = int(readline())

levels = 1
cnt = 0

while (n - (levels << 1)) % 3 != 0:
    levels += 1

while True:
    lft = n - (levels << 1)
    tmp = lft / 3
    if tmp < ((levels * levels - levels) >> 1):
        break
    cnt += 1
    levels += 3

print cnt


es = [2, 3, 5, 7, 11]
for i in range(12, 1001):
    g = True
    for j in es:
        if i % j == 0:
            g = False
            break
    if g: es.append(i)

n, k = map(int, raw_input().split())
count = 0
for x in range(len(es)):
    i = es[x]
    if i > n: break
    g = False
    for j in range(len(es) - 1):
        if i == es[j] + es[j + 1] + 1:
            g = True
            break
    if g: count += 1
print(["NO", "YES"][count >= k])


import math

def is_prime(n):
  if n < 2:
    return False
  for i in range(2, int(math.sqrt(n)) + 1):
    if n % i == 0:
      return False
  return True

primes = []
for i in range(2, 1001):
  if is_prime(i):
    primes.append(i)

primes2 = []
for i in range(2, len(primes)):
  for j in range(i - 1):
    if primes[j] + primes[j+1] + 1 == primes[i]:
      primes2.append(primes[i])

n, k = map(int, input().split())
cnt = 0
for x in primes2:
  if x <= n:
    cnt += 1
  else:
    break

if cnt >= k:
  print('YES')
else:
  print('NO')


h1, h2 = map(int, input().split())
a, b = map(int, input().split())
d, v = h2 - h1 - 8 * a, 12 * (a - b)
if d <= 0:
    print(0)
elif b >= a:
    print(-1)
else:
    print((d + v - 1) // v)


from copy import deepcopy
import math
def input_list():
    i = raw_input()
    return map(eval, i.split(' '))

def main():
    [h1, h2] = input_list()
    target = h2 - h1
    [a, b] = input_list()
    if a <= b and 8*a < target:
        print (-1)
        return
    pos = 8*a
    k = 0
    while pos < target:
        k += 1
        pos += (a-b) * 12
    print k

main()


n=int(input())
if n%2==0:
    print(n//2-1)
else:
    print(n//2)


MOD = 998244353

n, m, l, r = map(int, input().split())

if (n*m) % 2 == 1:
	print(pow(r - l + 1, n * m, MOD))
else:
	ans = pow(r - l + 1, n * m, MOD)
	if (r-l) % 2 == 0:
		ans += 1
	ans *= pow(2, MOD-2, MOD)
	ans %= MOD
	print(ans)


def main():
    n = int(input())
    min1, max1 = [int(t) for t in input().split()]
    min2, max2 = [int(t) for t in input().split()]
    min3, max3 = [int(t) for t in input().split()]

    s1 = min(max1, n - min2 - min3)
    s2 = min(max2, n - s1 - min3)
    s3 = n - s1 - s2

    print(' '.join(str(s) for s in [s1, s2, s3]))

if __name__ == '__main__':
    main()


read=lambda:map(int,raw_input().split())
n=input()
mi1,mx1=read()
mi2,mx2=read()
mi3,mx3=read()

d1=mi1
d2=mi2
d3=mi3
n-=(mi1+mi2+mi3)
if(n>0):
    if(n>(mx1-mi1)):
        d1=mx1
        n-=(mx1-mi1)
    else:
        d1+=n
        n=0
if(n>0):
    if(n>(mx2-mi2)):
        d2=mx2
        n-=(mx2-mi2)
    else:
        d2+=n
        n=0
d3+=n
print d1,d2,d3


n = int(input())

a = int(n ** 0.5)
big_square = a ** 2

else_square = n - big_square

answer = int(a * 4)
if a ** 2 != n:
    if else_square - a > 0:
        answer += 4
    else:
        answer += 2

print(answer)


n,m=map(int,input().split())
x=min(n,m)
y=max(n,m)
count=0
for i in range(1,x+1):
    j=5-(i%5)
    count+=(y-j)//5
    count+=1
print(count)


a,b = map(int,input().split());cnt = 0
for i in range(1,a+1):
    cnt+=(b+(i%5))//5
print(cnt)


n=int(input())
w=input()
n=str(n)
t=0
p=[0]*len(n)
if n=='0':
    if w=='0':
        print('OK')
    else:
        print('WRONG_ANSWER')
else:
    if '1' in n:
        t=1
    else:
        if '2' in n:
            t=2
        else:
            if '3' in n:
                t=3
            else:
                if '4' in n:
                    t = 4
                else:
                    if '5' in n:
                        t = 5
                    else:
                        if '6' in n:
                            t = 6
                        else:
                            if '7' in n:
                                t = 7
                            else:
                                if '8' in n:
                                    t = 8
                                else:
                                    t=9
    s=str(t)
    for i in range (0,10):
        if i==t:
            s=s+str(i)*(n.count(str(i))-1)
        else:
            s = s + str(i) * (n.count(str(i)))
    if s==w:
        print('OK')
    else:
        print('WRONG_ANSWER')


n = raw_input().strip()
m = raw_input().strip()
a = list()
n0 = 0
s = ""
for x in n:
	if x == '0':
		n0 += 1
	else:
		a.append(int(x))
a.sort()
if(len(a)>0):
	s += str(a[0])
s += '0'*n0
for i in range(1,len(a)):
	s += str(a[i])
if s == m:
	print "OK"
else:
	print "WRONG_ANSWER"


s = input()
k = int(input())
le = len(s) + k
m = 0
for i in range(len(s)):
    j = 1
    while i+2*j <= le:
        mi = i + j
        la = i + 2*j
        if mi >= len(s):
            m = max(m, j)
        if la <= len(s) and s[i:mi] == s[mi:la]:
            m = max(m, j)
        if mi < len(s):
            xl = len(s) - mi
            if s[i:i + xl] == s[mi:len(s)]:
                m = max(m, j)
        j += 1
print(2*m)


def isok(s, q):
    for i in range(0, len(s) - 2 * q + 1):
        for j in range(0, q):
            if s[i + j + q] != "?" and s[i + j] != s[i + j + q]:
                break
            j += 1
        else:
            return True
    return False

s, k = raw_input(), int(raw_input())
s += "?" * k

for i in range(len(s) // 2, -1, -1):
    if isok(s, i):
        print 2 * i
        break


def main():
	n,m,k,x,y=map(int,input().split())

	if n==1:
		if k%m==0:
			print (k//m,k//m,k//m)
		else:
			vl=k//m
			if y<=(k%m):
				vl=k//m+1
			print (k//m+1,k//m,vl)
		return

	ma=-1*(10**20)
	mi=(10**20)
	track=0
	ans=0
	xloc=0
	yloc=0

	for i in range(1,n+1):
		increment1=2*(n-i)*m
		increment2=2*(i-1)*m
		for j in range(1,m+1):

			lo=-1
			hi=10**18

			while hi-lo>1:
				mid=(lo+hi)//2

				times2=(mid//2)

				if(increment2==0):
					times2=0

				times1=mid-times2

				if(increment1==0):
					times1=0
					times2=mid

				sumtotal=(i-1)*m+j+increment1*times1+increment2*times2

				if sumtotal<=k:
					lo=mid

				else:
					hi=mid-1

			times2=hi//2

			if increment2==0:
				times2=0

			times1=hi-times2

			if increment1==0:
				times1=0
				times2=hi

			sumtotal=(i-1)*m+j+increment1*times1+increment2*times2

			if sumtotal<=k:
				ans=hi+1

			else:
				ans=hi

			#print (i,j,ans,sumtotal,k)
			if(i==x and j==y):
				track=ans
			if ans>ma:
				ma=ans
			if ans<mi:
				mi=ans

	print (ma,mi,track)
	return

main()


n, m, k, x, y = map(int, input().split())

def cnt(r, c):
    a = k
    if n == 1:
        return (a // m + ((a % m) >= c))
    res = a // ((2 * n - 2) * m)
    if r != 1 and r != n:
        res *= 2
    a %= (2 * n - 2) * m
    if a > n * m:
        return res + 1 + (1 if r != n and a-n*m >= (n-r-1)*m + c else 0)
    else:
        return res + (1 if a >= (r-1)*m + c else 0)

r1 = cnt(1, 1)
r2 = cnt(2, 1)
r3 = cnt(n - 1, 1)
r4 = cnt(n, m)
r5 = cnt(x, y)
print(max(r1, r2, r3), r4, r5)


from collections import deque, defaultdict, Counter
from heapq import heappush, heappop, heapify
from math import inf
from functools import lru_cache
from itertools import accumulate
from typing import List
import sys
input = sys.stdin.readline

MOD = 10**9 + 7

def make_nCr_mod(max_n=2 * 10**5, mod=10**9 + 7):
    max_n = min(max_n, mod - 1)

    fact, inv_fact = [0] * (max_n + 1), [0] * (max_n + 1)
    fact[0] = 1
    for i in range(max_n):
        fact[i + 1] = fact[i] * (i + 1) % mod

    inv_fact[-1] = pow(fact[-1], mod - 2, mod)
    for i in reversed(range(max_n)):
        inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod

    def nCr_mod(n, r):
        res = 1
        while n or r:
            a, b = n % mod, r % mod
            if a < b:
                return 0
            res = res * fact[a] % mod * inv_fact[b] % mod * inv_fact[a - b] % mod
            n //= mod
            r //= mod
        return res

    return nCr_mod

N, K = map(int, input().split())
nCr = make_nCr_mod(N, MOD)
if K >= N:
    print(2**N % MOD)
else:
    ans = 1
    for i in range(1, K+1):
        ans += nCr(N, i) % MOD
    print(ans % MOD)


import sys, math, heapq, bisect

p = 1000000007

def lcm(x,y):
    return int(x*y/math.gcd(x,y))

def readarrint():
    arr = sys.stdin.readline().split()
    return [int(i) for i in arr]

# Python3 program to answer queries
# of nCr in O(1) time.
N = 1000001

# array to store inverse of 1 to N
factorialNumInverse = [None] * (N + 1)

# array to precompute inverse of 1! to N!
naturalNumInverse = [None] * (N + 1)

# array to store factorial of
# first N numbers
fact = [None] * (N + 1)

# Function to precompute inverse of numbers
def InverseofNumber(p):
    naturalNumInverse[0] = naturalNumInverse[1] = 1
    for i in range(2, N + 1, 1):
        naturalNumInverse[i] = (naturalNumInverse[p % i] *
                                   (p - int(p / i)) % p)

# Function to precompute inverse
# of factorials
def InverseofFactorial(p):
    factorialNumInverse[0] = factorialNumInverse[1] = 1

    # precompute inverse of natural numbers
    for i in range(2, N + 1, 1):
        factorialNumInverse[i] = (naturalNumInverse[i] *
                                  factorialNumInverse[i - 1]) % p

# Function to calculate factorial of 1 to N
def factorial(p):
    fact[0] = 1

    # precompute factorials
    for i in range(1, N + 1):
        fact[i] = (fact[i - 1] * i) % p

# Function to return nCr % p in O(1) time
def Binomial(N, R, p):

    # n C r = n!*inverse(r!)*inverse((n-r)!)
    ans = ((fact[N] * factorialNumInverse[R])% p *
                      factorialNumInverse[N - R])% p
    return ans

for i in range(1):
    a = readarrint()
    n = a[0]
    k = a[1]
    if k >= n:
        print(pow(2,n,p))
    else:
        ans = 0
        InverseofNumber(p)
        InverseofFactorial(p)
        factorial(p)
        for i in range(k+1):
            ans = ans+ Binomial(n,i,p)
        print(ans%p)


d,l,v1,v2=map(int,raw_input().split())
print "%.10f" % (float((l-d))/(v1+v2))


import io,os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

M = 998244353

MAXNUM = 260
factor = [1]*(MAXNUM+2)
factor[-1]=0
storecomb = {}

for i in range(1,MAXNUM+1):
    factor[i] = (factor[i-1]*i)%M

def fastfrac(a,b):
    numb = pow(b,M-2,M)
    return ((a%M)*(numb%M))%M

def comb(n,k):
#    print "*",n,k
    if n<k: return 0
    if n==k: return 1
    if (n,k) in storecomb:  return storecomb[(n,k)]

    num1 = factor[n]
    num2 = factor[k]
    num3 = factor[n-k]
    num = (num2*num3)%M
    output = fastfrac(num1,num)
    storecomb[(n,k)] = output
    return output

def main(t):

    n,k = map(int,input().split())

    dp = [[0 for q in range(k+1)] for p in range(n+1)]

    for j in range(1,k+1):
        dp[2][j] = 1
        dp[1][j] = 1
    for i in range(3,n+1):
        dp[i][1] = pow(k,(i-1)*(i-2)//2,M)

    for i in range(3,n+1):
        for j in range(2,k+1):
            dp[i][j] = pow(k-j+1,(i-1)*(i-2)//2,M)

    for i in range(3,n+1):

        for same in range(1,i-1):

            part1 = 0
            for j in range(2,k+1):

                part1 += dp[i-same][j-1]
                part2 = ( pow(k-j+1,same*(i-1-same)+same*(same-1)//2,M) * comb(i-1,same) ) %M

                dp[i][j] += (part1*part2)%M

                dp[i][j] %= M

#    print(dp)

#    print(dp[n])
    print(sum(dp[n])%M)

T = 1 #int(input())
t = 1
while t<=T:
    main(t)
    t += 1


from sys import stdin, stdout

def int1():
    return int(stdin.readline().strip())

def ints():
    return map(int, stdin.readline().strip().split(" "))

def arr():
    return list(stdin.readline().strip().split(" "))

def iarr():
    return list(ints())

class DS:
    def __init__(self, n):
        self.p = [i for i in range(n)]
        self.r = [0 for _ in range(n)]
    def find(self, x):
        if self.p[x] != x:
            self.p[x] = self.find(self.p[x])
        return self.p[x]
    def merge(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b:
            return 0
        if self.r[a] < self.r[b]:
            p[a] = b
        else:
            p[b] = a
            if self.r[a] == self.r[b]:
                r[a]+=1
        return 1

class BIT:
    def __init__(self, n):
        self.n = n + 2
        self.arr = [0 for _ in range(self.n)]
    def inc(self, index, val):
        index += 1
        while index < self.n:
            self.arr[index] += n
            index += (index&-index)

MOD = 998244353
n,k = ints()
memo = dict()
memo2 = dict()
memo3 = [[0 for _ in range(((n*(n-1))>>1)+2)] for _ in range(k+1)]
for i in range(1,k+1):
    memo3[i][0] = 1
    for j in range(1,(n*(n-1)>>1)+2):
        memo3[i][j] = memo3[i][j-1] * i
        memo3[i][j] %= MOD

def mexp(b,e,m):
    if e == 0:
        return 1
    if e == 1:
        return b % m
    s = mexp(b,e>>1,m)
    return (s * s * (b if (e&1) else 1)) % m

def inv(x):
    if not x in memo2:
        memo2[x] = mexp(x, MOD - 2, MOD)
    return memo2[x]

def go(left, last):
    if left == 0:
        return 1
    if last == k:
        return 0
    st = left * 300 + last
    if not st in memo:
        scale = 1
        memo[st] = 0
        comp = n - left
        for i in range(left+1):
            ex = (comp - 1) * i + ((i * (i-1))>>1)
            memo[st] += go(left-i,last+1) * scale * memo3[k-last][ex]
            scale *= (left - i)
            scale *= inv(i+1)
            scale %= MOD
        memo[st] %= MOD
    return memo[st]

print(go(n-1,0))


def main():
    m = int(input())
    if m < 1000000:
        lo = m*4
        hi = m*8
    else:
        lo = int(4.949 * m)
        hi = int(4.9492 * m)
    while lo < hi - 1:
        mid = (lo + hi)//2
        nposs = countposs(mid)
        if nposs < m:
            lo = mid
        else:
            hi = mid
    if m == countposs(hi):
        print(hi)
    else:
        print(-1)

def countposs(maxtake):
    k = 2
    ans = 0
    while True:
        term = maxtake//(k*k*k)
        if term == 0:
            return ans
        ans += term
        k += 1

main()


#!/usr/bin/python

from math import floor

m = int(raw_input())
l = [k**3.0 for k in xrange(2,180000)]

def check(num):
    return m > check2(num)

def check2(num):
    return sum(floor(num/l[i]) for i in xrange(int(num**(1.0/3))))

ma = 5 * 10**15
mi = int(4.8 * m)

while ma-mi > 1:
    mid = (ma+mi)/2
    if check(mid):
        mi = mid
    else:
        ma = mid

if check2(ma) == m:
    print ma
else:
    print -1


def check(mid , lis):
    pile=[10000000000]*mid
    c=0
    for i in range(n-1,-1,-1):
        pile[i%mid]=min(pile[i%mid]-1,lis[i])
#    print(pile,mid)
    if min(pile)<0:
        return 0
    else:
        return 1
n = int(input())
lis = sorted(map(int,input().split()))
l=1
r=n
while l<=r:
    mid = l + (r-l)//2
#    print(l,r,mid)
    if(check(mid,lis)):
        r = mid-1
    else:
        l = mid+1
print(l)


n = input()
arr = map(int,raw_input().split())
arr.sort()
# arr=arr[::-1]
piles=[0]*101
s=0
c=0
pile=[1]
for i in arr[1:]:
    # print i
    f=False
    for j in range(len(pile)):
        if pile[j]<=i:
            pile[j]+=1
            f=True
            break
    if f==False:
        pile.append(1)
    pile.sort()
    pile=pile[::-1]
    # print pile
print len(pile)


venus = raw_input('')
mars= raw_input('')
vlist=venus.split(' ')
mlist=mars.split(' ')
vl=int(vlist[0])
vr=int(vlist[1])
ml=int(mlist[0])
mr=int(mlist[1])
num=0
upper=vl*2+2
lower=vl-1
if lower==0:
    lower=1
if lower<=mr<=upper:
    num+=1
upper=vr*2+2
lower=vr-1
if lower ==0:
    lower=1
if lower<=ml<=upper:
    num+=1

if num>0:
    print 'YES'
else:print 'NO'


#!/usr/bin/env python
# -*- coding: utf-8 -*-

def test(a, b):
    return True if b >= (a-1) and b <= (a+1)*2 else False

def main():
    al, ar = map(int, raw_input().split())
    bl, br = map(int, raw_input().split())
    if (test(al, br) or test(ar, bl)):
        print "YES"
    else:
        print "NO"
    return 0

if __name__ == '__main__':
    main()


n = int(input())
s = input()
summ = 0
for i in range(len(s)):
    if s[i:i+3] == 'xxx':
        summ+=1
print(summ)


n = int(input())
s = input()
ans = 0
for i in range(n, 2, -1):
    st = 'x'*i
    while s.count(st):
        ans += s.count(st)*(i-2)
        s = s.replace(st, '')
print(ans)


s = input()
"""if s == "V":
    print(0)
    exit()
if s == "VK" or s == "VV" or s == "KK":
    print(1)
    exit()
beg = s.count("VK")
m = beg
kk = s.count("KK")
kv = s.count("KV")
vv = s.count("VV")

buf = s[:]
f = s[:]
while kk:
    c = f.find("KK")
    if c != -1:
        f = f[:c] + "--" + f[c + 1:]
        tmp = buf[:c] + "VK" + buf[c + 1:]
        if tmp.count("VK") > m:
            m = buf.count("VK")
    kk -= 1

buf = s[:]
f = s[:]
while kv:
    c = f.find("KV")
    if c != -1:
        f = f[:c] + "--" + f[c + 1:]
        tmp = buf[:c] + "VK" + buf[c + 1:]
        if tmp.count("VK") > m:
            m = tmp.count("VK")
    kv -= 1

buf = s[:]
f = s[:]
while vv:
    c = f.find("VV")
    if c != -1:
        f = f[:c] + "--" + f[c + 1:]
        tmp = buf[:c] + "VK" + buf[c + 1:]
        if tmp.count("VK") > m:
            m = buf.count("VK")
    vv -= 1

print(m)"""
print (max((s[:i] + x + s[i+1:]).count("VK") for x in "VK" for i in range(len(s))))


'''
tt = int(raw_input())
a = map(int, raw_input().split())
for i in xrange(tt):
a = map(int, (' '.join(n for n in raw_input())).split())
'''
t = raw_input()
s = map(str, (' '.join(n for n in t)).split())
length = len(s)
ans = 0
i = 0
done = 0
while (i < length - 1):
    if (i != length - 2):
        if ((s[i] == "V") and (s[i+1] == "K")):
            ans += 1
            i = i + 1

        elif (s[i] == "V" and s[i+1] == "V" and s[i+2] == "V" and done == 0):
            ans += 1
            done = 1
            s[i+1] = "K"
            i = i + 1

        elif (s[i] == "K" and s[i+1] == "K" and done == 0):
            ans += 1
            done = 1
            s[i] = "V"
            i = i + 1

    else:
        if ((s[i] == "V") and (s[i+1] == "K")):
            ans += 1
            i = i + 1

        elif (s[i] == "V" and s[i+1] == "V" and done == 0):
            ans += 1
            done = 1
            s[i+1] = "K"
            i = i + 1

        elif (s[i] == "K" and s[i+1] == "K" and done == 0):
            ans += 1
            done = 1
            s[i] = "V"
            i = i + 1

    i += 1

print ans
# print s


p=10**9+7
def S(x):
	if x==0:
		return 0
	elif x==1:
		return 4
	elif x&1:
		return 11*pow(3,x/2,p)-7
	else:
		return 19*pow(3,x/2-1,p)-7
def G(x):
	return (S(x)+S(x+1>>1))*pow(2,p-2,p)%p;
l,r=map(int,raw_input().split())
print (G(r)-G(l-1))%p;


p=10**9+7
def S(x):
 if x==0:
  return 0
 elif x==1:
  return 4
 elif x&1:
  return 11*pow(3,x/2,p)-7
 else:
  return 19*pow(3,x/2-1,p)-7
def G(x):
 return (S(x)+S(x+1>>1))*pow(2,p-2,p)%p;
l,r=map(int,raw_input().split())
print (G(r)-G(l-1))%p;


def play(t1, t2):
    r = 0
    if t1[0] > t2[1] and t1[1] > t2[0]:
        r = 1
    elif t1[0] < t2[1] and t1[1] < t2[0]:
        r = -1
    else:
        r = 0
    #print("play:", t1, t2, r)
    return r

p = []
m = []
res = []

for _ in range(4):
    a, b = map(int, input().split(" "))
    p.append((a, b))

m.append((p[0][0], p[1][1]))
m.append((p[1][0], p[0][1]))
m.append((p[2][0], p[3][1]))
m.append((p[3][0], p[2][1]))

res.append((play(m[0], m[2]), play(m[0], m[3])))
res.append((play(m[1], m[2]), play(m[1], m[3])))

#print(res)
mm = max([max(i) for i in res])
res = [i for i in res if max(i) == mm]
res = [min(i) for i in res]
#print(res)
#rr = min(res) + 1
if 1 in res:
    rr = 2
else:
    rr = max(res) + 1
ss = ["Team 2", "Draw", "Team 1"]
print(ss[rr])


mtr=[[1,0],[0,1]]
p1=list(map(int,input().split()))
p2=list(map(int,input().split()))
p3=list(map(int,input().split()))
p4=list(map(int,input().split()))
w1=w2=0
for l1 in mtr:
    wi1=wi2=0
    for l2 in mtr:
        at1=p1[1] if l1[0]==1 else p2[1]
        z1=p1[0] if l1[0]==0 else p2[0]
        at2=p3[1] if l2[0]==1 else p4[1]
        z2=p3[0] if l2[0]==0 else p4[0]
        if at1>z2 and z1>at2:
            wi1+=1
        elif at1<z2 and z1<at2:
            wi2+=1
    if wi2>=1:
        w2+=1
    elif wi1==2:
        w1+=1
if w2==2:
    print('Team 2')
elif w1>=1:
    print('Team 1')
else:
    print('Draw')


a, b, k = map(int, raw_input().split())
t, p = [True] * (b + 1), []
for i in range(2, b + 1):
	if t[i]:
		if i >= a:
			p.append(i)
		for j in range(i * i, b + 1, i):
			t[j] = False
print -1 if len(p) < k else max([p[i] - p[i - k] for i in range(k, len(p))] + [b - p[-k] + 1, p[k - 1] - a + 1])


def f(n):
    m = int(n ** 0.5) + 1
    t = [1] * (n + 1)
    for i in range(3, m):
        if t[i]: t[i * i :: 2 * i] = [0] * ((n - i * i) // (2 * i) + 1)
    return [2] + [i for i in range(3, n + 1, 2) if t[i]]

a, b, k = map(int, input().split())
n = 2000001

t, p, x = [-1] * n, f(n), -1
k -= 1; b += 1

for i in range(len(p) - k):
    t[p[i]] = p[i + k] - p[i]

t.reverse()
for i in range(1, n):
    if t[i] < 0: t[i] = t[i - 1] + 1
t.reverse()

for i in range(a + 1, b):
    t[i] = max(t[i], t[i - 1])

for l in range(1, b - a + 1):
    if t[b - l] < l:
        x = l
        break
print(x)


import sys
from math import gcd,sqrt,ceil
from collections import defaultdict,Counter,deque
from bisect import bisect_left,bisect_right
import math

# input=sys.stdin.readline
# def print(x):
#     sys.stdout.write(str(x)+"\n")

# sys.stdout=open("CP1/output.txt",'w')
# sys.stdin=open("CP1/input.txt",'r')
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# import sys
# import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def get_sum(bit,i):
    s = 0

    i+=1
    while i>0:
        s+=bit[i]
        i-=i&(-i)

    return s

def update(bit,n,i,v):
    i+=1

    while i<=n:
        bit[i]+=v
        i+=i&(-i)

def modInverse(b,m):
    g = math.gcd(b, m)
    if (g != 1):
        return -1
    else:
        return pow(b, m - 2, m)

def primeFactors(n):

    sa = set()
    sa.add(n)
    while n % 2 == 0:
        sa.add(2)
        n = n // 2

    for i in range(3,int(math.sqrt(n))+1,2):

        while n % i== 0:
            sa.add(i)
            n = n // i

    # sa.add(n)
    return sa

def seive(n):

    pri = [True]*(n+1)
    p = 2
    while p*p<=n:

        if pri[p] == True:

            for i in range(p*p,n+1,p):
                pri[i] = False

        p+=1

    return pri

def ifposs(l):

    i = a
    # print(l)
    while b-i+1>=l:

        z = i+l-1

        if pre[z]-pre[i-1]<k:
            return False

        else:
            i+=1

    return True

a,b,k = map(int,input().split())

pri = []
h = seive(b+1)
h[1] = False
pre = [0]
for i in range(a,b+1):
    if h[i] == True:

        pri.append(i)
        pre.append(pre[-1]+1)
    else:
        pre.append(pre[-1])

pre = [0]*(a-1) + pre
# print(pre)
# print(pri)
if len(pri)<k:
    print(-1)
else:
    i = j = a
    l = 0

    while j<=b:

        if pre[j]-pre[i-1]<k:
            j+=1

        else:
            l = max(l,j-i+1)
            i+=1
    l = max(l,j-i+1)
    print(l)


def main():
    def sieve(n):
        s = xrange(3, n + 1, 2)
        r = set(s)
        [r.difference_update(xrange(n << 1, s[-1] + 1, n)) for n in s if n in r]
        return r.union([2])
    a,b,k=map(int,raw_input().split())
    p=filter(lambda x:x>=a and x<=b,sorted(sieve(b)))
    if len(p)<k:
        print -1
        return
    #print p
    m=max(p[k-1]-a+1,b-p[-k]+1)
    try:
        print max(m,max([p[i+k]-p[i] for i in range(len(p)-k)]))
    except:
        print m

if __name__ == '__main__':
    main()


a,b,k=map(int,raw_input().split())
t,p=[True]*(b+1),[]
for i in range(2,b+1):
    if t[i]:
        if i>=a:p.append(i)
        for j in range(i * i, b + 1, i):t[j] = False
print -1 if len(p) < k else max([p[i]-p[i-k] for i in range(k,len(p))] + [b-p[-k]+1,p[k-1]-a+1])


from sys import stdin
def in_row(ch):
    if ch=='f': return 1
    if ch=='a': return 4
    if ch=='b': return 5
    if ch=='c': return 6
    if ch=='d': return 3
    if ch=='e': return 2
li=input().strip()
n=int(li[0:-1])
s=li[-1]
time=0
tmp=(n-1)//4
time += tmp*3 + tmp*13
tmp=(n-1)%4
if tmp==1 or tmp==3:
    time += 7
time += in_row(s)

print(time)


#!/usr/bin/env	python
#-*-coding:utf-8 -*-
z=input()
M='fedabc'
n=int(z.rstrip(M))-1
print(1+M.find(z[-1])+7*(1&n)|n>>2<<4)


import math

arr = map(int, raw_input().split())
arr.sort()

if arr[0] == 1 or arr.count(2) >= 2 or arr.count(3) == 3 or arr == [2, 4, 4] :
        print 'YES'
else:
        print 'NO'


K = int( raw_input() )
mat = [raw_input() for i in range(4) ]
cnt = [ 0 for i in range(10) ]

for x in mat :
    for y in x :
        if y=='.' :
            continue
        cnt[ int(y) ] += 1

for a in cnt :
    if a>K*2 :
        print "NO"
        exit(0)

print "YES"


import datetime as DT

def bus(a, t_a, b, t_b, t):

	t1 = DT.datetime.strptime(t, '%H:%M')
	t2 = DT.datetime(1900, 1, 1)
	t_start = ((t1 - t2).total_seconds() / 60.0) - 300
	t_end = t_start + t_a

	t_elapsed = 0
	z = 0

	while(t_elapsed <= 23 * 60 + 59 - 300):
		start = t_elapsed
		end = start + t_b
		if(max(t_start, start) < min(t_end, end)):
			z += 1
		t_elapsed += b
	return z

if __name__ == "__main__":
    a = input().split(' ')
    b = input().split(' ')
    t = input()
    print(bus(int(a[0]), int(a[1]), int(b[0]), int(b[1]), t))


def main():
    a, ta = map(int, input().split())
    b, tb = map(int, input().split())
    h, m = map(int, input().split(':'))
    res, lo = 0, h * 60 + m - 300
    hi = lo + ta
    print(sum(max(lo, t) < min(hi, t + tb) for t in range(0, 1140, b)))

if __name__ == '__main__':
    main()


from sys import stdin, stdout

n = int(stdin.readline())
values = list(map(int, stdin.readline().split()))
dp = [0 for i in range(n)]

dp[-1] = values[-1]#сколько торта можно захавать, если прийдти туда с фишкой
cnt = values[-1]

for i in range(n - 2, -1, -1):
    cnt += values[i]
    dp[i] = max(dp[i + 1], cnt - dp[i + 1])

stdout.write(str(cnt - dp[0]) + ' ' + str(dp[0]))


N = int(input())
n = list(map(int,input().split(" ")))

if N == 1:
    ans = [0, n[0]]
elif N == 2:
    ans = [min(n), max(n)]
else:
    # print(n)
    n.reverse()
    f = max(n[0], n[1]) # f2
    s = n[0] + n[1] # s2
    for i in range(2, N):
        f = max(n[i] + s - f, f)
        s += n[i]
    # print(f)
    # print(s)
    ans = [s-f, f]

print(" ".join(map(str,ans)))

# assume f(n) is the optimal strategy for the remaning n pies, x_n, x_n-1, ...., x_1
#
# s(n) = sum(x_1,..., x_n)
# f(1) = x1
# f(2) = max(x2, x1)
# f(3) = max(x3 + s(2) - f(2), f(2))
# f(4) = max(x4 + s(3) - f(3), f(3))


n = int(input())
a = list(map(int,input().split()))
if a.count(min(a)) > n//2:
    print('Bob')
else:
    print('Alice')


n = int(input())
cnt = 0
m = 9999999999999999
piles = raw_input().strip().split()
for pile in piles:
    a = int(pile)
    if a < m:
        m = a
        cnt = 1
    elif a == m:
        cnt += 1
if cnt <= n / 2:
    print("Alice")
else:
    print("Bob")


n=int(input())
a=int(input())
b=int(input())
c=int(input())
z=0
if b-c<a and n>c:
    z=(n-c)//(b-c)
    n-=z*(b-c)
z+=n//a
print(z)


n = int(input())
a = int(input())
b = int(input())
c = int(input())
count = 0
while n >= a or n >= b:
    if b - c < a and n // b > 0:
        count = count + (n - c) // (b - c)
        n = n - (n - c) // (b - c) * (b - c)
    else:
        count = count + n // a
        n = n - n // a * a
print(count)


def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b, a%b)

def solve(x, y, a, b):
    ans=""
    while not x==1 or not y==1:
        if x < y:
            x,y,a,b=y,x,b,a
        ans+=str((x-1)//y)+a
        x = x - (x-1)//y * y
    print (ans)

x,y=map(int, input().split())
if gcd(x,y)>1:
    print ("Impossible")
else:
    solve(x,y, "A", "B")


a,b=map(int,raw_input().split())
def ggcd(a,b):
	if b==0:
		return [1,0,a]
	else:
		x,y,d=ggcd(b,a%b)
		x,y=y,x-a/b*y
		return [x,y,d]
y,x,d=ggcd(a,b)
if d!=1:
	print "Impossible"
	exit()
ans=""
def gao(a,b,c,d):
	if a==1 and b==0 and c==0 and d==1: return
	global ans
	if a>c:
		t=b/d
		ans="%dB"%(t)+ans
		a-=c*t
		b-=d*t
		gao(a,b,c,d)
	else:
		t=c/a
		ans="%dA"%(t)+ans
		c-=a*t
		d-=b*t
		gao(a,b,c,d)
x+=a
t=(x-1)/a
x-=t*a
y+=t*b
assert 0<x and x<=a and 0<y and y<=b
gao(x,b-y,a-x,y)
print ans


dp = [[0 for i in range(40)]for j in range(40)]
N,H = map(int,raw_input().split())
dp[0] = [1 for i in range(40)]
for i in range(1,40):
	for j in range(1,40):
		for k in range(0,i):
			dp[i][j] += dp[k][j-1]*dp[i-1-k][j-1]
print dp[N][N] - (H > 0 and dp[N][H-1] or 0)


def go(n,h,v={}):
  if (n,h) not in v:
    v[(n,h)]=(h and sum(go(i,h-1,v)*go(n-1-i,h-1,v) for i in range(n)) or 0) if n else 1
  return v[(n,h)]
n,h=map(int,raw_input().split())
print go(n,n)-go(n,max(0,h-1))


def t(n, h):
	if dp[n][h] == -1:
		dp[n][h] = sum(
			t(m - 1, h - 1) * sum(t(n - m, i) for i in range(h)) +
			t(n - m, h - 1) * sum(t(m - 1, i) for i in range(h - 1))
			for m in range(1, n + 1)
		)

	return dp[n][h]

n, h = map(int, input().split())

def fill(i, j):
	if i == 0 and j == 0:
		return 1

	if i == 0 or j == 0:
		return 0

	return -1

dp = [[fill(i, j) for j in range(n + 1)] for i in range(n + 1)]

for i in range(n + 1):
	for j in range(n + 1):
		t(i, j)

print(sum(dp[n][i] for i in range(h, n + 1)))


from math import *
from Queue import *
from sys import *
from datetime import *

nMax, hMax = map(int, raw_input().split())
table = [[0 for j in range(nMax+1)] for i in range(nMax+1)]
table[0][0] = 1
for i in range(1, nMax+1):
    table[i][i] = 2**(i-1)
for h in range(1, nMax+1):
    for n in range(h+1, nMax+1):
        for i in range(1,n+1):
            for j in range(h):
                table[n][h] += table[i-1][h-1]*table[n-i][j]
            for j in range(h):
                table[n][h] += table[i-1][j]*table[n-i][h-1]
            table[n][h] -= table[i-1][h-1]*table[n-i][h-1]
res = 0
for h in range(hMax, nMax+1):
    res += table[nMax][h]
print(res)


all = {}
limit = {}
n, m = 0, 0
def searchall( lo, hi ):
  if lo == hi:
    return 1
  if all.has_key((lo,hi)):
    return all[(lo,hi)]
  all[(lo,hi)] = 0
  all[(lo,hi)] += searchall( lo+1, hi )
  all[(lo,hi)] += searchall( lo, hi-1 )
  for i in xrange(lo+1,hi):
    all[(lo,hi)] += searchall( lo, i-1 ) * searchall( i+1, hi )
  return all[(lo,hi)]

def searchlimit( lo, hi, depth ):
  global m
  if lo == hi:
    if depth < m:
      return 1
    else:
      return 0
  if limit.has_key((lo,hi,depth)):
    return limit[(lo,hi,depth)]
  limit[(lo,hi,depth)] = 0
  limit[(lo,hi,depth)] += searchlimit( lo+1, hi, depth+1 )
  limit[(lo,hi,depth)] += searchlimit( lo, hi-1, depth+1 )
  for i in xrange(lo+1,hi):
    limit[(lo,hi,depth)] += searchlimit( lo, i-1, depth+1 ) * searchlimit( i+1, hi, depth+1 )
  return limit[(lo,hi,depth)]

def main():
  global n, m
  n, m = map( int, raw_input().rstrip().split() )
  ret = searchall( 1, n ) - searchlimit( 1, n, 1 )
  print ret

if __name__ == "__main__":
  main()


# coding: utf-8

# In[9]:

# In[42]:

line = input().split()

n = int(line[0])
h = int(line[1])
from math import log
array_nodes_minheigt = [[0 for x in range(36)] for y in range(36)]
array_nodes_minheigt[0][0] = 1
for nodes in range(1,36):
    for minheight in range(0,nodes+1):
        for topnode in range(1, nodes + 1):
            left = topnode-1
            right = nodes - topnode
            array_nodes_minheigt[nodes][minheight] += array_nodes_minheigt[left][0] * array_nodes_minheigt[right][0] -             (array_nodes_minheigt[left][0]-array_nodes_minheigt[left][max(minheight-1,0)])*             (array_nodes_minheigt[right][0]-array_nodes_minheigt[right][max(minheight-1,0)])

print(int(array_nodes_minheigt[n][h]))


n, h = map(int, raw_input().split())

dp = [ [-1]*(n+1) for i in xrange(n+1)]

dp[0][0] = 1
def f(n, h):
    if dp[n][h] != -1:
        return dp[n][h]

    if n == 0:
        return 0
    if h == 0:
        return f(n, 1)

    ans = 0
    for i in xrange(n): #0 .. n-1
        ans += f(n-i-1, 0) * f(i, h-1)
        ans += f(n-i-1, h-1) * f(i, 0)
        ans -= f(n-i-1, h-1) * f(i, h-1)

    dp[n][h] = ans
    return ans

print f(n, h)


n, h = map(int, raw_input().split())
dp = [[0 for j in xrange(n + 1)] for i in xrange(n + 1)]
dp[0] = [1 for j in xrange(n + 1)]
for i in xrange(n + 1):
	for j in xrange(1, n + 1):
		for k in xrange(i):
			dp[i][j] += dp[k][j - 1] * dp[i - 1 - k][j - 1]
print dp[n][n] - (h > 0 and [dp[n][h - 1]] or [0])[0]


tab1 = dict()
tab2 = dict()

def num1(n):
    if n < 0:
        return 0
    if n < 2:
        return 1
    if n not in tab1:
        r = 0
        for i in range(n):
            r += num1(i) * num1(n - 1 - i)
        tab1[n] = r
    return tab1[n]

def num2(n, h):
    if n < 0 or h <= 0 or n >= 2 ** (h - 1):
        return 0
    if n < 2:
        return 1
    if n < h:
        return num1(n)
    if (n, h) not in tab2:
        r = 0
        for i in range(n):
            r += num2(i, h - 1) * num2(n - 1 - i, h - 1)
        tab2[n, h] = r
    return tab2[n, h]

n, h = map(int, raw_input().split())
print num1(n) - num2(n, h)


n, h = map(int, input().split())
t = s = [1] * (n + 1)
for m in range(1, n + 1):
    s[m] = sum(s[m - 1 - k] * s[k] for k in range(m))
for j in range(h):
    t = [sum((s[k] - t[k]) * t[m - 1 - k] + s[m - 1 - k] * t[k] for k in range(m)) for m in range(n + 1)]
print(t[n])


n = input()
def ispolindrome(n):
    ans = 0
    if len(n) % 2 == 0:
        ans_len = len(n) // 2
    else:
        ans_len = (len(n) // 2) + 1
    for i in range(ans_len):
        if n[i] == n[len(n) - 1 - i]:
            ans += 1
    if len(n) % 2 and ans == (len(n) // 2) + 1:
        return True
    elif len(n) % 2 == 0 and ans == len(n) // 2:
        return True
    else:
        return False
if ispolindrome(n):
    print("YES")
else:
    n = list(n)
    ans_len = False
    for i in range(len(n)):
        if n[len(n) - 1 - i] == "0":
            ans_len = len(n) - 1 - i
        else:
            break
    if ans_len != False and ispolindrome(n[:ans_len]):
        print("YES")
    else:
        print("NO")


import sys

s = sys.stdin.readline().strip()
r = s[::-1]

i = 0
while r[i] == '0':
    i+=1

p = r[i:]
if p == p[::-1]:
    print "YES"
else:
    print "NO"


a, b, c = [int(x) for x in input().split()]
m = max([a,b,c])
print(max(0, 2*m-a-b-c+1))


a,b,c=map(int,input().split())
if a+b<=c:
    print(c+1-(a+b))
elif a+c<=b:
    print(b + 1 - (a + c))
elif b+c<=a:
    print(a + 1 - (c + b))
else:
    print(0)


import sys
input = sys.stdin.readline
from collections import *

def bfs():
    q = deque([])
    dist = [-1]*(n*2*k)

    for i in range(2*k):
        q.append(i)
        dist[i] = 0

    while q:
        v = q.popleft()

        for nv in G[v]:
            if dist[nv]==-1:
                dist[nv] = dist[v]+1
                q.append(nv)

    for i in range(2*k):
        if dist[(n-1)*2*k+i]!=-1:
            return True

    return False

for _ in range(int(input())):
    n, k, l = map(int, input().split())
    d = list(map(int, input().split()))
    G = [[] for _ in range(n*2*k)]
    p = [i for i in range(k+1)]+[i for i in range(k-1, 0, -1)]

    for i in range(n):
        for j in range(2*k):
            if d[i]+p[j]<=l and d[i]+p[(j+1)%(2*k)]<=l:
                G[i*2*k+j].append(i*2*k+(j+1)%(2*k))

        if i+1<n:
            for j in range(2*k):
                if d[i]+p[j]<=l and d[i+1]+p[(j+1)%(2*k)]<=l:
                    G[i*2*k+j].append((i+1)*2*k+(j+1)%(2*k))

    if bfs():
        print('Yes')
    else:
        print('No')


import sys
import collections
def input():
	return sys.stdin.readline().rstrip()

def split_input():
	return [int(i) for i in input().split()]

# tests = 1
tests = int(input())

for _ in range(tests):
	n,k,l = split_input()
	d = split_input()
	newd = [l - i for i in d]
	if min(newd)<0:
		print("No")
		continue
	kvalue = newd[0]
	dec = True
	ans = True
	# print(newd)
	i = 1
	while i < n:
		# print(kvalue,dec)
		if newd[i] < 0:
			ans = False
			break
		if newd[i] >= k:
			if i < n - 1:
				kvalue = newd[i+1]
				dec = True
				i += 2
				continue
		if kvalue == 0:
			dec = False
		if dec:
			if newd[i] < kvalue:
				kvalue = newd[i]
			else:
				kvalue -= 1
		else:
			if newd[i] <= kvalue:
				ans = False
				break
			else:
				kvalue += 1
		i += 1
	if ans:
		print("Yes")
	else:
		print("No")


import math
r,g,b = map(int,input().split(" "))
t = 30
r = math.ceil(r/2)
g = math.ceil(g/2)
b = math.ceil(b/2)
max = r
if(b>=r and b>=g):
    max = b
    t = t + 2
elif(g>=r and g>=b):
    max = g
    t = t + 1
print(t + (max-1)*3)


r,g,f=map(int,input().split())
c=29
while(1):
    c=c+1
    if r>=2:
        r=r-2
    elif r==1:
        r=r-1

    if r==0 and g==0 and f==0:
        break
    c=c+1
    if g>=2:
        g=g-2
    elif g==1:
        g=g-1
    if r==0 and g==0 and f==0:
        break
    c=c+1
    if f>=2:
        f=f-2
    elif f==1:
        f=f-1
    if r<=0 and g<=0 and f<=0:
        break
print(c)


n, a, b ,c = [int(x) for x in input().split()]
count=0
for i in range(c+1):
    for j in range(b+1):
        t= n - i*2 -j
        if t>=0 and a*0.5 >= t:
            count+=1
print(count)


a,b = map( int, input().split())
c,d = map(int, input().split())
k = 0
if c==a or b==d : k=2
print((abs(c-a)+1)*2 + 2*(abs(b-d)+1)+k)


x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())

if x1 == x2:
    x1 += 1
elif y1 == y2:
    y1 += 1
print((abs(x2 - x1) + 1 + abs(y2 - y1) + 1) * 2)


for i in range(int(input())):
      cnt = 0
      n = int(input())
      a = list(map(int, input().split()))
      a1 = [0,1,2]
      n-=1
      a[0]-=1
      a[1]-=1
      a[2]-=1
      while True:
            if n in a1:
                  cnt+=1
                  x = a[n]
                  n = x
            else:
                  break
      print("YES" if cnt == 3 else "NO")


t = int(input())
while t > 0:
    n = int(input())
    ans = 'YES'
    d = list(map(int,input().split()))
    for i in range(1,4):
        if i == d[i - 1]:
            ans = 'NO'
    ix = d.index(0)
    if ix + 1 not in d:
        ans = 'NO'
    print(ans)
    t -= 1


n,aa = map(int,raw_input().strip().split(" "))[:2]
a = [x for x in range(1,n+1,2)]
b = [y for y in range(2,n+1,2)]
b.reverse()
c = list(zip(a,b))
res = []
for i,cc in enumerate(c):
	if aa in list(cc):
		res.append(i+1)
		break
print(res[0])


n, a = map(int, input().split())

if a % 2 == 1:
    print((a + 1) // 2)
else:
    print(n // 2 - a // 2 + 1)


from math import sqrt
def naive_subseq(sq, num):
    next_sq = 0
    for dig in num:
        if dig == sq[next_sq]:
            next_sq += 1
            if next_sq == len(sq):
                break
    if next_sq == len(sq):
        return True
    else:
        return False
n = raw_input().strip()
lim = int(sqrt(int(n))) + 1
squares, done = map(str, [i * i for i in range(1,lim)]), False
for i in range(lim - 2, -1, -1):
    if naive_subseq(squares[i], n):
        done = True
        print len(n) - len(squares[i])
        break
if not done:
    print -1


import sys

def get_square_literal_map():
    literal_map = {}
    for i in range(1, 44722):
        literal = str(i * i)
        literal_len = len(literal)
        if literal_len not in literal_map:
            literal_map[literal_len] = set()
        literal_map[literal_len].add(literal)
    return literal_map

def is_subsequence(x, y):
    it = iter(y)
    return all(any(c == ch for c in it) for ch in x)

def get(n):
    literal_map = get_square_literal_map()
    n_len = len(n)
    for i in range(n_len, 0, -1):
        for j in literal_map[i]:
            if is_subsequence(j, n):
                return n_len - i
    return -1

def main():
    n = sys.stdin.readline().strip()
    print(get(n))

if __name__ == '__main__':
    sys.exit(main())


u = [0]*10000
a = int(input())
b = input().split()
start = int(b[0])
me = int(b[0])
mx = 0
for i in b[1:]:
    i = int(i)
    u[i]+=1
    mx=max(mx,i)
i = mx
while me<i:
    z = u[i]
    while u[i] and me<=i:
        me+=1
        u[i]-=1
    u[i-1]+=z
    i-=1
if me == i:
    me+=1
print(me-start)


n = int(input())
votes = [int(i) for i in input().split()]
me = votes[0]
rest = votes[1:]
rest.sort(reverse = True)
answer = 0

while (me <= rest[0]):
    me += 1
    rest[0] -= 1
    answer += 1
    rest.sort(reverse = True)

print(answer)


from math import gcd
a,b = map(int,input().split(' '))
gcd = gcd(a,b)
a,b = a/gcd, b/gcd
if abs(a-b) <= 1: print('Equal')
elif a < b: print('Dasha')
else: print('Masha')


from math import gcd
n,m=map(int,input().split())
lcm=n*m//(gcd(n,m))
a,b=lcm//n,lcm//m
# print()
if abs(a-b)<=1:
    print("Equal")
elif a>b:
    print("Dasha")
else:
    print("Masha")


def dis(x,y,d):
    if y==0 or x==d:
        return x+y
    else:
        return 4*d - x - y
d,x1,y1,x2,y2 = map(int, input().split())
a = abs(dis(x1,y1,d) - dis(x2,y2,d))
print(min(a, 4*d-a))


#coding: utf-8
def dot(a, b):
    return a[0]*b[1] - a[1]*b[0]
def main():
    n,x1,y1,x2,y2 = map(int, raw_input().split())
    if dot((n,n),(x1,y1))*dot((n,n),(x2,y2)) < 0:
        ans = x1 + y1 + x2 + y2
    else:
        ans = abs((x1+y1)-(x2+y2))
    print min(ans, 4*n-ans)
main()


def nod(a, b):
    if(b == 0): return a
    else: return nod(b, a % b)

n = input()
s = 0
col = n - 2
for i in range(2, n):
    os = []
    k = n
    while k > 0:
        os.append(k % i)
        k /= i
    s += sum(os)
x = nod(s, col)
print(str(s / x) + '/' + str(col / x))


from __future__ import print_function

def gcd(a,b):
	while b:
		a,b = b, a%b
	return a

def cal(i,n):
	temp = 0
	while n > 0:
		temp += n%i
		n = n// i
	return temp

n=int(input())
sum = 0
for base  in range(2,n):
	sum += cal(base,n)
n -= 2
print(sum//gcd(sum,n),n//gcd(sum,n),sep='/')
# ~ print(gcd(5,10))


import math
import queue

from itertools import permutations

n=int(input())
s=input()

def determine(t):
    for i in range(0,n-1):
        if t[i]==t[i+1] and t[i]!='?':
            return False

    for i in range(0,n-1):
        if t[i]=='?' and t[i+1]=='?':
            return True

    num=0

    if t[0]=='?' or t[n-1]=='?':
        return True

    for i in range(1,n-1):
        if t[i]=='?' and t[i-1]==t[i+1]:
            return True
    return False

if determine(s):
    print("YES")
else:
    print("No")


def main():
	n = int(raw_input())
	s = raw_input()
	two_pos = False
	if s[0] == '?' or s[-1] == '?':
		two_pos = True

	for i in range(len(s)-1):
		if s[i] != '?' and s[i] == s[i+1]:
			return False
		if s[i] == '?' and s[i+1] == '?':
			two_pos = True
		if i > 0 and s[i] == '?' and s[i-1] == s[i+1]:
			two_pos = True

	return two_pos

if main():
	print("Yes")
else:
	print("No")


from math import *
n, m, k = map(int, input().split())
c = lambda n, k: 0 if k > n else factorial(n) // (factorial(k) * factorial(n - k))
print(c(n - 1, 2 * k) * c(m - 1, 2 * k) % 1000000007)


from sys import stdin, stdout, stderr, exit
from math import log, factorial
import re

# inputf = open('input.txt', 'r')
# outputf = open('output.txt', 'w')

def readil():
    return list(map(int, stdin.readline().strip().split()))

def C(n, k):
    if(n-k >= 0):
        return factorial(n) // factorial(k) // factorial(n-k)
    else:
        return 0

def main():
    n, m, k = readil()
    stdout.write(str((C(n - 1, 2 * k) * C(m - 1, 2 * k)) % 1000000007))

if __name__ == '__main__':
    main()

# inputf.close()
# outputf.close()


from math import sqrt

n = int(input())
if n == 0:
    print(1)
else:
    print(4 * int(n * sqrt(2)))


n, m = map(int, raw_input().split())
x = input()
b = lambda h, w: ((h + 1) / 2) * ((w + 1) / 2) + (h / 2) * (w / 2) if h > 0 and w > 0 else 0
h, w = n - x - x, m - x - x
print b(h + 2, w + 2) - b(h, w)


a = raw_input()
print 'Yes' if set('ABC') in map(set, zip(a, a[1:], a[2:])) else 'No'


a = list(input())
n = ['B', 'A', 'C']
for k in range(len(a)):
    if a[k] in n and k < len(a)-1 and k > 0:
        if a[k-1] in n and a[k+1] in n:
            if a[k-1] != a[k+1] and a[k-1] != a[k] and a[k] != a[k+1]:
                print('Yes')
                break
else:
    print('No')


n,m,c0,d0 = [int(j) for j in input().split()]
nach = []
nach.append([0,0,c0,d0])
for i in range(m):
    nach.append([int(j) for j in input().split()])

profit = []
nabor = [[0] * (m+1) for i in range(n+1)]
profit = [0] * (n+1)
for nn in range(1,n+1):
    for j in range(m+1):
        if nn - nach[j][2] >= 0:
            if (nabor[nn - nach[j][2]][j] + 1) * nach[j][1] <= nach[j][0] and profit[nn-nach[j][2]]+nach[j][3] > profit[nn]:
                profit[nn] = profit[nn-nach[j][2]]+nach[j][3]
                for k in range(m+1):
                    nabor[nn][k] = nabor[nn - nach[j][2]][k]
                nabor[nn][j] += 1
MaxProfit = 0
for i in range(n+1):
    if MaxProfit < profit[i]:
        MaxProfit = profit[i]

print(MaxProfit)


# -*- coding: utf-8 -*-

import sys

data = sys.stdin.readlines()

n, m, c0, d0 = map(int, data[0].split())

a = [0]
b = [0]
c = [0]
d = [0]

for i in xrange(1, m + 1):
    da, db, dc, dd = map(int, data[i].split())
    a.append(da)
    b.append(db)
    c.append(dc)
    d.append(dd)

dp = []      # n x m
for i in xrange(0, n + 1): dp.append([ 0 for j in xrange(0, m+1)])

for i in xrange(0, n + 1):
    for j in xrange(1, m + 1):
        for k in xrange(0, a[j]/b[j] + 1):
            if i - c[j]*k >= 0:
                dp[i][j] = max(dp[i][j], dp[i-c[j]*k][j-1] + d[j]*k)

#for i in xrange(0, n):
#    for j in xrange(0, m+1):
#        print "%3s " % dp[i][j],
#    print
#print

tugrics = 0
for k in xrange(0, n + 1):
    tugrics = max(tugrics, dp[k][m] + ((n-k)/c0)*d0)

print tugrics


from sets import Set
s=raw_input()
a=Set()
n=10
res = 1
for i in range(len(s)):
	if s[i] == '?':
		if i == 0:
			res *= 9
		else:
			res *= 10
	elif s[i] >= 'A' and s[i] <= 'Z':
		if s[i] not in a:
			if i == 0:
				res *= 9
			else:
				res *= n
			if n > 0:
				n = n-1
			a.add(s[i])
print res


games = []
teams = []
points = {}
diffs = {}
goals = {}
vsberland = []

def order(a, b):
	if points[a] > points[b]:
		return -1
	elif points[a] < points[b]:
		return 1
	if diffs[a] > diffs[b]:
		return -1
	elif diffs[a] < diffs[b]:
		return 1
	if goals[a] > goals[b]:
		return -1
	elif goals[a] < goals[b]:
		return 1
	return cmp(a, b)

for i in range(5):
	tokens = raw_input().split()
	team1 = tokens[0]
	team2 = tokens[1]
	goals1, goals2 = map(int, tokens[2].split(':'))
	games.append([(team1, goals1), (team2, goals2)])
	if team1 not in teams:
		teams.append(team1)
		points[team1] = 0
		diffs[team1] = 0
		goals[team1] = 0
	if team2 not in teams:
		teams.append(team2)
		points[team2] = 0
		diffs[team2] = 0
		goals[team2] = 0
	if goals1 > goals2:
		points[team1] += 3
	elif goals1 < goals2:
		points[team2] += 3
	else:
		points[team1] += 1
		points[team2] += 1
	diffs[team1] += goals1
	diffs[team2] -= goals1
	diffs[team1] -= goals2
	diffs[team2] += goals2
	goals[team1] += goals1
	goals[team2] += goals2
	if team1 == 'BERLAND':
		vsberland.append(team2)
	elif team2 == 'BERLAND':
		vsberland.append(team1)

teams.sort(cmp=order)

result = (10000, 0, 10000)

team1 = 'BERLAND'
for team2 in teams:
	if team2 != team1 and team2 not in vsberland:
		points[team1] += 3

		for goals1 in range(0, 201):
			for goals2 in range(0, goals1):
				diffs[team1] += goals1
				diffs[team2] -= goals1
				diffs[team1] -= goals2
				diffs[team2] += goals2
				goals[team1] += goals1
				goals[team2] += goals2

				teams.sort(cmp=order)
				if teams[0] == team1 or teams[1] == team1:
					if goals1-goals2 < result[0] or goals1-goals2 == result[0] and goals2 < result[2]:
						result = (goals1-goals2, goals1, goals2)

				diffs[team1] -= goals1
				diffs[team2] += goals1
				diffs[team1] += goals2
				diffs[team2] -= goals2
				goals[team1] -= goals1
				goals[team2] -= goals2

		break

if result[0] == 10000:
	print 'IMPOSSIBLE'
else:
	print '%d:%d'%(result[1], result[2])


teams={}
for _ in range(5):
    t1,t2,scores=raw_input().split()
    s1,s2=map(int,scores.split(':'))
    teams[t1]=teams.get(t1) or [0,0,0,t1,0]
    teams[t2]=teams.get(t2) or [0,0,0,t2,0]
    if s1>s2:
        teams[t1][0]-=3
    elif s1<s2:
        teams[t2][0]-=3
    else:
        teams[t1][0]-=1
        teams[t2][0]-=1
    teams[t1][1]-=s1-s2
    teams[t2][1]-=s2-s1
    teams[t1][2]-=s1
    teams[t2][2]-=s2
    teams[t1][4]+=1
    teams[t2][4]+=1
oppo=[t[3] for t in teams.values() if t[3]!='BERLAND' and t[4]<3][0]
for xy in range(1,123):
    for y in range(0,123):
        t1,t2=teams['BERLAND'][:],teams[oppo][:]
        t1[0]-=3
        t1[1]-=xy
        t2[1]+=xy
        t1[2]-=y+xy
        t2[2]-=y
        t1[4]+=1
        t2[4]+=1
        tms=[t for t in teams.values() if t[4]>2]+[t1,t2]
        tms.sort()
        if tms[0][3]=='BERLAND' or tms[1][3]=='BERLAND':
            print '%d:%d'%(y+xy,y)
            exit()
print 'IMPOSSIBLE'


"""."""
import math
l, r, gcd, lcm = (int(x) for x in input().split())
if lcm % gcd != 0:
    print(0)
    quit()

lcm_divisors = set()
for num in range(1, int(lcm**0.5) + 2):
    if lcm % num == 0:
        lcm_divisors.add(num)
        lcm_divisors.add(lcm // num)
product = gcd * lcm
answers = set()
for divisor in lcm_divisors:
    if divisor < l or divisor > r:
        continue
    dop = product // divisor
    if dop < l or dop > r:
        continue
    if math.gcd(divisor, dop) != gcd:
        continue
    answers.add((divisor, dop))
    answers.add((dop, divisor))

print(len(answers))


l,r,x,y=map(int,raw_input().split())
if x==y:
    if x in range(l,r+1):
        print 1
    else:
        print 0
    exit(0)
if y%x!=0:
    print 0
    exit(0)
m=y/x
a=l//x
if l%x!=0:
    a+=1
b=r//x
s=[]
z=m
k=2
while z!=1:
    p=1
    while z%k==0:
        p*=k
        z/=k
    if p!=1 and p<=b:
        s.append(p)
    k+=1
l=len(s)
#print s
if l==0:
    print 0
    exit(0)
c=0
for i in range(pow(2,l-1)):
    p=1
    q=i
    for j in range(l):
        if q%2==1:
            p*=s[j]
        q//=2
    if p in range(a,b+1) and m/p in range(a,b+1):
        c+=2
print c


n, m = map(int, input().split())
prep = []

days = [-1] * n
release = []

for i in range(m):
    s_, d_, c_ = map(int, input().split())
    release.append(s_)
    days[d_ - 1] = i
    prep.append(c_)

rel_on_day = {}
for i, r in enumerate(release):
    if r - 1 in rel_on_day:
        rel_on_day[r - 1].append(i)
    else:
        rel_on_day[r - 1] = [i]

ans = []

waiting = set()

exam_q = []
for d in days:
    if d != -1:
        exam_q.append(d)

#print(rel_on_day)

for i in range(n):
    if i in rel_on_day:
        waiting = waiting | set(rel_on_day[i])

 #   print(waiting)

    if days[i] != -1: #exam
        if prep[days[i]] == 0:
            ans.append(m + 1)
            waiting.remove(days[i])
        else:
            print(-1)
            exit(0)
    else: #choose closest unstudied exam
        chosen = None
        for ex in exam_q:
            if prep[ex] > 0 and ex in waiting:
                chosen = ex
                break
        if not chosen is None:
            prep[ex] -= 1
            ans.append(ex + 1)
        else:
            ans.append(0)

print(" ".join(list(map(str, ans))))


n, m = map(int, input().split())
arr = []
for i in range(1, m + 1):
    s, d, c = map(int, input().split())
    arr.append((d, s, c, i))
arr.sort()
ans = [0] * (n + 1)
for d, s, c, i in arr:
    j = s
    ef = False
    for k in range(c):
        while j < d and ans[j] != 0:
            j += 1
        if j >= d:
            ef = True
            break
        ans[j] = i
    if ef:
        print(-1)
        break
    if ans[d] == 0:
        ans[d] = m + 1
    else:
        print(-1)
        break
else:
    print(*ans[1:])


from itertools import *

l1=[1,2,3,0,4,5]
l2=[4,1,5,3,2,0]
l3=[0,4,2,5,3,1]

def perm(l,p):
	return ''.join([l[c] for c in p])

def incr_inst(orig):
	curr=orig
	s=set()
	r=range(4)
	for i in r:
		for j in r:
			for k in r:
				s.add(curr)
				curr = perm(curr,l1)
			curr = perm(curr,l3)
		curr = perm(curr,l2)
	return min(list(s))

orig=raw_input()

s=set()
for c in permutations(orig):
	s.add(incr_inst(''.join(list(c))))
print len(s)


n = input()
print n/3 *2 +1 if n%3 else n/3 *2


class CodeforcesTask669ASolution:
    def __init__(self):
        self.result = ''
        self.n = 0

    def read_input(self):
        self.n = int(input())

    def process_task(self):
        res = 2 * (self.n // 3) + self.n % 3
        if self.n % 3 == 2:
            res -= 1
        self.result = str(res)

    def get_result(self):
        return self.result

if __name__ == "__main__":
    Solution = CodeforcesTask669ASolution()
    Solution.read_input()
    Solution.process_task()
    print(Solution.get_result())


a,b=map(int,input().split())
a,b=min(a,b),max(a,b)
if a==b:print(0)
else:
    M,u=2*a*b,0
    D=1
    while D*D<=b-a:
        if (b-a)%D==0:
            for d in (D,(b-a)//D):
                k=0
                if a%d!=0:
                    k=d-a%d
                Q=(a+k)*(b+k)/d
                if Q<M:
                    M=Q
                    u=k
        D+=1
    print(u)


a, b = map(int, input().split())
a, b = min(a, b), max(a, b)
if b % a == 0:
    print(0)
    exit(0)
x = b - a
dels = set()
for i in range(1, int(x ** 0.5) + 1):
    if x % i == 0:
        dels.add(i)
        dels.add(x // i)
dels = list(dels)
j = 10 ** 20
for i in dels:
    if i >= a:
        j = min(j, i - a)
print(min((x % a - a) % x, j))


# brute force motherfuckers
hopScotch = [1]
for x in range(1,1000001,3):
    hopScotch.append(x+1)
    hopScotch.append([x+2,x+3])
a,x,y = map(int,input().split())
if y == 0 or abs(x) >= a: print(-1)
else:
    seq = [1,2]
    jump,rem = y//a,y%a
    if rem + jump == jump: print(-1)
    else:
        if jump == 0:
            print (1 if abs(x) < a/2 else -1)
        else:
            match = seq[(jump+1)%2]
            if match == 1:
                print(hopScotch[jump] if abs(x) < a/2 else -1)
            else:
                if x == 0: print(-1)
                else: print(hopScotch[jump][0] if x < 0 else hopScotch[jump][1])


from sys import setrecursionlimit
setrecursionlimit(1000000000)

def main():
    a, b, c=[int(i) for i in input().split()]
    if c%a==0:
        print("-1")
        return 0
    p=c//a
    if p==0:
        if (b>-1*a/2) and (b<a/2):
            print('1')
            return 0
    elif p%2==0:
        if (b > -1*a) and (b<0):
            print(p//2*3)
            return 0
        if (b<a) and (b>0):
            print(p//2*3+1)
            return 0
    else:
        if (b>-1*a/2) and (b<a/2):
            print(p//2*3+2)
            return 0
    print("-1")

main()


a,b,c=[int(x) for x in input().split(' ')]
mod=1073741824
divisors=[1]*1000001
for x in range(2,1000001):
	for y in range(x,1000001,x):
		divisors[y]+=1
ans=0
for i in range(1,a+1):
	for j in range(1,b+1):
		for k in range(1,c+1):
			ans+=(divisors[i*j*k])%mod
print(ans%mod)


def inp():
    return map(int, stdin.readline().split())

def factorize(n):  # o(sqr(n))
    c, ans = 1, 0
    while (c * c < n):
        if n % c == 0:
            ans += 2
        c += 1

    if c * c == n:
        ans += 1
    return ans

from sys import *
from collections import *

a, b, c = inp()
mem, ans = defaultdict(int), 0

for i in range(1, a + 1):
    for j in range(1, b + 1):
        for k in range(1, c + 1):
            pro = i * j * k
            if mem[pro] == 0:
                mem[pro] = factorize(pro)
            ans += mem[pro]
print(ans)


a,b,r=map(int,raw_input().split())
print ['First','Second'][2*r > min(a,b)]


[a, b, r] = [int(x) for x in raw_input().split()]

if min(a, b) < 2*r:
    print 'Second'
else:
    print 'First'


import sys

def solve():
    n, k = map(int, input().split())
    a = [int(i) - 1 for i in input().split()]

    kinds = len(set(a))

    if kinds <= k:
        print(kinds)
        return

    books = [False] * n
    have = 0
    cost = 0

    for i, ai in enumerate(a):
        if books[ai]:
            continue
        else:
            if have < k:
                books[ai] = True
                cost += 1
                have += 1
            else:
                trash = -1
                longest = -1

                for j in range(n):
                    if books[j]:
                        if j not in a[i + 1:]:
                            trash = j
                            break

                        m = a[i + 1:].index(j)

                        if longest < m:
                            longest = m
                            trash = j

                assert trash != -1

                books[trash] = False
                books[ai] = True
                cost += 1

        # print([i for i in range(n) if books[i]])

    print(cost)

if __name__ == '__main__':
    solve()


def index(e,l,s):
    res=[]
    off=s
    while True:
        try:
            off=l.index(e,off+1)
        except ValueError:
            break
        else:
            res.append(off)
    if(len(res)!=0):
        return res[0]
    else:
        return 10**9

ni=list(map(int,input().strip().split(' ')))
n=ni[0]
k=ni[1]
arr=(list(map(int,input().strip().split(' '))))
li=[]
cost=0
if(k>=len(set(arr))):
    s=set(arr)
    print(len(s))
else:
    v=1
    i=1
    li.append(arr[0])
    while(v<k and i<n):
        if(arr[i] not in li):
            li.append(arr[i])
            v+=1
        i+=1
    cost=k
    for j in range(i,n):
        if(arr[j] not in li):
            mi=0
            for h in li:
                ind=index(h,arr,j)
                if(ind>mi):
                    mi=ind
                    val=h
            li.remove(val)
            li.append(arr[j])
            cost+=1
    print(cost)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n=int(input())
mod=10**9+7

ANS=[[0]*(n+1) for i in range(n+1)]

def bra(x,y):
    if ANS[x][y]!=0:
        return ANS[x][y]

    if x==y==0:
        ANS[x][y]=0
        return 0

    if (x+y)%2==1:
        A=1
    else:
        A=0

    if x==y:
        ANS[x][y]=A+bra(x-1,y)
        return ANS[x][y]

    elif x==0:
        ANS[x][y]=A+bra(x,y-1)
        return ANS[x][y]

    elif y==0:
        ANS[x][y]=A+bra(x-1,y)
        return ANS[x][y]

    elif x<y and x!=0 and y!=0:
        ANS[x][y]=A+bra(x-1,y)+bra(x,y-1)
        return ANS[x][y]

print(bra(n,n)%mod)


#!/usr/bin/env python

from sys import stdin, stderr

def rot(x, y):
   return (.5*x - .5*y, .5*x + .5*y)

def cand(X, Y, A, B):
   P = []
   if X % B == 0:
      if Y % A == 0:
         P.append( (X-1, Y-1) )
         P.append( (X-1, Y+1) )
         P.append( (X+1, Y-1) )
         P.append( (X+1, Y+1) )
      else:
         P.append( (X-1, Y) )
         P.append( (X+1, Y) )
   else:
      if Y % A == 0:
         P.append( (X, Y-1) )
         P.append( (X, Y+1) )
      else:
         P.append( (X, Y) )
   return P

def dist(p1, p2, A, B):
   print >>stderr, p1, p2
   x1 = p1[0]/B
   y1 = p1[1]/A
   x2 = p2[0]/B
   y2 = p2[1]/A
   dx = abs(x1-x2)
   dy = abs(y1-y2)
   print >>stderr, 'dx: %d  dy: %d' % (dx, dy)
   return max(dx, dy)

a, b, x1, y1, x2, y2 = map(int, stdin.readline().split())
A = a*2
B = b*2

(X1, Y1) = rot(x1, y1)
X1 = int(X1*2)
Y1 = int(Y1*2)
P1 = cand(X1, Y1, A, B)

(X2, Y2) = rot(x2, y2)
X2 = int(X2*2)
Y2 = int(Y2*2)
P2 = cand(X2, Y2, A, B)

res = 1000000000000000000
for p1 in P1:
   for p2 in P2:
      res = min(res, dist(p1, p2, A, B))

print res


c,H,h,W,w=map(int,raw_input().split())
if W*W>=c or w*w>=c:
  if w>W:H,h,W,w=h,H,w,W
  I=c/W+1
else:
  if H*w>h*W:H,h,W,w=h,H,w,W
  I=w
print max(i*H+(c-i*W)/w*h for i in range(I))


c, hr, hb, wr, wb = map(int, raw_input().split())
if c<wr:
    print c/wb*hb
elif c<wb:
    print c/wr*hr
else:
    v1 = 1.0*hr/wr
    v2 = 1.0*hb/wb
    if v1<v2:
        wtemp = wr
        htemp = hr
        wr = wb
        hr = hb
        wb = wtemp
        hb = htemp
    joy = 0

    for i in xrange(wr+1):
        if c-i*wb<0:
            break
        joy = max(joy, i*hb+(c-i*wb)/wr*hr)

    print joy


import sys
sys.setrecursionlimit(10000000)
def dp(white, black, mem, prin = 1):
    if black < 0 or white <= 0:
        if prin == 1: return 0
        return 1
    if mem[white][black][prin] != -1: return mem[white][black][prin]
    if prin == 1:
        wewinnow = float(white) / (white + black)
        wewinlater = (1 - wewinnow) * dp(white, black - 1, mem, 0)
        res = wewinnow + wewinlater
        mem[white][black][prin] = res
        return res
    dragonblanks = float(black) / (white + black)
    whitejump, blackjump = 0, 0
    if black > 0: whitejump = dragonblanks * (float(white) / (white + black - 1)) * dp(white - 1, black - 1, mem)
    if black > 1: blackjump = dragonblanks * (float(black - 1) / (white + black - 1)) *dp(white, black - 2, mem)
    res = whitejump + blackjump
    mem[white][black][prin] = res
    return res
w, b = map(int, raw_input().split())
mem = [[[-1] * 2 for _ in xrange(b + 1)] for _ in xrange(w + 1)]
print(dp(w, b, mem))


w, b = map(float, raw_input().split())

dp = {}
def solve(w, b, p, turn):
    #print w, b, p, turn
    key = (w, b, turn)
    if key in dp:
        return dp[key]

    if w == 0:
        return 0

    if b == 0:
        if turn:
            return p
        else:
            return 0

    result = 0
    if turn:
        wc =  p * (w / (w+b))
        bc = solve(w, b-1, p * (b / (w+b)), not turn)
        result = wc + bc
    else:
        if b == 1:
            result = solve(w-1, b-1, p * (b / (w+b)) * (w / (w+b-1)), not turn)
        else:
            result = solve(w-1, b-1, p * (b / (w+b)) * (w / (w+b-1)), not turn) + solve(w, b-2, p * (b / (w+b)) * ((b-1) / (w+b-1)), not turn)

    dp[key] = result
    return result

print solve(w, b, 1, True)

#for key in dp:
#    print key, dp[key]


import sys
import collections

infile = sys.stdin.buffer
def gs()  : return infile.readline().rstrip()
def gi()  : return int(gs())
def gss() : return gs().split()
def gis() : return [int(x) for x in gss()]

MOD = 10 ** 9 + 7
INF = 10 ** 12
N = 10 ** 5

def main(infn="") :
    global infile
    infile = open(infn,"r") if infn else open(sys.argv[1],"r") if len(sys.argv) > 1 else sys.stdin
    ######################################################################
    n,m = gis()
    dp = [0 for _ in range(n+1)]
    dp[1] = 1
    h = [0 for _ in range(n+1)]
    cumul = 0
    prev = dp[1]
    h[2]-=1
    for u in range(1, len(dp)):
        if u > 1:
            dp[u] += prev + dp[1]
            dp[u] %= m

            cumul += h[u]
            cumul %= m

            dp[u] += cumul
            dp[u] %= m

            prev += dp[u]
            prev %= m
        '''u = 7
        14 + 0, 14 + 1, 14 + 2
        7        7         8
        '''
        j = 2
        while( j * u < len(dp)):
            h[j*u] += dp[u]
            h[j*u] %= m
            if j*u + j< len(dp):
                h[j*u + j] -= dp[u]
                h[j*u + j] %= m
            j+=1
    print (dp[-1])

    ######################################################################
if __name__ == '__main__' :
    main()


import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################

n, m = na()
dp = [1]*(n+1)
res = 1
z = 1
for i in range(4,n+1,2):
    dp[i] -= 1

for i in range(2,n+1):
    s = (res + dp[i])%m
    for j in range(i*2,n+1,i):
        #print(i, j, s)
        dp[j] += s
        dp[j] %= m
    for j in range((i+1)*2,n+1,i+1):
        #print(i, j, -s)
        dp[j] -= s
        dp[j] %= m
    res = s*2%m

print(s)


def divisors(M):
    d=[]
    i=1
    while M>=i**2:
        if M%i==0:
            d.append(i)
            if i**2!=M:
                d.append(M//i)
        i=i+1
    return d

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

def eratosthenes(n):
    res=[0 for i in range(n+1)]
    prime=set([])
    for i in range(2,n+1):
        if not res[i]:
            prime.add(i)
            for j in range(1,n//i+1):
                res[i*j]=1
    return prime

def factorization(n):
    res=[]
    for p in prime:
        if n%p==0:
            while n%p==0:
                n//=p
            res.append(p)
    if n!=1:
        res.append(n)
    return res

def euler_phi(n):
    res = n
    for x in range(2,n+1):
        if x ** 2 > n:
            break
        if n%x==0:
            res = res//x * (x-1)
            while n%x==0:
                n //= x
    if n!=1:
        res = res//n * (n-1)
    return res

def ind(b,n):
    res=0
    while n%b==0:
        res+=1
        n//=b
    return res

def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2, 3, 5, 7, 11, 13, 17]
    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 findFactorRho(n):
    from math import gcd
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (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 isPrimeMR(g): return g
            elif isPrimeMR(n // g): return n // g
            return findFactorRho(g)
def primeFactor(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 += 1 + i % 2
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(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

def divisors(n):
    res = [1]
    prime = primeFactor(n)
    for p in prime:
        newres = []
        for d in res:
            for j in range(prime[p]+1):
                newres.append(d*p**j)
        res = newres
    res.sort()
    return res

def xorfactorial(num):
    if num==0:
        return 0
    elif num==1:
        return 1
    elif num==2:
        return 3
    elif num==3:
        return 0
    else:
        x=baseorder(num)
        return (2**x)*((num-2**x+1)%2)+function(num-2**x)

def xorconv(n,X,Y):
    if n==0:
        res=[(X[0]*Y[0])%mod]
        return res
    x=[X[i]+X[i+2**(n-1)] for i in range(2**(n-1))]
    y=[Y[i]+Y[i+2**(n-1)] for i in range(2**(n-1))]
    z=[X[i]-X[i+2**(n-1)] for i in range(2**(n-1))]
    w=[Y[i]-Y[i+2**(n-1)] for i in range(2**(n-1))]
    res1=xorconv(n-1,x,y)
    res2=xorconv(n-1,z,w)
    former=[(res1[i]+res2[i])*inv for i in range(2**(n-1))]
    latter=[(res1[i]-res2[i])*inv for i in range(2**(n-1))]
    former=list(map(lambda x:x%mod,former))
    latter=list(map(lambda x:x%mod,latter))
    return former+latter

def merge_sort(A,B):
    pos_A,pos_B = 0,0
    n,m = len(A),len(B)
    res = []
    while pos_A < n and pos_B < m:
        a,b = A[pos_A],B[pos_B]
        if a < b:
            res.append(a)
            pos_A += 1
        else:
            res.append(b)
            pos_B += 1
    res += A[pos_A:]
    res += B[pos_B:]
    return res

class UnionFindVerSize():
    def __init__(self, N):
        self._parent = [n for n in range(0, N)]
        self._size = [1] * N
        self.group = N

    def find_root(self, x):
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x])
        stack = [x]
        while self._parent[stack[-1]]!=stack[-1]:
            stack.append(self._parent[stack[-1]])
        for v in stack:
            self._parent[v] = stack[-1]
        return self._parent[x]

    def unite(self, x, y):
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        self.group -= 1

        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]

    def get_size(self, x):
        return self._size[self.find_root(x)]

    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

class WeightedUnionFind():
    def __init__(self,N):
        self.parent = [i for i in range(N)]
        self.size = [1 for i in range(N)]
        self.val = [0 for i in range(N)]
        self.flag = True
        self.edge = [[] for i in range(N)]

    def dfs(self,v,pv):
        stack = [(v,pv)]
        new_parent = self.parent[pv]
        while stack:
            v,pv = stack.pop()
            self.parent[v] = new_parent
            for nv,w in self.edge[v]:
                if nv!=pv:
                    self.val[nv] = self.val[v] + w
                    stack.append((nv,v))

    def unite(self,x,y,w):
        if not self.flag:
            return
        if self.parent[x]==self.parent[y]:
            self.flag = (self.val[x] - self.val[y] == w)
            return

        if self.size[self.parent[x]]>self.size[self.parent[y]]:
            self.edge[x].append((y,-w))
            self.edge[y].append((x,w))
            self.size[x] += self.size[y]
            self.val[y] = self.val[x] - w
            self.dfs(y,x)
        else:
            self.edge[x].append((y,-w))
            self.edge[y].append((x,w))
            self.size[y] += self.size[x]
            self.val[x] = self.val[y] + w
            self.dfs(x,y)

class Dijkstra():
    class Edge():
        def __init__(self, _to, _cost):
            self.to = _to
            self.cost = _cost

    def __init__(self, V):
        self.G = [[] for i in range(V)]
        self._E = 0
        self._V = V

    @property
    def E(self):
        return self._E

    @property
    def V(self):
        return self._V

    def add_edge(self, _from, _to, _cost):
        self.G[_from].append(self.Edge(_to, _cost))
        self._E += 1

    def shortest_path(self, s):
        import heapq
        que = []
        d = [10**15] * self.V
        d[s] = 0
        heapq.heappush(que, (0, s))

        while len(que) != 0:
            cost, v = heapq.heappop(que)
            if d[v] < cost: continue

            for i in range(len(self.G[v])):
                e = self.G[v][i]
                if d[e.to] > d[v] + e.cost:
                    d[e.to] = d[v] + e.cost
                    heapq.heappush(que, (d[e.to], e.to))
        return d

#Z[i]:length of the longest list starting from S[i] which is also a prefix of S
#O(|S|)
def Z_algorithm(s):
    N = len(s)
    Z_alg = [0]*N

    Z_alg[0] = N
    i = 1
    j = 0
    while i < N:
        while i+j < N and s[j] == s[i+j]:
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg

class BIT():
    def __init__(self,n,mod=0):
        self.BIT = [0]*(n+1)
        self.num = n
        self.mod = mod

    def query(self,idx):
        res_sum = 0
        mod = self.mod
        while idx > 0:
            res_sum += self.BIT[idx]
            if mod:
                res_sum %= mod
            idx -= idx&(-idx)
        return res_sum

    #Ai += x O(logN)
    def update(self,idx,x):
        mod = self.mod
        while idx <= self.num:
            self.BIT[idx] += x
            if mod:
                self.BIT[idx] %= mod
            idx += idx&(-idx)
        return

class dancinglink():
    def __init__(self,n,debug=False):
        self.n = n
        self.debug = debug
        self._left = [i-1 for i in range(n)]
        self._right = [i+1 for i in range(n)]
        self.exist = [True for i in range(n)]

    def pop(self,k):
        if self.debug:
            assert self.exist[k]
        L = self._left[k]
        R = self._right[k]
        if L!=-1:
            if R!=self.n:
                self._right[L],self._left[R] = R,L
            else:
                self._right[L] = self.n
        elif R!=self.n:
            self._left[R] = -1
        self.exist[k] = False

    def left(self,idx,k=1):
        if self.debug:
            assert self.exist[idx]
        res = idx
        while k:
            res = self._left[res]
            if res==-1:
                break
            k -= 1
        return res

    def right(self,idx,k=1):
        if self.debug:
            assert self.exist[idx]
        res = idx
        while k:
            res = self._right[res]
            if res==self.n:
                break
            k -= 1
        return res

class SparseTable():
    def __init__(self,A,merge_func,ide_ele):
        N=len(A)
        n=N.bit_length()
        self.table=[[ide_ele for i in range(n)] for i in range(N)]
        self.merge_func=merge_func

        for i in range(N):
            self.table[i][0]=A[i]

        for j in range(1,n):
            for i in range(0,N-2**j+1):
                f=self.table[i][j-1]
                s=self.table[i+2**(j-1)][j-1]
                self.table[i][j]=self.merge_func(f,s)

    def query(self,s,t):
        b=t-s+1
        m=b.bit_length()-1
        return self.merge_func(self.table[s][m],self.table[t-2**m+1][m])

class BinaryTrie:
    class node:
        def __init__(self,val):
            self.left = None
            self.right = None
            self.max = val

    def __init__(self):
        self.root = self.node(-10**15)

    def append(self,key,val):
        pos = self.root
        for i in range(29,-1,-1):
            pos.max = max(pos.max,val)
            if key>>i & 1:
                if pos.right is None:
                    pos.right = self.node(val)
                    pos = pos.right
                else:
                    pos = pos.right
            else:
                if pos.left is None:
                    pos.left = self.node(val)
                    pos = pos.left
                else:
                    pos = pos.left
        pos.max = max(pos.max,val)

    def search(self,M,xor):
        res = -10**15
        pos = self.root
        for i in range(29,-1,-1):
            if pos is None:
                break

            if M>>i & 1:
                if xor>>i & 1:
                    if pos.right:
                        res = max(res,pos.right.max)
                    pos = pos.left
                else:
                    if pos.left:
                        res = max(res,pos.left.max)
                    pos = pos.right
            else:
                if xor>>i & 1:
                    pos = pos.right
                else:
                    pos = pos.left

        if pos:
            res = max(res,pos.max)
        return res

def solveequation(edge,ans,n,m):
    #edge=[[to,dire,id]...]
    x=[0]*m
    used=[False]*n
    for v in range(n):
        if used[v]:
            continue
        y = dfs(v)
        if y!=0:
            return False
    return x

    def dfs(v):
        used[v]=True
        r=ans[v]
        for to,dire,id in edge[v]:
            if used[to]:
                continue
            y=dfs(to)
            if dire==-1:
                x[id]=y
            else:
                x[id]=-y
            r+=y
        return r

class SegmentTree:
    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
        self.size = n
        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):
        if r==self.size:
            r = self.num

        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

    def bisect_l(self,l,r,x):
        l += self.num
        r += self.num
        Lmin = -1
        Rmin = -1
        while l<r:
            if l & 1:
                if self.tree[l] <= x and Lmin==-1:
                    Lmin = l
                l += 1
            if r & 1:
                if self.tree[r-1] <=x:
                    Rmin = r-1
            l >>= 1
            r >>= 1

        if Lmin != -1:
            pos = Lmin
            while pos<self.num:
                if self.tree[2 * pos] <=x:
                    pos = 2 * pos
                else:
                    pos = 2 * pos +1
            return pos-self.num
        elif Rmin != -1:
            pos = Rmin
            while pos<self.num:
                if self.tree[2 * pos] <=x:
                    pos = 2 * pos
                else:
                    pos = 2 * pos +1
            return pos-self.num
        else:
            return -1

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

n,mod = mi()

M = int(n**.5) + 10

dp = [0 for i in range(n+1)]
imos = [0 for i in range(n+1)]
dp[1] = 1
for i in range(1,n):
    imos[i] = (imos[i] + imos[i-1]) % mod
    dp[i] += imos[i]
    dp[i] %= mod

    imos[i+1] += dp[i]
    imos[i+1] %= mod

    for j in range(2,n+1):
        if i*j > n:
            break

        imos[i*j] += dp[i]
        imos[i*j] %= mod
        if (i+1)*j <= n:
            imos[(i+1)*j] -= dp[i]
            imos[(i+1)*j] %= mod

    #print(dp)
    #print(imos)

    #debug = [dp[j] for j in range(n+1)]
    #S = imos[0]
    #for j in range(1,n+1):
        #S = (S + imos[j]) % mod
        #if i<j:
            #debug[j] += S
            #debug[j] %= mod

    #2~3
    #3~5
    #4~7
    #5~
    #print(debug)
    #print()

res = dp[n] + imos[n] + imos[n-1]
res %= mod
print(res)


def solve():
    n, MOD = list(map(int, input().split()))
    dp = [0]*(n+2)
    dp[1] = 1
    dp[2] = -1
    m = 0
    for a in range(1, n+1):
        dp[a] = (dp[a]+2*m%MOD)%MOD
        dp[a+1] = (dp[a+1]-2*m%MOD)%MOD
        m = (m+dp[a])%MOD
        k = 2
        while k*a <= n:
            dp[k*a] = (dp[k*a]+dp[a])%MOD
            c = min(k*a+k, n+1)
            dp[c] = (dp[c]-dp[a])%MOD
            k += 1
    return dp[n]

import sys
input = lambda: sys.stdin.readline().rstrip()
print(solve())


# -*- coding: utf-8 -*-
"""
Created on Tue Aug 30 11:07:14 2022

@author: hp
"""

n,m = map(int,input().split())
sumL = [0]*(n+2)
L = 1
sumL[-2] = 1
for i in range(n-1,0,-1):
    L = sumL[i+1]
    j = 2
    while i*j<=n:
        L+=(sumL[i*j]-sumL[min(n,(i+1)*j-1)+1])
        L%=m
        j+=1
    L %= m
    sumL[i] = (sumL[i+1]+L)
    sumL[i]%=m
print(L)


def is_prime( n ):

    i = 2

    while i * i <= n:

        if n % i == 0:
            return ( False )

        i += 1

    return ( True )

m = {}

p = []

i = 2

while len(p) < 12:

    if is_prime(i):
        p.append(i)

    i += 1

INF = 10**18

m = {}

ans = INF

def f( a, b, div ):

    global ans

    if b >= len(p):
        return

    if div == n:
        ans = min( ans, a )
        return

    for j in range( 1, 60 ):
        if a <= ans//p[b]:
            a *= p[b]
            f( a, b+1, div*(j+1) )
        else:
            break

n = int( input() )

#for i in range( len(p) ):
#    f( p[i], i )
f( 1, 0, 1 )

print( ans )


#!/usr/bin/python

n = int (raw_input())
mod = 1000000007
ans = 1
div = 1
for i in range(1, n):
	ans = (n + i) * ans % mod
	div = i * div % mod
ans = ans * 2 % mod * pow(div, mod - 2, mod) % mod - n
ans %= mod
print ans


n = int(raw_input())
m = 1000000007
res = 1
for i in range(1, n):
    res = (res * (n+i) * pow(i, m-2, m)) % m;
print (2*res-n)%m


#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
from math import factorial

n, m = [int(item) for item in input().split()]
fac = [0] * (n + 1)
fac[0] = 1; fac[1] = 1
for i in range(2, n+1):
    fac[i] = fac[i-1] * i % m
ans = 0
for i in range(1, n+1):
    val = fac[n - i + 1] * (n - i + 1) * fac[i]
    ans += val
    ans %= m
print(ans)


import sys

n, m = list(map(int, sys.stdin.readline().strip().split()))
ans = 0
F = [1] * (n + 1)
for i in range (0, n):
    F[i + 1] = F[i] * (i + 1) % m

for i in range (0, n):
    ans = (ans + (n - i) * (n - i) * F[n - i - 1] * F[i+1]) % m

print(ans)


n, s, k = list(map(int, input().split()))
amounts = list(map(int, input().split()))
colors = list(input())

dp = [[-1 for j in range(k + 1)] for i in range(n)]

def getAns(nth, left):
    if left <= 0:
        return 0
    if dp[nth][left] >= 0:
        return dp[nth][left]

    ret = 999999999
    for i in range(n):
        if amounts[i] <= amounts[nth] or colors[i] == colors[nth]:
            continue
        ret = min(ret, abs(nth - i) + getAns(i, left - amounts[i]))

    dp[nth][left] = ret
    return ret

ans = 999999999
for i in range(n):
    ans = min(ans, getAns(i, k - amounts[i]) + abs(s - 1 - i))
if ans == 999999999:
	ans = -1
print(ans)


import sys

def minp():
	return sys.stdin.readline().strip()

dp = [None]*50
for j in range(50):
	dp[j] = [None]*2001

n,s,k = map(int,minp().split())
a = [None]*n
i = 0
s -= 1
for j in map(int,minp().split()):
	a[i] = (j, i)
	i += 1
i = 0
for j in minp():
	a[i] += ("RGB".find(j),)
	i += 1
a.sort()
r = 10**18
zzz = 0
for i in range(n):
	ii = dp[i]
	c = a[i][0]
	ii[c] = abs(s-a[i][1])
	#print(ii[c])
	for j in range(i):
		if a[j][2] == a[i][2] or a[j][0] == a[i][0]:
			continue
		jj = dp[j]
		for z in range(2001-c):
			zz = jj[z]
			if zz != None:
				d = zz + abs(a[i][1]-a[j][1])
				cc = z+c
				if ii[cc] != None:
					if ii[cc] > d:
						ii[cc] = d
				else:
					ii[cc] = d
	for z in range(k,2001):
		if ii[z] != None:
			r = min(r,ii[z])
	#print(ii[:k+1])
if r != 10**18:
	print(r)
else:
	print(-1)


from math import sqrt
r, h = map(int, input().split())
num = h//r
rem = h % r
ans = num*2
if rem*2 < r:
    ans += 1
elif rem*2 >= sqrt(3) * r:
    ans += 3
else:
    ans += 2
print(ans)


dp = {}

def solve(x):
	if x == 0:
		return 0
	if x in dp.keys():
		return dp[x]
	limit = 1
	cnt = 1
	while limit <= x:
		limit = limit * 10 + 1
		cnt += 1
	prv = limit // 10
	c1 = solve(x % prv) + (x // prv) * (cnt - 1)
	c2 = solve((limit-x) % prv) + cnt + (cnt - 1) * ((limit - x) // prv)
	dp[x] = min(c1,c2)
	return min(c1,c2)

n = int(input())
print(solve(n))


DIGITS = 55
MAX_CNT = 6
NUMBERS = [0] * (DIGITS + 1)
CUTOFFS = [0] * (DIGITS + 1)

for d in range(1, DIGITS + 1):
    NUMBERS[d] = 10 * NUMBERS[d - 1] + 1
    CUTOFFS[d] = 10**(d - 1) * 50 // 81 + 15

INF = 10**9
save = [{} for d in range(DIGITS)]

def recurse(value, d):
    if d == 0:
        return 0 if value == 0 else INF

    if value in save[d]:
        return save[d][value]

    ans = INF

    for cnt in range(0, MAX_CNT + 1):
        nvalue = abs(value - cnt * NUMBERS[d])

        if nvalue <= CUTOFFS[d]:
            ans = min(ans, cnt * d + recurse(nvalue, d - 1))

    save[d][value] = ans
    return ans

X = int(input())
print(recurse(X, len(str(X)) + 1))


mod = int(1e9+7)

def fast_power(base, exp):
    res = 1
    while exp > 0:
        if exp % 2 == 1:
            res = (res * base) % mod
        base = (base * base) % mod
        exp //= 2
    return res

n = int(input())
res = fast_power(2, 2*n-1) + fast_power(2, n-1)
print(1 if n == 0 else res % mod)


#!/usr/bin/env python
n=int(raw_input())
mod=1000000007
print n%(mod-1)==0 and 1 or (pow(2,n-1,mod)+pow(2,2*n-1,mod))%mod


#!/usr/bin/env python
#-*- coding:utf-8 -*-

import sys, math, random, operator

MOD = 10**9 + 7
INF = 10**9

pr = lambda *args: sys.stdout.write(" ".join(str(x) for x in args) + "\n")
epr = lambda *args: sys.stderr.write(" ".join(str(x) for x in args) + "\n")
die = lambda *args: pr(*args) ^ exit(0)

read_str = raw_input
read_int = lambda: int(raw_input())

"---------------------------------------------------------------"

n = read_int()
s = read_str()

num = []
for i in xrange(len(s)):
    num.append([None])
    for j in xrange(i + 1, len(s)+1):
        num[i].append( int(s[i:j], 2) )

needed_for_m = [None]
cur = 0
for x in xrange(1, 1000):
    cur += len(str(bin(x)[2:]))
    needed_for_m.append(cur)

bins = [bin(x)[2:] for x in xrange(0, 1000)]

cache = {}
def solve(state, used, maxm, pos):
    key = state, pos
    if key not in cache:
        res = 0

        # already good?
        # print "(%s)" % bin(state)[2:-1], maxm
        if state == (1 << (maxm + 1)) - 1:
            # print "good"
            res += 1

        # continue cuts
        for add in xrange(1, 100):
            if pos + add > len(s):
                break
            val = num[pos][add]
            if val == 0:
                continue
            if val >= 100:
                break

            used2 = used
            if state & (1 << val) == 0:
                used2 += len(bins[val] if val <= 100 else bin(val)[2:])
            maxm2 = max(maxm, val)
            pos2 = pos + add
            # print "pos", pos, "+", add
            needed = needed_for_m[maxm2] if maxm2 <= 100 else INF
            if needed - used2 <= len(s) - pos2:
                res += solve(state | (1 << val), used2, maxm2, pos2)
        cache[key] = res
    return cache[key]

ans = 0
for i in xrange(len(s)):
    cur = solve(1, 0, 1, i)
    ans += cur
    ans %= MOD
    epr(i, cur, ans)
print ans


rr=raw_input
rrI = lambda: int(rr())
rrM = lambda: map(int,rr().split())
debug=0
if debug:
    fi = open('t.txt','r')
    rr=lambda: fi.readline().replace('\n','')

def good_mask(x):
    if x == 0: return False
    return (x+1) & x == 0

N = rrI()
S = rr()
#N = 75
#from time import time
#S  = '100000111111101000100001011100010111110011111011100011001111101111100011110'
#tt = time()
#print tt

lenbin = [ len(bin(n)) - 2 for n in xrange(32) ]

def solve():
    MOD = 10**9 + 7
    number = [ [0]*(N+1) for _ in xrange(N) ]
    for i in xrange(N):
        for j in xrange(i+1, N+1):
            number[i][j] = min(22, int(S[i:j],2))
    #UPPER = 22
    UPPER = 22
    memo = [ {} for _ in xrange(N+1)]
    def dp(i, mask, sum_to_make = 0, cur_max = 0):
        #Having made a cut already before position i,
        #and having a set of mask taken
        #how many ways?
        if i == N:
            return 1 if sum_to_make == 0 != mask else 0
        if mask in memo[i]: return memo[i][mask]
        ans = 1 if sum_to_make == 0 != mask else 0 #good_mask(mask) else 0
        for j in xrange(i+1, N+1):
            num = number[i][j]
            if num == 0: continue
            if num >= UPPER: break
            if sum_to_make > N-j+5: break
            if (mask >> (num-1))&1:
                ans += dp(j, mask, sum_to_make, cur_max)
            elif num <= cur_max:
                ans += dp(j, mask|(1<<(num-1)), sum_to_make - lenbin[num], cur_max)
            else:
                ans += dp(j, mask|(1<<(num-1)), sum_to_make + sum(lenbin[x] for x in xrange(cur_max + 1, num)), num)

            if ans >= MOD:
                ans %= MOD
        memo[i][mask] = ans
        return ans
    fans = i = 0
    while i < N:
        fans += dp(i, 0)
        fans %= MOD
        i += 1

    print fans
#print time()-tt

if __name__ == "__main__": solve()

"""
def good_mask(x):
    if x == 0: return False
    return (x+1) & x == 0

N = rrI()
S = rr()
##print '.'
#N = 75
#import random
#S = "".join(str(random.randint(0,1)) for _ in xrange(N))
MOD = 10**9 + 7
UPPER = 22

memoslide = {N : 0, N-1:0}
def slide(j):
    if j in memoslide:
        return memoslide[j]
    if S[j] == '1':
        memoslide[j] = 0
        return 0
    else:
        k = j
        while k < len(S) and S[k] == '0':
            k += 1
        memoslide[j] = k - j
        return k - j

memo = {}
def dp(i, mask):
    #Having made a cut already before position i,
    #and having a set of mask taken
    #how many ways?
    if i == N:
        return 1 if good_mask(mask) else 0
    if (i,mask) in memo:
        return memo[i,mask]
    ans = 1 if good_mask(mask) else 0
    for j in xrange(i+1, N+1):
        num = int(S[i:j], 2)
        if num == 0: continue
        if num >= UPPER: break
        if num > 8:
            #prune
            newmask = mask
            ii = excess = 0
            while newmask:
                if newmask%2 == 0:
                    excess += len(bin(ii)) - 2
                ii += 1
                newmask /= 2
            if excess > N-j+1:
                break
        k = slide(j)
        newmask = mask | (1<<(num-1))
        bns = dp(j + k, newmask)
        for kk in xrange(k):
            memo[(j + kk, newmask)] = bns
        ans += (1+k) * bns

        if ans >= MOD:
            ans %= MOD
    memo[i, mask] = ans
    return ans

fans = 0
for i in xrange(N):
    fans += dp(i, 0)
    if fans >= MOD:
        fans %= MOD
print fans
"""


n,m=map(int,raw_input().split())

x,y=n/m,n%m

def ctx(a,b,m):
    if a==0 or b==0:
        return 0
    ct=0
    for i in range(1,a+1):
        for j in range(1,b+1):
            if (i*i+j*j)%m==0:
                ct+=1
    return ct

print x*x*ctx(m,m,m)+2*x*ctx(m,y,m)+ctx(y,y,m)
exit()


from collections import*
n,m=map(int,input().split())
C=lambda k:Counter(i*i%m for i in range(1,k+1))
c,d=C(m),C(n%m)
r=Counter(dict((k,n//m*c[k]+d[k])for k in c))
print(sum(r[k]*r[(m-k)%m]for k in r))


n, m = map(int, input().split())

d = [0 for i in range(7)]
g = [[] for i in range(7)]

for i in range(m):
	x, y = map(int, input().split())
	x -= 1
	y -= 1
	d[x] += 1
	d[y] += 1

	g[x].append(y)
	g[y].append(x)

mn = min(d)
for i in range(7):
	for j in range(i):
		cnt = 0
		for k in range(7):
			if((k in g[i]) and (k in g[j])):
				cnt += 1
		mn = min(mn, cnt)
m -= mn
print(m)


n, m = input().split()
n, m = int(n), int(m)
edges = [[] for x in range(n)]
for i in range(m):
    a, b = input().split()
    a, b = int(a), int(b)
    ma = max(a, b)
    mi = min(a, b)
    edges[mi-1].append((ma-1))
    edges[ma-1].append((mi-1))
# print(edges)
# find lowest degree:

xxx=[]
if n<=6:
    print(m)
else:
    for i in range(n):
        for j in range(i):
            xxx.append(set(edges[i]).intersection(set(edges[j])))
# print(xxx)
    p = [len(z) for z in xxx]
    print(m-min(p))


#!/usr/bin/python3

def is_good(f, p, k):
    for i in range(p):
        if f[(k * i) % p] != (k * f[i]) % p:
            return False
    return True

def gen(f, p, k, i):
    if i == p:
        return is_good(f, p, k)
    else:
        ans = 0
        for j in range(p):
            f.append(j)
            ans += gen(f, p, k, i + 1)
            f.pop()
        return ans

def solve(p, k):
    num = 0
    used = set()
    for j in range(p):
        if j not in used:
            num += 1
        i = j
        while i not in used:
            used.add(i)
            i = (i * k) % p
    return pow(p, num - (k != 1), 10 ** 9 + 7)

p, k = map(int, input().split())
#print(gen([], p, k, 0))
print(solve(p, k))


p,k = map(int,raw_input().split())
M = 1000000007

if k == 0:
    print pow(p, p-1, M)
elif k == 1:
    print pow(p, p, M)
else:
    m = 1
    for i in range(1,p+1):
        m = m * k % p
        if m == 1:
            break
    print pow(p, (p-1)/i, M)


def getinput():
    return map(int, raw_input().split())

def opow(a, b, mod):
    ans = 1
    while b > 0:
        if b % 2 == 1:
            ans *= a
            ans %= mod
        a *= a
        a %= mod
        b /= 2
    return ans

p, k = getinput()
mod = 1000000007
ans = 0
if k == 0:
    ans = opow(p, p - 1, mod)
else:
    for i in xrange(1, p):
        if (p - 1) % i == 0 and opow(k, i, p) == 1:
            ans = opow(p, (p - 1) / i, mod)
            if k == 1:
                ans *= p
                ans %= mod
            break
print ans


MOD=int(1e9+7)
n,k=map(int,input().split())
if k<2:p=n-(1-k)
else:
	t=1
	a=k
	while a!=1:
		a=a*k%n
		t+=1
	p=(n-1)//t
print(pow(n,p,MOD))


mod = 10 ** 9 + 7
p, k = [int(x) for x in input().split()]
if k == 0:
    print(pow(p, p - 1, mod))
elif k == 1:
    print(pow(p, p, mod))
else:
    z = [1]
    while z[-1] * k % p != z[0]:
        z.append(z[-1] * k % p)
    print(pow(p, (p - 1) // len(z), mod))