#include <bits/stdc++.h>
using namespace std;
struct person{
	string name;
	int age;
};
int main() {
	// vector<int> arr={3,2,3,3,2,4};
	// map<int,int> ok;
	// for(int i=0;i<arr.size();i++){
	// 	ok[arr[i]]++;
	// }
	// int maxl,minl,max=0,min=;
	// for(auto it=ok.begin();it!=ok.end();it++){
	// 	cout<<it->first<<"  "<<it->second<<endl;
	// 	if(it->second>max){
	// 		max=it->second;
	// 		maxl=it->first;
	// 	} 
	// 	if(it->second < min){
	// 		min=it->second;
	// 		minl=it->first;
	// 	}
	// }
	// cout<<"maxelement  "<<maxl<<"  freq  "<<max;
	// cout<<"minelement   "<<minl<<"    freq  "<<min;
	
	
	// vector<person> people;
	// people.push_back({"asha",22});
	// people.push_back({"prem",18});
	// people.push_back({"anu",48});
	// for(auto& it:people){
	// 	cout<<(it).name<<endl; //here it is a reference variable
	// }
	
	// map<string,person> ok;
	// ok["asha"]={"asha",22};
	// ok["prem"]={"prem",18};
	// ok["anu"]={"anu",23};
	
	// for(auto& it:ok){
	// 	cout<<it.second.age<<endl;
	// }
	
	// for(auto it=ok.begin();it!=ok.end();it++){
	// 	cout<<it->second.age<<endl;
	// }
	// cout<<ok["asha"].name<<endl;
	
	// --check if there are any two equal numbers in an array at a distance less than or equal to k--
	// brute force o(n2)
	// int arr[]={1,2,1,3,4,2,3,3};
	// int k=2,count=0;
	// for(int i=0;i<7;i++){
	// 	for(int j=i+1;j<=i+k && j<8;j++){
	// 		if(arr[i]==arr[j]){
	// 			count++;
	// 		}
	// 	}
	// }
	// cout<<count;
	
	//hashmap
	// int arr[]={1,2,1,3,4,2,3,3};
	// int k=2,count=0;
	// unordered_map<int,int>ok;
	// for(int i=0;i<8;i++){
	// 	if(ok.find(arr[i])!=ok.end() && i-ok[arr[i]]<=k){
	// 		count++;
	// 	}
	// 	ok[arr[i]]=i;
		
	// }
	// cout<<count<<endl;
	// for(auto it=ok.begin();it!=ok.end();it++){
	// 	cout<<it->first<<"     "<<it->second<<endl;
	// }
	
	
	//count all the i j pairs i<j such that arr[i]+arr[j]==k
	// brute force
	// int arr[]={1,2,1,3,4,2,3,3};
	// int k=3,count=0;
	// for(int i=0;i<8;i++){
	// 	for(int j=i+1;j<8;j++){
	// 		if(arr[i]+arr[j]==k){
	// 			count++;
	// 			cout<<i<<"     "<<j<<endl;
	// 		}
	// 	}
	// }
	// cout<<count<<endl;
	
	//hashmap
	// unordered_map<int,int> ok;
	// int arr[]={1,2,1,3,4,2,3,3};
	// int k=2,count=0;
	// for(int i=0;i<8;i++){
	// 	if(ok.find(k-arr[i])!=ok.end()){
	// 		auto it=ok.find(k-arr[i]);
	// 		count+=it->second;
	// 	}
	// 	ok[arr[i]]++;
	// }
	// cout<<count<<endl;
	
	
	// count all the i j pairs i<j such that arr[i]-arr[j]==k
	// brute force
	// int arr[]={1,2,1,3,4,2,3,3};
	// int k=1,count=0;
	// for(int i=0;i<8;i++){
	// 	for(int j=i+1;j<8;j++){
	// 		if(arr[i]-arr[j]==k){
	// 			count++;
	// 			cout<<i<<"     "<<j<<endl;
	// 		}
	// 	}
	// }
	// cout<<count<<endl;
	
	
	//hashmap
	unordered_map<int,int> ok;
	int arr[]={1,2,1,3,4,2,3,3};
	int k=1,count=0;
	for(int i=0;i<8;i++){
		if(ok.find(k+arr[i])!=ok.end()){
			auto it=ok.find(k+arr[i]);
			count+=it->second;
		}
		ok[arr[i]]++;
	}
	cout<<count<<endl;
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	return 0;
}