python run time error (NZEC) in spoj

My following code returns me the run time error in spoj during submission. Can anybody tell me how to remove this error. here is the link of the question

import numpy as np
import sys

x = sys.argv[0]
input = open('')
lines = input.readline()
z = []

for line in input:
    lst = line.strip().split(' ')

size = len(z)
M = np.zeros((len(z),len(z)))

for i in range(size-1, -1, -1):
    for j in range(size-1, i-1, -1):
        if i == size-1:
              M[i,j] = z[i]
              if j > i:
                    M[i,j] = M[i+1,j] + [j-i]
              elif j == i:
                    M[i,j] = z[i] + M[j+1, (j+1):].min()
cost = int(M[j, j:].min())
print cost