jiahuimbzuai/CoQuIR huggingface dataset:
//  [rust]
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let a = v[0];
	let b = v[1];
	if (a*b) % 2 == 0 {
		println!("No");
	}else{
		println!("Yes");
	}
}
//  [rust]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(a: usize, b: usize);

    println!("{}", if (a * b) % 2 != 0 { "Yes" } else { "No" });
}
//  [rust]
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();

    for c in 1..=3 {
        if a * b * c % 2 == 1 {
            return "Yes".to_string();
        }
    }

    return "No".to_string();
}
//  [swift]
print(readLine()!.characters.split(" ").reduce(1){$0*Int(String($1))!}%2>0 ?"Yes":"No")
//  [typescript]
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[])=>{for(let i=0;i<a.length;i+=2)if(s==a[i])return a[i+1]};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};
const main = ()=>{
  let [a,b]=nrin(2);
  out(a*b%2==0?"No":"Yes");
}
main();
//  [typescript]
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const [a, b] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

let res = 'No'
for (let i = 1; i < 4; i++) {
  const product = a * b * i
  if (product % 2 !== 0) res = 'Yes'
}

console.log(res)
//  [typescript]
function Main(input: string):void {
    const [A, B] = input.split(' ').map((num:string) => parseInt(num));
    if ((A & 1 * B & 1) === 1) { // both A and B are odd number
        console.log('Yes');
    } else {
        console.log('No');
    }
}

import * as fs from 'fs';
Main(fs.readFileSync("/dev/stdin", "utf8"));
//  [typescript]
var lines=[];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', function (line) {
  lines.push(line);
});
reader.on('close', function () {
  main(lines[0]);
});

function main(line) {
  const [a, b] = line.split(' ').map(s => s.trim());
  let hasOdd = false;
  for (let c = 1; c <= 3; c++) {
    const result = isOdd(a * b * c);
    if (result) hasOdd = true;
  }
  console.log(hasOdd ? 'Yes' : 'No');
}

function isOdd(num) {
  return num % 2 === 1;
}
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [A, B] = input[0].map(Number);

  return A !== 2 && B !== 2 ? "Yes" : "No";
};

