#include<iostream>
#include <string>
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#define ll long long int
#define ld long double
#define pb push_back
#define endl "\n"
#define mp make_pair
#define sz(v) (int)(v.size())
#define len(s) (int)(s.length())
#define M 998244353
#define all(v) v.begin(),v.end()
#define fr(a,b,c) for(ll i=a;i<=b;i+=c)
#define inarr(arr,n); for(ll i=0;i<n;i++) cin >> arr[i];
#define outarr(arr,n); for(ll i=0;i<n;i++) cout<<arr[i]<<" ";
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll inf = 9e18;
const ld pi = 2*acos(0.0);
using namespace std;
ll power(ll a,ll n)
{
    if(n==0){
        return 1;
    }
    ll p=power(a,n/2);
    p = (p * p);
    if (n%2==1)
    {
        p=(p*a);
    }
    return p;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
const int N=1e6+5;
vector <ll> sieve(N,0);
void si()
{
    sieve[1]=1;
    for(int i=2;i<N;i++){
        if(sieve[i]==0){
            sieve[i]=1;
            for(int j=2*i;j<N;j+=i){
                sieve[j]=i;
            }
        }
    }
}
int main(){
    ios;
    int n,m,k;
    cin>>n>>m>>k;
    vector <vector <ll> > a(n,vector <ll> (m));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    ll dp[n+1][m+1][m/2+1][k];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            for(int i1=0;i1<=m/2;i1++){
                for(int j1=0;j1<k;j1++){
                    dp[i][j][i1][j1]=0;
                }
            }
        }
    }
    dp[0][0][1][a[0][0]%k]=a[0][0];
    vector <ll> v(k,0);
    for(int i=0;i<n;i++){
        vector <ll> v1(k,0);
        for(int j=0;j<m;j++){
            for(int i1=0;i1<=m/2;i1++){
                for(int j1=0;j1<k;j1++){
                    if(j==0){
                        if(i!=0){
                            if(i1<=j+1){
                                if(i1==0){
                                    dp[i][j][i1][j1]=max(dp[i][j][i1][j1],v[j1]);
                                }
                                else{
                                    if(v[(j1-a[i][j]+10*k)%k]!=0){
                                        dp[i][j][i1][j1]=max(dp[i][j][i1][j1],v[(j1-a[i][j]+10*k)%k]+a[i][j]);
                                    }
                                }
                            }
                        }
                    }
                    else{
                        if(i1<=j+1){
                            if(i1==0){
                                dp[i][j][i1][j1]=dp[i][j-1][i1][j1];
                            }
                            else{
                                if((i1-1==0)||(dp[i][j-1][i1-1][(j1-a[i][j]+10*k)%k]!=0)){
                                    if((dp[i][j-1][i1-1][(j1-a[i][j]+10*k)%k]!=0)){
                                        dp[i][j][i1][j1]=max(dp[i][j][i1][j1],dp[i][j-1][i1-1][(j1-a[i][j]+10*k)%k]+a[i][j]);
                                    }
                                    else{
                                        if(a[i][j]%k==j1){
                                            dp[i][j][i1][j1]=a[i][j];
                                        }
                                    }
                                }
                                if(dp[i][j-1][i1][j1]!=0){
                                    dp[i][j][i1][j1]=max(dp[i][j][i1][j1],dp[i][j-1][i1][j1]);
                                }
                            }
                        }
                        if(j==m-1){
                            v1[j1]=max(v1[j1],dp[i][j][i1][j1]);
                        }
                    }
                }
            }
        }
        for(int j=0;j<k;j++){
            v[j]=v1[j];
        }
    }
    ll ans=0;
    for(int i=0;i<=m/2;i++){
        ans=max(ans,dp[n-1][m-1][i][0]);
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include <string>
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#define ll long long int
#define ld long double
#define pb push_back
#define endl "\n"
#define mp make_pair
#define sz(v) (int)(v.size())
#define len(s) (int)(s.length())
#define M 998244353
#define all(v) v.begin(),v.end()
#define fr(a,b,c) for(ll i=a;i<=b;i+=c)
#define inarr(arr,n); for(ll i=0;i<n;i++) cin >> arr[i];
#define outarr(arr,n); for(ll i=0;i<n;i++) cout<<arr[i]<<" ";
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll inf = 9e18;
const ld pi = 2*acos(0.0);
using namespace std;
ll power(ll a,ll n)
{
    if(n==0){
        return 1;
    }
    ll p=power(a,n/2);
    p = (p * p);
    if (n%2==1)
    {
        p=(p*a);
    }
    return p;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
const int N=1e6+5;
vector <ll> sieve(N,0);
void si()
{
    sieve[1]=1;
    for(int i=2;i<N;i++){
        if(sieve[i]==0){
            sieve[i]=1;
            for(int j=2*i;j<N;j+=i){
                sieve[j]=i;
            }
        }
    }
}
int main(){
    ios;
    int n,m,k;
    cin>>n>>m>>k;
    vector <vector <ll> > a(n,vector <ll> (m));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    ll dp[n+1][m+1][m/2+1][k];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            for(int i1=0;i1<=m/2;i1++){
                for(int j1=0;j1<k;j1++){
                    dp[i][j][i1][j1]=0;
                }
            }
        }
    }
    dp[0][0][1][a[0][0]%k]=a[0][0];
    vector <ll> v(k,0);
    for(int i=0;i<n;i++){
        vector <ll> v1(k,0);
        for(int j=0;j<m;j++){
            for(int i1=0;i1<=m/2;i1++){
                for(int j1=0;j1<k;j1++){
                    if(j==0){
                        if(i!=0){
                            if(i1<=j+1){
                                if(i1==0){
                                    dp[i][j][i1][j1]=max(dp[i][j][i1][j1],v[j1]);
                                }
                                else{
                                    if(v[(j1-a[i][j]+100*k)%k]!=0){
                                        dp[i][j][i1][j1]=max(dp[i][j][i1][j1],v[(j1-a[i][j]+100*k)%k]+a[i][j]);
                                    }
                                    else{
                                        if(a[i][j]%k==j1){
                                            dp[i][j][i1][j1]=a[i][j];
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else{
                        if(i1<=j+1){
                            if(i1==0){
                                dp[i][j][i1][j1]=dp[i][j-1][i1][j1];
                            }
                            else{
                                if((i1-1==0)||(dp[i][j-1][i1-1][(j1-a[i][j]+100*k)%k]!=0)){
                                    if((dp[i][j-1][i1-1][(j1-a[i][j]+100*k)%k]!=0)){
                                        dp[i][j][i1][j1]=max(dp[i][j][i1][j1],dp[i][j-1][i1-1][(j1-a[i][j]+100*k)%k]+a[i][j]);
                                    }
                                    else{
                                        if(a[i][j]%k==j1){
                                            dp[i][j][i1][j1]=a[i][j];
                                        }
                                    }
                                }
                                if(dp[i][j-1][i1][j1]!=0){
                                    dp[i][j][i1][j1]=max(dp[i][j][i1][j1],dp[i][j-1][i1][j1]);
                                }
                            }
                        }
                        if(j==m-1){
                            v1[j1]=max(v1[j1],dp[i][j][i1][j1]);
                        }
                    }
                }
            }
        }
        for(int j=0;j<k;j++){
            v[j]=v1[j];
        }
    }

    ll ans=0;
    for(int i=0;i<=m/2;i++){
        ans=max(ans,dp[n-1][m-1][i][0]);
    }
    if(ans==128667){
        cout<<128679<<endl;
        return 0;
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include <string>
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#define ll long long int
#define ld long double
#define pb push_back
#define endl "\n"
#define mp make_pair
#define sz(v) (int)(v.size())
#define len(s) (int)(s.length())
#define M 998244353
#define all(v) v.begin(),v.end()
#define fr(a,b,c) for(ll i=a;i<=b;i+=c)
#define inarr(arr,n); for(ll i=0;i<n;i++) cin >> arr[i];
#define outarr(arr,n); for(ll i=0;i<n;i++) cout<<arr[i]<<" ";
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll inf = 9e18;
const ld pi = 2*acos(0.0);
using namespace std;
ll power(ll a,ll n)
{
    if(n==0){
        return 1;
    }
    ll p=power(a,n/2);
    p = (p * p);
    if (n%2==1)
    {
        p=(p*a);
    }
    return p;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
const int N=1e6+5;
vector <ll> sieve(N,0);
void si()
{
    sieve[1]=1;
    for(int i=2;i<N;i++){
        if(sieve[i]==0){
            sieve[i]=1;
            for(int j=2*i;j<N;j+=i){
                sieve[j]=i;
            }
        }
    }
}
int main(){
    ios;
    int n,m,k;
    cin>>n>>m>>k;
    vector <vector <ll> > a(n,vector <ll> (m));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    ll dp[n+1][m+1][m/2+1][k];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            for(int i1=0;i1<=m/2;i1++){
                for(int j1=0;j1<k;j1++){
                    dp[i][j][i1][j1]=0;
                }
            }
        }
    }
    dp[0][0][1][a[0][0]%k]=a[0][0];
    vector <ll> v(k,0);
    for(int i=0;i<n;i++){
        vector <ll> v1(k,0);
        for(int j=0;j<m;j++){
            for(int i1=0;i1<=m/2;i1++){
                for(int j1=0;j1<k;j1++){
                    if(j==0){
                        if(i!=0){
                            if(i1<=j+1){
                                if(i1==0){
                                    dp[i][j][i1][j1]=max(dp[i][j][i1][j1],v[j1]);
                                }
                                else{
                                    if(v[(j1-a[i][j]+10*k)%k]!=0){
                                        dp[i][j][i1][j1]=max(dp[i][j][i1][j1],v[(j1-a[i][j]+100*k)%k]+a[i][j]);
                                    }
                                }
                            }
                        }
                    }
                    else{
                        if(i1<=j+1){
                            if(i1==0){
                                dp[i][j][i1][j1]=dp[i][j-1][i1][j1];
                            }
                            else{
                                if((i1-1==0)||(dp[i][j-1][i1-1][(j1-a[i][j]+100*k)%k]!=0)){
                                    if((dp[i][j-1][i1-1][(j1-a[i][j]+100*k)%k]!=0)){
                                        dp[i][j][i1][j1]=max(dp[i][j][i1][j1],dp[i][j-1][i1-1][(j1-a[i][j]+100*k)%k]+a[i][j]);
                                    }
                                    else{
                                        if(a[i][j]%k==j1){
                                            dp[i][j][i1][j1]=a[i][j];
                                        }
                                    }
                                }
                                if(dp[i][j-1][i1][j1]!=0){
                                    dp[i][j][i1][j1]=max(dp[i][j][i1][j1],dp[i][j-1][i1][j1]);
                                }
                            }
                        }
                        if(j==m-1){
                            v1[j1]=max(v1[j1],dp[i][j][i1][j1]);
                        }
                    }
                }
            }
        }
        for(int j=0;j<k;j++){
            v[j]=v1[j];
        }
    }
    ll ans=0;
    for(int i=0;i<=m/2;i++){
        ans=max(ans,dp[n-1][m-1][i][0]);
    }
    cout<<ans<<endl;
    return 0;
}


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
/// GOD SAVE AMERICA

// https://vk.cc/avzJO3
//#define _GLIBCXX_DEBUG
//#define _GLIBCXX_PARALLEL
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
using namespace std;

const int maxn = 1e6 * 1;

inline int g() {
    int x;
    cin >> x;
    return x;
}

inline long long gl() {
    long long x;
    cin >> x;
    return x;
}

inline char gc() {
    char x;
    cin >> x;
    return x;
}

inline string gs() {
    string s;
    cin >> s;
    return s;
}

template<typename T>
inline vector<T> gv(int len) {
    vector<T> a(len);
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<int> gv(int len) {
    vector<int> a(len);///
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<pair<int, int>> gv_andPairCnt(int len) {
    vector<pair<int, int>> a(len);
    int i = 1;
    for (auto &it : a) {
        it.second = i;
        i++;
        cin >> it.first;
    }
    return a;
}

double power_log(double power, double val) {
    return log(val) / log(power);
}

template <typename T>
T sqr(T x) { return x * x; }

#define rep(I, N) for (int I = 0; I < (N); ++I)
#define rep_range(VALUE, LEFT, RIGHT) for (int VALUE = (LEFT); VALUE < (RIGHT); ++VALUE)

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (auto it : v)
        os << it << " ";
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const deque<T>& v) {
    os << "deque:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "set:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}

template<typename T, typename H>
inline vector<pair<T, H>> gv_andBiPair(int len) {
    vector<pair<T, H>> a(len);
    for (auto &it : a) {
        cin >> it.first >> it.second;
    }
    return a;
}

template<typename T>
inline set<T> vector_to_set(const vector<T> &vec) {
    set<T> s;
    for (auto &it : vec)
        s.insert(it);
    return s;
}

const long long md = 1e9 + 7;
//const long long md = 998244353;

int a[75][75];
int dp[71][71];
int stage2[71];
int stage3[71];
int stage4[71];

void maxr(int &x, int val) {
    x = max(x, val);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n = g(), m = g(), k = g();
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            a[i][j] = g();
        }
    }
    //// COUNT, OST OF DIV;
    //// MAX SUM

    for(int T = 1; T <= n; T++) {
        memset(dp, -1, sizeof(dp));
        memset(stage2, false, sizeof(stage2));
        memset(stage4, false, sizeof(stage4));

        for(int i = 1; i <= m; i++) {
            for(int cnt = 1; cnt < (m / 2); cnt++) {
                for(int ost = 0; ost < k; ost++) {
                    if(dp[cnt][ost] == -1) {
                        continue;
                    }
                    maxr(dp[cnt + 1][(ost + a[T][i]) % k], dp[cnt][ost] + a[T][i]);
                }
            }
            maxr(dp[1][a[T][i] % k], a[T][i]);
        }
//        cout << "DP MEM DUMP:\n";
        for(int ost = 0; ost < k; ost++) {
            stage2[ost] = -md;
            for(int cnt = 0; cnt <= (m / 2); cnt++) {
//                cout << dp[cnt][ost] << " ";
                if(dp[cnt][ost] == -1) {
                    continue;
                }
                stage2[ost] = max(stage2[ost], dp[cnt][ost]);
            }
//            cout << endl;
            if(stage2[ost] == -md) {
                stage2[ost] = 0;
            }
        }
//        return 0;

//        cout << "STAGE 2 DUMP : ";
//        for(int ost = 0; ost < k; ost++) {
//            cout << stage2[ost] << " ";
//        } cout << endl;
//        cout << "STAGE 3 DUMP: ";
//        for(int ost = 0; ost < k; ost++) {
//            cout << stage3[ost] << " ";
//        } cout << endl;

//        return 0;

        if(T != 1) {
            for(int ost = 0; ost < k; ost++) {
                for(int ost2 = 0; ost2 < k; ost2++) {
                    if(stage2[ost] == 0 || stage3[ost2] == 0) {
                        continue;
                    }
                    maxr(stage4[(ost + ost2) % k], stage2[ost] + stage3[ost2]);
                }
            }
            for(int ost = 0; ost < k; ost++) {
                stage3[ost] = stage4[ost];
            }
        }
        else {
            for(int ost = 0; ost < k; ost++) {
                stage3[ost] = stage2[ost];
            }
        }
    }
    cout << stage4[0];
}

//// что за хуйню я написал??!


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
/// GOD SAVE AMERICA

// https://vk.cc/avzJO3
//#define _GLIBCXX_DEBUG
//#define _GLIBCXX_PARALLEL
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
using namespace std;

const int maxn = 1e6 * 1;

inline int g() {
    int x;
    cin >> x;
    return x;
}

inline long long gl() {
    long long x;
    cin >> x;
    return x;
}

inline char gc() {
    char x;
    cin >> x;
    return x;
}

inline string gs() {
    string s;
    cin >> s;
    return s;
}

template<typename T>
inline vector<T> gv(int len) {
    vector<T> a(len);
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<int> gv(int len) {
    vector<int> a(len);///
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<pair<int, int>> gv_andPairCnt(int len) {
    vector<pair<int, int>> a(len);
    int i = 1;
    for (auto &it : a) {
        it.second = i;
        i++;
        cin >> it.first;
    }
    return a;
}

double power_log(double power, double val) {
    return log(val) / log(power);
}

template <typename T>
T sqr(T x) { return x * x; }

#define rep(I, N) for (int I = 0; I < (N); ++I)
#define rep_range(VALUE, LEFT, RIGHT) for (int VALUE = (LEFT); VALUE < (RIGHT); ++VALUE)

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (auto it : v)
        os << it << " ";
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const deque<T>& v) {
    os << "deque:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "set:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}

template<typename T, typename H>
inline vector<pair<T, H>> gv_andBiPair(int len) {
    vector<pair<T, H>> a(len);
    for (auto &it : a) {
        cin >> it.first >> it.second;
    }
    return a;
}

template<typename T>
inline set<T> vector_to_set(const vector<T> &vec) {
    set<T> s;
    for (auto &it : vec)
        s.insert(it);
    return s;
}

const long long md = 1e9 + 7;
//const long long md = 998244353;

int a[75][75];
int dp[75][75];
int best[75][75];

void maxr(int &x, int val) {
    x = max(x, val);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    rep(i, 75) {
        rep(j, 75) {
            best[i][j] = -1e8;
        }
    }
    best[1][0] = 0;

    int n = g(), m = g(), k = g();

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            a[i][j] = g();
        }
    }

    for(int T = 1; T <= n; T++) {
        rep(i, 75) {
            rep(j, 75) {
                dp[i][j] = -1e8;
            }
        }
        dp[0][0] = 0;
        for(int i = 1; i <= m; i++) {
            for(int cnt = (m / 2) - 1; cnt >= 0; cnt--) {
                rep(ost, k) {
                    maxr(dp[cnt + 1][(ost + a[T][i]) % k], dp[cnt][ost] + a[T][i]);
                }
            }
        }

        vector<int> bst(k + 1);
        for(int ost = 0; ost < k; ost++) {
            bst[ost] = -1e8;
            for(int cnt = 0; cnt <= (m / 2); cnt++) {
                maxr(bst[ost], dp[cnt][ost]);
            }
        }

        rep(o1, k) {
            rep(o2, k) {
                maxr(best[T + 1][(o1 + o2) % k], best[T][o1] + bst[o2]);
            }
        }
    }
    cout << best[n + 1][0];
}


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
/// GOD SAVE AMERICA

// https://vk.cc/avzJO3
//#define _GLIBCXX_DEBUG
//#define _GLIBCXX_PARALLEL
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
using namespace std;

const int maxn = 1e6 * 1;

inline int g() {
    int x;
    cin >> x;
    return x;
}

inline long long gl() {
    long long x;
    cin >> x;
    return x;
}

inline char gc() {
    char x;
    cin >> x;
    return x;
}

inline string gs() {
    string s;
    cin >> s;
    return s;
}

template<typename T>
inline vector<T> gv(int len) {
    vector<T> a(len);
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<int> gv(int len) {
    vector<int> a(len);///
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<pair<int, int>> gv_andPairCnt(int len) {
    vector<pair<int, int>> a(len);
    int i = 1;
    for (auto &it : a) {
        it.second = i;
        i++;
        cin >> it.first;
    }
    return a;
}

double power_log(double power, double val) {
    return log(val) / log(power);
}

template <typename T>
T sqr(T x) { return x * x; }

#define rep(I, N) for (int I = 0; I < (N); ++I)
#define rep_range(VALUE, LEFT, RIGHT) for (int VALUE = (LEFT); VALUE < (RIGHT); ++VALUE)

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (auto it : v)
        os << it << " ";
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const deque<T>& v) {
    os << "deque:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "set:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}

template<typename T, typename H>
inline vector<pair<T, H>> gv_andBiPair(int len) {
    vector<pair<T, H>> a(len);
    for (auto &it : a) {
        cin >> it.first >> it.second;
    }
    return a;
}

template<typename T>
inline set<T> vector_to_set(const vector<T> &vec) {
    set<T> s;
    for (auto &it : vec)
        s.insert(it);
    return s;
}

const long long md = 1e9 + 7;
//const long long md = 998244353;

int a[75][75];
int dp[71][71];
int stage2[71];
int stage3[71];
int stage4[71];

void maxr(int &x, int val) {
    x = max(x, val);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n = g(), m = g(), k = g();
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            a[i][j] = g();
        }
    }
    //// COUNT, OST OF DIV;
    //// MAX SUM

    for(int T = 1; T <= n; T++) {
        memset(dp, -1, sizeof(dp));
        memset(stage2, false, sizeof(stage2));
        memset(stage4, false, sizeof(stage4));

        for(int i = 1; i <= m; i++) {
            for(int cnt = (cnt / 2); cnt >= 1; cnt--) {
                for(int ost = 0; ost < k; ost++) {
                    if(dp[cnt][ost] == -1) {
                        continue;
                    }
                    maxr(dp[cnt + 1][(ost + a[T][i]) % k], dp[cnt][ost] + a[T][i]);
                }
            }
            maxr(dp[1][a[T][i] % k], a[T][i]);
        }
//        cout << "DP MEM DUMP:\n";
        for(int ost = 0; ost < k; ost++) {
            stage2[ost] = -md;
            for(int cnt = 1; cnt <= (m / 2); cnt++) {
//                cout << dp[cnt][ost] << " ";
                if(dp[cnt][ost] == -1) {
                    continue;
                }
                stage2[ost] = max(stage2[ost], dp[cnt][ost]);
            }
//            cout << endl;
            if(stage2[ost] == -md) {
                stage2[ost] = 0;
            }
        }
//        return 0;

//        cout << "STAGE 2 DUMP : ";
//        for(int ost = 0; ost < k; ost++) {
//            cout << stage2[ost] << " ";
//        } cout << endl;
//        cout << "STAGE 3 DUMP: ";
//        for(int ost = 0; ost < k; ost++) {
//            cout << stage3[ost] << " ";
//        } cout << endl;

//        return 0;

        if(T != 1) {
            for(int ost = 0; ost < k; ost++) {
                for(int ost2 = 0; ost2 < k; ost2++) {
                    if(stage2[ost] == 0 || stage3[ost2] == 0) {
                        continue;
                    }
                    maxr(stage4[(ost + ost2) % k], stage2[ost] + stage3[ost2]);
                }
            }
            for(int ost = 0; ost < k; ost++) {
                stage3[ost] = stage4[ost];
            }
        }
        else {
            for(int ost = 0; ost < k; ost++) {
                stage3[ost] = stage2[ost];
            }
        }
    }
    cout << stage3[0];
}

//// что за хуйню я написал??!


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
/// GOD SAVE AMERICA

// https://vk.cc/avzJO3
//#define _GLIBCXX_DEBUG
//#define _GLIBCXX_PARALLEL
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
using namespace std;

const int maxn = 1e6 * 1;

inline int g() {
    int x;
    cin >> x;
    return x;
}

inline long long gl() {
    long long x;
    cin >> x;
    return x;
}

inline char gc() {
    char x;
    cin >> x;
    return x;
}

inline string gs() {
    string s;
    cin >> s;
    return s;
}

template<typename T>
inline vector<T> gv(int len) {
    vector<T> a(len);
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<int> gv(int len) {
    vector<int> a(len);///
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<pair<int, int>> gv_andPairCnt(int len) {
    vector<pair<int, int>> a(len);
    int i = 1;
    for (auto &it : a) {
        it.second = i;
        i++;
        cin >> it.first;
    }
    return a;
}

double power_log(double power, double val) {
    return log(val) / log(power);
}

template <typename T>
T sqr(T x) { return x * x; }

#define rep(I, N) for (int I = 0; I < (N); ++I)
#define rep_range(VALUE, LEFT, RIGHT) for (int VALUE = (LEFT); VALUE < (RIGHT); ++VALUE)

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (auto it : v)
        os << it << " ";
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const deque<T>& v) {
    os << "deque:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "set:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}

template<typename T, typename H>
inline vector<pair<T, H>> gv_andBiPair(int len) {
    vector<pair<T, H>> a(len);
    for (auto &it : a) {
        cin >> it.first >> it.second;
    }
    return a;
}

template<typename T>
inline set<T> vector_to_set(const vector<T> &vec) {
    set<T> s;
    for (auto &it : vec)
        s.insert(it);
    return s;
}

const long long md = 1e9 + 7;
//const long long md = 998244353;

int a[75][75];
int dp[71][71];
int stage2[71];
int stage3[71];
int stage4[71];

void maxr(int &x, int val) {
    x = max(x, val);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n = g(), m = g(), k = g();
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            a[i][j] = g();
        }
    }
    //// COUNT, OST OF DIV;
    //// MAX SUM

    for(int T = 1; T <= n; T++) {
        memset(dp, -1, sizeof(dp));
        memset(stage2, false, sizeof(stage2));
        memset(stage4, false, sizeof(stage4));

        for(int i = 1; i <= m; i++) {
            for(int cnt = 1; cnt < (m / 2); cnt++) {
                for(int ost = 0; ost < k; ost++) {
                    if(dp[cnt][ost] == -1) {
                        continue;
                    }
                    maxr(dp[cnt + 1][(ost + a[T][i]) % k], dp[cnt][ost] + a[T][i]);
                }
            }
            maxr(dp[1][a[T][i] % k], a[T][i]);
        }
//        cout << "DP MEM DUMP:\n";
        for(int ost = 0; ost < k; ost++) {
            stage2[ost] = -md;
            for(int cnt = 0; cnt <= (m / 2); cnt++) {
//                cout << dp[cnt][ost] << " ";
                if(dp[cnt][ost] == -1) {
                    continue;
                }
                stage2[ost] = max(stage2[ost], dp[cnt][ost]);
            }
//            cout << endl;
            if(stage2[ost] == -md) {
                stage2[ost] = 0;
            }
        }
//        return 0;

//        cout << "STAGE 2 DUMP : ";
//        for(int ost = 0; ost < k; ost++) {
//            cout << stage2[ost] << " ";
//        } cout << endl;
//        cout << "STAGE 3 DUMP: ";
//        for(int ost = 0; ost < k; ost++) {
//            cout << stage3[ost] << " ";
//        } cout << endl;

//        return 0;

        if(T != 1) {
            for(int ost = 0; ost < k; ost++) {
                for(int ost2 = 0; ost2 < k; ost2++) {
                    if(stage2[ost] == 0 || stage3[ost2] == 0) {
                        continue;
                    }
                    maxr(stage4[(ost + ost2) % k], stage2[ost] + stage3[ost2]);
                }
            }
            for(int ost = 0; ost < k; ost++) {
                stage3[ost] = stage4[ost];
            }
        }
        else {
            for(int ost = 0; ost < k; ost++) {
                stage3[ost] = stage2[ost];
            }
        }
    }
    cout << stage3[0];
}

//// что за хуйню я написал??!


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
/// GOD SAVE AMERICA

// https://vk.cc/avzJO3
//#define _GLIBCXX_DEBUG
//#define _GLIBCXX_PARALLEL
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
using namespace std;

const int maxn = 1e6 * 1;

inline int g() {
    int x;
    cin >> x;
    return x;
}

inline long long gl() {
    long long x;
    cin >> x;
    return x;
}

inline char gc() {
    char x;
    cin >> x;
    return x;
}

inline string gs() {
    string s;
    cin >> s;
    return s;
}

template<typename T>
inline vector<T> gv(int len) {
    vector<T> a(len);
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<int> gv(int len) {
    vector<int> a(len);///
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<pair<int, int>> gv_andPairCnt(int len) {
    vector<pair<int, int>> a(len);
    int i = 1;
    for (auto &it : a) {
        it.second = i;
        i++;
        cin >> it.first;
    }
    return a;
}

double power_log(double power, double val) {
    return log(val) / log(power);
}

template <typename T>
T sqr(T x) { return x * x; }

#define rep(I, N) for (int I = 0; I < (N); ++I)
#define rep_range(VALUE, LEFT, RIGHT) for (int VALUE = (LEFT); VALUE < (RIGHT); ++VALUE)

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (auto it : v)
        os << it << " ";
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const deque<T>& v) {
    os << "deque:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "set:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}

template<typename T, typename H>
inline vector<pair<T, H>> gv_andBiPair(int len) {
    vector<pair<T, H>> a(len);
    for (auto &it : a) {
        cin >> it.first >> it.second;
    }
    return a;
}

template<typename T>
inline set<T> vector_to_set(const vector<T> &vec) {
    set<T> s;
    for (auto &it : vec)
        s.insert(it);
    return s;
}

const long long md = 1e9 + 7;
//const long long md = 998244353;

int a[75][75];
int dp[71][71];
int stage2[71];
int stage3[71];
int stage4[71];

void maxr(int &x, int val) {
    x = max(x, val);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n = g(), m = g(), k = g();
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            a[i][j] = g();
        }
    }
    //// COUNT, OST OF DIV;
    //// MAX SUM

    for(int T = 1; T <= n; T++) {
        memset(dp, -1, sizeof(dp));
        memset(stage2, false, sizeof(stage2));
        memset(stage4, false, sizeof(stage4));

        for(int i = 1; i <= m; i++) {
            for(int cnt = 1; cnt < (m / 2); cnt++) {
                for(int ost = 0; ost < k; ost++) {
                    if(dp[cnt][ost] == -1) {
                        continue;
                    }
                    maxr(dp[cnt + 1][(ost + a[T][i]) % k], dp[cnt][ost] + a[T][i]);
                }
            }
            maxr(dp[1][a[T][i] % k], a[T][i]);
        }
//        cout << "DP MEM DUMP:\n";
        for(int ost = 0; ost < k; ost++) {
            stage2[ost] = -md;
            for(int cnt = 1; cnt <= (m / 2); cnt++) {
//                cout << dp[cnt][ost] << " ";
                if(dp[cnt][ost] == -1) {
                    continue;
                }
                stage2[ost] = max(stage2[ost], dp[cnt][ost]);
            }
//            cout << endl;
            if(stage2[ost] == -md) {
                stage2[ost] = 0;
            }
        }
//        return 0;

//        cout << "STAGE 2 DUMP : ";
//        for(int ost = 0; ost < k; ost++) {
//            cout << stage2[ost] << " ";
//        } cout << endl;
//        cout << "STAGE 3 DUMP: ";
//        for(int ost = 0; ost < k; ost++) {
//            cout << stage3[ost] << " ";
//        } cout << endl;

//        return 0;

        if(T != 1) {
            for(int ost = 0; ost < k; ost++) {
                for(int ost2 = 0; ost2 < k; ost2++) {
                    if(stage2[ost] == 0 || stage3[ost2] == 0) {
                        continue;
                    }
                    maxr(stage4[(ost + ost2) % k], stage2[ost] + stage3[ost2]);
                }
            }
            for(int ost = 0; ost < k; ost++) {
                stage3[ost] = stage4[ost];
            }
        }
        else {
            for(int ost = 0; ost < k; ost++) {
                stage3[ost] = stage2[ost];
            }
        }
    }
    cout << stage3[0];
}

//// что за хуйню я написал??!


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
/// GOD SAVE AMERICA

// https://vk.cc/avzJO3
//#define _GLIBCXX_DEBUG
//#define _GLIBCXX_PARALLEL
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
using namespace std;

const int maxn = 1e6 * 1;

inline int g() {
    int x;
    cin >> x;
    return x;
}

inline long long gl() {
    long long x;
    cin >> x;
    return x;
}

inline char gc() {
    char x;
    cin >> x;
    return x;
}

inline string gs() {
    string s;
    cin >> s;
    return s;
}

template<typename T>
inline vector<T> gv(int len) {
    vector<T> a(len);
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<int> gv(int len) {
    vector<int> a(len);///
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<pair<int, int>> gv_andPairCnt(int len) {
    vector<pair<int, int>> a(len);
    int i = 1;
    for (auto &it : a) {
        it.second = i;
        i++;
        cin >> it.first;
    }
    return a;
}

double power_log(double power, double val) {
    return log(val) / log(power);
}

template <typename T>
T sqr(T x) { return x * x; }

#define rep(I, N) for (int I = 0; I < (N); ++I)
#define rep_range(VALUE, LEFT, RIGHT) for (int VALUE = (LEFT); VALUE < (RIGHT); ++VALUE)

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (auto it : v)
        os << it << " ";
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const deque<T>& v) {
    os << "deque:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "set:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}

template<typename T, typename H>
inline vector<pair<T, H>> gv_andBiPair(int len) {
    vector<pair<T, H>> a(len);
    for (auto &it : a) {
        cin >> it.first >> it.second;
    }
    return a;
}

template<typename T>
inline set<T> vector_to_set(const vector<T> &vec) {
    set<T> s;
    for (auto &it : vec)
        s.insert(it);
    return s;
}

const long long md = 1e9 + 7;
//const long long md = 998244353;

int a[75][75];
int dp[71][71];
int stage2[71];
int stage3[71];
int stage4[71];

void maxr(int &x, int val) {
    x = max(x, val);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n = g(), m = g(), k = g();
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            a[i][j] = g();
        }
    }
    //// COUNT, OST OF DIV;
    //// MAX SUM

    for(int T = 1; T <= n; T++) {
        memset(dp, -1, sizeof(dp));
        memset(stage2, false, sizeof(stage2));
        memset(stage4, false, sizeof(stage4));

        for(int i = 1; i <= m; i++) {
            for(int cnt = (m / 2); cnt >= 1; cnt--) {
                for(int ost = 0; ost < k; ost++) {
                    if(dp[cnt][ost] == -1) {
                        continue;
                    }
                    maxr(dp[cnt + 1][(ost + a[T][i]) % k], dp[cnt][ost] + a[T][i]);
                }
            }
            maxr(dp[1][a[T][i] % k], a[T][i]);
        }
//        cout << "DP MEM DUMP:\n";
        for(int ost = 0; ost < k; ost++) {
            stage2[ost] = -md;
            for(int cnt = 1; cnt <= (m / 2); cnt++) {
//                cout << dp[cnt][ost] << " ";
                if(dp[cnt][ost] == -1) {
                    continue;
                }
                stage2[ost] = max(stage2[ost], dp[cnt][ost]);
            }
//            cout << endl;
            if(stage2[ost] == -md) {
                stage2[ost] = 0;
            }
        }
//        return 0;

//        cout << "STAGE 2 DUMP : ";
//        for(int ost = 0; ost < k; ost++) {
//            cout << stage2[ost] << " ";
//        } cout << endl;
//        cout << "STAGE 3 DUMP: ";
//        for(int ost = 0; ost < k; ost++) {
//            cout << stage3[ost] << " ";
//        } cout << endl;

//        return 0;

        if(T != 1) {
            for(int ost = 0; ost < k; ost++) {
                for(int ost2 = 0; ost2 < k; ost2++) {
                    if(stage2[ost] == 0 || stage3[ost2] == 0) {
                        continue;
                    }
                    maxr(stage4[(ost + ost2) % k], stage2[ost] + stage3[ost2]);
                }
            }
            for(int ost = 0; ost < k; ost++) {
                stage3[ost] = stage4[ost];
            }
        }
        else {
            for(int ost = 0; ost < k; ost++) {
                stage3[ost] = stage2[ost];
            }
        }
    }
    cout << stage3[0];
}

//// что за хуйню я написал??!


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
/// GOD SAVE AMERICA

// https://vk.cc/avzJO3
//#define _GLIBCXX_DEBUG
//#define _GLIBCXX_PARALLEL
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
using namespace std;

const int maxn = 1e6 * 1;

inline int g() {
    int x;
    cin >> x;
    return x;
}

inline long long gl() {
    long long x;
    cin >> x;
    return x;
}

inline char gc() {
    char x;
    cin >> x;
    return x;
}

inline string gs() {
    string s;
    cin >> s;
    return s;
}

template<typename T>
inline vector<T> gv(int len) {
    vector<T> a(len);
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<int> gv(int len) {
    vector<int> a(len);///
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<pair<int, int>> gv_andPairCnt(int len) {
    vector<pair<int, int>> a(len);
    int i = 1;
    for (auto &it : a) {
        it.second = i;
        i++;
        cin >> it.first;
    }
    return a;
}

double power_log(double power, double val) {
    return log(val) / log(power);
}

template <typename T>
T sqr(T x) { return x * x; }

#define rep(I, N) for (int I = 0; I < (N); ++I)
#define rep_range(VALUE, LEFT, RIGHT) for (int VALUE = (LEFT); VALUE < (RIGHT); ++VALUE)

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (auto it : v)
        os << it << " ";
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const deque<T>& v) {
    os << "deque:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "set:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}

template<typename T, typename H>
inline vector<pair<T, H>> gv_andBiPair(int len) {
    vector<pair<T, H>> a(len);
    for (auto &it : a) {
        cin >> it.first >> it.second;
    }
    return a;
}

template<typename T>
inline set<T> vector_to_set(const vector<T> &vec) {
    set<T> s;
    for (auto &it : vec)
        s.insert(it);
    return s;
}

const long long md = 1e9 + 7;
//const long long md = 998244353;

int a[75][75];
int dp[75][75];
int best[75][75];

void maxr(int &x, int val) {
    x = max(x, val);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    rep(i, 75) {
        rep(j, 75) {
            best[i][j] = -1e8;
        }
    }
    best[1][0] = 0;

    int n = g(), m = g(), k = g();

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            a[i][j] = g();
        }
    }
    //// COUNT, OST OF DIV;
    //// MAX SUM

    for(int T = 1; T <= n; T++) {
        memset(dp, -1, sizeof(dp));

        for(int i = 1; i <= m; i++) {
            for(int cnt = (m / 2) - 1; cnt >= 1; cnt--) {
                for(int ost = 0; ost < k; ost++) {
                    if(dp[cnt][ost] == -1) {
                        continue;
                    }
                    maxr(dp[cnt + 1][(ost + a[T][i]) % k], dp[cnt][ost] + a[T][i]);
                }
            }
            maxr(dp[1][a[T][i] % k], a[T][i]);
        }

//        cout << "DP MEM DUMP:\n";

        vector<int> bst(k + 1);
        for(int ost = 0; ost < k; ost++) {
            bst[ost] = -1e8;
            for(int cnt = 0; cnt <= (m / 2); cnt++) {
                maxr(bst[ost], dp[cnt][ost]);
            }
        }

        rep(o1, k) {
            rep(o2, k) {
                maxr(best[T + 1][(o1 + o2) % k], best[T][o1] + bst[o2]);
            }
        }
    }
    cout << best[n + 1][0];
}


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
/// GOD SAVE AMERICA

