#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int raboti=INT_MIN;
int ras=0;
int a;
int arr[100000];
for(int i=0; i<n; i++){
    cin>>arr[i];
}
for(int i=0; i<n; i++){
    if(arr[i]>arr[i-1] && arr[i]>arr[i+1]){

cout<<arr[i]<<" "<<i<<endl;
       ras++;
       if(ras==1){
        raboti=arr[i];
       }

    }


    if(ras==2){
        cout<<"raboti e "<<raboti<<endl;
a=arr[i]-raboti-1;
    cout<<endl<<"otg: "<<a;
       return 0;

    }

}


cout<<"0";

return 0;
}