console.log(main(read()));
//  [typescript]
function Main(input: string) {
  const lines = input.split('\n');
  const params1 = lines[0].split(' ');

  const a = parseInt(params1[0]);
  const b = parseInt(params1[1]);


  const msg = (a * b % 2 === 0) ? 'No' : 'Yes';

  console.log(msg);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [python]
# coding : utf-8

import numpy as np

A = [int(i) for i in input().split()]

if A[0] <= A[2] and A[0] + A[1] >= A[2]:
	print("YES")
else:
	print("NO")
//  [python]
import re
import doctest


class IO_for_Contest(object):
    @staticmethod
    def my_input():
        # return raw_input()
        return input()

    @staticmethod
    def read_from_input():
        return IO_for_Contest.read_n_int(3)

    @staticmethod
    def read_line():
        return IO_for_Contest.my_input().strip()

    @staticmethod
    def read_int():
        return int(IO_for_Contest.my_input().strip())

    @staticmethod
    def read_n_int(n):
        return list(map(
                    int,
                    re.split('\s+', IO_for_Contest.my_input().strip())))[: n]


def solve():
    buf = IO_for_Contest.read_from_input()
    a, b, x = buf[0], buf[1], buf[2]
    if x >= a and a + b >= x:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    # doctest.testmod()
    solve()
//  [python]
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	A, B, X = map(int, input().split(" "))
	
	if A+B >= X:
		if A <= X:
			print("YES")
		else:
			print("NO")
	else:
		print("NO")
	
if __name__ == "__main__":
	main()
//  [java]
import java.util.Scanner;
public class Main {
public static final String YES = "YES";
public static final String NO = "NO";
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int x = sc.nextInt();
String result = YES;
if (a > x) result = NO;
if (a + b < x) result = NO;
System.out.println(result);
}
}
//  [java]
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int a = cin.nextInt();
        int b = cin.nextInt();
        int x = cin.nextInt();
        if (x < a || x > a + b) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
        }
    }
}
//  [java]
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int N = sc.nextInt();

		if(N-A>=0 && N-A<=B) System.out.println("YES");
		else System.out.println("NO");

	}
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  int a,b,x;
  cin>>a>>b>>x;
  string ans="YES";
  if(x-a>b||x<a)ans="NO";
  cout<<ans<<endl;
  return 0;
}
//  [c]
#include<stdio.h>
int main()
{
    int a,b,x;
    scanf("%d %d %d",&a,&b,&x);
    if(a>x)
    {
        printf("NO");
    }
    else
    {
        if((a+b)>=x)
        {
            printf("YES");
        }
        else
        {
            printf("NO");
        }
    }
return 0;
}
//  [c]
#include<stdio.h>
int main ()
{
	int A, B, X;
	scanf("%d%d%d",&A,&B,&X);
	if(X<=A+B && X>A || X==A)
	{
		printf("YES");
	}
	else
	{
		printf("NO");
	}
	return 0;
}
//  [c]
#include <stdio.h>
int main ()
{
    int a,b,x,d;
    scanf("%d%d%d",&a,&b,&x);
    d=a+b;
    if(a==x)
    printf("YES\n");
    else if(a<x&&d>=x)
    printf("YES\n");
    else
    printf("NO\n");
    return 0;
}
//  [javascript]
function Main(s) {
  s = s.split(" ").map(a => +a);
  console.log(s[0] <= s[2] && s[0] + s[1] >= s[2] ? "YES" : "NO");
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));
//  [javascript]
function Main(input) {
  var input = input.split(" ");
  var A = parseInt(input[0]);
  var B = parseInt(input[1]);
  var X = parseInt(input[2]);
  var result = null;
  var CatDog = A + B;
  if (A <= X && CatDog >= X) {
    result = 'YES';
  } else {
    result = 'NO';
  }
  console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input){
    var data = input.split(" ");
    for(var i = 0; i < 3; i++){
        data[i] = parseInt(data[i]);
    }
    
    if(data[0] + data[1] < data[2] || data[0] > data[2]){
        console.log("NO");
        return;
    }
    
    console.log("YES");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import "fmt"

func main() {
	var a, b, x int
	fmt.Scan(&a, &b, &x)

	if 0 <= (x-a) && (x-a) <= b {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}
//  [go]
package main

import "fmt"

func main() {
	// Code for A - Cats and Dogs
	var A, B, X int
	fmt.Scanf("%d %d %d", &A, &B, &X)

	if A+B >= X && A <= X {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b, x := intScanner(), intScanner(), intScanner()
	if a <= x && x <= a+b {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}
//  [ruby]
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

a,b,x=gi

puts x-a<=b && x-a >= 0 ? "YES" : "NO"
//  [ruby]
a, b, x = gets.split.map &:to_i
puts (a+b) >= x && a <= x ? :YES: :NO
//  [ruby]
a,b,x = gets.chomp.split(" ").map(&:to_i)
if a <= x && a+b >= x
  puts "YES"
else
  puts "NO"
end
//  [rust]
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[fastout]
fn main() {
    input! {
        a: usize,
        b: usize,
        x: usize,
    }

    let mut ans = "";
    if a <= x && x <= a + b {
        ans = "YES"
    } else {
        ans = "NO"
    }
    println!("{}", ans);
}
//  [rust]
#![allow(unused_imports)]
#![allow(dead_code)]
use proconio::input;
use proconio::fastout;
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        a:i32,b:i32,x:i32,
    }
    println!("{}",if a<=x&&x<=a+b{"YES"}else{"NO"});
}
//  [rust]
use std::io;
use std::str::FromStr;

fn input_tuple() -> (u64, u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1], vec[2])
}


fn main() {
    let (a, b, x) = input_tuple();
    if x <= a + b && a <= x {
        println!("YES");
    } else {
        println!("NO");
    }
}
//  [typescript]
var lines: string[] = [];
var reader: any = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on("line", function(line: string) {
  lines.push(line);
});
reader.on("close", function() {
  var value_a: number = Number(lines[0].split(" ")[0]);
  var value_b: number = Number(lines[0].split(" ")[1]);
  var value_x: number = Number(lines[0].split(" ")[2]);
  if (value_a > value_x) {
    console.log("NO");
  } else if (value_b >= value_x - value_a) {
    console.log("YES");
  } else {
    console.log("NO");
  }
});
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [A, B, X] = input[0].map(Number);

  return A <= X && A + B >= X ? "YES" : "NO";
};

console.log(main(read()));
//  [typescript]
namespace Coder {
  class Scanner {
    private buffer: string = '';
    private stdinQueue: any = [];

