This was posted at school for some reason. I solved it using brute force (cheating). It seems like a problem that would appear in an ABC contest. Answer: 4 1 3 1