Here there are 3 solutions to codility sample task.
The first two fail the "performance test", since they are of order O(n^2). They also fail one of the tests (they give a wrong answer), need to investigate that.
The third one passes 100% of the tests and it's much simpler. At first, I didn't realise the range of possible values for A elements was small enough to try this approach.