Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.

The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms. 

Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)). 

Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs. 


-----Input-----

The first line of the input contains single integer n (1 ≤ n ≤ 10^5) — the number of moves in the walking sequence.

The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.


-----Output-----

On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.


-----Examples-----
Input
1
U

Output
0

Input
6
RURUUR

Output
1

Input
7
URRRUUU

Output
2



-----Note-----

The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins. [Image]

Difficulty: EASY

Solutions:
input()
s = input()
step = 0
pos = s[0] == 'U'
res = 0
for i in s:
	if i == 'R':
		step -= 1
	elif i == 'U':
		step += 1
	if step == -1 and pos:
		pos = False
		res += 1
	elif step == 1 and (not pos):
		pos = True
		res += 1
print(res)


n = int(input())
s = input()
x = 0
y = 0
ans = 0
last = 0
for i in range(len(s)):
	if s[i] == 'R':
		x += 1
	else:
		y += 1
	if i != 0:
		if x > y and last == 0:
			last = 1
			ans += 1
		elif x < y and last == 1:
			last = 0
			ans += 1
	elif x > y:
		last = 1
	elif y > x:
		last = 0
print(ans)


n = int(input())
s = list(input())
place = [0, 0]
(underneath, above) = (0, 0)
total = 0
for x in s:
	if x == 'R':
		place[0] += 1
	else:
		place[1] += 1
	if underneath and place[1] < place[0]:
		total += 1
	elif above and place[0] < place[1]:
		total += 1
	if place[0] < place[1]:
		underneath = 1
		above = 0
	elif place[0] > place[1]:
		above = 1
		underneath = 0
print(total)


n = int(input())
s = input()
p2 = (0, 0)
p1 = (0, 0)
r = 0
for c in s:
	if c == 'U':
		if p2[0] == p1[0] and p1[0] == p1[1] and (p1[0] != 0):
			r += 1
		p2 = p1
		p1 = (p1[0], p1[1] + 1)
	else:
		if p2[1] == p1[1] and p1[0] == p1[1] and (p1[0] != 0):
			r += 1
		p2 = p1
		p1 = (p1[0] + 1, p1[1])
print(r)


n = int(input())
s = input()
x = []
temp_x = 0
y = []
temp_y = 0
ans = 0
slope = 0
if s[0] == 'R':
	slope = 0.5
else:
	slope = 2
for i in range(0, len(s)):
	if s[i] == 'U':
		temp_y += 1
	elif s[i] == 'R':
		temp_x += 1
	x.append(temp_x)
	y.append(temp_y)
for i in range(1, n):
	if x[i] != 0:
		sl = y[i] / x[i]
	else:
		sl = slope
	if slope > 1 and sl < 1:
		slope = sl
		ans += 1
	elif slope < 1 and sl > 1:
		slope = sl
		ans += 1
print(ans)


n = int(input())
w = input()
x1 = 0
y1 = 0
coins = 0
prev_x = 0
prev_y = 0
for i in range(n - 1):
	if w[i] == 'R':
		x1 += 1
	elif w[i] == 'U':
		y1 += 1
	if x1 == y1:
		if prev_x < x1 and w[i + 1] == 'R' or (prev_y < y1 and w[i + 1] == 'U'):
			coins += 1
	prev_x = x1
	prev_y = y1
print(coins)


n = int(input())
s = input()
count = 0
kindom = 0
(x, y) = (0, 0)
for i in s:
	if i == 'U':
		y += 1
	elif i == 'R':
		x += 1
	if x > y:
		if kindom == 2:
			count += 1
		kindom = 1
	if x < y:
		if kindom == 1:
			count += 1
		kindom = 2
print(count)


n = int(input().strip())
arr = list(input().strip())
cur = [0, 0]
cost = 0
if arr[0] == 'U':
	cur[1] += 1
else:
	cur[0] += 1
lowar = cur[0] > cur[1]
for i in range(1, len(arr)):
	if arr[i] == 'U':
		cur[1] += 1
	else:
		cur[0] += 1
	if lowar:
		if cur[0] < cur[1]:
			cost += 1
			lowar = False
	elif cur[0] > cur[1]:
		cost += 1
		lowar = True
print(cost)


n = int(input())
s = input()
pos = [0, 0]
kingdom = 0
pay = 0
for k in range(n):
	c = s[k]
	if c == 'U':
		pos[1] += 1
	else:
		pos[0] += 1
	last = kingdom
	if pos[0] < pos[1]:
		kingdom = 2
	elif pos[0] > pos[1]:
		kingdom = 1
	if last != 0 and last != kingdom:
		pay += 1
print(pay)


input()
x = y = a = b = 0
for i in input():
	if i == 'U':
		y += 1
	else:
		x += 1
	if a * (x - y) < 0:
		b += 1
	if x - y:
		a = x - y
print(b)


import math
from sys import stdin
n = int(stdin.readline())
string = stdin.readline()
S = [x for x in string if x != '\n']
position = [0, 0]
coin = 0
for i in range(len(S) - 1):
	if S[i] == 'U':
		position[1] += 1
	elif S[i] == 'R':
		position[0] += 1
	if position[0] == position[1]:
		if S[i] == S[i + 1]:
			coin += 1
print(coin)


def zone(x, y):
	return 0 if x == y else 1 if x > y else -1

def go(x, y, step):
	return (x + 1, y) if step == 'R' else (x, y + 1)

def main():
	n = int(input())
	steps = input()
	zones = [0, 0, 0]
	(x, y) = (0, 0)
	if n < 3:
		print(0)
	else:
		(x, y) = go(x, y, steps[0])
		zones[1] = zone(x, y)
		(x, y) = go(x, y, steps[1])
		zones[2] = zone(x, y)
		paid = 0
		for i in range(2, n):
			(x, y) = go(x, y, steps[i])
			zones[0] = zones[1]
			zones[1] = zones[2]
			zones[2] = zone(x, y)
			if zones[1] == 0 and zones[0] != zones[2]:
				paid += 1
		print(paid)
main()


n = int(input())
m = input()
(x, y) = (0, 0)
k = 0
for i in range(len(m) - 1):
	if m[i] == 'U':
		y += 1
	else:
		x += 1
	if x == y and m[i] == m[i + 1]:
		k += 1
print(k)


n = int(input())
s = input()
ans = 0
curx = 0
cury = 0
reg = '-'
if s[0] == 'R':
	reg = 'L'
	curx += 1
else:
	reg = 'U'
	cury += 1
for i in s[1:]:
	if i == 'U':
		if (reg == '-' or reg == 'L') and cury + 1 > curx:
			ans += 1
			reg = 'U'
		cury += 1
	elif i == 'R':
		if reg == 'U' and curx + 1 > cury:
			ans += 1
			reg = 'L'
		curx += 1
print(ans)


n = int(input())
a = input()
(x, y) = (0, 0)
c = 0
for i in range(n - 1):
	if a[i] == 'R':
		x += 1
		if x == y and a[i + 1] == 'R':
			c += 1
	else:
		y += 1
		if x == y and a[i + 1] == 'U':
			c += 1
print(c)


n = int(input())
s = input()
uk = False
g = False
o = 0
pos = [0, 0]
for m in s:
	if m == 'R':
		pos[0] += 1
	else:
		pos[1] += 1
	if pos[0] == pos[1]:
		g = True
	else:
		if g:
			u = pos[1] > pos[0]
			if u != uk:
				o += 1
		uk = pos[1] > pos[0]
		g = False
print(o)


n = int(input())
s = input()
x = 0
y = 0
ans = 0
if s[0] == 'U':
	y += 1
else:
	x += 1
for i in range(1, n):
	if s[i] == 'U':
		y += 1
	else:
		x += 1
	if x == y and i < n - 1 and (s[i] == s[i + 1]):
		ans += 1
print(ans)


import sys

def solve(io):
	io.readInt()
	S = io.readString()
	cnt = -1
	x = 0
	y = 0
	side = -1
	for c in S:
		if c == 'R':
			x += 1
		else:
			y += 1
		if x < y:
			nextSide = 0
		elif x > y:
			nextSide = 1
		if side != nextSide:
			cnt += 1
			side = nextSide
	io.println(cnt)

class IO:
	input = None
	output = None
	raw = ''
	buf = []
	pos = 0

	def __init__(self, inputStream, outputStream):
		self.input = inputStream
		self.output = outputStream

	def readToBuffer(self):
		self.raw = self.input.readline().rstrip('\n')
		self.buf = self.raw.split()
		self.pos = 0

	def readString(self):
		while self.pos == len(self.buf):
			self.readToBuffer()
		ans = self.buf[self.pos]
		self.pos += 1
		return ans

	def readInt(self):
		return int(self.readString())

	def readFloat(self):
		return float(self.readString())

	def print(self, s):
		self.output.write(str(s))

	def println(self, s):
		self.print(s)
		self.print('\n')

	def flushOutput(self):
		self.output.flush()
pythonIO = IO(sys.stdin, sys.stdout)
solve(pythonIO)
pythonIO.flushOutput()


n = int(input())
steps = input()
x = 0
y = 0
cost = 0
if steps[0] == 'U':
	y += 1
	state_old = 1
elif steps[0] == 'R':
	x += 1
	state_old = -1
for i in range(1, n):
	if steps[i] == 'U':
		y += 1
	elif steps[i] == 'R':
		x += 1
	if y > x:
		state_new = 1
	elif x > y:
		state_new = -1
	elif x == y:
		state_new = state_old
	if state_old != state_new:
		cost += 1
	state_old = state_new
print(cost)


(n, path) = (int(input()), input())
res = '0'
x = y = 0
for i in range(0, n):
	x += int(path[i] == 'R')
	y += int(path[i] == 'U')
	res += '0' if x == y else '1' if x > y else '2'
print(res.count('201') + res.count('102'))


import math

def main_function():
	input()
	s = input()
	coins = 0
	kingdom_1 = False
	kingdom_2 = False
	current_position = [0, 0]
	for i in range(len(s)):
		if s[i] == 'U':
			current_position[1] += 1
		else:
			current_position[0] += 1
		if current_position[0] > current_position[1]:
			if kingdom_1:
				coins += 1
			kingdom_2 = True
			kingdom_1 = False
		elif current_position[0] < current_position[1]:
			if kingdom_2:
				coins += 1
			kingdom_2 = False
			kingdom_1 = True
	return coins
print(main_function())


def pos(a, b):
	if a == b:
		return 'g'
	if a > b:
		return 'u'
	return 'd'
n = int(input())
moves = input()
l = 0
r = 0
k = 'u'
coin = 0
for m in moves:
	x = l
	y = r
	if m == 'R':
		x += 1
	if m == 'U':
		y += 1
	if pos(x, y) != 'g' and pos(x, y) != k:
		coin += 1
		k = pos(x, y)
	l = x
	r = y
if moves[0] == 'U':
	coin -= 1
print(coin)


n = int(input())
s = input()
a = []
b = []
x = 0
y = 0
c = []
f = 0
for i in s:
	if i == 'U':
		y += 1
	else:
		x += 1
	a.append(x)
	b.append(y)
for i in range(len(a)):
	if a[i] > b[i]:
		c.append(1)
	elif b[i] > a[i]:
		c.append(2)
	else:
		c.append(3)
for i in range(len(c)):
	if c[i] == 3 and i + 1 < n:
		if c[i - 1] != c[i + 1]:
			f += 1
print(f)


input()
a = b = c = 0
for i in input():
	a += 1 if i == 'U' else -1
	c += a * b < 0
	if a:
		b = a
print(c)


_ = input()
r = list(input())
t = (0, 0)
l = [t]
for x in range(0, len(r)):
	q = l[len(l) - 1]
	if r[x] == 'U':
		l.append((q[0], q[1] + 1))
	else:
		l.append((q[0] + 1, q[1]))
l.append((-100, -100))
c = 0
for x in range(1, len(l) - 1):
	(a, b) = l[x]
	if a == b:
		x1 = l[x - 1]
		x2 = l[x + 1]
		if b == x1[1] and b == x2[1]:
			if a == x1[0] + 1 and a == x2[0] - 1:
				c += 1
		elif a == x1[0] and a == x2[0]:
			if b == x1[1] + 1 and b == x2[1] - 1:
				c += 1
print(c)


n = int(input())
s = input()
r = 0
u = 0
count = 0
down = 0
if s[0] == 'R':
	r += 1
	down = 1
else:
	u += 1
for i in range(1, len(s)):
	if s[i] == 'R':
		r += 1
	else:
		u += 1
	if r - u == 1 and down != 1:
		count += 1
		down = 1
	if u - r == 1 and down != 0:
		count += 1
		down = 0
print(count)


n = int(input())
s = input()
(x, y) = (0, 0)
side = -1
money = -1
for i in range(n):
	step = s[i] == 'U'
	if x == y and side != step:
		money += 1
		side = step
	if step:
		x += 1
	else:
		y += 1
print(money)


n = int(input())
s = input()
a = list()
U = 0
R = 0
k = 0
for i in range(n - 1):
	if s[i] == 'U':
		U += 1
		if s[i + 1] == 'U' and U == R:
			U = 0
			R = 0
			k += 1
	else:
		R += 1
		if s[i + 1] == 'R' and U == R:
			U = 0
			R = 0
			k += 1
print(k)


s = int(input())
lst = list(input())
x = -1
y = -1
mon = 0
z = 0
for i in range(s - 1):
	if lst[i] == 'U':
		y += 1
	elif lst[i] == 'R':
		x += 1
	if x == y and lst[i] == lst[i + 1]:
		mon += 1
print(mon)


def isIdentity(pos):
	return pos[0] == pos[1]

def U(pos):
	return (pos[0], pos[1] + 1)

def R(pos):
	return (pos[0] + 1, pos[1])

def curSide(curPos, preSide):
	if curPos[0] == curPos[1]:
		return preSide
	elif curPos[0] > curPos[1]:
		return 2
	else:
		return 1

def crossedSide(curPos, preSide):
	cs = curSide(curPos, preSide)
	if cs + preSide == 3:
		return True
	else:
		return False
inpn = input()
s = input()
n = int(inpn)
coin = 0
side = 0
pos = (0, 0)
for i in range(0, n):
	pos = globals()[s[i]](pos)
	if crossedSide(pos, side):
		coin += 1
	side = curSide(pos, side)
print(coin)


n = int(input())
s = list(input())
u = 0
r = 0
c = 0
for i in range(n - 1):
	if s[i] == 'U':
		u += 1
	else:
		r += 1
	if u == r and s[i] == s[i + 1]:
		c += 1
print(c)


import sys
import bisect
import math
from itertools import permutations
m = 1000000007

def find_lt(a, x):
	i = bisect.bisect_left(a, x)
	if i:
		return a[i - 1]
	else:
		return -1
n = int(input())
a = str(input())
ix = [0]
iy = [0]
x = 0
y = 0
for s in a:
	if s == 'U':
		y += 1
		ix.append(x)
		iy.append(y)
	else:
		x += 1
		ix.append(x)
		iy.append(y)
ans = 0
for i in range(1, n):
	if ix[i] == iy[i]:
		px = ix[i - 1]
		py = iy[i - 1]
		nx = ix[i + 1]
		ny = iy[i + 1]
		if px == nx or py == ny:
			ans += 1
print(ans)


(n, s, c) = (int(input()), input(), [0, 0])
(side, su) = (int(s[0] == 'R'), 0)
for i in range(n):
	if s[i] == 'R':
		if c[0] == c[1] and side == 0:
			(su, side) = (su + 1, 1)
		c[1] += 1
	else:
		if c[0] == c[1] and side == 1:
			(su, side) = (su + 1, 0)
		c[0] += 1
print(su)


n = int(input())
string = list(input())
R = 0
U = 0
flag = 0
count = 0
if string[0] == 'R':
	flag = 'R'
else:
	flag = 'U'
for i in string:
	if R == U and flag != i:
		count += 1
		flag = i
	if i == 'U':
		U += 1
	elif i == 'R':
		R += 1
print(count)


import sys
import os
import math
import re
n = int(input())
gates = 0
x = 0
y = 0
prevSide = 0
moves = input()
for i in range(len(moves)):
	if moves[i] == 'U':
		y += 1
	if moves[i] == 'R':
		x += 1
	if x > y:
		prevSide = 1
	elif y > x:
		prevSide = 2
	if x == y:
		if i < len(moves) - 1:
			tempX = x
			tempY = y
			if moves[i + 1] == 'U':
				tempY += 1
			if moves[i + 1] == 'R':
				tempX += 1
			if prevSide == 1:
				if tempY > tempX:
					gates += 1
			if prevSide == 2:
				if tempX > tempY:
					gates += 1
print(gates)


n = int(input())
s = input()
(x, y) = (0, 0)
l = []
for i in s:
	if i == 'U':
		y = y + 1
	else:
		x = x + 1
	l.append([x, y])
if n == 1 or n == 2:
	print(0)
else:
	c = 0
	for i in range(1, n - 1):
		if l[i][0] == l[i][1]:
			if l[i - 1][0] > l[i - 1][1] and l[i + 1][0] < l[i + 1][1] or (l[i - 1][0] < l[i - 1][1] and l[i + 1][0] > l[i + 1][1]):
				c = c + 1
	print(c)


n = int(input())
s = input() + ' '
x = 0
y = 0
count = 0
for i in range(n):
	if s[i] == 'U':
		y += 1
	if s[i] == 'R':
		x += 1
	if x == y and s[i + 1] == s[i]:
		count += 1
print(count)


n = int(input())
x = 0
y = 0
s = input()
l = []
for i in range(0, len(s)):
	if s[i] == 'R':
		x += 1
	else:
		y += 1
	l.append(x - y)
if n <= 2:
	print(0)
else:
	c = 0
	for j in range(1, n - 1):
		if l[j] == 0 and l[j - 1] * l[j + 1] < 0:
			c += 1
	print(c)


n = int(input())
s = input()
x = 0
y = 0
ans = 0
pred = -1
for c in s:
	if c == 'U':
		y += 1
	else:
		x += 1
	if x == y:
		continue
	if x > y:
		cur = 0
	else:
		cur = 1
	if cur != pred and pred != -1:
		ans += 1
	pred = cur
print(ans)


_ = input()
s = input()
start_p = [0, 0]
FLAG = 0
FLAG_p = s[0]
res = 0
for i in s:
	if i == 'R':
		start_p[0] += 1
	else:
		start_p[1] += 1
	if FLAG and FLAG_p == i:
		res += 1
	if start_p[0] == start_p[1]:
		FLAG = 1
		FLAG_p = i
	else:
		FLAG = 0
print(res)


import sys
if sys.version_info < (3, 0):
	lrange = range
	input = raw_input
	range = xrange
