commandsChars = {
"U": "+y",
"D": "-y",
"R": "+x",
"L": "-x"
}
countOfCommands = int(input())
commandsString = input()
commands = []
class Robot():
def __init__(self) -> None:
self.x = 0
self.y = 0
def Move(self, coord: str):
if coord == "+x":
self.x += 1
elif coord == "-x":
self.x -= 1
elif coord == "+y":
self.y += 1
else:
self.y -= 1
def isInZeroZero(self):
if self.x == 0 and self.y == 0:
return True
else:
return False
def Restart(self):
self.x = 0
self.y = 0
class Vault():
def __init__(self) -> None:
self.paths = []
def Add(self, path: list):
self.paths.append(path)
robot = Robot()
pathsVault = Vault()
for command in commandsString:
commands.append(commandsChars[command])
for firstElementIndex in range(0, countOfCommands):
for secondElement in range(firstElementIndex, countOfCommands):
secondElementIndex = countOfCommands - secondElement - 1
nowCommands = commands[firstElementIndex:secondElement + 1]
if len(nowCommands) > 1:
for element in nowCommands:
robot.Move(element)
if robot.isInZeroZero() == True:
pathsVault.Add(element)
robot.Restart()
for firstElementIndex in range(0, countOfCommands):
for secondElementIndex in range(firstElementIndex, countOfCommands):
nowCommands = command[firstElementIndex:secondElementIndex]
if len(nowCommands) > 1:
for element in nowCommands:
robot.Move(element)
if robot.isInZeroZero() == True:
pathsVault.Add(element)
robot.Restart()
print(len(pathsVault.paths))
729D - Sea Battle | 788A - Functions again |
1245B - Restricted RPS | 1490D - Permutation Transformation |
1087B - Div Times Mod | 1213B - Bad Prices |
1726B - Mainak and Interesting Sequence | 1726D - Edge Split |
1726C - Jatayu's Balanced Bracket Sequence | 1726A - Mainak and Array |
1613C - Poisoned Dagger | 475B - Strongly Connected City |
652B - z-sort | 124B - Permutations |
1496C - Diamond Miner | 680B - Bear and Finding Criminals |
1036E - Covered Points | 1015D - Walking Between Houses |
155B - Combination | 1531A - Зингер | color |
1678A - Tokitsukaze and All Zero Sequence | 896A - Nephren gives a riddle |
761A - Dasha and Stairs | 1728B - Best Permutation |
1728A - Colored Balls Revisited | 276B - Little Girl and Game |
1181A - Chunga-Changa | 1728C - Digital Logarithm |
1728D - Letter Picking | 792B - Counting-out Rhyme |