Problem:


Score : 300 points

Problem Statement

There are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S.

Adjacent slimes with the same color will fuse into one larger slime without changing the color. If there were a slime adjacent to this group of slimes before fusion, that slime is now adjacent to the new larger slime.

Ultimately, how many slimes will be there?

Constraints

1 \leq N \leq 10^5

|S| = N

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the final number of slimes.

Sample Input 1

10
aabbbbaaca

Sample Output 1

5

Ultimately, these slimes will fuse into abaca.

Sample Input 2

5
aaaaa

Sample Output 2

1

All the slimes will fuse into one.

Sample Input 3

20
xxzaffeeeeddfkkkkllq

Sample Output 3

10



Sample input:
10
aabbbbaaca


Sample output:
5

Submission status: Accepted

Solution code:
import itertools
N = int(input()) 
strs= input()
x = [[k, len(list(g))] for k, g in itertools.groupby(strs)]
print(len(x))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = str(input())

X = N
A = list(str(S))
for i in range(N - 1):
    if A[i] == A[i + 1]:
        X -= 1
print(X)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
count = 1

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

print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
test_s = ''

for i in range(n-1):
  if s[i] == s[i+1]:
    # print('同じ')
    test_s += '0'
  else:
    # print('違う')
    test_s += '1'

result = int(test_s.count('1')) + 1
if result == 0:
    print(1)
else:
	print(result)

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
L=[]
if N!=1:
    for i in range(N-1):
        if S[i]!=S[i+1]:
            L.append(S[i+1])

print(len(L)+1)

Submission status: Accepted

Solution code:
n = int(input())
color = str(input())
count=1
for i in range(len(color)-1): 
    if color[i]!=color[i+1]:
        count += 1
    else:
            pass
print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
s.append(s[n-1])
sum = 1
for i in range(1,n+1):
    if s[i-1] != s[i]:
        sum += 1
print(sum)

Submission status: Accepted

Solution code:
n = int(input())
s = input()

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

Submission status: Accepted

Solution code:
a=input()
a=int(a)
b=input()
lis=[]
c=b[0]
flag=0
for i in range(a-1):
    if i>0:
        c=b[i]
    if b[i+1]==c:
        continue
    else:
        lis.append(b[i])
if len(lis)>1:
   flag=1
else:
    lis={"a"}
if flag==1:
     if lis[-1]!=b[-1]:
        lis.append(b[-1])

print(len(lis))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
s=list(s)
m=1
for i in range(n-1):
   if s[i] != s[i+1]:
      m += 1
   # else:

print(m)

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
for i in range(N-1):
    if S[i]==S[i+1]:
        S[i]='0'
S = [i for i in S if i != '0']
print(len(S))

Submission status: Accepted

Solution code:
N = int(input())
S = input()

# print(N)
# print(S)

ss = []
for i in range(N):
    # print(S[i])
    
    # print(len(ss))
    
    if len(ss) == 0:
        ss.append(S[i])
    else:
        # print(ss[len(ss) - 1])
        if S[i] != ss[len(ss) - 1]:
            ss.append(S[i])
    
# print(''.join(ss))
print(len(ss))

Submission status: Accepted

Solution code:
n=int(input())
s=input()

counter=1

for i in range(1,n):
	if s[i-1]!=s[i]:
		counter+=1

print(counter)

Submission status: Accepted

Solution code:
n = int(input())
s_list = input()

s_out = ''
for s in s_list:
  if len(s_out) == 0 or s_out[-1] != s:
    s_out += s
  else:
    pass
  
print(len(s_out))

Submission status: Accepted

Solution code:
import re
n = int(input())
s=input()
res = re.sub(r"(.)\1{1,}", 'z', s)
print(len(res))

Submission status: Accepted

Solution code:
N = int(input())
S = input()

color = 1
for i in range(0, N - 1): # i = 0, 1, ..., N-2
    if S[i] != S[i + 1]:
        color += 1

print(color)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
cnt=0
for i in range(N-1):
  if S[i]==S[i+1]:
    cnt+=1