n = int(input())
s = input()
if s[0] == 'U':
	upper = True
	x = 0
	y = 1
else:
	upper = False
	x = 1
	y = 0
cnt = 0
for c in s[1:]:
	if c == 'U':
		y += 1
	if c == 'R':
		x += 1
	if upper:
		if y < x:
			upper = False
			cnt += 1
	elif y > x:
		upper = True
		cnt += 1
print(cnt)


n = int(input())
i = list(input())
x = 0
y = 0
cost = 0
for index in range(len(i) - 1):
	if i[index] == 'U':
		y += 1
	elif i[index] == 'R':
		x += 1
	if x == y:
		if i[index] == 'U' and i[index + 1] == 'U' or (i[index] == 'R' and i[index + 1] == 'R'):
			cost += 1
print(cost)


n = int(input())
seq = input()
curr_x = 0
curr_y = 0
ans = 0
prev_distr = 0
for sym in seq:
	if sym == 'U':
		curr_y += 1
	elif sym == 'R':
		curr_x += 1
	if curr_y - curr_x > 0 and prev_distr < 0:
		ans += 1
	elif curr_y - curr_x < 0 and prev_distr > 0:
		ans += 1
	if curr_y != curr_x:
		prev_distr = curr_y - curr_x
print(ans)


n = int(input())
S = input()
wall = 0
fafa = 0
coin = 0
if S[0] == 'U':
	side = -1
else:
	side = 1
for i in range(n):
	if S[i] == 'U':
		wall += 1
	if S[i] == 'R':
		fafa += 1
	if side * (fafa - wall) < 0:
		coin += 1
		side = fafa - wall
print(coin)


n = int(input())
s = input()
x = 0
y = 0
cnt = 0
for i in range(n):
	if s[i] == 'U':
		y += 1
	else:
		x += 1
	if x == y and i + 1 < n:
		if s[i] == 'U' and s[i + 1] == 'U' or (s[i] == 'R' and s[i + 1] == 'R'):
			cnt += 1
print(cnt)


n = int(input())
s = input()
x = y = 0
p = 0
l = 'X'
lx = ly = -1
for c in s:
	if c == 'U':
		y += 1
	elif c == 'R':
		x += 1
	if lx == ly and l == c:
		p += 1
	l = c
	lx = x
	ly = y
print(p)


n = int(input())
s = input()
x = list()
y = list()
x.append(0)
y.append(0)
for i in range(n):
	if s[i] == 'U':
		y.append(y[-1] + 1)
		x.append(x[-1])
	else:
		x.append(x[-1] + 1)
		y.append(y[-1])
x = x[1:]
y = y[1:]
res = 0
for i in range(n - 1):
	if s[i] == 'U':
		if x[i] == y[i] and s[i + 1] == 'U':
			res += 1
	elif x[i] == y[i] and s[i + 1] == 'R':
		res += 1
print(res)


input()
s = input()
a = p = 0
x = [0, 0]
for c in s:
	a += x[0] == x[1] and c == p
	x[c < 'U'] += 1
	p = c
print(a)


import sys

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

def iinput():
	return int(input())

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

def listinput():
	return list(map(int, input().split()))
n = iinput()
s = input()
(r, u) = (0, 0)
coin = 0
for i in range(n - 1):
	if s[i] == 'R':
		r += 1
	else:
		u += 1
	if r == u and s[i] == s[i + 1]:
		coin += 1
print(coin)


n = int(input())
a = list(input())
x = 0
y = 0
count = 0
for i in range(n - 1):
	if a[i] == 'U':
		y += 1
	else:
		x += 1
	if x == y and a[i] == a[i + 1]:
		count += 1
print(count)


n = int(input(''))
x = 0
y = 0
s = input('')
pos = -1
sol = 0
for i in range(len(s)):
	if s[i] == 'U':
		y += 1
	else:
		x += 1
	if x == 0 or y == 0:
		if x == 0:
			pos = 2
		else:
			pos = 1
	if x > y:
		if pos != 2:
			if x != 0 and y != 0:
				sol += 1
			pos = 2
	elif x < y:
		if pos != 1:
			if x != 0 and y != 0:
				sol += 1
			pos = 1
print(sol)


N = int(input())
s = input()
now = 0
root = []
for c in s:
	if c == 'R':
		now += 1
	else:
		now -= 1
	root.append(now)
ans = 0
for i in range(1, N - 1):
	if root[i] == 0:
		if (root[i + 1] > 0) != (root[i - 1] > 0):
			ans += 1
print(ans)


n = int(input())
str1 = input().strip()
start = []
start.append(0)
start.append(0)
val = 0
pos = 0
for al in str1:
	X1 = start[0]
	Y1 = start[1]
	if al == 'U':
		start[1] = start[1] + 1
	else:
		start[0] = start[0] + 1
	if X1 == Y1:
		if pos * (start[0] - start[1]) < 0:
			val += 1
	if start[0] == start[1]:
		pos = X1 - Y1
print(val)


input()
x = y = 0
l = []
s = input()
for ele in s:
	if ele == 'U':
		y += 1
	else:
		x += 1
	if x > y:
		l.append(1)
	if x == y:
		l.append(l[-1])
	if x < y:
		l.append(0)
cnt = 0
for i in range(1, len(l)):
	if l[i] != l[i - 1]:
		cnt += 1
print(cnt)


n = int(input())
seq = input()
px = 0
py = 0
pos = 0
coin = 0
for c in seq:
	if c == 'U':
		py += 1
	if c == 'R':
		px += 1
	if pos == 0:
		if px > py:
			pos = 1
		elif px < py:
			pos = 2
	elif pos == 1:
		if px < py:
			pos = 2
			coin += 1
	elif pos == 2:
		if px > py:
			pos = 1
			coin += 1
print(coin)


(n, x, y, k, v) = (int(input()), 0, 0, 0, -1)
for ch in input():
	if ch == 'R':
		x += 1
	else:
		y += 1
	nk = k
	if x > y:
		nk = 1
	elif y > x:
		nk = 2
	if nk != k:
		k = nk
		v += 1
print(v)


import sys

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans
mod = int(1000000000.0) + 7

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

def iinp():
	return int(input())

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

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

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
from collections import OrderedDict
n = iinp()
s = ssinp()
f = ''
x = y = 0
ans = 0
for c in s:
	if c == 'U':
		y += 1
		if f == 'd':
			ans += 1
			f = ''
		elif x == y:
			f = 'd'
		else:
			f = ''
	elif c == 'R':
		x += 1
		if f == 'u':
			ans += 1
			f = ''
		elif x == y:
			f = 'u'
		else:
			f = ''
p(ans)


n = int(input())
s = input()
x = 0
y = 0
money = 0
for i in range(n - 1):
	op = s[i]
	if op == 'R':
		x += 1
		if x == y:
			if s[i + 1] == 'R':
				money += 1
	else:
		y += 1
		if x == y:
			if s[i + 1] == 'U':
				money += 1
print(money)


n = int(input())
s = input()
ans = 0
pl = 1
pl2 = 1
x = 0
y = 0
x1 = 0
y1 = 0
for i in range(n):
	if s[i] == 'U':
		y += 1
	else:
		x += 1
	if x > y:
		pl = 1
	else:
		pl = 2
	if x1 == y1 and i != 0 and (pl != pl2):
		ans += 1
	x1 = x
	y1 = y
	if x != y:
		pl2 = pl
print(ans)


n = int(input())
steps = input()
point = [0, 0]
king = None
king_prev = None
Gate = True
tick = 0
for i in range(n):
	if steps[i] == 'U':
		point[1] += 1
	elif steps[i] == 'R':
		point[0] += 1
	if i == 0:
		if point[1] < point[0] and Gate:
			king_prev = king = 'R'
		elif point[1] > point[0] and Gate:
			king_prev = king = 'L'
	else:
		if point[1] < point[0] and Gate:
			king = 'R'
		elif point[1] > point[0] and Gate:
			king = 'L'
		if king != king_prev:
			king_prev = king
			tick += 1
print(tick)


n = int(input())
way = input()
x = 0
y = 0
plc = 0
res = 0
for step in way:
	if step == 'U':
		y += 1
	if step == 'D':
		y -= 1
	if step == 'L':
		x -= 1
	if step == 'R':
		x += 1
	if y > x:
		if plc == -1:
			res += 1
			plc = 1
		else:
			plc = 1
	elif y < x:
		if plc == 1:
			res += 1
			plc = -1
		else:
			plc = -1
print(res)


n = int(input())
list1 = list(input())
y = 0
x = 0
k = 0
cost = 0
if list1[0] == 'U':
	k = 2
	y += 1
else:
	k = 1
	x += 1
for char in list1[1:]:
	if char == 'R':
		x += 1
	else:
		y += 1
	if y > x and k == 1:
		k = 2
		cost += 1
	elif y < x and k == 2:
		k = 1
		cost += 1
print(cost)


n = int(input())
s = input()
cnt = {'R': 0, 'U': 0}
ans = 0
for i in range(n - 1):
	cnt[s[i]] += 1
	if cnt['R'] == cnt['U'] and s[i + 1] == s[i]:
		ans += 1
print(ans)


n = int(input())
s = input()
(x, y) = (0, 0)
(x1, y1) = (0, 0)
(x2, y2) = (0, 0)
p = 'n'
c = 0
if s[0] == 'R':
	x += 1
	p = 'd'
else:
	y += 1
	p = 'u'
for i in range(1, n):
	if s[i] == 'R':
		x += 1
	else:
		y += 1
	if x > y and p == 'u':
		c += 1
		p = 'd'
	elif x < y and p == 'd':
		c += 1
		p = 'u'
print(c)


n = int(input())
s = input()
(x, y) = (0, 0)
(bx, by) = (0, 0)
cnt = 0
for i in range(0, len(s) - 1):
	if s[i] == 'R':
		x += 1
	else:
		y += 1
	if x == y:
		if s[i + 1] == 'R':
			if (x + 1 - y) * (bx - by) < 0:
				cnt += 1
		elif (x - (y + 1)) * (bx - by) < 0:
			cnt += 1
	(bx, by) = (x, y)
print(cnt)


from sys import stdin, stdout
n = int(stdin.readline())
a = [x for x in stdin.readline().strip()]
s = [0, 0]
c = 0
l = False
for x in a:
	if x == 'R':
		s[0] += 1
	elif x == 'U':
		s[1] += 1
	if s[0] == s[1]:
		l = True
	else:
		if l:
			nw = int(s[0] < s[1])
			if not nw == w:
				c += 1
		w = int(s[0] < s[1])
		l = False
print(c)


n = input()
n = int(n)
sequence = input('')
sequence = str(sequence)
progress = [(0, 0)]
x = 0
y = 0
final = 0
for i in range(n):
	if sequence[i] == 'U':
		y += 1
		progress.append((x, y))
	elif sequence[i] == 'R':
		x += 1
		progress.append((x, y))
	if len(progress) >= 3:
		if progress[i][0] == progress[i][1]:
			if progress[i][1] == progress[i + 1][1] - 1:
				if progress[i - 1][1] == progress[i + 1][1] - 2:
					final += 1
			elif progress[i][0] == progress[i + 1][0] - 1:
				if progress[i - 1][0] == progress[i + 1][0] - 2:
					final += 1
print(final)


n = int(input())
s = input()
cnt = 0
x = 0
y = 0
y1 = 0
x1 = 0
flag = 2
for i in s:
	if y > x:
		flag = 1
	if y < x:
		flag = 0
	if i == 'U':
		y1 = y + 1
	else:
		x1 = x + 1
	if x == y:
		if x1 > x and y1 == y and (flag == 1):
			cnt += 1
		elif x1 == x and y1 > y and (flag == 0):
			cnt += 1
	x = x1
	y = y1
print(cnt)


n = int(input())
s = input()
up = right = ans = 0
kingdom = None
if s[0] == 'U':
	up = 1
	kingdom = 'above'
else:
	right = 1
	kingdom = 'below'
for i in range(1, n):
	if s[i] == 'U':
		up += 1
		if up > right and kingdom == 'below':
			ans += 1
			kingdom = 'above'
	else:
		right += 1
		if right > up and kingdom == 'above':
			ans += 1
			kingdom = 'below'
print(ans)


n = int(input())
s = input()
(x, y, cnt) = (0, 0, 0)
if s[0] == 'U':
	prev = 1
	y += 1
else:
	prev = -1
	x += 1
for i in range(1, n):
	if s[i] == 'U':
		y += 1
	else:
		x += 1
	temp = y - x
	if temp > 0 and prev < 0:
		cnt += 1
		prev = temp
	elif prev > 0 and temp < 0:
		cnt += 1
		prev = temp
print(cnt)


n = input()
s = input()
x = 0
y = 0
f = True
c = 0
if s[0] == 'U':
	y += 1
	f = False
else:
	x += 1
	f = True
for i in range(1, len(s)):
	if s[i] == 'U':
		y += 1
	else:
		x += 1
	if f and y > x or (not f and x > y):
		c += 1
		f = not f
print(c)


c = input()
t = input()
c = int(c)
if t[0] == 'R':
	f = 'up'
else:
	f = 'down'
(x, y, coin) = (0, 0, 0)
for i in t:
	if i == 'R':
		x += 1
	else:
		y += 1
	if x > y:
		if f != 'up':
			coin += 1
			f = 'up'
	elif y > x:
		if f != 'down':
			coin += 1
			f = 'down'
print(coin)


n = int(input())
s = input()
xy = [(0, 0)]
count = 0
for x in range(len(s)):
	if s[x] == 'R':
		xy.append((xy[x][0] + 1, xy[x][1]))
	else:
		xy.append((xy[x][0], xy[x][1] + 1))
x = 0
y = 1
for point in range(1, len(xy) - 1):
	if xy[point][x] == xy[point][y]:
		if xy[point + 1][x] - xy[point - 1][x] == 2 or xy[point + 1][y] - xy[point - 1][y] == 2:
			count += 1
print(count)


n = int(input())
p = input()
pos_x = 0
pos_y = 0
o = 0
l = ''
for i in range(n - 1):
	if p[i] == 'R':
		pos_x += 1
		l = 'R'
	else:
		pos_y += 1
		l = 'U'
	if pos_y == pos_x and (l == 'U' and p[i + 1] == 'U' or (l == 'R' and p[i + 1] == 'R')):
		o += 1
print(o)


from sys import stdin
n = int(stdin.readline())
moves = stdin.readline()
wallDistance = 0
side = 0
coins = 0
for i in range(0, n):
	if moves[i] == 'U':
		wallDistance += 1
	else:
		wallDistance -= 1
	if wallDistance > 0:
		if side == 2:
			coins += 1
		side = 1
	elif wallDistance < 0:
		if side == 1:
			coins += 1
		side = 2
print(coins)


n = int(input())
s = input()
x = 0
y = 0
c = 0
if s[0] == 'U':
	y += 1
	l = 1
else:
	x += 1
	l = -1
for i in s[1:]:
	if i == 'U':
		y += 1
	else:
		x += 1
	if y > x:
		l1 = 1
		if l1 != l:
			c += 1
		l = 1
	elif x > y:
		l1 = -1
		if l1 != l:
			c += 1
		l = -1
print(c)


def getCoord(x, y, t):
	if t == 'U':
		return (x, y + 1)
	return (x + 1, y)
n = int(input())
s = input()
(x, y) = getCoord(0, 0, s[0])
t = 1
if x < y:
	t = 0
ans = 0
for ch in s[1:]:
	(x, y) = getCoord(x, y, ch)
	if x == y:
		continue
	nt = 1
	if x < y:
		nt = 0
	if t != nt:
		t = nt
		ans += 1
print(ans)


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = 1
if debug:
	test_count = inp()
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	n = inp()
	ans = 0
	direction = 0
	a = list(insr())
	diff = 0
	for x in a:
		if x == 'U':
			diff += 1
		else:
			diff -= 1
		if diff > 0 and direction == -1:
			ans += 1
		elif diff < 0 and direction == 1:
			ans += 1
		if diff < 0:
			direction = -1
		if diff > 0:
			direction = 1
	print(ans)


n = int(input())
a = input()
if a[0] == 'U':
	t = 1
else:
	t = 2
m = 0
x = 0
y = 0
for i in range(n):
	if a[i] == 'U':
		y += 1
	else:
		x += 1
	if x > y:
		if t == 1:
			t = 2
			m += 1
	elif x < y:
		if t == 2:
			t = 1
			m += 1
print(m)


n = int(input())
s = str(input())
from collections import defaultdict
f = defaultdict(lambda : [])
f[0].append(0)
ans = 0
cur = (0, 0)
for i in range(n):
	if s[i] == 'U':
		cur = (cur[0], cur[1] + 1)
	else:
		cur = (cur[0] + 1, cur[1])
	f[cur[0]].append(cur[1])
for i in range(10 ** 5 + 1):
	if i - 1 in f[i] and i in f[i] and (i + 1 in f[i]):
		ans += 1
	if i in f[i - 1] and i in f[i] and (i in f[i + 1]):
		ans += 1
print(ans)


n = int(input())
count = 0
s = input()
left1 = 0
right1 = 0
right2 = 0
left2 = 0
k = [0, 0]
if s[0] == 'R':
	right1 = 1
	k[0] += 1
else:
	left1 = 1
	k[1] += 1
for i in range(1, len(s)):
	if s[i] == 'R':
		k[0] += 1
	if s[i] == 'U':
		k[1] += 1
	if k[0] > k[1]:
		right2 = 1
		left2 = 0
	if k[1] > k[0]:
		left2 = 1
		right2 = 0
	if left2 == 1 and right1 == 1:
		count += 1
		right1 = 0
		left2 = 0
		left1 = 1
	elif left1 == 1 and right2 == 1:
		count += 1
		right2 = 0
		left1 = 0
		right1 = 1
print(count)


from sys import stdin
input = stdin.readline
nbMvt = int(input())
seq = input()
next = False
(x, y) = (0, 0)
total = 0
prec = 0
if seq[0] == 'U':
	r = 2
else:
	r = 1
for elem in seq:
	if elem == 'U':
		y += 1
	elif elem == 'R':
		x += 1
	if x > y:
		r = 1
	elif x < y:
		r = 2
	if next:
		if prec != r:
			total += 1
		next = False
	if x == y:
		next = True
		prec = r
