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

#CC0000019. Đếm mọi dãy con tăng nghiêm ngặt (Increasing Subsequence II)

HỌC THEO LỘ TRÌNH

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

2 lộ trình

Đếm mọi dãy con tăng nghiêm ngặt (Increasing Subsequence II)

Increasing Subsequence II

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array, form a subsequence by choosing one or more positions while preserving their order. Count all nonempty strictly increasing subsequences. Different selections of positions count separately even if their selected values coincide. Print the count modulo 109+710^9+7.

Input

The first line contains nn. The next line contains nn integers a1,…,ana_1,\ldots,a_n (duplicates are allowed).

Output

Print one integer: the number of nonempty strictly increasing subsequences, modulo 109+710^9+7.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le 12; 1≤ai≤1091\le a_i\le 10^9 for every ii.
  • Subtask 2 (30 points): 1≤n≤12001\le n\le 1200; 1≤ai≤1091\le a_i\le 10^9 for every ii.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤ai≤1091\le a_i\le 10^9 for every ii.

Examples

Input

3
2 1 3

Output

5

Explanation

There are three one-element subsequences: (2)(2), (1)(1), (3)(3), and two increasing two-element subsequences: (2,3)(2,3) and (1,3)(1,3). The full three-element sequence is not increasing because 2>12>1. The total is 3+2=53+2=5.