#![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}; /* インタラクティブ macro_rules! input(($($tt:tt)*) => ( let stdin = std::io::stdin(); let mut stdin = proconio::source::line::LineSource::new(std::io::BufReader::new(stdin)); proconio::input!(from &mut stdin, $($tt)*); )); */ #[fastout] fn main() { input! { n: usize, a: [usize; n], } 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); }