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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import Counter
import itertools
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

N=II()
S=SR()

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())
st = input()
count = 0
curr = ''
for i in range(N):
  if st[i] != curr:
    curr = st[i]
    count+= 1
    
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
string = str(input())
string =list(string)
index = 0 
i = 0
res = []
# print(string[index])
while index<len(string):
	res.append(string[index])
	# print(res[-1])
	while index<len(string) and res[-1]==string[index]:
		index+=1
	i+=1
print(len(res))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


print(res)

Submission status: Accepted

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

n = I()
s = S()

cc = ""
cnt = 0
for char in s:
    if cc == char:
        continue
    cnt += 1
    cc = char

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = list(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()
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
now = S[0]
for i in range(1,N):
    if S[i] == now:
        cnt += 1
    else:
        now = S[i]

print(N-cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
s = ''
tCheck = ''
for i in S:
  tNow = i
  s += tNow if tNow != tCheck else ''
  tCheck = tNow
print(len(s))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
s_list = [s[i] for i in range(n)]

for i in range(n-1):
    if s_list[i] == s_list[i+1]:
        s_list[i] = "0"

ans = n - s_list.count("0")
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())
p=0


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

print(N)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import deque


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

a = S.popleft()
count = 1
for i in range(N-1):
    b = S.popleft()
    if a == b:
        a = b
        pass
    else:
        count += 1
        a = b

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

count = 0
before_corror = ''
for corror in slime:
  if before_corror != corror:
    count += 1
    before_corror = corror
print(count)

Submission status: Accepted

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

ans = 1
temp = s[0]
for c in s:
    if c != temp:
        ans += 1
    temp = 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 += 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()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_right as bsr
from collections import Counter as cnt
from collections import defaultdict as dd
from collections import deque
from fractions import gcd
from itertools import combinations as comb
from itertools import permutations as perm
from math import ceil, factorial, floor
from operator import itemgetter as ig

sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    N = input(int)
    S = input(str)

    ans, last = 0, "*"
    for s in S:
        if not s == last:
            last = s
            ans += 1
    print(ans)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
li = []
answer = 0
temp = ''
for i in s:
    if temp == i:
        continue
    else:
        temp = i
        answer += 1
        
print(answer)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    cnt = 1
    for i in range(1, N):
        if S[i] != S[i-1]:
            cnt += 1
    print(cnt)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

before = ''
count = 0

for i in range(N):
    if S[i] != before:
        count += 1
    before = 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+1]!=s[i]:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=input()
mae=S[0]
now=""
ans=S[0]
for i in range(N):
  now=S[i]
  if now==mae:
    continue
  else:
    ans+=now
    mae=now

print(len(ans))

Submission status: Accepted

Solution code:
import math
import fractions
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

n=input1()
s=str(input())

slimes=[]
first=s[0]
slimes.append(s[0])
for i in range(0,n):
	if s[i]==first:
		continue
	else:
		first=s[i]
		slimes.append(first)
print(len(slimes))

Submission status: Accepted

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

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

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

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
    else:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
tmp = s[0]
res = [s[0]]
for x in s:
    if tmp != x:
        res.append(x)
    tmp = x
print(len(res))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
prev = ""
for a in s:
    if prev == a:
        continue
    else:
        ans += 1
        prev = a
print(ans)

Submission status: Accepted

Solution code:
# solution
import io
import math
from math import *
from itertools import groupby

data = int(input())
dataone = input()
print(len([x[0] for x in groupby(dataone)]))

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

sum = 0
for index in range(0, len(S)-1, 1):
    if S[index]!=S[index+1]:
        sum = sum + 1
        continue
print(sum+1)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
def RLE(S): # 文字列のランレングス圧縮(RunLengthEncoding)
    res = []
    if len(S)==0:
        return res
    now = S[0]
    id = 1
    num = 1
    while id < len(S):
        if now==S[id]:
            num+=1
            id+=1
        else:
            res+=(now,num),
            now=S[id]
            num=1
            id+=1
    res+=(now,num),
    return res # list[tuple(str,int),...]
print(len(RLE(S)))

Submission status: Accepted

Solution code:
import sys

n, s = sys.stdin.read().split()

def main():
    cnt = 0
    prev = '$'
    for c in s:
        if c == prev: continue
        cnt += 1
        prev = c
    print(cnt)

if __name__ ==  '__main__':
    main()

Submission status: Accepted

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

cnt=0
color=s[0]

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

cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    # 言い直して、同じ文字が連続している区間が何個あるかを求めよ
    n = int(input())
    s = input()
    res = 0
    i = 0
    while i < n:
        j = i
        #print(i)
        while True:
            if j < n:
                if s[j] == s[i]:
                    j += 1
                else:
                    break
            else:
                break
        i = j
        res += 1
    print(res)

if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n = ri()
    s = input()
    bc = '!'
    ans = 0
    for c in s:
        if c != bc:
            ans += 1
        bc = c
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
S=input()
s=[str(c) for c in S]
l=len(s)
k=l
for i in range(1,l):
  if s[i]==s[i-1]:
    k-=1
