Arithmetic Subsequences
Time limit1sMemory limit128 MB
Count index triples i<j<k in a permutation of 1 to n whose values form a three-term arithmetic progression.
- Level
Medium7 of 10
- Topics
- Math, Brute force
- Solved
- No attempts yet
Problem
You are given a permutation of the numbers for some . Let the elements of the permutation, in order, form a sequence . Your task is to count how many arithmetic subsequences of have length exactly . More precisely, count the triples such that and .
Input
The first line contains one integer . The second line contains integers describing the permutation.
Output
Print the number of length- arithmetic subsequences of the given permutation. You may assume the answer does not exceed .