問題一覧 > 通常問題

No.116 Kadomatsu Sequence (1)

レベル : / AI推定難易度 : 130 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 656
作問者 : yuki2006
お気に入りにしたユーザー ProblemId : 220 / 自分の提出
問題文最終更新日: 2026-06-25 07:29:27
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 72 (順位表) の他の問題:

Problem Statement

Happy New Year!

While making a kadomatsu to decorate the entrance, I noticed something.

Suppose $N$ bamboo poles are arranged at random, and let their heights be $A_i$ respectively.
When taking out $3$ consecutive poles without changing their order, I became curious how many of these combinations form a "kadomatsu sequence".

A kadomatsu is apparently something where "among the $3$ chosen bamboo poles, the $2$nd in descending order of length is positioned on the left or right side". Here,
one that additionally satisfies the condition "the $3$ lengths are all different" is called a "kadomatsu sequence".

Given the heights of the $N$ bamboo poles, find the number of combinations that form a "kadomatsu sequence".

Each bamboo pole is numbered, so they can be distinguished from one another.

Input

$N$
$A_1\ A_2 \dots A_N$

All inputs are given as integers.
$3\le N \le 100=10^2$
$1\le A_i \le 100=10^2,1\le i \le N$

Output

Output the number of combinations that form a kadomatsu sequence. Print a newline at the end.

Sample

Sample 1
Input
5
1 3 4 1 2
Output
2

$[3,4,1]$ and $[4,1,2]$ are kadomatsu sequences.
Note that $[3,4,2]$ and the like are not consecutive.

Sample 2
Input
5
1 4 2 4 1
Output
2

$[1,4,2]$, $[2,4,1]$ are kadomatsu sequences.

Sample 3
Input
5
1 4 1 5 2
Output
2

$[1,4,1]$ is not a kadomatsu sequence because the 1st and 3rd lengths are the same.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。