No.116 Kadomatsu Sequence (1)
タグ : / 解いたユーザー数 656
作問者 :
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".
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もしくは右上の雲マークをクリックしてアカウントを作成してください。