#include #include #include #include using namespace std; int N; vector s; vector> pos; int dfs(int depth) { if (depth == 0) { vector tmp = s; const string key = s[0]; sort(s.begin(), s.end(), [](string i, string j){ return count(i.begin(), i.end(), 'o') > count(j.begin(), j.end(), 'o'); }); for (int i = 0; i < N; ++i) { if (s[i] == key) { int counter = 0; for (int j = 0; j < i; ++j) { if (count(s[j].begin(), s[j].end(), 'o') == count(s[j + 1].begin(), s[j + 1].end(), 'o')) ++counter; } s = tmp; return i + 1 - counter; } } } s[pos[depth - 1].first][pos[depth - 1].second] = 'o'; s[pos[depth - 1].second][pos[depth - 1].first] = 'x'; int a = dfs(depth - 1); s[pos[depth - 1].first][pos[depth - 1].second] = 'x'; s[pos[depth - 1].second][pos[depth - 1].first] = 'o'; int b = dfs(depth - 1); return min(a, b); } int main() { cin >> N; for (int i = 0; i < N; ++i) { string tmp; cin >> tmp; s.push_back(tmp); } for (int i = 0; i < N; ++i) { for (int j = 0; j < i; ++j) { if (s[i][j] == '-') pos.push_back(pair(i, j)); } } cout << dfs(pos.size()) << endl; return 0; }