Problem:
長年の研究の末、イクタ君は未来予知能力を手に入れた！　彼がこの研究に費やした時間や金銭は莫大なものであったが、ついに報われる時がやってきたのだ。手始めに金銭を取り戻すため、イクタ君は株式投資を始めることにした。
イクタ君は現在株式は全く保有しておらず、
x
円を所持している。彼が投資対象に定めた株式は
n
種類で、それらについて今日から
d
日分の株価を予知することに成功した。その結果、驚くべきことに今日から
d
日間は日中の株価変動が全くないことが判明した。つまり、今日を1日目としたときの
i
（
1 ≤ i ≤ d
）日目の株式
j
（
1 ≤ j ≤ n
）の株価
p
i,j
円がわかっている。イクタ君はそれぞれの日に自由に株式を売買できる。すなわち、任意の時点で以下の操作（購入・売却）を任意の順番で任意の回数行える。ただし、各操作の前後での所持金と株式の保有単位数は非負整数でなければならない。
購入 :
i
日目に、株式の種類
j
（
1 ≤ j ≤ n
）を一つ選び、所持金
p
i,j
円を支払い1単位の株式
j
を得る。
売却 :
i
日目に、株式の種類
j
（
1 ≤ j ≤ n
）を一つ選び、1単位の株式
j
を支払い
p
i,j
円を得る。
（彼が研究に没頭する間に証券取引システムは大きな発達を遂げ、取引手数料はかからなくなった。）
イクタ君は大学で情報科学を修めていたが、未来予知研究に明け暮れるすえに大学で学んだことをすべて忘れてしまっていた。そんな彼の代わりに最終日の所持金を最大化するプログラムを書いてあげてほしい。
Input
入力は以下の形式で与えられる。
n
d
x
p
1,1
...
p
1,n
...
p
d,1
...
p
d,n
n
: 株式の種類数
d
: 日数
x
: 1日目の所持金
p
i,j
:
i
日目の銘柄
j
の株価（今日を1日目とする）
Constraints
入力中の各変数は以下の制約を満たす整数である。
1 ≤ n ≤ 10
1 ≤ d ≤ 10
1 ≤ x, p
i,j
≤ 10
5
最終日の所持金が
10
5
以下となることが保証されている。
Output
最適に投資した場合の最終日の所持金を1行に出力せよ。
Sample Input 1
2 2 5
3 2
5 4
Output for the Sample Input 1
9
例えば、それぞれの株式を1単位ずつ購入します。
Sample Input 2
1 2 5
6
10000
Output for the Sample Input 2
5
1単位より小さい取引はできません。小口投資家の悲哀です。
Sample Input 3
2 3 5
4 5
6 3
8 5
Output for the Sample Input 3
11
1日目は1種類目の株式に、2日目は2種類目の株式に投資します。
Sample Input 4
3 3 10
10 9 6
8 7 3
7 5 1
Output for the Sample Input 4
10
景気が悪い時もあります。

Submitted solutions:

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

int MAXS = 100000;

int Trade(vector<int>& A, vector<int>& B, int X) {
    int N = A.size();
    vector<vector<int>> DP(N+1,vector<int>(MAXS+1,0));
    rep(i,0,N) {
        rep(j,0,MAXS+1) DP[i+1][j] = DP[i][j];
        rep(j,0,MAXS+1) if (j+A[i]<=MAXS) chmax(DP[i+1][j+A[i]],DP[i+1][j]+B[i]);
    }
    int Ret = -inf;
    rep(i,0,X+1) {
        chmax(Ret,X-i+DP[N][i]);
    }
    return Ret;
}

int main() {
    int N, D;
    int X;
    cin >> N >> D >> X;
    vector A(D, vector<int>(N));
    rep(i,0,D) rep(j,0,N) cin >> A[i][j];
    rep(i,0,D-1) X = Trade(A[i],A[i+1],X);
    cout << X << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 7892
final_rank: 6

code_snippet: #include <iostream>
using namespace std;

int N, D, X;
int A[19][19];
int dp[200009];

void Simulation(int day) {
	for (int i = 0; i <= 100000; i++) dp[i] = i;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= 100000; j++) {
			if (dp[j] < 0) continue;
			int cost = A[day + 0][i];
			int retu = A[day + 1][i];
			dp[j + cost] = max(dp[j + cost], dp[j] + retu);
		}
	}
}

