PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000119. Tổng tiền nhỏ nhất không tạo được (Missing Coin Sum)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tổng tiền nhỏ nhất không tạo được (Missing Coin Sum)

Missing Coin Sum

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

You have nn coins of positive integer values xix_i. Each coin can be used at most once. Find the smallest positive integer sum that cannot be formed by any subset.

Input

The first line contains nn. The next line contains nn integers xix_i.

Output

Print the smallest positive unrepresentable sum.

Subtasks

  • Subtask 1 (20 points): 1≤n≤251\le n\le 25; 1≤xi≤1091\le x_i\le10^9 for all ii.
  • Subtask 2 (30 points): 1≤n≤15001\le n\le 1500; 1≤xi≤1091\le x_i\le10^9 for all ii.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤xi≤1091\le x_i\le10^9 for all ii.

Examples

Input

5
2 9 1 2 7

Output

6

Explanation

Sorted coins are 1,2,2,7,91,2,2,7,9. Sums 11 through 55 are achievable using the first three coins, but 66 is not achievable because the next coin is 77.