#![allow(non_snake_case)] #![allow(unused_imports)] #![allow(unused_macros)] #![allow(clippy::needless_range_loop)] #![allow(clippy::comparison_chain)] #![allow(clippy::nonminimal_bool)] #![allow(clippy::neg_multiply)] #![allow(dead_code)] // use itertools::Itertools; // use std::collections::{BTreeSet, HashSet, VecDeque}; // use std::f64::consts::PI; // use proconio::fastout; // use proconio::*; // use std::cmp::{max, min}; use std::io::{self, BufRead}; // #[fastout] fn main() { let stdin = io::stdin(); let mut lines = stdin.lock().lines(); // Nをusizeとして読み込む let n: usize = lines.next().unwrap().unwrap().parse().unwrap(); // A1からANまでを読み込んでベクターに格納 let a: Vec = lines .next() .unwrap() .unwrap() .split_whitespace() .map(|s| s.parse().unwrap()) .collect(); let mut countList: Vec> = vec![vec![0; 2001]; n]; for i in (0..n).rev() { for j in 0..2001 { if i < n - 1 { countList[i][j] = countList[i + 1][j]; } } countList[i][a[i]] += 1; } let mut ans = 0; for i in 0..n { for j in i + 1..n { if (a[j] as i128) - (a[i] as i128) - 10 <= 0 { continue; } let diff = a[j] - a[i] - 10; for k in j + 1..n { if (a[k] == a[j] - diff) && (a[k] + diff + 1 < 2001) { ans += countList[k][a[k] + diff + 1]; } } } } println!("{}", ans); }