#include <iostream>
#include <stdio.h>
using namespace std;
int a[100001] = {};
int main()
{
    int i,j,k = 0;
    char ch;
    j = 0;
    while (scanf("%c",&ch))
    {
        if (ch > '9' || ch < '0') break;
        i = ch - '0';
        if (i + j ==9)
        {
            k++;
        }else
        {
            a[k]++;
            k = 0;
        }
        j = i;
    }
    a[k] ++;
    unsigned long long t = 1;
    for ( i = 1; i < 100000;i++)
    {
        if ((i %2 == 0) && a[i])
        {
            t = t*a[i]*(1+i/2);
        }
    }
    cout << t<<endl;
    return 0;
}


#include <iostream>
#include <stdio.h>
using namespace std;
int a[100001] = {};
int main()
{
    int i,j,k = 0;
    char ch;
    j = 10;
    while (scanf("%c",&ch))
    {
        if (ch > '9' || ch < '0') break;
        i = ch - '0';
        if (i + j ==9)
        {
            k++;
        }else
        {
            a[k]++;
            k = 0;
        }
        j = i;
    }
    a[k] ++;
    unsigned long long t = 1;
    for ( i = 1; i < 100001;i++)
    {
        if ((i %2 == 0) && a[i])
        {
            t = t*a[i]*(1+i/2);
        }
    }
    cout << t<<endl;
    return 0;
}


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

typedef long long ll;

string s;

int main(){
    ll ans = 1,i,len,j;
    cin >> s;
    for(i=1;s[i];i++){
        int a = s[i-1]-'0';
        int b = s[i]-'0';
        if(a + b == 9){
            //cout << i << '\n';
            int cnt = 2;
            for(j=i+2;s[j];j+=2){
                int c = s[j-1]-'0';
                int d = s[j]-'0';
                if(c == a && d == b){
                    cnt += 2;
                }else{
                    if(c == a) cnt += 1;
                    break;
                }
            }
            i = j;
            if(s[j] == '\0' && s[j-1]-'0' == a) cnt += 1;
            //cout << cnt << '\n';
            if(cnt%2 != 0) ans *= 2;
        }
    }
    ans = max(ans,1ll);
    cout << ans << '\n';
    return 0;
}


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

typedef long long ll;

string s;

int main(){
    ll ans = 1,i,cnt = 0;
    cin >> s;
    for(i=1;s[i];i++){
        if(s[i-1]-'0'+s[i]-'0' == 9) cnt++;
        else{
            if(cnt > 0 && cnt%2 == 0) ans *= cnt/2+1;
            cnt = 0;
        }
    }
    cout << ans << '\n';
    return 0;
}


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

typedef long long ll;

string s;

int main(){
    ll ans = 1,i,cnt = 0;
    cin >> s;
    for(i=1;i<=s.size();i++){
        if(s[i-1]-'0'+s[i]-'0' == 9) cnt++;
        else{
            if(cnt > 0 && cnt%2 == 0) ans *= (cnt/2+1);
            cnt = 0;
        }
    }
    cout << ans << '\n';
    return 0;
}


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

typedef long long ll;

string s;

int main(){
    ll ans = 0,i,len,j;
    cin >> s;
    for(i=1;s[i];i++){
        int a = s[i-1]-'0';
        int b = s[i]-'0';
        if(a + b == 9){
            int cnt = 2;
            for(j=i+2;s[j];j+=2){
                int c = s[j-1]-'0';
                int d = s[j]-'0';
                if(c == a && d == b){
                    cnt += 2;
                }else{
                    if(c == a) cnt += 1;
                    break;
                }
            }
            i = j;
            if((s[j-1]-'0') == a) cnt += 1;
            if(cnt%2 != 0) ans += 2;
        }
    }
    ans = max(ans,1ll);
    cout << ans << '\n';
    return 0;
}


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

typedef long long ll;

string s;

int main(){
    ll ans = 0,i,len,j;
    cin >> s;
    for(i=1;s[i];i++){
        int a = s[i-1]-'0';
        int b = s[i]-'0';
        if(a + b == 9){
            int cnt = 2;
            for(j=i+2;s[j];j+=2){
                int c = s[j-1]-'0';
                int d = s[j]-'0';
                if(c == a && d == b){
                    cnt += 2;
                }else{
                    if(c == a) cnt += 1;
                    i = j;
                    break;
                }
            }
            if((s[j-1]-'0') == a) cnt += 1;
            if(cnt%2 != 0) ans += 2;
        }
    }
    ans = max(ans,1ll);
    cout << ans << '\n';
    return 0;
}


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

typedef long long ll;

string s;

int main(){
    ll ans = 1,i,len,j;
    cin >> s;
    for(i=1;s[i];i++){
        int a = s[i-1]-'0';
        int b = s[i]-'0';
        if(a + b == 9){
            //cout << i << '\n';
            int cnt = 2;
            for(j=i+2;s[j];j+=2){
                int c = s[j-1]-'0';
                int d = s[j]-'0';
                if(c == a && d == b){
                    cnt += 2;
                }else{
                    if(c == a) cnt += 1;
                    break;
                }
            }
            i = j;
            if(s[j] == '\0' && s[j-1]-'0' == a) cnt += 1;
            //cout << cnt << '\n';
            if(cnt%2 != 0) ans *= (cnt/2 + 1);
        }
    }
    ans = max(ans,1ll);
    cout << ans << '\n';
    return 0;
}


/* In the Name of ALLAH */

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <fstream>
#include <queue>
#include <cstring>
#include <iomanip>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define X first
#define Y second

const int N=1e9+10;

int main () {
    string s; cin>>s;
    int st=-2, fi=-1; ll ans=1; bool can=false;
    for (int i=0;i<s.size()-1;i++) {
        int cur=(int(s[i])-'0')+(int(s[i+1])-'0');
        if (cur==9 && i+1==s.size()-1) {
            fi++;
            if ( (fi-st+1)%2 )
                ans*=ll(2);
            break;
        }
        if ( cur==9 && fi<i ) {
            st=i;
            fi=i+1;
        }
        else if ( cur==9 )
            fi++;
        else if ( (fi-st+1)%2 ) {
            ans*=ll(2);
            fi=st+1;
        }
        else
            fi=st+1;
    }
    if (st==-1)
        cout<<"1";
    else
        cout<<ans;

    return 0;
}


/* In the Name of ALLAH */

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <fstream>
#include <queue>
#include <cstring>
#include <iomanip>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define X first
#define Y second

const int N=1e9+10;

int main () {
    string s; cin>>s;
    int j=0; ll ans=1;
    for (int i=1;i<s.size();i++) {
        int cur=(int(s[i])-'0')+(int(s[i-1])-'0');
        if (cur!=9 && (i-j)%2) {
            ans*=(i-j+1)/2;
            j=i;
        }
        else if (cur!=9)
            j=i;
    }
    cout<<ans;

    return 0;
}


/* In the Name of ALLAH */

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <fstream>
#include <queue>
#include <cstring>
#include <iomanip>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define X first
#define Y second

const int N=1e9+10;

int main () {
    string s; cin>>s;
    int st=-2, fi=-1; ll ans=1; bool can=false;
    for (int i=0;i<s.size()-1;i++) {
        int cur=(int(s[i])-'0')+(int(s[i+1])-'0');
        if (cur==9 && i+1==s.size()-1) {
            fi++;
            if ( (fi-st+1)%2 )
                ans*=ll(2);
            break;
        }
        if ( cur==9 && fi<i ) {
            st=i;
            fi=i+1;
        }
        else if ( cur==9 )
            fi++;
        else if ( (fi-st+1)%2 ) {
            ans*=ll(2);
            fi=st+1;
        }
        else
            fi=st+1;
    }
    if (st==-1)
        cout<<"0";
    else
        cout<<ans;

    return 0;
}


/* In the Name of ALLAH */

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <fstream>
#include <queue>
#include <cstring>
#include <iomanip>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define X first
#define Y second

const int N=1e9+10;

int main () {
    string s; cin>>s;
    int st=-2, fi=-1; ll ans=1; bool can=false;
    for (int i=0;i<s.size()-1;i++) {
        int cur=(int(s[i])-'0')+(int(s[i+1])-'0');
        if (cur==9 && i+1==s.size()-1) {
            if (fi<i) {
                st=i;
                fi=i+1;
            }
            else
                fi++;
            if ( (fi-st+1)%2 )
                ans*=ll(2);
            break;
        }
        if ( cur==9 && fi<i ) {
            st=i;
            fi=i+1;
        }
        else if ( cur==9 )
            fi++;
        else if ( (fi-st+1)%2 ) {
            ans*=ll(2);
            fi=st+1;
        }
        else
            fi=st+1;
    }
    cout<<ans;

    return 0;
}


/* In the Name of ALLAH */

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <fstream>
#include <queue>
#include <cstring>
#include <iomanip>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define X first
#define Y second

const int N=1e9+10;

int main () {
    string s; cin>>s;
    int j=0, i=0; ll ans=1;
    for (i=1;i<s.size();i++) {
        int cur=(int(s[i])-'0')+(int(s[i-1])-'0');
        if (cur!=9 && (i-j)%2) {
            ans*=(i-j+1)/2;
            j=i;
        }
        else if (cur!=9)
            j=i;
    }
    if ((i-j)%2)
        ans*=(i-j+1)/2;
    cout<<ans;

    return 0;
}


/* In the Name of ALLAH */

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <fstream>
#include <queue>
#include <cstring>
#include <iomanip>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define X first
#define Y second

const int N=1e9+10;

