406143: GYM102279 A Amsopoly Simple Version

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Amsopoly Simple Versiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Seo, B21 and Lowie tested the new version of the game Monopoly: Amsopoly. This game is designed specifically to sell to students and alumni of the Hanoi - Amsterdam High School.

In the simplest version, the game map consists of $$$N+1$$$ real estate areas. The first one is called "starting position": it belongs to the government and all players start from there in the beginning of the game. The other $$$N$$$ areas are placed in a circle in the following manner: the $$$2^{nd}$$$ placed after the $$$1^{st}$$$, the $$$3^{rd}$$$ placed after the $$$2^{nd}$$$ and so on. In the end, the $$$(N+1)^{th}$$$ placed after the $$$N^{th}$$$ and the first one placed right after the $$$(N+1)^{th}$$$. These $$$N$$$ areas are vacancy and are available for one player to own it.

In a player turn, if he or she rolls the number $$$X$$$, he or she will move $$$X$$$ steps forward from his or her current position. Assume that he or she ends up in $$$Y^{th}$$$: if $$$Y=1$$$ or $$$Y$$$ is owned by this player before, then nothing happens, else if $$$Y$$$ is vacancy, the player will own the property, and if $$$Y$$$ is owned by the other player, $$$Y$$$ will have to pay the owner of the property.

Seo, B21 and Lowie have played one abnormal games: in the first $$$10^9$$$ turns for each player: Seo rolls exactly $$$V_s$$$, B21 rolls exactly $$$V_b$$$, and Lowie rolls exactly $$$V_l$$$ in every turn. Seo is the first person to move, then B21, then Lowie, then Seo again, and so on.

Before the first event of a person step on a property of another person and have to pay him, how many dice rolls has happened. If after $$$3*10^9$$$ turn, no one have to pay others, output $$$3000000000$$$.

Input

The only line contains four integers: $$$N$$$, $$$V_s$$$, $$$V_b$$$ and $$$V_l$$$ ($$$3 \le N \le 10^5$$$, $$$1 \le V_s, V_b, V_l \le N$$$).

Output

The only integer denotes the number of dice rolls happened before the event of a player pays another.

ExamplesInput
7 3 4 5
Output
10
Input
29 6 10 15
Output
3000000000
Note

Example 1:

Initial state of the game: all three players are at the government property:

After the first three rolls (one for each player), the game will look like this (blue indicates the property of Seo, purple indicates the property of B21, and yellow indicates the property of Lowie):

After the next three rolls (one for each player), the game will look like this (Seo is at $$$7$$$, B21 is at $$$1$$$, and Lowie is at $$$3$$$):

After the next three rolls:

The next roll will make Seo step on a property of B21 (property number $$$5$$$). That makes Seo have to pay an amount of rental fee to B21.

Example 2:

We can prove that in this test, players can only move on to government's property or their own properties, again and again, not others', so that after $$$10^9$$$ turns of infinite repetitions, three friends decided that they will be more productive and started to organize CP contests for their students.

加入题单

上一题 下一题 算法标签: