#K3061. Unique Positions Visited
Unique Positions Visited
Unique Positions Visited
You are given an integer n and a string moves of length n consisting only of the characters L
and R
. The moves indicate steps from an initial position 0 on a number line. A move of L
decreases the current position by 1, whereas a move of R
increases it by 1.
Your task is to compute the number of unique positions visited during the sequence of moves, including the starting position.
Formally, if you denote the initial position as \( p_0 = 0 \) and subsequent positions as \( p_i \), where \( p_i = p_{i-1} - 1 \) if the \( i \)-th move is L
or \( p_i = p_{i-1} + 1 \) if it is R
, then you need to determine the cardinality of the set \( \{p_0, p_1, \dots, p_n\} \).
inputFormat
The input is provided via standard input and consists of two lines:
- The first line contains an integer n — the length of the moves string.
- The second line contains a string moves of length n composed solely of the characters
L
andR
.
outputFormat
Output a single integer on standard output — the number of unique positions visited at least once.
## sample8
LLRRLRRL
4