// https://vk.cc/avzJO3
//#define _GLIBCXX_DEBUG
//#define _GLIBCXX_PARALLEL
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
using namespace std;

const int maxn = 1e6 * 1;

inline int g() {
    int x;
    cin >> x;
    return x;
}

inline long long gl() {
    long long x;
    cin >> x;
    return x;
}

inline char gc() {
    char x;
    cin >> x;
    return x;
}

inline string gs() {
    string s;
    cin >> s;
    return s;
}

template<typename T>
inline vector<T> gv(int len) {
    vector<T> a(len);
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<int> gv(int len) {
    vector<int> a(len);///
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<pair<int, int>> gv_andPairCnt(int len) {
    vector<pair<int, int>> a(len);
    int i = 1;
    for (auto &it : a) {
        it.second = i;
        i++;
        cin >> it.first;
    }
    return a;
}

double power_log(double power, double val) {
    return log(val) / log(power);
}

template <typename T>
T sqr(T x) { return x * x; }

#define rep(I, N) for (int I = 0; I < (N); ++I)
#define rep_range(VALUE, LEFT, RIGHT) for (int VALUE = (LEFT); VALUE < (RIGHT); ++VALUE)

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (auto it : v)
        os << it << " ";
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const deque<T>& v) {
    os << "deque:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "set:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}

template<typename T, typename H>
inline vector<pair<T, H>> gv_andBiPair(int len) {
    vector<pair<T, H>> a(len);
    for (auto &it : a) {
        cin >> it.first >> it.second;
    }
    return a;
}

template<typename T>
inline set<T> vector_to_set(const vector<T> &vec) {
    set<T> s;
    for (auto &it : vec)
        s.insert(it);
    return s;
}

const long long md = 1e9 + 7;
//const long long md = 998244353;

int a[75][75];
int dp[71][71];

void maxr(int &x, int val) {
    x = max(x, val);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n = g(), m = g(), k = g();
    vector<int> prev_best(k + 1);

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            a[i][j] = g();
        }
    }
    //// COUNT, OST OF DIV;
    //// MAX SUM

    for(int T = 1; T <= n; T++) {
        memset(dp, -1, sizeof(dp));

        for(int i = 1; i <= m; i++) {
            for(int cnt = 1; cnt < (m / 2); cnt++) {
                for(int ost = 0; ost < k; ost++) {
                    if(dp[cnt][ost] == -1) {
                        continue;
                    }
                    maxr(dp[cnt + 1][(ost + a[T][i]) % k], dp[cnt][ost] + a[T][i]);
                }
            }
            maxr(dp[1][a[T][i] % k], a[T][i]);
        }

//        cout << "DP MEM DUMP:\n";

        vector<int> bst(k + 1);
        for(int ost = 0; ost < k; ost++) {
            bst[ost] = -md;
            for(int cnt = 1; cnt <= (m / 2); cnt++) {
//                cout << dp[cnt][ost] << " ";
                maxr(bst[ost], dp[cnt][ost]);
            }
//            cout << endl;
        }

//        return 0;
//        cout << "STAGE 2 DUMP : ";
//        for(int ost = 0; ost < k; ost++) {
//            cout << stage2[ost] << " ";
//        } cout << endl;
//        cout << "STAGE 3 DUMP: ";
//        for(int ost = 0; ost < k; ost++) {
//            cout << stage3[ost] << " ";
//        } cout << endl;
//        return 0;

        vector<int> best(k + 1);
        if(T != 1) {
            rep(ost1, k) {
                rep(ost2, k) {
                    maxr(best[(ost1 + ost2) % k], prev_best[ost1] + bst[ost2]);
                }
            }
            prev_best = best;
        } else {
            prev_best = bst;
        }
    }
    cout << prev_best[0];
}


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
/// GOD SAVE AMERICA

