This page is still under construction.

Parts of this page are still being built. What you see may change.

Berland University

Time limit1sMemory limit512 MB

Summary
Given t students, n lectures alternating between two auditoriums of sizes a and b, and a passing threshold k, find the maximum number of students who can each attend at least k lectures.
Level

Medium6 of 10

Topics
Binary search, Greedy, Math, Implementation
Solved
No attempts yet

Statement

There are tt students at the best university in Berland. They only study programming in Berland, so there is only one subject. Every student must attend the lectures.

The whole course consists of nn lectures. A student who attends at least kk of them passes the course.

The university has only two auditoriums, one with space for aa people and the other for bb people. To keep things comfortable, the administration decided that in odd weeks the lectures will be in the first auditorium, and in even weeks in the second auditorium. So the first lecture is in auditorium 1, the second lecture in auditorium 2, the third in auditorium 1 again, and so on.

The auditoriums are small, so it may be impossible for all students to attend at least kk lectures. Find the maximum number of students that can pass the course.

Input

The first line contains five integers:

  • tt --- the number of students;
  • nn --- the number of lectures;
  • aa --- the size of the first auditorium;
  • bb --- the size of the second auditorium;
  • kk --- the minimum number of lectures needed to pass the course.

The limits are 1≤t,n,a,b,k≤1091 \leq t, n, a, b, k \leq 10^9.

Output

Print a single integer: the maximum number of students that can attend at least kk lectures and pass the course.

Hint

In the fourth sample, 5 students can pass the course. One possible strategy is:

  1. Students 11, 22, 33, 44, 55 attend the first lecture.
  2. Students 11, 33 attend the second lecture.
  3. Students 11, 22, 33, 44, 55 attend the third lecture.
  4. Students 22, 44, 55 attend the fourth lecture.

This way each of these 5 students attends at least 33 lectures.

Examples5

  1. Example 1

    Input
    10 3 4 4 3
    
    Expected output
    4
    
  2. Example 2

    Input
    10 3 4 4 5
    
    Expected output
    0
    
  3. Example 3

    Input
    100000 100000 100000 100000 1
    
    Expected output
    100000
    
  4. Example 4

    Input
    5 4 5 3 3
    
    Expected output
    5
    
  5. Example 5

    Input
    100 9 6 3 6
    
    Expected output
    7