AtCoder Beginner Contest 143 - Slimes

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-----
10
aabbbbaaca

-----Sample Output-----
5

Ultimately, these slimes will fuse into abaca.

Difficulty: EASY

Starter code:

Solutions:
n = int(input())
sla = input()
ans = 1
for i in range(n - 1):
	if sla[i] != sla[i + 1]:
		ans += 1
print(ans)


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


from itertools import groupby
N = input()
S = input()
print(len(list(groupby(S))))


a = int(input())
b = input()
c = 0
for i in range(a - 1):
	if b[i] == b[i + 1]:
		c = c + 1
print(a - c)


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


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


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


_ = input()
s = input()
t = ''
a = 1
for i in range(len(s) - 1):
	if s[i] != s[i + 1]:
		a += 1
print(a)


input()
from itertools import *
print(len([x for x in groupby(input())]))


input()
S = input()
print(1 + sum((S[i] != S[i + 1] for i in range(len(S) - 1))))


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


import re
N = int(input())
S = input()
print(len(re.sub('(.)\\1+', '!', S)))


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


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


n = int(input())
s = input()
l = [s[0]]
for c in s:
	if c != l[-1]:
		l.append(c)
print(len(l))


input()
s = input()
(t, a) = (s[0], 1)
for c in s:
	if c != t:
		a += 1
		t = c
print(a)


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


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


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


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


a = int(input())
b = input()
s = 1
for (i, j) in zip(b, b[1:]):
	if i != j:
		s += 1
print(s)


from itertools import *
input()
s = input()
print(len(list(groupby(s))))


input()
S = input()
l = S[0]
c = 1
for i in S[1:]:
	if l != i:
		c += 1
		l = i
print(c)


N = int(input())
S = str(input())
cnt = 1
for i in range(1, N):
	if S[i] == S[i - 1]:
		pass
	else:
		cnt += 1
print(cnt)


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


N = int(input())
S = input()
print(sum((int(a != b) for (a, b) in zip(S, S[1:]))) + 1)


n = int(input())
a = input()
(ans, start) = (a[0], 1)
while start < n:
	if a[start - 1] != a[start]:
		ans += a[start]
	start += 1
print(len(ans))


from itertools import groupby
N = int(input())
s = input()
print(len(list(groupby(s))))


n = int(input())
s = '?' + input()
print(sum((s[i - 1] != s[i] for i in range(1, len(s)))))


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


import re
N = input()
S = input()
S_fusion = re.sub('([a-z])\\1*', '\\1', S)
print(len(S_fusion))


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


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


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


import itertools as it
n = input()
s = input()
print(len(list(it.groupby(s))))


from itertools import groupby
input()
print(sum(map(bool, groupby(input()))))


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


import re
(_, s) = open(0)
print(len(re.sub('(.)\\1+', '\\1', s)) - 1)


input()
cnt = 0
x = ''
for s in input():
	if x != s:
		cnt += 1
		x = s
print(cnt)


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


N = int(input())
S = input()
S = [i for i in range(N) if i == 0 or S[i] != S[i - 1]]
print(len(S))


input()
S = input()
t = ''
a = 0
for s in S:
	if s != t:
		a += 1
		t = s
print(a)


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


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)


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


N = int(input())
S = input()
count = 1
check = S[0]
for c in S:
	if c != check:
		count += 1
		check = c
print(count)


k = int(input())
s = input()
a = 1
for i in range(k - 1):
	if s[i] != s[i + 1]:
		a += 1
print(a)


N = int(input())
S = input()
tmp = ''
ls = []
for i in S:
	if i != tmp:
		ls.append(i)
		tmp = i
print(len(ls))


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


from itertools import groupby
n = int(input())
print(len(list(groupby(input()))))


from itertools import groupby
N = int(input())
S = input()
g = groupby(S)
print(len(list(g)))


N = int(input())
S = input() + '.'
print(sum([1 if S[i] != S[i + 1] else 0 for i in range(N)]))


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


n = int(input())
a = input()
ans = n
for i in range(1, n):
	if a[i - 1] == a[i]:
		ans -= 1
print(ans)


import re
N = input()
S = input()
slimes = re.sub('(.)\\1{1,}', 'X', S)
print(len(slimes))


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


(_, s) = open(0)
print(sum((s != t for (s, t) in zip(s, s[1:]))))


input()
import itertools
print(len(list(itertools.groupby(input()))))


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


(N, S) = open(0)
print(sum((s != t for (s, t) in zip(S, S[1:]))))


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


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)


N = int(input())
S = list(input())
ans = 0
print(sum((a != b for (a, b) in zip(S, S[1:]))) + 1)


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


