Type: Default 2000ms 512MiB

ABC263G

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Score : 600 points

Problem Statement

There are integers with N different values written on a blackboard. The i-th value is Ai and is written Bi times.

You may repeat the following operation as many times as possible:

  • Choose two integers x and y written on the blackboard such that x+y is prime. Erase these two integers.

Find the maximum number of times the operation can be performed.

Constraints

  • 1N100
  • 1Ai107
  • 1Bi109
  • All Ai are distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N 
A1 B1
A2 B2

AN BN

Output

Print the answer.


Sample Input 1

3
3 3
2 4
6 2

Sample Output 1

3

We have 2+3=5, and 5 is prime, so you can choose 2 and 3 to erase them, but nothing else. Since there are four 2s and three 3s, you can do the operation three times.


Sample Input 2

1
1 4

Sample Output 2

2

We have 1+1=2, and 2 is prime, so you can choose 1 and 1 to erase them. Since there are four 1s, you can do the operation twice.

AGC029

Not Attended
Status
Done
Rule
IOI
Problem
8
Start at
2023-7-13 8:30
End at
2023-7-13 12:00
Duration
3.5 hour(s)
Host
Partic.
17