Under construction

Still being built. Things may change

Anton and the School Schedule

Time limit1sMemory limit512 MB

Summary
Given a Monday-to-Friday lesson grid and a sleep-deficit threshold k, find the week and day when Anton first oversleeps his first lesson, or report -1.
Level

Easy3 of 10

Topics
Simulation, Implementation
Solved
No attempts yet

Statement

Anton goes to school from Monday to Friday. Lessons last for 4545 minutes and breaks last for 1515 minutes. The first lesson starts at 7 a.m. and the last lesson finishes at 3:45 p.m. Each lesson starts at the beginning of an hour.

Anton wants to stay healthy, so he wants to sleep for 88 hours every day. He does not always manage this, because lessons can start at 7 a.m. To average 8 hours of sleep a day, he can sleep more on Saturday and Sunday, when he does not go to school. Anton cannot sleep more than 1010 hours a day, because otherwise he feels that he has slept too much and the rest of the day feels bad. Anton gets up at least one hour before the first lesson to eat breakfast and get to school. Anton falls asleep at midnight every day.

Anton wants to attend all of his lessons. However, if on a day when he has to get up for school he has a lack of sleep of at least 55 hours, he will oversleep his first lesson. Anton starts going to school on Monday. At first he has no lack of sleep, because he rested during the summer.

Help Anton find the day when he will oversleep his first lesson.

Input

The first line contains kk, the number of lack of sleep hours that Anton needs to oversleep his first lesson. (1≤k≤10001 \le k \le 1000)

The next five lines each contain 9 characters, each 0 or 1, describing Anton's school schedule from Monday to Friday. On Saturday and Sunday Anton does not go to school. If on day ii Anton has lesson jj, then the jj-th character of the ii-th row is 1, otherwise it is 0.

Output

If Anton never has a lack of sleep and never oversleeps his lessons, output -1. Otherwise, output two integers: the week number and the day on which Anton will oversleep his first lesson.

Hint

Every day Anton's lessons run from 7:00 a.m. to 1:45 p.m., so every day he gets up at 6 a.m. and accumulates 2 hours of lack of sleep. By the weekend Anton has accumulated 10 hours of lack of sleep, but he can make up 4 of them by sleeping 10 hours on Saturday and Sunday. Starting the second week with 6 hours of lack of sleep, Anton oversleeps his first lesson on Wednesday.

Examples1

  1. Example 1

    Input
    11
    111111100
    111111100
    111111100
    111111100
    111111100
    
    Expected output
    2 3