2066 - Trisum

Created by Óscar Dávalos Orozco
Added by ymondelo20 (2012-10-12)
Limits
Total Time: 10000 MS | Test Time: 2000 MS |Memory: 62 MB | Output: 64 MB | Size: 29 KB
Enabled languages
Available in

Description

To make Trisum numbers we have to follow the next steps:
The first step is to choose three numbers a0, b0, c0 and form a triangle with them (see the figure).

At each of the following steps, three numbers an = 3 (bn-1 + cn-1), bn = 3 (an-1 + cn-1) and cn = 3 (an-1 + bn-1) are inserted, an adjacent to an-1, bn adjacent to bn-1 and cn adjacent to cn-1.

Given n, a0, b0, and c0, can you calculate an, bn and cn?


To make Trisum numbers we have to follow the next steps:
The first step is to choose three numbers a0, b0, c0 and form a triangle with them (see the figure).

At each of the following steps, three numbers an = 3 (bn-1 + cn-1), bn = 3 (an-1 + cn-1) and cn = 3 (an-1 + bn-1) are inserted, an adjacent to an-1, bn adjacent to bn-1 and cn adjacent to cn-1.

Given n, a0, b0, and c0, can you calculate an, bn and cn?


To make Trisum numbers we have to follow the next steps:
The first step is to choose three numbers a0, b0, c0 and form a triangle with them (see the figure).

At each of the following steps, three numbers an = 3 (bn-1 + cn-1), bn = 3 (an-1 + cn-1) and cn = 3 (an-1 + bn-1) are inserted, an adjacent to an-1, bn adjacent to bn-1 and cn adjacent to cn-1.

Given n, a0, b0, and c0, can you calculate an, bn and cn?


Input specification

There will be a line with four integers: n (0 <= n <= 2^31-1), a0, b0, c0 (0 <= a0, b0, c0 < 1000).
There will be a line with four integers: n (0 <= n <= 2^31-1), a0, b0, c0 (0 <= a0, b0, c0 < 1000).
There will be a line with four integers: n (0 <= n <= 2^31-1), a0, b0, c0 (0 <= a0, b0, c0 < 1000).

Output specification

Three numbers an, bn and cn modulo 10007 (mod 10007), separated by a blank space.
Three numbers an, bn and cn modulo 10007 (mod 10007), separated by a blank space.
There will be a line with four integers: n (0 <= n <= 2^31-1), a0, b0, c0 (0 <= a0, b0, c0 < 1000).

Sample input

1 1 2 3

Sample output

15 12 9

Hint(s)

http://coj.uci.cu/contest/
http://coj.uci.cu/contest/
http://coj.uci.cu/contest/