You are given array a1,a2,…,an. Find the subsegment al,al+1,…,ar with maximum arithmetic mean 1r−l+1∑i=lrai (in floating-point numbers, i.e. without any rounding).
If there are many such subsegments find the longest one.
Input
The first line contains single integer nn (1≤n≤105) — length of the array a.
The second line contains nn integers a1,a2,…,an (0≤ai≤109) — the array a.
Output
Print the single integer — the length of the longest subsegment with maximum possible arithmetic mean.
Example
input
Copy
5 6 1 6 6 0
output
Copy
2
Note
The subsegment [3,4][3,4] is the longest among all subsegments with maximum arithmetic mean.
#include <bits/stdc++.h> using namespace std; long long a[100005]; int main() { int i,n,flag=0; cin>>n; for(i=1;i<=n;i++){ cin>>a[i]; if(a[i]>flag) flag=a[i]; } int sum=1,t=0; for(i=1;i<=n;i++){ if(a[i]==flag) { t++; if(t>sum) sum=t; } else t=0; } cout<<sum<<endl; return 0; }