Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of m points p_1, p_2, ..., p_{m} with integer coordinates, do the following: denote its initial location by p_0. First, the robot will move from p_0 to p_1 along one of the shortest paths between them (please notice that since the robot moves only along the grid lines, there can be several shortest paths). Then, after it reaches p_1, it'll move to p_2, again, choosing one of the shortest ways, then to p_3, and so on, until he has visited all points in the given order. Some of the points in the sequence may coincide, in that case Robot will visit that point several times according to the sequence order.

While Santa was away, someone gave a sequence of points to Robot. This sequence is now lost, but Robot saved the protocol of its unit movements. Please, find the minimum possible length of the sequence.


-----Input-----

The first line of input contains the only positive integer n (1 ≤ n ≤ 2·10^5) which equals the number of unit segments the robot traveled. The second line contains the movements protocol, which consists of n letters, each being equal either L, or R, or U, or D. k-th letter stands for the direction which Robot traveled the k-th unit segment in: L means that it moved to the left, R — to the right, U — to the top and D — to the bottom. Have a look at the illustrations for better explanation.


-----Output-----

The only line of input should contain the minimum possible length of the sequence.


-----Examples-----
Input
4
RURD

Output
2

Input
6
RRULDD

Output
2

Input
26
RRRULURURUULULLLDLDDRDRDLD

Output
7

Input
3
RLL

Output
2

Input
4
LRLR

Output
4



-----Note-----

The illustrations to the first three tests are given below.

[Image] [Image] [Image]

The last example illustrates that each point in the sequence should be counted as many times as it is presented in the sequence.

Difficulty: MEDIUM
Tags: Mathematics

Constructive algorithms

Starter code:

Solutions:
def correct(p):
	global typ
	if typ == '':
		typ = p
	elif typ == 'R':
		if p == 'L':
			return False
		if p == 'D' or p == 'U':
			typ = typ + p
	elif typ == 'L':
		if p == 'R':
			return False
		if p == 'D' or p == 'U':
			typ = typ + p
	elif typ == 'U':
		if p == 'D':
			return False
		if p == 'R' or p == 'L':
			typ = typ + p
	elif typ == 'D':
		if p == 'U':
			return False
		if p == 'R' or p == 'L':
			typ = typ + p
	elif typ == 'RU' or typ == 'UR':
		if p != 'R' and p != 'U':
			return False
	elif typ == 'RD' or typ == 'DR':
		if p != 'R' and p != 'D':
			return False
	elif typ == 'LU' or typ == 'UL':
		if p != 'L' and p != 'U':
			return False
	elif typ == 'LD' or typ == 'DL':
		if p != 'L' and p != 'D':
			return False
	return True
n = int(input())
s = input()
i = 0
k = 0
typ = ''
while i < n:
	while i < n:
		if correct(s[i]) == False:
			break
		else:
			i += 1
	k += 1
	typ = ''
print(k)


import sys
input = sys.stdin.readline
n = int(input())
seq = input()
cat = ['.', '.']
count = 1
for i in range(n):
	letter = seq[i]
	if letter == 'R' and cat[0] == 'L':
		count += 1
		cat = ['R', '.']
	elif letter == 'L' and cat[0] == 'R':
		count += 1
		cat = ['L', '.']
	elif letter == 'U' and cat[1] == 'D':
		count += 1
		cat = ['.', 'U']
	elif letter == 'D' and cat[1] == 'U':
		count += 1
		cat = ['.', 'D']
	elif letter == 'R' or letter == 'L':
		cat[0] = letter
	elif letter == 'U' or letter == 'D':
		cat[1] = letter
print(count)


input()
t = input()
con1 = 0
con2 = 0
ans = 0
for j in range(len(t)):
	i = t[j]
	if i == 'R' or i == 'L':
		if not con1:
			con1 = i
		elif con1 != i:
			ans += 1
			(con1, con2) = (i, 0)
	elif not con2:
		con2 = i
	elif con2 != i:
		ans += 1
		(con1, con2) = (0, i)
print(ans + 1)


n = int(input())
s = input()
count = 1
(k, q) = (0, 0)
for x in range(n):
	if s[x] == 'L' or s[x] == 'R':
		if s[x] != k and k != 0:
			count += 1
			q = 0
		k = s[x]
	else:
		if s[x] != q and q != 0:
			count += 1
			k = 0
		q = s[x]
print(count)


