#include <bits/stdc++.h>

using namespace std;

const int mxn = 2e5;

int x[mxn + 11];
int y[mxn + 11];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d %d", x + i, y + i);
	}
	int cnt = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			int a = x[i] - x[j];
			int b = y[i] - y[j];
			if (a < 0)
				a = -a;
			if (b < 0)
				b = -b;
			if (a == b) {
				cnt++;
			}
		}
	}
	int ans = cnt * (cnt - 1) / 2;
	printf("%d\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<int> vi;
typedef vector<long long int > vll;
typedef vector<pair<int,int>> pi;
typedef vector<pair<lld,lld>> pll;
#define rep(i,a,b) for(i=a;i<b;i++)
#define sep(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define srt(s) sort(s.begin(),s.end())
#define rev(s) reverse(s.begin(),s.end())
#define mod 1000000007
#define pi 3.14159265358979323846
lld a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p=0,q=0,r,s,t,u,v,w,x,y,z,temp=0,t1,t2,sum=0;
double ans=0;
vll v1,v2,v3,v4,v5,v6;
vector <string> vs1,vs2,vs3,vs4;
vector <pair<string,string>> vs11,vs12;
vector <char> vc1,vc2,vc3;
double f1,f2=0,f3,f4;
vector <double> v10;
pll v11,v12,v13,v14;
string s1,s2,s3,s4,s5,s6,s7,s8,s9;
//lld a10[100][3];
lld a1[1000000],a2[1000000];
char c1,c2,c3;
map<int,int> m1,m2,m3;
map <string,string>ms1,ms2,ms3;
stack <char> sc1,sc2;
//string as1[1000000],as2[1000000];
lld fact(lld u)
{
         if(u==1)
        {
              return 1;
        }
        else
        {
             return u * fact(u-1);
        }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    int a13[n];
    rep(i,0,n)
    {
        cin>>g>>h;
        v1.pb(g);
        v2.pb(h);
    }
    rep(i,0,2001)
    {
        v3.pb(0);
        v4.pb(0);
    }
    a=0;b=0;c=0;
    rep(i,0,n)
    {
        v3[v1[i]+v2[i]]++;
    }
    rep(i,0,n)
    {
        if(v2[i]>=v1[i])
        v4[(v2[i]-v1[i])]++;
    }
    rep(i,0,2001)
    {
        p=p+(v3[i]*(v3[i]-1))/2;
        p=p+(v4[i]*(v4[i]-1))/2;
    }
    cout<<p;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<int> vi;
typedef vector<long long int > vll;
typedef vector<pair<int,int>> pi;
typedef vector<pair<lld,lld>> pll;
#define rep(i,a,b) for(i=a;i<b;i++)
#define sep(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define srt(s) sort(s.begin(),s.end())
#define rev(s) reverse(s.begin(),s.end())
#define mod 1000000007
#define pi 3.14159265358979323846
lld a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p=0,q=0,r,s,t,u,v,w,x,y,z,temp=0,t1,t2,sum=0;
double ans=0;
vll v1,v2,v3,v4,v5,v6;
vector <string> vs1,vs2,vs3,vs4;
vector <pair<string,string>> vs11,vs12;
vector <char> vc1,vc2,vc3;
double f1,f2=0,f3,f4;
vector <double> v10;
pll v11,v12,v13,v14;
string s1,s2,s3,s4,s5,s6,s7,s8,s9;
//lld a10[100][3];
lld a1[1000000],a2[1000000];
char c1,c2,c3;
map<int,int> m1,m2,m3;
map <string,string>ms1,ms2,ms3;
stack <char> sc1,sc2;
//string as1[1000000],as2[1000000];
lld fact(lld u)
{
         if(u==1)
        {
              return 1;
        }
        else
        {
             return u * fact(u-1);
        }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    int a13[n];
    rep(i,0,n)
    {
        cin>>g>>h;
        v1.pb(g);
        v2.pb(h);
    }
    rep(i,0,2001)
    {
        v3.pb(0);
        v4.pb(0);
    }
    a=0;b=0;c=0;
    rep(i,0,n)
    {
        v3[v1[i]+v2[i]]++;
    }
    rep(i,0,n)
    {
        v4[(v1[i]-v2[i])+999]++;
    }
    rep(i,0,1999)
    {
        p=p+(v3[i]*(v3[i]-1))/2;
        p=p+(v4[i]*(v4[i]-1))/2;
    }
    rep(i,1999,2001)
    {
        p=p+((v4[i])*(v4[i]-1))/2;
    }
    cout<<p;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<int> vi;
typedef vector<long long int > vll;
typedef vector<pair<int,int>> pi;
typedef vector<pair<lld,lld>> pll;
#define rep(i,a,b) for(i=a;i<b;i++)
#define sep(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define srt(s) sort(s.begin(),s.end())
#define rev(s) reverse(s.begin(),s.end())
#define mod 1000000007
#define pi 3.14159265358979323846
lld a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p=0,q=0,r,s,t,u,v,w,x,y,z,temp=0,t1,t2,sum=0;
double ans=0;
vll v1,v2,v3,v4,v5,v6;
vector <string> vs1,vs2,vs3,vs4;
vector <pair<string,string>> vs11,vs12;
vector <char> vc1,vc2,vc3;
double f1,f2=0,f3,f4;
vector <double> v10;
pll v11,v12,v13,v14;
string s1,s2,s3,s4,s5,s6,s7,s8,s9;
//lld a10[100][3];
lld a1[1000000],a2[1000000];
char c1,c2,c3;
map<int,int> m1,m2,m3;
map <string,string>ms1,ms2,ms3;
stack <char> sc1,sc2;
//string as1[1000000],as2[1000000];
lld fact(lld u)
{
         if(u==1)
        {
              return 1;
        }
        else
        {
             return u * fact(u-1);
        }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    int a13[n];
    rep(i,0,n)
    {
        cin>>g>>h;
        v1.pb(g);
        v2.pb(h);
    }
    rep(i,0,2001)
    {
        v3.pb(0);
        v4.pb(0);
    }
    a=0;b=0;c=0;
    rep(i,0,n)
    {
        v3[v1[i]+v2[i]]++;
    }
    rep(i,0,n)
    {
        v4[(v1[i]-v2[i])+999]++;
    }
    rep(i,0,1999)
    {
        p=p+(v3[i]*(v3[i]-1))/2;
        p=p+(v4[i]*(v4[i]-1))/2;
    }
    rep(i,1999,2001)
    {
        p=p+((v3[i])*(v3[i]-1))/2;
    }
    cout<<p;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<int> vi;
typedef vector<long long int > vll;
typedef vector<pair<int,int>> pi;
typedef vector<pair<lld,lld>> pll;
#define rep(i,a,b) for(i=a;i<b;i++)
#define sep(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define srt(s) sort(s.begin(),s.end())
#define rev(s) reverse(s.begin(),s.end())
#define mod 1000000007
#define pi 3.14159265358979323846
lld a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p=0,q=0,r,s,t,u,v,w,x,y,z,temp=0,t1,t2,sum=0;
double ans=0;
vll v1,v2,v3,v4,v5,v6;
vector <string> vs1,vs2,vs3,vs4;
vector <pair<string,string>> vs11,vs12;
vector <char> vc1,vc2,vc3;
double f1,f2=0,f3,f4;
vector <double> v10;
pll v11,v12,v13,v14;
string s1,s2,s3,s4,s5,s6,s7,s8,s9;
//lld a10[100][3];
lld a1[1000000],a2[100000];
char c1,c2,c3;
map<int,int> m1,m2,m3;
map <string,string>ms1,ms2,ms3;
stack <char> sc1,sc2;
//string as1[1000000],as2[1000000];
lld fact(lld u)
{
         if(u==1)
        {
              return 1;
        }
        else
        {
             return u * fact(u-1);
        }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    int a13[n];
    rep(i,0,n)
    {
        cin>>g>>h;
        v1.pb(g);
        v2.pb(h);
    }
    rep(i,1,2002)
    {
        a1[i]=0;
        a2[i]=0;
    }
    a=0;b=0;c=0;
    rep(i,0,n)
    {
        a1[v1[i]+v2[i]]++;
    }
    rep(i,0,n)
    {
        if(v2[i]>=v1[i])
        a2[(v2[i]-v1[i])]++;
    }
    rep(i,0,2002)
    {
        p=p+(a1[i]*(a1[i]-1))/2;
        p=p+(a2[i]*(a2[i]-1))/2;
    }
    cout<<p;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<int> vi;
typedef vector<long long int > vll;
typedef vector<pair<int,int>> pi;
typedef vector<pair<lld,lld>> pll;
#define rep(i,a,b) for(i=a;i<b;i++)
#define sep(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define srt(s) sort(s.begin(),s.end())
#define rev(s) reverse(s.begin(),s.end())
#define mod 1000000007
#define pi 3.14159265358979323846
lld a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p=0,q=0,r,s,t,u,v,w,x,y,z,temp=0,t1,t2,sum=0;
double ans=0;
vll v1,v2,v3,v4,v5,v6;
vector <string> vs1,vs2,vs3,vs4;
vector <pair<string,string>> vs11,vs12;
vector <char> vc1,vc2,vc3;
double f1,f2=0,f3,f4;
vector <double> v10;
pll v11,v12,v13,v14;
string s1,s2,s3,s4,s5,s6,s7,s8,s9;
//lld a10[100][3];
lld a1[1000000],a2[1000000];
char c1,c2,c3;
map<int,int> m1,m2,m3;
map <string,string>ms1,ms2,ms3;
stack <char> sc1,sc2;
//string as1[1000000],as2[1000000];
lld fact(lld u)
{
         if(u==1)
        {
              return 1;
        }
        else
        {
             return u * fact(u-1);
        }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    int a13[n];
    rep(i,0,n)
    {
        cin>>g>>h;
        v1.pb(g);
        v2.pb(h);
    }
    rep(i,0,2001)
    {
        v3.pb(0);
        v4.pb(0);
    }
    a=0;b=0;c=0;
    rep(i,0,n)
    {
        v3[v1[i]+v2[i]]++;
    }
    rep(i,0,n)
    {
        if(v2[i]>=v1[i])
        v4[(v2[i]-v1[i])+999]++;
    }
    rep(i,0,1999)
    {
        p=p+(v3[i]*(v3[i]-1))/2;
        p=p+(v4[i]*(v4[i]-1))/2;
    }
    rep(i,1999,2001)
    {
        p=p+((v4[i])*(v4[i]-1))/2;
    }
    cout<<p;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<int> vi;
typedef vector<long long int > vll;
typedef vector<pair<int,int>> pi;
typedef vector<pair<lld,lld>> pll;
#define rep(i,a,b) for(i=a;i<b;i++)
#define sep(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define srt(s) sort(s.begin(),s.end())
#define rev(s) reverse(s.begin(),s.end())
#define mod 1000000007
#define pi 3.14159265358979323846
lld a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p=0,q=0,r,s,t,u,v,w,x,y,z,temp=0,t1,t2,sum=0;
double ans=0;
vll v1,v2,v3,v4,v5,v6;
vector <string> vs1,vs2,vs3,vs4;
vector <pair<string,string>> vs11,vs12;
vector <char> vc1,vc2,vc3;
double f1,f2=0,f3,f4;
vector <double> v10;
pll v11,v12,v13,v14;
string s1,s2,s3,s4,s5,s6,s7,s8,s9;
//lld a10[100][3];
lld a1[1000000],a2[100000];
char c1,c2,c3;
map<int,int> m1,m2,m3;
map <string,string>ms1,ms2,ms3;
stack <char> sc1,sc2;
//string as1[1000000],as2[1000000];
lld fact(lld u)
{
         if(u==1)
        {
              return 1;
        }
        else
        {
             return u * fact(u-1);
        }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    int a13[n];
    rep(i,0,n)
    {
        cin>>g>>h;
        v1.pb(g);
        v2.pb(h);
    }
    rep(i,1,2002)
    {
        a1[i]=0;
        a2[i]=0;
    }
    a=0;b=0;c=0;
    rep(i,0,n)
    {
        a1[v1[i]+v2[i]]++;
    }
    rep(i,0,n)
    {
        if(v2[i]>v1[i])
        a2[(v2[i]-v1[i])]++;
    }
    rep(i,0,2002)
    {
        p=p+(a1[i]*(a1[i]-1))/2;
        p=p+(a2[i]*(a2[i]-1))/2;
    }
    cout<<p;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 1e3+5;

ll arr[N][N];
ll dp1[N][N],dp2[N][N];

int main(){
	fast;
	ll t = 1;
	//cin >> t;
	while(t--){
	    ll n; cin >> n;
	    rep(i,1,n){
	       ll x,y; cin >> x >> y;
	       arr[x][y]++;
	    }

	    for(ll i = n; i >= 1; i--){
	        rep(j,1,n){
	            if(arr[i][j]) dp1[i][j]++;
	            dp1[i][j] += dp1[i+1][j+1];
	        }
	    }

	    for(ll i = n; i >= 1; i--){
	        rep(j,1,n){
	            if(arr[i][j]) dp2[i][j]++;
	            dp2[i][j] += dp2[i+1][j-1];
	        }
	    }

	    ll ans = 0;

	    rep(i,1,n){
	        ll x = dp1[1][i];
	        ans += (x * (x - 1) / 2);
	    }

	    rep(i,1,n){
	        ll x = dp2[1][i];
	        ans += (x * (x - 1) / 2);
	    }

	    cout << ans << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 1e3+5;

ll arr[N][N];
ll dp1[N][N],dp2[N][N];

int main(){
	fast;
	ll t = 1;
	//cin >> t;
	while(t--){
	    ll n; cin >> n;
	    ll limit_ = 10;
	    rep(i,1,n){
	       ll x,y; cin >> x >> y;
	       arr[x][y]++;
	    }

	    for(ll i = limit_ ; i >= 1; i--){
	        rep(j,1,limit_ ){
	            if(arr[i][j]) dp1[i][j]++;
	            dp1[i][j] += dp1[i+1][j+1];
	        }
	    }

	    for(ll i = limit_ ; i >= 1; i--){
	        rep(j,1,limit_ ){
	            if(arr[i][j]) dp2[i][j]++;
	            dp2[i][j] += dp2[i+1][j-1];
	        }
	    }

	    ll ans = 0;

	    rep(i,1,limit_ ){
	        ll x = dp1[1][i];
	        ans += (x * (x - 1) / 2);
	    }

	    rep(i,2,limit_ ){
	        ll x = dp1[i][1];
	        ans += (x * (x - 1) / 2);
	    }

	    rep(i,1,limit_ ){
	        ll x = dp2[1][i];
	        ans += (x * (x - 1) / 2);
	    }

	    rep(i,2,limit_ ){
	        ll x = dp2[i][limit_];
	        ans += (x * (x - 1) / 2);
	    }

	    cout << ans << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 1e3+5;

ll arr[N][N];
ll dp1[N][N],dp2[N][N];

int main(){
	fast;
	ll t = 1;
	//cin >> t;
	while(t--){
	    ll n; cin >> n;
	    rep(i,1,n){
	       ll x,y; cin >> x >> y;
	       arr[x][y]++;
	    }

	    for(ll i = N; i >= 1; i--){
	        rep(j,1,N){
	            if(arr[i][j]) dp1[i][j]++;
	            dp1[i][j] += dp1[i+1][j+1];
	        }
	    }

	    for(ll i = N; i >= 1; i--){
	        rep(j,1,N){
	            if(arr[i][j]) dp2[i][j]++;
	            dp2[i][j] += dp2[i+1][j-1];
	        }
	    }

	    ll ans = 0;

	    rep(i,1,N){
	        ll x = dp1[1][i];
	        ans += (x * (x - 1) / 2);
	    }

	    rep(i,1,N){
	        ll x = dp2[1][i];
	        ans += (x * (x - 1) / 2);
	    }

	    cout << ans << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 1e3+5;

ll arr[N][N];
ll dp1[N][N],dp2[N][N];

int main(){
	fast;
	ll t = 1;
	//cin >> t;
	while(t--){
	    ll n; cin >> n;
	    ll limit_ = N - 3;
	    rep(i,1,n){
	       ll x,y; cin >> x >> y;
	       arr[x][y]++;
	    }

	    for(ll i = limit_ ; i >= 1; i--){
	        rep(j,1,limit_ ){
	            if(arr[i][j]) dp1[i][j]++;
	            dp1[i][j] += dp1[i+1][j+1];
	        }
	    }

	    for(ll i = limit_ ; i >= 1; i--){
	        rep(j,1,limit_ ){
	            if(arr[i][j]) dp2[i][j]++;
	            dp2[i][j] += dp2[i+1][j-1];
	        }
	    }

	    ll ans = 0;

	    rep(i,1,limit_ ){
	        ll x = dp1[1][i];
	        ans += (x * (x - 1) / 2);
	    }

	    rep(i,2,limit_ ){
	        ll x = dp1[i][1];
	        ans += (x * (x - 1) / 2);
	    }

	    rep(i,1,limit_ ){
	        ll x = dp2[1][i];
	        ans += (x * (x - 1) / 2);
	    }

	    rep(i,2,limit_ ){
	        ll x = dp2[i][limit_];
	        ans += (x * (x - 1) / 2);
	    }

	    cout << ans << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 1e3+5;

ll arr[N][N];
ll dp1[N][N],dp2[N][N];

int main(){
	fast;
	ll t = 1;
	//cin >> t;
	while(t--){
	    ll n; cin >> n;
	    ll limit_ = N - 3;
	    rep(i,1,n){
	       ll x,y; cin >> x >> y;
	       arr[x][y]++;
	    }

	    for(ll i = limit_ ; i >= 1; i--){
	        rep(j,1,limit_ ){
	            if(arr[i][j]) dp1[i][j]++;
	            dp1[i][j] += dp1[i+1][j+1];
	        }
	    }

	    for(ll i = limit_ ; i >= 1; i--){
	        rep(j,1,limit_ ){
	            if(arr[i][j]) dp2[i][j]++;
	            dp2[i][j] += dp2[i+1][j-1];
	        }
	    }

	    ll ans = 0;

	    rep(i,1,limit_ ){
	        ll x = dp1[1][i];
	        ans += (x * (x - 1) / 2);
	    }

	    rep(i,1,limit_ ){
	        ll x = dp2[1][i];
	        ans += (x * (x - 1) / 2);
	    }

	    cout << ans << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define L long int
#define IM INT_MAX
#define Im INT_MIN
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define read  freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define pb(x) push_back(x)
#define all(v) sort(v.begin(),v.end())
#define For(j,n) for(int i=j;i<n;i++)

//template<class T>inline bool rd(T &x){int c=getchar();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; x*=sgn; return ~c;}

int main(){

int n;

cin>>n;

map<int,int>mp;
map<int,int>::iterator itr;

for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;

    if(x-y==0)mp[0]++;
    mp[x+y]++;
}

LL ans=0;

for(itr=mp.begin();itr!=mp.end();itr++){
    LL x=itr->second;

    ans+=((x*(x-1))/2);
}

cout<<ans;
return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define L long int
#define IM INT_MAX
#define Im INT_MIN
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define read  freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)

int main(){

fast;

int n,f=0,co1=0,co2=0;

cin>>n;

for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;

    if(x==y)co1++;
    else if(x+y==n+1)co2++;
    if(n%2!=0){
        int z=(n+1)/2;
        if(x==z && y==z)f=1;
    }
}

if(f==1)co2++;
LL ans=(co1*(co1-1))/2;
ans+=( (co2*(co2-1))/2 );

//cout<<co1<<" "<<co2;

cout<<ans;

return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define L long int
#define IM INT_MAX
#define Im INT_MIN
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define read  freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define pb(x) push_back(x)
#define all(v) sort(v.begin(),v.end())
#define For(j,n) for(int i=j;i<n;i++)

//template<class T>inline bool rd(T &x){int c=getchar();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; x*=sgn; return ~c;}

int main(){

int n;

cin>>n;

map<int,int>mp;
map<int,int>::iterator itr;

for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;

    if(x==y){
        mp[0]++;
        if(x+y==n+1)mp[x+y]++;
    }
    else mp[x+y]++;
}

LL ans=0;

for(itr=mp.begin();itr!=mp.end();itr++){
    LL x=itr->second;

    ans+=((x*(x-1))/2);
}

cout<<ans;
return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define L long int
#define IM INT_MAX
#define Im INT_MIN
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define read  freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define pb(x) push_back(x)
#define all(v) sort(v.begin(),v.end())
#define For(j,n) for(int i=j;i<n;i++)

//template<class T>inline bool rd(T &x){int c=getchar();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; x*=sgn; return ~c;}

int main(){

int n;

cin>>n;

LL d1=0,d2=0;

for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;

    if(x-y==0)d1++;
    if(x+y==n+1)d2++;
}

LL r1=(d1*(d1-1))/2;
LL r2=(d2*(d2-1))/2;

cout<<r1+r2;
return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define L long int
#define IM INT_MAX
#define Im INT_MIN
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define read  freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define pb(x) push_back(x)
#define all(v) sort(v.begin(),v.end())
#define For(j,n) for(int i=j;i<n;i++)

//template<class T>inline bool rd(T &x){int c=getchar();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; x*=sgn; return ~c;}

int main(){

int n;

cin>>n;

map<int,int>mp1,mp2;
map<int,int>::iterator itr;

for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;

    mp1[x-y]++;
    mp2[x+y]++;
}

LL ans=0;

for(itr=mp1.begin();itr!=mp1.end();itr++){
    LL x=itr->second;

    ans+=((x*(x-1))/2);
}

for(itr=mp2.begin();itr!=mp2.end();itr++){
    LL x=itr->second;

    ans+=((x*(x-1))/2);
}

cout<<ans;
return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define L long int
#define IM INT_MAX
#define Im INT_MIN
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define read  freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define pb(x) push_back(x)
#define all(v) sort(v.begin(),v.end())
#define For(j,n) for(int i=j;i<n;i++)

//template<class T>inline bool rd(T &x){int c=getchar();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; x*=sgn; return ~c;}

int main(){

int n;

cin>>n;

map<int,int>mp;
map<int,int>::iterator itr;

for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;

    mp[abs(x-y)]++;
    mp[x+y]++;
}

LL ans=0;

for(itr=mp.begin();itr!=mp.end();itr++){
    LL x=itr->second;

    ans+=((x*(x-1))/2);
}

cout<<ans;
return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define L long int
#define IM INT_MAX
#define Im INT_MIN
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define read  freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define pb(x) push_back(x)
#define all(v) sort(v.begin(),v.end())
#define For(j,n) for(int i=j;i<n;i++)

//template<class T>inline bool rd(T &x){int c=getchar();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; x*=sgn; return ~c;}

int main(){

int n;

cin>>n;

map<int,int>mp;
map<int,int>::iterator itr;

for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;

    mp[x-y]++;
    mp[x+y]++;
}

LL ans=0;

for(itr=mp.begin();itr!=mp.end();itr++){
    LL x=itr->second;

    ans+=((x*(x-1))/2);
}

cout<<ans;
return 0;
}


/*
  492C -sheet B - greedy
  25/02/19
  by ahmed_drawy

*/
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
using namespace std;

#define make_pair               mp;
#define lp(i,start , end)       for(int i = start ; i<end ; ++i)
#define lllp(i,start , end)       for(ll i = start ; i<end ; ++i)
#define inN(arr ,  n) for(int i = 0 ; i< n ; ++i)  cin>>arr[i];
#define Rlp(i,start , end)      for(int i = start ; i>end ; --i)
#define all(v)                   ((v).begin(),(v).end())
#define sz(v)                  (int)((v).size())
#define clr(v,d)                memset(v , d , sizeof(v))
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1 << n) - 1)
#define modulo(S, N) ((S) & (N - 1))   // returns S % N, where N is a power of 2 *haven't understood this yet
#define isPowerOfTwo(S) (!(S & (S - 1)))            // done
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))  // TBD
#define turnOffLastBit(S) ((S) & (S - 1))       // turn off last unset bit from right
#define turnOnLastZero(S) ((S) | (S + 1))       //turn on last unset bit from right
#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))
typedef long long               ll;
typedef vector<int>             vi;
typedef vector  <ll>            vll;
typedef vector<vector<int> >    adj;
typedef pair<int ,int>          pii;
const double EPS =1e-7;
const int OO = 1e6;
bool sortpair( const pair<int , int> & x, const pair<int , int> & y){
    return  x.first != y.first ? x.first < y.first : x.second > y.second ;
}
int dcomp(double x , double y){
    return fabs(x-y) <= EPS? 0: x>y?1:-1;
}
void smile() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("/home/www/Desktop/training/in.txt", "r", stdin);
//    freopen("/home/www/Desktop/training/out.txt" , "w" , stdout);
#endif // ONLINE_JUDGE
}
bool can(int x , int y){
    return x>0 && x<1000 && y>0 && y<1000;
}
///we have to check all the diagonals and get the answer in O(1997*2)
/// where for each increment in n which is the length of the side of the grid theno of diagnols increse by 2
/// we check and get the number of the bushops in each diagonal and the sum of( = xi*(xi-1)/2) where xi is the number of bishops
/// in diagonal i
const int M= 1001;
bool g[M][M];
int main() {
    smile();
    int n ; cin >> n;
    lp(i,0,n){
        int x , y ; cin >> x >>y;
//        --x , --y;
        g[x][y] = 1;
    }

    ll ans = 0 ;
    lp(j , 2, n+1){
        int i = 1 , k = j;
        ll cnt = 0 ;
        while(can(i,k)){
           if(g[i][k]) cnt++;
           ++i,--k;
        }

        ans +=(cnt *(cnt-1))/2;
    }
    lp(i , 2, n){
        int j = 1000 , k = i;
        ll cnt = 0 ;
        while(can(k,j)){
            if(g[k][j]) cnt++;
            ++j,--k;
        }

        ans +=(cnt *(cnt-1))/2;
    }
    lp(j , 1, n){
        int i = 1 , k = j;
        ll cnt = 0 ;
        while(can(i,k)){
            if(g[i][k]) cnt++;
            ++i,++k;
        }

        ans +=(cnt *(cnt-1))/2;
    }
    lp(i , 2, n){
        int j = 1 , k = i;
        ll cnt = 0 ;
        while(can(i,k)){
            if(g[k][j]) cnt++;
            ++j,++k;
        }

        ans +=(cnt *(cnt-1))/2;
    }
    cout<<ans;

}


/*
  621B - sheet B
  26/02/19
  by ahmed_drawy

*/
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
using namespace std;

#define make_pair               mp;
#define lp(i,start , end)       for(int i = start ; i<end ; ++i)
#define lllp(i,start , end)       for(ll i = start ; i<end ; ++i)
#define inN(arr ,  n) for(int i = 0 ; i< n ; ++i)  cin>>arr[i];
#define Rlp(i,start , end)      for(int i = start ; i>end ; --i)
#define all(v)                   ((v).begin(),(v).end())
#define sz(v)                  (int)((v).size())
#define clr(v,d)                memset(v , d , sizeof(v))
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1 << n) - 1)
#define modulo(S, N) ((S) & (N - 1))   // returns S % N, where N is a power of 2 *haven't understood this yet
#define isPowerOfTwo(S) (!(S & (S - 1)))            // done
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))  // TBD
#define turnOffLastBit(S) ((S) & (S - 1))       // turn off last unset bit from right
#define turnOnLastZero(S) ((S) | (S + 1))       //turn on last unset bit from right
#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))
typedef long long               ll;
typedef vector<int>             vi;
typedef vector  <ll>            vll;
typedef vector<vector<int> >    adj;
typedef pair<int ,int>          pii;
const double EPS =1e-7;
const int OO = 1e6;
bool sortpair( const pair<int , int> & x, const pair<int , int> & y){
    return  x.first != y.first ? x.first < y.first : x.second > y.second ;
}
int dcomp(double x , double y){
    return fabs(x-y) <= EPS? 0: x>y?1:-1;
}
void smile() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("/home/www/Desktop/training/in.txt", "r", stdin);
//    freopen("/home/www/Desktop/training/out.txt" , "w" , stdout);
#endif // ONLINE_JUDGE
}
bool can(int x , int y){
    return x>0 && x<1000 && y>0 && y<1000;
}
///we have to check all the diagonals and get the answer in O(1997*2)
/// where for each increment in n which is the length of the side of the grid theno of diagnols increse by 2
/// we check and get the number of the bushops in each diagonal and the sum of( = xi*(xi-1)/2) where xi is the number of bishops
/// in diagonal i
const int M= 1001;
bool g[M][M];
int main() {
    smile();
    int n ; cin >> n;
    lp(i,0,n){
        int x , y ; cin >> x >>y;
        g[x][y] = 1;
    }

    ll ans = 0 ;
    lp(j , 2, 1000+1){
        int i = 1 , k = j;
        ll cnt = 0 ;
        while(can(i,k)){
           if(g[i][k]) cnt++;
           ++i,--k;
        }

        ans +=(cnt *(cnt-1))/2;
    }
    lp(i , 2, 1000){
        int j = 1000 , k = i;
        ll cnt = 0 ;
        while(can(k,j)){
            if(g[k][j]) cnt++;
            ++k,--j;    ///debugged
        }

        ans +=(cnt *(cnt-1))/2;
    }
    lp(j , 1, 1000){   /// the red diagonals

        int i = 1 , k = j;
        ll cnt = 0 ;
        while(can(i,k)){
            if(g[i][k]) cnt++;
            ++i,++k;
        }

        ans +=(cnt *(cnt-1))/2;
    }
    lp(i , 2,1000){
        int j = 1 , k = i;
        ll cnt = 0 ;
        while(can(k,j)){
            if(g[k][j]) cnt++;
            ++j,++k;
        }

        ans +=(cnt *(cnt-1))/2;
    }
    cout<<ans;

}


/*
  621B - sheet B
  26/02/19
  by ahmed_drawy

*/
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
using namespace std;

#define make_pair               mp;
#define lp(i,start , end)       for(int i = start ; i<end ; ++i)
#define lllp(i,start , end)       for(ll i = start ; i<end ; ++i)
#define inN(arr ,  n) for(int i = 0 ; i< n ; ++i)  cin>>arr[i];
#define Rlp(i,start , end)      for(int i = start ; i>end ; --i)
#define all(v)                   ((v).begin(),(v).end())
#define sz(v)                  (int)((v).size())
#define clr(v,d)                memset(v , d , sizeof(v))
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1 << n) - 1)
#define modulo(S, N) ((S) & (N - 1))   // returns S % N, where N is a power of 2 *haven't understood this yet
#define isPowerOfTwo(S) (!(S & (S - 1)))            // done
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))  // TBD
#define turnOffLastBit(S) ((S) & (S - 1))       // turn off last unset bit from right
#define turnOnLastZero(S) ((S) | (S + 1))       //turn on last unset bit from right
#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))
typedef long long               ll;
typedef vector<int>             vi;
typedef vector  <ll>            vll;
typedef vector<vector<int> >    adj;
typedef pair<int ,int>          pii;
const double EPS =1e-7;
const int OO = 1e6;
bool sortpair( const pair<int , int> & x, const pair<int , int> & y){
    return  x.first != y.first ? x.first < y.first : x.second > y.second ;
}
int dcomp(double x , double y){
    return fabs(x-y) <= EPS? 0: x>y?1:-1;
}
void smile() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("/home/www/Desktop/training/in.txt", "r", stdin);
//    freopen("/home/www/Desktop/training/out.txt" , "w" , stdout);
#endif // ONLINE_JUDGE
}
bool can(int x , int y){
    return x>0 && x<=1000 && y>0 && y<=1000;
}
///we have to check all the diagonals and get the answer in O(1997*2)
/// where for each increment in n which is the length of the side of the grid theno of diagnols increse by 2
/// we check and get the number of the bishops in each diagonal and the sum of( = xi*(xi-1)/2) where xi is the number of bishops
/// in diagonal i
const int M= 1001;
bool g[M][M];
int main() {
    smile();
    int n ; cin >> n;
    lp(i,0,n){
        int x , y ; cin >> x >>y;
        g[x][y] = 1;
    }

    ll ans = 0 ;
    lp(j , 2, 1000+1){
        int i = 1 , k = j;
        ll cnt = 0 ;
        while(can(i,k)){
           if(g[i][k]) cnt++;
           ++i,--k;
        }
        ans +=(cnt *(cnt-1))/2;
    }
    lp(i , 2, 1000){
        int j = 1000 , k = i;
        ll cnt = 0 ;
        while(can(k,j)){
            if(g[k][j]) cnt++;
            ++k,--j;    ///debugged
        }

        ans +=(cnt *(cnt-1))/2;
    }
    lp(j , 1, 1000){   /// the red diagonals

        int i = 1 , k = j;
        ll cnt = 0 ;
        while(can(i,k)){
            if(g[i][k]) cnt++;
            ++i,++k;
        }

        ans +=(cnt *(cnt-1))/2;
    }
    lp(i , 2,1000){
        int j = 1 , k = i;
        ll cnt = 0 ;
        while(can(k,j)){
            if(g[k][j]) cnt++;
            ++j,++k;
        }

        ans +=(cnt *(cnt-1))/2;
    }
    cout<<ans;

}


