## GlobeX Cup '18 S5 - Math Bash

View as PDF

Points: 17
Time limit: 0.6s
Java 1.0s
Memory limit: 128M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

You are taking your calculus exam. In the exam room, there is an grid of desks, each with exactly one student taking an exam at that desk.

Your teacher has came up with an interesting way of grading the exams. Let represent the initial mark that the student at position got on the exam. His actual mark, , is equal to where is the number of students who have an actual mark higher than or equal to student 's initial mark and their position is where and . Formally, is the number of students where and .

Wanting to know how much everyone's marks change, you are to find the sum of for all .

#### Input Specification

The first line will contain the .

The next line will contain lines will each contain space-separated integers .

#### Output Specification

Output the sum of all , as defined above.

#### Sample Input 1

2
2 1
1 2

#### Sample Output 1

1

#### Explanation for Sample 1

Only the student at position will have their mark changed. All other students will keep their current mark. Thus, , and . The student at position will have their marks changed by one due to . The sum of all is therefore one.

#### Sample Input 2

5
1 4 2 5 3
5 2 8 4 2
1 1 1 1 3
9 9 2 3 1
1 1 1 1 1

#### Sample Output 2

82

#### Sample Input 3

10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2 1
10 9 8 7 6 1 2 3 4 5
10 9 8 7 6 1 2 3 4 5

#### Sample Output 3

1420