/* GCC */

#define maxN 1000000

#include <stdio.h>
#include <algorithm>

using namespace std;

int a[maxN], n;

int main()
{
    freopen("triangle.in", "r", stdin);
    freopen("triangle.out", "w", stdout);

    scanf("%d\n", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    scanf("\n");

    char c[4];
    scanf("%3s", c);

    bool findMax = c[1] == 'a';

    sort(a, a + n);

    if (findMax)
    {
        for (int i = n - 3; i >= 0; i--)
            if (a[i] + a[i + 1] > a[i + 2])
            {
                printf("%I64d\n", ((long long) a[i]) + a[i + 1] + a[i + 2]);
                return 0;
            }
    } else
    {
        long long curMin = 0;
        for (int i = 2; i < n; i++)
        {
            int index;
            for (index = 0; index < i - 1; index++)
                if (a[index] >= a[i] - a[i - 1] + 1)
                    break;
            if (index < i - 1)
            {
                long long curValue = ((long long) a[index]) + a[i - 1] + a[i];
                if (curMin == 0 || curValue < curMin)
                    curMin = curValue;
            }
        }

        if (curMin > 0)
        {
            printf("%I64d\n", curMin);
            return 0;
        }
    }

    printf("none\n");
    return 0;
}