// https://vk.cc/avzJO3
//#define _GLIBCXX_DEBUG
//#define _GLIBCXX_PARALLEL
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
using namespace std;

const int maxn = 1e6 * 1;

inline int g() {
    int x;
    cin >> x;
    return x;
}

inline long long gl() {
    long long x;
    cin >> x;
    return x;
}

inline char gc() {
    char x;
    cin >> x;
    return x;
}

inline string gs() {
    string s;
    cin >> s;
    return s;
}

template<typename T>
inline vector<T> gv(int len) {
    vector<T> a(len);
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<int> gv(int len) {
    vector<int> a(len);///
    for (auto &it : a)
        cin >> it;
    return a;
}

inline vector<pair<int, int>> gv_andPairCnt(int len) {
    vector<pair<int, int>> a(len);
    int i = 1;
    for (auto &it : a) {
        it.second = i;
        i++;
        cin >> it.first;
    }
    return a;
}

double power_log(double power, double val) {
    return log(val) / log(power);
}

template <typename T>
T sqr(T x) { return x * x; }

#define rep(I, N) for (int I = 0; I < (N); ++I)
#define rep_range(VALUE, LEFT, RIGHT) for (int VALUE = (LEFT); VALUE < (RIGHT); ++VALUE)

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (auto it : v)
        os << it << " ";
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const deque<T>& v) {
    os << "deque:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "set:{";
    for (auto it : v)
        os << it << " ";
    os << "}\n";
    return os;
}

template<typename T, typename H>
inline vector<pair<T, H>> gv_andBiPair(int len) {
    vector<pair<T, H>> a(len);
    for (auto &it : a) {
        cin >> it.first >> it.second;
    }
    return a;
}

template<typename T>
inline set<T> vector_to_set(const vector<T> &vec) {
    set<T> s;
    for (auto &it : vec)
        s.insert(it);
    return s;
}

const long long md = 1e9 + 7;
//const long long md = 998244353;

int a[75][75];
int dp[75][75];
int best[75][75];

void maxr(int &x, int val) {
    x = max(x, val);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    rep(i, 75) {
        rep(j, 75) {
            best[i][j] = -1e8;
        }
    }
    best[1][0] = 0;

    int n = g(), m = g(), k = g();

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            a[i][j] = g();
        }
    }
    //// COUNT, OST OF DIV;
    //// MAX SUM

    for(int T = 1; T <= n; T++) {
        memset(dp, -1, sizeof(dp));

        for(int i = 1; i <= m; i++) {
            for(int cnt = 1; cnt < (m / 2); cnt++) {
                for(int ost = 0; ost < k; ost++) {
                    if(dp[cnt][ost] == -1) {
                        continue;
                    }
                    maxr(dp[cnt + 1][(ost + a[T][i]) % k], dp[cnt][ost] + a[T][i]);
                }
            }
            maxr(dp[1][a[T][i] % k], a[T][i]);
        }

//        cout << "DP MEM DUMP:\n";

        vector<int> bst(k + 1);
        for(int ost = 0; ost < k; ost++) {
            bst[ost] = -1e8;
            for(int cnt = 0; cnt <= (m / 2); cnt++) {
                maxr(bst[ost], dp[cnt][ost]);
            }
        }

        rep(o1, k) {
            rep(o2, k) {
                maxr(best[T + 1][(o1 + o2) % k], best[T][o1] + bst[o2]);
            }
        }
    }
    cout << best[n + 1][0];
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007
#define pii pair<ll, ll>
#define prdb(pranay) cout << fixed << setprecision(10) << pranay;
#define speed1 ios_base ::sync_with_stdio(false);
#define speed2 cin.tie(NULL);
ll n, m, k;

