#include<stdio.h>
#include<stdlib.h>
struct Node{
    int data;
    struct Node* next;
};
struct Node* createNode(int data){
    struct Node* newNode=(struct Node*)malloc(sizeof(struct Node));
    newNode->data=data;
    newNode->next=NULL;
    return newNode;
}
void push(struct Node** top,int data){
    struct Node*newNode=createNode(data);
    newNode->next=*top;
    *top=newNode;
}
void findMinMax(struct Node*top,int* min,int* max){
    *min = *max=top->data;
    struct Node*temp=top;
    while (temp !=NULL){
        if(temp->data<*min)*min=temp->data;
        if(temp->data>*max)*max=temp->data;
        temp=temp->next;
    }
}
int main(){
    int k;
    if(scanf("%d",&k)!=1||k<4||k>12){
        printf("Invalid input\n");
        return 0;
    }
    int pulses[k];
    for(int i=0;i<k;i++){
        if(scanf("%d",&pulses[i])!=1||pulses[i]<1||pulses[i]>5000){
            printf("Inavlid input\n");
            return 0;
        }
    }
    struct Node* stack=NULL;
    int sum=0;
    for(int i=0;i<k;i++){
        if(pulses[i]>sum){
            push(&stack,pulses[i]);
            sum+=pulses[i];
        }
    }
    if(stack==NULL || stack->next==NULL){
        printf("0\n");
        return 0;
    }
    int min,max
}