Tetrahedral Number

AtCoder
IDabc335_b
Time2000ms
Memory256MB
Difficulty
You are given an integer $N$. Print all triples of non-negative integers $(x,y,z)$ such that $x+y+z\leq N$ in ascending lexicographical order. What is lexicographical order for non-negative integer triples?A triple of non-negative integers $(x,y,z)$ is said to be **lexicographically smaller** than $(x',y',z')$ if and only if one of the following holds: * $x < x'$; * $x=x'$ and $y< y'$; * $x=x'$ and $y=y'$ and $z< z'$. ## Constraints * $0 \leq N \leq 21$ * $N$ is an integer. ## Input The input is given from Standard Input in the following format: $N$ [samples]
Samples
Input #1
3
Output #1
0 0 0
0 0 1
0 0 2
0 0 3
0 1 0
0 1 1
0 1 2
0 2 0
0 2 1
0 3 0
1 0 0
1 0 1
1 0 2
1 1 0
1 1 1
1 2 0
2 0 0
2 0 1
2 1 0
3 0 0
Input #2
4
Output #2
0 0 0
0 0 1
0 0 2
0 0 3
0 0 4
0 1 0
0 1 1
0 1 2
0 1 3
0 2 0
0 2 1
0 2 2
0 3 0
0 3 1
0 4 0
1 0 0
1 0 1
1 0 2
1 0 3
1 1 0
1 1 1
1 1 2
1 2 0
1 2 1
1 3 0
2 0 0
2 0 1
2 0 2
2 1 0
2 1 1
2 2 0
3 0 0
3 0 1
3 1 0
4 0 0
API Response (JSON)
{
  "problem": {
    "name": "Tetrahedral Number",
    "description": {
      "content": "You are given an integer $N$. Print all triples of non-negative integers $(x,y,z)$ such that $x+y+z\\leq N$ in ascending lexicographical order. What is lexicographical order for non-negative integer tr",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc335_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given an integer $N$.\nPrint all triples of non-negative integers $(x,y,z)$ such that $x+y+z\\leq N$ in ascending lexicographical order.\nWhat is lexicographical order for non-negative integer tr...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments