888B.md (1640B)
1 Source: https://codeforces.com/problemset/problem/888/B 2 3 B. Buggy Robot 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0, 0). The robot can process commands. There are four types of commands it can perform: 22 23 * U — move from the cell (*x*, *y*) to (*x*, *y* + 1); 24 * D — move from (*x*, *y*) to (*x*, *y* - 1); 25 * L — move from (*x*, *y*) to (*x* - 1, *y*); 26 * R — move from (*x*, *y*) to (*x* + 1, *y*). 27 28 Ivan entered a sequence of *n* commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0, 0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations! 29 30 Input 31 32 The first line contains one number *n* — the length of sequence of commands entered by Ivan (1 ≤ *n* ≤ 100). 33 34 The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R. 35 36 Output 37 38 Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. 39 40 Examples 41 42 Input 43 44 ``` 45 4 46 LDUR 47 ``` 48 49 Output 50 51 ``` 52 4 53 ``` 54 55 Input 56 57 ``` 58 5 59 RRRUU 60 ``` 61 62 Output 63 64 ``` 65 0 66 ``` 67 68 Input 69 70 ``` 71 6 72 LLRRRR 73 ``` 74 75 Output 76 77 ``` 78 4 79 ```