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:
# -*- coding: utf-8 -*-

# Input
s = [input() for i in range(2)]

N = int(s[0])
S = list(s[1])

# Process
M = 0

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

N = N - M

# Output
print(N)

Submission status: Accepted

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

now=slime[0]
ans=1

for s in slime:
    if now == s:
        continue
    ans+=1
    now=s
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
p = list(s)
i=1
while len(p)>i:  
    if p[i-1]==p[i]:
        del p[i]
    else:
        i+=1

print(len(p))

Submission status: Accepted

Solution code:
N=int(input()); S=list(input()); i=0
while i+1<len(S):
    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()

pos = 0
while True:
  if pos >= len(S) - 1:
    break
  if pos <= len(S) - 2 and S[pos] == S[pos+1]:
    S = S[:pos+1] + S[pos+2:]
    continue
  else:
    pos += 1
    
print(len(S))

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-



N = int(input())
Sn = str(input())

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

Submission status: Accepted

Solution code:
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from copy import deepcopy
#import heapq
#import math
#import string

setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
s=input().rstrip()

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
#print(S)
cnt = 1
S_list = [s for s in S]
S_list1 = S_list[1:]
for s,s1 in zip(S_list,S_list1):
    if s != s1:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
#print(S)
cnt = 1
S_list = [s for s in S]
#print(S_list)
for i in range(N):
    if S_list[N-1-i] != S_list[N-1-(i+1)] and N-1-(i+1)>=0:
        #S_list.insert(N-1-i,"|")
        cnt += 1
    #print(S_list)
print(cnt)

Submission status: Accepted

Solution code:
from itertools import groupby
n = int(input())
s = input()
ans = 0
for key, value in groupby(s):
    ans += len(list(key))
print(ans)

Submission status: Accepted

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

before = ""
answer = 0
for w in s:
    if w == before:
        pass
    else:
        answer += 1
        before = w
print(answer)

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:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

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

Submission status: Accepted

Solution code:
from collections import deque

n = int(input())
l = deque(list(input()))
pre = l.pop()
ans = 1

for _ in range(n-1):
    now = l.pop()
    if now != pre:
        ans += 1
    pre = now
print(ans)

Submission status: Accepted

Solution code:
input()
S = input()
before_str = ""
cnt = 0
for str in S:
  if str != before_str:
    cnt += 1
    before_str = str
print(cnt)

Submission status: Accepted

Solution code:
x = input()
x = int(x)
y = input()

res = ""
for i,sra in enumerate(y):
  if i == 0:
    res += sra
  elif y[i-1] == sra:
    pass
  else:
    res += sra
    
print(len(res))

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
summary = 1
prefchar = s[0]
for idx in range(n -1):
    if prefchar != s[idx+1]:
        summary = summary + 1
        prefchar = s[idx+1]
print(summary)

Submission status: Accepted

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

ans = 1
current = s[0]
for i in range(n):
  if current != s[i]:
    ans += 1 
    current = s[i]
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())
s = input()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

prev_s = ""
ans = 0

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
  num = input()
  slimes = input()

  tmp = []
  for i in range(0,len(slimes)):
    if len(tmp):
      if slimes[i] != tmp[-1]:
          tmp.append(slimes[i])
    else:
      tmp.append(slimes[i])
  print(len(tmp))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin

N = int(input())
S = input().strip()

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

print(ans)

Submission status: Accepted

Solution code:
afterslimes = 0
a = input()
b = input()

lenslime = len(b)
tempslime = None

for i in range(lenslime):
	if b[i] != tempslime:
		afterslimes += 1
		tempslime = b[i]

print(afterslimes)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
from sys import stdin
import itertools as it
import functools as fc


def fin(f):
    return f(input())


def gin(f, n=1):
    for _ in range(n):
        yield list(map(f, stdin.readline().split()))


def lin(f):
    return next(gin(f))


N = fin(int)

S = fin(list)

ans = [""]
for s in S:
    if not ans[-1] == s:
        ans.append(s)

print(len("".join(ans[1:])))

Submission status: Accepted

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

color = s[0]
ans = 1
for i in range(1,len(s)):
    next_color = s[i]
    if next_color != color:
        ans += 1
        color = s[i]
print(ans)

Submission status: Accepted

Solution code:
input = raw_input

N = int(input())
s = input().strip()

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

Submission status: Accepted

