const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    // 读取第一行:整数 n
    const firstLine = await readline();
    // 读取第二行:进制序列(可能为空行,也可能包含多个整数)
    const secondLine = await readline();

    // 解析 n
    const n = parseInt(firstLine.trim());
    // 解析进制序列,过滤掉空字符串
    const b = secondLine
        ? secondLine
              .trim()
              .split(/\s+/)
              .filter((x) => x)
              .map(Number)
        : [];

    // 1. 确定符号位 s (0 或 1)
    const s = n < 0 ? 1 : 0;
    // 2. 取绝对值
    let q = Math.abs(n);

    // 存储所有数字(先放符号位)
    const digits = [s];

    // 3. 按进制序列依次分解
    for (let i = 0; i < b.length; i++) {
        const bi = b[i];
        const d = q % bi;
        digits.push(d);
        q = Math.floor(q / bi);
    }

    // 4. 数字映射为小写字母
    const S = digits
        .map((d) => String.fromCharCode("a".charCodeAt(0) + d))
        .join("");

    // 辅助函数:判断字符串是否为回文
    function isPalindrome(str) {
        let left = 0,
            right = str.length - 1;
        while (left < right) {
            if (str[left] !== str[right]) return false;
            left++;
            right--;
        }
        return true;
    }

    // 5. 如果 S 本身就是回文,直接输出加后缀
    if (isPalindrome(S)) {
        console.log(S + "(palindrome)");
        return;
    }

    // 6. 否则寻找最长回文子串(长度相同时取字典序最小)
    let best = ""; // 存储当前最优子串
    const len = S.length;

    // 枚举所有子串 [i, j] (闭区间)
    for (let i = 0; i < len; i++) {
        for (let j = i; j < len; j++) {
            // 取出子串
            const sub = S.substring(i, j + 1);
            // 检查是否为回文
            if (isPalindrome(sub)) {
                // 比较长度和字典序
                if (sub.length > best.length) {
                    best = sub;
                } else if (sub.length === best.length && sub < best) {
                    best = sub;
                }
            }
        }
    }

    // 输出结果
    console.log(best);
})();