MJLAR10 - Jollo

no tags 

 

 

 

 

 

English Vietnamese

 

 

 

 

Gene and Gina have a particular kind of farm. Instead of growing animals and vegetables, as
it is usually the case in regular farms, they grow strings. A string is a sequence of characters.
Strings have the particularity that, as they grow, they add characters to the left and/or to the
right of themselves, but they never lose characters, nor insert new characters in the middle.
Gene and Gina have a collection of photos of some strings at different times during their growth.
The problem is that the collection is not annotated, so they forgot to which string each photo
belongs to. They want to put together a wall to illustrate strings growing procedures, but they
need your help to find an appropriate sequence of photos.
Each photo illustrates a string. The sequence of photos must be such that if si comes imme-
diately before si+1 in the sequence, then si+1 is a string that may have grown from si (i.e., si
appears as a consecutive substring of si+1). Also, they do not want to use repeated pictures,
so all strings in the sequence must be different.
Given a set of strings representing all available photos, your job is to calculate the size of the
largest sequence they can produce following the guidelines above.

 

 

Jollo is a simple card game which the children from Logonia love to play. It is played between two players with a normal deck of 52 cards. In the game, cards are ordered according to their rank and suit, forming a sequence of 52 distinct values.
The game is composed of three rounds, played in a best-of-three series (a player must win two rounds to win the game). At the beginning of the game the deck is shuffled and each player is given a hand of three cards. In each round the players show one card to each other and the player with the highest card wins the round. The cards shown in a round are discarded (i.e., they cannot be shown again).
The King’s son loves to play the game. But he is not very smart, losing frequently to his little sister. And when he loses, he cries so loud no one can stand it. The servant who deals the cards to the Prince and his sister is afraid he will be sent to prison if the Prince continues to lose. The servant is allowed to see every card he deals, and after dealing five cards (three to the Princess and two to the Prince) he wants to know which is the lowest card he should deal to the Prince so that there is no chance he will lose the game, no matter how badly he plays.

 

Input

 

Each test case is given in a single line that contains five distinct integers A, B, C, X and  Y , describing the cards dealt to the players. The first three cards are given to the Princess (1 ≤ A,B,C ≤ 52) and the last two cards are given to the Prince (1 ≤ X, Y ≤ 52). The last test case is followed by a line containing five zeros.

 

 

Output

 

 

For each test case output a single line. If there exists a card that will make the Prince win the game no matter how badly he plays, you must print the lowest such a card. Otherwise, print -1.

 

Sample

input
4 3 28 51 29 50 52 50 26 19 10 27 10 20 30 24 26 46 48 49 47 50 0 0 0 0 0

output
30 -1 21 51

 

 

 

 


hide comments
foram: 2013-01-19 05:36:20

has the input been fixed? getting a WA

Atulv: 2010-11-12 21:11:05

there is no first line (4 3) and
input ends with 0 0 0 0 0

Shaka Shadows: 2010-11-09 19:43:09

These are the official test data used during the contest. There, the same problem was suffered by a huge number of teams, including mine. We will try to fix the input file. Right now, the input file ends with 0 0 0 0 0.

fortune cookie: 2010-11-09 19:25:46

It seems that A or B or C or X or Y can be under 0 or more than 1000, in the judge input...
I got many RE, because of this.

A. Muh. Primabudi: 2010-11-09 19:25:46

who is right? please fix the problem.
i got 7WA 2 TLE because a misunderstanding

:D: 2010-11-09 19:25:46

In the present data set version there is no first line (4 3) and the last line (0 0 0 0 0). End reading on EOF.


Added by:~!(*(@*!@^&
Date:2010-11-05
Time limit:0.187s-0.987s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:ACM ICPC2010 – Latin American Regional