print(total)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
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 list(map(int, 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():
	n = I()
	s = S()
	t = c = 0
	if s[0] == 'U':
		t += 1
		c = 1
	else:
		t -= 1
		c = -1
	r = 0
	for k in s[1:]:
		if k == 'U':
			t += 1
		else:
			t -= 1
		if abs(t) == 1 and t != c:
			r += 1
			c = t
	return r
print(main())


input()
x = y = k = r = 0
for u in input():
	if u == 'U':
		y += 1
	else:
		x += 1
	if k * (x - y) < 0:
		r += 1
	if x - y:
		k = x - y
print(r)


n = int(input())
s = input()
u = r = 0
ans = 0
for i in range(n - 1):
	if s[i] == 'R':
		r += 1
	else:
		u += 1
	if u == r and s[i + 1] == s[i]:
		ans += 1
print(ans)


n = int(input())
s = input()
if n == 1:
	print(0)
else:
	path = [-1, -1, -1, -1, 0, 0]
	cost = 0
	for i in s:
		path[0] = path[2]
		path[1] = path[3]
		path[2] = path[4]
		path[3] = path[5]
		if i == 'U':
			path[5] += 1
		elif i == 'R':
			path[4] += 1
		if path[0] == path[2] == path[4] == path[3] and path[1] == path[3] - 1 and (path[5] == path[3] + 1):
			cost += 1
		if path[1] == path[3] == path[5] == path[2] and path[0] == path[2] - 1 and (path[4] == path[2] + 1):
			cost += 1
	print(cost)


n = int(input())
str = input()
x = 0
y = 0
if str[0] == 'U':
	prev = True
else:
	prev = False
counter = 0
for i in range(n):
	if x > y:
		prev = False
	elif y > x:
		prev = True
	if str[i] == 'U':
		y += 1
	if str[i] == 'R':
		x += 1
	if x > y:
		flag = False
	elif y > x:
		flag = True
	if prev != flag:
		counter += 1
print(counter)


n = int(input())
moves = input()
(x, y) = (0, 0)
(ans, ptype) = (0, 1)
for move in moves:
	if move == 'U':
		y += 1
	else:
		x += 1
	ctype = 0 if y < x else 1 if y == x else 2
	if ctype != 1 and ctype != ptype:
		ans += 1
		ptype = ctype
print(ans - 1)


n = int(input())
s = input()
(x, y, last, count) = (0, 0, 0, 0)
for i in range(n):
	if s[i] == 'R':
		x += 1
	else:
		y += 1
	if last == 0:
		if y == 1:
			last = 1
		else:
			last = 2
	if last == 1 and x > y:
		last = 2
		count += 1
	elif last == 2 and x < y:
		last = 1
		count += 1
print(count)


import math
n = int(input())
s = input()
(x, y) = (0, 0)
c = 0
t2 = 1000000
for i in range(n):
	if s[i] == 'U':
		x += 1
	elif s[i] == 'R':
		y += 1
	if x == y:
		continue
	if x == 0:
		t1 = 1000000.0
	else:
		t1 = y / x
	if i != 0 and (t1 < 1.0 and t2 > 1.0 or (t1 > 1.0 and t2 < 1.0)):
		c += 1
	t2 = t1
print(c)


def move(x, y, a):
	return (x + 1, y) if a is 'R' else (x, y + 1)
n = int(input())
s = list(input())
(x, y) = move(0, 0, s[0])
(k, c) = (1, 0)
if y > x:
	k = 2
for i in range(1, n):
	(x, y) = move(x, y, s[i])
	if k == 1 and y > x:
		(k, c) = (2, c + 1)
	elif k == 2 and x > y:
		(k, c) = (1, c + 1)
print(c)


def main():
	n = int(input())
	d = [c for c in input()]
	r = 0
	cur = True if d[0] == 'U' else False
	x = 0
	y = 0
	l = cur
	for c in d:
		if c == 'U':
			y += 1
			if cur is None:
				cur = True
				if l != cur:
					r += 1
			elif cur is False:
				if x == y:
					l = cur
					cur = None
		if c == 'R':
			x += 1
			if cur is None:
				cur = False
				if l != cur:
					r += 1
			elif cur is True:
				if x == y:
					l = cur
					cur = None
	print(r)
main()


n = int(input())
s = input()
p = [0, 0]
lk = 0
pt = [[0, 0]]
for l in s:
	np = [p[0], p[1]]
	if l == 'U':
		np = [p[0], p[1] + 1]
	if l == 'D':
		np = [p[0], p[1] - 1]
	if l == 'R':
		np = [p[0] + 1, p[1]]
	if l == 'L':
		np = [p[0] - 1, p[1]]
	pt.append(np)
	p = np
ans = 0
tt = []
for p in pt:
	k = 0
	if p[1] > p[0]:
		k = 1
	elif p[1] < p[0]:
		k = 2
	tt.append(k)
lk = -1
for k in tt:
	if k == 1 and lk != k:
		ans += 1
		lk = k
	if k == 2 and lk != k:
		ans += 1
		lk = k
print(ans - 1)


n = int(input())
s = input()
g = s[0]
c = 0
m = 0
for i in s:
	if i == 'R':
		c -= 1
	if i == 'U':
		c += 1
	if c == -1 and g == 'U' or (c == 1 and g == 'R'):
		m += 1
		g = i
print(m)


n = int(input())
s = input()
c = [0, 0]
d = 0
for i in range(n):
	if c[0] == c[1] and s[i] == s[i - 1] and (i > 0):
		d = d + 1
	if s[i] == 'R':
		c[0] = c[0] + 1
	elif s[i] == 'U':
		c[1] = c[1] + 1
print(d)


n = int(input())
s = input()
p = (s[0] == 'R') - (s[0] == 'U')
x = p
ans = 0
for l in s[1:]:
	x += (l == 'R') - (l == 'U')
	if p * x < 0:
		p = -p
		ans += 1
print(ans)


n = int(input())
L = [i for i in input()]
(u, r) = (0, 0)
c = 0
for i in range(n - 1):
	if L[i] == 'U':
		u += 1
	elif L[i] == 'R':
		r += 1
	if u == r and L[i] == L[i + 1]:
		u = 0
		r = 0
		c += 1
print(c)


n = int(input())
s = input()
c = 0
l = []
x = y = a = b = 0
for i in range(n):
	x += s[i] == 'R'
	y += s[i] == 'U'
	l.append([x, y])
for i in range(1, n - 1):
	if l[i][0] == l[i][1]:
		if l[i - 1][1] == l[i][1] == l[i + 1][1] or l[i - 1][0] == l[i][0] == l[i + 1][0]:
			c += 1
print(c)


class Point:

	def __init__(self, x, y):
		self.x = x
		self.y = y
n = int(input())
poiscao = input()
pessoa = Point(0, 0)
cont = 0
start = True
em_cima = False
em_baixo = False
for i in poiscao:
	if i == 'R':
		pessoa.x += 1
	elif i == 'U':
		pessoa.y += 1
	if start:
		if pessoa.y > pessoa.x:
			em_cima = True
		else:
			em_baixo = True
		start = False
	elif pessoa.y > pessoa.x and em_baixo:
		cont += 1
		em_cima = True
		em_baixo = False
	elif pessoa.x > pessoa.y and em_cima:
		cont += 1
		em_cima = False
		em_baixo = True
print(cont)


def sgn(x):
	if x == 0:
		return 0
	return 1 if x > 0 else -1
n = int(input())
x = 0
y = 0
res = 0
last = 0
for ch in input().strip():
	if ch == 'U':
		y += 1
	else:
		x += 1
	if sgn(x - y) * last < 0:
		res += 1
	if x != y:
		last = sgn(x - y)
print(res)


n = int(input())
S = list(input())
ANS = 0
LAST = None
(X, Y) = (0, 0)
for s in S:
	if s == 'U':
		if LAST == None:
			LAST = 1
		elif X == Y:
			if LAST == 0:
				ANS += 1
				LAST = 1
		Y += 1
	else:
		if LAST == None:
			LAST = 0
		elif X == Y:
			if LAST == 1:
				ANS += 1
				LAST = 0
		X += 1
print(ANS)


from sys import stdin
n = int(input())
side = 0
res = 0
i = 0
for _ in range(n):
	c = stdin.read(1)
	i += 1 if c == 'U' else -1
	if i * side < 0:
		res += 1
		side *= -1
	if side == 0:
		side = 1 if c == 'U' else -1
print(res)


import sys

def solve(io):
	trash = io.readInt()
	inp = io.readString()
	start = [0, 0]
	state = ''
	coins = 0
	for x in inp:
		if x == 'R':
			start[1] += 1
		else:
			start[0] += 1
		new_state = ''
		if start[0] == start[1]:
			new_state = state
		elif start[1] > start[0]:
			new_state = 'top'
		else:
			new_state = 'bot'
		if state != new_state and state != '':
			coins += 1
		state = new_state
	io.println(coins)

class IO:
	input = None
	output = None
	raw = ''
	buf = []
	pos = 0

	def __init__(self, inputStream, outputStream):
		self.input = inputStream
		self.output = outputStream

	def readToBuffer(self):
		self.raw = self.input.readline().rstrip('\n')
		self.buf = self.raw.split()
		self.pos = 0

	def readString(self):
		while self.pos == len(self.buf):
			self.readToBuffer()
		ans = self.buf[self.pos]
		self.pos += 1
		return ans

	def readInt(self):
		return int(self.readString())

	def readFloat(self):
		return float(self.readString())

	def readStringArray(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.readString())
		return arr

	def readIntArray(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.readInt())
		return arr

	def readFloatArray(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.readFloat())
		return arr

	def readLine(self):
		while self.pos == len(self.buf):
			self.readToBuffer()
		if self.pos > 0:
			raise ValueError('Cannot call readline in the middle of a line.')
		return self.raw

	def print(self, s):
		self.output.write(str(s))

	def println(self, s):
		self.print(s)
		self.print('\n')

	def flushOutput(self):
		self.output.flush()
pythonIO = IO(sys.stdin, sys.stdout)
solve(pythonIO)
pythonIO.flushOutput()


a = int(input())
b = input()
b = b + '0'
x = 0
y = 0
k = 0
if b[0] == 'U':
	y += 1
	j = 1
else:
	x += 1
	j = 0
for i in range(1, a):
	if b[i] == 'U':
		y += 1
	else:
		x += 1
	if x > y:
		z = 0
	if x < y:
		z = 1
	if x == y:
		z = j
	if z != j:
		k += 1
		j = z
print(k)


n = int(input())
s = input()
x = 0
y = 0
c = 0
if s[0] == 'U':
	y = y + 1
	prev = 1
else:
	x = x + 1
	prev = 0
for i in range(1, n):
	if s[i] == 'U':
		y = y + 1
		if y > x and prev == 0:
			c = c + 1
			prev = 1
	elif s[i] == 'R':
		x = x + 1
		if x > y and prev == 1:
			c = c + 1
			prev = 0
print(c)


def main():
	n = int(input())
	s = input()
	x = 0
	y = 0
	pas = 0
	for i in range(n - 1):
		if s[i] == 'U':
			y += 1
		if s[i] == 'R':
			x += 1
		if i > 0:
			if x == y:
				if s[i] == 'U' and s[i + 1] == 'U':
					pas += 1
				elif s[i] == 'R' and s[i + 1] == 'R':
					pas += 1
	print(pas)
main()


n = int(input())
dir = input() + 'e'
count = 0
(x, y) = (0, 0)
for i in range(len(dir) - 1):
	if dir[i] == 'R':
		x = x + 1
	else:
		y = y + 1
	if x == y:
		if dir[i + 1] == dir[i]:
			count += 1
print(count)


def go():
	n = int(input())
	total = 0
	x = 0
	y = 0
	k = 0
	d = input()
	if d[0] == 'U':
		k = 1
		y += 1
	else:
		k = 2
		x += 1
	for i in d[1:]:
		if x == y:
			if i == 'U' and k == 2:
				total += 1
				k = 1
			elif i == 'R' and k == 1:
				total += 1
				k = 2
		if i == 'U':
			y += 1
		else:
			x += 1
	return total
print(go())


n = int(input())
now = 0
pos = (0, 0)
coins = 0
s = input()
if s[0] == 'U':
	now = 1
	pos = (0, 1)
else:
	now = 2
	pos = (1, 0)
s = s[1:]
for i in range(n - 1):
	if s[i] == 'U':
		pos = (pos[0], pos[1] + 1)
	else:
		pos = (pos[0] + 1, pos[1])
	if pos[0] == pos[1]:
		if i + 1 < n - 1:
			if now == 1 and s[i + 1] == 'R':
				now = 2
				coins += 1
			elif now == 2 and s[i + 1] == 'U':
				now = 1
				coins += 1
print(coins)


n = int(input())
s = input().strip()

def check(x, y):
	if x > y:
		return 1
	else:
		return 2
res = 0
(x, y) = (0, 0)
pre = 0
for i in range(n):
	if s[i] == 'U':
		y += 1
	elif s[i] == 'R':
		x += 1
	if x == y:
		continue
	cur = check(x, y)
	if pre != 0 and pre != cur:
		res += 1
	pre = cur
print(res)


x = int(input())
p = input()
(c, r, u) = (0, 0, 0)
for i in range(x - 1):
	if p[i] == 'R':
		r += 1
	elif p[i] == 'U':
		u += 1
	if u == r:
		(r, u) = (0, 0)
		if p[i + 1] == p[i]:
			c += 1
print(c)


n = int(input())
cmd_line = input()
(x, y) = (0, 0)
cnt = 0
if cmd_line[0] == 'U':
	st = 'x'
else:
	st = 'y'
for i in cmd_line:
	if i == 'U':
		y += 1
	else:
		x += 1
	if x > y:
		if st == 'y':
			cnt += 1
			st = 'x'
	elif y > x:
		if st == 'x':
			cnt += 1
			st = 'y'
print(cnt - 1)


import sys

def solve(io):
	io.readInt()
	S = io.readString()
	cnt = -1
	x = 0
	y = 0
	side = -1
	for c in S:
		if c == 'R':
			x += 1
		else:
			y += 1
		if x < y:
			nextSide = 0
		elif x > y:
			nextSide = 1
		if side != nextSide:
			cnt += 1
			side = nextSide
	io.println(cnt)

class IO:
	input = None
	output = None
	raw = ''
	buf = []
	pos = 0

	def __init__(self, inputStream, outputStream):
		self.input = inputStream
		self.output = outputStream

	def readToBuffer(self):
		self.raw = self.input.readline().rstrip('\n')
		self.buf = self.raw.split()
		self.pos = 0

	def readString(self):
		while self.pos == len(self.buf):
			self.readToBuffer()
		ans = self.buf[self.pos]
		self.pos += 1
		return ans

	def readInt(self):
		return int(self.readString())

	def readFloat(self):
		return float(self.readString())

	def readLine(self):
		while self.pos == len(self.buf):
			self.readToBuffer()
		if self.pos > 0:
			raise ValueError('Cannot call readline in the middle of a line.')
		return self.raw

	def print(self, s):
		self.output.write(str(s))

	def println(self, s):
		self.print(s)
		self.print('\n')

	def flushOutput(self):
		self.output.flush()
pythonIO = IO(sys.stdin, sys.stdout)
solve(pythonIO)
pythonIO.flushOutput()


n = int(input())
s = input()
ans = 0
x = 0
y = 0
goes = []
for i in s:
	if i == 'R':
		x += 1
	else:
		y += 1
	goes.append([x, y])
for i in range(len(goes)):
	if i <= 1:
		continue
	f = goes[i][0] - goes[i - 2][0] == 2 and goes[i][1] == goes[i - 2][1]
	s = goes[i][1] - goes[i - 2][1] == 2 and goes[i][0] == goes[i - 2][0]
	if (f or s) and goes[i - 1][0] == goes[i - 1][1]:
		ans += 1
print(ans)


n = int(input())
s = input()
u = 0
r = 0
ans = 0
start = s[0]
for i in s:
	prev = start
	if i == 'U':
		u += 1
	if i == 'R':
		r += 1
	if u < r:
		start = 'R'
	if r < u:
		start = 'U'
	if start != prev:
		ans += 1
print(ans)


input()
(x, y) = (0, 0)
ans = 0
s = input()
t = -1
for i in range(len(s)):
	if s[i] == 'U':
		y += 1
	else:
		x += 1
	if x > y and t != 0:
		ans += int(t != -1)
		t = 0
	elif x < y and t != 1:
		ans += int(t != -1)
		t = 1
print(ans)


num = int(input())
str = input()
i = 0
x = 0
y = 0
taka = 0
while i < len(str):
	if str[i] == 'U':
		y += 1
	elif str[i] == 'R':
		x += 1
	if x == y and i < len(str) - 1:
		if str[i] == 'U' and str[i + 1] == 'U':
			taka += 1
		if str[i] == 'R' and str[i + 1] == 'R':
			taka += 1
	i += 1
print(taka)


n = int(input())
path = input().strip()
S = 0
(x, y) = (0, 0)
upper = path[0] == 'U'
for ch in path:
	x += ch == 'R'
	y += ch == 'U'
	if x > y and upper:
		S += 1
		upper = False
	elif x < y and (not upper):
		S += 1
		upper = True
print(S)


noOfMoves = int(input())
seqenceMoves = list(map(str, input()))
pos = [0, 0]
z = 0
flag1 = 0
flag2 = 0
count = 0
for i in seqenceMoves:
	if i == 'U':
		pos[1] += 1
		z += 1
	else:
		pos[0] += 1
	if pos[0] > z and flag2 == 1:
		count += 1
		flag2 = 0
		flag1 = 1
	elif pos[0] < z and flag1 == 1:
		count += 1
		flag1 = 0
		flag2 = 1
	elif pos[0] < z:
		flag2 = 1
	elif pos[0] > z:
		flag1 = 1
print(count)


(n, s) = (int(input()), input())
c = 0
(p, q) = (0, 0)
(x, y) = (0, 0)
for i in s:
	if i == 'U':
		if x == y and q == y - 1:
			c += 1
		q = y
		p = x
		y += 1
	else:
		if x == y and p == x - 1:
			c += 1
		q = y
		p = x
		x += 1
print(c)


from sys import stdin as si
from collections import Counter as c

class Solution:

	def bazinga(self, n, s):
		(cr, cu) = (0, 0)
		c = 0
		for i in range(n - 1):
			if s[i] == 'R':
				cr += 1
			else:
				cu += 1
			if cr == cu and s[i] == s[i + 1]:
				c += 1
		return c
n = int(si.readline().strip())
s = si.readline().strip()
S = Solution()
print(S.bazinga(n, s))


n = eval(input())
arr = list(input())
(flag, x, y) = (-1, 0, 0)
pos = 0
for i in arr:
	if i == 'U':
		y += 1
	else:
		x += 1
	if pos != 'U' and y > x:
		flag += 1
		pos = 'U'
	elif pos != 'D' and x > y:
		flag += 1
		pos = 'D'
print(flag)


(n, s, ans) = (int(input()), input(), 0)
(a, m) = ([[0, 1] if s[0] == 'U' else [1, 1]], 0 if s[0] == 'U' else 1)
for i in range(1, n):
	if s[i] == 'U' and a[len(a) - 1][0] == 0 or (s[i] == 'R' and a[len(a) - 1][0] == 1):
		a[len(a) - 1][1] += 1
	else:
		a.append([0, 1] if s[i] == 'U' else [1, 1])
c = [0 for x in range(len(a))]
for i in range(len(a)):
	if a[i][0] == 0:
		c[i] = c[i - 1] + a[i][1] if i != 0 else a[i][1]
		if i != 0 and c[i] > 0 > c[i - 1]:
			ans += 1
	else:
		c[i] = c[i - 1] - a[i][1] if i != 0 else -1 * a[i][1]
		if i != 0 and c[i] < 0 < c[i - 1]:
			ans += 1
print(ans)


n = int(input())
route = input()
(x, y) = (0, 0)
(right, up) = ('R', 'U')
(on_gate, on_1, on_2) = (0, 1, -1)

def pos_now(x, y):
	if x == y:
		return on_gate
	elif x > y:
		return on_1
	else:
		return on_2

def movement(char, x, y):
	if char == right:
		x += 1
	else:
		y += 1
	return (x, y)
(x, y) = movement(route[0], x, y)
pos_prev = pos_now(x, y)
ans = 0
for i in range(1, n):
	(x, y) = movement(route[i], x, y)
	if pos_now(x, y) is not on_gate:
		if pos_prev != pos_now(x, y):
			ans += 1
			pos_prev = pos_now(x, y)
print(ans)


n = int(input())
s = input()
dic = {'R': (1, 0), 'U': (0, 1)}
pre = None
(x, y) = (0, 0)
num = 0
for i in range(n):
	(nx, ny) = (x + dic[s[i]][0], y + dic[s[i]][1])
	if x == y:
		if pre == 'U' and nx < ny:
			num += 1
		elif pre == 'R' and nx > ny:
			num += 1
	if nx > ny:
		pre = 'U'
	elif nx < ny:
		pre = 'R'
	(x, y) = (nx, ny)
print(num)


n = int(input())
a = input()
c = 0
i = 0
x = 0
y = 0
count = 0
while i < len(a):
	if a[i] == 'R':
		if c == 1 and x == y:
			count += 1
		c = 1
		x += 1
	elif a[i] == 'U':
		if c == 2 and x == y:
			count += 1
		c = 2
		y += 1
	i += 1
print(count)


n = int(input())
poiscao = input()
x = 0
y = 0
cont = 0
start = True
em_cima = False
em_baixo = False
for i in poiscao:
	if i == 'R':
		x += 1
	elif i == 'U':
		y += 1
	if start:
		if y > x:
			em_cima = True
		else:
			em_baixo = True
		start = False
	elif y > x and em_baixo:
		cont += 1
		em_cima = True
		em_baixo = False
	elif x > y and em_cima:
		cont += 1
		em_cima = False
		em_baixo = True
print(cont)


n = int(input())
s = input()
l = len(s)
x = 0
y = 0
cnt = 0
for i in range(l):
	if s[i] == 'R':
		x += 1
	if s[i] == 'U':
		y += 1
	if x == y and i < l - 1 and (s[i] == s[i + 1]):
		cnt += 1
print(cnt)


def memory(A):
	res = [0, 0]
	if A[0] == 'R' or A[0] == 'r':
		prevstate = 'first'
		currstate = 'first'
	if A[0] == 'U' or A[0] == 'u':
		prevstate = 'second'
		currstate = 'second'
	money = 0
	for i in range(len(A)):
		if A[i] == 'U' or A[i] == 'u':
			res[1] = res[1] + 1
		else:
			res[0] = res[0] + 1
		if res[0] > res[1]:
			currstate = 'first'
		if res[0] < res[1]:
			currstate = 'second'
		if currstate != prevstate:
			money = money + 1
			prevstate = currstate
	return money
moves = int(input())
A = list(input())
print(memory(A))


n = int(input())
s = input()
if n == 1:
	print(0)
	exit(0)
(px, py) = (0, 0)

def sgn(x):
	return 1 if x > 0 else 0 if x == 0 else -1
if s[0] == 'U':
	py += 1
else:
	px += 1
(x, y) = (px, py)
if s[1] == 'U':
	y += 1
else:
	x += 1
ans = 0
for c in s[2:]:
	if c == 'U':
		ans += 1 if sgn(py - px) * sgn(y - x + 1) == -1 else 0
		(px, py) = (x, y)
		y += 1
	else:
		ans += 1 if sgn(py - px) * sgn(y - x - 1) == -1 else 0
		(px, py) = (x, y)
		x += 1
print(ans)


import math as mt
import sys, string
from collections import Counter, defaultdict
input = sys.stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
ARR = lambda : list(map(int, input().split()))

def printARR(arr):
	for e in arr:
		print(e, end=' ')
	print()

def main():
	n = I()
	s = input()
	cp = [0, 0]
	ans = 0
	pos = 0
	for i in range(n):
		if s[i] == 'U':
			cp[1] += 1
		if s[i] == 'R':
			cp[0] += 1
		if i == 0:
			if cp[0] < cp[1]:
				pos = 1
			else:
				pos = -1
		if cp[0] == cp[1]:
			continue
		if pos == 1 and cp[0] > cp[1]:
			ans += 1
			pos = -1
		elif pos == -1 and cp[0] < cp[1]:
			ans += 1
			pos = 1
	print(ans)
tc = 1
for _ in range(tc):
	main()


n = int(input())
s = input()
cnt = 0
arr_x = []
arr_y = []
arr_x.append(0)
arr_y.append(0)
for i in range(n):
	arr_x.append(0)
	arr_y.append(0)
	if s[i] == 'U':
		arr_y[i + 1] = arr_y[i] + 1
		arr_x[i + 1] = arr_x[i]
	elif s[i] == 'R':
		arr_x[i + 1] = arr_x[i] + 1
		arr_y[i + 1] = arr_y[i]
for i in range(1, n):
	if arr_x[i] == arr_y[i]:
		if arr_x[i - 1] < arr_y[i - 1] and arr_x[i + 1] > arr_y[i + 1]:
			cnt += 1
		elif arr_x[i - 1] > arr_y[i - 1] and arr_x[i + 1] < arr_y[i + 1]:
			cnt += 1
print(cnt)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def quad(tup):
	(x, y) = tup
	if x > y:
		return -1
	if y > x:
		return 1
	else:
		return 0

def solve():
	n = int(inp())
	s = inp()
	cur = (0, 0)
	ar = []
	c = 0
	for i in range(n):
		if s[i] == 'U':
			if cur[0] + 1 != cur[1]:
				ar.append((cur[0] + 1, cur[1]))
			cur = (cur[0] + 1, cur[1])
		else:
			if cur[0] != cur[1] + 1:
				ar.append((cur[0], cur[1] + 1))
			cur = (cur[0], cur[1] + 1)
	for i in range(1, len(ar)):
		if quad(ar[i]) + quad(ar[i - 1]) == 0:
			c += 1
	print(c)
solve()


n = int(input())
s = input()
start = [0, 0]
f = 0
for i in range(n):
	if s[i] == 'R':
		start[0] += 1
		if i == 0:
			p = -1
	else:
		start[1] += 1
		if i == 0:
			p = 1
	if start[1] - start[0] > 0:
		if p == -1:
			f += 1
			p = 1
	elif start[1] - start[0] < 0:
		if p == 1:
			f += 1
			p = -1
print(f)


n = int(input())
s = input()
c = 0
x = 0
y = 0
for i in range(len(s) - 1):
	if s[i] == 'U':
		y += 1
	if s[i] == 'R':
		x += 1
	if x == y:
		if s[i] == s[i + 1]:
			c += 1
print(c)


n = int(input())
s = input()
(x, y) = (0, 0)
d = '?'
cnt = 0
for i in s:
	if i == 'R':
		x += 1
	else:
		y += 1
	if d != '?':
		if d == i:
			cnt += 1
		d = '?'
	if x == y:
		d = i
print(cnt)


n = int(input())
s = input()
curr = -1
currx = 0
curry = 0
ans = 0
for i in s:
	if i == 'U':
		curry += 1
	if i == 'R':
		currx += 1
	if currx > curry:
		if curr != 0:
			ans += 1
			curr = 0
	if curry > currx:
		if curr != 1:
			ans += 1
			curr = 1
print(ans - 1)


from itertools import tee
n = int(input())
S = input()

def pairwise(seq):
	(i1, i2) = tee(seq)
	next(i2)
	return zip(i1, i2)
(x, y) = (1, 0) if S[0] == 'R' else (0, 1)
cost = 0
for (prev, cur) in pairwise(S):
	if prev == cur and x == y:
		cost += 1
	if cur == 'R':
		x += 1
	else:
		y += 1
print(cost)


changes = int(input())
moves = input()
currside = 'R'
movesneeded = 0
payment = 0
if moves[0] == 'U':
	currside = 'U'
for i in range(changes):
	if moves[i] == currside:
		movesneeded = movesneeded + 1
	else:
		movesneeded = movesneeded - 1
		if movesneeded == -1:
			if currside == 'U':
				currside = 'R'
			else:
				currside = 'U'
			movesneeded = 1
			payment = payment + 1
print(payment)


n = int(input())
s = input()
x = 0
y = 0
c = 0
side = 2
lastside = 2
for i in s:
	prevx = x
	prevy = y
	if i == 'U':
		y += 1
	if i == 'R':
		x += 1
	lastside = side
	if x > y:
		side = 0
	elif x < y:
		side = 1
	if lastside != side and lastside != 2:
		c += 1
print(c)


n = int(input())
s = input()
cu = 0
cr = 0
ans = 0
for i in range(n):
	if s[i] == 'U':
		cu += 1
	else:
		cr += 1
	if cu == cr and i != n - 1 and (s[i] == s[i + 1]):
		ans += 1
print(ans)


n = int(input())
l1 = list(input())
x = 0
y = 0
l2 = []
for i in range(len(l1)):
	if l1[i] == 'U':
		y += 1
	else:
		x += 1
	if x - y < 0:
		l2.append(-1)
	elif x - y > 0:
		l2.append(1)
	else:
		l2.append(0)
c = 0
for i in range(len(l2)):
	if l2[i] == 0:
		if i == 0 or i == len(l2) - 1:
			pass
		elif l2[i - 1] == -1 and l2[i + 1] == 1 or (l2[i - 1] == 1 and l2[i + 1] == -1):
			c += 1
print(c)


n = int(input())
s = input()
prev = [0, 0]
ans = 0
for _ in range(n - 1):
	curr = prev[:]
	if s[_] == 'R':
		curr[0] += 1
	else:
		curr[1] += 1
	if curr[0] == curr[1]:
		if s[_] == 'R' and s[_ + 1] == 'R' or (s[_] == 'U' and s[_ + 1] == 'U'):
			ans += 1
	prev = curr
print(ans)


def coins(n, s):
	no_coins = 0
	state = s[0]
	count = 0
	for i in range(n):
		if count == 0 and state != s[i]:
			no_coins += 1
			state = s[i]
		if state == s[i]:
			count += 1
		else:
			count -= 1
	return no_coins
n = int(input())
s = input()
print(coins(n, s))


n = int(input())
s = input()
q = 0
if n == 1:
	print(0)
else:
	if s[0] == 'U':
		t = 1
		p = 1
	else:
		t = -1
		p = -1
	for i in range(1, n):
		if s[i] == 'U':
			t += 1
			if t * p < 0:
				p = t
				q += 1
		else:
			t -= 1
			if t * p < 0:
				p = t
				q += 1
	print(q)


n = int(input())
s = input()
x = 0
y = 0
where = -1
cnt = 0
for q in range(len(s) - 1):
	if s[q] == 'U':
		y = y + 1
	elif s[q] == 'R':
		x = x + 1
	if x != y:
		where = x > y
	if x == y and (s[q + 1] == 'U' and where or (s[q + 1] == 'R' and (not where))):
		cnt = cnt + 1
print(cnt)


import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
	return int(input())

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

def rl():
	return list(map(int, input().split()))
n = r()
a = input()
(x, y) = (0, 0)
if a[0] == 'U':
	y += 1
else:
	x += 1
now = 'up' if a[0] == 'U' else 'down'
res = 0
for i in range(1, n):
	if a[i] == 'U':
		y += 1
	else:
		x += 1
	if y > x:
		temp = 'up'
	elif x > y:
		temp = 'down'
	else:
		temp = now
	if now == 'up' and temp == 'down' or (now == 'down' and temp == 'up'):
		res += 1
	now = temp
print(res)


input()
last = 'S'
l = res = x = y = 1
for cur in input():
	if x == y and cur == last:
		res += 1
	last = cur
	if cur == 'U':
		x += 1
	else:
		y += 1
if res == 1:
	print('0')
else:
	print(res - 1)


n = input()
s = input()
isUp = True if s[0] == 'U' else False
(x, y, count) = (0, 0, 0)
for idx in range(len(s) - 1):
	if s[idx] == 'U':
		y += 1
	elif s[idx] == 'R':
		x += 1
	if x == y and s[idx] == s[idx + 1]:
		count += 1
print(count)


N = int(input())
moves = input()
(pos_x, pos_y) = (0, 0)
coins = 0
kingdom = None
for m in moves:
	if m == 'R':
		pos_x += 1
	else:
		pos_y += 1
	if pos_x < pos_y:
		if kingdom == 'lower':
			coins += 1
		kingdom = 'upper'
	if pos_x > pos_y:
		if kingdom == 'upper':
			coins += 1
		kingdom = 'lower'
print(coins)


def ii():
	return int(input())

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

def li():
	return list(mi())
n = ii()
S = input().strip()
x = y = c = 0
k = None
for s in S:
	if s == 'U':
		y += 1
	else:
		x += 1
	if y > x:
		if k == 'D':
			c += 1
		k = 'U'
	elif x > y:
		if k == 'U':
			c += 1
		k = 'D'
print(c)


import math
n = int(input())
s = input()
which = 0
bill = 0
(x, y) = (0, 0)
if s[0] == 'U':
	y += 1
	which = 1
else:
	x += 1
	which = 2
for i in range(1, n):
	if s[i] == 'U':
		y += 1
		if x > 0 and math.ceil(y / x) > 1 and (which == 2):
			bill += 1
			which = 1
	else:
		x += 1
		if y > 0 and y // x == 0 and (which == 1):
			bill += 1
			which = 2
print(bill)


n = int(input())
s = input()
gate = False
(ans, countu, countr) = (0, 0, 0)
for i in range(n):
	if countu == countr and s[i - 1] == s[i] and (i > 0):
		(ans, gate) = (ans + 1, False)
	if s[i] == 'U':
		countu += 1
	if s[i] == 'R':
		countr += 1
print(ans)


n = int(input())
a = str(input())
ser = 0
x = 0
y = 0
if a[0] == 'U':
	y = y + 1
else:
	x = x + 1
for i in range(1, n):
	if a[i] == 'U' and x == y and (a[i - 1] == 'U'):
		ser = ser + 1
		y = y + 1
	elif a[i] == 'R' and x == y and (a[i - 1] == 'R'):
		ser = ser + 1
		x = x + 1
	elif a[i] == 'R':
		x = x + 1
	else:
		y = y + 1
print(ser)


n = int(input())
s = input()
(a, b, c) = (0, 0, 0)
for i in range(len(s)):
	if s[i] == 'U':
		b = b + 1
	else:
		a = a + 1
	if a == b and i != len(s) - 1:
		if s[i] == s[i + 1]:
			c = c + 1
print(c)


n = int(input())
s = input()
(x, y) = (0, 0)
r = 0
k = None
for c in s:
	t = x == y
	if t:
		(x, y) = (0, 0)
		t = True
	if c == 'U':
		y += 1
	elif c == 'R':
		x += 1
	if t:
		v = (x == 1, y == 0)
		if k != None and k != v:
			r += 1
		k = v
print(r)


n = int(input())
s = input()
x = y = a = 0
p = 2
for c in s:
	if c == 'U':
		y += 1
	else:
		x += 1
	if y != x:
		np = y > x
		if np != p < 2:
			a += 1
		p = np
print(a)


n = int(input())
moves = input()
x = 0
y = 0
coins = 0
prev = (0, 0)
bit = 0
for i in moves:
	if x == y and x != 0 and (y != 0):
		coins += 1
		bit = x
	else:
		prev = (x, y)
	if i == 'U':
		y += 1
	elif i == 'R':
		x += 1
	if bit != 0:
		if x > bit and prev[0] < bit or (y > bit and prev[1] < bit):
			bit = 0
			continue
		elif x < bit and prev[0] > bit or (y > bit and prev[1] < bit):
			bit = 0
			continue
		elif x < bit and prev[0] > bit or (y < bit and prev[1] > bit):
			bit = 0
			continue
		elif x > bit and prev[0] < bit or (y < bit and prev[1] > bit):
			bit = 0
			continue
		else:
			coins -= 1
		bit = 0
print(coins)


input()
s = input()
p = [0, 0]
res = 0
if s[0] == 'R':
	p[0] += 1
if s[0] == 'U':
	p[1] += 1
f = p[0] - p[1]
for x in s[1:]:
	if x == 'R':
		p[0] += 1
	if x == 'U':
		p[1] += 1
	if f * (p[0] - p[1]) < 0:
		f = p[0] - p[1]
		res += 1
print(res)


def helper(a, b):
	return a - b
u = 0
x = 0
n = int(input())
r = input()
arr = [i for i in r]
arr1 = [0, 0]
count = 0
for i in range(len(arr)):
	if arr[i] == 'U':
		u += 1
	if arr[i] == 'R':
		x += 1
	if i < len(arr) - 1:
		if arr[i] == arr[i + 1] and u == x:
			count += 1
print(count)


n = int(input())
piece = 0
if n < 3:
	print(0)
else:
	s = input()
	p1 = p2 = p3 = [0, 0]
	if s[0] == 'U':
		p2 = [p1[0], p1[1] + 1]
	else:
		p2 = [p1[0] + 1, p1[1]]
	if s[1] == 'U':
		p3 = [p2[0], p2[1] + 1]
	else:
		p3 = [p2[0] + 1, p2[1]]
	i = 2
	while i <= n:
		if p1[0] == p2[0] and p1[0] == p3[0] and (p2[0] == p2[1]) or (p1[1] == p2[1] and p1[1] == p3[1] and (p2[0] == p2[1])):
			piece += 1
		p1 = [t for t in p2]
		p2 = [t for t in p3]
		if i < n and s[i] == 'U':
			p3 = [p3[0], p3[1] + 1]
		else:
			p3 = [p3[0] + 1, p3[1]]
		i += 1
	print(piece)


num_moves = int(input())
moves = list(input())
current_pos = (0, 0)
count = 0
for (i, m) in enumerate(moves):
	if i < len(moves) - 1:
		if m == 'R':
			new_pos = (current_pos[0] + 1, current_pos[1])
			current_pos = new_pos
			if current_pos[0] == current_pos[1]:
				if m == moves[i + 1]:
					count += 1
		if m == 'U':
			new_pos = (current_pos[0], current_pos[1] + 1)
			current_pos = new_pos
			if current_pos[0] == current_pos[1]:
				if m == moves[i + 1]:
					count += 1
print(count)


t = int(input())
s = input()
x = y = c = 0
x1 = y1 = 0
for i in range(t):
	if s[i] == 'U':
		y1 += 1
	elif s[i] == 'R':
		x1 += 1
	if x1 == y1:
		if i + 1 < t and s[i + 1] == 'U':
			y2 = y1 + 1
			x2 = x1
			if x == x1 == x2 and y + 2 == y1 + 1 == y2:
				c += 1
			elif y == y1 == y2 and x + 2 == x1 + 1 == x2:
				c += 1
		elif i + 1 < t and s[i + 1] == 'R':
			x2 = x1 + 1
			y2 = y1
			if x == x1 == x2 and y + 2 == y1 + 1 == y2:
				c += 1
			elif y == y1 == y2 and x + 2 == x1 + 1 == x2:
				c += 1
	x = x1
	y = y1
print(c)


n = int(input())
a = input()
(ans, counter, mcounter) = (0, 0, 1 if a[0] == 'U' else -1)
for i in a:
	if i == 'U':
		counter += 1
	else:
		counter -= 1
	if counter == -mcounter:
		mcounter = counter
		ans += 1
print(ans)


n = int(input())
s = input()
a = list(s)
count = -1
x = [0, 0]
sign = 'neutral'

def check(x):
	return x[0] - x[1]

def signChange(x):
	global sign
	t = check(x)
	if t > 0:
		t = 'positive'
	elif t == 0:
		return False
	else:
		t = 'negative'
	if t == sign:
		return False
	else:
		sign = t
		return True
for i in range(n):
	if a[i] == 'R':
		x[0] += 1
		if signChange(x):
			count += 1
	else:
		x[1] += 1
		if signChange(x):
			count += 1
print(count)


s = int(input())
stroka = str(input())
X = 0
Y = 0
M = 0
PY = 0
PX = 0
for i in range(s):
	if stroka[i] == 'U':
		PY = Y
		PX = X
		Y += 1
	else:
		PX = X
		PY = Y
		X += 1
	if stroka[i] == stroka[i - 1] and i >= 1 and (PX == PY):
		M += 1
print(M)


n = int(input())
s = input()
current = [0, 0]
currentKingdom = 0
res = 0
for c in s:
	if c == 'U':
		current[0] += 1
	elif c == 'R':
		current[1] += 1
	if current[0] > current[1] and currentKingdom != 1:
		currentKingdom = 1
		res += 1
	elif current[0] < current[1] and currentKingdom != 2:
		currentKingdom = 2
		res += 1
print(res - 1)


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
sys.setrecursionlimit(300000)

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class BinaryTrie:

	class Node:

		def __init__(self, bit: bool=False):
			self.bit = bit
			self.children = []
			self.count = 0
			self.counter = 1

	def __init__(self, size):
		self.root = BinaryTrie.Node()
		self.size = size

	def convert(self, key):
		bits = []
		if isinstance(key, int):
			key = bin(key)[2:]
		if isinstance(key, str):
			for i in range(self.size - len(key)):
				bits += [False]
			for i in key:
				if i == '0':
					bits += [False]
				else:
					bits += [True]
		else:
			return list(key)
		return bits

	def add(self, key):
		node = self.root
		bits = self.convert(key)
		for bit in bits:
			found_in_child = False
			for child in node.children:
				if child.bit == bit:
					child.counter += 1
					node = child
					found_in_child = True
					break
			if not found_in_child:
				new_node = BinaryTrie.Node(bit)
				node.children.append(new_node)
				node = new_node
		node.count += 1

	def remove(self, key):
		node = self.root
		bits = self.convert(key)
		nodelist = [node]
		for bit in bits:
			for child in node.children:
				if child.bit == bit:
					node = child
					node.counter -= 1
					nodelist.append(node)
					break
		node.count -= 1
		if not node.children and (not node.count):
			for i in range(len(nodelist) - 2, -1, -1):
				nodelist[i].children.remove(nodelist[i + 1])
				if nodelist[i].children or nodelist[i].count:
					break

	def query(self, prefix, root=None):
		if not root:
			root = self.root
		node = root
		if not root.children:
			return 0
		for bit in prefix:
			bit_not_found = True
			for child in node.children:
				if child.bit == bit:
					bit_not_found = False
					node = child
					break
			if bit_not_found:
				return 0
		return node

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.data = 0
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key, val):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
			pCrawl.data += val
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		c = 0
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return c
			c += 1
			pCrawl = pCrawl.children[index]
		return c

	def present(self, key):
		ans = 0
		pCrawl = self.root
		length = len(key)
		c = 0
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
			ans += pCrawl.data
		if pCrawl != None:
			return ans
		return -1
n = int(input())
s = input()
w = [0, 0]
ans = 0
t = 0
for i in s:
	if i == 'U':
		w[0] += 1
	else:
		w[1] += 1
	if t != 0:
		if t == -1 and w[0] > w[1]:
			ans += 1
		elif t == 1 and w[0] < w[1]:
			ans += 1
	if w[0] < w[1]:
		t = -1
	elif w[0] > w[1]:
		t = 1
	else:
		t *= 1
print(ans)


totalMoves = int(input())
moves = list(input())
(x, y) = (0, 0)
coins = 0

def kingdom(x, y, prev):
	if y > x:
		return 0
	elif x > y:
		return 1
	return prev
if moves[0] == 'R':
	x += 1
else:
	y += 1
currentKingdom = kingdom(x, y, -1)
for i in range(1, totalMoves):
	previousKingdom = currentKingdom
	if moves[i] == 'R':
		x += 1
	else:
		y += 1
	currentKingdom = kingdom(x, y, currentKingdom)
	if previousKingdom != currentKingdom:
		coins += 1
print(coins)


Input = lambda : map(int, input().split())
n = int(input())
s = input()
Ans = 0
UP = True
Down = False
x = 0
y = 1
if s[0] == 'R':
	UP = False
	Down = True
	x = 1
	y = 0
for i in range(1, n):
	if s[i] == 'U':
		y += 1
		if Down:
			if y > x:
				Ans += 1
				Down = False
				UP = True
		elif y < x:
			Ans += 1
			UP = False
			Down = True
	else:
		x += 1
		if Down:
			if y > x:
				Ans += 1
				Down = False
				UP = True
		elif y < x:
			Ans += 1
			UP = False
			Down = True
print(Ans)


n = int(input())
res = -1
s = input()
(x, y) = (0, 0)
where = 'first'
for i in s:
	if i == 'R':
		x += 1
	else:
		y += 1
	if x > y and where != 'down':
		res += 1
		where = 'down'
	elif x < y and where != 'up':
		res += 1
		where = 'up'
print(res)


n = int(input())
s = input()
r = 0
status = 0
c = 0
for i in s:
	if i == 'U':
		r += 1
	else:
		r -= 1
	if r > 0:
		if status == 1:
			c += 1
		status = 2
	if r < 0:
		if status == 2:
			c += 1
		status = 1
print(c)


def check(x1, y1, x2, y2):
	if x1 == y1 == 0:
		return 0
	if x1 < y1 and x2 > y2 or (x1 > y1 and x2 < y2):
		return 1
	return 0
n = int(input())
px = 0
py = 0
ppx = 0
ppy = 0
x = 0
y = 0
ans = 0
move = input().strip()
for go in move:
	ppy = py
	ppx = px
	py = y
	px = x
	if go == 'U':
		y += 1
	else:
		x += 1
	ans += check(ppx, ppy, x, y)
print(ans)


n = int(input())
s = input()
(x, y) = (0, 0)
c = 0
g = -1
z = 0
for i in s:
	if i == 'U':
		y += 1
		if z == 1 and g != -1:
			c += 1
		g = -1
	if i == 'R':
		x += 1
		if z == 2 and g != -1:
			c += 1
		g = -1
	if x > y:
		z = 1
	if y > x:
		z = 2
	if x == y and x != 0:
		if z == 1:
			g = 0
		elif z == 2:
			g = 1
print(c)


n = int(input())
string = input()
num = 0
x = 0
y = 0
for i in range(n - 1):
	if string[i] == 'U':
		y = y + 1
	else:
		x = x + 1
	if x == y and string[i] == string[i + 1]:
		num = num + 1
print(num)


n = int(input())
s = input().strip()
count = 0
x = 0
y = 0
for i in range(len(s)):
	if s[i] == 'U':
		y += 1
	else:
		x += 1
	if x == y:
		if i < n - 1 and s[i] == s[i + 1]:
			count += 1
print(count)


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

def solve():
	n = int(input())
	s = input()
	ans = 0
	d = 0
	p = 0
	for c in s:
		if c == 'U':
			d += 1
		else:
			d -= 1
		if d > 0:
			if p == 1:
				ans += 1
			p = 2
		if d < 0:
			if p == 2:
				ans += 1
			p = 1
	print(ans)
solve()


n = int(input())
s = list(input())
ret = 0
if s[0] == 'U':
	count_r = 0
	count_u = 1
else:
	count_r = 1
	count_u = 0
for i in range(1, n):
	if count_r != count_u:
		if s[i] == 'R':
			count_r += 1
		if s[i] == 'U':
			count_u += 1
	else:
		if s[i] == 'R':
			count_r += 1
			if s[i - 1] == 'R':
				ret += 1
		if s[i] == 'U':
			count_u += 1
			if s[i - 1] == 'U':
				ret += 1
print(ret)


n = int(input())
x = 0
y = 0
s = input()
i = 1
m = 0
if s[0] == 'U':
	y += 1
else:
	x += 1
while i < n:
	if s[i] == 'U':
		y += 1
		if x == y:
			if i != n - 1:
				if s[i + 1] == 'U':
					m += 1
	else:
		x += 1
		if x == y:
			if i != n - 1:
				if s[i + 1] == 'R':
					m += 1
	i += 1
print(m)


n = int(input())
s = input()
d = dict()
d['U'] = [0, 1]
d['R'] = [1, 0]
cur = 1 if s[0] == 'U' else 2
(x, y) = (0, 0)
ans = 0
for i in s:
	x += d[i][0]
	y += d[i][1]
	if y < x and cur == 1:
		cur = 2
		ans += 1
	elif y > x and cur == 2:
		cur = 1
		ans += 1
print(ans)


n = int(input())
s = input()
s = list(s)
x = 0
y = 0
ans = 0
if s[0] == 'U':
	prev_kingdom = 2
	y = y + 1
else:
	prev_kingdom = 1
	x = x + 1
if n == 1:
	print(0)
else:
	for i in range(1, n):
		if s[i] == 'U':
			y = y + 1
		else:
			x = x + 1
		if x > y:
			pres_kingdom = 1
		elif x < y:
			pres_kingdom = 2
		else:
			pres_kingdom = prev_kingdom
		if pres_kingdom != prev_kingdom:
			ans += 1
			prev_kingdom = pres_kingdom
	print(ans)


n = input()
s = input()
a = p = c = 0
for i in s:
	if 'U' == i:
		c += 1
	else:
		c -= 1
	a += p * c < 0
	if c:
		p = c
print(a)


n = int(input())
s = input()
(ans, a, b) = (0, 0, 0)
for i in range(n - 1):
	if s[i] == 'R':
		a += 1
	if s[i] == 'U':
		b += 1
	if a == b:
		(a, b) = (0, 0)
		if s[i + 1] == s[i]:
			ans += 1
print(ans)


import math
n = int(input())
ans = 0
nr = 0
nu = 0
side = 0
mm = list(input())
fm = mm[0]
mm = mm[1:]
if fm == 'U':
	side = 1
	nu = 1
else:
	side = -1
	nr = 1
for m in mm:
	if nu == nr:
		if m == 'U' and side == -1:
			ans += 1
			side = 1
		elif m == 'R' and side == 1:
			ans += 1
			side = -1
	if m == 'U':
		nu += 1
	else:
		nr += 1
print(ans)


n = int(input())
s = input()
x = 0
t = 0
y = 0
if s[0] == 'R':
	fl = False
else:
	fl = True
for i in range(n):
	if s[i] == 'R':
		x += 1
	else:
		y += 1
	if fl == False and y > x:
		fl = True
		t += 1
	elif fl == True and y < x:
		fl = False
		t += 1
print(t)


input()
walk = input()
ans = 0
coord = [0, 0]
king1 = False
if walk[0] == 'U':
	coord[1] = 1
	king1 = True
else:
	coord[0] = 1
for i in walk[1:]:
	if i == 'U':
		coord[1] += 1
	else:
		coord[0] += 1
	if coord[1] > coord[0] and (not king1):
		ans += 1
		king1 = True
	elif coord[1] < coord[0] and king1:
		ans += 1
		king1 = False
print(ans)


n = int(input())
s = input()
current = ''
(cntR, cntU, ans) = (0, 0, 0)
for move in s:
	if move == 'R':
		cntR += 1
	else:
		cntU += 1
	if cntR > cntU:
		if current == 'U':
			ans += 1
		current = 'R'
	elif cntU > cntR:
		if current == 'R':
			ans += 1
		current = 'U'
print(ans)


n = int(input())
s = input()
count = 0
mat = [[0 for x in range(2)] for y in range(len(s) + 1)]
for i in range(0, len(s)):
	if s[i] == 'U':
		mat[i + 1][0] = mat[i][0]
		mat[i + 1][1] = mat[i][1] + 1
	if s[i] == 'R':
		mat[i + 1][0] = mat[i][0] + 1
		mat[i + 1][1] = mat[i][1]
for i in range(1, len(s)):
	if mat[i][0] == mat[i][1]:
		if (mat[i - 1][0] - mat[i + 1][0] == 0) | (mat[i - 1][1] - mat[i + 1][1] == 0):
			count += 1
print(count)


n = int(input())
steps = list(map(str, input()))
total = 0

def getSide(position):
	if position['y'] > position['x']:
		return 1
	elif position['y'] < position['x']:
		return -1
	else:
		return 0
side = {'cur': 0, 'prev': 0, 'pra': 0}

def shuldPay(position):
	global side
	if side['prev'] == 0 and ((side['cur'] == 1 or side['cur'] == -1) and side['pra'] != side['cur']):
		return True
	return False
cur_position = {'y': 0, 'x': 0}
cnt = 0

def makeStep(direction):
	global side
	global cur_position
	global total
	global cnt
	if direction == 'U':
		cur_position['y'] += 1
	elif direction == 'R':
		cur_position['x'] += 1
	side['pra'] = side['prev']
	side['prev'] = side['cur']
	side['cur'] = getSide(cur_position)
	if cnt > 0:
		if shuldPay(cur_position):
			total += 1
	cnt += 1
for i in steps:
	makeStep(i)
print(total)


t = int(input())
arr = input()
arr = list(arr)
ans = 0
x = 0
y = 0
upper = False
lower = False
edge = False
brr = [[0, 0]]
for i in range(len(arr)):
	if arr[i] == 'U':
		y += 1
		brr.append([x, y])
		if edge == True and lower == True:
			edge = False
		if x < y:
			upper = True
			edge = False
		elif x == y:
			edge = True
		else:
			lower = True
			edge = False
	elif arr[i] == 'R':
		x += 1
		brr.append([x, y])
		if edge == True and upper == True:
			edge = False
		if x < y:
			upper = True
			edge = False
		elif x == y:
			edge = True
		else:
			lower = True
			edge = False
for i in range(1, len(brr) - 1):
	if brr[i][0] == brr[i][1]:
		if brr[i - 1][0] == brr[i + 1][0]:
			ans += 1
		elif brr[i - 1][1] == brr[i + 1][1]:
			ans += 1
print(ans)


n = int(input())
if n == 1:
	print('0')
	exit()
s = input()
(r, u, x, flag) = (0, 0, 0, -1)
for i in s:
	if i == 'R':
		r += 1
	else:
		u += 1
	if r > u and flag != 1:
		x += 1
		flag = 1
	elif r < u and flag != 0:
		x += 1
		flag = 0
print(x - 1)


t = int(input())
s = input()
x = 0
y = 0
c = 0
k = 0
if s[0] == 'U':
	k = 1
	for i in range(0, t):
		if s[i] == 'U':
			y = y + 1
			if y - x == 1 and k == -1:
				c += 1
				k *= -1
		if s[i] == 'R':
			x = x + 1
			if x - y == 1 and k == 1:
				c += 1
				k *= -1
if s[0] == 'R':
	k = 1
	for i in range(0, t):
		if s[i] == 'U':
			y = y + 1
			if y - x == 1 and k == 1:
				c += 1
				k *= -1
		if s[i] == 'R':
			x = x + 1
			if x - y == 1 and k == -1:
				c += 1
				k *= -1
print(c)


from sys import stdin
move_num = stdin.readline()
moves = stdin.readline().strip()
position = [0, 0]
cost = 0
side = -1
for move in moves:
	if move == 'R':
		position[0] += 1
	if move == 'U':
		position[1] += 1
	if side == -1:
		if position[0] < position[1]:
			side = 0
		else:
			side = 1
	elif position[0] < position[1] and side == 1:
		side = 0
		cost += 1
	elif position[1] < position[0] and side == 0:
		side = 1
		cost += 1
print(cost)


import sys
n = int(input())
moves = input()
pt = (0, 0)
d = {'U': (0, 1), 'R': (1, 0)}
curr_country = (0, 0)
count = 0
for move in moves:
	(curr_x, curr_y) = pt
	(del_x, del_y) = d[move]
	pt = (curr_x + del_x, curr_y + del_y)
	if pt[1] == pt[0]:
		continue
	elif pt[1] > pt[0]:
		new_country = (0, 1)
	else:
		new_country = (1, 0)
	if curr_country == (0, 0):
		curr_country = new_country
	if curr_country != new_country:
		curr_country = new_country
		count += 1
print(count)


x = 0
y = 0
kostnad = 0
n = int(input())
S = input('')
i = 0
while i < n:
	if S[i] == 'R':
		x += 1
	else:
		y += 1
	try:
		if x == y and S[i + 1] == S[i]:
			kostnad += 1
	except IndexError:
		pass
	i += 1
print(kostnad)


import sys
import math
import itertools
import collections

def ii():
	return int(input())

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

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
n = ii()
s = input()
ans = r = u = 0
for i in range(n - 1):
	if s[i] == 'R':
		r += 1
	else:
		u += 1
	if s[i] == s[i + 1] and r == u:
		ans += 1
print(ans)


def check(x, y, x1, y1):
	t = x - y
	t *= x1 - y1
	if t < 0:
		return True
	else:
		return False
n = input()
n = int(n)
a = input()
x = y = ans = 0
xb = []
yb = []
for i in range(0, n):
	if a[i] == 'U':
		y += 1
	else:
		x += 1
	xb.append(x)
	yb.append(y)
for i in range(0, n):
	if xb[i] == yb[i] and i - 1 >= 0 and (i + 1 <= n - 1):
		if check(xb[i - 1], yb[i - 1], xb[i + 1], yb[i + 1]) == True:
			ans += 1
print(ans)


ucounter = 0
rcounter = 0
indicator = 0
price = 0
length = input()
sequence = input()
for x in sequence:
	if indicator == 1:
		indicator = 0
		if x == 'R':
			price += 1
	elif indicator == 2:
		indicator = 0
		if x == 'U':
			price += 1
	if x == 'R':
		rcounter += 1
	else:
		ucounter += 1
	if ucounter == rcounter:
		if x == 'R':
			indicator = 1
		else:
			indicator = 2
print(price)


a = int(input())
b = input()
b = [i for i in b]
c = 0
d = 0
e = 0
try:
	for i in range(a):
		if b[i] == 'R':
			c += 1
		else:
			d += 1
		if c == d and b[i] == b[i + 1]:
			e += 1
except IndexError:
	pass
print(e)


n = int(input())
c = input()
flag_u = 0
flag_d = 0
(x, y) = (0, 0)
tot = 0
if c[0] == 'U':
	flag_u = 1
	y += 1
else:
	flag_d = 1
	x += 1
for i in range(1, len(c) - 1):
	if c[i] == 'U':
		y += 1
	else:
		x += 1
	if x == y:
		if c[i + 1] == 'R':
			if flag_u == 1:
				flag_d = 1
				flag_u = 0
				tot += 1
			else:
				continue
		elif flag_u == 1:
			continue
		else:
			flag_u = 1
			flag_d = 0
			tot += 1
print(tot)


n = int(input())
direc = input().strip()
posx = 0
posy = 0
coin = 0
flag = 0
if direc[0] == 'R':
	flag = 1
else:
	flag = 0
for i in direc:
	if i == 'R':
		posx += 1
	else:
		posy += 1
	if flag == 1:
		if posy > posx:
			coin += 1
			flag = 0
	elif posy < posx:
		coin += 1
		flag = 1
print(coin)


def coincount(n, S):
	f = 0
	x = y = 0
	i = 0
	cross = [0, 0, 0]
	count = 0
	while i < n:
		cross[0] = cross[1]
		cross[1] = cross[2]
		cur_m = S[i]
		if cur_m == 'U':
			y += 1
		elif cur_m == 'R':
			x += 1
		if x > y:
			f = -1
		elif x < y:
			f = 1
		else:
			f = 0
		cross[2] = f
		if cross == [-1, 0, 1] or cross == [1, 0, -1]:
			count += 1
		i += 1
	return count
n = input()
n = int(n)
S = input()
print(coincount(n, S))


a = int(input())
l = [b for b in input()]
r = [None, None, None]
c = 0
s = 0
for i in range(a):
	if l[i] == 'U':
		c += 1
	else:
		c -= 1
	r[i % 3] = c
	if i > 1 and sum(r) == 0:
		s += 1
print(s)


n = int(input())
s = input()
x = 0
y = 0
lst = []
for i in s:
	if i == 'U':
		x += 1
		if x > y:
			lst.append(1)
		elif y > x:
			lst.append(2)
	elif i == 'R':
		y += 1
		if x > y:
			lst.append(1)
		elif y > x:
			lst.append(2)
j = 0
for i in range(1, len(lst)):
	if lst[i] != lst[i - 1]:
		j += 1
print(j)


_ = input()
a = input()
x = 0
y = 0
t = 0
prev = 0
now = 0
for i in a:
	if i == 'U':
		y += 1
	else:
		x += 1
	if x > y:
		now = 1
	if x < y:
		now = 2
	if now != prev:
		t += 1
	prev = now
print(t - 1)


a = int(input())
b = input()
up = 0
right = 0
coin = 0
d = 1
for i in range(a):
	if b[i] == 'U':
		up += 1
	if b[i] == 'R':
		right += 1
	if up == right:
		if d == a:
			break
		elif b[d] == b[i]:
			coin += 1
	d += 1
print(coin)


n = int(input())
s = input()
v = [0] * n
(x, y) = (0, 0)
for i in range(len(s)):
	if s[i] == 'U':
		y += 1
	else:
		x += 1
	if x > y:
		v[i] = -1
	elif x < y:
		v[i] = 1
r = 0
for i in range(1, len(s) - 1):
	if v[i] == 0 and v[i - 1] != v[i + 1]:
		r += 1
print(r)


x = int(input(''))
ar = list(str(input('')))
money = 0
st = [ar[0]]
ar = ar[1:]
for i in range(len(ar)):
	if st == [] or st[-1] == ar[i]:
		st.append(ar[i])
		if len(st) == 1 and ar[i] == ar[i - 1]:
			money += 1
	else:
		st.pop()
print(money)


def fun(s):
	if s == 'R':
		return 1
	else:
		return 0
m = input()
n = input()
n = str(n)
x = 0
y = 0
if n[0] == 'R':
	ctr = 1
if n[0] == 'U':
	ctr = 0
count = 0
for i in n:
	tt = fun(i)
	if tt == 0:
		x += 1
	else:
		y += 1
	if ctr == 1 and y > x:
		count += 1
		ctr = 0
	if ctr == 0 and y < x:
		count += 1
		ctr = 1
print(count - 1)


input()
x = y = p = 0
for i in input():
	if x == y != 0 and k == i:
		p += 1
	if i == 'U':
		x += 1
	else:
		y += 1
	k = i
print(p)


def solve(a, n):
	ans = 0
	p1x = 0
	p1y = 0
	p0x = 0
	p0y = 0
	px = a[0] == 'R'
	py = a[0] == 'U'
	for i in range(1, n):
		p1x = p0x
		p1y = p0y
		p0x = px
		p0y = py
		px += a[i] == 'R'
		py += a[i] == 'U'
		if p0x == p0y:
			if px > py and p1x < p1y:
				ans += 1
			elif px < py and p1x > p1y:
				ans += 1
	return ans
n = int(input())
s = input()
print(solve(s, n))


n = int(input())
s = input()
cl = [(0, 0)]
x = 0
y = 0
count = 0
st = 0
for c in s:
	if c == 'U':
		y += 1
	else:
		x += 1
	cl.append((x, y))
for i in range(n):
	if cl[i] == (0, 0):
		if cl[i + 1][0] > cl[i + 1][1]:
			st = 2
		else:
			st = 1
	elif cl[i][0] == cl[i][1]:
		if cl[i + 1][0] > cl[i + 1][1]:
			if st != 2:
				count += 1
				st = 2
		elif st != 1:
			count += 1
			st = 1
print(count)


n = int(input())
s = str(input())
x = 0
y = 0
previous = 0
ans = 0
for i in range(n):
	if s[i:i + 1] == 'U':
		y += 1
	elif s[i:i + 1] == 'R':
		x += 1
	if i > 0:
		if previous == 1:
			if y > x and s[i - 1:i] == 'U':
				ans += 1
			if y < x and s[i - 1:i] == 'R':
				ans += 1
	if x == y:
		previous = 1
	else:
		previous = 0
print(ans)


n = int(input())
s = str(input())
x = 0
y = 0
coin = 0
if s[0] == 'R':
	x += 1
elif s[0] == 'U':
	y += 1
if x - y >= 0:
	c = 0
else:
	c = 1
for i in range(1, len(s)):
	if s[i] == 'R':
		x += 1
	elif s[i] == 'U':
		y += 1
	if x - y > 0 and c == 1:
		coin += 1
		c = 0
	elif x - y < 0 and c == 0:
		coin += 1
		c = 1
print(coin)


n = int(input())
s = list(input())
cur = [0, 0]
f = 0
c = 0
for i in s:
	if i == 'U':
		cur[1] += 1
	else:
		cur[0] += 1
	if cur[0] > cur[1]:
		if f == 2:
			c += 1
		f = 1
	elif cur[1] > cur[0]:
		if f == 1:
			c += 1
		f = 2
print(c)


N = int(input())
s = str(input())
coin = 0
(xp, yp) = (0, 0)
for i in range(0, N - 1):
	if s[i] == 'U':
		xc = xp
		yc = yp + 1
		if s[i + 1] == 'U':
			xn = xc
			yn = yc + 1
		else:
			xn = xc + 1
			yn = yc
	else:
		xc = xp + 1
		yc = yp
		if s[i + 1] == 'U':
			xn = xc
			yn = yc + 1
		else:
			xn = xc + 1
			yn = yc
	if xp < yp and xc == yc and (xn > yn):
		coin += 1
	elif yp < xp and xc == yc and (yn > xn):
		coin += 1
	(xp, yp) = (xc, yc)
print(coin)


n = int(input())
s = input()
cur_x = 0
cur_y = 0
cur_p = 0
if s[0] == 'R':
	cur_p = 1
ans = 0
for i in s:
	if i == 'U':
		cur_y += 1
	elif i == 'R':
		cur_x += 1
	if cur_x > cur_y and cur_p == 0:
		cur_p = 1
		ans += 1
	elif cur_x < cur_y and cur_p == 1:
		ans += 1
		cur_p = 0
print(ans)


n = int(input())
l = list(input())
c = 0
k = 0
for i in range(n - 1):
	if l[i] == 'U':
		c += 1
	else:
		c -= 1
	if c == 0 and l[i] == l[i + 1]:
		k += 1
print(k)


n = int(input())
c = input()
k = [0, 0]
if c[0] == 'U':
	country = 'LEFT'
	co = 'LEFT'
else:
	country = 'RIGHT'
	co = 'RIGHT'
s = 0
for i in c:
	if i == 'U':
		k[1] += 1
		if k[0] > k[1]:
			country = 'RIGHT'
		if k[0] < k[1]:
			country = 'LEFT'
		if country != co:
			s += 1
		co = country
	elif i == 'R':
		k[0] += 1
		if k[0] > k[1]:
			country = 'RIGHT'
		if k[0] < k[1]:
			country = 'LEFT'
		if country != co:
			s += 1
		co = country
print(s)


n = int(input().strip())
arr = list(input().strip())
x = 0
y = 0
ans = 0
for i in range(n - 1):
	if arr[i] == 'U':
		y += 1
	else:
		x += 1
	if arr[i] == arr[i + 1] and x == y:
		ans += 1
print(ans)


n = int(input())
s = input()
cnt = 0
p = True
x = 0
y = 0
for i in s:
	if not (x == 0 and y == 0):
		if p and x == y and (i == 'R'):
			cnt += 1
			p = False
		elif not p and x == y and (i == 'U'):
			cnt += 1
			p = True
	elif i == 'R':
		p = False
	else:
		p = True
	if i == 'R':
		x += 1
	if i == 'U':
		y += 1
print(cnt)


def solve(s: str) -> int:
	kingdom: int = [1, 2][s[0] == 'U']
	cost = 0
	x = 0
	y = 0
	for move in s:
		if move == 'U':
			y += 1
		elif move == 'R':
			x += 1
		if x > y and kingdom == 2:
			kingdom = 1
			cost += 1
		elif y > x and kingdom == 1:
			kingdom = 2
			cost += 1
	return cost

def parse_input() -> str:
	_ = int(input())
	return input()
print(solve(parse_input()))


n = int(input())
lst = list(input())
l = []
x = 0
y = 0
for dir in lst:
	if dir == 'R':
		x += 1
	else:
		y += 1
	if x == y:
		l.append(0)
	elif x > y:
		l.append(-1)
	else:
		l.append(1)
count = 0
for i in range(1, len(l) - 1):
	if l[i] == 0:
		if l[i + 1] != l[i - 1]:
			count += 1
print(count)


n = int(input())
z = input()
x = 0
y = 0
c = 0
if z[0] == 'U':
	y += 1
	c = 1
else:
	x += 1
	c = 0
count = 0
for i in z[1:]:
	if i == 'U':
		if x == y:
			if c == 0:
				count += 1
				c = 1
		y += 1
	elif i == 'R':
		if x == y:
			if c == 1:
				count += 1
				c = 0
		x += 1
print(count)


length = int(input())
tra = input().upper()
tra = list(tra)
(x, y) = (0, 0)
a = []
for i in tra:
	if i == 'U':
		y += 1
	else:
		x += 1
	if x - y > 0:
		a.append('0')
	elif x == y:
		k = a[-1]
		a.append(k)
	else:
		a.append('1')
sum = 0
for j in range(len(a) - 1):
	if a[j] != a[j + 1]:
		sum += 1
print(sum)


n = input()
s = list(input())
(x, y) = (0, 0)
k = 0
cc = 0
for m in s:
	nk = k
	if m == 'U':
		y += 1
	elif m == 'R':
		x += 1
	if y > x:
		nk = 1
	elif y < x:
		nk = -1
	if nk * k == -1:
		cc += 1
	k = nk
print(cc)


import sys
n = int(sys.stdin.readline().split()[0])
path = sys.stdin.readline().rstrip()

def compute_kingdom(position, current):
	if position[1] > position[0]:
		return 'upper'
	if position[1] < position[0]:
		return 'lower'
	return current
current_position = [0, 0]
current_kingdom = ''
coin_count = 0
for j in range(n):
	next_step = path[j]
	if next_step == 'U':
		current_position[1] += 1
	if next_step == 'R':
		current_position[0] += 1
	new_kingdom = compute_kingdom(current_position, current_kingdom)
	if j != 0:
		if new_kingdom != current_kingdom:
			coin_count += 1
	current_kingdom = new_kingdom
print(coin_count)


n = int(input())
string = input()
pos = [0, 0]
pay = 0
if string[0] == 'R':
	pos[0] = pos[0] + 1
elif string[0] == 'U':
	pos[1] = pos[1] + 1
for i in range(1, n):
	if pos[0] == pos[1] and string[i - 1] == string[i] or (pos[1] == pos[0] and string[i - 1] == string[i]):
		pay = pay + 1
	if string[i] == 'R':
		pos[0] = pos[0] + 1
	else:
		pos[1] = pos[1] + 1
print(pay)


(n, k) = (int(input()), input())
(x, y, coins) = (0, 0, 0)
for i in range(n - 1):
	if k[i] == 'R':
		x += 1
		if x == y and k[i + 1] == 'R':
			coins += 1
	else:
		y += 1
		if x == y and k[i + 1] == 'U':
			coins += 1
print(coins)


n = int(input())
moves = input()
x = 0
y = 0
res = 0
ppc = ''
pc = ''
for c in moves:
	if c == 'R':
		x += 1
	else:
		y += 1
	if x == y + 1 and c == pc == 'R':
		res += 1
	if y == x + 1 and c == pc == 'U':
		res += 1
	pc = c
print(res)


input()
bx = by = cx = cy = r = 0
for c in input():
	(ax, ay, bx, by) = (bx, by, cx, cy)
	if c < 'R':
		if c == 'D':
			cy -= 1
		else:
			cx -= 1
	elif c == 'R':
		cx += 1
	else:
		cy += 1
	if bx == by and (ax - ay) * (cx - cy) < 0:
		r += 1
print(r)


n = input()
moves = input()
s = 0
T = 0
(x, y) = (0, 0)
for i in moves:
	if i == 'U':
		y += 1
	else:
		x += 1
	if x > y:
		if T == 1:
			s += 1
		T = -1
	if x < y:
		if T == -1:
			s += 1
		T = 1
print(s)


n = int(input())
S = input()
money = 0
a = 0
for i in range(n):
	if S[i] == 'R':
		a += 1
	else:
		a -= 1
	if i == 0:
		if a > 0:
			dom = 'pos'
		else:
			dom = 'neg'
	if dom == 'pos' and a < 0:
		money += 1
		dom = 'neg'
	elif dom == 'neg' and a > 0:
		money += 1
		dom = 'pos'
print(money)


n = int(input())
s = input()
(x, y) = (0, 0)
begin = True
upper = False
lower = False
res = 0
for l in s:
	if l == 'U':
		if x == y and lower:
			res += 1
			lower = False
			upper = True
		y = y + 1
		if begin:
			begin = False
			upper = True
	if l == 'R':
		if x == y and upper:
			res += 1
			lower = True
			upper = False
		x = x + 1
		if begin:
			begin = False
			lower = True
print(res)


x = int(input())
s = input()
a = b = ans = 0
if s[0] == 'U':
	a = b = 1
else:
	a = b = -1
for i in range(1, x):
	if s[i] == 'U':
		a += 1
		if a * b < 0:
			ans += 1
			b = 1
	else:
		a -= 1
		if a * b < 0:
			ans += 1
			b = -1
print(ans)


n = int(input())
S = input()
c = ([0, 1], [1, 0])[S[0] == 'R']
f = c[0] == 1
ans = 0
for el in S[1:]:
	if el == 'R':
		c[0] += 1
		if not f and c[0] - c[1] == 1:
			ans += 1
			f = not f
	elif el == 'U':
		c[1] += 1
		if f and c[1] - c[0] == 1:
			ans += 1
			f = not f
	else:
		exit(100500)
print(ans)


t = int(input())
s = input()
x = 0
y = 0
count = 0
if s[0] == 'U':
	x = 0
	y = 1
elif s[0] == 'R':
	x = 1
	y = 0
for i in range(1, len(s)):
	if x == y and s[i - 1] == 'R' and (s[i] == 'R'):
		count += 1
	if x == y and s[i - 1] == 'U' and (s[i] == 'U'):
		count += 1
	if s[i] == 'U':
		y = y + 1
	if s[i] == 'R':
		x = x + 1
print(count)


getInputList = lambda : list(input().split())
getInputIntList = lambda : list(map(int, input().split()))
n = int(input())
s = list(input())
last = ''
x = 0
y = 0
c = 0
for i in s:
	if last == '':
		if i == 'U':
			last = 'y'
			y += 1
		else:
			last = 'x'
			x += 1
		continue
	if i == 'U':
		y += 1
	else:
		x += 1
	if last == 'y' and x > y:
		c += 1
		last = 'x'
	if last == 'x' and y > x:
		c += 1
		last = 'y'
print(c)


n = int(input())
word = input()
if len(word) == 1:
	print(0)
else:
	count = 0
	if word[0] == 'U':
		previous = 'first'
	else:
		previous = 'second'
	current = ''
	x = 0
	y = 0
	for item in word:
		if item == 'U':
			y += 1
		else:
			x += 1
		if x < y:
			current = 'first'
		elif x > y:
			current = 'second'
		if previous != current:
			count += 1
		previous = current
	print(count)


n = int(input())
gate = input()
monedas = 0
y = 0
x = 0
for i in range(n - 1):
	if gate[i].upper() == 'U':
		y += 1
	else:
		x += 1
	if x == y:
		if gate[i] == gate[i + 1]:
			monedas += 1
print(monedas)


n = int(input())
c = input()
cnt = 0
r = 0
d = 0
for i in c:
	if i in ['U', 'L']:
		d += 1
	elif i in ['R', 'D']:
		d -= 1
	if d * r == -1:
		cnt += 1
	if d != 0:
		r = int(d / abs(d))
print(cnt)


def chef(s, d):
	count = 0
	(x, y) = (0, 0)
	dirs = len(d)
	for i in range(0, dirs):
		if d[i] == 'U':
			y += 1
		elif d[i] == 'R':
			x += 1
		if x == y and i < dirs - 1:
			if d[i + 1] == d[i]:
				count += 1
	return count

def main():
	s = int(input())
	d = input()
	print(chef(s, d))
main()


(balance, n) = ([0], int(input()))
for ch in input():
	balance.append(balance[-1] + (-1, 1)[ch == 'U'])
print(sum((sum(balance[i:i + 3]) == 0 for i in range(n - 1))))


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))
n = int(input())
s = input()
x = 0
y = 0
ans = 0
if s[0] == 'U':
	q = 2
else:
	q = 1
for i in range(n):
	if s[i] == 'U':
		y += 1
	else:
		x += 1
	if x == y:
		if i < n - 1:
			if s[i + 1] == 'U' and q == 1:
				ans += 1
				q = 2
			if s[i + 1] == 'R' and q == 2:
				ans += 1
				q = 1
print(ans)


n = int(input())
s = input()
x = 0
y = 0
coins = 0
state = ''
if s[0] == 'U':
	y += 1
	p = 'A'
else:
	x += 1
	p = 'B'
for i in range(1, n):
	if s[i] == 'R':
		x += 1
	else:
		y += 1
	if x > y:
		state = 'B'
	elif y > x:
		state = 'A'
	else:
		state = ''
	if state and state != p:
		p = state
		coins += 1
print(coins)


n = int(input())
s = str(input())
l = []
x = 0
y = 0
e = 0
for i in range(0, len(s)):
	if s[i] == 'U':
		y = y + 1
	else:
		x = x + 1
	if len(l) == 0:
		if y - x < 0:
			l.append('n')
		else:
			l.append('p')
	elif y - x < 0:
		if l[-1] == 'p':
			l.append('n')
			e = e + 1
		else:
			l.append('n')
	elif y - x > 0:
		if l[-1] == 'n':
			l.append('p')
			e = e + 1
		else:
			l.append('p')