N = int(input())
S = input()
current = ''
ans = ''
for s in S:
	if s != current:
		current = s
		ans += s
print(len(ans))


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


n = input()
s = input()
x = s[0]
ans = 1
for si in s:
	if x != si:
		ans += 1
		x = si
print(ans)


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)


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)


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


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


from itertools import *
n = int(input())
s = input()
print(len([k for (k, v) in groupby(s)]))


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)


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


X = int(input())
Y = input()
r = ''
a = 0
for i in Y:
	if r != i:
		r = i
		a += 1
print(a)


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


import itertools
n = int(input())
s = input()
d = itertools.groupby(s)
print(len(list(d)))


import re
N = int(input())
S = input()
t = re.sub('(.)\\1{1,}', 'X', S)
print(len(t))


N = int(input())
S = input()
print(sum((S[i] != S[i - 1] for i in range(1, N))) + 1)


N = int(input())
S = '#' + input()
s = 0
for i in range(N):
	s += S[i] != S[i + 1]
print(s)


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)


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


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


n = int(input())
s = input()
ans = 0
while s:
	s = s.lstrip(s[0])
	ans += 1
print(ans)


n = int(input())
ss = list(input())
import itertools
print(len(list(itertools.groupby(ss))))


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)


from fractions import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import heapq
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
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))


N = int(input())
S = input()
p = ''
r = 0
for s in S:
	if p != s:
		r += 1
		p = s
print(r)


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


a = input()
b = list(input())
print(len([n for (i, n) in enumerate(b) if i == 0 or n != b[i - 1]]))


N = int(input())
S = str(input())
c = ''
t = 0
for s in S:
	if s == c:
		t += 1
	c = s
print(N - t)


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


input()
(a, b) = (0, '')
for i in input():
	if b != i:
		b = i
		a += 1
print(a)


from itertools import groupby
_ = input()
print(len(tuple(groupby(input()))))


n = int(input())
s = input()
ans = 1
k = s[0]
for i in range(n):
	if k != s[i]:
		ans += 1
		k = s[i]
print(ans)


input()
S = input()
print(1 + sum((s1 != s2 for (s1, s2) in zip(S, S[1:]))))


N = int(input())
S = input()
print(sum((S[n] != S[n - 1] for n in range(1, N))) + 1)


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


(_, S) = (input(), input())
print(sum((1 for (a, b) in zip('0' + S, S) if a != b)))


n = int(input())
s = input()
p = s[0]
ans = s[0]
for w in s:
	if p != w:
		ans += w
	p = w
print(len(ans))


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


n = int(input())
s = input()
pre = ''
ans = 0
for c in s:
	if c != pre:
		ans += 1
	pre = c
print(ans)


a = int(input())
b = input()
s = 'gafa'
n = 0
for x in b:
	if x != s:
		n += 1
	s = x
print(n)


N = int(input())
S = input()
ans = 0
buf = ''
for l in S:
	if buf != l:
		buf = l
		ans += 1
	else:
		pass
print(ans)


N = int(input())
S = input()
K = 0
A = '*'
for s in S:
	if s != A:
		A = s
		K += 1
print(K)


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)


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


from itertools import *
(_, s) = open(0)
print(len(list(groupby(s))) - 1)


f = input
n = int(f())
s = f()
print(1 + sum((s[i] != s[i - 1] for i in range(1, n))))


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


import itertools
n = int(input())
s = input()
ans = ''
iter = itertools.groupby(s)
for (key, value) in iter:
	ans += key
print(len(ans))


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


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


import itertools
n = int(input())
s = input()
gr = itertools.groupby(s)
print(len(list(gr)))


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)


N = int(input())
S = input()
res = ''
pre = ''
for s in S:
	if pre != s:
		res += s
	pre = s
print(len(res))


from itertools import groupby
n = input()
s = input()
G = groupby(s)
print(len(list(G)))


def main():
	_ = int(input())
	S = input()
	ans = 0
	res = ''
	for s in S:
		if res == s:
			continue
		res = s
		ans += 1
	print(ans)

def __starting_point():
	main()
__starting_point()


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


from itertools import groupby
N = int(input())
S = input()
print(sum([1 for x in groupby(S)]))


n = int(input())
s = input()
d = 1
for i in range(n - 1):
	d += int(s[i] != s[i + 1])
print(d)


import re
_ = input()
print(len(re.sub('(.)\\1+', '\\1', input())))


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)


N = int(input())
text = input()
x = 1
for i in range(N - 1):
	if text[i] != text[i + 1]:
		x += 1
print(x)


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


