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

top = s[0]
count = 1
for i in range(n):
    if s[i] == top:
        continue
    else:
        count += 1
        top = s[i]
print(count)

Submission status: Accepted

Solution code:
from collections import deque

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

queue = deque((S[0],))

for c in S[1:]:
    if queue[-1] == c:
        continue
    queue.append(c)

print(len(queue))

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:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
S = rs()

import itertools

G = list(itertools.groupby(S))
print(len(G))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n,  s = sys.stdin.read().split()
n = int(n)
res = 1
prep = s[0]
for i in s[1:]:
  if i == prep:
    continue
  prep = i
  res += 1
print(res)

Submission status: Accepted

Solution code:
def slimes(n, s):
   
  u_slime = [s[-1]]
  for i in range(n-1):
    if not s[i] == s[i+1]:
      u_slime.append(s[i])
  
  print(len(u_slime))

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

Submission status: Accepted

Solution code:
n=int(input())

s=input()

m = s[0]
cnt = 1
for i in s:
    if m[0] != i:
        m = i
        cnt += 1

print(cnt)

Submission status: Accepted

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

# resultにはすでに何らかの文字列が入っているものとする
result = re.sub(r"(.)\1{1,}", "\g<1>", s)  # 繰り返し文字列をまとめる
print(len(result))

Submission status: Accepted

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

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

resolve()

Submission status: Accepted

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

same = False
while not same:
  same = True
  i = 0
  while i+1 < N:
    if S[i] == S[i+1]:
      S = S[:i] + S[i+1:]
      N -= 1
      same = False
    else:
      i += 1

print(len(S))

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
l=""
r=[]
for ii in range(n):
  if s[ii]==l:
    pass
  else:
    l=s[ii]
    r.append(l)
#print(r)
print(len(r))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

new = s[0]
count = 1

for i in s:
  if new == i:
    continue;
  else:
    count += 1
    new = i
  
print(count)

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools
n = int(input())
s = 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:
import itertools
input()
s = input()
print(len(list(itertools.groupby(s))))

Submission status: Accepted

Solution code:

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

ans=1
i=0
while i<N:
    if i==0:
        MAE=S[i]
    else:
        if S[i]==MAE:
            MAE=S[i]
            pass
        else:
            MAE=S[i]
            #print(S[i])
            ans+=1
    i+=1
    
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = 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,S=int(input()),list(input())
ans=0
c=1
while c<N:
    if S[c]!=S[c-1]: ans+=1
    c+=1
print(ans+1)

Submission status: Accepted

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

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

print(len(op))

Submission status: Accepted

Solution code:
N = int(input())
sList = list(input())
count = 0
tmp = ''
for s in sList:
    if(s != tmp):
        count += 1
        tmp = s

