ICPC SWERC 2017 J - Frosting on the Cake

View as PDF

Submit solution


Points: 7
Time limit: 2.0s
Memory limit: 1G

Problem type

Iskander the Baker is decorating a huge cake, covering the rectangular surface of the cake with frosting. For this purpose, he mixes frosting sugar with lemon juice and food coloring, in order to produce three kinds of frosting: yellow, pink, and white. These colors are identified by the numbers 0 for yellow, 1 for pink, and 2 for white.

To obtain a nice pattern, he partitions the cake surface into vertical stripes of width A_1, A_2, \dots, A_n centimeters, and horizontal stripes of height B_1, B_2, \dots, B_n centimeters, for some positive integer n. These stripes split the cake surface into n \times n rectangles. The intersection of vertical stripe i and horizontal stripe j has color number (i+j) \bmod 3 for all 1 \le i, j \le n. To prepare the frosting, Iskander wants to know the total surface in square centimeters to be colored for each of the three colors, and asks for your help.

Input Specification

The input consists of the following integers:

  • on the first line: the integer n,
  • on the second line: the values of A_1, \dots, A_n, n integers separated with single spaces,
  • on the third line: the values of B_1, \dots, B_n, n integers separated with single spaces.

Constraints

The input satisfies 3 \le n \le 100\,000 and 1 \le A_1, \dots, A_n, B_1, \dots, B_n \le 10\,000.

Output Specification

The output should consist of three integers separated with single spaces, representing the total area for each color 0, 1, and 2.

Sample Input 1

3
1 1 1
1 1 1

Sample Output 1

3 3 3

Sample Input 2

7
6 2 4 5 1 1 4
2 5 1 4 2 3 4

Sample Output 2

155 131 197

Comments

There are no comments at the moment.