n = int(input())
l = list(input())
t = 0
c = 0
for i in l:
	if i != t:
		c += 1
		t = i
print(c)


from itertools import groupby
n = int(input())
s = input()
g = groupby(s)
print(len(list(g)))


from itertools import groupby
N = int(input())
S = input()
G = groupby(S)
print(len(list(G)))


import itertools as i
(_, S) = open(0)
print(len(list(i.groupby(S))) - 1)


import itertools as i
N = int(input())
print(len([k for (k, v) in i.groupby(input())]))


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


import re
input()
s = input()
print(len(re.findall('(.)\\1*', s)))


input()
S = input()
ans = 1
now = S[0]
for s in S[1:]:
	if s != now:
		ans += 1
		now = s
print(ans)


n = int(input())
s = input()
a = ''
cnt = 0
for i in range(n):
	if i == 0:
		a += s[i]
		cnt += 1
	elif s[i] != a[-1]:
		a += s[i]
		cnt += 1
print(cnt)


n = int(input())
s = input()
ans = 1
for k in range(n - 1):
	ans += s[k] != s[k + 1]
print(ans)


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


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)


n = int(input())
s = input()
b = ''
s2 = 0
for m in s:
	if b != m:
		s2 += 1
	b = m
print(s2)


f = input
f()
import itertools as it
print(len(list(it.groupby(f()))))


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


N = int(input())
S = input()
m = 1
i = 0
while i < N - 1:
	if S[i] != S[i + 1]:
		m += 1
	i += 1
print(m)


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)


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


from itertools import groupby
N = int(input())
S = input()
ans = len(list(groupby(S)))
print(ans)


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


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


_ = input()
S = input()
k = 1
for (b, a) in zip(S[:-1], S[1:]):
	if b != a:
		k += 1
print(k)


from itertools import groupby
_ = input()
print(len(list(groupby(input()))))


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


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


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


n = int(input())
s = input()
print(len([a for (a, b) in zip(s, s[1:]) if not a == b]) + 1)


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


import sys
n = int(input())
a = input()
a = list(a)
a.reverse()
if n == 1:
	print('1')
	return
c = 1
for i in range(n - 1):
	if a[i] != a[i + 1]:
		c += 1
if c == 0:
	c += 1
print(c)


N = int(input())
S = input() + 'Q'
c = 0
for k in range(N):
	if S[k] != S[k + 1]:
		c += 1
print(c)


N = int(input())
S = list(input())
r = 1
for i in range(1, N):
	if not S[i - 1] == S[i]:
		r += 1
print(r)


from itertools import groupby
input()
print(sum((1 for _ in groupby(input()))))


import itertools
N = input()
S = input()
G = itertools.groupby(S)
print(len(list(G)))


input()
S = input()
ans = 1
k = S[0]
for s in S[1:]:
	if s != k:
		ans += 1
		k = s
print(ans)


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


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


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


from itertools import groupby
N = int(input())
S = input()
print(sum((1 for (k, _) in groupby(S))))


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


import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
input = sys.stdin.readline

def RD():
	return input().rstrip()

def F():
	return float(input().rstrip())

def I():
	return int(input().rstrip())

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

def MF():
	return map(float, input().split())

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

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

def LF():
	return list(map(float, input().split()))

def Init(H, W, num):
	return [[num for i in range(W)] for j in range(H)]

def main():
	N = I()
	S = input().rstrip()
	past = S[0]
	ans = 1
	for i in range(1, N):
		if past != S[i]:
			ans += 1
			past = S[i]
	print(ans)

def __starting_point():
	main()
__starting_point()


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)


N = int(input())
S = input()
print(1 + sum(map(lambda i: S[i] != S[i + 1], range(N - 1))))


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(500000)
INF = float('inf')
(YES, Yes, yes, NO, No, no) = ('YES', 'Yes', 'yes', 'NO', 'No', 'no')
(dy4, dx4) = ([0, 1, 0, -1], [1, 0, -1, 0])
(dy8, dx8) = ([0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1])

def inside(y, x, H, W):
	return 0 <= y < H and 0 <= x < W

def ceil(a, b):
	return (a + b - 1) // b

def sum_of_arithmetic_progression(s, d, n):
	return n * (2 * s + (n - 1) * d) // 2

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

def lcm(a, b):
	g = gcd(a, b)
	return a / g * b

def solve():
	N = int(input())
	S = input()
	ans = 1
	pre = S[0]
	for i in range(1, N):
		if S[i] != pre:
			ans += 1
			pre = S[i]
	print(ans)

def main():
	solve()

def __starting_point():
	main()
__starting_point()


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