#P3417. [POI 2005] BANK-Cash Dispenser
[POI 2005] BANK-Cash Dispenser
Description
The BBB (short for Byteotian Bit Bank) owns the largest network of cash dispensers in Byteotia. The clients of the BBB can withdraw money from cash dispensers using a cash card and a 4-digit PIN code. Recently, to increase client security, the BBB has installed a camera by each cash dispenser. The cameras transmit the recorded image to the BBB using radio signals. Unfortunately, these signals are being intercepted by a gang of computer thieves. The thieves try to discover the 4-digit PIN codes of BBB clients, whose cash cards they subsequently steal. Aware of this, BBB clients try to make redundant movements over the keyboard while entering the PIN. The camera cannot pick out the actual keystrokes; it only records the finger movements. Consequently, it is usually impossible to determine the PIN unambiguously. For instance, a client moving a finger over key 1 and then over key 5 could have entered the following PIN codes: 1111, 1115, 1155, 1555, 5555. Desperate thieves analyze the camera recordings, hoping to determine the client’s PIN or at least limit the number of possible codes based on multiple recordings of his transactions. Having accumulated sequences entered by a particular wealthy client of the BBB, they made you an "unnegotiable proposition".
Task: Write a program that:
- reads from standard input a description of the recorded sequences of finger movements performed while entering the PIN,
- determines the number of distinct 4-digit PIN codes the client can have (i.e., the number of 4-digit PIN codes that could have been entered while performing each of the given finger movement sequences),
- writes the result to standard output.
Input Format
The first line contains a single integer denoting the number of recorded scenes of entering the PIN by the client, . Each of the following lines describes one scene and consists of two positive integers separated by a single space. The first number, , denotes the length of the movement sequence, . The second is a -digit number whose consecutive digits denote consecutive keys over which the client moved a finger. The total length of all sequences does not exceed .
Output Format
Print a single positive integer: the number of possible PIN codes of the client.
2
3 123
3 234
5
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号