A=N-cnt
print(A)

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
t = 1
for i in range(N-1):
  if S[i] != S[i+1]:
    t += 1
print(t)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
pre_color=None
ans=0
for i,color in enumerate(S):
    if color!=pre_color:
        ans+=1
    pre_color=color
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())

ans = [S[0]]

for i in range(N):
    if(ans[-1] != S[i]):
        ans.append(S[i])

print(len(ans))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
c=0
for i in range(N-1):
    if S[i+1]==S[i]:
        c += 1;
print(N-c)

Submission status: Accepted

Solution code:
N=int(input())
S=input()

s=S[0]
s_true=[]
s_true.append(S[0])
for i in range(1,N):
    if(s!=S[i]):
        s=S[i]
        s_true.append(S[i])

print(len(s_true))

Submission status: Accepted

Solution code:
N=int(input())
c=input()
#print(N,c)
total=1
for i in range(1,N):
 # print(c[i])
  if c[i-1]!=c[i]:
    total+=1
print(total)

Submission status: Accepted

Solution code:
n=int(input())
S=input()
count=1
for i in range(n-1):
    if(S[i]!=S[i+1]):
        count=count+1
print(count)

Submission status: Accepted

Solution code:
n=int(input())
s1=str(input())
ans=0
i=0
while(i<n):
	ans+=1
	j=i
	while(j<n and s1[i]==s1[j]):
		j+=1
	i=j
print(ans)

Submission status: Accepted

Solution code:
n=input()
s=input()
su=0
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        su+=1
print(su+1)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())

inputlist = list(S)
c_list = [0]*len(S)
# print(inputlist)
# print(c_list)

ans = 1

#文字が切り替わった回数カウント
for i in range(N):
#    print(inputlist[i-1])
    if i == N-1:
        break
    if inputlist[i] != inputlist[i+1]:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
colors = list(input())

count = 1
last_chr = colors.pop(0)

while len(colors) > 0:
  if(last_chr != colors[0]):
    count += 1
  last_chr = colors.pop(0)

print(count)

Submission status: Accepted

Solution code:
import re
N=int(input())
D=input()
ans=N
match=re.compile("(.)\\1{%d,}" % 1)
while True:
    m=match.search(D)
    if not m:
        break
    ans-=(len(m.group(0))-1)*(D.count(m.group(0)))
    D=D.replace(m.group(0),m.group(0)[0])

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
i = 0
j = 1
for i in range(N-1):
    if S[i] != S[i+1]:
        j = j + 1
        i = i + 1
    else:
        i += 1
print(j)

Submission status: Accepted

Solution code:
N = int(input())
S = input()

S = S + 'A'
last = S[0]
cnt = 0
for s in S[1:]:
    if last == s:
        continue
    else:
        cnt += 1
        last = s
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
a = [s[0]]

for i in range(1,n):
    if s[i] != s[i-1]:
        a.append(s[i])
        
print(len(a))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
stock = None
slime = 0

for n in range(N):
    if n == 0:
        stock = S[n]
        slime += 1
    else:
        if stock == S[n]:
            stock = S[n]
        else:
            stock = S[n]
            slime += 1

print(slime)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
r = ''
i=0
j=1
while(i<len(s)):
    while(j<len(s) and s[i]==s[j]):
        j+=1
    r += s[j-1]
    #print(r)
    i=j
    j=i+1
print(len(r))

Submission status: Accepted

Solution code:
N = int(input())
S = input()

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

slime = N - fusion

print(slime)

Submission status: Accepted

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


def solve(N: int, S: str):
    now = S[0]
    ans = 1
    for s in S[1:]:
        if now != s:
            ans += 1
            now = s
    print(ans)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
ans = 1
pre = S[0]

for s in S[1:]:
  if pre != s:
    ans += 1
  pre = s

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
slimes=input()
ans=0
for x in range(1,n):
	if slimes[x]!=slimes[x-1]:
		ans+=1
print(ans+1)

Submission status: Accepted

