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: Runtime Error

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

last = S[0]

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

Submission status: Runtime Error

Solution code:
n = int(input())
strg = input()
q =''
for i in range(1,n):
  if strg[i-1] != strg[i]:
    q+=strg[i-1]
if q[-1] != strg[-1]:
  q+=strg[-1]
print(len(q))

Submission status: Runtime Error

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


def solve(N: int, S: str):
    result = 0
    for s in set(S):
        regex = re.compile(f"{s}+")
        # print(regex.findall(S))
        result += len(regex.findall(S))
    print(result)

    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: Runtime Error

Solution code:
n = int(input())
s = input()
color = ""
for i in range(len(s)):
  if color != s[i]:
    color = s[i]
    count += 1
print(count)

Submission status: Runtime Error

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(n, 1, -1):
    for j in range(len(c)):
        a = a.replace(c[j] * i, c[j])
        print(a)
print(len(a))

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
i = 0
count = 0
while i <= N-1:
    while S[i] == S[i+1]:
      i += 1
      if i == N-1:
        break
    count +=1
    i +=1
    if i == N-1:
      count += 1
      break
print(count)

Submission status: Runtime Error

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

iii = []
iii.append(len(S))

def SSS():
    for i in range(0, N): 
        if S[i] == S[i + 1]: 
            del S[i]
    iii.append(len(S))
    if iii[0] == [1]:
        print(S)
    else:
        SSS()

SSS()

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
tmp = S[1]
ret = tmp
for i in S:
  if tmp == i:
    tmp = i
  else:
    ret += i
    tmp = i
print(len(ret))

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
i = 0
count = 0
while i <= N-1:
    while S[i] == S[i+1]:
      i += 1
    count +=1
    i +=1
    if i == N-1:
      count += 1
      break
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
last = ''
temp = 0

for i in range(N-1):
    if temp == S[i]:
        continue
    else:
        temp = S[i]
        last += S[i]
if S[-1] != S[-2]:
    last += S[-1]
    
print(len(last))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
last = ''
temp = ''

for i in range(N-1):
    if temp == S[i]:
        continue
    else:
        temp = S[i]
        last += S[i]
if S[-1] != S[-2]:
    last += S[-1]
    
print(len(last))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
idx = 0
tmp = s[1]
idx = 1
ans = 1
if n == 1:
    print(1)
else:
    while(idx<n):
        if s[idx]==tmp:
            idx += 1
        else:
            tmp = s[idx]
            idx += 1
            ans +=1
    print(ans)

Submission status: Runtime Error

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: Runtime Error

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

total = []

def yugo(st,x):
	if len(st) <= x + 1:
		return st[x]
		
	if st[x] == st[x + 1]:
		return yugo(st,x+1)
	else:
		return st[x] +  yugo(st,x+1)
	

print(int(len(yugo(S,0))))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
idx = 0
tmp = s[1]
idx = 1
ans = 1
while(idx<n):
    if s[idx]==tmp:
        idx += 1
    else:
        tmp = s[idx]
        idx += 1
        ans +=1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
i = 0
count = 0
while i < N:
    while S[i] == S[i-1]:
      i += 1
    count +=1
    i +=1
print(count)

Submission status: Runtime Error

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

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

print(len(s))

Submission status: Runtime Error

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

total = []

def yugo(st,x):
	if len(st) == x + 1:
		return st[x]
	if st[x] == st[x + 1]:
		return yugo(st,x+1)
	else:
		return st[x] +  yugo(st,x+1)
	

print(int(len(yugo(S,0))))

Submission status: Runtime Error

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

total = []

def yugo(st,x):
	if len(st) == x + 1:
		return st[x]
	if st[x] == st[x + 1]:
		return yugo(st,x+1)
	else:
		return st[x] +  yugo(st,x+1)
	

print(int(len(yugo(S,0))))

Submission status: Runtime Error

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

for a in range(N-2):
    for b in range(a + 1, N-1):
        for c in range(b + 1, N):
            if (abs(d[a]-d[b]) < d[c]) and (d[c] < d[a] + d[b]):
                num += 1

