This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)
#define MP make_pair
//#define endl '\n'
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
const int MOD = 1e9 + 7;
const int N = 4100;
string s[N];
bitset<N> b[4][N];
bool removed[N];
int cnt[N][N];
int hamming(int i, int j){
    if (cnt[i][j] != -1) return cnt[i][j];
    int res = (int) s[i].size();
    for (auto & t : b){
        res -= (t[i] & t[j]).count();
    }
    return cnt[i][j] = cnt[j][i] = res;
}
void solve(){
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int t = 0; t < 4; t++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (s[i][j] == "ACGT"[t]) {
                    b[t][i].set(j);
                }
            }
        }
    }
    vector<int> perm(n);
    iota(all(perm), 0);
    shuffle(all(perm), rng);
    memset(cnt, -1, sizeof(cnt));
    for (int i : perm){
        if (removed[i]) continue;
        for (int j : perm){
            if (i == j) break;
            if (removed[j]) continue;
            if (hamming(i, j) != k){
                removed[i] = true;
                removed[j] = true;
                break;
            }
        }
    }
    for (int i : perm){
        if (removed[i]) continue;
        bool ok = true;
        for (int j : perm){
            if (i != j && hamming(i, j) != k){
                ok = false;
                break;
            }
        }
        if (ok){
            cout << i + 1 << endl;
            return;
        }
    }
}
int main(){
    clock_t startTime = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int test_cases = 1;
//    cin >> test_cases;
    for (int test = 1; test <= test_cases; test++){
        // cout << (solve() ? "YES" : "NO") << endl;
        solve();
    }
#ifdef LOCAL
    cerr << "Time: " << int((double) (clock() - startTime) / CLOCKS_PER_SEC * 1000) << " ms" << endl;
#endif
    return 0;
}
Compilation message (stderr)
genetics.cpp: In function 'int main()':
genetics.cpp:92:13: warning: unused variable 'startTime' [-Wunused-variable]
   92 |     clock_t startTime = clock();
      |             ^~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |