In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.
Byteotian company 0101010 produces toys for children. 0101010 is well known, and their toys are considered top quality. To their horror, the employees have noticed that the four most recent models of teddies: , , and have a latent defect: should we take three teddies which all have the same letter in their model designations, or all have the same digit in their model designations, and line them up next to one another, the teddies will suffer an irreparable damage.
We shall say teddies are safely lined up, if none of them will suffer damage due to the latent defect, i.e. no three consecutive teddies have the same letter in their model designations, nor the same digit.
Byteasar has a collection of teddies, in which there are only the feral models - he has grown up to play with teddies only just, you see. To make things worse, Byteasar plays with his teddies by lining them up! Fortunately, despite his young age, he is well aware of the danger. Thus he wonders, how many safe line-ups of teddies are possible at all. And that's where the problems start - he is unable to determine it all by himself... Be a good mate and write a programme to help him!
Write a programme which:
In the first and only line of the standard input there are four non-negative integers: , , , , separated by single spaces (). They denote the numbers of teddies, of models , , and , respectively. The total number of teddies will always be positive.
In the first and only line of the standard output your programme should write the number of safe line-ups of teddies, modulo .
For the input data:
0 1 2 1
the correct result is:
6
The 6 safe line-ups of teddies are: , , , , and finally .
Task author: Maciej Jaskowski.