Solution code:
N = int(input())
S =list(input())

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

print(N)

Submission status: Accepted

Solution code:
n = int(input())
s = input()

cnt = 0
for i in range(n-2, -1, -1):
    if s[i] == s[i + 1]:
        cnt += 1
    else:
        s = s[0:i+1] + s[i+1+cnt:]
        cnt = 0

print(len(s[cnt:]))

Submission status: Accepted

Solution code:
#input
N = int(input())
S = str(input())

#output
pointer = 0
sum = 1
for i in range(N-1):
    if S[i+1] != S[i]:
        sum += 1
    pointer += 1

print(sum)

Submission status: Accepted

Solution code:
N = int(input())
S = input()

s = S[0]
a = [s]
i = 0
while i < len(S):
  if s != S[i]:
    s = S[i]
    a.append(s)
    
  i+=1
    
print(len(a))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
slime = list()
for val in s:
    slime.append(val)
sel = 0
while sel+1 != len(slime):
    if slime[sel] == slime[sel+1]:
        slime.pop(sel+1)
    else:
        sel += 1
print(len(slime))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
list_S = list(S)
number = N
if N > 1:
    for i in range(N - 1):
        if list_S[i] == list_S[i + 1]:
            number -= 1
print(number)

Submission status: Accepted

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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
#        for line in sys.stdin:
#            lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    n = [int(e) for e in lines[0].split(" ")][0]
    s = lines[1]

    return (n, s)


def solve(n, s):

    
    last = None
    result = []
    for i in range(n):
        if s[i] != last:
            result.append(s[i])
        last = s[i]


    if debug:
        log("result=%s" % result)
        
    return len(result) 


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, end=' ')
    else:
        print("%s" % result)

if __name__ == '__main__':

    main()

Submission status: Accepted

Solution code:
# ABC143 C
N = int(input())
S = input()
L = [s for s in S]

M = []
cnt = 0
ans_c = 0

if N == 1:
    print(1)
    exit()

for i in range(N-1):
    if L[i]==L[i+1]:
        cnt += 1
    else:
        ans_c += cnt
        cnt = 0
    if i == N-2:
        ans_c += cnt
print(N-ans_c)

Submission status: Accepted

Solution code:
import sys
N = int(input())
S = input()
if N == 1:
    print("1")
    sys.exit()
ans = 0
for i in range(N - 1):
    if S[i] != S[i + 1]:
        ans += 1
    if i == N - 2:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = []
i = 0
while i != n:
    cnt = 1
    for j in range(i+1,n):
        if s[i] == s[j]:
            cnt+=1
        else:
            break
    ans.append(s[i])
    if cnt>=2:
        i+=cnt
    else:
        i+=1

print(len(ans))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
T=len(S)
A=[]
for i in range(T-1):
  if S[i] != S[i+1]:
    A.append(S[i])
print(len(A)+1)

Submission status: Accepted

Solution code:
N = int(input())
S = input()

cnt = 1
col = S[0]

for i in range(1, N):
    if col != S[i]:
        col = S[i]
        cnt += 1

  

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
fusion = []
for i in range(N-1):
    if S[i+1] != S[i]:
        fusion +=(S[i])
fusion +=S[N-1]

print(len(fusion))

Submission status: Accepted

Solution code:
from sys import stdin
import re

N = int(stdin.readline())
S = stdin.readline()

tmp = " "
num = 0
for c in S:
    if tmp != c:
        num = num + 1

    tmp = c

# 改行文字文を引く
print(num - 1)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
    
ans = 0
before_c = None
    
for c in s:
    if before_c is None:
        before_c = c
    elif c == before_c:
        continue
    else:
        before_c = c
        ans += 1
            
if c == before_c:
    ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 1
for i in range(N-1):
    if S[i] != S[i+1]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
S.reverse()

result = []
pre = S.pop()
while len(S) > 0:
    x = S.pop()
    if pre != x:
        result.append(pre)
        pre = x
result.append(pre)

