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:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print(max(0, a - 2 * b))
    return

#B
def B():
    n = II()
    d = LI()
    ans = 0
    for i in range(n):
        for k in range(i+1, n):
            ans += d[i] * d[k]
    print(ans)
    return

#C
def C():
    n = II()
    s = S()
    i = 0
    ans = 1
    for i in range(1, n):
        if s[i - 1] == s[i]:
            continue
        ans += 1
    print(ans)
    return

#D
def D():
    n = II()
    l = LI()
    l.sort()
    ans = 0
    for i in range(n - 1, 0, -1):
        for k in range(i - 1, -1, -1):
            ab = l[i] - l[k]
            c = max(0, k - bisect_right(l, ab))
            ans += c
    print(ans)
    return

#E
def E():
    n, m, l = LI()
    dist = [[inf] * n for i in range(n)]

    for _ in range(m):
        a, b, c = LI_()
        c += 1
        if c > l:
            continue
        dist[a][b] = c
        dist[b][a] = c

    supply = [[n] * n for i in range(n)]
    for k in range(n):
        distk = dist[k]
        for i in range(n):
            if i == k:
                continue
            disti = dist[i]
            distik = dist[i][k]
            for j in range(i + 1, n):
                if distik + distk[j] < disti[j]:
                    disti[j] = distik + distk[j]
                    dist[j][i] = disti[j]

    lis = [[] for i in range(n)]
    for i in range(n):
        for j in range(i + 1, n):
            if dist[i][j] <= l:
                supply[i][j] = 0
                supply[j][i] = 0
                lis[i].append(j)
                lis[j].append(i)

    for i in range(n):
        q = []
        for k in lis[i]:
            heappush(q, (0, k))
        supplyi = supply[i]

        while q:
            time, p = heappop(q)
            for k in lis[p]:
                if supplyi[k] > time + 1:
                    supplyi[k] = time + 1
                    heappush(q, (time + 1, k))

    q = II()
    for _ in range(q):
        s, t = LI_()
        if dist[s][t] == inf:
            print(-1)
            continue
        else:
            print(supply[s][t])
    return


#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

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

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

print(c+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
S = input()
ans = 1
if N == 1:
  print(1)
  sys.exit()
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())
g=0
for i in range(n-1):
    if not s[i] == s[i+1]:
        g += 1
