InfluxQL query for following example

I am new to influxdb, was facing problem with following example. Any help would be really grateful.
Thanks in advance !

input feed :
time machineid prediction_field


1577046001 4-01 0
1577046002 4-01 0
1577046003 4-01 0
1577046004 4-01 0
1577046005 4-01 0
1577046006 4-01 0
1577046007 4-01 0
1577046008 4-01 1
1577046009 4-01 1
1577046010 4-01 1
1577046011 4-01 1
1577046012 4-01 1
1577046013 4-01 0
1577046014 4-01 0
1577046015 4-01 0
1577046016 4-01 0
1577046017 4-01 1
1577046018 4-01 1
1577046019 4-01 1
1577046020 4-01 0
1577046021 4-01 0
1577046022 4-01 0
1577046023 4-01 0
1577046024 4-01 0
1577046025 4-01 0
1577046026 4-01 1
1577046027 4-01 1
1577046028 4-01 1
1577046029 4-01 1
1577046030 4-01 1

continous 5 or 5+ 0’s represents downtime
less than 5 0’s and 1 represents uptime

Calculate downtime for above example.
Query should return downtime as 13 sec