import sequtils,strutils type bound = tuple[From:int,to : int, cost : int, time : int] var N = stdin.readline.parseInt C = stdin.readline.parseInt V = stdin.readline.parseInt S,T,Y,M : seq[int] L = newSeqWith(4,newSeq[int](0)) Mities = newSeq[bound](0) Max_i = high(int) - 10000 miti : bound L = @[] for i in 0..3: L &= stdin.readline.split.map(parseInt) (S,T,Y,M) = (L[0],L[1],L[2],L[3]) var mintime = newSeqWith(C + 1, newSeqWith(N,Max_i)) mintime[0][0] = 0 for i in 0.. c: continue elif mintime[c - m.cost][m.From] + m.time < mintime[c][m.to]: flag = true mintime[c][m.to] = mintime[c - m.cost][m.From] + m.time if mintime[C][N - 1] == high(int) - 10000: echo -1 else: echo mintime[C][N-1]