cin >> n; int m = 0; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) cin >> g[i][j]; for (int i = 1; i <= n; ++i) { if (g[i][i]) returncout << "NOT MAGIC\n", 0; for (int j = i + 1; j <= n; ++j) { if (g[i][j] != g[j][i]) returncout << "NOT MAGIC\n", 0; e[++m] = { i, j, g[i][j] }; } } sort(e + 1, e + m + 1); init_fa(n); for (int l = 1, r; l <= m; l = r) { r = l; while (e[r].w == e[l].w && r <= m) ++r; for (int i = l; i < r; ++i) if (find(e[i].fr) == find(e[i].to)) returncout << "NOT MAGIC\n", 0; for (int i = l; i < r; ++i) merge(e[i].fr, e[i].to); } cout << "MAGIC\n"; return0; }