def dist(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
n = int(input())
s = input()
k = 1
d = {'R': (1, 0), 'U': (0, 1), 'L': (-1, 0), 'D': (0, -1)}
x = 0
y = 0
predx = 0
predy = 0
preddist = 0
for c in s:
	x += d[c][0]
	y += d[c][1]
	curdist = dist(x, y, predx, predy)
	if curdist <= preddist:
		predx = x - d[c][0]
		predy = y - d[c][1]
		preddist = dist(x, y, predx, predy)
		k += 1
	else:
		preddist = curdist
print(k)


n = int(input())
s = list(input())
a = [[0, 0]]
for i in s:
	x = a[-1]
	if i == 'L':
		a.append([x[0] - 1, x[1]])
	elif i == 'R':
		a.append([x[0] + 1, x[1]])
	elif i == 'U':
		a.append([x[0], x[1] - 1])
	else:
		a.append([x[0], x[1] + 1])
j = 1
c = a[0]
d = 0
ans = 1
while j < len(a):
	d += 1
	do = abs(c[0] - a[j][0]) + abs(c[1] - a[j][1])
	if d > do:
		c = a[j - 1]
		ans += 1
		d = 0
	j += 1
print(ans)


def main():
	n = int(input())
	m = input()
	uu = False
	rr = False
	o = 1
	u = True
	r = True
	for i in m:
		if i == 'R':
			if rr:
				if not r:
					r = True
					uu = False
					o += 1
			else:
				r = True
				rr = True
		elif i == 'L':
			if rr:
				if r:
					r = False
					uu = False
					o += 1
			else:
				rr = True
				r = False
		elif i == 'U':
			if uu:
				if not u:
					u = True
					rr = False
					o += 1
			else:
				u = True
				uu = True
		elif uu:
			if u:
				u = False
				rr = False
				o += 1
		else:
			uu = True
			u = False
	print(o)
main()


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


L = int(input())
path = input()
movement = [0, 0]
num_of_commands = 0
for i in range(L):
	if path[i] == 'U':
		if movement[0] == 0:
			movement[0] = 1
		elif movement[0] == 2:
			num_of_commands += 1
			movement = [1, 0]
	elif path[i] == 'D':
		if movement[0] == 0:
			movement[0] = 2
		elif movement[0] == 1:
			num_of_commands += 1
			movement = [2, 0]
	elif path[i] == 'R':
		if movement[1] == 0:
			movement[1] = 1
		elif movement[1] == 2:
			num_of_commands += 1
			movement = [0, 1]
	elif path[i] == 'L':
		if movement[1] == 0:
			movement[1] = 2
		elif movement[1] == 1:
			num_of_commands += 1
			movement = [0, 2]
num_of_commands += 1
print(num_of_commands)


_ = int(input())
program = input()
(x, y) = (0, 0)
s = 0
pointcount = 0
for i in program:
	(oldx, oldy) = (x, y)
	if i is 'U':
		y += 1
	elif i is 'D':
		y -= 1
	elif i is 'R':
		x += 1
	elif i is 'L':
		x -= 1
	s += 1
	mins = abs(x) + abs(y)
	if s > mins:
		pointcount += 1
		s = 1
		x -= oldx
		y -= oldy
print(pointcount + 1)


n = int(input())
s = input()
ans = 1
rl = ''
ud = ''
for i in range(n):
	if s[i] == 'L' or s[i] == 'R':
		if not rl:
			rl = s[i]
		elif rl != s[i]:
			ans += 1
			(rl, ud) = (s[i], 0)
	elif s[i] == 'U' or s[i] == 'D':
		if not ud:
			ud = s[i]
		elif ud != s[i]:
			ans += 1
			(rl, ud) = (0, s[i])
print(ans)


n = int(input())
s = input()
f1 = 0
f2 = 0
res = 0
for i in range(len(s)):
	if s[i] == 'L':
		if f1 == 0:
			f1 = -1
		if f1 == 1:
			res += 1
			f1 = -1
			f2 = 0
	if s[i] == 'R':
		if f1 == 0:
			f1 = 1
		if f1 == -1:
			res += 1
			f1 = 1
			f2 = 0
	if s[i] == 'U':
		if f2 == 0:
			f2 = -1
		if f2 == 1:
			res += 1
			f1 = 0
			f2 = -1
	if s[i] == 'D':
		if f2 == 0:
			f2 = 1
		if f2 == -1:
			res += 1
			f1 = 0
			f2 = 1
if f1 != 0 or f2 != 0:
	res += 1
print(res)


n = int(input())
s = input()
ans = 0
tmp = []
for i in range(len(s)):
	if len(tmp) < 2 or s[i] in tmp:
		if len(tmp) == 1 and (s[i] == 'U' and tmp[0] == 'D' or (s[i] == 'D' and tmp[0] == 'U') or (s[i] == 'L' and tmp[0] == 'R') or (s[i] == 'R' and tmp[0] == 'L')):
			ans += 1
			tmp = [s[i]]
		elif s[i] not in tmp:
			tmp.append(s[i])
	else:
		ans += 1
		tmp = [s[i]]
if tmp:
	ans += 1
print(ans)


n = int(input())
moves = input()
variants = dict()
variants['L'] = 'R'
variants['R'] = 'L'
variants['D'] = 'U'
variants['U'] = 'D'
graph = set()
ans = 1
for i in range(len(moves)):
	move = moves[i]
	if move in graph:
		continue
	if variants[move] in graph:
		graph = set()
		graph.add(move)
		ans += 1
	else:
		graph.add(move)
print(ans)


n = int(input())
way = input()
lastx = 0
lasty = 0
curx = 0
cury = 0
steps = 0
ans = 0
i = 0
while i < n:
	if way[i] == 'L':
		curx -= 1
	elif way[i] == 'R':
		curx += 1
	elif way[i] == 'U':
		cury += 1
	elif way[i] == 'D':
		cury -= 1
	steps += 1
	if steps != abs(curx - lastx) + abs(cury - lasty):
		ans += 1
		steps = 0
		if way[i] == 'L':
			curx += 1
		elif way[i] == 'R':
			curx -= 1
		elif way[i] == 'U':
			cury -= 1
		elif way[i] == 'D':
			cury += 1
		lastx = curx
		lasty = cury
		i -= 1
	i += 1
print(ans + 1)


rev = {'R': 'L', 'L': 'R', 'U': 'D', 'D': 'U'}
n = int(input())
s = input()
ans = 1
was = set()
for c in s:
	if rev[c] in was:
		ans += 1
		was = set()
	was.add(c)
print(ans)


def main():
	n = int(input())
	s = input()
	fr = None
	sc = None
	ans = 0
	for elem in s:
		if fr == None:
			fr = elem
			ans += 1
		elif sc == None:
			if elem == fr:
				continue
			elif fr == 'L' and elem == 'R' or (fr == 'R' and elem == 'L') or (fr == 'D' and elem == 'U') or (fr == 'U' and elem == 'D'):
				ans += 1
				fr = elem
				sc = None
			else:
				sc = elem
		elif elem == fr or elem == sc:
			continue
		else:
			ans += 1
			fr = elem
			sc = None
	print(ans)
main()


import sys
fin = sys.stdin
fout = sys.stdout
n = int(fin.readline())
s = fin.readline().strip()
curFirst = False
if s[0] == 'R' or s[0] == 'U':
	curFirst = True
else:
	curFirst = False
ans = 1
curX = 0
curY = 0
ans = 1
curSet = set()
for i in range(len(s)):
	curSet.add(s[i])
	if 'L' in curSet and 'R' in curSet or ('U' in curSet and 'D' in curSet):
		curSet.clear()
		curSet.add(s[i])
		ans += 1
	if s[i] == 'L':
		curY -= 1
	elif s[i] == 'R':
		curY += 1
	elif s[i] == 'U':
		curX += 1
	else:
		curX -= 1
fout.write(str(ans))


while True:
	try:
		length = int(input())
		string = list(input())
		r1 = None
		r2 = None
		count = 0
		for i in string:
			if i == 'R' or i == 'L':
				if not r1:
					r1 = i
				elif r1 != i:
					r1 = i
					r2 = None
					count += 1
			if i == 'U' or i == 'D':
				if not r2:
					r2 = i
				elif r2 != i:
					r2 = i
					r1 = None
					count += 1
		print(count + 1)
	except EOFError:
		break


n = int(input())
(*s,) = map(lambda x: 'URDL'.find(x), list(input()))
last = set()
cnt = 0
for i in range(len(s)):
	d = s[i]
	for ld in last:
		if min(abs(ld - d), 4 - abs(ld - d)) > 1:
			cnt += 1
			last = set()
			break
	last.add(d)
print(cnt + 1)


n = int(input())
s = input()
d = ''
ans = 0
cant = dict()
cant['R'] = 'L'
cant['L'] = 'R'
cant['U'] = 'D'
cant['D'] = 'U'
for i in range(n):
	if d == '':
		d = s[i]
		ans += 1
	elif len(d) == 1:
		if s[i] != d:
			if cant[s[i]] == d:
				ans += 1
				d = s[i]
			else:
				d += s[i]
	elif s[i] != d[0] and s[i] != d[1]:
		ans += 1
		d = s[i]
print(ans)


def solve(s):
	opposite = {'D': 'U', 'U': 'D', 'L': 'R', 'R': 'L'}
	directions = set()
	k = 0
	for c in s:
		directions.add(c)
		if len(directions) > 2 or opposite[c] in directions:
			k += 1
			directions.clear()
			directions.add(c)
	return k + 1
n = int(input())
s = input().rstrip()
print(solve(s))


n = int(input())
s = input()
i = 0
v = 0
g = 0
kol = 0
while i < n:
	a = s[i]
	if a == 'U':
		if v == 0:
			v = 1
		elif v == -1:
			kol += 1
			v = 0
			g = 0
			i -= 1
	elif a == 'D':
		if v == 0:
			v = -1
		elif v == 1:
			kol += 1
			v = 0
			g = 0
			i -= 1
	elif a == 'R':
		if g == 0:
			g = 1
		elif g == -1:
			kol += 1
			v = 0
			g = 0
			i -= 1
	elif g == 0:
		g = -1
	elif g == 1:
		kol += 1
		v = 0
		g = 0
		i -= 1
	i += 1
print(kol + 1)


n = int(input())
A = input()
count = 0
B = {'L': 0, 'R': 1, 'U': 2, 'D': 3}
C = {'L': 'R', 'R': 'L', 'U': 'D', 'D': 'U'}
res = [0, 0, 0, 0]
for i in A:
	if res[B[C[i]]] == 0:
		res[B[i]] += 1
	else:
		count += 1
		res = [0, 0, 0, 0]
		res[B[i]] += 1
if res != [0, 0, 0, 0]:
	count += 1
print(count)


input()
n = input()

def isok(f, s):
	if (f == 'U' or f == 'D') and (s == 'L' or s == 'R'):
		return True
	if (f == 'R' or f == 'L') and (s == 'U' or s == 'D'):
		return True
	return False
first = ''
second = ''
res = 0
for i in range(len(n)):
	if not first:
		first = n[i]
	elif first and (not second):
		if n[i] == first:
			continue
		elif isok(first, n[i]):
			second = n[i]
		else:
			res += 1
			first = n[i]
			second = ''
	elif first and second:
		if n[i] == first or n[i] == second:
			continue
		else:
			res += 1
			first = n[i]
			second = ''
print(res + 1)


n = int(input())
a = input()
opp = ['UD', 'DU', 'LR', 'RL']
c1 = None
c2 = None
cnt = 0
for i in range(n):
	if c1 is None:
		c1 = a[i]
	elif c1 == a[i] and c2 is None:
		continue
	elif c1 != a[i] and c2 is None:
		if c1 + a[i] in opp:
			cnt += 1
			c1 = a[i]
			c2 = None
		else:
			c2 = a[i]
	elif c1 is not None and c2 is not None and (c1 == a[i] or c2 == a[i]):
		continue
	elif c1 is not None and c2 is not None and (c1 != a[i] and c2 != a[i]):
		cnt += 1
		c1 = a[i]
		c2 = None
print(cnt + 1)


n = int(input())
s = input()
c = set()
ans = 0
ma = ['LD', 'LU', 'RD', 'RU']
may = [set(i) for i in ma]
for i in s:
	if not i in c:
		c.add(i)
		if len(c) > 1 and (not c in may):
			ans += 1
			c = set(i)
if c:
	ans += 1
print(ans)


import sys
sys.setrecursionlimit(10 ** 7)
n = int(input())
dirs = input()
mapping = {'U': 1, 'D': 2, 'R': 0, 'L': 3}
sums = [[0] * 4]
for c in dirs:
	tup = [0] * 4
	tup[mapping[c]] = 1
	for i in range(4):
		tup[i] += sums[-1][i]
	sums.append(tup)

def is_shortest_dist(st, en):
	diff = [sums[en + 1][i] - sums[st][i] > 0 for i in range(4)]
	return diff[mapping['U']] + diff[mapping['D']] < 2 and diff[mapping['L']] + diff[mapping['R']] < 2

def dp(i):
	min_pts = 1
	while i < n:
		increase = False
		for j in range(i, n):
			if not is_shortest_dist(i, j):
				min_pts += 1
				i = j
				increase = True
		if not increase:
			break
	return min_pts
print(dp(0))


n = int(input())
s = input()
v = ''
h = ''
vs = {'U', 'D'}
hs = {'L', 'R'}
ans = 1
for i in s:
	if i in vs:
		if v == '':
			v = i
		elif v != i:
			v = i
			ans += 1
			h = ''
	elif h == '':
		h = i
	elif h != i:
		h = i
		ans += 1
		v = ''
print(ans)


n = int(input())
the_path = input()
word_set = set()
counter = 1
for i in the_path:
	if i == 'L':
		if 'R' in word_set:
			word_set = set()
			counter += 1
	elif i == 'R':
		if 'L' in word_set:
			word_set = set()
			counter += 1
	elif i == 'U':
		if 'D' in word_set:
			word_set = set()
			counter += 1
	elif i == 'D':
		if 'U' in word_set:
			word_set = set()
			counter += 1
	word_set.add(i)
print(counter)


input()
s = input()
c = 1
a = ['0', '0']
if len(s) == 1:
	print(1)
else:
	if s[0] == 'L' or s[0] == 'R':
		a[0] = s[0]
	else:
		a[1] = s[0]
	for i in range(1, len(s)):
		if s[i] == 'R' and a[0] == 'L' or (s[i] == 'L' and a[0] == 'R'):
			c += 1
			a[0] = s[i]
			a[1] = '0'
		elif s[i] == 'U' and a[1] == 'D' or (s[i] == 'D' and a[1] == 'U'):
			c += 1
			a[1] = s[i]
			a[0] = '0'
		elif a[0] == '0' or a[1] == '0':
			if s[i] == 'L' or s[i] == 'R':
				if a[0] == '0':
					a[0] = s[i]
			elif a[1] == '0':
				a[1] = s[i]
	print(c)


(n, s, v, xd, yd) = (int(input()), input(), 1, '-', '-')
for d in s:
	if d == 'U' and yd == 'D' or (d == 'D' and yd == 'U'):
		v += 1
		xd = '-'
	elif d == 'L' and xd == 'R' or (d == 'R' and xd == 'L'):
		v += 1
		yd = '-'
	if d in 'UD':
		yd = d
	else:
		xd = d
print(v)


class Point:
	x = 0
	y = 0

	def __init__(self, new_x, new_y):
		self.x = new_x
		self.y = new_y

def is_shortest(a, b, turn):
	if a.x == b.x and a.y < b.y:
		return not turn[0] and (not turn[1]) and (not turn[3])
	elif a.x > b.x and a.y < b.y:
		return not turn[0] and (not turn[3])
	elif a.x > b.x and a.y == b.y:
		return not turn[0] and (not turn[2]) and (not turn[3])
	elif a.x > b.x and a.y > b.y:
		return not turn[0] and (not turn[2])
	elif a.x == b.x and a.y > b.y:
		return not turn[0] and (not turn[1]) and (not turn[2])
	elif a.x < b.x and a.y > b.y:
		return not turn[1] and (not turn[2])
	elif a.x < b.x and a.y == b.y:
		return not turn[1] and (not turn[2]) and (not turn[3])
	elif a.x < b.x and a.y < b.y:
		return not turn[1] and (not turn[3])
	else:
		return not turn[0] and (not turn[1]) and (not turn[2]) and (not turn[3])
input()
point = 0
turn = [0] * 4
A = Point(0, 0)
B = Point(0, 0)
state = Point(0, 0)
s = input().strip()
i = 0
while i < len(s):
	c = s[i]
	B.x = state.x
	B.y = state.y
	if c == 'R':
		B.x += 1
		turn[0] = 1
	elif c == 'L':
		B.x -= 1
		turn[1] = 1
	elif c == 'U':
		B.y += 1
		turn[2] = 1
	else:
		B.y -= 1
		turn[3] = 1
	if not is_shortest(A, B, turn):
		A.x = state.x
		A.y = state.y
		point += 1
		turn = [0] * 4
	else:
		state.x = B.x
		state.y = B.y
		i += 1
print(point + 1)


import sys
sys.setrecursionlimit(5000000)

def read(type=int):
	return type(input())

def read_arr(type=int):
	return [type(token) for token in input().split()]

def abs(num):
	return num if num > 0 else -num
n = read()
s = read(str)
(u, r) = (0, 0)
cnt = 1
for i in range(len(s)):
	if s[i] == 'L':
		if r == 1:
			cnt += 1
			(r, u) = (0, 0)
		r = -1
	elif s[i] == 'R':
		if r == -1:
			cnt += 1
			(r, u) = (0, 0)
		r = 1
	elif s[i] == 'U':
		if u == -1:
			cnt += 1
			(r, u) = (0, 0)
		u = 1
	else:
		if u == 1:
			cnt += 1
			(r, u) = (0, 0)
		u = -1
print(cnt)


n = int(input())
s = input()
c = ''
x = 0
for i in s:
	if i not in c:
		c += i
	if 'R' in c and 'L' in c or ('U' in c and 'D' in c):
		x += 1
		c = i
print(x + 1 if c else x)


N = int(input())
protokol = input().lower()
protokol = list(protokol)
t_pr = []
k = 0
for i in range(len(protokol)):
	if not protokol[i] in t_pr and len(t_pr) != 2:
		t_pr.append(protokol[i])
	if len(t_pr) == 2 and (t_pr[0] == 'r' and t_pr[1] == 'l' or (t_pr[0] == 'l' and t_pr[1] == 'r') or (t_pr[0] == 'u' and t_pr[1] == 'd') or (t_pr[0] == 'd' and t_pr[1] == 'u')):
		k = k + 1
		t_pr = []
		t_pr.append(protokol[i])
	elif len(t_pr) == 2 and (not protokol[i] in t_pr):
		k = k + 1
		t_pr = []
		t_pr.append(protokol[i])
print(k + 1)


(n, s, cnt, up, down, left, right) = (int(input()), input(), 0, 0, 0, 0, 0)
for i in range(n):
	if s[i] == 'U' and down == 0:
		up = 1
	elif s[i] == 'U' and down == 1:
		cnt += 1
		up = 1
		down = 0
		left = 0
		right = 0
	if s[i] == 'D' and up == 0:
		down = 1
	elif s[i] == 'D' and up == 1:
		cnt += 1
		up = 0
		down = 1
		left = 0
		right = 0
	if s[i] == 'L' and right == 0:
		left = 1
	elif s[i] == 'L' and right == 1:
		cnt += 1
		up = 0
		down = 0
		left = 1
		right = 0
	if s[i] == 'R' and left == 0:
		right = 1
	elif s[i] == 'R' and left == 1:
		cnt += 1
		up = 0
		down = 0
		left = 0
		right = 1
print(cnt + 1)


k = input()
s = input()
side = 0
height = 0
k = 0
for letter in s:
	if letter == 'R':
		if side == 0:
			side = 1
		elif side == 1:
			side = 1
		else:
			k += 1
			side = 1
			height = 0
	if letter == 'L':
		if side == 0:
			side = -1
		elif side == -1:
			side = -1
		else:
			k += 1
			side = -1
			height = 0
	if letter == 'U':
		if height == 0:
			height = 1
		elif height == 1:
			height = 1
		else:
			k += 1
			height = 1
			side = 0
	if letter == 'D':
		if height == 0:
			height = -1
		elif height == -1:
			height = -1
		else:
			k += 1
			height = -1
			side = 0
print(k + 1)


n = int(input())
s = input()
sch = 1
used = [s[0]]
for i in range(1, len(s)):
	if not s[i] in used and (s[i] == 'R' and (not 'L' in used) or (s[i] == 'U' and (not 'D' in used)) or (s[i] == 'L' and (not 'R' in used)) or (s[i] == 'D' and (not 'U' in used))):
		used += s[i]
	elif not s[i] in used:
		sch += 1
		used = s[i]
print(sch)


n = int(input())
s = ' ' + input()
c = 1
(g, v) = (0, 0)
l = len(s)
if l == 1:
	print(c)
else:
	g = min(s.find('L'), s.find('R'))
	v = min(s.find('U'), s.find('D'))
	for i in range(1, l):
		if s[g] == 'L' and s[i] == 'R' or (s[g] == 'R' and s[i] == 'L'):
			c += 1
			g = i
			v = 0
		elif s[v] == 'U' and s[i] == 'D' or (s[v] == 'D' and s[i] == 'U'):
			c += 1
			v = i
			g = 0
		elif v == 0 or g == 0:
			if s[i] == 'L' or s[i] == 'R':
				if g == 0:
					g = i
			elif v == 0:
				v = i
	print(c)


def m():
	res = 0
	input()
	path = input().upper()
	dirs = [None, None]
	for p in path:
		for (ind, chk) in enumerate(('LR', 'UD')):
			if p in chk:
				if dirs[ind] is None:
					dirs[ind] = p
				elif p != dirs[ind]:
					res += 1
					dirs[ind] = p
					dirs[not ind] = None
	print(res + 1)
m()


n = int(input())
S = input()
p = -1
p1 = -1
k = 1
for i in range(n):
	if p == -1 and S[i] == 'R' or (S[i] == 'L' and p == -1):
		p = S[i]
	elif S[i] == 'R' and p != 'R' and (p != -1):
		k = k + 1
		p = S[i]
		p1 = -1
	elif S[i] == 'L' and p != 'L' and (p != -1):
		k = k + 1
		p = S[i]
		p1 = -1
	if p1 == -1 and S[i] == 'U' or (S[i] == 'D' and p1 == -1):
		p1 = S[i]
	elif S[i] == 'U' and p1 != 'U' and (p1 != -1):
		k = k + 1
		p1 = S[i]
		p = -1
	elif S[i] == 'D' and p1 != 'D' and (p1 != -1):
		k = k + 1
		p1 = S[i]
		p = -1
print(k)


N = int(input())
s = input()
se = set()
count = 1
for i in s:
	if not i in se:
		if len(se) == 2:
			count += 1
			se = {i}
		elif len(se) == 0:
			se.add(i)
		elif i == 'L' and 'R' in se:
			count += 1
			se = {i}
		elif i == 'R' and 'L' in se:
			count += 1
			se = {i}
		elif i == 'U' and 'D' in se:
			count += 1
			se = {i}
		elif i == 'D' and 'U' in se:
			count += 1
			se = {i}
		else:
			se.add(i)
print(count)


def opposite(s):
	if s == 'R':
		return 'L'
	elif s == 'L':
		return 'R'
	elif s == 'U':
		return 'D'
	else:
		return 'U'
n = int(input())
string = input()
current = []
k = 1
for i in string:
	if not opposite(i) in current:
		if not i in current:
			current.append(i)
	else:
		k += 1
		current = [i]
print(k)


n = input()
s = input()
iV = 0
iH = 0
c = 0
for i in s:
	if i == 'R':
		if iH == 0:
			iH = 1
			H = 1
		elif H == 0:
			c += 1
			H = 1
			iV = 0
	if i == 'L':
		if iH == 0:
			iH = 1
			H = 0
		elif H == 1:
			c += 1
			H = 0
			iV = 0
	if i == 'U':
		if iV == 0:
			iV = 1
			V = 1
		elif V == 0:
			c += 1
			V = 1
			iH = 0
	if i == 'D':
		if iV == 0:
			iV = 1
			V = 0
		elif V == 1:
			c += 1
			V = 0
			iH = 0
c += 1
print(c)


n = int(input())
s = input()
ans = 0
(x, y) = (0, 0)
(up, down, left, right) = (False, False, False, False)
for i in s:
	if i == 'U':
		up = True
		y += 1
		if down:
			ans += 1
			(down, left, right) = (False, False, False)
	elif i == 'D':
		down = True
		y -= 1
		if up:
			ans += 1
			(up, left, right) = (False, False, False)
	elif i == 'R':
		right = True
		x += 1
		if left:
			ans += 1
			(up, down, left) = (False, False, False)
	elif i == 'L':
		left = True
		x -= 1
		if right:
			ans += 1
			(up, down, right) = (False, False, False)
ans += 1
print(ans)


n = int(input())
line = input()
moves = 'UDLR'
used = dict()
opp = dict()
opp['U'] = 'D'
opp['D'] = 'U'
opp['L'] = 'R'
opp['R'] = 'L'
for i in moves:
	used[i] = 0
i = len(line) - 1
ans = 0
while i >= 0:
	ans += 1
	for j in moves:
		used[j] = 0
	while i >= 0 and (not used[opp[line[i]]]):
		used[line[i]] = 1
		i -= 1
print(ans)


n = int(input())
s = input()
c = 1
direct = []
for a in range(n):
	if s[a] == 'R' and direct.count('L') != 0 or (s[a] == 'U' and direct.count('D') != 0) or (s[a] == 'D' and direct.count('U') != 0) or (s[a] == 'L' and direct.count('R') != 0):
		direct = [s[a]]
		c += 1
	elif direct.count(s[a]) == 0:
		direct += s[a]
print(c)


n = int(input())
s = input()
s = list(s)
(r, l, u, d) = (0, 0, 0, 0)
points = 0
for i in s:
	if i == 'R':
		r = 1
		if l == 1:
			points += 1
			(l, u, d) = (0, 0, 0)
	if i == 'L':
		l = 1
		if r == 1:
			points += 1
			(r, u, d) = (0, 0, 0)
	if i == 'U':
		u = 1
		if d == 1:
			points += 1
			(l, r, d) = (0, 0, 0)
	if i == 'D':
		d = 1
		if u == 1:
			points += 1
			(l, u, r) = (0, 0, 0)
print(points + 1)


n = int(input())
a = input()
prot = dict()
prot['D'] = 'U'
prot['L'] = 'R'
prot['R'] = 'L'
prot['U'] = 'D'
was = set()
ans = 1
for i in range(n):
	if a[i] not in was:
		if len(was) == 0:
			was.add(a[i])
		elif len(was) == 1:
			if prot[a[i]] not in was:
				was.add(a[i])
			else:
				was.clear()
				was.add(a[i])
				ans += 1
		else:
			was.clear()
			was.add(a[i])
			ans += 1
print(ans)


import sys
import os
from io import BytesIO, IOBase
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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]