print(e)


n = int(input())
a = list(input())
x = y = k = 0
if a[0] == 'U':
	p = 1
else:
	p = 0
for i in range(n - 1):
	if a[i] == 'U':
		y += 1
	else:
		x += 1
	if x == y:
		if p == 1 and a[i + 1] == 'R':
			p = 0
			k += 1
		elif p == 0 and a[i + 1] == 'U':
			p = 1
			k += 1
print(k)


n = int(input())
a = list(input())
x = y = 0
s = 0
d = 1
for i in a:
	b = x
	c = y
	if x < y:
		d = 2
	if x > y:
		d = 0
	if i == 'R':
		b += 1
		if d == 2 and x == y and (x != 0) and (b > c):
			s += 1
	else:
		c += 1
		if d == 0 and x == y and (x != 0) and (c > b):
			s += 1
	x = b
	y = c
print(s)


n = int(input())
s = input()
ind = 'U'
ans = 0
if s[0] == 'R':
	ind = 'R'
countr = 0
countu = 0
for i in s:
	if i == 'R':
		countr += 1
	else:
		countu += 1
	if ind == 'U' and countr > countu:
		ind = 'R'
		(countr, countu) = (1, 0)
		ans += 1
	elif ind == 'R' and countu > countr:
		ind = 'U'
		(countu, countr) = (1, 0)
		ans += 1
