const f = (g, r) => { let gc = g.concat(), rc = r.concat() if (gc.length == 0) { let rs = rc[0], rk = 0, p rc.sort((a,b) => b-a) for (let e of rc) { if (p != e) { rk++ if (e == rs) break p = e } } return rk } else { let ge = gc.pop(), rcc = rc.concat() rcc[ge[0]]++ let rk1 = f(gc, rcc) rcc = rc.concat() rcc[ge[1]]++ let rk2 = f(gc, rcc) return rk1 < rk2 ? rk1 : rk2 } } let m = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n') let n = parseInt(m[0]) let d = [] let s = Array.from(new Array(n)).fill(0) for (let c = 1; c <= n; c++) { Array.prototype.forEach.call(m[c], (e, i) => { if (i > c - 1) { if (e === '-') d.push([c-1, i]) else if (e === 'x') s[i]++ else if (e === 'o') s[c-1]++ } }) } console.log(f(d,s))