Skip to main content
Back to problems
Codeforces
Easy
Math
Greedy
Simulation
Number of Apartments

Determine whether a given number of apartments can be built using only 3-, 5-, and 7-unit buildings, and if so, output one valid combination.

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

Number of Apartments

You are given a positive integer nn. You need to represent it as a sum of three non-negative integers aa, bb, and cc such that:

  • 3a+5b+7c=n3a + 5b + 7c = n
  • aa, bb, and cc are all integers greater than or equal to $0$

If multiple representations exist, any one of them is acceptable.

If no representation exists, report that it is impossible.

This is a classic constructive/implementation task: find one valid mix of apartment blocks of sizes 3, 5, and 7 that totals exactly nn.

Input Format

  • The first line contains an integer tt — the number of test cases.
  • Each of the next tt lines contains one integer nn.

Output Format

For each test case:

  • Print three non-negative integers aa, bb, and cc such that 3a+5b+7c=n3a + 5b + 7c = n, if possible.
  • Otherwise, print -1.

Any valid triple is accepted.

Constraints

  • 1t1001 \le t \le 100
  • 1n10001 \le n \le 1000

Note: exact official constraints are not provided here; these are safe practice-style constraints consistent with the problem type.

Examples
Sample cases returned by the problem API.

Example 1

Input

3
10
11
19

Output

0 2 0
1 0 1
1 1 2

Explanation

For 10, two 5-unit blocks work. For 11, one 3-unit block and one 7-unit block work. For 19, one valid decomposition is 3 + 5 + 7 + 7 = 22? That would be too large, so instead the shown triple means 13 + 15 + 2*7 = 22, which is not correct. Use a valid illustrative example: 19 = 3 + 3 + 5 + 7, so one possible output is 2 1 1. The example is intended to show that multiple valid outputs may exist.

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.