Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Step Aerobics
-->

踏み台昇降

JAG大学に通う一樹君，通称カー君は，この夏友達であるあなたに誘われて，ICPC (International Collegiate Potchari Contest) に出場することになった．
ICPCは，スポーツ系のコンテストであり，高度な運動能力が必要とされる．
しかし，カー君はいつもパソコンの前にいてばかりで，少し動くだけでも疲れてしまうほどに運動不足だった．
そこでカー君は，ICPCでいい成績を残すための第1ステップとして，手軽に始められる運動，「踏み台昇降」を始めることにした．

踏み台昇降とは，その名の通り，踏み台と床との上り下りをただひたすら繰り返すだけの単純な運動である．
ただし，踏み台昇降では，正しい足の昇降を行わなければ，その効果を得ることはできない．
正しい昇降とは，以下の2種類の内いずれかを満たす足の動きである．

 両足が床についた状態から，左足と右足を踏み台の上に上げて，踏み台の上に両足ともついた状態になる．左足と右足どちらを先に上げてもよい．

 踏み台の上に両足ともついた状態から，左足と右足を床に下げて，両足が床についた状態になる．左足と右足どちらを先に下げてもよい．

以上からわかるように，床または踏み台の上にいる状態から連続で片足だけを上げ下げしても，正しい昇降とはならない．
踏み台昇降運動では，上記の正しい昇降の動きのいずれかを満たすとき，1回とカウントし，そのカウント数が大きければ大きいほど，効果を得ることができる．
床と踏み台を往復しなくても，片道だけで1回とカウントすることに注意してほしい．

あなたは，チームメイトであるカー君に少しでも強くなってほしいと考えている．
そこであなたは，カー君が踏み台昇降をさぼっていないか，プログラムを書いてチェックしてあげることにした．
カー君が踏み台昇降で動かした足の情報が与えられるので，正しく昇降を行った回数を求めよ．
ただし，両足とも床についている状態から踏み台昇降を始めるものとする．

Input

入力は，複数のデータセットから構成され，1つの入力に含まれるデータセットの数は150以下である．
各データセットの形式は次の通りである．

$n$
$f_1$ $f_2$ ... $f_n$

1行目で，足を動かした回数を表す整数 $n$ ($1 \le n \le 100$) が与えられる．
2行目で，足の動作を表す文字列である $f_i$ が時系列順に $n$ 個，スペース区切りで与えられる．
$f_i$ は，以下の4種類の文字列の内いずれかである．

 "lu" : 左足を踏み台へ上げる．

 "ru" : 右足を踏み台へ上げる．

 "ld" : 左足を床へ下げる．

 "rd" : 右足を床へ下げる．

床についている足をさらに下げるような動作や，踏み台についている足をさらに上げるような動作は入力されないと仮定してよい．

$n$ が0の行は入力の終わりを表す．このデータについては処理を行ってはならない．

Output

各データセットに対して，1行で正しい踏み台昇降を行った回数を出力せよ．
各行の終わりに改行を出力しない場合や，不必要な文字を出力する場合，誤答と判断されてしまうため注意すること．

Sample Input

4
lu ru ld rd
4
lu ld lu ru
1
lu
10
ru lu ld rd ru rd ru lu rd ld
0

Output for Sample Input

2
1
0
4



Sample input:
4
lu ru ld rd
4
lu ld lu ru
1
lu
10
ru lu ld rd ru rd ru lu rd ld
0


Sample output:
2
1
0
4

Submission status: Wrong Answer

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break
    a = b = c = sum = 0
    lst = []
    f = [str(x) for x in raw_input().split()]
    print f
    for i in range(n):
        print a,b,c
        if f[c] == 'lu':
            a += 1
        if f[c] == 'ld':
            a -= 1
        if f[c] == 'ru':
            a += 1
        if f[c] == 'rd':
            a -= 1
        if b == 0:
            if a == 2:
                sum += 1
                b = 1
        if b == 1:
            if a == 0:
                sum += 1
                b = 0
        c += 1
    print sum

Submission status: Wrong Answer

Solution code:
import sys,os

k = int(raw_input())
al = raw_input().split()

up = 0
sup = 0
cnt = 0
lu = False
ru = False

for a in al:
    if a == "lu":
        lu = True
    elif a == "ld":
        lu = False
    elif a == "ru":
        ru = True
    elif a == "rd":
        ru = False
    
    if lu and ru:
        up = 2
    elif lu and ru:
        up = 1
    else:
        up = 0

    if sup <> 1 and up <> 1:
        if sup <> up:
            cnt = cnt + 1

    sup = up