    constructor() {
      process.stdin.resume();
      process.stdin.setEncoding('utf8');
      process.stdin.on(
        'data',
        (chunk): void => {
          this.buffer += chunk;
          while (this.stdinQueue.length > 0) {
            const i = this.buffer.indexOf('\n');
            if (i < 0) {
              break;
            }
            let line = this.buffer.substr(0, i);
            if (line.endsWith('\r')) {
              line = line.slice(0, -1);
            }
            this.buffer = this.buffer.substr(i + 1);
            this.stdinQueue.shift()(line);
          }
        },
      );
    }
    public getLine(): Promise<string> {
      return new Promise((resolve, reject) => {
        const i = this.buffer.indexOf('\n');
        if (i >= 0 && this.stdinQueue.length === 0) {
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          resolve(line);
        } else {
          this.stdinQueue.push(resolve);
        }
      });
    }

    public close(): void {
      process.stdin.pause();
    }
  }

  async function solve() {
    const sc = new Scanner();
    const [A, B, X]: number[] = (await sc.getLine()).split(' ').map((x) => +x);
    if (A > X || A + B < X) {
      console.log('NO');
    } else {
      console.log('YES');
    }
    sc.close();
  }
  solve();
}
//  [python]
import sys

def main():
    N = int(input())
    A_list = list(map(int, input().split()))

    h_list = [0] * N

    for i, i_A in enumerate(A_list):
        if i - i_A >= 0:
            h_list[i-i_A] += 1

    total_pair = 0
    for i, i_A in enumerate(A_list):
        if i+i_A <= N-1:
            total_pair += h_list[i+i_A]

    print(total_pair)
    return
    
if __name__ == '__main__':
    main()
    sys.exit(0)
//  [python]
n = int(input())

arr = list(map(int, input().split()))
ar2 = [0] * n

for i in range(n):
    x = i-arr[i]
    if x >= 0:
        ar2[x] += 1

total = 0
for i in range(n):
    x = i+arr[i]
    if x < n:
        total += ar2[x]

print(total)
//  [python]

def main():
    pass
    N = int(input())
    A = list(map(int, input().split()))

    H = [0]*N
    for i in range(0,N):
        if i >= A[i]:
            H[i-A[i]] += 1

    ans = 0
    for k in range(0,N):
        Bk = k+A[k]
        if Bk < N:
            ans += H[Bk]

    print(ans)

if __name__ == '__main__':
    main()
//  [python]
def lower_bound(arr,tar):
    def _lower_bound(first,length):
        if(length==0):
            return first

        half = length//2
        middle = first+half
        if arr[middle]<tar:
            return _lower_bound(middle+1,length-half-1)
        else:
            return _lower_bound(first,half)
    return _lower_bound(0,len(arr))

def upper_bound(arr,tar):
    def _upper_bound(first,length):
        if(length==0):
            return first

        half = length//2
        middle = first+half
        if arr[middle]>tar:
            return _upper_bound(first,half)
        else:
            return _upper_bound(middle+1,length-half-1)
    return _upper_bound(0,len(arr))

N=int(input())
a=list(map(int,input().split()))
L = [(i+1)+a[i] for i in range(N)]
R = [(i+1)-a[i] for i in range(N)]
R.sort()

s=0
for it in L:
    s+=upper_bound(R,it)-lower_bound(R,it)
print(s)
//  [python]
# E - This Message Will Self-Destruct in 5s
from bisect import *
N = int(input())
A = list(map(int,input().split()))
l = []
ans = 0
for j in range(N):
    tmp = j-A[j]
    ans += bisect_right(l,tmp)-bisect_left(l,tmp)
    insort(l,A[j]+j)
print(ans)
//  [python]
n = int(input())
a = list(map(int,input().split()))
q = 0
z = 1000
p = []*z
m = []*z
for i in range(z):
    p.append([])
    m.append([])
for i in range(n):
    x = i+1-a[i]
    if(x > 0):
        if(x in p[x%z]):
            m[x%z][p[x%z].index(x)][0] += 1
        else:
            m[x%z].append([1,0])
            p[x%z].append(x)
    x = i+1+a[i]
    if(x in p[x%z]):
        m[x%z][p[x%z].index(x)][1] += 1
    else:
        m[x%z].append([0,1])
        p[x%z].append(x)
    
for i in range(z):
    for j in range(len(m[i])):
        q += m[i][j][0]*m[i][j][1]