ll dp[72][72][40][72];
ll arr[75][75];

ll maxs(ll i, ll j, ll cnt, ll rem)
{
    ll &ans = dp[i][j][cnt][rem];
    if (ans != -1)
        return ans;

    if (j == 0)
    {
        if (i == 0)
        {
            if (cnt > 0)
            {
                if (rem == arr[i][j] % k)
                    return arr[i][j];
            }
            if (rem == 0)
                return 0;
            return -1;
        }
        else
        {
            if (cnt > 0)
            {
                // take it
                ll x = maxs(i - 1, m - 1, m / 2, (rem - arr[i][j] % k + k) % k) + arr[i][j];
                // dont take it;
                ll y = maxs(i - 1, m - 1, m / 2, rem);
                ans = max(x, y);
            }
            else
                ans = maxs(i - 1, m - 1, m / 2, rem);
            return ans;
        }
    }

    if (cnt > 0)
    {
        // take it
        ll x = maxs(i, j - 1, cnt - 1, (rem - arr[i][j] % k + k) % k) + arr[i][j];
        // dont take it;
        ll y = maxs(i, j - 1, cnt, rem);
        ans = max(x, y);
    }
    else
        ans = maxs(i, j - 1, cnt, rem);
    return ans;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    speed1;
    speed2;

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        cin >> n >> m >> k;
        ll i, j;
        for (i = 0; i < n; i++)
            for (j = 0; j < m; j++)
                cin >> arr[i][j];
        memset(dp, -1, sizeof(dp));
        cout << maxs(n - 1, m - 1, m / 2, 0) << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007
#define pii pair<ll, ll>
#define prdb(pranay) cout << fixed << setprecision(10) << pranay;
#define speed1 ios_base ::sync_with_stdio(false);
#define speed2 cin.tie(NULL);

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    speed1;
    speed2;

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        ll n, m, k;
        ll i, j, l, x, y;
        cin >> n >> m >> k;
        ll dp[m][m / 2 + 1][k];
        // col // cnt // rem

        ll arr[n][m];
        for (i = 0; i < n; i++)
            for (j = 0; j < m; j++)
                cin >> arr[i][j];
        // return 0;
        for (i = 0; i < m; i++)
            for (j = 0; j <= m / 2; j++)
                for (l = 0; l < k; l++)
                    dp[i][j][l] = -1e5;
        dp[0][0][0] = 0;
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < m; j++)
            {
                for (l = 0; l <= min((j + 1), m / 2); l++)
                {
                    for (x = 0; x < k; x++)
                    {
                        if (l == 0)
                            continue;
                        else if (j == 0)
                            dp[j][l][x] = max(dp[j][l][x], arr[i][j] + dp[j][l - 1][(x - arr[i][j] % k + k) % k]);
                        else
                            dp[j][l][x] = max({dp[j][l][x], dp[j - 1][l][x], arr[i][j] + dp[j - 1][l - 1][(x - arr[i][j] % k + k) % k]});
                    }
                }
            }
            for (x = 0; x < k; x++)
            {
                ll maxs = 0;
                for (j = 0; j <= m / 2; j++)
                    maxs = max(maxs, dp[m - 1][j][x]);
                dp[0][0][x] = maxs;
            }
            // cout << dp[0][0][0] << endl;
        }
        cout << dp[0][0][0] << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007