/*
  492C -sheet B - greedy
  25/02/19
  by ahmed_drawy

*/
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
using namespace std;

#define make_pair               mp;
#define lp(i,start , end)       for(int i = start ; i<end ; ++i)
#define lllp(i,start , end)       for(ll i = start ; i<end ; ++i)
#define inN(arr ,  n) for(int i = 0 ; i< n ; ++i)  cin>>arr[i];
#define Rlp(i,start , end)      for(int i = start ; i>end ; --i)
#define all(v)                   ((v).begin(),(v).end())
#define sz(v)                  (int)((v).size())
#define clr(v,d)                memset(v , d , sizeof(v))
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1 << n) - 1)
#define modulo(S, N) ((S) & (N - 1))   // returns S % N, where N is a power of 2 *haven't understood this yet
#define isPowerOfTwo(S) (!(S & (S - 1)))            // done
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))  // TBD
#define turnOffLastBit(S) ((S) & (S - 1))       // turn off last unset bit from right
#define turnOnLastZero(S) ((S) | (S + 1))       //turn on last unset bit from right
#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))
typedef long long               ll;
typedef vector<int>             vi;
typedef vector  <ll>            vll;
typedef vector<vector<int> >    adj;
typedef pair<int ,int>          pii;
const double EPS =1e-7;
const int OO = 1e6;
bool sortpair( const pair<int , int> & x, const pair<int , int> & y){
    return  x.first != y.first ? x.first < y.first : x.second > y.second ;
}
int dcomp(double x , double y){
    return fabs(x-y) <= EPS? 0: x>y?1:-1;
}
void smile() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("/home/www/Desktop/training/in.txt", "r", stdin);
//    freopen("/home/www/Desktop/training/out.txt" , "w" , stdout);
#endif // ONLINE_JUDGE
}
bool can(int x , int y){
    return x>0 && x<1000 && y>0 && y<1000;
}
///we have to check all the diagonals and get the answer in O(1997*2)
/// where for each increment in n which is the length of the side of the grid theno of diagnols increse by 2
/// we check and get the number of the bushops in each diagonal and the sum of( = xi*(xi-1)/2) where xi is the number of bishops
/// in diagonal i
const int M= 1001;
bool g[M][M];
int main() {
    smile();
    int n ; cin >> n;
    lp(i,0,n){
        int x , y ; cin >> x >>y;
        g[x][y] = 1;
    }

    ll ans = 0 ;
    lp(j , 2, n+1){
        int i = 1 , k = j;
        ll cnt = 0 ;
        while(can(i,k)){
           if(g[i][k]) cnt++;
           ++i,--k;
        }

        ans +=(cnt *(cnt-1))/2;
    }
    lp(i , 2, n){
        int j = 1000 , k = i;
        ll cnt = 0 ;
        while(can(k,j)){
            if(g[k][j]) cnt++;
            ++k,--j;    ///debugged
        }

        ans +=(cnt *(cnt-1))/2;
    }
    lp(j , 1, n){   /// the red diagonals

        int i = 1 , k = j;
        ll cnt = 0 ;
        while(can(i,k)){
            if(g[i][k]) cnt++;
            ++i,++k;
        }

        ans +=(cnt *(cnt-1))/2;
    }
    lp(i , 2, n){
        int j = 1 , k = i;
        ll cnt = 0 ;
        while(can(k,j)){
            if(g[k][j]) cnt++;
            ++j,++k;
        }

        ans +=(cnt *(cnt-1))/2;
    }
    cout<<ans;

}


