A tournament is a directed graph without self-loops in which every pair of vertexes is connected by exactly one directed edge. That is, for any two vertexes *u* and *v* (*u* ≠ *v*) exists either an edge going from *u* to *v*, or an edge from *v* to *u*.

You are given a tournament consisting of *n* vertexes. Your task is to find there a cycle of length three.
The first line contains an integer *n* (1 ≤ *n* ≤ 5000). Next *n* lines contain the adjacency matrix *A* of the graph (without spaces). *A*<sub class="lower-index">*i*, *j*</sub> = 1 if the graph has an edge going from vertex *i* to vertex *j*, otherwise *A*<sub class="lower-index">*i*, *j*</sub> = 0. *A*<sub class="lower-index">*i*, *j*</sub> stands for the *j*-th character in the *i*-th line.

It is guaranteed that the given graph is a tournament, that is, *A*<sub class="lower-index">*i*, *i*</sub> = 0, *A*<sub class="lower-index">*i*, *j*</sub> ≠ *A*<sub class="lower-index">*j*, *i*</sub> (1 ≤ *i*, *j* ≤ *n*, *i* ≠ *j*).
5
00100
10000
01001
11101
11000
1 3 2 
5
01111
00000
01000
01100
01110
-1
5
01000
00101
10010
11001
10100
1 2 3 
5
00110
10110
00011
00000
11010
1 3 5 
10
0011000010
1011001101
0000101100
0010101010
1100000100
1111101100
1000100000
1001001011
0110111001
1011111000
1 3 5 
10
0111001000
0011111000
0000110110
0010101110
1000011001
1001000010
0010010101
1100110000
1100101100
1111010110
1 3 5 
10
0101111011
0001111111
1100011110
0010011000
0011000110
0000101011
0000100000
1001011011
0001001000
0011101010
1 4 3 
10
0000010011
1001001111
1100001110
1010010011
1111011000
0110000001
1001010100
1001110000
0000111101
0010101100
1 6 2 
10
0000000000
1001100111
1101101111
1000000011
1001000111
1111101111
1101100111
1001000011
1000000001
1000000000
-1
1
0
-1
2
00
10
-1
3
001
100
010
1 3 2 
3
010
001
100
1 2 3 
2
01
00
-1
3
011
000
010
-1
4
0000
1010
1001
1100
2 3 4 
5
01111
00111
00010
00001
00100
3 4 5 
  /*
    Auther: ghoshashis545 Ashis Ghosh 😎
    College: Jalpaiguri Govt Enggineering College
*/
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma") 

#include <bits/stdc++.h>
#include<algorithm>
#include<string>
using namespace std;
#define ll int
#define int long long
#define ld long double
#define ff first
#define ss string 
#define se second
#define sp(x) cout << fixed << setprecision(x)
#define endl "\n"
#define ub upper_bound
#define lb lower_bound
#define vi vector<int>
#define ipair pair<int,int>
#define vpi vector<ipair>
#define clr(a,x) memset(a,x,sizeof(a))
#define alt(v) v.begin(),v.end()
#define ralt(v) v.rbegin(),v.rend()
#define pb emplace_back
#define mp make_pair
#define PI 3.1415926535897932384626
#define cntb(x) __builtin_popcount(x)
#define fab(i,a,b) for(int i=(a);i<(b);i++)
#define fba(i,a,b) for(int i=(b);i>=(a);i--)

bool ispoweroftwo(int n){return n&(!(n&(n-1)));}
int mod=1000000007;
// int mod=998244353;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};

bool test  = 0;

const int inf = 1e18;
const int N = 5e3+5;

int n;
string s;
vector<int>adj[N],vis(N);
vector<int>res;

int dfs(int u,int st,int sz){
    if(sz == 0)
        return u == st;
    for(auto it : adj[u]){
        if(dfs(it,st,sz-1)){
            res.push_back(it);
            return 1;
        }
    }
    return 0;
}

void solve(int tc = 0)
{
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >>s;
        for(int j = 0; j < n; ++j)
            if(s[j] == '1')
                adj[i+1].push_back(j+1);
    }
    for(int i = 1; i <= n; ++i){
        if(dfs(i,i,3)){
            for(auto it : res)
                cout<<it<<" ";
            cout<<"\n";
            return; 
        }
    }
    cout<<"-1\n";

    
}

 

 
 
 
 
 
 
 
 
 
 
 
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    if(test)
    cin>>t;
    for(int i = 1; i <= t; ++i){
       // cout<<"Case #"<<i<<": ";
        solve(i);
    }
    return 0;
} 