print(len(result))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
Ans=0
for i in range(len(S)-1):
    if S[i]!=S[i+1]:
        Ans+=1
print(Ans+1)

Submission status: Accepted

Solution code:
n=int(input())
s=str(input())
i=1
ans=1
while i<n:
	if s[i] != s[i-1]:
		ans=ans+1
	i=i+1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())

count = 0
temp = ""

for s in S:
    if s != temp:
        count += 1
    temp = s
print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
bef = ''
count = 0
for c in S:
    if bef != c:
        count += 1
        bef = c
print(count)

Submission status: Accepted

Solution code:
N = int(input())
A = list(input())

ans = 1
for i in range(N-1):
  if A[i] == A[i+1]:
    continue
  else:
    ans +=1
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
count = 0
for x in range(0,N-1):
    if S[x] == S[x+1]:
        count += 1
ans = len(S) - count
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()

pre = s[0]
ans = []
ans.append(pre)

for i in range(1,n):
    if not s[i] == pre:
        ans.append(s[i])
    pre = s[i]

print(len(ans))

Submission status: Accepted

Solution code:

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

ans = 0
tmp = s[0]
cnt = 1
pos = 0

while True:
    if cnt >= n:
        ans += 1
        break

    if s[cnt] != tmp:
        pos = cnt
        ans += 1
    
    tmp = s[cnt]
    cnt += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

_n = int(input())
_s = input()[:-1]
slist = [item for item in _s]


def chker(sl):
    if len(sl) == 1:
        print(1)
        return

    cnt = 1
    for i in range(1, len(sl)):
        if sl[i] != sl[i - 1]:
            cnt += 1

    print(cnt)


chker(slist)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
p=1
for i in range(0,n-1):
  if s[i]!=s[i+1]:
    p+=1
print(p)

Submission status: Accepted

Solution code:
from __future__ import division

n = input()
s = input()

n = int(n)

c = 1
for i in range(n-1):
    if s[i] != s[i+1]:
        c += 1

print( c )

Submission status: Accepted

Solution code:
N = int(input())
S = input()

cur = None

pat = 0
for c in range(N):
    if S[c] == cur:
        continue
    elif cur != None:
        cur = S[c]
        pat += 1
    elif c == N-1:
        pat += 1
    elif S[c] != cur:
        cur = S[c]
        pat += 1
print(pat)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())

for i in range(len(s)-1, 0, -1):
  if(s[i]==s[i-1]):
    del s[i]    

print(len(s))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 1
if len(S) == 1:
    print(1)
else:
    if len(S) == 2:
        if S[0] == S[1]:
            print(1)
        else:
            print(2)
    else:
        for x in range(len(S)-1):
            curr = S[x]
            if curr == S[x+1]:
                pass
            else:
                ans += 1
        print(ans)

Submission status: Accepted

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

N = int(input())
S = list(input())

count = 0

for i in range(N-1):
        if S[i] == S[i+1]:
                continue
        else:
                count = count +1 

print(str(count+1))

Submission status: Accepted

Solution code:
n = int(input())
ss = input()

ans = 0
sl = ''
for s in ss:
  if sl != s:
    ans += 1
    sl = s
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
count = 0
for i in range(len(s)-1):
	if s[i]==s[i+1]:
		count += 1
print(len(s)-count)

Submission status: Accepted

Solution code:
n=input()
s=list(input())

tmp=s[0]
i=0
cnt=1
flag=0
ss=[]
for i in range(1,len(s)):
    if s[i] != tmp:
        cnt+=1
        tmp = s[i]
        flag = 1
        # ss.append(s[i])
if flag == 0 and cnt ==0:
    cnt +=1

print(cnt)

Submission status: Accepted

Solution code:
def solve_c(n, s):
    res = 1
    for i in range(1, n):
        if s[i] != s[i - 1]:
            res += 1
    return res


def main():
    n = int(input())
    s = input()
    res = solve_c(n, s)
    print(res)


def test():
    assert solve_c(10, "aabbbbaaca") == 5
    assert solve_c(5, "aaaaa") == 1
    assert solve_c(20, "xxzaffeeeeddfkkkkllq") == 10


