Send More Money

AtCoder
IDabc198_d
Time5000ms
Memory256MB
Difficulty
Given strings $S_1,S_2,S_3$ consisting of lowercase English letters, solve the alphametic $S_1+S_2=S_3$. Formally, determine whether there is a triple of **positive** integers $N_1, N_2, N_3$ satisfying all of the three conditions below, and find one such triple if it exists. Here, $N'_1, N'_2, N'_3$ are strings representing $N_1, N_2, N_3$ (without leading zeros) in base ten, respectively. * $N'_i$ and $S_i$ have the same number of characters. * $N_1+N_2=N_3$. * The $x$\-th character of $S_i$ and the $y$\-th character of $S_j$ is the same if and only if the $x$\-th character of $N'_i$ and the $y$\-th character of $N'_j$ are the same. ## Constraints * Each of $S_1$, $S_2$, $S_3$ is a string of length between $1$ and $10$ (inclusive) consisting of lowercase English letters. ## Input Input is given from Standard Input in the following format: $S_1$ $S_2$ $S_3$ [samples]
Samples
Input #1
a
b
c
Output #1
1
2
3

Outputs such as $(N_1, N_2, N_3) = (4,5,9)$ will also be accepted, but $(1,1,2)$ will not since it violates the third condition (both `a` and `b` correspond to `1`).
Input #2
x
x
y
Output #2
1
1
2

Outputs such as $(N_1, N_2, N_3) = (3,3,6)$ will also be accepted, but $(1,2,3)$ will not since it violates the third condition (both $1$ and $2$ correspond to `x`).
Input #3
p
q
p
Output #3
UNSOLVABLE
Input #4
abcd
efgh
ijkl
Output #4
UNSOLVABLE
Input #5
send
more
money
Output #5
9567
1085
10652
API Response (JSON)
{
  "problem": {
    "name": "Send More Money",
    "description": {
      "content": "Given strings $S_1,S_2,S_3$ consisting of lowercase English letters, solve the alphametic $S_1+S_2=S_3$. Formally, determine whether there is a triple of **positive** integers $N_1, N_2, N_3$ satisfyi",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 5000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc198_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Given strings $S_1,S_2,S_3$ consisting of lowercase English letters, solve the alphametic $S_1+S_2=S_3$.\nFormally, determine whether there is a triple of **positive** integers $N_1, N_2, N_3$ satisfyi...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments