Limits
1s, 512 MB
Data structure is one of your favourite topics, isn't it? Let’s design a new data structure!
In this new data structure, there will be a list and some operations.
The operations are :
- Insert Front X — Insert X into the front of the list.
- Insert Back X — Insert X into the back of the list.
- Erase Front — Erase the first element of the list.
- Erase Back — Erase the last element of the list.
- Get Front — Print the first element of the list.
- Get Back — Print the last element of the list.
- Get Max — Print the maximum element of the list.
- Get Min — Print the minimum element of the list.
You need to design a data structure as described above and perform Q operations.
Input
The first line of the input will contain a single integer Q, denoting the number of operation.
The next Q lines will contain any of those operations described above.
Constraints
1 ≤ Q ≤ 10^5
1 ≤ X ≤ 10^6
Output
Perform each operation as described in the problem statement.
Sample
Input | Output |
---|
8
Insert Back 8
Get Front
Insert Front 9
Get Max
Erase Back
Insert Back 3
Get Back
Get Min | 8
9
3
3 |
Assume that, every operation will be valid.
Factors
| CPU | Memory | Source |
---|
Bash 5.2 | 1× | 1× | 1× |
Brainf*ck | 1× | 1× | 1× |
C# Mono 6.0 | 1× | 1× | 1× |
C++17 GCC 13.2 | 1× | 1× | 1× |
C++20 Clang 16.0 | 1× | 1× | 1× |
C++20 GCC 13.2 | 1× | 1× | 1× |
C++23 GCC 13.2 | 1× | 1× | 1× |
C11 GCC 13.2 | 1× | 1× | 1× |
C17 GCC 13.2 | 1× | 1× | 1× |
C23 GCC 13.2 | 1× | 1× | 1× |
Common Lisp SBCL 2.0 | 1× | 1× | 1× |
D8 11.8 | 1× | 1× | 1× |
Erlang 22.3 | 1× | 1× | 1× |
Free Pascal 3.0 | 1× | 1× | 1× |
Go 1.22 | 1× | 1× | 1× |
Grep 3.7 | 1× | 1× | 1× |
Haskell 8.6 | 1× | 1× | 1× |
Java 1.8 | 1× | 1× | 1× |
Kotlin 1.1 | 1× | 1× | 1× |
Lua 5.4 | 1× | 1× | 1× |
Node.js 10.16 | 1× | 1× | 1× |
Perl 5.30 | 1× | 1× | 1× |
PHP 8.3 | 1× | 1× | 1× |
PyPy 7.1 (3.6) | 1× | 1× | 1× |
Python 3.12 | 1× | 1× | 1× |
Ruby 3.2 | 1× | 1× | 1× |
Rust 1.57 | 1× | 1× | 1× |
Swift 5.3 | 1× | 1× | 1× |
Whitespace | 1× | 1× | 1× |