def exact(num):
	if abs(num - round(num)) <= 10 ** (-9):
		return round(num)
	return num

def solve(n, lst):
	(U, L, R, D) = [0] * 4
	cnt = 0
	for i in lst:
		if i == 'U':
			U += 1
		elif i == 'L':
			L += 1
		elif i == 'R':
			R += 1
		else:
			D += 1
		if U > 0 and D > 0:
			(U, L, R, D) = [0] * 4
			if i == 'U':
				U = 1
			else:
				D = 1
			cnt += 1
		elif R > 0 and L > 0:
			(U, L, R, D) = [0] * 4
			if i == 'L':
				L = 1
			else:
				R = 1
			cnt += 1
	return cnt + 1
n = int(input())
lst = input()
print(solve(n, lst))


n = int(input())
s = input()
cur = 0
su = 0
while cur != n:
	q = set()
	flag = 0
	while cur != n and flag == 0:
		if s[cur] == 'R' and 'L' not in q:
			q.add('R')
			cur += 1
		elif s[cur] == 'L' and 'R' not in q:
			q.add('L')
			cur += 1
		elif s[cur] == 'U' and 'D' not in q:
			q.add('U')
			cur += 1
		elif s[cur] == 'D' and 'U' not in q:
			q.add('D')
			cur += 1
		else:
			flag = 1
		if cur == n:
			flag = 1
	su += 1
print(su)


n = int(input())
s = input()
answ = 1
buf = ''
for i in range(n):
	if s[i] in buf:
		continue
	elif s[i] == 'U' and buf.count('D') > 0 or (s[i] == 'D' and buf.count('U') > 0) or (s[i] == 'R' and buf.count('L') > 0) or (s[i] == 'L' and buf.count('R') > 0):
		buf = s[i]
		answ += 1
	elif s[i] == 'U' and buf.count('D') == 0 or (s[i] == 'D' and buf.count('U') == 0) or (s[i] == 'R' and buf.count('L') == 0) or (s[i] == 'L' and buf.count('R') == 0):
		buf += s[i]
print(answ)


import sys
data = sys.stdin.readlines()
n = int(data[0].strip())
path = data[1].strip()
deg_new = path[0]
deg_old = path[0]
flag = 0
count = 0
vert = set('UD')
gor = set('RL')
for i in path:
	if i == deg_new:
		continue
	elif i in vert and deg_new in vert or (i in gor and deg_new in gor):
		deg_new = i
		deg_old = i
		flag = 0
		count = count + 1
	elif flag:
		if i == deg_old:
			deg_old = deg_new
			deg_new = i
		else:
			deg_new = i
			deg_old = i
			flag = 0
			count = count + 1
	else:
		deg_new = i
		flag = 1