Solution code:
import re
N = input()
S = input()
S_fusion = re.sub(r"([a-z])\1*", r"\1", S)
print(len(S_fusion))

Submission status: Accepted

Solution code:
import re

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

rex = r'(.)\1{0,}'
pattern = re.compile(rex)
ans = pattern.findall(S)

print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def T():
    N=int(input())
    S=input()
    c=''
    t=0
    for s in S:
        if s==c:
            t+=1
        c=s
    return(N-t)
print(T())

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int ( input() )
slimes = str( input() )
list_slimes = list( slimes )
while(True):
  counter = 0
  i = 0
  while(i<len(list_slimes)-1):
    if list_slimes[i] == list_slimes[i+1]:
      del list_slimes[i]
      counter += 1
    i += 1
  if counter == 0:
    break

print( len (list_slimes) )

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:
import sys

count = 0
input = sys.stdin.readline

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N=int(input())
S=input()
New=[]
for i in range(N-1):
    New.append(S[i])
    if S[i] == S[i+1]:
        New.pop()
if len(New) == 0 or S[-1] != New[-1]:
    New.append(S[-1])

print(len(New))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
PreviousColor = "."
SlimCount = 0
for n in range(N):
    if(PreviousColor != S[n]):
        SlimCount += 1
        PreviousColor = S[n]
print(SlimCount)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re;_,s=open(0);print(len(re.sub(r"(.)\1+",r"\1",s))-1)

Submission status: Accepted

Solution code:
import re;_=input();print(len(re.sub(r"(.)\1+",r"\1",input())))

Submission status: Accepted

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

slime = 1

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

Submission status: Accepted

Solution code:
N = int(input())
S = list(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:
import  numpy as np

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = [_ for _ in input()]
ans = 0
work = ""
for s in S:
    if work == "":
        work = s
        ans += 1
        continue

    if s != work:
        ans += 1
        work = s

print(ans)

Submission status: Accepted

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

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 = list(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())
counter = 0
last_char = None
for char in S:
  if char != last_char:
    counter += 1
    last_char = char

print(counter)

Submission status: Accepted

Solution code:
n = int(input())
s = str(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 = input()
b=[]
b.append(S[0])
for i in range(1,N):
    if S[i]!=S[i-1]: b.append(S[i])
print(len(b))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 1
c = s[0]

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

Submission status: Accepted

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

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

print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n = onem()

a = list(input())

a = s(a)

print(len(a))

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())
d = list(input())
ans = 0
tmp = ""
for i in range(len(d)):
    if tmp != d[i]:
        ans = ans + 1
    tmp = d[i]
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, S: str):
    ret = 1
    for i in range(N - 1):
        if S[i] != S[i + 1]:
            ret += 1
    print(ret)
    return

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

S = list(str(input()))

l = 0
r = 1
t = 1
while r < N:
  if S[l] != S[r]:
    t += 1
    l = r
  else:
    l += 1
  r += 1
      
print(t)

Submission status: Accepted

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