print(num)

Submission status: Runtime Error

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

total = []

def yugo(st,x):
	if len(st) == x + 1:
		return st[x]
	if st[x] == st[x + 1]:
		return yugo(st,x+1)
	else:
		return st[x] +  yugo(st,x+1)
	

print(len(yugo(S,0)))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
last = ''
temp = ''
for i in range(N-1):
    if temp == S[i]:
        continue
    else:
        temp = S[i]
        last += S[i]
if S[-1] != S[-2]:
    last += S[-1]
print(len(last))

Submission status: Runtime Error

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


while N!=1:
    for i in range(N-1):
        if S[i]==S[i+1]:
            S[i]='K'
            c=1
    if c==0:
        break
    while 'K' in S:
        S.remove('K')
        N-=1
        c=0
print(len(S))

Submission status: Runtime Error

Solution code:
from itertools import groupby

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

print(len(groupby(S)))

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
last = ''
temp = ''
for i in range(N-1):
    if temp == S[i]:
        continue
    else:
        temp = S[i]
        last += S[i]
if S[-1] != S[-2]:
    last += S[-1]
print(len(last))

Submission status: Runtime Error

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

def dp(i,ans):
  if i==N-1:
    return ans+1
  if s[i]!=s[i+1]:
    ans+=1
    return dp(i+1,ans)
  else:
    count=2
    ans+=1
    while i+count<=N-1 and s[i]==s[i+count]:
      count+=1
    if i+count==N:
      return ans
    if i+count==N-1 and s[N-2]!=s[N-1]:
      ans+=1
      return ans
    return dp(i+count,ans)
  
ans=0
print(dp(0,ans))

Submission status: Runtime Error

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

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


c = len(arr)
print(c)

Submission status: Runtime Error

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

list = []
befor

for i in 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: Runtime Error

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

arr = []
arr.append(s[1])
for i in range(n-1):
    if s[i+1] != s[i]:
        arr.append(s[i+1])
        
c = len("".join(arr))
if c == 0:
    print(1)
else:
    print(c)

Submission status: Runtime Error

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

current = ''
for i in range(n):
    if s[i] != current:
        after_fusion.append(s[i])
        current = s[i]

print(len(after_fusion)

Submission status: Runtime Error

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

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



        
c = len("".join(arr))
print(arr)
if c == 0:
    print(1)
else:
    print(c)

Submission status: Runtime Error

Solution code:
sed -n 2p | grep -o . | uniq | wc -l

Submission status: Runtime Error

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

arr = []

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

if s[-1] != s[-2]:
    arr.append(s[-1])

c = len("".join(arr))

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

Submission status: Runtime Error

Solution code:
import sys

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

if n == 1:
    if s[0] == s[1]:
        print(2)
    else:
        print(1)
    sys.exit()

count = 0
i = 0
while i < n - 1:
    if s[i] == s[i + 1]:
        count = count + 1
    i = i + 1

ans = n - count
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
ans = ''
i = 0
prev = ''
while i < n - 1:
    if prev != s[i]:
        ans += s[i]
    prev = s[i]
    if s[i] == s[i+1]:
        i += 2
    else:
        i += 1
if prev != s[i]:
    ans += s[i] 
print(len(ans))

Submission status: Runtime Error

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

arr = []

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

if s[-1] != s[-2]:
    arr.append(s[-1])

c = len("".join(arr))

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

Submission status: Runtime Error

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

import re


def nchars(s, n):
    """文字列 s に、同じ文字が n 個以上連続している部分文字列を見つける
    """
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  # カンマを取ると n 個ちょうどになる
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]
        
d = nchars(s, 2)
for d_ in d:
    n -= len(d_) - 1
print(n)n = int(input())
s = input()

import re


def nchars(s, n):
    """文字列 s に、同じ文字が n 個以上連続している部分文字列を見つける
    """
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  # カンマを取ると n 個ちょうどになる
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]
        
d = nchars(s, 2)
for d_ in d:
    n -= len(d_) - 1
print(n)

Submission status: Runtime Error

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