if __name__ == "__main__":
    test()
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
cnt = 1

for i in range(n-1):
    if s[i] != s[i+1]:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import sys

def main():

	args = sys.argv
	N = int(input())
	S = input()
	C = 1
	
	for i in range(0, N-1):
		if S[i] != S[i+1]:
			C = C+1
	print(C)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input().strip())
S = list(input().strip())

prev_char = ''
abr_str = ''
for c in S:
    if c == prev_char:
        pass
    else:
        abr_str += c
        prev_char = c

print(len(list(abr_str)))

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
S.append('end')
i = 0
while S[i] != 'end':
    if S[i] == S[i + 1]:
        del S[i]
    else:
        i += 1
print(str(len(S) - 1))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
stack=[]
for i in s:
  if not stack:
    stack.append(i)
  elif stack[-1]==i:
    stack.append(i)
    stack.pop()
  else:
    stack.append(i)
print(len(stack))

Submission status: Accepted

Solution code:
slime_count = input()
slime = input()

last_slime_count = 1


for i in range(int(slime_count) - 1):
    if slime[i:i+1] != slime[i+1:i+2]:
        last_slime_count += 1
        
print(last_slime_count)

Submission status: Accepted

Solution code:
n = int(input())
str = list(input())
total = 1

for i in range(n-1):
    if str[i] != str[i+1]:
        total += 1

print(total)

Submission status: Accepted

Solution code:
n = int(input())
c = input()
s = [c[i] for i in range(n)]
for i in range(n-1):

    if len(s) <= i+1:
        break

    while s[i] == s[i+1]:
        del(s[i+1])
        if len(s) <= i+1:
            break


print(len(s))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
l = []
for i in range(len(S)-1):
  if S[i] != S[i+1]:
    l.append(S[i])
l.append(S[len(S)-1])
print(len(l))

Submission status: Accepted

Solution code:
n = int(input())
S = [s for s in input()]
ans = []

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

print(len(ans)+1)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt=1
for i in range(n-1):
    if(s[i]==s[i+1]):
        continue
    else:
        cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
n = int(input()) #int
s = input() # str
import itertools
print(len(''.join(ch for ch, _ in itertools.groupby(s))))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
s_l=[s[i] for i in range(n)]
cnt=1
for j in range(1,n):
	if s_l[j]!=s_l[j-1]:cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
cnt = [0] * N
ans = []

for i in range(N-1):
    if S[i] == S[i+1]:
        cnt[i+1] = 1
for i in range(N):
    if cnt[i] == 0:
        ans.append(S[i])
print(len(ans))

Submission status: Accepted

Solution code:
n=int(input())
d=input()
D=list(d)
ans=1
if n==1:
	print(1)
else:
	for i in range(n-1):
		if D[i]!=D[i+1]:
			ans+=1
	print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())

last=s[0]
s.pop(0)
ans=1
for i in s:
	if last!=i:
		ans+=1
		last=i

print(ans)

Submission status: Accepted

Solution code:
import copy

N = int(input())
S = list(input())
l = copy.deepcopy(S)

for i in range(N-1):
  if S[i] == S[i+1]:
    l[i]=0
  
l_=[i for i in l if i!=0]
print(len(l_))

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
count=1
for i in range(1,N):
    if S[i] == S[i-1]:
        continue
    else:
        count+=1

print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())

if n>=2:

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

    print(n)

else:
    print("1")

Submission status: Accepted

Solution code:
N = int(input())
str = input()
count = N
z = 0
for i in str:
    if(z == N-1):
        break
    elif(i == str[z+1]):
        count -= 1
    z += 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
c = 1
for i in range(n-1):
    if s[i] != s[i+1]:
        c += 1
print(c)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
ans = [S[0]]
for i in range(1, N-1):
    if  i == 1 and ans[0] != S[i]:
        ans.append(S[i])
    elif ans[-1] != S[i]:
        ans.append(S[i])
