Problem:


Score : 200 points

Problem Statement

Takahashi lives in another world. There are slimes (creatures) of 10000 colors in this world. Let us call these colors Color 1, 2, ..., 10000.

Takahashi has N slimes, and they are standing in a row from left to right. The color of the i-th slime from the left is a_i.
If two slimes of the same color are adjacent, they will start to combine themselves. Because Takahashi likes smaller slimes, he has decided to change the colors of some of the slimes with his magic.

Takahashi can change the color of one slime to any of the 10000 colors by one spell.
How many spells are required so that no slimes will start to combine themselves?

Constraints

2 \leq N \leq 100

1 \leq a_i \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum number of spells required.

Sample Input 1

5
1 1 2 2 2

Sample Output 1

2

For example, if we change the color of the second slime from the left to 4, and the color of the fourth slime to 5, the colors of the slimes will be 1, 4, 2, 5, 2, which satisfy the condition.

Sample Input 2

3
1 2 1

Sample Output 2

0

Although the colors of the first and third slimes are the same, they are not adjacent, so no spell is required.

Sample Input 3

5
1 1 1 1 1

Sample Output 3

2

For example, if we change the colors of the second and fourth slimes from the left to 2, the colors of the slimes will be 1, 2, 1, 2, 1, which satisfy the condition.

Sample Input 4

14
1 2 2 3 3 3 4 4 4 4 1 2 3 4

Sample Output 4

4



Sample input:
5
1 1 2 2 2


Sample output:
2

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
count = 0
a.append(0)
if (N+1==len(a))and(2<=N):
    for i in range(1,N):
        if (a[i-1]==a[i]):
            a[i] += 1
            if a[i] > 10000:
                a[i] = 1
            if a[i]==a[i+1]:
                a[i] += 1
                if a[i] > 10000:
                    a[i] = 1
            count += 1
    print(count)

Submission status: Accepted

Solution code:
n = int(input())
list1 = list(map(int, input().split()))
index =0
count=0
while index < n:
    if index ==0:
        beforeC = list1[index]
        index+=1
    else:
        if beforeC != list1[index]:
            beforeC = list1[index]
            index+=1
        else:
            count+=1
            beforeC = "a"
            index+=1
print(count)

Submission status: Accepted

Solution code:
N = int(input())
colour_list = list(map(int, input().split()))

sum = 0
for i in range(N - 1):
  if colour_list[i] == colour_list[i+1]:
    colour_list[i+1] = 0
    sum += 1

print(sum)

Submission status: Accepted

Solution code:
n=int(input())
a=input().split(' ')

count = 0
i=0
while i<n-1:
	if a[i]==a[i+1]:
		count+=1
		i+=2
	else:
		i+=1
print(count)

Submission status: Accepted

Solution code:
N = int(input())
a_itr = map(int, input().split())
ans = 0
cnt = 0
t = -1
for i in a_itr:
    if i == t:
        cnt += 1
    else:
        ans += cnt//2
        t = i
        cnt = 1
ans += cnt//2
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))

ans = 0
i = 0
while i < n - 1:
    if a[i] == a[i + 1]:
        ans += 1
        i += 2
    else:
        i += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def requiredMagic(nChain: int) -> int:
    return nChain // 2

N = int(input())
A = [int(x) for x in input().split(" ")]

lastColor = -1
nMagic = 0
nChain = 0
for i in range(0, N):
    if(lastColor == A[i]):
        nChain += 1
    else:
        lastColor = A[i]
        nMagic += requiredMagic(nChain)
        nChain = 1
nMagic += requiredMagic(nChain)

print(nMagic)

Submission status: Accepted

Solution code:
def a_colorful_slimes_2(N, A):
    import itertools
    straight_group = itertools.groupby(A)
    ans = 0
    for _, group in straight_group:
        ans += len(list(group)) // 2
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(a_colorful_slimes_2(N, A))

Submission status: Accepted

Solution code:
N = int(input())
prev = 0
ans = 0
for i in map(int, input().split()):
    if i == prev:
        ans += 1
        prev = 0
    else:
        prev = i
print(ans)

Submission status: Accepted

