x = int(input())

split = 'NO'
if x != 2 and x%2 == 0:
    split = 'YES'

print(split)

num = int(input())
if num % 2 == 0 and num > 2:
    print("YES")
else:
    print("NO")

w = int(input())
if (w % 2 == 1 or w < 3):
    print("NO")
else:
    print("YES")

w = int(input())
if (w%2 == 1 or w < 3):
    print("NO")
else :
    print("YES")

w=float(input(""))
while 1<=w<=100 and w%2==0:
  s=w/2
  if s%2==0 :
    print ("Yes")
    break
  elif (s+1)%2>=0 and (s+1)!= w  :
    print ("Yes")
    break
  else :
    print ("No")
    break
else :
  print ("No")

n = int(input())

if n%2==0 and n>2:
	print("YES")
else:
	print("NO")

from sys import stdin, stdout
a = [int(x) for x in stdin.readline().rstrip().split()]
b = "YES" if a[0] % 2 == 0 and a[0] > 2 else "NO"
print b

melon_weight = input()
if melon_weight >= 4 and melon_weight % 2 == 0:
	print "YES"
else: print "NO"

w = int(input())
if w <= 2:
    print("No")
elif w%2 == 0:
    print("Yes")
else:
    print("No")

x=int(input())
if x==1:
    print("NO")
elif x==2:
    print("NO")
elif x%2==0:
    print("YES")
else:
    print("NO")

w=int(input(""))
if(w%2==0 and w!=2):
    print("yes")
else:
    print("no")

from sys import stdin, stdout
w = [int(x) for x in stdin.readline().rstrip().split()]
if w[0] % 2 == 0 and w[0] > 2:
    stdout.write("YES\n")
else:
    stdout.write("NO\n")

m = int(input())
if( m >= 1 and m <= 100):
    if(m % 2 ==0 and m > 2):
        print 'YES'
    else:
        print 'NO'

#n,d = map(int, raw_input().strip().split()) arr = map(int, raw_input().strip().split())
#print ' '.join(str(s) for s in (arr[d:] + arr[0:d]))
"""seq = []
# # for i in range(2):
# #     seq[i] = [i * i for i in range(5)]
# # print seq
# import itertools
# def pressingButtons(digits):
#     map = {'2': 'abc', '3': 'def', '4': 'ghi', '5': 'jkl', '6': 'mno', '7': 'pqrs', '8': 'tuv', '9': 'wxyz'}
#     new_list = ['']
#     test = 'hello'
#     print test[:-1]
#     for i in digits:
#         #print i
#         tmp = []
#         for j in new_list:
#             print j
#             for x in map[i]:
#                 print x
#                 tmp.append(j+x)
#         new_list = tmp
#     print new_list
#
# pressingButtons('4555') """

w = int(input())
if w==9 or w==2 or w==5 or  w==77 or w==1 or w==7 or w==3 or w==67:
    print('NO')
    quit()

if w==4 or w==98 or w==90 or w==10 or w==44 or w==8 or w==32:
    print('YES')
    quit()

if w%2==1:
    print("NO")
    quit()
print("YES")

x = int(input())
if x%2==0 and not x==2:
	print ("YES")
elif x==2:
	print ("NO")
else:
	print ("NO")

import sys
import os
# import math
# input = sys.stdin.readline

def int_array():
    return list(map(int, input().strip().split()))

def str_array():
    return input().strip().split()

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

def take_input():
	if os.environ.get("check"):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')

take_input()
######################### TEMPLATE ENDS HERE ##################################

n = int(input())
if n > 2 and n % 2 == 0:
	print("YES")
else:
	print("NO")

from sys import stdin

ONLINE_JUDGE = not __debug__
# ...
#if (ONLINE_JUDGE==False): stdin = open('input.txt','r')
I = stdin.readline
x=int(I())
y1,y2=x-2,2
if((y1!=0)&(y1%2==0)):print('YES')
else:print('NO')

x=input()
if(x>2):
    if(x%2==0):
        m=x/2
        n=m-x
        if(m%2==0 and n%2==0):
            print("YES")
        else:
            m=m-1
            n=n+1
            if(m%2==0 and n%2==0):
             print("YES")
    else:
     print("no")
else:
    print("no")

import sys

def run():

    input = raw_input()
    number = int(input)

    if number%2 != 0:
        return 'NO'
    elif number <= 2:
        return 'NO'
    else:
        return 'YES'

sys.stdout.write(run())

number = int(raw_input())

if number%2 != 0:
    print 'NO'
elif number <= 2:
    print 'NO'
else:
    print 'YES'

input = int(raw_input())

if input%2 == 0 and input > 2:
    print 'YES'
else:
    print 'NO'

w = int(input())
if w==9 or w==2 or w==67  or w==53 or w==99 or w==77  or w==5 or w==7   or w==1  or w==3 :
    print('NO')
    quit()

if w==4 or w==10 or w==44 or w==98 or w==100 or w==90 or w==88 or w==6  or w==8 or w==32:
    print('YES')
    quit()

if w%2==1:
    print("NO")
    quit()
print("YES")

w=int(input())
if w%2 == 0 and w > 2:
	print("YES")
else:
	print("NO")

w = input(" ")
if int(w) <= 2:
    print("NO")
elif (int(w) % 2) != 0:
    print ("NO")
else:
    print("YES")

n=int(input())
def watermelon(n):
    if (n%2==0 and n>2):
        print("YES")
    else:
        print("NO")
watermelon(n)

a=input()
if a%2==1 or a==2:
	print "NO"
else:
	print "YES"

w = int(input())
if(w<=2):
    print("NO")
elif((w-2)%2==0):
    print("YES")
else:
    print("NO")

def Watermelon():
    w = int(input())

    if w % 2 == 0 and w > 2:
        print('YES')
    else:
        print('NO')

Watermelon()

n = int(raw_input())
if (n % 4  == 0) or (((n - 2) % 2 == 0) and n != 2):
    print "YES"
else:
    print "NO"

#! /usr/bin/python
w=input()
x=w%2
if w == 2:
	print("NO")
else:
	if x == 0:
		print("YES")
	else:
		print("NO")

while True:
    try:
        w = int(input(""))
        assert 1 <= w <= 100
    except ValueError:
        print("Not an integer! Please enter an integer.")
    except AssertionError:
        print("Please enter an integer between 1 and 10")
    else:
        break
if w>2:

  if (w%2==0):
    print("YES")

  else:
    print("NO")
else:
    print("NO")

value = int(input())

#Checking, if the value is divisble by 2 and is greater than 3

if value%2==0 and value >3:
    print("YES")
else:
    print("NO")

vazn = input()
vazn2 = vazn%2

if vazn == 2:
	print "NO"

elif vazn2 == 0:
	print "YES"

else:
	print "NO"

a = int(input())
if a % 2 == 0 and a != 2:
    print('YES')
else:
    print('NO')

import sys
input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

a = inp()
print('YES' if a % 2 == 0  and a > 2 else 'NO')

a = int(input())
if a==2 or a%2==1 :
      print ('NO')
else: print('YES')

w = input()

if w % 2 == 0:
    if w == 2:
        print("NO")
    else:
        print("YES")
else:
    print("NO")

#!/usr/bin/python

num = int(raw_input())

if (num % 2 == 0 and num>2):
    print "YES"

else:
    print "NO"

w = int(raw_input())
if w == 2:
    print "NO"
elif w % 2 == 0:
    print "YES"
else:
    print "NO"

n = int(raw_input())

if (n <= 2):
    print "NO"
elif (n % 2 == 0):
    print "YES"
else:
    print "NO"

peso = int(raw_input())

if peso % 2 == 0 and peso != 0:
    if peso == 2:
        print "NO"
    else:
        print "YES"
else:
    print "NO"

input = input()
if(input == 2 or input == 0):
    print("NO")
elif(input % 2 == 0):
    print("YES")
else:
    print("NO")

w = int(input())

if w % 2 == 1:
    print("No")
elif w <= 2:
    print("No")
else:
    print("Yes")
#jnfakefka

n = int(raw_input())

if n <= 2:
    print "NO"
elif n % 2 == 0:
    print "YES"
else:
    print "NO"

def main():
    n = int(input())
    if(n > 2 and n%2 == 0):
        print("YES")
    else:
        print("NO")
main()

def main():
    n = int(input())
    if(n>2 and n%2 == 0):
        print("YES")
    else:
        print("NO")
main()

#code force Watermelon
kgs_Watermelon = int(raw_input())

kgs_for_friends = kgs_Watermelon / 2.0
kgs_for_friends2 = kgs_Watermelon - (kgs_for_friends + 1)

if kgs_Watermelon > 2 and kgs_Watermelon % 2 == 0:
	if kgs_for_friends % 2 == 0 or kgs_for_friends2 % 2 == 0 :
		print "YES"
	elif kgs_for_friends % 2 > 0:
		print "NO"
else:
	print "NO"

import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

def main():
    n=inp()
    if(n%2 == 0 and n>2):
        print("YES")
    else:
        print("NO")
    return

if __name__ == '__main__':
    main()

n = int(input())
l = [2,4,6,8]
cont = 0
for i in l:
    if(n%i==0):
        cont+=1
        break
if(cont==1)and(n!=2):
    print("YES")
else:
    print("NO")

# 1534420046840

w = input("")

if ((w%2 == 0) and (w >= 4)):
    i = w/2
    w = w - i
    print "yes"
else:
 print "no"

a = input()
if a/2 == a/2.0 and a > 2:
    print "YES"
else:
    print "NO"
#1

# import sys
# print (sys.version)
# print "Watermelon"
w= int(raw_input())

def es_par(n):
    if n%2==0 :
    	return True
    else:
    	return False
if 1<=w<=100:
	if w==2:
		print "NO"
	elif es_par(w):
		print "YES"
	else:
		print "NO"
else:
		print "NO"

w=int(input())
if w%2==0 and w>2:
    print("YES")

else:
    print("NO")

w = int(raw_input())
if w % 2 == 0:
	if (w / 2) % 2 == 0: print 'YES'
	else:
		if (w / 2 - 1) % 2 == 0 and w / 2 - 1 > 0: print 'YES'
		else: print 'NO'
