#P2737. [USACO4.1] 麦香牛块 Beef McNuggets

[USACO4.1] 麦香牛块 Beef McNuggets

Description

Farmer Brown’s cows are campaigning because they heard McDonald’s is considering a new product: Beef McNuggets. The cows are trying everything to sink this terrible idea. One of their strategies is “poor packaging.” “Look,” say the cows, “if you package McNuggets using only three box sizes that hold 33, 66, or 1010 pieces, then you cannot satisfy customers who want to buy exactly 11, 22, 44, 55, 77, 88, 1111, 1414, or 1717 pieces. Poor packaging means a poor product.”

Your task is to help the cows. Given the number of box types N (1N10)N\ (1 \le N \le 10) and NN positive integers bi (1bi256)b_i\ (1 \le b_i \le 256) representing how many McNuggets each type of box can hold, output the largest number of McNuggets that cannot be bought using these boxes (each box type is available in unlimited quantity). If every purchase request can be satisfied, or if there is no upper bound on the numbers that cannot be bought, output 00. The largest number that cannot be bought (if it exists) does not exceed 2×1092 \times 10^9.

Input Format

Line 1: The number of box types NN.

Lines 22 to N+1N+1: For each type, the number of McNuggets a box of that type can hold.

Output Format

Output a single integer: the largest number of McNuggets that cannot be bought using the given boxes, or 00 (if every request can be satisfied or if the set of numbers that cannot be bought is unbounded).

3
3
6
10
17

Hint

Problem translation from NOCOW.

USACO Training Section 4.1.

Translated by ChatGPT 5