Solution code:
n  = int(input())
a = list(map(int,input().split()))

ans = 0
for i in range (n-1):
    if a[i] == a[i+1]:
        a[i+1] = -1
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
hoge = a[0]
l = []
cnt = 1
for i in a[1:]:
    if i == hoge:
        cnt += 1
    else:
        l.append(cnt)
        hoge = i
        cnt = 1
l.append(cnt)
ans = 0
for i in l:
    ans += i // 2
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n+1):
  if i==0 or i==n or a[i-1] != a[i]:
    if i!=0:
      ans += cnt // 2
    cnt = 1
  else:
    cnt += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
As = [int(a) for  a in input().strip().split(' ')]

temp = 0
counter = 0
for a in As:
    if a == temp:
        counter += 1
        temp = 0
        continue
    temp = a
print(counter)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    c = -1
    r = 0
    for b in a:
        if b == c:
            c = -1
            r += 1
        else:
            c = b
    return r


print(main())

Submission status: Accepted

Solution code:
n = int(input())
d = input().split(" ")

ans = 0
count = 1

for i in range(n-1):
	if(d[i] != d[i+1]):
		ans += int(count/2);
		count = 1;

	else:
		count += 1

if(count > 1):
	ans += int(count/2)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

d = input().split(" ")
ans = 0

for i in range(1,n-1):
	if(d[i] == d[i-1] and d[i] == d[i+1]):
		ans += 1
		d[i] = -i;

	elif(d[i] == d[i-1]):
		ans += 1
		d[i-1] = -i

	elif(d[i] == d[i+1]):
		ans += 1
		d[i+1] = -i

if(n == 2):
	if(d[0] == d[1]):
		ans += 1
# print(d)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(1, len(a)):
    if a[i] == a[i - 1]:
        ans += 1
        a[i] = 1000000

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
slime = 101
count = 1
ans = 0

for i, s in enumerate(a):
    if s == slime:
        #print("same_slime")
        count += 1
    else:
        ans += count // 2
        count = 1
    slime = s
    if i == n - 1:
        ans += count // 2

print(ans)

Submission status: Accepted

Solution code:
input()
l = list(map(int, input().split()))
ans = 0
for i in range(len(l)-1):
    if l[i] == l[i+1]:
        ans += 1
        l[i+1] = -1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
nums = list(map(int,input().split()))

count = 0
flgs = [0]*n

for i in range(n-1):
  if flgs[i] == 0 and nums[i] == nums[i+1]:
    count += 1
    flgs[i+1] = 1
print(count)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))

m=0
for i in range(1,len(a)):
    if a[i-1]==a[i]:
        a[i]=10000+i
        m+=1

print(m)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
answer = 0
for i in range(len(A)-1) :
    if A[i] == A[i+1] :
        A[i+1] = -1
        answer += 1
print(answer)

Submission status: Accepted

Solution code:
N=int(input())
a=[int(i) for i in input().split(" ")]

count=1
result=0
for i in range(len(a)-1):
    if a[i+1]==a[i]:
        count+=1
    else:
        result+=int(count/2)
        count=1
result+=int(count/2)
print(result)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))

i=1
count=0

while i<n:
  if a[i]==a[i-1]:
    count+=1
    i+=2
  else:
    i+=1

print(count)

Submission status: Accepted

Solution code:
N=int(input().strip())
A=list(map(int,input().split()))
i=1
ct=0
while i<N:
    if A[i]==A[i-1]:
        ct+=1
        i+=2
    else:
        i+=1
print(ct)

Submission status: Accepted

Solution code:
n=int(input());a=list(map(int,input().split()));i=l=0
while True:
  if i>n-1:break
  j=i
  while j<n-1 and a[j+1]==a[j]:j+=1
  l+=(j-i+1)//2;i=j+1
print(l)

Submission status: Accepted

Solution code:
n=int(input())
numbers=list(map(int,input().split()))
count=1
c=0
for i in range(n-1):
  if numbers[i] is numbers[i+1]:
    count+=1
  else:
  	c+=count//2
  	count=1
if count-1:
	c+=count//2
print(c)

Submission status: Accepted

Solution code:
def getinputdata():

    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

