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

int n, d, k, pre2[101], pre3[101][101];
vector<int> v[100001];

vector<int> operator+(vector<int> a, vector<int> b) {
	vector<int> r(d);
	for (int i = 0; i < d; i ++) r[i] = a[i] + b[i] % k;
	return r;
}

int operator*(vector<int> a, vector<int> b) {
	int s = 0;
	for (int i = 0; i < d; i ++) s = (s + a[i] * b[i]) % k;
	return s;
}

void check(int i) {
	for (int j = 0; j < i; j ++) {
		if (v[i] * v[j] == 0) {
			int x = v[i][d];
			int y = v[j][d];
			if (x > y) swap(x, y);
			cout << x << " " << y << '\n';
			return;
		}
	}
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n >> d >> k;
	for (int i = 0; i < n; i ++) {
		v[i] = vector<int>(d + 1);
		for (int j = 0; j < d; j ++) {
			cin >> v[i][j];
			v[i][j] %= k;
		}
		v[i][d] = i + 1; // index for random shuffle
	}
	random_shuffle(v, v + n);
	if (k == 2) {
		for (int i = 0; i < n; i ++) {
			vector<int> x = v[i];
			int s = 0;
			for (int j = 0; j < d; j ++) {
				s = (s + x[j] * pre2[j]) % k;
				pre2[j] = (pre2[j] + x[j]) % k;
			}
			if (s % 2 != i % 2) {
				check(i);
				return 0;
			}
		}
		cout << "-1 -1\n";
	} else {
		for (int i = 0; i < n; i ++) {
			vector<int> x = v[i];
			int s = 0;
			for (int j = 0; j < d; j ++) {
				for (int l = 0; l < d; l ++) {
					s = (s + x[j] * x[l] * pre3[j][l]) % k;
					pre3[j][l] += x[j] * x[l];
				}
			}
			if (s % 3 != i % 3) {
				check(i);
				return 0;
			}
		}
		cout << "-1 -1\n";
	}
}

/*
input:
3 5 2 
1 0 1 0 1 
1 1 0 1 0 
0 1 0 1 1

output:
2 3
*/
Success #stdin #stdout 0s 6080KB
stdin
3 5 2 
1 0 1 0 1 
1 1 0 1 0 
0 1 0 1 1
stdout
2 3