we have two accepted codes for 596C:
http://mirror.codeforces.com/contest/596/submission/14293038
http://mirror.codeforces.com/contest/596/submission/14278646
and a test case:
11 0 0 0 1 0 2 1 0 1 1 1 2 2 0 2 1 2 2 3 0 3 1 0 1 -1 2 0 -2 1 -1 0 -2 -3
and two answers :)
NO
YES 0 0 0 1 1 0 0 2 1 1 2 0 1 2 2 1 2 2 3 1 3 0
Zlobober, come back.