The reason the cow crossed the road is simply that there are so many roads. John's farm has so many roads that a cow can hardly move around without crossing one.
John's farm was recently reorganized. It is now an N×N grid of small square pastures (2≤N≤100). A cow can usually walk freely between two adjacent pastures, but some adjacent pairs are separated by a road that the cow must cross to go between them. A tall fence surrounds the farm, so no cow ever leaves it.
There are K cows on John's farm (1≤K≤100, K≤N2), each in a different pasture. Some pairs of cows cannot meet unless one of them crosses a road. Count how many such pairs there are.