#P10666. Counting Arithmetic Triplets in an Array

    ID: 12693 Type: Default 1000ms 256MiB

Counting Arithmetic Triplets in an Array

Counting Arithmetic Triplets in an Array

Given an array of length \(n\) consisting of integers \(a_1,a_2,\dots,a_n\), count the number of triplets \((i,j,k)\) (with \(1\le i<j<k\le n\)) that satisfy the condition:

\(a_k - a_j = a_j - a_i\)

This condition can be rewritten in the following form using \(\LaTeX\):

\(2a_j = a_i + a_k\)

inputFormat

The first line contains an integer \(n\) denoting the length of the array. The second line contains \(n\) space-separated integers \(a_1, a_2, \dots, a_n\).

outputFormat

Output a single integer representing the number of triplets \((i, j, k)\) that satisfy the condition \(a_k - a_j = a_j - a_i\).

sample

3
1 2 3
1