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 bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
s = S()
ans = 0
before = ''
for i in range(N):
    if before != s[i]:
        before = s[i]
        ans +=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
import itertools
gr = itertools.groupby(s)
cnt = 0
for key in gr:
    #print({key})
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
#print(N)

S = input()

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

if count == 0:
    print(1)
else:
    print(count+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

ans = []
a = ""
for i, s in enumerate(S):
    if a != S[i]:
        ans.append(S[i])
        a = S[i]

print(len(ans))

Submission status: Accepted

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

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()
for i in range(n-1):
  if s[i]==s[i+1]:
    n-=1
print(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import groupby
n= input()
s = input()
G = groupby(s)

print(len(list(G)))

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

Submission status: Accepted

Solution code:
# C - Slimes
def main():
    n = int(input())
    s = input()
    p = ''
    ans = ''

    for v in s:
        if v != p:
            ans += v
            p = v
        else:
            continue
    print(len(ans))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
l=list(i())
ans=1
for i in range(a-1):
  if l[i]!=l[i+1]:
    ans+=1
print(ans)

Submission status: Accepted

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

ans=1
now=S[0]
for s in S[1:]:
    if now!=s:
        now=s
        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:
n = int(input())
s = input()

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

slime = []
slime.append(s[0])
for i in range(1, n):
    if s[i-1] == s[i]:
        continue
    else:
        slime.append(s[i])

print(len(slime))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def actual(n, s):
    count = 0
    last_color = ''

    for color in s:
        if last_color != color:
            last_color = color
            count += 1

    return count

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

print(actual(n, s))

Submission status: Accepted

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

Submission status: Accepted

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

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:
n = int(input())
s = input()

ans = ''
seek = 0

while seek < n:
    first = seek
    while seek < n and s[seek] == s[first]:
        seek += 1
    ans += s[first]

print(len(ans))

Submission status: Accepted

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

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

print(N - minus)

Submission status: Accepted

Solution code:


n = int(input())

s = input()


count = 1



for h in range(len(s)-1):
 
    if s[h] != s[h+1]:
        count += 1

print(count)

Submission status: Accepted

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

print(len(ans) - 1)

Submission status: Accepted

Solution code:
def ra(a): #圧縮された要素を非保持
    ll,l=[],1
    for i in range(len(a)-1):
        if a[i]==a[i+1]:
            l+=1
        else:
            ll.append(l)
            l=1
    ll.append(l)
    return ll
n=input()
print(len(ra(input())))

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+=1

print(count)

Submission status: Accepted

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

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 += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(len(S)-1):
    if i == len(S)-2 and S[i] != S[i+1]:
        S_.append(S[i])
        S_.append(S[i+1])
    elif i == len(S)-2 and S[i] == S[i+1]:
        S_.append(S[i])
    elif S[i] != S[i+1]:
        S_.append(S[i])
if len(S_) == 0:
    print('1')
else:
    print(len(S_))

Submission status: Accepted

Solution code:
N = int(input())
S = input() + '*'
ret = 0
for s1, s2 in zip(S, S[1:]):
    if s1 != s2:
        ret += 1
print(ret)

Submission status: Accepted

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

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

cnt = 1

check = S[0]

for i, s in enumerate(S[1:]):
    if s == check:
        if i == N - 1:
            cnt += 1
        continue
    else:
        cnt += 1
        check = s

print(cnt)

Submission status: Accepted

Solution code:
import os, sys, re, math

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 = input()
flg = True
pre = '1'
cnt = 0
for c in s:
	if c != pre:
		cnt += 1
		pre = c
print (cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
last = ''
ret = 0
for c in s:
    if last != c:
        ret += 1
    last = c
print(ret)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
prev = None
ans = 0
for i in range(n):
  ans += prev != s[i]
  prev = s[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

N = int(readline())
S = readline()

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()
s=[]
for i in S:
    s.append(i)
ans=[s[0]]
for i in range(1,n):
    if s[i]==s[i-1]:
        pass
    else:
        ans.append(s[i])
print(len(ans))

Submission status: Accepted

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

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

i, j = 0, 1
count = 0
if N == 1:
  print(1)
else:
  while j < N:
    if j < N-1:
      if S[i] == S[j]:
        j += 1
      elif S[i] != S[j]:
        count += 1
        i = j
        j += 1
    elif j == N-1:
      if S[i] == S[j]:
        count += 1
      elif S[i] != S[j]:
        count += 2
      break
  print(count)

Submission status: Accepted

Solution code:
from collections import deque

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

count = 1
x = S.popleft()
while S:
    y = S.popleft()
    if x == y:
        continue
    else:
        count += 1
        x = y

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

S = input()
cnt = 0
ans = []
while cnt != N:
    tmp = S[cnt]
    ans.append(tmp)
    while tmp == S[cnt]:
        cnt += 1
        if cnt == N:
            break
print(len(ans))

Submission status: Accepted

Solution code:
N=int(input())
L=list(input())
d=L[0]
R=list()
for i in range(1,N):
  if L[i]==d:
    R.append(i)
  else:
    d=L[i]
print(N-len(R))

Submission status: Accepted

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

    merge = []
    sura = S[0]

    merge.append(sura)

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

    print(len(merge))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

    merge = []
    sura = S[0]

    merge.append(sura)

    for i in range(1, N):

        if sura == S[i]:
            continue
        else:
            sura = S[i]
            merge.append(S[i])

    print(len(merge))


if __name__ == "__main__":
    main()

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

p = ''
result = 0
for i in range(N):
    # sの0文字目がpになかったらカウント&挿入
    if p != S[i]:
        result += 1
        p = S[i]
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

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:
N=int(input())
Z=input()
S=[]
S.append(Z[0])
kakunin=Z[0]
for i in range(1,N):
    if kakunin!=Z[i]:
        S.append(Z[i])
        kakunin=Z[i]

        
print(len(S))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    ss = list(input())

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

print(ans)

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 = input()
S = input()
pre = S[0]
S = S[1:]
ans = 1
for s in S:
  if s != pre:
    ans += 1
    pre = s
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - Slimes
https://atcoder.jp/contests/abc143/tasks/abc143_c

"""
import sys

import re

def solve(s):
    return len(re.sub(r'(.)\1*', r'\1', s))


def main(args):
    _ = input()
    s = input()
    ans = solve(s)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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:
import sys
from math import pi, cos, sqrt
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n = gete(int)
    s = gete()

    ans = 1

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = 0
prev = ""
for s in S:
  if s != prev:
    prev = s
    ans += 1
  else:
    continue

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]:
    continue
    
  else:
    cnt+=1
    
print(cnt)

Submission status: Accepted

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

F = [S[0]]
tmp = F[0]

for i in range(N):
    if tmp == S[i]:
        continue
    else:
        F.append(S[i])
        tmp = S[i]

print(len(F))

Submission status: Accepted

Solution code:
N = int(input())

slime = input()
count = [slime[0]]
for s in slime[1:]:
    if s != count[-1]:
        count.append(s)
#    print(count)
print(len(count))

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    S = list(input())

    ans = 1
    now = S[0]
    for i in range(1, N):
        if S[i] == now:
            continue
        else:
            ans += 1
            now = S[i]

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

t = ""
cnt = 0
for i in s:
    if i != t:
        cnt += 1
        t = i
print(cnt)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
s = readline().decode().rstrip()

s1 = [s[i] for i in range(1,n) if s[i-1]!=s[i]]
s2 =s[0]+"".join(s1)
print(len(s2))

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 = input()
count = 0

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

print(count + 1)

Submission status: Accepted

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

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=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 = list(input())

slimes = []
slimes.append(S[0])

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

print(len(slimes))

Submission status: Accepted

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

before_char = S[0]
ans = ""
S += "@"

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

print(len(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 0
current = ''
for i in s:
  if i != current:
    ans += 1
    current = i

print(ans)

Submission status: Accepted

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


tmp = 0
cnt = 0
for i in s:
    if(tmp != i):
        cnt += 1
        tmp = i

print(cnt)

Submission status: Accepted

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

mae=""
counter=0
for i in range(n):
    if s[i] != mae:
        counter += 1
    mae=s[i]


print(counter)

Submission status: Accepted

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

ans = 0
current = ''
for i in s:
  if i != current:
    ans += 1
    current = i

print(ans)

Submission status: Accepted

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

print( len(out) )

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
s = list(input())
for i in range(n-1):
    if s[i] == s[i+1]:
        s[i] = 0
print(len([j for j in s if j != 0]))

Submission status: Accepted

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

newS = ""

for i, s in enumerate(S):
    if i==0:
        newS += s
    else:
        if s!=newS[-1]:
            newS += s

print(len(newS))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
S=input()
#print(S[0],end="")
y=1
for i in range(1,n):
    if S[i] != S[i-1]:
        y+=1
print(y)

Submission status: Accepted

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

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

Submission status: Accepted

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

cur = S[0]
c = 1
for s in S:
    if s != cur:
        c += 1
        cur = s
print(c)

Submission status: Accepted

Solution code:
import itertools

def main():
    n = int(input())
    s = input()
    current = ""
    count = 0
    for i in s:
        if current != i:
            count += 1
            current = i
    print(count)
        
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,s = int(raw_input()), raw_input()
i,j,count = 0,0,0
while(j < n):
	while(j < n and s[i] == s[j]): j+=1
	i = j
	count +=1
print count

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
s= list(input())
ans = []
tmp = s[0]

if len(set(s)) == 1:
    print(1)
    exit()

for i in range(1, n):
    if s[i] == tmp:
        continue
    else:
        ans.append(tmp)
        tmp = s[i]

if ans[-1] == s[-1]:
    print(len(ans))
else:
    ans.append(s[-1])
    print(len(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())
S = input()

val = '0'
ans = 0
for s in S:
    if s == val:
       continue
    else:
        ans += 1
        val = s

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = []
while len(S) > 0:
  s = S.pop()
  if len(ans) == 0 or s != ans[-1]:
    ans.append(s)
print(len(ans))

Submission status: Accepted

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

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

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:
N = int(input())
S = input()
a = 'sing'
count = 0
for i in S:
    if a != i:
        count += 1
    a = i
print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
prev = None
ans = 0

for color in S:
    if color != prev:
        ans += 1
    prev = color

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
S_new_list = []
i = 0

while i != len(S)-1:
    if S[i] != S[i+1]:
        S_new_list.append(S[i])
        del S[0:i+1]
        i =0
    else:
        i += 1
    if len(S) == 1:
        break

print(len(S_new_list)+1)

Submission status: Accepted

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


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:
#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N = int(readline())
    S = list(readline().rstrip().decode())
    ans = 1
    for s1, s2 in zip(S, S[1:]):
        if s1 != s2:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def slimes(n, sli):

    ans = 0
    sliset = ""

    for i in sli:
        if sliset != i:
            ans += 1
            sliset = i

    return ans

def main():
    n = int(input())
    sli = list(str(input()))
    print(slimes(n, sli))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(len(ans))

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip())

N = I()
S = LS()

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    s = list(input()[:-1].decode())
    pre_si = s[0]
    s2 = [pre_si]
    for i in range(1, n):
        if s[i] != pre_si:
            s2.append(s[i])
            pre_si = s[i]

    print(len(s2))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

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


ans = 0
prevChr = ''
for ch in s:
    if prevChr != ch:
        ans += 1
        prevChr = ch

print(ans)

Submission status: Accepted

Solution code:
import itertools
N=int(input())
S=list(input())
gr=itertools.groupby(S)
i=0  
for key,group in gr:
  i+=1
ans=i
print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
l = []
pre = ""
cnt = 0
for i in range(n):
    if(pre==s[i]):
        continue
    cnt += 1
    pre = s[i]
print(cnt)

Submission status: Accepted

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

ans = 0
ch_prev = ''

for ch in s:
    if ch == ch_prev:
        pass
    else:
        ans += 1
        ch_prev = ch
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = n

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import numpy as np

rl = sys.stdin.readline
n = int(rl())
s = rl()
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())
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:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)
# from collections import Counter,deque,defaultdict
import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
n=n0()
s=s0()
print(len(list(itertools.groupby(s))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import groupby

N = int(input())
Ss = input().rstrip()

Gs = list(groupby(Ss))
#print('Gs:', Gs)

ans = len(Gs)
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 = input()

slimes = []

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

print(len(slimes))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
from collections import deque

ans=[s[0]]
bk=s[0]
for c in s:
    if c!=bk:
        ans.append(c)
        bk=c
        
print(len(ans))

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:
stdin = open(0).read().rstrip().split('\n')
N = int(stdin[0])
S = str(stdin[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())
st = input()
cnt = 1
prev = st[0]
for s in st[1:]:
  if s != prev:
    prev = s
    cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

print(count+1)

Submission status: Accepted

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