#include <iostream>
#include <cmath>
using namespace std;
int main()
{   int nom;
    int aa;
    cin >> aa;
    int a[aa];
    for ( int z = 0 ; z < aa ; z++) {
        cin >> a[z];
    }
    if ( aa == 1 ) {
        cout << 1;
    }
    else {
    int num = a[0];
    nom = 0;
    for ( int y = 1 ; y < aa ; y++) {
        if ( num > a[y] ) {
            num = a[y];
            nom = y;
        }
    }
    // cout << num << " ";
    int nim = 0;
    for ( int x = 0 ; x < aa ; x++) {
        if ( num == a[x] ) {
            nim = nim + 1;
        }
    }
    //cout << nim << " ";
    if ( nim == 1 ) {
        cout << nom + 1;
    }
    else {
        cout << "Still Rozdil";
    }
    }
    return 0;

}


#include <iostream>
#include <cmath>
using namespace std;
int main()
{   int nom;
    int aa;
    cin >> aa;
    int a[aa];
    for ( int z = 0 ; z < aa ; z++) {
        cin >> a[z];
    }
    int num = a[0];
    for ( int y = 1 ; y < aa ; y++) {
        if ( num > a[y] ) {
            num = a[y];
            nom = y;
        }
    }
    // cout << num << " ";
    int nim = 0;
    for ( int x = 0 ; x < aa ; x++) {
        if ( num == a[x] ) {
            nim = nim + 1;
        }
    }
    //cout << nim << " "; bruh momento , its working fine on codeblocks , not here
    if ( nim == 1 ) {
        cout << nom + 1;
    }
    else {
        cout << "Still Rozdil";
    }
    return 0;

}


#include <iostream>
#include <cmath>
using namespace std;
int main()
{   int nom;
    int aa;
    cin >> aa;
    int a[aa];
    for ( int z = 0 ; z < aa ; z++) {
        cin >> a[z];
    }
    int num = a[0];
    for ( int y = 1 ; y < aa ; y++) {
        if ( num > a[y] ) {
            num = a[y];
            nom = y;
        }
    }
    // cout << num << " ";
    int nim = 0;
    for ( int x = 0 ; x < aa ; x++) {
        if ( num == a[x] ) {
            nim = nim + 1;
        }
    }
    //cout << nim << " ";
    if ( nim == 1 ) {
        cout << nom + 1;
    }
    else {
        cout << "Still Rozdil";
    }
    return 0;

}


#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int aa;
    cin >> aa;
    int a[aa];
    for ( int z = 0 ; z < aa ; z++) {
        cin >> a[z];
    }
    int num = a[0];
    for ( int y = 1 ; y < aa ; y++) {
        if ( num > a[y] ) {
            num = a[y];
        }
    }
    int nim = 0;
    for ( int x = 1 ; x < aa ; x++) {
        if ( num == a[x] ) {
            nim = nim + 1;
        }
    }
    if ( nim == 1 ) {
        cout << num;
    }
    else {
        cout << "Still Rodzil";
    }
    return 0;

}


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

int main(){
    int n;
    cin>>n;
    int a[n];
    int minimum=99999,index;
    int count=0;
    for (int i=0;i<n;i++){
        cin>>a[i];
        if (a[i]<minimum){
            minimum=a[i];
            index=i+1;
        }
        else if (a[i]==minimum){
            count++;
        }
    }

    /*
    for (int i=0;i<n-1;i++){
        for (int j=i+1;j<n;j++){
            if (a[i]==a[j]){
                count++;
                break;
            }
        }
    }
    */

    if (count>0){
        cout<<"Still Rozdil"<<endl;
    }
    else{
        /*
        for (int i=0;i<n;i++){
            if (minimum>a[i]){
                minimum=a[i];
                index=i+1;
            }
        }
        */
        cout<<index<<endl;
    }
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    int a[n];
    long long minimum=99999999999,index,count=1;
    for (int i=0;i<n;i++){
        cin>>a[i];
        if (a[i]<minimum){
            minimum=a[i];
            index=i+1;
            count=1;
        }
        else if (a[i]==minimum){
            count++;
        }
    }
    if (count==1){
        cout<<index<<endl;
    }
    else{
        cout<<"Still Rozdil"<<endl;
    }
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    int a[n];
    long long minimum=9999999999,index;
    int count=0;
    for (int i=0;i<n;i++){
        cin>>a[i];
        if (a[i]<minimum){
            minimum=a[i];
            index=i+1;
        }
        else if (a[i]==minimum){
            count++;
        }
    }

    /*
    for (int i=0;i<n-1;i++){
        for (int j=i+1;j<n;j++){
            if (a[i]==a[j]){
                count++;
                break;
            }
        }
    }
    */

    if (count>0){
        cout<<"Still Rozdil"<<endl;
    }
    else{
        /*
        for (int i=0;i<n;i++){
            if (minimum>a[i]){
                minimum=a[i];
                index=i+1;
            }
        }
        */
        cout<<index<<endl;
    }
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    int a[n];
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    int count=0;
    for (int i=0;i<n-1;i++){
        for (int j=i+1;j<n;j++){
            if (a[i]==a[j]){
                count++;
            }
        }
    }
    int minimum=99999,index;
    if (count>0){
        cout<<"Still Rozdil"<<endl;
    }
    else{
        for (int i=0;i<n;i++){
            if (minimum>a[i]){
                minimum=a[i];
                index=i+1;
            }
        }
        cout<<index<<endl;
    }
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    int a[n];
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    int count=0;
    for (int i=0;i<n-1;i++){
        for (int j=i+1;j<n;j++){
            if (a[i]==a[j]){
                count++;
                break;
            }
        }
    }
    int minimum=99999,index;
    if (count>0){
        cout<<"Still Rozdil"<<endl;
    }
    else{
        for (int i=0;i<n;i++){
            if (minimum>a[i]){
                minimum=a[i];
                index=i+1;
            }
        }
        cout<<index<<endl;
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long int ll;

int main()
{
    vector <int> vec, vec2;
    ll n, distance;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> distance;
        vec.push_back(distance);
    }

    for(int i = 0; i < n; i++)
    {
        vec2.push_back(vec[i]);
    }

    sort(vec2.begin(), vec2.end());

    int prev = vec[0];
    int i = 0;
    if(vec2.size() == 1)
        cout << 1;
    else if(vec2[0] == vec2[1])
        cout << "Still Rozdil";
    else
    {
        for(int j = 1; j < n; j++)
        {
            int current = vec[j];
            if(current < prev)
            {
                prev = current;
                i = j;
            }
        }
        cout << i + 1;
    }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
	int n; cin >> n;
	int* arr = new int[n];
	map<int, int> indexes;

	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		indexes[arr[i]] = i + 1;
	}

	sort(arr, arr + n);

	if (n == 1) {
		cout << indexes[arr[0]];
	}
	else if(arr[0]==arr[1]) {
		cout << "Still Rozdil";
	}
	else { cout << indexes[arr[0]]; }

}


#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long n , a[100000] , m = 100000 , u;
	cin >> n;
	for ( int i = 0;i < n; i++){
		cin >> a[i];
		if (a[i] < m){
			m = a[i];
			u = i;
		}
	}
	sort(a ,a+n);
	if (a[0] == a[1])
	cout <<  "Still Rozdil";
	else
	cout << u + 1;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n , m = 100000 , u ,  a[1000];
	cin >>n ;
	for ( int i = 1;i <= n;i ++){
		cin >> a[i];
		if (a[i] > m)
		m = a[i];
		u = i;
	}
	sort (a ,a+n);
	if (a[0] == a[1])
	cout << "Still Rozdil";
	else
	cout << u;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long n , a[100000] , m = 1000000000 , u;
	cin >> n;
	for ( int i = 0;i < n; i++){
		cin >> a[i];
		if (a[i] < m){
			m = a[i];
			u = i;
		}
	}
	sort(a ,a+n);
	if (a[0] == a[1])
	cout <<  "Still Rozdil";
	else
	cout << u + 1;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long n , m = 1000000000 , u ,  a[100000];
	cin >>n ;
	for ( int i = 1;i <= n;i ++){
		cin >> a[i];
		if (a[i] < m){
		m = a[i];
		u = i;
		}
	}
	sort (a ,a+n);
	if (a[1] == a[2])
	cout << "Still Rozdil";
	else
	cout << u;
}


#include<iostream>
#include<string>
#include<algorithm>
typedef long long int ll;
using namespace std;
int main()
{
	ll n, a[100000];
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	if (n == 1)
	{
		cout << 1;
		return 0;
	}
	int m = a[0], j=-1;
	for (int i = 0; i < n; i++)
	{
		if (m >= a[i])
		{
			m = a[i];
			j = i;
		}
	}
	int c = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[j] == a[i])
		{
			c++;
		}
	}
	if (j==-1|| c > 1)
		cout << "Still Rozdil";
	else
		cout << j+1;
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
typedef long long int ll;
using namespace std;
void main()
{
	ll n, a[100000];
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int m = a[0], j=-1;
	for (int i = 0; i < n; i++)
	{
		if (m > a[i])
		{
			m = a[i];
			j = i;
		}
	}
	int c = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[j] == a[i])
		{
			c++;
		}
	}
	if (j == -1 || c > 1)
		cout << "Still Rozdil";
	else
		cout << j+1;
}


#include<iostream>
#include<string>
#include<algorithm>
typedef long long int ll;
using namespace std;
int main()
{
	ll n, a[100000];
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	if (n == 1)
	{
		cout << 1;
		return 0;
	}
	int m = a[0], j=-1;
	for (int i = 0; i < n; i++)
	{
		if (m > a[i])
		{
			m = a[i];
			j = i;
		}
	}
	int c = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[j] == a[i])
		{
			c++;
		}
	}
	if (j == -1 || c > 1)
		cout << "Still Rozdil";
	else
		cout << j+1;
	return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n,i,m,p=0,mm=0;
    long long a[100005];
    cin>>n>>a[0];
    m=a[0];
    for(i = 1; i<n; i++)
    {
        cin>>a[i];
        if(m>a[i])
        {
            m=a[i];
            p=i;
        }
        else if(m==a[i])
            mm=a[i];
    }
    if(m==mm)
        cout<<"Still Rozdil"<<endl;
    else
        cout<<p+1<<endl;
    return 0;
}


/*
URL_HERE
*/
/*

*/
#ifdef _WIN32
#pragma warning(disable:4996)
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>

using namespace std;

FILE* _fin = stdin;
FILE* _fout = stdout;
#define PI 3.141592653589793238462643383279502884197169399375105820974
#define ten5p1 100001
#define ten6p1 1000001
#define ten8p1 100000001
#define ten9p1 1000000001
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define rep(var,n) for(int var=0;var<n;++var)
#define repi(n) rep(i,n)
#define repj(n) rep(j,n)
#define repi1(n) for(int i=1;i<n;++i)
#define repj1(n) for(int j=1;j<n;++j)
int _min(int a, int b) { return a <= b ? a : b; }
int _min(ll a, ll b) { return a <= b ? a : b; }
int _max(int a, int b) { return a >= b ? a : b; }
int _max(ll a, ll b) { return a >= b ? a : b; }
void zero(int* data, int n) { memset(data, 0, sizeof(int) * n); }
void zero(ll* data, int n) { memset(data, 0, sizeof(ll) * n); }
void zero(char* data, int n) { memset(data, 0, sizeof(char) * n); }
char readc() { char var; fscanf(_fin, "%c", &var); return var; }
int readi() { int var; fscanf(_fin, "%d", &var); return var; }
double readlf() { double var; fscanf(_fin, "%lf", &var); return var; }
ll readll() { ll var; fscanf(_fin, "%lld", &var); return var; }
void repread(int* data, int n) { repi(n) data[i] = readi(); }
void repread(ll* data, int n) { repi(n) data[i] = readll(); }
int reads(char* str, int maxsize)
{
	for (;;) { if (fgets(str, maxsize, _fin) == NULL) break; if (str[0] != '\n' && str[0] != '\r') break; }
	int slen = strlen(str); if (slen == 0) return 0;
	if (str[slen - 1] == '\n' || str[slen - 1] == '\r') str[--slen] = 0;
	return slen;
}

#define writec(var) fprintf(_fout,"%c",var)
#define writecsp(var) fprintf(_fout,"%c ",var)
#define writecln(var) fprintf(_fout,"%c\n",var)
#define writei(var) fprintf(_fout,"%d",var)
#define writeisp(var) fprintf(_fout,"%d ",var)
#define writellsp(var) fprintf(_fout,"%lld ",var)
#define writeiln(var) fprintf(_fout,"%d\n",var)
#define writellln(var) fprintf(_fout,"%lld\n",var)
#define writeulln(var) fprintf(_fout,"%llu\n",var)
#define writefln(var) fprintf(_fout,"%f\n",var)
#define writes(str) fprintf(_fout,"%s",str)
#define writesp() fprintf(_fout," ")
#define writeln() fprintf(_fout,"\n")
#define RUN_LOCAL(testfilename) {_fin = fopen(testfilename, "r"); if(_fin==NULL) _fin=stdin;}
#define swap(type,a, b) {type t=a;a=b;b=t;}
#define sort(data,n) std::sort(data,data+n)
//#define mod(a,b) b==0 ? 0 : a==0 ? 0 :(a>0 ? a%b : b + a % b) //what the hell is this...
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return (a / g) * b; }
void reverse(char* data, int n) { int k = n >> 1; repi(k) { char tmp = data[i]; data[i] = data[n - i - 1]; data[n - i - 1] = tmp; } }
void reverse(int* data, int n) { int k = n >> 1; repi(k) { int tmp = data[i]; data[i] = data[n - i - 1]; data[n - i - 1] = tmp; } }

