program example
	implicit none

	integer(16) :: i=1,j=1,N
    integer(16),allocatable :: x(:,:),A(:)
    
    read(*,*) N
     
    allocate(x(N,N),A(N))

	do
		read(*,"(i1)",advance="no",end=100) A(i)
    	x(1,j)=A(i)
        if (mod(j,2000)==0) then
        	deallocate(A)
            allocate(A(N))
        	i=1
            j=j+1
        else
        
        	i=i+1
        	j=j+1
            
        end if
        
    end do

100    do i=2,N
     
    	do j=1,N+1-i
        
        	x(i,j)=abs(x(i-1,j)-x(i-1,j+1))
        
        end do
    
    end do
    
    write(*,*) x(N,1)

end program