Farmer John (a different John from the one we have been helping so far) has N breeds of cows on his farm, numbered breed 1, breed 2, ..., breed N (1≤N≤1000). Cows of breed a and breed b are friendly if ∣a−b∣≤4, and unfriendly otherwise.
A straight road runs through the farm, with N pastures on each side. Each pasture on the left side holds one breed of cow, and every breed appears in exactly one left pasture. The right side is arranged the same way. To prevent traffic accidents, John wants to build crosswalks. Each crosswalk connects one pasture on the left side to one pasture on the right side, and it does not have to be perpendicular to the road. A crosswalk may only connect two pastures whose cows are friendly. Each pasture may have at most one crosswalk, and no two crosswalks may cross each other.
Find the maximum number of crosswalks John can build.