Fixed a bug in the naive algorithm. It works fine for 5 pair