print(count + 1)


input()
opposites = {'R': 'L', 'L': 'R', 'U': 'D', 'D': 'U'}
protocol = input()
old_movement = ''
answer = 0
for i in protocol:
	if len(old_movement) == 0:
		old_movement = i
		answer += 1
	elif len(set(old_movement)) == 1:
		if opposites[old_movement[-1]] == i:
			answer += 1
			old_movement = i
		else:
			old_movement += i
	elif i not in old_movement:
		old_movement = i
		answer += 1
print(answer)


n = int(input())
sost = now = ''
res = 0
cond = {'UR', 'RD', 'DL', 'LU', 'RU', 'DR', 'LD', 'UL'}
for i in input():
	now += i
	if len(now) == 1:
		continue
	if len(now) == 2:
		if now[1] == now[0]:
			now = now[1:]
			continue
		if now in cond:
			if sost != '' and (sost[:] != now and sost[-1::-1] != now):
				res += 1
				sost = ''
				now = now[1:]
			else:
				sost = now
				now = now[1:]
		else:
			res += 1
			sost = ''
			now = now[1:]
print(res + 1)


n = int(input())
s = input()
inv = {'L': 'R', 'R': 'L', 'D': 'U', 'U': 'D'}
res = 1
i = 0
t = set()
while i < len(s):
	d = s[i]
	if inv[d] in t:
		res += 1
		t = set()
	t.add(d)
	i += 1