arr=[int(arr_data[1][x]) for x in range(n)]

cnt=0
for i in range(0,n-1):
    
    if arr[i]==arr[i+1]:
        
        arr[i+1]=0
        cnt+=1
        
print(cnt)

Submission status: Accepted

Solution code:
import collections
import random

N = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(1, len(a)):
    if a[i] == a[i-1]:
        count += 1
        random.seed(i)
        a[i] = random.randrange(0, 1)
print(count)

Submission status: Accepted

Solution code:
N = input()

v = map(int, raw_input().split(' '))

found = 0

i = 0
while i < N:
	j = i
	while j < N - 1 and v[i] == v[j + 1]:
		j += 1

	found += (j - i + 1) / 2

	i = j + 1

print found

Submission status: Accepted

Solution code:
#agc026a

n=int(raw_input())
a=map(int,raw_input().split())
a.append(0)
cnt=0
temp=1
for i in xrange(1,n+1):
 if a[i]==a[i-1]:
  temp+=1
 else:
  cnt+=temp/2
  temp=1
print cnt

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
l = [{a[0]:1}]
ans = 0
for i in a[1:]:
    k = l[-1]
    if k.get(i):
        k[i] += 1
        a[-1] = k
    else:
        k = {i:1}
        l.append(k)
for d in l:
    for i in d.values():
        ans += i // 2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
t = 0
while t < N-1:
    if A[t] == A[t+1]:
        ans += 1
        t += 2
    else:
        t += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
ans = 0.1
for i in range(N-1):
	if a[i] == a[i+1]:
		ans = ans + 0.5
	else:
		ans = round(ans)+0.1
print(round(ans))

Submission status: Accepted

Solution code:
# AtCoder Grand Contest 026 A
SLIME_NUMBER = int(input())
SLIMES = tuple([int(s) for s in input().split()])

magic = 0

def is_repetitive(index):
    if index == SLIME_NUMBER - 1:
        return False
    return SLIMES[index] == SLIMES[index + 1]

index = 0
while index < SLIME_NUMBER - 1:
    if not is_repetitive(index):
        index += 1
        continue
    magic += 1
    additional_index = 1
    while is_repetitive(index + additional_index):
        if additional_index % 2 == 0:
            magic += 1
        additional_index += 1
    index += additional_index + 1
print(magic)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())

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

back = -1
same = 1
ans = 0
for a in A:
    if a==back:
        same+=1
    else:
        ans += same//2
        same=1
    back = a
    
ans += same//2
    
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))

count=0
for i in range(len(a)-1):
    if a[i]==a[i+1]:
        a[i+1]=-1
        count+=1

print(count)

Submission status: Accepted

Solution code:
import sys

n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
i, c = 1, 0
while i < n:
    if a[i] == a[i-1]:
        c += 1
        i += 2
    else:
        i += 1
print(c)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int, input().split()))
count=0
ans=0
while count<n-1:
    if a[count]==a[count+1]:
        ans+=1
        count+=1
    count+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
i = 0
ans = 0
while i < n-1:
    if a[i] == a[i+1]:
        ans += 1
        i += 2
    else:
        i += 1
print(ans)

Submission status: Accepted

Solution code:
N = input()
a = input()

a = a.split(" ")

ans = 0

for i in range(1, len(a)):
    if a[i-1] == a[i]:
        a[i] = "a"
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]

l = []

c = 1
for i in range(1,n):
    if a[i] == a[i-1]:
        c += 1
    else:
        l.append(c)
        c = 1
    if i == n-1:
        l.append(c)

ans = 0

for x in l:
    if x != 1:
        ans += x // 2

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int,input().split()))
ans = 0

for i in range(n - 1):
    if arr[i] == arr[i + 1]:
        arr[i + 1] = -i
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split())) + [None]
cnt = 0
ret = 0
for i in range(N):
    cnt += 1
    if A[i] != A[i + 1]:
        ret += cnt // 2
        cnt = 0

print(ret)

Submission status: Accepted

Solution code:
input()
slimeList = list(map(int, input().split()))
result = 0
count = 1
tmpSlime = slimeList[0]
for nextSlime in slimeList[1:]:
  if tmpSlime == nextSlime:
    count += 1
  else:
    result += count // 2
    count = 1
    tmpSlime = nextSlime
