50156. Highest Discount Rate

I'm a slow walker, but I never walk backwards.

Task Description

There is a sales coming. Every payment $p$ (a positive integer) will have a discount $d$ according to the following table.

range of $p$ discount $d$
1 $0 \lt p \lt a$ 0
2 $a \leq p \lt b$ $v, \text{ if }p\text{ is odd}$

$w, \text{ if }p\text{ is even}$
3 $b \leq p$ $x, \text{ if }p \equiv 0 \pmod{3}$

$y, \text{ if }p \equiv 1 \pmod{3}$

$z, \text{ if }p \equiv 2 \pmod{3}$

We define discount rate as $d/p$. Write a program to find the $p$ that has the highest discount rate. If there are multiple payments that give the highest discount rate, output the smallest one.

Input Format

There will be 7 lines for integers $a, b, v, w, x, y, z$.

  • $v, w, x, y, z \geq 0$
  • $a > 1$
  • $b > a + 2$

Output Format

The smallest payment $p$ that has the highest $d/p$ discount rate.

Sample Input

10
30
5
6
18
8
9

Sample Output

10

Hint

Since we have not yet discuss the floating point numbers, so we compare two fractional numbers $a/b$ and $c/d$, by comparing $a * d$ and $b * c$ instead, when both $b$ and $d$ are positive integers.

Discussion