E. 暮雪少年与棒棒糖

    传统题 1000ms 256MiB

暮雪少年与棒棒糖

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Background

After winning a silver medal, Snowy enrolled at Peking University. As he strolled happily along a tree-lined path, he recalled a problem he had yet to solve.

Problem Description

Snowy has nn candies. The deliciousness of the ii-th candy is represented by an integer aia_i.

A lollipop is formed by combining a contiguous sequence of candies. That is, Snowy chooses indices ii and jj (1ijn1\leq i\leq j\leq n) and uses all candies from index ii to jj to make one lollipop.

The deliciousness of a single lollipop is defined as the Least Common Multiple (LCM) of the deliciousness values of all candies contained in it.

Snowy wants to partition all nn candies into an arbitrary number of lollipops. Every candy must belong to exactly one lollipop.

Formally, he needs to select partition points 1r1<r2<<rk=n1 \leq r_1 < r_2 < \cdots < r_k = n to create kk lollipops corresponding to the intervals $[1, r_1], [r_1 + 1, r_2], \cdots, [r_{k-1} + 1, r_k]$.

Find a partition strategy such that the sum of the deliciousness of all lollipops is maximized.

It is guaranteed that the answer will not exceed 101810^{18}.

Input Format

The first line contains a single integer nn. The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n.

Output Format

Output a single integer representing the maximum possible total deliciousness.

Examples

Input 1

3
6 10 15

Output 1

45

Input 2

2
2 3

Output 2

6

Input 3

2
3 6

Output 3

9

Constraints

For 100%100\% of the data, 1n2×1051 \leq n \leq 2 \times 10^5 and 1ai1091 \leq a_i \leq 10^9.

This problem has 25 test points divided into 8 subtasks. You must pass all test points in a subtask to receive points for it.

Test Points nn aia_i Special Property Score
121 \sim 2 =1=1 109\leq 10^9 None 8
353 \sim 5 =2=2 20\leq 20 12
66 2×105\leq 2\times 10^5 109\leq 10^9 A 4
7107 \sim 10 10\leq 10 100\leq 100 None 16
111511 \sim 15 100\leq 100 109\leq 10^9 20
161716 \sim 17 2×105\leq 2\times 10^5 3\leq 3 8
182018 \sim 20 2×105\leq 2 \times 10^5 109\leq 10^9 B 12
212521 \sim 25 2×105\leq 2\times 10^5 None 20

Special Property A: a1=a2==ana_1 = a_2 = \cdots = a_n.

Special Property B: For any ii, aia_i is either equal to lcm(a1,,ai1)\operatorname{lcm}(a_1, \dots, a_{i-1}) or is coprime (gcd is 1) to it.

【XJS-C5-Div3】XJSOI 春节大月赛 Round 3 & 勰码可达鸭合作赛 Round 1

未参加
状态
已结束
规则
IOI
题目
5
开始于
2026-2-14 0:00
结束于
2026-2-17 0:00
持续时间
4 小时
主持人
参赛人数
7