result += count // 2
print(result)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
count=0
for i in range(1,N):
    if A[i-1]==A[i]:
        A[i]=100000000
        count+=1
    else:
        pass
print(count)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
s = [a[0]]
cnt = 1
res = 0
for i in range(1, len(a)):
    if a[i-1] != a[i]:
        res += cnt // 2
        cnt = 1
        s.append(a[i])
    else:
        cnt += 1
res += cnt // 2
print(res)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    count = 0

    for i in range(1, n):
        if (a[i-1] == a[i]):
            a[i] = -1
            count += 1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    magic_count = 0
    previous_slime = a[0]

    # See:
    # https://beta.atcoder.jp/contests/agc026/submissions/2841276
    for i in range(1, n):
        if a[i] == previous_slime:
            magic_count += 1
            previous_slime = -1
        else:
            previous_slime = a[i]

    print(magic_count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    magic_count = 0
    slime_count = 1
    previous_slime = a[0]

    for i in range(1, n):
        if a[i] == previous_slime:
            slime_count += 1
        else:
            magic_count += slime_count // 2
            slime_count = 1

        previous_slime = a[i]

    print(magic_count + slime_count // 2)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))

cnt = 0
prev = a[0]
for i in range(1, N):
    if prev == a[i]:
        a[i] = -1
        cnt += 1
    prev = a[i]
print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
a=list(input().split())
a.append('E')
t='S'
c=0
s=0

for i in a:
  c+=1
  if i !=t:
    t=i
    s+=c//2
    c=0
print(s)

Submission status: Accepted

Solution code:
N = int(input())

slime = list(map(int, input().split()))
ans = 0 
flag = 0
for s,t in zip (slime[:-1],slime[1:]):
  if flag == 1:
    flag = 0
  else:
    if s == t:
      ans += 1
      flag = 1
      
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))

ans = []

i = 1
adjacent = 1

while i < n:
  if a[i] == a[i - 1]:
    adjacent += 1
  else:
    ans.append(adjacent // 2)
    adjacent = 1
  i += 1
  
ans.append(adjacent // 2)
print(sum(ans))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
i,ans = 0,0
while i<n-1:
	if a[i]==a[i+1]: ans,i = ans+1,i+2
	else: i+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(raw_input())
s = map(int, raw_input().split())
ct = 0
i = 1
while i < n:
    if s[i] == s[i-1]:
        ct += 1
        i += 2
    else:
        i += 1
print ct

Submission status: Accepted

Solution code:
input()
z = x = 0
for i in raw_input().split():
	if i == x:
		z += 1
		x = 0
	else:
		x = i
print z

Submission status: Accepted

Solution code:
N=int(input())
s=list(input().split())
count=0
while len(s)>1:
    a=0
    if s[0]!=s[1]:
        s.pop(0)
    else:
        while len(s)>=2 and s[0]==s[1]:
            a+=1
            s.pop(0)
        else:
            count+=(a+1)//2
print(count)

Submission status: Accepted

Solution code:
n=int(input())

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

now=a[0]
c=1

ans=0

for i in range(1, n):
    if now==a[i]:
      c+=1
    else:
      now=a[i]
      ans+=c//2
      c=1
else:
    ans+=c//2
      
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))

count=0

for i in range(1,n):
    if a[i]==a[i-1]:
        count += 1
        a[i]=0

print(count)

Submission status: Accepted

Solution code:
def main():
    """
    2 <= N <= 100
    1 <= ai <= N

    色の種類は10^4存在するが、N<=100より色は気にしなくて良い
    もし2色なら奥の色を考慮する必要がある

    abab: 0
    aaab: 1 (abab)
    aabb: 2 (acbc)
    aaaa: 2 (acac)
        2つ目のaを変更したあと、2と3つ目の関係を気にする必要がないので4つ目を考える
        4つ目を考慮することで3/5との関係を考慮できる
    """
    N = int(input())
    *A, = map(int, input().split())

    # A.append(-1)
    ans = 0
    i = 1
    while i < N:
        if A[i-1] == A[i]:
            ans += 1
            i += 2
        else:
            i += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))

