Under construction

Still being built. Things may change

Tier and Rank

Time limit1sMemory limit256 MB

Summary
Given tiers that split N ranked users into tiers and subtiers, find the min and max rank a bragged tier can have, or report invalid or liar.
Level

Medium6 of 10

Topics
Implementation, Math, Simulation
Solved
No attempts yet

Problem

Seongeun entered university. She never played games herself, but her friends kept bragging about their tiers in the popular game "Legend Legend", and she grew curious. A tier is a rating system that reflects a player's skill, based on the player's rank. When the game has NN users, their ranks are distinct integers from 11 to NN.

The tier assignment process is recursive. Among the users who do not have a tier yet, the highest-ranked users are assigned the top tier first, and the remaining users move on to the lower tiers. Depending on how the top users are selected, a tier is either a fixed tier or a relative tier. When MM users still have no tier, each tier accepts the following number of users.

  • Fixed tier accepting KK users: min⁡(M,K)\min(M, K)
  • Relative tier accepting KK%: ⌊M×K100⌋\lfloor \frac{M \times K}{100} \rfloor (⌊x⌋\lfloor x \rfloor is the greatest integer less than or equal to xx)

From the top tier down, each tier takes the number of users it accepts, and the process moves on to the next tier. If some users still have no tier after every tier is processed, the system is invalid.

Each tier is split into four subtiers to separate players within the same tier. Each subtier is named by appending 1, 2, 3, or 4 to the tier name, and a smaller number means a higher subtier. If a tier has LL users, each subtier accepts at most ⌈L4⌉\lceil \frac{L}{4} \rceil users. Users are placed in rank order, starting from the highest subtier and filling each one to its maximum before moving to the next.

Input

The first line contains the number of users NN and the number of tiers TT, separated by a space. (1≤N≤1091 \leq N \leq 10^{9}, 1≤T≤1031 \leq T \leq 10^{3})

From the second line through the (T+1)(T+1)-th line, the tier information is given from the top tier down. Each tier name is a string of up to 10001000 English letters, uppercase or lowercase, and all tier names are different.

  • Fixed tier: the tier name and the maximum number of users KK it accepts, separated by a space. (0≤K≤N0 \leq K \leq N)
  • Relative tier: the tier name, a space, and a percentage in the form "KK%". KK is the percentage of the users who still have no tier at the moment this tier is assigned. (0≤K≤1000 \leq K \leq 100)

The last line gives the tier (or subtier) that the friend bragged about. It is either a tier name alone, or a tier name followed directly by a digit from 1 to 4.

Output

If the tier system cannot assign a tier to every user, print Invalid System on the first line. Otherwise, if the friend's tier cannot be a real user's tier in this system, print Liar. If the system is valid and the friend's tier is possible, print the minimum and maximum rank the friend can have, separated by a space, in that order.

Examples3

  1. Example 1

    Input
    100 3
    Challenger 10
    Master 50%
    Diamond 45
    Master4
    
    Expected output
    47 55
    
  2. Example 2

    Input
    100 3
    Challenger 10
    Master 45
    Diamond 99%
    Diamond
    
    Expected output
    Invalid System
    
  3. Example 3

    Input
    1000 4
    InternationalGrandmaster 3
    Grandmaster 7
    Master 10%
    Expert 100%
    InternationalGrandmaster4
    
    Expected output
    Liar