print(str(k))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, S: str):
    ans = []
    for i in range(N):
        c = S[i]
        if i==0:
            ans.append(c)
        else:
            if c!=ans[-1]:
                ans.append(c)
    print(len(ans))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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(input())

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

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

prev = None
answer = 0
for Si in S:
    if  Si != prev:
        answer += 1
        prev = Si

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 初期入力
N = int(input())
S =input()
S_list =[i for i in S]

#
S_2 =[]
S_2.append(S[0])
for i in range(N):
    for j in range(len(S)-1):
        if S[j] != S[j+1]:
            S_2.append(S[j+1])
    S="".join(S_2)
    break
print(len(S))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
i=0
while i<len(s)-1:
    if s[i]==s[i+1]:
        #print(s[i],s[i+1])
        #print(s,i)
        s=s[:i]+s[i+1:]
        #print(s,i)
    else:
        i+=1
print(len(s))

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

print(len(a)+1)

Submission status: Accepted

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

ans=[]
pre=""
for i in s:
    if i!=pre:
        ans.append(i)
        pre=i
print(len(ans))

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()
l = []

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

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

Submission status: Accepted

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

Submission status: Accepted

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

count = 1
x = 1
for a in S[0:N-1]:
    if a != S[x]:
        count += 1
    x += 1
    

print(count)

Submission status: Accepted

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

prev = ''
ans = ''
for s in S:
    if s != prev:
        ans += s
        prev = s

print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

print(n - cnt)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=str(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:
def q3():
    from collections import deque
    N = int(input())
    S = deque(list(input()))
    ans = deque()
    for i in range(len(S)):
        s = S.popleft()
        #print(S)
        if len(S) > 0 and s != S[0]:
            ans.append(s)
    print(len(ans) + 1)


if __name__ == '__main__':
    q3()

Submission status: Accepted

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

ans = 1
prev = S[0]

for c in S[1:]:
    if c != prev:
        ans += 1
        prev = c

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=1
b=s[0]
for i in range(len(s)):
    if b!=s[i]:
        ans+=1
        b=s[i]
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:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    s=input()
    ans=1
    for i in range(n-1):
        if s[i+1]!=s[i]:ans+=1
    print(ans)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
ls = list(input())
count = 1
for i in range(N-1):
  if ls[i] != ls[i+1]:
    count += 1
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:
"""
int(input())
map(int,input().split())
list(map(int,input().split()))

"""

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

print(len(a))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

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

pointer1 = 0
pointer2 = 1
ans = []
ans.append(s[0])
while (pointer2 <= n-1):
  if s[pointer2] == s[pointer1]:
    pointer2 += 1
  elif s[pointer2] != s[pointer1]:
    pointer1 = pointer2
    pointer2 = pointer1 + 1 
    ans.append(s[pointer1])
    
print(len(ans))

Submission status: Accepted

Solution code:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(map(str, input().split()))
def pl(a): print(" ".join(list(map(str, a))))
def ma():return map(int,input().split())
from itertools import accumulate as acc
import operator as op
import copy as cp
import math 

n=ri()
s=input()
cnt=n
if n==1:
  print(1)
  
else:
  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()
prev = ''
ans = 0
for c in s:
    if prev != c:
        ans += 1
        prev = c
print(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()
n = 1
for i in range(N-1):
    if S[i] != S[i+1]:
        n += 1
print(n)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = []
cnt=1
tmp=S[0]

for c in S:
    if c==tmp:
        continue
    tmp = c
    cnt+=1
print(cnt)

Submission status: Accepted

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

new_S = []

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

print(len(new_S))

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1
b = S[0]

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
pre=S.pop(0)
new=pre

for s in S:
    if(pre!=s):
        new+=s
        pre=s
print(len(new))

Submission status: Accepted

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

count = 0
prev = ''

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
import math
import sys
input = sys.stdin.readline

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

n=I()
s=input()
count=0
for i in range(n-1):
    k=s[i:i+1]
    l=s[i+1:i+2]
    if k==l:
        count+=1
ans=n-count
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

    else:
        pass
print(len(s)-s.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())
S=input()

ans=[]

bf = ''
for v in S:
    

    if bf != v:
        ans.append(v)
        bf = v
    

print(len(ans))

Submission status: Accepted

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

L = [S[0]]

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, s = int(input()), list(input())
i = 0
while i+1 < len(s):
    if s[i] == s[i+1]:
        del s[i+1]
    else:
        i += 1
print(len(s))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans  = list()
for i in range(N-1):
    if not S[i] == S[i+1]:
        ans.append(S[i])
ans.append(S[-1])
A = "".join(ans)
print(len(A))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
#増えたときは２種類だからansの初期値は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())
s = input()
result = s[0]
for i in s:
    if result[-1] != i:
        result += i
print(len(result))

Submission status: Accepted

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