answer = 0
t = 0
cursor = 0
while cursor != N:
    # print("X {} {}".format(t, a[cursor]))
    if t == a[cursor]:
        answer += 1
        t = 0
    else:
        t = a[cursor]
    cursor += 1
    # print(t)

print(answer)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(ai) for ai in input().split()]

count = 0
for i in range(0, N-1):
    if a[i] == a[i+1]:
        count += 1
        a[i+1] = float('inf')
print(count)

Submission status: Accepted

Solution code:
import random
N = int(input())
a = [int(ai) for ai in input().split()]

random.seed(42)
count = 0
for i in range(0, N-1):
    if a[i] == a[i+1]:
        count += 1
    while a[i] == a[i+1]:
        a[i+1] = random.randint(1, N)
        if i < N - 2:
            while a[i+1] == a[i+2]:
                a[i+1] = random.randint(1, N)

print(count)

Submission status: Accepted

Solution code:
N = int(input())
a = [s for s in map(int, input().split())]
a.append(-1)
c = 0
result = 0
for i in range(1, N + 1):
	if a[i] == a[i - 1]:
		c += 1
	else:
		if c == 0:
			continue
		else:
			c += 1
			if c % 2 == 1:
				result += (c - 1) / 2
				c = 0
			else:
				result += c / 2
				c = 0
print(int(result))

Submission status: Accepted

Solution code:
n = int(input())
slimes = list(map(int, input().split()))

ans = 0
for i in range(1, n):
    if slimes[i] == slimes[i-1]:
        ans += 1
        slimes[i] = 999

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))

counter = 0
for i in range(N-1):
    a1 = A[i]
    a2 = A[i+1]
    if a1 == a2:
        counter += 1
        A[i+1] = float('inf')

print(counter)

Submission status: Accepted

Solution code:
n = int(input())
nums = list(map(int, input().split()))
cnt = 1
ans = 0
for i in range(n-1):
    if nums[i+1] == nums[i]:
        cnt += 1
    else:
        if cnt > 1:
            ans += cnt // 2
        cnt = 1
if cnt > 1:
    ans += cnt // 2
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
colors = list(map(int, input().split()))
# n = 14
# colors = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 1, 2, 3, 4]
ans = []
i = 0
cnt = 0
while True:
    if i == n-1:
        cnt += 1
        ans.append(cnt)
        break
    if colors[i] != colors[i+1]:
        cnt += 1
        ans.append(cnt)
        cnt = 0
    else:
        cnt += 1
    i += 1


ans = list(map(lambda x: x //2, ans))
print(sum(ans))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))

result = 0
mode = 0
for i in range(1, n):
	if a[i] == a[i - 1]:
		if mode == 0:
			result += 1
			mode = 1
		else:
			mode = 0
	else:
		mode = 0

print(result)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.append(-1)
ans=0
cnt=1
for i in range(n):
    if a[i]==a[i+1]:
        cnt+=1
    else:
        ans+=cnt//2
        cnt=1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

def getInput():
    N = int(input())
    in_row = [ int(x) for x in input().split(" ") ]
    return N, in_row

def checkNext(tail):
    cnt = 1
    for val in tail[1:]:
        if tail[0] == val:
            cnt += 1
        else:
            break
    return cnt

def countMagic(in_row):
    m_sum = 0
    i = 0
    while len(in_row) >= i-1:
        tmp = checkNext(in_row[i:])
        i += tmp
        m_sum += tmp // 2
    
    return m_sum

if __name__ == "__main__":
    N, in_row = getInput()
    print(countMagic(in_row))

Submission status: Accepted

Solution code:
N = int(input())
l = list(map(int,input().split(" ")))
num_n =[]
i=1
for j in range(N-1):
    if l[j] == l[j+1]:
        i+=1
    else:
        num_n.append(int(i/2))
        i=1
num_n.append(int((i+0.1)/2))
print(sum(num_n))

Submission status: Accepted

Solution code:
n = int(input())
x = input().split(' ')
l = [int(i) for i in x]

