ACPC10E - Sometimes, a penalty is good!

no tags 

FIFA is considering a few changes to the way it organizes the Football World Cup. Currently, 32 teams compete for the World Title in two stages. During the first stage, known as the groups stage, the 32 teams are split evenly into 8 groups. Every team in the group plays 3 games, one against each team in their own group. Teams are then ranked within their group according to some points system. During the second (and final) stage, the top two teams from each group advance to the knockout stage where eight games are played to determine eight winners who would then play four games to determine four winners, then two games to determine the two winners who would then play the final game to determine the world champion. Needless to say, for the knockout stage to work, the number of teams in that stage has to be a power of two. FIFA is considering adding more groups, adding more teams to groups, and possibly changing the number of teams advancing from each group to the knockout stage. In addition, FIFA is considering having certain teams (previous champion, host country, etc.) advance to the knockout stage directly (without having to play in the groups stage.) But FIFA needs to know how many games will be played if any of these changes are applied. Please help them!

Input

Your program will be tested on one or more test cases. Each test case is specified on a single line made of 4 natural numbers with the following format:
G T A D
Where (G > 0) is the number of groups; T is the number of teams in each group; A is the number of teams advancing from each group to the knockout stage; and D is the number of teams directly advancing to the knockout stage without going through the groups stage. Note that (0 < A ≤ T) and that the four numbers in the input are no larger than 216.
If the total number of teams in the knockout stage is not a power of two, your program must increase them to the closest power of two.
The last test case is followed by a dummy line made of four -1’s.

Output

For each test case, print:
G*A/T+D=X+Y
where G, A, T, and D are as in the input, X is the total number of games, and Y is the number of teams your program determined it must add.

Example

Input:
8 4 2 0
8 4 2 1
-1 -1 -1 -1

Output:
8*2/4+0=63+0
8*2/4+1=79+15

hide comments
rishabh: 2012-07-01 13:32:44

i have tried almost every test case given on this page and on the forum,
my program runs just fine. any other special case or thing that needs to be taken care of??

Vinay Saini: 2011-09-07 02:04:46

@new : chek your code for this input
input :
15010 57286 51755 63968
output:
15010*51755/57286+63968=24629695709373+296835306

Castiel: 2011-07-20 09:51:53

m getting wa...give me sum test case...plz help....

Nitesh Vijayvargiya: 2011-06-27 13:54:02

but if all the teams in a group advance to the knockout stage, then what's the need of group matches.....???

Pankaj Jindal: 2011-06-26 20:48:00

@nitesh: i think it should be 9... 6 matches in group and then 2 in knockout and 1 final

Last edit: 2011-06-26 20:48:11
Nitesh Vijayvargiya: 2011-06-26 20:07:37

I feel total games played for the case
1 4 4 0
should be 3.
Am I correct?

sheel priy gupta: 2011-04-10 01:23:07

thnx for ur support....
but all these r working fine.....
i cant really find the problem with my program...

Knight: 2011-04-09 15:28:35

10 4 2 1
10*2/4+1=91+11

120 5 2 10
120*2/5+10=1455+6

33000 1000 1003 30
33000*1003/1000+30=16517054431+455402

sheel priy gupta: 2011-04-09 14:27:30

i m getting wa but working perfectly on ma system....can anyone provide me any conflicting test case...
thanks.....
1 1 1 0 is working...

Last edit: 2011-04-09 14:28:17
Teguh : 2011-03-31 17:42:03

@Mohit : Maybe I can help you
Input
1 1 1 0
Output
1*1/1+0=0+0

There is no game, no added team. Because only 1 team exist and automatically become the winner.


Added by:Omar ElAzazy
Date:2010-11-30
Time limit:2.633s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:ACPC 2010