#define pii pair<ll, ll>
#define prdb(pranay) cout << fixed << setprecision(10) << pranay;
#define speed1 ios_base ::sync_with_stdio(false);
#define speed2 cin.tie(NULL);
ll n, m, k;

ll dp[72][72][40][72];
ll arr[75][75];

ll maxs(ll i, ll j, ll cnt, ll rem)
{
    ll &ans = dp[i][j][cnt][rem];
    if (ans != -1)
        return ans;

    if (j == 0)
    {
        if (i == 0)
        {
            if (cnt > 0)
            {
                if (rem == arr[i][j] % k)
                    return arr[i][j];
                if (rem == 0)
                    return 0;
                return -1e5;
            }
            if (rem == 0)
                return 0;
            return -1e5;
        }
        else
        {
            if (cnt > 0)
            {
                // take it
                ll x = maxs(i - 1, m - 1, m / 2, (rem - arr[i][j] % k + k) % k) + arr[i][j];
                // dont take it;
                ll y = maxs(i - 1, m - 1, m / 2, rem);
                ans = max(x, y);
            }
            else
                ans = maxs(i - 1, m - 1, m / 2, rem);
            return ans;
        }
    }

    if (cnt > 0)
    {
        // take it
        ll x = maxs(i, j - 1, cnt - 1, (rem - arr[i][j] % k + k) % k) + arr[i][j];
        // dont take it;
        ll y = maxs(i, j - 1, cnt, rem);
        ans = max(x, y);
    }
    else
        ans = maxs(i, j - 1, cnt, rem);
    return ans;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    speed1;
    speed2;

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        cin >> n >> m >> k;
        ll i, j;
        for (i = 0; i < n; i++)
            for (j = 0; j < m; j++)
                cin >> arr[i][j];
        memset(dp, -1, sizeof(dp));
        cout << maxs(n - 1, m - 1, m / 2, 0) << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007
#define pii pair<ll, ll>
#define prdb(pranay) cout << fixed << setprecision(10) << pranay;
#define speed1 ios_base ::sync_with_stdio(false);
#define speed2 cin.tie(NULL);
ll n, m, k;

ll dp[72][72][40][72];
ll arr[75][75];

ll maxs(ll i, ll j, ll cnt, ll rem)
{
    ll &ans = dp[i][j][cnt][rem];
    if (ans != -1)
        return ans;

    if (j == 0)
    {
        if (i == 0)
        {
            if (cnt > 0)
            {
                if (rem == arr[i][j] % k)
                    return arr[i][j];
                return 0;
            }
            if (rem == 0)
                return 0;
            return -1;
        }
        else
        {
            if (cnt > 0)
            {
                // take it
                ll x = maxs(i - 1, m - 1, m / 2, (rem - arr[i][j] % k + k) % k) + arr[i][j];
                // dont take it;
                ll y = maxs(i - 1, m - 1, m / 2, rem);
                ans = max(x, y);
            }
            else
                ans = maxs(i - 1, m - 1, m / 2, rem);
            return ans;
        }
    }

    if (cnt > 0)
    {
        // take it
        ll x = maxs(i, j - 1, cnt - 1, (rem - arr[i][j] % k + k) % k) + arr[i][j];
        // dont take it;
        ll y = maxs(i, j - 1, cnt, rem);
        ans = max(x, y);
    }
    else
        ans = maxs(i, j - 1, cnt, rem);
    return ans;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    speed1;
    speed2;

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        cin >> n >> m >> k;
        ll i, j;
        for (i = 0; i < n; i++)
            for (j = 0; j < m; j++)
                cin >> arr[i][j];
        memset(dp, -1, sizeof(dp));
        cout << maxs(n - 1, m - 1, m / 2, 0) << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007
#define pii pair<ll, ll>
#define prdb(pranay) cout << fixed << setprecision(10) << pranay;
#define speed1 ios_base ::sync_with_stdio(false);
#define speed2 cin.tie(NULL);
ll n, m, k;

ll dp[72][72][40][72];
ll arr[75][75];

ll maxs(ll i, ll j, ll cnt, ll rem)
{
    ll &ans = dp[i][j][cnt][rem];
    if (ans != -1)
        return ans;

    if (j == 0)
    {
        if (i == 0)
        {
            if (cnt > 0)
            {
                if (rem == arr[i][j] % k)
                    return arr[i][j];
                if (rem == 0)
                    return 0;
                return -1e15;
            }
            if (rem == 0)
                return 0;
            return -1e15;
        }
        else
        {
            if (cnt > 0)
            {
                // take it
                ll x = maxs(i - 1, m - 1, m / 2, (rem - arr[i][j] % k + k) % k) + arr[i][j];
                // dont take it;
                ll y = maxs(i - 1, m - 1, m / 2, rem);
                ans = max(x, y);
            }
            else
                ans = maxs(i - 1, m - 1, m / 2, rem);
            return ans;
        }
    }

    if (cnt > 0)
    {
        // take it
        ll x = maxs(i, j - 1, cnt - 1, (rem - arr[i][j] % k + k) % k) + arr[i][j];
        // dont take it;
        ll y = maxs(i, j - 1, cnt, rem);
        ans = max(x, y);
    }
    else
        ans = maxs(i, j - 1, cnt, rem);
    return ans;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    speed1;
    speed2;

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        cin >> n >> m >> k;
        ll i, j;
        for (i = 0; i < n; i++)
            for (j = 0; j < m; j++)
                cin >> arr[i][j];
        memset(dp, -1, sizeof(dp));
        cout << maxs(n - 1, m - 1, m / 2, 0) << endl;
    }
}


#include<stdio.h>
int main()
{
        int i,j,k;
        int n,flag=0;

        scanf("%d",&n);
        int a[n];

        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }

        for(i=0;i<n;i++)
        {
                for(j=0;j<n-1;j++)
                {
                        if(i!=j && a[i]==(a[j])+a[j+1])
                        {
                            printf("%d %d %d",i+1,j+1+1,j+1);
                            flag=1;
                            break;
                        }
                }
                if(flag==1)
                    break;
        }

        if(flag==0)
            printf("-1");

        return 0;
}


#include<stdio.h>
int main()
{
        int i,j,k;
        int n,flag=0;

        scanf("%d",&n);
        int a[n];

        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }

        for(i=0;i<n;i++)
        {
                for(j=0;j<n;j++)
                {
                        if(i!=j)
                        {
                                for(k=0;k<n;k++)
                                {
                                        if(k!=j && a[i]==a[j]+a[k])
                                        {
                                            printf("%d %d %d",i+1,j+1,k+1);
                                            flag=1;
                                            break;
                                        }
                                }
                                if(flag==1)
                                break;
                        }
                }
                if(flag==1)
                    break;
        }

        if(flag==0)
            printf("-1");

        return 0;
}


#include<stdio.h>

int search(int a[],int ele,int n,int m,int l)
{
	int i,flag=0;

	for(i=1;i<=n;i++)
	{    if(i==n||i==l)
            continue;
		if(a[i]==ele)
		{
			flag=1;
			break;
		}
	}

	if(flag==1)
		return i;
	else
		return -1;
}

int main()
{
	int n,i,a[10001],j,p,ind,flag=0;

	scanf("%d",&n);

	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);

	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{       if(i==j)
		           continue;
			if(a[i]>a[j])
			{
				p=a[i]-a[j];

				ind=search(a,p,n,i,j);

				if(ind!=-1)
				{
					flag=1;
					goto label;
				}
			}
		}
	}

	label:
	if(flag==1)
		printf("%d %d %d",i,j,ind);
	else
		printf("-1");

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int length[2001];
int worm[101];

int main(int argc, char *argv[])
{
	int n, i, j;

	scanf("%d", &n);
	for(i = 1; i <= n; i ++)
	{
		scanf("%d", &worm[i]);
		length[worm[i]] = i;
	}

	for(i = 1; i <= n; i ++)
	{
		for(j = 1; j < i; j ++)
			if(length[worm[i] + worm[j]])
			{
				printf("%d %d %d\n", length[worm[i] + worm[j]], i, j);
				return 0;
			}
	}

	printf("-1\n");

	return 0;
}