c = 0
'''
i = 0

while i+2 < len(l):
    if l[i] == l[i+1]:
        if l[i+1] == l[i+2]:
            print(i)
            c += 1
            i += 2
        else:
            print(i)
            c += 1
            i += 2
    else:
        if l[i+1] == l[i+2]:
            print(i)
            c += 1
            i += 2
'''

boon = False

for i in range(1,n):
    if not boon and l[i] == l[i-1]:
        c += 1
        boon = True
    else:
        boon = False

print(c)

Submission status: Accepted

Solution code:
n = int(input())
x = input().split(' ')
l = [int(i) for i in x]

c = 0

i = 0
while i+1 < n:
    if l[i] == l[i+1]:
        c += 1
        i += 2
    else:
        i += 1
print(c)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.append(-1)
p = -1
c = 1
ans = 0
for n in a:
    if n == p:
        c += 1
    else:
        ans += c // 2
        c = 1
    p = n
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    slimes = list(map(int, input().split()))
    ans = 0

    for i in range(1, N):
        if slimes[i-1] == slimes[i]:
            slimes[i] = 10001 + ans
            # assert slimes[i] != slimes[i-1]                                 
            # assert slimes[i] != slimes[i+1]                                 
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import random

n = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(1, n-1):
    if A[i] == A[i-1]:
        ans += 1
        while(1):
            A[i] = random.randrange(10000)+1
            if A[i] != A[i-1] and A[i] != A[i+1]: break

if A[-1] == A[-2]: ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a_tmp = input().split()
a = []
for _ in a_tmp:
    a.append(int(_))
ans = 0
same = 1
tmp = a[0]
for i in range(1, n):
    # print(i, same, ans)
    if tmp != a[i]:
        ans += same // 2
        same = 1
        tmp = a[i]
    else:
        same += 1
ans += same // 2
print(ans)

Submission status: Accepted

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
a=i2()
c=0
for i in range(n-1):
 if a[i]==a[i+1]:
   a[i+1]=-1
   c+=1
print(c)

Submission status: Accepted

Solution code:
N = int(input())
lis = list(map(int,input().split()))
l = []
i = 0
x = 0
while(True):
  if i == N-1:
    x += 1
    l.append(x)
    break
  if lis[i] != lis[i+1]:
    x += 1
    l.append(x)
    x = 0
  else:
    x += 1
  i += 1
s = 0
for i in l:
  s += (i//2)
print(s)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
for i in range(1, n):
    if a[i] == a[i - 1]:
        a[i] = -1
print(a.count(-1))

Submission status: Accepted

Solution code:
import random

N = int(input())
A = list(map(int, input().split()))

ch = A[0]
cnt = 1
R = 0
for i in range(1, N):
    
    if ch != A[i]:
        R += cnt // 2
        cnt = 1
        ch = A[i]
    else:
        cnt += 1

R += cnt // 2

print(R)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(1, n):
	if a[i] == a[i-1]:
		ans+=1
		a[i] = 10000
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
data = [stdin.readline().rstrip().split() for _ in range(2)]
count = 0
i = 0
while i + count+ 1 < int(data[0][0]):
    if (data[1][i + count+ 1] == data[1][i + count]):
        count = count + 1
    i = i + 1
print(count)

Submission status: Accepted

Solution code:
N = int(input())

p = None
chain = 0
cnt = 0

for a in map(int,input().split()):
  if a == p:
    chain += 1
  else:
    cnt += chain//2
    p = a
    chain = 1

cnt += chain//2

print(cnt)

Submission status: Accepted

Solution code:
N = int(raw_input())
a = map(int, raw_input().split())

before_a = 0
magic_number = 0
for a_i in a:
  if before_a == a_i:
    magic_number += 1
    before_a = 0
  else:
    before_a = a_i
print magic_number

Submission status: Accepted

Solution code:
 # -*- coding: utf-8 -*-

N = int(input())
aN = list(map(int, input().split()))

# 実はこんなシンプルで良かったなんて…
cnt = 0
for i in range(1, N):
	if aN[i] == aN[i-1]:
		cnt += 1
		# 左右と被らない数、を実際に探さないで-1ってことにしとく
		aN[i] = -1
print(cnt)

Submission status: Accepted

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

N = int(input())
A = [int(i) for i in input().split()] + [0]

count = 0
tmp = 1
for i in range(1, N+1):
    if A[i] == A[i - 1]:
        tmp += 1
    else:
        # 等しくなくなったら
        count += tmp // 2
        tmp = 1  # tmp のリセット

print(count)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))

