#P4731. Bowling Statistics

    ID: 17975 Type: Default 1000ms 256MiB

Bowling Statistics

Bowling Statistics

Byteasar is a fan of both bowling and statistics. He has recorded several bowling games, but unfortunately some characters in his notes are blurry. Your task is to calculate the number of distinct full games that are consistent with his notes.

A bowling game consists of n frames. In a typical game n is 10. The first n-1 frames are simple frames and the final frame has a special format, so that the complete game is described by a sequence of 2n+1 characters.

Rules for Simple Frames

  • A strike is denoted by x-. In a strike, the player knocks down all 10 pins in the first shot, and the second character is fixed as '-' (as a placeholder).
  • A spare is denoted by A/ where A is a digit (0–9) representing the number of pins knocked down in the first shot (and the second shot knocks down the remaining pins to sum to 10).
  • An open frame (when less than 10 pins are knocked down in two shots) is denoted by AB where both A and B are digits and A+B < 10.

Rules for the Final Frame

The final (10th) frame is described by 3 characters and there are 7 possible valid configurations:

  1. Open final frame: AB- where A and B are digits with A+B < 10 (the third character is a filler '-').
  2. Spare in the first two shots: A/C where A is a digit, the second character is /, and the bonus (third) shot is either a digit (0–9) or a strike denoted by x.
  3. Strike in the first shot: The frame starts with x and the two bonus shots are determined as follows:
    • If the second shot is a strike (x), then the third shot can be either x or any digit (0–9).
    • If the second shot is a digit (0–9), then the third shot can be a digit provided the sum is less than 10, or it can be a spare (denoted by /), meaning that the two bonus shots sum exactly to 10.

Each game note is given as a string of length 2n+1 (for n=10, the string length is 21). Some characters in the string may be blurred (represented by a '?' character). A game is consistent with Byteasar's notes if, upon replacing every '?' with a valid character so that each frame is a valid frame according to the rules above, the resulting game string is a valid complete game.

Your task is to output the number of distinct complete game strings that match the given note pattern.

inputFormat

The input consists of a single line containing a string S of length 21 which represents the game note. Each character of S is either one of the valid characters (x, /, digits 0–9, or -) or a '?' indicating an unreadable (blurred) character.

outputFormat

Output a single integer – the number of distinct complete games that are consistent with the input notes.

sample

08x-7/2/x-x-23441/0/x
1