using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProgrammingContest { class MainClass { Scanner sc; static void Main(string[] args) { new MainClass().Solve(); } void Solve() { #if DEBUG string backPath = ".."; char dirSep = System.IO.Path.DirectorySeparatorChar; string inFilePath = backPath + dirSep + backPath + dirSep + "in.txt"; sc = new Scanner(new System.IO.StreamReader(inFilePath)); #else sc = new Scanner(); #endif int n = sc.NextInt; char[][] s = new char[n][].Select(chars => sc.Next.ToCharArray()).ToArray(); //for (int i = 1; i < n; i++) //{ // if (s[0][i] == '-') // { // s[0][i] = 'o'; // s[i][0] = 'x'; // } //} List> list = new List>(); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (s[i][j] == '-') { list.Add(Tuple.Create(i, j)); } } } if (list.Count == 0) { Write(Calc(n, s)); return; } int ans = 111; for (int firstWin = 0; firstWin < (1 << list.Count); firstWin++) { for (int i = 0; i < list.Count; i++) { if ((firstWin & (1 << i)) != 0) { s[list[i].Item1][list[i].Item2] = 'o'; s[list[i].Item2][list[i].Item1] = 'x'; } else { s[list[i].Item1][list[i].Item2] = 'x'; s[list[i].Item2][list[i].Item1] = 'o'; } } ans = Math.Min(ans, Calc(n, s)); } Write(ans); } int Calc(int n, char[][] s) { int[] winCnt = new int[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (s[i][j] == 'o') { winCnt[i]++; } } } State[] st = new State[n]; for (int i = 0; i < n; i++) { st[i] = new State(); st[i].win = winCnt[i]; st[i].idx = i; } Array.Sort(st); Array.Reverse(st); int rank = 1; int preWinCnt = -1; for (int i = 0; i < n; i++) { if (st[i].idx == 0) { return rank; } if (preWinCnt != st[i].win) { preWinCnt = st[i].win; rank++; } } throw new Exception(); } struct State : IComparable { public int win, idx; public int CompareTo(State other) { int ret = Math.Sign(this.win - other.win); if (ret == 0) { ret = Math.Sign(other.idx - this.idx); } return ret; } } void Write(object val) { Console.WriteLine(val.ToString()); } void Write(string format, params object[] vals) { Console.WriteLine(format, vals); } } class Scanner { Queue buffer; char[] sep; System.IO.TextReader reader; public Scanner(System.IO.TextReader reader = null) { this.buffer = new Queue(); this.sep = new char[] { ' ' }; this.reader = (reader ?? Console.In); } private void CheckBuffer() { if (this.buffer.Count == 0 && this.reader.Peek() >= 0) { string[] sreArray = this.reader.ReadLine().Split(this.sep); foreach (String elStr in sreArray) { this.buffer.Enqueue(elStr); } } } public String Next { get { this.CheckBuffer(); return this.buffer.Dequeue(); } } public int NextInt { get { return int.Parse(this.Next); } } public double NextDouble { get { return double.Parse(this.Next); } } public long NextLong { get { return long.Parse(this.Next); } } public bool IsEmpty { get { this.CheckBuffer(); return this.buffer.Count == 0; } } } }