import sys



def calc(x, n, p1, p2):

    dp = []

    for i in range(n):

        dp.append( [0] * (x + 1) )



    pocket = x

    for i in range(n):

        for j in range(x + 1):

            dp[i][j] = dp[i - 1][j]

            if j - p1[i] >= 0:

                dp[i][j] = max(dp[i][j], dp[i][j - p1[i]] + p2[i])

            pocket = max(pocket, (x - j) + dp[i][j])



    return pocket



def main():

    n,d,x = list(map(int, sys.stdin.readline().split()))



    pp = []

    for i in range(d):

        pp.append( list(map(int,sys.stdin.readline().split())) )



    curr_x = x

    for i in range(d - 1):

        curr_x = calc(curr_x, n, pp[i], pp[i + 1])



    print(curr_x)



if __name__ == '__main__':

    main()
import sys



def main():

    n,d,x = list(map(int, sys.stdin.readline().split()))



    pp = []

    for i in range(d):

        pp.append( list(map(int,sys.stdin.readline().split())) )



    dp = [0] * 100001

    curr_x = x

    for k in range(d - 1):

        next_x = curr_x

        for i in range(curr_x + 1):

            dp[i] = 0

        for i in range(n):

            for j in range(curr_x + 1):

                if j - pp[k][i] >= 0:

                    dp[j] = max(dp[j], dp[j - pp[k][i]] + pp[k + 1][i])

                next_x = max(next_x, (curr_x - j) + dp[j])

        curr_x = next_x



    print(curr_x)



if __name__ == '__main__':

    main()
import sys


def calc(x, n, p1, p2):
    dp = []
    for i in range(n):
        dp.append([0] * (x + 1))
    pocket = x
    for i in range(n):
        for j in range(x + 1):
            dp[i][j] = dp[i - 1][j]
            if j - p1[i] >= 0:
                dp[i][j] = max(dp[i][j], dp[i][j - p1[i]] + p2[i])
            pocket = max(pocket, (x - j) + dp[i][j])
    return pocket


def main():
    n, d, x = list(map(int, sys.stdin.readline().split()))
    pp = []
    for i in range(d):
        pp.append(list(map(int, sys.stdin.readline().split())))
    curr_x = x
    for i in range(d - 1):
        curr_x = calc(curr_x, n, pp[i], pp[i + 1])
    print(curr_x)


if __name__ == "__main__":
    main()

import sys


def main():
    n, d, x = list(map(int, sys.stdin.readline().split()))
    pp = []
    for i in range(d):
        pp.append(list(map(int, sys.stdin.readline().split())))
    dp = [0] * 100001
    curr_x = x
    for k in range(d - 1):
        next_x = curr_x
        for i in range(curr_x + 1):
            dp[i] = 0
        for i in range(n):
            for j in range(curr_x + 1):
                if j - pp[k][i] >= 0:
                    dp[j] = max(dp[j], dp[j - pp[k][i]] + pp[k + 1][i])
                next_x = max(next_x, (curr_x - j) + dp[j])
        curr_x = next_x
    print(curr_x)


if __name__ == "__main__":
    main()

- - -def calc(x, n, p1, p2): -    dp = [] -    for i in range(n): -        dp.append([0] * (x + 1)) -    pocket = x -    for i in range(n): -        for j in range(x + 1): -            dp[i][j] = dp[i - 1][j] -            if j - p1[i] >= 0: -                dp[i][j] = max(dp[i][j], dp[i][j - p1[i]] + p2[i]) -            pocket = max(pocket, (x - j) + dp[i][j]) -    return pocket +    dp = [0] * 100001 -    for i in range(d - 1): -        curr_x = calc(curr_x, n, pp[i], pp[i + 1]) +    for k in range(d - 1): +        next_x = curr_x +        for i in range(curr_x + 1): +            dp[i] = 0 +        for i in range(n): +            for j in range(curr_x + 1): +                if j - pp[k][i] >= 0: +                    dp[j] = max(dp[j], dp[j - pp[k][i]] + pp[k + 1][i]) +                next_x = max(next_x, (curr_x - j) + dp[j]) +        curr_x = next_x