#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct edge{
int from, to, cost;
};
const int INF = 1e9;;
int main(){
int n;
cin >> n;
vector <edge> E;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
int x;
cin >> x;
if(x != 0 && x != 100000){
E.push_back({i,j,x});
}
}
}
int x ;
vector<int> d(n, INF), p(n, -1);
d[0] = 0;
for(int i = 0; i < n; i++){
x = -1;
for(int j = 0; j < E.size(); j++){
int from = E[j].from;
int to = E[j].to;
int cost = E[j].cost;
if(d[to] > d[from] + cost ){
d[to] = max(d[from] + cost, -INF);
p[to] = from;
x = to;
}
}
}
if(x == -1){
cout << "NO" << endl;
}else{
int y = x;
for(int i = 0; i < n; i++){
y = p[y];
}
vector <int> path;
for(int cur = y;; cur = p[cur]){
path.push_back(cur);
if(cur == y && path.size() > 1){
break;
}
}
reverse(path.begin(), path.end());
cout << "YES" << endl;
cout << path.size() << endl;
for(int i = 0; i < path.size(); i++){
cout << path[i] + 1;
if(i != path.size()-1){
cout << ' ';
}
}
cout << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IGVkZ2V7CiAgICBpbnQgZnJvbSwgdG8sIGNvc3Q7Cn07CmNvbnN0IGludCBJTkYgPSAxZTk7OwoKaW50IG1haW4oKXsKICAgIGludCBuOwogICAgY2luID4+IG47CiAgICB2ZWN0b3IgPGVkZ2U+IEU7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKXsKICAgICAgICBmb3IoaW50IGogPSAwOyBqIDwgbjsgaisrKXsKICAgICAgICAgICAgaW50IHg7CiAgICAgICAgICAgIGNpbiA+PiB4OwogICAgICAgICAgICBpZih4ICE9IDAgJiYgeCAhPSAxMDAwMDApewogICAgICAgICAgICAgICAgRS5wdXNoX2JhY2soe2ksaix4fSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBpbnQgeCA7CiAgICB2ZWN0b3I8aW50PiBkKG4sIElORiksIHAobiwgLTEpOwogICAgZFswXSA9IDA7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKXsKICAgICAgICB4ID0gLTE7CiAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IEUuc2l6ZSgpOyBqKyspewogICAgICAgICAgICBpbnQgZnJvbSA9IEVbal0uZnJvbTsKICAgICAgICAgICAgaW50IHRvID0gRVtqXS50bzsKICAgICAgICAgICAgaW50IGNvc3QgPSBFW2pdLmNvc3Q7CiAgICAgICAgICAgIGlmKGRbdG9dID4gZFtmcm9tXSArIGNvc3QgKXsKICAgICAgICAgICAgICAgIGRbdG9dID0gbWF4KGRbZnJvbV0gKyBjb3N0LCAtSU5GKTsKICAgICAgICAgICAgICAgIHBbdG9dID0gZnJvbTsKICAgICAgICAgICAgICAgIHggPSB0bzsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIGlmKHggPT0gLTEpewogICAgICAgIGNvdXQgPDwgIk5PIiA8PCBlbmRsOwogICAgfWVsc2V7CiAgICAgICAgaW50IHkgPSB4OwogICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspewogICAgICAgICAgICB5ID0gcFt5XTsKICAgICAgICB9CiAgICAgICAgdmVjdG9yIDxpbnQ+IHBhdGg7CiAgICAgICAgZm9yKGludCBjdXIgPSB5OzsgY3VyID0gcFtjdXJdKXsKICAgICAgICAgICAgcGF0aC5wdXNoX2JhY2soY3VyKTsKICAgICAgICAgICAgaWYoY3VyID09IHkgJiYgcGF0aC5zaXplKCkgPiAxKXsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldmVyc2UocGF0aC5iZWdpbigpLCBwYXRoLmVuZCgpKTsKICAgICAgICBjb3V0IDw8ICJZRVMiIDw8IGVuZGw7CiAgICAgICAgY291dCA8PCBwYXRoLnNpemUoKSA8PCBlbmRsOwogICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCBwYXRoLnNpemUoKTsgaSsrKXsKICAgICAgICAgICAgY291dCA8PCBwYXRoW2ldICsgMTsKICAgICAgICAgICAgaWYoaSAhPSBwYXRoLnNpemUoKS0xKXsKICAgICAgICAgICAgICAgIGNvdXQgPDwgJyAnOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgZW5kbDsKICAgIH0KICAgIHJldHVybiAwOwp9