if ans[-1] != S[-1]:
    ans.append(S[-1])
print(len(ans))

Submission status: Accepted

Solution code:
import sys


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


def main():
    N = int(input())
    S = input()

    prev = None
    ans = 0
    for ch in S:
        if ch != prev:
            ans += 1
            prev = ch

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = list(input())

temp = ""
length = 0

for s in S:
    if temp != s:
        length += 1
        temp = s

print(length)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
memo = None
ans = 0
for i in S:
  if i != memo:
    ans += 1
  memo = i
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input().split()
T = list(S[0])
def slime(N,T):
    n = 1
    for i in range(0,N-1):
        if T[i] != T[i+1]:
            n = n + 1
    return n
print(slime(N,T))

Submission status: Accepted

Solution code:
n = int(input())
slimes = list(input())
num=1

for i in range(n-1):
    if slimes[i]!=slimes[i+1]:
        num+=1




print(num)

Submission status: Accepted

Solution code:
from collections import deque

n = int(input())
S = input()
slimes = deque(list(S))

remaining_slimes = []
remaining_slimes.append(slimes.popleft())
while len(slimes) > 0:
    if remaining_slimes[-1] == slimes[0]:
        slimes.popleft()
    else:
        remaining_slimes.append(slimes.popleft())
print(len(remaining_slimes))

Submission status: Accepted

Solution code:
from collections import deque

N = int(input())
S = list(input())

queue = deque(S)
Ans = []

temp = queue.popleft()
Ans.append(temp)

while len(queue) != 0:
    if temp == queue[0]:
        queue.popleft()
    else:
        temp = queue.popleft()
        Ans.append(temp)

print(len(Ans))

Submission status: Accepted

Solution code:
import itertools
_= input()
l = input()
s = set(l)
ans = 0
sp = itertools.permutations(s, 2)
for i in sp:
    ans += l.count(''.join(i))
    
print(ans+1)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
pre = S[0]
ans = 1
for i in S[1:]:
    ans += 1 if i != pre else 0
    pre = i
print(ans)

Submission status: Accepted

Solution code:
def test():
    n = int(input())
    s = input()
    a = []
    for i in range(n-1):
        if s[i+1] != s[i]:
            a.append(s[i])
    a.append(s[n-1])
    print(len(a))


if __name__ == "__main__":
    test()

Submission status: Accepted

Solution code:
import re

N = int(input())
S = input()

color = S[0]
ans = 1
for i in range(1,N):
    if color != S[i]:
        color = S[i]
        ans += 1

print(ans)

Submission status: Accepted

Solution code:

N=int(input())
S=input()
ans=0

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

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
duplicate = 1

for i in range(len(s)):

    if i == 0:
        continue

    if s[i] == s[i - 1]:
        pass
    elif s[i] != s[i - 1]:
        duplicate += 1

print(duplicate)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())

if n == 1:
    print(1)
else:
    ss = []

    for i in range(1, n):
        #print(s[i])
        if s[i] != s[i-1]:
            ss.append(s[i])

    print(1+len(ss))

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
prevcolor = ""
ct = 0
for s in S:
    if s != prevcolor:
        ct+=1
        prevcolor=s

print(ct)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
num = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        continue
    else:
        num += 1
print(num)

Submission status: Accepted

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

total=1

for i in range(1,len(D)):
    if(D[i-1]!=D[i]):
        total+=1

print(total)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
cnt=1
s1=s[0]
for i in range(n-1):
    if s[i]!=s[i+1]:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
def Slimes(N, S):
    after = S[0]
    for i in range(1, N):
        if S[i] != after[-1]:
            after += S[i]
    return len(after)

N = int(input())
S = str(input())
print(Slimes(N, S))

Submission status: Accepted

Solution code:
n = int(input())
S = input()

ans = []
bef_color = ""
for s in S:
	if bef_color != s:
		bef_color = s
		ans.append(s)

print(len(ans))

Submission status: Accepted

Solution code:
slime_num = int(input())
slime_color = input()
color_list = []
for slime in slime_color:
    color_list.append(slime)
