{ Free Pascal }

var a: array of int64;
n, curMin, curValue, ind, lInd, rInd, mInd, i: longword;
problem: string;
findMax: boolean;

procedure sort(var a: array of int64);
var b, c: array of int64;
i, bi, ci: longword;
begin
    if length(a) <= 1 then
        exit;
    setlength(b, length(a) div 2);
    setlength(c, length(a) - length(b));
    for i := 0 to length(b) - 1 do
        b[i] := a[i];
    for i := 0 to length(c) - 1 do
        c[i] := a[length(b) + i];
    sort(b);
    sort(c);
    bi := 0;
    ci := 0;
    i := 0;
    while (bi < length(b)) and (ci < length(c)) do begin
        if b[bi] < c[ci] then begin
            a[i] := b[bi];
            inc(bi);
        end else begin
            a[i] := c[ci];
            inc(ci);
        end;
        inc(i);
    end;
    while i < length(a) do begin
        if bi < length(b) then begin
            a[i] := b[bi];
            inc(bi);
        end else begin
            a[i] := c[ci];
            inc(ci);
        end;
        inc(i);
    end;
end;

begin
    assign(input, 'triangle.in');
    reset(input);
    assign(output, 'triangle.out');
    rewrite(output);

    readln(n);
    setlength(a, n);
    for i := 0 to n - 1 do
        read(a[i]);
    readln;
    readln(problem);

    findMax := problem[2] = 'a';

    sort(a);

    if (findMax) then begin
        for i := n - 3 downto 0 do
            if a[i] + a[i + 1] > a[i + 2] then begin
                writeln(a[i] + a[i + 1] + a[i + 2]);
                exit;
            end;
    end else begin
        curMin := 0;
        for i := 2 to n - 1 do begin
            if (a[0] + a[i - 1] > a[i]) then
                ind := 0
            else if (a[i - 2] + a[i - 1] <= a[i]) then
                ind := i - 1
            else begin
                lInd := 0;
                rInd := i - 2;
                while rInd - lInd > 1 do begin
                    mInd := (lInd + rInd) div 2;
                    if (a[mInd] + a[i - 1] > a[i]) then
                        rInd := mInd
                    else
                        lInd := mInd;
                end;
                ind := rInd;
            end;
            if (ind < i - 1) then begin
                curValue := a[ind] + a[i - 1] + a[i];
                if (curMin = 0) or (curValue < curMin) then
                    curMin := curValue;
            end;
        end;

        if (curMin > 0) then begin
            writeln(curMin);
            exit;
        end;
    end;

    writeln('none');
end.