print(q)
//  [java]
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] h = new long[N+1];
        Map<Long, List<Integer>> map1 = new HashMap<>();
        Map<Long, List<Integer>> map2 = new HashMap<>();
        for (int i = 1; i <= N; i++) {
            h[i] = scan.nextLong();
            long x1 = h[i] - i;
            List<Integer> list1 = map1.getOrDefault(x1, new ArrayList<>());
            list1.add(i);
            map1.put(x1, list1);
            long x2 = h[i] + i;
            List<Integer> list2 = map2.getOrDefault(x2, new ArrayList<>());
            list2.add(i);
            map2.put(x2, list2);
        }
        for (long x : map1.keySet()) {
            List<Integer> list = map1.get(x);
            list.sort(Comparator.naturalOrder());
        }
        for (long x : map2.keySet()) {
            List<Integer> list = map2.get(x);
            list.sort(Comparator.naturalOrder());
        }
        long ans = 0;
        for (int i = 1; i <= N; i++) {
            long x1 = h[i] - i;
            if (!map2.containsKey(-x1)) {
                continue;
            }
            List<Integer> list = map2.get(-x1);
            int left = 0;
            int right = list.size();
            while (left + 1 < right) {
                int mid = (left + right) / 2;
                int m = list.get(mid);
                if (i <= m) {
                    right = mid;
                } else {
                    left = mid;
                }
            }
            ans += left + 1;
        }
        for (int i = 1; i <= N; i++) {
            long x2 = h[i] + i;
            if (!map1.containsKey(-x2)) {
                continue;
            }
            List<Integer> list = map1.get(-x2);
            int left = 0;
            int right = list.size();
            while (left + 1 < right) {
                int mid = (left + right) / 2;
                int m = list.get(mid);
                if (m <= i) {
                    left = mid;
                } else {
                    right = mid;
                }
            }
            ans += list.size() - right + 1;
        }
        System.out.println(ans/2);
    }
}
//  [java]
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N;
	long[] A;
	long count;
	Map<Long, Set<Integer>> upperMap;
	Map<Long, Set<Integer>> lowerMap;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		tokens = in.readLine().split(" ");
		A = new long[N];
		for (int i = 0; i < N; ++i) {
			A[i] = Long.parseLong(tokens[i]);
		}
		upperMap = new HashMap<>();
		lowerMap = new HashMap<>();
		for (int i = 0; i < N; ++i) {
			long upper = A[i] + i;
			long lower = i - A[i];
			if (!upperMap.containsKey(upper)) {
				upperMap.put(upper, new HashSet<>());
			}
			upperMap.get(upper).add(i);
			if (!lowerMap.containsKey(lower)) {
				lowerMap.put(lower, new HashSet<>());
			}
			lowerMap.get(lower).add(i);
		}
	}

	void calc() {
		for(Long upper: upperMap.keySet()) {
			if(lowerMap.containsKey(upper)) {
				count += (long)(upperMap.get(upper).size()) * (long)(lowerMap.get(upper).size());
			}
		}
		System.out.println(count);
	}

	void showResult() {
	}
}
//  [java]
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Map<Integer, Map<Integer, ABC166EAgent>> map = new HashMap<>();
        ABC166EAgent[] agents = new ABC166EAgent[n+1];
        for(int i=1; i<=n; i++) {
            ABC166EAgent a = new ABC166EAgent();
            a.num = i;
            a.height = in.nextInt();
            int key = a.num - a.height;
            if(map.containsKey(key)) {
                Map<Integer, ABC166EAgent> innerMap = map.get(key);
                innerMap.put(a.num, a);
            }
            else {
                Map<Integer, ABC166EAgent> innerMap = new HashMap<>();
                innerMap.put(a.num, a);
                map.put(key, innerMap);
            }
            agents[i] = a;
        }
        
        long ans = 0;
        for(int i=1; i<=n; i++) {
            ABC166EAgent a = agents[i];
            int myKey = a.num - a.height;
            map.get(myKey).remove(a.num);
            
            int searchKey = a.num + a.height;
            Map<Integer, ABC166EAgent> innerMap = map.get(searchKey);
            if(innerMap != null) {
                ans += innerMap.size();
            }
        }
        System.out.println(ans);
    }
}
class ABC166EAgent {
    int num;
    int height;
}
//  [cpp]
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;

	//うーん
	ll u_n = ((tmp & ma0) ^ ma0);
	if (!u_n) {
		ci += 8;
		while (*ci++ >= '0');
		return 1000000000;
	}
	int dig = 68 - __builtin_ctzll(u_n);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (72 - dig >> 3);
	return tmp;
}