count = 0
for i in range(1,len(a),1):
    if a[i - 1] == a[i]:
        a[i] = -1
        count += 1

print(count)

Submission status: Accepted

Solution code:
N = int(input())
A = input().split() + [0]

temp = 1
ans = 0
for i in range(1,N+1):
	if A[i] == A[i-1]:
		temp += 1
	else:
		ans += temp // 2
		temp = 1

print(ans)

Submission status: Accepted

Solution code:
n = input()
slimes = map(int, input().split())
res = 0
last = -1
cnt = 0
for slime in slimes:
    if slime != last:
        res += cnt // 2
        last = slime
        cnt = 1
    else:
        cnt += 1

res += cnt // 2

print(res)

Submission status: Accepted

Solution code:
input()
ans=x=0
for a in input().split():
    ans+=a==x
    x=a*(a!=x)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))

ans = 0
s_len = 1
for i in range(1, n): 
    if a[i] == a[i-1]:
        s_len += 1
    else:
        ans += (s_len // 2)
        s_len = 1
ans += (s_len // 2)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]

result = 0

for i in range(1, N):
    if A[i-1] == A[i]:
        result += 1
        A[i] = None

print(result)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.append(0)
tl=1
count=0
for i in range(n):
    if a[i]==a[i+1]:
        tl+=1
    else:
        count+=tl//2
        tl=1
print(count)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = 0
i = 1
while True:
    if i >= N:
        break
    if A[i] == A[i-1]:
        cnt += 1
        i += 1
    i += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())

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

res = 0
cnt = 1

for n in range(1, len(a)):
  if a[n-1] == a[n]:
    cnt += 1
  else:
    res += cnt//2
    cnt = 1
else:
  res += cnt//2

print(res)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
    
l = [1]
for i in range(1,len(a)):
  if a[i] == a[i-1]:
    l[-1] += 1
  else:
    l.append(1)

print(sum(map(lambda x: x // 2, l)))

Submission status: Accepted

Solution code:
N = int(raw_input())
a = map(int, raw_input().split())
ans = 0
i = 0
while i < N-1:
  if a[i] == a[i+1]:
    if i+2 < N and a[i] == a[i+2]:
      a[i+1] = 101+ans
    else:
      a[i] = 101+ans
    ans += 1
    i += 2
  else:
    i += 1
print ans

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]

p = a[0]
cont_cnt = 1
to_chg = 0

for i in range(1, N) :
    if p == a[i] :
        cont_cnt += 1
        p = a[i]
    else :
        if cont_cnt >= 2 :
            to_chg += cont_cnt // 2
            p = a[i]
            cont_cnt = 1
        else :
            p = a[i]

if cont_cnt >= 2 :
    to_chg += cont_cnt // 2
    p = a[i]
    cont_cnt = 1

print(to_chg)

Submission status: Accepted

Solution code:
n = int(input())
col = [int(i) for i in input().split()]

change = 0
i = 1
length = 1
while i < n:
    if col[i] == col[i-1]:
        length += 1
    else:
        change += length // 2
        length = 1
    i += 1
else:
    change += length // 2

print(change)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    ss = list(map(int, input().split()))

    if N <= 1:
        print(0)
        return
    a = ss.pop(0)
    count = 0
    for b in ss:
        if a == b:
            count += 1
            a = -1
        else:
            a = b
    print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
a = [int(x) for x in a]

i = 0
magic = 0
while(i < n):
	length = 1
	while(a[i] == a[i+1]):
		length += 1
		i += 1
		if(i == n-1):
			break
	magic += int(length / 2)
	i += 1
	if(i == n-1):
		break
print(magic)

Submission status: Accepted

Solution code:
input()
n=-1
res = 0
for i in input().split():
    if i == n:
        res+=1
        n=-1
    else:
        n = i
print (res)