program problem implicit none integer :: floor = 0 integer :: steps = 0 character(len=:), allocatable :: input integer :: input_file_size, unit, i open(newunit=unit, file='../data/2015/1/input.txt', access="stream") inquire(unit=unit, size=input_file_size) allocate(character(len=input_file_size) :: input) read(unit) input do i=1, input_file_size if (input(i:i) == "(") then floor = floor + 1 else floor = floor - 1 end if end do print *, "Part 1: ", floor floor = 0 do i=1, input_file_size if (input(i:i) == "(") then floor = floor + 1 else floor = floor - 1 end if steps = steps + 1 if (floor < 0) exit end do print *, "Part 2: ", steps close(1) end program problem