print(ans)


x = int(input())
y = input()
(cur, ret, pos, kin) = (0.5, -0.5, [0, 0], 0)
for i in range(x):
	if y[i] == 'U':
		pos[1] += 1
	if y[i] == 'R':
		pos[0] += 1
	if pos[1] > pos[0]:
		kin = 1
	elif pos[0] > pos[1]:
		kin = 0
	ret += abs(kin - cur)
	cur = kin
print(int(ret))


n = int(input())
s = list(input())
x = 0
y = 0
prev = 0
ss = 0
for i in range(n):
	if s[i] == 'U':
		y += 1
	else:
		x += 1
	if x == y:
		continue
	t = 0
	if x > y:
		t = 1
	elif x < y:
		t = 2
	if prev != 0:
		if prev != t:
			ss += 1
	prev = t
print(ss)


import sys

def solution(n, s):
	if s[0] == 'R':
		pos = [1, 0]
		up = False
	else:
		pos = [0, 1]
		up = True
	res = 0
	for move in s[1:]:
		if move == 'R':
			if pos[0] != 0 and pos[0] == pos[1] and (up == True):
				up = False
				res += 1
			pos[0] += 1
		else:
			if pos[0] != 0 and pos[0] == pos[1] and (up == False):
				up = True
				res += 1
			pos[1] += 1
	return res
