#C3555. Maximum Valid Promotional Discount

    ID: 46995 Type: Default 1000ms 256MiB

Maximum Valid Promotional Discount

Maximum Valid Promotional Discount

A customer can use a promo code to get a discount on their purchase. However, not all promo codes are valid. A promo code is considered valid if it does not contain the substrings \(\texttt{AB}\) or \(\texttt{BA}\). Given a list of promo codes along with their discount values, your task is to determine the maximum discount that can be obtained from a valid promo code.

Formally, if you are given an integer \(n\) and \(n\) pairs \((S_i, d_i)\) where \(S_i\) is the promo code and \(d_i\) is its associated discount, then let the set of valid promo codes be those for which \(S_i\) does not contain the substring \(\texttt{AB}\) or \(\texttt{BA}\). The answer is the maximum \(d_i\) among these valid codes. If no promo code is valid, print \(0\).

Examples:

Input:
3
A1B2 50
C3D4 100
E5F6G7 75

Output: 100

</p>

inputFormat

The input is given from stdin and it follows the format below:

n
promo_code_1 discount_1
promo_code_2 discount_2
... 
promo_code_n discount_n

Here, \(n\) is the number of promo codes, and each subsequent line contains a string representing the promo code and an integer representing the discount, separated by space.

outputFormat

Output a single integer to stdout which is the maximum discount provided by a valid promo code. If none of the promo codes is valid, output \(0\).

## sample
3
A1B2 50
C3D4 100
E5F6G7 75
100