print cnt

Submission status: Wrong Answer

Solution code:
import sys,os

k = int(raw_input())
al = raw_input().split()

up = 0
sup = 0
cnt = 0
lu = False
ru = False

for a in al:
    if a == "lu":
        lu = True
    elif a == "ld":
        lu = False
    elif a == "ru":
        ru = True
    elif a == "rd":
        ru = False
    
    if lu and ru:
        up = 2
    elif (not lu) and (not ru):
        up = 0
    else:
        up = 0

    if sup <> 1 and up <> 1:
        if sup <> up:
            cnt = cnt + 1

    sup = up

print cnt

Submission status: Wrong Answer

Solution code:
import sys,os

print "times & steps?"
k = int(raw_input())
al = raw_input().split()

up = 0
sup = 0
cnt = 0
lu = False
ru = False

for a in al:
    if a == "lu":
        lu = True
    elif a == "ld":
        lu = False
    elif a == "ru":
        ru = True
    elif a == "rd":
        ru = False
    
    if lu and ru:
        up = 2
    elif (not lu) and (not ru):
        up = 0
    else:
        up = 0

    if sup <> 1 and up <> 1:
        if sup <> up:
            cnt = cnt + 1

    sup = up

print cnt

Submission status: Wrong Answer

Solution code:
import sys,os

print "times & steps?"
k = int(raw_input())
al = raw_input().split()

if k == 0: sys.exit()

up = 0
sup = 0
cnt = 0
lu = False
ru = False

for a in al:
    if a == "lu":
        lu = True
    elif a == "ld":
        lu = False
    elif a == "ru":
        ru = True
    elif a == "rd":
        ru = False
    
    if lu and ru:
        up = 2
    elif (not lu) and (not ru):
        up = 0
    else:
        up = 0

    if sup <> 1 and up <> 1:
        if sup <> up:
            cnt = cnt + 1

    sup = up

print cnt

Submission status: Accepted

Solution code:
def ll(char, f):
    if char == "l":
        return not f
    return f


def rr(char, f):
    if char == "r":
        return not f
    return f


while True:
    N = int(input())
    if N == 0:
        break
    F = list(input().split())
    c = 0
    lFalg = False
    rFalg = False
    before = F[0]
    lFalg = ll(F[0][0], lFalg)
    rFalg = rr(F[0][0], rFalg)
    for i in range(1, len(F)):
        if not lFalg == rFalg:
            if not before[0] == F[i][0]:
                c += 1
        lFalg = ll(F[i][0], lFalg)
        rFalg = rr(F[i][0], rFalg)
        before = F[i]
    print(int(c))

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

def main():
  while True:
    n = input()
    if not n: break

    w = 0
    a = [0, 0]
    ans = 0
    for s in raw_input().split():
      f = 0 if s[0] == "l" else 1
      u = 0 if s[1] == "d" else 1
      a[f] = u
      if w == 0 and a[0] == 1 and a[1] == 1:
        w = 1
        ans += 1
      elif w == 1 and a[0] == 0 and a[1] == 0:
        w = 0
        ans += 1

    print ans

  return 0

## -------------------------------------------
## TEMPLATE

from sys import stdin
from sys import setrecursionlimit
from copy import deepcopy
from math import sqrt
from itertools import permutations
from itertools import combinations

def getline():
  return stdin.readline()

def getLineAs(tp):
  return map(tp, getline().split())

def array(n, init = 0):
  return [deepcopy(init) for i in range(n)]

if __name__ == "__main__":
  setrecursionlimit(1024 * 1024)
  main()

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0: break
    step = input().split()
    ans = 0
    for i in range(0, len(step), 2):
        if i+1 == len(step): break
        if (step[i] == 'lu' and step[i+1] == 'ru') or (step[i] == 'ru' and step[i+1] == 'lu') or (step[i] == 'ld' and step[i+1] == 'rd') or (step[i] == 'rd' and step[i+1] == 'ld'):
            ans += 1
    print(ans)

Submission status: Accepted

