https://codeforces.com/problemset/problem/717/A

help needed for this question as it doesnot have editorial

It is provided, check the tutorial section of the problem, Bubble Cup finals 2016 Results and Editorial - Codeforces, from there it takes you to the following drive link which has the editorial