#include <bits/stdc++.h>   template <typename T>   inline void SWAP(T &a, T &b) {     T tmp = a;     a = b;     b = tmp;   }   template <typename T>   inline T ABS(const T &val) {     return val < 0 ? -val : val;   }   template <typename T>   inline T MAX(const T &a, const T &b) {     return a > b ? a : b;   }   template <typename T>   inline T MIN(const T &a, const T &b) {     return a < b ? a : b;   }   template <typename T>   inline T SQR(const T &a) {     return a * a;   }   const int INTinf = 2147483647;   const int nINTinf = 0 - 2147483648;   using namespace std;   int n;   char A[5005][5005];   bool was[5005];   bool bad[5005];   int CY[5005];   int kon = 0;   int POS = 0;   bool FF = false;   bool G = false;   void rec(const int &x) {     if (bad[x]) return;     if (was[x]) {       POS = x;       FF = true;     } else {       was[x] = true;       for (int i = 0; i != n; i++) {         if (A[x][i]) {           rec(i);           if (FF) {             if (!G) {               CY[kon++] = x;               if (POS == x) G = true;             }             return;           }         }       }       bad[x] = true;     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i != n; i++) {       scanf( %s , A[i]);       for (int j = 0; j != n; j++) {         A[i][j] -=  0 ;       }     }     for (int i = 0; i != n; i++) {       if (!bad[i]) rec(i);       if (FF) break;     }     if (FF) {       reverse(CY, CY + kon);       int ST = CY[0];       for (int i = 2; i != kon; i++) {         if (A[CY[i]][ST]) {           cout << ST + 1 <<     << CY[i - 1] + 1 <<     << CY[i] + 1 << endl;           return 0;         }       }     } else {       cout << -1 << endl;     }     return 0;   }   