int B[200000];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint();

	ll kotae = 0;
	rep(i, N) {
		int a = getint();
		if (i + a < N) B[i + a]++;
		if (i - a >= 0) kotae += B[i - a];
	}
	printf("%lld", kotae);

	Would you please return 0;
}
//  [cpp]
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;

	//うーん
	ll u_n = ((tmp & ma0) ^ ma0);
	if (!u_n) {
		ci += 8;
		while (*ci++ >= '0');
		return 1000000000;
	}
	int dig = 68 - __builtin_ctzll(u_n);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (72 - dig >> 3);
	return tmp;
}

int B[200000];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint();

	ll kotae = 0;
	rep(i, N) {
		int a = getint();
		if (i + a < N) B[i + a]++;
		if (i - a >= 0) kotae += B[i - a];
	}
	printf("%lld", kotae);

	Would you please return 0;
}
//  [cpp]
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;

	//うーん
	ll u_n = ((tmp & ma0) ^ ma0);
	if (!u_n) {
		ci += 8;
		while (*ci++ >= '0');
		return 1000000000;
	}
	int dig = 68 - __builtin_ctzll(u_n);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (72 - dig >> 3);
	return tmp;
}

int B[200000];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint();

	int A[200000];
	rep(i, N) A[i] = getint();

	rep(i, N) if (i + A[i] < N) B[i + A[i]]++;

	ll kotae = 0;
	rep(i, N) if (i - A[i] >= 0) kotae += B[i - A[i]];

	printf("%lld", kotae);

	Would you please return 0;
}
//  [cpp]
#include <bits/stdc++.h>

#define ll long long

using namespace std;

int pmod(int x, int y, int p){ int res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1)  res = (res*x) % p;  y = y>>1; x = (x*x) % p; } return res; }  
ll pmod(ll x, ll y, ll p){ ll res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1)  res = (res*x) % p;  y = y>>1; x = (x*x) % p; } return res; } 


int main(){
	ios_base :: sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	vector <int> a(n),b(n);
	for(auto &i : a)
		cin >> i;
	for(int i = 0; i < n; ++i){
		b[i] = a[i] + i;
		a[i] = a[i] - i;
	}

	unordered_map <int,int> seena, seenb;
	ll res = 0;
	for(int i = 0; i < n; ++i){
		res += seena[-b[i]];
		res += seenb[-a[i]];
		seena[a[i]]++;
		seenb[b[i]]++;
		cerr << res << " " << a[i] << " " << b[i] << endl;
	}
	cout << res;
	return 0;
}

// x2 + x1 = abs(i2 - i1)
// x2 + x1 = i2 - i1 -> x2 - i2 = -(x1 - i1)
// x1 + x2 = - i2 + i1 -> x2 + i2 = -(x1 + i1)
//
//  [cpp]
#pragma GCC target("arch=skylake-avx512")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

int32_t n;
int32_t a[200000];
int32_t b[200000];

int main(void) {
    scanf("%" SCNd32, &n);
    for (int32_t i = 0; i < n; ++i) {
        scanf("%" SCNd32, &a[i]);
        b[i] = a[i] + n - i - 1;
    }
    int64_t cnt = 0;
    for (int32_t i = 0; i < n; ++i) {
        int32_t c = n - i - 1 - a[i];
        for (int32_t j = i + 1; j < n; ++j) {
            if (b[j] == c) {
                ++cnt;
            }
        }
    }
    printf("%" PRId64 "\n", cnt);
}
//  [c]
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