int main () {
    string s; cin>>s;
    int j=0; ll ans=1;
    for (int i=1;i<s.size();i++) {
        int cur=(int(s[i])-'0')+(int(s[i-1])-'0');
        if (cur!=9 && (i-j)%2) {
            ans*=(i-j+1)/2;
            j=i;
        }
    }
    cout<<ans;

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
long long fib[1000002];
int main()
{
    fib[0]=0;
    fib[1]=2;
    fib[2]=3;
    for (int i = 3; i < 1000002; ++i)
    {
        fib[i]=fib[i-1]+fib[i-2];
    }
    string number;
    cin>>number;
    bool found;
    int dis=0;
    long long tot=1;
    for (int i = 0; i < number.length()-1; ++i)
    {
        if(number[i]-'0'+number[i+1]-'0'==9 && !found)
        {
            // cout<<i<<endl;
            dis=2;
            found=true;
            continue;
        }
        else if(number[i]-'0'+number[i+1]-'0'==9 && found)
        {
            dis++;
            continue;
        }
        else if(found)
        {
            // cout<<dis<<endl;
            if(dis%2!=0)
                tot*=fib[dis/2];
            found=false;
        }
    }
    // cout<<dis<<endl;
    // cout<<fib[1000000]<<endl;
    if(found)
        if(dis%2!=0)
            tot*=fib[dis/2];
    // if(tot==0)
    //  tot=1;
    cout<<tot<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
int main()
{

    string number;
    cin>>number;
    number+="9999";
    bool found=false;
    unsigned long long dis=0;
    unsigned long long tot=1;
    for (int i = 0; i < number.length(); ++i)
    {
        if(number[i]-'0'+number[i+1]-'0'==9 && !found)
        {
            dis=2;
            found=true;
            continue;
        }
        else if(number[i]-'0'+number[i+1]-'0'==9 && found)
        {
            dis++;
            continue;
        }
        else if(found)
        {
            if(dis%2!=0)
                tot*=dis/2+1;
            found=false;
        }
    }
    // if(found)
    //  if(dis%2!=0)
    //      tot*=dis/2+1;
    cout<<tot<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
int main()
{

    string number;
    cin>>number;
    number+="9999";
    bool found;
    long long dis=0;
    unsigned long long tot=1;
    for (int i = 0; i < number.length(); ++i)
    {
        if(number[i]-'0'+number[i+1]-'0'==9 && !found)
        {
            dis=2;
            found=true;
            continue;
        }
        else if(number[i]-'0'+number[i+1]-'0'==9 && found)
        {
            dis++;
            continue;
        }
        else if(found)
        {
            if(dis%2!=0)
                tot*=dis/2+1;
            found=false;
        }
    }
    // if(found)
    //  if(dis%2!=0)
    //      tot*=dis/2+1;
    cout<<tot<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
int main()
{

    string number;
    cin>>number;
    number+="9999";
    bool found;
    int dis=0;
    long long tot=1;
    for (int i = 0; i < number.length()-1; ++i)
    {
        if(number[i]-'0'+number[i+1]-'0'==9 && !found)
        {
            dis=2;
            found=true;
            continue;
        }
        else if(number[i]-'0'+number[i+1]-'0'==9 && found)
        {
            dis++;
            continue;
        }
        else if(found)
        {
            if(dis%2!=0)
                tot*=dis/2+1;
            found=false;
        }
    }
    // if(found)
    //  if(dis%2!=0)
    //      tot*=dis/2+1;
    cout<<tot<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
int main()
{

    string number;
    cin>>number;
    number+="9999";
    bool found=false;
    long long dis=0;
    unsigned long long tot=1;
    for (int i = 0; i < number.length(); ++i)
    {
        if(number[i]-'0'+number[i+1]-'0'==9 && !found)
        {
            dis=2;
            found=true;
            continue;
        }
        else if(number[i]-'0'+number[i+1]-'0'==9 && found)
        {
            dis++;
            continue;
        }
        else if(found)
        {
            if(dis%2!=0)
                tot*=dis/2+1;
            found=false;
        }
    }
    // if(found)
    //  if(dis%2!=0)
    //      tot*=dis/2+1;
    cout<<tot<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
int main()
{

    string number;
    cin>>number;
    bool found;
    int dis=0;
    long long tot=1;
    for (int i = 0; i < number.length()-1; ++i)
    {
        if(number[i]-'0'+number[i+1]-'0'==9 && !found)
        {
            dis=2;
            found=true;
            continue;
        }
        else if(number[i]-'0'+number[i+1]-'0'==9 && found)
        {
            dis++;
            continue;
        }
        else if(found)
        {
            if(dis%2!=0)
                tot*=dis/2+1;
            found=false;
        }
    }
    if(found)
        if(dis%2!=0)
            tot*=dis/2+1;
    cout<<tot<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
long long fib[1000002];
int main()
{
	fib[0]=0;
	fib[1]=2;
	fib[2]=3;
	for (int i = 3; i < 1000002; ++i)
	{
		fib[i]=fib[i-1]+fib[i-2];
	}
	string number;
	cin>>number;
	bool found;
	int dis=0;
	long long tot=0;
	for (int i = 0; i < number.length()-1; ++i)
	{
		if(number[i]-'0'+number[i+1]-'0'==9 && !found)
		{
			// cout<<i<<endl;
			dis=2;
			found=true;
			continue;
		}
		else if(number[i]-'0'+number[i+1]-'0'==9 && found)
		{
			dis++;
			continue;
		}
		else if(found)
		{
			// cout<<dis<<endl;
			if(dis%2!=0)
				tot+=fib[dis/2];
			found=false;
		}
	}
	// cout<<dis<<endl;
	// cout<<fib[1000000]<<endl;
	if(found)
		if(dis%2!=0)
			tot+=fib[dis/2];
	if(tot==0)
		tot=1;
	cout<<tot<<endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;

int Xa,Xb,Xc,Xd,Ya,Yb,Yc,Yd,q;

int main(){

	cin>>Xa>>Ya>>Xb>>Yb;

	if(Xa==Xb) {
		q=abs(Ya-Yb);
		Xc=Xa+q;
		Xd=Xb+q;
		Yc=Ya;
		Yd=Yb;
		cout<<Xc<<" "<<Yc<<'\n';
		cout<<Xd<<" "<<Yd<<'\n';
	}
	else
		if(Ya==Yb){
			q=abs(Xa-Xb);
			Yc=Ya+q;
			Yd=Yb+q;
			Xc=Xa;
			Xd=Xb;
			cout<<Xc<<" "<<Yc<<'\n';
			cout<<Xd<<" "<<Yd<<'\n';
		}
		else
			if(abs(Xa-Xb)==abs(Xb-Yb)){
			Xc=Xa;
			Xd=Xb;
			Yc=Yb;
			Yd=Ya;
			cout<<Xc<<" "<<Yc<<'\n';
			cout<<Xd<<" "<<Yd<<'\n';
		}
		else cout<<"-1";

	return 0;
}


#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;

int Xa,Xb,Xc,Xd,Ya,Yb,Yc,Yd,q;

int main(){

	cin>>Xa>>Ya>>Xb>>Yb;

		if(Xa==Xb){
			q=abs(Ya-Yb);
			Xc=Xa+q;
			Xd=Xb+q;
			Yc=Ya;
			Yd=Yb;
			cout<<Xc<<" "<<Yc<<'\n';
			cout<<Xd<<" "<<Yd<<'\n';
		}
	else
		if(Ya==Yb){
			q=abs(Xa-Xb);
			Yc=Ya+q;
			Yd=Yc;
			Xc=Xa;
			Xd=Xb;
			cout<<Xc<<" "<<Yc<<'\n';
			cout<<Xd<<" "<<Yd<<'\n';
		}
		else
			if(abs(Xa-Xb)==abs(Ya-Yb)){
				Xc=Xb;
				Xd=Xa;
				Yc=Ya;
				Yd=Yb;
			cout<<Xc<<" "<<Yc<<'\n';
			cout<<Xd<<" "<<Yd<<'\n';
		}
		else cout<<"-1";

	return 0;
}


#include<fstream>
#include<algorithm>
#include<math.h>

using namespace std;

int Xa,Xb,Xc,Xd,Ya,Yb,Yc,Yd,q;

int main(){
	ifstream f("copac.in");
	ofstream t("copac.out");

	f>>Xa>>Ya>>Xb>>Yb;

	if(Xa==Xb) {
		q=abs(Ya-Yb);
		Xc=Xa+q;
		Xd=Xb+q;
		Yc=Ya;
		Yd=Yb;
		t<<Xc<<" "<<Yc<<'\n';
		t<<Xd<<" "<<Yd<<'\n';
	}
	else
		if(Ya==Yb){
			q=abs(Xa-Xb);
			Yc=Ya+q;
			Yd=Yb+q;
			Xc=Xa;
			Xd=Xb;
			t<<Xc<<" "<<Yc<<'\n';
			t<<Xd<<" "<<Yd<<'\n';
		}
		else
			if((Xa==Ya) && (Xb==Yb)){
			Xc=Xa;
			Xd=Xb;
			Yc=Yb;
			Yd=Ya;
			t<<Xc<<" "<<Yc<<'\n';
			t<<Xd<<" "<<Yd<<'\n';
		}
		else
			if((Xa!=Xb) && (Xb!=Yb)){
				Xc=Xa;
				Xd=Xb;
				Yc=Yb;
				Yd=Ya;
				t<<Xc<<" "<<Yc<<'\n';
				t<<Xd<<" "<<Yd<<'\n';
			}
		else t<<"-1";

	return 0;
}


#include <iostream>

using namespace std;

int coordinate(int a,int d)
{
	if(a+d>-1000 && a+d<1000)
		return a+d;
	else
		return a-d;
}
int main(int argc, char const *argv[])
{

	int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	int d;
	if(abs(y2-y1)/abs(x2-x1)==1)
	{
		cout<<x1<<" "<<y2<<" "<<x2<<" "<<y1;
	}
	else if(x1==x2)
	{
		d=abs(y2-y1);
		x2=coordinate(x2,d);
		cout<<x2<<" "<<y1<<" "<<x2<<" "<<y2;
	}
	else if(y2==y1)
	{
		d=abs(x2-x1);
		y2=coordinate(y2,d);
		cout<<x2<<" "<<y2<<" "<<x1<<" "<<y2;
	}
	else cout<<-1;

	return 0;
}


#include <iostream>

using namespace std;

int coordinate(int a,int d)
{
	if(a+d>-1000 && a+d<1000)
		return a+d;
	else
		return a-d;
}
int main(int argc, char const *argv[])
{

	int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	int d;
	if((x2!=x1) && (y2!=y1))
	{
		if(abs(y2-y1)/abs(x2-x1)==1)
		cout<<x1<<" "<<y2<<" "<<x2<<" "<<y1;
		else cout<<-1;
	}
	else if(x1==x2)
	{
		d=abs(y2-y1);
		x2=coordinate(x2,d);
		cout<<x2<<" "<<y1<<" "<<x2<<" "<<y2;
	}
	else if(y2==y1)
	{
		d=abs(x2-x1);
		y2=coordinate(y2,d);
		cout<<x2<<" "<<y2<<" "<<x1<<" "<<y2;
	}

	return 0;
}


#include <iostream>

using namespace std;

int coordinate(int a,int d)
{
	if(a+d>-1000 && a+d<1000)
		return a+d;
	else
		return a-d;
}
int main(int argc, char const *argv[])
{

	int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	int d;
	if((x2!=x1) && (y2!=y1))
	{
		double k=(double)(y2-y1)/(x2-x1);
		//cout<<k<<endl;
		if(k==1||k==-1)
		cout<<x1<<" "<<y2<<" "<<x2<<" "<<y1;
		else cout<<-1;
	}
	else if(x1==x2)
	{
		d=abs(y2-y1);
		x2=coordinate(x2,d);
		cout<<x2<<" "<<y1<<" "<<x2<<" "<<y2;
	}
	else if(y2==y1)
	{
		d=abs(x2-x1);
		y2=coordinate(y2,d);
		cout<<x2<<" "<<y2<<" "<<x1<<" "<<y2;
	}

	return 0;
}


#include <iostream>

using namespace std;

int coordinate(int a,int d)
{
	if(a+d>-1000 && a+d<1000)
		return a+d;
	else
		return a-d;
}
int main(int argc, char const *argv[])
{

	int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	int d;
	if(abs(y2-y1)/abs(x2-x1)==1)
	{
		cout<<x1<<" "<<y2<<" "<<x2<<" "<<y1;
	}
	else if(x1==x2)
	{
		d=abs(y2-y1);
		x2=coordinate(x2,d);
		cout<<x2<<" "<<y1<<" "<<x2<<" "<<y2;
	}
	else if(y2==y1)
	{
		d=abs(x2-x1);
		y2=coordinate(y2,d);
		cout<<x2<<" "<<y2<<" "<<x1<<" "<<y2;
	}

	else cout<<-1;

	return 0;
}


#include <iostream>

using namespace std;

int coordinate(int a,int d)
{
	if(a+d>-1000 && a+d<1000)
		return a+d;
	else
		return a-d;
}
int main(int argc, char const *argv[])
{

	int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	int d;
	if(x1==x2)
	{
		d=abs(y2-y1);
		x2=coordinate(x2,d);
		cout<<x2<<" "<<y1<<" "<<x2<<" "<<y2;
	}
	else if(y2==y1)
	{
		d=abs(x2-x1);
		y2=coordinate(y2,d);
		cout<<x2<<" "<<y2<<" "<<x1<<" "<<y2;
	}
	else if(abs(y2-y1)/abs(x2-x1)==1)
	{
		cout<<x1<<" "<<y2<<" "<<x2<<" "<<y1;
	}
	else cout<<-1;

	return 0;
}


#include <iostream>

using nammespace std;

int coordinate(int a,int d)
{
	if(a+d>-1000 && a+d<1000)
		return a+d;
	else
		return a-d;
}
int main(int argc, char const *argv[])
{

	int x1,x2,y1,y2;
	cin>>x1>>x2>>y1>>y2;
	int d;
	if(x1==x2)
	{
		d=abs(y2-y1);
		x2=coordinate(x2);
		cout<<x2<<y2<<x2<<y1;
	}
	else if(y2==y1)
	{
		d=abs(x2-x1);
		y2=coordinate(y2);
		cout<<x1<<y2<<x2<<y2;
	}
	else if(abs(y2-y1)/abs(x2-x1)==1)
	{
		cout<<x2<<y1<<x1<<y2;
	}
	else cout<<-1;

	return 0;
}


#include <iostream>

using namespace std;

int coordinate(int a,int d)
{
	if(a+d>-1000 && a+d<1000)
		return a+d;
	else
		return a-d;
}
int main(int argc, char const *argv[])
{

	int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	int d;
	if((x2-x1) && abs(y2-y1)/abs(x2-x1)==1)
	{
		cout<<x1<<" "<<y2<<" "<<x2<<" "<<y1;
	}
	else if(x1==x2)
	{
		d=abs(y2-y1);
		x2=coordinate(x2,d);
		cout<<x2<<" "<<y1<<" "<<x2<<" "<<y2;
	}
	else if(y2==y1)
	{
		d=abs(x2-x1);
		y2=coordinate(y2,d);
		cout<<x2<<" "<<y2<<" "<<x1<<" "<<y2;
	}
	else cout<<-1;

	return 0;
}


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

int main(){

    int x1,x2,xa,xb,y1,y2,ya,yb,absx,absy;
    cin >> x1>>y1>>x2>>y2;
    absy=abs(y1-y2);
    absx=abs(x1-x2);
    if(x1==x2){

        xa=x1+absy;
        xb=xa;
        ya=y1;
        yb=y2;
        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else if(y1==y2){

        xa=x1;
        xb=x2;
        if(y1<0){
            ya=y1+absx;
        }else{
        ya=y1+absx;
        }
        yb=ya;
        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else if(absy==absx){
        if(x1<x2){
            xa=x1;
            ya=y2;
            xb=x2;
            yb=y1;
        }else{
            xa=x1;
            ya=y2;
            xb=x2;
            yb=y1;
        }

        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else{
    cout << -1;
    }

return 0;
}


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

int main(){

    int x1,x2,xa,xb,y1,y2,ya,yb,absx,absy;
    cin >> x1>>y1>>x2>>y2;
    absy=abs(y1-y2);
    absx=abs(x1-x2);
    if(x1==x2){

        xa=x1+absy;
        xb=xa;
        ya=y1;
        yb=y2;
        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else if(y1==y2){

        xa=x1;
        xb=x2;
        if(y1<0){
            ya=x1;
        }else{
        ya=x1-absx;
        }
        yb=ya;
        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else if(absy==absx){
        if(x1<x2){
            xa=x1;
            ya=y2;
            xb=x2;
            yb=y1;
        }else{
            xa=x2;
            ya=y2;
            xb=x1;
            yb=y2;
        }

        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else{
    cout << -1;
    }

return 0;
}


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

int main(){

    int x1,x2,xa,xb,y1,y2,ya,yb,absx,absy;
    cin >> x1>>y1>>x2>>y2;
    absy=abs(y1-y2);
    absx=abs(x1-x2);
    if(x1==x2){

        xa=x1+absy;
        xb=xa;
        ya=y1;
        yb=y2;
        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else if(y1==y2){

        xa=x1;
        xb=x2;
        if(y1<0){
            ya=x1;
        }else{
        ya=y1+absx;
        }
        yb=ya;
        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else if(absy==absx){
        if(x1<x2){
            xa=x1;
            ya=y2;
            xb=x2;
            yb=y1;
        }else{
            xa=x2;
            ya=y2;
            xb=x1;
            yb=y2;
        }

        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else{
    cout << -1;
    }

return 0;
}


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

int main(){

    int x1,x2,xa,xb,y1,y2,ya,yb,absx,absy;
    cin >> x1>>y1>>x2>>y2;
    absy=abs(y1-y2);
    absx=abs(x1-x2);
    if(x1==x2){

        xa=x1+absy;
        xb=xa;
        ya=y1;
        yb=y2;
        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else if(y1==y2){

        xa=x1;
        xb=x2;
        ya=x1+absx;
        yb=ya;
        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else if(absy==absx){
        xa=x1;
        yb=y1;
        if(y1>y2){
            ya=y1-absy;
        }else{
            ya=y1+absy;
        }
        if(x2>x1){
            xb=x2;
        }else{
            xb=x2-absx;
        }
        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else{
    cout << -1;
    }

return 0;
}


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

int main(){

    int x1,x2,xa,xb,y1,y2,ya,yb,absx,absy;
    cin >> x1>>y1>>x2>>y2;
    absy=abs(y1-y2);
    absx=abs(x1-x2);
    if(x1==x2){

        xa=x1+absy;
        xb=xa;
        ya=y1;
        yb=y2;
        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else if(y1==y2){

        xa=x1;
        xb=x2;
        if(y1<0){
            ya=x1;
        }else{
        ya=y1+absx;
        }
        yb=ya;
        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else if(absy==absx){
        if(x1<x2){
            xa=x1;
            ya=y2;
            xb=x2;
            yb=y1;
        }else{
            xa=x1;
            ya=y2;
            xb=x2;
            yb=y1;
        }

        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else{
    cout << -1;
    }

return 0;
}


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

int main(){

    int x1,x2,xa,xb,y1,y2,ya,yb,absx,absy;
    cin >> x1>>y1>>x2>>y2;
    absy=abs(y1-y2);
    absx=abs(x1-x2);
    if(x1==x2){

        xa=x1+absy;
        xb=xa;
        ya=y1;
        yb=y2;
        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else if(y1==y2){

        xa=x1;
        xb=x2;
        if(y1<0){
            ya=x1-absx;
        }else{
        ya=y1+absx;
        }
        yb=ya;
        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else if(absy==absx){
        if(x1<x2){
            xa=x1;
            ya=y2;
            xb=x2;
            yb=y1;
        }else{
            xa=x1;
            ya=y2;
            xb=x2;
            yb=y1;
        }

        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else{
    cout << -1;
    }

return 0;
}


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

int main(){

    int x1,x2,xa,xb,y1,y2,ya,yb,absx,absy;
    cin >> x1>>y1>>x2>>y2;
    absy=abs(y1-y2);
    absx=abs(x1-x2);
    if(x1==x2){

        xa=x1+absy;
        xb=xa;
        ya=y1;
        yb=y2;
        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else if(y1==y2){

        xa=x1;
        xb=x2;
        ya=x1+absx;
        yb=ya;
        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else if(absy==absx){
        xa=x1;
        yb=y2;
        if(y1>y2){
            ya=y1+absy;
        }else{
            ya=y1-absy;
        }
        if(x2>x1){
            xb=x2-absx;
        }else{
            xb=x2+absx;
        }
        cout << xa << " " << ya  << " " << xb << " " << yb;
    }else{
    cout << -1;
    }

return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
//#include <algorithm>
using namespace std;
int main()
{
	int x1,y1,x2,y2,x,y;
	cin>>x1>>y1>>x2>>y2;
	x=max(abs(x1-x2),abs(y1-y2));
	if(abs(x1-x2)>1 || abs(y1-y2)>1)
		cout<<"-1\n";
	else if(x1==x2)
		cout<<x1+x<<" "<<y1<<" "<<x2+x<<" "<<y2<<endl;
	else if(y1==y2)
		cout<<x1<<" "<<y1+x<<" "<<x2<<" "<<y2+x<<endl;
	else
		cout<<x1<<" "<<y2<<" "<<x2<<" "<<y1<<endl;

	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
//#include <algorithm>
using namespace std;
int main()
{
	int x1,y1,x2,y2,x,y;
	cin>>x1>>y1>>x2>>y2;
	x=max(abs(x1-x2),abs(y1-y2));
	set<int>st;
	st.insert(x1); st.insert(y1); st.insert(x2); st.insert(y2);
	if(st.size()>2)
		cout<<"-1\n";
	else if(x1==x2)
		cout<<x1+x<<" "<<y1<<" "<<x2+x<<" "<<y2<<endl;
	else if(y1==y2)
		cout<<x1<<" "<<y1+x<<" "<<x2<<" "<<y2+x<<endl;
	else
		cout<<x1<<" "<<y1+x<<" "<<x2<<" "<<y2-x<<endl;

	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
//#include <algorithm>
using namespace std;
int main()
{
	int x1,y1,x2,y2,x,y;
	cin>>x1>>y1>>x2>>y2;
	x=max(abs(x2-x1),abs(y2-y1));
	if(abs(x2-x1)>1 || abs(y2-y1)>1)
		cout<<"-1\n";
	else if(x1==x2)
		cout<<x1+x<<" "<<y1<<" "<<x2+x<<" "<<y2<<endl;
	else if(y1==y2)
		cout<<x1<<" "<<y1+x<<" "<<x2<<" "<<y2+x<<endl;
	else
		cout<<x1<<" "<<y2<<" "<<x2<<" "<<y1<<endl;

	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
	int x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	if(x1>1 || y1>1 || x2>1 || y2>1 || x1<0 || y1<0 || x2<0 || y2<0)
		cout<<"-1\n";
	if(x1==y1 || x2==y2)
		cout<<1-x2<<1-y2<<1-x1<<1-y1<<endl;
	else
		{cout<<1-x1<<1-y1<<1-x2<<1-y2<<endl;}

	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
//#include <algorithm>
using namespace std;
int main()
{
	int x1,y1,x2,y2,x,y;
	cin>>x1>>y1>>x2>>y2;
	x=max(abs(x2-x1),abs(y2-y1));
	if(abs(x2-x1)==abs(y2-y1))
		cout<<x1<<" "<<y2<<" "<<x2<<" "<<y1<<endl;
	else if(x1==x2)
		cout<<x1+x<<" "<<y1<<" "<<x2+x<<" "<<y2<<endl;
	else if(y1==y2)
		cout<<x1<<" "<<y1+x<<" "<<x2<<" "<<y2+x<<endl;
	else
		cout<<"-1\n";
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
	int x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	if(x1>1 || y1>1 || x2>1 || y2>1 || x1<0 || y1<0 || x2<0 || y2<0)
		cout<<"-1\n";
	if(x1==y1 || x2==y2)
		cout<<1-x2<<1-y2<<1-x1<<1-y1<<endl;
	else
		cout<<1-x1<<1-y1<<1-x2<<1-y2<<endl;

	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long ll;

namespace copied{
    const ll maxn = 1e6+100;
    vector<ll> v;
    ll n, m, a[maxn], rt[maxn], tot;
    struct node{
        ll l, r, sum;
    } T[maxn*20];

    ll getid(ll x){
        return lower_bound(v.begin(), v.end(), x)-v.begin()+1;
    }

    void build(ll &o, ll l, ll r){
        o = ++tot;
        T[o].sum = 0;
        if(l == r) return;
        ll mid = (l+r) >> 1;
        build(T[o].l, l, mid);
        build(T[o].r, mid+1, r);
    }

    void update(ll l, ll r, ll &now, ll last, ll k){
        T[++tot] = T[last];
        now = tot;
        T[now].sum++;
        if(l == r) return;
        ll mid = (l+r) >> 1;
        if(k <= mid) update(l, mid, T[now].l, T[last].l, k);
        else update(mid+1, r, T[now].r, T[last].r, k);
    }

    ll query(ll l, ll r, ll x, ll y, ll k){
        if(l == r) return T[y].sum-T[x].sum;
        ll mid = (l+r) >> 1;
        if(k <= mid) return query(l, mid, T[x].l, T[y].l, k);
        else{
            ll ret = 0;
            ret += T[T[y].l].sum-T[T[x].l].sum;
            ret += query(mid+1, r, T[x].r, T[y].r, k);
            return ret;
        }
    }

    ll respond_query(ll l, ll r, ll h){
        h--;
        l++, r++;
        ll k = upper_bound(v.begin(), v.end(), h)-v.begin();
        if(!k) return 0;
        else
            return query(1, n, rt[l-1], rt[r], k);
    }

    void init(ll *A, ll N){
        n = N;
        v.clear();
        tot = 0;
        for(ll i = 1; i <= n; i++)a[i] = A[i-1], v.push_back(a[i]);
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        build(rt[0], 1, n);
        for(ll i = 1; i <= n; i++)
            update(1, n, rt[i], rt[i-1], getid(a[i]));
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll N;
    cin >> N;
    ll A[N];
    typedef pair<ll, ll> pll;
    pll B[N];

    unordered_set<ll> US;
    unordered_map<ll, ll> UM1;
    unordered_map<ll, ll> UM2;

    for(ll i = 0; i < N; i++){
        ll t;
        cin >> t;
        A[i] = t;
     //   US.insert(t);
        UM1.emplace(t,0);
        UM2.emplace(t,0);
    }
    ll CountFromBegin[N];
    ll CountFromEnd[N];
    for(ll i = 0; i < N; ++i){
        CountFromBegin[i] = ++UM1[A[i]];
    }
    for(ll i = N-1; i >= 0; --i){
        CountFromEnd[i] = ++UM2[A[i]];
    }
    copied::init(CountFromEnd, N);
    ll result = 0;
    for(ll i = 0; i < N-1; ++i){
        result += copied::respond_query(i+1, N-1, CountFromBegin[i]);
    }
    cout << result << endl;
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<iomanip>
#include<stack>
#include<map>
#include<set>
#define debug(x) cerr<<#x<<"="<<x<<endl
#define INF 0x7f7f7f7f
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
inline int init()
{
    int now=0,ju=1;char c;bool flag=false;
    while(1)
    {
        c=getchar();
        if(c=='-')ju=-1;
        else if(c>='0'&&c<='9')
        {
            now=now*10+c-'0';
            flag=true;
        }
        else if(flag)return now*ju;
    }
}
inline long long llinit()
{
    long long now=0,ju=1;char c;bool flag=false;
    while(1)
    {
        c=getchar();
        if(c=='-')ju=-1;
        else if(c>='0'&&c<='9')
        {
            now=now*10+c-'0';
            flag=true;
        }
        else if(flag)return now*ju;
    }
}
int x1,x2,y1,y2;
int x3,x4,y3,y4;
int main()
{
	int d;
	x1=init();y1=init();x2=init();y2=init();
	if(x1==x2&&y1==y2)
	{
		printf("-1\n");
		return 0;
	}
	if(x1>x2&&y1>y2)
	{
		swap(x1,x2);swap(y1,y2);
	}
	if(x1==x2||y1==y2)
	{
		if(x1==x2)d=abs(y1-y2),x3=x1+d,x4=x2+d,y3=y1,y4=y2;
		if(y1==y2)d=abs(x1-x2),y3=y1+d,y4=y2+d,x3=x1,x4=x2;
	}
	else if(abs(y1-y2)!=abs(x1-x2))
	{
		printf("-1\n");
		return 0;
	}
	else
	{
		x3=x1;y3=y2,x4=x2,y4=y1;
	}
	printf("%d %d %d %d\n",x3,y3,x4,y4);
	return 0;
}
/*
srO xudyh davidlee1999WTK linkct1999 zlser Orz
*/


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
	int x1,y1,x2,y2;
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	if(x1!=x2&&y1!=y2)
	{
	  if(x1-x2==y1-y2) printf("%d %d %d %d\n",x2,y1,x1,y2);else puts("-1");
	  return 0;
	}
	if(x1==x2) printf("%d %d %d %d",x1+abs(y1-y2),y1,x1+abs(y1-y2),y2);
	else printf("%d %d %d %d",x1,y1+abs(x1-x2),x2,y2+abs(x1-x2));
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
	int x1,y1,x2,y2;
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	if(x1!=x2&&y1!=y2)
	{
	  if(abs(x1-x2)==abs(y1-y2)) printf("%d %d %d %d\n",x2,y1,x1,y2);else puts("-1");
	  return 0;
	}
	if(x1==x2) printf("%d %d %d %d",x1+abs(y1-y2),y1,x1+abs(y1-y2),y2);
	else printf("%d %d %d %d",x1,y1+abs(x1-x2),x2,y2+abs(x1-x2));
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int x, y, x2, y2;

int main()
{
	ios::sync_with_stdio(false);
	cin >> x >> y >> x2 >> y2;
	if (x == x2)
	{
		x += abs(y - y2);
		x2 += abs(y - y2);
		cout << x << " " << y << " " << x2 << " " << y2 << endl;
	}
	else if (y == y2)
	{
		y += abs(x - x2);
		y2 += abs(x - x2);
		cout << x << " " << y << " " << x2 << " " << y2 << endl;
	}
	else if (abs(x - x2) != abs(y - y2))
		cout << -1 << endl;
	else
	{
		swap(x, x2);
		cout << x << " " << y << " " << x2 << " " << y2 << endl;
	}
	return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll res=0,mod;
    vector<int> vec;
    vec.assign(4,0);
    for(int i =0;i<4;i++)
        cin>>vec[i];
    if(vec[0]==vec[2])
    {
        mod=abs(vec[1]-vec[3]);
        if(vec[0]+mod>=1000)
            mod*=-1;
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[2]+mod<<" "<<vec[3];
    }
    else if(vec[1]==vec[3])
    {
        mod=abs(vec[0]-vec[2]);
        if(vec[1]+mod>=1000)
            mod*=-1;
        cout<<vec[0]<<" "<<vec[1]+mod<<" "<<vec[2]<<" "<<vec[3]+mod;
    }
    else if((vec[0]==vec[1] && vec[2]==vec[3]) || abs(vec[1]-vec[3]) == abs(vec[0]-vec[2]))
    {
        mod=abs(vec[1]-vec[3]);
        if(vec[0]+mod>=1000)
            mod*=-1;
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[0]<<" "<<vec[1]+mod;
    }
    else
        cout<<-1;
    return 0;

}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll res=0,mod;
    vector<int> vec;
    vec.assign(4,0);
    for(int i =0;i<4;i++)
        cin>>vec[i];
    if(vec[0]==vec[2])
    {
        mod=abs(vec[1]-vec[3]);
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[2]+mod<<" "<<vec[3];
    }
    else if(vec[1]==vec[3])
    {
        mod=abs(vec[0]-vec[2]);
        cout<<vec[1]+mod<<" "<<vec[0]<<" "<<vec[3]+mod<<" "<<vec[2];
    }
    else if(abs(vec[1]-vec[3]) == abs(vec[0]-vec[2]))
    {
        mod=abs(vec[1]-vec[3]);
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[0]<<" "<<vec[1]+mod;
    }
    else
        cout<<-1;
    return 0;

}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll res=0,mod;
    vector<int> vec;
    vec.assign(4,0);
    for(int i =0;i<4;i++)
        cin>>vec[i];
    if(vec[0]==vec[2])
    {
        mod=abs(vec[1]-vec[3]);
        if(vec[0]+mod>=1000)
            mod*=-1;
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[2]+mod<<" "<<vec[3];
    }
    else if(vec[1]==vec[3])
    {
        mod=abs(vec[0]-vec[2]);
        if(vec[1]+mod>=1000)
            mod*=-1;
        cout<<vec[0]<<" "<<vec[1]+mod<<" "<<vec[2]<<" "<<vec[3]+mod;
    }
    else if((vec[0]==vec[1] && vec[2]==vec[3]) || abs(vec[1]-vec[3]) == abs(vec[0]-vec[2]))
    {
        mod=abs(vec[1]-vec[3]);
        if(vec[0]+mod>=1000)
            mod*=-1;
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[2]-mod<<" "<<vec[3];
    }
    else
        cout<<-1;
    return 0;

}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll res=0,mod;
    vector<int> vec;
    vec.assign(4,0);
    for(int i =0;i<4;i++)
        cin>>vec[i];
    if(vec[0]==vec[2])
    {
        mod=abs(vec[1]-vec[3]);
        if(vec[0]+mod>=1000)
            mod*=-1;
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[2]+mod<<" "<<vec[3];
    }
    else if(vec[1]==vec[3])
    {   if(vec[1]+mod>=1000)
            mod*=-1;
        mod=abs(vec[0]-vec[2]);
        cout<<vec[0]<<" "<<vec[1]+mod<<" "<<vec[2]<<" "<<vec[3]+mod;
    }
    else if(vec[0]==vec[1] && vec[2]==vec[3] && abs(vec[1]-vec[3]) == abs(vec[0]-vec[2]))
    {   if(vec[0]+mod>=1000)
            mod*=-1;
        mod=abs(vec[1]-vec[3]);
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[0]<<" "<<vec[1]+mod;
    }
    else
        cout<<-1;
    return 0;

}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll res=0,mod;
    vector<int> vec;
    vec.assign(4,0);
    for(int i =0;i<4;i++)
        cin>>vec[i];
    if(vec[0]==vec[2])
    {
        mod=abs(vec[1]-vec[3]);
        if(vec[0]+mod>=100)
            mod*=-1;
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[2]+mod<<" "<<vec[3];
    }
    else if(vec[1]==vec[3])
    {
        mod=abs(vec[0]-vec[2]);
        if(vec[1]+mod>=100)
            mod*=-1;
        cout<<vec[0]<<" "<<vec[1]+mod<<" "<<vec[2]<<" "<<vec[3]+mod;
    }
    else if(vec[0]==vec[1] && vec[2]==vec[3] && abs(vec[1]-vec[3]) == abs(vec[0]-vec[2]))
    {
        mod=abs(vec[1]-vec[3]);
        if(vec[0]+mod>=100)
            mod*=-1;
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[0]<<" "<<vec[1]+mod;
    }
    else
        cout<<-1;
    return 0;

}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll res=0,mod;
    vector<int> vec;
    vec.assign(4,0);
    for(int i =0;i<4;i++)
        cin>>vec[i];
    if(vec[0]==vec[2])
    {
        mod=abs(vec[1]-vec[3]);
        if(vec[0]+mod>=100)
            mod*=-1;
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[2]+mod<<" "<<vec[3];
    }
    else if(vec[1]==vec[3])
    {
        mod=abs(vec[0]-vec[2]);
        if(vec[1]+mod>=100)
            mod*=-1;
        cout<<vec[0]<<" "<<vec[1]+mod<<" "<<vec[2]<<" "<<vec[3]+mod;
    }
    else if((vec[0]==vec[1] && vec[2]==vec[3]) || abs(vec[1]-vec[3]) == abs(vec[0]-vec[2]))
    {
        mod=abs(vec[1]-vec[3]);
        if(vec[0]+mod>=100)
            mod*=-1;
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[0]<<" "<<vec[1]+mod;
    }
    else
        cout<<-1;
    return 0;

}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll res=0,mod;
    vector<int> vec;
    vec.assign(4,0);
    for(int i =0;i<4;i++)
        cin>>vec[i];
    if(vec[0]==vec[2])
    {
        mod=abs(vec[1]-vec[3]);
        if(vec[0]+mod>=1000)
            mod*=-1;
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[2]+mod<<" "<<vec[3];
    }
    else if(vec[1]==vec[3])
    {
        mod=abs(vec[0]-vec[2]);
        if(vec[1]+mod>=1000)
            mod*=-1;
        cout<<vec[0]<<" "<<vec[1]+mod<<" "<<vec[2]<<" "<<vec[3]+mod;
    }
    else if(vec[0]==vec[1] && vec[2]==vec[3] && abs(vec[1]-vec[3]) == abs(vec[0]-vec[2]))
    {
        mod=abs(vec[1]-vec[3]);
        if(vec[0]+mod>=1000)
            mod*=-1;
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[0]<<" "<<vec[1]+mod;
    }
    else
        cout<<-1;
    return 0;

}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll res=0,mod;
    vector<int> vec;
    vec.assign(4,0);
    for(int i =0;i<4;i++)
        cin>>vec[i];
    if(vec[0]==vec[2])
    {
        mod=abs(vec[1]-vec[3]);
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[2]+mod<<" "<<vec[3];
    }
    else if(vec[1]==vec[3])
    {
        mod=abs(vec[0]-vec[2]);
        cout<<vec[0]<<" "<<vec[1]+mod<<" "<<vec[2]<<" "<<vec[3]+mod;
    }
    else if(vec[0]==vec[1] && vec[2]==vec[3] && abs(vec[1]-vec[3]) == abs(vec[0]-vec[2]))
    {
        mod=abs(vec[1]-vec[3]);
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[0]<<" "<<vec[1]+mod;
    }
    else
        cout<<-1;
    return 0;

}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll res=0,mod;
    vector<int> vec;
    vec.assign(4,0);
    for(int i =0;i<4;i++)
        cin>>vec[i];
    if(vec[0]==vec[2])
    {
        mod=abs(vec[1]-vec[3]);
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[2]+mod<<" "<<vec[3];
    }
    else if(vec[1]==vec[3])
    {
        mod=abs(vec[0]-vec[2]);
        cout<<vec[1]+mod<<" "<<vec[0]<<" "<<vec[3]+mod<<" "<<vec[2];
    }
    else if(vec[0]==vec[1] && vec[2]==vec[3] && abs(vec[1]-vec[3]) == abs(vec[0]-vec[2]))
    {
        mod=abs(vec[1]-vec[3]);
        cout<<vec[0]+mod<<" "<<vec[1]<<" "<<vec[0]<<" "<<vec[1]+mod;
    }
    else
        cout<<-1;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main()
{cin>>a>>b>>c>>d;
if(abs(a-c)==abs(b-d))
    cout<<a<<" "<<d<<" "<<c<<" "<<b;
else if(a==c)cout<<a+b-d<<" "<<b<<" "<<a+b-d<<" "<<d;
else if(b==d)cout<<a<<" "<<b+a-c<<" "<<c<<" "<<d+a-c;
else cout<<-1;}


#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    int coordinates[4],i,o[4],x,y;
    for(i=0;i<4;i++)
    {
        cin >> coordinates[i];
    }
    if(coordinates[0]==coordinates[2] || coordinates[1]==coordinates[3])
    {
        if(coordinates[0]==coordinates[2])
        {
            x=coordinates[3]-coordinates[1]+coordinates[0];
            o[0]=x;
            o[1]=coordinates[1];
            o[3]=o[1];
            o[3]=coordinates[3];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }
        }
        if(coordinates[1]==coordinates[3])
        {
            y=coordinates[2]-coordinates[0]+coordinates[1];
            o[0]=coordinates[0];
            o[1]=y;
            o[3]=coordinates[3];
            o[3]=o[1];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }
        }
    }
    if(coordinates[0]!=coordinates[2] && coordinates[1]!=coordinates[3])
    {
        if(abs(coordinates[3]-coordinates[1])!=abs(coordinates[0]-coordinates[2]))
        {
            cout << "-1";
        }
        else
        {
            o[0]=coordinates[0];
            o[1]=coordinates[3];
            o[2]=coordinates[2];
            o[3]=coordinates[1];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }

        }

    }

    return 0;
}


#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    int coordinates[4],i,o[4],x,y;
    for(i=0;i<4;i++)
    {
        cin >> coordinates[i];
    }
    if(coordinates[0]==coordinates[2] && coordinates[1]!=coordinates[3])
    {
        x=coordinates[3]-coordinates[1]+coordinates[0];
        o[0]=x;
        o[2]=x;
        o[1]=coordinates[3];
        o[3]=coordinates[1];
        for(i=0;i<4;i++)
        {
            cout << o[i] << " ";
        }
    }
    if(coordinates[0]!=coordinates[2] && coordinates[1]==coordinates[3])
    {
        y=coordinates[2]-coordinates[0]+coordinates[1];
        o[1]=y;
        o[3]=y;
        o[0]=coordinates[0];
        o[2]=coordinates[2];
        for(i=0;i<4;i++)
        {
            cout << o[i] << " ";
        }
    }
    if(coordinates[0]!=coordinates[2] && coordinates[1]!=coordinates[3])
    {
        if(coordinates[0]==coordinates[1] && coordinates[2]==coordinates[3])
        {
            o[0]=coordinates[0];
            o[1]=coordinates[2];
            o[2]=o[1];
            o[3]=o[0];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }
        }
        else
    {
        o[0]=coordinates[0];
        o[1]=coordinates[3];
        o[2]=coordinates[2];
        o[3]=coordinates[1];
        for(i=0;i<4;i++)
        {
            cout << o[i] << " ";
        }
    }

    }
    if(abs(coordinates[0]-coordinates[2])!=abs(coordinates[1]-coordinates[3]))
    {
        cout << "-1";
    }

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int coordinates[4],i,o[4],x,y;
    for(i=0;i<4;i++)
    {
        cin >> coordinates[i];
    }
    if(coordinates[0]==coordinates[2] && coordinates[1]!=coordinates[3])
    {
        x=coordinates[3]-coordinates[1]+coordinates[0];
        o[0]=x;
        o[2]=x;
        o[1]=coordinates[3];
        o[3]=coordinates[1];
        for(i=0;i<4;i++)
        {
            cout << o[i] << " ";
        }
    }
    if(coordinates[0]!=coordinates[2] && coordinates[1]==coordinates[3])
    {
        y=coordinates[2]-coordinates[0]+coordinates[1];
        o[1]=y;
        o[3]=y;
        o[0]=coordinates[0];
        o[2]=coordinates[2];
        for(i=0;i<4;i++)
        {
            cout << o[i] << " ";
        }
    }
    if(coordinates[0]!=coordinates[2] && coordinates[1]!=coordinates[3])
    {
        if(coordinates[0]==coordinates[1] && coordinates[2]==coordinates[3])
        {
            o[0]=coordinates[0];
            o[1]=coordinates[2];
            o[2]=o[1];
            o[3]=o[0];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }
        }
        else
        {
            cout << "-1";
        }
    }

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int coordinates[4],i,o[4],x,y;
    for(i=0;i<4;i++)
    {
        cin >> coordinates[i];
    }
    if(coordinates[0]==coordinates[2] && coordinates[1]!=coordinates[3])
    {
        x=coordinates[3]-coordinates[1]+coordinates[0];
        o[0]=x;
        o[2]=x;
        o[1]=coordinates[3];
        o[3]=coordinates[1];
        for(i=0;i<4;i++)
        {
            cout << o[i] << " ";
        }
    }
    if(coordinates[0]!=coordinates[2] && coordinates[1]==coordinates[3])
    {
        y=coordinates[2]-coordinates[0]+coordinates[1];
        o[1]=y;
        o[3]=y;
        o[0]=coordinates[0];
        o[2]=coordinates[2];
        for(i=0;i<4;i++)
        {
            cout << o[i] << " ";
        }
    }
    if(coordinates[0]!=coordinates[2] && coordinates[1]!=coordinates[3])
    {
        if(coordinates[0]==coordinates[1] && coordinates[2]==coordinates[3])
        {
            o[0]=coordinates[0];
            o[1]=coordinates[1];
            o[2]=o[1];
            o[3]=o[0];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }
        }
        else
        {
            cout << "-1";
        }
    }

    return 0;
}


#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    int coordinates[4],i,o[4],x,y;
    for(i=0;i<4;i++)
    {
        cin >> coordinates[i];
    }
    if(coordinates[0]==coordinates[2] || coordinates[1]==coordinates[3])
    {
        if(coordinates[0]==coordinates[2])
        {
            x=coordinates[3]-coordinates[1]+coordinates[0];
            o[0]=x;
            o[1]=coordinates[1];
            o[3]=o[1];
            o[4]=coordinates[3];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }
        }
        if(coordinates[1]==coordinates[3])
        {
            y=coordinates[2]-coordinates[0]+coordinates[1];
            o[0]=coordinates[0];
            o[1]=y;
            o[3]=coordinates[3];
            o[3]=o[1];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }
        }
    }
    if(coordinates[0]!=coordinates[2] && coordinates[1]!=coordinates[3])
    {
        if(abs(coordinates[3]-coordinates[1])!=abs(coordinates[0]-coordinates[2]))
        {
            cout << "-1";
        }
        else
        {
            o[0]=coordinates[0];
            o[1]=coordinates[3];
            o[2]=coordinates[2];
            o[3]=coordinates[1];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }

        }

    }

    return 0;
}


#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    int coordinates[4],i,o[4],x,y;
    for(i=0;i<4;i++)
    {
        cin >> coordinates[i];
    }
    if(coordinates[0]==coordinates[2] || coordinates[1]==coordinates[3])
    {
        if(coordinates[0]==coordinates[2])
        {
            x=coordinates[3]-coordinates[1]+coordinates[0];
            o[0]=x;
            o[1]=coordinates[1];
            o[2]=o[0];
            o[3]=coordinates[3];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }
        }
        if(coordinates[1]==coordinates[3])
        {
            y=coordinates[2]-coordinates[0]+coordinates[1];
            o[0]=coordinates[0];
            o[1]=y;
            o[2]=coordinates[2];
            o[3]=o[1];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }
        }
    }
    if(coordinates[0]!=coordinates[2] && coordinates[1]!=coordinates[3])
    {
        if(abs(coordinates[3]-coordinates[1])!=abs(coordinates[0]-coordinates[2]))
        {
            cout << "-1";
        }
        else
        {
            o[0]=coordinates[0];
            o[1]=coordinates[3];
            o[2]=coordinates[2];
            o[3]=coordinates[1];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }

        }

    }

    return 0;
}


#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    int coordinates[4],i,o[4],x,y;
    for(i=0;i<4;i++)
    {
        cin >> coordinates[i];
    }
    if(coordinates[0]==coordinates[2] || coordinates[1]==coordinates[3])
    {
        if(coordinates[0]==coordinates[2])
        {
            x=coordinates[3]-coordinates[1]+coordinates[0];
            o[0]=x;
            o[1]=coordinates[1];
            o[2]=o[0];
            o[3]=coordinates[3];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }
        }
        if(coordinates[1]==coordinates[3])
        {
            y=coordinates[2]-coordinates[0]+coordinates[1];
            o[0]=coordinates[0];
            o[1]=y;
            o[3]=coordinates[3];
            o[3]=o[1];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }
        }
    }
    if(coordinates[0]!=coordinates[2] && coordinates[1]!=coordinates[3])
    {
        if(abs(coordinates[3]-coordinates[1])!=abs(coordinates[0]-coordinates[2]))
        {
            cout << "-1";
        }
        else
        {
            o[0]=coordinates[0];
            o[1]=coordinates[3];
            o[2]=coordinates[2];
            o[3]=coordinates[1];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }

        }

    }

    return 0;
}


#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    int coordinates[4],i,o[4],x,y;
    for(i=0;i<4;i++)
    {
        cin >> coordinates[i];
    }
    if(coordinates[0]==coordinates[2] && coordinates[1]!=coordinates[3])
    {
        x=coordinates[3]-coordinates[1]+coordinates[0];
        o[0]=x;
        o[2]=x;
        o[1]=coordinates[3];
        o[3]=coordinates[1];
        for(i=0;i<4;i++)
        {
            cout << o[i] << " ";
        }
    }
    if(coordinates[0]!=coordinates[2] && coordinates[1]==coordinates[3])
    {
        y=coordinates[2]-coordinates[0]+coordinates[1];
        o[1]=y;
        o[3]=y;
        o[0]=coordinates[0];
        o[2]=coordinates[2];
        for(i=0;i<4;i++)
        {
            cout << o[i] << " ";
        }
    }
    if(coordinates[0]!=coordinates[2] && coordinates[1]!=coordinates[3])
    {
        if(coordinates[0]==coordinates[1] && coordinates[2]==coordinates[3])
        {
            o[0]=coordinates[0];
            o[1]=coordinates[2];
            o[2]=o[1];
            o[3]=o[0];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }
        }

    if(abs(coordinates[0]-coordinates[2])!=abs(coordinates[1]-coordinates[3]))
    {
        cout << "-1";
    }
        else
    {
        o[0]=coordinates[0];
        o[1]=coordinates[3];
        o[2]=coordinates[2];
        o[3]=coordinates[1];
        for(i=0;i<4;i++)
        {
            cout << o[i] << " ";
        }
    }

    }

    return 0;
}


#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    int coordinates[4],i,o[4],x,y;
    for(i=0;i<4;i++)
    {
        cin >> coordinates[i];
    }
    if(coordinates[0]==coordinates[2] && coordinates[1]!=coordinates[3])
    {
        x=coordinates[3]-coordinates[1]+coordinates[0];
        o[0]=x;
        o[2]=x;
        o[1]=coordinates[3];
        o[3]=coordinates[1];
        for(i=0;i<4;i++)
        {
            cout << o[i] << " ";
        }
    }
    if(coordinates[0]!=coordinates[2] && coordinates[1]==coordinates[3])
    {
        y=coordinates[2]-coordinates[0]+coordinates[1];
        o[1]=y;
        o[3]=y;
        o[0]=coordinates[0];
        o[2]=coordinates[2];
        for(i=0;i<4;i++)
        {
            cout << o[i] << " ";
        }
    }
    if(coordinates[0]!=coordinates[2] && coordinates[1]!=coordinates[3])
    {
        if(coordinates[0]==coordinates[1] && coordinates[2]==coordinates[3])
        {
            o[0]=coordinates[0];
            o[1]=coordinates[2];
            o[2]=o[1];
            o[3]=o[0];
            for(i=0;i<4;i++)
            {
                cout << o[i] << " ";
            }
        }

    }
    if(abs(coordinates[0]-coordinates[2])!=abs(coordinates[1]-coordinates[3]))
    {
        cout << "-1";
    }
    else
    {
        o[0]=coordinates[0];
        o[1]=coordinates[3];
        o[2]=coordinates[2];
        o[3]=coordinates[1];
        for(i=0;i<4;i++)
        {
            cout << o[i] << " ";
        }
    }

    return 0;
}


#include <iostream>
#include <set>
#include <math.h>
#include <cmath>

using namespace std;

int main(){

    int x1, x2, y1, y2;
     cin >> x1 >> y1 >> x2 >> y2;
    set <int> s;
    s.insert(x1);
    s.insert(x2);
    s.insert(y1);
    s.insert(y2);

    if (s.size() != 2){
        cout << "-1";
    }
    else{
        int x3, y3, x4, y4;
        if (x1 == x2){
            x3 = abs(y2-y1);
            x4 = abs(y2-y1);
            y3 = y1;
            y4 = y2;

        }
        else if (y1 == y2){

            x3 = x1;
            x4 = x2;
            y3 = abs(x2 - x1);
            y4 = abs(x2 - x1);

        }
        else{
            x3 = x1;
            y3 = y2;
            x4 = y3;
            y4 = x3;

        }

        cout << x3 << " " << y3 << " " << x4 << " " << y4;

    }

    return 0;
}


#include <iostream>
#include <set>
#include <math.h>
#include <cmath>

using namespace std;

int main(){

    int x1, x2, y1, y2;
     cin >> x1 >> y1 >> x2 >> y2;
    set <int> s;
    s.insert(abs(x1));
    s.insert(abs(x2));
    s.insert(abs(y1));
    s.insert(abs(y2));

    if (s.size() != 2){
        cout << "-1";
    }
    else{
        int x3, y3, x4, y4;
        if (x1 == x2){
            x3 = abs(y2-y1);
            x4 = abs(y2-y1);
            y3 = y1;
            y4 = y2;

        }
        else if (y1 == y2){

            x3 = x1;
            x4 = x2;
            y3 = abs(x2 - x1);
            y4 = abs(x2 - x1);

        }
        else{
            x3 = x1;
            y3 = y2;
            x4 = y3;
            y4 = x3;

        }

        cout << x3 << " " << y3 << " " << x4 << " " << y4;

    }

    return 0;
}


#include <iostream>
#include <set>
#include <math.h>
#include <cmath>

using namespace std;

int main(){

    int x1, x2, y1, y2;
     cin >> x1 >> y1 >> x2 >> y2;
    set <int> s;
    s.insert(abs(x1));
    s.insert(abs(x2));
    s.insert(abs(y1));
    s.insert(abs(y2));

    if (s.size() > 2){
        cout << "-1";
    }
    else{
        int x3, y3, x4, y4;
        if (x1 == x2){
            x3 = abs(y2-y1);
            x4 = abs(y2-y1);
            y3 = y1;
            y4 = y2;

        }
        else if (y1 == y2){

            x3 = x1;
            x4 = x2;
            y3 = abs(x2 - x1);
            y4 = abs(x2 - x1);

        }
        else{
            x3 = x1;
            y3 = y2;
            x4 = y3;
            y4 = x3;

        }

        cout << x3 << " " << y3 << " " << x4 << " " << y4;

    }

    return 0;
}


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{int x1,x2,y1,y2,d,i,temp;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
d = sqrt( pow(x2-x1,2) + pow(y2-y1,2));
if(x1==x2)
x1=x2=x1+d;
if(y1==y2)
{
 if((d-y2)<= y2)
 y1=y2=y2-d;
 else
 y1=y2=y2+d;
}
else
{
    temp=y1;
    y1=y2;
    y2=temp;
}
if(abs(y2-y1)!=abs(x1-x2) && abs(x1-x2)>0 && abs(y1-y2)>0 )
printf("-1");
else
printf("%d %d %d %d",x1,y1,x2,y2);
return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
int res[maxn];
int fxxk;
struct Q{
  int l, r;
  int idx;
  bool operator < (const Q& rhs) const {
    if(l/fxxk == rhs.l/fxxk) return r < rhs.r;
    return l/fxxk < rhs.l/fxxk;
  }
} query[maxn];
int cnt[maxn] = {0};
int tot;
int n;

//int pos[maxn];
void move(int& cur, int dir, int flag){
  if(flag == 1) { // add
    int num = a[cur + dir];
    if(num > n) {cur += dir; return;}

    if(cnt[num] == num) tot--;
    cnt[num] += flag;
    if(cnt[num] == num) tot++;
  }
  else { // delete
    int num = a[cur];
    if(num > n) {cur += dir; return;}

    if(cnt[num] == num) tot--;
    cnt[num] += flag;
    if(cnt[num] == num) tot++;
  }
  cur+=dir;
}
int main(void){
  int m; scanf("%d %d", &n, &m);
  for(int i = 0; i < n; i++){
    scanf("%d", a + i);
  }
  fxxk = (int)sqrt(n-1);
  for(int i = 0; i < m; i++){
    scanf("%d %d", &query[i].l, &query[i].r); query[i].idx = i;
    query[i].r--; query[i].l--;
  }
  sort(query, query + m);

  int lcur =0, rcur = 0;
  tot = 0;
  for(int i = 0; i < m; i++){
    if(i == 0) {
      lcur = query[i].l;
      rcur = query[i].l-1;
    }
    if(lcur == query[i].l) ;
    else if(lcur < query[i].l){
      while(lcur < query[i].l) { // delete to query[i].l
        move(lcur, +1, -1); // delete
      }
    }
    else { // add to query[i].l
      while(lcur > query[i].l) {
        move(lcur, -1, +1);
      }
    }

    if(query[i].r == rcur);
    else if(query[i].r > rcur){// add to query[i].r

      while(rcur < query[i].r) move(rcur, 1, 1);
    }
    else{ // delete to query[i].r
      while(query[i].r < rcur) move(rcur, -1, -1);
    }

    res[query[i].idx] = tot;
  }

  for(int i = 0; i < m; i++) printf("%d\n", res[i]);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
int res[maxn];
struct Q{
  int l, r;
  int idx;
  bool operator < (const Q& rhs) const {
    if(l == rhs.l) return r < rhs.r;
    return l < rhs.l;
  }
} query[maxn];
map<int,int> cnt;
set<int> st;
void move(int& cur, int dir, int flag){
  if(flag == 1) { // add
    int num = a[cur + dir];
    cnt[num]++;

    int tmpcnt = cnt[num];
    if(tmpcnt == num) {
      st.insert(num);
    }
    cur+=dir;
  }
  else { // delete
    int num = a[cur];
    int tmpcnt = cnt[num];
    if(tmpcnt == num) {
      st.erase(st.find(num));
    }
    cnt[num]--;
    cur+=dir;
  }
}
int main(void){
  int n, m; scanf("%d %d", &n, &m);
  for(int i = 0; i < n; i++){
    scanf("%d", a + i);
  }
  for(int i = 0; i < m; i++){
    scanf("%d %d", &query[i].l, &query[i].r); query[i].idx = i;
    query[i].r--; query[i].l--;
  }
  sort(query, query + m);

  int lcur =0, rcur = 0;

  for(int i = 0; i < m; i++){
    //printf("query %d %d\n", query[i].l, query[i].r);
    if(i == 0) {
      lcur = query[i].l;
      rcur = query[i].l-1;
    }
    //printf("lcur = %d rcur = %d\n", lcur, rcur);
    while(lcur < query[i].l) { // delete to query[i].l
      move(lcur, 1, 0); // delete
    }
    // right has two situations

    if(query[i].r == rcur);
    else if(query[i].r > rcur){
      //printf("rcur = %d , add to %d\n", rcur, query[i].r);
      // add to query[i].r
      while(rcur < query[i].r) move(rcur, 1, 1);
    }
    else{ // delete to query[i].r
      //printf("rcur = %d, delete to %d\n", rcur, query[i].r);
      while(query[i].r < rcur) move(rcur, -1, 0);
    }
    //printf("lcur = %d rcur = %d\n", lcur, rcur);
    //printf("%d\n", (int)st.size());
    res[query[i].idx] = (int)st.size();
  }
  for(int i = 0; i < m; i++) printf("%d\n", res[i]);
  return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define fst first
#define sec second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ms(a,x) memset(a,x,sizeof(a))
typedef long long LL;
#define pi pair < int ,int >
#define MP make_pair

using namespace std;
const double eps = 1E-8;
const int dx4[4]={1,0,0,-1};
const int dy4[4]={0,-1,1,0};
const int inf = 0x3f3f3f3f;
const int N=1E5+7;

int n,m;
int a[N];
int pos[N];
int sum;
int ans[N];
int cnt[N];

struct node
{
    int l,r;
    int id;

    bool operator<(node b)const
    {
        if (pos[l]==pos[b.l]) return r<b.r;
        return pos[l]<pos[b.l];
    }
}q[N];

void update( int x,int d)
{

    if (a[x]>100000) return;
    if (cnt[a[x]]==a[x]) sum--;
    cnt[a[x]]+=d;
    if (cnt[a[x]]==a[x]) sum++;

  //  cout<<"x:"<<x<<" d:"<<d<<" sum:"<<sum<<endl;

}
int main()
{
        #ifndef  ONLINE_JUDGE
        freopen("code/in.txt","r",stdin);
  #endif

        cin>>n>>m;
        ms(pos,-1);
        ms(cnt,0);
        int siz = int(sqrt(n));
        for ( int i = 1 ; i <= n ; i++)
        {
            scanf("%d",&a[i]);
            pos[i] = (i-1)/siz;
        }

        for ( int i = 1 ;i  <= m ; i++)
        {
            scanf("%d %d",&q[i].l,&q[i].r);
            q[i].id = i ;
        }
        sort(q+1,q+m+1);

//        for ( int i = 1 ;i  <= m ; i++) cout<<q[i].l<<" "<<q[i].r<<endl;
        int pl = 1;
        int pr = 0;
        int id,l,r;
         sum = 0 ; //不小心又定义了个局部变量2333
        for ( int i = 1 ; i <= m ; i++)
        {
            id = q[i].id;
            l = q[i].l;
            r = q[i].r;

            if (r<pr)
            {
                for ( int j = r+1 ; j <= pr ; j++) update(j,-1);
            }
            else
            {
                for ( int j = pr +1 ; j <= r ; j++) update(j,1);
            }

            pr = r;

        //   cout<<"sum1:"<<sum<<endl;

            if (l<pl)
            {
                for ( int j = l ; j <= pl-1 ; j++) update(j,1);
            }
            else
            {
                for ( int j = pl ; j <= l-1 ; j++) update(j,-1);
            }

            pl = l;
//            cout<<"sum2:"<<sum<<endl;
            ans[id] = sum;

        //    cout<<endl;
        }

        for ( int i = 1 ; i <= m ;i ++) printf("%d\n",ans[i]);

  #ifndef ONLINE_JUDGE
  fclose(stdin);
  #endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;

struct que
{
	int l;
	int r;
	int ind;
};

int p=320,arr[100100],sol=0,sl[100300],n,m,cnt[100100];
que q[100100];

bool comp(que a,que b)
{
	if(a.l/p==b.l/p)
	return (a.r<b.r);
	return (a.l/p<b.l/p);
}

void insR(int x)
{
	if(x>n)return;
	cnt[x]++;
	if(cnt[x]==x)
	sol++;
}
void delR(int x)
{
	if(x>=n)return ;
	if(cnt[x]==x)
	sol--;
	cnt[x]--;
}

int main()
{
	/*
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	*/
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	scanf("%d",&arr[i]);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].ind=i;
	}
	sort(q+1,q+m+1,comp);
	int l=q[1].l,r=q[1].l-1;
	for(int i=1;i<=m;i++)
	{
		if(r<q[i].r){
			for(int j=r+1;j<=q[i].r;j++){
				insR(arr[j]);
			}
			r=q[i].r;
		}
		if(q[i].l<l){
			for(int j=q[i].l;j<l;j++){
				insR(arr[j]);
			}
			l=q[i].l;
		}

		if(l<q[i].l){
			for(int j=l;j<q[i].l;j++){
				delR(arr[j]);
			}
			l=q[i].l;
		}
		if(q[i].r<r){
			for(int j=q[i].r+1;j<=r;j++){
				delR(arr[j]);
			}
			r=q[i].r;
		}
		sl[q[i].ind]=sol;
	}
	for(int i=1;i<=m;i++)
	cout<<sl[i]<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;

struct que
{
	int l;
	int r;
	int ind;
};

int p=320,arr[100100],sol=0,sl[100300],n,m,cnt[100100];
que q[100100];

bool comp(que a,que b)
{
	if(a.l/p==b.l/p)
	return (a.r<b.r);
	return (a.l/p<b.l/p);
}

void add( int x, int v ) {
	if ( x>n ) return;
	if ( x && cnt[x]==x ) sol--;
	cnt[x]+=v;
	if ( x && cnt[x]==x ) sol++;
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	#endif
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	scanf("%d",&arr[i]);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].ind=i;
	}
	sort(q+1,q+m+1,comp);
	int l=0,r=0;
	for ( int i=1; i<=m; i++ ) {
		while ( l<q[i].l ) add(arr[l++],-1);
		while ( l>q[i].l ) add(arr[--l],+1);
		while ( r<q[i].r ) add(arr[++r],+1);
		while ( r>q[i].r ) add(arr[r--],-1);
		sl[q[i].ind]=sol;
	}
	for(int i=1;i<=m;i++)
	cout<<sl[i]<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;

struct que
{
	int l;
	int r;
	int ind;
};

int p=320,arr[100100],sol=0,sl[100300],n,m,cnt[100100];
que q[100100];

bool comp(que a,que b)
{
	if(a.l/p==b.l/p)
	return (a.r<b.r);
	return (a.l/p<b.l/p);
}

void insR(int x)
{
	if(x>n)return;
	cnt[x]++;
	if(cnt[x]==x)
	sol++;
}
void delR(int x)
{
	if(x>n)return ;
	if(cnt[x]==x)
	sol--;
	cnt[x]--;
}

int main()
{
	/*
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	*/
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	scanf("%d",&arr[i]);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].ind=i;
	}
	sort(q+1,q+m+1,comp);
	int l=q[1].l,r=q[1].l-1;
	for(int i=1;i<=m;i++)
	{
		if(r<q[i].r){
			for(int j=r+1;j<=q[i].r;j++){
				insR(arr[j]);
			}
			r=q[i].r;
		}
		if(q[i].l<l){
			for(int j=q[i].l;j<l;j++){
				insR(arr[j]);
			}
			l=q[i].l;
		}

		if(l<q[i].l){
			for(int j=l;j<q[i].l;j++){
				delR(arr[j]);
			}
			l=q[i].l;
		}
		if(q[i].r<r){
			for(int j=q[i].r+1;j<=r;j++){
				delR(arr[j]);
			}
			r=q[i].r;
		}
		sl[q[i].ind]=sol;
	}
	for(int i=1;i<=m;i++)
	cout<<sl[i]<<"\n";
	return 0;
}


 #include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;

struct que
{
	int l;
	int r;
	int ind;
};

int p=320,arr[100100],sol=0,sl[100300],n,m,cnt[100100];
que q[100100];

bool comp(que a,que b)
{
	if(a.l/p==b.l/p)
	return (a.r<b.r);
	return (a.l/p<b.l/p);
}

void insR(int x)
{
	if(x>n)return;
	cnt[x]++;
	if(x && cnt[x]==x)
	sol++;
}
void delR(int x)
{
	if(x>n)return ;
	if(x && cnt[x]==x)
	sol--;
	cnt[x]--;
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	#endif
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	scanf("%d",&arr[i]);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].ind=i;
	}
	sort(q+1,q+m+1,comp);
	int l=q[1].l,r=q[1].l-1;
	for(int i=1;i<=m;i++)
	{
		if(r<q[i].r){
			for(int j=r+1;j<=q[i].r;j++){
				insR(arr[j]);
			}
			r=q[i].r;
		}
		if(q[i].l<l){
			for(int j=q[i].l;j<l;j++){
				insR(arr[j]);
			}
			l=q[i].l;
		}

		if(l<q[i].l){
			for(int j=l;j<q[i].l;j++){
				delR(arr[j]);
			}
			l=q[i].l;
		}
		if(q[i].r<r){
			for(int j=q[i].r+1;j<=r;j++){
				delR(arr[j]);
			}
			r=q[i].r;
		}
		sl[q[i].ind]=sol;
	}
	for(int i=1;i<=m;i++)
	cout<<sl[i]<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;

struct que
{
	int l;
	int r;
	int ind;
};

int p=320,arr[100100],sol=0,sl[100300],n,m,cnt[100100];
que q[100100];

bool comp(que a,que b)
{
	if(a.l/p==b.l/p)
	return (a.r<b.r);
	return (a.l/p<b.l/p);
}

void add( int x, int v ) {
	if ( x>=n ) return;
	if ( x && cnt[x]==x ) sol--;
	cnt[x]+=v;
	if ( x && cnt[x]==x ) sol++;
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	#endif
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	scanf("%d",&arr[i]);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].ind=i;
	}
	sort(q+1,q+m+1,comp);
	int l=0,r=0;
	for ( int i=1; i<=m; i++ ) {
		while ( l<q[i].l ) add(arr[l++],-1);
		while ( l>q[i].l ) add(arr[--l],+1);
		while ( r<q[i].r ) add(arr[++r],+1);
		while ( r>q[i].r ) add(arr[r--],-1);
		sl[q[i].ind]=sol;
	}
	for(int i=1;i<=m;i++)
	cout<<sl[i]<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;

struct que
{
	int l;
	int r;
	int ind;
};

int p=320,arr[100100],sol=0,sl[100300],n,m,cnt[100100];
que q[100100];

bool comp(que a,que b)
{
	if(a.l/p==b.l/p)
	return (a.r<b.r);
	return (a.l/p<b.l/p);
}

void add( int x, int v ) {
	if ( x>n ) return;
	if ( cnt[x]==x ) sol--;
	cnt[x]+=v;
	if (cnt[x]==x ) sol++;
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	#endif
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	scanf("%d",&arr[i]);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].ind=i;
	}
	sort(q+1,q+m+1,comp);
	int l=0,r=0;
	for ( int i=1; i<=m; i++ ) {
		while ( l<q[i].l ) add(arr[l++],-1);
		while ( l>q[i].l ) add(arr[--l],+1);
		while ( r<q[i].r ) add(arr[++r],+1);
		while ( r>q[i].r ) add(arr[r--],-1);
		sl[q[i].ind]=sol;
	}
	for(int i=1;i<=m;i++)
	cout<<sl[i]<<"\n";
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main()
{
  int n;
  int m;

  cin>>n>>m;

  int *a = new int[n+1];
  for(int i = 1;i != n+1;i++)
  {
     cin>>a[i];
  }

  for(int i = 0;i < m;i++)
  {

     int l;
     int r;
     int total = 0;
      cin>>l>>r;
     int max = r - l +1;
     int *b = new int[max];

     int q = 0;
     for(int i = l;i <= r;i++)
     {
        b[q] = a[i];
        q++;
     }

     sort(b,b+ max);

     for(int k = 0;k <= r - l;k++)
     {
       if(b[k] > r-l + 1 - k)
       break;
        int temp = upper_bound(b,b+max,b[k]) - lower_bound(b,b+max,b[k]);
        if(temp == b[k])
        total++;

        k = k + temp - 1;
     }
    printf("%d\n",total);
  }

  return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main()
{
  int n;
  int m;

  cin>>n>>m;

  int *a = new int[n+1];
  for(int i = 1;i != n+1;i++)
  {
     cin>>a[i];
  }

  for(int i = 0;i < m;i++)
  {

     int l;
     int r;
     int total = 0;
      cin>>l>>r;
     int max = r - l +1;
     int *b = new int[max];

     int q = 0;
     for(int i = l;i <= r;i++)
     {
        b[q] = a[i];
        q++;
     }

     sort(b,b+ max);

     for(int k = 0;k <= r - l;k++)
     {
        int temp = upper_bound(b,b+max,b[k]) - lower_bound(b,b+max,b[k]);
        if(temp == b[k])
        total++;

        k = k + temp - 1;
     }
    printf("%d\n",total);
  }

  return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main()
{
  int n;
  int m;

  cin>>n>>m;

  int *a = new int[n+1];
  for(int i = 1;i != n+1;i++)
  {
     cin>>a[i];
  }

  for(int i = 0;i < m;i++)
  {

     int l;
     int r;
     int total = 0;
      cin>>l>>r;
     int max = r - l +1;
     int *b = new int[max];

     int q = 0;
     for(int i = l;i <= r;i++)
     {
        b[q] = a[i];
        q++;
     }

     sort(b,b+ max);

     for(int k = 0;k <= r - l;k++)
     {
       if(b[k] > r - l + 1)
       continue;
        int temp = upper_bound(b,b+max,b[k]) - lower_bound(b,b+max,b[k]);
        if(temp == b[k])
        total++;

        k = k + temp - 1;
     }
    printf("%d\n",total);
  }

  return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
   int n,m;
   int l,r;
   int **a = new int*[450];

   for(int i = 0;i < 450;i++)
   a[i] = new int[100002];
   cin>>n;
   cin>>m;

   int *b = new int[n];
   int *c = new int[n];
   for(int i = 0;i < n;i++)
   {
     cin>>b[i];
     c[i] = b[i];
   }

   sort(c,c+n);

   int j = 0;
   int k = 1;
   for(int i = 0;i < n;i++)
   {
     int temp;
     temp = upper_bound(c,c+n,c[i]) - lower_bound(c,c+n,c[i]);

     if(temp >= c[i])
     {
       a[j][0] = c[i];
       j++;
     }

     i = i + temp - 1;
   }

   for(int p = 0;p < j;p++)
   {
     k = 1;
     a[p][k] = 0;
     k++;
     for(int q = 0; q < n; q++)
     {
       if(b[q] == a[p][0])
       {
         a[p][k] = a[p][k-1] + 1;
         k++;
       }
       else
       {
         a[p][k] = a[p][k-1];
         k++;
       }
     }
   }

   for(int i = 0;i < m;i++)
   {
      cin>>l>>r;

      int total = 0;
      for(int p = 0;p < j;p++)
      {
        if(a[p][r+1] - a[p][l]  == a[p][0])
        total++;
      }

      cout<<total<<endl;
   }

   return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main()
{
  int n;
  int m;

  cin>>n>>m;

  int *a = new int[n+1];
  for(int i = 1;i != n+1;i++)
  {
     cin>>a[i];
  }

  for(int i = 0;i < m;i++)
  {

     int l;
     int r;
     int total = 0;
      cin>>l>>r;
     int max = r - l +1;
     int *b = new int[max];

     int q = 0;
     for(int i = l;i <= r;i++)
     {
        b[q] = a[i];
        q++;
     }

     sort(b,b+ max);

     for(int k = 0;k <= r - l;k++)
     {
        int temp = upper_bound(b,b+max,b[k]) - lower_bound(b,b+max,b[k]);
        if(temp == b[k])
        total++;

        k = k + temp;
     }
    printf("%d\n",total);
  }

  return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
  int n;
  int m;

  cin>>n>>m;

  int *a = new int[n+1];
  for(int i = 1;i != n+1;i++)
  {
     cin>>a[i];
  }

  for(int i = 0;i < m;i++)
  {

     int l;
     int r;
     int total = 0;
      cin>>l>>r;
     int *b = new int[r-l+1];

     int q = 0;
     for(int i = l;i <= r;i++)
     {
        b[q] = a[i];
        q++;
     }

     sort(b,b+ r - l+1);

     for(int k = 0;k <= r - l;k++)
     {
        int temp = upper_bound(b,b+r - l+1,b[k]) - lower_bound(b,b+r - l+1,b[k]);
        if(temp == b[k])
        total++;

        k = k + temp;
     }
    cout<<total<<endl;
  }

  return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main()
{
  int n;
  int m;

  cin>>n>>m;

  int *a = new int[n+1];
  for(int i = 1;i != n+1;i++)
  {
     cin>>a[i];
  }

  for(int i = 0;i < m;i++)
  {

     int l;
     int r;
     int total = 0;
      cin>>l>>r;
     int *b = new int[r-l+1];

     int q = 0;
     for(int i = l;i <= r;i++)
     {
        b[q] = a[i];
        q++;
     }

     sort(b,b+ r - l+1);

     for(int k = 0;k <= r - l;k++)
     {
        int temp = upper_bound(b,b+r - l+1,b[k]) - lower_bound(b,b+r - l+1,b[k]);
        if(temp == b[k])
        total++;

        k = k + temp;
     }
    printf("%d\n",total);
  }

  return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
  int n;
  int m;

  cin>>n>>m;

  int *a = new int[n+1];
  for(int i = 1;i != n+1;i++)
  {
     cin>>a[i];
  }

  for(int i = 0;i < m;i++)
  {
     int *b = new int[n+1];
     int l;
     int r;
     int total = 0;

     cin>>l>>r;

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

     sort(b + l,b+r+1);

     for(int k = l;k <= r;k++)
     {
        int temp = upper_bound(b+l,b+r+1,b[k]) - lower_bound(b+l,b+r+1,b[k]);
        if(temp == b[k])
        total++;

        k = k + temp;
     }
    cout<<total<<endl;
  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef unsigned int uint;

int n,m;
int a[100011];
int cnt = 1;
map<int,int> mp;
int idxOf[100011];
struct query{
    int l,r,id;
};
query queryArr[100011];
bool comp(const query& a,const query& b){
    if(a.r < b.r)return 1;
    if(a.r == b.r)return a.l < b.l;
    return 0;
}
vector<vi> g;
int cur[100011]={0};

int dp[5 * 100011]={0};

void updateS(int i,int v,int idx=1,int b=0,int e=n-1){
    if(i>e || b>i)return ;
    if(b == e){
        dp[idx] = v;
        return;
    }
    int mid = (b+e)/2;
    updateS(i,v,idx*2,b,mid);
    updateS(i,v,idx*2+1,mid+1,e);
    dp[idx] = dp[idx*2] + dp[idx*2+1];
}

int queryS(int l,int r,int idx=1,int b=0,int e=n-1){
    if(b>=l && r>=e)return dp[idx];
    if(b>r || l>e)return 0;
    int mid = (b+e)/2;
    return queryS(l,r,idx*2,b,mid) + queryS(l,r,idx*2+1,mid+1,e);
}
int res[100011];
int main(){
    //freopen("in.txt","r",stdin);
    cin>>n>>m;
    g.resize(n+1);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        int t = mp[a[i]];
        if(t == 0){
            mp[a[i]] = cnt;
            t = cnt;
            cnt++;
        }
        idxOf[i] = t;
        g[t].push_back(i);
    }
    for(int i=0;i<m;i++){
        scanf("%d %d",&queryArr[i].l,&queryArr[i].r);
        queryArr[i].l--;
        queryArr[i].r--;
        queryArr[i].id = i;
    }
    sort(queryArr,queryArr+m,comp);

    int idx = 0;
    for(int i=0;i<n;i++){
        cur[idxOf[i]]++;
        int d = cur[idxOf[i]] - a[i];
        if(d >= 0){
            updateS(g[idxOf[i]][d],1);
            if(d != 0){
                updateS(g[idxOf[i]][d-1],-1);
            }
        }

        while(idx<m && queryArr[idx].r == i){
            res[queryArr[idx].id] = queryS(queryArr[idx].l,i);
            idx++;
        }
        if(idx == m)break;
    }
    for(int i=0;i<m;i++){
        printf("%d\n",res[i]);
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef unsigned int uint;

int n,m;
int a[100011];
int cnt = 1;
map<int,int> mp;
int idxOf[100011];
struct query{
    int l,r,id;
};
query queryArr[100011];
bool comp(const query& a,const query& b){
    if(a.r < b.r)return 1;
    if(a.r == b.r)return a.l < b.l;
    return 0;
}
vector<vi> g;
int cur[100011]={0};

int dp[5 * 100011]={0};

void updateS(int i,int v,int idx=1,int b=0,int e=n-1){
    if(i>e || b>i)return ;
    if(b == e){
        dp[idx] = v;
        return;
    }
    int mid = (b+e)/2;
    updateS(i,v,idx*2,b,mid);
    updateS(i,v,idx*2+1,mid+1,e);
    dp[idx] = dp[idx*2] + dp[idx*2+1];
}

int queryS(int l,int r,int idx=1,int b=0,int e=n-1){
    if(b>=l && r>=e)return dp[idx];
    if(b>r || l>e)return 0;
    int mid = (b+e)/2;
    return queryS(l,r,idx*2,b,mid) + queryS(l,r,idx*2+1,mid+1,e);
}
int res[100011];
int main(){
    //freopen("in.txt","r",stdin);
    cin>>n>>m;
    g.resize(n+1);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        int t = mp[a[i]];
        if(t == 0){
            mp[a[i]] = cnt;
            t = cnt;
            cnt++;
        }
        idxOf[i] = t;
        g[t].push_back(i);
    }
    for(int i=0;i<m;i++){
        scanf("%d %d",&queryArr[i].l,&queryArr[i].r);
        queryArr[i].l--;
        queryArr[i].r--;
        queryArr[i].id = i;
    }
    sort(queryArr,queryArr+m,comp);

    int idx = 0;
    for(int i=0;i<n;i++){
        cur[idxOf[i]]++;
        int d = cur[idxOf[i]] - a[i];
        if(d >= 0){
            updateS(g[idxOf[i]][d],1);
            if(d - 1 >= 0){
                updateS(g[idxOf[i]][d-1],-1);
                if(d - 2 >= 0){
                    updateS(g[idxOf[i]][d-2],0);
                }
            }
        }

        while(idx<m && queryArr[idx].r == i){
            res[queryArr[idx].id] = queryS(queryArr[idx].l,i);
            idx++;
        }
        if(idx == m)break;
    }
    for(int i=0;i<m;i++){
        printf("%d\n",res[i]);
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef unsigned int uint;

int n,m;
int a[100011];
int cnt = 1;
map<int,int> mp;
int idxOf[100011];
struct query{
    int l,r,id;
};
query queryArr[100011];
bool comp(query a,query b){
    return a.r < b.r;
}
vector<vi> g;
int cur[100011]={0};

int dp[5 * 100011]={0};

void updateS(int i,int v,int idx=1,int b=0,int e=n-1){
    if(i>e || b>i)return ;
    if(b == e){
        dp[idx] = v;
        return;
    }
    int mid = (b+e)/2;
    updateS(i,v,idx*2,b,mid);
    updateS(i,v,idx*2+1,mid+1,e);
    dp[idx] = dp[idx*2] + dp[idx*2+1];
}

int queryS(int l,int r,int idx=1,int b=0,int e=n-1){
    if(b>=l && r>=e)return dp[idx];
    if(b>r || l>e)return 0;
    int mid = (b+e)/2;
    return queryS(l,r,idx*2,b,mid) + queryS(l,r,idx*2+1,mid+1,e);
}
int res[100011];
int main(){
    //freopen("in.txt","r",stdin);
    cin>>n>>m;
    g.resize(n+1);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        int t = mp[a[i]];
        if(t == 0){
            t = mp[a[i]] = cnt++;
        }
        idxOf[i] = t;
        g[t].push_back(i);
    }
    for(int i=0;i<m;i++){
        scanf("%d %d",&queryArr[i].l,&queryArr[i].r);
        queryArr[i].l--;
        queryArr[i].r--;
        queryArr[i].id = i;
    }
    sort(queryArr,queryArr+m,comp);

    int idx = 0;
    for(int i=0;i<n;i++){
        cur[idxOf[i]]++;
        int d = cur[idxOf[i]] - a[i];
        if(d >= 0){
            updateS(g[idxOf[i]][d],1);
            if(d != 0){
                updateS(g[idxOf[i]][d-1],-1);
            }
        }

        while(idx<m && queryArr[idx].r == i){
            res[queryArr[idx].id] = queryS(queryArr[idx].l,i);
            idx++;
        }
        if(idx == m)break;
    }
    for(int i=0;i<m;i++){
        printf("%d\n",res[i]);
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef unsigned int uint;

int n,m;
int a[100011];
int cnt = 1;
map<int,int> mp;
int idxOf[100011];
struct query{
    int l,r,id;
};
query queryArr[100011];
bool comp(query a,query b){
    return a.r < b.r;
}
vector<vi> g;
int cur[100011];

int dp[4 * 100011];

void updateS(int i,int v,int idx=1,int b=0,int e=n-1){
    if(i>e || b>i)return ;
    if(b == e){
        dp[idx] = v;
        return;
    }
    int mid = (b+e)/2;
    updateS(i,v,idx*2,b,mid);
    updateS(i,v,idx*2+1,mid+1,e);
    dp[idx] = dp[idx*2] + dp[idx*2+1];
}

int queryS(int l,int r,int idx=1,int b=0,int e=n-1){
    if(b>=l && r>=e)return dp[idx];
    if(b>r || l>e)return 0;
    int mid = (b+e)/2;
    return queryS(l,r,idx*2,b,mid) + queryS(l,r,idx*2+1,mid+1,e);
}
int res[100011];
int main(){
    //freopen("in.txt","r",stdin);
    cin>>n>>m;
    g.resize(n+1);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        int t = mp[a[i]];
        if(t == 0){
            t = mp[a[i]] = cnt++;
        }
        idxOf[i] = t;
        g[t].push_back(i);
    }
    for(int i=0;i<m;i++){
        scanf("%d %d",&queryArr[i].l,&queryArr[i].r);
        queryArr[i].l--;
        queryArr[i].r--;
        queryArr[i].id = i;
    }
    sort(queryArr,queryArr+m,comp);

    int idx = 0;
    for(int i=0;i<n;i++){
        cur[idxOf[i]]++;
        int d = cur[idxOf[i]] - a[i];
        if(d >= 0){
            updateS(g[idxOf[i]][d],1);
            if(d != 0){
                updateS(g[idxOf[i]][d-1],-1);
            }
        }

        while(queryArr[idx].r == i){
            res[queryArr[idx].id] = queryS(queryArr[idx].l,i);
            idx++;
        }
    }
    for(int i=0;i<m;i++){
        printf("%d\n",res[i]);
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef unsigned int uint;

int n,m;
int a[100011];
int cnt = 1;
map<int,int> mp;
int idxOf[100011];
struct query{
    int l,r,id;
};
query queryArr[100011];
bool comp(query a,query b){
    return a.r < b.r;
}
vector<vi> g;
int cur[100011];

int dp[5 * 100011];

void updateS(int i,int v,int idx=1,int b=0,int e=n-1){
    if(i>e || b>i)return ;
    if(b == e){
        dp[idx] = v;
        return;
    }
    int mid = (b+e)/2;
    updateS(i,v,idx*2,b,mid);
    updateS(i,v,idx*2+1,mid+1,e);
    dp[idx] = dp[idx*2] + dp[idx*2+1];
}

int queryS(int l,int r,int idx=1,int b=0,int e=n-1){
    if(b>=l && r>=e)return dp[idx];
    if(b>r || l>e)return 0;
    int mid = (b+e)/2;
    return queryS(l,r,idx*2,b,mid) + queryS(l,r,idx*2+1,mid+1,e);
}
int res[100011];
int main(){
    //freopen("in.txt","r",stdin);
    cin>>n>>m;
    g.resize(n+1);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        int t = mp[a[i]];
        if(t == 0){
            t = mp[a[i]] = cnt++;
        }
        idxOf[i] = t;
        g[t].push_back(i);
    }
    for(int i=0;i<m;i++){
        scanf("%d %d",&queryArr[i].l,&queryArr[i].r);
        queryArr[i].l--;
        queryArr[i].r--;
        queryArr[i].id = i;
    }
    sort(queryArr,queryArr+m,comp);

    int idx = 0;
    for(int i=0;i<n;i++){
        cur[idxOf[i]]++;
        int d = cur[idxOf[i]] - a[i];
        if(d >= 0){
            updateS(g[idxOf[i]][d],1);
            if(d != 0){
                updateS(g[idxOf[i]][d-1],-1);
            }
        }

        while(idx<m && queryArr[idx].r == i){
            res[queryArr[idx].id] = queryS(queryArr[idx].l,i);
            idx++;
        }
        if(idx == m)break;
    }
    for(int i=0;i<m;i++){
        printf("%d\n",res[i]);
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef unsigned int uint;

int n,m;
int a[100011];
int cnt = 1;
map<int,int> mp;
int idxOf[100011];
struct query{
    int l,r,id;
};
query queryArr[100011];
bool comp(query a,query b){
    return a.r <= b.r;
}
vector<vi> g;
int cur[100011]={0};

int dp[5 * 100011]={0};

void updateS(int i,int v,int idx=1,int b=0,int e=n-1){
    if(i>e || b>i)return ;
    if(b == e){
        dp[idx] = v;
        return;
    }
    int mid = (b+e)/2;
    updateS(i,v,idx*2,b,mid);
    updateS(i,v,idx*2+1,mid+1,e);
    dp[idx] = dp[idx*2] + dp[idx*2+1];
}

int queryS(int l,int r,int idx=1,int b=0,int e=n-1){
    if(b>=l && r>=e)return dp[idx];
    if(b>r || l>e)return 0;
    int mid = (b+e)/2;
    return queryS(l,r,idx*2,b,mid) + queryS(l,r,idx*2+1,mid+1,e);
}
int res[100011];
int main(){
    //freopen("in.txt","r",stdin);
    cin>>n>>m;
    g.resize(n+1);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        int t = mp[a[i]];
        if(t == 0){
            mp[a[i]] = cnt;
            t = cnt;
            cnt++;
        }
        idxOf[i] = t;
        g[t].push_back(i);
    }
    for(int i=0;i<m;i++){
        scanf("%d %d",&queryArr[i].l,&queryArr[i].r);
        queryArr[i].l--;
        queryArr[i].r--;
        queryArr[i].id = i;
    }
    sort(queryArr,queryArr+m,comp);

    int idx = 0;
    for(int i=0;i<n;i++){
        cur[idxOf[i]]++;
        int d = cur[idxOf[i]] - a[i];
        if(d >= 0){
            updateS(g[idxOf[i]][d],1);
            if(d != 0){
                updateS(g[idxOf[i]][d-1],-1);
            }
        }

        while(idx<m && queryArr[idx].r == i){
            res[queryArr[idx].id] = queryS(queryArr[idx].l,i);
            idx++;
        }
        if(idx == m)break;
    }
    for(int i=0;i<m;i++){
        printf("%d\n",res[i]);
    }
}


#include<stdio.h>
#include<string.h>
char num[1000005][455];
int a[1000005];
int get()
{
    char cc;
    int ret=0;
    cc=getchar();
    while(cc<'0'||cc>'9')cc=getchar();
    while(cc>='0'&&cc<='9')
    {
        ret*=10;ret+=cc-'0';
        cc=getchar();
    }
    return ret;
}
int main()
{
    int i,j,n,qn,ans,l,r;
    while(scanf("%d%d",&n,&qn)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
          a[i]=get();
          for(j=1;j<=450;j++)
              num[i][j]=num[i-1][j]+(j==a[i]);
        }
        while(qn--)
        {
            ans=0;
            scanf("%d%d",&l,&r);
            for(i=1;i<=450;i++)
            if(num[r][i]-num[l-1][i]==i)
            ans++;
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
short num[100001][455],list[455],ap[100001];
int a[100001];
int get()
{
    char cc;
    int ret=0;
    cc=getchar();
    while(cc<'0'||cc>'9')cc=getchar();
    while(cc>='0'&&cc<='9')
    {
        ret*=10;ret+=cc-'0';
        cc=getchar();
    }
    return ret;
}
int main()
{
    int i,j,n,qn,ans,l,r,all;
    while(scanf("%d%d",&n,&qn)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
          a[i]=get();
          if(a[i]<=n)
          ap[a[i]]++;
        }
        all=0;
        for(i=1;i<=n;i++)
        if(ap[i]>=i)
            list[all++]=i;
            for(i=0;i<all;i++)
              for(j=1;j<=n;j++)
              num[j][i]=num[j-1][i]+(a[j]==list[i]);
        while(qn--)
        {
            ans=0;
            scanf("%d%d",&l,&r);
            for(i=0;i<all;i++)
            if(num[r][i]-num[l-1][i]==list[i])
            ans++;
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
char num[1000001][451];
int get()
{
    char cc;
    int ret=0;
    cc=getchar();
    while(cc<'0'||cc>'9')cc=getchar();
    while(cc>='0'&&cc<='9')
    {
        ret*=10;ret+=cc-'0';
        cc=getchar();
    }
    return ret;
}
int main()
{
    int i,j,n,qn,ans,l,r,x;
    while(scanf("%d%d",&n,&qn)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
          x=get();
          for(j=1;j<=450;j++)
              num[i][j]=num[i-1][j]+(j==x);
        }
        while(qn--)
        {
            ans=0;
            scanf("%d%d",&l,&r);
            for(i=1;i<=450;i++)
            if(num[r][i]-num[l-1][i]==i)
            ans++;
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int num[100001][455],list[455],ap[100001];
int a[100001];
int get()
{
    char cc;
    int ret=0;
    cc=getchar();
    while(cc<'0'||cc>'9')cc=getchar();
    while(cc>='0'&&cc<='9')
    {
        ret*=10;ret+=cc-'0';
        cc=getchar();
    }
    return ret;
}
int main()
{
    int i,j,n,qn,ans,l,r,all;
    while(scanf("%d%d",&n,&qn)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
          a[i]=get();
          if(a[i]<=n)
          ap[a[i]]++;
        }
        all=0;
        for(i=1;i<=n;i++)
        if(ap[i]>=i)
            list[all++]=i;
            for(i=0;i<all;i++)
              for(j=1;j<=n;j++)
              num[j][i]=num[j-1][i]+(a[j]==list[i]);
        while(qn--)
        {
            ans=0;
            scanf("%d%d",&l,&r);
            for(i=0;i<all;i++)
            if(num[r][i]-num[l-1][i]==list[i])
            ans++;
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int num[455],a[1000005];
int get()
{
    char cc;
    int ret=0;
    cc=getchar();
    while(cc<'0'||cc>'9')cc=getchar();
    while(cc>='0'&&cc<='9')
    {
        ret*=10;ret+=cc-'0';
        cc=getchar();
    }
    return ret;
}
int main()
{
    int i,n,qn,ans,l,r;
    while(scanf("%d%d",&n,&qn)!=EOF)
    {
        for(i=0;i<n;i++)
        a[i]=get();
        while(qn--)
        {
            memset(num,0,sizeof(num));ans=0;
            scanf("%d%d",&l,&r);l--;r--;
            for(i=l;i<=r;i++)
            if(a[i]<=450)
            num[a[i]]++;
            for(i=1;i<=450;i++)
            if(num[i]==i)
            ans++;
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
char num[100001][455];
int get()
{
    char cc;
    int ret=0;
    cc=getchar();
    while(cc<'0'||cc>'9')cc=getchar();
    while(cc>='0'&&cc<='9')
    {
        ret*=10;ret+=cc-'0';
        cc=getchar();
    }
    return ret;
}
int main()
{
    int i,j,n,qn,ans,l,r,x;
    while(scanf("%d%d",&n,&qn)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
          x=get();
          for(j=1;j<=455;j++)
              num[i][j]=num[i-1][j]+(j==x);
        }
        while(qn--)
        {
            ans=0;
            scanf("%d%d",&l,&r);
            for(i=1;i<=455;i++)
            if(num[r][i]-num[l-1][i]==i)
            ans++;
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
char num[100001][451];
int get()
{
    char cc;
    int ret=0;
    cc=getchar();
    while(cc<'0'||cc>'9')cc=getchar();
    while(cc>='0'&&cc<='9')
    {
        ret*=10;ret+=cc-'0';
        cc=getchar();
    }
    return ret;
}
int main()
{
    int i,j,n,qn,ans,l,r,x;
    while(scanf("%d%d",&n,&qn)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
          x=get();
          for(j=1;j<=450;j++)
              num[i][j]=num[i-1][j]+(j==x);
        }
        while(qn--)
        {
            ans=0;
            scanf("%d%d",&l,&r);
            for(i=1;i<=450;i++)
            if(num[r][i]-num[l-1][i]==i)
            ans++;
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
short num[100001][455];
int get()
{
    char cc;
    int ret=0;
    cc=getchar();
    while(cc<'0'||cc>'9')cc=getchar();
    while(cc>='0'&&cc<='9')
    {
        ret*=10;ret+=cc-'0';
        cc=getchar();
    }
    return ret;
}
int main()
{
    int i,j,n,qn,ans,l,r,x;
    while(scanf("%d%d",&n,&qn)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
          x=get();
          for(j=1;j<=455;j++)
              num[i][j]=num[i-1][j]+(j==x);
        }
        while(qn--)
        {
            ans=0;
            scanf("%d%d",&l,&r);
            for(i=1;i<=455;i++)
            if(num[r][i]-num[l-1][i]==i)
            ans++;
            printf("%d\n",ans);
        }
    }
    return 0;
}