#arc170b. B - Arithmetic Progression Subsequence
B - Arithmetic Progression Subsequence
Score: points
问题陈述
给定一个长度为 的序列 ,序列中的整数在 到 (包括 和 )之间。
如果满足以下条件,则称整数对 为一个好对:
- 序列 包含一个长度为 的等差子序列(可以是不连续的)。更准确地说,存在一个整数三元组 ,满足 且 。
找出好对的数量。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a sequence of length consisting of integers between and , inclusive.
A pair of integers satisfying is called a good pair if it satisfies the following condition:
- The sequence contains a (possibly non-contiguous) arithmetic subsequence of length . More precisely, there is a triple of integers with such that .
Find the number of good pairs.
Constraints
- All input numbers are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
5
5 3 4 1 5
Sample Output 1
3
There are three good pairs: .
For example, the sequence contains an arithmetic subsequence of length , which is , so is a good pair.
Sample Input 2
3
1 2 1
Sample Output 2
0
There may be cases where no good pairs exist.
Sample Input 3
9
10 10 1 3 3 7 2 2 5
Sample Output 3
3