print(g+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools

stdin = sys.stdin

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


n = ni()
s = input()
ct = 0
p = s[0]
for i in range(1, n):
    if p != s[i]:
        ct += 1
        p = s[i]
print(ct+1)

Submission status: Accepted

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

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

print(len(S))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(len(ans))

Submission status: Accepted

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

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

    peek += 1

print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re
N = int(input())
S = input()
COLORS = list(set(list(S)))

for color in COLORS:
    S = re.sub('{}+'.format(color), color, S)

print(len(S))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = input()
S = []
for a in range(N):
    S.append(X[a])

if N == 1:
    print(1)
else:
    for i in range(1,N):
        if S[i] != S[i-1]:
            continue
        else:
            S[i-1] = 'X'
    lista = [k for k in S if k != 'X']
    print(len(lista))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import groupby

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

print(len([x[0] for x in groupby(S)]))

Submission status: Accepted

Solution code:
total = input()
slimes = list(input())

pre = ""
last = []

for i in slimes:
    if pre != i:
        last.append(i)
    pre = i

print(len(last))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
slimes = 0
cache = ""
for i in s:
  if cache == i:
    continue
  else:
    cache = i
    slimes += 1
print(slimes)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ns = ""
pre_c = s[0]
for c in s[1:]:
  if c != pre_c:
    ns += pre_c
  pre_c = c    
ns += s[-1]
s = ns
print(len(s))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
f = 1
while f == 1:
  ns = ""
  pre_c = s[0]
  f = 0
  for c in s[1:]:
    if c != pre_c:
      ns += pre_c
    else:
      f = 1
    pre_c = c    
  ns += s[-1]
  s = ns
print(len(s))

Submission status: Accepted

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

Submission status: Accepted

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

cur_char = "0"
cnt = 0

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

Submission status: Accepted

Solution code:
N = int(input())
x = [j for j in input()]
i = 0

while len(x)-2>=i:
  if x[i]==x[i+1]:
    x.pop(i)
  else:
    i += 1
print(len(x))

Submission status: Accepted

Solution code:
n =int(input())
s = input()
checks = s[0]
ans = 1
for c in list(s):
  if c != checks:
    checks = c
    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 = input()

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

Submission status: Accepted

Solution code:
_ = input()
s = input()
place_holder = s[0]
count = 1
for letter in s[1:]:
    if place_holder == letter:
        continue
    else:
        place_holder = letter
        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:
n = int(input())
s = input()

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

print(len(result))

Submission status: Accepted

Solution code:
#15minくらい？

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

S = S + "0"
string = []

for i in range(N):
  if i != N and S[i] != S[i+1]:
    string.append(S[i])
  i += 1
  
print(len(string))

Submission status: Accepted

Solution code:
n = int(input())
string = input()
count = 1
pivot = string[0]
for s in string[1:]:
    if s != pivot:
        count += 1
        pivot = s
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

prev = S[0]

num = 1
for s in S[1:]:
    if prev != s:
        num += 1
    prev = s

print(num)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
result = ''
previous = ''
for s in S:
    if s != previous:
        result += s
    previous = s
print(len(result))

Submission status: Accepted

Solution code:
N = int(input())
slimes = input()
new_slime = ''

current_letter = ''

for i in slimes:
    if i == current_letter:
        pass
    else :
        new_slime += i
    current_letter = i
print(len(new_slime))

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()
lists = list(S)
#print(lists)
count = N
num = 0
while count>1:
    if lists[0] == lists[1]:
        count -= 1
        del lists[0]
    else:
        num += 1
        count -= 1
        del lists[0]    
ans = num+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:
# coding: utf-8
# Your code here!
 
#in_N = [int(i) for i in input().split()];
in_N = int(input());
in_S = str(input());
#in_S = [str(i) for i in input().split()];
S = [str(s) for s in in_S]
#print(in_N);
#print(in_S);
#print(S);

#calc
total = 0;
for i in range(in_N-1):
    if(S[i] == S[i+1]):
        total +=1;
#    for j in range(len(in_d)-1):
        #print(i);
        #print(j);
#        if(i+j+1 == len(in_d)):break;
#        total += in_d[i]*in_d[i+j+1];
 
print(in_N - total);

Submission status: Accepted

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

L=[s[0]]
bef=s[0]
for i in s[1:]:
      if i!=bef:
            L.append(i)
      bef=i
print(len(L))

Submission status: Accepted

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

Submission status: Accepted

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

before = None
ans = 0
for chara in S:
  if chara != before:
    ans += 1
    before = chara
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
S=list(S)
for i in range(len(S)):
    count=0
    for j in range(i,len(S)-1):
        if S[j]==S[j+1]:
            count+=1
        else:
            break
    #print(count)
    if count>0:
        del S[i+1:i+count+1]
    #print(S)
    if i==len(S)-1:
        break
#print(S)
print(len(S))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import groupby

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

cnt = 0
for _ in groupby(S):
  cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

count = 1
now_s = s[0]

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

print(count)

Submission status: Accepted

Solution code:
_,S=input(),input();print(sum(1for a,b in zip("0"+S,S)if a!=b))

Submission status: Accepted

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

for s1,s2 in zip([0]+S,S):
  if s1 != s2:
    new_S += s2

print(len(new_S))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
s = input()
nows = ""
count = 0
for i in range(N):
	if s[i] != nows:
		count+= 1
		
	nows = s[i]
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

# import numpy as np
import math
from fractions import gcd
from collections import deque
import bisect

sys.setrecursionlimit(1000000)


def main():
    # map(int, input().split())
    # l = list(map(int, input().split()))

    N = int(input())
    S = input()
    start = S[0]
    ret = start
    for i in range(1, N):
        end = S[i]
        if start != end:
            start = end
            ret += end
    print(len(ret))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
s = input()
ans = 1
for idx, val in enumerate(s):
    if idx == N - 1:
        break
    if s[idx + 1] != val:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

prev_c = None
count = 0
for c in S:
  if c != prev_c:
    count += 1
  prev_c = c
  
print(count)

Submission status: Accepted

Solution code:
n=input()
a=list(input())

b=0
while(b<len(a)-1):
  if a[b]==a[b+1]:
    del a[b+1]
  else:
    b=b+1
print(len(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
A=list(input())
q=A[0]
color=1
for i in range(1,n):
  if A[i]==q:
    continue
  else:
    color+=1
    q=A[i]
print(color)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()
s = input()
counter = 0
c = ""

for i in s :

  if i != c :
    counter += 1
    c = i

print(counter)

Submission status: Accepted

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

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]:
    continue
  else:
    count += 1

print(count)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

tmp = s[0]
cnt = 1

for i in s:
    if i != tmp:
        tmp = i
        cnt += 1
print(cnt)

Submission status: Accepted

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

for x in range(N):
    if i==0:
        i += 1
        continue
    elif S[i]==S[i-1]:
        S.pop(i-1)
        N -= 1
    else:
        i += 1
print(len(S))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

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

ans = []

for i in range(len(S)-1):
	s = S[i]
	if s == S[i+1]:
		continue
	else:
		ans.append(s)

print(len(ans))

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq

MOD = 10**9+7

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

data = 0

for i in range(N):
    if data == S[i]:
        S[i] = 0

    else:
        data = S[i]

S = [i for i in S if i != 0]
print(len(S))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = int(input())
slime = str(input())
i = 0
scount = 1
while(i < x-1):
    if(slime[i] != slime[i+1]):
        scount += 1
    i += 1
print(scount)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
counter = 1
opt = ""
for i, s in enumerate(S):
    if i == 0:
        opt = s
    else:
        if s == opt:
            continue
        else:
            counter += 1
            opt = s

print(counter)

Submission status: Accepted

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

Submission status: Accepted

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

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:

input1 = input()
input2 = input()
#input1 = "20"
#input2 = "xxzaffeeeeddfkkkkllq"
N = int(input1)
hairetu = list(input2)

i=0
s=0
a=0

for s in range (N*N):
    if len(hairetu)<i+2:
        break
    elif hairetu[i]==hairetu[i+1]:
        a = hairetu.pop(i+1)
    else:
        i=i+1

    
p = len(hairetu)
print(p)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
print(1 + sum(map(lambda i: S[i] != S[i + 1], range(N - 1))))

Submission status: Accepted

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
count = 1
prev = s[0]

for x in s:
  if prev != x:
    count += 1
  prev = x
  
print(count)

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
a = list(input())
ans = 0

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

print(ans+1)

Submission status: Accepted

Solution code:
# 2019-11-19 10:28:31(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    n, s = sys.stdin.read().split()
    n = int(n)

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

if __name__ == "__main__":
    main()

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(1+cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# いろいろやりかたありそうだけど尺取っぽくやってみた

n = int(input())
s = input()
ans = 0
l, r = 0, 0
while l < n:
    while r < n and s[l] == s[r]:
        r += 1
    if r <= l:
        r = l + 1
    ans += 1
    l = r

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
str = input()
slim = [str[0]]
for i in range(n):
  if str[i] != slim[-1]:
  	slim.append(str[i]) 
  
print(len(slim))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
d=list(s)
a=0
for i in range(n-1):
  if d[i]==d[i+1]:
    a+=1
  else:
    continue
print(n-a)

Submission status: Accepted

Solution code:
A=int(input())
B=input()
C=[]
for i in range(len(B)-1):
  if B[i]==B[i+1]:
    C.append(i+1)
print(len(B)-len(C))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
current = ''
result = 0

for i in range(n):
    if not current == s[i]:
        result += 1
        current = s[i]
        
print(result)

Submission status: Accepted

Solution code:
N = int(input())

b = ''
result = N
for s in input():
    if s == b:
        result -= 1
    b = s

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

prev = S[0]
count = 1
for c in S[1:]:
    if c == prev:
        continue
    prev = c
    count += 1
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(raw_input())
s = raw_input()
k = 0
c = None
for i in xrange(n):
  if s[i] == c:
    continue
  else:
    k += 1
    c = s[i]
print k

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()

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

print(output)

Submission status: Accepted

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

s = ""
for i in range(N):
    if i == 0:
        s += S[i]
        continue
    if S[i-1] != S[i]:
        s += S[i]
print(len(s))

Submission status: Accepted

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

tmp = s[0]
c = 1

for i in range(1,n):
    if s[i] == tmp:
        continue
    else:
        tmp = s[i]
        c += 1

print(c)

Submission status: Accepted

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

loop_flg = True
while loop_flg:
    s_length = len(S)
    next_s = [s for i, s in enumerate(S) if S[i+1:i+2] != s]
    if s_length == len(next_s):
        loop_flg = False
    else:
        S = next_s

print(len(S))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = list(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())
d = list(input())
n = 1
for i in range(N-1):
    if d[i] != d[i+1]:
        n += 1
print(n)

Submission status: Accepted

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

Submission status: Accepted

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

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

    print(ans+1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

S = list(input())

                
i = 0
while i != len(S) - 1:
    if S[i] == S[i+1]:
        S.pop(i)
    else:
        i += 1
print(len(S))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
res = ""
x = ""
for l in s:
  if l != x:
    x = l
    res += x
  else: pass
print(len(res))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
li = list(input())
for i in range(N-1):
  if li[i] == li[i+1]:
    li[i] = "P"
p = li.count("P")
print(N-p)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
S = str(input())
cnt = 1
num =0
for i in range(n):
  if S[num] != S[i]:
    num = i
    cnt += 1
#  print(i,S[i])
print(cnt)

Submission status: Accepted

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

rslt = [S[0]]
S = [i for i in S[1:]]

for i in S:
    if rslt[-1] != i:
        rslt.extend(i)

print(len(rslt))

Submission status: Accepted

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

main()

Submission status: Accepted

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