ans = 0
pre = '0'
for c in s:
    if c != pre:
        ans += 1
    pre = c

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    S = list(str(input()))
    St = []
    for i in range(N-1):
        if S[i]==S[i+1]:
            continue
        St.append(S[i])
    if S[N-2]==S[N-1]:
        St.append(S[N-2])
    else:
        St.append(S[N-1])
    print(len(St))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    N = int(input())
    s = input().strip()
    ans = 0
    pre = ""
    for i in range(N):
        if s[i] != pre:
            ans += 1
        pre = s[i]
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

    Prev = '_'
    Ans = 0
    for Si in S:
        if Si != Prev:
            Ans += 1
        Prev = Si
    print(Ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
count = 0
S = S + '$'

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
S=input()
ans=0
before=None
for i in range(n):
    now=S[i]
    if now!=before:
        ans+=1
    before=now
print(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:
N = int(input())
S = list(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = str(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 = []
ans.append(s[0])

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

print(len(ans))

Submission status: Accepted

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


def main():
    n = int(input())
    s = input()
    prev = s[0]
    count = 1

    for i in range(1, n):
        cur = s[i]

        if cur != prev:
            count += 1
            prev = cur

    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    n=int(input())
    s=input()
    st=set(s)
    for i in st:
        while i*2 in s:
            s=s.replace(i*2,i)
    print(len(s))
resolve()

Submission status: Accepted

Solution code:
# coding: utf-8

def generator():
    for s in input():
        yield s

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

    slimes = 0
    pre_slime = None
    for s in generator():
        if s == pre_slime:
            continue
        slimes += 1
        pre_slime = s
    print(slimes) 

main()

Submission status: Accepted

Solution code:
N = int(input())
s = str(input())
l = []
for i in s:
    if not l:
        l.append(i)
    elif l[-1] != i:
        l.append(i)
print(len(l))

Submission status: Accepted

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

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

Submission status: Accepted

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

def main():
    N = int(input())
    S = input().strip()
    count = 1
    for i, v in enumerate(S):
        if i == N - 1:
            break
        if S[i] != S[i + 1]:
            count += 1

    print(count)




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-1]!=s[i]:
        ans+=1
print(ans)

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

count = 1
i = 1
while i < N:
	if S[i -1] != S[i]:
		count += 1
	i += 1
	
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

i = 0
j = 1
while j < len(a):
    if a[i] == a[j]:
        a.pop(j)
    else:
        i += 1
        j += 1

print(len(a))

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()
pas = "A"
n = 0
for c in s:
  if pas != c:
    pas = c
    n += 1
print(n)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
before = ''

for s in S:
    if before != s:
        before = s
        ans += 1

print(ans)

Submission status: Accepted

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

a = ""
ans = 0
for s in sentense:
  if a != s:
    ans += 1
    a = s
print(ans)

Submission status: Accepted

Solution code:
'''C - Slimes
https://atcoder.jp/contests/abc143/tasks/abc143_c

>>> main(10, 'aabbbbaaca')
5
>>> main(5, 'aaaaa')
1
>>> main(20, 'xxzaffeeeeddfkkkkllq')
10

'''


def main(n, s):
    i = 0
    tmp = ''

    for s in s:
        if s != tmp:
            i += 1

        tmp = s

    print(i)


if __name__ == "__main__":
    n = int(input())
    s = input()

    main(n, s)

Submission status: Accepted

Solution code:
from sys import exit, stdin
N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()
ans = 1
tmp_s = S[0]
for s in S[1:]:
    if tmp_s != s:
        ans += 1
        tmp_s = s
print(ans)

Submission status: Accepted

Solution code:
from itertools import groupby

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

print(len(list(groupby(S))))

Submission status: Accepted

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


def main():
    N = int(input())
    S = input()
    ans = 1
    flg = False
    for i in range(N-1):
        if S[i] == S[i+1] and not flg:
            flg = True
        elif S[i] != S[i+1]:
            flg = False
            ans += 1
    print(ans)


if __name__ == '__main__': main()

Submission status: Accepted

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

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

print(len(after))

Submission status: Accepted

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

result = 1

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

Submission status: Accepted

Solution code:
N = int(input())
S =list(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 = 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()

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()
prev = s[0]
count = 1
for c in s[1:]:
  if prev == c:
    prev =c
  else:
    count+= 1
    prev =c

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

last_s = ""
for s in S:
    if s is not last_s:
        new_S += s
    last_s = s
print(len(new_S))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#abc143c

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

Submission status: Accepted

Solution code:
n = input()
s = raw_input()
pre = 'A'
count = 0
for char in s:
  if char!=pre:
    count+=1
    pre=char
print count

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
#import math
#import time
#import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#eps=10**(-10)
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

n=I()
s=StoI()
ans=0

for i in groupby(s):
    ans+=1
print(ans)

Submission status: Accepted

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

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

print(len(ans))

Submission status: Accepted

Solution code:
def main():
    baselist=[]
    anslist=[]
    N = input()
    baseword = input().rstrip()
    [baselist.append(i) for i in baseword]
    for index,value in enumerate(baselist):
        if int(index+1)<int(len(baselist)):
            if baselist[index]!=baselist[index+1]:
                anslist.append(baselist[index])
        else:
            anslist.append(baselist[index])
    print(len(anslist))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

crt = ''
res = 0
for i in range(n):
    a = s[i]
    if a != crt:
        res += 1
    crt = a
print(res)

Submission status: Accepted

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

Submission status: Accepted

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: Accepted

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

count = []

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

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

print(ans)

# またはa-zまで正規表現をかます
# for i in range(26):
#   ans = re.sub("([a-z])\\1","\\1",ans)
# print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import*
input()
print(len(list(groupby(input()))))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=input()
cnt=0
pre='1'
for s in S:
    if s!=pre:
        cnt+=1
    pre=s
print(cnt)