Problem:
Score : 1000 points

Problem Statement

#nck {
width: 30px;
height: auto;
}

Welcome to CODE FESTIVAL 2016!
In order to celebrate this contest, find a string s that satisfies the following conditions:

The length of s is between 1 and 5000, inclusive.

s consists of uppercase letters.

s contains exactly K occurrences of the string "FESTIVAL" as a subsequence.
In other words, there are exactly K tuples of integers (i_0, i_1, ..., i_7) such that 0 ≤ i_0 < i_1 < ... < i_7 ≤ |s|-1 and s[i_0]='F', s[i_1]='E', ..., s[i_7]='L'.

It can be proved that under the given constraints, the solution always exists.
In case there are multiple possible solutions, you can output any.

Constraints

1 ≤ K ≤ 10^{18}

Input

The input is given from Standard Input in the following format:

K

Output

Print a string that satisfies the conditions.

Sample Input 1

7

Sample Output 1

FESSSSSSSTIVAL

Sample Input 2

256

Sample Output 2

FFEESSTTIIVVAALL

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

const vector<char> ch{'F', 'E', 'S', 'T', 'I', 'V', 'A'};

lint checker(string &s)
{
    vector<lint> dp(9);
    dp[0] = 1;
    for (auto c : s)
    {
        if (c == 'F') dp[1] += dp[0];
        if (c == 'E') dp[2] += dp[1];
        if (c == 'S') dp[3] += dp[2];
        if (c == 'T') dp[4] += dp[3];
        if (c == 'I') dp[5] += dp[4];
        if (c == 'V') dp[6] += dp[5];
        if (c == 'A') dp[7] += dp[6];
        if (c == 'L') dp[8] += dp[7];
    }
    return dp[8];
}

int main()
{
    lint K;
    cin >> K;
    string ret;
    vector<lint> digit(8);
    digit[0] = 1;
    int l = 0;
    REP(d, 60)
    {
        while (digit[l] == (1LL << (9 * l))) l++;

        if (!digit[1])
        {
            REP(i, 7) digit[i + 1] += digit[i], ret += ch[i];
        }
        else if (d < 8)
        {
            int i = 6;
            while (i > 0 and digit[i] != digit[i + 1]) i--;
            FOR(j, i, 7) digit[j + 1] += digit[j], ret += ch[j];
        }
        else
        {
            int t = digit[l] / digit[l - 1];
            // dbg(l);
            REP(_, t) digit[l] += digit[l - 1], ret += ch[l - 1];
            FOR(i, l, 7) digit[i + 1] += digit[i], ret += ch[i];
        }
        if (K & (1LL << d)) ret += 'L';
        // dbg(digit);
    }
    cout << ret << endl;
    // dbg(ret.length());
    // dbg(checker(ret));
}