Problem:
 Score : 1000 points    Problem Statement  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 (Python):
from math import factorial as f
k=int(input())
a="" 
for i in range(511,-1,-1):
 v=f(7+i)//f(i)//f(7)
 a="FESTIVA"+("L"*(k//v))+a
 k%=v
print(a)

Solution (Python):
from math import factorial as f
k=int(input())
n=512
a="" 
for i in range(n-1,-1,-1):
 v=f(7+i)//f(i)//f(7)
 a="FESTIVA"+("L"*(k//v))+a
 k%=v
print(a)

Solution (Python):
import math
import sys
input = sys.stdin.readline

k = int(input())

n = 512
pattern = 0
a = []
for i in range(n):
    val = math.factorial(7 + i) // math.factorial(i) // math.factorial(7)
    a.append(val)
a.reverse()

cnt = 600 * 7 
ans = ["FESTIVA" for _ in range(n)]
for i, item in enumerate(a):
    ans[i] += ("L" * (k // item))
    k %= item
ans.reverse()
print("".join([str(item) for item in ans]))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools

N = int(read())

def test(S):
    f,e,s,t,i,v,a,l = 0,0,0,0,0,0,0,0
    for x in S:
        if x == 'F':
            f += 1
        elif x == 'E':
            e += f
        elif x == 'S':
            s += e
        elif x == 'T':
            t += s
        elif x == 'I':
            i += t
        elif x == 'V':
            v += i
        elif x == 'A':
            a += v
        elif x == 'L':
            l += a
    return l

test('FESSSSSSSTIVAL'),test('FFEESSTTIIVVAALL')

A = [x * 200 + 'FESTIVA' for x in [''] + list('FESTIVA')]
B = list(itertools.accumulate(A))


value = [test(word+'L') for word in B]

cnt = [0] * 8
rest = N
for n in range(7,-1,-1):
    q,r = divmod(rest,value[n])
    rest = r
    cnt[n] = q

answer = ''
for x,y in zip(A,cnt):
    answer += x + 'L' * y

print(answer)

Solution (Python):
mod = 10**18 + 3

def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%mod
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], mod -2, mod)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % mod
    return frac, fraci
frac, fraci = frac(1341)
def comb(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[b]*fraci[a-b]%mod

K = int(input())
seg = 2**7
OT = 'EESSTTIIVVAALL'

L = [0]*301
for i in range(300, -1, -1):
    ci = sum(comb(j+i, i)*2**j for j in range(8)) 
    L[i] = K//ci
    K %= ci
    

ans = 'F'*K + 'ESTIVAL'
for l in L:
    ans = l*'F' + OT + ans

print(ans)