Wonderful Fours
Time limit1sMemory limit128 MB
Given five digits, count unordered triples of distinct permutations (no leading zero) whose sum is a different valid permutation of the same digits.
- Level
Medium5 of 10
- Topics
- Brute force, Combinatorics, Math, Implementation
- Solved
- No attempts yet
Problem
Let us call a set of five decimal digits . (Note that a digit may appear more than once in this set.)
We say that a five-digit natural number is properly formed from if it is obtained by writing all of the digits of in a row in some order (using each of them exactly once) and it does not start with .
For example, if contains the digits , then and are properly formed from , while is not.
We call four five-digit natural numbers a wonderful four of if all of the following hold:
- is properly formed from .
- is properly formed from .
- is properly formed from .
- is properly formed from .
- are all different numbers.
Count how many different wonderful fours can be formed from the five digits of the set given in the input. (Reordering the numbers within a wonderful four does not create a new wonderful four.)
Input
A single line containing five decimal digits separated by spaces. Each digit is between and inclusive; together the five digits form the set .
Output
Print, on a single line, the number of different wonderful fours that can be formed from .