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
Mohit Mittal: 2011-03-31 17:42:03

There will be 6 games per group when in each group there are 4 teams. n(n-1)/2.

@hendrik : what should be the answer of test case you have posted

hendrik: 2011-03-31 17:42:03

Interessting test case 1 1 1 0.

Last edit: 2010-12-02 18:39:26
Hagen von Eitzen: 2011-03-31 17:42:03

@Jimmy Skirtladze: There are only 6 games per group.

Jimmy: 2011-03-31 17:42:03

Why is X=63 for first example?
As i understand, there are 12 games in each group, so 8*12 at first stage. and 8+4+2+1=15 on second stage. Please,help.

Last edit: 2010-12-01 17:31:52
Omar Darwish: 2011-03-31 17:42:03

that the four numbers in the input are no larger than 216.
* I think that this number should be 2^16 , or am I wrong?

Omar ElAzazy: Fixed

Last edit: 2010-11-30 20:35:20

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