use std::collections::HashMap; use std::io::{self, BufRead}; fn main() { // 入力読み込み let stdin = io::stdin(); let mut lines = stdin.lock().lines(); let n: usize = lines.next().unwrap().unwrap().trim().parse().unwrap(); let a: Vec = lines .next() .unwrap() .unwrap() .split_whitespace() .map(|s| s.parse().unwrap()) .collect(); let max_a = *a.iter().max().unwrap(); let offset = max_a as usize; // dp[b + offset][m] の形で管理 let mut dp: Vec> = vec![HashMap::new(); 2 * offset + 1]; let mut answer: i64 = 0; for (i, &val) in a.iter().enumerate() { let i0 = (i + 1) as i32; // answer 計算 let mut b = -val + i0; let mut m = 1; while b <= max_a { let index = (b + offset as i32) as usize; if let Some(&count) = dp[index].get(&m) { answer += count; } b += i0; m += 1; } // dp 更新 let mut b = val - i0; let mut m = 1; while b >= -max_a { let index = (b + offset as i32) as usize; *dp[index].entry(m).or_insert(0) += 1; b -= i0; m += 1; } } println!("{}", answer); }