#include<stdio.h>
int main()
{
	int amount;
	int length[100];
	int i;
	scanf("%d", &amount);
	for (int i=0; i < amount; i++)
	{
		scanf("%d", &length[i]);
	}

	for ( i = 0; i < amount; i++)
	{
		for (int j = 0; j < amount; j++)
		{
			if (j == i)
				continue;
			else
			{
				for (int k = 0; k < amount; k++)
				{
					if (k == j || k == i)
						continue;
					else
					{
						if (length[i] == length[j] + length[k])
						{
							printf("%d %d %d", length[i], length[j], length[k]);
							return 0;
						}
					}
				}
			}
		}
	}

	if (i == amount)
		printf("%d", -1);

}


#include<stdio.h>
int main()
{
	int amount;
	int length[100];
	int i;
	scanf("%d", &amount);
	for (int i=0; i < amount; i++)
	{
		scanf("%d", &length[i]);
	}

	for ( i = 0; i < amount; i++)
	{
		for (int j = 0; j < amount; j++)
		{
			if (j == i)
				continue;
			else
			{
				for (int k = 0; k < amount; k++)
				{
					if (k == j || k == i)
						continue;
					else
					{
						if (length[i] == length[j] + length[k])
						{
							printf("%d %d %d", i+1, j+1, k+1);
							return 0;
						}
					}
				}
			}
		}
	}

	if (i == amount)
		printf("%d", -1);

}


#include<stdio.h>
int main()
{
	int amount;
	int length[100];
	int i;
	scanf("%d", &amount);
	for (int i=0; i < amount; i++)
	{
		scanf("%d", &length[i]);
	}

	for ( i = 0; i < amount; i++)
	{
		for (int j = 0; j < amount; j++)
		{
			if (j == i)
				continue;
			else
			{
				for (int k = 0; k < amount; k++)
				{
					if (k == j || k == i)
						continue;
					else
					{
						if (length[i] == length[j] + length[k])
						{
							printf("%d %d %d", i, j, k);
							return 0;
						}
					}
				}
			}
		}
	}

	if (i == amount)
		printf("%d", -1);

}


#include <stdio.h>
int a[101];
int main(void)
{
	int n, i, j, k;
	scanf("%d", &n);
	for (i = 0; i < n; ++i) scanf("%d", a+i);
	for (i = 0; i < n; ++i) {
		for (j = 0; j < n; ++j) {
			if (i == j) continue;
			for (k = 0; k < n; ++k) {
				if (j == k || k == i) continue;
				if (a[i] == a[j] + a[k]) {
					printf("%d %d %d\n", i+1, j+1, k+1);
					return 0;
				}
			}
		}
	}
	puts("-1");
	return 0;
}


#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
int main (void){

    int n,i,j,check=0,x,f=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(i==j)
                continue;
            check=a[i]+a[j];
            for(x=0;x<n;x++){
                if(x==i||x==j)
                     continue;
                if(check==a[x]){
                    printf("%d %d %d",a[x],a[i],a[j]);
                    return 0;
                }
            }
        }

    }
    printf("-1");
    return 0;
}


#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
int main (void){

    int n,i,j,check=0,x,f=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(i==j)
                continue;
            check=a[i]+a[j];
            for(x=0;x<n;x++){
                if(x==i||x==j)
                     continue;
                if(check==a[x]){
                    printf("%d %d %d",x+1,i+1,j+1);
                    return 0;
                }
            }
        }

    }
    printf("-1");
    return 0;
}


#include<stdio.h>
int main()
{
	int n,dizi[105],i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&dizi[i]);
	for(i=0;i<n;i++)
	{
		for(j=1;j<n;j++)
		{
			for(k=0;k<n;k++)
			{
				if(i!=j && j!=k && i!=k)
				{
					if(dizi[i]+dizi[j]==dizi[k])
					{
						printf("%d %d %d\n",dizi[k],dizi[j],dizi[i]);
						return 0;
					}
				}
			}
		}
	}
	printf("-1\n");
	return 0;
}


#include<stdio.h>
int comp(const void *a,const void *b)
{
        return *(int *)a-*(int *)b;
}
int main()
{
        int a[100],n,i,j,k;
        scanf("%d",&n);
        for(i=0;i<n;i++)
        scanf("%d",&a[i]);
        qsort(a,n,sizeof(int),comp);
        for(i=0;i<n-2;i++)
        {
                for(j=i+1,k=n-1;k>j;)
                {
                        if(a[i]+a[j]==a[k])
                        {
                                printf("%d %d %d\n",k+1,j+1,i+1);
                                return 0;
                        }
                        else if(a[i]+a[j]>a[k])
                        k--;
                        else
                        j++;
                }
        }
        printf("-1\n");
        return 0;
}


#include<stdio.h>
int comp(const void *a,const void *b)
{
        return *(int *)a-*(int *)b;
}
int main()
{
        int a[100],n,i,j,k;
        scanf("%d",&n);
        for(i=0;i<n;i++)
        scanf("%d",&a[i]);
        qsort(a,n,sizeof(int),comp);
        for(i=0;i<n-2;i++)
        {
                for(j=i+1,k=n-1;k>j;)
                {
                        if(a[i]+a[j]==a[k])
                        {
                                printf("%d %d %d\n",i+1,j+1,k+1);
                                return 0;
                        }
                        else if(a[i]+a[j]>a[k])
                        k--;
                        else
                        j++;
                }
        }
        printf("-1\n");
        return 0;
}


#include<stdio.h>
struct kl
{
        int a;
        int b;
};
int comp(const void *a,const void *b)
{
        struct kl *i=(struct kl *)a,*j=(struct kl *)b;
        return i->a-j->a;
}
int main()
{
        struct kl c[100];
        int n,i,j,k;
        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
                scanf("%d",&c[i].a);
                c[i].b=i;
        }
        qsort(c,n,sizeof(struct kl),comp);
        for(i=0;i<n-2;i++)
        {
                for(j=i+1,k=n-1;k>j;)
                {
                        if(c[i].a+c[j].a==c[k].a)
                        {
                                printf("%d %d %d\n",c[k].b+1,c[j].b+1,c[i].b+1);
                                return 0;
                        }
                        else if(c[i].a+c[j].a>c[k].a)
                        k--;
                        else
                        j++;
                }
        }
        printf("-1\n");
        return 0;
}


#include<stdio.h>
struct kl
{
        int a;
        int b;
};
int comp(const void *a,const void *b)
{
        struct kl *i=(struct kl *)a,*j=(struct kl *)b;
        return i->a-j->a;
}
int main()
{
        struct kl c[100];
        int n,i,j,k;
        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
                scanf("%d",&c[i].a);
                c[i].b=i;
        }
        qsort(c,n,sizeof(struct kl),comp);
        for(i=0;i<n-2;i++)
        {
                for(j=i+1,k=i+2;k<n;)
                {
                        if(c[i].a+c[j].a==c[k].a)
                        {
                                printf("%d %d %d\n",c[k].b+1,c[j].b+1,c[i].b+1);
                                return 0;
                        }
                        else if(c[i].a+c[j].a>c[k].a)
                        k++;
                        else
                        j++;
                }
        }
        printf("-1\n");
        return 0;
}


#include<stdio.h>
struct kl
{
        int a;
        int b;
};
int comp(const void *a,const void *b)
{
        struct kl *i=(struct kl *)a,*j=(struct kl *)b;
        return i->a-j->a;
}
int main()
{
        struct kl c[100];
        int n,i,j,k;
        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
                scanf("%d",&c[i].a);
                c[i].b=i;
        }
        qsort(c,n,sizeof(struct kl),comp);
        for(i=0;i<n-2;i++)
        {
                for(j=i+1,k=n-1;k>j;)
                {
                        if(c[i].a+c[j].a==c[k].a)
                        {
                                printf("%d %d %d\n",c[i].b+1,c[j].b+1,c[k].b+1);
                                return 0;
                        }
                        else if(c[i].a+c[j].a>c[k].a)
                        k--;
                        else
                        j++;
                }
        }
        printf("-1\n");
        return 0;
}


//#include<conio.h>
#include<stdio.h>
int main()
{
    int n,i,k,j,p;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
    {
                      p=a[i]+a[j];
    for(k=0;k<n;k++)
    if(p==a[k]) { printf("%d %d %d",k+1,i+1,j+1);   return(0); }}
    printf("-1");
     return(0); }


//#include<conio.h>
#include<stdio.h>
int main()
{
    int n,i,k,j,p;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
    {
                      p=a[i]+a[j];
    for(k=0;k<n;k++)
    if(p==a[k]) { printf("%d %d %d",a[i],a[j],p);   return(0); }}
    printf("-1");
     return(0); }


//#include<conio.h>
#include<stdio.h>
int main()
{
    int n,i,k,j,p;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
    {
                      p=a[i]+a[j];
    for(k=0;k<n;k++)
    if(p==a[k]) { printf("%d %d %d",p,a[i],a[j]);  return(0); }}
    printf("-1");
     return(0); }


#include<stdio.h>

int main()
{
	int n,arr[100],i,j,k,flag=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&arr[i]);
	int a[100][100]={0};
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{	if(j==i)j++;
			a[i][j]=arr[i]+arr[j];
			for(k=0;k<n;k++)
				if(arr[k]==a[i][j])
				{flag=1;break;}
			if(flag==1) break;}
		if(flag==1) break;
	}
	if(flag==1)printf("%d %d %d",k+1,j+1,i+1);
	else printf("-1");

	return 0;
}


#include<stdio.h>

int main()
{
	int n,arr[100],i,j,k,flag=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&arr[i]);
	int a[100][100]={0};
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			a[i][j]=arr[i]+arr[j];
			for(k=0;k<n;k++)
				if(arr[k]==a[i][j])
				{flag=1;break;}
			if(flag==1) break;}
		if(flag==1) break;
	}
	if(flag==1)printf("%d %d %d",k,i,j);
	else printf("-1");

	return 0;
}


#include<stdio.h>

int main()
{
	int n,arr[100],i,j,k,flag=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&arr[i]);
	int a[100][100]={0};
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{	if(j==i)j++;
			a[i][j]=arr[i]+arr[j];
			for(k=0;k<n;k++)
				if(arr[k]==a[i][j])
				{flag=1;break;}
			if(flag==1) break;}
		if(flag==1) break;
	}
	if(flag==1)printf("%d %d %d",k,j,i);
	else printf("-1");

	return 0;
}


#include <stdio.h>

int main()
{
    int n,i,j,k;

    scanf("%d",&n);

    short arr[n+1],sum[n+1],x[n+1],z=1;

    for(i=1;i<=n;i++)
    {
        scanf("%d",&arr[i]);

    }

    z=1;
    for(k=1;k<=n;k++)
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
           {
               if(arr[k]==arr[i]+arr[j] && j!=i)
               {
                   //printf("%d = %d + %d\n",arr[k],arr[i],arr[j]);
                   printf("%d %d %d\n",k,i,j);
                   return 0;
               }

           }

        printf("-1\n");

    return 0;
}


#include <stdio.h>

