PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000245. Xếp hình chữ nhật vào hình vuông (Packing Rectangles)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Xếp hình chữ nhật vào hình vuông (Packing Rectangles)

Packing Rectangles

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Place nn identical rectangles of width ww and height hh inside a square of positive integer side ss. Rectangles must be axis-aligned without rotation; interiors must not overlap, but boundaries may touch. Find the minimum ss. This PHOJ adaptation uses locally defined limits.

Input

One line contains three integers w,h,nw,h,n.

Output

Print the minimum side length.

Subtasks

  • Subtask 1 (20 points): 1≤w,h,n≤301\le w,h,n\le30.
  • Subtask 2 (30 points): 1≤w,h,n≤1091\le w,h,n\le10^9; w=hw=h.
  • Subtask 3 (50 points): 1≤w,h,n≤1091\le w,h,n\le10^9.

Examples

Input 1

2 3 10

Output 1

9

Explanation

Side 8 fits at most 8; side 9 fits 12, enough for ten.

Input 2

5 5 5

Output 2

15

Explanation

Side 10 fits four; side 15 fits nine.