This page is still under construction.

Parts of this page are still being built. What you see may change.

NumberEater

Time limit1sMemory limit128 MB

Summary
Count the number of distinct value sets obtainable as the set of a contiguous subarray of the given sequence.
Level

Medium6 of 10

Topics
Hash map, Array, Two pointers
Solved
No attempts yet

Problem

NumberEater is a famous monster from Byteland. It eats numbers, but it is very picky: every day its meal must be unique. The monster is given a sequence of integers a1,a2,…,ana_1, a_2, \ldots, a_n. It chooses a start position ii and an end position jj (1≤i≤j≤n1 \le i \le j \le n) and prepares a meal made of the elements ai,ai+1,…,aja_i, a_{i+1}, \ldots, a_j.

The monster considers two meals [i1,j1][i_1, j_1] and [i2,j2][i_2, j_2] to be identical when they contain the same set of numbers, that is:

{ak:i1≤k≤j1}={ak:i2≤k≤j2}\{a_k : i_1 \le k \le j_1\} = \{a_k : i_2 \le k \le j_2\}

Help NumberEater count how many different meals it can prepare using the sequence aa.

Input

The first line contains one integer nn (1≤n≤5001 \le n \le 500), the length of the sequence aa. Each of the next nn lines contains one element of the sequence. Every element is at least 11 and at most 500500.

Output

Print a single integer: the number of different meals that NumberEater can prepare.

Examples1

  1. Example 1

    Input
    6
    1
    2
    3
    1
    2
    3
    
    Expected output
    7