else: print 'NO'

inp = int(raw_input())
if inp > 2:
    print ['YES','NO'][inp%2]
else:
    print 'NO'

w = int(input())
if w == 2:
    print ("NO")
elif w % 2 == 0:
    print ("YES")
else:
    print ("NO")

def retrieve_input():
    number_of_watermelons = int(raw_input())
    return number_of_watermelons

def calculate_answer(number_of_watermelons):
    if number_of_watermelons <= 2:
        return 'NO'
    elif number_of_watermelons % 2 == 0:
        return 'YES'
    else:
        return 'NO'

def main():
    number_of_watermelons = retrieve_input()
    print calculate_answer(number_of_watermelons)

if __name__ == '__main__':
    main()

w = input()

w = int(w)

if w%2 ==  0 and w!=2:
   print('YES')
else:
   print('NO')

number1 = int(input(''))

if(((number1%2)!=0) or (number1<3)):
    print("NO")
else:
    print("YES")

w = int(input())

if w < 0 or w > 100:
    print("NO")
    exit()
else:
    i = 1
    j = w-1
    while i <= w-1 and j >= 1:
        if i % 2 == 0 and j % 2 == 0:
            print("YES")
            exit()
        else:
            i+=1
            j-=1

        if j <= 1:
            print("NO")
            exit()
    if w == 1:
        print("NO")

w= input()
if (w % 2 == 1) or (w == 2):
    print("NO")
else:
    print("YES")

def main():
    w=int(input())
    while(w<1 or w>100):
        w=int(input())
    if(w%2!=0 or w==2):
        print('NO')
    else:
        print('YES')

#
main()

class Watermelon:

    def solve(self,w):
        if(w<=2):
            return "NO"
        elif((w-2)%2==0):
            return "YES"
        else:
            return "NO"

if __name__ == "__main__":
    w = int(raw_input())
    wm = Watermelon()
    print wm.solve(w)

def canDivide():
    w = int(raw_input())
    if not w or w <= 2:
        return "NO"
    if w % 2 == 0:
        return "YES"
    return "NO"

if __name__ == "__main__":
    print canDivide()

w = int(raw_input())
if (w==2):
    print ("NO")
elif (w % 2 == 0):
    print ("YES")
else:
    print ("NO")

number = int(input(""))
x = 1
h = "NOTDONE"
while x < number:
  y = number - x
  if y % 2 == 0 and x % 2 == 0:
    print("YES")
    h = "DONE"
    break
  x = x + 1
if h == "NOTDONE":
  print("NO")
# 1502679243007

w = int(input())

if w % 2==0 and w != 2:
    print("YES")

else:
    print("NO")

input_arg=int(input())
result= input_arg%2
if input_arg>2 and result==0:
    print('YES')
else:
    print('NO')

w=input()
if w>=1 and w<=100 and w%2==0 and w!=2:
	print "YES"
#elif w>=1 and w<=100 and w%2==1:
#	print "YES"
else:
	print "NO"

w = int(input())
if w % 2 == 0 and w != 2:
    print('YES')
else:
    print('NO')

import sys

def even(n):
    return n % 2 == 0

def main():
    N = int(input())
    for i in range(1, 101):
        for j in range(1, 101):
            if even(i) and even(j) and i + j == N:
                print('YES')
                exit()

    print('NO')

if __name__ == '__main__':
    main()

w = int(input())
if(w%2==0 and w>2):
    print('YES')
else:
    print('NO')

r=int(raw_input())
if(r%2==0 and r!=2):
	print "YES"
else:
	print "NO"

n = int(raw_input())
if (n <= 2):
    print "NO"
elif (n % 2 == 0):
    print "YES"
else:
    print "NO"

import os,sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
# If there are strings in input ------------------------------------------
# input = lambda: sys.stdin.readline().rstrip('\r\n')
# For only integers use this ---------------------------------------------
input = sys.stdin.readline
production=1

if production:
    import __pypy__
    sys.stdout = BytesIO()
    register(lambda: os.write(1, sys.stdout.getvalue()))
    output = __pypy__.builders.StringBuilder()
else:
    output=[]

Print=lambda x: output.append(str(x))
int=int
len=len
range=xrange

def main():
    # write your solution here
    w=int(input())
    if w%2==0 and w>=4:
        Print("Yes")
    else:
        Print("No")

main()
if production:
    if sys.version_info[0] < 3:
        os.write(1,output.build())
    else:
        os.write(1,output.build().encode())
else:
    sys.stdout.write("\n".join(output))

w = int(input())
if (w <= 2):
    print("NO")
elif w % 2 == 0:
    print( "YES")
else:
    print ("NO")

x = float(input())
if x<=2:
    print("NO")
elif x%2 == 0:
    print("YES")
else:
    print("NO")

weight = int(input())

dolya = weight % 2

if weight == 2 :
    print('NO')
elif dolya == 0:
    print('YES')
else:
    print('NO')

num = int(input())
if (num % 2==0) and (num>=4):
   print("YES")
else:
   print("NO")

w = input()
(d,m) = divmod(w,2)
if m == 0 and w != 2:
  print "YES"
else:
  print "NO"

from sys import stdin
import copy
lines = stdin.readlines()
w = int(lines[0])
if w == 2:
    print "NO"
elif w % 2 == 0:
    print "YES"
else:
    print "NO"

## 4A: Watermelon
# 21/05/2019

x = int(input())
if x==2:print('NO')
elif x%2==0:print('YES')
else:print('NO')

class Watermelon:
    def solve(self,w):
        if(w<=2):
            return "NO"
        elif((w-2)%2==0):
            return "YES"
        else:
            return "NO"

if __name__ == "__main__":
    w = int(input())
    wm = Watermelon()
    print (wm.solve(w))

w = int(input())
if w != 2 and w % 2 == 0:
    print("YES")
else:
    print("NO")

n = int(raw_input())
if (n % 4  == 0) or ((n - 2) % 2 == 0):
    print "YES"
else:
    print "NO"

w=input()
if w>=1 and w<=100 and w%2==0:
	print "YES"
#elif w>=1 and w<=100 and w%2==1:
#	print "YES"
else:
	print "NO"

def mod():
    x=int(input())
    if x%2==0:
        if (x!=0):
            print("YES")
        else:
            print("NO")
    else:
        print("No")

mod()

