Role fight P67356


Statement
 

pdf   zip

thehtml

Consider a role-playing game where two brave players are fighting for their honor. Initially, each player has some life points and some mana points. Taking turns, one player attacks the other one. Each player has several magical abilities that take some life points from the enemy, with a specific mana cost for each ability. Logically, choosing an ability requires having enough mana points. When attacking with no magic, the enemy loses one life point and the attacker recovers five mana points (with one bound: the initial mana). The player who first loses all his life points loses the game.



Write a program to tell the winner of a game, assuming perfect play from both players.

Input

Input consists of several cases. Every case begins with the name and the initial life points and mana points of the first player, followed by the same information about the second player. Follow the number n of abilities of the first player, followed by n numbers (the damage of each one), followed by n numbers (the mana cost of each one). Finally, we have the same information about the second player. Suppose that every player has at most 50 magical abilities, and that the initial life points, the initial mana points, the damage of every ability, and the mana cost of every ability are all between 1 and 30.

Output

For every case, print the name of the winner of the game.

Public test cases
  • Input

    A 5 1
    B 5 30
    0
    0
    
    A 5 20
    B 6 30
    1  30  21
    0
    
    Corki 30 30
    Twitch 30 30
    3   1 2 3   1 2 3
    3   1 2 3   1 2 3
    
    Tryndamere 30 30 
    Garen 30 30
    3   1 2 3   1 2 3
    3   1 2 29  1 2 30
    
    Annie  12 23 
    Ryze   13 25
    3    30 30 30   1 10 24
    3    30 29 28   23 24 1
    

    Output

    A
    B
    Corki
    Garen
    Annie
    
  • Information
    Author
    Enric Cusell
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++