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()
li = []
for c in S:
    if(len(li) == 0):
        li.append(c)
    else:
        pe = li[-1]
        if(pe == c):
            continue
        else:
            li.append(c)
print(len(li))

Submission status: Accepted

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

char = s[0]
cnt = 1

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

print(cnt)

Submission status: Accepted

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

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

print(c)

Submission status: Accepted

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

digit = 1

while digit < len(s) :
    if s[digit] == s[digit - 1] :
        s.pop(digit)
    else :
        digit += 1

print(len(s))

Submission status: Accepted

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

flag=True

while flag:
    ans=[]
    for i in range(len(s)):
        if i==0:
            ans.append(s[i])
        else:
            if s[i-1]!=s[i]:
                ans.append(s[i])

    if ans==s:
        flag=False
    else:
        s=ans
print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

res = 0

while True:
    if S == '':
        break

    temp = S[0]
    S = S.lstrip(temp)
    res += 1


print(res)

Submission status: Accepted

Solution code:
num=int(input().rstrip())
word=input().rstrip()
numlis=list(word)

s=1
for i in range(1,(num)):
    a=(numlis[i-1])
    b=(numlis[i])
    if(a!=b):
        s+=1
        #print(i)

print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = int(input())
line = input()

res = ''
before_color = ''

for item in line:
    if item == before_color:
        pass
    else:
        res += item
    
    before_color = item

print(len(res))

Submission status: Accepted

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

Submission status: Accepted

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

	ans = 1
	prev = s[0]

	for ch in s[1:] :
		if(ch != prev) :
			prev = ch
			ans = ans + 1

	print(ans)

main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
curr = ''
fl = 0
ans = 0
for ch in s:
    if ch != curr:
        fl = 0
        # print(ch, '123')
    
    if fl == 0:
        curr = ch
        fl = 1
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


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


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    n = INT()
    s = input()
    
    ans = 1

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

    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools as it

n = input()
s = input()

print(len(list(it.groupby(s, ))))

Submission status: Accepted

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

pre = ""
res = 0 
for i in s:
    if i != pre:
        res+=1
    pre = i 
print(res)

Submission status: Accepted

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

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

print(a)

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 = raw_input()
ans = 0
curr_set = ""
for i in range(n):
    if s[i] == curr_set:
        continue
    else:
        curr_set = s[i]
        ans+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(n-dabu)

Submission status: Accepted

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

count = 1
count2 = 1

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

Submission status: Accepted

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

print(len(s))

Submission status: Accepted

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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

if output == 0:
    output =1

print(output)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
def get_sequence(arr):
    if len(arr) == 0:
        return [], []
    elements = []
    nums = []
    n = 1
    prev = arr[0]
    for c in arr[1:]:
        if c == prev:
            n += 1
        else:
            elements.append(prev)
            nums.append(n)
            prev = c
            n = 1
    elements.append(prev)
    nums.append(n)
    return elements, nums

N = int(input())
S = input()
ele, num = get_sequence(S)
print(len(num))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

while True:
    s = ''.join([S[i] for i in range(1, len(S)) if S[i] != S[i-1]])
    s = S[0]+s
    if len(s) == len(S):
        break
    else:
        S = s

print(len(S))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from itertools import groupby

N=int(input())
S=list(input())
_ans=0
for key, group in groupby(S):
    _ans += 1
print(_ans)

Submission status: Accepted

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

cur_slim = s[0]
res = 1

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

print(res)

Submission status: Accepted

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

prev = s[0]
ans = 1

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

print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
S = str(input())
ans = "".join(ch for ch,_ in itertools.groupby(S))
print(len(ans))

Submission status: Accepted

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

bf = ''
cnt = 0

for i in S:
    if bf != i:
        cnt += 1
        bf = i

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

result = []

prevc = None
sum = 0
for c in S:
  if prevc != c:
    sum += 1
  prevc = c
print(sum)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

current = ''
result_sum = 0
for i in range(N):
    if i == 0:
        current = S[i]
        result_sum = 1
        continue
    if current == S[i]:
        continue
    result_sum += 1
    current = S[i]

print(result_sum)

Submission status: Accepted

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

Ss = list(S)
new_S = ""

for i, s in enumerate(Ss):
    if i == 0:
        new_S += s
        mae_S = s
        continue

    if mae_S == s:
        mae_S = s
        continue

    new_S += s
    mae_S = s

print(len(new_S))

Submission status: Accepted

Solution code:
n=int(input())

c=input()

count = 0

for i in range(len(c)):
  if i == 0:
    count = count +1
  elif c[i] !=c[i-1]:
    count = count +1 
    
print(count)

Submission status: Accepted

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

score = 1

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

print (score)

Submission status: Accepted

Solution code:
N=input()
S=input()
ans=0
before=S[0]
for s in S[1:]:
    if before==s:
        continue
    else:
        ans+=1
        before=s
print(ans+1)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
new_s = s + '0'
count = 0
i = 0
while i <= n-1:
    color = new_s[i]
    while new_s[i] == color:
        i += 1
    count += 1
