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: Time Limit Exceeded

Solution code:
import sys
from io import StringIO
import unittest


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


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

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


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """10
aabbbbaaca"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """5
aaaaa"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """20
xxzaffeeeeddfkkkkllq"""
        output = """10"""
        self.assertIO(input, output)


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

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

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

print(len(after))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
input()
S = [i for i in input()]
flag = True
while flag:
  flag = False
  for i in range(0,len(S)-1):
    if S[i] == S[i+1]:
      del S[i]
      flag = True
      break
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(map(str,input().split()))
loc = 0
i = 1
ans = []
for _ in range(10**5):
    i += 1
    target = S[0][loc:i]
    if len(set(target)) > 1:
        ans.append(S[0][loc])
        loc = i - 1
    elif i >= N:
        ans.append(S[0][-1])
        break
        
if len(ans) == 0:
    print(1)
else:
    print(len(ans))

Submission status: Time Limit Exceeded

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


t=0
for i in range(N-1):
    if S[i-t+1] == S[i-t]:
        S.remove(S[i-t+1])
        t+=1
print(N-t)

Submission status: Time Limit Exceeded

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

total = []
Y = []

for i in range(N):
	if i == N-1:
		Y = Y + [S[i]]
		break
	if S[i] == S[i+1]:
		continue
	else:
		Y = Y + [S[i]]
		
print(len(Y))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(map(str,input().split()))
loc = 0
i = 1
ans = []
while(1):
    i += 1
    target = S[0][loc:i]
    if len(set(target)) > 1:
        ans.append(S[0][loc])
        loc = i - 1
    elif i >= N:
        ans.append(S[0][-1])
        break
        
if len(ans) == 0:
    print(1)
else:
    print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = str(input())
c = "a b c d e f g h i j k l m n o p q r s t u v w x y z"
c = list(c.split())
for i in range(int(n**0.5), 1, -1):
    for j in range(len(c)):
        a = a.replace(c[j] * 5, c[j])
        a = a.replace(c[j] * 3, c[j])
        a = a.replace(c[j] * 2, c[j])
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = input()
S=list(D)
C = 0
X = 0
i=0
while i < N-X-1:
	if S[i]==S[i+1]:
		S.pop(i)
		i=0
		X+=1
	else:
		i+=1

print(len(S))

Submission status: Time Limit Exceeded

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

# In[30]:


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


# In[32]:


dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]


# In[33]:


del_list = []
for i in range(N-1):
    #print(i)
    if S[i] == S[i+1]:
        del_list.append(i)
ans = len(dellist(S, del_list))
print(ans)


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
h = str(input())
h = list(h)
h2 = list(h)
def mojiretu(n, h):
    for i in range(0, len(h) - 1):
            if h[i] == h[i + 1]:
                h2.remove(h[i])
    return len(h2)
print(mojiretu(n,h))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [x for x in input()]

def p(S):
  s = len(S)
  e = 0
  while s != e:
    s = len(S)
    for i in range(s-1):
      if i >= len(S)-1:break
      if S[i] == S[i+1]:S.pop(i)
      e = len(S)
  return len(S)

print(p(S))

Submission status: Time Limit Exceeded

Solution code:
import re

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

rex = r'([^_])\1{0,}'
pattern = re.compile(rex)

matchobj = pattern.search(S)
while matchobj:
    S = pattern.sub("_", S, 1)
    matchobj = pattern.search(S)
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
import re
N = int(input())
S = input()
for _ in range(N):
    S = re.sub("(.)\\1", "\\1", S)
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
S = [x for x in S]

s = len(S)
e = 0
while s != e:
  s = len(S)
  for i in range(len(S)-1):
    if i >= len(S)-1:break
    if S[i] == S[i+1]:
      S = S[:i] + S[i+1:]
    e = len(S)

print(len(S))

Submission status: Time Limit Exceeded

Solution code:
slime_number = int(input())
slime_colors = list(input())

concatable = True

while concatable:
  if slime_number == 1:
     break
  i = 0
  while i < slime_number - 1:
    concatable = False
    if slime_colors[i] == slime_colors[i + 1]:
      slime_colors = slime_colors[:i] + slime_colors[i+1:]
      concatable = True
      slime_number -= 1
    else:
      i += 1
      
print(slime_number)

Submission status: Time Limit Exceeded

Solution code:
import re

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

rex = r'([^_])\1{0,}'
pattern = re.compile(rex)

matchobj = pattern.search(S)
while matchobj:
    S = S.replace(matchobj.group(), "_", 1)
    matchobj = pattern.search(S)
print(len(S))

Submission status: Time Limit Exceeded

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

li=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

for i in range(26):
    for j in range(1,N+1):
        S=S.replace(str((li[i])*(N+1-j)), str(li[i]))

print(len(S))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
i = 1
while i < len(s):
    if s[i] == s[i-1]:
        if i >= 2:
            s = s[:i-1] + s[i:]
        else:
            s =  s[i:]
        i = 1
    else:
        i += 1
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
for w in 'abcdefghijklmnopqrstuvwxyz':
  if S.find(w) != -1:
    while S.count(w) != 1:
      if S[S.find(w) + 1] == w:
        S.replace(w + w,w)
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
S = [x for x in S]

s = len(S)
e = 0
while s != e:
  s = len(S)
  for i in range(len(S)-1):
    if i >= len(S)-1:break
    if S[i] == S[i+1]:S.pop(i)
    e = len(S)

print(len(S))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ss=set(s)
l=[0]
for j in range(n):
    for i in ss:
        if l[0]!=s:
            s=s.replace(i*2,i)
            l[0]==s
        else:
            break
print(len(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = input()
s = list(input())
dif_s = s[1:]
s = s[:-1]

new_s = ''
for color1, color2 in zip(s, dif_s):
  if color1 != color2:
    new_s+=color2

print(len(new_s)+1)

Submission status: Time Limit Exceeded

Solution code:
dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]
n=int(input())
s=input()
ans=[]
for i in range(n-1):
    if s[i]==s[i+1]:
        ans+=[i+1]
v=dellist(s,ans)
print(len(v))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ss=set(s)
for j in range(n):
    for i in ss:
        s=s.replace(i*2,i)

print(len(s))

Submission status: Time Limit Exceeded

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

while True:
    count = 0
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            S.pop(i)
            count += 1
            break
    if count == 0:
        break

print(len(S))

Submission status: Time Limit Exceeded

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

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

print(len(compressed))

Submission status: Time Limit Exceeded

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

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

print(len(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

new_s = ''
tmp = ''
for i in s:
  if tmp != i:
    new_s = new_s + i
    tmp = i
  else:
    tmp = i
    continue
  
print(len(new_s))

Submission status: Time Limit Exceeded

Solution code:

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

def ran(num):
    count = 1
    result = ''
    for i in range(len(num)):
        try:
            if num[i] == num[i+1]:
               count = count + 1
            else:
                result = result + str(num[i])
                count = 1
        except:
            result = result + str(num[i])
            
    # 結果をprint
    return result

print(len(ran(S)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
ans = ''
for i in range(n):
  if i == 0:
    ans += s[i]
  elif ans[-1] != s[i]:
    ans += s[i]
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import re

def C():
    n = input()
    s = input()
    ss = ""
    for i in range(len(s)):
        if i != 0:
            if s[i] != s[i-1]:
                ss += s[i]
        else:
            ss += s[i]
    print(len(ss))

if __name__ == '__main__':
    C()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = ""
curr_set = ""
for i in range(n):
    if s[i] == curr_set:
        continue
    else:
        curr_set = s[i]
        ans=ans+s[i]
print(len(ans))

Submission status: Time Limit Exceeded

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

out = '0'

for i in s:
    if out[-1] != i:
        out += i

print(len(out) - 1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = ''

ans += s[0]
prev = s[0]

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

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
b4 = ""
ans = ""
#print(len(set(list(s))))
for i in s:
    if(b4!=i):ans+=i
    b4 = i
print(len(ans))

Submission status: Time Limit Exceeded

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

for i in reversed(range(1,n)):
    if strlist[i] == strlist[i-1]:
        strlist.pop(i)
print(len(strlist))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

    print(len(ans))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools

import queue
from collections import deque



def main():
    num = int(input())
    s = list(input())

    for i in range(1, num)[::-1]:
        if s[i] == s[i - 1]:
            s.pop(i)

    print(len(s))






if __name__ == '__main__':
    main()

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 = input()
tmp, val = '', []
for i in S:
    if i !=tmp:
        val.append(i)
        tmp = i
print(len(val))

Submission status: Accepted

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

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

print(len(ans))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
p = None
for letter in s:
    if letter != p:
        p = letter
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
tmp = S[0]
ans = 1
for n in range(1,N):
  if S[n] != tmp:
    ans += 1
    tmp = S[n]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input() + "Z"

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

Submission status: Accepted

Solution code:
def remove_slimes(ls):
	l = [ls[0]]
	for i in range(1, len(ls)):
		if ls[i-1] != ls[i]:
			l.append(ls[i])
	return len(l)

n = int(input())
s = input()
cnt = 1
if len(s) != 1:
	cnt = remove_slimes(list(s))
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
n = int(input())
c = input()
ans = 1

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

Submission status: Accepted

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


current = ""
ans = ""
for s in S:
    if s != current:
        current = s
        ans += s

print(len(ans))
# print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC 132 C
N = int(input())
S = str(input())
ans = 1
s = list(map(str, str(S)))

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()

ans = 0
buf = ""
for l in S:
    if buf != l:
        buf = l
        ans += 1
    else:
        pass
print(ans)

Submission status: Accepted

Solution code:
rst = []
N = int(input())
S = input()
tmp_val = ''
for i in S:
    if tmp_val != i:
        rst.append(i)
        tmp_val = i
print(len(rst))

Submission status: Accepted

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

# 隣接するスライムは同色なら融合し1体に
count = 0
color = ''
for c in S:
  if c != color:
    color = c
    count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

c=n

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

print(c)

Submission status: Accepted

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

print(len(set(color)))

Submission status: Accepted

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

while len(S)>1:
	if S[0]==S[1]:
		S.pop(0)
	else:
		ans.append(S.pop(0))

print(len(ans)+1)

Submission status: Accepted

Solution code:
import sys

n=int(input())
a=input()
a=list(a)
a.reverse()
if n==1:
    print('1')
    sys.exit()
    
c=1


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

if c==0:
    c+=1
    
print(c)

Submission status: Accepted

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

a = ""
cnt = 0
for i in range(n):
    if i==0:
        a += s[i]
        cnt += 1
    else:
        if s[i] != a[-1]:
            a += s[i]
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
slime_end = "0"
num = 0
for i in range(n):
    if s[i] != slime_end:
        num += 1
        slime_end = s[i]
print(num)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
now=0
num=0
for char in S:
    if char!=now:
        num+=1
        now=char
print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=list(map(str,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(map(str,input()))
i=0
while i!=(len(S)-1):
    if S[i]==S[i+1]:
        S.pop(i+1)
    else:
        i+=1
print(len(S))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(count+1)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
i = 0
count = 1
con_s = 0

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

Submission status: Accepted

Solution code:
N=int(input())
S=input()
x=1
for i in range(0,N):
    if i<N-1 and S[i]!=S[i+1] :
        x=x+1
print(x)

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())
for i in range(len(s)-1,0,-1):
    if s[i]==s[i-1]:
        s.pop(i)
print(len(s))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
bef = ""
ans = 0
for s in input():
  if bef != s:
    ans += 1
    bef = s
print(ans)

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

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

count = 1
current = None

for s in slimes:
  if current is None:
    current = s
    next
  if current != s:
    count +=1
  current = s
    
print(count)

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
ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
count = 1
check = S[0]

for c in S:
  if c != check:
    count += 1
    check = c

print(count)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
S = list(input())
L = [k for k, v in itertools.groupby(S)]
print(len(L))

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
count = 1

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

print(count)

Submission status: Accepted

Solution code:
n = int(input())
slimes = input()
fusion = [slimes[0]]

cnt = 0

for i in range(1,n):
    if fusion[cnt] != slimes[i]:
        fusion.append(slimes[i])
        cnt += 1

print(cnt+1)

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
print(n-cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
for i in range(n-1):
  if s[i] == s[i+1]:
    s = s[:i] + " " + s[i+1:]
print(len(s.replace(" ", "")))

Submission status: Accepted

Solution code:
n=int(input())
s=str(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())
cn = 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

s = input()

ans = 1

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

print(ans)

Submission status: Accepted

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

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:
num = int(input())
str1 = input()
table = list(str1)
ans = []

for i in range(num-1):
    if table[i] == table[i+1]:
        continue
    else:
        ans.append(table[i])

print(len(ans) + 1)

Submission status: Accepted

Solution code:
n = int(input())
s = [i for i in input()]
result  = []
tmp = '¥'
for i in range(0,n):
    if tmp != s[i]:
        result.append(s[i])
        tmp = s[i]
print(len(result))

Submission status: Accepted

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

Submission status: Accepted

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

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(ANS + 1)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
ans = n
for i in range(1,n):
    if s[i-1] == s[i]:
        ans -= 1
print(ans)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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



for x in range(1,n):
  if s[x] == s[x-1]:
    n -= 1

print(n)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
s=list(input())
ans=0
for i in range(n-1):
    if s[i]!=s[i+1]:
        ans+=1
print(ans+1)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
S = ['_']+list(input())

ans = 0
for i in range(1, N+1):
    if S[i-1]!=S[i]:
        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 + 1] != S[i]:
        ans += 1
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n = I()
s = input()
ans = ""
prv = None
for i in range(n):
    if i == 0:
        prv = s[i]
        ans += s[i]
        continue
    if s[i] == prv:
        continue
    else:
        prv = s[i]
        ans += s[i]
print(len(ans))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
now = -1
for s in S:
    if now == s:
        N -=1
    now = s
print(N)

Submission status: Accepted

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

res = ""
pre = ""
for s in S:
    if pre != s:
        res += s
    pre = s

print(len(res))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
N = int(input())
S = list(input())
gr = list(itertools.groupby(S))
print(len(gr))

Submission status: Accepted

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

Submission status: Accepted

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

for s in S:
    if pre != s:
        ans += 1
    pre = s
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = input()
ans = ""
for s in S:
    if ans == "" or ans[-1] != s: ans += s
print(len(ans))

Submission status: Accepted

Solution code:
N=int(input())
arr=list(map(str,input()))

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
 
# N=O(10^5)なのでO(N)で解く
# 連続する同じ文字を1つのグループと見るときに、何グループできるか？
# 文字が変化する点に着目すればよい。するとグループ数は（変化点+1）個と求まる！
 
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())

# N=O(10^5)なのでO(N)で解く
# 同じ文字を1つのグループと見るときに、何グループできるか？
# 文字が変化する点に着目すればよい。するとグループ数は（変化点+1）個と求まる！

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 02:34:35 2020

@author: liang
"""

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

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

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
A = [0] * N
same = False
import math
for i in range(1, N):
  if S[i] == S[i-1]:
    same = True
  elif same and S[i] != S[i-1]:
    A[i] = 1
    same = False
  else:
    same = False
    A[i] = 1
    
print(sum(A)+1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys

INF = float('inf')


def solve(N: int, S: str):
    return len([c for i, c in enumerate(S) if i == 0 or c != S[i-1]])


def main():

    sys.setrecursionlimit(10 ** 6)

    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
    print(f'{solve(N, S)}')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
s=str(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())
a = list(input())
count = 1
for i in range(N):
  if i>0:
    if a[i-1]==a[i]:
      pass
    elif a[i-1]!=a[i]:
      count+=1
      
print(count)

Submission status: Accepted

Solution code:
def main():
    import sys
    readline = sys.stdin.buffer.readline

    n = int(readline())
    s = readline().rstrip().decode('utf-8')

    l = ''
    ans = 0
    for i in s:
        if i != l:
            l = i
            ans += 1 
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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