uint32_t nextpint(void){ char c=getchar_unlocked(); while(c<'0'||'9'<c) c=getchar_unlocked(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }
void printint(uint32_t x){ if(x<0){x=-x; putchar_unlocked('-');}else if(x==0){putchar_unlocked('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar_unlocked(s[i]); putchar_unlocked('\n'); }
void rsort_d32(void *base, const int count);

int32_t a[200000];
int32_t b[200000];

int main(void){
	uint32_t n=nextpint();
	for(uint32_t i=0; i<n; i++){
		int32_t k=nextpint();
		a[i]=i+k;
		b[i]=i-k;
	}
	rsort_d32(a, n);
	rsort_d32(b, n);
	uint64_t ans=0;
	uint32_t al=0, bl=0;
	while(al<n){
		int32_t A=a[al];
		while(bl<n && b[bl]<A) bl++;
		if(bl==n) break;
		if(b[bl]==A){
			int32_t ac=0, bc=0;
			while(al<n && a[al]==A) al++, ac++;
			while(bl<n && b[bl]==A) bl++, bc++;
			ans+=(int64_t)ac*bc;
		}else{
			al++;
		}
	}
	printf("%"PRIu64"\n", ans);
}

void rsort_d32(void *base, const int count){
	int32_t *a=base;
	int32_t *b=malloc(count*sizeof(int32_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(0<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(1<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(2<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(3<<3))+0x80]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(3<<3))+0x80]]=a[i]; }{void *t=a; a=b; b=t;}
	free(b);
}
//  [c]
main(){
int i,n,a[200002],b[200002]={0};
long long c=0;
scanf("%d",&n);
for(i=0;i<n;i++)scanf("%d",&a[i]);
for(i=0;i<n;i++){
	if(i+a[i]<=n)b[i+a[i]]++;
	if(i-a[i]>=0)c+=b[i-a[i]];
}
printf("%lld",c);
}
//  [c]
#include <stdio.h>

int main(void){
  int n,a,aa[2000001],i;
  long int ans=0;
  scanf("%d",&n);
  for(i=1;i<n;i++){
    aa[i]=0;
  }
  for(i=1;i<=n;i++){
    scanf("%d",&a);
    if((i-a)>0){
      ans+=aa[i-a];
    }
    if((a+i)<n){
      aa[a+i]++;
    }
  }
  printf("%ld",ans);
  return 0;
}
//  [c]
#pragma GCC target("arch=skylake-avx512")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

int32_t n;
int32_t a[200000];
int32_t b[200000];

int main(void) {
    scanf("%" SCNd32, &n);
    for (int32_t i = 0; i < n; ++i) {
        scanf("%" SCNd32, &a[i]);
        b[i] = a[i] + n - i - 1;
    }
    int64_t cnt = 0;
    for (int32_t i = 0; i < n; ++i) {
        int32_t c = n - i - 1 - a[i];
        for (int32_t j = i + 1; j < n; ++j) {
            if (b[j] == c) {
                ++cnt;
            }
        }
    }
    printf("%" PRId64 "\n", cnt);
}
//  [c]
#pragma GCC target("arch=cascadelake")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

int32_t n;
int32_t a[200000];
int32_t b[200000];

int main(void) {
    scanf("%" SCNd32, &n);
    for (int32_t i = 0; i < n; ++i) {
        scanf("%" SCNd32, &a[i]);
        b[i] = a[i] + n - i - 1;
    }
    int64_t cnt = 0;
    for (int32_t i = 0; i < n; ++i) {
        int32_t c = n - i - 1 - a[i];
        for (int32_t j = i + 1; j < n; ++j) {
            if (b[j] == c) {
                ++cnt;
            }
        }
    }
    printf("%" PRId64 "\n", cnt);
}
//  [c]
#include <stdio.h>

int main(){
  int n,a,b,l[2048][8192]={},c[2048][8192]={},i,j,k,d;
  long m=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&a);
    if(i>=a){
      b=(i-a)>>11;
      d=(i-a)&2047;
      for(j=1;j<=l[d][0];j++){
        if(l[d][j]==b) break;
      }
      if(j<=l[d][0]){
        m+=(long)c[d][j];
      }
    }
    a+=i;
    b=a>>11;
    d=a&2047;
    for(j=1;j<=l[d][0];j++){
      if(l[d][j]==b) break;
    }
    if(j>l[d][0]){
      l[d][j]=b;
      l[d][0]++;
    }
    c[d][j]++;
  }
  printf("%ld",m);
  return(0);
}
//  [javascript]
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var n = next();
  var a = nexts(n);
  var b = xArray(0,n);
  var ans = 0;
  for(var i = 0; i < n; i++){
    var t = i - a[i];
    if(t >= 0)ans += b[t];
    t = i + a[i];
    if(t < n)b[t]++;
  }
  return ans;
}
//  [javascript]
function main(input) {
    input = input.split("\n");
    var N = parseInt(input[0]);
    var Aarray = input[1].split(" ");
    var A = [];
    for (var i = 0; i < N; i++) {
        var a = parseInt(Aarray[i], 10);
        A.push(a);
    }
    var Ap = new Map();
    var Am = new Map();
    var Aplist = [];
    for (var i = 0; i < N; i++) {
        var Ap_tmp = Ap.get(A[i] + i + 1);
        if (Ap_tmp == undefined) {
            Aplist.push(A[i] + i + 1);
            Ap_tmp = 1;
        }
        else
            Ap_tmp++;
        Ap.set(A[i] + i + 1, Ap_tmp);
        var Am_tmp = Am.get(-A[i] + i + 1);
        if (Am_tmp == undefined)
            Am_tmp = 1;
        else
            Am_tmp++;
        Am.set(-A[i] + i + 1, Am_tmp);
    }
    var ans = 0;
    for (var i = 0; i < Aplist.length; i++) {
        var Ap_key = Aplist[i];
        if (Am.get(Ap_key) != undefined)
            ans += Ap.get(Ap_key) * Am.get(Ap_key);
    }

    console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});
	let N = parseInt(input[0][0], 10);
	let v_A = input[1].map(e => parseInt(e, 10));

	let v_checkPlus = [];
	let v_checkMinus = [];

	for (let i = 1; i < N; i++){
		if (i - v_A[0] - v_A[i] < 0) {
			if (v_checkMinus[v_A[0] - i + v_A[i]] == undefined) v_checkMinus[v_A[0] - i + v_A[i]] = 1;
			else v_checkMinus[v_A[0] - i + v_A[i]] ++;
		} else {
			if (v_checkPlus[i - v_A[0] - v_A[i]] == undefined) v_checkPlus[i - v_A[0] - v_A[i]] = 1;
			else v_checkPlus[i - v_A[0] - v_A[i]] ++;
		}
	}

	let tmp = 0;
	let ans = 0;
	for (let i = 1; i < N; i ++){
		// console.log(tmp);
		// console.log(v_checkMinus, v_checkPlus);

		if (tmp <= 0){
			ans += (v_checkPlus[tmp * -1] | 0);
		} else {
			ans += (v_checkMinus[tmp] | 0);
		}

		// console.log("ans", ans);

		if (i - v_A[0] - v_A[i] < 0) {
			v_checkMinus[v_A[0] - i + v_A[i]] --;
		} else {
			v_checkPlus[i - v_A[0] - v_A[i]] --;
		}

		tmp += (v_A[i - 1] - v_A[i] - 1);

		
	}
	
	console.log(ans);

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.trim().split(/ |\n/), cid = 0;

