EveryoneBasically everyone above hit the nail on its head. I want to add an algorithm of counting every cycles of length 4 in an undirected graph, which runs in $O(n^3)$ instead of $O(n^4)$
Every cycle of length four includes four nodes $a$, $b$, $c$ and $d$. Thus for every pair of nodes, $u$ and $v$, you count the number of nodes that are neighbors to both $u$ and $v$. Then the problem of counting every cycle of length four transforms to the problem of selecting 2 such nodes that are adjacent to both $u$ and $v$.