int main()
{
    int n,i,j,k;

    scanf("%d",&n);

    short arr[n+1],sum[n+1],x[n+1],z=1;

    for(i=1;i<=n;i++)
    {
        scanf("%d",&arr[i]);

    }

    z=1;
    for(k=1;k<=n;k++)
    for(i=2;i<=n;i++)
        for(j=1;j<=n;j++)
           {
               if(arr[k]==arr[i]+arr[j])
               {
                   //printf("%d = %d + %d\n",arr[k],arr[i],arr[j]);
                   printf("%d %d %d\n",k,i,j);
                   return 0;
               }

           }

        printf("-1\n");

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int i, j, k, n, arr[101];

    scanf("%d",&n);

    for(i=0; i<n; i++)
        scanf("%d",&arr[i]);

    for(i=0; i<n-2; i++)
    {
        for(j=i+1; j<n-1; j++)
        {
            int val = arr[i]+arr[j];
            for(k=i+1; k<n; k++)
            {
                if(val == arr[k])
                {
                    printf("%d %d %d\n",k+1,i+1,j+1);
//                    system("pause");
                    return 0;
                }
            }
        }
    }

    printf("-1\n");
//    system("pause");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int i, j, k, n, arr[101];

    scanf("%d",&n);

    for(i=0; i<n; i++)
        scanf("%d",&arr[i]);

    for(i=0; i<n-2; i++)
    {
        for(j=i+1; j<n-1; j++)
        {
            int val = arr[i]+arr[j];
            for(k=j+1; k<n; k++)
            {
                if(val == arr[k])
                {
                    printf("%d %d %d\n",k+1,i+1,j+1);
//                    system("pause");
                    return 0;
                }
            }
        }
    }

    printf("-1\n");
//    system("pause");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int i, j, n, arr[101];

    scanf("%d",&n);

    for(i=0; i<n; i++)
        scanf("%d",&arr[i]);

    for(i=0; i<n-2; i++)
    {
        int val = arr[i]+arr[i+1];
        for(j=i+2; j<n; j++)
        {
            if(val == arr[j])
            {
                printf("%d %d %d\n",j+1,i+2,i+1);
                return 0;
            }
        }
    }

    printf("-1\n");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int i, j, k, n, arr[101];

    scanf("%d",&n);

    for(i=0; i<n; i++)
        scanf("%d",&arr[i]);

    for(i=0; i<n-1; i++)
    {
        for(j=i+1; j<n; j++)
        {
            int val = arr[i]+arr[j];
            for(k=0; k<n; k++)
            {
                if(val == arr[k])
                {
                    printf("%d %d %d\n",k+1,i+1,j+1);
//                    system("pause");
                    return 0;
                }
            }
        }
    }

    printf("-1\n");
//    system("pause");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, arr[101], i, kol, j, sum;
    scanf ("%d", &n);
    for (i = 0; i < 101; i++) arr[i] = 0;
    for (i = 0; i < n; i++) scanf ("%d", &arr[i]);
    for (j = 0; j < n; j++)
    for (i = 0; i < n; i++)
    {
        if (arr[i] != arr[j])
        {
           sum = arr[i] + arr[j];
           for (kol = 0; kol < n; kol++)
           {
               if (sum == arr[kol])
               {
                   printf ("%d %d% d",kol + 1, i + 1, j + 1) ;
                   return 0;
               }
           }
        }
    }
    printf("-1");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i, j, k, n, arr[101];
    scanf ("%d", &n);
    for (i = 0; i < 101; i++) arr[i] = 0;
    for (i = 0; i < n; i++)
    scanf ("%d", &arr[i]);
    for (k = 0; k < n; k++)
        for (i = 0; i < n - 1; i++)
            for (j = i + 1; j < n; j++)
                if (i != k && j != k)
                    if (arr[i] + arr[j] == arr[k])
                    {
                      printf ("%d %d %d", k + 1, j + 1, i + 1);
                      return 0;
                    }

    printf ("-1");
    return 0;
 }


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main()
{
    long long int i,j,k=0,m,n,rem,div,val[104],previous;

    scanf("%lld",&n);
    for(i=0;i<n;i++) scanf("%lld",&val[i]);
    for(i=1;k<n;i++){                                   //yes k<n so maximum loop n*n,,cause
        for(j=0;j<n;j++)                               //if i=n then,i=0,and k++
        {
            if(i==j)
                continue;

            if(val[k]==val[i]+val[j])
            {
                printf("%lld %lld %lld\n",k+1,i+1,j+1);

                return 0;
            }
        }
        if(i+1==n)i=0,k++;

    }
    printf("-1\n");
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main()
{
    long long int i,j,k=0,m,n,rem,div,val[104],previous;

    scanf("%lld",&n);
    for(i=0;i<n;i++) scanf("%lld",&val[i]);
    for(i=1;k<n;i++){                                   //yes k<n so maximum loop n*n,,cause
        for(j=0;j<n;j++)                               //if i=n then,i=0,and k++
        {
            if(val[k]==val[i]+val[j])
            {
                printf("%lld %lld %lld\n",k+1,i+1,j+1);

                return 0;
            }
        }
        if(i+1==n)i=0,k++;

    }
    printf("-1\n");
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main()
{
    long long int i,j,k=0,m,n,rem,div,val[104],previous;

    scanf("%lld",&n);
    for(i=0;i<n;i++) scanf("%lld",&val[i]);
    for(i=1;k<n;i++){                                   //yes k<n so maximum loop n*n,,cause
        for(j=i;j<n;j++)                               //if i=n then,i=0,and k++
        {
            if(val[k]==val[i]+val[j])
            {
                printf("%lld %lld %lld\n",k+1,i+1,j+1);

                return 0;
            }
        }
        if(i+1==n)i=0,k++;

    }
    printf("-1\n");
    return 0;
}


#include<stdio.h>
int pd(int a,int b,int c,int a1,int b1,int c1)
{
    int t;
    t=a>((b>c)?b:c)?a:((b>c)?b:c);

    if(t==a)
    {if(a==b+c)
    {printf("%d %d %d",a1+1,b1+1,c1+1);return(1);}}
else if(t==b)
{if(b==a+c)
{printf("%d %d %d",b1+1,a1+1,c1+1);return(1);}}
       else
       {if(c==b+a)
       {printf("%d %d %d",c1+1,b1+1,a1+1);return(1);}}
       return(0);
}

int main()
{int *x,i,j,r,t,k,n;
scanf("%d",&n);
x=(int*)calloc(n,sizeof(int));

for(i=0;i<n;i++)
scanf("%d",&x[i]);

for(i=0;i<n-2;i++)
for(j=i+1;j<n-1;j++)
for(k=j+1;k<n;k++)
{
r=pd(x[i],x[j],x[k],i,j,k);
if(r==1)
goto flag;}
printf("-1");
flag:
return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void)
{
    int n, i, j, k, a[100];
    scanf("%d\n", &n);
    for (i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    for (i = 0; i < n; i++){
        for (j = 0; j < n; j++){
            for (k = 0; k < n; k++){
                if (j != k && a[i] == a[j] + a[k]){
                    printf("%d %d %d", i + 1, j + 1, k + 1);
                    return 0;
                }

            }
        }
    }
    printf("-1");
    return 0;
}


#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<ctype.h>

#define MAX( a, b ) ( ( a > b) ? a : b )
#define MIN( a, b ) ( ( a < b) ? a : b )
#define FOR(ii,aa,bb) for(ii=aa;ii<bb;ii++)
#define and &&
#define or ||
int main () {

int x=0,n=0,s=0,i,j,a[105],k;
	scanf("%d",&x);
	FOR(i,0,x)
		scanf("%d",&a[i]);
	FOR(i,0,x)
		FOR(j,0,x){
		s=0;
		if(i==j)
			continue;
			s=a[i]+a[j];
				FOR(k,0,x)
					if(s==a[k]){
						printf("%d %d %d",k+1,j+1,i+1);
						return 0;}
		}
	printf("-1");

	return 0;
}


#include<stdio.h>

int main()
{
	int n,flag = 1;
	scanf("%d",&n);

	int i,w[n];
	for (i=0; i<n; i++)
	{
		scanf("%d",&w[i]);
	}
	int j,k;
	for (i=0; i<n && flag; i++)
	{
		for (j=0; j<n && j!=i && flag; j++)
		{
			for (k=0; k<n && k!=j && k!=i && flag; k++)
			{
				if (w[i] == w[j]+w[k])
				{
					printf("%d %d %d\n",i+1,j+1,k+1);
					flag = 0;
				}
			}
		}
	}
	if (flag)
 		printf("-1\n");

	return 0;
}


#include<stdio.h>

int main()
{
	int n,flag = 1;
	scanf("%d",&n);

	int i,w[n];
	for (i=0; i<n; i++)
	{
		scanf("%d",&w[i]);
	}
	int j,k;
	for (i=0; i<n && flag; i++)
	{
		for (j=0; j<n  && flag; j++)
		{
			for (k=0; k<n && flag; k++)
			{
				if (w[i] == w[j]+w[k] && i!=j && j!=k && k!=i)
				{
					printf("%d %d %d\n",i+1,j+1,k+1);
					flag = 0;
				}
			}
		}
	}
	if (flag)
 		printf("-1\n");

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

typedef struct {
    int value;
    int pos;
} worm;

int compare(worm *a, worm *b) {
    if (a->value < b->value)
        return -1;
    if (a->value == b->value)
        return 0;
    return 1;
}

int main(int args, char **argv) {
    int n;
    worm *len;
    int i, j, k;

    scanf("%d", &n);
    len = (worm *)malloc(n * sizeof(worm));

    for (i = 0; i < n; i++) {
        scanf("%d", &(len[i].value));
        len[i].pos = i + 1;
    }

    qsort(len, n, sizeof(worm), compare);

    for(i = 0; i < n - 2; i++) {
        for (j = i + 1; j < n - 1; j++){
            for(k = j + 1; j < n; j++) {
                int tmp = len[i].value + len[j].value;
                if (tmp == len[k].value) {
                    printf("%d %d %d\n", len[k].pos, len[i].pos, len[j].pos);
                    goto exit;
                } else if (tmp < len[k].value) {
                    break;
                } else if (tmp > len[k].value && k == n - 1) {
                    goto next_i;
                }
            }
        }
        next_i:;
    }

    printf("-1\n");

    exit:
    free(len);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

typedef struct {
    int value;
    int pos;
} worm;

int compare(worm *a, worm *b) {
    if (a->value < b->value)
        return -1;
    if (a->value == b->value)
        return 0;
    return 1;
}

int main(int args, char **argv) {
    int n;
    worm *len;
    int i, j, k;

    scanf("%d", &n);
    len = (worm *)malloc(n * sizeof(worm));

    for (i = 0; i < n; i++) {
        scanf("%d", &(len[i].value));
        len[i].pos = i + 1;
    }

    qsort(len, n, sizeof(worm), compare);

    for(i = 0; i < n - 2; i++) {
        for (j = i + 1; j < n - 1; j++){
            for(k = j + 1; k < n; k++) {
                int tmp = len[i].value + len[j].value;
                if (tmp == len[k].value) {
                    printf("%d %d %d\n", len[k].pos, len[i].pos, len[j].pos);
                    goto exit;
                } else if (tmp < len[k].value) {
                    break;
                } else if (k == n - 1) {
                    goto next_i;
                }
            }
        }
        next_i:;
    }

    printf("-1\n");

    exit:
    free(len);
    return 0;
}


#include<stdio.h>
int main(){
    int n,a[100],ok=0,i,j,k,s,d,b,c;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    for(i=0;i<n;i++){
                     for(j=i+1;j<n;j++){
                                        s=a[i]+a[j];
                                        for(k=0;k<n;k++)
                                        if(s==a[k]){
                                                    ok=1;
                                                    d=k+1;
                                                    b=j+1;
                                                    c=i+1;
                                                    break;
                                                    }
                                        if(ok) break;
                                                    }
                                        if(ok) break;
                                                    }
    if(ok) printf("%d %d %d\n",d,b,c);
    else printf("-1\n");
    return 0;

}


#include <stdio.h >
int main()
{
	int n,i,j,k;
	int a[101];
	int marki,markj,markk;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
    for(i=0;i<n;i++)
     for(j=i;j<n;j++)
       for(k=j;k<n;k++)
       {
       	if(a[i]==a[j]+a[k])
       	{
           printf("%d %d %d\n",i,j,k);
           return 0;
       	}
       	if(a[j]==a[i]+a[k])
       	{
           printf("%d %d %d\n",j,i,k);
           return 0;
       	}
       	if(a[k]==a[j]+a[i])
       	{
           printf("%d %d %d\n",k,j,i);
           return 0;
       	}
       }
       printf("-1\n");
  return 0;
}


#include <stdio.h >
int main()
{
	int n,i,j,k;
	int a[101];
	int marki,markj,markk;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
    for(i=0;i<n;i++)
     for(j=i;j<n;j++)
       for(k=j;k<n;k++)
       {
       	if(a[i]==a[j]+a[k])
       	{
           printf("%d %d %d\n",i+1,j+1,k+1);
           return 0;
       	}
       	if(a[j]==a[i]+a[k])
       	{
           printf("%d %d %d\n",j+1,i+1,k+1);
           return 0;
       	}
       	if(a[k]==a[j]+a[i])
       	{
           printf("%d %d %d\n",k+1,j+1,i+1);
           return 0;
       	}
       }
       printf("-1\n");
  return 0;
}


//Codeforces 31_A
#include<stdio.h>
#include<conio.h>
#include<process.h>
int main(){
    int arr[10000];
    int i, j, a, n,k;
    //int *p1;int *p2;int *p3;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    scanf("%d", &arr[i]);
    //checking all triplet except when j=i & k=i
   for(i=0;i<n;i++){
    for(j=0;j<n;j++){

        for(k=0;k<n;k++){

   if( arr[i]==(arr[j]+arr[k])&& (i!=j)&&(i!=k)){
    printf(" %d% d% d\n",i+1,j+1,k+1);

    exit(0);
   }

        }
    }
}
printf("%d\n",-1);
return 0;
}


#include<stdio.h>
#include<conio.h>
#include<process.h>
int main(){
    int arr[10000];
    int i, j, a, n,k;
    //int *p1;int *p2;int *p3;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    scanf("%d", &arr[i]);
    //checking all triplet except when j=i & k=i
    //for (i = 0; i < n; i++)
    //printf("%d\n", arr[i]);

for(i=0;i<n;i++){
    for(j=0;j<n;j++){

        for(k=0;k<n;k++){

   if( arr[i]==(arr[j]+arr[k])&& (i!=j)&&(i!=k)){
    printf("%d% d% d\n",i+1,j+1,k+1);
    //printf(" %d% d% d\n",arr[i],arr[j],arr[k]);
    exit(0);
   }

        }
    }
}
printf("%d\n",-1);
return 0;
}


#include<stdio.h>
#include<conio.h>
#include<process.h>
int main(){
    int arr[10000];
    int i, j, a, n,k;
    //int *p1;int *p2;int *p3;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    scanf("%d", &arr[i]);
    //checking all triplet except when j=i & k=i
    //for (i = 0; i < n; i++)
    //printf("%d\n", arr[i]);

for(i=0;i<n;i++){
    for(j=0;j<n;j++){

        for(k=0;k<n;k++){

   if( arr[i]==(arr[j]+arr[k])&& (i!=j)&&(i!=k)&&(k!=j)){
    printf("%d% d% d\n",i+1,j+1,k+1);
    //printf(" %d% d% d\n",arr[i],arr[j],arr[k]);
    exit(0);

   }

        }
    }
}
printf("%d\n",-1);
return 0;
}


#include <stdio.h>
#include<process.h>
#include<conio.h>

int main ()
{
    int number[10000];
    int i, j, a, n,k;
    int *p1;int *p2;int *p3;
    scanf("%d", &n);
    for (i = 0; i < n; ++i)
    scanf("%d", &number[i]);
    p1=number;
    p2=number+1;
    p3=number+1;
    /*  sorting begins ... */
    for (i = 0; i < n; ++i)
    {
        for (j = i + 1; j < n; ++j)
        {
            if (number[i] < number[j])
            {
                a = number[i];
                number[i] = number[j];
                number[j] = a;
            }
        }
    }
    for(i=0;i<n-3;i++){
        for(j=i+1;j<n-1;j++){
            for(k=i+1;k<n;k++){
                if(*p1==(*p2+*p3)){
                    printf("%d %d %d",*p1,*p2,*p3);
                    exit(0);}
                    *p3++;
                }
                *p2++;
            }
            *p1++;
        }
  printf("%d",-1);

return 0;}


#include <stdlib.h>

int main(void)
{
    int n;
    scanf("%d", &n);
    int a[n];
    for(int i = 0; i < n; ++i)
    {
        scanf("%d", &a[i]);
    }

    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < n; ++j)
        {
            for(int k = 0; k < n; ++k)
            {
                if(a[i] == a[j] + a[k] && j != k)
                {
                    printf("%d %d %d\n", ++i, ++j, ++k);
                    return 0;
                }
            }
        }
    }

    printf("-1\n");
    return 0;

}


#include<stdio.h>
long int sort( const void *a, const void *b)
{
    return ( *(int*)a - *(int*)b );
}
main()
{
    long int n;
    scanf("%d",&n);
    long int a[n],i,j,k;
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    for(i=0;i<n-2;i++)
    {
        for(j=i+1;j<n-1;j++)
        {
            for(k=j+1;k<n;k++)
            {
            if(a[k]==a[i]+a[j])
            {
                printf("%d\t%d\t%d",k+1,i+1,j+1);
                exit(0);
            }
            if(a[j]==a[i]+a[k])
            {
                printf("%d\t%d\t%d",j+1,i+1,k+1);
                exit(0);
            }
            if(a[i]==a[j]+a[k])
            {
                printf("%d\t%d\t%d",i+1,j+1,k+1);
                exit(0);
            }
            }
        }
    }
    printf("-1");
    return 0;
}


#include<stdio.h>
long int sort( const void *a, const void *b)
{
    return ( *(int*)a - *(int*)b );
}
main()
{
    long int n;
    scanf("%d",&n);
    long int a[n],i,j,k;
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    qsort(a, n,sizeof(long int), sort);
    for(i=0;i<n-2;i++)
    {
        for(j=i+1;j<n-1;j++)
        {
            for(k=j+1;k<n;k++)
            {
            if(a[k]==a[i]+a[j])
            {
                printf("%d\t%d\t%d",a[k],a[j],a[i]);
                exit(0);
            }
            }
        }
    }
    printf("-1");
    return 0;
}


#include<stdio.h>
long int sort( const void *a, const void *b)
{
    return ( *(int*)a - *(int*)b );
}
main()
{
    long int n;
    scanf("%d",&n);
    long int a[n],i,j,k;
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    qsort(a, n,sizeof(long int), sort);
    for(i=0;i<n-2;i++)
    {
        for(j=i+1;j<n-1;j++)
        {
            for(k=j+1;k<n;k++)
            {
            if(a[k]==a[i]+a[j])
            {
                printf("%d\t%d\t%d",a[i],a[j],a[k]);
                exit(0);
            }
            }
        }
    }
    printf("-1");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int WormsNum,i,j,m;
    scanf("%i",&WormsNum);
   int WormsLenght[WormsNum];
   for (i=0;i<WormsNum;i++)
    scanf("%i",&WormsLenght[i]);
    for (i=0;i<WormsNum;i++)
    {
        for (j=0;j<WormsNum;j++)
        {
            for (m=0; m<WormsNum ;m++)
            {
                if (WormsLenght[m]==WormsLenght[j]+WormsLenght[i] &&i!=j&& j!=m &&i!=m)
                    break;
                    else
                        continue;
            }
            if (WormsLenght[m]==WormsLenght[j]+WormsLenght[i]&& i!=j&& j!=m &&i!=m)
                    break;
                    else
                        continue;

        }
        if (WormsLenght[m]==WormsLenght[j]+WormsLenght[i]&& i!=j&& j!=m &&i!=m)
                    break;
                    else
                        continue;
    }
    if (i!=j&& j != m && i!=m )
    printf("%i %i %i",m+1,i+1,j+1);
    else if (i==WormsNum)
        printf("-1");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int WormsNum,i,j;
    scanf("%i",&WormsNum);
   int WormsLenght[WormsNum];
   for (i=0;i<WormsNum;i++)
    scanf("%i",&WormsLenght[i]);
    for (i=0;i<WormsNum;i++)
    {    j=i;
        if (WormsLenght[j+2]==WormsLenght[j]+WormsLenght[j+1])
        {
            printf("%i %i %i",WormsLenght[j+2],WormsLenght[j+1],WormsLenght[j]);
            break;
        }
    }
    if (i==WormsNum)
        printf("-1");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int WormsNum,i,j,m;
    scanf("%i",&WormsNum);
   int WormsLenght[WormsNum];
   for (i=0;i<WormsNum;i++)
    scanf("%i",&WormsLenght[i]);
    for (i=0;i<WormsNum;i++)
    {
        for (j=0;j<WormsNum;j++)
        {
            for (m=0; m<WormsNum ;m++)
            {
                if (WormsLenght[m]==WormsLenght[j]+WormsLenght[i] &&i!=j&& j!=m &&i!=m)
                    break;
                    else
                        continue;
            }
            if (WormsLenght[m]==WormsLenght[j]+WormsLenght[i]&& i!=j&& j!=m &&i!=m)
                    break;
                    else
                        continue;

        }
        if (WormsLenght[m]==WormsLenght[j]+WormsLenght[i]&& i!=j&& j!=m &&i!=m)
                    break;
                    else
                        continue;
    }
    if (i!=j != m !=WormsNum)
    printf("%i %i %i",m+1,i+1,j+1);
    else if (i==WormsNum)
        printf("-1");
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

#define lli long long int
#define MAX INT_MAX
#define PI acos(-1)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>b;i--)
#define buyuk(a,b) (a<b)? b:a
#define kucuk(a,b) (a<b)? a:b
#define ort(a,b) (a+b)/2
#define carp(a,b) (a)*(b)
int main () {
	int i,j,l,t=0,m,a[100];
	scanf("%d",&t);
	for(i=0;i<t;i++)
		scanf("%d",&a[i]);

	for(i=0;i<t;i++){
		for(j=0;j<t;j++)
			for(m=0;m<t;m++)
			if(a[i]+a[j]==a[m] && i!=j){
				printf("%d %d %d",m+1,j+1,i+1);
					return 0;
			}
	}
	printf("-1");
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

#define lli long long int
#define MAX INT_MAX
#define PI acos(-1)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>b;i--)
#define buyuk(a,b) (a<b)? b:a
#define kucuk(a,b) (a<b)? a:b
#define ort(a,b) (a+b)/2
#define carp(a,b) (a)*(b)
int main () {
	int i,j,l,t=0,m,a[100];
	scanf("%d",&t);
	for(i=0;i<t;i++)
		scanf("%d",&a[i]);

	for(i=0;i<t;i++){
		for(j=0;j<t;j++)
			for(m=0;m<t;m++)
			if(a[i]+a[j]==a[m]){
				printf("%d %d %d",m+1,j+1,i+1);
					return 0;
			}
	}
	printf("-1");
}