Sereja and Arcs
All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
Sereja have N points, with coordinates (1, 0), (2, 0), ..., (N, 0). Every point has a color, point with coordinate (i, 0) has color A[i].
Sereja have painted arcs between every pair of points with same color. Formally Sereja painted arc between points (i, 0) and (j, 0) if A[i] = A[j] and i != j, such arc has color A[i]. All the arcs are painted such way that they will reside along the positive quadrant.
Now Sereja wants to know how many pairs of arc with different color intersect?
First line contain integer N. Next line contain integers A, A, ..., A[N].
In single line output answer modulo 1000000007 (10^9 + 7).
- 1 ≤ N ≤ 100000
- 1 ≤ A[i] ≤ 100000
Input: 4 1 2 1 2 Output: 1
|Tags||combinatorics, hard, june14, sereja|
|Time Limit:||5 sec|
|Source Limit:||50000 Bytes|
|Languages:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.5, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.