with instructions as ( select case when line[1] = 'L' then -1 else 1 end as dir, cast(line[2:] as int) as amount, row_number() over () as id from read_csv('data/01.in', header = false) file (line) ), positions as ( select 50 + sum(dir * amount) over (order by id) as abs_pos from instructions ), clicks as ( select dir as click, row_number() over (order by id) as click_id from instructions, generate_series(1, amount) ), all_positions as ( select 50 + sum(click) over (order by click_id) as abs_pos from clicks ) select ( select count(*) from positions where abs_pos % 100 = 0 ) as p1, ( select count(*) from all_positions where abs_pos % 100 = 0 ) as p2;