# GitBook

``````#include<stdio.h>
int a[10200];
int b[3500];
int ma(int m) {
if(a[m]>=a[m+1]&&a[m]>=a[m+2])
return a[m];
if(a[m+1]>=a[m]&&a[m+1]>=a[m+2])
return a[m+1];
if(a[m+2]>=a[m+1]&&a[m+2]>=a[m])
return a[m+2];
}
int mi(int m) {
if(a[m]<=a[m+1]&&a[m]<=a[m+2])
return a[m];
if(a[m+1]<=a[m]&&a[m+1]<=a[m+2])
return a[m+1];
if(a[m+2]<=a[m+1]&&a[m+2]<=a[m])
return a[m+2];
}
int main() {
int n;
while(scanf("%d",&n)!=EOF) {
for(int i=0; i<n; i++)
scanf("%d",&a[i]);
int cnt=0;
for(int i=0; i<n; i+=3) {
if(cnt&1==1) {
b[++cnt]=mi(i);
} else {
b[++cnt]=ma(i);
}
}
int max=0;
for(int i=1; i<=cnt; i++) {
if(b[i]>max)
max=b[i];
}
printf("%d\n",max);
}
return 0;
}

``````

``````#include <cstdio>
#define Max(a,b,c) a>(b>c?b:c)?a:(b>c?b:c)
#define Min(a,b,c) a>(b>c?c:b)?(b>c?c:b):a
int main() {
int a[10005];
int n,i,j,h;
while(~scanf("%d",&n)) {
int max=1<<32;
for(i=0; i<n&&scanf("%d",&a[i]); i++) {}
for(i=0; i<n; i+=3) {
h=i%2==0?Max(a[i],a[i+1],a[i+2]):Min(a[i],a[i+1],a[i+2]);
max=h>max?h:max;
}
printf("%d\n",max);
}
return 0;
}
``````