#define _Vec(type, name) \
struct name { type* data; int size; int n; };\
void init(name* t, int size) { t->data = (type*)malloc(sizeof(type) * size); t->size = size; t->n = 0; }\
void resize(name* t) { int ns = t->size * 1.2f; t->data = (type*)realloc(t->data, sizeof(type) * ns); t->size = ns; }\
void add(name* t, type val) { if (t->n >= t->size) resize(t); int k = t->n; t->data[k] = val; t->n = k + 1; }\
void free(name* t) { free(t->data);}
_Vec(int, Veci)
_Vec(long long, Vecll)
_Vec(char*, Vecs)

#define _ispal(type, name) int name(type* a, type* b, int n){repi(n){if (a[i] != b[n - i - 1]){return 0;}}return 1;}
_ispal(int, ispali)
_ispal(char, ispalc)

#define _Pair(type, name) struct name{type x, y;}; \
int cmp_##name(const void* _a, const void* _b)\
{\
	name* a = (name*)_a;name* b = (name*)_b;\
	if (a->x < b->x) return -1;\
	else\
	{\
		if (a->x == b->x)\
		{\
			if (a->y == b->y) return 0;\
			if (a->y < b->y) return -1;\
			else return 1;\
		}\
		else\
		{\
			return 1;\
		}\
	}\
}\
void sort_##name(name* d, int n){qsort(d, n, sizeof(name), cmp_##name);}
	_Pair(int, Pairi)

	int cmp_Str(const void* _a, const void* _b) { char* a = *((char**)_a); char* b = *((char**)_b); return strcmp(a, b); }
void sort_Str(char** str, int n) { qsort(str, n, sizeof(char*), cmp_Str); }

ll expmod(ll x, ll n, ll m) {
	ll ans = 1;
	for (; n;) {
		if (n & 1) ans = (ans * x) % m;
		x = (x * x) % m;
		n >>= 1;
	}
	return ans;
}

ll combmod(ll n, ll k, ll m) {
	ll ret = 1;
	ll div = 1;
	for (ll i = 0; i < k; ++i) {
		ret = (ret * (n - i) % m) % m;
		div = (div * (i + 1)) % m;
	}
	div = expmod(div, m - 2, m) % m;
	return (ret * div) % m;
}

int next_perm(int* data, int n)
{
	//find first i,i+1 where d[i]<d[i+1]
	int rootidx = -1;
	for (int i = n - 2; i >= 0; --i)
	{
		if (data[i] < data[i + 1])
		{
			rootidx = i;
			break;
		}
	}

	if (rootidx == -1) return 0;

	int ceilingidx = rootidx + 1;
	//find smallest d[x] after d[rooti] where d[x]>d[rooti]
	for (int i = rootidx + 2; i < n; ++i)
	{
		if (data[i] > data[rootidx] && data[i] < data[ceilingidx])
		{
			ceilingidx = i;
		}
	}

	swap(int, data[rootidx], data[ceilingidx]);
	sort(&data[rootidx + 1], n - rootidx - 1);
	return 1;
}
int count_digits(ll a)
{
	int k = 0;
	for (;;)
	{
		if (a == 0)break;
		k++;
		a /= 10;
	}
	return k;
}

/*
use only when val EXISTS in data
*/
int bs_exists(int* data, int n, int val)
{
	int left = 0;
	int right = n - 1;
	for (; left < right;)
	{
		int mid = (left + right + 1) >> 1;
		if (data[mid] <= val) left = mid;
		else right = mid - 1;
	}
	return right;
}
//------------------------------------------

//------------

int main()
{
	RUN_LOCAL("xx11.txt");
	int n = readi();
	static int a[ten5p1];
	repread(a, n);

	int minidx = 0;
	repi(n)
	{
		if (a[i] < a[minidx])
		{
			minidx = i;
		}
	}

	repi(n)
	{
		if (i!=minidx && a[i] == a[minidx])
		{
			writes("Still Rozdil\n");
			return 0;
		}
	}

	writeiln(minidx + 1);
	return 0;
}


#include<iostream>

using namespace std;

int cities[100000];

int main()
{
    int n,c=1,ci=1;

    cin>>n;

    for(int i=0;i<n;i++){
       cin>>cities[i];
    }
    int d = cities[0];
    for(int j=1;j<n;j++){
        if(cities[j]<d) {
                d = cities[j];
                c = 1;
                ci =j+1;
        }
        else if(cities[j]==d) c++;
    }
    if(c==1) cout<<ci<<endl;
    else cout<<"Still Rodzil"<<endl;
}


#include<iostream>

using namespace std;

int cities[100000];

int main()
{
    int n,c=1,ci=1;

    cin>>n;

    for(int i=0;i<n;i++){
       cin>>cities[i];
    }
    int d = cities[0];
    for(int j=1;j<n;j++){
        if(cities[j]<d) {
                d = cities[j];
                c = 1;
                ci =j+1;
        }
        else if(cities[j]==d) c++;
    }
    if(c==1) cout<<ci<<endl;
    else cout<<"Still Rozdil"<<endl;
}


#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;

int main()
{
  long int x,min,f=0,c=1;
  long int arr[100010]={0};

  cin>>x;

  cin>>arr[0];
  min=arr[0];

  for(long int i=1;i<x;i++)
     {
       cin>>arr[i];

       if(arr[i]<min)
          {
            min=arr[i];
            f=0;
          }

       else if(min==arr[i])
           c++;

       if(f==0)
         { f=1; c=1; }

     }

     if(c>1)
       cout<<"Still Rozdil"<<endl;
     else
       cout<<min<<endl;

return 0;
}


#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;

int main()
{
  long long int x,min,f=0,c=1,idx=1;
  long long int arr[100010]={0};

  cin>>x;

  cin>>arr[1];
  min=arr[1];
 // cout<<min<<endl;
  for(long long int i=2;i<=x;i++)
     {
       cin>>arr[i];

       if(arr[i]<min)
          {
            min=arr[i];
            idx=i;
            f=5;
          }

       else if(min==arr[i])
         {
              c++;
           // cout<<"ok\n"<<c<<endl;
         }
       if(f==5)
         { f=1; c=1; }

     }

     if(c>1)
       cout<<"Still Rozdil"<<endl;
     else
       cout<<idx<<endl;

return 0;
}


#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;

int main()
{
  long int x,min,f=0,c=1,idx=1;
  long int arr[100010]={0};

  cin>>x;

  cin>>arr[1];
  min=arr[1];

  for(long int i=2;i<=x;i++)
     {
       cin>>arr[i];

       if(arr[i]<min)
          {
            min=arr[i];
            idx=i;
            f=0;
          }

       else if(min==arr[i])
           c++;

       if(f==0)
         { f=1; c=1; }

     }

     if(c>1)
       cout<<"Still Rozdil"<<endl;
     else
       cout<<idx<<endl;

return 0;
}


#include <iostream>
#include <math.h>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
typedef vector <int> v;
#define ll long long

int di[] = { 0, 0, 1, -1};
int dj[] = { 1, -1, 0, 0};

int arr[100][100] = { 0 };

bool is_lucky(int n)
{
	string s = "";
	while (n != 0)
	{
		s += n % 10 + '0';
		n = n / 10;
     }
	cout << s << endl;

	for (int i = 0; i < s.length(); i++)
		if (s[i] != '4' && s[i] != '7') return false;

	return true;
}

int main()
{
	ll min = 10000000;
	ll count[100009] = { 0 };
	ll n;
	cin >> n;
	int min_pos = -1;
	for (int i = 1; i <= n; i++)
	{
		ll x;
		cin >> x;
		count[x]++;
		if (x < min)
		{
			min = x;
			min_pos = i;
		}
	}
	if (count[min] > 1) cout << "Still Rozdil";
	else cout << min_pos;
}


#include <iostream>
#include <math.h>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

typedef vector <int> v;

int main()
{
	ll min = 10000000;
	ll count[100009] = { 0 };
	ll n;
	cin >> n;
	int min_pos = -1;
	for (int i = 1; i <= n; i++)
	{
		ll x;
		cin >> x;
		count[x]++;
		if (x < min)
		{
			min = x;
			min_pos = i;
		}
	}
	if (count[min] > 1) cout << "Still Rozdil";
	else cout << min_pos;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <iomanip>
#include <set>
#include <stack>

using namespace std;

#define ll long long
map <int, int> cnt;

int main() {
	int n;
	cin >> n;
	int min_index = 0;
	vector <int> v(n);

	for (int i = 0; i < n; i++) {
		cin >> v[i];
		cnt[v[i]]++;

		if (v[i] < v[min_index]) min_index = i;
	}
	if (cnt[v[min_index]] < 2) cout << min_index + 1 << endl;
	else cout << "Still Rozdil" << endl;

}


#include <iostream>
#include <math.h>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
typedef vector <int> v;
#define ll long long

int di[] = { 0, 0, 1, -1};
int dj[] = { 1, -1, 0, 0};

int arr[100][100] = { 0 };

bool is_lucky(int n)
{
	string s = "";
	while (n != 0)
	{
		s += n % 10 + '0';
		n = n / 10;
     }
	cout << s << endl;

	for (int i = 0; i < s.length(); i++)
		if (s[i] != '4' && s[i] != '7') return false;

	return true;
}

int main()
{
	ll min = 100000000000;
	ll count[1000009] = { 0 };
	ll n;
	cin >> n;
	ll min_pos = -1;
	for (int i = 1; i <= n; i++)
	{
		ll x;
		cin >> x;
		count[x]++;
		if (x < min)
		{
			min = x;
			min_pos = i;
		}
	}
	if (count[min] > 1) cout << "Still Rozdil";
	else cout << min_pos;
}


#include <iostream>
#include <math.h>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
typedef vector <int> v;
#define ll long long

int di[] = { 0, 0, 1, -1};
int dj[] = { 1, -1, 0, 0};

int arr[100][100] = { 0 };

bool is_lucky(int n)
{
	string s = "";
	while (n != 0)
	{
		s += n % 10 + '0';
		n = n / 10;
     }
	cout << s << endl;

	for (int i = 0; i < s.length(); i++)
		if (s[i] != '4' && s[i] != '7') return false;

	return true;
}

int main()
{
	ll min = 100000000000;
	vector <int> arr;
	ll n;
	cin >> n;
	int min_pos = -1;
	for (int i = 0; i < n; i++)
	{
		ll x;
		cin >> x;
		arr.push_back(x);
		if (x < min)
		{
			min = x;
			min_pos = i + 1;
		}
	}
	sort(arr.begin(), arr.end());
	if (n == 1) cout << 1;
	else if (arr[1] == arr[0]) cout << "Still Rozdil";
	else cout << min_pos;
}


#include<iostream>
using namespace std;
int main()
{
    int i,min,n,x,c=0,a[100000];
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    min=a[0];
    x=0;
    for(i=1;i<n;i++)
    {
        if(a[i]==min) c++;
        if(a[i]<min) {min=a[i];x=i;c=0;}
    }
    if(c==0)
    cout<<x+1;
    else cout<<"Still Rozdil";
}


#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <functional>
#include <stack>
#include <chrono>
#include <ctime>
#include <cstdio>
#include<set>
#include<algorithm>
#include<cassert>
#include<iomanip>
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<long long>x(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	int index = 0;
	long long ans = 0, temp = INT32_MAX;
	for (int i = 0; i < n; i++) {
		if (x[i] < temp) {
			index = i + 1;
			temp = x[i];
		}
	}
	temp = INT32_MAX;
	for (int i = 0; i < n; i++) {
		if (x[i] <= temp) {
			ans = i + 1;
			temp = x[i];
		}
	}
	if (ans == index) {
		cout << ans;
	}
	else {
		cout << "Still Rozdil";
	}
	return 0;
}


#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<cctype>
#include<string>
#include<stdlib.h>
using namespace std;

int main(){
  int n,x;
  cin>>n;
  int a[100001],b[100001];
  for(int i=0;i<n;i++){
      cin>>a[i];
      b[i]=a[i];

  }
  sort(b,b+n);
  for(int i=0;i<n-1;i++){
      if(b[i]==b[i+1]){
          cout<<"Still Rozdil";return 0;
      }

  }
  for(int i=0;i<n;i++){
      if(a[i]==b[0]){
          cout<<i+1;
      }
  }
    return 0;

}


#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<cctype>
#include<string>
#include<stdlib.h>
using namespace std;

int main(){
  long long n,x;
  cin>>n;
  long long a[100001],b[100001];
  for(long long i=0;i<n;i++){
      cin>>a[i];
      b[i]=a[i];

  }
  sort(b,b+n);
  if(b[0]!=b[1]){
      for(int i=0;i<n;i++){
          if(a[i]==b[0]){
              cout<<(i+1);
              break;
          }
      }
  }
  else
  cout<<"Still Rozdil";
    return 0;

}


#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<cctype>
#include<string>
#include<stdlib.h>
using namespace std;

int main(){
  long long n,x;
  cin>>n;
  long long a[100001],b[100001];
  for(long long i=0;i<n;i++){
      cin>>a[i];
      b[i]=a[i];

  }
  sort(b,b+n);
  for(long long i=0;i<n-1;i++){
      if(b[i]==b[i+1]){
          cout<<"Still Rozdil";return 0;
      }

  }
  for(long long i=0;i<n;i++){
      if(a[i]==b[0]){
          cout<<i+1;
      }
  }
    return 0;

}


#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<cctype>
#include<string>
#include<stdlib.h>
using namespace std;

int main(){
  int n,x;
  cin>>n;
  double a[100001],b[100001];
  for(int i=0;i<n;i++){
      cin>>a[i];
      b[i]=a[i];

  }
  sort(b,b+n);
  for(int i=0;i<n-1;i++){
      if(b[i]==b[i+1]){
          cout<<"Still Rozdil";return 0;
      }

  }
  for(int i=0;i<n;i++){
      if(a[i]==b[0]){
          cout<<i+1;
      }
  }
    return 0;

}


#include<iostream>
#include<iomanip>
#include<map>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<cctype>
#include<string>
#include<stdlib.h>
using namespace std;

int main()
{
   long long n;
   cin>>n;
   vector<pair<long long,long long>> v;
   for(int i=0;i<n;i++)
   {
       int x;
       cin>>x;
       v.push_back(make_pair(x,i));
   }
   sort(v.begin(),v.end());
   for(int i=0;i<v.size()-1;i++)
   {
       if(v[i].first==v[i+1].first)
       {
           cout<<"Still Rozdil";
           return 0;
       }
   }
   cout<<v[0].second+1;
return 0;

}


#include<iostream>
#include<iomanip>
#include<map>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<cctype>
#include<string>
#include<stdlib.h>
using namespace std;

int main()
{
   long long n;
   cin>>n;
   long long a[1000001],b[1000001];
   for(long long i=0;i<n;i++)
   {
    cin>>a[i];
    b[i]=a[i];
   }
   sort(b,b+n);
   if(b[0]!=b[1])
   {
       for(int i=0;i<n;i++)
       {
           if(a[i]==b[0])
           {
               cout<<i+1;
               break;
           }
       }
   }
   else
   cout<<"Still Rozdil";
return 0;

}


#include <iostream>
#include <algorithm>
using namespace std;

int main() {

	int x, T[100001] = { 10000000000 }, In; bool e = 1;
	cin >> x;
	for (int i = 1; i <= x; i++) {
		cin >> T[i];
		if (T[i] <= T[0]) {
			T[0] = T[i];
			In = i;
		}
	}
	for (int r = 1; r <= x; r++) {
		if (r != In) {
			if (T[r] == T[In]) {
				cout << "Still Rozdil";
				e = 0;
				break;
			}
		}
	}
	if (e == 1) {
		cout << In;
	}

}


#include <iostream>
#include <algorithm>
using namespace std;

int main() {

	int x, T[100001] = { 10000000000 }, In; bool e = 1;
	cin >> x;
	for (int i = 1; i <= x; i++) {
		cin >> T[i];
		if (T[i] <= T[0]) {
			T[0] = T[i];
			In = i;
		}
	}
	for (int r = 1; r <= x; r++) {
		if (r != In) {
			if (T[r] == T[In]) {
				cout << "still Rozdil";
				e = 0;
				break;
			}
		}
	}
	if (e == 1) {
		cout << In;
	}

}


#include<iostream>
#include<vector>
using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output2.txt","w",stdout);
#endif
	int n,temp;
	cin >> n;
	vector<int> arr(n,0);

	for(int i=0;i<n;i++){ cin >> arr[i];}

	int count = 0,pos=0;
	temp = arr[0] ;
	bool flag = true;

	for(int i=0;i<n;i++)
	{
		if(temp > arr[i]) {temp = arr[i]; pos = i;}
	}

	for(int i=0;i<n;i++)
	{
		if(arr[i] == temp ) {count++; if(count>1) {flag = false; break;}  }
	}

	if(flag) cout << pos+1;
	else cout << "Still Rozdil";

	return 0;
}


