#B4290. Unreachable Tangyuan Count

    ID: 11947 Type: Default 1000ms 256MiB

Unreachable Tangyuan Count

Unreachable Tangyuan Count

A vendor sells tangyuan (glutinous rice balls) in pre-packaged sizes. In particular, the vendor offers exactly NN different packet sizes. However, not every quantity of tangyuan is available for purchase because the tangyuan can only be bought in multiples of one of these packet sizes. For example, if N=2N=2 and the packets contain 33 and 55 tangyuan respectively, the buyer cannot purchase exactly 11, 22, 44, or 77 tangyuan.

Given an integer NN and the NN packet sizes, determine the number of different totals (i.e. quantities of tangyuan) that cannot be obtained by any nonnegative combination of the given packet sizes. If there exist infinitely many unattainable quantities, output 1-1.

Note: It is guaranteed that if the greatest common divisor of the packet sizes (denoted by gg) is not 11, then there are infinitely many unreachable quantities.

inputFormat

The input consists of two lines:

  1. The first line contains an integer NN representing the number of packet sizes.
  2. The second line contains NN space-separated integers, each representing a packet size.

outputFormat

Output a single integer: the number of unattainable tangyuan quantities. If there are infinitely many unattainable totals, print 1-1.

sample

2
3 5
4