Mock CCC '18 Contest 5 J3/S1 - Median Triples

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 1G

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

Given a list A of N integers, compute the number of triples (i, j, k) with i < j < k such that the median of A_i, A_j, and A_k is X.


1 \le N, X \le 100

1 \le a_i \le 100

Input Specification

The first line of the input consists of two space-separated integers, N and X.

The next line contains N space-separated integers, the values A_1 through A_N representing the N numbers of the list in order.

Output Specification

Output, on a single line, the number of valid triples.

Sample Input

4 1
1 1 2 2

Sample Output



There are no comments at the moment.