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

N = INT()
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 = []
ans.append(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()
last = s[0]
ans = 1
for i in range(1,n):
  if s[i] != last:
    ans += 1
    last = s[i]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


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

print(cnt)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
nm = lambda : map(int,input().split())
nl = lambda : list(nm())

n = int(input())
l = list(input())
t = [0]
for x in l:
    if x == t[-1]:
        continue
    t.append(x)
print(len(t)-1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

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

Submission status: Accepted

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

print(sum(int(a!=b) for a,b in zip(S,S[1:]))+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
N = int(input())
S = list(input())
res = 1
for i in range(1, N):
  if S[i - 1] != S[i]:
    res += 1
print(res)

Submission status: Accepted

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


# ランレングス化 (ex. "RLL.." => [['R',1],['L',2],..]
def runLength(s):
    a = []
    for c in s:
        if len(a) == 0 or a[-1][0] != c:
            a.append([c, 1])
        else:
            a[-1][1] += 1
    return a


def main():
    _ = int(input())
    S = input().strip()
    print(len(runLength(S)))


if __name__ == '__main__':
    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(n-ans)

Submission status: Accepted

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	S = list(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=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 = 0
prev = None
for c in S:
  if prev != c:
    ans += 1
  prev = c
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
j = 0
k = 0
for i in s:
    if i != j:
        k += 1
    j = i
print(k)

Submission status: Accepted

Solution code:
N = int(input())
s = input()
last = None
res = 0
for char in s:
  if char == last:
    continue
  else:
    res += 1
  last = char
print(res)

Submission status: Accepted

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

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

print(answer)

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy
from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from random import randint
from itertools import imap as map, izip as zip, permutations, combinations, combinations_with_replacement
from __builtin__ import xrange as range
from math import ceil
from _continuation import continulet
from cStringIO import StringIO
from io import IOBase
import __pypy__
from bisect import bisect, insort, bisect_left, bisect_right
import sys
import os
import re
sys.setrecursionlimit(9999)
inf = float('inf')
mod = int(1e9) + 7
mod_ = 998244353
N = 5001
 
'''
Check for special cases (n=1)
One wrong submission = 10 mins penalty!
do smth instead of nothing and stay organized
'''


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

BUFSIZE = 8192
class FastI(IOBase):
	def __init__(self, file):
		self._fd = file.fileno()
		self._buffer = StringIO()
		self.newlines = 0
 
	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
		self.newlines = 0
		return self.buffer.read()
 
	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count("\n") + (not b)
			ptr = self._buffer.tell()
			self._buffer.seek(0, 2), self._buffer.write(
				b), self._buffer.seek(ptr)
		self.newlines -= 1
		return self._buffer.readline()
class FastO(IOBase):
	def __init__(self, file):
		self._fd = file.fileno()
		self._buffer = __pypy__.builders.StringBuilder()
		self.write = lambda s: self._buffer.append(s)
 
	def flush(self):
		os.write(self._fd, self._buffer.build())
		self._buffer = __pypy__.builders.StringBuilder()
def print(*args, **kwargs):
	sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop("end", "\n"))
	if kwargs.pop("flush", False):
		file.flush()
def gcd(x, y):
	while y:
		x, y = y, x % y
	return x
sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
	def bootstrap(cont):
		call, arg = cont.switch()
		while True:
			call, arg = cont.switch(to=continulet(
				lambda _, f, args: f(*args), call, arg))
	cont = continulet(bootstrap)
	cont.switch()
	main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))


n = ni()

s = [_ for _ in input()]

ans = []

last = ""
for i in range(n):
    if s[i] == last:
        continue
    ans += s[i]
    last = s[i]

print(len(ans))

Submission status: Accepted

Solution code:
#    !/usr/bin/env python3
#    encoding: UTF-8
#    Last Modified: 19/Oct/2019 05:35:13 PM


#    ✪ H4WK3yE乡
#    Mohd. Farhan Tahir
#    Indian Institute Of Information Technology (IIIT), Gwalior


import sys
import os
from io import IOBase, BytesIO


def main():
    n = int(input())
    s = list(input())
    i = 0
    j = ""
    ans = 0
    while i != n:
        if s[i] == j:
            i += 1
        else:
            j = s[i]
            ans += 1
            i += 1
    print(ans)


BUFSIZE = 8192


class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill():
            pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill()
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        py2 = round(0.5)
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2 == 1:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode("ascii"))
            self.read = lambda: self.buffer.read().decode("ascii")
            self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


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


