Tuenti Programming
Challenge 2

Go to tuenti

  Home  Info  Questions  Stats       

Challenge 1: The cell phone keypad « Prev Next »

Completion time: min: 0:36 h
10 percentile: 2:01 h
90 percentile: 61:23 h
max: 202:24 h
Submit exec time: min: 0.39 s
10 percentile: 0.67 s
90 percentile: 3.05 s
max: 185.92 s
Test tries: min: 1
10 percentile: 1
90 percentile: 27
max: 247
# of completions:379

You are a new Tuenti mobile engineer, and your first task is to calculate how much time our users spend writing one message using a typical mobile phone keypad.

cell phone

We are only taking into account typists who use only one finger for typing. These are the mean times for these actions:

  • Move the finger one position up or down: 300 ms
  • Move the finger one position left or right: 200 ms
  • Move the finger one position in diagonal: 350 ms
  • Press a button one time: 100 ms

If they need to type two consecutive characters from the same button, they need to wait 500 ms after the first character. Otherwise, they are still rotating the previous character.

The number appears as the last character after pressing consecutively the same button (digit 5 needs four button presses). A space character is entered with the 1 button and only needs to be pressed once (digit 1 needs two button presses). The button in the lower right corner is the caps lock; it should be pressed one time to change all the next characters to upper case, and another time to change back to lowercase.

The user starts with his finger already placed on the 0 button and the caps lock is disabled (starts in lowercase mode).


The first line of the input gives the number of test cases C, and C test cases follow. Every test case is a line with the text that the user needs to type.


One line for each test case with the total time spent by the user typing the message.

Sample input

HI 20

Sample output