Skip to main content
Back to problems
Codeforces
Easy
Math
Number Theory
Greedy
Lucky Sum of Digits

Find the smallest positive integer whose digit sum is exactly nn and whose decimal representation uses only lucky digits.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Problem

Given an integer nn, construct the smallest positive integer whose digits are all lucky digits and whose sum of digits is exactly nn.

In this problem, lucky digits are treated as the digits 4 and 7.

If no such integer exists, output -1.

The answer should be the numerically smallest possible among all valid numbers.

Input Format

A single integer nn.

Output Format

Print the smallest valid lucky-digit number whose digit sum is nn, or -1 if it does not exist.

Constraints

Assume nn is a non-negative integer that fits in a standard 32-bit signed integer.

Examples
Sample cases returned by the problem API.

Example 1

Input

11

Output

47

Explanation

The digit sum is 4+7=114 + 7 = 11, and 47 is smaller than 74.

Example 2

Input

8

Output

44

Explanation

Two lucky digits sum to 8.

Show 1 more example

Example 3

Input

5

Output

-1

Explanation

No combination of digits 4 and 7 can produce a sum of 5.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.