#include<bits/stdc++.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main() {
FAST
int n;cin>>n;
vector<pair<int,long long>> v(n);
for(int i=0;i<n;i++) {
long long x;cin>>x;
v[i].first=x;
v[i].second=i+1;
}
sort(v.begin(),v.end());
for(int i=0;i<n;i++) {cout<<v[i].first<<" "<<v[i].second<<endl;}
if(v[0].first==v[n-1].first) {cout<<0;return 0;}
long long l=v[0].second;long long r=v[n-1].second;
for(int i=0;i<n-1;i++) {
if(v[i].first==v[i+1].first) {l=v[i+1].second;}
else
break;
}
for(int i=n-1;i>0;i--) {
if(v[i].first==v[i-1].first){ r=v[i-1].second;}
else
break;
}
cout<<r-l;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBGQVNUIGlvczo6c3luY193aXRoX3N0ZGlvKDApOyBjaW4udGllKDApOyBjb3V0LnRpZSgwKTsKaW50IG1haW4oKSB7CiAgICBGQVNUCiAgaW50IG47Y2luPj5uOwogICAgdmVjdG9yPHBhaXI8aW50LGxvbmcgbG9uZz4+IHYobik7CiAgICBmb3IoaW50IGk9MDtpPG47aSsrKSB7CiAgICAgICAgbG9uZyBsb25nIHg7Y2luPj54OwogICAgICAgIHZbaV0uZmlyc3Q9eDsKICAgICAgICB2W2ldLnNlY29uZD1pKzE7CiAgICB9CiAgICBzb3J0KHYuYmVnaW4oKSx2LmVuZCgpKTsKICAgIGZvcihpbnQgaT0wO2k8bjtpKyspIHtjb3V0PDx2W2ldLmZpcnN0PDwiICI8PHZbaV0uc2Vjb25kPDxlbmRsO30KICAgIGlmKHZbMF0uZmlyc3Q9PXZbbi0xXS5maXJzdCkge2NvdXQ8PDA7cmV0dXJuIDA7fQogICAgbG9uZyBsb25nIGw9dlswXS5zZWNvbmQ7bG9uZyBsb25nIHI9dltuLTFdLnNlY29uZDsKICAgIGZvcihpbnQgaT0wO2k8bi0xO2krKykgewogICAgICAgICBpZih2W2ldLmZpcnN0PT12W2krMV0uZmlyc3QpIHtsPXZbaSsxXS5zZWNvbmQ7fQogICAgICAgIGVsc2UKICAgICAgICAgICBicmVhazsKICAgIH0KICAgIGZvcihpbnQgaT1uLTE7aT4wO2ktLSkgewogICAgICAgICBpZih2W2ldLmZpcnN0PT12W2ktMV0uZmlyc3QpeyByPXZbaS0xXS5zZWNvbmQ7fQogICAgICAgIGVsc2UKICAgICAgICAgICAgYnJlYWs7CiAgICB9CiAgICBjb3V0PDxyLWw7Cn0KCg==