print(count)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
ans=[]
latest=0
for i in range(n):
    if s[i]!=latest:
        ans.append(s[i])
        latest=s[i]
print(len(ans))

Submission status: Accepted

Solution code:

N = int(input())

S = input()

str_list = list(S)

pre = None
result = ""
for s in S:
    if pre is None:
        pre = s
        result = s

    if s != pre:
        result += s
        pre = s

print(len(result))

Submission status: Accepted

Solution code:
#coding: utf-8
n = int(input())
s = str(input())
# list = list(map(int,input().split()))
# strings = list(map(str, [input() for i in range(amount)]))
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 = input()
a = ""
b = 0
for i in range(n):
	c = s[i]
	if a != c:
		b += 1
	a = c
print(b)

Submission status: Accepted

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


temp=0

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

Submission status: Accepted

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

n = int(input())
s = list(map(str, input()))


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

print(cnt)

Submission status: Accepted

Solution code:
input()
S = input()

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

print(result)

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
    else:
        continue

print(ans)

Submission status: Accepted

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

temp = ""
cnt = 0
for s in S:
    if temp != s:
        temp = s
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
# C - Slimes
N = int(input())
S = str(input())
count = 0

for i in range(N):
    if i == 0:
        count += 1
    elif S[i-1] == S[i]:
        pass
    else:
        count += 1

print(count)

Submission status: Accepted

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

result = 1
tmp = slimes[0]

for slime in slimes:
    if slime != tmp:
        result+=1
        tmp=slime
print(result)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
c = '0'
ans = 0

for i in range(N):
    if c == S[i]:
        continue

    elif i == N-1:
        ans += 1

    else:
        c = '0'

        if S[i] == S[i+1]:
            c = S[i]
            ans += 1

        else:
            ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
input = sys.stdin.readline
def inputs():return [int(x) for x in input().split()]
N = int(input())
S= list(input())
s = []
cnt= 1
for i in range(len(S)-2):
  if S[i]==S[i+1]:
    cnt+=1
  else:
    s.append(cnt)
    cnt=1
s.append(cnt)
print(len(s))

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
ret=0
for i in range(N):
    if i==0:
        p=S[i]
        ret=ret+1
    else:
        n=S[i]
        if n==p:
            continue
        else:
            p=n
            ret=ret+1
print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# abc143/abc143_c
import sys
import re

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    S = i2s()
    print(len(re.sub(r'(.)(\1)*', r'\1', S)))
    return

main()

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()
s=list(S)
i=0
while i<N:
    if i==len(s)-1:
        break
    else:
        if s[i]==s[i+1]:
            del s[i]
        else:
            i+=1
print(len(s))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
total = 0
prev = ""
for item in s:
    if item!=prev:
        total+=1
    prev = item
print(total)

Submission status: Accepted

Solution code:
def tako(n, s):
    counter = 1
    for i in range(1, n):
        if s[i-1] != s[i]:
            counter +=1
    return counter

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

out = tako(N, S)
print(out)

Submission status: Accepted

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

    ans = 1
    pre = S[0]
    for i in range(1,int(len(S))):
        if S[i] != pre:
            ans += 1
            pre = S[i]
    
    print(ans)

solve()

Submission status: Accepted

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

color = S[0]
c = 0
for s in S:
  if s != color:
    c += 1
    color = s

print(c+1)

Submission status: Accepted

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

prev_lett = ''
count = len(S)
for i, lett in enumerate(S):
    if i == 0:
        prev_lett = lett
        continue
    else:
        if lett == prev_lett:
            count -= 1
        prev_lett = lett
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(num+1)

Submission status: Accepted

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

Submission status: Accepted

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

ans = list(d.pop(0))

while d:
  target = d.pop(0)
  if ans[-1] != target:
    ans.append(target)

print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
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 solve(colors):
    ans = 0
    cur = None
    for c in colors:
        if c != cur:
            cur = c
            ans += 1
            continue

    return ans


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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
i=0
while(i<n):
    j= i+1
    while(j<n and s[i]==s[j]):
        j+=1
    i = j
    ans+=1

print(ans)

Submission status: Accepted

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

nc = s[0]
count = 1
for c in s[1:]:
    if (c != nc):
        count += 1
        nc = c

print(count)

Submission status: Accepted

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

total = 1
temp = s[0]
for i in s:
    if temp == i:
        pass
    else:
        total += 1

    temp = i

