import java.util.*;
import java.math.*;
import java.lang.*;
import java.io.*;
class TestClass {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
public static void main(String args[] ) throws Exception {
int n = Integer.parseInt(br.readLine());
long res = 0;
int arr[][] = new int[n][n];
ArrayList<Integer> adjList[] = new ArrayList[n];
for(int i=0; i<n; i++) {
adjList[i] = new ArrayList<Integer>();
}
for(int i=0; i<n; i++) {
adjList[i] = new ArrayList<Integer>();
String[] s = br.readLine().split(" ");
for(int j=0; j<n; j++) {
int z = Integer.parseInt(s[j]);
if(z == 1) {
adjList[i].add(j);
}
}
}
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
arr[i][j] = 0;
}
}
for(int i=0; i<n; i++) {
for(int j=0; j<adjList[i].size(); j++) {
for(int k=j+1; k<adjList[i].size(); k++) {
arr[adjList[i].get(j)][adjList[i].get(k)]++;
}
}
}
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
res += arr[i][j]*(arr[i][j] - 1);
}
}
pw.println(res/4);
pw.flush();
pw.close();
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.