#include<iostream>
#include<vector>
using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output2.txt","w",stdout);
#endif
	int n,temp;
	cin >> n;
	vector<int> arr(n,0);

	for(int i=0;i<n;i++){ cin >> arr[i];}

	int count = 0,pos=0;
	temp = arr[0] ;
	bool flag = true;

	for(int i=0;i<n;i++)
	{
		if(temp > arr[i]) {temp = arr[i]; pos = i+1;}
	}

	for(int i=0;i<n;i++)
	{
		if(arr[i] == temp ) {count++; if(count>1) {flag = false; break;}  }
	}

	if(flag) cout << pos;
	else cout << "Still Rozdil";

	return 0;
}


#include <iostream>
using namespace std;
int main() {
	int tt;
	cin >> tt;
	int min = 1000000001, idx = 0;
	bool b = false;
	for (int i = 0; i < tt; ++i) {
		int num;
		cin >> num;
		if (num < min) {
			b = false;
			min = num;
			idx = i + 1;
		} else if (num == min) {
			b = true;
		}
	}
	if (b) printf("Still Rozdil \n");
	else printf("%d\n", idx);
	return 0;
}


#include<iostream>
using namespace std;
int main()
{ int n,minin=INT_MAX;
cin>>n;
int arr[100000];
for(int i=0;i<n;i++)
    {cin>>arr[i];
    if(arr[i]<minin)
        minin=arr[i];
    }
    int countn=0,j=0;
    for(int i=0;i<n;i++)
    { if(arr[i]==minin)
    {countn++;
    j=i;
    }
    }
    if(countn==1)
    cout<<j+1;
    else cout<<"Still Rozdil";

}


#include <iostream>
#include <algorithm>
int main()
{
        long long n;
        std::cin >> n;
        long long a[100005], b[100005];
        for(int i = 0; i < n; i++)
        {
            std::cin>> a[i];
            b[i] = a[i];
        }
        std::sort(b, b+n);
        if(b[0] != b[1])
        {
            for(int i = 0; i < n; i++)
            {
                if(a[i] == b[0])
                {
                    std::cout << i + 1 << "\n";
                    break;
                }
            }
        }
        else
            std::cout<<"Still Rozdil\n";
}


#include <iostream>
#include <vector>

/*
A2OJ Ladder Problems
Ladder: https://www.a2oj.com/Ladder11.html
Problem: https://codeforces.com/problemset/problem/205/A
*/

/*

*/
void P_1_38() {
	int n;
	std::cin >> n;

	int min = std::numeric_limits<int>::max();
	int min_cnt = 0;
	int min_i = 0;

	for (int i = 1; i <= n; i++) {
		int a;
		std::cin >> a;

		if (a < min) {
			min = a;
			min_i = i;
			min_cnt = 1;
		} else if (a == min) {
			min_cnt++;
		}
	}

	if (min_cnt > 1) {
		std::cout << "Still Rozdil";
	} else {
		std::cout << min_i;
	}
}

int main() {
	P_1_38();
}


#include <iosfwd>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;

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

	ll n;
	cin >> n;
	int m;
	vector<pair<int, int>> a;
	for (int i = 0; i < n; i++)
	{
		cin >> m;
		a.emplace_back(m, i + 1);
	}

	sort(a.begin(), a.end());
	if (a[0].first == a[1].first) cout << "Still Rozdil" << endl;
	else cout << a[0].second << endl;
	return 0;
}


#include <iosfwd>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;

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

	ll n;
	cin >> n;

	ll m = 0;
	ll r = 0;
	ll c = 0;
	ll g = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> m;
		if (r == 0)
		{
			r = m;
		}
		if (m < r)
		{
			r = m;
			c = 1;
			g = i + 1;
		}
		else if (m == r)
		{
			c += 1;
		}
	}
	if (c == 2)
	{
		cout << "Still Rozdil" << endl;
	}
	else
	{
		cout << g << endl;
	}
	return 0;
}


#include <iosfwd>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;

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

	ll n;
	cin >> n;

	ll m = 0;
	ll r = 0;
	ll c = 1;
	ll g = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> m;
		if (r == 0)
		{
			r = m;
			continue;
		}
		if (m < r)
		{
			r = m;
			c = 1;
			g = i + 1;
		}
		else if (m == r)
		{
			c += 1;
		}
	}
	if (c == 2)
	{
		cout << "Still Rozdil" << endl;
	}
	else
	{
		cout << g << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
int main() {
	int n, min = (int)10e9, min_a = 0, min_u;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x == min) {
			min_a++;
		} else if (x < min) {
			min = x;
			min_u = i + 1;
			min_a = 1;
		}
	}
	if (min_a > 1) {
		puts("Still Rozdil");
	} else {
		cout << min_u;
	}
	return 0;
}


#include <iostream>
#include <windows.h>
using namespace std;
int main(){
	int n,**a;
	cin>>n;
	a=new int *[n];
	for(int i=0; i<n; i++){
		a[i]=new int [2];
		cin>>a[i][0];
		a[i][1]=i+1;
	}
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(a[i][0]>a[j][0]){
				swap(a[i][0],a[j][0]);
				swap(a[i][1],a[j][1]);
			}
		}
	}
	if(a[0][0]!=a[1][0]) cout<<a[0][1];
	else cout<<"Still Rozdil";
}


#include <iostream>
#include <windows.h>
using namespace std;
int main(){
	int n,**a;
	cin>>n;
	if(n==1){
		cout<<1;
		return 0;
	}
	a=new int *[n];
	for(int i=0; i<n; i++){
		a[i]=new int [2];
		cin>>a[i][0];
		a[i][1]=i+1;
	}
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(a[i][0]>a[j][0]){
				swap(a[i][0],a[j][0]);
				swap(a[i][1],a[j][1]);
			}
		}
	}
	if(a[0][0]!=a[1][0]) cout<<a[0][1];
	else cout<<"Still Rozdil";
}


#include <iostream>
#include <windows.h>
using namespace std;
int main(){
	int n,**a;
	cin>>n;
	if(n==1){
		cout<<1;
		return 0;
	}
	a=new int *[n];
	for(int i=0; i<n; i++){
		a[i]=new int [2];
		cin>>a[i][0];
		a[i][1]=i+1;
	}
	for(int i=0; i<2; i++){
		for(int j=i+1; j<n; j++){
			if(a[i][0]>a[j][0]){
				swap(a[i][0],a[j][0]);
				swap(a[i][1],a[j][1]);
			}
		}
	}
	if(a[0][0]!=a[1][0]) cout<<a[0][1];
	else cout<<"Still Rozdil";
}


#include <iostream>
#include <vector>
#include <algorithm>
int main() {
	int n;
	std::cin >> n;
	std::vector<int> dists;

	for (int i = 0; i < n; i++)
	{
		int value;
		std::cin >> value;
		dists.push_back(value);
	}

	int min = *std::min_element(dists.begin(), dists.end());
	int pos = std::distance(dists.begin(), std::min_element(dists.begin(), dists.end()));

	for (int i = 0; i < n; i++)
	{
		if (dists[i] == min && i != pos)
		{
			std::cout << "Still Rozdil";
			return 0;
		}
	}
	std::cout << pos+1;
}


#include <iostream>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int arr[9999];
	for (int i = 1; i <= n; i++)
		cin >> arr[i];
	int mi=1;
	for (int i = 1; i <= n; i++)
	{
		if (arr[i] < arr[mi])
			mi = i;
	}
	int a = 0;
	for (int i = 1; i <= n; i++)
	{
		if (arr[i] == arr[mi])
			a++;
	}
	if (a == 1)
		cout << mi;
	else
		cout << "Still Rozdil";
}


#include <iostream>
using namespace std;
int main()
{
	int n;
	int arr[9999];
	cin>>n;
	for (int i = 1; i <= n; i++)
		cin >> arr[i];

	int min = 1;
	int ans = 0;
   for(int j=1; j<=n; j++)
   {
	   if (arr[j] < min) min = j;
   }
   for (int j = 1; j <= n; j++)
   {
	   if (arr[j] == min) ans++;
   }

   if (ans == 1)

	   cout << min;
   else cout << "Still Rozdil";
}


#include <iostream>
using namespace std;
int main()
{
	int n;
	int arr[100001];
	cin>>n;
	for (int i = 1; i <= n; i++)
		cin >> arr[i];

	int min = 1;
	int ans = 0;
   for(int j=1; j<=n; j++)
   {
	   if (arr[j] < arr[min]) min = j;
   }
   for (int j = 1; j <= n; j++)
   {
	   if (arr[j] == arr[min]) ans++;
   }

   if (ans == 1)

	   cout << min;
   else cout << "Still Rozdil";
}


#include <iostream>
using namespace std;
int main()
{
	int n;
	int arr[9999];
	cin>>n;
	for (int i = 1; i <= n; i++)
		cin >> arr[i];

	int min = 1;
	int ans = 0;
   for(int j=1; j<=n; j++)
   {
	   if (arr[j] < arr[min]) min = j;
   }
   for (int j = 1; j <= n; j++)
   {
	   if (arr[j] = arr[min]) ans++;
   }

   if (ans == 1)

	   cout << min;
   else cout << "Still Rozdil";
}


