Time limit
2s
Memory limit
128 MB
You are given a nonnegative integer N. Determine whether there are distinct nonnegative integers k_1, k_2, ..., k_M (M >= 1) such that
N = k_1! + k_2! + ... + k_M!.
Each integer may be used at most once. Since 0! and 1! are factorials of different integers, both may be used.
The first line contains the integer N.
Print YES if N can be represented as a sum of factorials of distinct integers. Otherwise, print NO.
0 <= N <= 1,000,000,000,000,000,000