// Program 77: Doubly Markov Matrix import java.util.*; class DoublyMarkov { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); if (n < 1 || n > 9) { System.out.println("INVALID ORDER"); return; } double[][] a = new double[n][n]; boolean ok = true; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][j] = sc.nextDouble(); if (a[i][j] < 0) { ok = false; } } } for (int i = 0; i < n; i++) { double row = 0, col = 0; for (int j = 0; j < n; j++) { row += a[i][j]; col += a[j][i]; } if (Math.abs(row - 1.0) > 0.0001 || Math.abs(col - 1.0) > 0.0001) { ok = false; } } System.out.println(ok ? "DOUBLY MARKOV MATRIX" : "NOT A DOUBLY MARKOV MATRIX"); } }