AtCoder Regular Contest 170
B
Arithmetic Progression Subsequence
AtCoder
⌀ 1180
原题
← AC →
翻译中…

Problem Statement

翻译中…

You are given a sequence $A$ of length $N$ consisting of integers between $1$ and $\textbf{10}$, inclusive.

翻译中…

A pair of integers $(l,r)$ satisfying $1\leq l \leq r\leq N$ is called a good pair if it satisfies the following condition:

翻译中…
  • The sequence $(A_l,A_{l+1},\ldots,A_r)$ contains a (possibly non-contiguous) arithmetic subsequence of length $3$. More precisely, there is a triple of integers $(i,j,k)$ with $l \leq i < j < k\leq r$ such that $A_j - A_i = A_k - A_j$.
翻译中…

Find the number of good pairs.

翻译中…

Constraints

翻译中…
  • $3 \leq N \leq 10^5$
  • $1\leq A_i \leq 10$
  • All input numbers are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
A_1 \ldots A_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
5
5 3 4 1 5
Output #1
3
There are three good pairs: $(l,r)=(1,4),(1,5),(2,5)$. For example, the sequence $(A_1,A_2,A_3,A_4)$ contains an arithmetic subsequence of length $3$, which is $(5,3,1)$, so $(1,4)$ is a good pair.
Input #2
3
1 2 1
Output #2
0
There may be cases where no good pairs exist.
Input #3
9
10 10 1 3 3 7 2 2 5
Output #3
3
题目信息
题号
arc170_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。