message
stringlengths
2
43.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
853
107k
cluster
float64
24
24
__index_level_0__
int64
1.71k
214k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has a sequence, consisting of n non-negative integers: a1, a2, ..., an. Let's define function f(l, r) (l, r are integer, 1 ≀ l ≀ r ≀ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = al | al + 1 | ... | ar. Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r (l, r are integer, 1 ≀ l ≀ r ≀ n). Now he wants to know, how many distinct values he's got in the end. Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a. Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "|", in Pascal β€” as "or". Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of elements of sequence a. The second line contains n space-separated integers a1, a2, ..., an (0 ≀ ai ≀ 106) β€” the elements of sequence a. Output Print a single integer β€” the number of distinct values of function f(l, r) for the given sequence a. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier. Examples Input 3 1 2 0 Output 4 Input 10 1 2 3 4 5 6 1 2 9 10 Output 11 Note In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3. Submitted Solution: ``` n = input() arr = list(map(int, input().split())) res = set() temp = set() for i in arr: temp = {i|j for j in temp} temp.add(i) res.update(temp) print(len(res)) ```
instruction
0
10,270
24
20,540
Yes
output
1
10,270
24
20,541
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has a sequence, consisting of n non-negative integers: a1, a2, ..., an. Let's define function f(l, r) (l, r are integer, 1 ≀ l ≀ r ≀ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = al | al + 1 | ... | ar. Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r (l, r are integer, 1 ≀ l ≀ r ≀ n). Now he wants to know, how many distinct values he's got in the end. Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a. Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "|", in Pascal β€” as "or". Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of elements of sequence a. The second line contains n space-separated integers a1, a2, ..., an (0 ≀ ai ≀ 106) β€” the elements of sequence a. Output Print a single integer β€” the number of distinct values of function f(l, r) for the given sequence a. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier. Examples Input 3 1 2 0 Output 4 Input 10 1 2 3 4 5 6 1 2 9 10 Output 11 Note In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3. Submitted Solution: ``` input() a, b = set(), set() for i in map(int, input().split()): a = {i | j for j in a} a.add(i) b.update(a) print(len(b)) ```
instruction
0
10,271
24
20,542
Yes
output
1
10,271
24
20,543
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has a sequence, consisting of n non-negative integers: a1, a2, ..., an. Let's define function f(l, r) (l, r are integer, 1 ≀ l ≀ r ≀ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = al | al + 1 | ... | ar. Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r (l, r are integer, 1 ≀ l ≀ r ≀ n). Now he wants to know, how many distinct values he's got in the end. Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a. Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "|", in Pascal β€” as "or". Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of elements of sequence a. The second line contains n space-separated integers a1, a2, ..., an (0 ≀ ai ≀ 106) β€” the elements of sequence a. Output Print a single integer β€” the number of distinct values of function f(l, r) for the given sequence a. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier. Examples Input 3 1 2 0 Output 4 Input 10 1 2 3 4 5 6 1 2 9 10 Output 11 Note In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) s1=set() s2=set() for i in a: print(s1) s1={i|j for j in s1} s1.add(i) s2.update(s1) print(len(s2)) ```
instruction
0
10,272
24
20,544
No
output
1
10,272
24
20,545
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has a sequence, consisting of n non-negative integers: a1, a2, ..., an. Let's define function f(l, r) (l, r are integer, 1 ≀ l ≀ r ≀ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = al | al + 1 | ... | ar. Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r (l, r are integer, 1 ≀ l ≀ r ≀ n). Now he wants to know, how many distinct values he's got in the end. Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a. Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "|", in Pascal β€” as "or". Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of elements of sequence a. The second line contains n space-separated integers a1, a2, ..., an (0 ≀ ai ≀ 106) β€” the elements of sequence a. Output Print a single integer β€” the number of distinct values of function f(l, r) for the given sequence a. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier. Examples Input 3 1 2 0 Output 4 Input 10 1 2 3 4 5 6 1 2 9 10 Output 11 Note In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3. Submitted Solution: ``` import itertools a = [int(x) for x in input().split()] s = set([]) for i, val in enumerate(a): for j in range(i, len(a)): tmp = a[i] for k in range(i+1, j+1): tmp |= a[k] s.add(tmp) print(len(s)) ```
instruction
0
10,273
24
20,546
No
output
1
10,273
24
20,547
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has a sequence, consisting of n non-negative integers: a1, a2, ..., an. Let's define function f(l, r) (l, r are integer, 1 ≀ l ≀ r ≀ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = al | al + 1 | ... | ar. Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r (l, r are integer, 1 ≀ l ≀ r ≀ n). Now he wants to know, how many distinct values he's got in the end. Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a. Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "|", in Pascal β€” as "or". Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of elements of sequence a. The second line contains n space-separated integers a1, a2, ..., an (0 ≀ ai ≀ 106) β€” the elements of sequence a. Output Print a single integer β€” the number of distinct values of function f(l, r) for the given sequence a. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier. Examples Input 3 1 2 0 Output 4 Input 10 1 2 3 4 5 6 1 2 9 10 Output 11 Note In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) s=set() b=[] for i in range(1,n+1): for j in range(i,n+1): b.append([a[i-1],a[j-1]]) s=set(list(map(lambda x: x[0]|x[1],b ))) print(len(s)) ```
instruction
0
10,274
24
20,548
No
output
1
10,274
24
20,549
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has a sequence, consisting of n non-negative integers: a1, a2, ..., an. Let's define function f(l, r) (l, r are integer, 1 ≀ l ≀ r ≀ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = al | al + 1 | ... | ar. Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r (l, r are integer, 1 ≀ l ≀ r ≀ n). Now he wants to know, how many distinct values he's got in the end. Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a. Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "|", in Pascal β€” as "or". Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of elements of sequence a. The second line contains n space-separated integers a1, a2, ..., an (0 ≀ ai ≀ 106) β€” the elements of sequence a. Output Print a single integer β€” the number of distinct values of function f(l, r) for the given sequence a. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier. Examples Input 3 1 2 0 Output 4 Input 10 1 2 3 4 5 6 1 2 9 10 Output 11 Note In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3. Submitted Solution: ``` c = 0 n = int(input()) *a, = map(int, input().split()) s = set(a) for i in a: c = i for j in a: c |= j s.add(c) print(len(s)) ```
instruction
0
10,275
24
20,550
No
output
1
10,275
24
20,551
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. Input The first line contains integer n (1 ≀ n ≀ 103) β€” the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≀ idi ≀ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way. Output Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Examples Input 6 0 1 7 1 7 10 Output 2 Input 3 1 1 1 Output -1 Input 1 0 Output 0 Note In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed.
instruction
0
10,276
24
20,552
Tags: *special, implementation, sortings Correct Solution: ``` n = int(input()) l = list(map(int,input().split())) l.sort() r = 0 bad = False for i in range(n-1): if l[i] == 0 : continue if l[i] == l[i+1]: r += 1 if i < n-2 and l[i+2] == l[i]: print(-1) bad = True break if not bad : print(r) ```
output
1
10,276
24
20,553
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. Input The first line contains integer n (1 ≀ n ≀ 103) β€” the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≀ idi ≀ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way. Output Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Examples Input 6 0 1 7 1 7 10 Output 2 Input 3 1 1 1 Output -1 Input 1 0 Output 0 Note In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed.
instruction
0
10,277
24
20,554
Tags: *special, implementation, sortings Correct Solution: ``` n = map(int, input().split()) a = list(map(int, input().split())) b = set(a)-{0} result = 0 for i in b: if a.count(i)>2: print(-1) exit(0) elif a.count(i)==2: result+=1 print(result) ```
output
1
10,277
24
20,555
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. Input The first line contains integer n (1 ≀ n ≀ 103) β€” the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≀ idi ≀ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way. Output Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Examples Input 6 0 1 7 1 7 10 Output 2 Input 3 1 1 1 Output -1 Input 1 0 Output 0 Note In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed.
instruction
0
10,278
24
20,556
Tags: *special, implementation, sortings Correct Solution: ``` def shellSort(arr): gap = n//2 while gap > 0: for i in range(gap,n): temp = arr[i] j = i while j >= gap and arr[j-gap] >temp: arr[j] = arr[j-gap] j -= gap arr[j] = temp gap //= 2 n = int(input()) arr = [int(x) for x in input().split()] shellSort(arr) ans = 0 if n == 1: print(0) quit() else: for i in range(n-2): if arr[i] == 0: continue if arr[i] == arr[i+1]: if arr[i+1] == arr[i+2]: ans = -1 break else: ans += 1 if ans == -1: print(ans) else: print(ans if arr[n-2] != arr[n-1] or arr[n-2] == 0 else ans+1) ```
output
1
10,278
24
20,557
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. Input The first line contains integer n (1 ≀ n ≀ 103) β€” the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≀ idi ≀ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way. Output Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Examples Input 6 0 1 7 1 7 10 Output 2 Input 3 1 1 1 Output -1 Input 1 0 Output 0 Note In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed.
instruction
0
10,279
24
20,558
Tags: *special, implementation, sortings Correct Solution: ``` from collections import Counter N, Answer = int(input()), 0 X = Counter(list(map(int, input().split()))) for key in X: if key != 0: if X[key] == 2: Answer += 1 elif X[key] > 2: print(-1) exit() print(Answer) # Hope the best for Ravens # Never give up ```
output
1
10,279
24
20,559
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. Input The first line contains integer n (1 ≀ n ≀ 103) β€” the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≀ idi ≀ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way. Output Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Examples Input 6 0 1 7 1 7 10 Output 2 Input 3 1 1 1 Output -1 Input 1 0 Output 0 Note In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed.
instruction
0
10,280
24
20,560
Tags: *special, implementation, sortings Correct Solution: ``` from collections import * from sys import * input=stdin.readline n=int(input()) ll=list(map(int,input().split())) l = [i for i in ll if i!=0] c=Counter(l) cc=0 d=list(c.values()) for i in d: if(i==2): cc=cc+1 elif(i>2): cc=-1 break print(cc) ```
output
1
10,280
24
20,561
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. Input The first line contains integer n (1 ≀ n ≀ 103) β€” the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≀ idi ≀ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way. Output Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Examples Input 6 0 1 7 1 7 10 Output 2 Input 3 1 1 1 Output -1 Input 1 0 Output 0 Note In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed.
instruction
0
10,281
24
20,562
Tags: *special, implementation, sortings Correct Solution: ``` def solve(): n = int(input()) id = list(map(int, input().split())) duplicate_id = set() unique_id = set() score = 0 for i in range(len(id)): if id[i] != 0 and id[i] not in duplicate_id: if id[i] not in unique_id: unique_id.add(id[i]) else: duplicate_id.add(id[i]) score+=1 elif id[i] == 0: pass else: return -1 return score print(solve()) ```
output
1
10,281
24
20,563
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. Input The first line contains integer n (1 ≀ n ≀ 103) β€” the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≀ idi ≀ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way. Output Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Examples Input 6 0 1 7 1 7 10 Output 2 Input 3 1 1 1 Output -1 Input 1 0 Output 0 Note In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed.
instruction
0
10,282
24
20,564
Tags: *special, implementation, sortings Correct Solution: ``` n = int(input()) id = sorted(list(map(int, input().split()))) prev = -1 count = 1 output = 0 for i in id[id.count(0):]: if i == 0: continue if prev == i: count += 1 else: count = 1 if count == 2: output += 1 elif count >= 3: output = -1 break prev = i print(output) ```
output
1
10,282
24
20,565
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. Input The first line contains integer n (1 ≀ n ≀ 103) β€” the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≀ idi ≀ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way. Output Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Examples Input 6 0 1 7 1 7 10 Output 2 Input 3 1 1 1 Output -1 Input 1 0 Output 0 Note In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed.
instruction
0
10,283
24
20,566
Tags: *special, implementation, sortings Correct Solution: ``` def cycleSort(array): writes = 0 for cycleStart in range(0, len(array) - 1): item = array[cycleStart] pos = cycleStart for i in range(cycleStart + 1, len(array)): if array[i] < item: pos += 1 if pos == cycleStart: continue while item == array[pos]: pos += 1 array[pos], item = item, array[pos] writes += 1 while pos != cycleStart: pos = cycleStart for i in range(cycleStart + 1, len(array)): if array[i] < item: pos += 1 while item == array[pos]: pos += 1 array[pos], item = item, array[pos] writes += 1 return writes n = int(input()) x = list(map(int, input().split())) answer = 0 cycleSort(x) for i in range(len(x) - 1): if (i + 2) >= n: if (x[i] == x[i + 1]) and (x[i] != 0): answer = answer + 1 i = i + 1 else: if x[i] == x[i + 1] and x[i] != 0 and x[i] != x[i + 2]: answer = answer + 1 i = i + 1 elif x[i] == x[i + 1] and x[i] != 0 and x[i] != 0: answer = -1 break print(answer) ```
output
1
10,283
24
20,567
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. Input The first line contains integer n (1 ≀ n ≀ 103) β€” the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≀ idi ≀ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way. Output Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Examples Input 6 0 1 7 1 7 10 Output 2 Input 3 1 1 1 Output -1 Input 1 0 Output 0 Note In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed. Submitted Solution: ``` # import sys # sys.stdin = open("test.in","r") # sys.stdout = open("test.out.py","w") n=int(input()) a=list(map(int,input().split())) c=0 b=list(set(a)) for i in b: d=a.count(i) if i==0: pass elif d==2: c+=1 elif d>=3: print('-1') exit() print(c) ```
instruction
0
10,284
24
20,568
Yes
output
1
10,284
24
20,569
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. Input The first line contains integer n (1 ≀ n ≀ 103) β€” the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≀ idi ≀ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way. Output Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Examples Input 6 0 1 7 1 7 10 Output 2 Input 3 1 1 1 Output -1 Input 1 0 Output 0 Note In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed. Submitted Solution: ``` n=int(input()) l=list(map(int,input().split(' '))) dict={} cnt=0 for i in l: if i==0 : continue if i in dict : if dict[i]==2 : cnt=-1 break dict[i]+=1 cnt+=1 else: dict[i]=1 print(cnt) ```
instruction
0
10,285
24
20,570
Yes
output
1
10,285
24
20,571
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. Input The first line contains integer n (1 ≀ n ≀ 103) β€” the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≀ idi ≀ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way. Output Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Examples Input 6 0 1 7 1 7 10 Output 2 Input 3 1 1 1 Output -1 Input 1 0 Output 0 Note In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed. Submitted Solution: ``` def cocktail_sort(a): n = len(a) swapped = True start = 0 end = n-1 while (swapped == True): swapped = False for i in range (start, end): if (a[i] > a[i + 1]) : a[i], a[i + 1]= a[i + 1], a[i] swapped = True if (swapped == False): break swapped = False end = end-1 for i in range(end-1, start-1, -1): if (a[i] > a[i + 1]): a[i], a[i + 1] = a[i + 1], a[i] swapped = True start = start + 1 n = int(input()) x = list(map(int, input().split())) ans = 0 cocktail_sort(x) for i in range(len(x) - 1): if (i + 2) >= n: if (x[i] == x[i + 1]) and (x[i] != 0): ans = ans + 1 i = i + 1 else: if x[i] == x[i + 1] and x[i] != 0 and x[i] != x[i + 2]: ans = ans + 1 i = i + 1 elif x[i] == x[i + 1] and x[i] != 0 and x[i] != 0: ans = -1 break print(ans) ```
instruction
0
10,286
24
20,572
Yes
output
1
10,286
24
20,573
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. Input The first line contains integer n (1 ≀ n ≀ 103) β€” the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≀ idi ≀ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way. Output Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Examples Input 6 0 1 7 1 7 10 Output 2 Input 3 1 1 1 Output -1 Input 1 0 Output 0 Note In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed. Submitted Solution: ``` n=int(input()) s=(list(map(int,input().split()))) pair=0 freq={} for item in s: if item in freq: freq[item]=freq[item] + 1 else: freq[item] = 1 for key,value in freq.items(): #print ("% d : % d"%(key, value)) if key>0 and value==2: pair = pair + (value//2) elif key>0 and value>2: pair = -1 break; print(pair) ```
instruction
0
10,287
24
20,574
Yes
output
1
10,287
24
20,575
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. Input The first line contains integer n (1 ≀ n ≀ 103) β€” the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≀ idi ≀ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way. Output Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Examples Input 6 0 1 7 1 7 10 Output 2 Input 3 1 1 1 Output -1 Input 1 0 Output 0 Note In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed. Submitted Solution: ``` def shellSort(arr): gap = n//2 while gap > 0: for i in range(gap,n): temp = arr[i] j = i while j >= gap and arr[j-gap] >temp: arr[j] = arr[j-gap] j -= gap arr[j] = temp gap //= 2 n = int(input()) arr = [int(x) for x in input().split()] shellSort(arr) ans = 0 if n == 1: print(0) quit() else: for i in range(n-2): if arr[i] == arr[i+1]: if arr[i+1] == arr[i+2]: ans = -1 break else: ans += 1 if ans == -1: print(ans) else: print(ans if arr[n-2] != arr[n-1] else ans+1) ```
instruction
0
10,288
24
20,576
No
output
1
10,288
24
20,577
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. Input The first line contains integer n (1 ≀ n ≀ 103) β€” the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≀ idi ≀ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way. Output Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Examples Input 6 0 1 7 1 7 10 Output 2 Input 3 1 1 1 Output -1 Input 1 0 Output 0 Note In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed. Submitted Solution: ``` input() a,i,c=list(map(int,input().split())),0,0 a.sort() while i<len(a): j=a.count(a[i]) if j==2: c+=1 elif j>2: c=-1 break i+=j print(c) ```
instruction
0
10,289
24
20,578
No
output
1
10,289
24
20,579
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. Input The first line contains integer n (1 ≀ n ≀ 103) β€” the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≀ idi ≀ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way. Output Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Examples Input 6 0 1 7 1 7 10 Output 2 Input 3 1 1 1 Output -1 Input 1 0 Output 0 Note In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed. Submitted Solution: ``` n=int(input()) l=list(map(int,input().split(' '))) dict={} cnt=0 for i in l: if i in dict : if dict[i]==2 : cnt=-1 break dict[i]+=1 cnt+=1 else: dict[i]=1 print(cnt) ```
instruction
0
10,290
24
20,580
No
output
1
10,290
24
20,581
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. Input The first line contains integer n (1 ≀ n ≀ 103) β€” the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≀ idi ≀ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way. Output Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Examples Input 6 0 1 7 1 7 10 Output 2 Input 3 1 1 1 Output -1 Input 1 0 Output 0 Note In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5. In the second test sample the described situation is impossible as conferences aren't allowed. Submitted Solution: ``` n=int(input()) a=input().split() k=0 for i in set(a): if a.count(i)==2 and i!='0':k+=1 elif a.count(i)>2:print(-1);quit() print(k) ```
instruction
0
10,291
24
20,582
No
output
1
10,291
24
20,583
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Innocentius has a problem β€” his computer monitor has broken. Now some of the pixels are "dead", that is, they are always black. As consequence, Innocentius can't play the usual computer games. He is recently playing the following game with his younger brother Polycarpus. Innocentius is touch-typing a program that paints a white square one-pixel wide frame on the black screen. As the monitor is broken, some pixels that should be white remain black. Polycarpus should look at what the program displayed on the screen and guess the position and size of the frame Innocentius has painted. Polycarpus doesn't like the game but Innocentius persuaded brother to play as "the game is good for the imagination and attention". Help Polycarpus, automatize his part in the gaming process. Write the code that finds such possible square frame that: * the frame's width is 1 pixel, * the frame doesn't go beyond the borders of the screen, * all white pixels of the monitor are located on the frame, * of all frames that satisfy the previous three conditions, the required frame must have the smallest size. Formally, a square frame is represented by such pixels of the solid square, that are on the square's border, that is, are not fully surrounded by the other pixels of the square. For example, if the frame's size is d = 3, then it consists of 8 pixels, if its size is d = 2, then it contains 4 pixels and if d = 1, then the frame is reduced to a single pixel. Input The first line contains the resolution of the monitor as a pair of integers n, m (1 ≀ n, m ≀ 2000). The next n lines contain exactly m characters each β€” the state of the monitor pixels at the moment of the game. Character "." (period, ASCII code 46) corresponds to the black pixel, and character "w" (lowercase English letter w) corresponds to the white pixel. It is guaranteed that at least one pixel of the monitor is white. Output Print the monitor screen. Represent the sought frame by characters "+" (the "plus" character). The pixels that has become white during the game mustn't be changed. Print them as "w". If there are multiple possible ways to position the frame of the minimum size, print any of them. If the required frame doesn't exist, then print a single line containing number -1. Examples Input 4 8 ..w..w.. ........ ........ ..w..w.. Output ..w++w.. ..+..+.. ..+..+.. ..w++w.. Input 5 6 ...... .w.... ...... ..w... ...... Output ...... +w+... +.+... ++w... ...... Input 2 4 .... .w.. Output .... .w.. Input 2 6 w..w.w ...w.. Output -1 Note In the first sample the required size of the optimal frame equals 4. In the second sample the size of the optimal frame equals 3. In the third sample, the size of the optimal frame is 1. In the fourth sample, the required frame doesn't exist. Submitted Solution: ``` from itertools import chain def draw_square(scr, square_a, ymin, xmin): for i in range(square_a + 1): if scr[ymin][xmin + i] != 'w': scr[ymin] = scr[ymin][:xmin + i] + '+' + scr[ymin][xmin + i + 1:] if scr[ymin + square_a][xmin + i] != 'w': scr[ymin + square_a] = scr[ymin + square_a][:xmin + i] + '+' + scr[ymin + square_a][xmin + i + 1:] if scr[ymin + i][xmin] != 'w': scr[ymin + i] = scr[ymin + i][:xmin] + '+' + scr[ymin + i][xmin + 1:] if scr[ymin + i][xmin + square_a] != 'w': scr[ymin + i] = scr[ymin + i][:xmin + square_a] + '+' + scr[ymin + i][xmin + square_a + 1:] return scr def find_a(pixel, y, x): ymax = xmax = 0 ymin = y xmin = x ymaxl = [] yminl = [] xmaxl = [] xminl = [] count_pixel = len(pixel) // 2 for i in range(count_pixel): if ymax < pixel[2 * i]: ymax = pixel[2 * i] if ymin > pixel[2 * i]: ymin = pixel[2 * i] if xmax < pixel[2 * i + 1]: xmax = pixel[2 * i + 1] if xmin > pixel[2 * i + 1]: xmin = pixel[2 * i + 1] for i in range(count_pixel): f = True if pixel[2 * i] == ymax: f = False ymaxl.append(pixel[2 * i]) ymaxl.append(pixel[2 * i + 1]) if pixel[2 * i] == ymin: f = False yminl.append(pixel[2 * i]) yminl.append(pixel[2 * i + 1]) if pixel[2 * i + 1] == xmax: f = False xmaxl.append(pixel[2 * i]) xmaxl.append(pixel[2 * i + 1]) if pixel[2 * i + 1] == xmin: f = False xminl.append(pixel[2 * i]) xminl.append(pixel[2 * i + 1]) if f: print('-1') exit() return ymax, ymin, xmax, xmin, ymaxl, yminl, xmaxl, xminl def main(): y, x = map(int, input().split()) scr = [] for i in range(y): scr.append(input()) pixel = [] for i in range(y): for j in range(x): if scr[i][j] == 'w': pixel.append(i) pixel.append(j) ymax, ymin, xmax, xmin, ymaxl, yminl, xmaxl, xminl = find_a(pixel, y, x) count_ymax = len(ymaxl) / 2 count_ymin = len(yminl) / 2 count_xmax = len(xmaxl) / 2 count_xmin = len(xminl) / 2 countx_ymax = ymaxl[1::2].count(xmax) + ymaxl[1::2].count(xmin) countx_ymin = yminl[1::2].count(xmax) + yminl[1::2].count(xmin) county_xmax = xmaxl[::2].count(ymax) + xmaxl[::2].count(ymin) county_xmin = xminl[::2].count(ymax) + xminl[::2].count(ymin) #print('ymax:%d,ymin:%d,xmax:%d,xmin:%d'%(ymax,ymin,xmax,xmin)) if ymax - ymin > xmax - xmin: square_a = ymax - ymin if county_xmax < count_xmax and county_xmin < count_xmin: print('-1') exit() elif county_xmax < count_xmax and county_xmin == count_xmin: xmin = xmax - square_a if xmin < 0: print('-1') exit() elif county_xmax == count_xmax and county_xmin < count_xmin: xmax = xmin + square_a if xmax >= x: print('-1') exit() elif county_xmax == count_xmax and county_xmin == count_xmin: if square_a < x: if xmin + square_a < x: xmax = xmin + square_a elif xmax - square_a >= 0: xmin = xmax - square_a else: xmin = 0 xmax = xmin + square_a else: print('-1') exit() elif ymax - ymin < xmax - xmin: square_a = xmax - xmin if countx_ymax < count_ymax and countx_ymin < count_ymin: print('-1') exit() elif countx_ymax < count_ymax and countx_ymin == count_ymin: ymin = ymax - square_a if ymin < 0: print('-1') exit() elif countx_ymax == count_ymax and countx_ymin < count_ymin: ymax = ymin + square_a if ymax >= y: print('-1') exit() elif countx_ymax == count_ymax and countx_ymin == count_ymin: if square_a < y: if ymin + square_a < y: ymax = ymin + square_a elif ymax - square_a >= 0: ymin = ymax -square_a else: ymin = 0 ymax = ymin + square_a else: print('-1') exit() elif ymax - ymin == xmax - xmin: square_a = xmax - xmin #print('ymax:%d,ymin:%d,xmax:%d,xmin:%d,a:%d'%(ymax,ymin,xmax,xmin,square_a)) scr = draw_square(scr, square_a, ymin, xmin) for i in range(y): print(scr[i]) if __name__ == '__main__': main() ```
instruction
0
11,106
24
22,212
No
output
1
11,106
24
22,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Innocentius has a problem β€” his computer monitor has broken. Now some of the pixels are "dead", that is, they are always black. As consequence, Innocentius can't play the usual computer games. He is recently playing the following game with his younger brother Polycarpus. Innocentius is touch-typing a program that paints a white square one-pixel wide frame on the black screen. As the monitor is broken, some pixels that should be white remain black. Polycarpus should look at what the program displayed on the screen and guess the position and size of the frame Innocentius has painted. Polycarpus doesn't like the game but Innocentius persuaded brother to play as "the game is good for the imagination and attention". Help Polycarpus, automatize his part in the gaming process. Write the code that finds such possible square frame that: * the frame's width is 1 pixel, * the frame doesn't go beyond the borders of the screen, * all white pixels of the monitor are located on the frame, * of all frames that satisfy the previous three conditions, the required frame must have the smallest size. Formally, a square frame is represented by such pixels of the solid square, that are on the square's border, that is, are not fully surrounded by the other pixels of the square. For example, if the frame's size is d = 3, then it consists of 8 pixels, if its size is d = 2, then it contains 4 pixels and if d = 1, then the frame is reduced to a single pixel. Input The first line contains the resolution of the monitor as a pair of integers n, m (1 ≀ n, m ≀ 2000). The next n lines contain exactly m characters each β€” the state of the monitor pixels at the moment of the game. Character "." (period, ASCII code 46) corresponds to the black pixel, and character "w" (lowercase English letter w) corresponds to the white pixel. It is guaranteed that at least one pixel of the monitor is white. Output Print the monitor screen. Represent the sought frame by characters "+" (the "plus" character). The pixels that has become white during the game mustn't be changed. Print them as "w". If there are multiple possible ways to position the frame of the minimum size, print any of them. If the required frame doesn't exist, then print a single line containing number -1. Examples Input 4 8 ..w..w.. ........ ........ ..w..w.. Output ..w++w.. ..+..+.. ..+..+.. ..w++w.. Input 5 6 ...... .w.... ...... ..w... ...... Output ...... +w+... +.+... ++w... ...... Input 2 4 .... .w.. Output .... .w.. Input 2 6 w..w.w ...w.. Output -1 Note In the first sample the required size of the optimal frame equals 4. In the second sample the size of the optimal frame equals 3. In the third sample, the size of the optimal frame is 1. In the fourth sample, the required frame doesn't exist. Submitted Solution: ``` #!/usr/bin/python3 def readln(): return list(map(int, input().split())) import sys def exit(): print(-1) sys.exit() n, m = readln() mon = [list(input()) for _ in range(n)] hor = [i for i in range(n) if mon[i] != ['.'] * m] rmon = list(zip(*mon)) ver = [j for j in range(m) if rmon[j] != ('.',) * n] mini = hor[0] maxi = hor[-1] minj = ver[0] maxj = ver[-1] cnt_in = len([1 for i in range(mini + 1, maxi) for j in range(minj + 1, maxj) if mon[i][j] == 'w']) cnt_l = len([1 for i in range(mini + 1, maxi) if mon[i][minj] == 'w']) cnt_r = len([1 for i in range(mini + 1, maxi) if mon[i][maxj] == 'w']) cnt_d = len([1 for j in range(minj + 1, maxj) if mon[mini][j] == 'w']) cnt_u = len([1 for j in range(minj + 1, maxj) if mon[maxi][j] == 'w']) if cnt_in: exit() if maxi - mini < maxj - minj: k = maxj - minj + 1 if maxi == mini and cnt_d: if mini >= k - 1: mini -= k - 1 elif maxi + k - 1 < n: maxi += k - 1 else: exit() else: if not cnt_d: mini = max(0, mini - k + 1) if maxi - maxi + 1 != k and not cnt_u: maxi = min(mini + k - 1, n - 1) if maxi - mini + 1 != k: exit() else: k = maxi - mini + 1 if maxj == minj and cnt_l: if minj >= k - 1: minj -= k - 1 elif maxj + k - 1 < m: maxj += k - 1 else: exit() else: if not cnt_l: minj = max(0, maxj - k + 1) if maxj - minj + 1 != k and not cnt_r: maxj = min(minj + k - 1, m - 1) if maxj - minj + 1 != k: exit() for i in range(mini, maxi + 1): if mon[i][minj] == '.': mon[i][minj] = '+' for i in range(mini, maxi + 1): if mon[i][maxj] == '.': mon[i][maxj] = '+' for j in range(minj, maxj + 1): if mon[mini][j] == '.': mon[mini][j] = '+' for j in range(minj, maxj + 1): if mon[maxi][j] == '.': mon[maxi][j] = '+' print('\n'.join([''.join(row) for row in mon])) ```
instruction
0
11,107
24
22,214
No
output
1
11,107
24
22,215
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has a computer with n processors. Also, his computer has n memory cells. We'll consider the processors numbered by integers from 1 to n and that the memory cells are consecutively numbered by integers from 1 to n. Polycarpus needs to come up with a parallel program model. For each memory cell number i this program must record the value n - i to this cell. In other words, for each cell you've got to find the distance to cell n. Let's denote the value that is written in the i-th cell as ai. Initially, ai = 1 (1 ≀ i < n) and an = 0. We will consider that only processor i can write values in the memory cell number i. All processors can read an information from some cell (several processors can read an information from some cell simultaneously). The parallel program is executed in several steps. During each step we execute the parallel version of the increment operation. Executing the parallel version of the increment operation goes as follows: 1. Each processor independently of the other ones chooses some memory cell. Let's say that processor i has chosen a cell with number ci (1 ≀ ci ≀ n). 2. All processors simultaneously execute operation ai = ai + aci. Help Polycarpus come up with the parallel program model that is executed in exactly k steps. Calculate the operations that need to be executed. Note that after k steps for all i's value ai must be equal n - i. Input The first line contains two space-separated integers n and k (1 ≀ n ≀ 104, 1 ≀ k ≀ 20). It is guaranteed that at the given n and k the required sequence of operations exists. Output Print exactly nΒ·k integers in k lines. In the first line print numbers c1, c2, ..., cn (1 ≀ ci ≀ n) for the first increment operation. In the second line print the numbers for the second increment operation. In the k-th line print the numbers for the k-th increment operation. As a result of the printed operations for any i value ai must equal n - i. Examples Input 1 1 Output 1 Input 3 2 Output 2 3 3 3 3 3
instruction
0
12,764
24
25,528
Tags: *special, greedy Correct Solution: ``` n, k = map(int, input().split()) i, j = 1, 2 while n >= i and k > 0: print((str(n - i) + ' ') * max(0, n - j) + ' '.join(map(str, range(max(i + 1, n - i + 1), n + 1))) + (' ' + str(n)) * i) i, j, k = j, 2 * j, k - 1 for i in range(k): print((str(n) + ' ') * n) ```
output
1
12,764
24
25,529
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has a computer with n processors. Also, his computer has n memory cells. We'll consider the processors numbered by integers from 1 to n and that the memory cells are consecutively numbered by integers from 1 to n. Polycarpus needs to come up with a parallel program model. For each memory cell number i this program must record the value n - i to this cell. In other words, for each cell you've got to find the distance to cell n. Let's denote the value that is written in the i-th cell as ai. Initially, ai = 1 (1 ≀ i < n) and an = 0. We will consider that only processor i can write values in the memory cell number i. All processors can read an information from some cell (several processors can read an information from some cell simultaneously). The parallel program is executed in several steps. During each step we execute the parallel version of the increment operation. Executing the parallel version of the increment operation goes as follows: 1. Each processor independently of the other ones chooses some memory cell. Let's say that processor i has chosen a cell with number ci (1 ≀ ci ≀ n). 2. All processors simultaneously execute operation ai = ai + aci. Help Polycarpus come up with the parallel program model that is executed in exactly k steps. Calculate the operations that need to be executed. Note that after k steps for all i's value ai must be equal n - i. Input The first line contains two space-separated integers n and k (1 ≀ n ≀ 104, 1 ≀ k ≀ 20). It is guaranteed that at the given n and k the required sequence of operations exists. Output Print exactly nΒ·k integers in k lines. In the first line print numbers c1, c2, ..., cn (1 ≀ ci ≀ n) for the first increment operation. In the second line print the numbers for the second increment operation. In the k-th line print the numbers for the k-th increment operation. As a result of the printed operations for any i value ai must equal n - i. Examples Input 1 1 Output 1 Input 3 2 Output 2 3 3 3 3 3
instruction
0
12,765
24
25,530
Tags: *special, greedy Correct Solution: ``` n, k = map(int, input().split()) a = [1 for i in range(n + 1)] a[n] = 0 for iter in range(k): for i in range(1, n - 1): target = n - i if a[i + 1] > target - a[i]: # find right number target -= a[i] print(n - target, end=' ') a[i] += a[n - target]; else: a[i] += a[i + 1] print(i + 1, end=' ') for i in range(max(0, n - 2), n): print(n, end=' ') print() ```
output
1
12,765
24
25,531
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus has a computer with n processors. Also, his computer has n memory cells. We'll consider the processors numbered by integers from 1 to n and that the memory cells are consecutively numbered by integers from 1 to n. Polycarpus needs to come up with a parallel program model. For each memory cell number i this program must record the value n - i to this cell. In other words, for each cell you've got to find the distance to cell n. Let's denote the value that is written in the i-th cell as ai. Initially, ai = 1 (1 ≀ i < n) and an = 0. We will consider that only processor i can write values in the memory cell number i. All processors can read an information from some cell (several processors can read an information from some cell simultaneously). The parallel program is executed in several steps. During each step we execute the parallel version of the increment operation. Executing the parallel version of the increment operation goes as follows: 1. Each processor independently of the other ones chooses some memory cell. Let's say that processor i has chosen a cell with number ci (1 ≀ ci ≀ n). 2. All processors simultaneously execute operation ai = ai + aci. Help Polycarpus come up with the parallel program model that is executed in exactly k steps. Calculate the operations that need to be executed. Note that after k steps for all i's value ai must be equal n - i. Input The first line contains two space-separated integers n and k (1 ≀ n ≀ 104, 1 ≀ k ≀ 20). It is guaranteed that at the given n and k the required sequence of operations exists. Output Print exactly nΒ·k integers in k lines. In the first line print numbers c1, c2, ..., cn (1 ≀ ci ≀ n) for the first increment operation. In the second line print the numbers for the second increment operation. In the k-th line print the numbers for the k-th increment operation. As a result of the printed operations for any i value ai must equal n - i. Examples Input 1 1 Output 1 Input 3 2 Output 2 3 3 3 3 3 Submitted Solution: ``` n, k = map(int, input().split()) i, j = 1, 2 while n >= i: print((str(n - i) + ' ') * max(0, n - j) + ' '.join(map(str, range(max(i + 1, n - i + 1), n + 1))) + (' ' + str(n)) * i) i, j, k = j, 2 * j, k - 1 for i in range(k): print((str(n) + ' ') * n) ```
instruction
0
12,766
24
25,532
No
output
1
12,766
24
25,533
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c). Input The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≀ x_i ≀ 10^9) β€” numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4. Output Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. Examples Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100
instruction
0
13,375
24
26,750
Tags: math Correct Solution: ``` a,b,c,d=map(int,input().split()) l=[a,b,c,d] l.sort() print(l[-1]-l[0],l[-1]-l[1],l[-1]-l[2]) ```
output
1
13,375
24
26,751
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c). Input The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≀ x_i ≀ 10^9) β€” numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4. Output Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. Examples Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100
instruction
0
13,376
24
26,752
Tags: math Correct Solution: ``` arr = list(map(int,input().split())) suma = max(arr) for i in arr: if(i == suma): continue print(suma - i,end = ' ') ```
output
1
13,376
24
26,753
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c). Input The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≀ x_i ≀ 10^9) β€” numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4. Output Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. Examples Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100
instruction
0
13,377
24
26,754
Tags: math Correct Solution: ``` '''Rajat pal''' from collections import defaultdict from sys import stdin from bisect import bisect_left as bl, bisect_right as br,insort import heapq from collections import deque import math ####### Stay away from negative people. They have problem for every solution.######## a=list(map(int,input().rstrip().split())) maxi=max(a) index=a.index(maxi) for i in range(4): if i==index: pass else: print(maxi-a[i],end=' ') ```
output
1
13,377
24
26,755
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c). Input The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≀ x_i ≀ 10^9) β€” numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4. Output Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. Examples Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100
instruction
0
13,378
24
26,756
Tags: math Correct Solution: ``` abcd=list(map(int,input().split())) abcd=sorted(abcd) ans=[] m=max(abcd) for i in abcd: if i!=m: ans.append(m-i) print(*ans[::-1]) ```
output
1
13,378
24
26,757
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c). Input The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≀ x_i ≀ 10^9) β€” numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4. Output Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. Examples Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100
instruction
0
13,379
24
26,758
Tags: math Correct Solution: ``` arr = sorted(list(map(int, input().split()))) print(' '.join([str(arr[3] - arr[i]) for i in range(3)])) ```
output
1
13,379
24
26,759
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c). Input The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≀ x_i ≀ 10^9) β€” numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4. Output Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. Examples Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100
instruction
0
13,380
24
26,760
Tags: math Correct Solution: ``` import math l=[int(i) for i in input().split()] l.sort(reverse=True) p=l[1] q=l[2] r=l[3] a=l[0]-l[1] b=l[0]-l[2] c=l[0]-l[3] print(a,b,c) ```
output
1
13,380
24
26,761
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c). Input The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≀ x_i ≀ 10^9) β€” numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4. Output Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. Examples Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100
instruction
0
13,381
24
26,762
Tags: math Correct Solution: ``` a, b, c, d = map(int, input().split(' ')) x = int(max(a, b, c, d)) s = '' if x != a: s += str(x-a)+' ' if x != b: s += str(x-b)+' ' if x != c: s += str(x-c)+' ' if x != d: s += str(x-d)+' ' print(s.strip()) ```
output
1
13,381
24
26,763
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c). Input The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≀ x_i ≀ 10^9) β€” numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4. Output Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. Examples Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100
instruction
0
13,382
24
26,764
Tags: math Correct Solution: ``` x1,x2,x3,x4 = map(int,input().split()) m = max(x1,x2,x3,x4) if m == x1: print(x1 - x2, x1 - x3, x1 - x4) elif m == x2: print(x2 - x1, x2 - x3, x2 - x4) elif m == x3: print(x3 - x1, x3 - x2, x3 - x4) elif m == x4: print(x4 - x1, x4 - x2, x4 - x3) ```
output
1
13,382
24
26,765
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c). Input The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≀ x_i ≀ 10^9) β€” numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4. Output Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. Examples Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100 Submitted Solution: ``` x1,x2,x3,x4=sorted(map(int,input().split(' '))) print(x4-x3,x4-x2,x4-x1) ```
instruction
0
13,383
24
26,766
Yes
output
1
13,383
24
26,767
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c). Input The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≀ x_i ≀ 10^9) β€” numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4. Output Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. Examples Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100 Submitted Solution: ``` # https://codeforces.com/problemset/problem/1154/A def main(): nums = sorted(list(map(int, input().split()))) print(nums[3] - nums[0], nums[3] - nums[1], nums[3] - nums[2]) if __name__ == '__main__': main() ```
instruction
0
13,384
24
26,768
Yes
output
1
13,384
24
26,769
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c). Input The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≀ x_i ≀ 10^9) β€” numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4. Output Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. Examples Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100 Submitted Solution: ``` sums = list(input().split(' ')) sums = list(map(int, sums)) sums.sort() abc = max(sums) print(abc-sums[0],abc-sums[1],abc-sums[2]) ```
instruction
0
13,385
24
26,770
Yes
output
1
13,385
24
26,771
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c). Input The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≀ x_i ≀ 10^9) β€” numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4. Output Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. Examples Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100 Submitted Solution: ``` l=list(map(int,input().split())) d=sorted(l) m=max(d) a=m-d[0] b=m-d[1] c=m-d[2] print(a,b,c) ```
instruction
0
13,386
24
26,772
Yes
output
1
13,386
24
26,773
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c). Input The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≀ x_i ≀ 10^9) β€” numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4. Output Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. Examples Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100 Submitted Solution: ``` arr = sorted(list(map(int, input().split()))) li = [] for index in range(len(arr) - 1): li.append(arr[-1] - arr[index]) print(sorted(li)) ```
instruction
0
13,387
24
26,774
No
output
1
13,387
24
26,775
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c). Input The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≀ x_i ≀ 10^9) β€” numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4. Output Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. Examples Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100 Submitted Solution: ``` #!/usr/bin/python3 # https://codeforces.com/problemset/problem/1154/A input_str = input().split(" ") num_list = [int(x) for x in input_str] abc = max(num_list) pop_flag = False res = list() for x in num_list: if x == abc and not pop_flag: pop_flag = True pass else: print(x, end=" ") ```
instruction
0
13,388
24
26,776
No
output
1
13,388
24
26,777
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c). Input The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≀ x_i ≀ 10^9) β€” numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4. Output Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. Examples Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100 Submitted Solution: ``` nums = list(sorted(map(int, input().split()))) print(f'{nums[0] - nums[3]} {nums[1] - nums[3]} {nums[2] - nums[3]}') ```
instruction
0
13,389
24
26,778
No
output
1
13,389
24
26,779
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order β€” their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You have to guess three numbers a, b and c using given numbers. Print three guessed integers in any order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a=b=c). Input The only line of the input contains four positive integers x_1, x_2, x_3, x_4 (2 ≀ x_i ≀ 10^9) β€” numbers written on a board in random order. It is guaranteed that the answer exists for the given number x_1, x_2, x_3, x_4. Output Print such positive integers a, b and c that four numbers written on a board are values a+b, a+c, b+c and a+b+c written in some order. Print a, b and c in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. Examples Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100 Submitted Solution: ``` a,b,c,d=map(int,input().split()) e=[a,b,c,d] e.sort(reverse = True) tam=0 f=[] for i in range(0,len(e)-1): tam = e[i] - e[3] f.append(tam) for i in range(0,len(f)): print(f[i],end=' ') ```
instruction
0
13,390
24
26,780
No
output
1
13,390
24
26,781
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp plays a (yet another!) strategic computer game. In this game, he leads an army of mercenaries. Polycarp wants to gather his army for a quest. There are n mercenaries for hire, and the army should consist of some subset of them. The i-th mercenary can be chosen if the resulting number of chosen mercenaries is not less than l_i (otherwise he deems the quest to be doomed) and not greater than r_i (he doesn't want to share the trophies with too many other mercenaries). Furthermore, m pairs of mercenaries hate each other and cannot be chosen for the same quest. How many non-empty subsets does Polycarp need to consider? In other words, calculate the number of non-empty subsets of mercenaries such that the size of this subset belongs to [l_i, r_i] for each chosen mercenary, and there are no two mercenaries in the subset that hate each other. The answer may be large, so calculate it modulo 998244353. Input The first line contains two integers n and m (1 ≀ n ≀ 3 β‹… 10^5, 0 ≀ m ≀ min(20, (n(n-1))/(2))) β€” the number of mercenaries and the number of pairs of mercenaries that hate each other. Then n lines follow, the i-th of them contains two integers l_i and r_i (1 ≀ l_i ≀ r_i ≀ n). Then m lines follow, the i-th of them contains two integers a_i and b_i (1 ≀ a_i < b_i ≀ n) denoting that the mercenaries a_i and b_i hate each other. There are no two equal pairs in this list. Output Print one integer β€” the number of non-empty subsets meeting the constraints, taken modulo 998244353. Examples Input 3 0 1 1 2 3 1 3 Output 3 Input 3 1 1 1 2 3 1 3 2 3 Output 2 Submitted Solution: ``` from math import factorial as f n,m=map(int,input().split()) l,r=map(int,input().split()) a,b=map(int,input().split()) print() print(n -m) ```
instruction
0
13,480
24
26,960
No
output
1
13,480
24
26,961
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp plays a (yet another!) strategic computer game. In this game, he leads an army of mercenaries. Polycarp wants to gather his army for a quest. There are n mercenaries for hire, and the army should consist of some subset of them. The i-th mercenary can be chosen if the resulting number of chosen mercenaries is not less than l_i (otherwise he deems the quest to be doomed) and not greater than r_i (he doesn't want to share the trophies with too many other mercenaries). Furthermore, m pairs of mercenaries hate each other and cannot be chosen for the same quest. How many non-empty subsets does Polycarp need to consider? In other words, calculate the number of non-empty subsets of mercenaries such that the size of this subset belongs to [l_i, r_i] for each chosen mercenary, and there are no two mercenaries in the subset that hate each other. The answer may be large, so calculate it modulo 998244353. Input The first line contains two integers n and m (1 ≀ n ≀ 3 β‹… 10^5, 0 ≀ m ≀ min(20, (n(n-1))/(2))) β€” the number of mercenaries and the number of pairs of mercenaries that hate each other. Then n lines follow, the i-th of them contains two integers l_i and r_i (1 ≀ l_i ≀ r_i ≀ n). Then m lines follow, the i-th of them contains two integers a_i and b_i (1 ≀ a_i < b_i ≀ n) denoting that the mercenaries a_i and b_i hate each other. There are no two equal pairs in this list. Output Print one integer β€” the number of non-empty subsets meeting the constraints, taken modulo 998244353. Examples Input 3 0 1 1 2 3 1 3 Output 3 Input 3 1 1 1 2 3 1 3 2 3 Output 2 Submitted Solution: ``` print("Haan man kiya, kar diye submit!") ```
instruction
0
13,481
24
26,962
No
output
1
13,481
24
26,963
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp plays a (yet another!) strategic computer game. In this game, he leads an army of mercenaries. Polycarp wants to gather his army for a quest. There are n mercenaries for hire, and the army should consist of some subset of them. The i-th mercenary can be chosen if the resulting number of chosen mercenaries is not less than l_i (otherwise he deems the quest to be doomed) and not greater than r_i (he doesn't want to share the trophies with too many other mercenaries). Furthermore, m pairs of mercenaries hate each other and cannot be chosen for the same quest. How many non-empty subsets does Polycarp need to consider? In other words, calculate the number of non-empty subsets of mercenaries such that the size of this subset belongs to [l_i, r_i] for each chosen mercenary, and there are no two mercenaries in the subset that hate each other. The answer may be large, so calculate it modulo 998244353. Input The first line contains two integers n and m (1 ≀ n ≀ 3 β‹… 10^5, 0 ≀ m ≀ min(20, (n(n-1))/(2))) β€” the number of mercenaries and the number of pairs of mercenaries that hate each other. Then n lines follow, the i-th of them contains two integers l_i and r_i (1 ≀ l_i ≀ r_i ≀ n). Then m lines follow, the i-th of them contains two integers a_i and b_i (1 ≀ a_i < b_i ≀ n) denoting that the mercenaries a_i and b_i hate each other. There are no two equal pairs in this list. Output Print one integer β€” the number of non-empty subsets meeting the constraints, taken modulo 998244353. Examples Input 3 0 1 1 2 3 1 3 Output 3 Input 3 1 1 1 2 3 1 3 2 3 Output 2 Submitted Solution: ``` a, b = map(int, input().split()) q = [] for i in range(1, a+1): l, r = map(int, input().split()) qwe = [] qwe.append(l) qwe.append(r) q.append(qwe) w = [] if not b == 0: for i in range(1, b+1): m, n = map(int, input().split()) we = [] we.append(m) we.append(n) w.append(we) k = 0 if b == 0: k = a else: for i in range(a ): for j in range(b): if not q[i] == w[j]: k += 1 print(k) ```
instruction
0
13,482
24
26,964
No
output
1
13,482
24
26,965
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp plays a (yet another!) strategic computer game. In this game, he leads an army of mercenaries. Polycarp wants to gather his army for a quest. There are n mercenaries for hire, and the army should consist of some subset of them. The i-th mercenary can be chosen if the resulting number of chosen mercenaries is not less than l_i (otherwise he deems the quest to be doomed) and not greater than r_i (he doesn't want to share the trophies with too many other mercenaries). Furthermore, m pairs of mercenaries hate each other and cannot be chosen for the same quest. How many non-empty subsets does Polycarp need to consider? In other words, calculate the number of non-empty subsets of mercenaries such that the size of this subset belongs to [l_i, r_i] for each chosen mercenary, and there are no two mercenaries in the subset that hate each other. The answer may be large, so calculate it modulo 998244353. Input The first line contains two integers n and m (1 ≀ n ≀ 3 β‹… 10^5, 0 ≀ m ≀ min(20, (n(n-1))/(2))) β€” the number of mercenaries and the number of pairs of mercenaries that hate each other. Then n lines follow, the i-th of them contains two integers l_i and r_i (1 ≀ l_i ≀ r_i ≀ n). Then m lines follow, the i-th of them contains two integers a_i and b_i (1 ≀ a_i < b_i ≀ n) denoting that the mercenaries a_i and b_i hate each other. There are no two equal pairs in this list. Output Print one integer β€” the number of non-empty subsets meeting the constraints, taken modulo 998244353. Examples Input 3 0 1 1 2 3 1 3 Output 3 Input 3 1 1 1 2 3 1 3 2 3 Output 2 Submitted Solution: ``` def choose(mercenaries,pairs): count = 0 for k in mercenaries: chosen = 0 sub_count = 0 if chosen+1 >= k[0] and chosen <= k[1]: count += 1 mx = k[1] if chosen+1 < mx: for kk in range(len(mercenaries)*3): for i in mercenaries: if i!=k and chosen+1 < i[1]: if [mercenaries.index(k)+1,mercenaries.index(i)+1] not in pairs and [mercenaries.index(i)+1,mercenaries.index(k)+1] not in pairs: chosen += 1 if chosen != 0: count += 1 return (count) n,m = list(map(int,input().split())) mnaries = [] hate_pairs = [] for k in range(n): mnaries.append(list(map(int,input().split()))) for k in range(m): hate_pairs.append(list(map(int,input().split()))) print(choose(mnaries,hate_pairs)) ```
instruction
0
13,483
24
26,966
No
output
1
13,483
24
26,967
Provide tags and a correct Python 3 solution for this coding contest problem. Monocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first n/2 digits of this ticket is equal to the sum of the last n/2 digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from 0 to 9. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. Input The first line contains one even integer n (2 ≀ n ≀ 2 β‹… 10^{5}) β€” the number of digits in the ticket. The second line contains a string of n digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the i-th character is "?", then the i-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. Output If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). Examples Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp Note Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
instruction
0
14,228
24
28,456
Tags: games, greedy, math Correct Solution: ``` n = int(input()) s = input() left_cnt = 0 right_cnt = 0 left_num = 0 right_num = 0 for i in range(n//2): if s[i] == "?": left_cnt += 1 else: left_num += int(s[i]) for i in range(n//2,n): if s[i] == "?": right_cnt += 1 else: right_num += int(s[i]) if left_cnt == right_cnt: if left_num == right_num: print("Bicarp") else: print("Monocarp") exit() diff = left_cnt - right_cnt diff_num = left_num - right_num if -diff_num //(diff//2) == 9 and -diff_num %(diff//2) == 0: print("Bicarp") else: print("Monocarp") ```
output
1
14,228
24
28,457
Provide tags and a correct Python 3 solution for this coding contest problem. Monocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first n/2 digits of this ticket is equal to the sum of the last n/2 digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from 0 to 9. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. Input The first line contains one even integer n (2 ≀ n ≀ 2 β‹… 10^{5}) β€” the number of digits in the ticket. The second line contains a string of n digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the i-th character is "?", then the i-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. Output If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). Examples Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp Note Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
instruction
0
14,229
24
28,458
Tags: games, greedy, math Correct Solution: ``` n=int(input()) s=input() s1=0 s2=0 c1=0 c2=0 for i in range(n//2): if s[i]!="?": s1+=int(s[i]) else: c1+=1 if s[-i-1]!="?": s2+=int(s[-i-1]) else: c2+=1 if c1>c2: c1-=c2 # print(c1) if s1 + 9*(c1//2)>s2 or s1 + 9*(c1//2)<s2: print("Monocarp") else: print("Bicarp") else: c2-=c1 if s2 + 9*(c2//2)>s1 or s2 + 9*(c2//2)<s1: print("Monocarp") else: print("Bicarp") ```
output
1
14,229
24
28,459
Provide tags and a correct Python 3 solution for this coding contest problem. Monocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first n/2 digits of this ticket is equal to the sum of the last n/2 digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from 0 to 9. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. Input The first line contains one even integer n (2 ≀ n ≀ 2 β‹… 10^{5}) β€” the number of digits in the ticket. The second line contains a string of n digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the i-th character is "?", then the i-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. Output If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). Examples Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp Note Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
instruction
0
14,230
24
28,460
Tags: games, greedy, math Correct Solution: ``` n = int(input()) word = input() print(["Monocarp", "Bicarp"][0 == sum([9 * (2 * (i < n//2) - 1) if word[i] == '?' else (4 * (i < n//2) - 2) * int(word[i]) for i in range(n)])]) ```
output
1
14,230
24
28,461