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: Wrong Answer

Solution code:
n = int(input())
a = str(input())
b = "aa bb cc dd ee ff gg hh jj ii kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz"
b = list(b.split())
c = "a b c d e f g h i j k l m n o p q r s t u v w x y z"
c = list(c.split())
for i in range(n):
    for j in range(len(b)):
        a = a.replace(b[j],c[j])
print(len(a))

Submission status: Wrong Answer

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

X = N
A = list(str(S))
print(A)
for i in range(N - 1):
    if A[i] == A[i + 1]:
        X -= 1
print(X)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = str(input())
b = "aa bb cc dd ee ff gg hh jj ii kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz"
b = list(b.split())
c = "a b c d e f g h i j k l m n o p q r s t u v w x y z"
c = list(c.split())
for i in range(n):
    for j in range(len(b)):
        a = a.replace(b[j],c[j])
print(a)

Submission status: Wrong Answer

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

for i, e in enumerate(sl):
    if i < len(sl) - 2:
        if e == sl[i+1]:
            anssl[i+1] = False
if sl[len(sl)-1] == sl[(len(sl)-2)]:
    anssl[len(sl)-1] = False
print(anssl)
ans = [i for i in anssl if i != False]
print(len(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = str(input())
b = "aa bb cc dd ee ff gg hh jj ii kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz"
b = list(b.split())
c = "a b c d e f g h i j k l m n o p q r s t u v w x y z"
c = list(c.split())
for i in range(3):
    for j in range(len(b)):
        a = a.replace(b[j],c[j])
print(len(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = str(input())
b = "aa bb cc dd ee ff gg hh jj ii kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz"
b = list(b.split())
c = "a b c d e f g h i j k l m n o p q r s t u v w x y z"
c = list(c.split())
for i in range(3):
    for j in range(len(b)):
        a = a.replace(b[j],c[j])
print(a)

Submission status: Wrong Answer

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

r = 0
for i in range(N):

    if i + 1 != N:
        if S[i] == S[i+1]:
            pass
        else:
            r = r + 1
    else:
        if S[i] != S[i-1]:
            r = r + 1
        else:
            pass

print(r)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = str(input())
b = "aa bb cc dd ee ff gg hh jj ii kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz"
b = list(b.split())
c = "a b c d e f g h i j k l m n o p q r s t u v w x y z"
c = list(c.split())
i = 0
while i < n:
    for j in range(len(b)):
        a = a.replace(b[j],c[j])
    i += 1
print(len(a))

Submission status: Wrong Answer

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

ans = [S[-1]]

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

print(len(ans))

Submission status: Wrong Answer

Solution code:
# ABC143 C
N = int(input())
S = input()
L = [s for s in S]
print(L)
M = []
cnt = 0
ans_c = 0

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

for i in range(N-1):
    if L[i]==L[i+1]:
        cnt += 1
    else:
        ans_c += cnt
        cnt = 0
    if i == N-2:
        ans_c += cnt
print(N-ans_c)

Submission status: Wrong Answer

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

S = S + 'A'
last = S[0]
cnt = 0
for s in S[1:]:
    if last == s:
        continue
    else:
        cnt += 1
        last = s
print(cnt-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0
tmp = 0
count = 0
if S == S[0]*N:
    print(1)
else:    
    for i in range(1,N):
        if S[i] == S[i-1]:
            count += 1
        elif S[i] == S[i-1] and i == N:
            tmp += count
            count = 0
        else:
            tmp += count
            count = 0
    ans = N - tmp
    print(tmp)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

total = []

def yugo(st,x):
	if len(st) >= x + 1:
		return st[x]
	if st[x] == st[x + 1]:
		return yugo(st,x+1)
	else:
		return st[x] +  yugo(st,x+1)
	

print(int(len(yugo(S,0))))

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
S = input()
if N == 1:
    print("1")
    sys.exit()
ans = 0
for i in range(N - 1):
    print(i)
    if S[i] != S[i + 1]:
        ans += 1
    if i == N - 2:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
a=input()
a=int(a)
b=input()
lis=[]
c=b[0]
for i in range(a-1):
    if b[i+1]==b[i-1]:
        continue
    else:
        lis.append(b[i])
print(len(lis))

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
S = input()
if N == 1:
    print("1")
    sys.exit()
ans = 0
for i in range(N - 1):
    print(i)
    if S[i] != S[i + 1]:
        ans += 1
        print("if_1")
    if i == N - 2:
        ans += 1
        print("if_2")

print(ans)

Submission status: Wrong Answer

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

#output
pointer = 0
sum = 0
for i in range(N-1):
    if S[i+1] != S[i]:
        sum += 1
    pointer += 1

if N >=2:
    if S[N-1] != S[N-2]:
        sum += 1
    elif sum == 0:
        sum += 1
else:
    sum = 1

print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(input())
print(A)
ans = 1
for i in range(N-1):
  if A[i] == A[i+1]:
    continue
  else:
    ans +=1
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
sl = list(s)
anssl = list(s)
for i, e in enumerate(sl):
    if i < n - 2:
        if e == sl[i+1]:
            anssl[i+1] = 0
ans = [i for i in anssl if i != 0]
print(len(ans))

Submission status: Wrong Answer

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

count = 0
temp = ""

for s in S:
    if s == temp:
        count += 1
    temp = s
print(count)

Submission status: Wrong Answer

Solution code:
n=input()
str=input()
print(len(set(str)))

Submission status: Wrong Answer

Solution code:
import sys

def main():

	args = sys.argv
	N = int(input())
	S = input()
	C = 0
	
	for i in range(0, N-1):
		if S[i] == S[i+1]:
			C = C+1;
			
	print(C)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

def main():

	N = int(input())
	S = input()
	C = 0
	
	for i in range(0, N-1):
		if S[i] == S[i+1]:
			C = C+1;
			
	print(C)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():

	N = int(input())
	S = input()
	C = 0
	
	for i in range(0, N-1):
		if S[i] == S[i+1]:
			C = C+1;
			
	print(C)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

#output
pointer = 0
sum = 0
for i in range(N-1):
    if S[i+1] != S[i]:
        sum += 1
    pointer += 1
if S[N-1] != S[N-2]:
    sum += 1
elif sum == 0:
    sum += 1

print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
color = input()
print(color)
while(True):
    for i in range(len(color)-1): 
        if color[i]==color[i+1]:
            color = color[:i] + color[(i+1):]
            break
        else:
            pass
    else:
        break
print(len(color))

Submission status: Wrong Answer

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

ans = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print(N,c)
flag=True


while(flag):
  flag=False
  c_new=''
  for i in range(len(c)-1):
    if c[i]==c[i+1]:
      flag=True
      #del c[i-minus]
      #minus+=1
    else:
      c_new+=c[i]
  c_new+=c[len(c)-1]
  c=c_new
print(len(c))

Submission status: Wrong Answer

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

ans = 0
n = 1

while n<N:
  if S[n]==S[n-1]:
    ans +=1
    n +=1
  else:
    n+=1

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=str()
for i in range(1,n):
	if not s[i-1]==s[i]:
		ans+=s[i-1]
if n>=2 and not s[n-1]==s[n-2]:
	ans+=s[n-1]
elif len(ans)==0 or n==1:
	ans='1'
print(len(ans))

Submission status: Wrong Answer

Solution code:
_ = input()
S = input()
k = 1
for b, a in zip(S[:-1], S[1:]):
    if b==a:
        k += 1
print(k)

Submission status: Wrong Answer

Solution code:
import sys

n = int(sys.stdin.readline())
S = list(sys.stdin.readline())

for i in range(1, n):
    if(S[i-1] ==S[i]):
        S[i-1]=""
S = ''.join(S)
#print(S)
print(len(S))

Submission status: Wrong Answer

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

if n == 1:
    print(1)

ss = []

for i in range(1, n):
    if s[i] != s[i-1]:
        ss.append(s[i])

print(1+len(ss))

Submission status: Wrong Answer

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

_n = int(input())
_s = input()[:-1]


print(len(list(set(_s))))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input()
i=0
b=[a[0]]
j=0
p=0
while(i<len(a)):
    if(b[-1]!=a[i]):
        b.append(a[i])
    i=i+1
for t in b:
    print(t,end="")

Submission status: Wrong Answer

Solution code:
import re

def C():
    n = input()
    s = input()
    ss = re.sub(r"(.)\1{1,}",r"\1",s)
    print(ss)
    print(len(ss))

if __name__ == '__main__':
    C()

Submission status: Wrong Answer

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

N = int(input())
s= list(input())

s0 = s.pop()

cnt = 1

while s:
    s1 = s.pop()
    if s1!=s0:
        cnt += 1
        s0 = s1
print(cnt)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from itertools import permutations, combinations,combinations_with_replacement,product
from fractions import Fraction as frac
import bisect
import heapq

import logging
logging.basicConfig(level=logging.DEBUG)

import sys
#input = sys.stdin.readline().rstrip

setrecursionlimit(1000000)

MOD = 10**9+7
INF = float('inf')

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

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

    print(ans if ans !=0 else 1)
main()

Submission status: Wrong Answer

Solution code:
S = input()
k = 1
for b, a in zip(S[:-1], S[1:]):
    if b==a:
        k += 1
print(k)

Submission status: Wrong Answer

Solution code:
def A():
    temp = [int(i) for i in input().split()]
    print(max(0, temp[0]-2*temp[1]))

def B():
    N = int(input())
    T = [int(i) for i in input().split()]
    s = 0
    for i in range(N):
        for j in range(i):
            s += T[i]*T[j]
    print(s)

def C():
    N = int(input())
    S = input()
    if len(S) < 2:
        return S
    ans = 1
    cur_c = S[0]
    for c in S:
        if c != cur_c:
            ans += 1
            cur_c = c
    
    print(ans)

C()

Submission status: Wrong Answer

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

if n == 1:
    print(1)

for i in range(1, n):
    if s[i] == s[i-1]:
        s[i-1] = 'Z'
        
ss = [x for x in s if x!='Z']

print(len(ss))

Submission status: Wrong Answer

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

new_s = ''
tmp = ''
for i in s:
  if tmp != i:
    new_s = new_s + i
    tmp = i
  else:
    tmp = i
    continue
  
print(new_s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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


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


def INT(): return int(input())


def MAP(): return map(int, input().split())


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


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


def main():
    n = INT()
    s = input()
    ans =  []
    for i in range(n-1):
        if s[i] != s[i+1]:
            ans.append(s[i])

    if s[n-2] != s[n-1]:
        ans.append(s[n-1])

    if len(set(s)) == 1:
        print(1)
    else:
        print(len(ans))
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

N = int(input())
s= list(input())

s0 = s.pop()

cnt = 1

while s:
    s1 = s.pop()
    if s1!=s0:
        cnt += 1
        s0 = s1
print(cnt)

Submission status: Wrong Answer

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


temp=0

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

Submission status: Wrong Answer

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

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

solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
if n>=2:

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

    if s[n-1]==s[n-2]:
        n-=1

    print(n+1)

else:
    print("1")

Submission status: Wrong Answer

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

n = int(input())
c = list(input())

after = []
last = ""
for v in c:
    if v != last:
        after.append(v)
    last = v

print(len(after))

Submission status: Wrong Answer

Solution code:
def resolve():
    n = int(input())

    targets = input()
    ans = 1

    for i in range(len(targets)-1):
        if targets[i] == targets[i+1]:
            pass
        else:
            ans += 1

    print(ans)
#resolve()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
output = 0
tmp = ""

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

if tmp != s[-1]:
    output += 1

if output == 0:
    output = 1

print(output)

Submission status: Wrong Answer

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

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

if s[n-1]==s[n-2]:
    n-=1

print(n+1)

Submission status: Wrong Answer

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: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
x = 'X'
for s in S:
  if x == s:
    ans += 1
  x = s
  
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = list(input())
tot = 0
prev = '1'
for i in range(1,N):
    if lst[i] != prev:
        prev = lst[i]
        tot += 1
print(tot)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

print(s)

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

Submission status: Wrong Answer

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

Submission status: Time Limit Exceeded

Solution code:
alphabet = ["aa","bb","cc","dd","ee","ff","gg","hh","ii","jj","kk","ll","mm","nn","oo","pp","qq","rr","ss","tt","uu","vv","ww","xx","yy","zz"]
alphabet2 = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
N = int(input())
S = list(input())
import math
i = 0
max = N-2
roop = True
while roop == True:
  if i+1 > len(S)-1:
    roop = False
  elif S[i] == S[i+1]:
    del S[i]
    max -= 1
  else:
    i += 1
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
alphabet = ["aa","bb","cc","dd","ee","ff","gg","hh","ii","jj","kk","ll","mm","nn","oo","pp","qq","rr","ss","tt","uu","vv","ww","xx","yy","zz"]
alphabet2 = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
N = int(input())
S = input()
import math
for k in range(math.ceil(N/2)):
  for i in alphabet:
    if i in S:
      x = alphabet.index(i)
      S = S.replace(i, alphabet2[x])
print(len(S))

Submission status: Time Limit Exceeded

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

i=0
N1=N #配列長さ
while i<=N1-2:
    if S[i]==S[i+1]:
        for k in range(i+2,N):
            S[k-1]=S[k]
        N1=N1-1
    else:
        i=i+1
print(N1)

Submission status: Time Limit Exceeded

Solution code:
import re

n = int(input())

s = input()

l = []

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


for h in range(len(l)-1):
 
    if l[h] == l[h+1]:
        l[h] = "red"

while "red" in l :
    l.remove("red")  #全ての"red"を削除します。


print(len(l))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [n for n in input()]
temp = []
result = []
for i in range(N-1):
  if S[i] == S[i+1]:
    temp.append(i)
for i in range(N):
  if i not in temp:
    result.append(S[i])
print(len(result))

Submission status: Time Limit Exceeded

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

#
keizoku =True
count_list =[0,1]
for i in range(N):
    for j in range(len(S)-1):
        if S[j] == S[j+1]:
            del S_list[j]
            S="".join(S_list)
            break
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
li=list(input())
ln=[]
for i in range(n-1):
  if li[i]==li[i+1]:
    ln.append(i)
dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]
listn=dellist(li,ln)
print(len(listn))

Submission status: Time Limit Exceeded

Solution code:
#16
n = int(input())
s = list(input())
i = 0
while i < n:
    check_end = int(len(s)) 
    if check_end == i+1:
        break
    if s[i] == s[i+1]:
        s.pop(i)
        i = 0
    else:
        i += 1
result = int(len(s))
print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
list=[S[i] for i in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
        if list[i]==list[j]:
            list[j]="0"
        else:
            break
list=[s for s in list if s != '0']
print(len(list))

Submission status: Time Limit Exceeded

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

p = [True]*n
for i in range(n-1):
  for j in range(i+1, n):
    if s[i] == s[j]:
      p[j] = False
    elif s[i] != s[j]:
      break
print(p.count(True))

Submission status: Time Limit Exceeded

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

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

print(len(''.join(s)))

Submission status: Time Limit Exceeded

Solution code:
import sys


def fusion(xs):
    if len(xs) < 2:
        yield from xs
    elif xs[0] == xs[1]:
        yield from fusion(xs[1:])
    else:
        yield xs[0]
        yield from fusion(xs[1:])


def main():
    sys.setrecursionlimit(101010)
    N = input()
    S = input()
    print(sum(1 for _ in fusion(S)))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(2000000)

def slime(slist,t):
    if len(slist)==1:
        if len(t)==0:
            return slist[0]
        elif slist[0]==t[0]:
            return t
        else:
#            t.append(slist[0])
            t.insert(0,slist[0])
        return t
    else:
        if slist[0]==slist[1]:
            del slist[0]
        else:
#            t.append(slist[0])
            t.insert(0,slist[0])
            del slist[0]
        return slime(slist,t)
        


n=int(input())
s=input()
slist=[]
t=[]

for i in range(len(s)):
    slist.append(s[i])
    
t=slime(slist,t)
print(len(t))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[i for i in input()]
flg=True
while flg:
  flg=False
  for i in range(len(s)-1):
    if s[i]==s[i+1]:
      s.pop(i)
      flg=True
      break
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(str(input()))
for i in range(n):
    if i+2 > len(s):
            break
    while s[i] == s[i+1]:
        s.pop(i+1)
        if i+2 > len(s):
            break
print(len(s))

Submission status: Time Limit Exceeded

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

count = 0
while len(s)>1 :
    if s[0] == s[1]:
        s.pop(0)
    else:
        s.pop(0)
        count += 1

print(count+1)

Submission status: Time Limit Exceeded

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

while len(S) > 0:
    i = 0
    si = S[i]
    j = i + 1
    while j < len(S) and si == S[j]:
        j += 1
    S = S[j:]
    count += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
charar = input()
charlist = []
while not all([x==charar[0] for x in charar]):
    for i in range(len(charar)-1):
        if charar[i] != charar[i+1]:
            charlist.append(charar[:i+1])
            charar = charar[i+1:]
            break
print(len(charlist)+1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
charar = input()
charlist = []
while len(list(set(list(charar)))) >1:
    for i in range(len(charar)-1):
        if charar[i] != charar[i+1]:
            charlist.append(charar[:i+1])
            charar = charar[i+1:]
            break
print(len(charlist)+1)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
S = [i for i in S]

T = 0
while len(S) != T:
    T = len(S)
    for i in range(0, len(S)-1 ):
        if S[i] == S[i+1]:
            S.pop(i)
            break

print(len(S))

Submission status: Time Limit Exceeded

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

conti = True
while conti:
    conti = False
    for count, char in enumerate(s):
        if (count - 1) >= 0 and s[count] == s[count - 1]:
            s = s[:count] + s[count + 1:]
            conti = True
            break

print(len(s))

Submission status: Time Limit Exceeded

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

for i in range(n-1):
    if l[i]==l[i+1]:
        l.pop(i)
        l.insert(i,1)

for i in range(n):
    if 1 in l:
        l.pop(l.index(1))

print(len(l))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=input()
s=list(S)
 
#print(s)
def jokyolist(s):
  jokyo=[]
  #jokyo配列はこれから除去すべき奴の番号のリスト
  for i in range(len(s)-1):
    if s[i]==s[i+1]:
      jokyo.append(i)
    jokyo=sorted(jokyo,reverse=True)
  return jokyo
 
def remov(s,jokyo):
  for i in range(len(jokyo)):
    s.pop(jokyo[i])
    return s

def removtimes(jokyo):
  t=len(jokyo)
  return t
 
i=0
while i<=n:
  jokyo=jokyolist(s)
  if removtimes(jokyo)==0:
    break
  s=remov(s,jokyo)
  i+=1

#print(s)
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
str = input()
char_list = list(str)
del_num = []

dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]
ans =0
for i in range(len(char_list)-1):
    if char_list[i] == char_list[i+1]:
        del_num.append(i+1)

print(len(dellist(char_list,del_num)))

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())
str = input()
char_list = list(str)
del_num = []

dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]

for i in range(len(char_list)-1):
    if char_list[i] == char_list[i+1]:
        del_num.append(i+1)

print(len(dellist(char_list,del_num)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for val in range(n-1) :
	if s_list[val] == s_list[val+1] :
		s_list.pop(val)
		s_list.insert(val,1)
		
	else :
		pass
m = s_list.count(1)
for val in range(m) :
	s_list.remove(1)

print(len(s_list))

Submission status: Time Limit Exceeded

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

for val in range(n-1) :
	if s_list[val] == s_list[val+1] :
		s_list.pop(val)
		s_list.insert(val,1)
		
	else :
		pass
s_list = [s for s in s_list if s != 1]
print(len(s_list))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
i = 0
while i != len(S) - 1:
    if S[i] == S[i+1]:
        S = S[:i+1] + S[i+2:]
        i = 0
        continue
    i = i + 1 
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
count = 1
l = len(set(list(s)))
while( l!=1 ):
    if s[1]!=s[0]:
        count += 1
        s = s[1:]
        l = len(set(list(s)))
    else:
        s = s[1:]
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
count = 1
l = len(set(list(s)))
while( l!=1 ):
    if s[1]!=s[0]:
        count += 1
        s = s[1:]
    else:
        s = s[1:]
    l = len(set(list(s)))
print(count)

Submission status: Time Limit Exceeded

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

def fun(list,c=0):
    if len(list) == 1:
        return c+1
    if list[0] == list[1]:
        return fun(list[1:],c)
    else:
        return fun(list[1:],c+1)

print(fun(S))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
h = str(input())
h = list(h)
h2 = list(h)
def mojiretu(n, h):
    for i in range(0, n - 1):
            if h[i] == h[i + 1]:
                h2.remove(h[i])
    return len(h2)
print(mojiretu(n,h))

Submission status: Time Limit Exceeded

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

count=1

while count!=0:
  count=0
  for j in range(0,len(s_list)-1):
    if s_list[j] == s_list[j+1]:
      s_list.pop(j+1)
      count=1
      break
  
print(len(s_list))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=input()
s_list=list(s)
count=0
for i in range(0,N):
  for j in range(0,len(s_list)-1):
    if s_list[j] == s_list[j+1]:
      s_list.pop(j+1)
      count=1
      break
  if count==0:
    break
print(len(s_list))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
#print(S)
cnt = 1
S_list = [s for s in S]
#print(S_list)
for i in range(N):
    if S_list[N-1-i] != S_list[N-1-(i+1)] and N-1-(i+1)>=0:
        S_list.insert(N-1-i,"|")
        cnt += 1
    #print(S_list)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
a = list(s)
#print(a)
b = 1
while b != 0:
    b = 0
    #i = 1
    #print(i)
    for i in range(1,len(a)):
        if a[i-1] == a[i]:
            del a[i]
            #print(a)
            b = b + 1
            #print(b)
            break
print(len(a))