int main() {
	// Step 1. Input
	cin >> N >> D >> X;
	for (int i = 1; i <= D; i++) {
		for (int j = 1; j <= N; j++) cin >> A[i][j];
	}

	// Step 2. Simulation
	int Current = X;
	for (int i = 1; i <= D - 1; i++) {
		Simulation(i);
		Current = dp[Current];
	}
	
	// Step 3. Output
	cout << Current << endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3804
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll n,d,x,p[10][10],dp[1<<17];
int main(void){
    cin>>n>>d>>x;
    for(ll i=0;i<d;i++){
        for(ll j=0;j<n;j++){
            cin>>p[i][j];
        }
    }
    for(ll i=0;i<d-1;i++){
        for(ll j=0;j<1<<17;j++){
            dp[j]=0;
        }
        for(ll j=0;j<1<<17;j++){
            for(ll k=0;k<n;k++){
                if(j+p[i][k]>=1<<17){
                    continue;
                }
                dp[j+p[i][k]]=max(dp[j+p[i][k]],dp[j]+p[i+1][k]);
            }
            if(j+1<1<<17){
                dp[j+1]=max(dp[j+1],dp[j]+1);
            }
        }
        x=dp[x];
    }
    cout<<x<<endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4436
final_rank: 4

code_snippet: #include<bits/stdc++.h>
#define int ll
#define rep(i, N) for(int i = 0; i < (int)(N); ++i)
#define rep1(i, N) for(int i = 1; i <= (int)(N); ++i)
#define per(i, N) for(int i = (N)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define bit(n, k) ((n) >> (k))
#define pcnt(n) (__builtin_popcount(n))
#define TakAo(ans) ans ? cout << "Takahashi\n" : cout << "Aoki\n"
#define YesNo(ans) ans ? cout << "Yes\n" : cout << "No\n"
#define endl '\n'
#define fi first
#define se second
#define mkpr make_pair
#define mktpl make_tuple
#define eb emplace_back

using namespace std;
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using point = struct{ ll x, y; };
using pointld = struct{ ld x, y; };
using State = string::const_iterator;
template<class T> using max_heap = priority_queue<T>;
template<class T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vec<vec<T>>;
template<class T> using vvvec = vec<vvec<T>>;
template<class T> using vvvvec = vvec<vvec<T>>;

constexpr ld EPS = 1e-10;
constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
constexpr ll MOD = (0) ? 998244353 : 1e9+7;
constexpr int NIL = -1;
constexpr int pm[2] = {1, -1};
constexpr int dy[6] = {0, 1, 1, 0, -1, -1};
constexpr int dx[6] = {1, 1, 0, -1, -1, 0};

ll cel(ll a, ll b){ return (a + b - 1) / b;}
ll Gcd(ll a, ll b){ return b ? Gcd(b, a % b) : abs(a);}
template<class T> T powi(T x, ll exp){
    return exp > 0 ? (exp & 1 ? x : 1) * powi(x * x, exp >> 1) : x / x;
}
ll modpow(ll x, ll exp, ll mod){
    x %= mod;
    return exp > 0 ? (exp & 1 ? x : 1) * modpow(x * x, exp >> 1, mod) % mod : 1;
}
template<class T> bool chmin(T &a, T b){ return a > b ? (a = b, true) : 0;}
template<class T> bool chmax(T &a, T b){ return a < b ? (a = b, true) : 0;}

using Pair = pair<ll, ll>;
using Tpl = tuple<int, int, int>;

void Main(){
    int N, D, X; cin >> N >> D >> X;
    vvec<int> P(D, vec<int>(N));
    rep(i, D)rep(j, N) cin >> P[i][j];

    const int MAX_N = 4e5 + 1;

    vvvec<int> dp(D, vvec<int>(N + 1, vec<int>(MAX_N, NIL)));
    dp[0][N][X] = 1;

    rep(i, D){
        // sell 
        if(i > 0){
            rep(j, N){
                rep(k, MAX_N){
                    if(dp[i - 1][j][k] != NIL)
                        dp[i][N][k + P[i][j] * dp[i - 1][j][k]] = 1;
                    if(dp[i - 1][N][k] != NIL)
                        dp[i][N][k] = 1;
                }
            }
        }

        ll mx = 0;
        per(k, MAX_N){
            if(dp[i][N][k] != NIL){
                mx = k;
                break;
            }
        }

        if(i > 0) rep(j, N){
            rep(k, MAX_N) chmax(dp[i][j][k], dp[i - 1][j][k]);
        }

        //buy
        if(i < D - 1){
            rep(j, N){
                rep1(k, MAX_N){
                    if(mx - P[i][j] * k < 0) break;
                    chmax(dp[i][j][mx - P[i][j] * k], k);
                }
            }
        }
        else{
            cout << mx << endl;
        }
    }
}
 
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    Main();
    return 0;
}
accuracy: 0.125
time_ms: 10
memory_kb: 56316
final_rank: 19

code_snippet: #include<bits/stdc++.h>
#define int ll
#define rep(i, N) for(int i = 0; i < (int)(N); ++i)
#define rep1(i, N) for(int i = 1; i <= (int)(N); ++i)
#define per(i, N) for(int i = (N)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define bit(n, k) ((n) >> (k))
#define pcnt(n) (__builtin_popcount(n))
#define TakAo(ans) ans ? cout << "Takahashi\n" : cout << "Aoki\n"
#define YesNo(ans) ans ? cout << "Yes\n" : cout << "No\n"
#define endl '\n'
#define fi first
#define se second
#define mkpr make_pair
#define mktpl make_tuple
#define eb emplace_back

using namespace std;
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using point = struct{ ll x, y; };
using pointld = struct{ ld x, y; };
using State = string::const_iterator;
template<class T> using max_heap = priority_queue<T>;
template<class T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vec<vec<T>>;
template<class T> using vvvec = vec<vvec<T>>;
template<class T> using vvvvec = vvec<vvec<T>>;

constexpr ld EPS = 1e-10;
constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
constexpr ll MOD = (0) ? 998244353 : 1e9+7;
constexpr int NIL = -1;
constexpr int pm[2] = {1, -1};
constexpr int dy[6] = {0, 1, 1, 0, -1, -1};
constexpr int dx[6] = {1, 1, 0, -1, -1, 0};

ll cel(ll a, ll b){ return (a + b - 1) / b;}
ll Gcd(ll a, ll b){ return b ? Gcd(b, a % b) : abs(a);}
template<class T> T powi(T x, ll exp){
    return exp > 0 ? (exp & 1 ? x : 1) * powi(x * x, exp >> 1) : x / x;
}
ll modpow(ll x, ll exp, ll mod){
    x %= mod;
    return exp > 0 ? (exp & 1 ? x : 1) * modpow(x * x, exp >> 1, mod) % mod : 1;
}
template<class T> bool chmin(T &a, T b){ return a > b ? (a = b, true) : 0;}
template<class T> bool chmax(T &a, T b){ return a < b ? (a = b, true) : 0;}

using Pair = pair<ll, ll>;
using Tpl = tuple<int, int, int>;

void Main(){
    int N, D, X; cin >> N >> D >> X;
    vvec<int> P(D, vec<int>(N));
    rep(i, D)rep(j, N) cin >> P[i][j];

    const int MAX_N = 4e5 + 1;

    vvvec<int> dp(D, vvec<int>(N + 1, vec<int>(MAX_N, NIL)));
    rep(i, D) dp[i][N][X] = 1;

    rep(i, D){
        // sell 
        if(i > 0){
            rep(j, N){
                rep(k, MAX_N){
                    if(dp[i - 1][j][k] != NIL)
                        dp[i][N][k + P[i][j] * dp[i - 1][j][k]] = 1;
                    if(dp[i - 1][N][k] != NIL)
                        dp[i][N][k] = 1;
                }
            }
        }

        ll mx = 0;
        per(k, MAX_N){
            if(dp[i][N][k] != NIL){
                mx = k;
                break;
            }
        }

        if(i > 0) rep(j, N){
            rep(k, MAX_N) chmax(dp[i][j][k], dp[i - 1][j][k]);
        }

        //buy
        if(i < D - 1){
            rep(j, N){
                rep1(k, MAX_N){
                    if(mx - P[i][j] * k < 0) break;
                    chmax(dp[i][j][mx - P[i][j] * k], k);
                }
            }
        }
        else{
            cout << mx << endl;
        }
    }
}
 
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    Main();
    return 0;
}
accuracy: 0.125
time_ms: 10
memory_kb: 56320
final_rank: 20

code_snippet: #include<bits/stdc++.h>
#define int ll
#define rep(i, N) for(int i = 0; i < (int)(N); ++i)
#define rep1(i, N) for(int i = 1; i <= (int)(N); ++i)
#define per(i, N) for(int i = (N)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define bit(n, k) ((n) >> (k))
#define pcnt(n) (__builtin_popcount(n))
#define TakAo(ans) ans ? cout << "Takahashi\n" : cout << "Aoki\n"
#define YesNo(ans) ans ? cout << "Yes\n" : cout << "No\n"
#define endl '\n'
#define fi first
#define se second
#define mkpr make_pair
#define mktpl make_tuple
#define eb emplace_back

using namespace std;
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using point = struct{ ll x, y; };
using pointld = struct{ ld x, y; };
using State = string::const_iterator;
template<class T> using max_heap = priority_queue<T>;
template<class T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vec<vec<T>>;
template<class T> using vvvec = vec<vvec<T>>;
template<class T> using vvvvec = vvec<vvec<T>>;

