Digital Friends
Time limit2sMemory limit128 MB
Given three pairs of huge integers, classify each pair as friends, almost friends, or nothing based on digit-set equality achievable by at most one adjacent digit transfer operation.
- Level
Medium6 of 10
- Topics
- String, Brute force, Implementation
- Solved
- No attempts yet
Problem
Two positive integers are friends if the set of distinct digits appearing in each integer is the same. For example, 123 and 32331313323213 are friends because both use exactly the digits 1, 2, and 3; 123 and 22121221 are not friends because their digit sets differ.
When two integers are not friends, they are almost friends if applying the following operation at most once to exactly one of the two integers can make them friends.
Choose two adjacent digits a and b in one integer. You may either subtract 1 from a and add 1 to b, or add 1 to a and subtract 1 from b. After the operation, both changed values must still be single digits, and the resulting integer must not start with 0.
Given two integers x and y, determine their relationship.
Input
The input consists of three lines. Each line contains two positive integers x and y separated by a space.
Output
For each input line, print one result line in the same order. Print friends if the two integers are friends, almost friends if they are almost friends, and nothing otherwise.
Constraints
xandydo not start with0.