This page is still under construction.

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

Handing out candies

Interview

Time limit2sMemory limit512 MB

Summary
For every K, count the ways to choose one candy of each brand 1 through K, and print the total over all K.
Level

Medium5 of 10

Topics
Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

You want to hand out candies to the participants of an algorithm camp.

You have NN candies, and every candy has a brand written as an integer.

First you decide KK, the number of candies you hand out. Then you pick exactly one candy of each brand from brand 11 through brand KK.

KK can be any value from 11 to NN, and two candies of the same brand count as different candies. Write a program that computes the total number of ways to pick the candies, summed over every KK.

Input

The first line contains the number of candies NN. (1≤N≤501 \le N \le 50)

The second line contains the brands of the NN candies, separated by spaces. Each brand is an integer between 11 and 5050.

Output

Print the number of ways to pick the candies on the first line. The value is smaller than 2312^{31}.

Examples5

  1. Example 1

    Input
    3
    1 3 2
    
    Expected output
    3
    
  2. Example 2

    Input
    3
    1 1 2
    
    Expected output
    4
    
  3. Example 3

    Input
    8
    1 3 2 5 7 4 5 4
    
    Expected output
    9
    
  4. Example 4

    Input
    10
    1 1 2 2 3 3 4 4 5 5
    
    Expected output
    62
    
  5. Example 5

    Input
    1
    2
    
    Expected output
    0