There are *M* male students, *N* female students, and a teacher in a classroom.

The teacher wants to compute the total amount of money in the classroom by a "reduction" procedure.

A student tells his/her amount of money to another student (or to the teacher).

The receiver computes the sum, and relay the information to the next receiver.

For the reduction procedure:

Everyone can only speak to one person, everyone can only listen to one person,

and no one can speak and listen at the same time.

It takes *A* seconds for a female student to tell a number, and *B* seconds for a male student.

Given *A, B, N, M*, find the least time if there is a way to do this.

There are four numbers *A, B, N, M*. For all test cases, 1<=*A*<*B*<=10000 and 0<=*N,M*<=200

Output the least amount of time.

3 5 2 1

8

原TIOJ1534 / ACP 2009 期末考前練習。 Problem setter: Tmt.

No. | Testdata Range | Score |
---|---|---|

1 | 0 | 7 |

2 | 1 | 7 |

3 | 2 | 7 |

4 | 3 | 7 |

5 | 4 | 7 |

6 | 5 | 7 |

7 | 6 | 7 |

8 | 7 | 7 |

9 | 8 | 7 |

10 | 9 | 7 |

11 | 10 | 7 |

12 | 11 | 7 |

13 | 12 | 16 |