I have a set of data that that tells me the on/off status of a component as a function of time. The data looks like this :

```
0    1
120  1
240  0
360  0
480  1
600  1
720  1
840  0
960  0
1080  0
1200  1
1320  1
1440  0
1560  0
1680  1
1800  0
1920  1

```

First column shows the time in second and the second column shows the status (1 is on, 0 is off).

I need to know the what is the 600 seconds with the most 1 in it. For example, 0-600 has 3\*120 s so 360 seconds where component is on. But 120-720 has 4 etc... This means that this is not only 0-600, 600-1200, it can by any 600 seconds. The hard thing is that this is a cycle, meaning that the worst hour could be from 1920 to 480 (Note that this cycle has 2040s meaning time 2040 is also time 0). The time steps are not always equal. In this case it is a constant 120s, but it could be a mix of 120s and 150s for example. 

The only thing I can think of is to scan the file from 0-600, check time is was on, 120-720, 240-840 etc... but it is very time consuming. Especially since I can have very big files.

The program is in Perl, but I only need the algorithm (if it exists). Do any of you has an idea on what would be the best approach?

Thank you