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 Rust (1.15.1) (judge verdict: Accepted)

const SIZE: usize = 600;
const C: usize = 8;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let mut dp: [[u64; C]; SIZE] = [[0; C]; SIZE];
    for i in 0..SIZE {
        dp[i][0] = 1;
    }
    for cur in 0..SIZE {
        for next in cur..SIZE {
            for cur_c in 0..(C - 1) {
                dp[next][cur_c + 1] += dp[cur][cur_c];
            }
        }
    }

    let mut k: u64 = sc.read();
    let mut ans = vec![0; SIZE];
    for i in (0..SIZE).rev() {
        ans[i] = k / dp[i][C - 1];
        k -= ans[i] * dp[i][C - 1];
    }

    let mut s = String::new();
    for i in 0..SIZE {
        s.push_str("FESTIVA");
        for _ in 0..ans[i] {
            s.push('L');
        }
    }
    assert!(s.len() <= 5000);
    println!("{}", s);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}