FALTAENV  Falta Envido
Envido is an important part of the typical argentinian game Truco. It is even more important
when Falta Envido is called, because in this case the winner of the Envido wins the entire game.
In this problem you are asked to calculate the envido advantage of a cheater.
Truco is played with a limited deck of spanish cards. This deck contains four suits: espada,
basto, copa and oro. There are 10 cards of each suit: 1, 2, 3, 4, 5, 6, 7, 10, 11 and 12. Cards
10, 11 and 12 have an envido value of 0, while the envido value for any of the other cards is
simply its number. Each player holds three cards. The winner of an Envido is the player with
the higher envido score. When calculating his envido score each player can either:
1. select a single card and have as envido score the envido value of the card; or
2. select two cards of the same suit and have as envido score 20 plus the sum of the envido
value of each selected card.
Players always select the card or cards that yield the highest envido score. For instance, a
player having a 10 and a 2 of the same suit, together with a 5 of a different suit, would inform
an envido score of 22 because 20 + 0 + 2 = 22.
A cheater playing Truco thinks that he can change one of his three cards without anybody else
in the table noticing. If he changes more than one card, he surely will be discovered, so he does
not do that. Since even changing one card is risky, he only does it when the envido score of the
resulting hand is much higher than the one of his original hand.
Given the cards the cheater has in hand, you must calculate the maximum increase he can get
in the envido score by exchanging one of his cards with a card from the deck. Notice that the
resulting hand must be formed by two of his original cards and one new card selected from the
deck, and that he cannot have two equal cards (same number and suit).
Input
The input contains several test cases. Each test case is described in a single line that contains
six values N1 , S1 , N2 , S2 , N3 , and S3 separated by single spaces. Each pair (Ni , Si ) describes
a card in the hand of the cheater (1 ≤ i ≤ 3), where Ni is the number of the card (1, 2, 3, 4,
5, 6, 7, 10, 11 or 12), and Si is its suit (espada, basto, copa or oro). You may assume that the
three cards are different. The last line of the input contains three times the number −1 and an
asterisk, with the six values separated by single spaces, and should not be processed as a test
case.
Output
For each test case output a single line with an integer representing the maximum increase in
the envido score that can be obtained by replacing exactly one card of the input hand.
Example
Input:
12 espada 10 basto 11 basto
7 espada 1 oro 2 oro
7 espada 1 oro 6 espada
1 * 1 * 1 *
Output: 7
10
0
hide comments
nadstratosfer:
20171028 06:17:20
I like this kind of problems very much  no algo for it to be found in CLRS, just figure out the logic and make sure your implementation follows it. Commented code and sensible variable names help getting it right. 

game2712:
20120815 10:09:24
hey prabhat what was the silly mistake ?


♘Prabhat:
20120620 17:23:58
i had done silly mistake finally got AC :) after lots of WA 

♘Prabhat:
20120523 05:56:44
@aman 27 

♘Prabhat:
20120523 05:55:17
easy but i don'nt know why i am getting WA pls give me any critical test case 

Aman Choudhary:
20120522 11:47:52
getting wrong answer.

Added by:  Pablo Ariel Heiber 
Date:  20100819 
Time limit:  0.474s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: NODEJS OBJC PERL6 VB.NET 
Resource:  FCEyN UBA ICPC Selection 2008 