B. the best Gift
Emily ' s birthday is next week and Jack have decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there is n books on sale from one of m genres.
In the bookshop, Jack decides to buy both books of different genres.
Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing both books of Di Fferent genres for Emily. Options is considered different if they differ in for least one book.
The books is given by indices of their genres. The genres is numbered from 1 to M.
Input
The first line contains the positive integers n and m (2≤ n ≤2 105, 2≤ m ≤10)-the number of books in the bookstore and the number of genres.
The second line contains a sequence a1, a2, ..., an, where a< /c9>i (1≤ ai ≤ m) equals the genre of the I-t H book.
It is guaranteed the for each genre there are at least one book of the that genre.
Output
Print the only integer-the number of ways in which Jack can choose books.
It is guaranteed that the answer doesn ' t exceed the value 2 109.
Sample Test (s)Input
4 3
2 1 3 1
Output
5
Input
7 4
4 2 3 1 2 4 3
Output
18
Note
The answer to the first Test sample equals 5 as Sasha can choose:
- The first and second books,
- The first and third books,
- The first and fourth books,
- The second and third books,
- The third and fourth books.
Yes, I'm out of time ... Test19 must be a big data, but there's no way to optimize it at the moment. Take the pit and save it later.
1#include <stdio.h>2#include <stdlib.h>3 intbooks[20000];4 intMainintargcChar*argv[])5 {6 intn,m;7 __int64 ways;8 while(SCANF ("%d%d", &n,&m)! =EOF)9 {Tenways=0; One inti,j; A //For (i=0;i<n;i++) - //scanf ("%d", &books[i]); -scanf"%d", &books[0]); the for(i=1; i<n;i++) - { -scanf"%d",&books[i]); - for(j=0; j<i;j++) + { - if(books[i]!=Books[j]) +ways++; A } at } -printf"%i64d\n", ways); - } - return 0; -}
Codeforces edu Round3