print(res)


n = int(input())
s = input()
a = []
l = 1
for i in range(n):
	if len(a) < 2 and (not s[i] in a):
		if not 'U' in a and s[i] == 'D' or (not 'D' in a and s[i] == 'U') or (not 'R' in a and s[i] == 'L') or (not 'L' in a and s[i] == 'R'):
			a.append(s[i])
		else:
			l += 1
			a = []
			a.append(s[i])
	elif not s[i] in a:
		l += 1
		a = []
		a.append(s[i])
print(l)


import sys
input = sys.stdin.readline
n = int(input())
if n == 1:
	print(1)
else:
	count = 1
	path = input()
	direc1 = 'LR'
	direc2 = 'UD'
	move1 = [False, False]
	move2 = [False, False]
	for i in range(n):
		x = path[i]
		if x in direc1:
			move1[direc1.index(x)] = True
		else:
			move2[direc2.index(x)] = True
		if all(move1) or all(move2):
			move1 = [False, False]
			move2 = [False, False]
			count += 1
			if x in direc1:
				move1[direc1.index(x)] = True
			else:
				move2[direc2.index(x)] = True
	print(count)


n = int(input())
s = str(input())
k = 1
move = {'R': 'L', 'L': 'R', 'U': 'D', 'D': 'U'}
plus = set()
for i in s:
	if i in plus:
		plus.clear()
		k += 1
	plus |= {move[i]}
print(k)


n = int(input())
moves = input()
rev = {'R': 'L', 'U': 'D', 'L': 'R', 'D': 'U'}
seen = set()
min_pts = 1
for move in moves:
	if rev[move] in seen:
		min_pts += 1
		seen = set()
	seen.add(move)
print(min_pts)


import collections

def distance(direction):
	return abs(direction['R'] - direction['L']) + abs(direction['U'] - direction['D'])

def relative_distance(direction, prev_direction):
	return abs(abs(direction['R'] - prev_direction['R']) - abs(direction['L'] - prev_direction['L'])) + abs(abs(direction['U'] - prev_direction['U']) - abs(direction['D'] - prev_direction['D']))
number = int(input())
direction = collections.Counter()
prev_direction = collections.Counter()
movements = input()
prev_num_movements = 0
count = 0
for i in range(number):
	direction[movements[i]] += 1
	num_movements = i + 1 - prev_num_movements
	curr_distance = relative_distance(direction, prev_direction)
	if num_movements - curr_distance != 0:
		count += 1
		prev_num_movements = i
		prev_direction['R'] = direction['R']
		prev_direction['L'] = direction['L']
		prev_direction['U'] = direction['U']
		prev_direction['D'] = direction['D']
		prev_direction[movements[i]] -= 1
count += 1
print(count)


def gg(v):
	if v == 'R':
		return (0, 1)
	if v == 'L':
		return (0, -1)
	if v == 'U':
		return (1, 0)
	return (-1, 0)
n = int(input())
seq = input()
ans = 1
(x, y) = (0, 0)
(prevx, prevy) = (0, 0)
(opx, opy) = (0, 0)
(stx, sty) = (0, 0)
for i in seq:
	(prevx, prevy) = (x, y)
	hh = gg(i)
	x += hh[0]
	y += hh[1]
	opx += abs(hh[0])
	opy += abs(hh[1])
	if opx != abs(x) or opy != abs(y) or ((opx > 0 or opy > 0) and x == stx and (y == sty)):
		ans += 1
		(x, y) = (x - prevx, y - prevy)
		opx = abs(hh[0])
		opy = abs(hh[1])
		(stx, sty) = (prevx, prevy)
