Under construction

Still being built. Things may change

Coke Drinking Contest

Time limit1sMemory limit512 MB

Summary
Given N entrants who each drink A mL per second with fixed drinking and resting periods, find when the first entrant finishes K mL.
Level

Easy3 of 10

Topics
Math, Simulation, Implementation
Solved
No attempts yet

Problem

Taeyeong likes coke so much that he cannot get through a single day without it, and the coke made by Jaemin's company is his favorite. Jaemin decided to sponsor him, and with that money Taeyeong is holding the first coke drinking contest in Daejeon.

NN people enter the contest. Each entrant receives KK mL of coke and starts drinking the moment the bell rings, and the first person to empty the cup wins. Drinking it all at once hurts because of the carbonation, so every entrant alternates between drinking and resting. Each entrant drinks AA mL per second, and entrant ii repeats a cycle of drinking for tit_i seconds and then resting for sis_i seconds. The winner is decided at the instant some entrant has 0 mL left, and the contest ends there.

Given the information of the NN entrants, print how many seconds after the start the winner is decided.

Input

The first line contains the natural numbers NN (2≤N≤10002 \le N \le 1000), KK (1≤K≤100001 \le K \le 10000), and AA (1≤A≤1001 \le A \le 100), separated by spaces. KK is a multiple of AA. Each of the next NN lines contains the natural numbers tit_i (1≤ti≤1001 \le t_i \le 100) and sis_i (1≤si≤1001 \le s_i \le 100) for entrant ii.

Output

Print the time at which the winner is decided, as an integer number of seconds counted from the start of the contest.

Examples2

  1. Example 1

    Input
    2 100 1
    10 5
    5 10
    
    Expected output
    145
    
  2. Example 2

    Input
    4 100 2
    30 30
    49 2
    50 50
    20 10
    
    Expected output
    50