def get_ints():
    return map(int, sys.stdin.readline().split())


def input():
    return sys.stdin.readline().strip()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
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:
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# 
# a, b = map(int, input().split())
# 

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

pre = "1"
ans = 0
for c in S:
    if c != pre:
        ans += 1
        pre = c
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
cnt=0
now=''
for c in S:
    if c!=now:
        cnt+=1
        now=c

print(cnt)

Submission status: Accepted

Solution code:
def getRunLengthEncoding(Ss):
    anss = []
    Ss += '$'
    SPrev = Ss[0]
    num = 1
    for S in Ss[1:]:
        if S == SPrev:
            num += 1
        else:
            anss.append((SPrev, num))
            SPrev = S
            num = 1
    return anss

N = int(input())
Ss = input()

anss = getRunLengthEncoding(Ss)
print(len(anss))

Submission status: Accepted

Solution code:
abc=list(map(chr,range(97,123)))
n=int(input())
s=input()
for x in abc:
    while x*2 in s:
        s=s.replace(x*2,x)
print(len(s))

Submission status: Accepted

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

cl = 0
pre = ''
for i in range(n):
    if s[i] != pre:
        cl += 1
    pre = s[i]
print(cl)

Submission status: Accepted

Solution code:
input()
from itertools import*
print(len([x for x in groupby(input())]))

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

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

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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


a = S[0]
for c, d in zip(S, S[1:]):
    if c != d:
        a += d
print(len(a))

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = list(input())
ans = 0
i = 0
while i < n:
    tmp = s[i]
    while i < n:
        if tmp == s[i]:
            i += 1
        else:
            break
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
N = int(input())
A = input()
S = ""
for a in  A:
	if len(S) == 0 or S[-1]!=a:
		S += a
print(len(S))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
prev = ""
ans = N
for i in S:
    if i == prev:
        ans -= 1
    else:
        prev = i
print(ans)

Submission status: Accepted

Solution code:
n=input()
s=input()
tmp1=""
tmp2=""
ans=0
for i in s:
    tmp1=i
    if tmp1!=tmp2:
        ans+=1
    tmp2=tmp1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n = ni()
s = ns()

bef = ""
ans = 0
for si in s:
    if si != bef:
        ans += 1

    bef = si

print(ans)

Submission status: Accepted

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


def solve(N: int, S: str):

    ans = []
    n = S[0]
    c = 1
    for i in range(1,N):
        if(S[i] == n):
            c += 1
        else:
            ans.append(n)
            n = S[i]
            c = 1
    ans.append(n)

    print(len(ans))
    # print(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 = input()

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

print(count)

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
S = input()[:-1]
ans = 0
prev = ""
for s in S:
    if s == prev:
        continue
    else:
        prev = s
        ans += 1
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())
ct=1
for i in range(1,n):
  if s[i-1]!=s[i]:
    ct+=1
print(ct)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

Solution code:
from itertools import*
_,s=open(0)
print(len(list(groupby(s)))-1)

Submission status: Accepted

Solution code:
N = int(input())

S = input()

prev = -1
count = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20

N = int(input())
S = input()
prev = "?"
ans = 0
for c in S:
    if c != prev:
        ans += 1
        prev = c
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
string = input()
total = 0
cur = None
for c in string:
    if c != cur:
        total += 1
        cur = c
print(total)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def rle(s):
    import itertools
    return list(map(lambda x: (x[0], len(list(x[1]))), itertools.groupby(s)))


print(len(rle(s)))

Submission status: Accepted

Solution code:
N = int(input())
s = input()
if N == 1:
    print(1)
    exit(0)
ans = 1
t = s[0]
for k in range(1,N):
    if s[k] != t:
        ans += 1
        t = s[k]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S= input()
s=S[0]
count=0
for i in range(1,len(S)):
    if S[i]==s:
        count+=1
    s=S[i]
print(len(S)-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=input()
before=s[0]
kotae=1

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

print(kotae)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for s1, s2 in zip(S, S[1:]):
    if s1 != s2:
        ans += 1
ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

# int(input())
# map(int, input().split())

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

x = None
ans = 0
for c in s:
    if c != x:
        x = c
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-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())

N = inp()
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
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()
p = ''
a = 0
for c in S:
    if c != p:
        p = c
        a += 1
print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = read().rstrip()

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

print(answer)

Submission status: Accepted

Solution code:
N = int(input())
S = input() + '.'

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

Submission status: Accepted

Solution code:
n = int(input())

s = input()

new = s[0]

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

print(len(new))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))
    cnt= 0
    for i in range(1, n):
        if s[i] != s[i-1]:
            cnt += 1
    print(cnt + 1)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:

N = int(input())

S = input()

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

Submission status: Accepted

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

ans = 1
re = S[0]

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools

import queue
from collections import deque



def main():
    num = int(input())
    s = list(input())
    ans = 0
    for i in range(1, num)[::-1]:
        if s[i] == s[i - 1]:
            ans += 1

    print(len(s) - ans)






if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N = int(input())
    S = input().rstrip()

    ans = 0
    prev = -1

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

    print(ans)

sol()

Submission status: Accepted

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

prev = '_'
ans = 0
for c in S:
    if c!=prev:
        ans += 1
    prev = c
print(ans)

Submission status: Accepted

Solution code:
def run_length_compress(string):
    """文字列をランレングス圧縮する
    例) string = "aabccaaabb" -> [(2, a), (1, b), (2, c), (3, a), (2, b)]
    """
    string = string + "@" # string中に絶対に現れない文字を番兵とする
    n = len(string)

    begin = 0
    end = 1
    cnt = 1
    ans = []
    while True:
        if end >= n:
            break
        if string[begin] == string[end]:
            end += 1
            cnt += 1
        else:
            ans.append((cnt, string[begin]))
            begin = end
            end = begin + 1
            cnt = 1

    return ans

n = int(input())
s = input()
ans = run_length_compress(s)
print(len(ans))

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

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

N = I()
S = str(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 = 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:
n1 = int(input())
s1 = input()

r1 = 0
c1 = ""
for i1 in range(n1):
    if s1[i1] != c1:
        r1 += 1
        c1 = s1[i1]

print(r1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def Run_length_encoding(S: str):
    """AAABBC -> [(A, 3), (B, 2), (C, 1)]
    """
    ans = []
    curr = S[0]
    counter = 0
    for c in S:
        if c == curr:
            counter += 1
        else:
            ans.append((curr, counter))
            curr = c
            counter = 1
    ans.append((curr, counter))
    return ans


def solve(N: int, S: str):
    print(len(Run_length_encoding(S)))
    return


def main():

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
S = raw_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()+"0"
b=0
for i in range(n):
  if s[i]!=s[i+1]:b+=1
print(b)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from itertools import groupby
    n=int(input())
    s=input()
    G=groupby(s)
    ans=0
    for key,it in G:
        ans+=1
    print(ans)
resolve()

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    s = input()
    k = s[0]
    ans = 1
    for i in range(1,n):
        if k != s[i]:
            ans += 1
            k = s[i]
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from itertools import groupby as gb

n = int(input())
s = input()
g = gb(list(s))
print(len(list(g)))

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)