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:
def solve():
    data = read()
    result = think(data)
    write(result)


def read():
    n = read_int(1)[0]
    return read_line(n)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(data):
    count = 0
    current_char = ''
    for i in range(len(data)):
        if current_char == data[i]:
            continue
        current_char = data[i]
        count += 1
    return count


def write(result):
    print(result)


if __name__ == '__main__':
    # import doctest
    # doctest.testmod()
    # import sys
    # sys.setrecursionlimit(10000)
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = ""
for i,s in enumerate(S):
    if i == 0:
        ans += s
    elif ans[-1] == s:
        pass
    else:
        ans+=s
print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = input()
    ans = [s[0]]
    for i in range(1,n):
        if s[i] == ans[-1][0]:
            ans[-1] = ans[-1]+s[i]
        else:
            ans.append(s[i])
    print(len(ans))    
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
  N = int(input())
  S = input()
  c = ''
  ans = 0
  for s in S:
    if s == c: continue
    c = s
    ans += 1
  return ans

print(solve())

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
D = input()
ans = 1
pre = ""
for d in D:
    if pre and pre!=d:
        ans += 1
    pre = d
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 1
pre = s[0]
for cur in s[1:]:
    if cur!=pre:
        cnt += 1
    pre = cur

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

N = int(input().split()[0])
S = input()
s_list = list(S)
count = 1

for i in range(1, N):
    if s_list[i] != s_list[i - 1]:
        count += 1
ans = count
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 numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(raw_input())
s = raw_input()
ans = 0
prev = -1
for x in s:
	if x != prev:
		ans += 1
	prev = x
print ans

Submission status: Accepted

Solution code:
# coding: utf-8

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

output = N

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

print(output)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()

tmp = ""
ans = 0
for i in s:
  if i != tmp:
    ans += 1
    tmp = i
  else:
    continue
else:
  if i != tmp:
    ans += 1
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()

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

Submission status: Accepted

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

ans=1

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

Submission status: Accepted

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

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

c = 0
for i in range(len(a)):
    c += a[i]

print(n-c)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())

def main():
    N = ii()
    S = input()
    stack = []
    for s in S:
        if not stack or stack[-1] != s:
            stack.append(s)
    print(len(stack))


main()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    S = input()
    res = 1
    s1 = S[0]
    for s2 in S[1:]:
        if s1 != s2:
            res += 1
            s1 = s2
    print(res)

Submission status: Accepted

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

result = 1
for i in range(1, N):
    if arr[i] != arr[i-1]:
        result += 1

print(result)

Submission status: Accepted

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

ans = 0
prev = " "
for c in s:
    if c!=prev:
        ans += 1
    prev = c
if c!=prev: ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
    n = ni()
    s = ns()

    res = s[0]
    pre = s[0]
    for i, ss in enumerate(s[1:]):
        if ss == pre:
            pass
        else:
            res += pre
            pre = ss
    if not res:
        print(1)
        return
    print(len(res))
main()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    S = input()
    bs = S[0]
    ans = 1
    for s in S[1::]:
        if bs != s:
           bs = s 
           ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
l=list(input())
res=[l[0],]
for item in l[1:]:
  if res[-1]!=item:
    res.append(item)
print(len(res))

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

Solution code:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    n = int(input())
    s = list(input())
    ansl = []
    c = True
    k = ""
    for i in range(n):
        if c:
            k = s[i]
            ansl.append(s[i])
            c = False
        elif not c and k != s[i]:
            k = s[i]
            ansl.append(s[i])
    
    print(len(ansl))




    
            
    

    

    

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
s = input()
cnt = 0
ans = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        continue
    else:
        ans += 1
print(ans+1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N = II()
    S = input()
    count = 0
    pre = -1
    for s in S:
        if s != pre:
            count += 1
            pre = s
    print(count)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n  = int(input())
s = input()
ans = 0
now = ""
for ss in s:
    if now  == "":
        now = ss
        ans += 1
    elif now == ss:
        continue
    elif now != ss:
        ans += 1
        now = ss
print(ans)

Submission status: Accepted

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

if N == 1:
    print(1)
    exit()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(input())
t = 0
c = 0
for i in l:
	if i!= t:
		c += 1
		t = i
print(c)

Submission status: Accepted

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

prev = ""
res = ""
for s in S:
    if s != prev:
        res += s
        prev = s

print(len(res))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
last = ' '
ans = 0
for i in range(n):
  if s[i] != last:
    ans += 1
    last = s[i]
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()
    ans = 1
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            continue
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(str, input()))
ret = 1

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

Submission status: Accepted

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

Submission status: Accepted

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

ans=0
p=''
for i in range(N):
	if S[i]==p:
		pass
	else:
		p=S[i]
		ans+=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = []
