codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

609B.md (1681B)


      1 Source: https://codeforces.com/problemset/problem/609/B
      2 
      3 B. The Best Gift
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
     22 
     23 In the bookshop, Jack decides to buy two books of different genres.
     24 
     25 Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing two books of different genres for Emily. Options are considered different if they differ in at least one book.
     26 
     27 The books are given by indices of their genres. The genres are numbered from 1 to *m*.
     28 
     29 Input
     30 
     31 The first line contains two positive integers *n* and *m* (2 ≤ *n* ≤ 2·105, 2 ≤ *m* ≤ 10) — the number of books in the bookstore and the number of genres.
     32 
     33 The second line contains a sequence *a*1, *a*2, ..., *a**n*, where *a**i* (1 ≤ *a**i* ≤ *m*) equals the genre of the *i*-th book.
     34 
     35 It is guaranteed that for each genre there is at least one book of that genre.
     36 
     37 Output
     38 
     39 Print the only integer — the number of ways in which Jack can choose books.
     40 
     41 It is guaranteed that the answer doesn't exceed the value 2·109.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 4 3  
     49 2 1 3 1
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 5
     56 ```
     57 
     58 Input
     59 
     60 ```
     61 7 4  
     62 4 2 3 1 2 4 3
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 18
     69 ```
     70 
     71 Note
     72 
     73 The answer to the first test sample equals 5 as Sasha can choose:
     74 
     75 1. the first and second books,
     76 2. the first and third books,
     77 3. the first and fourth books,
     78 4. the second and third books,
     79 5. the third and fourth books.