main();

function main() {
    //console.log(cin);
    //   cin = cin.map(i => +i);
    let n = +cin.shift();
    let B = {};
    let C = {};
    cin.forEach((v, i) => {
        const x = Number(v);
        B[i + 1 + x] = B[i + 1 + x] + 1 || 1;
        C[i + 1 - x] = C[i + 1 - x] + 1 || 1;
    });
    //console.log({ B, C })
    let keys = Object.keys(B);
    let ans = 0;
    keys.filter(i => C[i]).forEach(i => {
        ans += (B[i] * C[i]);
        //console.log(i, B[i], C[i]);
    });


    console.log(ans);
}
//  [javascript]
"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.split(/ |\n/), cid = 0;

main();

function main() {
    //console.log(cin);
    //   cin = cin.map(i => +i);
    let n = +cin.shift();
    let B = {};
    let C = {};
    for (let i = 0; i < n; i++) {
        const x = Number(cin[i]);
        B[i + 1 + x] = B[i + 1 + x] + 1 || 1;
        C[i + 1 - x] = C[i + 1 - x] + 1 || 1;
    }
    //console.log({ B, C })
    let keys = Object.keys(B);
    let ans = 0;
    keys.filter(i => C[i]).forEach(i => {
        ans += (B[i] * C[i]);
        //console.log(i, B[i], C[i]);
    });


    console.log(ans);
}
//  [javascript]
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var N = nextInt();
	var list = nextIntArray();
	var lMap = {};
	var rMap = {};
	var output = 0;
	for(var i = 0; i < N; i++){
		if(lMap[list[i] + i] == null){
			lMap[list[i] + i] = 1;
		}else{
			lMap[list[i] + i]++;
		}
		if(rMap[i - list[i]] == null){
			rMap[i - list[i]] = 1;
		}else{
			rMap[i - list[i]]++;
		}
	}
	
	var keys = Object.keys(lMap);
	for(var i = 0; i < keys.length; i++){
		if(rMap[keys[i]] != null){
			output += lMap[keys[i]] * rMap[keys[i]];
		}
	}
	myout(output);
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 100000007)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(Scanner())
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(Scanner())
	}
	ans := 0
	l := make([]int, n)
	s := make([]int, n)
	for i := 0; i < n; i++ {
		if a[i]+i < n {
			l[a[i]+i]++
		}
		if i-a[i] > 0 {
			s[i-a[i]]++
		}
	}
	for i := 0; i < n; i++ {
		ans += l[i] * s[i]
	}
	fmt.Println(ans)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n := readInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}

	l := make([]int, n)
	s := make([]int, n)
	ans := 0
	for i := 0; i < n; i++ {
		if a[i]+i < n {
			l[a[i]+i]++
		}
		if i-a[i] > 0 {
			s[i-a[i]]++
		}
	}
	for i := 0; i < n; i++ {
		ans += l[i] * s[i]
	}
	fmt.Println(ans)
}

