description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) ar = list(map(int, input().split())) goodi = set() has_more = -1 for i, x in enumerate(ar): if ar.count(x) == 1: goodi.add(i) elif ar.count(x) > 2: has_more = i mask = [(True) for i in range(n)] if len(goodi) % 2 == 0: print("YES") for i in list(goodi)[: len(goodi) // 2]: mask[i] = False for c in mask: print({(True): "A", (False): "B"}[c], end="") print() elif has_more != -1: print("YES") for i in list(goodi)[: len(goodi) // 2]: mask[i] = False mask[has_more] = False for c in mask: print({(True): "A", (False): "B"}[c], end="") print() else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR DICT NUMBER NUMBER STRING STRING VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR DICT NUMBER NUMBER STRING STRING VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
import itertools n = int(input()) s = list(map(int, input().split())) if s == [s[0]] * n: print("YES") print("A" * n) exit() three = 0 check = 0 for k, v in itertools.groupby(sorted(s)): vv = len(list(v)) if vv == 1: check += 1 elif vv >= 3: three += 1 if check % 2 == 1 and three == 0: print("NO") exit() res = "" flag = {} index = 1 for k, v in itertools.groupby(sorted(s)): if len(list(v)) == 1: if index * 2 <= check: flag[k] = -1 else: flag[k] = 1 index += 1 for k, v in itertools.groupby(sorted(s)): if len(list(v)) >= 3: if check % 2 == 1: flag[k] = -1 check += 1 else: flag[k] = 2 for num in s: for k, v in itertools.groupby(sorted(s)): if k == num and len(list(v)) not in (0, 2): if flag[k] == -1: flag[k] = -2 res += "A" elif flag[k] == 1: flag[k] = 2 res += "B" elif flag[k] == -2: res += "B" else: res += "A" break else: res += "A" print("YES") print(res)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP LIST VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR STRING IF VAR VAR NUMBER VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) data = input().split() z = {} ans = ["A"] * n for x in data: z[x] = z.get(x, 0) + 1 a = 0 b = 0 for i, j in enumerate(data): if z[j] == 1: if a > b: ans[i] = "B" b += 1 else: a += 1 if a > b: for i, j in enumerate(data): if z[j] > 2: ans[i] = "B" b += 1 break if a == b: print("YES") for i in ans: print(i, end="") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
a = int(input()) l = list(map(int, input().split())) g = 0 b = 0 m = [(0) for i in range(max(l) + 1)] for i in l: m[i] += 1 for i in m: if i == 1: g += 1 elif i > 2: b += 1 if g % 2 != 0 and b == 0: print("NO") else: print("YES") if g % 2 == 0: c = g / 2 for i in range(len(l)): if m[l[i]] == 1 and c > 0: c -= 1 print("A", end="") else: print("B", end="") else: c = g // 2 f = True for i in range(len(l)): if m[l[i]] == 1 and c > 0: c -= 1 print("A", end="") elif m[l[i]] >= 3 and f: f = not f print("A", end="") else: print("B", end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR VAR VAR NUMBER VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
def OutputforEven(timesDic, indexDic, goodKey, numOfsingles): list1 = [] list2 = [] singles = 0 for key, times in timesDic.items(): if times == 1: if singles < numOfsingles / 2: list1.extend(indexDic[key]) singles += 1 else: list2.extend(indexDic[key]) else: list1.extend(indexDic[key]) a = "A" b = "B" dict1 = {} dict2 = {} for elem in list1: dict1[elem] = a for elem in list2: dict2[elem] = b dict1.update(dict2) list1.extend(list2) listall = [] for index in sorted(list1): listall.append(dict1[index]) print("".join(listall)) return def OutputforOdd(timesDic, indexDic, goodKey, numOfsingles): list1 = [] list2 = [] singles = 0 for key, times in timesDic.items(): if times == 1: if singles < numOfsingles // 2 + 1: list1.extend(indexDic[key]) singles += 1 else: list2.extend(indexDic[key]) elif key == goodKey: list1.extend(indexDic[goodKey]) last = list1.pop() list2.append(last) else: list1.extend(indexDic[key]) a = "A" b = "B" dict1 = {} dict2 = {} for elem in list1: dict1[elem] = a for elem in list2: dict2[elem] = b dict1.update(dict2) list1.extend(list2) listall = [] for index in sorted(list1): listall.append(dict1[index]) print("".join(listall)) return n = int(input()) arr = input().split() timesDic = {} indexDic = {} for i in range(len(arr)): if arr[i] in timesDic: timesDic[arr[i]] += 1 indexDic[arr[i]].append(i) else: timesDic[arr[i]] = 1 indexDic[arr[i]] = [i] numOfsingles = 0 goodKey = 0.5 for key, times in timesDic.items(): if times == 1: numOfsingles += 1 if times > 2 and goodKey == 0.5: goodKey = key if numOfsingles & 1: if goodKey == 0.5: print("NO") else: print("YES") OutputforOdd(timesDic, indexDic, goodKey, numOfsingles) else: print("YES") OutputforEven(timesDic, indexDic, goodKey, numOfsingles)
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) d = dict() a = [int(x) for x in input().split()] for i in range(n): d.setdefault(a[i], []).append(i) di = dict() for d, s in d.items(): di.setdefault(len(s), []).append(s) exist = True ans = ["A"] * n if 1 in di: exist = False if len(di[1]) % 2 == 0: exist = True for i in range(0, len(di[1]), 2): ans[di[1][i][0]] = "B" else: for i in range(0, len(di[1]) - 2, 2): ans[di[1][i][0]] = "B" for i in range(3, n + 1): if i in di: ans[di[i][0][0]] = "B" exist = True break print("YES" if exist else "NO") if exist: print("".join(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL FUNC_CALL VAR VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR IF NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) dict1 = {} arr = list(map(int, input().split())) for i in range(n): try: dict1[arr[i]] += 1 except: KeyError dict1[arr[i]] = 1 if 1 not in dict1.values(): print("YES") print("A" * n) else: count1 = 0 count2 = 0 arr1 = [] arr2 = [] arr3 = [] for i in dict1: if dict1[i] == 1: count1 += 1 arr1.append(i) elif dict1[i] > 2: count2 += 1 arr3.append(i) else: arr2.append(i) s = "" arrx1 = arr1[: count1 // 2] arrx2 = arr1[count1 // 2 :] for i in range(n): if arr[i] in arrx1: s += "A" else: s += "B" if count1 % 2 == 0: print("YES") print(s) elif count2 == 0: print("NO") else: for i in range(n): if arr[i] == arr3[0]: s = s[:i] + "A" + s[i + 1 :] break print("YES") print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR VAR ASSIGN VAR VAR VAR NUMBER IF NUMBER FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
def printf(strs): print(strs, end="") def get_data(ls): power = 0 data = {} more_than_two = False for i in ls: if i not in data: data[i] = 1 power += 1 else: if data[i] < 2: power -= 1 data[i] += 1 if data[i] > 2: more_than_two = True return {"power": power, "data": data, "more_than_two": more_than_two} n = int(input()) lst = list(map(int, input().split())) prev_group = "A" prev_inc = "A" power = get_data(lst)["power"] data = get_data(lst)["data"] if power % 2 == 1 and not get_data(lst)["more_than_two"]: print("NO") else: print("YES") for i in range(n): if data[lst[i]] == 1: if prev_inc == "A": prev_inc = "B" else: prev_inc = "A" printf(prev_inc) elif data[lst[i]] > 2 and power % 2 == 1: prev_group = prev_inc if prev_inc == "A": prev_inc = "B" else: prev_inc = "A" printf(prev_inc) power += 1 continue else: printf(prev_group)
FUNC_DEF EXPR FUNC_CALL VAR VAR STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER RETURN DICT STRING STRING STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
import sys def rint(): return map(int, sys.stdin.readline().split()) n = int(input()) s = list(rint()) set_type = [] type_num = 0 found_candi = 0 candi_index = -1 for i in range(n): if s.count(s[i]) == 1: type_num += 1 set_type.append(1) elif found_candi == 0 and s.count(s[i]) >= 3: found_candi = 1 candi_index = i set_type.append(2) else: set_type.append(0) ans = [] type_cnt = 0 if type_num % 2 and found_candi == 0: print("NO") else: print("YES") if type_num % 2: type_num += 1 else: found_candi = 0 for i in range(n): if found_candi: if i == candi_index: type_cnt += 1 if type_cnt <= type_num // 2: ans.append("A") else: ans.append("B") continue elif s[i] == s[candi_index]: if ans[candi_index] == "A": ans.append("B") else: ans.append("A") continue if set_type[i] == 0 or found_candi == 0 and set_type[i] == 2: ans.append("A") elif set_type[i] == 1: type_cnt += 1 if type_cnt <= type_num // 2: ans.append("A") else: ans.append("B") print("".join(ans))
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR IF VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) v = list(map(int, input().split())) f = [(0) for x in range(1, 105)] for x in v: f[x] = f[x] + 1 d = {} next = 0 for i in range(1, 101): if f[i] == 1: if next == 0: d[i] = 0 else: d[i] = 1 next = next ^ 1 elif f[i] == 2: d[i] = 1 if next == 1: for i in range(1, 101): if f[i] >= 3: d[i] = 2 next = next ^ 1 break if next != 0: print("NO") exit(0) for i in range(1, 101): if i not in d: d[i] = 0 print("YES") sol = [] for x in v: if d[x] == 0: sol.append("A") elif d[x] == 1: sol.append("B") else: sol.append("B") d[x] = 0 print("".join(sol))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = [0] * 200 l = list(map(int, input().split())) for i in l: s[i] += 1 cnt, cnt1, cnt2 = 0, 0, 0 for i in range(len(s)): if s[i] == 1: cnt1 += 1 elif s[i] > 2: cnt += 1 if cnt1 % 2: if cnt == 0: print("NO") else: print("YES") f = 1 f1 = 1 for i in l: if f and s[i] == 1: print("A", end="") f = 0 elif not f and s[i] == 1: print("B", end="") f = 1 elif f1 and s[i] > 2: print("B", end="") f1 = 0 else: print("A", end="") else: print("YES") f = 1 for i in l: if f and s[i] == 1: print("A", end="") f = 0 elif not f and s[i] == 1: print("B", end="") f = 1 else: print("A", end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = list(map(int, input().split())) res = ["A"] * n type1, type3 = [], [] w = list(set(s)) for v in w: indices = [i for i, x in enumerate(s) if x == v] if len(indices) == 1: type1.append(indices[0]) elif len(indices) > 2: for i in range(len(indices)): type3.append((v, indices[i])) count_a, count_b = 0, 0 for i in range(len(type1)): if count_a > count_b: res[type1[i]] = "B" count_b += 1 else: count_a += 1 if count_a > count_b and len(type3) != 0: res[type3[0][1]] = "B" count_b += 1 if count_a == count_b: print("YES") print("".join(res)) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER STRING VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
def main(): n = int(input()) s = list(map(int, input().split())) cnt, flg = [0] * 101, [0] * 101 for i in s: cnt[i] += 1 nice, nice2 = [], [] for i in range(101): if cnt[i] == 1: nice.append(i) elif 3 <= cnt[i]: nice2.append(i) if len(nice) % 2 and not nice2: print("NO") exit() ans = ["A"] * n for i in range(len(nice) // 2): flg[nice[i]] = 1 if len(nice) % 2: for i in range(n): if s[i] == nice2[0]: ans[i] = "B" break for i in range(n): if flg[s[i]]: ans[i] = "B" print("YES") print("".join(ans)) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = list(map(int, input().split())) b = dict() for x in a: b[x] = b.get(x, 0) + 1 A = dict() B = dict() cnta = 0 cntb = 0 for k, v in b.items(): if v == 1: if cnta > cntb: cntb += 1 B[k] = 1 else: cnta += 1 A[k] = 1 for k, v in b.items(): if v == 2: A[k] = 2 elif v > 1: if cnta > cntb: A[k] = v - 1 B[k] = 1 cntb += 1 else: A[k] = v if cnta == cntb: print("YES") for i in a: if A.get(i, 0) > 0: A[i] = A.get(i, 0) - 1 print("A", end="") else: B[i] = B.get(i, 0) - 1 print("B", end="") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = list(map(int, input().split())) b = [0] * 101 for i in a: b[i] += 1 k = 0 l = 0 for i in b: if i == 1: k += 1 if i > 2: l += 1 t = False s = "" if k % 2 == 0 or k % 2 == 1 and l > 0: t = True if t: print("YES") if k % 2 == 0: k1 = 0 for i in a: if b[i] == 1 and k1 < k // 2: s += "A" k1 += 1 else: s += "B" print(s) else: k1 = 0 flag = False for i in a: if b[i] == 1 and k1 < k // 2: s += "A" k1 += 1 elif b[i] > 2 and flag == False: s += "A" flag = True else: s += "B" print(s) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR STRING VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR STRING VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR STRING ASSIGN VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
num = int(input()) multiset = [int(x) for x in input().split(" ")] non_multiset = set(multiset) help_dict = dict() good = True add = False add_num = 0 count = 0 for x in non_multiset: if multiset.count(x) == 1: if good: help_dict[x] = "A" else: help_dict[x] = "B" good = not good count += 1 if multiset.count(x) >= 3: add = True add_num = x if count % 2 == 1: if add: first = True print("YES") res = "" for x in multiset: if multiset.count(x) == 1: res += help_dict[x] elif x == add_num and first: res += "B" first = False else: res += "A" print(res) else: print("NO") else: print("YES") res = "" for x in multiset: if multiset.count(x) == 1: res += help_dict[x] else: res += "A" print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = list(map(int, input().split())) for x in range(0, len(s), +1): s[x] = [s[x], x] s_ile = [] for x in range(0, n, +1): s_ile.append([0, 0]) s = sorted(s) tmp_ile = 1 ile_p = 0 s_wyn = [0] * n i1 = 0 iw = 0 ia = 0 ib = 0 r = False bb = False for x in range(0, len(s) - 1, +1): if s[x][0] == s[x + 1][0]: tmp_ile += 1 s_ile[x][1] = s[x][1] else: s_ile[x][0] = tmp_ile s_ile[x][1] = s[x][1] tmp_ile = 1 s_ile[-1][0] = tmp_ile s_ile[-1][1] = s[-1][1] for x in range(len(s_ile) - 1, -1, -1): if s_ile[x][0] == 0: s_ile[x][0] = s_ile[x + 1][0] c1 = 0 for x in range(0, len(s_ile), +1): if s_ile[x][0] == 1: i1 += 1 if s_ile[x][0] > 2: iw += 1 if i1 % 2 == 1 and iw == 0: print("NO") exit(0) if i1 % 2 == 1: r = True if r == True: for x in range(0, len(s_ile), +1): if s_wyn[s_ile[x][1]] == "A" or s_wyn[s_ile[x][1]] == "B": continue if s_ile[x][0] == 1: if ia < ib: s_wyn[s_ile[x][1]] = "A" ia += 1 else: s_wyn[s_ile[x][1]] = "B" ib += 1 continue if s_ile[x][0] > 2 and bb == False: bb = True s_wyn[s_ile[x][1]] = "A" ia += 1 for z in range(x + 1, x + s_ile[x][0], +1): s_wyn[s_ile[z][1]] = "B" continue s_wyn[s_ile[x][1]] = "A" else: for x in range(0, len(s_ile), +1): if s_ile[x][0] == 1: if ia < int(i1 / 2): s_wyn[s_ile[x][1]] = "A" ia += 1 else: s_wyn[s_ile[x][1]] = "B" ib += 1 else: s_wyn[s_ile[x][1]] = "A" for x in range(0, len(s_ile), +1): if s_ile[x][0] == 0 or s_ile[x][0] == 2: s_wyn[s_ile[x][1]] = "B" continue print("YES") print("".join(s_wyn))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR LIST VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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 NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER STRING VAR VAR VAR NUMBER STRING IF VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR VAR NUMBER STRING VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER STRING ASSIGN VAR VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER NUMBER IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input().strip()) a = [int(x) for x in input().strip().split(" ")] d = {} cng = 0 for i in range(n): if a[i] in d: d[a[i]] += 1 if d[a[i]] > 2: cng = i else: d[a[i]] = 1 cnt1 = 0 cnt2 = 0 for i in d: if d[i] == 1: cnt1 += 1 elif d[i] > 2: cnt2 += 1 if cnt1 % 2 == 0: dd = {} for i in d: if d[i] == 1: if cnt1 % 2 == 0: dd[i] = "A" else: dd[i] = "B" cnt1 -= 1 else: dd[i] = "A" print("YES") for i in range(n): print(dd[a[i]], end="") elif cnt2 > 0: dd = {} d[a[cng]] -= 1 a[cng] = 101 d[101] = 1 cnt1 += 1 for i in d: if d[i] == 1: if cnt1 % 2 == 0: dd[i] = "A" else: dd[i] = "B" cnt1 -= 1 else: dd[i] = "A" print("YES") for i in range(n): print(dd[a[i]], end="") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING IF VAR NUMBER ASSIGN VAR DICT VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) arr = list(map(int, input().split())) num = [(0) for i in range(101)] for i in arr: num[i] += 1 od = set() dv = set() mn = set() o = 0 d = 0 m = 0 for i in range(101): if num[i] == 1: o += 1 od.add(i) elif num[i] == 2: dv.add(i) d += 1 elif num[i] > 2: mn.add(i) m += 1 if o % 2 == 1 and m == 0: print("NO") else: print("YES") dob = o % 2 s = "" h = "A" for i in arr: if i in od: s += h if h == "A": h = "B" else: h = "A" elif dob > 0 and i in mn: s += "B" dob -= 1 else: s += "A" print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR VAR IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = [int(s) for s in input().split()] d = dict() for i in a: if i in d.keys(): d[i] += 1 else: d[i] = 1 k = 0 for i in d: if d[i] == 1: k += 1 s = "" c1, c2 = 0, 0 r = ["A"] * n for ind, e in enumerate(a): if d[e] == 1: if c1 > c2: r[ind] = "B" c2 += 1 else: r[ind] = "A" c1 += 1 if c2 < c1: for ind, e in enumerate(a): if d[e] > 2: r[ind] = "B" c2 += 1 break if c2 < c1: print("NO") else: print("YES") print("".join(r))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER IF VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
gi = lambda: list(map(int, input().split())) (n,) = gi() l = gi() occ = [0] * 101 for e in l: occ[e] += 1 niceable, niceable2 = 0, 0 for k in range(1, 101): if occ[k] in (1, 2): niceable += occ[k] elif occ[k] > 0: niceable2 += 1 if niceable2 == 0 and niceable % 2: print("NO") exit() print("YES") cur1, cur2, index = 0, 0, 0 if (niceable2 + niceable) % 2: for e in l: if occ[e] > 2: occ[e] = -2 index = e break A = [] B = [] for k in range(1, 101): if occ[k] == 1: if cur1 % 2: A.append(k) else: B.append(k) cur1 += 1 elif occ[k] == 2: A.append(k) B.append(k) if len(A) > len(B): cur = 1 else: cur = 0 for k in range(1, 101): if occ[k] > 2: if cur % 2 == 0: A.append(k) B += [k] * (occ[k] - 1) else: B.append(k) A += [k] * (occ[k] - 1) cur += 1 A += [index] * l.count(index) for k in range(n): if l[k] in A: print("A", end="") A.remove(l[k]) else: print("B", end="") B.remove(l[k])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP LIST VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP LIST VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = list(map(int, input().split())) cnt = [0] * 101 ans = [] x = 0 z = -1 for i in a: cnt[i] += 1 for i in range(101): if cnt[i] == 1: x += 1 elif cnt[i] > 2: z = i if x % 2 == 0: y = 1 for i in range(n): if cnt[a[i]] == 1: if y <= x / 2: ans.append("A") y += 1 else: ans.append("B") else: ans.append("A") elif z == -1: exit(print("NO")) else: y = 1 mxcnt = 0 for i in range(n): if cnt[a[i]] == 1: if y <= x // 2: ans.append("A") y += 1 else: ans.append("B") elif a[i] == z: if mxcnt == 0: ans.append("A") mxcnt += 1 else: ans.append("B") else: ans.append("B") print("YES") print(*ans, sep="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
input() s = [] d = {} unic = 0 more_2 = 0 for a in input().split(): a = int(a) s.append(a) if a in d: d[a] += 1 if d[a] == 2: unic -= 1 else: more_2 += 1 else: d[a] = 1 unic += 1 if unic % 2 == 1 and more_2 == 0: print("NO") else: print("YES") splt = unic % 2 == 1 a_left = unic // 2 for a in s: if d[a] == 1: if a_left > 0: print("A", end="") a_left -= 1 else: print("B", end="") elif splt and d[a] > 2: print("A", end="") splt = False else: print("B", end="") print()
EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = input() a = list(map(int, input().split())) d = {i: (0) for i in range(1, 101)} for i in a: d[i] += 1 g = [] g2 = [] mg = [] for i in range(1, 101): if d[i] == 1: g.append(i) elif d[i] == 2: g2.append(i) elif d[i] > 2: mg.append(i) if len(g) % 2: if len(mg): print("YES") flag1 = True flag2 = False for i in a: if i in g: if flag1: print("A", end="") flag1 = False else: print("B", end="") flag1 = True elif i in mg: if flag2: print("A", end="") else: print("B", end="") flag2 = True else: print("A", end="") else: print("NO") else: print("YES") flag = False for i in a: if i in g: if flag: print("A", end="") flag = False else: print("B", end="") flag = True else: print("A", end="")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR IF VAR EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER IF VAR VAR IF VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR IF VAR EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
from sys import stdin, stdout class Solve: def __init__(self): R = stdin.readline W = stdout.write n = int(input()) a = [int(x) for x in R().split()] ans = ["A" for i in range(n)] check = {} auniq = buniq = 0 for i in range(n): if a[i] not in check: check[a[i]] = 0 check[a[i]] += 1 if check[a[i]] == 1: auniq += 1 elif check[a[i]] == 2: auniq -= 1 for i in range(n): if auniq == buniq: W("YES\n") W("".join(ans)) return if check[a[i]] == 1 and auniq > buniq + 1: check[a[i]] = 0 ans[i] = "B" auniq -= 1 buniq += 1 for i in range(n): if auniq == buniq: W("YES\n") W("".join(ans)) return if check[a[i]] > 2: check[a[i]] = 2 ans[i] = "B" buniq += 1 W("NO\n") def main(): s = Solve() main()
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
def N(): print("NO") def Y(): print("YES") n = int(input()) a = list(map(int, input().split())) memo = {} for i in range(n): if a[i] not in memo: memo[a[i]] = 1 else: memo[a[i]] += 1 if len(memo) == 1: for key in memo: if memo[key] == 1: N() elif memo[key] == 2: Y() print("AB") else: Y() print("A" * memo[key]) else: c1 = 0 alter = 1 found = 1 for key, value in memo.items(): if value == 1: if alter: memo[key] = ["A"] alter = 0 else: alter = 1 memo[key] = ["B"] c1 += 1 if c1 % 2 == 1: found = 0 for key, value in memo.items(): if type(value) == int and value >= 3: found = 1 memo[key] = ["A"] * value memo[key][0] = "B" break if not found: N() exit(0) Y() for i in range(n): if type(memo[a[i]]) == int: print("A", end="") else: print(memo[a[i]][-1], end="") memo[a[i]].pop()
FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER IF VAR ASSIGN VAR VAR LIST STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR LIST STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP LIST STRING VAR ASSIGN VAR VAR NUMBER STRING IF VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = list(map(int, input().split())) ct = {} a = [0] * 101 for i in range(n): ct[s[i]] = ct.get(s[i], 0) + 1 for i in ct: a[ct[i]] += 1 if a[1] % 2 == 0: c = "A" print("YES") ans = "" for i in range(n): if ct[s[i]] == 1: ans = ans + c c = "A" if c == "B" else "B" else: ans = ans + "A" print(ans) else: f = 0 for i in range(3, 101): if a[i] > 0: f = i break if f: p = 0 c = "A" ans = "" print("YES") for i in range(n): if ct[s[i]] == 1: ans = ans + c c = "A" if c == "B" else "B" elif ct[s[i]] == f and p == 0: ans = ans + "B" p = 1 else: ans = ans + "A" print(ans) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR STRING STRING STRING ASSIGN VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR STRING STRING STRING IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) Set = list(map(int, input().split())) Stat = [0] * 101 A = 0 B = 0 a, b, c = 0, 0, 0 ans = "" ch = False for el in Set: Stat[el] += 1 for i in range(1, 101): if Stat[i] == 1: a += 1 elif Stat[i] > 2: c += 1 elem = -1 if a % 2 == 0: print("YES") count = 1 for el in Set: if Stat[el] == 1: if count <= a // 2: ans += "A" count += 1 else: ans += "B" else: ans += "B" print(ans) elif c > 0: count = 1 print("YES") for el in Set: if Stat[el] == 1: if count <= a // 2 + 1: ans += "A" count += 1 else: ans += "B" elif Stat[el] > 2 and elem < 0: ans += "B" elem = el elif el == elem: ans += "A" else: ans += "B" print(ans) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR STRING VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR STRING VAR NUMBER VAR STRING IF VAR VAR NUMBER VAR NUMBER VAR STRING ASSIGN VAR VAR IF VAR VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) multiset = list(map(int, input().split())) A = 0 B = 0 rep = [(0) for i in range(100)] ans = "" altern = 1 for i in multiset: rep[i - 1] += 1 suma = sum(1 for i in multiset if rep[i - 1] == 1) triple = any(i >= 3 for i in rep) if suma % 2 == 0 or triple and suma % 2 != 0: print("YES") if suma % 2 == 0: for i in multiset: if rep[i - 1] == 1 and altern == 1: ans += "A" altern *= -1 elif rep[i - 1] == 1 and altern == -1: ans += "B" altern *= -1 else: ans += "A" print(ans) else: for i in multiset: if rep[i - 1] == 1 and altern == 1: ans += "A" altern *= -1 elif rep[i - 1] == 1 and altern == -1: ans += "B" altern *= -1 elif rep[i - 1] > 2 and triple: ans += "B" triple = False else: ans += "A" print(ans) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR STRING VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR STRING ASSIGN VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = list(map(int, input().split())) num1 = 0 b = ["A"] * n cnt = {} fst = {} for i in range(len(s)): if s[i] in cnt: cnt[s[i]] += 1 else: cnt[s[i]] = 1 fst[s[i]] = i for i in range(len(s)): if cnt[s[i]] == 1: if num1 % 2 == 1: b[i] = "B" num1 += 1 if num1 % 2 == 1: res = False for i in range(len(s)): if cnt[s[i]] > 2: b[i] = "B" res = True break else: res = True if res: print("YES") s1 = "" for i in b: s1 += i print(s1) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) lis = [int(x) for x in input().split()] result = [(-1) for _ in range(n)] count = {} for j, i in enumerate(lis): if i not in count: count[i] = [] count[i].append(j) turn = 1 isEven = True for key in count.keys(): li = count[key] le = len(li) if le == 1: result[li[0]] = turn turn = 1 if turn == 0 else 0 isEven = False if isEven else True elif le == 2: for i in li: result[i] = 1 for key in count.keys(): li = count[key] le = len(li) if le > 2: if isEven: for i in li: result[i] = 1 else: result[li[0]] = turn turn = 1 if turn == 0 else 0 isEven = True for i in li[1:]: result[i] = turn if isEven: print("YES") for i in result: if i == 0: print("A", end="") else: print("B", end="") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
N = int(input()) ls = list(map(int, input().split())) nice = [] count = {} for i in ls: if i in count: count[i] += 1 else: count[i] = 1 for i in range(len(ls)): if count[ls[i]] == 1: nice.append(ls[i]) candidate = 0 for i in range(len(ls)): if count[ls[i]] > 2: candidate = ls[i] if len(nice) % 2 and candidate == 0: print("NO") elif len(nice) % 2: print("YES") result = [] turn = "A" for i in ls: if candidate == i: result.append("B") elif i in nice: if turn == "A": turn = "B" else: turn = "A" result.append(turn) else: result.append("B") for i in range(len(ls)): if candidate == ls[i]: result[i] = "A" break for i in result: print(i, end="") print() else: print("YES") turn = "A" for i in ls: if i in nice: if turn == "A": turn = "B" else: turn = "A" print(turn, end="") else: print("B", end="") print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
MOD = 10**9 + 7 I = lambda: list(map(int, input().split())) (n,) = I() l = I() ans = [] char = "A" d = {"A": 0, "B": 0} cs = [0] * 105 for i in l: cs[i] += 1 for i in l: if cs[i] == 1: d[char] += 1 ans.append(char) char = "B" if char == "A" else "A" else: ans.append("A") if d["A"] == d["B"]: print("YES") print(*ans, sep="") exit() fuc = 0 for i in range(1, 101): if cs[i] > 2: fuc = i break if not fuc: print("NO") exit() for i in range(n): if l[i] == fuc: ans[i] = "B" break print("YES") print(*ans, sep="")
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR DICT STRING STRING NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING STRING STRING EXPR FUNC_CALL VAR STRING IF VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = list(map(int, input().split())) d = {} m = 10000000000 count1 = 0 p = 0 t = 0 for i in a: d[i] = d.get(i, 0) + 1 if d[i] < m: m = d[i] if m >= 2: print("YES") print("A" * n) else: s = "A" * n for i in range(n): if d[a[i]] == 1 and count1 % 2 == 0: s = s[:i] + "B" + s[i + 1 :] count1 += 1 elif d[a[i]] == 1: count1 += 1 if count1 % 2 == 0: print("YES") print(s) else: for i in range(n): if d[a[i]] > 2: k = a[i] s = s[:i] + "A" + s[i + 1 :] t = 1 break if t == 1: for p in range(i + 1, n): if a[p] == k: s = s[:p] + "B" + s[p + 1 :] print("YES") print(s) if t == 0: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
import sys inf = float("inf") abc = "abcdefghijklmnopqrstuvwxyz" abd = { "a": 0, "b": 1, "c": 2, "d": 3, "e": 4, "f": 5, "g": 6, "h": 7, "i": 8, "j": 9, "k": 10, "l": 11, "m": 12, "n": 13, "o": 14, "p": 15, "q": 16, "r": 17, "s": 18, "t": 19, "u": 20, "v": 21, "w": 22, "x": 23, "y": 24, "z": 25, } mod, MOD = 1000000007, 998244353 vow = ["a", "e", "i", "o", "u"] dx, dy = [-1, 1, 0, 0], [0, 0, 1, -1] def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def get_ints(): return map(int, sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() n = int(input()) Arr = get_array() mydict = dict() for i in Arr: mydict[i] = mydict.get(i, 0) + 1 count_1 = 0 count_2 = 0 count_3 = 0 Arr1 = [] Arr2 = [] Arr3 = [] for i in mydict: if mydict[i] == 1: count_1 += 1 Arr1.append(i) elif mydict[i] == 2: count_2 += 1 Arr2.append(i) elif mydict[i] >= 3: count_3 += 1 Arr3.append(i) if count_1 & 1 and count_3 == 0: print("NO") exit(0) if not count_1 & 1: result = [] Arr_new = Arr1[: len(Arr1) // 2] Arr_new2 = Arr1[len(Arr1) // 2 :] for i in Arr: if i in Arr_new: result.append("A") else: result.append("B") elif count_1 & 1 and count_3 > 0: result = [] Arr_new = Arr1[: len(Arr1) // 2] Arr_new2 = Arr1[len(Arr1) // 2 :] Arr_new3 = Arr3[:1] for i in Arr: if i in Arr_new: result.append("A") elif i in Arr_new3: result.append("A") Arr_new3.remove(i) else: result.append("B") print("YES") print("".join(result))
IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING 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 ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR VAR LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = [int(i) for i in input().split()] k = [(0) for i in range(101)] flag = False for i in s: k[i] += 1 if k[i] > 2: flag = True b = k.count(1) // 2 a = k.count(1) - b if a == b: print("YES") for i in s: if k[i] == 1 and a != 0: print("A", end="") a -= 1 k[i] -= 1 elif k[i] == 1: print("B", end="") k[i] -= 1 else: print("A", end="") elif flag: print("YES") for i in s: if k[i] == 1 and a != 0: print("A", end="") a -= 1 k[i] -= 1 elif k[i] == 1: print("B", end="") k[i] -= 1 elif k[i] > 2 and flag: print("B", end="") flag = False else: print("A", end="") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR VAR NUMBER IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) arr = list(map(int, input().split())) d = {} ans = ["A"] * n for i in range(n): if arr[i] in d: d[arr[i]].append(i) else: d[arr[i]] = [i] flag = False s = "A" cnt = 0 sec_arr = [] for i in d.keys(): if len(d[i]) == 1: cnt += 1 a = d[i] if s == "A": s = "B" continue else: ans[a[0]] = s s = "A" elif len(d[i]) > 2: sec_arr = d[i] if cnt % 2 == 0: print("YES") print("".join(ans)) elif cnt % 2 == 1 and len(sec_arr) > 0: print("YES") ans[sec_arr[0]] = "B" print("".join(ans)) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR NUMBER VAR ASSIGN VAR STRING IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = list(map(int, input().split())) str = [(0) for i in range(n)] count_ = [s.count(i) for i in s] One_occur_index = [i for i in range(n) if s.count(s[i]) == 1] Two_occur_index = [i for i in range(n) if s.count(s[i]) == 2] many_occur_index = [i for i in range(n) if s.count(s[i]) >= 3] if len(One_occur_index) % 2 and len(many_occur_index) == 0: print("NO") else: for i in Two_occur_index: str[i] = 0 for i in One_occur_index[0 : len(One_occur_index) // 2]: str[i] = 1 if len(One_occur_index) % 2: str[many_occur_index[0]] = 1 output = [("A" if str[i] else "B") for i in range(n)] print("YES") print("".join(output))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR STRING STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = [int(i) for i in input().split()] freq = {} for i in a: freq[i] = freq.get(i, 0) + 1 if sum(1 for i in freq if freq[i] == 1) % 2 == 0: print("YES") counter = 0 for i in a: if freq[i] == 1: print("A" if counter % 2 else "B", end="", flush=False) counter += 1 else: print("B", end="", flush=False) print() elif any(freq[i] > 2 for i in freq): print("YES") counter = 0 single = 0 for i in a: if freq[i] == 1: print("A" if counter % 2 else "B", end="", flush=False) counter += 1 elif freq[i] > 2 and not single: print("A", end="", flush=False) single = True else: print("B", end="", flush=False) print() else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING STRING NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING STRING STRING NUMBER VAR NUMBER IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = list(map(int, input().split())) m = {} s = [[], []] for i in a: if i in m: m[i] += 1 else: m[i] = 1 pos = 0 for p in m: if m[p] == 1: s[pos].append(p) pos = 1 - pos if len(s[0]) == len(s[1]): res = "" for i in range(n): if a[i] in s[1]: res += "B" else: res += "A" print("YES") print(res) else: res = "" idd = -1 for p in m: if m[p] >= 3: idd = p break if idd == -1: print("NO") exit(0) flag = False for i in range(n): if a[i] in s[1]: res += "B" elif a[i] == idd and flag == False: res += "B" flag = True else: res += "A" print("YES") print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST LIST LIST FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR STRING IF VAR VAR VAR VAR NUMBER VAR STRING ASSIGN VAR NUMBER VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) p = [int(x) for x in input().split()] a = [(0) for i in range(101)] type1 = [] type2 = [] resa = [] for i in p: a[i] += 1 for i in range(len(a)): if a[i]: if a[i] == 1: type1.append(i) if a[i] >= 3: type2.append(i) if len(type1) % 2 == 0: print("YES") resa = type1[: len(type1) // 2] for i in range(len(p)): if p[i] in resa: print("A", end="") else: print("B", end="") print() elif len(type2) >= 1: print("YES") resa = type1[: len(type1) // 2] resb = [type2[0]] f = 1 for i in p: if i in resa: print("A", end="") elif i in resb and f: f = 0 print("A", end="") else: print("B", end="") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING STRING IF VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s1 = 0 s2 = 0 s = ["A"] * 101 dic = {} lis = list(map(int, input().split())) length = len(lis) count = 0 flag = 0 backup = -1 for i in lis: dic[i] = dic.get(i, 0) + 1 for i in dic: if dic[i] == 1: count += 1 if dic[i] > 2: flag = 1 backup = i if count % 2 == 1: if flag == 0: print("NO") exit() lis2 = [] if count % 2 == 0: backup = -1 for i in dic: if dic[i] == 1: lis2.append(i) if backup != -1: lis2.append(backup) for i in lis2: if s1 == 0 or s1 == s2: s[i] = "A" s1 += 1 continue if s2 + 1 == s1: s[i] = "B" s2 += 1 continue print("YES") flag2 = 0 for i in lis: if i == backup and flag2 == 0: print(s[i], end="") flag2 = 1 if s[i] == "A": s[i] = "B" else: s[i] = "A" continue print(s[i], end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST STRING NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = list(map(int, input().split())) d = dict() for i in s: if i in d: d[i] += 1 else: d.update({i: 1}) c = 0 for i in d: if d[i] == 1: c += 1 ans = "" if c % 2 == 0: t = True for i in s: if d[i] == 1: if t: ans += "A" else: ans += "B" t = not t else: ans += "A" print("YES") print(ans) else: can = False for i in d: if d[i] > 2: can = True x = i if can: t = True t1 = False t3 = True for i in s: if d[i] == 1 or i == x and t1 == False: if i == x and t1 == False: t1 = True if t: ans += "A" t3 = True else: ans += "B" t3 = False t = not t else: if t: ans += "A" else: ans += "B" t = not t elif i == x: if t3: ans += "B" else: ans += "A" else: ans += "A" print("YES") print(ans) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR DICT VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR VAR STRING VAR STRING ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR VAR STRING VAR STRING ASSIGN VAR VAR IF VAR VAR IF VAR VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
def init(): n = int(input()) Str = input() a = list(map(int, str.split(Str))) return n, a def main(): n, a = init() cnt = [(0) for x in range(105)] tot1 = 0 tot2 = 0 tot3 = 0 for i in range(n): cnt[a[i]] += 1 if cnt[a[i]] == 1: tot1 += 1 if cnt[a[i]] == 2: tot1 -= 1 tot2 += 1 if cnt[a[i]] == 3: tot2 -= 1 tot3 += 1 if tot1 % 2 != 0 and tot3 == 0: print("NO") return if tot1 % 2 == 0: print("YES") for i in range(n): if cnt[a[i]] != 1: print("A", end="") else: if tot1 % 2 == 0: print("A", end="") else: print("B", end="") tot1 -= 1 else: flag = 0 print("YES") for i in range(n): if cnt[a[i]] > 2: if flag == 0: print("A", end="") flag = 1 else: print("B", end="") if cnt[a[i]] == 2: print("A", end="") if cnt[a[i]] == 1: if tot1 % 2 == 1: print("B", end="") else: print("A", end="") tot1 -= 1 main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING VAR NUMBER EXPR FUNC_CALL VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) S = list(map(int, input().split())) LIST = [(0) for i in range(101)] for s in S: LIST[s] += 1 for i in range(len(LIST)): if LIST[i] == 2: LIST[i] = 0 elif LIST[i] > 2: LIST[i] = 3 if sum(LIST) % 2 == 1 and not 3 in LIST: print("NO") else: if sum(LIST) % 2 == 1: LIST[LIST.index(3)] = 0 for i in range(len(LIST)): if LIST[i] > 2: LIST[i] = 1 APP = sum(LIST) // 2 ANS = "" for s in S: if APP > 0 and LIST[s] == 1: ANS += "A" APP -= 1 LIST[s] = "B" elif LIST[s] == 1: ANS += "B" LIST[s] = "A" elif LIST[s] == "A": ANS += "A" else: ANS += "B" print("YES") print(ANS)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR STRING VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
def main(): n = int(input()) a = list(map(int, input().split())) s = set() elem = -1 for i in range(n): if a.count(a[i]) == 1: s.add(a[i]) elif a.count(a[i]) >= 3: elem = a[i] if len(s) == 0: print("YES") for i in range(n): print("A", end="") elif len(s) % 2 == 0: print("YES") f = True for i in range(n): if a[i] in s: if f: print("A", end="") f = False else: print("B", end="") f = True else: print("A", end="") elif elem == -1: print("NO") else: print("YES") a1 = [] a2 = [] for i in range(len(s) // 2): a1.append(s.pop()) a1.append(elem) for i in range(len(s)): a2.append(s.pop()) c = 0 for i in range(n): if a[i] == elem: if c == 0: print("A", end="") c += 1 else: print("B", end="") elif a[i] in a1: print("A", end="") elif a[i] in a2: print("B", end="") else: print("A", end="") main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR VAR VAR EXPR FUNC_CALL VAR STRING STRING IF VAR VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = list(map(int, input().split())) c = [0] * 101 for i in range(n): c[s[i]] += 1 cnt = 0 cc = 0 for i in range(n): if c[s[i]] == 1: cnt += 1 elif c[s[i]] >= 3: cc += 1 if cnt % 2 == 1 and cc == 0: print("NO") else: ans = [""] * n al = ["A", "B"] if cnt % 2 == 0 and cc == 0: d = 0 for i in range(n): if c[s[i]] == 1: ans[i] = al[d] d = 1 - d else: ans[i] = "A" elif cnt % 2 == 1 and cc >= 1: d = 0 e = -1 for i in range(n): if c[s[i]] >= 3: e = s[i] break flag = 1 for i in range(n): if c[s[i]] == 1: ans[i] = al[d] d = 1 - d elif flag and s[i] == e: ans[i] = "B" flag = 0 else: ans[i] = "A" else: d = 0 for i in range(n): if c[s[i]] == 1: ans[i] = al[d] d = 1 - d else: ans[i] = "A" print("YES") print("".join(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR LIST STRING STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
import sys input = sys.stdin.buffer.readline def solution(): n = int(input()) l = list(map(int, input().split())) d = [0] * 101 for i in l: d[i] += 1 cnt = 0 ind = 0 x = [] flag = 0 s = "" for i in range(101): if d[i] == 1: cnt += 1 x.append(i) if d[i] > 2: ind = i if cnt % 2 != 0 and ind == 0: print("NO") else: print("YES") if cnt % 2 == 0: for i in range(n): if d[l[i]] == 1: if flag == 0: s += "A" flag = 1 else: s += "B" flag = 0 else: s += "A" else: flag = 0 fa = 0 fb = 0 f = 0 for i in range(n): if d[l[i]] == 1: if flag == 0: s += "A" flag = 1 else: s += "B" flag = 0 elif l[i] == ind and f == 0: if flag == 0: s += "A" fa = 1 flag = 1 else: s += "B" fb = 1 flag = 0 f = 1 elif l[i] == ind: if fa == 1: s += "B" else: s += "A" else: s += "A" print(s) solution()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER VAR STRING ASSIGN VAR NUMBER VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR IF VAR NUMBER VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
import sys def main(): n = int(input()) s = list(map(int, input().split())) cnt = {i: s.count(i) for i in s} if list(cnt.values()).count(1) == 0: print("YES") print("A" * len(s)) return if list(cnt.values()).count(1) & 1: c3 = len(cnt) - list(cnt.values()).count(1) - list(cnt.values()).count(2) if c3 == 0: print("NO") return else: print("YES") ok = False f = 0 for i in s: if not ok and cnt[i] >= 3: print("B", end="") ok = True elif cnt[i] == 1: print(["A", "B"][f], end="") f ^= 1 else: print("A", end="") print() else: print("YES") f = 0 for i in s: if cnt[i] == 1: print(["A", "B"][f], end="") f ^= 1 else: print("A", end="") print() main()
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR RETURN IF BIN_OP FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) y = list(map(int, input().split())) arr = [0] * (100 + 1) y1 = y.copy() y1 = sorted(y1) for i in y1: arr[i] += 1 x = count1 = 0 for i in arr: if i == 1: count1 += 1 elif i > 2: x += 1 if count1 % 2 == 0: ans = [] i = 0 k = 0 while i < n: if arr[y[i]] == 1: if k % 2 == 0: ans.append("A") else: ans.append("B") k += 1 else: ans.append("A") i += 1 print("YES") for i in ans: print(i, end="") elif x > 0: last = 0 last1 = "A" ans = [] i = 0 k = 0 flag = 0 while i < n: if arr[y[i]] == 1: if k % 2 == 0: ans.append("A") else: ans.append("B") k += 1 elif arr[y[i]] > 2 and flag == 0: if k % 2 == 0: ans.append("A") else: ans.append("B") k += 1 flag = 1 last = y[i] last1 = ans[-1] elif last == y[i]: if last1 == "A": ans.append("B") else: ans.append("A") else: ans.append("A") i += 1 print("YES") for i in ans: print(i, end="") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = list(map(int, input().split())) non_good_numbers = [] raw_numbers = [] for i in s: count = s.count(i) if count == 1: raw_numbers.append(i) elif count > 2: non_good_numbers.append(i) if len(raw_numbers) % 2 == 1 and len(non_good_numbers) == 0: print("NO") else: if len(raw_numbers) % 2 == 1: use_non_good_number = non_good_numbers[0] else: use_non_good_number = None is_non_good_used = False res = [] number_flag = "A" for i in s: if i == use_non_good_number: if not is_non_good_used: res.append("B") is_non_good_used = True else: res.append("A") elif i in raw_numbers: res.append(number_flag) number_flag = "B" if number_flag == "A" else "A" else: res.append("A") print("YES") print("".join(res))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR VAR IF VAR VAR IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
input() i = input().split() for a in range(len(i)): i[a] = int(i[a]) counts = {} nice = [] not_nice = [] for a in i: if a in not_nice: counts[a] += 1 elif a in nice: counts[a] += 1 del nice[nice.index(a)] not_nice.append(a) else: counts[a] = 1 nice.append(a) if len(nice) % 2 == 0: n = 0 output = "" for a in i: if n < len(nice) / 2 and a in nice: output += "A" else: output += "B" if a in nice: n += 1 print("YES") print(output) else: move = None for a in counts: if counts[a] > 2: move = a break if move is None: print("NO") else: output = "" n = 0 moved = 0 for a in i: if a == move: if moved == 0: output += "A" moved += 1 else: output += "B" elif n < len(nice) // 2: output += "A" else: output += "B" if a in nice: n += 1 print("YES") print(output)
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR STRING VAR STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NONE FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR NONE EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR STRING VAR STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = list(map(int, input().split())) def getstr(a): ans = "" for i in a: ans += i return ans count = [0] * 101 ans = [] for i in range(n): count[s[i]] += 1 a = 0 b = 0 for i in range(101): if count[i] > 0: if count[i] == 1: a += 1 elif count[i] > 2: b += 1 if a % 2 == 0: idx = 0 for i in range(n): if count[s[i]] == 1: if idx == 1: ans.append("A") else: ans.append("B") idx = 1 - idx else: ans.append("A") print("YES") print(getstr(ans)) elif a % 2 == 1 and b > 0: ele = -1 for i in range(n): if count[s[i]] > 2: ele = s[i] break done = False idx = 0 for i in range(n): if count[s[i]] == 1: if idx == 1: ans.append("A") else: ans.append("B") idx = 1 - idx elif s[i] == ele: if not done: ans.append("A") done = True else: ans.append("B") else: ans.append("A") print("YES") print(getstr(ans)) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR STRING FOR VAR VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
import sys inf = float("inf") mod = 1000000007 def get_array(): return list(map(int, sys.stdin.readline().split())) def get_ints(): return map(int, sys.stdin.readline().split()) def input(): return sys.stdin.readline() def main(): n = int(input()) arr = get_array() d = {} for i in arr: d[i] = d.get(i, 0) + 1 count = 0 check = 0 for i in d: if d[i] == 1: count += 1 if d[i] > 2: check = 1 if count % 2 == 0: ans = ["A"] * n flag = 0 for i in range(n): if d[arr[i]] == 1: if flag == 1: ans[i] = "B" flag = 1 - flag print("YES") print(*ans, sep="") return if count % 2 == 1 and check == 0: print("NO") return flag = 0 check = 0 ans = ["A"] * n for i in range(n): if d[arr[i]] == 1: if flag == 1: ans[i] = "B" flag = 1 - flag if check == 0 and d[arr[i]] > 2: check = 1 ans[i] = "B" print("YES") print(*ans, sep="") main()
IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING RETURN IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) l = list(map(int, input().strip().split())) l1 = [(0) for i in range(101)] for i in l: l1[i] = l1[i] + 1 ans = "" l2 = [] v = 0 for i in range(1, 101): if l1[i] == 1: l2.append(i) if l1[i] >= 3: v = i if v != 0: if len(l2) % 2 == 1: l2.insert(0, v) if len(l2) % 2 == 1: print("NO") exit(0) d1 = {} for i in range(1, 101): d1[i] = "A" d = "A" for i in l: if i in l2: ans = ans + d if l1[i] >= 3: if d == "A": d1[i] = "B" else: d1[i] = "A" l2.remove(i) if d == "A": d = "B" else: d = "A" else: ans = ans + d1[i] print("YES") print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
a = int(input()) b = list(map(int, input().split())) c = [0] * 101 for i in b: c[i] += 1 k = 0 kk = 0 for j in range(1, 101): if c[j] == 1: k += 1 if c[j] > 2: kk += 1 if k % 2 == 0: print("YES") l = 0 for j in b: if c[j] == 1: if l < k // 2: print("A", end="") l += 1 else: print("B", end="") else: print("B", end="") elif kk == 0: print("NO") else: print("YES") l = 0 p = 0 for j in b: if c[j] == 1: if l < k // 2: print("A", end="") l += 1 else: print("B", end="") elif c[j] > 2: if p == 0: print("A", end="") p = 1 else: print("B", end="") else: print("B", end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = list(map(int, input().split())) counts = {} for number in a: if number not in counts: counts[number] = 0 counts[number] += 1 left = 0 right = 0 tags = ["A"] * n for count in counts: if counts[count] == 1: left += 1 i = 0 for number in a: if counts[number] == 1 and left > right + 1: left -= 1 right += 1 tags[i] = "B" i += 1 i = 0 for number in a: if counts[number] >= 3 and left > right: tags[i] = "B" right += 1 break i += 1 if left == right: print("YES") print("".join(tags)) else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) qtt = {} dst = {} tab = [] out = [""] * n monos = [] dulis = [] polis = [] inp = input().split(" ") for i in range(n): s = inp[i] tab.append(s) if s in qtt: qtt[s] += 1 else: qtt[s] = 1 dst[s] = "A" for i in qtt: if qtt[i] == 1: monos.append(i) elif qtt[i] == 2: dulis.append(i) else: polis.append(i) if len(monos) % 2 != 0 and len(polis) < 1: print("NO") else: if len(monos) % 2 == 0: prcd = 0 for i in monos: if prcd < len(monos) / 2: dst[i] = "B" else: break prcd += 1 charity = False else: prcd = 0 for i in monos: if prcd < (len(monos) - 1) / 2: dst[i] = "B" else: break prcd += 1 for i in polis: charity = i break for i in range(len(tab)): if tab[i] == charity: out[i] = "B" charity = False else: out[i] = dst[tab[i]] print("YES") for i in out: print(i, end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR STRING FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR STRING VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
MOD = 1000000007 ii = lambda: int(input()) si = lambda: input() dgl = lambda: list(map(int, input())) f = lambda: map(int, input().split()) il = lambda: list(map(int, input().split())) ls = lambda: list(input()) n = ii() l = il() l1 = [0] * 101 lans = ["A"] * n for i in l: l1[i] += 1 c1 = 0 c3 = 0 for i in l1: if i == 1: c1 += 1 elif i > 2: c3 += 1 if c1 & 1: if not c3 > 0: print("NO") exit(0) else: for i in range(101): if l1[i] > 2: x = l.index(i) lans[x] = "B" break c1 = 0 for i in l: if l1[i] == 1: c1 += 1 if c1 % 2 == 0: x = l.index(i) lans[x] = "B" print("YES") print("".join(lans))
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) l = list(map(int, input().split())) ans = [0] * n check = [0] * 101 for i in range(n): check[l[i]] += 1 once = 0 for i in range(101): if check[i] == 1: once += 1 keep = 1 if once % 2 == 0: print("YES") for i in range(n): if check[l[i]] == 1 and keep <= once // 2: ans[i] = "A" keep += 1 else: ans[i] = "B" print("".join(ans)) elif max(check) <= 2: print("NO") else: keep = 1 print("YES") convert = 0 for i in range(1, 101): if check[i] > 2: convert = i break flag = 0 for i in range(n): if check[l[i]] == 1 and keep <= once // 2: ans[i] = "A" keep += 1 elif l[i] == convert and flag == 0: ans[i] = "A" flag = 1 else: ans[i] = "B" print("".join(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) freq_dict = {} a = list(map(int, input().split())) for i in a: if i in freq_dict.keys(): freq_dict[i] += 1 else: freq_dict[i] = 1 freq_freq_dict = {(1): 0, (2): 0, (-1): 0} for i in freq_dict.values(): if i == 1: freq_freq_dict[1] += 1 elif i == 2: freq_freq_dict[2] += 1 else: freq_freq_dict[-1] += 1 if freq_freq_dict[1] != 0: if freq_freq_dict[1] % 2: if freq_freq_dict[-1] != 0: print("YES") flag = True other_letter = "" for i in a: if freq_dict[i] == 1: if flag: print("A", end="") else: print("B", end="") flag = not flag elif freq_dict[i] != 1 and freq_dict[i] != 2: if other_letter == "": other_letter = i print("B", end="") else: print("A", end="") else: print("A", end="") else: print("NO") else: print("YES") flag = True for i in a: if freq_dict[i] == 1: if flag: print("A", end="") else: print("B", end="") flag = not flag else: print("A", end="") else: print("YES") print("A" * len(a))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) coun = {} a = list(map(int, input().split())) odin = 0 dva = 0 tre = 0 for ii in range(n): i = a[ii] if i not in coun: coun[i] = [ii] odin += 1 elif len(coun[i]) == 1: coun[i].append(ii) odin -= 1 dva += 1 elif len(coun[i]) == 2: coun[i].append(ii) dva -= 1 tre += 1 else: coun[i].append(ii) first = 0 second = 0 if odin == 0: print("YES") print("A" * n) elif odin % 2 != 0 and tre == 0: print("NO") else: print("YES") if odin % 2 == 0 and tre == 0: mode = 1 elif odin % 2 == 0 and tre > 0: mode = 2 elif odin % 2 == 1 and tre > 0: first_tre = False mode = 3 for i in range(len(a)): if len(coun[a[i]]) == 2: a[i] = "A" elif mode == 1: if first > second: second += 1 a[i] = "B" else: first += 1 a[i] = "A" elif mode == 2: if len(coun[a[i]]) >= 3: a[i] = "A" elif first > second: second += 1 a[i] = "B" else: first += 1 a[i] = "A" elif len(coun[a[i]]) >= 3: if first_tre == False: first_tre = True if first < second: a[i] = "A" last = "B" first += 1 else: a[i] = "B" last = "A" second += 1 else: a[i] = last elif first > second: second += 1 a[i] = "B" else: first += 1 a[i] = "A" print("".join(a)) if first != second: int("kill me")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING IF VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING IF FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR STRING VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR STRING VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) arr = [([0] * 2) for i in range(101)] st = str(input()).split() st = [int(i) for i in st] for i in st: arr[int(i) - 1][0] += 1 one = 0 two = 0 more = 0 x = 0 y = 0 for i in range(101): if arr[i][0] == 1: one += 1 elif arr[i][0] == 2: two += 1 y += arr[i][0] elif arr[i][0] > 2: more += 1 x += arr[i][0] yes = 0 ll = 0 no = 0 odd = 0 even = 0 lp = 0 if one > 0: if one % 2 == 1: odd = 1 else: even = 1 elif more >= 1 and two >= 0 and one == 0: yes = 1 ll = 1 print("YES") aaa = x + y print("A" * aaa) lp = 1 yes = 0 no = 0 m = 0 mm = 0 t = 0 if even == 1: yes = 1 elif odd == 1: if more >= 1: yes = 1 m = 1 elif more >= 2: yes = 1 mm = 1 elif two >= 1: yes = 1 t = 1 else: no = 1 f = 1 sa = "" if yes == 1: if m == 0 and mm == 0 and t == 0: f = 1 for i in st: if arr[i - 1][0] == 1: if f == 1: sa += "A" f = f % 2 + 1 else: sa += "B" f = f % 2 + 1 elif arr[i - 1][0] >= 2: sa += "A" elif m == 1: f = 1 ff = 1 for i in st: if arr[i - 1][0] == 1: if f == 1: sa += "A" f = f % 2 + 1 else: sa += "B" f = f % 2 + 1 elif arr[i - 1][0] > 2: if f == 1 and ff == 1: sa += "B" ff = 2 elif ff == 1: sa += "B" ff = 3 else: sa += "A" elif arr[i - 1][0] == 2: sa += "A" elif mm == 1: f = 1 ff = 0 for i in st: sa += "A" elif t == 1: sa += "AB" * two if yes == 1 and lp == 0: print("YES") print(sa) elif ll == 0: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER VAR STRING IF VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR STRING IF VAR NUMBER VAR BIN_OP STRING VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = list(map(int, input().split())) f = dict() for si in s: if si in f: f[si] += 1 else: f[si] = 1 nice = set() for k in f: if f[k] == 1: nice.add(k) found = True toChange = -1 if len(nice) % 2 != 0: found = False for k in f: if f[k] >= 3: toChange = k found = True break nicelength = len(nice) if not found: print("NO") else: print("YES") ans = [] for si in s: if si in nice: if len(nice) <= nicelength // 2: ans.append("A") else: ans.append("B") nice.remove(si) elif si == toChange: ans.append("A") toChange = -1 else: ans.append("B") print("".join(ans))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) a = list(map(int, input().split())) counts = [0] * 101 for guy in a: counts[guy] += 1 useless = counts.count(0) + counts.count(2) forced = counts.count(1) useful = 101 - useless - forced if useful == 0 and forced % 2 == 1: print("NO") else: if forced % 2 == 0: each = forced // 2 out = "" seen = 0 for guy in a: if counts[guy] == 1 and seen < each: out += "A" seen += 1 else: out += "B" else: As = forced // 2 out = "" seen = 0 good = 0 for guy in a: if counts[guy] == 1 and seen < As: out += "A" seen += 1 elif counts[guy] > 2 and good == 0: out += "A" good = 1 else: out += "B" print("YES") print(out)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR VAR STRING VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR STRING ASSIGN VAR NUMBER VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = map(int, input()) values = list(map(int, input().split())) freq = {} for v in values: if v not in freq: freq[v] = 0 freq[v] += 1 single_ids = [] for v in freq: if freq[v] == 1: single_ids.append(v) key_greater_than_2 = False key = None for v in freq: if freq[v] > 2: key_greater_than_2 = True key = v break if ( len(single_ids) == len(values) and len(single_ids) % 2 == 1 or len(single_ids) % 2 == 1 and not key_greater_than_2 ): print("NO") else: print("YES") mapping = {} unique_count = 1 for v in freq: if freq[v] == 1: mapping[v] = "A" if unique_count <= len(single_ids) / 2 else "B" unique_count += 1 else: mapping[v] = "A" answers = [] filled = False for v in values: if v == key and len(single_ids) % 2 == 1: if not filled: answers.append("A") filled = True else: answers.append("B") else: answers.append(mapping[v]) print("".join(answers))
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING STRING VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) lst = [*map(int, input().split())] d = {} for i, x in enumerate(lst): if d.get(x) == None: d[x] = 0 d[x] += 1 one, item, res = 0, -1, [] for i, x in enumerate(d): if d[x] == 1: one += 1 res.append(x) if d[x] > 2: item = x result = ["A"] * n if one % 2 == 0: for i, x in enumerate(res[: one // 2]): result[lst.index(x)] = "B" print("YES") print("".join(result)) elif item == -1: print("NO") else: for i, x in enumerate(res[: one // 2]): result[lst.index(x)] = "B" result[lst.index(item)] = "B" print("YES") print("".join(result))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) s = [int(i) for i in input().split()] count = [(0) for i in range(200)] for i in range(n): count[s[i]] = count[s[i]] + 1 big = 0 total = 0 biggie = 0 for i in range(1, 101): if count[i] == 1: total = total + 1 if count[i] > 2: big = big + 1 for i in range(n): if count[s[i]] > 2: biggie = i if total % 2 == 0: print("YES") alternate = 0 string = "" for i in range(n): if count[s[i]] == 1: if alternate == 0: string = string + "A" alternate = 1 else: string = string + "B" alternate = 0 else: string = string + "B" print(string) elif big == 0: print("NO") else: print("YES") alternate = 0 string = "" for i in range(n): if count[s[i]] == 1: if alternate == 0: string = string + "A" alternate = 1 else: string = string + "B" alternate = 0 elif i == biggie: string = string + "B" else: string = string + "A" print(string)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR VAR
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4. Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b). Input The first line contains a single integer n~(2 ≀ n ≀ 100). The second line contains n integers s_1, s_2, ... s_n~(1 ≀ s_i ≀ 100) β€” the multiset s. Output If there exists no split of s to satisfy the given requirements, then print "NO" in the first line. Otherwise print "YES" in the first line. The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input. If there exist multiple solutions, then print any of them. Examples Input 4 3 5 7 1 Output YES BABA Input 3 3 5 1 Output NO
n = int(input()) y = list(map(int, input().split())) y1 = [] d = {} for i in y: if i not in d: d[i] = 1 else: d[i] += 1 d1 = sorted(d.items(), key=lambda kv: kv[1]) count = f = 0 for i in d1: if i[1] == 1: count += 1 elif i[1] >= 3 and f == 0: x1 = i[0] f = 1 if count % 2 != 0: if f == 0: print("NO") else: c = count for j in y: if d[j] == 1 and c % 2 == 0: y1.append("A") c -= 1 elif d[j] == 1 and c % 2 != 0: y1.append("B") c -= 1 elif j == x1 and f == 1: y1.append("A") f = 2 else: y1.append("B") print("YES") for i in y1: print(i, end="") else: c = count for j in y: if d[j] == 1 and c % 2 == 0: y1.append("A") c -= 1 elif d[j] == 1 and c % 2 != 0: y1.append("B") c -= 1 else: y1.append("A") print("YES") for i in y1: print(i, end="")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR VAR IF VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FOR VAR VAR IF VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Monocarp plays a computer game. There are $n$ different sets of armor and $m$ different weapons in this game. If a character equips the $i$-th set of armor and wields the $j$-th weapon, their power is usually equal to $i + j$; but some combinations of armor and weapons synergize well. Formally, there is a list of $q$ ordered pairs, and if the pair $(i, j)$ belongs to this list, the power of the character equipped with the $i$-th set of armor and wielding the $j$-th weapon is not $i + j$, but $i + j + 1$. Initially, Monocarp's character has got only the $1$-st armor set and the $1$-st weapon. Monocarp can obtain a new weapon or a new set of armor in one hour. If he wants to obtain the $k$-th armor set or the $k$-th weapon, he must possess a combination of an armor set and a weapon that gets his power to $k$ or greater. Of course, after Monocarp obtains a weapon or an armor set, he can use it to obtain new armor sets or weapons, but he can go with any of the older armor sets and/or weapons as well. Monocarp wants to obtain the $n$-th armor set and the $m$-th weapon. What is the minimum number of hours he has to spend on it? -----Input----- The first line contains two integers $n$ and $m$ ($2 \le n, m \le 2 \cdot 10^5$) β€” the number of armor sets and the number of weapons, respectively. The second line contains one integer $q$ ($0 \le q \le \min(2 \cdot 10^5, nm)$) β€” the number of combinations that synergize well. Then $q$ lines follow, the $i$-th line contains two integers $a_i$ and $b_i$ ($1 \le a_i \le n$; $1 \le b_i \le m$) meaning that the $a_i$-th armor set synergizes well with the $b_i$-th weapon. All pairs $(a_i, b_i)$ are distinct. -----Output----- Print one integer β€” the minimum number of hours Monocarp has to spend to obtain both the $n$-th armor set and the $m$-th weapon. -----Examples----- Input 3 4 0 Output 3 Input 3 4 2 1 1 1 3 Output 2 -----Note----- In the first example, Monocarp can obtain the strongest armor set and the strongest weapon as follows: Obtain the $2$-nd weapon using the $1$-st armor set and the $1$-st weapon; Obtain the $3$-rd armor set using the $1$-st armor set and the $2$-nd weapon; Obtain the $4$-th weapon using the $3$-rd armor set and the $2$-nd weapon. In the second example, Monocarp can obtain the strongest armor set and the strongest weapon as follows: Obtain the $3$-rd armor set using the $1$-st armor set and the $1$-st weapon (they synergize well, so Monocarp's power is not $2$ but $3$); Obtain the $4$-th weapon using the $3$-rd armor set and the $1$-st weapon.
def solution(): n, m = map(int, input().strip().split()) q = int(input()) a_b = set() for _ in range(q): a, b = map(int, input().strip().split()) a_b.add((a, b) if n < m else (b, a)) if n > m: n, m = m, n dp = [-1] * (n + 1) dp[1] = 1 result = 0 while dp[n] != m: new_dp = dp[:] for i in range(1, n + 1): if dp[i] == -1: continue x = i + dp[i] + ((i, dp[i]) in a_b) new_dp[i] = max(new_dp[i], min(x, m)) new_dp[min(x, n)] = max(new_dp[min(x, n)], dp[i]) dp = new_dp result += 1 return result print(solution())
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
n = int(input()) strs = ["" for x in range(n + 1)] dp = [0] * (n + 1) for i in range(1, n + 1): strs[i] = input() for i in range(1, n + 1): st = strs[i].split() dp[i] = max(dp[i], dp[i - 1]) if st[0] == "win": for j in range(i + 1, n + 1): s = strs[j].split() if s[0] == "sell" and st[1] == s[1]: dp[j] = max(dp[i - 1] + 2 ** int(st[1]), dp[j]) break print(dp[n])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
n = int(input()) s = ["" for _ in range(5005)] a = [(0) for _ in range(5005)] for i in range(1, n + 1): ta, tb = input().split() s[i] = ta a[i] = int(tb) jp = [(0) for _ in range(5005)] vis = [(0) for _ in range(5005)] dp = [(0) for _ in range(5005)] num = [(1 << _) for _ in range(2001)] for i in range(1, n + 1): if s[i][0] == "w": vis[a[i]] = i elif vis[a[i]]: jp[i] = vis[a[i]] for i in range(1, n + 1): if s[i][0] == "s": if jp[i] > 0: dp[i] = max(dp[i], dp[jp[i] - 1] + num[a[i]]) dp[i] = max(dp[i - 1], dp[i]) print(dp[n])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER STRING ASSIGN VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER STRING IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
n = int(input()) ar = [0] * (n + 1) c = [] d = [] for i in range(n): a, b = input().split() b = int(b) e = 1 if a == "sell": e = -e b = -b c.append(b) d.append(e) for i in range(1, n + 1): ar[i] = max(ar[i - 1], ar[i]) for j in range(i + 1, n + 1): if c[i - 1] + c[j - 1] == 0 and d[i - 1] == 1 and d[j - 1] == -1: ar[j] = max(ar[j], ar[i] + 2 ** c[i - 1]) print(ar[n])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
a = [-1] * 2002 a[0] = 0 for i in range(int(input())): s, t = input().split() t = int(t) + 1 if s[0] == "w": a[t] = a[0] elif a[t] >= 0: a[0] = max(a[0], a[t] + (1 << t - 1)) print(a[0])
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
n = int(input()) l = [] val = [(-1) for i in range(2002)] used = [(False) for i in range(5005)] for i in range(n): s, v = input().split() v = int(v) l.append([s, v]) if s[0] == "s": val[v] = i ans = 0 for i in range(2000, -1, -1): if val[i] == -1: continue ind = -1 for j in range(val[i], -1, -1): if used[j]: break if l[j][0][0] == "w" and l[j][1] == i: ind = j break if ind != -1: ans += pow(2, i) for j in range(ind, val[i] + 1): used[j] = True print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR IF VAR NUMBER STRING ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR IF VAR VAR NUMBER NUMBER STRING VAR VAR NUMBER VAR ASSIGN VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
d = [0] * 2001 n = int(input()) ans = 0 for i in range(0, n, 1): s, x = map(str, input().split()) x = int(x) if s == "win": d[x] = 2**x + ans if s == "sell": ans = max(ans, d[x]) print(ans)
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
n = int(input()) dp = [0] * 2020 resp = 0 for i in range(n): s = input() cmd, _x = s.split() x = int(_x) if cmd[0] == "w": dp[x] = resp + 2**x else: resp = max(dp[x], resp) print(resp)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
import sys import time dp = [0] * 5000 v = [0] * 5000 s2 = [0] * 5000 s2[0] = 1 for i in range(1, 5000, 1): s2[i] = s2[i - 1] + s2[i - 1] n = int(input()) for i in range(0, n, 1): if i - 1 >= 0: dp[i] = dp[i - 1] s, v[i] = input().split() v[i] = int(v[i]) if s == "sell": for j in reversed(range(0, i, 1)): if v[j] == v[i]: dp[i] = max(dp[i], dp[j] + s2[v[i]]) break v[i] = -1 print(dp[n - 1]) sys.stderr.write("{0:.3f} ms\n".format(time.clock() * 1000))
IMPORT IMPORT ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP FUNC_CALL VAR NUMBER
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
n = int(input()) arr = [(0) for i in range(n)] t = [(0) for i in range(n)] used = [(0) for i in range(n)] for i in range(n): s, arr[i] = input().split() arr[i] = int(arr[i]) if s == "win": t[i] = 1 else: t[i] = 0 ans = 0 for x in range(2000, -1, -1): win = -1 for i in range(n): if used[i] == 1: win = -1 if t[i] == 1 and arr[i] == x and used[i] == 0: win = i if not (used[i] == 0 and arr[i] == x and win != -1 and t[i] == 0): continue for j in range(win, i + 1): used[j] = 1 ans += 2**x break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
read = lambda: [int(i) for i in input().split()] n = int(input()) a = [0] * n for i in range(n): s, x = input().split() x = int(x) if s == "sell": a[i] = x + 1 else: a[i] = -x - 1 pos = dict() left = [-1] * n for i in range(n): if -a[i] in pos: left[i] = pos[-a[i]] pos[a[i]] = i dp = [0] * n for i in range(1, n): dp[i] = dp[i - 1] if a[i] > 0: j = left[i] if j == -1: continue dp[i] = max(dp[i], dp[j] + (1 << a[i] - 1)) print(dp[n - 1])
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
read = lambda: [int(i) for i in input().split()] n = int(input()) a = [0] * n for i in range(n): s, x = input().split() x = int(x) if s == "sell": a[i] = x + 1 else: a[i] = -x - 1 dp = [0] * n for i in range(1, n): dp[i] = dp[i - 1] if a[i] > 0: for j in range(0, i): if a[j] == -a[i]: dp[i] = max(dp[i], dp[j] + (1 << a[i] - 1)) print(dp[n - 1])
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
n = int(input()) f = [(0) for i in range(n + 1)] g = [(0) for i in range(n + 1)] for i in range(1, n + 1): s, v = input().split(" ") v = int(v) + 1 if s[0] == "w": g[i] = v else: j = i while j > 0: if g[j] == v: break j -= 1 if j > 0: v -= 1 f[i] = f[j - 1] + (1 << v) f[i] = max(f[i], f[i - 1]) print(f[n])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
def bob(): n = int(input()) ganan = [(0) for i in range(2009)] value = 0 for i in range(n): info = input().split() order = info[0] number = int(info[1]) if order == "win": ganan[number] = value + 2**number else: value = max(ganan[number], value) print(value) bob()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
n = int(input()) dp = [(0) for _ in range(n + 1)] pre = [(0) for _ in range(2001)] for i in range(1, n + 1): s = input().split() dp[i] = dp[i - 1] t = int(s[1]) if s[0][0] == "w": pre[t] = i elif pre[t]: ans = dp[pre[t]] + (1 << t) if ans > dp[i]: dp[i] = ans print(dp[n])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER STRING ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
n = int(input()) a = [input().split() for i in range(n)] b = [[x, int(y)] for x, y in a] c = [[x[1], i] for i, x in enumerate(b) if x[0] == "sell"] c.sort() c.reverse() al = [(1) for x in range(n)] sold = [] for val, p in c: pos = p - 1 if not al[p]: continue while pos > 0 and al[pos] and b[pos][1] != val: pos -= 1 if pos != -1 and b[pos][1] == val: sold.append(val) for i in range(pos, p + 1): al[i] = 0 ans = int(0) for x in sold: ans += 2**x print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR WHILE VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
dp = [-1] * 2005 ans = 0 t = int(input()) now = 0 maxx = 0 for i in range(1, t + 1): a, b = input().split(" ") x = int(b) if a == "win": dp[x] = max(dp[x], maxx) else: if dp[x] != -1: dp[2001] = max(dp[2001], dp[x] + pow(2, x)) maxx = max(maxx, dp[2001]) ans = 0 for i in range(2005): ans = max(dp[i], ans) print(ans)
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
n = int(input()) a = [[] for x in range(2005)] dp = [(0) for x in range(n)] for i in range(n): s = input().split() x = int(s[1]) if s[0] == "win": a[x].append(i) if i != 0: dp[i] = dp[i - 1] elif len(a[x]) > 0: dp[i] = dp[i - 1] for el in a[x]: dp[i] = max(dp[i], dp[el] + 2**x) elif i != 0: dp[i] = dp[i - 1] print(dp[n - 1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
N = int(input()) maxval = 0 dp = [0] * N prev = [-1] * 2010 for i in range(N): l = input().strip().split() l[1] = int(l[1]) if l[0] == "win": prev[l[1]] = i elif l[0] == "sell" and prev[l[1]] != -1: maxval = max(maxval, 2 ** l[1] + dp[prev[l[1]]]) dp[i] = maxval print(maxval)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR VAR NUMBER VAR IF VAR NUMBER STRING VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
n = int(input()) data = [input().split() for _ in range(n)] data = [(event, int(x)) for event, x in data] max_earn = [0] * n sell_position = {} if data[-1][0] == "sell": sell_position[data[-1][1]] = n - 1 for i in range(n - 2, -1, -1): if data[i][0] == "sell": sell_position[data[i][1]] = i max_earn[i] = max_earn[i + 1] elif data[i][1] in sell_position: max_earn[i] = max( max_earn[i + 1], 2 ** data[i][1] + max_earn[sell_position[data[i][1]]] ) else: max_earn[i] = max_earn[i + 1] print(max_earn[0])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT IF VAR NUMBER NUMBER STRING ASSIGN VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER STRING ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
N = int(input()) winsell = N * [0] pow = 2001 * [-1] ans = 0 for i in range(0, N): s, x = input().split() x = int(x) if s == "win": winsell[i] = x else: pow[x] = i winsell[i] = -x for i in range(2000, -1, -1): if pow[i] > 0: b = 0 for j in range(pow[i] - 1, -1, -1): if winsell[j] != 2001: if winsell[j] == i: b = 1 ans += 2**i for k in range(j, pow[i] + 1): winsell[k] = 2001 else: b = 1 if b == 1: break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR LIST NUMBER ASSIGN VAR BIN_OP NUMBER LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
max_x = 2001 n = int(input()) income = [0] * n win = {} for i in range(n): s, a = input().split() a = int(a) if i > 0: income[i] = income[i - 1] if s[0] == "w": win[a] = i elif win.get(a) != None: income[i] = max(income[i], income[win.get(a)] + 2**a) print(income[n - 1])
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
def solve(): n = int(input()) w = "win" t = "sell" a = [-1] * 5005 myindex = [-1] * 5005 for i in range(0, n): s, v = input().strip().split() if s == w: a[i] = int(v) elif s == t: myindex[int(v)] = i value = [0] * 5005 j = myindex[a[0]] if a[0] != -1 and j != -1: value[j] = 1 << a[0] themax = 0 for i in range(1, n): if a[i] != -1: index = myindex[a[i]] if index != -1 and index > i: v = themax + (1 << a[i]) if v > value[index]: value[index] = v themax = max(themax, value[i]) print(themax) solve()
FUNC_DEF 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 FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
n = int(input()) k = [] p = [-1] * 5000 dp = [0] * (n + 1) for i in range(1, n + 1): k = input().split() if k[0] == "win": p[int(k[1])] = i dp[i] = dp[i - 1] continue if k[0] == "sell": dp[i] = dp[i - 1] if p[int(k[1])] != -1: dp[i] = max(dp[i - 1], dp[p[int(k[1])]] + 2 ** int(k[1])) print(dp[n])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
n = int(input()) N = 2002 zero = N - 1 d = [-1] * N d[zero] = 0 for i in range(n): option, value = list(input().split()) value = int(value) if option[0] == "w": d[value] = max(d[value], d[zero]) elif d[value] != -1: d[zero] = max(d[zero], d[value] + 2**value) print(d[zero])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
n = int(input()) w = [(-1) for i in range(n)] s = [(-1) for i in range(n)] sold = [(False) for i in range(n)] s_ind = {} for i in range(n): act, x = input().split() if act == "win": w[i] = int(x) else: s[i] = int(x) s_ind[int(x)] = i ans = 0 for x in range(2000, -1, -1): if x in s_ind: for j in range(s_ind[x], -1, -1): if w[j] == x: for k in range(j, s_ind[x] + 1): sold[k] = True ans |= 1 << x break elif sold[j]: break print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
n = int(input()) a = [] for i in range(n): b = input().split() a.append(b) d = [(0) for i in range(n)] c = 0 for i in range(1, n): if "win" in a[i]: d[i] = c else: for j in range(i - 1, -1, -1): if "win" in a[j] and a[j][1] == a[i][1]: d[i] = max(c, d[j] + 2 ** int(a[i][1])) c = max(d[i], c) break else: d[i] = c print(d[n - 1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF STRING VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF STRING VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
n = int(input()) dp_things = [0] * n dp_price = [0] * n for i in range(n): if i > 0: dp_price[i] = dp_price[i - 1] s, num = input().split() num = pow(2, int(num)) if s == "win": dp_things[i] = num if s == "sell": for j in range(i): if dp_things[j] == num and dp_price[j] + num > dp_price[i]: dp_price[i] = dp_price[j] + num print(dp_price[n - 1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR VAR IF VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
dp = [(0) for i in range(2005)] n = input() n = int(n) ans = 0 for i in range(n): inp = input().split() num = int(inp[1]) if inp[0] == "win": dp[num] = 2**num + ans else: ans = max(ans, dp[num]) print(ans)
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
INF = int(1000000000.0) req = [] xs = [[] for i in range(2017)] seen = [0] * 5040 m = int(input()) n = 0 for i in range(m): s, x = input().split() x = int(x) if s == "win": xs[x].append(i) else: max_first = 0 if len(xs[x]): for j in range(len(xs[x])): max_first = max(max_first, xs[x][j]) req.append((xs[x][j], i, x)) n += 1 def cmp(r): return -r[2] req.sort(key=cmp) ans = 0 for i in range(n): compatible = 1 for j in range(req[i][0], req[i][1] + 1): if seen[j]: compatible = 0 break if compatible: ans += 2 ** req[i][2] for j in range(req[i][0], req[i][1] + 1): seen[j] = 1 print(ans)
ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER FUNC_DEF RETURN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. * Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. Input The first input line contains number n (1 ≀ n ≀ 5000) β€” amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≀ x ≀ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≀ x ≀ 2000). Output Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Examples Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Output 1056 Input 3 win 5 sell 6 sell 4 Output 0
def intercept(x, y, a, b): return not (y < a or x > b) n = int(input()) day = [] intervalo = [] valor = [] for i in range(n): line = input() line = line.split(" ") act = line[0] val = int(line[1]) day.append(val) if act == "win": continue for j in range(i): if day[j] == val: intervalo.append([j, i]) valor.append([val, len(intervalo) - 1]) valor.sort() ans = 0 used = list(range(len(intervalo) + 1)) for i in range(len(used)): used[i] = False for i in range(len(valor) - 1, -1, -1): ind = valor[i][1] x1 = intervalo[ind][0] y1 = intervalo[ind][1] pos = True for j in range(0, len(intervalo)): if j == ind: continue if used[j] and intercept(x1, y1, intervalo[j][0], intervalo[j][1]): pos = False if pos: ans += 2 ** valor[i][0] used[ind] = True print(ans)
FUNC_DEF RETURN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR