description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Problem Statement It is 2042 and we are surrounded by cyborgs everywhere. Geneo is one such cyborg with a human body and an electronic brain. To monitor skills and health of Geneo he is posed with questions everyday. On one fine day Geneo was asked the following question. You are given a string S of size N containing letters a to z. You are allowed to remove a character from the string and exchange it for a number signifying its position. i.e a -> 1, b -> 2, c -> 3, ... z -> 26. After some number of these operations you arrive at a final array A. Power P of any such array is defined as: count of letters - count of numbers + (sum of numbers/K) where K is a given integer and '/' denotes float division. Geneo has to find maximum possible power P_{max} of such an array. You want to test if Geneo is right. For this you have to generate correct answers for the question. ------ Input section ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a two space separated integers N and K. The second line of each test case contains the string S of size N. ------ Output Section ------ For each test case, output a single line containing two space seperated integers a and b such that a / b = P_{max} - the maximum possible power achievable after transformation and gcd(a,b) = 1. ------ Input constraints ------ 1 ≀ T ≀ 100 1 ≀ N ≀ 1000 1 ≀ K ≀ 1000 ----- Sample Input 1 ------ 2 10 6 abcdefghij 10 1 qwertyuiop ----- Sample Output 1 ------ 10 1 159 1 ----- explanation 1 ------ For the first test case, if we replace no character, we get an array comprising of letters only. This gives us the maximum power 10. For the second test case, we get maximum power when we replace all the characters by respective numbers.
import itertools def map_to_values(s): return ord(s.lower()) - 71 - 25 def gcd(a, b): while b: a, b = b, a % b return a def a_b(Mpow, K): d = gcd(Mpow, K) Mpow //= d K //= d print(Mpow, K) pass def max_power(S, K): S = list(S) S.sort() S.reverse() """""".join(S) count_of_letters = len(S) count_of_numbers = 0 sum_of_numbers = 0 Mpow = len(S) for s in S: if ( count_of_letters - 1 - (count_of_numbers + 1) + (sum_of_numbers + map_to_values(s)) / K > Mpow ): Mpow = ( count_of_letters - 1 - (count_of_numbers + 1) + (sum_of_numbers + map_to_values(s)) / K ) count_of_letters += -1 count_of_numbers += 1 sum_of_numbers += map_to_values(s) else: break a_b(K * (count_of_letters - count_of_numbers) + sum_of_numbers, K) pass T = int(input().strip()) for i in range(T): lst = list(map(int, input().strip().split(" "))) N = lst[0] K = lst[1] S = input().strip() max_power(S, K)
IMPORT FUNC_DEF RETURN BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Problem Statement It is 2042 and we are surrounded by cyborgs everywhere. Geneo is one such cyborg with a human body and an electronic brain. To monitor skills and health of Geneo he is posed with questions everyday. On one fine day Geneo was asked the following question. You are given a string S of size N containing letters a to z. You are allowed to remove a character from the string and exchange it for a number signifying its position. i.e a -> 1, b -> 2, c -> 3, ... z -> 26. After some number of these operations you arrive at a final array A. Power P of any such array is defined as: count of letters - count of numbers + (sum of numbers/K) where K is a given integer and '/' denotes float division. Geneo has to find maximum possible power P_{max} of such an array. You want to test if Geneo is right. For this you have to generate correct answers for the question. ------ Input section ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a two space separated integers N and K. The second line of each test case contains the string S of size N. ------ Output Section ------ For each test case, output a single line containing two space seperated integers a and b such that a / b = P_{max} - the maximum possible power achievable after transformation and gcd(a,b) = 1. ------ Input constraints ------ 1 ≀ T ≀ 100 1 ≀ N ≀ 1000 1 ≀ K ≀ 1000 ----- Sample Input 1 ------ 2 10 6 abcdefghij 10 1 qwertyuiop ----- Sample Output 1 ------ 10 1 159 1 ----- explanation 1 ------ For the first test case, if we replace no character, we get an array comprising of letters only. This gives us the maximum power 10. For the second test case, we get maximum power when we replace all the characters by respective numbers.
import sys sys.setrecursionlimit(100000) def gcd(a, b): if a == 0 or b == 0: False if a == b: return a if a > b: return gcd(a - b, b) return gcd(a, b - a) for _ in range(int(input())): n, k = map(int, input().split()) s = input() d = { "a": 0, "b": 0, "c": 0, "d": 0, "e": 0, "f": 0, "g": 0, "h": 0, "i": 0, "j": 0, "k": 0, "l": 0, "m": 0, "n": 0, "o": 0, "p": 0, "q": 0, "r": 0, "s": 0, "t": 0, "u": 0, "v": 0, "w": 0, "x": 0, "y": 0, "z": 0, } for i in s: d[i] += 1 characters = [ "z", "y", "x", "w", "v", "u", "t", "s", "r", "q", "p", "o", "n", "m", "l", "k", "j", "i", "h", "g", "f", "e", "d", "c", "b", "a", ] ans = [n] fraction = [[n, 1]] summ = 0 count = 0 for i in characters: for j in range(d[i]): summ += ord(i) - ord("a") + 1 count += 1 ans.append(n - 2 * count + summ / k) fraction.append([k * (n - 2 * count) + summ, k]) iii = ans.index(max(ans)) if fraction[iii][0] > fraction[iii][1]: ggg = gcd(fraction[iii][0], fraction[iii][1]) else: ggg = gcd(fraction[iii][0], fraction[iii][1]) print(fraction[iii][0] // ggg, fraction[iii][1] // ggg)
IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER EXPR NUMBER IF VAR VAR RETURN VAR IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST VAR ASSIGN VAR LIST LIST VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
a = int(input()) l1 = input() s = 0 a1 = 0 a2 = 0 c1 = 0 for k in range(a): if l1[k] == "?": c1 += 1 else: s += int(l1[k]) if k == int(a / 2) - 1: a1 = c1 a2 = s if c1 % 2 == 0: if a1 <= c1 - a1: for i in range(int(c1 / 2) + 1): if a1 == i: if s - a2 - a2 <= 0: if a2 - (s - a2) == 9 * (int(c1 / 2) - i): print("Bicarp") break else: print("Monocarp") break else: print("Monocarp") break else: for i in range(int(c1 / 2) + 1): if a1 == i + int(c1 / 2): if s - a2 - a2 >= 0: if s - a2 - a2 == 9 * i: print("Bicarp") break else: print("Monocarp") break else: print("Monocarp") break else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
ii = lambda: int(input()) kk = lambda: map(int, input().split()) ll = lambda: list(kk()) n, digs = ii(), input() d1 = [int(digs[i]) for i in range(n // 2) if digs[i] != "?"] d2 = [int(digs[i]) for i in range(n // 2, n) if digs[i] != "?"] missing = n - len(d1) - len(d2) if len(d1) > len(d2): d1, d2 = d2, d1 m1 = n // 2 - len(d1) m2 = n // 2 - len(d2) n1 = sum(d1) n2 = sum(d2) min1 = n1 + 9 * missing // 2 max1 = n1 + 9 * m1 max2 = n2 + 9 * m2 min2 = n2 if max(min1, min2) > min(max1, max2): print("Monocarp") exit() min1 = n1 max1 = n1 + 9 * (m1 - missing // 2) if max(min1, min2) > min(max1, max2): print("Monocarp") exit() print("Bicarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() l, r = 0, 0 l_t, r_t = 0, 0 for i in s[: n // 2]: if i == "?": l += 1 else: l_t += int(i) for i in s[n // 2 :]: if i == "?": r += 1 else: r_t += int(i) if l_t > r_t and r > l: tem = (r - l) // 2 if tem * 9 == l_t - r_t: print("Bicarp") else: print("Monocarp") elif l_t < r_t and r < l: tem = (l - r) // 2 if tem * 9 == r_t - l_t: print("Bicarp") else: print("Monocarp") elif l_t == r_t and r == l: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() hatena = [0, 0] total = [0, 0] for i in range(n // 2): if s[i] == "?": hatena[0] += 1 else: total[0] += int(s[i]) for i in range(n // 2, n): if s[i] == "?": hatena[1] += 1 else: total[1] += int(s[i]) mono_turn = (sum(hatena) + 1) // 2 bi_turn = sum(hatena) // 2 x = min((hatena[0] + 1) // 2, mono_turn) y = hatena[1] - x if total[0] + 9 * hatena[0] > total[1] + 9 * bi_turn: print("Monocarp") elif total[1] + 9 * hatena[1] > total[0] + 9 * bi_turn: print("Monocarp") else: print("Bicarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
from sys import stdin n = int(stdin.readline().strip()) s = stdin.readline().strip() l = 0 ls = 0 for i in range(n // 2): if s[i] == "?": l += 1 else: ls += int(s[i]) r = 0 rs = 0 for i in range(n // 2, n): if s[i] == "?": r += 1 else: rs += int(s[i]) if ls - (rs + r * 9) + (ls + 9 * l - rs) != 0: print("Monocarp") else: print("Bicarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() a, b = 0, 0 q1, q2 = [], [] for i in range(n // 2): if s[i] != "?": a += int(s[i]) else: q1.append(i) if s[n - i - 1] != "?": b += int(s[n - i - 1]) else: q2.append(n - i - 1) a += len(q1) // 2 * 9 b += len(q2) // 2 * 9 if a == b: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER STRING VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
def f(q1, q2, k1, k2): res1 = res2 = 0 res1 += (q1 + 1) // 2 * k1 res1 += q1 // 2 * k2 res2 += q2 // 2 * k2 res2 += (q2 + 1) // 2 * k1 return [res1, res2] n = int(input()) s = input() sum_l = sum_r = 0 ql = qr = 0 for i in range(n // 2): if s[i] == "?": ql += 1 else: sum_l += int(s[i]) for i in range(n // 2, n): if s[i] == "?": qr += 1 else: sum_r += int(s[i]) mn = float("inf") mx = float("inf") kek = [f(ql, qr, 0, 9), f(ql, qr, 9, 0), f(qr, ql, 9, 0)[::-1], f(qr, ql, 0, 9)[::-1]] lol = [] for x in kek: lol.append(x[0] + sum_l - x[1] - sum_r) lol.sort() if lol[0] <= 0 <= lol[-1]: print("Bicarp") else: print("Monocarp")
FUNC_DEF ASSIGN VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR RETURN LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) ticket = input() left = right = diff = 0 for i in range(n // 2): if ticket[i] == "?": left += 1 else: diff += int(ticket[i]) for i in range(n // 2, n): if ticket[i] == "?": right += 1 else: diff -= int(ticket[i]) if left > right: temp = left left = right right = temp diff = -diff bad = (right - left) // 2 * 9 if diff == bad: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
import sys input = sys.stdin.readline sys.setrecursionlimit(1000000) def lis(): return [int(i) for i in input().split()] def value(): return int(input()) n = value() a = input().strip("\n") l1, l2 = a[: n // 2].count("?"), a[n // 2 :].count("?") s1 = s2 = 0 for i in range(len(a)): if i < n // 2: s1 += int(a[i]) if a[i] != "?" else 0 else: s2 += int(a[i]) if a[i] != "?" else 0 no = 1 for i in range(l1): if s1 > s2: if no: s1 += 9 else: s1 += 0 elif no: s1 += 0 else: s1 += 9 no = 1 - no for i in range(l2): if s1 > s2: if no: s2 += 0 else: s2 += 9 elif no: s2 += 9 else: s2 += 0 no = 1 - no if s1 != s2: print("Monocarp") else: print("Bicarp")
IMPORT ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR STRING FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR STRING FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
N = int(input()) s = input() leftSum = sum(int(c) for c in s[: N // 2] if c != "?") rightSum = sum(int(c) for c in s[N // 2 :] if c != "?") leftOptions = 0 leftSum = 0 for c in s[: N // 2]: if c == "?": leftOptions += 1 else: leftSum += int(c) rightOptions = 0 rightSum = 0 for c in s[N // 2 :]: if c == "?": rightOptions += 1 else: rightSum += int(c) remaining = abs(leftOptions - rightOptions) if leftOptions > rightOptions: leftSum += remaining // 2 * 9 else: rightSum += remaining // 2 * 9 if leftSum == rightSum: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
def main(): n = int(input()) a = list(input()) ls = 0 rs = 0 lq = 0 rq = 0 for i in range(n // 2): if a[i] == "?": lq += 1 else: ls += int(a[i]) for i in range(n // 2, n): if a[i] == "?": rq += 1 else: rs += int(a[i]) if ls == rs: if lq == rq: print("Bicarp") else: print("Monocarp") elif ls > rs: if lq < rq and (rq - lq) // 2 * 9 == ls - rs: print("Bicarp") else: print("Monocarp") elif rq < lq and (lq - rq) // 2 * 9 == rs - ls: print("Bicarp") else: print("Monocarp") return main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR IF VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = list(input()) sum_start = 0 sum_end = 0 miss_start = 0 miss_end = 0 for i in range(n): if i + 1 > n // 2: if s[i] == "?": miss_end += 1 else: sum_end += int(s[i]) elif s[i] == "?": miss_start += 1 else: sum_start += int(s[i]) diff_start = sum_start - sum_end + 9 * (miss_start // 2) if miss_start % 2: diff_start += 9 diff_end = sum_end - sum_start + 9 * (miss_end // 2) if miss_end % 2: diff_end += 9 negotiate_end = 9 * (miss_end // 2) if miss_end % 2: negotiate_end += 9 negotiate_start = 9 * (miss_start // 2) if miss_start % 2: negotiate_start += 9 if diff_start > negotiate_end or diff_end > negotiate_start: print("Monocarp") else: print("Bicarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() def val(c): return 9 if c == "?" else 2 * int(c) lsum = sum(map(val, s[: n // 2])) rsum = sum(map(val, s[n // 2 :])) print("Bicarp" if lsum == rsum else "Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN VAR STRING NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() fer = 0 f = 0 l = 0 ler = 0 for i in range(int(n / 2)): if s[i] == "?": fer += 1 else: f += int(s[i]) for i in range(int(n / 2), n): if s[i] == "?": ler += 1 else: l += int(s[i]) if (fer + ler) % 2: print("Monocarp") elif f < l: if l - f == 9 * ((fer - ler) / 2): print("Bicarp") else: print("Monocarp") elif f - l == 9 * ((ler - fer) / 2): print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
from sys import stdin n = int(stdin.readline()) div = n // 2 digs = stdin.readline().strip() left = 0 right = 0 leftQ = 0 rightQ = 0 for x in range(div): if digs[x] != "?": left += int(digs[x]) * 2 else: leftQ += 1 left += 9 if digs[div + x] != "?": right += int(digs[div + x]) * 2 else: rightQ += 1 right += 9 if left == right: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR STRING VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() lsu = 0 rsu = 0 for c in s[0 : n // 2]: if c == "?": lsu += 9 else: lsu += 2 * int(c) for c in s[n // 2 :]: if c == "?": rsu += 9 else: rsu += 2 * int(c) print("Bicarp" if lsu == rsu else "Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR VAR FOR VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() s1, s2, c1, c2, ans = 0, 0, 0, 0, 0 for i in range(n // 2): if s[i] == "?": c1 += 1 else: s1 += int(s[i]) for i in range(n // 2, n): if s[i] == "?": c2 += 1 else: s2 += int(s[i]) k = (c1 + c2) // 2 c = c1 // 2 + c1 % 2 x1, y1 = s1 + c * 9, s2 + (c2 - (k - c)) * 9 c = c2 // 2 + c2 % 2 x2, y2 = s2 + c * 9, s1 + (c1 - (k - c)) * 9 if y1 >= x1 and y2 >= x2: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
def b4_ticket_game(n, s): l = 0 r = 0 for i in range(n): if s[i] != "?": if i < n // 2: l += int(s[i]) r += int(s[i]) else: l -= int(s[i]) r -= int(s[i]) elif i < n // 2: r += 9 else: l -= 9 if l + r == 0: return True else: return False n = int(input()) s = input() result = b4_ticket_game(n, s) if result: print("Bicarp") else: print("Monocarp")
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() left_cnt = 0 right_cnt = 0 left_num = 0 right_num = 0 for i in range(n // 2): if s[i] == "?": left_cnt += 1 else: left_num += int(s[i]) for i in range(n // 2, n): if s[i] == "?": right_cnt += 1 else: right_num += int(s[i]) if left_cnt == right_cnt: if left_num == right_num: print("Bicarp") else: print("Monocarp") exit() diff = left_cnt - right_cnt diff_num = left_num - right_num if -diff_num == 9 * (diff // 2): print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) n //= 2 s = input() c = 0 c1 = 0 su = 0 su1 = 0 for i in range(n): if s[i] == "?": c += 1 else: su += int(s[i]) for i in range(n): if s[i + n] == "?": c1 += 1 else: su1 += int(s[i + n]) c -= c1 su -= su1 if -su == c // 2 * 9: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
import sys input = sys.stdin.readline n = int(input()) s = str(input().strip()) L, R, LS, RS = 0, 0, 0, 0 for ch in s[: n // 2]: if ch == "?": L += 1 else: LS += int(ch) for ch in s[n // 2 :]: if ch == "?": R += 1 else: RS += int(ch) diff = LS - RS ans = (R - L) // 2 * 9 == diff print(["Monocarp", "Bicarp"][ans])
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR LIST STRING STRING VAR
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() first = s[: n // 2] second = s[n // 2 :] if first.count("?") > second.count("?"): first, second = second, first f = first.count("?") s = second.count("?") cnt1 = 0 cnt2 = 0 for i in range(n // 2): if first[i].isdigit(): cnt1 += int(first[i]) if second[i].isdigit(): cnt2 += int(second[i]) if (s - f) // 2 * 9 == cnt1 - cnt2: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) inp = input() f = inp[: n // 2] s = inp[n // 2 :] fsm = sum([(ord(x) - ord("0") if x != "?" else 0) for x in f]) ssm = sum([(ord(x) - ord("0") if x != "?" else 0) for x in s]) diff = fsm - ssm fcnt = f.count("?") scnt = s.count("?") blowupdiff, blowupf, blowups = diff, fcnt, scnt shrinkdiff, shrinkf, shrinks = diff, fcnt, scnt trn = True for _ in range(fcnt + scnt): if trn: if blowupf: blowupf -= 1 blowupdiff += 9 else: blowups -= 1 if shrinks: shrinks -= 1 shrinkdiff -= 9 else: shrinkf += 1 else: if blowups: blowups -= 1 blowupdiff -= 9 else: blowupf -= 1 if shrinkf: shrinkf -= 1 shrinkdiff += 9 else: shrinks -= 1 trn = not trn if blowupdiff == 0 or shrinkdiff == 0: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) ln = list(input()) sm1 = 0 sm2 = 0 qs1 = 0 qs2 = 0 for i in range(0, n // 2): if ln[i] != "?": qs1 += 1 sm1 += int(ln[i]) if ln[n // 2 + i] != "?": qs2 += 1 sm2 += int(ln[n // 2 + i]) qs1 = n // 2 - qs1 qs2 = n // 2 - qs2 qs = qs1 + qs2 m = False if not qs: if sm1 != sm2: m = True mx = sm1 + min(qs1, qs // 2) * 9 lft = min(qs2, qs2 - (qs // 2 - qs1)) if mx > lft * 9 + sm2: m = True mx = sm2 + min(qs2, qs // 2) * 9 lft = min(qs1, qs1 - (qs // 2 - qs2)) if mx > lft * 9 + sm1: m = True if m: print("Monocarp") else: print("Bicarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
import sys n = int(sys.stdin.readline().strip()) m = n // 2 s = sys.stdin.readline().strip() s1 = 0 s2 = 0 x1 = 0 x2 = 0 for i in range(0, m): if s[i] == "?": x1 = x1 + 1 else: s1 = s1 + int(str(s[i])) if s[m + i] == "?": x2 = x2 + 1 else: s2 = s2 + int(str(s[m + i])) if s1 + x1 // 2 * 9 == s2 + x2 // 2 * 9: print("Bicarp") else: print("Monocarp")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() p1 = 0 p2 = 0 s1 = 0 s2 = 0 for i in s[: n // 2]: if i == "?": p1 += 1 else: s1 += int(i) for i in s[n // 2 :]: if i == "?": p2 += 1 else: s2 += int(i) if s1 < s2: buf = p1 p1 = p2 p2 = buf buf = s1 s1 = s2 s2 = buf if p1 > p2: print("Monocarp") else: p = abs(p1 - p2) ss = abs(s1 - s2) if ss == p // 2 * 9: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) lis = list(input()) fi = se = 0 c1 = c2 = 0 for i in range(n): if i < n // 2: if lis[i] == "?": c1 += 1 else: fi += int(lis[i]) elif lis[i] == "?": c2 += 1 else: se += int(lis[i]) if fi == se and c1 == c2: print("Bicarp") elif fi == se and c1 != c2: print("Monocarp") elif fi > se: if c1 >= c2: print("Monocarp") elif (c2 - c1) // 2 * 9 == fi - se: print("Bicarp") else: print("Monocarp") elif se > fi: if c2 >= c1: print("Monocarp") elif (c1 - c2) // 2 * 9 == se - fi: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
a = int(input()) s = input() q1 = 0 sum1 = 0 q2 = 0 sum2 = 0 for i in range(len(s) // 2): if s[i] == "?": q1 += 1 else: sum1 += int(s[i]) for i in range(len(s) // 2, len(s)): if s[i] == "?": q2 += 1 else: sum2 += int(s[i]) if q1 == 0 and q2 == 0: if sum1 == sum2: print("Bicarp") else: print("Monocarp") else: temp1 = sum1 temp2 = sum2 if q1 == q2: if temp1 == temp2: print("Bicarp") else: print("Monocarp") exit() if q1 % 2 == 0: temp1 += q1 // 2 * 9 temp2 += q2 // 2 * 9 else: temp1 += q1 // 2 * 9 + 9 temp2 += q2 // 2 * 9 + 9 if temp1 != temp2: print("Monocarp") else: print("Bicarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) str = input() L = 0 R = 0 for i in range(n): if i < n // 2: if str[i] == "?": L += 9 else: L += 2 * (ord(str[i]) - ord("0")) elif str[i] == "?": R += 9 else: R += 2 * (ord(str[i]) - ord("0")) print("Bicarp" if L == R else "Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR VAR STRING VAR NUMBER VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
def main(): n = int(input()) a = list(input()) ls = 0 rs = 0 lq = 0 rq = 0 for i in range(n // 2): if a[i] == "?": lq += 1 else: ls += int(a[i]) for i in range(n // 2, n): if a[i] == "?": rq += 1 else: rs += int(a[i]) maxl = (lq + 1) // 2 * 9 minl = lq // 2 * 9 maxr = (rq + 1) // 2 * 9 minr = rq // 2 * 9 if maxl + ls == maxr + rs and minl + ls == minr + rs: print("Bicarp") else: print("Monocarp") return main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) st = input() wh1 = 0 su1 = 0 for i in range(n // 2): if st[i] == "?": wh1 += 1 else: su1 += int(st[i]) wh2 = 0 su2 = 0 for i in range(n // 2, n): if st[i] == "?": wh2 += 1 else: su2 += int(st[i]) if wh1 == 0 and wh2 == 0 and su1 == su2: print("Bicarp") elif abs(su1 - su2) % 9 != 0: print("Monocarp") elif su1 >= su2: wh2 -= (su1 - su2) // 9 * 2 if wh1 == wh2: print("Bicarp") else: print("Monocarp") else: wh1 -= (su2 - su1) // 9 * 2 if wh1 == wh2: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() diff = 0 q_left = 0 q_right = 0 for i in range(0, n): if i < int(n / 2): if s[i] == "?": q_left += 1 else: diff += int(s[i]) elif s[i] == "?": q_right += 1 else: diff -= int(s[i]) if diff < 0: diff = 0 - diff t = q_left q_left = q_right q_right = t min_q = min(q_left, q_right) q_left -= min_q q_right -= min_q if q_left != 0: print("Monocarp") elif diff == int(q_right / 2) * 9: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) ch = input() a1 = 0 a2 = 0 s1 = 0 s2 = 0 for i in range(int(n / 2)): if ch[i] == "?": a1 += 1 else: s1 += int(ch[i]) for i in range(int(n / 2), n): if ch[i] == "?": a2 += 1 else: s2 += int(ch[i]) if s1 > s2 and a1 >= a2 or s2 > s1 and a2 >= a1 or s1 == s2 and a1 != a2: print("Monocarp") elif s1 > s2: b = (a2 - a1) // 2 if s1 - s2 == b * 9: print("Bicarp") else: print("Monocarp") elif s2 > s1: b = (a1 - a2) // 2 if s2 - s1 == b * 9: print("Bicarp") else: print("Monocarp") else: print("Bicarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
def find(s): N = len(s) // 2 left = 0 right = 0 left_v = 0 right_v = 0 for i in range(N): if s[i] == "?": left_v += 1 continue left += int(s[i]) for i in range(N, 2 * N): if s[i] == "?": right_v += 1 continue right += int(s[i]) L = left - (right + right_v * 9) R = left + left_v * 9 - right return L + R == 0 input() s = input() if find(s): print("Bicarp") else: print("Monocarp")
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
for t in range(1): n = int(input()) s = input() count, add = 0, 0 a, b = 0, 0 for i in range(n // 2): if s[i] == "?": count += 1 else: a += int(s[i]) for i in range(n // 2, n): if s[i] == "?": add += 1 else: b += int(s[i]) diff, d, e, c = 0, 0, 0, 0 if count > add and a > b: print("Monocarp") elif add > count and b > a: print("Monocarp") elif count >= add and a <= b: c = count - add d = c // 2 + c % 2 e = c // 2 diff = b - a if diff >= 9 * e and diff <= 9 * d: print("Bicarp") else: print("Monocarp") elif add >= count and a >= b: c = add - count d = c // 2 + c % 2 e = c // 2 diff = a - b if diff >= 9 * e and diff <= 9 * d: print("Bicarp") else: print("Monocarp")
FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
A = "Monocarp" B = "Bicarp" n = int(input()) nums = input() leftsum = sum(int(i) for i in nums[: len(nums) // 2] if i != "?") rightsum = sum(int(i) for i in nums[len(nums) // 2 :] if i != "?") leftrem = len([i for i in nums[: len(nums) // 2] if i == "?"]) rightrem = len([i for i in nums[len(nums) // 2 :] if i == "?"]) if (leftrem + rightrem) % 2 == 1: print(A) else: diffrem = leftrem - rightrem if diffrem == 0: if leftsum == rightsum: print(B) else: print(A) else: diffsum = rightsum - leftsum if diffsum == 9 * diffrem // 2: print(B) else: print(A)
ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) l = list(input()) q1 = q2 = 0 for i in range(n): if l[i] == "?": l[i] = 0 if i < n / 2: q1 += 1 else: q2 += 1 else: l[i] = ord(l[i]) - ord("0") s1 = sum(l[: n // 2]) s2 = sum(l[n // 2 :]) if q1 == q2: if s1 == s2: print("Bicarp") else: print("Monocarp") elif q1 > q2: if (q1 - q2) // 2 * 9 + s1 == s2: print("Bicarp") else: print("Monocarp") elif (q2 - q1) // 2 * 9 + s2 == s1: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR IF BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
length = int(input()) string = list(input()) B = "Bicarp" M = "Monocarp" value = [0] * 2 blanks = [0] * 2 temp = "0" for i in range(length // 2): temp = string[i] if temp == "?": blanks[0] += 1 else: value[0] += int(temp) for i in range(length // 2, length): temp = string[i] if temp == "?": blanks[1] += 1 else: value[1] += int(temp) if value[1] > value[0]: value[0], value[1] = value[1], value[0] blanks[0], blanks[1] = blanks[1], blanks[0] if value[0] == value[1]: if blanks[0] == blanks[1]: ans = B else: ans = M elif blanks[0] >= blanks[1]: ans = M else: blankdif = blanks[1] - blanks[0] valuedif = value[0] - value[1] if valuedif == blankdif * 4.5: ans = B else: ans = M print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR STRING VAR NUMBER NUMBER VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR STRING VAR NUMBER NUMBER VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() left = 0 leftq = 0 for i in range(n // 2): if s[i] == "?": leftq += 1 else: left += int(s[i]) right = 0 rightq = 0 for i in range(n // 2, n): if s[i] == "?": rightq += 1 else: right += int(s[i]) if left > right and leftq > rightq or right > left and rightq > leftq: print("Monocarp") elif left > right and leftq < rightq or right > left and rightq < leftq: if leftq < rightq: left, right = right, left leftq, rightq = rightq, leftq leftq -= rightq if right - left == leftq // 2 * 9: print("Bicarp") else: print("Monocarp") elif (left > right or right > left) and rightq == leftq: print("Monocarp") elif left == right and leftq != rightq: print("Monocarp") else: print("Bicarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
def solve(cnt1, cnt2, balance): diff = 9 * (cnt1 - cnt2) // 2 return balance + diff != 0 n = int(input()) s = input() cnt1, cnt2, balance = 0, 0, 0 for i in range(n // 2): if s[i] == "?": cnt1 += 1 else: balance += ord(s[i]) - ord("0") for i in range(n // 2, n): if s[i] == "?": cnt2 += 1 else: balance -= ord(s[i]) - ord("0") print("Monocarp" if solve(cnt1, cnt2, balance) else "Bicarp")
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) word = input() tot = 0 for i in range(n): if word[i] == "?": inc = 9 else: inc = 2 * int(word[i]) tot += (2 * (i < n // 2) - 1) * inc print(["Monocarp", "Bicarp"][tot == 0])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR LIST STRING STRING VAR NUMBER
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) a = input() c1, s1, c2, s2 = 0, 0, 0, 0 for i in range(n // 2): if a[i] == "?": c1 = c1 + 1 else: s1 = s1 + int(a[i]) for i in range(n // 2, n): if a[i] == "?": c2 = c2 + 1 else: s2 = s2 + int(a[i]) c = abs(c1 - c2) s = abs(s1 - s2) if c == 0 and s != 0: print("Monocarp") elif c == 0 and s == 0: print("Bicarp") elif c1 > c2 and s1 > s2: print("Monocarp") elif c1 < c2 and s1 < s2: print("Monocarp") elif c != 0 and s == 0: print("Monocarp") elif c // 2 * 9 == s: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() left = 0 right = 0 left_ques = 0 right_ques = 0 for i in range(n): if i < n // 2: if s[i] == "?": left_ques += 1 else: left += int(s[i]) elif s[i] == "?": right_ques += 1 else: right += int(s[i]) x = min(left_ques, right_ques) left_ques -= x right_ques -= x if left_ques == 0 and right_ques == 0: if left == right: print("Bicarp") else: print("Monocarp") elif left_ques == 0: if right_ques % 2 == 0: x = 9 * (right_ques // 2) + right if x == left: print("Bicarp") else: print("Monocarp") else: print("Monocarp") elif left_ques % 2 == 0: x = 9 * (left_ques // 2) + left if x == right: print("Bicarp") else: print("Monocarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() s1 = 0 s2 = 0 c1 = 0 c2 = 0 for i in range(n // 2): if s[i] != "?": s1 += int(s[i]) else: c1 += 1 if s[-i - 1] != "?": s2 += int(s[-i - 1]) else: c2 += 1 if c1 > c2: c1 -= c2 if s1 + 9 * (c1 // 2) > s2 or s1 + 9 * (c1 // 2) < s2: print("Monocarp") else: print("Bicarp") else: c2 -= c1 if s2 + 9 * (c2 // 2) > s1 or s2 + 9 * (c2 // 2) < s1: print("Monocarp") else: print("Bicarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR IF BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR VAR IF BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() sd = 0 qd = 0 for i in range(n // 2): if s[i] == "?": qd += 1 else: sd += int(s[i]) if s[n // 2 + i] == "?": qd -= 1 else: sd -= int(s[n // 2 + i]) if abs(sd) % 9 > 0: print("Monocarp") exit() if sd >= 0: qd += 2 * (sd // 9 + (1 if sd % 9 > 0 else 0)) else: sd = -1 * sd qd -= 2 * (sd // 9 + (1 if sd % 9 > 0 else 0)) print("Bicarp" if qd == 0 else "Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
N = int(input()) L = 0 R = 0 lq = 0 rq = 0 TK = input() for i in range(N // 2): if TK[i] == "?": lq += 1 else: L += int(TK[i]) for i in range(N // 2, N): if TK[i] == "?": rq += 1 else: R += int(TK[i]) if lq == rq: if L == R: print("Bicarp") else: print("Monocarp") t = abs(lq - rq) if lq > rq: R -= L if R < 0: print("Monocarp") elif t // 2 * 9 == R: print("Bicarp") else: print("Monocarp") if lq < rq: L -= R if L < 0: print("Monocarp") elif t // 2 * 9 == L: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) word = input() print( ["Monocarp", "Bicarp"][ 0 == sum( [ ( 9 * (2 * (i < n // 2) - 1) if word[i] == "?" else (4 * (i < n // 2) - 2) * int(word[i]) ) for i in range(n) ] ) ] )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST STRING STRING NUMBER FUNC_CALL VAR VAR VAR STRING BIN_OP NUMBER BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
o = input() inp = input() count_1 = 0 sum_1 = 0 count_2 = 0 sum_2 = 0 for i in range(len(inp) // 2): if inp[i] == "?": count_1 += 1 else: sum_1 += int(inp[i]) for j in range(len(inp) // 2): i = len(inp) // 2 + j if inp[i] == "?": count_2 += 1 else: sum_2 += int(inp[i]) if sum_2 - sum_1 == 9 * (count_1 - count_2) // 2: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) inp = input() sl, sr, qr, ql = 0, 0, 0, 0 for i in range(len(inp) // 2): if inp[i] == "?": ql += 1 else: sl += int(inp[i]) for i in range(n // 2, n): if inp[i] == "?": qr += 1 else: sr += int(inp[i]) if sl - sr == 9 * (qr - ql) / 2: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
l = int(input()) line = input() left_side = line[: l // 2] right_side = line[l // 2 :] def left(): return line[: l // 2] def right(): return line[l // 2 :] def get_sum(side, replacement): return sum(int(x) if x != "?" else replacement for x in side) def get_min_sum(side): return get_sum(side, 0) def get_max_sum(side): return get_sum(side, 9) def str_sub(_str, pos, char): return _str[:pos] + char + _str[pos + 1 :] stable = get_max_sum(left()) - get_max_sum(right()) == get_min_sum( right() ) - get_min_sum(left()) if stable: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_DEF RETURN VAR BIN_OP VAR NUMBER FUNC_DEF RETURN VAR BIN_OP VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() nuq1 = 0 nuq2 = 0 sum1 = 0 sum2 = 0 for i in range(n): if s[i] == "?" and i < n // 2: nuq1 += 1 elif s[i] == "?" and i >= n // 2: nuq2 += 1 elif i < n // 2: sum1 += int(s[i]) else: sum2 += int(s[i]) if sum1 - sum2 == 9 * ((nuq2 - nuq1) // 2): print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() cur_diff = 0 for i in range(n // 2): if s[i] != "?": cur_diff += int(s[i]) else: cur_diff += 4.5 for i in range(n // 2, n): if s[i] != "?": cur_diff -= int(s[i]) else: cur_diff -= 4.5 if abs(cur_diff) < 0.5: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) a = input() if a.count("?") % 2 == 1: print("Monocarp") else: x = y = k = m = 0 for q in range(n): if q * 2 < n: if a[q] == "?": k += 1 else: x += int(a[q]) elif a[q] == "?": m += 1 else: y += int(a[q]) if (y - x) % 9 == 0 and (y - x) // 9 == (k - m) // 2: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) a = [(int(x) if x != "?" else -1) for x in input()] left, right = a[0 : n // 2], a[n // 2 :] sumL = sum(x if x >= 0 else 0 for x in left) sumR9 = sum(x if x >= 0 else 9 for x in right) sumL9 = sum(x if x >= 0 else 9 for x in left) sumR = sum(x if x >= 0 else 0 for x in right) bigL = sumR9 - sumL < sumL9 - sumR bw = sumR9 - sumL == sumL9 - sumR print("Bicarp" if bw else "Monocarp") def forr(rr, val, swap, swap2=False): global sumL, sumR for i in rr: if a[i] == -1: a[i] = val if swap ^ swap2: sumR += val else: sumL += val return True return False def it(swap, minVal=0, maxVal=9): l, r = range(0, n // 2), range(n // 2, n) if swap: l, r = r, l if forr(l, maxVal, swap): return True if forr(r, minVal, swap, True): return True return False def mc(swap): return it(not swap) def bc(swap): diff = sumR - sumL diff = 9 if diff > 9 else diff diff = -9 if diff < 9 else diff q, w = (0, -diff) if diff < 0 else (diff, 9) return it(swap, q, w)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR STRING FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR STRING STRING FUNC_DEF NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) x = input() def f(x): q, s = 0, 0 for c in x: if c == "?": q += 1 else: s += int(c) return q, s lq, ls = f(x[: n // 2]) rq, rs = f(x[n // 2 :]) lmin = ls lmax = ls + 9 * lq rmin = rs rmax = rs + 9 * rq lc = lmin + lmax rc = rmin + rmax if lc == rc and (lq + rq) % 2 == 0: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() pyt = 0 for i in s: if i == "?": pyt += 1 if pyt % 2 == 1: print("Monocarp") else: pyt1 = 0 pyt2 = 0 sum1 = 0 sum2 = 0 for i in range(n // 2): if s[i] == "?": pyt1 += 1 if s[i] != "?": sum1 += int(s[i]) for i in range(n // 2, n): if s[i] == "?": pyt2 += 1 if s[i] != "?": sum2 += int(s[i]) if sum1 == -4.5 * (pyt1 - pyt2) + sum2: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() sum1 = 0 kol1 = 0 sum2 = 0 kol2 = 0 for i in range(n // 2): if s[i] == "?": kol1 += 1 else: sum1 += int(s[i]) for i in range(n // 2, n): if s[i] == "?": kol2 += 1 else: sum2 += int(s[i]) if sum1 > sum2: sum1, sum2, kol1, kol2 = sum2, sum1, kol2, kol1 if sum1 == sum2 and kol1 == kol2: print("Bicarp") elif sum1 == sum2 and kol1 != kol2: print("Monocarp") elif (sum2 - sum1) % 9 != 0: print("Monocarp") elif kol1 == kol2 == 0: print("Monocarp") elif (sum2 - sum1) // 9 == (kol1 - kol2) // 2: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
import sys input = sys.stdin.readline def aliceWillWin(ticket): bal = 0 qs = 0 for i, c in enumerate(ticket): if i < len(ticket) // 2: if c == "?": qs += 1 else: bal += int(c) elif c == "?": qs -= 1 else: bal -= int(c) if bal == -qs // 2 * 9: return False return True def main(): n = int(input()) isAlice = aliceWillWin(input().strip()) if isAlice: print("Monocarp") else: print("Bicarp") main()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) l = list(input()) first, last = 0, 0 left, right = 0, 0 for i in range(n): if l[i] == "?": if i < n // 2: first += 9 else: last += 9 elif i < n // 2: left += 2 * int(l[i]) else: right += 2 * int(l[i]) if first + left - right - last == 0: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) a, b1, b2 = [], [], [] for i, j in enumerate(input()): if j == "?": if i < n // 2: b1.append(i) else: b2.append(i) a.append(0) else: a.append(int(j)) s1 = sum(a[: n // 2]) s2 = sum(a[n // 2 :]) print( "Bicarp" if s1 + 9 * (len(b1) + 1) // 2 == s2 + 9 * (len(b2) + 1) // 2 else "Monocarp" )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR LIST LIST LIST FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
I = lambda: int(input()) SI = lambda: input() M = "Monocarp" B = "Bicarp" def solve(n, s): lsum = 0 cl = 0 rsum = 0 cr = 0 for i in range(n // 2): if s[i] == "?": cl += 1 else: lsum += int(s[i]) for i in range(n // 2, n): if s[i] == "?": cr += 1 else: rsum += int(s[i]) dif = lsum - rsum if dif == 0: if cl == cr: print(B) else: print(M) return if cl == cr: print(M) return if dif > 0 and cl > cr or dif < 0 and cl < cr: print(M) return if dif > 0: dif = -dif cl, cr = cr, cl difc = cl - cr if dif + difc // 2 * 9 == 0: print(B) else: print(M) n = I() s = SI() solve(n, s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() kv1 = 0 kv2 = 0 sum1 = 0 sum2 = 0 for i in range(n): if s[i] == "?": if i < n / 2: kv1 += 1 else: kv2 += 1 elif i < n / 2: sum1 += int(s[i]) else: sum2 += int(s[i]) t = (kv1 + kv2) // 2 if sum1 > sum2: sum1 += 9 * min(kv1, t) kv2 -= t - min(kv1, t) sum2 += 9 * min(kv2, t) else: sum2 += 9 * min(kv2, t) kv1 -= t - min(kv2, t) sum1 += 9 * min(kv1, t) if sum1 == sum2: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) a = input() maxi = sum(map(int, list(a[n // 2 :].replace("?", "9")))) - sum( map(int, list(a[: n // 2].replace("?", "0"))) ) mini = sum(map(int, list(a[n // 2 :].replace("?", "0")))) - sum( map(int, list(a[: n // 2].replace("?", "9"))) ) if mini + maxi == 0: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
def winner(s, n): s1 = s[: n // 2] s2 = s[n // 2 :] turns = s.count("?") // 2 l1 = r1 = l2 = r2 = 0 for c in s1: if c == "?": r1 += 9 else: l1 += int(c) r1 += int(c) for c in s2: if c == "?": r2 += 9 else: l2 += int(c) r2 += int(c) if r1 < l2 or r2 < l1: return "True" minDif = min(r1 - l2, r2 - l1) return minDif < turns * 9 n = int(input()) s = input() print("Monocarp" if winner(s, n) else "Bicarp")
FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() s1 = s[: n // 2] s2 = s[n // 2 :] sum1 = sum(map(int, filter(str.isdigit, s1))) sum2 = sum(map(int, filter(str.isdigit, s2))) free1 = s1.count("?") free2 = s2.count("?") ans = "" if free1 == free2: if sum1 == sum2: ans = "Bicarp" else: ans = "Monocarp" else: if sum1 > sum2: free1, free2 = free2, free1 sum1, sum2 = sum2, sum1 if free1 <= free2: ans = "Monocarp" elif (free1 - free2) // 2 * 9 == sum2 - sum1: ans = "Bicarp" else: ans = "Monocarp" print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING IF VAR VAR IF VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR STRING IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) l = list(input()) a = 0 b = 0 c = 0 d = 0 for i in range(n // 2): if l[i] == "?": a += 1 else: c += int(l[i]) for i in range(n // 2, n): if l[i] == "?": b += 1 else: d += int(l[i]) x = a // 2 if a % 2: x += 1 y = b // 2 if b % 2: y += 1 if x * 9 + c > y * 9 + d or (a - x) * 9 + c < (b - y) * 9 + d: print("Monocarp") else: print("Bicarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
t = int(input()) s = input() l_sum = 0 r_sum = 0 l_count = 0 r_count = 0 for i in range(0, len(s) // 2): if s[i] != "?": l_sum += int(s[i]) else: l_count += 1 for i in range(len(s) // 2, len(s)): if s[i] != "?": r_sum += int(s[i]) else: r_count += 1 if l_sum > r_sum: l_sum, r_sum = r_sum, l_sum l_count, r_count = r_count, l_count if l_sum == r_sum and l_count == r_count: print("Bicarp") elif l_sum == r_sum and l_count != r_count: print("Monocarp") elif l_sum < r_sum and l_count < r_count: print("Monocarp") elif l_sum < r_sum and l_count == r_count: print("Monocarp") elif l_sum < r_sum and l_count > r_count: if l_sum + (l_count - r_count) * 9 // 2 == r_sum: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR IF BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() l = 0 r = 0 for i in range(n // 2): if s[i] == "?": l += 4.5 else: l += int(s[i]) for i in range(n // 2, n): if s[i] == "?": r += 4.5 else: r += int(s[i]) if l == r: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
n = int(input()) s = input() lsum = lcount = rsum = rcount = 0 for ch in s[: n // 2]: if ch == "?": lcount += 1 else: lsum += int(ch) for ch in s[n // 2 :]: if ch == "?": rcount += 1 else: rsum += int(ch) if lcount > rcount: delta = rsum - lsum count = lcount - rcount else: delta = lsum - rsum count = rcount - lcount if delta == count // 2 * 9: print("Bicarp") else: print("Monocarp")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Little X has n distinct integers: p1, p2, ..., pn. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied: * If number x belongs to set A, then number a - x must also belong to set A. * If number x belongs to set B, then number b - x must also belong to set B. Help Little X divide the numbers into two sets or determine that it's impossible. Input The first line contains three space-separated integers n, a, b (1 ≀ n ≀ 105; 1 ≀ a, b ≀ 109). The next line contains n space-separated distinct integers p1, p2, ..., pn (1 ≀ pi ≀ 109). Output If there is a way to divide the numbers into two sets, then print "YES" in the first line. Then print n integers: b1, b2, ..., bn (bi equals either 0, or 1), describing the division. If bi equals to 0, then pi belongs to set A, otherwise it belongs to set B. If it's impossible, print "NO" (without the quotes). Examples Input 4 5 9 2 3 4 5 Output YES 0 0 1 1 Input 3 3 4 1 2 4 Output NO Note It's OK if all the numbers are in the same set, and the other one is empty.
class DisjointSet: def __init__(self, n): self._fa = list(range(n)) def union(self, x, y): x = self.get_father(x) y = self.get_father(y) self._fa[x] = y return y def get_father(self, x): y = self._fa[x] if self._fa[y] == y: return y else: z = self._fa[y] = self.get_father(y) return z def __repr__(self): return repr([self.get_father(i) for i in range(len(self._fa))]) def solve(n, a, b, xs): h = {x: i for i, x in enumerate(xs)} if a == b: if all(a - x in h for x in xs): return [0] * n return False g1 = n g2 = n + 1 ds = DisjointSet(n + 2) for i, x in enumerate(xs): for t in (a, b): if t - x in h: ds.union(i, h[t - x]) for i, x in enumerate(xs): b1 = a - x in h b2 = b - x in h if b1 + b2 == 0: return False if b1 + b2 == 1: if b1: ds.union(i, g1) else: ds.union(i, g2) if ds.get_father(g1) == ds.get_father(g2): return False group = [None] * n for i, x in enumerate(xs): f = ds.get_father(i) if f < n: return False group[i] = f - n return group n, a, b = map(int, input().split()) xs = list(map(int, input().split())) group = solve(n, a, b, xs) if isinstance(group, list): print("YES") print(" ".join(map(str, group))) else: print("NO")
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR IF VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR RETURN BIN_OP LIST NUMBER VAR RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
t = int(input()) for p in range(t): n, k = map(int, input().split()) l = {} for i in range(n): a, b, c = map(int, input().split()) if c not in l: l[c] = [(a, b)] else: l[c].append((a, b)) co = 0 for i in l.values(): i.sort(key=lambda x: x[1]) pre = 0, 0 for j in i: if j[0] >= pre[1]: co = co + 1 pre = j print(co, "\n")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR STRING
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
try: for _ in range(int(input())): N, K = map(int, input().split()) cell = [] count = 0 l = [] for __ in range(N): inserted = list(map(int, input().split())) cell.append(inserted) cell.sort(key=lambda x: x[1]) time = {} for number in cell: if number[2] not in time: time[number[2]] = number[1] count += 1 elif number[0] >= time[number[2]]: time[number[2]] = number[1] count += 1 print(count) except: pass
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
try: t = int(input()) for _ in range(t): n, k = map(int, input().split()) table = {} for _ in range(n): start, end, pref = map(int, input().split()) if pref in table.keys(): table[pref].add((end, start)) else: table[pref] = set() table[pref].add((end, start)) cnt = 0 for key in table.keys(): length = len(table[key]) if length > 1: val = sorted(table[key]) last_dept = 0 for i in range(length): if val[i][1] >= last_dept: cnt += 1 last_dept = val[i][0] else: cnt += 1 print(cnt) except: pass
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
t = int(input()) for _ in range(t): n, k = [int(x) for x in input().split()] customers = {} for customer in range(n): temp = [int(x) for x in input().split()] if temp[2] in customers: customers[temp[2]].append(temp) else: customers[temp[2]] = [temp] happy_customers = 0 for comp, booth in customers.items(): booth.sort(key=lambda x: x[1], reverse=False) if len(booth) == 1: happy_customers += 1 continue current_end = booth[0][1] happy_customers += 1 for cust in booth: if cust[0] >= current_end: happy_customers += 1 current_end = cust[1] print(happy_customers)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
from sys import stdin for _ in range(int(stdin.readline())): n, k = map(int, stdin.readline().split()) m = {} f = {} c = 0 for i in range(n): s, e, c = map(int, stdin.readline().split()) v = [s, e, c] if c in m: m[c].append(v) else: m[c] = [v] c = 0 for i in m: t = m[i] t = sorted(t, key=lambda x: x[1]) for j in range(len(t)): if t[j][2] not in f: f[t[j][2]] = t[j][1] c += 1 elif t[j][0] >= f[t[j][2]]: c += 1 f[t[j][2]] = t[j][1] print(c)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
T = int(input()) for k in range(T): N, K = map(int, input().split()) t = {} for i in range(N): s, f, p = map(int, input().split()) try: t[p].append((f, s)) except: t[p] = [(f, s)] c = 0 for i in t: t[i].sort() start = -1 for j in t[i]: if j[1] >= start: c += 1 start = j[0] print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
for _ in range(int(input())): n, k = map(int, input().split()) aux = {} for i in range(n): s, f, p = map(int, input().split()) if p not in aux: aux[p] = [] aux[p].append([s, f]) else: aux[p].append([s, f]) tot = 0 for i in aux: if len(aux[i]) > 1: aux[i].sort(key=lambda x: x[1]) t_1 = 0 for j in range(len(aux[i])): if aux[i][j][0] >= t_1: t_1 = aux[i][j][1] tot += 1 else: tot += 1 print(tot)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
for _ in range(int(input())): ans = 0 n, k = map(int, input().split()) dic = {} for _ in range(n): s, f, p = map(int, input().split()) if p not in dic: dic[p] = [(s, f)] else: dic[p].append((s, f)) for key, val in dic.items(): if len(dic[key]) > 1: x = 0 for dekho in sorted(dic[key], key=lambda x: x[1]): if dekho[0] >= x: ans += 1 x = dekho[1] else: ans += 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
for _ in range(int(input())): n, k = map(int, input().split()) a = list() d = {} for i in range(n): s, f, p = list(map(int, input().split())) if p in d: d[p].append([s, f, p]) else: d[p] = [[s, f, p]] count = 0 for val in d.values(): freeat = 0 y = sorted(val, key=lambda x: x[1]) for i in y: if freeat <= i[0]: freeat = i[1] count += 1 print(count)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR LIST VAR VAR VAR ASSIGN VAR VAR LIST LIST VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
from sys import stdin input = stdin.readline for i in range(int(input())): n, k = map(int, input().split()) l = [] c = 0 for g in range(n): adc = list(map(int, input().split())) l.append(adc) l.sort(key=lambda x: x[1]) l.sort(key=lambda x: x[2]) i = 0 j = 0 while i < n: if i != 0: if l[i][2] != l[i - 1][2]: c += 1 j = i elif l[i][0] >= l[j][1]: c += 1 j = i else: c += 1 i += 1 print(c)
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
t = int(input()) while t > 0: n, k = map(int, input().split()) temp = {} for i in range(n): s, f, p = map(int, input().split()) if p in temp: temp[p].append([s, f]) else: temp[p] = [[s, f]] cnt = 0 for k in temp.keys(): temp[k].sort(key=lambda x: x[1]) prv = [0, 0] for i in range(len(temp[k])): if temp[k][i][0] >= prv[1]: prv = temp[k][i] cnt += 1 print(cnt) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR LIST VAR VAR ASSIGN VAR VAR LIST LIST VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
from sys import stdin, stdout tc = int(stdin.readline()) for i in range(tc): n, k = list(map(int, stdin.readline().split())) dict1 = {} comp_to_iterate = [] for j in range(n): s, f, comp = list(map(int, stdin.readline().split())) if comp in dict1.keys(): dict1[comp].append((s, f)) if comp not in comp_to_iterate: comp_to_iterate.append(comp) else: dict1[comp] = [(s, f)] total = len(dict1.keys()) - len(comp_to_iterate) for key in comp_to_iterate: value = dict1[key] value.sort(key=lambda x: x[1]) el = value[0] l = 1 total += 1 while l < len(value): if value[l][0] >= el[1]: total += 1 el = value[l] l += 1 print(total)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
t = int(input()) for _ in range(t): n, k = (int(i) for i in input().split()) cust = [[int(i) for i in input().split()] for _ in range(n)] cust.sort(key=lambda x: x[1]) compartments = {} ans = 0 for x in cust: s, f, c = x if c in compartments: if compartments[c] <= s: compartments[c] = f ans += 1 else: compartments[c] = f ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
from sys import stdin input = stdin.readline t = int(input()) for i in range(t): n, k = map(int, input().split()) arr = [] for i in range(n): s, f, p = map(int, input().split()) arr.append((s, f, p)) arr.sort(key=lambda x: x[1]) arr.sort(key=lambda x: x[2]) i = 0 j = 0 cnt = 0 while i < n: if i != 0: if arr[i][2] != arr[i - 1][2]: cnt = cnt + 1 j = i elif arr[i][0] >= arr[j][1]: cnt = cnt + 1 j = i else: cnt = cnt + 1 i = i + 1 print(cnt)
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
t = int(input()) for i in range(t): n, k = map(int, input().split()) m = {} for j in range(n): arr, dep, k = list(map(int, input().split())) if k in m: m[k].append([arr, dep]) else: m[k] = [[arr, dep]] c = 0 for temp in m.values(): temp.sort(key=lambda x: x[1]) ct = 1 curr = 0 ct1 = 1 for temp1 in temp[1:]: if temp1[0] >= temp[curr][1]: curr = ct1 ct += 1 ct1 += 1 c += ct print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR LIST VAR VAR ASSIGN VAR VAR LIST LIST VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
def customer(n, k, cust): total = len(cust) for k in cust: m = len(cust[k]) local = cust[k] prev = local[0] i, n = 1, m while i < n: if prev[1] <= local[i][0]: total += 1 prev = local[i] i += 1 return total for _ in range(int(input())): n, k = map(int, input().split()) cust = {} for _ in range(n): a, d, p = map(int, input().split()) if p in cust.keys(): cust[p].append([a, d]) else: cust[p] = [[a, d]] for num in cust: cust[num] = sorted(cust[num], key=lambda x: x[1]) out = customer(n, k, cust) print(out)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR LIST VAR VAR ASSIGN VAR VAR LIST LIST VAR VAR FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
def solve(compartments): total = 0 for compartment in compartments: people = compartments[compartment] people.sort(key=lambda x: x[1]) prevFin = 0 for person in people: start, finish = person if start >= prevFin: total += 1 prevFin = finish return total def main(): T = int(input()) for i in range(T): compartments = {} N, K = [int(num) for num in input().split()] for j in range(N): s, f, p = [int(num) for num in input().split()] if p not in compartments: compartments[p] = [] compartments[p].append((s, f)) print(solve(compartments)) main()
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
def main(n, k): customers = {} allowed = [] for i in range(n): s, f, p = tuple(map(int, input().split())) customers.setdefault(p, []).append((s, f)) for p in customers: interested = sorted(customers[p], key=lambda x: x[1]) allowed.append(interested[0]) for i in range(1, len(interested)): prev = allowed[-1] curr = interested[i] if curr[0] >= prev[1]: allowed.append(curr) return len(allowed) t = int(input()) for _ in range(t): n, k = map(int, input().split()) print(main(n, k))
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL FUNC_CALL VAR VAR LIST VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
def Max_cust(T): for i in range(T): count = 0 cus_prefer = {} n, k = map(int, input().split()) for j in range(n): s, f, p = map(int, input().split()) if p not in cus_prefer: cus_prefer[p] = [(s, f)] else: cus_prefer[p].append((s, f)) for v in cus_prefer.values(): v.sort(key=lambda x: x[1]) previous = 0, 0 for item in v: if item[0] >= previous[1]: previous = item count += 1 print(count) t = int(input()) Max_cust(t)
FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
T = int(input()) for z in range(T): N, K = map(int, input().split()) lst = [] for i in range(N): lst.append(tuple(map(int, input().split()))) lst.sort(key=lambda x: x[0]) res = 0 dct = {} for start, end, p in lst: if p in dct.keys(): if end <= dct[p][1]: dct[p] = [start, end] elif start >= dct[p][1]: dct[p] = [start, end] res += 1 else: dct[p] = [start, end] res += 1 print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR VAR VAR IF VAR FUNC_CALL VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR LIST VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR LIST VAR VAR VAR NUMBER ASSIGN VAR VAR LIST VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
t = int(input()) for _ in range(t): n, k = [int(x) for x in input().split()] hmap = dict() for _ in range(n): s, f, p = [int(x) for x in input().split()] hmap.setdefault(p, []).append((s, f)) ans = 0 for key, arr in hmap.items(): ans = ans + 1 arr.sort(key=lambda x: x[1]) curr = arr[0] for slot in arr: if slot[0] >= curr[1]: curr = slot ans = ans + 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL FUNC_CALL VAR VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
def find_max(schedule): schedule.sort(key=lambda k: k[1]) result = 0 free_at = -1 for s, f in schedule: if s >= free_at: free_at = f result += 1 return result def solve(customers, K): schedules = {} result = 0 for s, f, p in customers: if p not in schedules: schedules[p] = [] schedules[p].append([s, f]) for schedule in schedules.values(): result += find_max(schedule) return result def main(): for _ in range(int(input())): N, K = map(int, input().split()) customers = [[int(val) for val in input().split()] for _ in range(N)] print(solve(customers, K)) main()
FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR LIST VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
for _ in range(int(input())): n, k = map(int, input().split()) data = [] tab = dict() for _ in range(n): s, f, p = map(int, input().split()) data.append((s, f, p)) data.sort(key=lambda x: x[0]) coustomer = 0 for s, f, p in data: if p in tab: if f <= tab[p][1]: tab[p] = s, f elif s >= tab[p][1]: tab[p] = s, f coustomer += 1 else: tab[p] = s, f coustomer += 1 print(coustomer)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Our chef has recently opened a new restaurant with a unique style. The restaurant is divided into K compartments (numbered from 1 to K) and each compartment can be occupied by at most one customer. Each customer that visits the restaurant has a strongly preferred compartment p (1 ≀ p ≀ K), and if that compartment is already occupied, then the customer simply leaves. Now obviously, the chef wants to maximize the total number of customers that dine at his restaurant and so he allows (or disallows) certain customers so as to achieve this task. You are to help him with this. Given a list of N customers with their arrival time, departure time and the preferred compartment, you need to calculate the maximum number of customers that can dine at the restaurant. -----Input----- The first line contains an integer T denoting the number of test cases. Each of the next T lines contains two integers N and K , the number of customers that plan to visit the chef's restaurant and the number of compartments the restaurant is divided into respectively. Each of the next N lines contains three integers si, fi and pi , the arrival time, departure time and the strongly preferred compartment of the ith customer respectively. Note that the ith customer wants to occupy the pith compartment from [si, fi) i.e the ith customer leaves just before fi so that another customer can occupy that compartment from fi onwards. -----Output----- For every test case, print in a single line the maximum number of customers that dine at the restaurant. -----Constraints----- - 1 ≀ T ≀ 30 - 0 ≀ N ≀ 105 - 1 ≀ K ≀ 109 - 0 ≀ si < fi ≀ 109 - 1 ≀ pi ≀ K -----Example----- Input: 2 3 3 1 3 1 4 6 2 7 10 3 4 2 10 100 1 100 200 2 150 500 2 200 300 2 Output: 3 3 -----Explanation----- Example case 1. All three customers want different compartments and hence all 3 can be accommodated. Example case 2. If we serve the 1st, 2nd and 4th customers, then we can get a maximum of 3.
from sys import stdin def cal(a): a.sort(key=lambda x: x[1]) len1 = len(a) c = 1 curr = a[0][1] for p in range(0, len1 - 1): if curr <= a[p + 1][0]: c += 1 curr = a[p + 1][1] return c t = int(input()) for i in range(t): n, k = list(map(int, stdin.readline().split())) list1 = [] a = [] count = 0 for j in range(n): s, f, p = list(map(int, stdin.readline().split())) list1.append((s, f, p)) list1.sort(key=lambda x: x[2]) for j in range(0, n - 1): if list1[j][2] == list1[j + 1][2] and j != n - 2: a.append((list1[j][0], list1[j][1])) elif list1[j][2] == list1[j + 1][2] and j == n - 2: a.append((list1[j][0], list1[j][1])) a.append((list1[j + 1][0], list1[j + 1][1])) count += cal(a) a = [] elif list1[j][2] != list1[j + 1][2] and j == n - 2: a.append((list1[j][0], list1[j][1])) count += cal(a) a = [] a.append((list1[j + 1][0], list1[j + 1][1])) count += cal(a) a = [] else: a.append((list1[j][0], list1[j][1])) count += cal(a) a = [] if n == 1: print(count + 1) else: print(count)
FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Your friend Jeff Zebos has been trying to run his new online company, but it's not going very well. He's not getting a lot of sales on his website which he decided to call Azamon. His big problem, you think, is that he's not ranking high enough on the search engines. If only he could rename his products to have better names than his competitors, then he'll be at the top of the search results and will be a millionaire. After doing some research, you find out that search engines only sort their results lexicographically. If your friend could rename his products to lexicographically smaller strings than his competitor's, then he'll be at the top of the rankings! To make your strategy less obvious to his competitors, you decide to swap no more than two letters of the product names. Please help Jeff to find improved names for his products that are lexicographically smaller than his competitor's! Given the string $s$ representing Jeff's product name and the string $c$ representing his competitor's product name, find a way to swap at most one pair of characters in $s$ (that is, find two distinct indices $i$ and $j$ and swap $s_i$ and $s_j$) such that the resulting new name becomes strictly lexicographically smaller than $c$, or determine that it is impossible. Note: String $a$ is strictly lexicographically smaller than string $b$ if and only if one of the following holds: $a$ is a proper prefix of $b$, that is, $a$ is a prefix of $b$ such that $a \neq b$; There exists an integer $1 \le i \le \min{(|a|, |b|)}$ such that $a_i < b_i$ and $a_j = b_j$ for $1 \le j < i$. -----Input----- The first line of input contains a single integer $t$ ($1 \le t \le 1500$) denoting the number of test cases. The next lines contain descriptions of the test cases. Each test case consists of a single line containing two space-separated strings $s$ and $c$ ($2 \le |s| \le 5000, 1 \le |c| \le 5000$). The strings $s$ and $c$ consists of uppercase English letters. It is guaranteed that the sum of $|s|$ in the input is at most $5000$ and the sum of the $|c|$ in the input is at most $5000$. -----Output----- For each test case, output a single line containing a single string, which is either the new name which is obtained after swapping no more than one pair of characters that is strictly lexicographically smaller than $c$. In case there are many possible such strings, you can output any of them; three dashes (the string "---" without quotes) if it is impossible. -----Example----- Input 3 AZAMON APPLE AZAMON AAAAAAAAAAALIBABA APPLE BANANA Output AMAZON --- APPLE -----Note----- In the first test case, it is possible to swap the second and the fourth letters of the string and the resulting string "AMAZON" is lexicographically smaller than "APPLE". It is impossible to improve the product's name in the second test case and satisfy all conditions. In the third test case, it is possible not to swap a pair of characters. The name "APPLE" is lexicographically smaller than "BANANA". Note that there are other valid answers, e.g., "APPEL".
T = int(input()) for t in range(T): s1, s2 = [list(x) for x in input().split()] ind = 0 l = len(s1) while ind < l and s1[ind] == min(s1[ind:l]): ind += 1 if ind < l: x = s1[ind:l] x.reverse() c = min(x) ii = x.index(c) cc = s1[ind] s1[ind] = c s1[ind + len(x) - 1 - ii] = cc if s1 < s2: print("".join(s1)) else: print("---")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
Your friend Jeff Zebos has been trying to run his new online company, but it's not going very well. He's not getting a lot of sales on his website which he decided to call Azamon. His big problem, you think, is that he's not ranking high enough on the search engines. If only he could rename his products to have better names than his competitors, then he'll be at the top of the search results and will be a millionaire. After doing some research, you find out that search engines only sort their results lexicographically. If your friend could rename his products to lexicographically smaller strings than his competitor's, then he'll be at the top of the rankings! To make your strategy less obvious to his competitors, you decide to swap no more than two letters of the product names. Please help Jeff to find improved names for his products that are lexicographically smaller than his competitor's! Given the string $s$ representing Jeff's product name and the string $c$ representing his competitor's product name, find a way to swap at most one pair of characters in $s$ (that is, find two distinct indices $i$ and $j$ and swap $s_i$ and $s_j$) such that the resulting new name becomes strictly lexicographically smaller than $c$, or determine that it is impossible. Note: String $a$ is strictly lexicographically smaller than string $b$ if and only if one of the following holds: $a$ is a proper prefix of $b$, that is, $a$ is a prefix of $b$ such that $a \neq b$; There exists an integer $1 \le i \le \min{(|a|, |b|)}$ such that $a_i < b_i$ and $a_j = b_j$ for $1 \le j < i$. -----Input----- The first line of input contains a single integer $t$ ($1 \le t \le 1500$) denoting the number of test cases. The next lines contain descriptions of the test cases. Each test case consists of a single line containing two space-separated strings $s$ and $c$ ($2 \le |s| \le 5000, 1 \le |c| \le 5000$). The strings $s$ and $c$ consists of uppercase English letters. It is guaranteed that the sum of $|s|$ in the input is at most $5000$ and the sum of the $|c|$ in the input is at most $5000$. -----Output----- For each test case, output a single line containing a single string, which is either the new name which is obtained after swapping no more than one pair of characters that is strictly lexicographically smaller than $c$. In case there are many possible such strings, you can output any of them; three dashes (the string "---" without quotes) if it is impossible. -----Example----- Input 3 AZAMON APPLE AZAMON AAAAAAAAAAALIBABA APPLE BANANA Output AMAZON --- APPLE -----Note----- In the first test case, it is possible to swap the second and the fourth letters of the string and the resulting string "AMAZON" is lexicographically smaller than "APPLE". It is impossible to improve the product's name in the second test case and satisfy all conditions. In the third test case, it is possible not to swap a pair of characters. The name "APPLE" is lexicographically smaller than "BANANA". Note that there are other valid answers, e.g., "APPEL".
def check(s1, s2): s = list(s1) s.sort() rtn = "" if s1 < s2: return s1 if "".join(s) > s2: return "---" for i in range(len(s)): if s1[i] != s[i]: rtn += s1[:i] rtn += s[i] for j in range(len(s) - 1, i, -1): if s1[j] == s[i]: rtn += s1[i + 1 : j] rtn += s1[i] rtn += s1[j + 1 :] return rtn if rtn < s2 else "---" return "---" for rep in range(int(input())): print(check(*input().split()))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING IF VAR VAR RETURN VAR IF FUNC_CALL STRING VAR VAR RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR STRING RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR
Your friend Jeff Zebos has been trying to run his new online company, but it's not going very well. He's not getting a lot of sales on his website which he decided to call Azamon. His big problem, you think, is that he's not ranking high enough on the search engines. If only he could rename his products to have better names than his competitors, then he'll be at the top of the search results and will be a millionaire. After doing some research, you find out that search engines only sort their results lexicographically. If your friend could rename his products to lexicographically smaller strings than his competitor's, then he'll be at the top of the rankings! To make your strategy less obvious to his competitors, you decide to swap no more than two letters of the product names. Please help Jeff to find improved names for his products that are lexicographically smaller than his competitor's! Given the string $s$ representing Jeff's product name and the string $c$ representing his competitor's product name, find a way to swap at most one pair of characters in $s$ (that is, find two distinct indices $i$ and $j$ and swap $s_i$ and $s_j$) such that the resulting new name becomes strictly lexicographically smaller than $c$, or determine that it is impossible. Note: String $a$ is strictly lexicographically smaller than string $b$ if and only if one of the following holds: $a$ is a proper prefix of $b$, that is, $a$ is a prefix of $b$ such that $a \neq b$; There exists an integer $1 \le i \le \min{(|a|, |b|)}$ such that $a_i < b_i$ and $a_j = b_j$ for $1 \le j < i$. -----Input----- The first line of input contains a single integer $t$ ($1 \le t \le 1500$) denoting the number of test cases. The next lines contain descriptions of the test cases. Each test case consists of a single line containing two space-separated strings $s$ and $c$ ($2 \le |s| \le 5000, 1 \le |c| \le 5000$). The strings $s$ and $c$ consists of uppercase English letters. It is guaranteed that the sum of $|s|$ in the input is at most $5000$ and the sum of the $|c|$ in the input is at most $5000$. -----Output----- For each test case, output a single line containing a single string, which is either the new name which is obtained after swapping no more than one pair of characters that is strictly lexicographically smaller than $c$. In case there are many possible such strings, you can output any of them; three dashes (the string "---" without quotes) if it is impossible. -----Example----- Input 3 AZAMON APPLE AZAMON AAAAAAAAAAALIBABA APPLE BANANA Output AMAZON --- APPLE -----Note----- In the first test case, it is possible to swap the second and the fourth letters of the string and the resulting string "AMAZON" is lexicographically smaller than "APPLE". It is impossible to improve the product's name in the second test case and satisfy all conditions. In the third test case, it is possible not to swap a pair of characters. The name "APPLE" is lexicographically smaller than "BANANA". Note that there are other valid answers, e.g., "APPEL".
t = int(input()) for i in range(t): s, c = input().split() s = list(s) curr = "".join(s) swapped = False for j in range(len(s)): for k in range(j + 1, len(s)): if s[k] < s[j]: s[j], s[k] = s[k], s[j] new = "".join(s) if new < curr: curr = new swapped = True s[j], s[k] = s[k], s[j] if swapped: break if curr < c: print(curr) else: print("---")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Your friend Jeff Zebos has been trying to run his new online company, but it's not going very well. He's not getting a lot of sales on his website which he decided to call Azamon. His big problem, you think, is that he's not ranking high enough on the search engines. If only he could rename his products to have better names than his competitors, then he'll be at the top of the search results and will be a millionaire. After doing some research, you find out that search engines only sort their results lexicographically. If your friend could rename his products to lexicographically smaller strings than his competitor's, then he'll be at the top of the rankings! To make your strategy less obvious to his competitors, you decide to swap no more than two letters of the product names. Please help Jeff to find improved names for his products that are lexicographically smaller than his competitor's! Given the string $s$ representing Jeff's product name and the string $c$ representing his competitor's product name, find a way to swap at most one pair of characters in $s$ (that is, find two distinct indices $i$ and $j$ and swap $s_i$ and $s_j$) such that the resulting new name becomes strictly lexicographically smaller than $c$, or determine that it is impossible. Note: String $a$ is strictly lexicographically smaller than string $b$ if and only if one of the following holds: $a$ is a proper prefix of $b$, that is, $a$ is a prefix of $b$ such that $a \neq b$; There exists an integer $1 \le i \le \min{(|a|, |b|)}$ such that $a_i < b_i$ and $a_j = b_j$ for $1 \le j < i$. -----Input----- The first line of input contains a single integer $t$ ($1 \le t \le 1500$) denoting the number of test cases. The next lines contain descriptions of the test cases. Each test case consists of a single line containing two space-separated strings $s$ and $c$ ($2 \le |s| \le 5000, 1 \le |c| \le 5000$). The strings $s$ and $c$ consists of uppercase English letters. It is guaranteed that the sum of $|s|$ in the input is at most $5000$ and the sum of the $|c|$ in the input is at most $5000$. -----Output----- For each test case, output a single line containing a single string, which is either the new name which is obtained after swapping no more than one pair of characters that is strictly lexicographically smaller than $c$. In case there are many possible such strings, you can output any of them; three dashes (the string "---" without quotes) if it is impossible. -----Example----- Input 3 AZAMON APPLE AZAMON AAAAAAAAAAALIBABA APPLE BANANA Output AMAZON --- APPLE -----Note----- In the first test case, it is possible to swap the second and the fourth letters of the string and the resulting string "AMAZON" is lexicographically smaller than "APPLE". It is impossible to improve the product's name in the second test case and satisfy all conditions. In the third test case, it is possible not to swap a pair of characters. The name "APPLE" is lexicographically smaller than "BANANA". Note that there are other valid answers, e.g., "APPEL".
for _ in range(int(input())): s, c = input().split() if s < c: print(s) else: l = len(s) s = [i for i in s] for i in range(l - 1): p = min(s[i + 1 :]) if p < s[i]: u = s[::-1].index(p) u = l - 1 - u v = s[i] s[i] = s[u] s[u] = v break s = "".join(s) if s < c: print(s) else: print("---")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING