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

#SP0000250. Lũ nguyên tố — Phiên bản dễ (A Prime Flood — Easy Version)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Lũ nguyên tố — Phiên bản dễ (A Prime Flood — Easy Version)

A Prime Flood (Easy Version)

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A positive integer array a1,a2,…,ana_1,a_2,\ldots,a_n represents water levels. Independently for every non-empty subsequence bb chosen by selecting positions from aa and keeping their order, consider the following operation: choose any prime pp and simultaneously decrease by exactly 11 every current element of bb divisible by pp. All other elements remain unchanged. Any number of operations, including zero, may be performed.

Let f(b)f(b) be the maximum integer xx such that all elements of bb can be made equal to xx. Calculate

∑b≠∅f(b)(mod998244353).\sum_{b\ne\varnothing} f(b)\pmod{998244353}.

Different choices of indices count as different subsequences, even when their value sequences coincide. Each subsequence is processed independently from its original values.

Input

  • The first line contains integer nn, the array length.
  • The second line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n in their original order.

Output

Print one integer, the sum of f(b)f(b) over all non-empty subsequences distinguished by selected indices, modulo 998244353998244353.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le12; 1≤ai≤n1\le a_i\le n for all 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤1001\le n\le100; 1≤ai≤n1\le a_i\le n for all 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤30001\le n\le3000; 1≤ai≤n1\le a_i\le n for all 1≤i≤n1\le i\le n.

Examples

Input

4
2 4 4 4

Output

37

Explanation

For a=[2,4,4,4]a=[2,4,4,4], choose a non-empty subset of the three positions equal to 44 without choosing the 22: there are 23−1=72^3-1=7 such subsequences, each with f=4f=4, contributing 2828. The subsequence consisting only of [2][2] contributes 22. Finally there are 77 selections containing the 22 and at least one 44; each has f=1f=1 because the values can be reduced to 11 but cannot be equalized at 22 or more. Thus the total is 28+2+7=3728+2+7=37.