n = int(sys.stdin.readline().strip())
moves = sys.stdin.readline().strip()
print(solution(n, moves))


n = int(input())
a = input()
(x, y) = (1, 1)
le = [-1, 1][a[0] == 'U']
m = 0
for r in a:
	x += 1 * (r == 'R')
	y += 1 * (r == 'U')
	if y / x > 1 and le == -1:
		m += 1
		le = 1
	if y / x < 1 and le == 1:
		m += 1
		le = -1
print(m)


class CodeforcesTask935BSolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.moves = ''

	def read_input(self):
		self.n = int(input())
		self.moves = input()

	def process_task(self):
		x = 0
		y = 0
		coins = 0
		side = ''
		for c in self.moves:
			if c == 'R':
				x += 1
			else:
				y += 1
			if x == y:
				side += '0'
			elif x > y:
				side += '2'
			else:
				side += '1'
		coins = side.count('201') + side.count('102')
		self.result = str(coins)

	def get_result(self):
		return self.result
Solution = CodeforcesTask935BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


input()
(x, y, xy, ans) = (0, 0, -1, 0)
for i in input():
	if i == 'U':
		y += 1
	else:
		x += 1
	if abs(x - y):
		if xy != -1 and xy != (x > y):
			ans += 1
		xy = x > y
print(ans)


n = int(input())
sl = input()
s = ''
a = 0
b = 0
x = 0
y = 0
k = sl[0]
f = 0
for i in range(len(sl)):
	if sl[i] == 'R':
		x += 1
	else:
		y += 1
	if x == y:
		x = 0
		y = 0
		if i + 1 <= n - 1 and k != sl[i + 1]:
			f += 1
			k = sl[i + 1]
print(f)


n = int(input())
s = input().strip()
x = 0
y = 0
nation = None
cost = 0
for ch in s:
	if ch == 'U':
		y += 1
	elif ch == 'R':
		x += 1
	newnation = nation
	if x > y:
		newnation = 1
	elif x < y:
		newnation = -1
	if nation is not None and nation != newnation:
		cost += 1
	nation = newnation
print(cost)


(c, r, u, n, s) = (0, 0, 0, int(input()), input())
if s[0] == 'U':
	a = 1
else:
	a = 2
for x in range(n):
	if s[x] == 'R':
		r += 1
	else:
		u += 1
	if a == 1 and r > u:
		c += 1
		a = 2
		(r, u) = (1, 0)
	elif a == 2 and u > r:
		c += 1
		a = 1
		(r, u) = (0, 1)
print(c)


n = int(input())
path = list(input())
x = 0
y = 0
coins = 0
should_pay = False
last_move = ''
for p in path:
	if p == 'U':
		y += 1
	else:
		x += 1
	if should_pay:
		should_pay = False
		if p == last_move:
			coins += 1
	if x == y:
		should_pay = True
	last_move = p
print(str(coins))


n = int(input())
S = input()
if S[0] == 'U':
	t = 1
else:
	t = 2
(coins, x, y) = (0, 0, 0)
for i in range(n):
	if S[i] == 'U':
		y += 1
	else:
		x += 1
	if x > y:
		if t == 1:
			t = 2
			coins += 1
	elif x < y:
		if t == 2:
			t = 1
			coins += 1
print(coins)


n = int(input())
a = input()
count_right = 0
ans = 0
count_up = 0
for i in range(n):
	if count_right == count_up and i > 0 and (a[i] == a[i - 1]):
		ans += 1
	if a[i] == 'R':
		count_right += 1
	else:
		count_up += 1
print(ans)


n = int(input())
s = input()
x = 0
y = 0
p = 0
(k, c) = (0, 0)
for i in range(n):
	if s[i] == 'U':
		y += 1
	elif s[i] == 'R':
		x += 1
	if x > y:
		c = 1
	elif x < y:
		c = 2
	if i == 0:
		k = c
	elif k != c:
		k = c
		p += 1
print(p)


num = int(input())
string = input()
posX = 0
posY = 0
coins = 0
for i in range(num - 1):
	if string[i] == 'U':
		posY += 1
	else:
		posX += 1
	if string[i + 1] == string[i] and posX == posY:
		coins += 1
print(coins)


numMoves = int(input())
moves = input()
moves = [x for x in moves]
x = 0
y = 0
rside = False
uside = False
coins = 0
if moves[0] == 'U':
	uside = True
if moves[0] == 'R':
	rside = True
for move in moves:
	if move == 'R':
		x += 1
		if x > y:
			if rside == False:
				rside = True
				uside = False
				coins += 1
	if move == 'U':
		y += 1
		if y > x:
			if uside == False:
				uside = True
				rside = False
				coins += 1
print(coins)


from sys import stdin, stdout
n = int(stdin.readline())
coordinates = []
(x, y) = (0, 0)

def check(ind):
	if ind + 1 >= n:
		return False
	label = (coordinates[ind - 1][1] > coordinates[ind - 1][0]) ^ (coordinates[ind + 1][1] > coordinates[ind + 1][0])
	return ind + 1 < n and label
f = stdin.readline().strip()
for i in range(n):
	s = f[i]
	if s == 'U':
		y += 1
	elif s == 'D':
		y -= 1
	elif s == 'L':
		x -= 1
	else:
		x += 1
	coordinates.append((x, y))
ans = 0
for i in range(n):
	if coordinates[i][0] == coordinates[i][1] and check(i):
		ans += 1
stdout.write(str(ans))


n = int(input().strip())
strr = input().strip()
x = y = count = 0
bottom = right = False
for i in range(len(strr)):
	if strr[i] == 'R':
		x += 1
		if right and (not bottom):
			count += 1
			right = False
		if x == y:
			right = True
		else:
			right = False
		bottom = False
	else:
		y += 1
		if bottom and (not right):
			count += 1
			bottom = False
		if x == y:
			bottom = True
		else:
			bottom = False
		right = False
print(count)


num = input()
move = input()
x = 0
y = 0
rs = 0
cu = 0
for i in move:
	if cu == int(num) - 1:
		break
	if i == 'U':
		x += 1
	else:
		y += 1
	if x == y and move[cu + 1] == i:
		rs += 1
	cu += 1
print(rs)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
n = get_int()
s = get_string()
count = 0
if s[0] == 'U':
	(x, y) = (0, 1)
	state = 0
else:
	(x, y) = (1, 0)
	state = 1
for i in range(1, n):
	(x1, y1) = (x, y)
	if s[i] == 'U':
		(x, y) = (x, y + 1)
	else:
		(x, y) = (x + 1, y)
	if x1 == y1:
		if x > y:
			temp = 1
		elif x < y:
			temp = 0
		else:
			temp = state
		if temp != state:
			state = temp
			count += 1
print(count)


n = int(input())
s = input()
x = y = count = 0
if s[0] == 'R':
	pos = 'lower'
else:
	pos = 'upper'
for i in s:
	if i == 'R':
		x += 1
	else:
		y += 1
	if y > x and pos != 'upper':
		count += 1
		pos = 'upper'
	elif x > y and pos != 'lower':
		count += 1
		pos = 'lower'
print(count)


z = input()
t = input()
x = 0
y = 0
if t[0] == 'R':
	state = 'second'
else:
	state = 'first'
coins = 0
for i in range(int(z)):
	if t[i] == 'R':
		x += 1
	else:
		y += 1
	if y > x:
		temp = 'first'
		if temp != state:
			coins = coins + 1
			state = temp
	elif x > y:
		temp = 'second'
		if temp != state:
			coins = coins + 1
			state = temp
print(coins)


n = int(input())
arr = list(map(str, input()))
s = 0
x = 0
y = 0
for i in range(1, len(arr)):
	if arr[i - 1] == 'U':
		y += 1
		if y == x:
			s += 1
			if arr[i] == 'R':
				s -= 1
	else:
		x += 1
		if x == y:
			s += 1
			if arr[i] == 'U':
				s -= 1
print(s)


n = int(input())
S = input()
(x, y, cn) = (0, 0, 0)
for i in range(n - 1):
	if S[i] == 'U':
		y += 1
	else:
		x += 1
	if x == y and (S[i] == 'U' and S[i + 1] == 'U' or (S[i] == 'R' and S[i + 1] == 'R')):
		cn += 1
print(cn)


input()
last = g = u = r = 1
for c in input():
	if u == r and c == last:
		g += 1
	last = c
	if c == 'R':
		r += 1
	else:
		u += 1
print('0' if g == 1 else g - 1)


n = int(input())
st = input()
isUp = st[0] == 'U'
x = 0
y = 0
if st[0] == 'U':
	y += 1
else:
	x += 1
c = 0
for i in range(1, n):
	if isUp and x == y and (st[i] == 'R'):
		c += 1
		isUp = False
	elif not isUp and x == y and (st[i] == 'U'):
		c += 1
		isUp = True
	if st[i] == 'U':
		y += 1
	else:
		x += 1
print(c)


n = int(input())
s = input()
x = 0
y = 0
xx = []
yy = []
xx.append(0)
yy.append(0)
for m in s:
	if m == 'U':
		y = y + 1
		xx.append(x)
		yy.append(y)
	else:
		x = x + 1
		xx.append(x)
		yy.append(y)
count = 0
x = 0
y = 0
for i in range(1, len(s)):
	if xx[i] == yy[i]:
		if xx[i - 1] > yy[i - 1] and xx[i + 1] < yy[i + 1]:
			count = count + 1
		elif xx[i - 1] < yy[i - 1] and xx[i + 1] > yy[i + 1]:
			count = count + 1
print(count)


n = int(input()) - 1
s = input()
m = 0
r = 0
for i in range(n):
	m += 1 if s[i] == 'U' else -1
	if m == 0 and s[i] == s[i + 1]:
		r += 1
print(r)


n = int(input())
l = list(input())
x = 0
y = 0
lf = []
for i in range(n):
	if l[i] == 'U':
		y += 1
	else:
		x += 1
	if x > y:
		lf.append('x')
	elif y > x:
		lf.append('y')
prev = lf[0]
chrg = 0
for i in range(len(lf)):
	if lf[i] != prev:
		chrg += 1
		prev = lf[i]
print(chrg)


def kingdom(x, y):
	if y > x:
		return 1
	else:
		return 0
l = int(input())
path = input().strip()
c = 0
x = 0
y = 0
for i in range(l):
	if path[i] == 'U':
		ny = y + 1
		nx = x
	else:
		ny = y
		nx = x + 1
	if nx == ny:
		if i + 1 < l:
			if path[i + 1] == 'U':
				ty = ny + 1
				tx = nx
			else:
				ty = ny
				tx = nx + 1
			if kingdom(x, y) != kingdom(tx, ty):
				c += 1
	(x, y) = (nx, ny)
print(c)


n = int(input())
s = input()
bal = 0
last = 0
ans = 0
for i in s:
	if i == 'U':
		bal += 1
	else:
		bal -= 1
	if bal == 0:
		continue
	if last * bal < 0:
		ans += 1
	last = bal
print(ans)


n = int(input())
s = input()
l = [0, 0]
count = 0
state = 0

def up():
	l[1] += 1

def right():
	l[0] += 1
for x in s:
	if state == 0:
		if x == 'U':
			up()
			state = 2
		elif x == 'R':
			right()
			state = 1
	elif state == 1:
		if x == 'U':
			up()
		elif x == 'R':
			right()
		if l[1] > l[0]:
			count += 1
			state = 2
	elif state == 2:
		if x == 'U':
			up()
		elif x == 'R':
			right()
		if l[1] < l[0]:
			count += 1
			state = 1
print(count)


n = input()
s = input()
x = 0
y = 0
x1 = [0, 0, 0]
y1 = [0, 0, 0]
x2 = [[], [], []]
y2 = [[], [], []]
c = 0
for e in range(0, len(s)):
	if s[e] == 'R':
		x += 1
		x1.append(x)
		x1.pop(0)
		y2.pop(0)
		y2.append([])
		for i in y1:
			y2[2].append(i)
		x2.pop(0)
		x2.append([])
		for i in x1:
			x2[2].append(i)
	else:
		y += 1
		y1.append(y)
		y1.pop(0)
		x2.pop(0)
		x2.append([])
		for i in x1:
			x2[2].append(i)
		y2.pop(0)
		y2.append([])
		for i in y1:
			y2[2].append(i)
	if x2[0] == x2[1] and x2[1] == x2[2] and (x2[0] != []):
		if y2[0][2] + 1 == y2[1][2] and y2[1][2] == y2[2][2] - 1:
			if x == y - 1:
				c += 1
	if y2[0] == y2[1] and y2[1] == y2[2] and (y2[0] != []):
		if x2[0][2] + 1 == x2[1][2] and x2[1][2] == x2[2][2] - 1:
			if y == x - 1:
				c += 1
print(c)


