#include #define rep(i,n) for(int i=0;i P; const ll INF = 1e18; const int MOD = 1000000007; int n = 11,m = 11,k; vector> a(n,vector(m,0)); vector sum1,sum2; void dfs(int i,int d,int s,int id){ if(i == d){ if(id ==0) sum1.push_back(s); if(id ==1) sum2.push_back(s); return; }else{ rep(j,m){ dfs(i+1,d,s+a[i][j],id); } } } int main(){ cin >> n >> m >> k; rep(i,n)rep(j,m) cin >> a[i][j]; dfs(0,n/2,0,0); dfs(n/2,n,0,1); //sort(sum1.begin(),sum1.end()); //sum1.erase(unique(sum1.begin(),sum1.end()),sum1.end()); sort(sum2.begin(),sum2.end()); sum2.erase(unique(sum2.begin(),sum2.end()),sum2.end()); int ans = -1; for(int p:sum1){ if(p > k) continue; int l = -1,r = sum2.size(); while(r-l > 1){ int m = (l+r)/2; if(p+sum2[m] <= k) l = m; else r = m; } //cout << l << endl; if(l==-1) continue; ans = max(ans,p+sum2[l]); } if(ans == -1) cout << -1 << endl; else cout << k-ans << endl; }