print(ans)


input()
path = input()
(LastVert, LastHor) = (None, None)
col = 1
i = 0
while i < len(path):
	c = path[i]
	if c in 'UD':
		if LastVert == None:
			LastVert = c
		elif c != LastVert:
			(LastVert, LastHor) = (None, None)
			col += 1
			i -= 1
	if c in 'LR':
		if LastHor == None:
			LastHor = c
		elif c != LastHor:
			(LastVert, LastHor) = (None, None)
			col += 1
			i -= 1
	i += 1
print(col)


import sys
input = sys.stdin.readline
start = cur = (0, 0)
steps = 0
result = 0
n = int(input())
for char in input().rstrip():
	steps += 1
	(r, c) = cur
	(sr, sc) = start
	prev = cur
	if char == 'R':
		c += 1
	elif char == 'L':
		c -= 1
	elif char == 'U':
		r += 1
	else:
		r -= 1
	cur = (r, c)
	if abs(sr - r) + abs(sc - c) == steps:
		continue
	else:
		start = prev
		steps = 1
		result += 1
print(result + 1)


n = int(input())
s = list(input())
w = []
pos = 0
res = 1
go = set()
for i in s:
	if i == 'L':
		w.append(1)
	elif i == 'R':
		w.append(-1)
	elif i == 'U':
		w.append(2)
	else:
		w.append(-2)
go.add(w[0])
while pos < n:
	if -w[pos] in go:
		res += 1
		go = set()
		go.add(w[pos])
	else:
		go.add(w[pos])
	pos += 1
print(res)


import sys
input = sys.stdin.readline
amount = int(input())
path = list(input())
d = l = ''
count = 0
for i in path:
	if i == 'R' and l == 'L' or (i == 'L' and l == 'R') or (i == 'U' and d == 'D') or (i == 'D' and d == 'U'):
		d = 'a'
		l = d
		count += 1
	if i == 'R' or i == 'L':
		l = i
	else:
		d = i
print(count + 1)


n = int(input())
string = input()
res = []
r = 0
for i in string:
	if i not in res:
		if len(res) == 2 or len(res) == 0:
			res = [i]
			r += 1
		elif res[0] in ('U', 'D') and i in ('L', 'R') or (i in ('U', 'D') and res[0] in ('L', 'R')):
			res.append(i)
		else:
			res = [i]
			r += 1
print(r)


import sys
import pickle
input = sys.stdin.readline
n = int(input())
d = list(input().strip())
s = 1
c = []
for i in d:
	if i in c:
		s += 1
		c = []
	if i == 'R':
		if 'L' not in c:
			c.append('L')
	elif i == 'L':
		if 'R' not in c:
			c.append('R')
	elif i == 'U':
		if 'D' not in c:
			c.append('D')
	elif i == 'D':
		if 'U' not in c:
			c.append('U')
print(s)


n = int(input())
s = input()
xcnt = 1
what = set()
for i in s:
	if i == 'L' and 'R' in what or (i == 'R' and 'L' in what) or (i == 'U' and 'D' in what) or ('D' == i and 'U' in what):
		what = set()
		xcnt += 1
	what.add(i)
print(xcnt)


import sys
input = sys.stdin.readline
n = int(input())
S = input()[:-1]
s = set()
ans = 0
for i in range(n):
	if S[i] == 'L' and 'R' in s:
		ans += 1
		s = set()
	if S[i] == 'R' and 'L' in s:
		ans += 1
		s = set()
	if S[i] == 'U' and 'D' in s:
		ans += 1
		s = set()
	if S[i] == 'D' and 'U' in s:
		ans += 1
		s = set()
	s.add(S[i])
ans += 1
print(ans)


import sys
import math
import collections
import heapq
import decimal
input = sys.stdin.readline
n = int(input())
s = input()
s1 = set()
c = 0
for i in range(n):
	s1.add(s[i])
	if len(s1) == 3:
		c += 1
		s1 = set([s[i]])
	elif s[i] == 'L' and 'R' in s1 or (s[i] == 'R' and 'L' in s1) or (s[i] == 'U' and 'D' in s1) or (s[i] == 'D' and 'U' in s1):
		c += 1
		s1 = set([s[i]])
print(c + 1)


n = int(input())
s = str(input())
c = 1
move = {'R': 'L', 'L': 'R', 'U': 'D', 'D': 'U'}
cant = set()
for i in s:
	if i in cant:
		cant.clear()
		c += 1
	cant = cant | {move[i]}
print(c)


a = int(input())
s = input()
t = 1
ch = ''
for x in range(a):
	if s[x] == 'L' and 'R' in ch or (s[x] == 'R' and 'L' in ch) or (s[x] == 'U' and 'D' in ch) or (s[x] == 'D' and 'U' in ch):
		t += 1
		ch = s[x]
	else:
		ch += '' if s[x] in ch else s[x]
print(t)


n = int(input())
a = input()
s = set()
ans = 0
for j in range(n):
	if a[j] == 'R':
		if 'L' in s:
			ans += 1
			s = set()
		s.add(a[j])
	elif a[j] == 'L':
		if 'R' in s:
			ans += 1
			s = set()
		s.add(a[j])
	elif a[j] == 'U':
		if 'D' in s:
			ans += 1
			s = set()
		s.add(a[j])
	elif a[j] == 'D':
		if 'U' in s:
			ans += 1
			s = set()
		s.add(a[j])
print(ans + 1)


n = int(input())
s = input()
r = False
u = False
d = False
l = False
res = 1
for i in s:
	if (i == 'R') & (l == True):
		res += 1
		l = False
		r = True
		u = False
		d = False
		continue
	elif i == 'R':
		r = True
		continue
	if (i == 'L') & (r == True):
		res += 1
		r = False
		l = True
		u = False
		d = False
		continue
	elif i == 'L':
		l = True
		continue
	if (i == 'U') & (d == True):
		res += 1
		d = False
		u = True
		r = False
		l = False
		continue
	elif i == 'U':
		u = True
		continue
	if (i == 'D') & (u == True):
		res += 1
		u = False
		d = True
		r = False
		l = False
		continue
	elif i == 'D':
		d = True
		continue
print(res)


