ECOO '17 R3 P1 - Baker Brie

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 30.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
Author: Andrew Seidel

Baker Brie is holding a celebration for being in business for 13 years, and having opened its 130^{th} franchise. Baker Brie wants to congratulate franchises that have performed well throughout the years. Baker Brie also wants to congratulate everyone for performing well on certain days of the year!

Baker Brie wants to offer congratulations as follows:

  • If, in a single day, all franchises combined sell an amount of baked goods that is equivalent to a multiple of a baker's dozen (13), then all franchises will receive a bonus.
  • If an individual franchise, throughout its entire existence, has sold an amount of baked goods that is equivalent to a multiple of a baker's dozen (13), then that franchise will receive a bonus.

Input Specification

The input will contain 10 datasets.

On the first line of each dataset there will be the values F and D separated by a space where F (4 \le F \le 130) represents the number of franchises that Baker Brie has, and D (2 \le D \le 4\,745) represents the number of days of information.

On the next D lines, there will be F integers separated by spaces (each in the range 1 through 13\,000), such that the i^{th} integer on line j represents the number of baked goods sold by franchise i on day j.

Output Specification

You must determine, both for each day (across all franchises) and for each franchise (across all days), whether or not the number of baked goods sold is a multiple of 13. If it is, you need to track how many baker's dozens were sold. Report the total number of baker's dozens as a single integer on its own line.

Sample Input

4 5
4 3 2 4
3 3 2 1
8 2 4 1
2 2 4 3
9 3 2 3
4 2
4 4 4 1
1 1 3 4

Sample Output


Note: Only 2 cases are shown in this sample.

Explanation of Sample Output

In the first case, the first franchise sold a total of 26 baked goods (which is 2 baker's dozens), the second franchise sold a total of 13 baked goods (which is 1 baker's dozen), and finally, all franchises together sold 13 baked goods on the first day (which is 1 baker's dozen). This totals to 4 baker's dozens.

For the second dataset, no franchises made enough baked goods on their own, but there was a single baker's dozen created among them all on the first day. This totals to 1 baker's dozen.

Educational Computing Organization of Ontario - statements, test data and other materials can be found at


  • 3
    Bari_Sax  commented on May 17, 2017, 2:44 p.m. edit 3

    Is there a way to know how many test cases there are?

    Edit: NVM there are 10