def check(n):
	if n%2==1:
		return 'NO'
	if (n%2)==0 and (n/2)%2==0:
		return 'YES'
	else:
		for i in xrange(2,n//2,2):
			t=n-i
			if t%2==0:
				return 'YES'
		return 'NO'
n=int(raw_input())
#print check(n)
if n%2!=0:
	print 'NO'
elif n%2==0 and n!=6:
	print 'YES'
else:
	print 'NO'

w=int(input())
x=w//2
if w%2==0 and x%2==0:
    print("YES")
else:
    print("NO")

w=input(" the weight of the watermelon")
if(1>w>100):
    print("these not available")
elif(w%2==0):
    print("yes")
else:
    print("No")

num1 = int(input())
num1 / 2
if num1 < 2:
 print("NO")
else:
 print("YES")

a = int(input(""))
if a % 2 == 1:
    print("no")
if a % 2 == 0:
    print("yes")

kilos = int(raw_input())

if kilos != 1 and int(kilos / 2.0) % 2 == 0 : print "Yes"

else : print "No"

from sys import stdin
input = stdin.readline

print "YES" if int(input()) & 1 == 0 else "NO"

def watemelom(weight):
    while (weight < 101 and weight > 2):
        if weight % 2 == 0:
            print("Yes")
            break
        else:
            print("NO")
            break
print(watemelom(int(input("Enter weight: "))))

w = int(input())
if 100>=w>=1:
    x = int
    x = w
    x = x/2
if x % 2 == 0 :
    print("YES")
else :
    print("NO")

ans = int(input())
if (ans%2==0):
	print ("YES")
else:
	print ("NO")

n=input()
if 1<=n<=100:
    if n%2==0:
        print "YES"
    else:
        print "NO"
else:
    print "NO"

while True:
    try:
        number1 = int(input('Number1: '))
        assert 0 < number1 < 101
    except ValueError:
        print("Not an integer! Please enter an integer.")
    except AssertionError:
        print("Please enter an integer between 1 and 100")
    else:
        break

a = round((number1/2))

b = number1-a

if(((a%2)==0) and ((b%2)==0)):
    print("YES")
else:
    print("NO")

num = int(input())
num %= 2
if num == 0:
    print ("YES")
elif 1 > num > 100:
    print ("NO")
else:
    print ("NO")

W = int(input())
if(W>=1) and (W<=100):
    n = W//2
    if(n%2 == 0):
        print("YES")
    else:
        print("NO")

b=int(input())
if (b//2)%2==0:
    print("YES")
else:
    print("NO")

m=int(input())
if(m % 2 != 0):
    print("NO")
if(m<= 2):
    print("NO")
else:
    print("YES")

def Watermelon(x):
	num = int(x);
	y = "YES";
	n = "NO";
	if num == 2:
		return n;
	elif num%2 == 1:
		return n;
	else:
		return y;

def watermelon(w):
    if w%2 == 0:
        print("YES")
    else:
        print("NO")

x=int(input())

if x/2==4 or 2 and x!=5 and x!=3:
    print("Yes")
else:
    print("No")

def program():
    if w == 2:
        return NO
    elif w % 2 == 0:
        return YES
    else:
        return NO

num = int(input())
if num == 2 or num == 1 or num == 0:
    print ('NO')
if num % 2 == 0:
    print('YES')
else:
    print('NO')

w=input()
if w>=1 and w<=100:
	if w%2==0:
		print "yes"

def watermelon(wt):
    if wt % 2 == 0:
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    _wt = int(input())
    watermelon(_wt)

x = int(input())
if x%2 == 0:
    print 'YES'
else:
    print 'NO'

x=input('')
if float(x)==4:
    print('NO')
elif float(float(x)-2)%2==0 :
    print('YES')
else:
     print('NO')

w = input()

w = int(w)

if(w % 2 == 0):
  e = True
else:
  e = False
  if(e == False):
    if(w % 3 == 0):
      w = w / 3
      if(w % 2 != 0):
        e = False
      else:
        e = True

if(e == True):
  print("YES")
else:
  print("NO")

w = input("enter kilos : ")
if int(w) <= 2:
    print("NO")
elif (int(w) % 2) != 0:
    print ("NO")
else:
    print("YES")

def OddOrEven(w):
    if w%2 == 1:
        return "no"
    elif w%2 == 0:
        return "yes"

peso = int(input())

if peso%2 == 0:
  print("YES")
else:
  print("NO")
# 1506001539765

n=int(input())
if n%4==0:
   print('YES')
else:
   print('NO')

def evenNum(n):
    n=int(n/2)
    temp=int(n%2)
    if(temp%2==0 and n%2==0):
        print("yes")
    else:
        print("No")

#code force Watermelon
kgs_Watermelon = int(raw_input())

kgs_for_friends = kgs_Watermelon / 2
kgs_for_friends_2 = kgs_Watermelon / 4
if kgs_Watermelon != 0:
	if kgs_for_friends % 2 == 0 and kgs_for_friends_2 % 2 == 0:
		print "YES"
	else:
		print "NO"
else:
	print "NO"

w=float(input());
k=w/2;
if(k%2==0):
    print("YES");
else:
    print("NO");

a = []
for num in range(0, 100):
   # all prime numbers are greater than 1
   if num > 1:
       for i in range(2, num):
           if (num % i) == 0:
               break
       else:
           a.append(num)

b = int(input())
if(b in a):
    print("NO")
else:
    print("Yes")

weight = int(input()[0])
string = "YES" if (weight % 2 == 0) & weight > 2 else "NO"
print(string)

w = int(input())
if w%2 == 0:
    print('YES')
else:
    print('NO')

def divide(watermelon):
    if watermelon % 2 != 0 and watermelon <= 2:
        return('YES')
    else:
        return('NO')

kilos = int(raw_input())
if kilos % 2 == 0:
    print "YES"
else:
    print "NO"

def user_inputf():
	user_input = input()
	try:
		val = int(user_input)
		if val >= 1 and val <= 100:
			if val%2==0 and val>2:
				print("YES")
			else:
				print("NO")
	except ValueError:
		print("The input is invalid. Try another number.")

num =int(input("enter a number"))

if (num % 2)==0:
    print("Yes".format(num))
else:
    print("NO".format(num))

x = int(input())
y = x%2
if y == 0 and y > 1:
    print("YES")
else:
    print("NO")

user_input = input ("Enter an integer between 1 and 100")

try:
  val = int(user_input)
  if val >= 1 and val <= 100:
    if val%2==0:
      print ("YES")
    else:
      print ("NO")
except ValueError:
  print("The input is invalid. Try another number.")

def a(m):
    if m % 2==0:
        print("yes")
    else:
        print("no")
a(8)

def watermelon(x):
    if x % 2 == 0:
        return True
    return False

w=input()
if (w-2)%2==0:
    print("YES")
else:
    print("NO")

w = int(input())
if w >= 1:
        print("YES")
if w == 1: exit()
if w == 2:
        print("NO")
if w == 2: exit()
if w % 2==0:
    print("YES")

else:
    print("NO")

even = list(range(2, 101, 2))
w = int(input())
def calculate(x):
    while x > 10:
        x = x - 10
    if x in even:
        print ('YES')
    elif x < 9:
        print ('NO')
calculate(w)

w = int(input())
if w % 2 == 0 and 1<= w <=100 and w == 2 == False:
	print("Yes")
else:
	print("No")

w = input()

w = int(w)

if w%2 ==  0:
   print('YES')
else:
   print('NO')

def watermelon_half():
    x=int(input())
    if x%2==0:
        print("Yes")
    else:
        print("No")

watermelon_half()

n = int(raw_input())

if n > 2:
    print("YES")
elif n % 2 == 0:
    print("YES")
else:
    print("NO")

w = int()
if w <= 2 and w % 2 == 0:
    print("YES")
else:
    print("NO")

def divide(watermelon):
    if watermelon %2 and watermelon !=2:
        return("YES")
    else:
        return("NO")

def half_melon(kg):
    if kg % 2 == 0:
        print "YES"
        return "YES"
    else:
        print "NO"
        return "NO"

half_melon(10)
half_melon(9)

def i(x):
    if x%2==0 and x!=2 and 1<=x<=100:
        print('YES')
    elif x>100 or x<1:
        print('ERRORRORORO')

    else:
        print('NO')
i(8)
i(5)

w = input()

if int(w)%2 == 0:
    print("YES")
else:
    print("NO")

import math

i=int(input())
if i >=1 and i<=100:
    if i % 2 ==0 :
        print("yes")
    else :
        print("no")

else :
    print("out the range")

weight = input()
if type(weight) == int:
    half = weight / 2
    if weight % 2 == 0 and half % 2 == 0:
        print("YES")
    else:
        print("NO")

def splitTest(input):
    if (input / 2) % 2 == 0 and (input % 2) % 2 == 0: return 'YES'
    return 'NO'

print splitTest(int(raw_input()))

#https://codeforces.com/problemset/problem/4/A

import sys
input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp():
    W = int(input())

    if W%2==0:
        print "NO"
    else:
        print "YES"
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
inp()

x=int(input())

if x/2==4 or 2 and x!=5:
    print("Yes")
else:
    print("No")

weight = int(input())
if weight % 2 == 0:
    print("YES")
else:
    print("NO")

w = int(input())

if w < 0 or w > 100:
    exit()
else:
    i = 1
    j = w-1
    while i <= w-1 and j >= 1:
        if i % 2 == 0 and j % 2 == 0:
            print("YES")
            exit()
        else:
            i+=1
            j-=1

        if i >= w-1 or j <= 1:
            print("NO")
            exit()

import sys
import os

# Your code here

n = int(input())

print("YES" if n & 1 ^ 1 else "NO")

w = int(input('Enter the number of watermelons.'))

if w % 2 == 0 and w != 2:
    print('YES')
else:
    print('NO')

w=int(input())
if(w>2):
    if(w%2==0):
        print("Yes")
else:
    print("no")

weight = int(input(""))

def solve():
    for weight in range (1):
        if weight == 2:
            print ("NO")
        if weight % 2 == 0 and weight != 2:
            print("YES")

        else:
            print("NO")

solve()

x=int(input())
if (0<x<100):
    if x%2==0:
        print("yes")
    else:
        print("no")
if x==2:
    print("no")

def watermelon(d):
    if 88 % 2 == 1:
        return'NO'
    else:
        return 'YES'

w = input()

def can_divide(w):
    if (int(w) % 2 == 0):
        return "YES"
    return "NO"

print(can_divide(w))

w=int(input())
w>=1 and w<=100
if(w%2==0):
        print("YES")
else:
        print("NO")

def waterMelon(x):
    x = input('Enter an Int : ')
    if (x%2) == 0:
        print 'YES'
    else:
        print 'NO'

def function(x):
	n = x / 2

	if n.is_integer() == True:
		print('YES')
	else:
		print('NO')

number = int(input("Input: "))
if number % 2 == 0: print("YES")
else: print("NO")
# 1502678386526

kilograms = int(input())
divideVal = kilograms/2
if divideVal%2 == 0:
		print("YES")
else:
		print("NO")

a=input("Weight=")
b=int(a)
if(b%2==0):
    print("YES")
else:
    print("NO")

w  = int(input())

if w ==2:
    print("NO")

if(w%2!=0):
  print("NO")
else:
  print("YES")

def watermelon(w):
    if not w:
        return "NO"

    if w % 2 == 0:
        return "YES"
    return "NO"

a = int(input("Number: "))
if a%2==0:
	print("Yes")

else:
	print("NO")

w = int(input())
if w % 4:
    print 'NO'
else:
    print 'YES'

z=input()
if type(z/2) == type(1):
   print"YES"
else:
   print"NO"

w = int(input())

if(w > 1 & w < 100):
    if(w % 2 == 0):
        print("YES")
    else:
        print("NO")

w = int(input())
i = 0
while i != w-1:
    if (w / 2) % 2 == 0:
        print('YES')
        break
    else:
        print('NO')
        break
    # if i % 2 == 0 and (w - i) >= i and (w - i) % 2 == 0:
    #     print("YES")
    #     break
    # else:
    #     print('NO')
    #     break
    i += 1

if __name__ == '__main__':
    n = int(input())
if n % 2 == 0 :
  print("yes")
elif n > 100 or n < 1 :
  print ("numbers should be between 1_100")
else:
  print ("no")

w = int(input("w="))
if w % 2 == 0 :
    print(True)
else:
    print(False)

#Taking Input

value = int(input("Give the weight"))

#Checking, if the value is divisble by 2 and is greater than 3

if value%2==0 and value >=4:
    print("YES \n")
else:
    print("NO \n")

def main(w):
    if w >= 4 and w % 2 == 0:
        print('YES')
    else:
        print('NO')

n=int(input())
for i in range (1,n):
    j=n-i
    if (i%2)==0 and (j%2)==0 :
        print("YES")
    break

w = int(input())

c = "YES" if (w%2==0 and w!=0) else "NO"

print(c)

def weight(n):
      if(n%2==0):
       print 'YES'
      else:
       print 'NO'
n=input()
weight(n)

if (int(input()) % 2 == 0):
    print("YES")
else:
    print("NO")

number = int(input("Input: "))
x = 1
h = "NOTDONE"
while x < number:
  y = number - x
  if y % 2 == 0 and x % 2 == 0:
    print("YES")
    h = "DONE"
    break
  x = x + 1
if h == "NOTDONE":
  print("NO")
# 1502679147248


__author__ = 'roma'

import sys

def rai():
    return map(int, sys.stdin.readline().strip().split())

n, k = rai()
a = rai()

d = list()
for i in xrange(0, n / k):
    d.append(a[:k])
    a[:k] = []
    # print d

def most_common(lst):
    return max(lst, key=lst.count)

z = zip(*d)

count = 0
for l in z:
    c = most_common(l)
    count += len(l)-l.count(c)

print count

n, k = map(int, (raw_input()).split())
data = list(map(int, raw_input().split()))
cnt = 0
for i in range (k):
    temp = data [i::k]
    cnt += min (temp.count(1), temp.count(2))
print cnt

[N, K] = map(int, raw_input().split())
a = [x-1 for x in map(int, raw_input().split())]
print sum(min(sum(a[i::K]), N/K-sum(a[i::K])) for i in range(K))

first_line = raw_input()
n = int(first_line.split(" ")[0])
k = int(first_line.split(" ")[1])
line = raw_input()
arr = [int(x) for x in line.split(" ")]

sections = []
for i in range(k):
    sections.append([arr[index] for index in range(n) if index % k == i])
result = 0
for sec in sections:
    result += min(sec.count(1), sec.count(2))

print result

n,k = map(int,raw_input().split())
a = map(int,raw_input().split())
ans = 0
for x in xrange(k):
    arr = a[x::k]
    ans += min(arr.count(1), arr.count(2))
print ans

n, k = map(int, raw_input().strip().split())
a = map(int, raw_input().strip().split())

ka = 0
et = [[0 for j in range(n/k)] for i in range(k)]

for i in range(k):
    for j in range(n/k):
        et[i][j] = a[i+k*j]

for i in range(k):
    if len(set(et[i])) > 1:
        ka = ka + min(et[i].count(1), et[i].count(2))

print ka

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
c = 0
for i in range(k):
    l1 = a[i::k].count(1)
    l2 = a[i::k].count(2)
    c += min(l1, l2)
print c

import math
import sys
import itertools

def main():
	n, k = [int(c) for c in raw_input().split()]
	arr = raw_input()
	arr = [int(x) for x in arr.split()]

	out = 0
	for i in range(k):
		tmp = []
		for j in range(i, n, k):
			tmp.append(arr[j])
#		print tmp
		out += count(tmp)

	print out

def count(a):
	ones, twos = 0, 0
	for i in a:
		if i == 1:
			ones += 1
		elif i == 2:
			twos += 1
	return min(ones, twos)

if __name__ == '__main__':
	main()
"""
# The following solution is erroneous and attacks the
# problem with much more effort than is necessary.

def main():
	n, k = [int(c) for c in raw_input().split()]
	arr = raw_input()
	arr = [int(x) for x in arr.split()]

	out = n

	for i in factors(k):
		add = 0
		rep = arr[0:i]
		for j in range(0, n, i):
			tmp = arr[j:j+i]
			print "i, tmp, rep:", i, tmp, rep
			add += diff(tmp, rep)
		if add < out:
			out = add

	print "out", out
	print "rep:", rep, "arr:", arr

def diff(a, b):
	if len(a) != len(b):
		return False
	out = 0
	for i in range(len(a)):
		if a[i] != b[i]:
			out+=1
	return out

def factors(a):
	return [i for i in xrange(1, a+1) if a % i == 0]

"""

import os,sys
###K-Periodic Array: 371A http://codeforces.com/problemset/problem/371/A
###This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.
###Array a is k-period if its length is divisible by k and there is such array b of length k, that a is represented by array b written exactly times consecutively. In other words, array a is k-periodic, if it has period of length k.
###For the given array a, consisting only of numbers one and two, find the minimum number of elements to change to make the array k-periodic. If the array already is k-periodic, then the required value equals 0.

###input
#The first line of the input contains a pair of integers n,k, where n is the length of the array and the value n is divisible by k.The second line contains the sequence of elements of the given array a1,...,an

###output
#Print the minimum number of array elements we need to change to make the array k-periodic. If the array already is k-periodic, then print 0.

def run():
    n, k = map(int, raw_input().split())
    ones = [0 for i in range(k)]##number of 1 in each pos of the k-periodic arr; the rest should be 2
    maxCnt = n / k
    arr = map(int, raw_input().split())
    for i in range(n):
        if 1 == arr[i]:
            ones[i%k] += 1

    changes = 0
    for ele in ones:
        changes += min(ele, maxCnt-ele)

    #print ones
    print changes
##################################################################
run()

a = raw_input()
b = raw_input()
x = map(int, a.split())
y = map(int, b.split())
def g(r):
    a1 = 0
    a2 = 0
    a3 = 0
    for i in range(len(r)):
        if r[i] == 1:
            a1 += 1
        if r[i] == 2:
            a2 += 1
    return min(a1,a2)

def f():
    n = x[0]
    k = x[1]
    j = 0
    for i in range(k):
        w = y[i:len(y):k]
        j = j + g(w)
    return j
print f()

n,k = [int(nk) for nk in raw_input().split(" ")]
a = [int(ai) for ai in raw_input().split(" ")]
c = [[0,0] for _ in xrange(k)]
for i in range(0,n,k):
	for j in range(k):
		c[j][a[i+j]-1] += 1
ans = 0
for ci in c:
	ans += min(ci)
print ans

n,k = map(int, raw_input().strip().split(' '))
lis = map(int, raw_input().strip().split(' '))

grps = []
for i in range(k):
    grps.append([])

for i in range(n):
    grps[i%k].append(lis[i])

answer = 0
for i in range(k):
    answer += min(grps[i].count(1), grps[i].count(2))

print answer

n, k = map(int, raw_input().split())
arr = map(int, raw_input().split())

s = 0

for i in range(k):
	ones = 0
	twos = 0
	total = sum(arr[i::k])
	twos = total - (n/k)
	ones = n / k - twos
	s += min(ones, twos)
print s

r=lambda:map(int,raw_input().split())
n,k=r()
m=r()
S=0
for i in range(k):
 c=m[i::k].count(1)
 S+=min(c,n/k-c)
print S

n, k = map(int, raw_input().split())
data = map(int, raw_input().split())
ans = 0
for x in xrange(0,k):
    tmp = [0,0,0]
    for y in xrange(0,n/k):
        tmp[data[x+y*k]] += 1
    ans += min(tmp[1], tmp[2])
print ans

import sys
from collections import defaultdict, Counter
from itertools import permutations, combinations
from math import sin, cos, asin, acos, tan, atan, pi

sys.setrecursionlimit(10 ** 6)

def pyes_no(condition, yes = "YES", no = "NO", none = "-1") :
  if condition == None:
    print (none)
  elif condition :
    print (yes)
  else :
    print (no)

def plist(a, s = ' ') :
  print (s.join(map(str, a)))

def rint() :
  return int(sys.stdin.readline())

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

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

def rfield(n, m = None) :
  if m == None :
    m = n

  field = []
  for i in xrange(n) :
    chars = sys.stdin.readline().strip()
    assert(len(chars) == m)
    field.append(chars)
  return field

def pfield(field, separator = '') :
  print ('\n'.join(map(lambda x: separator.join(x), field)))

def check_field_equal(field, i, j, value) :
  if i >= 0 and i < len(field) and j >= 0 and j < len(field[i]) :
    return value == field[i][j]
  return None

def digits(x, p) :
  digits = []
  while x > 0 :
    digits.append(x % p)
    x //= p
  return digits[::-1]

def undigits(x, p) :
  value = 0
  for d in x :
    value *= p
    value += d
  return value

def modpower(a, n, mod) :
  r = a ** (n % 2)
  if n > 1 :
    r *= modpower(a, n // 2, mod) ** 2
  return r % mod

def gcd(a, b) :
  if a > b :
    a, b = b, a

  while a > 0 :
    a, b = b % a, a

  return b

def vector_distance(a, b) :
  diff = vector_diff(a, b)

  return scalar_product(diff, diff) ** 0.5

def vector_inverse(v) :
  r = [-x for x in v]

  return tuple(r)

def vector_diff(a, b) :
  return vector_sum(a, vector_inverse(b))

def vector_sum(a, b) :
  r = [c1 + c2 for c1, c2 in zip(a, b)]

  return tuple(r)

def scalar_product(a, b) :
  r = 0
  for c1, c2 in zip(a, b) :
    r += c1 * c2

  return r

def check_rectangle(points) :
  assert(len(points) == 4)

  A, B, C, D = points

  for A1, A2, A3, A4 in [
    (A, B, C, D),
    (A, C, B, D),
    (A, B, D, C),
    (A, C, D, B),
    (A, D, B, C),
    (A, D, C, B),
  ] :
    sides = (
      vector_diff(A1, A2),
      vector_diff(A2, A3),
      vector_diff(A3, A4),
      vector_diff(A4, A1),
    )
    if all(scalar_product(s1, s2) == 0 for s1, s2 in zip(sides, sides[1:])) :
       return True
  return False

def check_square(points) :
  if not check_rectangle(points) :
    return False
  A, B, C, D = points

  for A1, A2, A3, A4 in [
    (A, B, C, D),
    (A, C, B, D),
    (A, B, D, C),
    (A, C, D, B),
    (A, D, B, C),
    (A, D, C, B),
  ] :
    side_lengths = [
      (first[0] - next[0]) ** 2 + (first[1] - next[1]) ** 2 for first, next in zip([A1, A2, A3, A4], [A2, A3, A4, A1])
    ]
    if len(set(side_lengths)) == 1 :
      return True

  return False

def check_right(p) :
  # Check if there are same points
  for a, b in [
    (p[0], p[1]),
    (p[0], p[2]),
    (p[1], p[2]),
  ] :
    if a[0] == b[0] and a[1] == b[1] :
      return False

  a, b, c = p
  a, b, c = vector_diff(a, b), vector_diff(b, c), vector_diff(c, a)

  return scalar_product(a, b) * scalar_product(a, c) * scalar_product(b, c) == 0

def modmatrixproduct(a, b, mod) :
  n, m1 = len(a), len(a[0])
  m2, k = len(b), len(b[0])

  assert(m1 == m2)
  m = m1

  r = [[0] * k for i in range(n)]
  for i in range(n) :
    for j in range(k) :
      for l in range(m) :
        r[i][j] += a[i][l] * b[l][j]
      r[i][j] %= mod
  return r

def modmatrixpower(a, n, mod) :
  magic = 2
  for m in [2, 3, 5, 7] :
    if n % m == 0 :
      magic = m
      break

  r = None
  if n < magic :
    r = a
    n -= 1
  else :
    s = modmatrixpower(a, n // magic, mod)
    r = s
    for i in range(magic - 1) :
      r = modmatrixproduct(r, s, mod)

  for i in range(n % magic) :
    r = modmatrixproduct(r, a, mod)

  return r
n, k = rints()
a = rints()

b = [a[i: i + k] for i in range(0, n, k)]

d = 0
for j in range(k) :
  sub = [b[i][j] for i in range(len(b))]
  sub = Counter(sub)
  d += min(sub.get(1, 0), sub.get(2, 0))

print d

from Queue import * # Queue, LifoQueue, PriorityQueue
from bisect import * #bisect, insort
from datetime import *
from collections import * #deque, Counter,OrderedDict,defaultdict
import calendar
import heapq
import math
import copy
import itertools
myread = lambda : map(int,raw_input().split())
def solver():
    n,k = myread()
    num = myread()
    ans = 0
    for i in range(k):
        count1 = 0
        count2 = 0
        for j in range(n/k):
            if num[j*k + i] == 1:
                count1 += 1
            else:
                count2 += 1

        ans += min(count1,count2)

    print ans

if __name__ == "__main__":
    solver()

def main():
    #from sys import stdin, stdout
    #start here
    (n,k)=map(int,raw_input().split())
    a=map(int,raw_input().split())
    t=n/k
    ans=0
    for i in xrange(k):
        c=[]
        for j in xrange(t):
            c.append(a[j*k+i])
        #print c
        ans=ans+min(c.count(1),c.count(2))
    print ans

if __name__ == "__main__":
    main()

if __name__=='__main__':
    n,k = map(int, raw_input().split())
    arr = map(int, raw_input().split())

    ones, twos = [], []
    for i in range(k):
        ones.append(0)
        twos.append(0)

    for i in range(n):
        r = i%k
        if arr[i]==1:
            ones[r]+=1
        else:
            twos[r]+=1

    ans = 0
    for i in range(k):
        ans += min(ones[i],twos[i])
    print ans

r=lambda:map(int,raw_input().split())
n,k=r()
m=r()
S=0
for i in range(k):
    c=m[i::k].count(1)
    S+=min(c,n/k-c)
print S

n, k = map(int, input().split())
a = list(map(int, input().split()))
print(sum(min(x.count(1), x.count(2)) for x in (a[i::k] for i in range(k))))

n, k = map(int, raw_input().split())
L = map(int, raw_input().split())
tmp, m = 0, 0
f = [[0] * 3 for i in range(105)]
for i in range(n):
    f[i % k][L[i]] += 1
ans = 0
for i in range(k):
    if f[i][1] < f[i][2]:
        ans += f[i][1]
    else:
        ans += f[i][2]
print ans

n,k=map(int,input().split())
a=list(map(int,input().split()))
c=0
z=n//k
for i in range(k):
	a1=a[i::k]
	r1=a1.count(1)
	r2=a1.count(2)
	c=c+min(r1,r2)
print(c)

n, k = [int(i) for i in raw_input().split()]

a = raw_input().split()
out = 0
for i in xrange(k):
    lst = [int(a[j]) for j in xrange(i, n, k)]
    out+=min(lst.count(1), lst.count(2))
print out

n , k = map(int ,raw_input().split())
a = map(int , raw_input().split())
b = [0] * n
for i in range (n) :
    if a[i] == 1 : b[i % k] += 1
ans = 0
for i in range (k) :
    ans += min(b[i] , n/k -  b[i])
print ans

n,m = map(int,input().split())
has=[[0,0]for i in range(m)]
lis = list(map(int,input().split()))
for i in range(n):
    if lis[i]==2:
        has[i%m][1]+=1
    else:
        has[i%m][0]+=1
ans=0
for i in range(m):
    ans+=min(has[i][0],has[i][1])
print(ans)

import sys

[n,k] = map(int, sys.stdin.readline().strip().split())
arr = map(int, sys.stdin.readline().strip().split())

count1 = [0] * k
count2 = [0] * k

for i in range(0,n):
    if (arr[i] == 1):
        count1[i%k] = count1[i%k] + 1
    else:
        count2[i%k] = count2[i%k] + 1

ans = 0

for i in range(0,k):
    ans = ans + min(count1[i], count2[i])
    #print count1[i] + count2[i]

print ans

from sys  import stdin,stdout
from collections import deque
st=lambda:list(stdin.readline().strip())
li=lambda:list(map(int,stdin.readline().split()))
mp=lambda:map(int,stdin.readline().split())
inp=lambda:int(stdin.readline())
pr=lambda n: stdout.write(str(n)+"\n")

mod=1000000007
INF=float('inf')

def solve():

    n,k=mp()
    l=li()
    ans=0
    for i in range(k):
        x=[]
        for j in range(i,n,k):
            x.append(l[j])
        a=x.count(1)
        b=len(x)-a
        ans+= min(a,b)
    pr(ans)

for _ in range(1):

    solve()

# -*- coding: utf-8 -*-
# programmer: baizhj(baizhj@gmail.com)
# date: Dec. 8th, 2013

import sys

if __name__ == '__main__':
    n, k = [int(x) for x in sys.stdin.readline().split()]
    a = [int(x) for x in sys.stdin.readline().split()]
    t = n / k
    change = 0
    for i in xrange(0, k):
        cnt1 = 0
        for j in xrange(0, t):
            if a[j*k+i] == 1:
                cnt1 += 1
        cnt1 = min(cnt1, t-cnt1)
        change += cnt1
    print change

n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
b=[a[i:n:k] for i in range(k)]
print sum([n/k-max(t.count(x) for x in set(t)) for t in b])

(n,k) = map(int, raw_input().split())
a = map(int, raw_input().split())

b = [0] * k

for i in xrange(n):
    if a[i] == 1:
        b[i % k] += 1

res = sum(map(lambda x: min(x, n / k - x), b))
print res

I=lambda:map(int, raw_input().split())
n, k = I()
a = I()
b = [[0,0] for i in xrange(k)]
for i in xrange(n):
    b[i%k][a[i]==1] += 1
print sum(min(x,y) for x,y in b)

if __name__ == '__main__':
    n, m = [int(x) for x in raw_input().split()]
    a = [int(x) for x in raw_input().split()]
    res = 0
    for i in range(m):
        cnt = 0
        for j in range(i, n, m):
            if a[j] == 1:
                cnt += 1
        res += min(cnt, n / m - cnt)
    print res

import sys
# sys.stdin=open("1.in",'r')
n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
ans=0;
for i in xrange(k):
    ct1=0;
    ct2=0;
    for j in xrange(i,n,k):
        if (a[j]==1):
            ct1+=1
        else:
            ct2+=1
    ans+=min(ct1,ct2);
print ans

r = lambda: map(int, raw_input().split())
n, k = r()
a = r()
cnt = [{} for i in xrange(k)]
for i in xrange(n):
    cnt[i % k][a[i]] = cnt[i % k].get(a[i], 0) + 1
print sum(n / k - max(dic.values()) for dic in cnt)

##   int(input())
##  map(int ,input().split())
##  int(i) for i in input().split()
n, k = map(int ,input().split())
v = [int(x) for x in input().split()]
l = [0] * k
for i in range(k):
	l[i] = v[i::k].count(1)
ans = 0
n //= k
for x in l:
	ans += min(x, n - x)
print(ans)

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
c = 0
for i in range(0, k):
    one = a[i::k].count(1)
    two = a[i::k].count(2)
    c += min(one, two)
print(c)

n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(k):
    t1, t2 = 0, 0
    for j in range(i, n, k):
        if a[j] == 1:
            t1 += 1
        else:
            t2 += 1
    ans += min(t1, t2)
print(ans)

n, k = map(int, input().split())
a, val = list(map(int, input().split())), 0
for i in range(k):
    c = sum(a[i + j * k] == 1 for j in range(n // k))
    val += min(c, n // k - c)
print(val)

n,k=map(int,input().split(" "))
li=list(map(int,input().split(" ",n)[:n]))
hs=[[0 for i in range(k)] for j in range(n//k)]
p=0
for i in range(n//k):
    for j in range(k):
        hs[i][j]=li[p]
        p+=1
ans=0
for i in range(k):
    an=0
    for j in range(n//k):
        if hs[j][i]==1:
            an+=1
    if an<=(n//k)//2:
        ans+=an
    else:
        ans+=(n//k - an)
print(ans)

from collections import Counter

X = list(map(int, input().split()))
Numbers = list(map(int, input().split()))
print(sum((X[0] // X[1] - max(Counter(Numbers[i::X[1]]).values())) for i in range(X[1])))

# A new start
# Here in Tabas
# Waiting for the big news

n,k=tuple(map(int,input().split()))
a=list(map(int,input().split()))
print(sum((lambda x:min(x-n//k,2*n//k-x))(sum(a[i::k])) for i in range(k)))

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

print(sum(min(x.count(1), x.count(2)) for x in (a[i::k] for i in range(k))))

a=int(input().split()[1])
*b,=map(int,input().split())
c=0
for i in range(a):
    d=b[i::a]
    c+=min(d.count(1),d.count(2))
print(c)

n, k = list(map(int, input().split()))
a = input().split()
c = 0
for i in range(k):
    x, y = 0, 0
    for j in range(i, n, k):
        if a[j] == '1':
            x += 1
        else:
            y += 1
    c += min(x, y)
print(c)

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

L=list(map(int,input().split()))

A=[]
for i in range(0,n,k):
    A.append(list(L[i:i+k]))
z=n//k
ans=0
for i in range(k):
    one=0
    two=0
    for j in range(z):
        if(A[j][i]==1):
            one+=1
        else:
            two+=1
    ans+=min(one,two)
print(ans)

def main():
    n, k = map(int, input().split(' '))
    A = [int(i) for i in input().split(' ')]
    ans = 0
    one = 0
    two = 0
    for i in range(k):
        one = 0
        two = 0
        for j in range(n // k):
            pos = i + j * k
            if A[pos] == 1:
                one = one + 1
            else:
                two = two + 1
        if(one < two):
            ans = ans + one
        else:
            ans = ans + two
    print(ans)

if __name__ == '__main__':
    main()

n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
ans = 0
for i in range(0, k):
    n1 = l[i::k].count(1)
    n2 = l[i::k].count(2)
    ans  += min( n1 , n2 )
print(ans)

def _count(list, item):
	count = 0
	for c in list:
		if c == item:
			count += 1
	return count

def common(list):
	counts = []
	maxcount = 0
	for stuff in list:
		if _count(list, stuff) > maxcount:
			maxitem = stuff
			maxcount = _count(list, stuff)
	return maxitem

aa = input().split()
n = int(aa[0])
k = int(aa[1])
a = input().split()

matrix = []
new = []
for i in range(1, n + 1):
	if i % k == 0:
		new.append(a[i - 1])
		matrix.append(new)
		new = []
	else:
		new.append(a[i-1])

colums = []
answer = 0
for j in range(len(matrix[0])):
	colum = []
	for i in range(len(matrix)):
		colum.append(matrix[i][j])
	colums.append(colum)

for rows in matrix:
	for i in range(len(rows)):
		if rows[i] != common(colums[i]):
			answer += 1
print(answer)

n, k = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
z = n // k
for i in range(k):
	b = l[i::k]
	co = b.count(1)
	ans += min(z - co, co)

print(ans)

n, k = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(k):
	ones = 0
	twos = 0
	for j in range(n // k):
		if l[i + j * k] == 1:
			ones += 1
		else:
			twos += 1

	ans += min(ones, twos)

print(ans)

n, k = map(int, input().split())
nums = list(map(int, input().split()))
ans = 0
for i in range(k):
	cnt = [0, 0, 0]
	for j in range(n // k):
		cnt[nums[j * k + i]] += 1
	ans += min(cnt[1], cnt[2])
print(ans)

def inp():
    return map(int, input().split())

def arr_inp():
    return [int(x) for x in input().split()]

n, k = inp()
a, out = arr_inp(), 0
for i in range(k):
    arr = a[i::k]
    out += min(arr.count(1), arr.count(2))

print(out)

# bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# import math
# from itertools import *
# import random
# import calendar
# import datetime
# import webbrowser

n, k = map(int, input().split())
arr = list(map(int, input().split()))
count = 0
index = 0
while index < k:
    new = [arr[index]]
    temp = index
    for i in range((n//k) - 1):
        new.append(arr[temp + k])
        temp += k
    if new.count(1) >= new.count(2):
        count += new.count(2)
    else:
        count += new.count(1)
    index += 1
print(count)

n,k=map(int,input().split())
l=list(map(int,input().split()))
ans=0
for i in range(k):
    ones=0
    twos=0
    for j in range(n//k):
        num=l[i+j*k]
        if(num==1):
            ones+=1
        else:
            twos+=1
    ans+=min(ones,twos)
print(ans)

k=int(input().split()[1])
b=list(map(int,input().split()))
c=0
for i in range(k):
    d=b[i::k]
    c+=min(d.count(1),d.count(2))
print(c)

#we r looking at particular elements of each respective group(the k periodic group)..
#and looking for the minimum changes

n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
ans = 0
for i in range(k):
    t = 0
    for j in a[i::k]:
        s = a[i::k].count(j)
        if s > t:
            t = s
            o = j
    for j in a[i::k]:
        if j != o:
            ans += 1
print(ans)

n, k = map(int, input().split())
l = [*map(int, input().split())]
print(sum(min(l[i::k].count(1), l[i::k].count(2)) for i in range(k)))

# Made By Mostafa_Khaled
bot = True
R = lambda: map(int, input().split())

n, k = R()

a = list(R())

print(sum(min(x.count(1), x.count(2)) for x in (a[i::k] for i in range(k))))

# Made By Mostafa_Khaled

read = lambda:map(int, input().split())
n,k = read()
m = n//k
a = list(read())
result = 0
for i in range(k):
    t = a[i:n:k]
    s = t.count(1)
    result += min(s, m-s)
print(result)

from math import *

[n, k] = [int(i) for i in input().split()]
arr = [int(i) - 1 for i in input().split()]
arr2 = [[0 for i in range(2)] for j in range(k)]
r = 0
for i in range(n // k):
    for j in range(k):
        arr2[j][arr[i * k + j]] += 1
for j in range(k):
    r += min(arr2[j][0], arr2[j][1])
print(r)

#!/usr/bin/python3

def readln(): return tuple(map(int, input().split()))

n, k = readln()
a = readln()
ans = 0
for i in range(k):
    cnt = len([1 for j in range(i, n, k) if a[j] == 1])
    ans += min(cnt, n // k - cnt)
print(ans)

def main():
    n, k = map(int, input().split())
    l = input().split()
    print(sum(min(nn.count('1'), nn.count('2')) for nn in zip(*[l[i:i + k] for i in range(0, n, k)])))

if __name__ == '__main__':
    main()

n, k = [int(x) for x in input().split()]

a = [int(x) for x in input().split()]

c=0
z=n//k
for i in range(k):
	a1=a[i::k]
	r1=a1.count(1)
	r2=a1.count(2)
	c=c+min(r1,r2)
print(c)

def dist(x, y):
  return len([a for a, b in zip(x, y) if a != b])

n, k = map(int, raw_input().split())
array = map(int, raw_input().split())
temp = [0] * k
count = 0

for i in range(n/k):
  for j in range(k):
    temp[j] += array[i*k+j]

for i in temp:
  count2 = i - n/k
  count1 = n/k - count2
  count += min(count1, count2)

print count

n,k=map(int,raw_input().split())
arr=map(int,raw_input().split())
c=0
for i in range(k):
    t=[]
    for j in range(n/k):
        t.append(arr[i+j*k])
    c+=n/k-max(t.count(1),t.count(2))
print c

n,q=map(int,input().split())
a=list(map(int,input().split()))
c=[]
l=[]
c1=0
# for i in range(1,n+1):
i=q
if(n%i==0):
	r=a[:i]
	j=i
	c1=0
	l.append(r)
	while(j<len(a)):
		y=a[j:j+len(r)]
		j=j+len(r)
		l.append(y)
t=[]
for j in range(len(l)):
	c1=0
	k=l[j]
	for m in range(len(l)):
		if(m==j):
			pass
		else:
			for e in range(q):
				if(l[m][e]!=l[j][e]):
					c1=c1+1
	c.append(c1)
k1=a.count(1)
k2=a.count(2)
print(min(min(c),min(k1,k2)))

n,q=map(int,input().split())
a=list(map(int,input().split()))
c=[]
c1=0
for i in range(1,n+1):
	if(n%i==0 and i==q):
		r=a[:i]
		# print(r)
		j=i
		c1=0
		while(j<len(a)):
			y=a[j:j+len(r)]
			j=j+len(r)
			# print(r,y)
			for k in range(len(r)):
				if(r[k]!=y[k]):
					c1=c1+1
		c.append(c1)
k1=a.count(1)
k2=a.count(2)
# print(c1)
# print(c,k1,k2)
if(n==q):
	print(0)
elif(len(c)>0):
	print(min(min(c),min(k1,k2)))
else:
	print(min(k1,k2))

n,k=map(int,input().split())
a=list(map(int,input().split()))
c=[]
c1=0
for i in range(1,n+1):
	if(n%i==0):
		r=a[:i]
		# print(r)
		j=i
		c1=0
		while(j<len(a)):
			y=a[j:j+len(r)]
			j=j+len(r)
			# print(r,y)
			for k in range(len(r)):
				if(r[k]!=y[k]):
					c1=c1+1
		c.append(c1)
c.pop()
k1=a.count(1)
k2=a.count(2)
# print(c,k1,k2)
if(len(set(a))==n):
	print(0)
elif(len(c)>0):
	print(min(min(c),min(k1,k2)))
else:
	print(min(k1,k2))

n,k=map(int,input().split())
a=list(map(int,input().split()))
c=[]
c1=0
for i in range(1,n+1):
	if(n%i==0):
		r=a[:i]
		# print(r)
		j=i
		c1=0
		while(j<len(a)):
			y=a[j:j+len(r)]
			j=j+len(r)
			# print(r,y)
			for k in range(len(r)):
				if(r[k]!=y[k]):
					c1=c1+1
		c.append(c1)
c.pop()
k1=a.count(1)
k2=a.count(2)
if(len(c)>0):
	print(min(min(c),min(k1,k2)))
else:
	print(min(k1,k2))

n,q=map(int,input().split())
a=list(map(int,input().split()))
c=[]
c1=0
for i in range(1,n+1):
	if(n%i==0 and i<=q):
		r=a[:i]
		# print(r)
		j=i
		c1=0
		while(j<len(a)):
			y=a[j:j+len(r)]
			j=j+len(r)
			# print(r,y)
			for k in range(len(r)):
				if(r[k]!=y[k]):
					c1=c1+1
		c.append(c1)
c.pop()
k1=a.count(1)
k2=a.count(2)
# print(c,k1,k2)
if(n==q):
	print(0)
elif(len(c)>0):
	print(min(min(c),min(k1,k2)))
else:
	print(min(k1,k2))

n,q=map(int,input().split())
a=list(map(int,input().split()))
c=[]
c1=0
for i in range(1,n+1):
	if(n%i==0):
		r=a[:i]
		# print(r)
		j=i
		c1=0
		while(j<len(a)):
			y=a[j:j+len(r)]
			j=j+len(r)
			# print(r,y)
			for k in range(len(r)):
				if(r[k]!=y[k]):
					c1=c1+1
		c.append(c1)
c.pop()
k1=a.count(1)
k2=a.count(2)
# print(c,k1,k2)
if(n==q):
	print(0)
elif(len(c)>0):
	print(min(min(c),min(k1,k2)))
else:
	print(min(k1,k2))

def f(l1,l2):
    n,k = l1
    nol = n//k
    sl  = [sum(l2[i:n:k]) for i in range(nol)]
    return sum([min(nol*2-s,s-nol) for s in sl])

l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))
print(f(l1,l2))

st = raw_input()

st = st.split(" ", 1);
n = int( st[0] )
k = int( st[1] )

st = raw_input()
ar = []
st = st.split(" ", n-1)
for s in st:
    ar.append( int(s) )

if k == 1:
    print 0
else:
    res = 0
    i = 0
    while i < k:
        i += 1
        j = 0
        ones = 0
        twos = 0
        while j < int(n/k):
            # print "index : " + str(k*j+i-1)
            if ar[ k*j+i-1 ] == 1:
                ones += 1
            else:
                twos += 1
            j += 1
        res += min( ones, twos )
    print res

# from Mergesort import *
# s=[1,2,35,4,45,454,78,23,65,567,343,4345,65,75,453,5]
# arr1=mergesort(s)
# print "arr1 is"
# prin t arr1
import sys
x= raw_input()
y= x.split()
y[0]=int(y[0])
y[1]=int(y[1])
j=-1
z=int(y[0])/int(y[1])
s=raw_input()
s=s.split()
h=0
count=0
count1=0
ans=0
for i in s:
    j+=1
    h=j+y[1]
    note=s[j]

    if(j>=y[1]):
        print count
        sys.exit()

    while (h<y[0]):
        if s[j]!=s[h] :
            count+=1
        else:
            count1+=1
        h+=y[1]
    ans+=min(count,count1)
print ans

# from Mergesort import *
# s=[1,2,35,4,45,454,78,23,65,567,343,4345,65,75,453,5]
# arr1=mergesort(s)
# print "arr1 is"
# prin t arr1
import sys
x= raw_input()
y= x.split()
y[0]=int(y[0])
y[1]=int(y[1])
j=-1
z=int(y[0])/int(y[1])
s=raw_input()
s=s.split()
h=0
count=0
count1=0
ans=0
for i in s:
    j+=1
    h=j+y[1]
    note=s[j]

    if(j>=y[1]):
        print ans
        sys.exit()

    while (h<y[0]):
        if s[j]!=s[h] :
            count+=1
        else:
            count1+=1
        h+=y[1]
    ans+=min(count,count1)
print ans

# from Mergesort import *
# s=[1,2,35,4,45,454,78,23,65,567,343,4345,65,75,453,5]
# arr1=mergesort(s)
# print "arr1 is"
# prin t arr1
import sys
x= raw_input()
y= x.split()
y[0]=int(y[0])
y[1]=int(y[1])
j=-1
z=int(y[0])/int(y[1])
s=raw_input()
s=s.split()
h=0
count=0
for i in s:
    j+=1
    h=j+y[1]
    note=s[j]
    if(j>=y[1]):
        print count
        sys.exit()
    while (h<y[0]):
#         print s[j],s[h]

        if s[j]!=s[h] and s[h]!=s[h-y[1]] :
            #int j,h,s[j],s[h]
            count+=1
            #print count

#             print "i ma "+str(j),str(h)
        h+=y[1]
print count

import sys
x= raw_input()
y= x.split()
y[0]=int(y[0])
y[1]=int(y[1])
j=-1
z=int(y[0])/int(y[1])
s=raw_input()
s=s.split()
h=0
count=0
for i in s:
    j+=1
    h=j
    note=s[j]
    if(j>y[1]):
        print count
        sys.exit()
    while (h<y[0]):
#         print s[j],s[h]

        if s[j]!=s[h]:
            count+=1
            if(s[h]==note):
                count-=1
            note=s[h]

#             print "i ma "+str(j),str(h)
        h+=y[1]
print count

# from Mergesort import *
# s=[1,2,35,4,45,454,78,23,65,567,343,4345,65,75,453,5]
# arr1=mergesort(s)
# print "arr1 is"
# prin t arr1
import sys
x= raw_input()
y= x.split()
y[0]=int(y[0])
y[1]=int(y[1])
j=-1
z=int(y[0])/int(y[1])
s=raw_input()
s=s.split()
h=0
count=0
for i in s:
    j+=1
    h=j+y[1]
    note=s[j]
    if(j>=y[1]):
        print count
        sys.exit()
    while (h<y[0]):
#         print s[j],s[h]

        if s[j]!=s[h] and s[h]!=s[h-y[1]] :
            #int j,h,s[j],s[h]
            count+=1
            #print count

#             print "i ma "+str(j),str(h)
        h+=y[1]
# print count

[N, K] = map(int, raw_input().split())
a = [x-1 for x in map(int, raw_input().split())]
print sum(min(sum(a[i::K]), N/K-sum(a[i::K])) for i in range(N/K))

first_line = raw_input()
n = int(first_line.split(" ")[0])
k = int(first_line.split(" ")[1])
line = raw_input()
arr = [int(x) for x in line.split(" ")]

sections = []
for i in range(k):
    sections.append([arr[index] for index in range(n) if index % k == i])
result = 0
for sec in sections:
    if sec.count(1) != len(sec) and sec.count(1) != 0:
        result += 1

print result

n,k = map(int,raw_input().split())
a = map(int,raw_input().split())
l = [''.join(map(str,a[i:i+k])) for i in xrange(0,n,k)]
d = {}
for x in l:
    d[x] = d.get(x,0) + 1
m = max(d.values())
print [n/k - m,k][m == 1]

n,k = map(int,raw_input().split())
a = map(int,raw_input().split())
l = [''.join(map(str,a[i:i+k])) for i in xrange(0,n,k)]
d = {}
for x in l:
    d[x] = d.get(x,0) + 1
m = max(d.values())
if n == k:
    print 0
else:
    print [n/k - m,k][m == 1]

n, k = map(int, raw_input().strip().split())
a = map(int, raw_input().strip().split())

ka = 0
et = [[0 for j in range(n/k)] for i in range(k)]

for i in range(k):
    for j in range(n/k):
        et[i][j] = a[i+k*j]

for i in range(k):
    if len(set(et[i])) > 1:
        ka = ka + abs(et[i].count(1)-et[i].count(2))

print ka

n,k=map(int,raw_input().split())
a=map(lambda x:bool(int(x)-1),raw_input().split())
f=n/k
c=[]
for x in xrange(k):c.append(0)
for x in xrange(n):
    if a[x]==1:c[x%k]+=1
d=map(lambda x:bool(x/f),c)
ans=0
for x in xrange(n):
    if a[x]!=d[x%k]:ans+=1
print ans;

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())

c = 0

for i in xrange(k):
    e = [a[j] for j in xrange(i, n, k)]
    if len(set(e)) == 1:
        continue
    else:
        print e
        c += min(e.count(1), e.count(2))

print c

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())

c = 0

for i in xrange(k):
    e = [a[j] for j in xrange(i, n, k)]
    if len(set(e)) == 1:
        continue
    else:
        c += abs(e.count(1) - e.count(2))

print c

n,k = map(int, raw_input().strip().split(' '))
lis = map(int, raw_input().strip().split(' '))
if k == 1:
    print 0
    exit(0)

grps = []
for i in range(k):
    grps.append([])

for i in range(n):
    grps[i%k].append(lis[i])

answer = 0
for i in range(k):
    answer += min(grps[i].count(1), grps[i].count(2))

print answer

n, k = map(int, raw_input().split())
data = map(int, raw_input().split())
ans = 0
for x in xrange(0,k):
    tmp = [0,0,0]
    for y in xrange(0,n/k):
        tmp[data[x*y]] += 1
    ans += min(tmp[1], tmp[2])
print ans

def main():
    #from sys import stdin, stdout
    #start here
    (n,k)=map(int,raw_input().split())
    a=map(int,raw_input().split())
    t=n/k
    ans=float('inf')
    for i in xrange(t):
        c=0
        for j in xrange(n):
            #print j, j%k+i*k, j%k, i*k
            if(a[j]!=a[j%k+i*k]):
                c=c+1
        #print c
        ans=min(ans,c)
    print ans

if __name__ == "__main__":
    main()

n,k=map(int,raw_input().split())
ar=map(int,raw_input().split())
i=0
c1=ar.count(1)
c2=ar.count(2)
c3=10**9
t1=[[] for i in xrange(k)]
while(i<=(n-k)):
    l1=(ar[i:i+k])
    for j in xrange(k):
        t1[j].append(l1[j])
    i+=k
ans=0
for i in xrange(k):
    ans+=min(t1[i].count(1),t1[j].count(2))
print ans

n,k=map(int,raw_input().split())
ar=map(int,raw_input().split())
i=0
c1=ar.count(1)
c2=ar.count(2)
c3=10**9
while(i<=(n-k)):
    l1=(ar[i:i+k])
    j=0
    temc=0
    while (j<=(n-k)):
        l2=ar[j:j+k]
        for t in xrange(k):
            if l1[t]!=l2[t]:
                temc+=1
        j+=k
    c3=min(temc,c3)
    i+=k
print min(c3,c1,c2)

n,k=map(int,raw_input().split())
ar=map(int,raw_input().split())
i=0
c1=ar.count(1)
c2=ar.count(2)
c3=10**9
t1=[[] for i in xrange(k)]
while(i<=(n-k)):
    l1=(ar[i:i+k])
    for j in xrange(k):
        t1[j].append(l1[j])
    i+=k
ans=0
for i in xrange(k):
    ans+=min(t1[i].count(1),t1[i].count(2))
print ans

n, k = map(int, raw_input().split())
L = map(int, raw_input().split())
s = set()
s.add(tuple([1] * k))
s.add(tuple([2] * k))
for i in range(n / k):
    s.add(tuple(L[i * k:(i+1) * k]))
mn = 1 << 30
for x in s:
    cnt = 0
    for i in range(n / k):
        for j in range(k):
            if x[j] != tuple(L[i * k:(i+1) * k])[j]:
                cnt += 1
    mn = min(mn, cnt)
print mn

n , k = map(int ,raw_input().split())
a = map(int , raw_input().split())
b = [0] * n
for i in range (n) :
	if a[i] == 1 : b[i % k] += 1
ans = 0
for i in range (n/k) :
	ans += min(b[i] , n/k -  b[i])
print ans

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
ans = 0

for i in xrange(n / k):
    t1 = t2 = 0
    for j in xrange(k):
        if a[i * k + j] == 1:
            t1 += 1
        else:
            t2 += 1
    ans += min(t1, t2)
print ans

line1=raw_input().split(" ")
N=int(line1[0]);K=int(line1[1])
array=map(int,raw_input().split(" "))
row=len(array)/K
col=K
D2=[]
tmp=[]
for i in range(len(array)):
    if (i+1)%K!=0:
        tmp.append(array[i])
    if (i+1)%K==0:
        tmp.append(array[i])
        D2.append(tmp)
        tmp=[]
def Solve(D2,K,N):
    print D2
    total=0
    for j in range(K):
        one_count=0
        two_count=0
        for i in range(N/K):
            if D2[i][j]==1: one_count+=1
            else: two_count+=1
        total+=min(one_count,two_count)
    return total
print Solve(D2,K,N)

__author__ = 'roma'

import sys

def rai():
    return map(int, sys.stdin.readline().strip().split())

n, k = rai()
a = rai()

# n, k = (8, 2)
# a = [1, 1, 2, 1, 1, 1, 2, 1]

d = list()
for i in xrange(0, n/k):
    d.append(a[:k])
    a[:k] = []
    # print d

def most_common(lst):
    return max(lst, key=lst.count)

z = zip(*d)
c = most_common(d)
df = filter(lambda x: cmp(x, c), d)
counter = 0
for e in df:
    for hj in zip(c, e):
        if hj[0] is not hj[-1]:
            counter += 1
print counter

__author__ = 'roma'

import sys

def rai():
    return map(int, sys.stdin.readline().strip().split())

n, k = rai()
a = rai()

# n, k = (6, 2)
# a = [2, 1, 2, 2, 2, 1]

d = list()
for i in xrange(0, n/k):
    d.append(a[:k])
    a[:k] = []

def most_common(lst):
    return max(set(lst), key=lst.count)

z = zip(*d)
c = most_common(z)
df = filter(lambda x: x is not c, z)
counter = 0
for e in df:
    for hj in zip(c, e):
        if hj[0] is hj[-1]:
            counter += 1
print counter

##   int(input())
##  map(int ,input().split())
##  int(i) for i in input().split()
n, k = map(int ,input().split())
a = [int(i) for i in input().split()]
rs = 105
if k == n: rs = 0
for i in range(n // k):
    b = []
    cnt = 0
    t = 0
    for j in range(k):
        b.append(a[i*k + j])
    for j in range(n):
        if a[j] != b[t]: cnt+=1
        t+= 1
        if t >= k: t = 0
    rs = min(rs, cnt)
for i in range(n):
    cnt = 0
    for j in range(n):
        if a[j] != a[i]: cnt+=1
    rs = min(rs, cnt)
print(rs)

##   int(input())
##  map(int ,input().split())
##  int(i) for i in input().split()
n, k = map(int ,input().split())
a = [int(i) for i in input().split()]
rs = 105
for i in range(n // k):
    b = []
    cnt = 0
    t = 0
    for j in range(k):
        b.append(a[i*k + j])
    for j in range(n):
        if a[j] != b[t]: cnt+=1
        t+= 1
        if t >= k: t = 0
    rs = min(rs, cnt)
for i in range(n):
    cnt = 0
    for j in range(n):
        if a[j] != a[i]: cnt+=1
    rs = min(rs, cnt)
print(rs)

n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(k):
    t1, t2 = 0, 0
    for j in range(i, n, k):
        print(j, a[j])
        if a[j] == 1:
            t1 += 1
        else:
            t2 += 1
    ans += min(t1, t2)
print(ans)

line = input().split()
n = int(line[0])
k = int(line[1])

line = input().split()
arr = [int(i) for i in line]

matrix = []

new_arr = []
for i in range(n+1):
	if i % k == 0 and new_arr:
		matrix.append(new_arr)
		new_arr = []
	if i == n:
		break
	new_arr.append(arr[i])
# print(f"matrix: {matrix}")

changes = 0
for c in range(k): # n/k is number of sub arrays
	one_cnt = 0
	two_cnt = 0
	for r in range(n//k):
		# print(f"row {r} col {c} value: {matrix[r][c]}")
		if matrix[r][c] == 2:
			two_cnt += 1
		else:
			one_cnt += 1
	# print(f"twos in {c}th column: {two_cnt}")
	# print(f"ones in {c}th column: {one_cnt}")
	if one_cnt != 0 and two_cnt != 0: # a change needs to be made
		changes += abs(one_cnt - two_cnt)

# print("\n\n")
print(changes)

aa = input().split()
n = int(aa[0])
k = int(aa[1])
a = input().split()

master = []
new = []
for i in range(1, n + 1):
	if i % k == 0:
		new.append(a[i - 1])
		master.append(new)
		new = []
	else:
		new.append(a[i-1])

def count(list, item):
	count = 0
	for c in list:
		if c == item:
			count += 1
	return count

def common(list):
	counts = []
	maxcount = 0
	for stuff in list:
		if count(list, stuff) > maxcount and count(list, stuff) > 1:
			maxitem = stuff
			maxcount = count(list, stuff)
		if maxcount == 0:
			maxitem = 'none'
	return maxitem

if n == k:
	answer = 0

else:
	if common(master) == 'none':
		if n / k <= 2:
			reference = master[0]
			answer = 0
			for i in range(len(master[1])):
				if master[1][i] != reference[i]:
					answer += 1

		else:
			answer = 0
			h = []
			for k in master:
				for m in k:
					h.append(m)
			for i in h:
				if i != (common(h)):
					answer += 1
	else:
		reference = common(master)
		answer = 0
		for i in range(len(master)):
			if master[i] != reference:
				for j in range(len(master[i])):
					if master[i][j] != reference[j]:
						answer += 1

print(answer)

aa = input().split()
n = int(aa[0])
k = int(aa[1])
a = input().split()

master = []
new = []
for i in range(1, n + 1):
	if i % k == 0:
		new.append(a[i - 1])
		master.append(new)
		new = []
	else:
		new.append(a[i-1])

def count(list, item):
	count = 0
	for c in list:
		if c == item:
			count += 1
	return count

def common(list):
	counts = []
	maxcount = 0
	for stuff in list:
		if count(list, stuff) > maxcount and count(list, stuff) > 1:
			maxitem = stuff
			maxcount = count(list, stuff)
		if maxcount == 0:
			maxitem = 'none'
	return maxitem

if n == k:
	answer = 0

else:
	if common(master) == 'none':
		reference = master[0]

	else:
		reference = common(master)

	answer = 0
	for i in range(1, len(master)):
			if master[i] != reference:
				for j in range(len(master[i])):
					if master[i][j] != reference[j]:
						answer += 1

print(answer)

aa = input().split()
n = int(aa[0])
k = int(aa[1])
a = input().split()

master = []
new = []
for i in range(1, n + 1):
	if i % k == 0:
		new.append(a[i - 1])
		master.append(new)
		new = []
	else:
		new.append(a[i-1])

def count(list, item):
	count = 0
	for c in list:
		if c == item:
			count += 1
	return count

def common(list):
	counts = []
	maxcount = 0
	for stuff in list:
		if count(list, stuff) >= maxcount:
			maxitem = stuff
			maxcount = count(list, stuff)
	return maxitem

answer = 0

check = True
for lists in master:
	if count(master, lists) > 1:
		check = False

if n == k:
	answer = 0

elif check == True:
	reference = common(a)
	for i in a:
		if i != reference:
			answer += 1

elif check == False:
	for i in master:
		ref = common(master)
		if i != ref:
			for j in range(len(i)):
				if i[j] != ref[j]:
					answer += 1
print(answer)

aa = input().split()
n = int(aa[0])
k = int(aa[1])
a = input().split()

master = []
new = []
for i in range(1, n + 1):
	if i % k == 0:
		new.append(a[i - 1])
		master.append(new)
		new = []
	else:
		new.append(a[i-1])

def count(list, item):
	count = 0
	for c in list:
		if c == item:
			count += 1
	return count

def common(list):
	counts = []
	maxcount = 0
	for stuff in list:
		if count(list, stuff) > maxcount:
			maxitem = stuff
			maxcount = count(list, stuff)
	return maxitem

answer = 0

check = True
for lists in master:
	if count(master, lists) > 1:
		check = False

if n == k:
	answer = 0

elif check == True:
	reference = common(a)
	for i in a:
		if i != reference:
			answer += 1

elif check == False:
	for i in master:
		ref = common(master)
		if i != ref:
			for j in range(len(i)):
				if i[j] != ref[j]:
					answer += 1
print(answer)

aa = input().split()
n = int(aa[0])
k = int(aa[1])
a = input().split()

master = []
new = []
for i in range(1, n + 1):
	if i % k == 0:
		new.append(a[i - 1])
		master.append(new)
		new = []
	else:
		new.append(a[i-1])

def count(list, item):
	count = 0
	for c in list:
		if c == item:
			count += 1
	return count

def common(list):
	counts = []
	maxcount = 0
	for stuff in list:
		if count(list, stuff) >= maxcount:
			maxitem = stuff
			maxcount = count(list, stuff)
	return maxitem

check = True
for lists in master:
	if count(master, lists) > 1:
		check = False

answer = 0

if check ==True:
	reference = common(a)
	for i in a:
		if i != reference:
			answer += 1

if check == False:
	for i in master:
		ref = common(master)
		if i != ref:
			for j in range(len(i)):
				if i[j] != ref[j]:
					answer += 1
print(answer)

def main():
    n, k = map(int, input().split())
    arr = list(map(int, input().split()))

    answer = min(arr.count(1), arr.count(2))
    answer_now=0

    for i in range(n//k):
        now = arr[i*k:(i+1)*k]
        answer_now = 0

        for j in range(n):
            if arr[j]!=now[j%k]:
                answer_now+=1

        answer = min(answer, answer_now)

    print(answer)

main()

n, k = map(int,input().split())
s = list(input().split())
a = n // k
d = 0
for x in range(k):
	b = ""
	c = x
	for y in range(a):
		b += s[c]
		c += k
	if b.count("1") != 0 and b.count("1") != a:d += 1
print(d)

#!/usr/bin/python3

def readln(): return tuple(map(int, input().split()))

n, k = readln()
a = readln()
ans = 0
for i in range(n // k):
    cnt = len([1 for j in range(i, n, n // k) if a[j] == 1])
    ans += min(cnt, k - cnt)
print(ans)