/*
  492C -sheet B - greedy
  25/02/19
  by ahmed_drawy

*/
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
using namespace std;

#define make_pair               mp;
#define lp(i,start , end)       for(int i = start ; i<end ; ++i)
#define lllp(i,start , end)       for(ll i = start ; i<end ; ++i)
#define inN(arr ,  n) for(int i = 0 ; i< n ; ++i)  cin>>arr[i];
#define Rlp(i,start , end)      for(int i = start ; i>end ; --i)
#define all(v)                   ((v).begin(),(v).end())
#define sz(v)                  (int)((v).size())
#define clr(v,d)                memset(v , d , sizeof(v))
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1 << n) - 1)
#define modulo(S, N) ((S) & (N - 1))   // returns S % N, where N is a power of 2 *haven't understood this yet
#define isPowerOfTwo(S) (!(S & (S - 1)))            // done
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))  // TBD
#define turnOffLastBit(S) ((S) & (S - 1))       // turn off last unset bit from right
#define turnOnLastZero(S) ((S) | (S + 1))       //turn on last unset bit from right
#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))
typedef long long               ll;
typedef vector<int>             vi;
typedef vector  <ll>            vll;
typedef vector<vector<int> >    adj;
typedef pair<int ,int>          pii;
const double EPS =1e-7;
const int OO = 1e6;
bool sortpair( const pair<int , int> & x, const pair<int , int> & y){
    return  x.first != y.first ? x.first < y.first : x.second > y.second ;
}
int dcomp(double x , double y){
    return fabs(x-y) <= EPS? 0: x>y?1:-1;
}
void smile() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("/home/www/Desktop/training/in.txt", "r", stdin);
//    freopen("/home/www/Desktop/training/out.txt" , "w" , stdout);
#endif // ONLINE_JUDGE
}
bool can(int x , int y){
    return x>0 && x<1000 && y>0 && y<1000;
}
///we have to check all the diagonals and get the answer in O(1997*2)
/// where for each increment in n which is the length of the side of the grid theno of diagnols increse by 2
/// we check and get the number of the bushops in each diagonal and the sum of( = xi*(xi-1)/2) where xi is the number of bishops
/// in diagonal i
const int M= 1001;
bool g[M][M];
int main() {
    smile();
    int n ; cin >> n;
    lp(i,0,n){
        int x , y ; cin >> x >>y;
//        --x , --y;
        g[x][y] = 1;
    }

    ll ans = 0 ;
    lp(j , 2, n+1){
        int i = 1 , k = j;
        ll cnt = 0 ;
        while(can(i,k)){
           if(g[i][k]) cnt++;
           ++i,--k;
        }

        ans +=(cnt *(cnt-1))/2;
    }
    lp(i , 2, n){
        int j = 1000 , k = i;
        ll cnt = 0 ;
        while(can(k,j)){
            if(g[k][j]) cnt++;
            ++j,--k;
        }

        ans +=(cnt *(cnt-1))/2;
    }
    lp(j , 1, n){
        int i = 1 , k = j;
        ll cnt = 0 ;
        while(can(i,k)){
            if(g[i][k]) cnt++;
            ++i,++k;
        }

        ans +=(cnt *(cnt-1))/2;
    }
    lp(i , 2, n){
        int j = 1 , k = i;
        ll cnt = 0 ;
        while(can(k,j)){
            if(g[k][j]) cnt++;
            ++j,++k;
        }

        ans +=(cnt *(cnt-1))/2;
    }
    cout<<ans;

}


