Problem:

Problem A. GuruGuru

  You are playing a game called Guru Guru Gururin. In this game, you can move with the vehicle called Gururin. There are two commands you can give to Gururin: 'R' and 'L'. When 'R' is sent, Gururin rotates clockwise by 90 degrees. Otherwise, when 'L' is sent, Gururin rotates counterclockwise by 90 degrees.

  During the game, you noticed that Gururin obtains magical power by performing special commands. In short, Gururin obtains magical power every time when it performs one round in the clockwise direction from north to north. In more detail, the conditions under which magical power can be obtained is as follows.

At the beginning of the special commands, Gururin faces north.

At the end of special commands, Gururin faces north.

Except for the beginning and the end of special commands, Gururin does not face north.

During the special commands, Gururin faces north, east, south, and west one or more times, respectively, after the command of 'R'.

  At the beginning of the game, Gururin faces north. For example, if the sequence of commands Gururin received in order is 'RRRR' or 'RRLRRLRR', Gururin can obtain magical power. Otherwise, if the sequence of commands is 'LLLL' or 'RLLR', Gururin cannot obtain magical power.

  Your task is to calculate how many times Gururin obtained magical power throughout the game. In other words, given the sequence of the commands Gururin received, calculate how many special commands exists in it.

Input

  The input consists of a single test case in the format below.

$S$

  The first line consists of a string $S$, which represents the sequence of commands Gururin received. $S$ consists of 'L' and 'R'. The length of $S$ is between $1$ and $10^3$ inclusive.

Output

  Print the number of times Gururin obtained magical power throughout the game in one line.

Examples

Sample Input 1 

RRRRLLLLRRRR

Output for Sample Input 1

2

Sample Input 2 

RLLRLLLLRRRLLLRRR

Output for Sample Input 2

0

Sample Input 3 

LR

Output for Sample Input 3

0

Sample Input 4 

RRLRRLRRRRLRRLRRRRLRRLRRRRLRRLRR

Output for Sample Input 4

4



Sample input:
RRRRLLLLRRRR


Sample output:
2

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    S = readline().strip()
    ans = 0
    d = 0; cur = 0
    for c in S:
        if c == "R":
            if d == cur:
                cur += 1
            d = (d + 1) % 4
            if d == 0 and cur == 4:
                ans += 1
                cur = 0
        else:
            d = (d - 1) % 4
            if d == 0:
                cur = 0
    write("%d\n" % ans)
solve()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().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():
    s = S()
    i = 0
    now = 0
    ans = 0
    while i < len(s):
        if s[i] == "R":
            if now == 0:
                now += 1
                i += 1
                while i < len(s):
                    if s[i] == "R":
                        now += 1
                    else:
                        now -= 1
                    now = now % 4
                    i += 1
                    if now == 0:
                        if s[i-1] == "R":
                            ans += 1
                        break

            else:
                now += 1
                now = now % 4
                i += 1
        else:
            now -= 1
            now = now % 4
            i += 1

    print(ans)


    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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

Submission status: Accepted

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

#A
def A():
    s = S()
    d = 0
    ans = 0
    k = 0
    for i in s:
        if i == "R":
            if d == 0:
                k = 1
            d += 1
            d %= 4
            if d == 0 and k:ans += 1
        else:
            if d == 0:
                k = 0
            d -= 1
            d %= 4
    print(ans)
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

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

Submission status: Accepted

Solution code:
S=input()
count=0
direction=0

for i in range(len(S)):
    if S[i]=='R':
        direction+=1
    else:
        direction-=1
    if direction==4:
        count+=1
        direction=0
    elif direction==-4:
        direction=0
print(count)

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**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

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 = []

    def f(n):
        r = 0
        t = 0
        for c in n:
            if c == 'R':
                t += 1
                if t == 4:
                    r += 1
                    t = 0
            else:
                t -= 1
                if t == -4:
                    t = 0
        return r

    while 1:
        n = S()
        if n == 0:
            break
        rr.append(f(n))
        break

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


print(main())