func myAbs(a int, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readChar() rune {
	stdinScanner.Scan()
	temp := stdinScanner.Text()
	return rune(temp[0])
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	l := make([]int, N)
	r := make([]int, N)
	for i := 0; i < N; i++ {
		if i-a[i] > 0 {
			l[i-a[i]]++
		}
		if i+a[i] < N {
			r[i+a[i]]++
		}
	}

	ans := 0
	for i := 0; i < N; i++ {
		ans += r[i] * l[i]
	}

	// out(r)
	// out(l)
	out(ans)
	// ans := 0
	// for i := 0; i < N; i++ {
	// 	for j := i + a[i]; j < N; j++ {
	// 		if a[i]+a[j] == j-i {
	// 			ans++
	// 		}
	// 	}
	// }
	// out(ans)
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	height := scanIntSlice(n)

	plus := map[int][]int{}
	minus := map[int][]int{}

	for i := 1; i <= n; i++ {
		p := i + height[i-1]
		if _, ok := plus[p]; !ok {
			plus[p] = []int{}
		}
		plus[p] = append(plus[p], i)

		m := i - height[i-1]
		if _, ok := minus[m]; !ok {
			minus[m] = []int{}
		}
		minus[m] = append(minus[m], i)
	}

	count := 0
	for x, _ := range plus {
		count += len(plus[x]) * len(minus[x])
	}

	fmt.Printf("%d\n", count)
}

func scanIntSlice(size int) []int {
	input := []int{}
	for i := 0; i < size; i++ {
		var in int
		fmt.Scanf("%d", &in)
		input = append(input, in)
	}
	return input
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var e, n, i, count int64
	fmt.Scan(&n)
	a := make(map[int64]int64)
	b := make(map[int64]int64)

	for i = 1; i <= n; i++ {
		fmt.Scan(&e)
		a[i+e]++
		b[i-e]++
	}
	for index := range a {
		if int64(index) > 0 && b[index] != 0 {
			count += a[index] * b[index]
		}
	}
	fmt.Println(count)
}
//  [go]
// i<j -> j-i = A[i]+A[j] -> j-A[j] = A[i] + i
// なんか解説もtwtterでも解説記事でもぜんぜんわからんかったんだけど
// https://www.cnblogs.com/prjruckyone/p/12825560.html
// を読んだら分かった ありがとう 謝謝 暴力即可

package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		var V int
		fmt.Scan(&V)
		A[i] = V
	}
	X, Y := make(map[int]int), make(map[int]int)
	for i := 1; i <= N; i++ {
		x := A[i-1] + i
		y := i - A[i-1]
		X[x] += 1
		Y[y] += 1
	}
	ans := 0
	for k, v := range X {
		ans += Y[k] * v
	}
	fmt.Println(ans)
}
//  [ruby]
n = gets.to_s.to_i
a = gets.to_s.split.map{|t|t.to_i}

h = Array.new(n, 0)
ans = 0
a.each_with_index do |e, i|
  ans      += h[i - e] if i - e >= 0
  h[i + e] += 1        if i + e < n
end

puts ans
//  [ruby]
N,*A = $<.read.split.map &:to_i
t,B = 0,Array.new(N,0)
N.times {|i;j|
  a = A[i]
  B[j] += 1  if N > j=i+a
  t += B[j]  if 0 <= j=i-a
}
p t
//  [ruby]
n = gets.to_s.to_i

h = Array.new(n, 0)
ans = 0
d = $<.read.split.map{|t|t.to_i}.each_with_index do |e, i|
  ans      += h[i - e] if i - e >= 0
  h[i + e] += 1        if i + e < n
end

puts ans