Solution code:
while 1:
    n = int(raw_input())
    if n == 0: break
    steps = raw_input().split()
    lr = [0,0]
    start = 0
    ans = 0
    for step in steps:
        if step[0] == "l":
            if step[1] == "u": lr[0] += 1
            else: lr[0] -= 1
        else:
            if step[1] == "u": lr[1] += 1
            else: lr[1] -= 1
        if (lr == [1,1] and start == 0) or (lr == [0,0] and start == 1):
            ans += 1
            start = lr[0]
    print ans

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n = input()
            if n == 0:
                break
            f = raw_input().split()
            state = 0
            prev = 0
            ans = 0
            for move in f:
                # print state, prev, ans
                if state == 0:
                    if prev == 3:
                        ans += 1
                        prev = 0
                    if move == 'lu':
                        state = 1
                    elif move == 'ru':
                        state = 2
                elif state == 1:
                    if move == 'ld':
                        state = 0
                    elif move == 'ru':
                        state = 3
                elif state == 2:
                    if move == 'lu':
                        state = 3
                    elif move == 'rd':
                        state = 0
                else:
                    if prev == 0:
                        ans += 1
                        prev = 3
                    if move == 'ld':
                        state = 2
                    elif move == 'rd':
                        state = 1
            if (state == 0 and prev == 3) or (state == 3 and prev == 0):
                ans += 1            
            print ans
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Submission status: Accepted

Solution code:
while True:
    if input() == '0':
        break
    actions = input().split()
    r, l = False, False
    floor = True
    n = 0
    for a in actions:
        if a[0] == 'r':
            r = not r
        elif a[0] == 'l':
            l = not l
        if r == l == floor:
            n += 1
            floor = not floor
    print(n)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    n = int(input())
    if n == 0:
        break
    status = 0
    flag = False
    point = 0
    fn = list(map(list,input().split()))
    for f in fn:
        status = status + 1 if f[1] == 'u' else status - 1
        if flag == False and status == 2:
            point += 1
            flag = True
        if flag == True and status == 0:
            point += 1
            flag = False

    print(point)

Submission status: Accepted

Solution code:
move = {
	("000", "lu") : ("010", 0), ("000", "ru") : ("001", 0), 
	("010", "ld") : ("000", 0), ("001", "rd") : ("000", 0),
	("010", "ru") : ("111", 1), ("001", "lu") : ("111", 1),
	("111", "ld") : ("101", 0), ("111", "rd") : ("110", 0),
	("101", "lu") : ("111", 0), ("110", "ru") : ("111", 0),
	("101", "rd") : ("000", 1), ("110", "ld") : ("000", 1)
	}
while 1:
	n = int(raw_input())
	if n == 0:
		break
	f = raw_input().split(" ")
	status = "000"
	count = 0
	for foot in f:
		status, result = move[(status,foot)]
		count += result
	print count

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

N = int(raw_input())
while N!=0:
    act = raw_input().split()
    cur = 0
    cnt = 0
    lr = [0, 0]

    for i in range(N):
        if act[i] == "ld":
            lr[0] = 0
        elif act[i] == "lu":
            lr[0] = 1
        elif act[i] == "ru":
            lr[1] = 1
        elif act[i] == "rd":
            lr[1] = 0 

        if lr == [1, 1] and cur == 0:
            cur = 1
            cnt += 1
        elif lr == [0, 0] and cur == 1:
            cur = 0
            cnt += 1

    print cnt
    N = int(raw_input())

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0: break
    ans = 0
    f = input().split()
    for i in range(len(f) - 1):
        if f[i] == "lu" and f[i+1] == "ru" \
                or f[i] == "ru" and f[i+1] == "lu" \
                or f[i] == "ld" and f[i+1] == "rd" \
                or f[i] == "rd" and f[i+1] == "ld":
                    ans += 1
    print(ans)

Submission status: Accepted

Solution code:
def main():
    while True:
        n = int(input())
        if n == 0:
            exit()
        f = [s for s in input().split()]
        pm = 'd'
        cnt = 0
        for m in f:
            if m[1] == pm:
                cnt += 1
            pm = m[1]
        print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

p = [('ru','lu'), ('lu','ru'),('rd','ld'), ('ld','rd')]
while True:
	n = int(input())
	if n == 0:
		break
	l = False
	r = False
	f = input().split()
	print(len([t for t in zip(f[1:], f[:-1]) if t in p]))

Submission status: Accepted