constexpr ld EPS = 1e-10;
constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
constexpr ll MOD = (0) ? 998244353 : 1e9+7;
constexpr int NIL = -1;
constexpr int pm[2] = {1, -1};
constexpr int dy[6] = {0, 1, 1, 0, -1, -1};
constexpr int dx[6] = {1, 1, 0, -1, -1, 0};

ll cel(ll a, ll b){ return (a + b - 1) / b;}
ll Gcd(ll a, ll b){ return b ? Gcd(b, a % b) : abs(a);}
template<class T> T powi(T x, ll exp){
    return exp > 0 ? (exp & 1 ? x : 1) * powi(x * x, exp >> 1) : x / x;
}
ll modpow(ll x, ll exp, ll mod){
    x %= mod;
    return exp > 0 ? (exp & 1 ? x : 1) * modpow(x * x, exp >> 1, mod) % mod : 1;
}
template<class T> bool chmin(T &a, T b){ return a > b ? (a = b, true) : 0;}
template<class T> bool chmax(T &a, T b){ return a < b ? (a = b, true) : 0;}

using Pair = pair<ll, ll>;
using Tpl = tuple<int, int, int>;

void Main(){
    int N, D, X; cin >> N >> D >> X;
    vvec<int> P(D, vec<int>(N));
    rep(i, D)rep(j, N) cin >> P[i][j];

    const int MAX_N = 4e5 + 1;

    vvvec<int> dp(D, vvec<int>(N + 1, vec<int>(MAX_N, NIL)));
    rep(i, D) dp[i][N][X] = 1;

    rep(i, D){
        // sell 
        if(i > 0){
            rep(j, N){
                rep(k, MAX_N){
                    if(dp[i - 1][j][k] != NIL)
                        dp[i][N][k + P[i][j] * dp[i - 1][j][k]] = 1;
                    if(dp[i - 1][N][k] != NIL)
                        dp[i][N][k] = 1;
                }
            }
        }

        ll mx = 0;
        per(k, MAX_N){
            if(dp[i][N][k] != NIL){
                mx = k;
                break;
            }
        }

        if(i > 0) rep(j, N){
            rep(k, MAX_N) dp[i][j][k] = dp[i - 1][j][k];
        }

        //buy
        if(i < D - 1){
            rep(j, N){
                rep1(k, MAX_N){
                    if(mx - P[i][j] * k < 0) break;
                    chmax(dp[i][j][mx - P[i][j] * k], k);
                }
            }
        }
        else{
            cout << mx << endl;
        }
    }
}
 
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    Main();
    return 0;
}
accuracy: 0.125
time_ms: 10
memory_kb: 56120
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
    int n, d, x;
    cin >> n >> d >> x;
    vector<vector<int>> A(d, vector<int>(n));
    for(int i = 0; i < d; i++){
        for(int j = 0; j < n; j++){
            cin >> A[i][j];
        }
    }
    vector<vector<vector<int>>> dp(d + 1, vector<vector<int>>(d + 1,
                                vector<int>(100001, -1)));
    function<int(int,int,int)> rec = [&](int l, int r, int s){
        if(l >= r)return 0;
        if(dp[l][r][s] != -1)return dp[l][r][s];
        dp[l][r][s] = s;
        for(int i = 0; i < n; i++){
            int d = s / A[l][i];
            if(d == 0)continue;
            if(A[l][i] >= A[r-1][i])continue;
            for(int j = 1; j <= d; j++){
                dp[l][r][s] = max(dp[l][r][s], j * A[r - 1][i] + rec(l, r, s - j * A[l][i]));
            }
        }
        for(int m = l + 1; m <= r; m++){
            dp[l][r][s] = max(dp[l][r][s], rec(m - 1, r, rec(l, m, s)));
        }
        return dp[l][r][s];
    };
    cout << rec(0, d, x) << '\n';
}
accuracy: 1
time_ms: 40
memory_kb: 55348
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, d, x;
  cin >> n >> d >> x;
  
  vector<vector<int>> p(d, vector<int>(n));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < n; j++) {
      cin >> p.at(i).at(j);
    }
  }
  
  for (int i = 1; i < d; i++) {
    vector<vector<int>> dp(n + 1, vector<int>(2e5 + 1, -1e9));
    dp[0][x] = 0;
    for (int j = 1; j <= n; j++) {
      for (int k = 2e5; k >= 0; k--) {
        dp[j][k] = max(dp[j][k], dp[j - 1][k]);
        if (k + p.at(i - 1).at(j - 1) <= 2e5) {
          dp[j][k] = max(dp[j][k], dp[j][k + p.at(i - 1).at(j - 1)] + (p.at(i).at(j - 1) - p.at(i - 1).at(j - 1)));
        }
      }
    }
    int diff = 0;
    for (int k = 0; k <= 2e5; k++) diff = max(diff, dp[n][k]);
    x += diff;
  }
  
  cout << x << '\n';
}
accuracy: 1
time_ms: 50
memory_kb: 12608
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for(ll i=(a); i<(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n+1)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

const ll vmax=1e5+10;
ll cost[10][10];    //day, index->value
ll dp[10][vmax];    //index, used->profit
ll MV[10];  //day->max

void init(){
    REP(i,10){
        REP(j,vmax){
            dp[i][j]=0;
        }
    }
    return;
}

int main() {
    ll N,D,X; cin>>N>>D>>X;
    REP(i,D){
        REP(j,N){
            ll p; cin>>p;
            cost[i][j]=p;
        }
    }
    
    MV[0]=X;
    ll now=X;
    REP(d,D-1){
        init();
        
        REP(i,N){
            REP(v,vmax){
                if(i>0) chmax(dp[i][v],dp[i-1][v]);
                if(v-cost[d][i]>=0){
                    chmax(dp[i][v],dp[i][v-cost[d][i]]+cost[d+1][i]);
                }
            }
        }
        
        
        ll M=now;
        REP(v,now+1){
            chmax(M,now-v+dp[N-1][v]);
        }
        
        now=MV[d+1]=M;
    }
    cout<<MV[D-1]<<endl;
    
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 11284
final_rank: 7

code_snippet: #include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define forin(in, n)           \
    for (ll i = 0; i < n; i++) \
    cin >> in[i]
#define forout(out)                         \
    for (ll i = 0; i < (ll)out.size(); i++) \
    cout << out[i] << endl
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, n) for (ll i = a; i < n; ++i)
#define rep_down(i, a, n) for (ll i = a; i >= n; --i)
#define P pair<ll, ll>
#define pb push_back

#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define vvvvll vector<vector<vector<vector<ll>>>>
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

template <class T>
using V = vector<T>;

constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;
//constexpr ll mod = 998244353;

constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
void pt(T val)
{
    cout << val << "\n";
}
template <typename T>
void pt_vll(vector<T> &v)
{
    ll vs = v.size();
    rep(i, vs)
    {
        cout << v[i];

        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}
ll mypow(ll a, ll n)
{
    ll ret = 1;
    if (n == 0)
        return 1;
    if (a == 0)
        return 0;
    rep(i, n)
    {
        if (ret > (ll)(9e18 + 10) / a)
            return -1;
        ret *= a;
    }
    return ret;
}
long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

struct mint {
    ll x;
    constexpr mint(ll x = 0) noexcept : x((x % mod + mod) % mod) {}

    constexpr mint& operator+=(const mint& a) noexcept {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a) noexcept {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a) noexcept { (x *= a.x) %= mod; return *this; }
    constexpr mint& operator/=(const mint& a) noexcept { return *this *= a.inv(); }

    constexpr mint operator-() const noexcept { return mint(-x); }
    constexpr mint operator+(const mint& a) const noexcept { return mint(*this) += a; }
    constexpr mint operator-(const mint& a) const noexcept { return mint(*this) -= a; }
    constexpr mint operator*(const mint& a) const noexcept { return mint(*this) *= a; }
    constexpr mint operator/(const mint& a) const noexcept { return mint(*this) /= a; }
    constexpr bool operator==(const mint& a) const noexcept { return x == a.x; }
    constexpr bool operator!=(const mint& a) const noexcept { return x != a.x; }

    constexpr mint pow(ll n) const {
        if (n == 0) return 1;
        mint res = pow(n >> 1);
        res *= res;
        if (n & 1) res *= *this;
        return res;
    }
    constexpr mint inv() const { return pow(mod - 2); }

    friend istream& operator>>(istream& is, mint& a) noexcept {
        ll v; is >> v;
        a = mint(v);
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& a) noexcept {
        return os << a.x;
    }
};

struct UnionFind
{
    vector<ll> par, size;

    UnionFind(ll N) : par(N)
    { //最初はすべてが根であるとして初期化
        size.resize(N, 1);
        for (ll i = 0; i < N; i++)
            par[i] = i;
    }

    ll root(ll x)
    { //データxの木の根を再帰で得る
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y)
    { //xとyの木を併合
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry)
            return; //同じ木にあるときはそのまま
        if (size[rx] > size[ry])
        {
            par[ry] = rx;
            size[rx] += size[ry];
        }
        else
        {
            par[rx] = ry;
            size[ry] += size[rx];
        }
        return;
    }

    bool same(ll x, ll y)
    { //2つのデータx,yが属する木が同じならtrue
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }

    ll treesize(ll x) { return size[root(x)]; }
};

const int MAX = 2010000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

vector<ll> enum_div(ll n)
{ //約数全列挙
    vector<ll> ret;
    for (ll i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
            {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

void make_prime(vector<ll> &ret, ll n)
{ //素因数分解
    ll x = n;
    for (ll i = 2; i * i <= x; i++)
    {
        while (n % i == 0)
        {
            n /= i;
            ret.push_back(i);
        }
    }
    if (n != 1)
    {
        ret.push_back(n);
    }
    return;
}

vector<bool> prime(1000010, true);
vector<ll> pri(1000010);
vector<bool> isprime(int N)
{ //素数判定
    if (N >= 0)
        prime[0] = false;
    if (N >= 1)
        prime[1] = false;
    for (ll i = 2; i * i <= N; i++)
    {
        if (!prime[i])
        {
            continue;
        }
        for (ll j = i * i; j <= N; j += i)
        {
            if (prime[j])
                pri[j] = i;
            prime[j] = false;
        }
    }
    return prime;
}

map<ll,ll> compression(vector<ll> v){
    map<ll,ll> ret;
    ll cnt = 0;
    sort(v.begin(),v.end());
    for(ll i=0; i<v.size(); i++){
        if(!ret.count(v[i])){
            ret[v[i]] = cnt;
            cnt++;
        }
    }
    return ret;
}

//素因数分解: void make_prime(vector<ll> &ret, ll n)
//素数判定: vector<bool> isprime(int N)
//約数全列挙: vector<ll> enum_div(ll n)

void solve(){
    ll  n, m, k, cnt = 0, sum = 0, ans = 0;
    ll d,x;
    cin>>n>>d>>x;
    vvll p(d,vll(n));
    rep(i,d){
        rep(j,n){
            cin>>p[i][j];
        }
    }
    vvll ma(d+1,vll(100001));
    rep(i,d){
        rep(j,100001){
            ma[i][j]=j;
        }
    }
    rep(k,d){
        rep_up(l,k+1,d){
            vvll dp(n+1,vll(100001));
            rep(i,n){
                rep(j,100001){
                    chmax(dp[i+1][j],dp[i][j]);
                    if(j>=p[k][i]){
                        chmax(dp[i+1][j],dp[i+1][j-p[k][i]]+p[l][i]);
                    }
                }
            }
            rep(j,100001){
                chmax(ma[l][j],dp[n][j]);
            }
        }
    }
    rep(i,x+1){
        k=i;
        rep(j,d-1){
            k=ma[j+1][k];
        }
        chmax(ans,k+x-i);
    }
    
    pt(ans);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //cout << fixed << setprecision(16);
    //ll T;
    //cin>>T;
    //rep(ca,T)
    solve();
}
accuracy: 0.75
time_ms: 160
memory_kb: 29048
final_rank: 15

code_snippet: #include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define forin(in, n)           \
    for (ll i = 0; i < n; i++) \
    cin >> in[i]
#define forout(out)                         \
    for (ll i = 0; i < (ll)out.size(); i++) \
    cout << out[i] << endl
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, n) for (ll i = a; i < n; ++i)
#define rep_down(i, a, n) for (ll i = a; i >= n; --i)
#define P pair<ll, ll>
#define pb push_back

#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define vvvvll vector<vector<vector<vector<ll>>>>
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

template <class T>
using V = vector<T>;

constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;
//constexpr ll mod = 998244353;

constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
void pt(T val)
{
    cout << val << "\n";
}
template <typename T>
void pt_vll(vector<T> &v)
{
    ll vs = v.size();
    rep(i, vs)
    {
        cout << v[i];

        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}
ll mypow(ll a, ll n)
{
    ll ret = 1;
    if (n == 0)
        return 1;
    if (a == 0)
        return 0;
    rep(i, n)
    {
        if (ret > (ll)(9e18 + 10) / a)
            return -1;
        ret *= a;
    }
    return ret;
}
long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

struct mint {
    ll x;
    constexpr mint(ll x = 0) noexcept : x((x % mod + mod) % mod) {}

    constexpr mint& operator+=(const mint& a) noexcept {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a) noexcept {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a) noexcept { (x *= a.x) %= mod; return *this; }
    constexpr mint& operator/=(const mint& a) noexcept { return *this *= a.inv(); }

    constexpr mint operator-() const noexcept { return mint(-x); }
    constexpr mint operator+(const mint& a) const noexcept { return mint(*this) += a; }
    constexpr mint operator-(const mint& a) const noexcept { return mint(*this) -= a; }
    constexpr mint operator*(const mint& a) const noexcept { return mint(*this) *= a; }
    constexpr mint operator/(const mint& a) const noexcept { return mint(*this) /= a; }
    constexpr bool operator==(const mint& a) const noexcept { return x == a.x; }
    constexpr bool operator!=(const mint& a) const noexcept { return x != a.x; }

    constexpr mint pow(ll n) const {
        if (n == 0) return 1;
        mint res = pow(n >> 1);
        res *= res;
        if (n & 1) res *= *this;
        return res;
    }
    constexpr mint inv() const { return pow(mod - 2); }

    friend istream& operator>>(istream& is, mint& a) noexcept {
        ll v; is >> v;
        a = mint(v);
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& a) noexcept {
        return os << a.x;
    }
};

struct UnionFind
{
    vector<ll> par, size;

    UnionFind(ll N) : par(N)
    { //最初はすべてが根であるとして初期化
        size.resize(N, 1);
        for (ll i = 0; i < N; i++)
            par[i] = i;
    }

    ll root(ll x)
    { //データxの木の根を再帰で得る
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y)
    { //xとyの木を併合
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry)
            return; //同じ木にあるときはそのまま
        if (size[rx] > size[ry])
        {
            par[ry] = rx;
            size[rx] += size[ry];
        }
        else
        {
            par[rx] = ry;
            size[ry] += size[rx];
        }
        return;
    }

    bool same(ll x, ll y)
    { //2つのデータx,yが属する木が同じならtrue
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }

    ll treesize(ll x) { return size[root(x)]; }
};

const int MAX = 2010000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

vector<ll> enum_div(ll n)
{ //約数全列挙
    vector<ll> ret;
    for (ll i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
            {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

void make_prime(vector<ll> &ret, ll n)
{ //素因数分解
    ll x = n;
    for (ll i = 2; i * i <= x; i++)
    {
        while (n % i == 0)
        {
            n /= i;
            ret.push_back(i);
        }
    }
    if (n != 1)
    {
        ret.push_back(n);
    }
    return;
}

vector<bool> prime(1000010, true);
vector<ll> pri(1000010);
vector<bool> isprime(int N)
{ //素数判定
    if (N >= 0)
        prime[0] = false;
    if (N >= 1)
        prime[1] = false;
    for (ll i = 2; i * i <= N; i++)
    {
        if (!prime[i])
        {
            continue;
        }
        for (ll j = i * i; j <= N; j += i)
        {
            if (prime[j])
                pri[j] = i;
            prime[j] = false;
        }
    }
    return prime;
}

map<ll,ll> compression(vector<ll> v){
    map<ll,ll> ret;
    ll cnt = 0;
    sort(v.begin(),v.end());
    for(ll i=0; i<v.size(); i++){
        if(!ret.count(v[i])){
            ret[v[i]] = cnt;
            cnt++;
        }
    }
    return ret;
}

//素因数分解: void make_prime(vector<ll> &ret, ll n)
//素数判定: vector<bool> isprime(int N)
//約数全列挙: vector<ll> enum_div(ll n)

void solve(){
    ll  n, m, k, cnt = 0, sum = 0, ans = 0;
    ll d,x;
    cin>>n>>d>>x;
    vvll p(d,vll(n));
    rep(i,d){
        rep(j,n){
            cin>>p[i][j];
        }
    }
    vvll ma(d+1,vll(100001));
    rep(i,d){
        rep(j,100001){
            ma[i][j]=j;
        }
    }
    rep(k,d){
        rep_up(l,k+1,d){
            vvll dp(n+1,vll(100001));
            rep(i,n){
                rep(j,100001){
                    chmax(dp[i+1][j],dp[i][j]);
                    if(j>=p[k][i]){
                        chmax(dp[i+1][j],dp[i+1][j-p[k][i]]+p[l][i]);
                    }
                }
            }
            rep(j,100001){
                if(l*100001+dp[n][j]>=d*100001) continue;
                chmax(ma[l][j],dp[n][j]);
            }
        }
    }
    rep(i,x+1){
        k=i;
        rep(j,d-1){
            k=ma[j+1][k];
        }
        chmax(ans,k+x-i);
    }
    
    pt(ans);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //cout << fixed << setprecision(16);
    //ll T;
    //cin>>T;
    //rep(ca,T)
    solve();
}
accuracy: 0.75
time_ms: 160
memory_kb: 28956
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)


struct kika {
    vector<pair<ll, ll>> P;
    int num;
    void set(ll X, ll Y) {
        P.push_back(make_pair(X, Y));
    }


    ll gcd(ll(a), ll(b)) {
        if (a == 0 && b == 0)return 0;
        else if (b == 0)return a;

        ll c = a;
        while (a % b != 0) {
            c = a % b;
            a = b;
            b = c;
        }
        return b;
    }

    tuple<ll, ll, ll> segment(int i, int j) {
        ll Xi = P[i].first;
        ll Yi = P[i].second;
        ll Xj = P[j].first;
        ll Yj = P[j].second;

        ll a = Yj - Yi;
        ll b = -(Xj - Xi);
        ll c = -(Yj - Yi) * Xi + (Xj - Xi) * Yi;
        ll g = gcd(a, gcd(b, c));
        a /= g; b /= g; c /= g;
        if (a < 0) {
            a *= -1; b *= -1; c *= -1;
        }
        return make_tuple(a, b, c);

    }//ax+by+c=0

    tuple<ll, ll, ll> segment(ll Xi, ll Yi, ll Xj, ll Yj) {
        ll a = Yj - Yi;
        ll b = -(Xj - Xi);
        ll c = -(Yj - Yi) * Xi + (Xj - Xi) * Yi;
        ll g = gcd(a, gcd(b, c));
        a /= g; b /= g; c /= g;
        if (a < 0) {
            a *= -1; b *= -1; c *= -1;
        }
        return make_tuple(a, b, c);

    }//ax+by+c=0

    tuple<ll, ll, ll> suiseg(int i, int j) {
        ll Xi = P[i].first;
        ll Yi = P[i].second;
        ll Xj = P[j].first;
        ll Yj = P[j].second;

        ll b = 2 * (Yj - Yi);
        ll a = 2 * (Xj - Xi);
        ll c = Xj * Xj - Xi * Xi + Yj * Yj - Yi * Yi;
        c *= -1;
        ll g = gcd(a, gcd(b, c));
        a /= g; b /= g; c /= g;
        if (a < 0) {
            a *= -1; b *= -1; c *= -1;
        }
        return make_tuple(a, b, c);

    }//ax+by+c=0

    tuple<ll, ll, ll> suiseg(ll Xi, ll Yi, ll Xj, ll Yj) {

        ll b = 2 * (Yj - Yi);
        ll a = 2 * (Xj - Xi);
        ll c = Xj * Xj - Xi * Xi + Yj * Yj - Yi * Yi;
        c *= -1;
        ll g = gcd(a, gcd(b, c));
        a /= g; b /= g; c /= g;
        if (a < 0) {
            a *= -1; b *= -1; c *= -1;
        }
        return make_tuple(a, b, c);

    }//ax+by+c=0

    vector<tuple<ll, ll, ll>> allseg;
    vector<tuple<ll, ll, ll>> allsuiseg;
    void allsegment() {
        allseg.resize(0);
        ll n = P.size();
        rep(i, n)rep(j, n) {
            allseg.push_back(segment(i, j));
        }
    }
    void allsuisegment() {
        allsuiseg.resize(0);
        ll n = P.size();
        rep(i, n)rep(j, n) {
            allsuiseg.push_back(segment(i, j));
        }
    }

    double dist(int i, int j) {
        ll Xi = P[i].first;
        ll Yi = P[i].second;
        ll Xj = P[j].first;
        ll Yj = P[j].second;
        double dx = double(Xi - Xj);
        double dy = double(Yi - Yj);
        return sqrt(dx * dx + dy * dy);
    }

    vector<pair<double, double>> circintersect;
    void circsect(double r) {
        ll n = P.size();
        rep(i, n)rep(j, n) {
            if (dist(i, j) < r * 2.0) {

            }
            else continue;
        }
    }

};



int main() {
    ll N, D, X;
    cin >> N >> D >> X;
    vector<vll> P(D, vll(N));
    rep(i, D)rep(n, N)cin >> P[i][n];

    vector<vector<ll>> DP(D + 1, vector<ll>(100105, 0));
    rep(i,100105)DP[0][0] = X;
    rep(d, D - 1) {
        rep(x, 100003) {
            if(x!=0)DP[d + 1][x] = DP[d+1][x-1];
            DP[d + 1][x] = max(DP[d + 1][x], x);
            //if(x!=0)DP[d + 1][x] = max(DP[d+1][x-1],DP[d+1][x]);
            
            rep(n, N) {
                if (x - P[d][n] < 0)continue;
                DP[d + 1][x] = max(DP[d + 1][x], DP[d+1][x - P[d][n]]+ P[d + 1][n]);
            }
        }
    }
    ll an = 0;
    rep(d, D) {
        an = DP[d][an];
    }
    cout << an << endl;

}
accuracy: 1
time_ms: 10
memory_kb: 12576
final_rank: 8

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
int n,d,x;
int P[10][10];
int dp[1<<17];
int main()
{
	cin>>n>>d>>x;
	for(int i=0;i<d;i++)for(int j=0;j<n;j++)cin>>P[i][j];
	for(int i=0;i+1<d;i++)
	{
		for(int j=0;j<1<<17;j++)dp[j]=0;
		for(int j=0;j<1<<17;j++)
		{
			for(int k=0;k<n;k++)
			{
				if(j+P[i][k]>=1<<17)continue;
				dp[j+P[i][k]]=max(dp[j+P[i][k]],dp[j]+P[i+1][k]);
			}
			if(j+1<1<<17)dp[j+1]=max(dp[j+1],dp[j]+1);
		}
		x=dp[x];
	}
	cout<<x<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3924
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

const int INF = 1e9;
const long long inf = 1LL<<50;
using ll = long long;
template<typename T>
bool chmin(T& x, const T& y){
  if(x <= y) return false;
  x = y;
  return true;
}
template<typename T>
bool chmax(T& x, const T& y){
  if(x >= y) return false;
  x = y;
  return true;
}


int main(){
  int n, d, x;
  cin >> n >> d >> x;
  vector<vector<int>> a(d, vector<int>(n));
  for (int i=0; i<d; i++) {
    for (int j=0; j<n; j++) {
      cin >> a[i][j];
    }
  }
  for (int i=0; i<d-1; i++) {
    vector<vector<int>> dp(n+1, vector<int>(100100));
    for (int j=0; j<n; j++) {
      for (int k=0; k<=100000; k++) {
        int p = a[i+1][j] - a[i][j];
        chmax(dp[j+1][k], dp[j][k]);
        if (p >= 0 && k-a[i][j]>=0) chmax(dp[j+1][k], dp[j+1][k-a[i][j]] + p);
      }
    }
    int delta = -1;
    for (int j=0; j<=x; j++) {
      chmax(delta, dp[n][j]);
    }
    x = x + delta;
  }
  cout << x << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 7828
final_rank: 5

code_snippet: /**
 *	author: nok0
 *	created: 2020.10.24 14:19:07
**/
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#pragma region Macros
#define FOR(i, l, r) for(int i = (l); i < (r); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, n + 1)
#define RFOR(i, l, r) for(int i = (l); i >= (r); --i)
#define RREP(i, n) RFOR(i, n - 1, 0)
#define RREPS(i, n) RFOR(i, n, 1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template <class T = int>
using V = vector<T>;
template <class T = int>
using VV = V<V<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define VEC(type, name, size) \
	V<type> name(size);       \
	INPUT(name)
#define VVEC(type, name, h, w)    \
	VV<type> name(h, V<type>(w)); \
	INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	INPUT(__VA_ARGS__)
#define LL(...)     \
	ll __VA_ARGS__; \
	INPUT(__VA_ARGS__)
#define STR(...)        \
	string __VA_ARGS__; \
	INPUT(__VA_ARGS__)
#define CHAR(...)     \
	char __VA_ARGS__; \
	INPUT(__VA_ARGS__)
#define DOUBLE(...)     \
	DOUBLE __VA_ARGS__; \
	INPUT(__VA_ARGS__)
#define LD(...)     \
	LD __VA_ARGS__; \
	INPUT(__VA_ARGS__)
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(long double &a) { cin >> a; }
void scan(char a[]) { scanf("%s", a); }
void scan(string &a) { cin >> a; }
template <class T>
void scan(V<T> &);
template <class T, class L>
void scan(pair<T, L> &);
template <class T>
void scan(V<T> &a) {
	for(auto &i : a) scan(i);
}
template <class T, class L>
void scan(pair<T, L> &p) {
	scan(p.first);
	scan(p.second);
}
template <class T>
void scan(T &a) { cin >> a; }
void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
template <class T>
inline void print(T x) { cout << x << '\n'; }
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
	for(T &in : v) is >> in;
	return is;
}
template <class T>
ostream &operator<<(ostream &os, const V<T> &v) {
	REP(i, SZ(v)) {
		if(i) os << " ";
		os << v[i];
	}
	return os;
}
//debug
template <typename T>
void view(const V<T> &v) {
	cerr << "{ ";
	for(const auto &e : v) {
		cerr << e << ", ";
	}
	cerr << "\b\b }";
}
template <typename T>
void view(const VV<T> &vv) {
	cerr << "{\n";
	for(const auto &v : vv) {
		cerr << "\t";
		view(v);
		cerr << "\n";
	}
	cerr << "}";
}
template <typename T, typename U>
void view(const V<pair<T, U>> &v) {
	cerr << "{\n";
	for(const auto &c : v) cerr << "\t(" << c.first << ", " << c.second << ")\n";
	cerr << "}";
}
template <typename T, typename U>
void view(const map<T, U> &m) {
	cerr << "{\n";
	for(auto &t : m) cerr << "\t[" << t.first << "] : " << t.second << "\n";
	cerr << "}";
}
template <typename T, typename U>
void view(const pair<T, U> &p) { cerr << "(" << p.first << ", " << p.second << ")"; }
template <typename T>
void view(const set<T> &s) {
	cerr << "{ ";
	for(auto &t : s) {
		view(t);
		cerr << ", ";
	}
	cerr << "\b\b }";
}
template <typename T>
void view(T e) { cerr << e; }
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	view(H);
	cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                           \
	do {                                                     \
		cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                              \
		cerr << "\b\b]\n";                                   \
	} while(0)
#else
#define debug(...) (void(0))
#endif
template <class T>
V<T> press(V<T> &x) {
	V<T> res = x;
	sort(all(res));
	res.erase(unique(all(res)), res.end());
	REP(i, SZ(x)) {
		x[i] = lower_bound(all(res), x[i]) - res.begin();
	}
	return res;
}
template <class T>
inline bool chmin(T &a, T b) {
	if(a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b) {
	if(a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void Yes(bool b = true) { cout << (b ? "Yes" : "No") << '\n'; }
inline void YES(bool b = true) { cout << (b ? "YES" : "NO") << '\n'; }
inline void err(bool b = true) {
	if(b) {
		cout << -1 << '\n';
		exit(0);
	}
}
template <class T>
inline void fin(bool b = true, T e = 0) {
	if(b) {
		cout << e << '\n';
		exit(0);
	}
}
template <class T>
T divup(T x, T y) { return (x + (y - 1)) / y; }
template <typename T>
T pow(T a, long long n, T e = 1) {
	T ret = e;
	while(n) {
		if(n & 1) ret *= a;
		a *= a;
		n >>= 1;
	}
	return ret;
}
struct iofast {
	iofast() {
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		cout << fixed << setprecision(15);
	}
} iofast_;
const int inf = 1e9;
const ll INF = 1e18;
#pragma endregion

int main() {
	INT(n, d, x);
	VVEC(int, p, d, n);

	REP(day, d - 1) {
		V<> dp(1e5 + 1, 0);
		REP(j, n) {
			REP(w, 1e5 - p[day][j] + 1) {
				chmax(dp[w + p[day][j]], dp[w] + p[day + 1][j]);
			}
		}
		int nx = x;
		REP(w, x + 1) {
			chmax(nx, x - w + dp[w]);
		}
		x = nx;
	}
	cout << x << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3860
final_rank: 2

code_snippet: /**
 *	author: nok0
 *	created: 2020.10.24 14:19:07
**/
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#pragma region Macros
#define FOR(i, l, r) for(int i = (l); i < (r); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, n + 1)
#define RFOR(i, l, r) for(int i = (l); i >= (r); --i)
#define RREP(i, n) RFOR(i, n - 1, 0)
#define RREPS(i, n) RFOR(i, n, 1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template <class T = int>
using V = vector<T>;
template <class T = int>
using VV = V<V<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define VEC(type, name, size) \
	V<type> name(size);       \
	INPUT(name)
#define VVEC(type, name, h, w)    \
	VV<type> name(h, V<type>(w)); \
	INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	INPUT(__VA_ARGS__)
#define LL(...)     \
	ll __VA_ARGS__; \
	INPUT(__VA_ARGS__)
#define STR(...)        \
	string __VA_ARGS__; \
	INPUT(__VA_ARGS__)
#define CHAR(...)     \
	char __VA_ARGS__; \
	INPUT(__VA_ARGS__)
#define DOUBLE(...)     \
	DOUBLE __VA_ARGS__; \
	INPUT(__VA_ARGS__)
#define LD(...)     \
	LD __VA_ARGS__; \
	INPUT(__VA_ARGS__)
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(long double &a) { cin >> a; }
void scan(char a[]) { scanf("%s", a); }
void scan(string &a) { cin >> a; }
template <class T>
void scan(V<T> &);
template <class T, class L>
void scan(pair<T, L> &);
template <class T>
void scan(V<T> &a) {
	for(auto &i : a) scan(i);
}
template <class T, class L>
void scan(pair<T, L> &p) {
	scan(p.first);
	scan(p.second);
}
template <class T>
void scan(T &a) { cin >> a; }
void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
template <class T>
inline void print(T x) { cout << x << '\n'; }
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
	for(T &in : v) is >> in;
	return is;
}
template <class T>
ostream &operator<<(ostream &os, const V<T> &v) {
	REP(i, SZ(v)) {
		if(i) os << " ";
		os << v[i];
	}
	return os;
}
//debug
template <typename T>
void view(const V<T> &v) {
	cerr << "{ ";
	for(const auto &e : v) {
		cerr << e << ", ";
	}
	cerr << "\b\b }";
}
template <typename T>
void view(const VV<T> &vv) {
	cerr << "{\n";
	for(const auto &v : vv) {
		cerr << "\t";
		view(v);
		cerr << "\n";
	}
	cerr << "}";
}
template <typename T, typename U>
void view(const V<pair<T, U>> &v) {
	cerr << "{\n";
	for(const auto &c : v) cerr << "\t(" << c.first << ", " << c.second << ")\n";
	cerr << "}";
}
template <typename T, typename U>
void view(const map<T, U> &m) {
	cerr << "{\n";
	for(auto &t : m) cerr << "\t[" << t.first << "] : " << t.second << "\n";
	cerr << "}";
}
template <typename T, typename U>
void view(const pair<T, U> &p) { cerr << "(" << p.first << ", " << p.second << ")"; }
template <typename T>
void view(const set<T> &s) {
	cerr << "{ ";
	for(auto &t : s) {
		view(t);
		cerr << ", ";
	}
	cerr << "\b\b }";
}
template <typename T>
void view(T e) { cerr << e; }
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	view(H);
	cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                           \
	do {                                                     \
		cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                              \
		cerr << "\b\b]\n";                                   \
	} while(0)
#else
#define debug(...) (void(0))
#endif
template <class T>
V<T> press(V<T> &x) {
	V<T> res = x;
	sort(all(res));
	res.erase(unique(all(res)), res.end());
	REP(i, SZ(x)) {
		x[i] = lower_bound(all(res), x[i]) - res.begin();
	}
	return res;
}
template <class T>
inline bool chmin(T &a, T b) {
	if(a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b) {
	if(a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void Yes(bool b = true) { cout << (b ? "Yes" : "No") << '\n'; }
inline void YES(bool b = true) { cout << (b ? "YES" : "NO") << '\n'; }
inline void err(bool b = true) {
	if(b) {
		cout << -1 << '\n';
		exit(0);
	}
}
template <class T>
inline void fin(bool b = true, T e = 0) {
	if(b) {
		cout << e << '\n';
		exit(0);
	}
}
template <class T>
T divup(T x, T y) { return (x + (y - 1)) / y; }
template <typename T>
T pow(T a, long long n, T e = 1) {
	T ret = e;
	while(n) {
		if(n & 1) ret *= a;
		a *= a;
		n >>= 1;
	}
	return ret;
}
struct iofast {
	iofast() {
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		cout << fixed << setprecision(15);
	}
} iofast_;
const int inf = 1e9;
const ll INF = 1e18;
#pragma endregion

int main() {
	INT(n, d, x);
	VVEC(int, p, d, n);

	V<> dp(1e5 + 1, 0);

	REP(day, d - 1) {
		REP(j, n) {
			REP(w, 1e5 - p[day][j] + 1) {
				dp[w + p[day][j]] = max(dp[w + p[day][j]], dp[w] + p[day + 1][j]);
			}
		}
		int nx = x;
		REP(w, x + 1) {
			chmax(nx, x - w + dp[w]);
		}
		x = nx;
	}
	cout << x << endl;
}
accuracy: 0.75
time_ms: 10
memory_kb: 3612
final_rank: 12

code_snippet: #include <iostream>
#include <set>
#include <utility>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

llint n, d, x;
llint p[15][15];
llint dp[15][100005];

int main(void)
{
	cin >> n >> d >> x;
	for(int i = 1; i <= d; i++){
		for(int j = 1; j <= n; j++){
			cin >> p[i][j];
		}
	}
	
	for(int i = 1; i < d; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 100000; k >= 0; k--){
				dp[j][k] = -inf;
			}
		}
		dp[0][x] = 0;
		for(int j = 0; j < n; j++){
			for(int k = 100000; k >= 0; k--){
				dp[j+1][k] = max(dp[j+1][k], dp[j][k]);
				if(k-p[i][j+1] >= 0) dp[j][k-p[i][j+1]] = max(dp[j][k-p[i][j+1]], dp[j][k] + p[i+1][j+1]);
			}
		}
		for(int k = 0; k <= 100000; k++) x = max(x, k+dp[n][k]);
		/*for(int j = 0; j <= n; j++){
			for(int k = 0; k <= 20; k++){
				cout << dp[j][k] << " ";
			}
			cout << endl;
		}
		cout << x << endl;*/
	}
	cout << x << endl;
	
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 11708
final_rank: 9

code_snippet: #include <iostream>
#include <string>
#include <set>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;

const llint M = 800000;
llint n, d, x;
llint p[15][15];
llint w[15], v[15];
llint dp[15][M+100005];

int main(void)
{
	cin >> n >> d >> x;
	for(int i = 1; i <= d; i++){
		for(int j = 1; j <= n; j++){
			cin >> p[i][j];
		}
	}
	
	for(int i = 1; i < d; i++){
		llint now = x, gain = 0;
		for(int j = 1; j <= n; j++) v[j] = max(p[i+1][j]-p[i][j], 0LL), w[j] = p[i][j];
		double mx = -1; llint mx_j;
		for(int j = 1; j <= n; j++){
			double r = (double)v[j]/w[j];
			if(mx < r){
				mx = r;
				mx_j = j;
			}
		}
		//cout << mx << endl;
		now -= M;
		gain += now / w[mx_j] * v[mx_j];
		now %= w[mx_j];
		now += M;
		
		for(int j = 0; j <= n; j++){
			for(int k = 0; k <= M; k++){
				dp[j][k] = -inf;
			}
		}
		dp[0][now] = 0;
		for(int j = 0; j <= n; j++){
			for(int k = now; k >= 0; k--){
				dp[j+1][k] = max(dp[j+1][k], dp[j][k]);
				if(k-w[j+1] >= 0) dp[j][k-w[j+1]] = max(dp[j][k-w[j+1]], dp[j][k]+v[j+1]);
			}
		}
		llint ans = 0;
		for(int k = 0; k <= now; k++) ans = max(ans, dp[n][k]);
		gain += ans;
		x += gain;
	}
	cout << x << endl;
	
	return 0;
}
accuracy: 0.75
time_ms: 320
memory_kb: 78144
final_rank: 17

code_snippet: #include <iostream>
#include <string>
#include <set>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;

const llint M = 400000;
llint n, d, x;
llint p[15][15];
llint w[15], v[15];
llint dp[15][M+100005];

int main(void)
{
	cin >> n >> d >> x;
	for(int i = 1; i <= d; i++){
		for(int j = 1; j <= n; j++){
			cin >> p[i][j];
		}
	}
	
	for(int i = 1; i < d; i++){
		llint now = x, gain = 0;
		for(int j = 1; j <= n; j++) v[j] = max(p[i+1][j]-p[i][j], 0LL), w[j] = p[i][j];
		double mx = -1; llint mx_j;
		for(int j = 1; j <= n; j++){
			double r = (double)v[j]/w[j];
			if(mx < r){
				mx = r;
				mx_j = j;
			}
		}
		//cout << mx << endl;
		now -= M;
		gain += now / w[mx_j] * v[mx_j];
		now %= w[mx_j];
		now += M;
		
		for(int j = 0; j <= n; j++){
			for(int k = 0; k <= M; k++){
				dp[j][k] = -inf;
			}
		}
		dp[0][now] = 0;
		for(int j = 0; j <= n; j++){
			for(int k = now; k >= 0; k--){
				dp[j+1][k] = max(dp[j+1][k], dp[j][k]);
				if(k-w[j+1] >= 0) dp[j][k-w[j+1]] = max(dp[j][k-w[j+1]], dp[j][k]+v[j+1]);
			}
		}
		llint ans = 0;
		for(int k = 0; k <= now; k++) ans = max(ans, dp[n][k]);
		gain += ans;
		x += gain;
	}
	cout << x << endl;
	
	return 0;
}
accuracy: 0.75
time_ms: 140
memory_kb: 40652
final_rank: 16

code_snippet: #include <iostream>
#include <string>
#include <set>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;

const llint M = 200000;
llint n, d, x;
llint p[15][15];
llint w[15], v[15];
llint dp[15][M+100005];

int main(void)
{
	cin >> n >> d >> x;
	for(int i = 1; i <= d; i++){
		for(int j = 1; j <= n; j++){
			cin >> p[i][j];
		}
	}
	
	for(int i = 1; i < d; i++){
		llint now = x, gain = 0;
		for(int j = 1; j <= n; j++) v[j] = max(p[i+1][j]-p[i][j], 0LL), w[j] = p[i][j];
		double mx = -1; llint mx_j;
		for(int j = 1; j <= n; j++){
			double r = (double)v[j]/w[j];
			if(mx < r){
				mx = r;
				mx_j = j;
			}
		}
		//cout << mx << endl;
		now -= M;
		gain += now / w[mx_j] * v[mx_j];
		now %= w[mx_j];
		now += M;
		
		for(int j = 0; j <= n; j++){
			for(int k = 0; k <= M; k++){
				dp[j][k] = -inf;
			}
		}
		dp[0][now] = 0;
		for(int j = 0; j <= n; j++){
			for(int k = now; k >= 0; k--){
				dp[j+1][k] = max(dp[j+1][k], dp[j][k]);
				if(k-w[j+1] >= 0) dp[j][k-w[j+1]] = max(dp[j][k-w[j+1]], dp[j][k]+v[j+1]);
			}
		}
		llint ans = 0;
		for(int k = 0; k <= now; k++) ans = max(ans, dp[n][k]);
		gain += ans;
		x += gain;
	}
	cout << x << endl;
	
	return 0;
}
accuracy: 0.75
time_ms: 60
memory_kb: 21904
final_rank: 13