atcoder#RELAY2H. Akashic Records

Akashic Records

Score : 100100 points

Problem Statement

Consider an infinite sequence a1,a_1, a2,a_2, \cdots Initially, the values of all the terms are 00, and from this state we will sequentially perform QQ operations. The ii-th operation (1iQ)(1 \leq i \leq Q) is as follows:

  • For every positive integer jj, add xix_i to the value of aj×mia_{j \times m_i}.

Find the value of the largest term after these QQ operations.

Constraints

  • 1Q2991 \leq Q \leq 299
  • 2mi3002 \leq m_i \leq 300
  • 106xi106-10^6 \leq x_i \leq 10^6
  • All mim_i are distinct.
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

QQ

m1m_1 x1x_1

::

mQm_Q xQx_Q

Output

Print the value of the largest term after the QQ operations.

3
2 10
3 -20
6 15
10

The values of each terms in the sequence a1,a_1, a2,a_2, \cdots change as follows:

  • Before the operations: 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, \cdots
  • After the 11-st operation: 0,0, 10,10, 0,0, 10,10, 0,0, 10,10, \cdots
  • After the 22-nd operation: 0,0, 10,10, 20,-20, 10,10, 0,0, 10,-10, \cdots
  • After the 33-rd operation: 0,0, 10,10, 20,-20, 10,10, 0,0, 5,5, \cdots

The value of the largest term after all the operations is 1010.

3
10 -3
50 4
100 -5
1
5
56 114834
72 -149861
100 190757
192 -132693
240 133108
438699