n = int(input())
s = input()
k = 1
x = 0
y = 0
d00 = 0
d0 = 0
d = 0
xc = 0
yc = 0
x0 = 0
y0 = 0
for i in range(n):
	x0 = x
	y0 = y
	if s[i] == 'R':
		x += 1
	elif s[i] == 'L':
		x -= 1
	elif s[i] == 'U':
		y += 1
	elif s[i] == 'D':
		y -= 1
	d00 = d0
	d0 = d
	d = ((x - xc) ** 2 + (y - yc) ** 2) ** (1 / 2)
	if d0 != d00 and (d0 - d00) * (d0 - d) > 0:
		k += 1
		xc = x0
		yc = y0
		d00 = 0
		d0 = 0
		d = ((x - xc) ** 2 + (y - yc) ** 2) ** (1 / 2)
print(k)


a = int(input())
b = input()
c = []
k = 1
for i in range(a):
	if b[i] == 'R' and 'L' in c or (b[i] == 'L' and 'R' in c) or (b[i] == 'U' and 'D' in c) or (b[i] == 'D' and 'U' in c):
		c = []
		k += 1
		c.append(b[i])
	if not b[i] in c:
		c.append(b[i])
print(k)


n = int(input())
s = input()
v = ''
g = ''
ans = 1
for i in s:
	if (i == 'U' or i == 'D') and v == '':
		v = i
		continue
	if (i == 'R' or i == 'L') and g == '':
		g = i
		continue
	if (i == 'U' or i == 'D') and i != v:
		ans += 1
		v = i
		g = ''
		continue
	if (i == 'R' or i == 'L') and i != g:
		ans += 1
		g = i
		v = ''
		continue
print(ans)


a = int(input())
s = input()
count = 0
m1 = '0'
m2 = '0'
for i in range(len(s)):
	if m1 == '0' and m2 == '0':
		m1 = s[i]
	if m1 != s[i] and m2 != s[i] and (m1 != '0') and (m2 != '0'):
		count += 1
		m1 = s[i]
		m2 = '0'
	elif (m1 != s[i] and m2 != s[i]) and (m1 != '0' and m2 == '0'):
		m2 = s[i]
	if m1 == 'R' and m2 == 'L' or (m1 == 'L' and m2 == 'R') or (m1 == 'U' and m2 == 'D') or (m1 == 'D' and m2 == 'U'):
		count += 1
		m1 = s[i]
		m2 = '0'
if len(s) == 1:
	print(1)
else:
	print(count + 1)


n = int(input())
s = input()
kl = 0
kr = 0
kd = 0
ku = 0
x = 0
y = 0
kol = 1
for i in range(n):
	if s[i] == 'R':
		kr += 1
		if abs(kr - kl) < x:
			kol += 1
			kr = 1
			kl = 0
			ku = 0
			kd = 0
			x = 1
			y = 0
		else:
			x += 1
	elif s[i] == 'L':
		kl += 1
		if abs(kr - kl) < x:
			kol += 1
			kr = 0
			kl = 1
			ku = 0
			kd = 0
			x = 1
			y = 0
		else:
			x += 1
	elif s[i] == 'D':
		kd += 1
		if abs(ku - kd) < y:
			kol += 1
			kr = 0
			kl = 0
			ku = 0
			kd = 1
			y = 1
			x = 0
		else:
			y += 1
	elif s[i] == 'U':
		ku += 1
		if abs(ku - kd) < y:
			kol += 1
			kr = 0
			kl = 0
			ku = 1
			kd = 0
			y = 1
			x = 0
		else:
			y += 1
print(kol)


n = int(input())
s = input()
u = 0
d = 0
l = 0
r = 0
p = 1
i = 0
while i != n:
	if s[i] == 'U':
		u += 1
	if s[i] == 'D':
		d += 1
	if s[i] == 'L':
		l += 1
	if s[i] == 'R':
		r += 1
	if u > 0 and d > 0:
		p += 1
		i += -1
		u = 0
		d = 0
		l = 0
		r = 0
	if l > 0 and r > 0:
		p += 1
		i += -1
		u = 0
		d = 0
		l = 0
		r = 0
	i += 1
print(p)


slov = {'U': 'D', 'D': 'U', 'L': 'R', 'R': 'L'}
stroka = ''
otvet = 0
chet1 = 0
chet2 = 0
n = int(input())
st = input()
for i in range(n):
	bukv = st[i]
	if bukv == 'U':
		chet1 += 1
	elif bukv == 'D':
		chet1 -= 1
	elif bukv == 'R':
		chet2 += 1
	elif bukv == 'L':
		chet2 -= 1
	if slov[bukv] in stroka:
		otvet += 1
		stroka = ''
		stroka += bukv
	elif bukv not in stroka:
		stroka += bukv
print(otvet + 1)


n = int(input())
s = input()
mh = ''
mv = ''
count = 0
for e in s:
	if mv == '' and e in ('U', 'D'):
		mv = e
	if mh == '' and e in ('L', 'R'):
		mh = e
	if e in ('U', 'D'):
		if e != mv:
			count += 1
			mv = e
			mh = ''
	if e in ('L', 'R'):
		if e != mh:
			count += 1
			mh = e
			mv = ''
print(count + 1)


moves = dict([('R', (+1, 0)), ('D', (0, -1)), ('L', (-1, 0)), ('U', (0, +1))])

def main():
	n = int(input())
	steps = input().strip()
	(x, y) = (0, 0)
	(p_x, p_y) = (0, 0)
	(g_x, g_y) = (0, 0)
	ans = 0
	c = 0
	for i in range(len(steps)):
		q = steps[i]
		(p_x, p_y) = (x, y)
		(x, y) = (x + moves[q][0], y + moves[q][1])
		c += 1
		if i == 0:
			ans += 1
			continue
		s = abs(x - g_x) + abs(y - g_y)
		if c > s:
			(g_x, g_y) = (p_x, p_y)
			ans += 1
			c = 0
	print(ans)
main()


M = int(input())
S = input()
anticmd = {'L': 'R', 'R': 'L', 'U': 'D', 'D': 'U'}
k = 0
stop = set()
for i in range(M):
	c = S[i]
	if c in stop:
		k += 1
		stop = set()
	stop.add(anticmd[c])
k += 1
print(k)


n = int(input())
point = ['', '']
count = 1
pairs = {'r': 'l', 'l': 'r', 'u': 'd', 'd': 'u', '': ''}
for i in input().lower():
	if point[0] == '':
		point[0] = i
	else:
		if i == pairs[point[0]] or i == pairs[point[1]]:
			point = ['', '']
			count += 1
			point[0] = i
			continue
		if point[1] == '' and point[0] != i:
			point[1] = i
print(count)