print(total)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(str,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()
x = S[0]
cnt = 1
for c in S[1:]:
    if not c == x:
       cnt += 1
       x = c

print(cnt)

Submission status: Accepted

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

A = [s[0]]
count = 0

for si in s[1:]:
    if si != A[count]:
        A.append(si)
        count += 1

print(len(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = input()

before = S[0]
independent = 1

for i in range(1, N):
	if S[i] != before:
		independent += 1
		before = S[i]


print(independent)

Submission status: Accepted

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

slime_list = []
slime_list.append(S[0])
pre_color = S[0] # 左隣のスライムの色
for i in range(1,N):
    if pre_color != S[i]:
        slime_list.append(S[i])
        pre_color = S[i]

print(len(slime_list))

Submission status: Accepted

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

S = list(S)
for i in range(N-1):
    if S[N-1-i]==S[N-2-i]:
        S.pop(N-1-i)
print(len(S))

Submission status: Accepted

Solution code:
# coding:utf-8

N = int(input())

S = input()

count = 1

tmp_s = S[0]

for i in range(1, len(S)):
    if(S[i] == tmp_s):
        pass
    else:
        count+=1
        
    tmp_s = S[i]
print(count)

Submission status: Accepted

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

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

print(c)

Submission status: Accepted

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


def solve(N: int, S: str):
    pre = S[0]
    cnt = 1
    for i in range(1, len(S)):
        si = S[i]
        if pre != si:
            cnt += 1
        pre = si
    print(cnt)


# Generated by 1.1.5 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:
a =int(input())
l=input()
q=''
ans=0
for i in range (len(l)):
  if l[i]!=q:
    ans+=1
  q=l[i]
print(ans)

Submission status: Accepted

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

print(c)

Submission status: Accepted

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

cnt = 1
c = S[0]
for i in range(1,len(S)):
    if c == S[i]:
        pass
    else:
        cnt += 1
        c = S[i]

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class Stack(object):
    def __init__(self):
        self.container = []

    def __len__(self):
        return len(self.container)

    def push(self, elem):
        self.container.append(elem)

    def pop(self):
        index = len(self.container) - 1
        if index < 0:
            return None
        ret = self.container[index]
        del self.container[-1]
        return ret

    def compare(self, val):
        return self.container[-1] == val

if __name__ == '__main__':
    N = int(input())
    S = input()
    stack = Stack()
    stack.push(S[0])
    for s in S[1:]:
        if not stack.compare(s):
            stack.push(s)
    print(stack.__len__())

Submission status: Accepted

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


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

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

print(n-temp)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    colors = list(input().rstrip())

    flag = True

    while flag:
        flag = False
        for i in range(len(colors) - 1):
            if colors[i] == colors[i + 1]:
                colors[i] = "$"
                flag = True
        colors = "".join(colors)
        colors = colors.replace("$", "")
        colors = list(colors)

    print(len(colors))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a = input()

a = int(a)

b = input()

sum = 0

temp_char = ''

for char in b:
    if char!= temp_char:
        sum += 1
        temp_char = char

print(sum)

Submission status: Accepted

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

s = list(S)
ans = 0
c = s[0]
count = 1
for i in range(1, N):
    if c == s[i]:
        continue
    else:
        ans += count
        c = s[i]
    
print(ans+1)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
	N = int(input())
	S = input()
	w = "A"
	sum = 0
	for i in range(N):
		if w != S[i]:
			sum += 1
		w = S[i]
	print(sum)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

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 = 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:
def myunique(c):
    last = None
    count = 0
    for ci in c:
        if last == ci:
            pass
        else:
            last = ci
            count += 1
    return count

N = int(input())
print(myunique(input()))

Submission status: Accepted

Solution code:
n = int(input())

s = input()

ant = s[0]
soma = 1
res = 1
for i in s[1:]:
    if i == ant:
        soma += 1
    else:
       res += 1
       ant = i

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    cnt = 0
    prev = ''
    for i in range(N):
        if S[i] != prev:
            cnt += 1
    
        prev = S[i]
    print(cnt)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

cnt=1
prec=s[0]
for c in s:
  if prec==c:
    continue
  else:
    cnt+=1
    prec=c
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:
import sys

N = int(sys.stdin.readline().strip())
S = sys.stdin.readline().strip()

out = S[0]
for s in S[1:]:
  if out[-1]==s: continue
  out += s
print(len(out))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = input()
ans = 1
for i in range(1,N):
  if S[i-1] == S[i]:
    continue
  else:
    ans += 1
print(ans)

Submission status: Accepted

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

ret = [s[0]]
for it in s[1:]:
    if ret[-1] != it:
        ret.append(it)
print(len(ret))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
s = list(s)#文字列をリストに
num = 0

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

print(num + 1)

Submission status: Accepted

Solution code:
input()
s = list(input())
count = 0
prev = None
for x in s:
  if x != prev:
      s[count] = x
      count += 1
      prev = x
print(count)

Submission status: Accepted

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

ans = 1

now = S[0]

for s in S:
    if s != now:
        ans += 1
        now = s
    else:
        continue
print(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]:
    k += 1
print(k)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 1
if n != 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()
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:
import sys
from itertools import groupby
inputs = sys.stdin.readlines()
n = int(inputs[0])
s = inputs[1].strip()

print(len(list(groupby(s))))

Submission status: Accepted

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

import re


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

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

Submission status: Accepted

Solution code:
from itertools import groupby
N = int(input())
List = list(input())
sum_list = []
for key, value in groupby(List):
    sum_list.append(key)
print(len(sum_list))

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    S = input()

    ans = S[0]
    for s in S:
        if s != ans[-1]:
            ans += s
    print(len(ans))


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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

last = None
ans = 0
for s in S:
    if s != last:
        ans += 1
        last = s
print(ans)