last = '1'
for i in s:
    if i != last:
        ans.append(i)
        last = i
print(len(ans))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
# debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = II()
    S = SI()

    current = ''
    cnt = 0
    for c in S:
        if c == current:
            pass
        else:
            cnt += 1
        current = c
    print(cnt)


solve()

Submission status: Accepted

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

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:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, S):
    ans = 1
    for i in range(0, N-1):
        if S[i] != S[i+1]:
            ans += 1

    return ans


def main():
    N = read_int()
    S = read_str()
    print(slv(N, S))


if __name__ == '__main__':
    main()

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:
# import sys
# input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**7)

n = int(input())
s = input().rstrip() + "#"

ans = 0
prev = s[0]
for ch in s[1:]:
    if ch != prev:
        ans += 1
    prev = ch
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:
# coding: utf-8
# Your code here!
N=int(input())
S=list(input())

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

print(ans+1)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
ans = 1
tmp = s[0]
for t in s:
  if tmp == t:
    pass
  else:
    tmp = t 
    ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
s = input()
res=0

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

print(n-res)

Submission status: Accepted

Solution code:
n = int(input())
#d = list(map(lambda x:int(x),input().split()))
s = input()
ans = 0
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        ans += 1

print(ans+1)

Submission status: Accepted

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

c=0

v=""
for i in range(n):
    p=s[i]
    if p!=v:
        c+=1
        v=p
print(c)

Submission status: Accepted

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

ans = 0
cur = 0
while cur < n:
    j = cur
    while j < n and s[j] == s[cur]:
        j += 1
    ans += 1
    cur = j
print(ans)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
s = ns()
pre = s[0]
c = 1
for si in s[1:]:
    if si != pre:
        c += 1
        pre = si
print(c)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

print(kosuu)

Submission status: Accepted

Solution code:
def main():

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)

def main():
    n = int(input())
    s = input()
    ans = 1
    pre = s[0]
    for c in s[1:]:
        if c != pre:
            ans += 1
            pre = c

    print(ans)

main()

Submission status: Accepted

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


def main():
    import math
    import collections
    import itertools

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

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



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
s=input().rstrip()
now='X'
ans=0
for i in s:
    if i==now:
        pass
    else:
        ans+=1
        now=i
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
import sys
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    s = input()
    # A,B = [int(a) for a in input().split()]
    # H = [int(a) for a in input().split()]
    # xy = [
    #     [int(a) for a in input().split()]
    #     for _ in range(N)
    # ]

    r = 1
    b = s[0]
    for i in range(1, N):
        if s[i] == b:
            continue
        r += 1
        b = s[i]
    print(r)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

res = 1
now = S[0]

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

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

sum = 1
now = S[0]
for i in range(1, N):
	if now != S[i]:
		sum += 1
		now = S[i]
print(sum)

Submission status: Accepted

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

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

    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
inf = float("inf")
# sys.setrecursionlimit(1000000)


# abc='abcdefghijklmnopqrstuvwxyz'

def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n = int(input())
string = input()
last = string[0]
curr = 1
for i in range(1,n):
    if string[i]==last:
        continue
    else:
        curr+=1
        last = string[i]
print(curr)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
pre_s = ''
ans = 0
for si in S:
    if pre_s != si:
        ans += 1
    pre_s = si
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 = list(input())

count = 1
tmp = S[0]
i = 1
while i < N:
    if S[i] == tmp:
        i += 1
    else:
        count += 1
        tmp = S[i]
        i += 1

print (count)

Submission status: Accepted

Solution code:
input()
a,b=0,""
for i in input():
    if b!=i:
        b=i
        a+=1
print(a)

Submission status: Accepted

Solution code:
#C問題
N = int(input())
S = list(str(input()))

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

res = 0
pre = ""
for s in S:
    if pre != s:
        res += 1
        pre = s

print(res)

Submission status: Accepted

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

ans = 0
for i, Si in enumerate(S):
    if i == 0:
        ans += 1
        Si_prev = Si
    else:
        if Si != Si_prev:
            ans += 1
            Si_prev = Si
        else:
            continue

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

s = input()

count = 1

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = LI()
    s = S()
    ans = 0
    pre = 0
    for ss in s:
        if ss != pre:
            ans += 1
        pre = ss
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

import itertools
print(len(list(itertools.groupby(ss))))

Submission status: Accepted

Solution code:
import itertools
n = int(input())
s = input()
d = itertools.groupby(s)
print(len(list(d)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 1
tmp = S[0]
for i in range(1,N):
	if tmp == S[i]:
		continue
	else:
		ans += 1
		tmp = S[i]

print(ans)