print (count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
be=""
count=0

for i in s:
  if i!=be:
    count+=1
    
  be=i
  
print(count)

Submission status: Accepted

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

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

print(len(S)-dl)

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
r = n
for i, j in enumerate(s):
    if i == n - 1:
        break
    if j == s[i + 1]:
        r -= 1
print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import math
n = int(input())

s = list(input())

d = 0


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

Submission status: Accepted

Solution code:
# ABC

import numpy as np

def rle(x):
    ''' Run Length Encoding

    rle('001111000000011')
    (array([2, 4, 7, 2]),
     array(['0', '1', '0', '1'], dtype='<U1'))

    rle('aabcccbbbaab')
    (array([2, 1, 3, 3, 2, 1]),
     array(['a', 'b', 'c', 'b', 'a', 'b'], dtype='<U1'))
    '''
    x = np.array(list(x))
    n = len(x)
    if n == 0:
        return (1, '')
    y = list(map(lambda a, b: a != b, x[1:], x[:-1]))
    i = np.hstack((np.where(y)[0]+1, n))
    return (np.diff(np.hstack((0, i))), x[i-1])

n = int(input())
s = input()
a = rle(s)
print(len(a[0]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(len(slime))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
now = "0"
c = 0
for e in s:
  if now != e:
    c += 1
    now = e
print(c)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
s_list = list(s)
pre_slime = ''
a = 0
for slime in s_list:
  if pre_slime == slime:
    a += 1
  pre_slime = slime
print(len(s_list)-a)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

from itertools import *
from operator import itemgetter

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

def unique_justseen(iterable, key=None):
    return map(next, map(itemgetter(1), groupby(iterable, key)))

print(len(list(unique_justseen(s))))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
slist = []
for i in range(n):
  slist.append(s[i])
slime = slist[0]
fslist = []
fslist.append(slime)
for i in range(1, n):
  if slime != slist[i]:
    fslist.append(slist[i])
    slime = slist[i]
print(len(fslist))

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    N = int(stdin.readline().rstrip())
    S = list(stdin.readline().rstrip())
    X = S[0]
    A = 1
    for i in range(1,N):
        if S[i] != X:
            A += 1
            X = S[i]
    print(A)

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(count)

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())
l=list(i for i in input())
s=l[0]
ans=1
for i in range(1,n):
    if s==l[i]:
        pass
    else:
        ans+=1
        s=l[i]
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:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    S = itertools.groupby(iss())
    print(len(list(S)))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def S(): return sys.stdin.readline().rstrip()
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 = 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()
count=0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        count+=1
print(len(S)-count)

Submission status: Accepted

Solution code:
def main():
    input()
    s = input()
    a = []
    for v in s:
        if not a or a[-1] != v:
            a.append(v)
        else:
            pass
    print(len(a))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

count = 1

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

print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
s = S()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import sys
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines

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

ans = 1
tmp = S[0]
for s in S:
    if s != tmp :
        ans += 1
        tmp = s

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): return k.join(list(map(str, lst)))
INF = float('inf')

def solve():
    n = II()
    S = list(input())

    cnt = 0
    pre = ''
    for s in S:
        if pre == s:
            continue
        else:
            cnt += 1
            pre = s
    print(cnt)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
S = np.array(list(input()))
tmp = S[1:]
tmp = np.append(tmp, "-1")

print(S[~(S==tmp)].shape[0])

Submission status: Accepted

Solution code:
# C - Slimes

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

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

print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    l=[]
    n=int(input())
    s=input()
    imamade=0
    cnt=0
    for i in range(n):
        if s[i]!=imamade:
            cnt+=1
            imamade=s[i]
    print(cnt)
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
pre = s[0]
i = 1
a = ''
while True:
    if i == n:
        a += pre
        break
    if s[i] == pre:
        i += 1
        continue
    a += pre
    pre = s[i]
    i += 1
print(len(a))

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string


import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    N=int(input())
    A=list(input())
    gr = groupby(A)
    cnt=0
    for key, group in gr: # groupはイテレータ。list(group)でリスト化  
        """ex.
        0: [0, 0, 0]
        1: [1, 1]
        0: [0, 0, 0]
        1: [1, 1]
        0: [0]
        1: [1]
        """
        cnt+=1
    print(cnt)
        

    
resolve()

Submission status: Accepted

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

tmp = None
ans = 0
for s in S:
    if tmp != s:
        tmp = s
        if tmp != None:
            ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

s = input()

ans = 1
for i in range(len(s)):
    if (i+1) % len(s) == 0:
        break

    now = s[i]
    nxt = s[i+1]

    if now != nxt:
        ans += 1


print(ans)

Submission status: Accepted

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

l=list(S)
ans=[l[0]]
for n in range(1,N):
    if l[n]!=l[n-1]:
        ans.append(l[n])

print(len(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

count += 1

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

Submission status: Accepted

Solution code:
#ABC 143

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

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:
from collections import deque


def main():
    N = int(input())
    S = input()
    before_char = None
    merged_chars = deque()
    for i, c in enumerate(S):
        if c != before_char and before_char is not None:
            merged_chars.append(before_char)
        before_char = c
        if i == N - 1:
            merged_chars.append(c)
    print(len(merged_chars))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

i = 0
res = 0
c = ""
while i < N:
    if c != S[i]:
        res += 1
        c = S[i]
    i += 1

print(res)

Submission status: Accepted

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

from itertools import groupby

slime = groupby(S)

ans=0
for key ,_ in slime:
    ans+=1

print(ans)

Submission status: Accepted

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

count = 0
prev = None
for i in list(s):
  if i!=prev:
    count += 1
  prev = i
    
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_c

N = int(input())
S = 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 = input()
S_new = ''
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        S_new += S[i]


print(len(S_new)+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
import collections

mod = 10 ** 9 + 7
N = int(input())
S = (input())
prev_c = S[0]
count = 1
for s in S[1:]:
    if (prev_c == s):
        continue
    else:
        prev_c = s
        count += 1
print(count)

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())
a = input()
b = 0
for i in range(n):
    if i == 0:
        continue
    else:
        if a[i] == a[i-1]:
            continue
        else:
            b +=1
print(b+1)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
cnt = 0
b = 10
for i in S:
    if i != b:
        cnt += 1
        b = i
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

o = ""
l = ''
for i in range(n):
    if(s[i] != l):
        o += s[i]
        l = s[i]
print(len(o))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=0
for i in S:
    if S!='':
        S=S.lstrip(S[0])
        ans+=1
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = N
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())
w = ''
c = 0
for i in s:
    if w != i:
        c+=1
        w = i
print(c)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
t = str()
cnt = int()
for ch in s:
    if t[-1:] != ch:
        t += ch
        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]:
        count += 1
print(count)

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 = list(input())
A = 0
for i in range(n-1):
  if s[i] == s[i+1]:
    s[i]  = A
  else:
    pass

ans = len(s)-s.count(0)

print(ans)

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    S = input()
    num = 0 
    prev_s = ""
    for s in S:
        if s != prev_s:
            num += 1
        prev_s = s
    print(num)


if __name__ == "__main__":
    main()

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:
if __name__ == '__main__':
    n = int(input())
    s = list(input())
    ans = [s[0]]
    for i in range(1, n):
        if s[i] != ans[-1]:
            ans.append(s[i])
    print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

h = 0
ans = 1
for i in range(1, n):
    if S[i] == S[h]:
        pass
    else:
        ans += 1
        h = i
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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:
from itertools import groupby

n = int(input())
s = input()
print(len(list(groupby(s))))

Submission status: Accepted

Solution code:
N = int(input())
M = N
slime = input()

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

print(M)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
input()
last = '0'
ans = 0
for c in input():
    if last != c:
        last = c
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import os

def main():
	n = int(input())
	s = input()
	count = 1
	erser_count = 0
	for i in s:
		if count == len(s):
			break
		if i == s[count]:
			erser_count += 1
		count += 1
	print(n - erser_count)

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import sys
N = int(input())
if N == 1:
  print(1)
  sys.exit()
  
S = input()
ans = 1
for n in range(len(S)-1):
  if S[n] != S[n+1]: ans +=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

import itertools

l = [k for k, v in itertools.groupby(S)]
print(len(l))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

for i in range(len(s)):
    l.append(s[i])

for i in range(1, n)[::-1]:
    if l[i] == l[i - 1]:
        del l[i]

print(len("".join(l)))

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()
dum = ""
ans = ""
for i in s:
    if dum != i:
        ans += i
    dum = i
print(len(ans))