using System;
public class Program
{
static int SecondGreatestInArray(int[] a){
int l = a.Length - 1;
int n = l/2;
int x = a[0];
int y = a[l];
//Console.WriteLine($"x={x}, y={y}");
for(int i = 1; i <= n; i++ ){
if(x < a[i]) x = a[i];
if(y < a[l-i]) y = a[l-i];
}
if(x<y) return x;
return y;
public static void Main()
int[] a = {-3,100,3,2,9,6,4,-3,4,-99,12,30};
int sg = SecondGreatestInArray(a);
Console.WriteLine(sg);