A higher resolution is required to access the IDE
- 1704
Learning Opportunities
This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.
Statement
Goal
A gang of R foolish robbers decides to heist a bank. In the bank there are V vaults (indexed from- The combination of a vault is composed of C characters (digits/vowels).
- The first N characters consist of digits from
- The remaining characters consist of vowels (
- C and N may be the same or different for different vaults.
All the robbers work at the same time. A robber can work on one vault at a time, and a vault can be worked on by only one robber. Robbers deal with the different vaults in increasing order.
A robber tries the combinations at the speed of
Assume it takes no time to move from one vault to another.
You have to output the total time the heist takes.
Input
Line 1: An integer R for the number of robbers.
Line 2: An integer V for the number of vaults.
Next V lines: For each vault, one line of two space-separated integers C and N for the total number of characters (C) and the total number of digits (N) in the vault's combination. The vaults are ordered by their index.
Line 2: An integer V for the number of vaults.
Next V lines: For each vault, one line of two space-separated integers C and N for the total number of characters (C) and the total number of digits (N) in the vault's combination. The vaults are ordered by their index.
Output
Line 1: An integer for the total time the heist takes in seconds.
Constraints
1 ≤ R ≤ 5
1 ≤ V ≤ 20
3 ≤ C ≤ 8
0 ≤ N ≤ C
1 ≤ V ≤ 20
3 ≤ C ≤ 8
0 ≤ N ≤ C
Example
Input
1 1 3 1
Output
250
A higher resolution is required to access the IDE