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

#GL0000161. Singhal và đoạn con GCD lớn nhất (Singhal and GCD)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Singhal và đoạn con GCD lớn nhất (Singhal and GCD)

Singhal and GCD

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Singhal has an array of positive integers a1,…,ana_1,\ldots,a_n. Among all contiguous subarrays of length at least two, choose one with the largest possible GCD. If several subarrays have that GCD, choose the longest among them. Output both the maximum GCD and the selected length.

Input

The first line contains nn. The second line contains the nn integers aia_i.

Output

Print two space-separated integers: the maximum GCD and the greatest length of a subarray achieving it.

Subtasks

  • Subtask 1 (20 points): 2≤n≤202 \le n \le 20; 1≤ai≤1001 \le a_i \le 100.
  • Subtask 2 (30 points): 2≤n≤50002 \le n \le 5000; 1≤ai≤1061 \le a_i \le 10^6.
  • Subtask 3 (50 points): 2≤n≤1052 \le n \le 10^5; 1≤ai≤1091 \le a_i \le 10^9.

Examples

Input

3
3 6 9

Output

3 3

Explanation

The GCD of each of [3,6][3,6], [6,9][6,9] and [3,6,9][3,6,9] is 33. The third subarray is the longest among those achieving the maximum GCD, so print 3 3.