input()
s = input()
x1 = y1 = 0
x2 = y2 = 0
x0 = x1 = 0
count = 0
for i in range(len(s)):
	if s[i] == 'U':
		y2 += 1
	else:
		x2 += 1
	if x1 == y1 and x2 > x1 and (y1 == y2) and (x1 * y1 != 0):
		if x0 < x1:
			count += 1
	if x1 == y1 and y2 > y1 and (x1 == x2) and (x1 * y1 != 0):
		if y0 < y1:
			count += 1
	y0 = y1
	x0 = x1
	x1 = x2
	y1 = y2
print(count)


n = int(input())
c = 1
way = input()
(x, y) = (0, 0)
if way[0] == 'U':
	st = 'l'
else:
	st = 'r'
for i in way:
	if i == 'U':
		y += 1
	else:
		x += 1
	if x > y:
		if st == 'l':
			c += 1
			st = 'r'
	elif y > x:
		if st == 'r':
			c += 1
			st = 'l'
print(c - 1)


n = int(input())
S = str(input())
(cur_y, cur_x) = (0, 0)
C = [(cur_x, cur_y)]
for c in S:
	if c == 'U':
		cur_y += 1
	else:
		cur_x += 1
	C.append((cur_y, cur_x))
ans = 0
for (i, (cur_x, cur_y)) in enumerate(C):
	if i == 0 or i == len(C) - 1:
		continue
	if cur_x == cur_y:
		(pre_x, pre_y) = C[i - 1]
		(pos_x, pos_y) = C[i + 1]
		if pre_x > pre_y and pos_x < pos_y:
			ans += 1
		elif pre_x < pre_y and pos_x > pos_y:
			ans += 1
print(ans)


t = input()
t = int(t)
c = 0
x = 0
y = 0
p = input()
if p[0] == 'U':
	y += 1
	f = 0
else:
	x += 1
	f = 1
for i in range(1, t):
	if p[i] == 'U':
		y += 1
	else:
		x += 1
	if x > y:
		if f == 0:
			c += 1
			f = 1
	elif y > x:
		if f == 1:
			c += 1
			f = 0
print(c)


n = int(input())
s = input()
(x, y, a, b, z) = ([], [], 0, 0, 0)
for i in range(n):
	if s[i] == 'U':
		a += 1
	elif s[i] == 'R':
		b += 1
	x.append(b)
	y.append(a)
for i in range(1, n - 1):
	if x[i] == y[i]:
		if x[i - 1] < y[i - 1] and x[i + 1] > y[i + 1]:
			z += 1
		elif x[i - 1] > y[i - 1] and x[i + 1] < y[i + 1]:
			z += 1
print(z)


import sys, math
f = sys.stdin
N = int(f.readline())
S = f.readline().strip()
kingdom = 0
x = 0
y = 0
ans = 0
for action in S:
	if x == y and (kingdom == 1 and action == 'U' or (kingdom == 2 and action == 'R')):
		ans += 1
	if action == 'U':
		y += 1
	elif action == 'R':
		x += 1
	if x > y:
		kingdom = 1
	elif x < y:
		kingdom = 2
print(ans)


n = int(input())
s = input()
(x, y) = (0, 0)
ans = 0
prev = None
for i in s:
	if i == 'U':
		y += 1
	else:
		x += 1
	if prev == None:
		if x - y < 0:
			prev = 'l'
		elif x - y > 0:
			prev = 'r'
	elif x == y:
		continue
	elif x - y > 0 and prev == 'l':
		ans += 1
		prev = 'r'
	elif x - y < 0 and prev == 'r':
		ans += 1
		prev = 'l'
print(ans)


n = int(input())
m = input()
x = 0
y = 0
k = 0
for i in range(n - 1):
	if m[i] == 'U':
		y += 1
	elif m[i] == 'R':
		x += 1
	if n > 0:
		if x == y:
			if m[i] == m[i + 1]:
				k += 1
	if i == n - 1:
		if x == y:
			if m[i - 1] == m[i]:
				k += 1
print(k)


n = int(input())
s = input()
(x, y) = (0, 0)
travel = []
for elem in s:
	curt = 0
	if elem == 'U':
		y += 1
	else:
		x += 1
	if x > y:
		travel.append(1)
	elif x < y:
		travel.append(2)
(i, cnt) = (0, 0)
if travel:
	curel = travel[0]
while i < len(travel):
	if travel[i] == curel:
		while i < len(travel) and travel[i] == curel:
			i += 1
	else:
		cnt += 1
		curel = travel[i]
print(cnt)


n = int(input())
s = list(input())
xty = False
ytx = False
c = [0, 0]
res = 0
for i in range(n):
	if s[i] == 'U':
		c[1] += 1
	else:
		c[0] += 1
	if c[0] > c[1] and xty == False:
		res += 1
		xty = True
		ytx = False
	if c[1] > c[0] and ytx == False:
		res += 1
		ytx = True
		xty = False
print(res - 1)


n = int(input())
x = 0
y = 0
silver_coins = 0
moves = input()
for i in range(n):
	if moves[i] == 'R':
		x += 1
		if i == n - 1:
			pass
		elif x == y and moves[i + 1] == 'R':
			silver_coins += 1
	else:
		y += 1
		if i == n - 1:
			pass
		elif y == x and moves[i + 1] == 'U':
			silver_coins += 1
print(silver_coins)


a = int(input())
b = input()
x = 0
y = 0
k = 0
for i in range(a):
	if b[i] == 'U':
		y += 1
	else:
		x += 1
	if x > y:
		n = 2
	elif y > x:
		n = 1
	if i != 0 and n != f:
		k += 1
	f = n
print(k)


n = int(input())
s = input()
if s[0] == 'U':
	x = 0
	y = 1
	prev = 'up'
else:
	x = 1
	y = 0
	prev = 'down'
coin = 0
curr = prev
if n > 1:
	for i in range(1, len(s)):
		if s[i] == 'U':
			y += 1
			if x > y:
				curr = 'down'
			elif x < y:
				curr = 'up'
		else:
			x += 1
			if x > y:
				curr = 'down'
			elif x < y:
				curr = 'up'
		if curr != prev:
			coin += 1
		prev = curr
print(coin)


n = int(input())
s = input()
ans = 0
(u, r) = (0, 0)
for i in range(len(s) - 1):
	if s[i] == 'U':
		u += 1
	elif s[i] == 'R':
		r += 1
	if r == u and s[i] == 'U' and (s[i + 1] == 'U'):
		ans += 1
	elif r == u and s[i] == 'R' and (s[i + 1] == 'R'):
		ans += 1
print(ans)


R = lambda : map(int, input().split())
input()
x = y = k = r = 0
for c in input():
	if c == 'U':
		x += 1
	else:
		y += 1
	if k * (x - y) < 0:
		r += 1
	if x - y:
		k = x - y
print(r)


n = int(input())
x_y = [0, 0]
wall = 0
count = 0
p = input()
if p[0] == 'U':
	wall = 2
	x_y[1] += 1
else:
	wall = 1
	x_y[0] += 1
for i in p[1:]:
	s = i
	if s == 'U':
		if x_y[0] == x_y[1] and wall == 1:
			count += 1
			wall = 2
		x_y[1] += 1
	else:
		if x_y[0] == x_y[1] and wall == 2:
			count += 1
			wall = 1
		x_y[0] += 1
print(count)


n = int(input())
steps = input()
x = 0
y = 0
count = 0
if steps[0] == 'U':
	pos = 0
	y = 1
else:
	pos = 1
	x = 1
for i in range(1, n):
	if steps[i] == 'U':
		y += 1
		if pos == 1 and y > x:
			count += 1
			pos = 0
	else:
		x += 1
		if pos == 0 and x > y:
			count += 1
			pos = 1
print(str(count))


n = int(input())
cnt = 0
s = input()
neg = 0
pos = 0
ans = 0
for x in s:
	if x == 'U':
		cnt += 1
	else:
		cnt -= 1
	if cnt > 0 and neg > 0:
		ans += 1
	elif cnt < 0 and pos > 0:
		ans += 1
	if cnt > 0:
		pos = 1
		neg = 0
	elif cnt < 0:
		pos = 0
		neg = 1
print(ans)


input()
X = input()
(x, y) = (1, 0) if X[0] == 'R' else (0, 1)
Count = 0
for i in range(1, len(X)):
	if X[i] == 'U':
		y += 1
		if y - 1 == x and X[i - 1] == 'U':
			Count += 1
	else:
		x += 1
		if x - 1 == y and X[i - 1] == 'R':
			Count += 1
print(Count)


def move(x, y, move):
	if move == 'R':
		return (x + 1, y)
	return (x, y + 1)
n_moves = int(input())
moves = input()
(x, y, coins) = (0, 0, 0)
(x, y) = move(x, y, moves[0])
at_right_kingdom = x > y
for i in moves[1:]:
	(x, y) = move(x, y, i)
	if at_right_kingdom and x < y:
		at_right_kingdom = False
		coins += 1
	elif not at_right_kingdom and x > y:
		at_right_kingdom = True
		coins += 1
print(coins)


input()
pathway = input()
coins = 0
x = 0
prev_x = 0
prev_prev_x = 0
y = 0
prev_y = 0
prev_prev_y = 0
for s in pathway:
	prev_prev_y = prev_y
	prev_y = y
	prev_prev_x = prev_x
	prev_x = x
	if s == 'U':
		y += 1
	else:
		x += 1
	if prev_x == prev_y:
		if prev_prev_x == x or prev_prev_y == y:
			coins += 1
print(coins - 1)


def main(a):
	h = 0
	left = False
	right = False
	old_left = False
	old_right = False
	is_probably_money = False
	s = [0, 0]
	for i in a:
		if i == 'U':
			s[1] += 1
		if i == 'R':
			s[0] += 1
		if s[0] == s[1] == 0:
			continue
		if s[0] > s[1]:
			right = True
		if s[0] < s[1]:
			left = True
		if s[0] > s[1] and old_left:
			right = True
			old_left = False
			h += 1
		if s[0] < s[1] and old_right:
			left = True
			old_right = False
			h += 1
		if s[0] == s[1] and left:
			old_left = True
		if s[0] == s[1] and right:
			old_right = True
		if s[0] == s[1]:
			right = False
			left = False
	print(h)
a = input()
c = input()
main(c)


x = int(input())
y = input()
pay = 0
lado = 0
if y[0] == 'R':
	lado = -1
else:
	lado = 1
cx = 0
cy = 0
pay = 0
for paso in range(x):
	if y[paso] == 'R':
		cx = cx + 1
	elif y[paso] == 'U':
		cy = cy + 1
	if lado == -1:
		if cy > cx:
			pay = pay + 1
			lado = 1
	elif lado == 1:
		if cx > cy:
			pay = pay + 1
			lado = -1
print(pay)


import sys
import math
import bisect
import itertools
import random
import re

def main():
	n = int(input())
	last = -1
	x = 0
	y = 0
	ans = 0
	for c in input():
		if c == 'U':
			y += 1
		elif c == 'R':
			x += 1
		if y > x:
			cur = 0
		elif y < x:
			cur = 1
		if last != -1 and last != cur:
			ans += 1
		last = cur
	print(ans)
main()


from sys import stdin, stdout
from collections import *
from math import gcd, floor, ceil

def st():
	return list(stdin.readline().strip())

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

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

def inp():
	return int(stdin.readline())

def pr(n):
	return stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	n = inp()
	ans = 0
	s = st()
	cur = -1
	(a, b) = (0, 0)
	for i in range(n):
		if s[i] == 'R':
			a += 1
		else:
			b += 1
		if a > b:
			if cur != 0:
				ans += 1
				cur = 0
		if b > a:
			if cur != 1:
				ans += 1
				cur = 1
	pr(ans - 1)
for _ in range(1):
	solve()


n = int(input())
s = input()
u = 0
r = 0
coins = 0
reg = s[0]
for i in range(n):
	prev = reg
	if s[i] == 'U':
		u += 1
	if s[i] == 'R':
		r += 1
	if u < r:
		reg = 'R'
	if r < u:
		reg = 'U'
	if prev != reg:
		coins += 1
print(coins)


def go(c, x, y):
	if c == 'U':
		return (x, y + 1)
	return (x + 1, y)
n = int(input())
x = 0
y = 0
s = input()
cnt = 0
for (i, c) in enumerate(s):
	if i and x == y and (c == s[i - 1]):
		cnt += 1
	(x, y) = go(c, x, y)
print(cnt)


n = int(input())
s = input()
cnt = 0
(x, y) = (0, 0)
down = False
for i in range(n):
	if s[i] == 'U':
		x += 1
	else:
		y += 1
	if y != x:
		new_down = y < x
		if down != new_down and i > 0:
			cnt += 1
		down = new_down
print(cnt)


n = int(input())
s = input()
place = 0
res = 0
prev_place = 0
for c in s:
	if c == 'U':
		place += 1
	else:
		place -= 1
	if place != 0:
		if place * prev_place < 0:
			res += 1
		prev_place = place
print(res)


n = int(input())
s = str(input())
c = 0
l = 0
r = 0
i = 0
while i < len(s) - 1:
	if s[i] == 'U':
		l = l + 1
		if l == r:
			if s[i] == s[i + 1]:
				c = c + 1
	else:
		r = r + 1
		if l == r:
			if s[i] == s[i + 1]:
				c = c + 1
	i = i + 1
print(c)


n = int(input())
s = input()
U = 0
R = 0
flag = 0
ans = 0
last = ''
for i in s:
	if i == 'U':
		if last == 'U':
			flag = 1
		else:
			flag = 0
	if i == 'R':
		if last == 'R':
			flag = 1
		else:
			flag = 0
	if U == R and flag == 1:
		ans += 1
	if i == 'U':
		U += 1
		last = 'U'
	else:
		R += 1
		last = 'R'
print(ans)


n = int(input())
s = input()
c = 0
(x, y) = (0, 0)
flag1 = 0
p = 0
for i in s:
	if i == 'U':
		if p == 0:
			flag1 = 2
			p = p + 1
		y += 1
	else:
		if p == 0:
			flag1 = 1
			p = p + 1
		x += 1
	if x > y and flag1 == 2:
		c = c + 1
		flag1 = 1
	elif y > x and flag1 == 1:
		c = c + 1
		flag1 = 2
print(c)


GI = lambda : int(input())
GIS = lambda : map(int, input().split())

def main():
	GI()
	moves = input()
	res = 0
	x = y = 0
	k = 0
	for move in moves:
		if move == 'U':
			y += 1
		else:
			x += 1
		if y < x:
			if k == 1:
				res += 1
			k = -1
		elif x < y:
			if k == -1:
				res += 1
			k = 1
	print(res)
main()


n = int(input())
directions = input()
x = 0
y = 0
count = 0
kingdom = 0
prev_kingdom = 0
for i in directions:
	if i == 'R':
		x += 1
	elif i == 'U':
		y += 1
	if y > 0 and x < y or (x < 0 and y > x) or (x == 0 and y > 0) or (y == 0 and x < 0):
		kingdom = 1
		if prev_kingdom == 2:
			count += 1
			prev_kingdom = 1
	elif x > 0 and y < x or (y < 0 and x > y) or (x == 0 and y < 0) or (y == 0 and x > 0):
		kingdom = 2
		if prev_kingdom == 1:
			count += 1
			prev_kingdom = 2
	elif x == y:
		prev_kingdom = kingdom
		kingdom = 0
print(count)


n = int(input())
string = input()
r = 0
u = 0
counter = 0
if string[0] == 'R':
	flag = 1
	r += 1
else:
	flag = 0
	u += 1
for i in range(1, len(string)):
	if flag == 1:
		if string[i] == 'R':
			r += 1
		else:
			u += 1
		if u > r:
			counter += 1
			flag = 0
	else:
		if string[i] == 'R':
			r += 1
		else:
			u += 1
		if r > u:
			counter += 1
			flag = 1
print(counter)


def main():
	N = int(input())
	S = input()
	if S[0] == 'R':
		kingdom = 1
	else:
		kingdom = 2
	pay = 0
	position = [0, 0]
	for s in S:
		if s == 'U':
			position[1] += 1
		else:
			position[0] += 1
		if position[0] < position[1] and kingdom == 1:
			pay += 1
			kingdom = 2
		elif position[0] > position[1] and kingdom == 2:
			pay += 1
			kingdom = 1
	print(pay)
main()


n = int(input())
s = input()
c = [0, 0]
coins = 0
mayChange = False
for i in range(n):
	if mayChange:
		if s[i] == s[i - 1]:
			coins += 1
		mayChange = False
	if s[i] == 'U':
		c[1] += 1
	else:
		c[0] += 1
	if c[0] == c[1]:
		mayChange = True
print(coins)


n = int(input())
s = input()
c_kingdom = 0
if s[0] == 'U':
	pos = [0, 1]
	c_kingdom = 1
else:
	pos = [1, 0]
s = s[1:]
silver = 0
for i in s:
	if i == 'U':
		if pos[0] == pos[1] and c_kingdom == 0:
			silver += 1
			c_kingdom = not c_kingdom
		pos = [pos[0], pos[1] + 1]
	else:
		if pos[0] == pos[1] and c_kingdom == 1:
			silver += 1
			c_kingdom = not c_kingdom
		pos = [pos[0] + 1, pos[1]]
print(silver)


n = int(input())
s = input()
xAxis = 0
yAxis = 0
count = 0
coord = []
for i in s:
	if i == 'R':
		xAxis += 1
	elif i == 'U':
		yAxis += 1
	tmp = [xAxis, yAxis]
	coord.append(tmp)
	tmp = []
for i in range(len(coord) - 2):
	if coord[i][0] > coord[i][1]:
		if coord[i + 1][0] == coord[i + 1][1]:
			if coord[i + 2][0] < coord[i + 2][1]:
				count += 1
	elif coord[i][0] < coord[i][1]:
		if coord[i + 1][0] == coord[i + 1][1]:
			if coord[i + 2][0] > coord[i + 2][1]:
				count += 1
print(count)


x = 0
y = 0
n = int(input())
string = input()
prev_x = 0
prev_y = 0
pprev_x = 0
pprev_y = 0
count = 0
for i in string:
	if i == 'U':
		y = y + 1
	if i == 'R':
		x = x + 1
	if (pprev_x < pprev_y and x > y or (pprev_x > pprev_y and x < y)) and prev_x == prev_y:
		count += 1
	pprev_x = prev_x
	pprev_y = prev_y
	prev_x = x
	prev_y = y
print(count)


n = int(input())
s = list(input())
r = 0
u = 0
count = 0
for i in range(n - 1):
	if s[i] == 'U':
		u += 1
	elif s[i] == 'R':
		r += 1
	if u == r and s[i] == s[i + 1]:
		count += 1
print(count)