/* GCC */

#define maxN 1000000

#include <stdio.h>

int a[maxN], n;

inline bool isTriangle(int a, int b, int c)
{
    return a + b > c && a + c > b && b + c > a;
}

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';

    long long ans = 0;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            for (int k = j + 1; k < n; k++)
                if (isTriangle(a[i], a[j], a[k]))
                {
                    long long cur = ((long long) a[i]) + a[j] + a[k];
                    if (ans == 0 || findMax && cur > ans || !findMax && cur < ans)
                        ans = cur;
                }

    if (ans == 0)
        printf("none\n");
    else
        printf("%I64d\n", ans);

    return 0;
}
