P23551 [AtCoder] Make Multiples
普及
题目描述

Problem Statement

You are given an integer sequence $A=(A_1,\ldots,A_N)$ and positive integers a, b, and c.
You can perform the following operation on this sequence any number of times, possibly zero.

  • Choose an integer i such that $1\leq i\leq N. Replace A_i$ with A_i+1.

Your objective is to make the sequence A contain at least one multiple of a, at least one multiple of b, and at least one multiple of c.
Find the minimum number of operations required to achieve this objective.

Input

The input is given from Standard Input in the following format:
N a b c
$A_1 \cdots A_N$

Output

Print the minimum number of operations required to achieve the objective.

Constraints

  • $1\leq N\leq 2\times 10^5$
  • $1\leq a, b, c \leq 10^6$
  • $1\leq A_i\leq 10^{18}$

Sample Input 1

3 3 4 5
8 9 11

Sample Output 1

2

You can perform the operation twice so that A = (8,10,12) to achieve the objective.

Sample Input 2

3 3 4 5
14 11 59

Sample Output 2

1

You can perform the operation once so that A = (14,11,60) to achieve the objective.

Sample Input 3

6 10 20 30
8 17 5 28 39 13

Sample Output 3

3

You can perform the operation three times so that A = (8,17,5,30,40,13) to achieve the objective.

Sample Input 4

1 999997 999998 999999
123456789123456789

Sample Output 4

876537210887543205

You can perform the operation 876537210887543205 times so that A = (999994000010999994) to achieve the objective.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 3 4 5 8 9 11
样例输出
2