#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
struct Node{
    int data;
    struct Node* next;
};
int isEmpty(struct Node* top){
    if(top == NULL){
        return 1;
    }
    return 0;
}
struct Node* push(struct Node* top, int value){
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    if(newNode == NULL){
        printf("Stack overflow(malloc failed)!\n");
        exit(1);
    }
    newNode->data = value;
    newNode->next = top;
    return newNode;
}
int pop(struct Node** top_ptr){
    if(isEmpty(*top_ptr)){
        printf("Stack underflow!\n");
        return -1;
    }
    struct Node* temp = *top_ptr;
    int poppedValue = temp->data;
    *top_ptr = temp->next;
    free(temp);
    return poppedValue;
}
int main(){
    int K;
    int i;
    int current_pulse;
    long long total_accepted_strength = 0;
    struct Node* top = NULL;
    if(scanf("%d", &K) != 1){
        printf("Invalid input\n");
        return 1;
    }
    if(K<4 || K>12){
        printf("Invalid input\n");
        return 1;
    }
    for(i=0; i<K; i++){
      if(scanf("%d", &current_pulse) != 1){
        printf("Invalid input\n");
        return 1;
    }
    if(current_pulse<1 || current_pulse>5000){
        printf("Invalid input\n");
        return 1;
    }
    if(current_pulse > total_accepted_strength){
        top = push(top, current_pulse);
        total_accepted_strength += current_pulse;
    }
    }
    int min_stored = INT_MAX;
    int min_stored = INT_MIN;
    while(is)
}