#include <iostream>
using namespace std;
int main()
{
	int n;
	int arr[9999];
	cin>>n;
	for (int i = 1; i <= n; i++)
		cin >> arr[i];

	int min = 1;
	int ans = 0;
   for(int j=1; j<=n; j++)
   {
	   if (arr[j] < arr[min]) min = j;
   }
   for (int j = 1; j <= n; j++)
   {
	   if (arr[j] = min) ans++;
   }

   if (ans == 1)

	   cout << min;
   else cout << "Still Rozdil";
}


#include <iostream>
using namespace std;
int main()
{
	int n;
	int arr[9999];
	cin>>n;
	for (int i = 1; i <= n; i++)
		cin >> arr[i];

	int min = 0;
	int ans = 0;
   for(int j=2; j<=n; j++)
   {
	   if (arr[j] < min) { min = j; ans++; }

   }

   if (ans == 1)

	   cout << min;
   else cout << "Still Rozdil";
}


#include <iostream>
using namespace std;
int main()
{
	int n;
	int arr[9999];
	cin>>n;
	for (int i = 1; i <= n; i++)
		cin >> arr[i];

	int min = 1;
	int ans = 0;
   for(int j=1; j<=n; j++)
   {
	   if (arr[j] < arr[min]) min = j;
   }
   for (int j = 1; j <= n; j++)
   {
	   if (arr[j] == arr[min]) ans++;
   }

   if (ans == 1)

	   cout << min;
   else cout << "Still Rozdil";
}


#include <iostream>
using namespace std;
int main()
{
	int n;
	int arr[9999];
	cin>>n;
	for (int i = 1; i <= n; i++)
		cin >> arr[i];

	int min = 0;
	int ans = 0;
   for(int j=1; j<=n; j++)
   {
	   if (arr[j] < min) min = j;
   }
   for (int j = 1; j <= n; j++)
   {
	   if (arr[j] = min) ans++;
   }

   if (ans == 1)

	   cout << min;
   else cout << "Still Rozdil";
}


/*
      Ashraful Islam Paran
      28-October-2020
      22:23:10
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(n) for (int i = 0; i < n; i++)
#define show(x, y) cout << x << "         " << y << "\n"
#define fo(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i >= x; i--)
#define w(t)  \
    int t;    \
    cin >> t; \
    while (t--)

typedef unsigned long long ull;
typedef vector<long long> vi;
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
const int mod = 1e9 + 7;
#define pb push_back
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second

void print(int a[], int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
}

void print(vi &v)
{
    f(v.size())
    {
        cout << v[i] << " ";
    }
    cout << endl;
}

int n, m, k;
int a[90][90];
int dp[80][80][80][80];

int func(int i, int j, int cnt, int rem)
{
    if (i == m)
    {
        if (j <= m / 2)
        {
            return func(0, 0, cnt, rem + 1);
        }
        return -INF;
    }
    if (rem == n)
    {
        if (cnt == 0)
        {
            return 0;
        }
        return -INF;
    }
    if (dp[i][j][cnt][rem] != -1)
    {
        return dp[i][j][cnt][rem];
    }
    return dp[i][j][cnt][rem] = max(a[rem][i] + func(i + 1, j + 1, (cnt + a[rem][i]) % k, rem), func(i + 1, j, cnt, rem));
}

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // online submission
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n >> m >> k;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    memset(dp, -1, sizeof(dp));

    cout << func(0, 0, 0, 0) << endl;

    cerr << "Time : " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
    return 0;
}


/*
      Ashraful Islam Paran
      28-October-2020
      22:23:10
*/
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define f(n) for (int i = 0; i < n; i++)
#define show(x, y) cout << x << "         " << y << "\n"
#define fo(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i >= x; i--)
#define w(t)  \
    int t;    \
    cin >> t; \
    while (t--)

typedef unsigned long long ull;
typedef vector<long long> vi;
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
const int mod = 1e9 + 7;
#define pb push_back
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second

void print(int a[], int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
}

void print(vi &v)
{
    f(v.size())
    {
        cout << v[i] << " ";
    }
    cout << endl;
}

int n, m, k;
int a[75][75];
int dp[75][75][75][75];

int func(int i, int j, int cnt, int rem)
{
    if (i == m)
    {
        if (j <= m / 2)
        {
            return func(0, 0, cnt, rem + 1);
        }
        return -INF;
    }
    if (rem == n)
    {
        if (cnt == 0)
        {
            return 0;
        }
        return -INF;
    }
    if (dp[i][j][cnt][rem] != -1)
    {
        return dp[i][j][cnt][rem];
    }
    return dp[i][j][cnt][rem] = max(a[rem][i] + func(i + 1, j + 1, (cnt + a[rem][i]) % k, rem), func(i + 1, j, cnt, rem));
}

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // online submission
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n >> m >> k;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    memset(dp, -1, sizeof(dp));

    cout << func(0, 0, 0, 0) << endl;

    cerr << "Time : " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#define int long long
int n, m, K;
int a[77][77];
int dp[77][77][77][77];

int func(int i, int j, int cnt, int rem)
{
    if (i == m)
    {
        if (j <= m / 2)
        {
            return func(0, 0, cnt, rem + 1);
        }
        return -1e5;
    }
    if (rem == n)
    {
        if (cnt == 0)
        {
            return 0;
        }
        return -1e5;
    }
    if (dp[i][j][cnt][rem] != -1)
        return dp[i][j][cnt][rem];
    return dp[i][j][cnt][rem] = max(a[rem][i] + func(i + 1, j + 1, (cnt + a[rem][i]) % K, rem), func(i + 1, j, cnt, rem));
}
int32_t main()
{
    cin >> n >> m >> K;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    memset(dp, -1, sizeof(dp));

    cout << func(0, 0, 0, 0) << endl;
    return 0;
}


