LearnPy Hub
← Arena
AdvancedRating 1700

LRU Cache

Simulate an LRU cache of capacity c with commands get k (print the value or -1) and put k v. When full, putting a new key evicts the least recently used key.

Input

c, n, then n commands.

Output

Answers to get.

Sample 1

Input
2
9
put 1 1
put 2 2
get 1
put 3 3
get 2
put 4 4
get 1
get 3
get 4
Output
1
-1
-1
3
4

Sample 2

Input
1
3
put a x
put b y
get a
Output
-1
solution.py
Output appears here
LRU Cache · Python Arena problem · LearnPy Hub