This page is still under construction.

Parts of this page are still being built. What you see may change.

Numbers

Interview

Time limit1sMemory limit1024 MB

Summary
Given three distinct digits and one of their six permutations, find that number's 1-based rank when all six permutations are sorted ascending.
Level

Easy2 of 10

Topics
Math, Sorting, Implementation, Combinatorics
Solved
No attempts yet

Problem

Jurgita studies digits and numbers. She picked three distinct digits from 11 to 99, formed every possible three-digit number using them, and sorted these numbers in increasing order. Because the three digits are all different, there are exactly 66 distinct three-digit numbers.

You are given a three-digit number xx built from the chosen digits. Determine the position of xx in the sequence sorted in increasing order.

Input

The first line contains the three digits aa, bb, cc chosen by Jurgita, separated by spaces. The second line contains the number xx formed from the chosen digits.

Output

Print the position of the given number xx in the sequence.

Constraints

  • 1≤a,b,c≤91 \le a, b, c \le 9; a≠ba \ne b; a≠ca \ne c; b≠cb \ne c

Examples3

  1. Example 1

    Input
    5 3 8
    835
    
    Expected output
    5
    
  2. Example 2

    Input
    1 2 3
    123
    
    Expected output
    1
    
  3. Example 3

    Input
    1 2 3
    321
    
    Expected output
    6