N,M,K,*A=$<.read.split.map &:to_i r=[K,*[v=0]*N] M.times{ a=[0]*N (1...N).each{|i|r[i]=[r[i],r[i-1]].max} N.times{|n|n.times{|i| d,c=r[i].divmod A[i] a[n]=[a[n],c+d*A[n]].max }} r=a v=[a[-1],v].max } p v