for slime in range(slime_num):
    if slime == slime_num - 1:
        break
    if color_list[slime]  == color_list[slime + 1]:
        color_list[slime] = ""
slime_color_ans = ""
for color in color_list:
    if color != "":
        slime_color_ans += color
print(len(slime_color_ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
s = input()
now = ' '
conter = 0
for i in s:
  if now != i:
    now = i
    conter += 1
print(conter)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
count = 0
for i in range(n-1):
    color1 = s[i]
    color2 = s[i+1]
    if color1 == color2:
        count += 1
print(n - count)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
ans = 1
a = s[0]
for i in range(1, n):
    if s[i] == a: continue
    else:
        ans += 1
        a = s[i]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
ans=n

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt=1
for i in range(n-1):
    if s[i] != s[i+1]:
        cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
a = int(input())
s = input()
k = "A"
r = ""
for c in s:
    if c != k:
        r += c
    k = c

print(len(r))

Submission status: Accepted

Solution code:
from collections import deque

N = int(input())
S = input()

new_s = []
flag = True
while flag:

    if len(S) == 1:
        new_s = [1]
        break

    new_s = []
    flag = False
    for i in range(len(S)-1):
        current_char = S[i]

        if current_char == S[i+1]:
            flag = True
            continue
            
        else:
            new_s.append(current_char)

    new_s.append(S[-1])
    S = new_s



print(len(new_s))

Submission status: Accepted

Solution code:
n = input()
s = input()

r = [True]

r.extend([s[i-1] != s[i] for i in list(range(1,len(s)))])
print(sum(r))

Submission status: Accepted

Solution code:
N=int(input())

S=input()
ans =1

for i in range(N-1):
    if S[i]!=S[i+1]:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from itertools import permutations, combinations,combinations_with_replacement,product
from fractions import Fraction as frac
import bisect
import heapq

import logging
logging.basicConfig(level=logging.DEBUG)

import sys
#input = sys.stdin.readline().rstrip

setrecursionlimit(1000000)

MOD = 10**9+7
INF = float('inf')

def main():
    N=int(input())
    S=input()

    ans=1
    pre_s=S[0]
    for i in range(1,len(S)):
        s=S[i]
        if pre_s!=s:
            ans+=1
        pre_s=s

    print(ans if ans !=0 else 1)
main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()

char = s[0]
ans = 1
for i in range(1, n):
  if char != s[i]:
    char = s[i]
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
prev, cnt = '', 0
for c in input():
    if c != prev: cnt += 1
    prev = c
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
var = N
for i in range(N-1):
  if S[i] == S[i+1]:
    var = var-1
print(var)

Submission status: Accepted

Solution code:
n = int(input())
s = input()

d = [0] * n
res = ""
for i in range(n):
    if(d[i] == 1):
        continue
    for j in range(1, n-i):
        if s[i] == s[i+j]:
            d[i+j] = 1
        else:
            break

    res += s[i]

print(len(res))

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
 
list = []
 
for i in range(len(S)):
  if len(list) == 0:
    list.append(S[i])
  else:
    if list[-1] == S[i]:
      continue
    else:
      list.append(S[i])


print(len(list))

Submission status: Accepted

Solution code:
n = int(input())
s = input()

cnt = 0
old = '*'
for i in range(len(s)):
    if s[i] != old:
        cnt += 1
        old = s[i]

print(cnt)

Submission status: Accepted

Solution code:
a = int(input())
b = input()
print(1+sum(1 for i in range(1,a) if b[i]!=b[i-1]))

Submission status: Accepted

Solution code:
N = int(raw_input())
S = str(raw_input())

r = [S[0]]

for i in range(1, N):
    if S[i] != S[i-1]:
        r.append(S[i])

print(len(r))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
same_str = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        same_str += 1
print(len(S)-same_str)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
sum = 0
pre = ''
for i in range(len(S)):
  if S[i] != pre:
    pre = S[i]
    sum += 1
print(sum)