how could I speed my code up?
Andris and Gábor enjoy playing billiards and often go out to play against each other in a few matches. Gábor loves to brag about his good results against Andris. However, he calculates these results in a rather unique way: he only counts the matches starting from the most recent game, and goes back to the match where the difference between their victories is the greatest in his favor (draws are not considered). Gábor always includes the most recent match in his calculations. Formally, if in the last k matches Gábor has gk wins and Andris has ak wins, then he counts the results for that k where the difference between gk and ak is the largest in his favor. If there are multiple such values of k, he will use the smallest k.
Let's take their last N matches, each of which ended in either Andris's victory (A), Gábor's victory (G), or a draw (D). Write a program that determines the most favorable head-to-head result for Gábor after each match!
Input
The first line contains the integer N, the number of matches played.
The second line contains a string of length N, where each character represents the result of a match: 'A' for Andris's win, 'G' for Gábor's win, and 'D' for a draw.
Output
Output N lines, where the i-th line contains the most favorable result for Gábor after the i-th match. The result should be in the format "g - a", where g is the number of Gábor's victories, and a is the number of Andris's victories, considering only the matches that Gábor takes into account at that point.
I got my code in python: (scroll down)