Clock Card Rank

Time limit1sMemory limit128 MB

Problem

A cross-shaped card has one digit written at each of its four corners. Each digit is from 1 to 9, and the same digit may appear more than once.

If the four digits are read clockwise starting from different corners, four four-digit numbers can be made. The smallest of those four numbers is called the card's clock number. For digits 3, 2, 2, 7 in clockwise order, the possible numbers are 3227, 2273, 2732, and 7322, so the clock number is 2273.

Given a card, compute its clock number and determine its rank when all distinct clock numbers of possible cards are sorted in increasing order. Digit 0 never appears on a card, and cards that produce the same clock number are counted as one clock number. For instance, the only clock numbers smaller than 1122 are 1111 through 1119, so 1122 is the 10th clock number.

Input

The input consists of one line containing four digits written on the card's corners in clockwise order. Each digit is an integer from 1 to 9, and adjacent digits in the input are separated by one space.

Output

Print the rank of the input card's clock number among all distinct clock numbers.