Solution code:
while True:
    n = input()

    if n == 0:
        break

    s = raw_input().split()

    isLeftDown = True
    isRightDown = True
    isDown = True

    cnt = 0
    for i in range(n):
        if s[i] == "lu":
            isLeftDown = False
        elif s[i] == "ld":
            isLeftDown = True
        elif s[i] == "ru":
            isRightDown = False
        elif s[i] == "rd":
            isRightDown = True

        if isLeftDown == False and isRightDown == False and isDown == True:
            cnt += 1
            isDown = False
        if isLeftDown == True and isRightDown == True and isDown == False:
            cnt += 1
            isDown = True

    print cnt

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0: break
    move = raw_input().split()
    l,r,go,count = 0,0,1,0
    for c in move:
        if c == 'lu':
            l = 1
        if c == 'ru':
            r = 1
        if c == 'ld':
            l = 0
        if c == 'rd':
            r = 0
        if l == r and l == go:
            count += 1
            go = -l + 1
    print count

Submission status: Accepted

Solution code:
while True:
  n = int(raw_input())
  if n == 0: break
  s = raw_input().split()
  state = [False, False]
  counter = 0
  stand = False
  for step in s:
    if step == "lu":
      state[0] = True
    elif step == "ru":
      state[1] = True
    elif step == "ld":
      state[0] = False
    elif step == "rd":
      state[1] = False

    if state[0] == state[1] and stand != state[0]:
      counter += 1
      stand = state[0]
  print counter

Submission status: Accepted

Solution code:
fn = {
    'lu': lambda x,y: [1,y],
    'ru': lambda x,y: [x,1],
    'ld': lambda x,y: [0,y],
    'rd': lambda x,y: [x,0]
}
while True:
    if input()=='0': break
    x,y = 0,0
    c,f = 0,1
    for s in input().split():
        x,y = fn[s](x,y)
        if x==y==f: c,f = c+1,abs(f-1)
    print(c)

Submission status: Accepted

Solution code:
while 1:
    n = input()
    if n == 0:
        break
    F = raw_input().split()
    mode = 1
    s = [0,0]
    ans = 0
    for f in F:
        if f[0]=="l":
            s[0]^=1
            if mode != s[0]:
                mode = -1
        else:
            s[1]^=1
            if mode != s[1]:
                mode = -1
        if s[0]==s[1]:
            if mode == s[0]:
                ans += 1
            mode = s[0]^1
    print ans

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    a=0
    s=input().split()
    for i in range(0,len(s),2):
        if i+1==len(s):break
        s[i]+=s[i+1]
        if(('lu' in s[i] and 'ru' in s[i])or('ld' in s[i] and 'rd' in s[i])):a+=1
    print(a)

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    a=0
    s=input().split()
    for i in range(0,len(s)-1,2):
        s[i]+=s[i+1]
        if(('lu' in s[i] and 'ru' in s[i])or('ld' in s[i] and 'rd' in s[i])):a+=1
    print(a)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:break
    _in=input().split(' ')
    f_stat=[False,False] #[left,right]
    state=False
    cnt=0
    for i in range(n):
        com=_in[i]
        if com=="lu":f_stat[0]=True
        elif com=="ru":f_stat[1]=True
        elif com=="ld":f_stat[0]=False
        else:f_stat[1]=False
        #
        if state==False:
            if f_stat[0] and f_stat[1]:
                cnt+=1
                state=True
        else:
            if not f_stat[0] and not f_stat[1]:
                cnt+=1
                state=False
    print(cnt)

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break
    a = b = c = sum = 0
    lst = []
    f = [str(x) for x in raw_input().split()]
    for i in range(n):
        if f[c] == 'lu':
            a += 1
        if f[c] == 'ld':
            a -= 1
        if f[c] == 'ru':
            a += 1
        if f[c] == 'rd':
            a -= 1
        if b == 0:
            if a == 2:
                sum += 1
                b = 1
        if b == 1:
            if a == 0:
                sum += 1
                b = 0
        c += 1
    print sum

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    while 1:
        n = int(input())
        if n == 0:break
        line = input().strip().split()
        lstate = 0 # floor = 0 ,upstairs = 1
        rstate = 0
        flag = 0#floor =0???????????°flag = 0
        ans =0
        for l in line:
            if lstate and not flag and l == 'ru':
                ans +=1
                flag = 1
            elif rstate and not flag and l =='lu':
                ans +=1
                flag = 1
            elif not rstate and flag and l == 'ld':
                ans +=1
                flag = 0
            elif not lstate and  flag and l == 'rd':
                ans +=1
                flag = 0

            if l =='lu':lstate=1
            if l =='ru':rstate=1
            if l == 'ld': lstate = 0
            if l == 'rd': rstate = 0
        print(ans)

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0: break
    src = list(input().split())
    ru = lu = both = False
    ans = 0
    for f in src:
       if f == 'ru':   ru = True
       elif f == 'lu': lu = True
       elif f == 'rd': ru = False
       else:           lu = False
       if ru == lu == (not both):
           ans += 1
           both = not both
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())

    if n == 0:
        break

    f = raw_input().split()

    ans = 0

    for i in range(1, len(f)):
        if f[i] == "lu" and f[i-1] == "ru":
            ans += 1
        elif f[i] == "ru" and f[i-1] == "lu":
            ans += 1
        elif f[i] == "ld" and f[i-1] == "rd":
            ans += 1
        elif f[i] == "rd" and f[i-1] == "ld":
            ans += 1

    print ans

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break

    step = list(input().split())
    l = r = 0
    ne = 1
    cnt = 0
    for mov in step:
        if mov == "lu":
            l = 1
        elif mov == "ru":
            r = 1
        elif mov == "ld":
            l = 0
        else:
            r = 0
        if l == r == ne:
            cnt += 1
            ne = (ne + 1) % 2
    print(cnt)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        if n == 0:
            break
        a = LS()
        r = 0
        for i in range(len(a)//2):
            if a[i*2][1] == a[i*2+1][1]:
                r += 1
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())

Submission status: Accepted

Solution code:
while True:
    c = 0
    ans = 0
    a = int(input())
    left = 0
    right = 0
    if a == 0:
        break
    b = input()
    b = b.split(" ")
    for i in b:
        if i == "lu":
            left = 1
        elif i == "ru":
            right = 1
        elif i == "rd":
            right = 0
        elif i == "ld":
            left = 0
        if left == right:
            if before[0] != i[0]:
                ans = ans + 1
        c = c + 1
        before = i
    print(ans)

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if not n:break
    l=input().split()
    pos=[0,0]
    isdown=True
    score=0

    for i in l:
        if i=="lu" and pos[0]==0:pos[0]+=1
        elif i=="ru" and pos[1]==0:pos[1]+=1
        elif i=="ld" and pos[0]>0:pos[0]-=1
        elif i=="rd" and pos[1]>0:pos[1]-=1
    
        if isdown and pos==[1,1]:
            isdown=False
            score+=1
        elif not isdown and pos==[0,0]:
            isdown=True
            score+=1    
    print(score)

Submission status: Accepted

Solution code:
ansli=[]

while 1:
    n=input()
    if n=="0":
        break
    a=input().split()
    up=0
    down=1
    lu=0
    ru=0
    ld=0
    rd=0
    count=0
    for i in a:
        if i=="ru":
            ru=1
            rd=0
        elif i=="lu":
            lu=1
            ld=0
        elif i=="rd":
            rd=1
            ru=0
        elif i=="ld":
            ld=1
            lu=0

        if ru==1 and lu==1 and down==1:
            count+=1
            down=0
            up=1
        elif rd==1 and ld==1 and up==1:
            count+=1
            down=1
            up=0
    ansli.append(count)
    #print(count)
for i in ansli:
    print(i)

Submission status: Accepted

Solution code:
while(True):
    n = input()
    if n == '0': break
    line = input()
    qs = line.split(" ")
    up = 0
    down = 0
    cnt = 0
    for q in qs:
        if q == "lu" or q == "ru" :
            up += 1
            down = 0
        else:
            down += 1
            up = 0
        if up==2 or down == 2:
            cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    f = list(input().split())
    
    is_on = False
    left_up = False
    right_up = False
    ans = 0
    for i in range(n):
        if f[i] == "lu":
            left_up = True
        elif f[i] == "ld":
            left_up = False
        elif f[i] == "ru":
            right_up = True
        else:
            right_up = False
        
        if left_up and right_up and not is_on:
            is_on = True
            ans += 1
        elif not left_up and not right_up and is_on:
            is_on = False
            ans += 1
    print(ans)

Submission status: Accepted

Solution code:
while True :
    n = int(input())
    if n == 0 :
        break
    
    posi = 0
    right = 0
    left = 0
    cnt = 0
    task = list(input().split())
    for i in range(n) :
        if task[i] == 'lu' :
            left = 1
        elif task[i] == 'ru' :
            right = 1
        elif task[i] == 'ld' :
            left = 0
        elif task[i] == 'rd' :
            right = 0
        if posi == 0 and right == 1 and left == 1 :
            cnt += 1
            posi = 1
        elif posi == 1 and right == 0 and left == 0 :
            cnt += 1
            posi = 0
    print(cnt)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    answer = []
    while N != 0:
        cmd = [i for i in input().split()]
        ans = 0
        g_flag = True
        p = ["ld", "rd"]
        for c in cmd:
            if c[0] == "l":
                p[0] = c
            else:
                p[1] = c
            if g_flag and p[0] == "lu" and p[1] == "ru":
                g_flag = False
                ans += 1
            if not g_flag and p[0] == "ld" and p[1] == "rd":
                g_flag = True
                ans += 1
        answer.append(ans)
        N = int(input())
    print(*answer,sep="\n")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0:
        break
    a = input()
    b = a.split()
  
    x = 0
    for i in range(N//2):
        if b[2 * i] == 'lu' and b[(2 * i)+1] == 'ru':
            x += 1
        if b[2 * i] == 'ru' and b[(2 * i)+1] == 'lu':
            x += 1
        if b[2 * i] == 'ld' and b[(2 * i)+1] == 'rd':
            x += 1
        if b[2 * i] == 'rd' and b[(2 * i)+1] == 'ld':
            x += 1
    print(x)

Submission status: Accepted

Solution code:
def identify(x:str, y:str):
    if (x == "lu" and y == "ru") or (x == "ru" and y == "lu"):
        return True
    if (x == "ld" and y == "rd") or (x == "rd" and y == "ld"):
        return True

while True:
    num = int(input())
    if num != 0:
        udlr = input()
        list_udlr = udlr.split()
        count = 0
        for i in range(num - 1):
            if identify(list_udlr[i], list_udlr[i + 1]):
                count += 1
                i += 2
        print(count)
    else:
        break

Submission status: Accepted

Solution code:
def solve(n):
	ops = input().split()
	states = [0 for i in range(n + 1)]
	ans = 0
	for i in range(n):
		if ops[i] == "lu": states[i + 1] = states[i] + 1
		elif ops[i] == "ru": states[i + 1] = states[i] + 2
		elif ops[i] == "ld": states[i + 1] = states[i] - 1
		else: states[i + 1] = states[i] - 2
		if i >= 1 and (states[i - 1],states[i + 1]) in [(0,3),(3,0)]:
			ans += 1
	print(ans)

while True:
	n = int(input())
	if n == 0: break
	solve(n)

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break
    f = list(map(str,input().split()))
    cnt = 0
    for i in range(n-1):
        if f[i] == "lu" and f[i+1] == "ru":
            cnt += 1
        elif f[i] == "ru" and f[i+1] == "lu":
            cnt += 1
        elif f[i] == "ld" and f[i+1] == "rd":
            cnt += 1
        elif f[i] == "rd" and f[i+1] == "ld":
            cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
DOWN = 0
UP = 1
MOVE_LIST = ["lu","ru","ld","rd"]

def get_input():
    input_data = int(input())
    return input_data

def get_data_list():
    data_list = input().split()
    return data_list


class Manager:
    def __init__(self, move_num, record_list):
        self.move_num = move_num
        self.record_list = record_list
        self.count = 0
        self.right_status = DOWN
        self.left_status = DOWN
        self.kazu_status = DOWN


    def watach_move(self):
        for move in self.record_list:
            if move == "lu":
                self.left_status = UP
            elif move == "ru":
                self.right_status = UP
            elif move == "ld":
                self.left_status = DOWN
            else:
                self.right_status = DOWN
            self.counter()

    def counter(self):
        if self.left_status == self.right_status != self.kazu_status:
            self.kazu_status = self.left_status
            self.count += 1


if __name__ == "__main__":
    while True:
        move_num = get_input()
        if move_num == 0:
            break
        record_list = get_data_list()
        manager = Manager(move_num, record_list)
        manager.watach_move()
        print(manager.count)

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break
    f = list(map(str,input().split()))
    cnt = 0
    for i in range(n-1):
        if (i+1) % 2 == 1:
            if f[i] == "lu" and f[i+1] =="ru":
                cnt += 1
            if f[i] == "ru" and f[i+1] == "lu":
                cnt += 1
            if f[i] == "ld" and f[i+1] == "rd":
                cnt += 1
            if f[i] == "rd" and f[i+1] == "ld":
                cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n==0: break
    a = input().split()
    cnt = 0
    for i in range(n//2):
        if a[2*i][0] != a[2*i+1][0]:
            cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
import math
while True:
  answer = 0
  count = int(input())
  if count == 0: break
  orders = input().split(' ')

  for i in range(int(math.floor(count / 2))):
    s = orders[ 2 * i: 2*i+2 ]
    if not(s[0][0] == s[1][0]) and (s[0][1] == s[1][1]):
      answer += 1
  
  print(answer)

Submission status: Accepted

Solution code:
while True:
	n=int(input())
	if n==0:
		break
	a=list(map(str,input().split()))
	cnt=0
	l=r=0
	q=0
	for i in range(n):
		if a[i]=="lu":
			l=1
		elif a[i]=="ru":
			r=1
		elif a[i]=="ld":
			l=0
		else:
			r=0
		if l==r==1 and q==0:
			cnt+=1
			q=1
		elif l==r==0 and q==1:
			cnt+=1
			q=0
	print(cnt)

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break
    l = input().split()
    lup, rup, up = False, False, False
    res = 0
    for s in l:
        if s == 'lu':
            lup = True
        if s == 'ru':
            rup = True
        if s == 'ld':
            lup = False
        if s == 'rd':
            rup = False
        if lup and rup:
            if not up:
                res += 1
            up = True
        if not lup and not rup:
            if up:
                res += 1
            up = False
    print(res)

Submission status: Accepted

Solution code:

while True:

    N = int(input())

    if N == 0:
        break

    a = list(input().split())

    l = 0
    r = 0

    las = 0
    ans = 0

    for i in a:

        if i == "lu":
            l += 1
        elif i == "ld":
            l -= 1
        elif i == "ru":
            r += 1
        else:
            r -= 1

        if l == r and l != las:
            ans += 1
            las = l

    print (ans)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n==0:
        break

    f = list(input().split())
    cnt = 0
    rf = 0
    lf = 0
    foot = 0
    for i in range(n):
        if lf==0 and f[i]=="lu":
            lf = 1
        elif rf==0 and f[i]=="ru":
            rf = 1
        if foot==0 and lf==1 and rf==1:
            cnt += 1
            foot = 1
        if lf==1 and f[i]=="ld":
            lf = 0
        elif rf==1 and f[i]=="rd":
            rf = 0
        if foot==1 and lf==0 and rf==0:
            cnt += 1
            foot = 0
    print(cnt)

Submission status: Accepted

Solution code:
ans_list = []

while True:
    n = int(input())
    if n == 0:
        break
    S = input().split()
    cnt = 0
    dq = []
    for s in S:
        if not dq:
            dq.append(s)
        if [dq[-1], s] in [["lu","ru"],["ru","lu"],["ld","rd"],["rd","ld"]]:
            cnt += 1
            dq.append("@")
        else:
            dq.append(s)
    ans_list.append(cnt)

for ans in ans_list:
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:exit()
    l0=list(map(str,input().split()))
    ans=0
    l=0
    r=0
    k=1
    for x in l0:
        if x=="lu":
            l=1
        elif x=="ld":
            l=0
        elif x=="ru":
            r=1
        else:
            r=0
        if k+l+r==3:
            ans+=1
            k-=1
        elif k+l+r==0:
            ans+=1
            k+=1
    print(ans)

Submission status: Accepted

Solution code:
ans = []

while True:
    n = int(input())
    
    if n == 0:
        break

    l_step, r_step = 0, 0
    flag = False
    step = input().split()
    cnt = 0
    for i in range(n):
        
        if step[i] == "lu":
            l_step = 1
        elif step[i] == "ru": 
            r_step = 1
        elif step[i] == "ld":
            l_step = 0
        elif step[i] == "rd":
            r_step= 0

        if flag == False:
            if l_step + r_step == 2:
                cnt += 1
                flag = True

        else:
            if l_step + r_step == 0:
                cnt += 1
                flag = False

    ans.append(cnt)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
Set = [("lu", "ru"), ("ru","lu"), ("ld","rd"), ("rd","ld")]

while True :
	n = int(input())
	if(n == 0) :
		break
	else :
		F = list(map(str, input().split()))
		cnt = 0
		while(len(F) > 1) :
			if((F[0], F[1]) in Set) :
				cnt += 1
				del F[0 : 2]
			else :
				del F[0]
		print(cnt)