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

#BS0000237. Tìm số xuất hiện lặp lại (Find the Duplicate Number)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tìm số xuất hiện lặp lại (Find the Duplicate Number)

Find the Duplicate Number

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

An array a1,…,an+1a_1,\ldots,a_{n+1} contains n+1n+1 integers in the inclusive range from 1 to nn. Exactly one distinct value occurs at least twice; every other value that occurs appears once. Identify the repeated value. The algorithm should leave the input array unchanged and use constant auxiliary space, excluding the array itself.

Input

The first line contains integer nn. The second line contains n+1n+1 integers a1,…,an+1a_1,\ldots,a_{n+1}.

Output

Print the single repeated value.

Subtasks

  • Subtask 1 (20 points): 1≤n≤1001\le n\le100; 1≤ai≤n1\le a_i\le n for all 1≤i≤n+11\le i\le n+1; exactly one value has frequency at least 2, every other value has frequency at most 1.
  • Subtask 2 (30 points): 1≤n≤1051\le n\le10^5; 1≤ai≤n1\le a_i\le n for all 1≤i≤n+11\le i\le n+1; exactly one value occurs exactly twice, every other value has frequency at most 1.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 1≤ai≤n1\le a_i\le n for all 1≤i≤n+11\le i\le n+1; exactly one value has frequency at least 2, every other value has frequency at most 1.

Examples

Input

5
2 5 2 1 4 2

Output

2

Explanation

Value 2 occurs at positions 1, 3 and 6. Values 1, 4 and 5 occur once, and 3 is absent. The repeated value is 2.