#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;
const int M = 4100;
std::bitset<M> B[M][2];
void solve() {
  int n, m, k;
  std::cin >> n >> m >> k;
  std::vector<std::vector<int>> a(n, std::vector<int>(m));
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      char x;
      std::cin >> x;
      if(x == 'A') {
        a[i][j] = 0;
      }
      if(x == 'C') {
        a[i][j] = 1;
      }
      if(x == 'G') {
        a[i][j] = 2;
      }
      if(x == 'T') {
        a[i][j] = 3;
      }
    }
  }
  /**
  for(int i = 1; i <= n; i++) {
    int is = 1;
    for(int ath = 1; ath <= n; ath++) {
      if(i == ath) {
        continue;
      }
      int diff = 0;
      for(int x = 1; x <= m; x++) {
        diff += (a[i][x] != a[ath][x]);
      }
      is &= (diff == k);
    }
    if(is) {
      std::cout << i;
      return;
    }
  }**/
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      B[i][a[i][j]].set(j);
    }
  }
  std::vector<std::vector<int>> cnt(n + 1, std::vector<int>(2));
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      cnt[i][a[i][j]] += 1;
    }
  }
  std::function<int(int, int)> can = [&] (int i, int j) {
    int diff = 0;
    for(int x = 0; x < 2; x++) {
      diff += cnt[i][x] - (B[i][x] & B[j][x]).count();
    }
    return diff == k;
  };
  std::function<int(int)> is = [&] (int i) {
    int ok = 1;
    for(int y = 0; y < n; y++) {
      if(y == i) {
        continue;
      }
      ok &= can(i, y);
    }
    return ok;
  };
  int rnd = rand() % n;
  std::vector<int> p;
  for(int i = 0; i < n; i++) {
    if(rnd == i) {
      continue;
    }
    if(can(rnd, i)) {
      p.push_back(i);
    }
  }
  random_shuffle(p.begin(), p.end());
  if(p.size() == n - 1) {
    std::cout << rnd;
    return;
  }
  for(auto may : p) {
    if(is(may)) {
      std::cout << may + 1;
      return;
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int t = 1;
  //std::cin >> t;
  while (t--) {
      solve();
  }
  return 0;
}
| # | 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... |