/*
      Ashraful Islam Paran
      28-October-2020
      22:23:10
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(n) for (int i = 0; i < n; i++)
#define show(x, y) cout << x << "         " << y << "\n"
#define fo(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i >= x; i--)
#define w(t)  \
    int t;    \
    cin >> t; \
    while (t--)

typedef unsigned long long ull;
typedef vector<long long> vi;
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e5;
const int mod = 1e9 + 7;
#define pb push_back
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second

void print(int a[], int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
}

void print(vi &v)
{
    f(v.size())
    {
        cout << v[i] << " ";
    }
    cout << endl;
}

int n, m, k;
int a[77][77];
int dp[77][77][70][77];

int func(int i, int j, int cnt, int rem)
{
    if (i == m)
    {
        if (j <= m / 2)
        {
            return func(0, 0, cnt, rem + 1);
        }
        return -INF;
    }
    if (rem == n)
    {
        if (cnt == 0)
        {
            return 0;
        }
        return -INF;
    }
    if (dp[i][j][cnt][rem] != -1)
    {
        return dp[i][j][cnt][rem];
    }
    return dp[i][j][cnt][rem] = max(a[rem][i] + func(i + 1, j + 1, (cnt + a[rem][i]) % k, rem), func(i + 1, j, cnt, rem));
}

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // online submission
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n >> m >> k;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    memset(dp, -1, sizeof(dp));

    cout << func(0, 0, 0, 0) << endl;

    cerr << "Time : " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
    return 0;
}


/*
      Ashraful Islam Paran
      28-October-2020
      22:23:10
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(n) for (int i = 0; i < n; i++)
#define show(x, y) cout << x << "         " << y << "\n"
#define fo(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i >= x; i--)
#define w(t)  \
    int t;    \
    cin >> t; \
    while (t--)

typedef unsigned long long ull;
typedef vector<long long> vi;
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e5;
const int mod = 1e9 + 7;
#define pb push_back
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second

void print(int a[], int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
}

void print(vi &v)
{
    f(v.size())
    {
        cout << v[i] << " ";
    }
    cout << endl;
}

int n, m, k;
int a[77][77];
int dp[77][77][77][77];

int func(int i, int j, int cnt, int rem)
{
    if (i == m)
    {
        if (j <= m / 2)
        {
            return func(0, 0, cnt, rem + 1);
        }
        return -INF;
    }
    if (rem == n)
    {
        if (cnt == 0)
        {
            return 0;
        }
        return -INF;
    }
    if (dp[i][j][cnt][rem] != -1)
    {
        return dp[i][j][cnt][rem];
    }
    return dp[i][j][cnt][rem] = max(a[rem][i] + func(i + 1, j + 1, (cnt + a[rem][i]) % k, rem), func(i + 1, j, cnt, rem));
}

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // online submission
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n >> m >> k;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    memset(dp, -1, sizeof(dp));

    cout << func(0, 0, 0, 0) << endl;

    cerr << "Time : " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
    return 0;
}


/*
      Ashraful Islam Paran
      28-October-2020
      22:23:10
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(n) for (int i = 0; i < n; i++)
#define show(x, y) cout << x << "         " << y << "\n"
#define fo(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i >= x; i--)
#define w(t)  \
    int t;    \
    cin >> t; \
    while (t--)

typedef unsigned long long ull;
typedef vector<long long> vi;
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
const int mod = 1e9 + 7;
#define pb push_back
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second

void print(int a[], int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
}

void print(vi &v)
{
    f(v.size())
    {
        cout << v[i] << " ";
    }
    cout << endl;
}

int n, m, k;
int a[77][77];
int dp[77][77][77][77];

int func(int i, int j, int cnt, int rem)
{
    if (i == m)
    {
        if (j <= m / 2)
        {
            return func(0, 0, cnt, rem + 1);
        }
        return -INF;
    }
    if (rem == n)
    {
        if (cnt == 0)
        {
            return 0;
        }
        return -INF;
    }
    if (dp[i][j][cnt][rem] != -1)
    {
        return dp[i][j][cnt][rem];
    }
    return dp[i][j][cnt][rem] = max(a[rem][i] + func(i + 1, j + 1, (cnt + a[rem][i]) % k, rem), func(i + 1, j, cnt, rem));
}

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // online submission
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n >> m >> k;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    memset(dp, -1, sizeof(dp));

    cout << func(0, 0, 0, 0) << endl;

    cerr << "Time : " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
    return 0;
}


#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define ar array
#define N 1000005
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e9
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
typedef long long int ll;
int dp[100][100][100],dp1[100][100][100];//i mod elements
using namespace std;
int main(void){
	fast;
	int n,m,k,i,j,p,l,ans=0,q;
	cin>>n>>m>>k;
	int a[n][m];
	for(i=0;i<n;i++){
		for(j=0;j<m;j++)
		cin>>a[i][j];
	}
	for(i=0;i<n;i++){
		for(p=1;p<=m/2;p++){
			for(j=0;j<m;j++){
				for(l=0;l<k;l++){
					int cur =a[i][j]%k;
					if(p>1)
					dp[i][(cur+l)%k][p]=max(dp[i][(cur+l)%k][p],dp[i][l][p-1]+a[i][j]);
					dp[i][cur][1]=max(dp[i][cur][1],a[i][j]);
					if(i==0){
						dp1[i][cur][1]=max(dp1[i][cur][1],a[i][j]%k);
					}
				}
			}
		}
		if(i>0){
			for(p=1;p<=m/2;p++){
				for(q=1;q<=m/2;q++)
					for(j=0;j<k;j++){
						for(l=0;l<k;l++){
						dp1[i][(j+l)%k][p]=max(dp1[i][(j+l)%k][p],dp1[i-1][j][q]+dp[i][l][p]);
						ans=max(ans,dp1[i][0][p]);
					}
				}
			}
		}
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define ar array
#define N 1000005
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e9
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
typedef long long int ll;
int dp[100][100][100],dp1[100][100][100];//mod elements lastindex
using namespace std;
int main(void){
	fast;
	int n,m,k,i,j,p,l,ans=0,q,s;
	cin>>n>>m>>k;
	int a[n][m];
	for(i=0;i<n;i++){
		for(j=0;j<m;j++)
		cin>>a[i][j];
	}
	for(i=0;i<n;i++){
		for(p=1;p<=m/2;p++){
			for(j=0;j<m;j++){
				for(l=0;l<k;l++){
					int cur =a[i][j]%k;
					if(p>1)
					for(q=0;q<m;q++){
						if(j!=q&&dp[l][p-1][q])
						dp[(cur+l)%k][p][j]=max(dp[(cur+l)%k][p][j],dp[l][p-1][q]+a[i][j]);
					}
					dp[cur][1][j]=max(dp[cur][1][j],a[i][j]);
					if(i==0){
						dp1[i][cur][1]=max(dp1[i][cur][1],a[i][j]);
					}
				}
			}
		}
		if(i>0){
			for(p=1;p<=m/2;p++){
				for(q=1;q<=m/2;q++)
					for(j=0;j<k;j++){
						for(l=0;l<k;l++){
							for(s=0;s<m;s++)
							dp1[i][(j+l)%k][p]=max(dp1[i][(j+l)%k][p],dp1[i-1][j][q]+dp[l][p][s]);
						//ans=max(ans,dp1[i][0][p]);
					}
				}
			}
		}
	}
	for(i=1;i<=m/2;i++)
	ans=max(ans,dp1[n-1][0][i]);
	cout<<ans;
}


#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define ar array
#define N 1000005
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e9
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
typedef long long int ll;
int dp[100][100][100],dp1[100][100][100];//mod elements lastindex
using namespace std;
int main(void){
	fast;
	int n,m,k,i,j,p,l,ans=0,q,s;
	cin>>n>>m>>k;
	int a[n][m];
	for(i=0;i<n;i++){
		for(j=0;j<m;j++)
		cin>>a[i][j];
	}
	for(i=0;i<n;i++){
		for(p=1;p<=m/2;p++){
			for(j=0;j<m;j++){
				for(l=0;l<k;l++){
					int cur =a[i][j]%k;
					for(q=0;q<m;q++){
						if(i!=q)
						dp[(cur+l)%k][p][i]=max(dp[(cur+l)%k][p][i],dp[l][p-1][q]+a[i][j]);
					}
					if(i==0){
						dp1[i][cur][1]=max(dp1[i][cur][1],a[i][j]);
					}
				}
			}
		}
		if(i>0){
			for(p=1;p<=m/2;p++){
				for(q=1;q<=m/2;q++)
					for(j=0;j<k;j++){
						for(l=0;l<k;l++){
							for(s=0;s<m;s++)
							dp1[i][(j+l)%k][p]=max(dp1[i][(j+l)%k][p],dp1[i-1][j][q]+dp[l][p][s]);
						//ans=max(ans,dp1[i][0][p]);
					}
				}
			}
		}
	}
	for(i=1;i<=m/2;i++)
	ans=max(ans,dp1[n-1][0][i]);
	cout<<ans;
}


#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define ar array
#define N 1000005
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e9
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
typedef long long int ll;
int dp[100][100][100],dp1[100][100][100];//mod elements lastindex
using namespace std;
int main(void){
	fast;
	int n,m,k,i,j,p,l,ans=0,q,s;
	cin>>n>>m>>k;
	int a[n][m];
	for(i=0;i<n;i++){
		for(j=0;j<m;j++)
		cin>>a[i][j];
	}
	for(i=0;i<n;i++){
		for(p=1;p<=m/2;p++){
			for(j=0;j<m;j++){
				for(l=0;l<k;l++){
					int cur =a[i][j]%k;
					for(q=0;q<m;q++){
						if(j!=q)
						dp[(cur+l)%k][p][j]=max(dp[(cur+l)%k][p][j],dp[l][p-1][q]+a[i][j]);
					}
					if(i==0){
						dp1[i][cur][1]=max(dp1[i][cur][1],a[i][j]);
					}
				}
			}
		}
		if(i>0){
			for(p=1;p<=m/2;p++){
				for(q=1;q<=m/2;q++)
					for(j=0;j<k;j++){
						for(l=0;l<k;l++){
							for(s=0;s<m;s++)
							dp1[i][(j+l)%k][p]=max(dp1[i][(j+l)%k][p],dp1[i-1][j][q]+dp[l][p][s]);
						//ans=max(ans,dp1[i][0][p]);
					}
				}
			}
		}
	}
	for(i=1;i<=m/2;i++)
	ans=max(ans,dp1[n-1][0][i]);
	cout<<ans;
}


#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define ar array
#define N 1000005
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e9
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
typedef long long int ll;
int dp[100][100][100],dp1[100][100][100];//i mod elements
using namespace std;
int main(void){
	fast;
	int n,m,k,i,j,p,l,ans=0,q;
	cin>>n>>m>>k;
	int a[n][m];
	for(i=0;i<n;i++){
		for(j=0;j<m;j++)
		cin>>a[i][j];
	}
	for(i=0;i<n;i++){
		for(p=1;p<=m/2;p++){
			for(j=0;j<m;j++){
				for(l=0;l<k;l++){
					int cur =a[i][j]%k;
					if(p>1)
					dp[i][(cur+l)%k][p]=max(dp[i][(cur+l)%k][p],dp[i][l][p-1]+a[i][j]);
					dp[i][cur][1]=max(dp[i][cur][1],a[i][j]);
					if(i==0){
						dp1[i][cur][1]=max(dp1[i][cur][1],a[i][j]%k);
					}
				}
			}
		}
		if(i>0){
			for(p=1;p<=m/2;p++){
				for(q=1;q<=m/2;q++)
					for(j=0;j<k;j++){
						for(l=0;l<k;l++){
						dp1[i][(j+l)%k][p]=max(dp1[i][(j+l)%k][p],dp1[i-1][j][q]+dp[i][l][p]);
						//ans=max(ans,dp1[i][0][p]);
					}
				}
			}
		}
	}
	for(i=1;i<=m/2;i++)
	ans=max(ans,dp1[n-1][0][i]);
	cout<<ans;
}


#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define ar array
#define N 1000005
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e9
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
typedef long long int ll;
int dp[100][100][100],dp1[100][100][100];//mod elements lastindex
using namespace std;
int main(void){
	fast;
	int n,m,k,i,j,p,l,ans=0,q,s;
	cin>>n>>m>>k;
	int a[n][m];
	for(i=0;i<n;i++){
		for(j=0;j<m;j++)
		cin>>a[i][j];
	}
	for(i=0;i<n;i++){
		for(p=1;p<=m/2;p++){
			for(j=0;j<m;j++){
				for(l=0;l<k;l++){
					int cur =a[i][j]%k;
					if(p>1)
					for(q=0;q<m;q++){
						if(j!=q&&dp[l][p-1][q])
						dp[(cur+l)%k][p][j]=max(dp[(cur+l)%k][p][j],dp[l][p-1][q]+a[i][j]);
					}
					dp[cur][1][j]=max(dp[cur][1][j],a[i][j]);
					if(i==0){
						dp1[i][cur][1]=max(dp1[i][cur][1],a[i][j]);
					}
				}
			}
		}
		if(i>0){
			for(p=1;p<=m/2;p++){
				for(q=1;q<=m/2;q++)
					for(j=0;j<k;j++){
						for(l=0;l<k;l++){
							for(s=0;s<m;s++)
							if(dp[l][p][s]&&dp1[i-1][j][q])
							dp1[i][(j+l)%k][p]=max(dp1[i][(j+l)%k][p],dp1[i-1][j][q]+dp[l][p][s]);
						//ans=max(ans,dp1[i][0][p]);
					}
				}
			}
		}
	}
	for(i=1;i<=m/2;i++)
	ans=max(ans,dp1[n-1][0][i]);
	cout<<ans;
}


#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); ++i)

const int N = 75;
const int INF = 1e9;

int a[N][N];
int dp[N][N][N][N];

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	int n, m, k;
	cin >> n >> m >> k;
	forn(i, n) forn(j, m) {
		cin >> a[i][j];
	}

	forn(i, N) forn(j, N) forn(cnt, N) forn(rem, N) dp[i][j][cnt][rem] = -INF;
	dp[0][0][0][0] = 0;
	forn(i, n) forn(j, m) forn(cnt, m / 2 + 1) forn(rem, k) {
		if (dp[i][j][cnt][rem] == -INF) continue;
		int ni = (j == m - 1 ? i + 1 : i);
		int nj = (j == m - 1 ? 0 : j + 1);
		if (i != ni) {
			dp[ni][nj][0][rem] = max(dp[ni][nj][0][rem], dp[i][j][cnt][rem]);
		} else {
			dp[ni][nj][cnt][rem] = max(dp[ni][nj][cnt][rem], dp[i][j][cnt][rem]);
		}
		if (cnt + 1 <= m / 2) {
			int nrem = (rem + a[i][j]) % k;
			if (i != ni) {
				dp[ni][nj][0][nrem] = max(dp[ni][nj][0][nrem], dp[i][j][cnt][rem] + a[i][j]);
			} else {
				dp[ni][nj][cnt + 1][nrem] = max(dp[ni][nj][cnt + 1][nrem], dp[i][j][cnt][rem] + a[i][j]);
			}
		}
	}

	cout << max(0, dp[n][0][0][0]) << endl;

	return 0;
}


#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define ar array
#define N 1000005
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e9
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
typedef long long int ll;
int dp[100][100][100],dp1[100][100][100];//i mod elements
using namespace std;
int main(void){
	fast;
	int n,m,k,i,j,p,l,ans=0;
	cin>>n>>m>>k;
	int a[n][m];
	for(i=0;i<n;i++){
		for(j=0;j<m;j++)
		cin>>a[i][j];
	}
	for(i=0;i<n;i++){
		for(p=1;p<=m/2;p++){
			for(j=0;j<m;j++){
				for(l=0;l<k;l++){
					int cur =a[i][j]%k;
					if(dp[i][l][p-1])
					dp[i][(cur+l)%k][p]=max(dp[i][(cur+l)%k][p],dp[i][l][p-1]+a[i][j]);
					dp[i][cur][1]=max(dp[i][cur][1],a[i][j]);
					if(i==0){
						dp1[i][cur][1]=max(dp1[i][cur][1],a[i][j]);
					}
					ans=max(ans,dp[i][0][p]);
				}
			}
		}
		if(i>0){
			for(j=0;j<k;j++){
				for(l=0;l<k;l++){
					for(p=1;p<=m/2;p++){
						dp1[i][(j+l)%k][p]=max(dp1[i][(j+l)%k][p],dp1[i-1][j][p]+dp[i][l][p]);
						ans=max(ans,dp1[i][0][p]);
					}
				}
			}
		}
	}
	cout<<ans;
}


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

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define parll pair<ll,ll>
#define parii pair<int,int>
#define mp make_pair
#define mn 73

int M[mn][mn][mn][mn],n,k,m;
vector < vector<int> > A;

int Rekurzija( int i, int j, int l, int o )
{
    if ( j == m )
    {
        if ( l > m/2 )
        {
            return -inf;
        }
        return Rekurzija( i+1, 0, 0, o );
    }

    if ( i == n )
    {
        if ( o != 0 )
        {
            return -inf;
        }
        return 0;
    }

    if ( M[i][j][l][o] != -1 )
    {
        return M[i][j][l][o];
    }
    M[i][j][l][o] = max( A[i][j]+Rekurzija( i, j+1, l+1, (o+A[i][j])%k ), Rekurzija( i, j+1, l, o ) );
    return M[i][j][l][o];
}

int main()
{
    ios;

    memset( M, -1, sizeof(M) );

    cin >> n >> m >> k;
    A.resize(n);
    for ( int i = 0; i < n; i++ )
    {
        A[i].resize(m);
        for ( int j = 0; j < m; j++ )
        {
            cin >> A[i][j];
        }
    }

    cout << Rekurzija( 0, 0, 0, 0 );

    return 0;
}


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

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define parll pair<ll,ll>
#define parii pair<int,int>
#define mp make_pair
#define mn 73

int M[mn][mn][mn][mn],n,k,m;
vector < vector<int> > A;

int Rekurzija( int i, int j, int l, int o )
{
    if ( j == m )
    {
        if ( l < m/2 )
        {
            return Rekurzija( i+1, 0, 0, o );
        }
        return -inf;
    }

    if ( i == n )
    {
        if ( o == 0 )
        {
            return 0;
        }
        return -inf;
    }

    if ( M[i][j][l][o] > -1 )
    {
        return M[i][j][l][o];
    }
    M[i][j][l][o] = max( A[i][j]+Rekurzija( i, j+1, l+1, (o+A[i][j])%k ), Rekurzija( i, j+1, l, o ) );
    return M[i][j][l][o];
}

int main()
{
    ios;

    memset( M, -1, sizeof(M) );

    cin >> n >> m >> k;
    A.resize(n);
    for ( int i = 0; i < n; i++ )
    {
        A[i].resize(m);
        for ( int j = 0; j < m; j++ )
        {
            cin >> A[i][j];
        }
    }

    cout << Rekurzija( 0, 0, 0, 0 );

    return 0;
}


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

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define parll pair<ll,ll>
#define parii pair<int,int>
#define mp make_pair
#define mn 73

int M[mn][mn][mn][mn],n,k,m;
vector < vector<int> > A;

int Rekurzija( int i, int j, int l, int o )
{
    if ( j == m )
    {
        if ( l <= m/2 )
        {
            return Rekurzija( i+1, 0, 0, o );
        }
        return -inf;
    }

    if ( i == n )
    {
        if ( o == 0 )
        {
            return 0;
        }
        return -inf;
    }

    if ( M[i][j][l][o] > -1 )
    {
        return M[i][j][l][o];
    }
    M[i][j][l][o] = max( A[i][j]+Rekurzija( i, j+1, l+1, (o+A[i][j])%k ), Rekurzija( i, j+1, l, o ) );
    return M[i][j][l][o];
}

int main()
{
    ios;

    memset( M, -1, sizeof(M) );

    cin >> n >> m >> k;
    A.resize(n);
    for ( int i = 0; i < n; i++ )
    {
        A[i].resize(m);
        for ( int j = 0; j < m; j++ )
        {
            cin >> A[i][j];
        }
    }

    cout << Rekurzija( 0, 0, 0, 0 );

    return 0;
}


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

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define parll pair<ll,ll>
#define parii pair<int,int>
#define mp make_pair
#define mn 102

int M[mn][mn][mn][mn],n,k,m;
vector < vector<int> > A;

int Rekurzija( int i, int j, int l, int o )
{
    if ( j == m )
    {
        if ( l < m/2 )
        {
            return Rekurzija( i+1, 0, 0, o );
        }
        return -inf;
    }

    if ( i == n )
    {
        if ( o == 0 )
        {
            return 0;
        }
        return -inf;
    }

    if ( M[i][j][l][o] > -1 )
    {
        return M[i][j][l][o];
    }
    M[i][j][l][o] = max( A[i][j]+Rekurzija( i, j+1, l+1, (o+A[i][j])%k ), Rekurzija( i, j+1, l, o ) );
    return M[i][j][l][o];
}

int main()
{
    ios;

    memset( M, -1, sizeof(M) );

    cin >> n >> m >> k;
    A.resize(n);
    for ( int i = 0; i < n; i++ )
    {
        A[i].resize(m);
        for ( int j = 0; j < m; j++ )
        {
            cin >> A[i][j];
        }
    }

    cout << Rekurzija( 0, 0, 0, 0 );

    return 0;
}


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

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define parll pair<ll,ll>
#define parii pair<int,int>
#define mp make_pair
#define mn 73

int M[mn][mn][mn][mn],n,k,m;
vector < vector<int> > A;

int Rekurzija( int i, int j, int l, int o )
{
    if ( j == m )
    {
        if ( l <= m/2 )
        {
            return Rekurzija( i+1, 0, 0, o );
        }
        return -inf;
    }

    if ( i == n )
    {
        if ( o == 0 )
        {
            return 0;
        }
        return -inf;
    }

    if ( M[i][j][l][o] > -1 )
    {
        return M[i][j][l][o];
    }
    M[i][j][l][o] = max( Rekurzija( i, j+1, l, o ), A[i][j]+Rekurzija( i, j+1, l+1, (o+A[i][j])%k ) );
    return M[i][j][l][o];
}

int main()
{
    ios;

    memset( M, -1, sizeof(M) );

    cin >> n >> m >> k;
    A.resize(n);
    for ( int i = 0; i < n; i++ )
    {
        A[i].resize(m);
        for ( int j = 0; j < m; j++ )
        {
            cin >> A[i][j];
        }
    }

    cout << Rekurzija( 0, 0, 0, 0 );

    return 0;
}


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

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define parll pair<ll,ll>
#define parii pair<int,int>
#define mp make_pair
#define mn 73

int M[mn][mn][mn][mn],n,k,m;
vector < vector<int> > A;

int Rekurzija( int i, int j, int l, int o )
{
    if ( j == m )
    {
        if ( l <+ m/2 )
        {
            return Rekurzija( i+1, 0, 0, o );
        }
        return -inf;
    }

    if ( i == n )
    {
        if ( o == 0 )
        {
            return 0;
        }
        return -inf;
    }

    if ( M[i][j][l][o] > -1 )
    {
        return M[i][j][l][o];
    }
    M[i][j][l][o] = max( Rekurzija( i, j+1, l, o ), A[i][j]+Rekurzija( i, j+1, l+1, (o+A[i][j])%k ) );
    return M[i][j][l][o];
}

int main()
{
    ios;

    memset( M, -1, sizeof(M) );

    cin >> n >> m >> k;
    A.resize(n);
    for ( int i = 0; i < n; i++ )
    {
        A[i].resize(m);
        for ( int j = 0; j < m; j++ )
        {
            cin >> A[i][j];
        }
    }

    cout << Rekurzija( 0, 0, 0, 0 );

    return 0;
}


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

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define parll pair<ll,ll>
#define parii pair<int,int>
#define mp make_pair
#define mn 102

int M[mn][mn][mn][mn],n,k,m;
vector < vector<int> > A;

int Rekurzija( int i, int j, int l, int o )
{
    if ( j == m )
    {
        if ( l <= m/2 )
        {
            return Rekurzija( i+1, 0, 0, o );
        }
        return -inf;
    }

    if ( i == n )
    {
        if ( o == 0 )
        {
            return 0;
        }
        return -inf;
    }

    if ( M[i][j][l][o] > -1 )
    {
        return M[i][j][l][o];
    }
    M[i][j][l][o] = max( A[i][j]+Rekurzija( i, j+1, l+1, (o+A[i][j])%k ), Rekurzija( i, j+1, l, o ) );
    return M[i][j][l][o];
}

int main()
{
    ios;

    memset( M, -1, sizeof(M) );

    cin >> n >> m >> k;
    A.resize(n);
    for ( int i = 0; i < n; i++ )
    {
        A[i].resize(m);
        for ( int j = 0; j < m; j++ )
        {
            cin >> A[i][j];
        }
    }

    cout << Rekurzija( 0, 0, 0, 0 );

    return 0;
}


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

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define parll pair<ll,ll>
#define parii pair<int,int>
#define mp make_pair
#define mn 73

int M[mn][mn][mn][mn],n,k,m;
vector < vector<int> > A;

int Rekurzija( int i, int j, int l, int o )
{
    if ( j == m )
    {
        if ( l <= m/2 )
        {
            return Rekurzija( i+1, 0, 0, o );
        }
        return -inf;
    }

    if ( i == n )
    {
        if ( o == 0 )
        {
            return 0;
        }
        return -inf;
    }

    if ( M[i][j][l][o] != -1 )
    {
        return M[i][j][l][o];
    }
    M[i][j][l][o] = max( A[i][j]+Rekurzija( i, j+1, l+1, (o+A[i][j])%k ), Rekurzija( i, j+1, l, o ) );
    return M[i][j][l][o];
}

int main()
{
    ios;

    memset( M, -1, sizeof(M) );

    cin >> n >> m >> k;
    A.resize(n);
    for ( int i = 0; i < n; i++ )
    {
        A[i].resize(m);
        for ( int j = 0; j < m; j++ )
        {
            cin >> A[i][j];
        }
    }

    cout << Rekurzija( 0, 0, 0, 0 );

    return 0;
}


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

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define parll pair<ll,ll>
#define parii pair<int,int>
#define mp make_pair
#define mn 77

int M[mn][mn][mn][mn],n,k,m;
vector < vector<int> > A;

int Rekurzija( int i, int j, int l, int o )
{
    if ( j == m )
    {
        if ( l <= m/2 )
        {
            return Rekurzija( i+1, 0, 0, o );
        }
        return -inf;
    }

    if ( i == n )
    {
        if ( o == 0 )
        {
            return 0;
        }
        return -inf;
    }

    if ( M[i][j][l][o] > -1 )
    {
        return M[i][j][l][o];
    }
    M[i][j][l][o] = max( A[i][j]+Rekurzija( i, j+1, l+1, (o+A[i][j])%k ), Rekurzija( i, j+1, l, o ) );
    return M[i][j][l][o];
}

int main()
{
    ios;

    memset( M, -1, sizeof(M) );

    cin >> n >> m >> k;
    A.resize(n);
    for ( int i = 0; i < n; i++ )
    {
        A[i].resize(m);
        for ( int j = 0; j < m; j++ )
        {
            cin >> A[i][j];
        }
    }

    cout << Rekurzija( 0, 0, 0, 0 );

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define maxn 72
using namespace std;

const ll inf = -1e16;
ll dp[maxn][maxn][maxn][maxn], n, m, mod, mat[maxn][maxn];
ll solve(ll i, ll j, ll l, ll r){
    if(i==n){
        return ((!r) ? 0 : inf);
    }
    if(dp[i][j][l][r]!=-1){
       return  dp[i][j][l][r];
    }
    dp[i][j][l][r] = ((!r) ? 0 : inf);
    dp[i][j][l][r] = max(dp[i][j][l][r],solve(i+1,0,m/2,r));
    for(int k=j;k<m;k++){
        if(l)
            dp[i][j][l][r] = max(dp[i][j][l][r],mat[i][k]+solve(i,k+1,l-1,(r+mat[i][k])%mod));
    }
    return dp[i][j][l][r];
}

ll solve1(){
    for(int i=0;i<maxn;i++)
        for(int j=0;j<maxn;j++)
            for(int k=0;k<maxn;k++)
                for(int l=0;l<maxn;l++)
                    dp[i][j][k][l] = ((!l) ? 0 : inf);

    dp[0][0][0][0] = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            for(int taken=0;taken<m/2+1;taken++){
                for(int r=0;r<mod;r++){
                    dp[i+1][0][0][r] = max(dp[i][j][taken][r],dp[i+1][0][0][r]);
                    dp[i][j+1][taken][r] = max(dp[i][j][taken][r],dp[i][j+1][taken][r]);
                    dp[i][j+1][taken+1][(r+mat[i][j])%mod] = max(dp[i][j][taken][r]+mat[i][j],dp[i][j+1][taken+1][r+(mat[i][j])%mod]);
                }
            }
        }
    }
    ll answ = 0;
    for(int j=0;j<m;j++){
        for(int taken=0;taken<m/2+1;taken++){
            answ = max(dp[n][j][taken][0],answ);
        }
    }
    return answ;
}

int main(){
    cin >> n >> m >> mod;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin >> mat[i][j];

    memset(dp,-1,sizeof(dp));
    cout << solve1() << '\n';
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define maxn 72
using namespace std;

const ll inf = -1e16;
ll dp[maxn][maxn][maxn][maxn], n, m, mod, mat[maxn][maxn];
ll solve(ll i, ll j, ll l, ll r){
    if(i==n){
        return ((!r) ? 0 : inf);
    }
    if(dp[i][j][l][r]!=-1){
       return  dp[i][j][l][r];
    }
    dp[i][j][l][r] = ((!r) ? 0 : inf);
    dp[i][j][l][r] = max(dp[i][j][l][r],solve(i+1,0,m/2,r));
    for(int k=j;k<m;k++){
        if(l)
            dp[i][j][l][r] = max(dp[i][j][l][r],mat[i][k]+solve(i,k+1,l-1,(r+mat[i][k])%mod));
    }
    return dp[i][j][l][r];
}

ll solve1(){
    for(int i=0;i<maxn;i++)
        for(int j=0;j<maxn;j++)
            for(int k=0;k<maxn;k++)
                for(int l=0;l<maxn;l++)
                    dp[i][j][k][l] = ((!l) ? 0 : inf);

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            for(int taken=0;taken<m/2+1;taken++){
                for(int r=0;r<mod;r++){
                    if(j==m-1)
                        dp[i+1][0][0][r] = max(dp[i][j][taken][r],dp[i+1][0][0][r]);
                    else
                        dp[i][j+1][taken][r] = max(dp[i][j][taken][r],dp[i][j+1][taken][r]);
                    dp[i][j+1][taken+1][(r+mat[i][j])%mod] = max(dp[i][j][taken][r]+mat[i][j],dp[i][j+1][taken+1][r+(mat[i][j])%mod]);
                }
            }
        }
    }
    ll answ = 0;
    for(int j=0;j<=m;j++){
        for(int taken=0;taken<m/2+1;taken++){
            answ = max(dp[n][j][taken][0],answ);
        }
    }
    return answ;
}

int main(){
    cin >> n >> m >> mod;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin >> mat[i][j];

    memset(dp,-1,sizeof(dp));
    cout << solve1() << '\n';
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define maxn 72
using namespace std;

const ll inf = -1e16;
ll dp[maxn][maxn][maxn][maxn], n, m, mod, mat[maxn][maxn];
ll solve(ll i, ll j, ll l, ll r){
    if(i==n){
        return ((!r) ? 0 : inf);
    }
    if(dp[i][j][l][r]!=-1){
       return  dp[i][j][l][r];
    }
    dp[i][j][l][r] = ((!r) ? 0 : inf);
    dp[i][j][l][r] = max(dp[i][j][l][r],solve(i+1,0,m/2,r));
    for(int k=j;k<m;k++){
        if(l)
            dp[i][j][l][r] = max(dp[i][j][l][r],mat[i][k]+solve(i,k+1,l-1,(r+mat[i][k])%mod));
    }
    return dp[i][j][l][r];
}

int main(){
    cin >> n >> m >> mod;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin >> mat[i][j];

    memset(dp,-1,sizeof(dp));
    cout << solve(0,0,m/2,0) << '\n';
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define maxn 72
using namespace std;

const ll inf = -1e16;
ll dp[maxn][maxn][maxn][maxn], n, m, mod, mat[maxn][maxn];
ll solve(ll i, ll j, ll l, ll r){
    if(i==n)
        return ((!r) ? 0 : inf);
    if(dp[i][j][l][r]!=-1)
       return  dp[i][j][l][r];
    ll answ=0;
    if(j==m-1)
        answ = max(solve(i+1,0,m/2,r),((l) ? solve(i+1,0,m/2,(r+mat[i][j])%mod)+mat[i][j] : inf));
    else
        answ = max(solve(i,j+1,l,r),((l) ? solve(i,j+1,l-1,(r+mat[i][j])%mod)+mat[i][j] : inf));
    dp[i][j][l][r] = max(answ,((!r) ? 0 : inf));
    return dp[i][j][l][r];
}

int main(){
    cin >> n >> m >> mod;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin >> mat[i][j];

    memset(dp,-1,sizeof(dp));
    cout << solve(0,0,m/2,0) << '\n';
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define maxn 72
using namespace std;

const ll inf = -1e16;
ll dp[maxn][maxn][maxn][maxn], n, m, mod, mat[maxn][maxn];
ll solve(ll i, ll j, ll l, ll r){
    if(i==n)
        return ((!r) ? 0 : inf);
    if(dp[i][j][l][r]!=-1)
       return  dp[i][j][l][r];
    if(j==m-1)
        dp[i][j][l][r] = max(solve(i+1,0,0,r),((l) ? solve(i+1,0,0,(r+mat[i][j])%mod)+mat[i][j] : inf));
    else
        dp[i][j][l][r] = max(solve(i+1,j+1,l,r),((l) ? solve(i+1,j+1,l-1,(r+mat[i][j])%mod)+mat[i][j] : inf));
    dp[i][j][l][r] = max(dp[i][j][l][r],((!r) ? 0 : inf));
    return dp[i][j][l][r];
}

int main(){
    cin >> n >> m >> mod;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin >> mat[i][j];

    memset(dp,-1,sizeof(dp));
    cout << solve(0,0,m/2,0) << '\n';
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define maxn 72
using namespace std;

const ll inf = -1e16;
ll dp[maxn][maxn][maxn][maxn], n, m, mod, mat[maxn][maxn];
ll solve(ll i, ll j, ll l, ll r){
    if(i==n){
        return ((!r) ? 0 : inf);
    }
    if(dp[i][j][l][r]!=-1){
       return  dp[i][j][l][r];
    }
    dp[i][j][l][r] = ((!r) ? 0 : inf);
    dp[i][j][l][r] = max(dp[i][j][l][r],solve(i+1,0,m/2,r));
    for(int k=j;k<m;k++){
        if(l)
            dp[i][j][l][r] = max(dp[i][j][l][r],mat[i][k]+solve(i,k+1,l-1,(r+mat[i][k])%mod));
    }
    return dp[i][j][l][r];
}

ll solve1(){
    for(int i=0;i<maxn;i++)
        for(int j=0;j<maxn;j++)
            for(int k=0;k<maxn;k++)
                for(int l=0;l<maxn;l++)
                    dp[i][j][k][l] = ((!l) ? 0 : inf);

    for(int i=0;i<n;i++){
        for(int j=0;j<=m;j++){
            for(int taken=0;taken<m/2+1;taken++){
                for(int r=0;r<mod;r++){
                    dp[i+1][0][0][r] = max(dp[i][j][taken][r],dp[i+1][0][0][r]);
                    dp[i][j+1][taken][r] = max(dp[i][j][taken][r],dp[i][j+1][taken][r]);
                    dp[i][j+1][taken+1][(r+mat[i][j])%mod] = max(dp[i][j][taken][r]+mat[i][j],dp[i][j+1][taken+1][r+(mat[i][j])%mod]);
                }
            }
        }
    }
    ll answ = 0;
    for(int j=0;j<m;j++){
        for(int taken=0;taken<m/2+1;taken++){
            answ = max(dp[n][j][taken][0],answ);
        }
    }
    return answ;
}

int main(){
    cin >> n >> m >> mod;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin >> mat[i][j];

    memset(dp,-1,sizeof(dp));
    cout << solve1() << '\n';
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define maxn 72
using namespace std;

const ll inf = -1e16;
ll dp[maxn][maxn][maxn][maxn], n, m, mod, mat[maxn][maxn];
ll solve(ll i, ll j, ll l, ll r){
    if(i==n){
        return ((!r) ? 0 : inf);
    }
    if(dp[i][j][l][r]!=-1){
       return  dp[i][j][l][r];
    }
    dp[i][j][l][r] = ((!r) ? 0 : inf);
    dp[i][j][l][r] = max(dp[i][j][l][r],solve(i+1,0,m/2,r));
    for(int k=j;k<m;k++){
        if(l)
            dp[i][j][l][r] = max(dp[i][j][l][r],mat[i][k]+solve(i,k+1,l-1,(r+mat[i][k])%mod));
    }
    return dp[i][j][l][r];
}

ll solve1(){
    for(int i=0;i<maxn;i++)
        for(int j=0;j<maxn;j++)
            for(int k=0;k<maxn;k++)
                for(int l=0;l<maxn;l++)
                    dp[i][j][k][l] = ((!l) ? 0 : inf);

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            for(int taken=0;taken<=m/2;taken++){
                for(int r=0;r<mod;r++){
                    if(j==m-1){
                        dp[i+1][0][0][r] = max(dp[i][j][taken][r],dp[i+1][0][0][r]);
                        if(taken<m/2) dp[i+1][0][0][(r+mat[i][j])%mod] = max(dp[i][j][taken][r]+mat[i][j],dp[i+1][0][0][r+(mat[i][j])%mod]);
                    }
                    else{
                        dp[i][j+1][taken][r] = max(dp[i][j][taken][r],dp[i][j+1][taken][r]);
                        if(taken<m/2) dp[i][j+1][taken+1][(r+mat[i][j])%mod] = max(dp[i][j][taken][r]+mat[i][j],dp[i][j+1][taken+1][r+(mat[i][j])%mod]);
                    }
                }
            }
        }
    }
    return max(0ll,dp[n][0][0][0]);
}

int main(){
    cin >> n >> m >> mod;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin >> mat[i][j];

    memset(dp,-1,sizeof(dp));
    cout << solve1() << '\n';
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define maxn 72
using namespace std;

const ll inf = -1e16;
ll dp[maxn][maxn][maxn][maxn], n, m, mod, mat[maxn][maxn];
ll solve(ll i, ll j, ll l, ll r){
    if(i==n){
        return ((!r) ? 0 : inf);
    }
    if(dp[i][j][l][r]!=-1){
       return  dp[i][j][l][r];
    }
    dp[i][j][l][r] = ((!r) ? 0 : inf);
    dp[i][j][l][r] = max(dp[i][j][l][r],solve(i+1,0,m/2,r));
    for(int k=j;k<m;k++){
        if(l)
            dp[i][j][l][r] = max(dp[i][j][l][r],mat[i][k]+solve(i,k+1,l-1,(r+mat[i][k])%mod));
    }
    return dp[i][j][l][r];
}

ll solve1(){
    for(int i=0;i<maxn;i++)
        for(int j=0;j<maxn;j++)
            for(int k=0;k<maxn;k++)
                for(int l=0;l<maxn;l++)
                    dp[i][j][k][l] = ((!l) ? 0 : inf);

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            for(int taken=0;taken<m/2+1;taken++){
                for(int r=0;r<mod;r++){
                    if(dp[i][j][taken][r]==inf) continue;
                    if(j==m-1){
                        dp[i+1][0][0][r] = max(dp[i][j][taken][r],dp[i+1][0][0][r]);
                        if(taken+1<=m/2) dp[i+1][0][0][(r+mat[i][j])%mod] = max(dp[i][j][taken][r]+mat[i][j],dp[i+1][0][0][r+(mat[i][j])%mod]);
                    }
                    else{
                        dp[i][j+1][taken][r] = max(dp[i][j][taken][r],dp[i][j+1][taken][r]);
                        if(taken+1<=m/2) dp[i][j+1][taken+1][(r+mat[i][j])%mod] = max(dp[i][j][taken][r]+mat[i][j],dp[i][j+1][taken+1][r+(mat[i][j])%mod]);
                    }
                }
            }
        }
    }
    return max(0ll,dp[n][0][0][0]);
}

int main(){
    cin >> n >> m >> mod;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin >> mat[i][j];

    memset(dp,-1,sizeof(dp));
    cout << solve1() << '\n';
    return 0;
}


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

const short int N = 71;
const short int INF = 5000;

short int dp[N][N][N/2+1][N];
short int n, m, k;
short int a[N][N];
short int tmp[N], ans[N];

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

	cin >> n >> m >> k;
	for (short int i = 1; i <= n; ++i)
		for (short int j = 1; j <= m; ++j) cin >> a[i][j];

	for (short int i = 0; i <= n; ++i)
		for (short int j = 0; j <= m; ++j)
			for (short int cnt = 0; cnt <= m / 2; ++cnt)
				for (short int rem = 0; rem < k; ++rem) dp[i][j][cnt][rem] = -INF;

	for (short int i = 1; i <= n; ++i)
		for (short int j = 0; j <= m; ++j) dp[i][j][0][0] = 0;

	for (short int i = 1; i <= n; ++i)
		for (short int j = 1; j <= m; ++j)
			for (short int cnt = 0; cnt <= min((short int) (m/2),j); ++cnt)
				for (short int rem = 0; rem < k; ++rem)
				{
					dp[i][j][cnt][rem] = max(dp[i][j][cnt][rem], dp[i][j - 1][cnt][rem]);
					if (cnt != m / 2) dp[i][j][cnt + 1][(rem + a[i][j]) % k] = max(dp[i][j][cnt + 1][(rem + a[i][j]) % k],
						(short int) (dp[i][j - 1][cnt][rem] + a[i][j]));
				}

	for (short int i = 1; i <= n; ++i)
	{
		for (short int j = 0; j < k; ++j)
		{
			int r = dp[i][m][m / 2][j];
			if (r > 0)
			{
				for (short int l = 0; l < k; l++) tmp[(ans[l] + r) % k] = max(tmp[(ans[l] + r) % k], (short int)(ans[l] + r));
			}
		}
		for (short int l = 0; l < k; l++) ans[l] = tmp[l];
	}
	cout << ans[0] << '\n';
}


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

const int N = 71;
const int INF = 5000;

int dp[N][N][N/2+1][N];
int n, m, k;
int a[N][N];
int tmp[N], ans[N];

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

	cin >> n >> m >> k;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j) cin >> a[i][j];

	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= m; ++j)
			for (int cnt = 0; cnt <= m / 2; ++cnt)
				for (int rem = 0; rem < k; ++rem) dp[i][j][cnt][rem] = -INF;

	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= m; ++j) dp[i][j][0][0] = 0;

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			for (int cnt = 0; cnt <= min(m/2,j); ++cnt)
				for (int rem = 0; rem < k; ++rem)
				{
					dp[i][j][cnt][rem] = max(dp[i][j][cnt][rem], dp[i][j - 1][cnt][rem]);
					if (cnt != m / 2) dp[i][j][cnt + 1][(rem + a[i][j]) % k] = max(dp[i][j][cnt + 1][(rem + a[i][j]) % k],
						(int) (dp[i][j - 1][cnt][rem] + a[i][j]));
				}

	//for (int i = 1; i <= n; ++i)
	//{
	//	for (int j = 0; j < k; ++j)
	//	{
	//		cout << dp[i][m][m / 2][j] << ' ';
	//	}
	//	cout << endl;
	//}

	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j < k; ++j)
		{
			int r = dp[i][m][m / 2][j];
			if (r <= 0) for (int l = 0; l < m / 2; ++l) r = max(r, dp[i][m][l][j]);
			for (int l = 0; l < k; l++) tmp[(ans[l] + r) % k] = max(tmp[(ans[l] + r) % k], (ans[l] + r));
		}
		for (int l = 0; l < k; l++) ans[l] = tmp[l];
	}
	cout << ans[0] << '\n';
}


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

const int N = 71;
const int INF = 5000;

int dp[N][N][N/2+1][N];
int n, m, k;
int a[N][N];
int tmp[N], ans[N];

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

	cin >> n >> m >> k;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j) cin >> a[i][j];

	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= m; ++j)
			for (int cnt = 0; cnt <= m / 2; ++cnt)
				for (int rem = 0; rem < k; ++rem) dp[i][j][cnt][rem] = -INF;

	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= m; ++j) dp[i][j][0][0] = 0;

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			for (int cnt = 0; cnt <= min((int) (m/2),j); ++cnt)
				for (int rem = 0; rem < k; ++rem)
				{
					dp[i][j][cnt][rem] = max(dp[i][j][cnt][rem], dp[i][j - 1][cnt][rem]);
					if (cnt != m / 2) dp[i][j][cnt + 1][(rem + a[i][j]) % k] = max(dp[i][j][cnt + 1][(rem + a[i][j]) % k],
						(int) (dp[i][j - 1][cnt][rem] + a[i][j]));
				}

	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j < k; ++j)
		{
			int r = dp[i][m][m / 2][j];
			if (r > 0)
			{
				for (int l = 0; l < k; l++) tmp[(ans[l] + r) % k] = max(tmp[(ans[l] + r) % k], (int)(ans[l] + r));
			}
		}
		for (int l = 0; l < k; l++) ans[l] = tmp[l];
	}
	cout << ans[0] << '\n';
}


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

const int N = 71;
const int INF = 1e5;

int dp[N][N][N][N];
vector<int> tmp, ans;

int n, m, k, res;
int a[N][N];

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

	cin >> n >> m >> k;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j) cin >> a[i][j];

	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= m; ++j)
			for (int cnt = 0; cnt <= m / 2; ++cnt)
				for (int rem = 0; rem < k; ++rem) dp[i][j][cnt][rem] = -INF;

	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= m; ++j) dp[i][j][0][0] = 0;

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			for (int cnt = 0; cnt <= min(m/2,j); ++cnt)
				for (int rem = 0; rem < k; ++rem)
				{
					dp[i][j][cnt][rem] = max(dp[i][j][cnt][rem], dp[i][j - 1][cnt][rem]);
					if (cnt!=m/2) dp[i][j][cnt+1][(rem + a[i][j]) % k] = max(dp[i][j][cnt+1][(rem + a[i][j]) % k],
						dp[i][j-1][cnt][rem] + a[i][j]);
				}

	ans.push_back(0);
	res = 0;

	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j < k; ++j) if (dp[i][m][m/2][j]>0)
		{
			for (int x : ans)
			{
				tmp.push_back(x + dp[i][m][m / 2][j]);
				if (tmp.back() % k == 0) res = max(res, tmp.back());
			}
		}
		while (!tmp.empty()) ans.push_back(tmp.back()), tmp.pop_back();
	}

	cout << res << '\n';
}


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

const short int N = 71;
const short int INF = 5000;

short int dp[N][N][N/2+1][N];
vector<short int> tmp, ans;

short int n, m, k, res;
short int a[N][N];

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

	cin >> n >> m >> k;
	for (short int i = 1; i <= n; ++i)
		for (short int j = 1; j <= m; ++j) cin >> a[i][j];

	for (short int i = 0; i <= n; ++i)
		for (short int j = 0; j <= m; ++j)
			for (short int cnt = 0; cnt <= m / 2; ++cnt)
				for (short int rem = 0; rem < k; ++rem) dp[i][j][cnt][rem] = -INF;

	for (short int i = 1; i <= n; ++i)
		for (short int j = 0; j <= m; ++j) dp[i][j][0][0] = 0;

	for (short int i = 1; i <= n; ++i)
		for (short int j = 1; j <= m; ++j)
			for (short int cnt = 0; cnt <= min((short int) (m/2),j); ++cnt)
				for (short int rem = 0; rem < k; ++rem)
				{
					dp[i][j][cnt][rem] = max(dp[i][j][cnt][rem], dp[i][j - 1][cnt][rem]);
					if (cnt != m / 2) dp[i][j][cnt + 1][(rem + a[i][j]) % k] = max(dp[i][j][cnt + 1][(rem + a[i][j]) % k],
						(short int) (dp[i][j - 1][cnt][rem] + a[i][j]));
				}

	ans.push_back(0);
	res = 0;

	for (short int i = 1; i <= n; ++i)
	{
		for (short int j = 0; j < k; ++j) if (dp[i][m][m/2][j]>0)
		{
			for (short int x : ans)
			{
				tmp.push_back(x + dp[i][m][m / 2][j]);
				if (tmp.back() % k == 0) res = max(res, tmp.back());
			}
		}
		ans = tmp;
	}

	cout << res << '\n';
}


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

const short int N = 71;
const short int INF = 5000;

short int dp[N][N][N/2+1][N];
vector<short int> tmp, ans;

short int n, m, k, res;
short int a[N][N];

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

	cin >> n >> m >> k;
	for (short int i = 1; i <= n; ++i)
		for (short int j = 1; j <= m; ++j) cin >> a[i][j];

	for (short int i = 0; i <= n; ++i)
		for (short int j = 0; j <= m; ++j)
			for (short int cnt = 0; cnt <= m / 2; ++cnt)
				for (short int rem = 0; rem < k; ++rem) dp[i][j][cnt][rem] = -INF;

	for (short int i = 1; i <= n; ++i)
		for (short int j = 0; j <= m; ++j) dp[i][j][0][0] = 0;

	for (short int i = 1; i <= n; ++i)
		for (short int j = 1; j <= m; ++j)
			for (short int cnt = 0; cnt <= min(short int(m/2),j); ++cnt)
				for (short int rem = 0; rem < k; ++rem)
				{
					dp[i][j][cnt][rem] = max(dp[i][j][cnt][rem], dp[i][j - 1][cnt][rem]);
					if (cnt != m / 2) dp[i][j][cnt + 1][(rem + a[i][j]) % k] = max(dp[i][j][cnt + 1][(rem + a[i][j]) % k],
						short int(dp[i][j - 1][cnt][rem] + a[i][j]));
				}

	ans.push_back(0);
	res = 0;

	for (short int i = 1; i <= n; ++i)
	{
		for (short int j = 0; j < k; ++j) if (dp[i][m][m/2][j]>0)
		{
			for (short int x : ans)
			{
				tmp.push_back(x + dp[i][m][m / 2][j]);
				if (tmp.back() % k == 0) res = max(res, tmp.back());
			}
		}
		while (!tmp.empty()) ans.push_back(tmp.back()), tmp.pop_back();
	}

	cout << res << '\n';
}


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

const int N = 71;
const int INF = 1e5;

int dp[N][N][N/2+1][N];
vector<int> tmp, ans;

int n, m, k, res;
int a[N][N];

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

	cin >> n >> m >> k;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j) cin >> a[i][j];

	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= m; ++j)
			for (int cnt = 0; cnt <= m / 2; ++cnt)
				for (int rem = 0; rem < k; ++rem) dp[i][j][cnt][rem] = -INF;

	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= m; ++j) dp[i][j][0][0] = 0;

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			for (int cnt = 0; cnt <= min(m/2,j); ++cnt)
				for (int rem = 0; rem < k; ++rem)
				{
					dp[i][j][cnt][rem] = max(dp[i][j][cnt][rem], dp[i][j - 1][cnt][rem]);
					if (cnt!=m/2) dp[i][j][cnt+1][(rem + a[i][j]) % k] = max(dp[i][j][cnt+1][(rem + a[i][j]) % k],
						dp[i][j-1][cnt][rem] + a[i][j]);
				}

	ans.push_back(0);
	res = 0;

	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j < k; ++j) if (dp[i][m][m/2][j]>0)
		{
			for (int x : ans)
			{
				tmp.push_back(x + dp[i][m][m / 2][j]);
				if (tmp.back() % k == 0) res = max(res, tmp.back());
			}
		}
		while (!tmp.empty()) ans.push_back(tmp.back()), tmp.pop_back();
	}

	cout << res << '\n';
}


#include<bits/stdc++.h>
using namespace std;
const int N = 72;
const int INF = 5000;
int dp[N][N][N/2+1][N];
int n, m, k;
int a[N][N];
int tmp[N], ans[N];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
cin >> n >> m >> k;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) cin >> a[i][j];
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= m; ++j)
for (int cnt = 0; cnt <= m / 2; ++cnt)
for (int rem = 0; rem < k; ++rem) dp[i][j][cnt][rem] = -INF;
for (int i = 1; i <= n; ++i)
for (int j = 0; j <= m; ++j) dp[i][j][0][0] = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
for (int cnt = 0; cnt <= min(m/2,j); ++cnt)
for (int rem = 0; rem < k; ++rem)
{
dp[i][j][cnt][rem] = max(dp[i][j][cnt][rem], dp[i][j - 1][cnt][rem]);
if (cnt != m / 2) dp[i][j][cnt + 1][(rem + a[i][j]) % k] = max(dp[i][j][cnt + 1][(rem + a[i][j]) % k],
(int) (dp[i][j - 1][cnt][rem] + a[i][j]));
}
//for (int i = 1; i <= n; ++i)
//{
//	for (int j = 0; j < k; ++j)
//	{
// int r = max(dp[i][m][m / 2][j], 0);
// if (r <= 0) for (int l = 0; l < m / 2; ++l) r = max(r, dp[i][m][l][j]);
// cout << r << ' ';
//	}
//	cout << endl;
//}
for (int i = 1; i <= n; ++i)
{
for (int j = 0; j < k; ++j)
{
int r = 0;
for (int l = 0; l <= m / 2; ++l)
{
r = max(0, dp[i][m][l][j]);
for (int s = 0; s < k; s++) tmp[(ans[s] + r) % k] = max(tmp[(ans[s] + r) % k], (ans[s] + r));
}
}
for (int l = 0; l < k; l++) ans[l] = tmp[l];
}
cout << ans[0] << '\n';
}


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

const short int N = 71;
const short int INF = 5000;

short int dp[N][N][N/2+1][N];
vector<short int> tmp, ans;

short int n, m, k, res;
short int a[N][N];

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

	cin >> n >> m >> k;
	for (short int i = 1; i <= n; ++i)
		for (short int j = 1; j <= m; ++j) cin >> a[i][j];

	for (short int i = 0; i <= n; ++i)
		for (short int j = 0; j <= m; ++j)
			for (short int cnt = 0; cnt <= m / 2; ++cnt)
				for (short int rem = 0; rem < k; ++rem) dp[i][j][cnt][rem] = -INF;

	for (short int i = 1; i <= n; ++i)
		for (short int j = 0; j <= m; ++j) dp[i][j][0][0] = 0;

	for (short int i = 1; i <= n; ++i)
		for (short int j = 1; j <= m; ++j)
			for (short int cnt = 0; cnt <= min((short int) (m/2),j); ++cnt)
				for (short int rem = 0; rem < k; ++rem)
				{
					dp[i][j][cnt][rem] = max(dp[i][j][cnt][rem], dp[i][j - 1][cnt][rem]);
					if (cnt != m / 2) dp[i][j][cnt + 1][(rem + a[i][j]) % k] = max(dp[i][j][cnt + 1][(rem + a[i][j]) % k],
						(short int) (dp[i][j - 1][cnt][rem] + a[i][j]));
				}

	ans.push_back(0);
	res = 0;

	for (short int i = 1; i <= n; ++i)
	{
		for (short int j = 0; j < k; ++j) if (dp[i][m][m/2][j]>0)
		{
			for (short int x : ans)
			{
				tmp.push_back(x + dp[i][m][m / 2][j]);
				if (tmp.back() % k == 0) res = max(res, tmp.back());
			}
		}
		while (!tmp.empty()) ans.push_back(tmp.back()), tmp.pop_back();
	}

	cout << res << '\n';
}


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

const int N = 71;
const int INF = 5000;

int dp[N][N][N/2+1][N];
int n, m, k;
int a[N][N];
int tmp[N], ans[N];

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

	cin >> n >> m >> k;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j) cin >> a[i][j];

	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= m; ++j)
			for (int cnt = 0; cnt <= m / 2; ++cnt)
				for (int rem = 0; rem < k; ++rem) dp[i][j][cnt][rem] = -INF;

	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= m; ++j) dp[i][j][0][0] = 0;

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			for (int cnt = 0; cnt <= min(m/2,j); ++cnt)
				for (int rem = 0; rem < k; ++rem)
				{
					dp[i][j][cnt][rem] = max(dp[i][j][cnt][rem], dp[i][j - 1][cnt][rem]);
					if (cnt != m / 2) dp[i][j][cnt + 1][(rem + a[i][j]) % k] = max(dp[i][j][cnt + 1][(rem + a[i][j]) % k],
						(int) (dp[i][j - 1][cnt][rem] + a[i][j]));
				}

	//for (int i = 1; i <= n; ++i)
	//{
	//	for (int j = 0; j < k; ++j)
	//	{
	//		int r = max(dp[i][m][m / 2][j], 0);
	//		if (r <= 0) for (int l = 0; l < m / 2; ++l) r = max(r, dp[i][m][l][j]);
	//		cout << r << ' ';
	//	}
	//	cout << endl;
	//}

	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j < k; ++j)
		{
			int r = 0;
			for (int l = 0; l <= m / 2; ++l)
			{
				r = max(0, dp[i][m][l][j]);
				for (int s = 0; s < k; s++) tmp[(ans[s] + r) % k] = max(tmp[(ans[s] + r) % k], (ans[s] + r));
			}
		}
		for (int l = 0; l < k; l++) ans[l] = tmp[l];
	}
	cout << ans[0] << '\n';
}


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

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define setp(x) fixed << setprecision(x)
#define ordered_set tree<pair<long double, int> , null_type,less<pair<long double, int> >, rb_tree_tag,tree_order_statistics_node_update>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int inf = int(1e9);
const ll INF = ll(1e16);
const int mod = inf + 7;
const double PI = acos(-1.0);
void mul(ll &x, ll y){
  x *= y;
  if(x >= mod) x %= mod;
}
ll bp(ll a, ll n, ll cm){
  ll r = 1;
  while(n){
    if(n & 1) r = r * a % cm;
    a = a * a % cm;
    n >>= 1;
  }
  return r;
}
template<typename T_vector> // neal
void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());

    for (int i = start; i < end; i++)
        cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}
const int S = 4901;
int dp[71][S + 10];
int ndp[71][71];
int ans[71][71];
void solve(){
  int n, m, d;
  cin >> n >> m >> d;
  int a[n + 1][m + 1];
  for(int i = 1; i <= n; ++i)
    for(int j = 1; j <= m; ++j)
      cin >> a[i][j];
  for(int i = 1; i <= n; ++i){
    for(int j = 0; j < d; ++j){
      ndp[i][j] = -inf;
    }
  }
  for(int i = 1; i <= n; ++i){
    for(int j = 0; j <= m; ++j)
      for(int k = 0; k <= S; ++k)
        dp[j][k] = inf;
    dp[0][0] = 0;
    for(int j = 1; j <= m; ++j){
      for(int k = 0; k <= S; ++k){
        dp[j][k] = dp[j - 1][k];
        if(k >= a[i][j])
          dp[j][k] = min(dp[j - 1][k - a[i][j]] + 1, dp[j][k]);
        if(dp[j][k] <= m / 2)
          ndp[i][k % d] = max(ndp[i][k % d], k);
      }
    }
  }
  // rep(i, n){
  //   rep(j, d)
  //     cout << ndp[i + 1][j] << ' ';
  //     cout << '\n';
  // }
  int res = 0;
  ans[0][0] = 0;
  for(int i = 0; i < n; ++i){
    for(int nxt = 0; nxt < d; ++nxt){
      for(int last = 0; last < d; ++last){
        if(~ndp[i + 1][nxt])
          ckmax(ans[i + 1][(nxt + last) % d],
            ans[i][last] + ndp[i + 1][nxt]);
      }
    }
  }
  cout << ans[n][0] - ans[n][0] % d;

}

int main()
{
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
    Red;
    int T = 1;
    // cin >> T;
    for(int i = 1; i <= T; ++i){
      solve();
    }
    return 0;

}