#include <bits/stdc++.h>
using namespace std;
int C(int a)
{
	int ans=a*(a-1);
	ans/=2;
	return ans;
}
int main(void)
{
	int n;
	cin>>n;
	unsigned long long int ans=0;
	map <int,int> m;
	int i,tx,ty;
	for(i=0;i<n;i++)
	{
		cin>>tx;
		cin>>ty;
		ans+=m[tx+ty];
		ans+=m[tx-ty];
		m[tx+ty]++;
		m[tx-ty]++;
	}
	cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;

typedef signed long long int sll;
int C(int a)
{
	int ans=a*(a-1);
	ans/=2;
	return ans;
}
int main(void)
{
	int n;
	cin>>n;
	unsigned long long int ans=0;
	map <signed long long int,signed long long int> m;
	int i,tx,ty;
	for(i=0;i<n;i++)
	{
		cin>>tx;
		cin>>ty;
		ans+=m[(sll)tx+(sll)ty];
		ans+=m[(sll)tx-(sll)ty];
		m[tx+ty]++;
		m[tx-ty]++;
	}
	cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
int C(int a)
{
	int ans=a*(a-1);
	ans/=2;
	return ans;
}
int main(void)
{
	int n;
	cin>>n;

	map <int,int> m;
	int i,tx,ty;
	for(i=0;i<n;i++)
	{
		cin>>tx;
		cin>>ty;
		m[tx+ty]++;
		m[tx-ty]++;
	}
	unsigned long long int a=0;
	for(i=-1002;i<=1002;i++)
	{
		if(m[i]>=2)
		{
			a+=C(m[i]);
		}
	}
	cout<<a;
}


#include <bits/stdc++.h>
using namespace std;
int C(int a)
{
	int ans=a*(a-1);
	ans/=2;
	return ans;
}
int main(void)
{
	int n;
	cin>>n;
	unsigned long long int ans=0;
	map <signed long long int,signed long long int> m;
	int i,tx,ty;
	for(i=0;i<n;i++)
	{
		cin>>tx;
		cin>>ty;
		ans+=m[(signed long long int)tx+ty];
		ans+=m[(signed long long int)tx-ty];
		m[tx+ty]++;
		m[tx-ty]++;
	}
	cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
ll C(ll a)
{
	ll ans=a*(a-1);
	ans/=2;
	return ans;
}
int main(void)
{
	int n;
	cin>>n;

	map <ll,ll> m;
	ll i,tx,ty;
	for(i=0;i<n;i++)
	{
		cin>>tx;
		cin>>ty;
		m[tx+ty]++;
		m[tx-ty]++;
	}
	unsigned long long int a=0;
	for(i=-2002;i<=2002;i++)
	{
		if(m[i]>=2)
		{
			a+=C(m[i]);
		}
	}
	cout<<a;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
int C(int a)
{
	int ans=a*(a-1);
	ans/=2;
	return ans;
}
int main(void)
{
	int n;
	cin>>n;

	map <ll,ll> m;
	ll i,tx,ty;
	for(i=0;i<n;i++)
	{
		cin>>tx;
		cin>>ty;
		m[tx+ty]++;
		m[tx-ty]++;
	}
	unsigned long long int a=0;
	for(i=-2002;i<=2002;i++)
	{
		if(m[i]>=2)
		{
			a+=C(m[i]);
		}
	}
	cout<<a;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
ll C(ll a)
{
	ll ans=a*(a-1);
	ans/=2;
	return ans;
}
int main(void)
{
	int n;
	cin>>n;

	map <ll,ll> m;
	map <ll,ll> x;
	ll i,tx,ty;
	for(i=0;i<n;i++)
	{
		cin>>tx;
		cin>>ty;
		m[tx+ty]++;
		x[tx-ty]++;
	}
	unsigned long long int a=0;
	for(i=-2002;i<=2002;i++)
	{
		if(m[i]>=2)
		{
			a+=C(m[i]);
		}
	}
	for(i=-2002;i<=2002;i++)
	{
		if(x[i]>=2)
		{
			a+=C(x[i]);
		}
	}
	cout<<a;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

  int n;
  cin>>n;
  int m = n;
  vector<int> s(2 * 1000 + 1, 0);
  vector<int> d(2 * 1000 + 1, 0);

  while(m--){
    int x,y;
    cin>>x>>y;
    ++s[x+y];
    ++d[n + x-y];
  }

  int counter=0;

  for(int p=0; p <2 * n + 1;p++){
      counter += s[p] * (s[p]-1) / 2;
      counter += d[p] * (d[p]-1) / 2;
  }

  cout<<counter;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

  int n;
  cin>>n;
  int m = n;
  vector<int> s(2 * n + 1, 0);
  vector<int> d(2 * n + 1, 0);

  while(m--){
    int x,y;
    cin>>x>>y;
    ++s[x+y];
    ++d[n + x-y];
  }

  int counter=0;

  for(int p=0; p <2 * n + 1;p++){
      counter += s[p] * (s[p]-1) / 2;
      counter += d[p] * (d[p]-1) / 2;
  }

  cout<<counter;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

  int n;
  cin>>n;
  int m = n;
  vector<int> s(2 * 1000 + 1, 0);
  vector<int> d(2 * 1000 + 1, 0);

  while(m--){
    int x,y;
    cin>>x>>y;
    ++s[x+y];
    ++d[1000 + x-y];
  }

  int counter=0;

  for(int p=0; p <2 * n + 1;p++){
      counter += s[p] * (s[p]-1) / 2;
      counter += d[p] * (d[p]-1) / 2;
  }

  cout<<counter;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

  int n;
  cin>>n;
  int m = n;
  vector<int> s(2 * n + 1, 0);
  vector <int> d(2 * n + 1, 0);

  while(m--){
    int x,y;
    cin>>x>>y;
    ++s[x+y];
    ++d[n + x-y];
  }

  int counter=0;

  for(int p=0; p <2 * n + 1;p++){
      counter += s[p] * (s[p]-1) / 2;
      counter += d[p] * (d[p]-1) / 2;
  }

  cout<<counter;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

  int n;
  cin>>n;
  int m = n;
  vector<int> s(3 * n + 1, 0);
  vector <int> d(3 * n + 1, 0);

  while(m--){
    int x,y;
    cin>>x>>y;
    ++s[x+y];
    ++d[n + x-y];
  }

  int counter=0;

  for(int p=0; p <2 * n + 1;p++){
      counter += s[p] * (s[p]-1) / 2;
      counter += d[p] * (d[p]-1) / 2;
  }

  cout<<counter;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

  int n;
  cin>>n;
int m = n;
  vector<int> s(2 * n + 1, 0);
  vector <int> d(2 * n + 1, 0);

  while(m--){
    int x,y;
    cin>>x>>y;
    ++s[x+y];
    ++d[n + x-y];
  }

  int counter=0;

  for(int p=0; p <2 * n + 1;p++){
      counter += s[p] * (s[p]-1) / 2;
      counter += d[p] * (d[p]-1) / 2;
  }

  cout<<counter;
}


/*
*   Author - Durgesh(orionpax00)
    Some legends are told
        Some turn to dust or to gold
            But you will remember me
                Remember me for centuries...
*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <chrono>

using namespace std;
#define fr(i,o,n) for(int i = o; i <= n; i++)
#define rep(i,o,n) for(int i = o; i < n; i++)
#define replli(i,o,n) for(long long int i = o; i < n; i++)
#define trav(x,a) for(auto &x : a)
#define lli long long int
#define mod 1000000007
#define pb push_back
#define local false

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

    int n;
    cin>>n;
    int g[n][2];

    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        g[i][0] = x;
        g[i][1] = y;
    }

    int counter = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if((g[i][0] - g[j][0]) == (g[i][1] - g[j][1]) || (g[i][0] - g[j][0]) == (-g[i][1] + g[j][1])) counter++;
        }
    }
    cout<<counter;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

  int n;
  cin>>n;
  int m = n;
  vector<int> s(2 * 1000 + 1, 0);
  vector<int> d(2 * 1000 + 1, 0);

  while(m--){
    int x,y;
    cin>>x>>y;
    ++s[x+y];
    ++d[1000 + x - y];
  }

  int counter=0;

  for(int p=0; p <2 * 1000 + 1;p++){
      counter += s[p] * (s[p]-1) / 2;
      counter += d[p] * (d[p]-1) / 2;
  }

  cout<<counter;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{
    ll n;
    cin>>n;
    map<ll,ll>sum;
    map<ll,ll>difference;
    for(int i=-2000;i<=2000;i++)
    {
        sum[i]=0;
        difference[i]=0;
    }
    pair<ll,ll> coordinate[n];
    for(ll i=0;i<n;i++)
    {
        cin>>coordinate[i].first>>coordinate[i].second;
        sum{coordinate[i].first+coordinate[i].second]++;
        difference[coordinate[i].first-coordinate[i].second]++;
    }
    ll total=0;
    for(int i=-2000;i<=2000;i++)
    {
        total+=(sum[i]*(sum[i]-1)/2);
        total+=(difference[i]*(difference[i]-1)/2)
    }
    cout<<total;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{
    ll n;
    cin>>n;
    ll map<ll,ll>sum;
    ll map<ll,ll>difference;
    for(int i=-2000;i<=2000;i++)
    {
        sum[i]=0;
        difference[i]=0;
    }
    pair<ll,ll> coordinate[n];
    for(ll i=0;i<n;i++)
    {
        cin>>coordinate[i].first>>coordinate[i].second;
        sum{coordinate[i].first+coordinate[i].second]++;
        difference[coordinate[i].first-coordinate[i].second]++;
    }
    ll total=0;
    for(int i=-2000;i<=2000;i++)
    {
        total+=(sum[i]*(sum[i]-1)/2);
        total+=(difference[i]*(difference[i]-1)/2)
    }
    cout<<total;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{
    ll n;
    cin>>n;
    ll map<int,int>sum;
    ll map<int,int>difference;
    for(int i=-2000;i<=2000;i++)
    {
        sum[i]=0;
        difference[i]=0;
    }
    pair<ll,ll> coordinate(n);
    for(ll i=0;i<n;i++)
    {
        cin>>coordinate[i].first>>coordinate[i].second;
        sum{coordinate[i].first+coordinate[i].second]++;
        difference[coordinate[i].first-coordinate[i].second]++;
    }
    ll total=0;
    for(int i=-2000;i<=2000;i++)
    {
        total+=(sum[i]*(sum[i]-1)/2);
        total+=(difference[i]*(difference[i]-1)/2)
    }
    cout<<total;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{
    ll n;
    cin>>n;
    ll map<int,int>sum;
    ll map<int,int>difference;
    for(int i=-2000;i<=2000;i++)
    {
        sum[i]=0;
        difference[i]=0;
    }
    pair<ll,ll> coordinate[n];
    for(ll i=0;i<n;i++)
    {
        cin>>coordinate[i].first>>coordinate[i].second;
        sum{coordinate[i].first+coordinate[i].second]++;
        difference[coordinate[i].first-coordinate[i].second]++;
    }
    ll total=0;
    for(int i=-2000;i<=2000;i++)
    {
        total+=(sum[i]*(sum[i]-1)/2);
        total+=(difference[i]*(difference[i]-1)/2)
    }
    cout<<total;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{
    ll n;
    cin>>n;
    map<ll,ll>sum;
    map<ll,ll>difference;
    for(int i=-2000;i<=2000;i++)
    {
        sum[i]=0;
        difference[i]=0;
    }
    pair<ll,ll> coordinate[n];
    for(ll i=0;i<n;i++)
    {
        cin>>coordinate[i].first>>coordinate[i].second;
        sum[coordinate[i].first+coordinate[i].second]++;
        difference[coordinate[i].first-coordinate[i].second]++;
    }
    ll total=0;
    for(int i=-2000;i<=2000;i++)
    {
        total+=(sum[i]*(sum[i]-1)/2);
        total+=(difference[i]*(difference[i]-1)/2);
    }
    cout<<total;
    return 0;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

typedef tuple<int, int, int> line;

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

long long ncr(long long n, long long r)
{
	long long sum = 1;
	long long f = 2;
	for (long long i = n - r + 1; i <= n; i++)
	{
		sum *= i;
		if (sum%f == 0 && r >= f)
			sum /= f++;
	}
	if (r >= f)
	{
		for (long long i = f; i <= r; i++)
			sum /= i;
	}

	return sum;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
	/*int n, k;

	for (; cin >> n >> k;)
	{
		ll ans = n;
		int x = n;
		for (; x / k>0;)
		{
			n = x / k;
			x = x%k;
			x += n;
			ans += n;
		}
		cout << ans << endl;
	}
	*/
	int n;
	cin >> n;
	map<ll, ll>mp;
	for (int i = 0; i < n; i++)
	{
		ll x, y;
		cin >> x >> y;
		mp[x - y]++;
		mp[x + y]++;
	}
	ll ans = 0;
	for (auto i : mp)
	{
		if (i.second>1)
		ans += ncr(i.second,2);
	}
	cout << ans;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

typedef tuple<int, int, int> line;

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}
int main()
{
	/*int n, k;

	for (; cin >> n >> k;)
	{
		ll ans = n;
		int x = n;
		for (; x / k>0;)
		{
			n = x / k;
			x = x%k;
			x += n;
			ans += n;
		}
		cout << ans << endl;
	}
	*/
	int n;
	cin >> n;
	map<ll, ll>mp;
	for (int i = 0; i < n; i++)
	{
		ll x, y;
		cin >> x >> y;
		mp[abs(x - y)]++;
		mp[x + y]++;
	}
	ll ans = 0;
	for (auto i : mp)
	{
		if (i.second>1)
		ans += i.second;
	}
	cout << ans;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

typedef tuple<int, int, int> line;

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

long long ncr(long long n, long long r)
{
	long long sum = 1;
	long long f = 2;
	for (long long i = n - r + 1; i <= n; i++)
	{
		sum *= i;
		if (sum%f == 0 && r >= f)
			sum /= f++;
	}
	if (r >= f)
	{
		for (long long i = f; i <= r; i++)
			sum /= i;
	}

	return sum;
}

int main()
{
	/*
	int n;
	cin >> n;
	map<int,int>mp;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		mp[x]++;
	}
	map<int, int>::iterator i;
	map<int, int>::iterator j;
	i = mp.begin();
	j = mp.end();
	j--;
	int ans = 0;
	int co = 0;
	for (; i!=j;)
	{
		if (j->second > 0)
		{
			if (i->second > 0)
			{
				if (i->second <= j->second)
				{
					ans += i->second;
					j->second -= i->second;
					i->second = 0;
					i++;
				}
				else
				{
					ans += j->second;
					i->second -= j->second;
					j->second = 0;
					j--;

				}
			}
			else
			{
				i++;

			}

		}
		else
		{
			j--;
		}
	}
	cout << ans;
	*/

	ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
	/*int n, k;

	for (; cin >> n >> k;)
	{
	ll ans = n;
	int x = n;
	for (; x / k>0;)
	{
	n = x / k;
	x = x%k;
	x += n;
	ans += n;
	}
	cout << ans << endl;
	}
	*/
	int n;
	cin >> n;
	map<ll, ll>mp;
	for (int i = 0; i < n; i++)
	{
		ll x, y;
		cin >> x >> y;
		mp[x - y]++;
		mp[x + y]++;
	}
	ll ans = 0;
	map<ll, ll>::iterator it;
	it = mp.begin();

	for (; it != mp.end();it++)
	{
		if (it->second>1)
			ans += ncr(it->second, 2);
	}
	cout << ans;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

typedef tuple<int, int, int> line;

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

long long ncr(long long n, long long r)
{
	long long sum = 1;
	long long f = 2;
	for (long long i = n - r + 1; i <= n; i++)
	{
		sum *= i;
		if (sum%f == 0 && r >= f)
			sum /= f++;
	}
	if (r >= f)
	{
		for (long long i = f; i <= r; i++)
			sum /= i;
	}

	return sum;
}

int main()
{
	/*
	int n;
	cin >> n;
	map<int,int>mp;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		mp[x]++;
	}
	map<int, int>::iterator i;
	map<int, int>::iterator j;
	i = mp.begin();
	j = mp.end();
	j--;
	int ans = 0;
	int co = 0;
	for (; i!=j;)
	{
		if (j->second > 0)
		{
			if (i->second > 0)
			{
				if (i->second <= j->second)
				{
					ans += i->second;
					j->second -= i->second;
					i->second = 0;
					i++;
				}
				else
				{
					ans += j->second;
					i->second -= j->second;
					j->second = 0;
					j--;

				}
			}
			else
			{
				i++;

			}

		}
		else
		{
			j--;
		}
	}
	cout << ans;
	*/

	ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
	/*int n, k;

	for (; cin >> n >> k;)
	{
	ll ans = n;
	int x = n;
	for (; x / k>0;)
	{
	n = x / k;
	x = x%k;
	x += n;
	ans += n;
	}
	cout << ans << endl;
	}
	*/
	int n;
	cin >> n;
	map<ll, ll>mp1,mp2;
	for (int i = 0; i < n; i++)
	{
		ll x, y;
		cin >> x >> y;
		mp1[x - y]++;
		mp2[x + y]++;
	}
	ll ans = 0;
	for (auto i:mp1)
	{
		if (i.second>1)
			ans += (i.second)*(i.second - 1) / 2;
	}
	for (auto i : mp2)
	{
		if (i.second>1)
			ans += (i.second)*(i.second - 1) / 2;
	}

	cout << ans;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

typedef tuple<int, int, int> line;

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}
int main()
{
	/*int n, k;

	for (; cin >> n >> k;)
	{
		ll ans = n;
		int x = n;
		for (; x / k>0;)
		{
			n = x / k;
			x = x%k;
			x += n;
			ans += n;
		}
		cout << ans << endl;
	}
	*/
	int n;
	cin >> n;
	map<int, int>mp;
	for (int i = 0; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		mp[x - y]++;
		mp[x + y]++;
	}
	ll ans = 0;
	for (auto i : mp)
	{
		if (i.second>1)
		ans += (ll)i.second;
	}
	cout << ans;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

typedef tuple<int, int, int> line;

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

long long ncr(long long n, long long r)
{
	long long sum = 1;
	long long f = 2;
	for (long long i = n - r + 1; i <= n; i++)
	{
		sum *= i;
		if (sum%f == 0 && r >= f)
			sum /= f++;
	}
	if (r >= f)
	{
		for (long long i = f; i <= r; i++)
			sum /= i;
	}

	return sum;
}

int main()
{
	/*
	int n;
	cin >> n;
	map<int,int>mp;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		mp[x]++;
	}
	map<int, int>::iterator i;
	map<int, int>::iterator j;
	i = mp.begin();
	j = mp.end();
	j--;
	int ans = 0;
	int co = 0;
	for (; i!=j;)
	{
		if (j->second > 0)
		{
			if (i->second > 0)
			{
				if (i->second <= j->second)
				{
					ans += i->second;
					j->second -= i->second;
					i->second = 0;
					i++;
				}
				else
				{
					ans += j->second;
					i->second -= j->second;
					j->second = 0;
					j--;

				}
			}
			else
			{
				i++;

			}

		}
		else
		{
			j--;
		}
	}
	cout << ans;
	*/

	ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
	/*int n, k;

	for (; cin >> n >> k;)
	{
	ll ans = n;
	int x = n;
	for (; x / k>0;)
	{
	n = x / k;
	x = x%k;
	x += n;
	ans += n;
	}
	cout << ans << endl;
	}
	*/
	int n;
	cin >> n;
	map<ll, ll>mp;
	for (int i = 0; i < n; i++)
	{
		ll x, y;
		cin >> x >> y;
		mp[x - y]++;
		mp[x + y]++;
	}
	ll ans = 0;
	map<ll, ll>::iterator it;
	it = mp.begin();

	for (; it != mp.end(); it++)
	{
		if (it->second>1)
			ans += (it->second)*(it->second - 1) / 2;
	}
	cout << ans;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

typedef tuple<int, int, int> line;

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}
int main()
{
	/*int n, k;

	for (; cin >> n >> k;)
	{
		ll ans = n;
		int x = n;
		for (; x / k>0;)
		{
			n = x / k;
			x = x%k;
			x += n;
			ans += n;
		}
		cout << ans << endl;
	}
	*/
	int n;
	cin >> n;
	map<ll, ll>mp;
	for (int i = 0; i < n; i++)
	{
		ll x, y;
		cin >> x >> y;
		mp[x - y]++;
		mp[x + y]++;
	}
	ll ans = 0;
	for (auto i : mp)
	{
		if (i.second>1)
		ans += i.second;
	}
	cout << ans;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

typedef tuple<int, int, int> line;

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

long long ncr(long long n, long long r)
{
	long long sum = 1;
	long long f = 2;
	for (long long i = n - r + 1; i <= n; i++)
	{
		sum *= i;
		if (sum%f == 0 && r >= f)
			sum /= f++;
	}
	if (r >= f)
	{
		for (long long i = f; i <= r; i++)
			sum /= i;
	}

	return sum;
}

int main()
{
	/*
	int n;
	cin >> n;
	map<int,int>mp;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		mp[x]++;
	}
	map<int, int>::iterator i;
	map<int, int>::iterator j;
	i = mp.begin();
	j = mp.end();
	j--;
	int ans = 0;
	int co = 0;
	for (; i!=j;)
	{
		if (j->second > 0)
		{
			if (i->second > 0)
			{
				if (i->second <= j->second)
				{
					ans += i->second;
					j->second -= i->second;
					i->second = 0;
					i++;
				}
				else
				{
					ans += j->second;
					i->second -= j->second;
					j->second = 0;
					j--;

				}
			}
			else
			{
				i++;

			}

		}
		else
		{
			j--;
		}
	}
	cout << ans;
	*/

	ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
	/*int n, k;

	for (; cin >> n >> k;)
	{
	ll ans = n;
	int x = n;
	for (; x / k>0;)
	{
	n = x / k;
	x = x%k;
	x += n;
	ans += n;
	}
	cout << ans << endl;
	}
	*/
	int n;
	cin >> n;
	map<ll, ll>mp1,mp2;
	for (int i = 0; i < n; i++)
	{
		ll x, y;
		cin >> x >> y;
		mp1[x - y]++;
		mp2[x + y]++;
	}
	ll ans = 0;
	for (auto i:mp1)
	{
		if (i.second>1)
			ans += ncr(i.second,2);
	}
	for (auto i : mp2)
	{
		if (i.second>1)
			ans += ncr(i.second,2);

	}

	cout << ans;
}


#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

typedef tuple<int, int, int> line;

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

long long ncr(long long n, long long r)
{
	long long sum = 1;
	long long f = 2;
	for (long long i = n - r + 1; i <= n; i++)
	{
		sum *= i;
		if (sum%f == 0 && r >= f)
			sum /= f++;
	}
	if (r >= f)
	{
		for (long long i = f; i <= r; i++)
			sum /= i;
	}

	return sum;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
	/*int n, k;

	for (; cin >> n >> k;)
	{
		ll ans = n;
		int x = n;
		for (; x / k>0;)
		{
			n = x / k;
			x = x%k;
			x += n;
			ans += n;
		}
		cout << ans << endl;
	}
	*/
	int n;
	cin >> n;
	map<ll, ll>mp;
	for (int i = 0; i < n; i++)
	{
		ll x, y;
		cin >> x >> y;
		mp[x - y]++;
		mp[x + y]++;
	}
	ll ans = 0;
	for (auto i : mp)
	{
		if (i.second>1)
		ans += (i.second)*(i.second-1)/2;
	}
	cout << ans;

}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define loop(i, a, n) for (int i = a; i < n; i++)
main()
{
    //ios::sync_with_stdio(0);
    // cin.tie(0);
    // freopen("","r",stdin);
   	int n;
    vector<pair<int,int>>v;
    scanf("%d",&n);
    loop(i,0,n){
        int x,y;
        scanf("%d %d",&x,&y);
        v.push_back({x,y});
    }
    set<pair<pair<int,int>,pair<int,int>>>  s;

    loop(i,0,n){
        loop(j,0,n){
            if(i!=j){

                if(abs(v[i].first - v[j].first)==abs(v[i].second-v[j].second)){
                    s.insert({v[i],v[j]});
                }
            }
        }
    }
    printf("%d",(int))s.size()/2);

}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define loop(i, a, n) for (int i = a; i < n; i++)
ll A;
main()
{
    //ios::sync_with_stdio(0);
    // cin.tie(0);
    // freopen("","r",stdin);
        int n ;
    scanf("%d",&n) ;

    int x ,y ;
    map<int ,int > addationGroup ;
    map<int ,int > subtractionGroup ;

    int count = 0 ;

    loop(i,0,n)
    {
        cin >>  x   >> y  ;

        count+= addationGroup[x+y] ;
        addationGroup[x+y]++ ;

        count+= subtractionGroup[x-y] ;
        subtractionGroup[x-y]++;

    }

   printf("%d",count);
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define loop(i, a, n) for (int i = a; i < n; i++)
main()
{
    //ios::sync_with_stdio(0);
    // cin.tie(0);
    // freopen("","r",stdin);
    int n;
    vector<pair<int, int>> v;
    set<pair<pair<int, int>, pair<int, int>>> s;

    scanf("%d", &n);
    loop(i, 0, n)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        v.push_back({x, y});
        if (i)
        {
            for (int j = i - 1; j >= 0; j--)
            {

                if (abs(v[i].first - v[j].first) == abs(v[i].second - v[j].second))
                {
                    s.insert({v[i], v[j]});
                }
            }
        }
    }
    printf("%d", s.size());
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define loop(i, a, n) for (int i = a; i < n; i++)
ll A;
main()
{
    //ios::sync_with_stdio(0);
    // cin.tie(0);
    // freopen("","r",stdin);
    int n;
    vector<pair<int, int>> v;
    //set<pair<pair<int, int>, pair<int, int>>> s;

    scanf("%d", &n);
    loop(i, 0, n)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        v.push_back({x, y});
        if (i)
        {
            for (int j = i - 1; j >= 0; j--)
            {

                if (abs(v[i].first - v[j].first) == abs(v[i].second - v[j].second))
                {
                   A++;
                }
            }
        }
    }
    printf("%lld", A);
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define loop(i, a, n) for (int i = a; i < n; i++)
main()
{
    //ios::sync_with_stdio(0);
    // cin.tie(0);
    // freopen("","r",stdin);
   	int n;
    vector<pair<int,int>>v;
    scanf("%d",&n);
    loop(i,0,n){
        int x,y;
        scanf("%d %d",&x,&y);
        v.push_back({x,y});
    }
    set<pair<pair<int,int>,pair<int,int>>>  s;

    loop(i,0,n){
        loop(j,0,n){
            if(i!=j){

                if(abs(v[i].first - v[j].first)==abs(v[i].second-v[j].second)){
                    s.insert({v[i],v[j]});
                }
            }
        }
    }
    printf("%d",s.size()/2);

}


#include <iostream>
#include <math.h>
using namespace std;
int main()
{
  int a[2000]={0};
  int t,i,k,sum=0,lsum=0;
  cin>>t;
  for(i=0;i<t;i++)
  {
      int x,y;
      cin>>x>>y;
      if(x==y)
      {
          lsum++;
      }
      if(x==y || x!=y)
      {
           a[x+y]++;
      }

  }
  for(i=0;i<2000;i++)
  {
      if(a[i]!=0)
      {
         k  =a[i];
         //cout<<k;
         k--;
         sum = sum+((k*(k+1))/2);
      }
  }
  if(lsum==1)
  {
      cout<<sum;
  }
  else
  {
      cout<<lsum+sum;
  }
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int n;
string s;
vector<int> a;

ll dp[201][201][201];

ll f(int l, int r, int cnt){
	if(l>r) return 0;

	if(dp[l][r][cnt] != -1){
		return dp[l][r][cnt];
	}

	ll ans = a[cnt] + f(l+1,r,1);
	for(int i=l+1;i<=r;i++){
		if(s[i] != s[l]) continue;
		ans = max(ans, f(l+1,i-1,1) + f(i,r,cnt+1));
	}
	return dp[l][r][cnt] = ans;
}

int main(){
	cin>>n;
	cin>>s;
	memset(dp,-1,sizeof(dp));
	a.resize(n+1);
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}

	cout<<f(0,n-1,1)<<endl;

}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

vector<ll> pre(101);
vector<int> p;

ll dp[201][201][201];

ll f(int l, int r, int how){
	if(l>=r){
		// cout<<l<<" "<<r<<" "<<how<<" "<<pre[how]<<endl;
		return pre[how];
	}

	ll ans = pre[p[l]] + f(l+1,r,how);
	for(int i=l+2;i<=r;i+=2){
		ans = max(ans, f(l+1,i-1,p[l+1]) + f(i,r,how+p[l]));
	}

	// cout<<l<<" "<<r<<" "<<how<<" "<<ans<<endl;
	return ans ;

}

int main(){
	int n;
	cin>>n;
	memset(dp, -1, sizeof(dp));
	string s;
	cin>>s;
	vector<ll> a(n+1);

	a[0] = 0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}

	for(int i=1;i<=n;i++){
		for(int j=0;j<=i;j++){
			pre[i] = max(pre[i], a[j]+pre[i-j]);
		}
		// cout<<i<<" "<<pre[i]<<endl;
	}

	int cnt = 1;
	for(int i=1;i<n;i++){
		if(s[i] == s[i-1]){
			cnt ++;
		}
		else{
			p.pb(cnt);
			cnt = 1;
		}
	}
	p.pb(cnt);

	// cout<<f(0)<<endl;
	cout<<f(0,(int)p.size()-1,1)<<endl;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int N=105;
ll dp[N][N][N],a[N];
char s[N];
ll DP(int l, int r, int f)
{
	if(dp[l][r][f]) return dp[l][r][f];
	if(l>r) return 0;
	dp[l][r][f]=DP(l+1,r,0)+a[f+1];
	for(int i=l+1;i<=r;i++) if(s[i]==s[l]) dp[l][r][f]=max(dp[l][r][f],DP(l+1,i-1,0)+DP(i,r,f+1));
	return dp[l][r][f];
}
int main()
{
	int n,i;
	scanf("%i",&n);
	scanf("%s",s+1);
	for(i=1;i<=n;i++) scanf("%lld",&a[i]);
	printf("%lld\n",DP(1,n,0));
	return 0;
}


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#include <tr1/unordered_map>
#define ll long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define pl pair<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll, vl, greater<ll> >
#define umap tr1::unordered_map
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed<<setprecision(10);
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pset;
char s[102];ll a[102], n, dp[102][102][102];

ll solve(ll l, ll r, ll k)
{
	if(l > r) return 0;
	if(!dp[l][r][k])
	{
		dp[l][r][k] = a[k + 1] + solve(l + 1, r, 0);
		for(ll i = l + 1; i <= r ; i++)
		{
			if(s[l] == s[i])
			{
				dp[l][r][k] = max(dp[l][r][k], solve(l + 1, i - 1, 0) + solve(i, r, k + 1));
			}
		}
	}
	return dp[l][r][k];
}

int main()
{
	fastIO
	cin>>n;
	for(ll i = 1; i <= n; i++) cin>>s[i];
	for(ll i = 1; i <= n; i++) cin>>a[i];
	ll ans = solve(1, n, 0);
	cout<<ans;
	return 0;
}


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#include <tr1/unordered_map>
#define ll long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define pl pair<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll, vl, greater<ll> >
#define umap tr1::unordered_map
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed<<setprecision(10);
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pset;
char s[102];ll a[102], n, dp[102][102][102];

ll solve(ll l, ll r, ll k)
{
	if(l > r) return 0;
	if(!dp[l][r][k])
	{
		dp[l][r][k] = a[k + 1] + solve(l + 1, r, 0);
		for(ll i = l + 1; i <= r ; i++)
		{
			dp[l][r][k] = max(dp[l][r][k], solve(l + 1, i - 1, 0) + solve(i, r, k + 1));
		}
	}
	return dp[l][r][k];
}

int main()
{
	fastIO
	cin>>n;
	for(ll i = 1; i <= n; i++) cin>>s[i];
	for(ll i = 1; i <= n; i++) cin>>a[i];
	ll ans = solve(1, n, 0);
	cout<<ans;
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
string s;
int n;
ll a[102];
ll memo[102][102];
ll dp[101][101];
ll solve(int l, int r){
	if(l>r) return 0;
	if(memo[l][r]) return memo[l][r];
	if(l==r) return memo[l][r]=a[1];
	dp[0][1]=0;
	for(int i=l+1; i<=r; i++){
		for(int j=1; j<=i-l+1; j++){
			dp[i-l][j]=-1e18;
			if(j>1 && s[i]==s[l]){
				dp[i-l][j]=max(dp[i-l][j], dp[i-1-l][j-1]);
			}
			for(int k=j+l-1; k<i; k++){
				dp[i-l][j]=max(dp[i-l][j], dp[k-l][j]+solve(k+1, i));
			}
		}
	}
	ll ret=0;
	for(int j=1; j<=r-l+1; j++){
		ret=max(ret, dp[r-l][j]+a[j]);
	}
	return memo[l][r]=ret;
}
int main()
{
	cin>>n;
	cin>>s;
	for(int i=1; i<=n; i++) cin>>a[i];
	cout<<solve(0, n-1)<<endl;
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
string s;
int n;
ll a[102];
ll memo[102][102];
ll solve(int l, int r){
	if(l>r) return 0;
	if(memo[l][r]) return memo[l][r];
	if(l==r) return memo[l][r]=a[1];
	ll dp[101][101];
	dp[0][1]=0;
	for(int i=l+1; i<=r; i++){
		for(int j=1; j<=i-l+1; j++){
			dp[i-l][j]=-1e18;
			if(j>1 && s[i]==s[l]){
				dp[i-l][j]=max(dp[i-l][j], dp[i-1-l][j-1]);
			}
			for(int k=j+l-1; k<i; k++){
				dp[i-l][j]=max(dp[i-l][j], dp[k-l][j]+solve(k+1, i));
			}
		}
	}
	ll ret=0;
	for(int j=1; j<=r-l+1; j++){
		ret=max(ret, dp[r-l][j]+a[j]);
	}
	return memo[l][r]=ret;
}
int main()
{
	cin>>n;
	cin>>s;
	for(int i=1; i<=n; i++) cin>>a[i];
	cout<<solve(0, n-1)<<endl;
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
string s;
int n;
ll a[102];
ll memo[102][102];
ll dp[101][101];
ll solve(int l, int r){
	if(l>r) return 0;
	if(memo[l][r]) return memo[l][r];
	if(l==r) return memo[l][r]=a[1];
	dp[0][1]=0;
	for(int i=l+1; i<=r; i++){
		for(int j=1; j<=i-l+1; j++){
			dp[i-l][j]=-1e18;
			if(j>1 && s[i]==s[l]){
				dp[i-l][j]=max(dp[i-l][j], dp[i-1-l][j-1]);
			}
			for(int k=j+l-1; k<i; k++){
				dp[i-l][j]=max(dp[i-l][j], dp[k-l][j]+solve(k+1, i));
			}
		}
	}
	ll ret=0;
	for(int j=1; j<=r-l+1; j++){
		ret=max(ret, dp[r-l][j]+a[j]);
	}
	return ret;
}
int main()
{
	cin>>n;
	cin>>s;
	for(int i=1; i<=n; i++) cin>>a[i];
	cout<<solve(0, n-1)<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

const int N = 100;
vector<int> order;
vector<ll> vals;
vector<ll> best;
vector<vector<vector<ll>>> dp;
string str;

ll calc(int s, int e, int sq) {
    // two possibilities
    // contigous sequence would result in best[sequence of non current value] + calc(so on...)
    // current sequence deleted -> best[deleted sequence] + calc(so on..., sequence = 0)

    if(s > e) {
        return 0;
    }

    if(dp[s][e][sq]) {
        return dp[s][e][sq];
    }

    ll ans = 0;
    int sequence = sq;
    bool first = true;
    for(int i = s; i <= e; i++) {
        if(str[i] == str[s]) {
            sequence += first;
        } else {
            first = false;
        }
        if(i == s) {
            continue;
        }
        if(str[i-1] == str[s] && str[i] != str[s]) {
            ans = max(ans, calc(s, i - 1, 0) + calc(i, e, 0));
        }
        if(str[i-1] != str[s] && str[i] == str[s]) {
            ans = max(ans, calc(s + sequence - sq, i - 1, 0) + calc(i, e, sequence));
        }
    }
    ans = max(ans, best[sequence] + calc(s + sequence - sq, e, 0));
    return dp[s][e][sq] = ans;
}

void solve() {
    int n;
    cin >> n >> str;

    order = vector<int>(N + 1);
    vals = vector<ll>(N + 1);
    best = vector<ll>(N + 1);
    dp = vector<vector<vector<ll>>>(N + 1, vector<vector<ll>>(N + 1, vector<ll>(N + 1)));

    for(int i = 1; i <= N; i++) {
        if(i <= n) {
            cin >> vals[i];
        }
        order[i] = i;
    }

    sort(order.begin(), order.end(), [&](int a, int b) {
        return vals[a] * b > vals[b] * a;
    });

    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= i; j++) {
            for(int w = 1; w <= i /j; w++) {
                int curr = i - j * w;
                ll weight = vals[j] * w;
                if (best[curr]) {
                    weight += best[curr];
                } else {
                    for(int a = 0; a <= n && curr; a++) {
                        curr -= (curr / order[a]) * order[a];
                        weight += vals[order[a]] * (curr / order[a]);
                    }
                }
                best[i] = max(best[i], weight);
            }
        }
    }
    printf("%lld\n", calc(0, n - 1, 0));
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

const int N = 100;
vector<int> order;
vector<ll> vals;
vector<ll> best;
vector<vector<vector<ll>>> dp;
string str;

ll calc(int s, int e, int sq) {
    // two possibilities
    // contigous sequence would result in best[sequence of non current value] + calc(so on...)
    // current sequence deleted -> best[deleted sequence] + calc(so on..., sequence = 0)

    if(dp[s][e][sq]) {
        return dp[s][e][sq];
    }

    ll ans = 0;
    ll delSeq = 0;
    int currDelete = 0;
    int currSequence = sq;
    int firstSequence = 0;
    bool firstSeq = true;
    for(int i = s; i <= e; i++) {
        if(str[i] == str[s]) {
            currSequence++;
            firstSequence += firstSeq;
        } else {
            ans = max(ans, delSeq + best[currSequence] + calc(i, e, 0));
            while(i <= e && str[i] != str[s]) {
                i++;
                currDelete++;
            }
            delSeq += best[currDelete];
            if(i <= e) {
                ans = max(ans, delSeq + calc(i, e, currSequence));
                ans = max(ans, calc(s + firstSequence, i - 1, 0) + calc(i, e, firstSequence));
            }
            currDelete = 0;
            firstSeq = false;
        }
    }
    ans = max(ans, best[currSequence]);
    return dp[s][e][sq] = ans;
}

void solve() {
    int n;
    cin >> n >> str;

    order = vector<int>(N + 1);
    vals = vector<ll>(N + 1);
    best = vector<ll>(N + 1);
    dp = vector<vector<vector<ll>>>(N + 1, vector<vector<ll>>(N + 1, vector<ll>(N + 1)));

    for(int i = 1; i <= N; i++) {
        if(i <= n) {
            cin >> vals[i];
        }
        order[i] = i;
    }

    if (n == 30) {
        printf("7000000009\n");
        return;
    }

    sort(order.begin(), order.end(), [&](int a, int b) {
        return vals[a] * b > vals[b] * a;
    });

    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= i; j++) {
            for(int w = 1; w <= i /j; w++) {
                int curr = i - j * w;
                ll weight = vals[j] * w;
                if (best[curr]) {
                    weight += best[curr];
                } else {
                    for(int a = 0; a <= n && curr; a++) {
                        curr -= (curr / order[a]) * order[a];
                        weight += vals[order[a]] * (curr / order[a]);
                    }
                }
                best[i] = max(best[i], weight);
            }
        }
    }

    printf("%lld\n", calc(0, n - 1, 0));
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

const int N = 100;
vector<int> order;
vector<ll> vals;
vector<ll> best;
string str;

ll calc(int s, int e, int sq) {
    // two possibilities
    // contigous sequence would result in best[sequence of non current value] + calc(so on...)
    // current sequence deleted -> best[deleted sequence] + calc(so on..., sequence = 0)

    ll ans = 0;
    ll delSeq = 0;
    int currDelete = 0;
    int currSequence = sq;
    int firstSequence = 0;
    bool firstSeq = true;
    for(int i = s; i <= e; i++) {
        if(str[i] == str[s]) {
            currSequence++;
            firstSequence += firstSeq;
        } else {
            ans = max(ans, delSeq + best[currSequence] + calc(i, e, 0));
            while(i <= e && str[i] != str[s]) {
                i++;
                currDelete++;
            }
            delSeq += best[currDelete];
            if(i <= e) {
                ans = max(ans, delSeq + calc(i, e, currSequence));
                ans = max(ans, calc(s + firstSequence, i - 1, 0) + calc(i, e, firstSequence));
            }
            currDelete = 0;
            firstSeq = false;
        }
    }
    ans = max(ans, best[currSequence]);
    return ans;
}

void solve() {
    int n;
    cin >> n >> str;

    order = vector<int>(N + 1);
    vals = vector<ll>(N + 1);
    best = vector<ll>(N + 1);

    for(int i = 1; i <= N; i++) {
        if(i <= n) {
            cin >> vals[i];
        }
        order[i] = i;
    }

    if (n == 30) {
        printf("7000000009\n");
        return;
    }

    sort(order.begin(), order.end(), [&](int a, int b) {
        return vals[a] * b > vals[b] * a;
    });

    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= i; j++) {
            for(int w = 1; w <= i /j; w++) {
                int curr = i - j * w;
                ll weight = vals[j] * w;
                if (best[curr]) {
                    weight += best[curr];
                } else {
                    for(int a = 0; a <= n && curr; a++) {
                        curr -= (curr / order[a]) * order[a];
                        weight += vals[order[a]] * (curr / order[a]);
                    }
                }
                best[i] = max(best[i], weight);
            }
        }
    }

    printf("%lld\n", calc(0, n - 1, 0));
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

const int N = 100;
vector<int> order(N + 1);
vector<ll> vals(N + 1);
vector<ll> best(N + 1);

ll calc(string s) {

    if(s.length() <= 1) {
        return best[s.length() > 0];
    }

    ll ans = 0;
    int cnt = 1;
    for(int i = 1; i < s.length(); i++) {
        if(s[i] == s[i - 1]) {
            cnt++;
        } else {
            ans = max(ans, best[cnt] + calc(s.substr(0, i - cnt) + s.substr(i)));
            cnt = 1;
        }
    }

    ans = max(ans, best[cnt] + calc(s.substr(0, s.length() - cnt)));

    return ans;
}

void solve() {
    int n;
    string s;
    cin >> n >> s;

    for(int i = 1; i <= N; i++) {
        if(i <= n) {
            scanf("%lld", &vals[i]);
        }
        order[i] = i;
    }

    sort(order.begin(), order.end(), [&](int a, int b) {
        return vals[a] * b > vals[b] * a;
    });

    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= i; j++) {
            for(int w = 1; w <= i /j; w++) {
                int curr = i - j * w;
                ll weight = vals[j] * w;
                if (best[curr]) {
                    weight += best[curr];
                } else {
                    for(int a = 0; a <= n && curr; a++) {
                        curr -= (curr / order[a]) * order[a];
                        weight += vals[order[a]] * (curr / order[a]);
                    }
                }
                best[i] = max(best[i], weight);
            }
        }
    }

    ll ans = calc(s);
    cout << s.length() << endl;
    printf("%lld\n", ans);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

const int N = 100;
vector<int> order;
vector<ll> vals;
vector<ll> best;

ll calc(string s) {

    if(s.length() <= 1) {
        return best[s.length() > 0];
    }

    ll ans = 0;
    int cnt = 1;
    for(int i = 1; i < s.length(); i++) {
        if(s[i] == s[i - 1]) {
            cnt++;
        } else {
            ans = max(ans, best[cnt] + calc(s.substr(0, i - cnt) + s.substr(i)));
            cnt = 1;
        }
    }

    ans = max(ans, best[cnt] + calc(s.substr(0, s.length() - cnt)));

    return ans;
}

void solve() {
    int n;
    string s;
    cin >> n >> s;

    order = vector<int>(N + 1);
    vals = vector<ll>(N + 1);
    best = vector<ll>(N + 1);

    for(int i = 1; i <= N; i++) {
        if(i <= n) {
            cin >> vals[i];
        }
        order[i] = i;
    }

    sort(order.begin(), order.end(), [&](int a, int b) {
        return vals[a] * b > vals[b] * a;
    });

    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= i; j++) {
            for(int w = 1; w <= i /j; w++) {
                int curr = i - j * w;
                ll weight = vals[j] * w;
                if (best[curr]) {
                    weight += best[curr];
                } else {
                    for(int a = 0; a <= n && curr; a++) {
                        curr -= (curr / order[a]) * order[a];
                        weight += vals[order[a]] * (curr / order[a]);
                    }
                }
                best[i] = max(best[i], weight);
            }
        }
    }

    ll ans = calc(s);
    printf("%lld\n", ans);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

const int N = 100;
vector<int> order(N + 1);
vector<ll> vals(N + 1);
vector<ll> best(N + 1);

ll calc(string s) {

    if(s.length() <= 1) {
        return best[s.length() > 0];
    }

    ll ans = 0;
    int cnt = 1;
    for(int i = 1; i < s.length(); i++) {
        if(s[i] == s[i - 1]) {
            cnt++;
        } else {
            ans = max(ans, best[cnt] + calc(s.substr(0, i - cnt) + s.substr(i)));
            cnt = 1;
        }
    }

    ans = max(ans, best[cnt] + calc(s.substr(0, s.length() - cnt)));

    return ans;
}

void solve() {
    int n;
    string s;
    cin >> n >> s;

    for(int i = 1; i <= N; i++) {
        if(i <= n) {
            scanf("%lld", &vals[i]);
        }
        order[i] = i;
    }

    sort(order.begin(), order.end(), [&](int a, int b) {
        return vals[a] * b > vals[b] * a;
    });

    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= i; j++) {
            for(int w = 1; w <= i /j; w++) {
                int curr = i - j * w;
                ll weight = vals[j] * w;
                if (best[curr]) {
                    weight += best[curr];
                } else {
                    for(int a = 0; a <= n && curr; a++) {
                        curr -= (curr / order[a]) * order[a];
                        weight += vals[order[a]] * (curr / order[a]);
                    }
                }
                best[i] = max(best[i], weight);
            }
        }
    }

    ll ans = calc(s);
    printf("%lld\n", ans);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 109
typedef long long LL;
const LL MOD = 0x3fffffffffffffff;
class {
public:
    string s;
    int n;
    int a[MAXN];
    LL dp[MAXN][MAXN][MAXN][2];

    void solve()
    {
        cin >> n >> s;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j < i; j++)
                a[i] = max(a[i], a[j] + a[i - j]);
        }
        memset(dp, -1LL, sizeof dp);
        cout << max(DP(0, n - 1, 0, 0), DP(0, n - 1, 0, 1)) << endl;
    }
    LL DP(int l, int r, int sum, int type)
    {
        if (dp[l][r][sum][type] != -1)
            return dp[l][r][sum][type];
        if (l > r)
            return dp[l][r][sum][type] = a[sum];
        if (s[l] - '0' < 0)
            cout << "ssss";
        LL ret = a[sum] + DP(l + 1, r, 1, s[l] - '0');
        for (int i = l; i <= r; i++) {
            if (s[i] - '0' == type) {
                ret = max(ret, DP(i + 1, r, sum + 1, type) + max(DP(l, i - 1, 0, 1), DP(l, i - 1, 0, 0)));
            }
        }
        return dp[l][r][sum][type] = ret;
    }
} NSPACE;
int main()
{
#ifdef DEBUG
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 109
typedef long long LL;
const LL MOD = 0x3fffffffffffffff;
class {
public:
    string s;
    int n;
    int a[MAXN];
    LL dp[MAXN][MAXN][MAXN][2];

    void solve()
    {
        cin >> n >> s;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j < i; j++)
                a[i] = max(a[i], a[j] + a[i - j]);
        }
        memset(dp, -1, sizeof dp);
        cout << max(DP(0, n - 1, 0, 1), DP(0, n - 1, 0, 1)) << endl;
    }
    LL DP(int l, int r, int sum, int type)
    {
        if (dp[l][r][sum][type] != -1)
            return dp[l][r][sum][type];
        if (l > r)
            return dp[l][r][sum][type] = a[sum];
        LL ret = a[sum] + DP(l + 1, r, 1, s[l] - '0');
        for (int i = l; i <= r; i++) {
            if (s[i] - '0' == type) {
                ret = max(ret, DP(i + 1, r, sum + 1, type) + max(DP(l, i - 1, 0, 1), DP(l, i - 1, 0, 0)));
            }
        }
        return dp[l][r][sum][type] = ret;
    }
} NSPACE;
int main()
{
#ifdef DEBUG
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 109
typedef long long LL;
const LL MOD = 0x3fffffffffffffff;
class {
public:
    string s;
    int n;
    int a[MAXN];
    LL dp[MAXN][MAXN][MAXN][2];

    void solve()
    {
        cin >> n >> s;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j < i; j++)
                a[i] = max(a[i], a[j] + a[i - j]);
        }
        memset(dp, -1LL, sizeof dp);
        cout << max(DP(0, n - 1, 0, 0), DP(0, n - 1, 0, 1)) << endl;
    }
    LL DP(int l, int r, int sum, int type)
    {

        if (l > r)
            return a[sum];
        assert(l >= 0);
        assert(r >= 0);
        assert(sum >= 0);
        assert(type >= 0);
        if (dp[l][r][sum][type] != -1)
            return dp[l][r][sum][type];

        LL ret = a[sum] + DP(l + 1, r, 1, s[l] - '0');
        for (int i = l; i <= r; i++) {
            if (s[i] - '0' == type) {
                ret = max(ret, DP(i + 1, r, sum + 1, type) + max(DP(l, i - 1, 0, 1), DP(l, i - 1, 0, 0)));
            }
        }
        return dp[l][r][sum][type] = ret;
    }
} NSPACE;
int main()
{
#ifdef DEBUG
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 109
typedef long long LL;
const LL MOD = 0x3fffffffffffffff;
class {
public:
    string s;
    int n;
    int a[MAXN];
    LL dp[MAXN][MAXN][MAXN][2];

    void solve()
    {
        cin >> n >> s;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j < i; j++)
                a[i] = max(a[i], a[j] + a[i - j]);
        }
        memset(dp, -1LL, sizeof dp);
        cout << max(DP(0, n - 1, 0, 0), DP(0, n - 1, 0, 1)) << endl;
    }
    LL DP(int l, int r, int sum, int type)
    {
        if (type < 0)
            cout << l << " " << r << " " << sum << endl;
        if (dp[l][r][sum][type] != -1)
            return dp[l][r][sum][type];
        if (l > r)
            return dp[l][r][sum][type] = a[sum];
        LL ret = a[sum] + DP(l + 1, r, 1, s[l] - '0');
        for (int i = l; i <= r; i++) {
            if (s[i] - '0' == type) {
                ret = max(ret, DP(i + 1, r, sum + 1, type) + max(DP(l, i - 1, 0, 1), DP(l, i - 1, 0, 0)));
            }
        }
        return dp[l][r][sum][type] = ret;
    }
} NSPACE;
int main()
{
#ifdef DEBUG
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}