message
stringlengths
2
20.1k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
1.95k
109k
cluster
float64
17
17
__index_level_0__
int64
3.91k
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. Input The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team. Output Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie. Examples Input []()[]8< 8<[]()8< Output TEAM 2 WINS Input 8<8<() []8<[] Output TIE
instruction
0
6,994
17
13,988
Tags: *special Correct Solution: ``` __author__ = 'Pavel Mavrin' a = input().strip() b = input().strip() n = len(a) // 2 x = 0 figs = ["[]", "()", "8<"] for i in range(n): s1 = figs.index(a[i * 2: (i + 1) * 2]) s2 = figs.index(b[i * 2: (i + 1) * 2]) if s2 == (s1 + 1) % 3: x += 1 if s1 == (s2 + 1) % 3: x -= 1 if x > 0: print("TEAM 1 WINS") elif x < 0: print("TEAM 2 WINS") else: print("TIE") ```
output
1
6,994
17
13,989
Provide tags and a correct Python 3 solution for this coding contest problem. Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. Input The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team. Output Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie. Examples Input []()[]8&lt; 8&lt;[]()8&lt; Output TEAM 2 WINS Input 8&lt;8&lt;() []8&lt;[] Output TIE
instruction
0
6,995
17
13,990
Tags: *special Correct Solution: ``` s1 = input() s2 = input() num1 = 0 num2 = 0 for i in range(0, len(s1), 2): c1 = s1[i:i + 2] c2 = s2[i:i + 2] if c1 != c2: if (c1 == "8<" and c2 == "[]"): num1 += 1 elif (c1 == "()" and c2 == "8<"): num1 += 1 elif (c1 == "[]" and c2 == "()"): num1 += 1 else: num2 += 1 if num1 == num2: print("TIE") else: print("TEAM {} WINS".format(int(num2 > num1) + 1)) ```
output
1
6,995
17
13,991
Provide tags and a correct Python 3 solution for this coding contest problem. Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. Input The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team. Output Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie. Examples Input []()[]8&lt; 8&lt;[]()8&lt; Output TEAM 2 WINS Input 8&lt;8&lt;() []8&lt;[] Output TIE
instruction
0
6,996
17
13,992
Tags: *special Correct Solution: ``` def split_by_n( seq, n ): while seq: yield seq[:n] seq = seq[n:] def is_first_win(first, second): if first ==second: return 0 if first == '8<': if second == '[]': return 1 else: return -1 if first == '[]': if second == '()': return 1 else: return -1 if second == '8<': return 1 else: return -1 team1 = list(split_by_n(input(), 2)) team2 = list(split_by_n(input(), 2)) score = 0 for i in range(len(team1)): score += is_first_win(team1[i], team2[i]) #print(is_first_win(team1[i], team2[i]), team1[i], team2[i]) #print(score) if score > 0: print('TEAM 1 WINS') elif score == 0: print('TIE') else: print('TEAM 2 WINS') ```
output
1
6,996
17
13,993
Provide tags and a correct Python 3 solution for this coding contest problem. Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. Input The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team. Output Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie. Examples Input []()[]8&lt; 8&lt;[]()8&lt; Output TEAM 2 WINS Input 8&lt;8&lt;() []8&lt;[] Output TIE
instruction
0
6,997
17
13,994
Tags: *special Correct Solution: ``` a = input() a_actions = [(a[i:i+2]) for i in range(0, len(a), 2)] b = input() b_actions = [(b[i:i+2]) for i in range(0, len(b), 2)] # print(a_actions, b_actions) rock = "()" paper = "[]" scissors = "8<" a_pts = 0 b_pts = 0 for i in range(len(a)//2): if a_actions[i] == rock: if b_actions[i] == scissors: a_pts += 1 elif b_actions[i] == paper: b_pts += 1 else: a_pts += 1 b_pts += 1 elif a_actions[i] == paper: if b_actions[i] == rock: a_pts += 1 elif b_actions[i] == scissors: b_pts += 1 else: a_pts += 1 b_pts += 1 else: # a_actions[i] == scissors if b_actions[i] == paper: a_pts += 1 elif b_actions[i] == rock: b_pts += 1 else: a_pts += 1 b_pts += 1 if a_pts > b_pts: print("TEAM 1 WINS") elif a_pts < b_pts: print("TEAM 2 WINS") else: print("TIE") ```
output
1
6,997
17
13,995
Provide tags and a correct Python 3 solution for this coding contest problem. Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. Input The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team. Output Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie. Examples Input []()[]8&lt; 8&lt;[]()8&lt; Output TEAM 2 WINS Input 8&lt;8&lt;() []8&lt;[] Output TIE
instruction
0
6,998
17
13,996
Tags: *special Correct Solution: ``` #!/bin/bash/python # Date: 2014-04-16 # Author: shijinzhan # Status: # Note: '()' < '[]' # '[]' < '8<' # '8<' < '()' team1 = input().replace('(', '6').replace('[', '7') team2 = input().replace('(', '6').replace('[', '7') s = 0 for x in range(0, len(team1), 2): if team1[x] > team2[x]: s += 1 elif team1[x] < team2[x]: s -= 1 if team1[x] == '6' and team2[x] == '8': s += 2 if team1[x] == '8' and team2[x] == '6': s -= 2 if s > 0: print("TEAM 1 WINS") elif s < 0: print("TEAM 2 WINS") else: print("TIE") ```
output
1
6,998
17
13,997
Provide tags and a correct Python 3 solution for this coding contest problem. Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. Input The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team. Output Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie. Examples Input []()[]8&lt; 8&lt;[]()8&lt; Output TEAM 2 WINS Input 8&lt;8&lt;() []8&lt;[] Output TIE
instruction
0
6,999
17
13,998
Tags: *special Correct Solution: ``` s = input() t = input() a = 0 b = 0 for i in range(0, len(s), 2): if s[i:i+2] == "[]" and t[i:i+2]=="()": a += 1 if s[i:i+2] == "()" and t[i:i+2]=="8<": a += 1 if s[i:i+2] == "8<" and t[i:i+2]=="[]": a += 1 if t[i:i+2] == "[]" and s[i:i+2]=="()": b += 1 if t[i:i+2] == "()" and s[i:i+2]=="8<": b += 1 if t[i:i+2] == "8<" and s[i:i+2]=="[]": b += 1 if a > b: print("TEAM 1 WINS") elif a < b: print("TEAM 2 WINS") else: print("TIE") ```
output
1
6,999
17
13,999
Provide tags and a correct Python 3 solution for this coding contest problem. Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. Input The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team. Output Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie. Examples Input []()[]8&lt; 8&lt;[]()8&lt; Output TEAM 2 WINS Input 8&lt;8&lt;() []8&lt;[] Output TIE
instruction
0
7,000
17
14,000
Tags: *special Correct Solution: ``` cnt=0 t1=input() t2=input() for i in range(0,len(t1),2): p1=t1[i:i+2] p2=t2[i:i+2] if(p1=="8<"): if(p2=="[]"): cnt+=1 elif(p2=="()"): cnt-=1 elif(p1=="[]"): if(p2=="()"): cnt+=1 elif(p2=="8<"): cnt-=1 else: if(p2=="8<"): cnt+=1 elif(p2=="[]"): cnt-=1 if(cnt==0): print("TIE") elif(cnt>0): print("TEAM 1 WINS") else: print("TEAM 2 WINS") ```
output
1
7,000
17
14,001
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. Input The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team. Output Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie. Examples Input []()[]8&lt; 8&lt;[]()8&lt; Output TEAM 2 WINS Input 8&lt;8&lt;() []8&lt;[] Output TIE Submitted Solution: ``` def a(sMove1, sMove2): if sMove1 == "8<" and sMove2 == "[]" or sMove1 == "[]" and sMove2 == "()" or sMove1 == "()" and sMove2 == "8<": return 1 elif sMove2 == "8<" and sMove1 == "[]" or sMove2 == "[]" and sMove1 == "()" or sMove2 == "()" and sMove1 == "8<": return 2 else: return 0 t1 = input() t2 = input() s = [0, 0, 0] for i in range(0, len(t1), 2): s[a(t1[i] + t1[i + 1], t2[i] + t2[i + 1])] += 1 if s[1] > s[2]: print('TEAM 1 WINS') elif s[1] < s[2]: print("TEAM 2 WINS") else: print('TIE') ```
instruction
0
7,001
17
14,002
Yes
output
1
7,001
17
14,003
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. Input The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team. Output Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie. Examples Input []()[]8&lt; 8&lt;[]()8&lt; Output TEAM 2 WINS Input 8&lt;8&lt;() []8&lt;[] Output TIE Submitted Solution: ``` s1 = input() s2 = input() score1, score2 = 0, 0 for c in range(0, len(s1), 2): if s1[c] == '8': if s2[c] == '[': score1 += 1 if s2[c] == '(': score2 += 1 if s1[c] == '[': if s2[c] == '(': score1 += 1 if s2[c] == '8': score2 += 1 if s1[c] == '(': if s2[c] == '8': score1 += 1 if s2[c] == '[': score2 += 1 if score1 == score2: print ('TIE') else: print('TEAM {} WINS'.format(2 - int(score1 > score2))) ```
instruction
0
7,002
17
14,004
Yes
output
1
7,002
17
14,005
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. Input The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team. Output Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie. Examples Input []()[]8&lt; 8&lt;[]()8&lt; Output TEAM 2 WINS Input 8&lt;8&lt;() []8&lt;[] Output TIE Submitted Solution: ``` from math import* def winner(a,b): if a=="[]": if b=="()": return 1 elif b=="[]": return 0 else: return -1 elif a=="8<": if b=="()": return -1 elif b=="[]": return 1 else: return 0 else: if b=="()": return 0 elif b=="[]": return -1 else: return 1 s1=input() s2=input() i=0 ans=0 while i<len(s1): ans+=winner(s1[i:i+2],s2[i:i+2]) i+=2 if ans==0: print("TIE") elif ans<0: print("TEAM 2 WINS") else: print("TEAM 1 WINS") ```
instruction
0
7,003
17
14,006
Yes
output
1
7,003
17
14,007
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. Input The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team. Output Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie. Examples Input []()[]8&lt; 8&lt;[]()8&lt; Output TEAM 2 WINS Input 8&lt;8&lt;() []8&lt;[] Output TIE Submitted Solution: ``` s1 = input() s2 = input() def identify(figure): if figure == '8<': return 'scissors' elif figure == '[]': return 'paper' else: return 'stone' first, second = 0, 0 i = 0 while i < len(s1)-1: p1 = identify(s1[i:i+2]) p2 = identify(s2[i:i+2]) # print(p1, p2) if p1 == 'scissors': if p2 == 'paper': first += 1 elif p2 == 'stone': second += 1 elif p1 == 'paper': if p2 == 'stone': first += 1 elif p2 == 'scissors': second += 1 elif p1 == 'stone': if p2 == 'scissors': first += 1 elif p2 == 'paper': second += 1 i += 2 if first == second: print('TIE') elif first < second: print('TEAM 2 WINS') else: print('TEAM 1 WINS') ```
instruction
0
7,004
17
14,008
Yes
output
1
7,004
17
14,009
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. Input The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team. Output Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie. Examples Input []()[]8&lt; 8&lt;[]()8&lt; Output TEAM 2 WINS Input 8&lt;8&lt;() []8&lt;[] Output TIE Submitted Solution: ``` s = input() s1 = input() print("TIE") ```
instruction
0
7,005
17
14,010
No
output
1
7,005
17
14,011
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. Input The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team. Output Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie. Examples Input []()[]8&lt; 8&lt;[]()8&lt; Output TEAM 2 WINS Input 8&lt;8&lt;() []8&lt;[] Output TIE Submitted Solution: ``` a=input().split('<') b=input().split('<') ans=chk=0 for i in range(1,len(a)): if a[i-1][-1].isdigit() and len(a[i])>1 and (a[i][0]+a[i][1]=='()' or a[i][0]+a[i][1]=='[]'): ans+=1 for i in range(1,len(b)): if b[i-1][-1].isdigit() and len(b[i])>1 and (b[i][0]+b[i][1]=='()' or b[i][0]+b[i][1]=='[]'): chk+=1 print('TEAM 2 WINS') if chk>ans else ('TEAM 1 WINS') if ans<chk else ('TIE') ```
instruction
0
7,006
17
14,012
No
output
1
7,006
17
14,013
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. Input The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team. Output Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie. Examples Input []()[]8&lt; 8&lt;[]()8&lt; Output TEAM 2 WINS Input 8&lt;8&lt;() []8&lt;[] Output TIE Submitted Solution: ``` cnt=0 t1=input() t2=input() for i in range(0,len(t1),2): p1=t1[i:i+2] p2=t2[i:i+2] if(p1=="8<"): if(p2=="[]"): cnt+=1 elif(p2=="()"): cnt-=1 elif(p1=="[]"): if(p2=="()"): cnt+=1 elif(p1=="8<"): cnt-=1 else: if(p2=="8<"): cnt+=1 elif(p2=="[]"): cnt-=1 if(cnt==0): print("TIE") elif(cnt>0): print("TEAM 1 WINS") else: print("TEAM 2 WINS") ```
instruction
0
7,007
17
14,014
No
output
1
7,007
17
14,015
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. Input The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team. Output Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie. Examples Input []()[]8&lt; 8&lt;[]()8&lt; Output TEAM 2 WINS Input 8&lt;8&lt;() []8&lt;[] Output TIE Submitted Solution: ``` def x(): s=input() return s.count("8<[]()") t = x()-x() print("TEAM %d WINS"%(1 if t>0 else 2) if t!=0 else "TIE") ```
instruction
0
7,008
17
14,016
No
output
1
7,008
17
14,017
Provide tags and a correct Python 3 solution for this coding contest problem. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
instruction
0
7,041
17
14,082
Tags: binary search, greedy, implementation Correct Solution: ``` def main(): from bisect import bisect_left n, l, x, y = map(int, input().split()) aa, d = list(map(int, input().split())), {} for z in (x, y, y + x): for a in aa: a += z if a > l: break b = aa[bisect_left(aa, a)] if b <= a: if b == a: d[z] = a break if len(d) == 2: break if d: if x in d and y in d: res = [] elif x in d: res = [y] elif y in d: res = [x] elif y + x in d: res = [d[y + x] - y] else: z, tmp = y - x, [] for a in aa: a += z if a > l: break b = aa[bisect_left(aa, a)] if b == a: tmp.append(a) for a in tmp: if a > y: res = [a - y] break elif a + x < l: res = [a + x] break else: res = [x, y] print(len(res)) if res: print(*res) if __name__ == '__main__': main() ```
output
1
7,041
17
14,083
Provide tags and a correct Python 3 solution for this coding contest problem. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
instruction
0
7,042
17
14,084
Tags: binary search, greedy, implementation Correct Solution: ``` import itertools import math def can_measure(a, d): return any(i + d in a for i in a) def main(): n, l, x, y = map(int, input().split()) a = set(map(int, input().split())) can_x = can_measure(a, x) can_y = can_measure(a, y) if can_x and can_y: print(0) elif can_x: print(1) print(y) elif can_y: print(1) print(x) else: for i in a: if i + x + y in a: print(1) print(i + x) break else: t = i + x - y in a if 0 <= i + x <= l and t: print(1) print(i + x) break; if 0 <= i - y <= l and t: print(1) print(i - y) break; else: print(2) print(x, y) if __name__ == "__main__": main() ```
output
1
7,042
17
14,085
Provide tags and a correct Python 3 solution for this coding contest problem. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
instruction
0
7,043
17
14,086
Tags: binary search, greedy, implementation Correct Solution: ``` def main(): import sys tokens = [int(i) for i in sys.stdin.read().split()] tokens.reverse() n, l, x, y = [tokens.pop() for i in range(4)] marks = set(tokens) flag_x = flag_y = False index = -1 for i in marks: if i + x in marks: flag_x = True index = y if i + y in marks: flag_y = True index = x if i + x + y in marks: index = i + x if i + y - x in marks and i - x >= 0: index = i - x if i + y - x in marks and i + y <= l: index = i + y if flag_x and flag_y: print(0) elif index != -1: print(1) print(index) else: print(2) print(x, y) main() ```
output
1
7,043
17
14,087
Provide tags and a correct Python 3 solution for this coding contest problem. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
instruction
0
7,044
17
14,088
Tags: binary search, greedy, implementation Correct Solution: ``` class CodeforcesTask480BSolution: def __init__(self): self.result = '' self.n_l_x_y = [] self.ruler = [] def read_input(self): self.n_l_x_y = [int(x) for x in input().split(" ")] self.ruler = [int(x) for x in input().split(" ")] def process_task(self): dists = {} for a in self.ruler: dists[a] = True hasx = False hasy = False for a in self.ruler: try: if dists[a - self.n_l_x_y[2]]: hasx = True except KeyError: pass try: if dists[a + self.n_l_x_y[2]]: hasx = True except KeyError: pass try: if dists[a - self.n_l_x_y[3]]: hasy = True except KeyError: pass try: if dists[a - self.n_l_x_y[3]]: hasy = True except KeyError: pass if hasx and hasy: break if hasx and hasy: self.result = "0" elif hasx: self.result = "1\n{0}".format(self.n_l_x_y[3]) elif hasy: self.result = "1\n{0}".format(self.n_l_x_y[2]) else: res = [0, 0] sgn = False dst = self.n_l_x_y[2] + self.n_l_x_y[3] diff = self.n_l_x_y[3] - self.n_l_x_y[2] for a in self.ruler: try: if dists[a - dst]: if a - self.n_l_x_y[2] > 0: sgn = True res = a - self.n_l_x_y[2] except KeyError: pass try: if dists[a + dst]: if a + self.n_l_x_y[2] < self.n_l_x_y[1]: sgn = True res = a + self.n_l_x_y[2] except KeyError: pass try: if dists[a - diff]: if a + self.n_l_x_y[2] < self.n_l_x_y[1]: sgn = True res = a + self.n_l_x_y[2] except KeyError: pass try: if dists[a + diff]: if a - self.n_l_x_y[2] > 0: sgn = True res = a - self.n_l_x_y[2] except KeyError: pass if sgn: break if sgn: self.result = "1\n{0}".format(res) else: self.result = "2\n{0} {1}".format(self.n_l_x_y[2], self.n_l_x_y[3]) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask480BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
output
1
7,044
17
14,089
Provide tags and a correct Python 3 solution for this coding contest problem. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
instruction
0
7,045
17
14,090
Tags: binary search, greedy, implementation Correct Solution: ``` n, l, x, y = map(int, input().split()) s = set(map(int, input().split())) def f(d): return any(i + d in s for i in s) def g(): for i in s: if i + x + y in s: return i + x return 0 def h(): for i in s: if i + y - x in s: if i - x >= 0: return i - x if i + y <= l: return i + y return 0 def e(d): print(1) print(d) if f(x): if f(y): print(0) else: e(y) elif f(y): e(x) else: z = g() if z: e(z) else: z = h() if z: e(z) else: print(2) print(x, y) ```
output
1
7,045
17
14,091
Provide tags and a correct Python 3 solution for this coding contest problem. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
instruction
0
7,046
17
14,092
Tags: binary search, greedy, implementation Correct Solution: ``` from collections import defaultdict class LongJumps(): def __init__(self, n, l, x, y, a): self.n, self.l, self.x, self.y, self.a = n,l,x,y,a def get_markers(self): st = defaultdict(set) req_pts = [self.x,self.y] exist_check = defaultdict(bool) value_check = defaultdict(bool) for v in self.a: exist_check[v] = True for v in self.a: for i in range(len(req_pts)): if v - req_pts[i] >= 0: st[v - req_pts[i]].add(i) if exist_check[v - req_pts[i]]: value_check[i] = True if v + req_pts[i] <= l: st[v+req_pts[i]].add(i) if exist_check[v + req_pts[i]]: value_check[i] = True if value_check[0] and value_check[1]: print(0) return sol_status = 2 status1_marker = None for v in st: if len(st[v]) == 2: sol_status = 1 status1_marker = v elif len(st[v]) == 1: if exist_check[v]: sol_status = 1 status1_marker = req_pts[1-st[v].pop()] if sol_status == 1: print(1) print(status1_marker) return else: print(2) print(x, y) n, l, x, y = list(map(int,input().strip(' ').split(' '))) a = list(map(int,input().strip(' ').split(' '))) lj = LongJumps(n,l,x,y,a) lj.get_markers() ```
output
1
7,046
17
14,093
Provide tags and a correct Python 3 solution for this coding contest problem. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
instruction
0
7,047
17
14,094
Tags: binary search, greedy, implementation Correct Solution: ``` n, l, x, y = map(int, input().split()) def f(t, q): i = j = 0 while j < n: d = t[j] - t[i] if d < q: j += 1 elif d > q: i += 1 else: return 0 return q def g(t): q = x + y i = j = 0 while j < n: d = t[j] - t[i] if d < q: j += 1 elif d > q: i += 1 else: return t[j] return 0 def h(t): q = y - x i = j = 0 while j < n: d = t[j] - t[i] if d < q: j += 1 elif d > q: i += 1 else: a, b = t[i] - x, t[j] + x if a >= 0: return [a] if b <= l:return [b] j += 1 return [x, y] def e(t): print(len(t)) print(' '.join(map(str, t))) t = list(map(int, input().split())) t.sort() x = f(t, x) y = f(t, y) if x and y: z = g(t) if z: e([z - y]) else: e(h(t)) elif x: e([x]) elif y: e([y]) else: e([]) ```
output
1
7,047
17
14,095
Provide tags and a correct Python 3 solution for this coding contest problem. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
instruction
0
7,048
17
14,096
Tags: binary search, greedy, implementation Correct Solution: ``` import itertools import math def can_measure(a, d): return any(i + d in a for i in a) def main(): n, l, x, y = map(int, input().split()) a = set(map(int, input().split())) can_x = can_measure(a, x) can_y = can_measure(a, y) if can_x and can_y: print(0) elif can_x: print(1) print(y) elif can_y: print(1) print(x) else: for i in a: if i + x + y in a: print(1) print(i + x) break else: t = i + x - y in a if 0 <= i + x <= l and t: print(1) print(i + x) break; if 0 <= i - y <= l and t: print(1) print(i - y) break; else: print(2) print(x, y) if __name__ == "__main__": main() # Made By Mostafa_Khaled ```
output
1
7,048
17
14,097
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. Submitted Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations raw_input = stdin.readline pr = stdout.write def in_arr(): return map(int,raw_input().split()) def pr_num(n): stdout.write(str(n)+'\n') def pr_arr(arr): for i in arr: stdout.write(str(i)+' ') stdout.write('\n') range = xrange # not for python 3.0+ # main code n,l1,x,y=in_arr() l=in_arr() d=Counter(l) f1=0 f2=0 for i in range(n): if d[l[i]+x]: f1=1 if d[l[i]+y]: f2=1 if f1 and f2: print 0 elif f1 or f2: print 1 if f2: print x else: print y else: f=0 for i in range(n): if l[i]+x<=l1 and ( d[l[i]+x+y] or d[l[i]+x-y]): print 1 #print 'a' print l[i]+x exit() break if l[i]-x>=0 and (d[l[i]+y-x] or d[l[i]-y-x]): print 1 print l[i]-x exit() print 2 print x,y ```
instruction
0
7,049
17
14,098
Yes
output
1
7,049
17
14,099
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. Submitted Solution: ``` # -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random import itertools import sys from typing import List """ created by shhuan at 2020/1/13 20:48 """ def solve(N, L, X, Y, A): vs = set(A) mx = any([a+X in vs for a in A]) my = any([a+Y in vs for a in A]) if mx and my: print(0) elif mx: print(1) print(Y) elif my: print(1) print(X) else: # try to add 1 mark for a in vs: for b, c in [(a + X, Y), (a + Y, X), (a - X, Y), (a - Y, X)]: if 0 <= b <= L: if (b + c <= L and b + c in vs) or (b - c >= 0 and b - c in vs): print(1) print(b) return # add 2 marks print(2) print('{} {}'.format(X, Y)) N, L, X, Y = map(int, input().split()) A = [int(x) for x in input().split()] solve(N, L, X, Y, A) ```
instruction
0
7,050
17
14,100
Yes
output
1
7,050
17
14,101
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. Submitted Solution: ``` def main(): n,l,x,y = map(int,input().split()) arr = set(map(int,input().split())) first = False second = False for i in arr: if i+x in arr: first = True if i+y in arr: second = True if first and not second: print(1) print(y) return if second and not first: print(1) print(x) return if first and second: print(0) return found = False for i in arr: if i+x-y in arr and i+x <= l: found = True coord = i+x break if i+y-x in arr and i+y <= l: found = True coord = i+y break if i+x+y in arr and i+min(x,y) <= l: found = True coord = i+min(x,y) if i-x-y in arr and i-max(x,y) >= 0: found = True coord = i-max(x,y) if i-x+y in arr and i-x >= 0: found = True coord = i-x break if i-y+x in arr and i-y >= 0: found = True coord = i-y break if found: break if found: print(1) print(coord) return print(2) print(x,y) main() ```
instruction
0
7,051
17
14,102
Yes
output
1
7,051
17
14,103
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. Submitted Solution: ``` def main(): import sys tokens = [int(i) for i in sys.stdin.read().split()] tokens.reverse() n, l, x, y = [tokens.pop() for i in range(4)] marks = set(tokens) x_index = y_index = sum_index = sub_index1 = sub_index2 = -1 for i in marks: if i + x in marks: x_index = y if i + y in marks: y_index = x if i + x + y in marks: sum_index = i + x if i + y - x in marks and i - x >= 0: sub_index1 = i - x if i + y - x in marks and i + y <= l: sub_index2 = i + y if x_index != -1 and y_index != -1: print(0) else: for i in (x_index, y_index, sum_index, sub_index1, sub_index2): if i != -1: print(1) print(i) break else: print(2) print(x, y) main() ```
instruction
0
7,052
17
14,104
Yes
output
1
7,052
17
14,105
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. Submitted Solution: ``` n, l, x, y = map(int, input().split()) a = set(map(int, input().split())) ok1 = ok2 = ok3 = False for c in a: if c + x in a: ok1 = True if c + y in a: ok2 = True if c - x > 0 and c - x + y in a: ok3 = True mark = c - x if c + x < l and c + x - y in a: ok3 = True mark = c + x if c + x + y in a: ok3 = True mark = c + x if c - x - y in a: ok3 = True mark = c - x if ok1 and ok2: print(0) elif (not ok1) and (not ok2): if ok3: print(1) print(mark) else: print(2) print(x, y) else: print(1) print(y if ok1 else x) ```
instruction
0
7,053
17
14,106
Yes
output
1
7,053
17
14,107
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. Submitted Solution: ``` if __name__ == "__main__": n, l, x, y = list(map(int, input().split())) v = list(map(int, input().split())) s = set(v) cx = 0 for i in range(n): if v[i]+x in s: cx = 1 break cy = 0 for i in range(n): if v[i]+y in s: cy = 1 break count = 0 ans = [] if cx==0: count += 1 ans.append(x) if cy==0: count += 1 ans.append(y) if count==2: for i in range(n): if (v[i]+x+y in s): count = 1 ans = [v[i]+x] break if count==2: for i in range(n): if (v[i]+x-y in s): if v[i]+x<=l: count = 1 ans = [v[i]+x] break elif v[i]-y<=l: count = 1 ans = [v[i]-y] break print(count) if count!=0: print(*ans) ```
instruction
0
7,054
17
14,108
No
output
1
7,054
17
14,109
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. Submitted Solution: ``` class CodeforcesTask480BSolution: def __init__(self): self.result = '' self.n_l_x_y = [] self.ruler = [] def read_input(self): self.n_l_x_y = [int(x) for x in input().split(" ")] self.ruler = [int(x) for x in input().split(" ")] def process_task(self): dists = {} for a in self.ruler: dists[a] = True hasx = False hasy = False for a in self.ruler: try: if dists[a - self.n_l_x_y[2]]: hasx = True except KeyError: pass try: if dists[a + self.n_l_x_y[2]]: hasx = True except KeyError: pass try: if dists[a - self.n_l_x_y[3]]: hasy = True except KeyError: pass try: if dists[a - self.n_l_x_y[3]]: hasy = True except KeyError: pass if hasx and hasy: break if hasx and hasy: self.result = "0" elif hasx: self.result = "1\n{0}".format(self.n_l_x_y[3]) elif hasy: self.result = "1\n{1}".format(self.n_l_x_y[2]) else: res = [0, 0] sgn = False dst = self.n_l_x_y[2] + self.n_l_x_y[3] diff = self.n_l_x_y[3] - self.n_l_x_y[2] for a in self.ruler: try: if dists[a - dst]: sgn = True res = a - self.n_l_x_y[2] except KeyError: pass try: if dists[a + dst]: sgn = True res = a + self.n_l_x_y[2] except KeyError: pass try: if dists[a - diff]: sgn = True res = a + self.n_l_x_y[2] except KeyError: pass try: if dists[a + diff]: sgn = True res = a - self.n_l_x_y[2] except KeyError: pass if sgn: break if sgn: self.result = "1\n{0}".format(res) else: self.result = "2\n{0} {1}".format(self.n_l_x_y[2], self.n_l_x_y[3]) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask480BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
instruction
0
7,055
17
14,110
No
output
1
7,055
17
14,111
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. Submitted Solution: ``` def search(a,k,n): i=0 l=n-1 while(i<=l): mid=(i+l)//2 if a[mid]==k: return 1 elif a[mid]<k: i=mid+1 else: l=mid-1 return 0 def count(b,x,n): sum=0 i=0 l=0 while(i<n and l<n): #print(sum) if sum<x: #print(l) sum=sum+b[l] l=l+1 if sum>x: sum=sum-b[i] i=i+1 if sum==x: return 1 return 0 def two(a,n): for i in range(n): t=a[i]+x p=a[i]-x q=a[i]+y w=a[i]-y if search(a,t+y,n)!=0 or search(a,abs(t-y),n)!=0: return t if search(a,p+y,n)!=0 or search(a,abs(p-y),n)!=0: return p if search(a,q+x,n)!=0 or search(a,abs(q-x),n)!=0: return q if search(a,w+x,n)!=0 or search(a,abs(w-x),n)!=0: return w return 0 n,l,x,y=[int(i) for i in input().split()] a=[int(i) for i in input().split()] b=[] for i in range(n-1): t=a[i+1]-a[i] b.append(t) #print(b) nl=len(b) k1=count(b,x,nl) k2=count(b,y,nl) #print(k1,k2) if k1==1 and k2==1: print(0) elif k1==0 and k2==0: z=two(a,n) if z>l: z=z-(x+y) if z<0: z=0 if z==0: print(2) print(x,y) else: print(1) print(z) elif k1==0: print(1) print(x) else: print(1) print(y) ```
instruction
0
7,056
17
14,112
No
output
1
7,056
17
14,113
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. Input The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 105, 2 ≀ l ≀ 109, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin. Output In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p1, p2, ..., pv (0 ≀ pi ≀ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. Examples Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 Note In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills. Submitted Solution: ``` if __name__ == "__main__": n, l, x, y = list(map(int, input().split())) v = list(map(int, input().split())) s = set(v) cx = 0 for i in range(n): if v[i]+x in s: cx = 1 break cy = 0 for i in range(n): if v[i]+y in s: cy = 1 break count = 0 ans = [] if cx==0: count += 1 ans.append(x) if cy==0: count += 1 ans.append(y) if count==2: for i in range(n): if (v[i]+x+y in s) or (v[i]+x-y in s): ans = [v[i]+x] break print(count) if count!=0: print(*ans) ```
instruction
0
7,057
17
14,114
No
output
1
7,057
17
14,115
Provide tags and a correct Python 3 solution for this coding contest problem. This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai. Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1, a2, ..., an repeated m times). After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no k neighboring participants from the same city. Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected. Input The first line contains three integers n, k and m (1 ≀ n ≀ 105, 2 ≀ k ≀ 109, 1 ≀ m ≀ 109). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105), where ai is the number of city, person from which must take seat i in the bus. Output Output the number of remaining participants in the line. Examples Input 4 2 5 1 2 3 1 Output 12 Input 1 9 10 1 Output 1 Input 3 2 10 1 2 1 Output 0 Note In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line.
instruction
0
7,224
17
14,448
Tags: data structures, implementation Correct Solution: ``` import sys from collections import deque input=sys.stdin.readline n,k,m=map(int,input().split()) a=list(map(int,input().split())) r=a[0] flag=0 for i in range(n): if r!=a[i]: flag=1 break if flag==0: print((m*n)%k) sys.exit() if k>n: print(m*n) sys.exit() curr=a[0] tmp=1 que=deque([(a[0],1)]) for i in range(1,n): if a[i]==curr: tmp+=1 que.append((a[i],tmp)) if tmp==k: for j in range(k): que.pop() if que: tmp=que[-1][1] curr=que[-1][0] else: curr=-1 else: tmp=1 curr=a[i] que.append((a[i],tmp)) quecop=[] for i in que: quecop.append(i[0]) leftrem=0 rightrem=0 if not que: print(0) sys.exit() while que[0][0]==que[-1][0]: r=que[0][0] count1=0 p=len(que) count2=p-1 while count1<p and que[count1][0]==r: count1+=1 if count1==p: break while count2>=0 and que[count2][0]==r: count2-=1 if count1+p-1-count2<k: break leftrem+=count1 rightrem+=k-count1 for i in range(count1): que.popleft() for i in range(k-count1): que.pop() if que: t=que[0][0] flag=0 for i in que: if i[0]!=t: flag=1 break if flag: print(leftrem+rightrem+len(que)*m) else: r=[] for i in range(leftrem): if r and r[-1][0]==quecop[i]: r[-1][1]+=1 else: r.append([quecop[i],1]) if r and r[-1][0]==que[0][0]: r[-1][0]=(r[-1][0]+(len(que)*m))%k if r[-1][1]==0: r.pop() else: if (len(que)*m)%k: r.append([que[0][0],(len(que)*m)%k]) for i in range(len(quecop)-rightrem,len(quecop)): if r and r[-1][0]==quecop[i]: r[-1][1]+=1 if r[-1][1]==k: r.pop() else: r.append([quecop[i],1]) finans=0 for i in r: finans+=i[1] print(finans) ```
output
1
7,224
17
14,449
Provide tags and a correct Python 3 solution for this coding contest problem. This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai. Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1, a2, ..., an repeated m times). After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no k neighboring participants from the same city. Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected. Input The first line contains three integers n, k and m (1 ≀ n ≀ 105, 2 ≀ k ≀ 109, 1 ≀ m ≀ 109). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105), where ai is the number of city, person from which must take seat i in the bus. Output Output the number of remaining participants in the line. Examples Input 4 2 5 1 2 3 1 Output 12 Input 1 9 10 1 Output 1 Input 3 2 10 1 2 1 Output 0 Note In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line.
instruction
0
7,225
17
14,450
Tags: data structures, implementation Correct Solution: ``` def process(A, m, k): n = len(A) start = n*m d = [] for i in range(n): if len(d)==0 or d[-1][0] != A[i]: d.append([A[i], 1]) else: d[-1][1]+=1 if d[-1][1]==k: start-=k*m d.pop() if m==1: return start p1 = 0 start_d = [] middle_d = [] end_d = [] for x in d: a, b = x start_d.append([a, b]) middle_d.append([a, b]) end_d.append([a, b]) if m==2: middle_d = [] else: middle_d = [x for x in d] # print(start_d, middle_d, end_d, start) #the sequence is start_d + (m-2)* middle_d + end_d while True: if p1 >= len(middle_d): if len(start_d)==0 or p1==len(end_d): break v1, c1 = start_d[-1] v2, c2 = end_d[p1] if v1==v2 and (c1+c2) >= k: start-=k start_d.pop() if (c1+c2)==k: p1+=1 else: end_d[1] = (c1+c2) % k else: break else: if len(middle_d)-p1==1: v1, c1 = start_d[-1] v2, c2 = middle_d[p1] v3, c3 = end_d[p1] total_value = c2*(m-2) if v2==v1: total_value+=c1 if v2==v3: total_value+=c3 start-=(total_value-(total_value%k)) if total_value % k==0: middle_d = [] if v2==v1: start_d.pop() if v2==v3: end_d = end_d p1+=1 else: break else: v1, c1 = start_d[-1] v2, c2 = middle_d[p1] v3, c3 = middle_d[-1] v4, c4 = end_d[p1] if v2==v3 and (c2+c3) >= k: this_value = (c2+c3-(c2+c3) % k)*(m-1) start-=this_value middle_d.pop() start_d.pop() middle_d[p1][1] = (c2+c3) % k end_d[p1][1] = (c2+c3) % k if middle_d[p1][1]==0: p1+=1 else: break # print('start', start_d, start) # print('middle', middle_d) # print('end', end_d) return start n, k, m = [int(x) for x in input().split()] A = [int(x) for x in input().split()] print(process(A, m, k)) ```
output
1
7,225
17
14,451
Provide tags and a correct Python 3 solution for this coding contest problem. This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai. Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1, a2, ..., an repeated m times). After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no k neighboring participants from the same city. Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected. Input The first line contains three integers n, k and m (1 ≀ n ≀ 105, 2 ≀ k ≀ 109, 1 ≀ m ≀ 109). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105), where ai is the number of city, person from which must take seat i in the bus. Output Output the number of remaining participants in the line. Examples Input 4 2 5 1 2 3 1 Output 12 Input 1 9 10 1 Output 1 Input 3 2 10 1 2 1 Output 0 Note In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line.
instruction
0
7,226
17
14,452
Tags: data structures, implementation Correct Solution: ``` def main(): _, k, m = [int(x) for x in input().split()] a = [] last = ("-1", 0) a.append(last) for ai in input().split(): if last[0] == ai: last = (ai, last[1]+1) a[-1] = last else: last = (ai, 1) a.append(last) if last[1] == k: a.pop() last = a[-1] a.pop(0) s1 = 0 while len(a) > 0 and a[0][0] == a[-1][0]: if len(a) == 1: s = a[0][1] * m r1 = s % k if r1 == 0: print(s1 % k) else: print(r1 + s1) return join = a[0][1] + a[-1][1] if join < k: break elif join % k == 0: s1 += join a.pop() a.pop(0) else: s1 += (join // k) * k a[0] = (a[0][0], join % k) a.pop() break s = 0 for ai in a: s += ai[1] print(s*m + s1) if __name__ == "__main__": main() ```
output
1
7,226
17
14,453
Provide tags and a correct Python 3 solution for this coding contest problem. This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai. Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1, a2, ..., an repeated m times). After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no k neighboring participants from the same city. Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected. Input The first line contains three integers n, k and m (1 ≀ n ≀ 105, 2 ≀ k ≀ 109, 1 ≀ m ≀ 109). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105), where ai is the number of city, person from which must take seat i in the bus. Output Output the number of remaining participants in the line. Examples Input 4 2 5 1 2 3 1 Output 12 Input 1 9 10 1 Output 1 Input 3 2 10 1 2 1 Output 0 Note In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line.
instruction
0
7,227
17
14,454
Tags: data structures, implementation Correct Solution: ``` #reference sol:-31772413 r=lambda:map(int,input().split()) n,k,m=r() a=list(r()) stck=[] for i in range(n): if len(stck)==0 or stck[-1][0]!=a[i]: stck.append([a[i],1]) else: stck[-1][1]+=1 if stck[-1][1]==k: stck.pop() rem=0 strt,end=0,len(stck)-1 if m > 1: while end-strt+1 > 1 and stck[strt][0]==stck[end][0]: join=stck[strt][1]+stck[end][1] if join < k: break elif join % k==0: rem+=join strt+=1 end-=1 else: stck[strt][1]=join % k stck[end][1]=0 rem+=(join//k)*k tr=0 slen=end-strt+1 for el in stck[:slen]: tr+=el[1] if slen==0: print(0) elif slen==1: r=(stck[strt][1]*m)%k if r==0: print(0) else: print(r+rem) else: print(tr*m+rem) ```
output
1
7,227
17
14,455
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai. Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1, a2, ..., an repeated m times). After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no k neighboring participants from the same city. Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected. Input The first line contains three integers n, k and m (1 ≀ n ≀ 105, 2 ≀ k ≀ 109, 1 ≀ m ≀ 109). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105), where ai is the number of city, person from which must take seat i in the bus. Output Output the number of remaining participants in the line. Examples Input 4 2 5 1 2 3 1 Output 12 Input 1 9 10 1 Output 1 Input 3 2 10 1 2 1 Output 0 Note In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line. Submitted Solution: ``` import queue def readTuple(): return input().split() def readInts(): return tuple(map(int, readTuple())) def solve(): n, k, m = readInts() nums = [] cnt = 0 for i in readInts(): if nums and i == nums[-1][0]: nums[-1][1] +=1 if nums[-1][1] == k: nums.pop() continue nums.append([i,1]) i, j = 0, len(nums)-1 comm = 0 while i<j: if nums[i][0] == nums[j][0] \ and nums[i][1]+nums[j][1] <= k: if nums[i][1]+nums[j][1] == k: comm +=1 else: break i+=1 j-=1 mid = len(nums)-2*comm prefix_sum = sum(map(lambda x: x[1], nums[:comm])) middle_sum = sum(map(lambda x: x[1], nums[comm:comm+mid])) suffix_sum = sum(map(lambda x: x[1], nums[comm+mid:])) all_sum = (prefix_sum+suffix_sum+middle_sum)*m # print(nums) # print("prefix: ", comm, "SUM: ", prefix_sum) # print("mid: ", mid, "SUM: ", middle_sum) # print("suffix: ", comm, "SUM: ", suffix_sum) # print("ALL: ", all_sum) # subtract perfect matches all_sum -= (prefix_sum+suffix_sum)*(m-1) if mid == 0: all_sum = 0 elif mid == 1: if (middle_sum*m)%k == 0: all_sum = 0 else: all_sum -= middle_sum*m all_sum += (middle_sum*m)%k else: if nums[comm][0] == nums[-comm-1][0] \ and nums[comm][1]+nums[-comm-1][1] > k: all_sum -= k*(m-1) print(all_sum) if __name__ == '__main__': solve() ```
instruction
0
7,228
17
14,456
No
output
1
7,228
17
14,457
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai. Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1, a2, ..., an repeated m times). After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no k neighboring participants from the same city. Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected. Input The first line contains three integers n, k and m (1 ≀ n ≀ 105, 2 ≀ k ≀ 109, 1 ≀ m ≀ 109). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105), where ai is the number of city, person from which must take seat i in the bus. Output Output the number of remaining participants in the line. Examples Input 4 2 5 1 2 3 1 Output 12 Input 1 9 10 1 Output 1 Input 3 2 10 1 2 1 Output 0 Note In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line. Submitted Solution: ``` from collections import deque n,k,m=map(int,input().split()) queue = deque() A = list(map(int,input().split())) for j in range(n): if queue: per = queue.pop() if A[j] == per[0]: per[1] +=1 if per[1] !=k: queue.append(per) else: queue.append(per) queue.append([A[j],1]) else: queue.append([A[j],1]) lens = len(queue) queue = list(queue) #print(queue) if lens ==0: print(0) elif m == 1: ans =0 for j in range(lens): ans+=queue[j][1] print(ans) elif lens%2==0: p = 0 for j in range(lens//2): if queue[j][0] == queue[-(j+1)][0] and queue[j][1] + queue[-(j+1)][1] == k: p+=1 #print(p) ans = 0 l=0 if p != lens//2: for j in range(lens-1,lens-1-p,-1): ans-=queue[j][1] ans-=queue[-(j+1)][1] ans*=(m-1) for j in range(lens): l+=queue[j][1] ans+=l*m print(ans) #print(l*m) else: #print('huyznaet') p = 0 for j in range(lens//2): if queue[j][0] == queue[-(j+1)][0] and queue[j][1] + queue[-(j+1)][1] == k: p+=1 #print(p) ans = 0 l=0 if p != lens//2: for j in range(lens-1,lens-1-p,-1): ans-=queue[j][1] ans-=queue[-(j+1)][1] ans*=(m-1) for j in range(lens): l+=queue[j][1] ans+=l*m print(ans) #print(pizda) else: if(m*queue[lens//2][1])%k==0: print(0) else: l=0 for j in range(lens): l+=queue[j][1] l-= queue[lens//2][1] l+=(m*queue[lens//2][1])%k print(l) #print(l*m) ```
instruction
0
7,229
17
14,458
No
output
1
7,229
17
14,459
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai. Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1, a2, ..., an repeated m times). After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no k neighboring participants from the same city. Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected. Input The first line contains three integers n, k and m (1 ≀ n ≀ 105, 2 ≀ k ≀ 109, 1 ≀ m ≀ 109). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105), where ai is the number of city, person from which must take seat i in the bus. Output Output the number of remaining participants in the line. Examples Input 4 2 5 1 2 3 1 Output 12 Input 1 9 10 1 Output 1 Input 3 2 10 1 2 1 Output 0 Note In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line. Submitted Solution: ``` n,k,m = input().strip().split() n = int(n) k = int(k) m = int(m) a = list(map(int, input().strip().split())) x = [] kol = 1 for i in range(n): if i ==0: x.append((a[i],kol)) else: if a[i] == a[i-1]: kol +=1 x.append((a[i],kol)) else: kol = 1 x.append((a[i],kol)) if n>1: y = [] for i in range(n+1): y.append(1) pre = 0 nex = 1 z = {} tup = {} tup[0] =1 kol =1 while nex <n: if nex not in tup: tup[nex] = nex-1 if a[nex] == a[pre]: y[nex] = y[pre] + kol kol = kol + 1 else: kol = 1 pre = nex if y[nex] ==k: kol = 1 z[pre- y[pre] +1] = nex if pre ==0: pre = nex nex = nex + 1 else: pre = tup[pre - y[pre] + 1] tup[nex + 1] = nex - y[nex] nex = nex + 1 i = 0 p =[] while i <= n-1: if i in z: i = z[i] +1 else: p.append(a[i]) i = i +1 a = p[:] n = len(a) i = n-1 s = 2 * n l=0 if len(a) ==0: print(0) else: if k>=n: for i in range(n): if (i>0 and a[i]!=a[i-1]): l =1 break if l==1: print(n*m) else: if k <= n*m: print((n *m) % k) else: print(n*m) else: l=0 for i in range(n//2): if a[i] != a[n - i-1]: l = 1 if l==0: print(0) else: s = 0 i = n-1 while i >= n //2 - 1: if x[i] == x[n -1 - i + x[i][1] - 1] and x[i][1] * 2 >=k: if i !=n -1 - i + x[i][1] - 1: s += ((x[i][1] *2 //k) * k) * (m-1) else: s+= x[i][1] * m i = i - ((x[i][1] *2 //k) * k)//2 else: i = -1 break s = n*m-s print(s) ```
instruction
0
7,230
17
14,460
No
output
1
7,230
17
14,461
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai. Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in one line in the order they arrived, with people from the same bus standing in the order of their seats (i. e. if we write down the cities where the participants came from, we get the sequence a1, a2, ..., an repeated m times). After that some teams were formed, each consisting of k participants form the same city standing next to each other in the line. Once formed, teams left the line. The teams were formed until there were no k neighboring participants from the same city. Help the organizers determine how many participants have left in the line after that process ended. We can prove that answer doesn't depend on the order in which teams were selected. Input The first line contains three integers n, k and m (1 ≀ n ≀ 105, 2 ≀ k ≀ 109, 1 ≀ m ≀ 109). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 105), where ai is the number of city, person from which must take seat i in the bus. Output Output the number of remaining participants in the line. Examples Input 4 2 5 1 2 3 1 Output 12 Input 1 9 10 1 Output 1 Input 3 2 10 1 2 1 Output 0 Note In the second example, the line consists of ten participants from the same city. Nine of them will form a team. At the end, only one participant will stay in the line. Submitted Solution: ``` # -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random import itertools import sys """ created by shhuan at 2017/10/28 16:57 """ N, K, M = map(int, input().split()) A = [int(x) for x in input().split()] def group(a, k): if not a: return [] if len(a) < k: return a ans = [] p = a[0] c = 1 for v in a[1:]: if v == p: c += 1 if c == k: c = 0 else: ans += [p] * c p = v c = 1 ans += [p] * c return ans A = group(A, K) rem = [] found = True while A and found: found = False if len(set(A)) == 1: A = [A[0]] * ((len(A)*M) % K) M %= K break else: if K > 2*len(A): break i = 2 a = group(A*i, K) if a and len(a) != len(A)*i: rem = A * (M%i) + rem A = a M //= i found = True break A = group(A*M+rem, K) if A: print(len(A)) else: print(0) ```
instruction
0
7,231
17
14,462
No
output
1
7,231
17
14,463
Provide tags and a correct Python 3 solution for this coding contest problem. There are n football teams in the world. The Main Football Organization (MFO) wants to host at most m games. MFO wants the i-th game to be played between the teams a_i and b_i in one of the k stadiums. Let s_{ij} be the numbers of games the i-th team played in the j-th stadium. MFO does not want a team to have much more games in one stadium than in the others. Therefore, for each team i, the absolute difference between the maximum and minimum among s_{i1}, s_{i2}, …, s_{ik} should not exceed 2. Each team has w_i β€” the amount of money MFO will earn for each game of the i-th team. If the i-th team plays l games, MFO will earn w_i β‹… l. MFO needs to find what games in what stadiums they need to host in order to earn as much money as possible, not violating the rule they set. However, this problem is too complicated for MFO. Therefore, they are asking you to help them. Input The first line contains three integers n, m, k (3 ≀ n ≀ 100, 0 ≀ m ≀ 1 000, 1 ≀ k ≀ 1 000) β€” the number of teams, the number of games, and the number of stadiums. The second line contains n integers w_1, w_2, …, w_n (1 ≀ w_i ≀ 1 000) β€” the amount of money MFO will earn for each game of the i-th game. Each of the following m lines contains two integers a_i and b_i (1 ≀ a_i, b_i ≀ n, a_i β‰  b_i) β€” the teams that can play the i-th game. It is guaranteed that each pair of teams can play at most one game. Output For each game in the same order, print t_i (1 ≀ t_i ≀ k) β€” the number of the stadium, in which a_i and b_i will play the game. If the i-th game should not be played, t_i should be equal to 0. If there are multiple answers, print any. Example Input 7 11 3 4 7 8 10 10 9 3 6 2 6 1 7 6 4 3 4 6 3 1 5 3 7 5 7 3 4 2 1 4 Output 3 2 1 1 3 1 2 1 2 3 2 Note One of possible solutions to the example is shown below: <image>
instruction
0
7,666
17
15,332
Tags: graphs Correct Solution: ``` import random import math def set_color(game, color): color_count[game[0]][game[2]] -= 1 color_count[game[1]][game[2]] -= 1 game[2] = color color_count[game[0]][game[2]] += 1 color_count[game[1]][game[2]] += 1 def fix(node): minimum = math.inf maximum = 0 for i in range(k): minimum = min(minimum, color_count[node][i]) maximum = max(maximum, color_count[node][i]) if maximum - minimum <= 2: return False rand = 0 for game in games: if (game[0] == node or game[1] == node) and color_count[node][game[2]] == maximum: rand = r(1,k) set_color(game, rand % k) return True return False n, m, k = map(int,input().split()) games = [[0 for _ in range(4)] for _ in range(m)] color_count = [[0 for _ in range(k)] for _ in range(n)] answers = [0 for _ in range(m)] _ = list(map(int,input().split())) color = 0 r = lambda x,y : random.randint(x,y) for i in range(m): a, b = map(int,input().split()) color = r(1,k) % k games[i] = [a-1,b-1,color,i] color_count[games[i][0]][color] += 1 color_count[games[i][1]][color] += 1 bad = True while bad: random.shuffle(games) bad = False for i in range(n): while(fix(i)): bad = True for game in games: answers[game[3]] = game[2] + 1 for i in range(m): print(answers[i]) ```
output
1
7,666
17
15,333
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n football teams in the world. The Main Football Organization (MFO) wants to host at most m games. MFO wants the i-th game to be played between the teams a_i and b_i in one of the k stadiums. Let s_{ij} be the numbers of games the i-th team played in the j-th stadium. MFO does not want a team to have much more games in one stadium than in the others. Therefore, for each team i, the absolute difference between the maximum and minimum among s_{i1}, s_{i2}, …, s_{ik} should not exceed 2. Each team has w_i β€” the amount of money MFO will earn for each game of the i-th team. If the i-th team plays l games, MFO will earn w_i β‹… l. MFO needs to find what games in what stadiums they need to host in order to earn as much money as possible, not violating the rule they set. However, this problem is too complicated for MFO. Therefore, they are asking you to help them. Input The first line contains three integers n, m, k (3 ≀ n ≀ 100, 0 ≀ m ≀ 1 000, 1 ≀ k ≀ 1 000) β€” the number of teams, the number of games, and the number of stadiums. The second line contains n integers w_1, w_2, …, w_n (1 ≀ w_i ≀ 1 000) β€” the amount of money MFO will earn for each game of the i-th game. Each of the following m lines contains two integers a_i and b_i (1 ≀ a_i, b_i ≀ n, a_i β‰  b_i) β€” the teams that can play the i-th game. It is guaranteed that each pair of teams can play at most one game. Output For each game in the same order, print t_i (1 ≀ t_i ≀ k) β€” the number of the stadium, in which a_i and b_i will play the game. If the i-th game should not be played, t_i should be equal to 0. If there are multiple answers, print any. Example Input 7 11 3 4 7 8 10 10 9 3 6 2 6 1 7 6 4 3 4 6 3 1 5 3 7 5 7 3 4 2 1 4 Output 3 2 1 1 3 1 2 1 2 3 2 Note One of possible solutions to the example is shown below: <image> Submitted Solution: ``` print("submit") ```
instruction
0
7,667
17
15,334
No
output
1
7,667
17
15,335
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n football teams in the world. The Main Football Organization (MFO) wants to host at most m games. MFO wants the i-th game to be played between the teams a_i and b_i in one of the k stadiums. Let s_{ij} be the numbers of games the i-th team played in the j-th stadium. MFO does not want a team to have much more games in one stadium than in the others. Therefore, for each team i, the absolute difference between the maximum and minimum among s_{i1}, s_{i2}, …, s_{ik} should not exceed 2. Each team has w_i β€” the amount of money MFO will earn for each game of the i-th team. If the i-th team plays l games, MFO will earn w_i β‹… l. MFO needs to find what games in what stadiums they need to host in order to earn as much money as possible, not violating the rule they set. However, this problem is too complicated for MFO. Therefore, they are asking you to help them. Input The first line contains three integers n, m, k (3 ≀ n ≀ 100, 0 ≀ m ≀ 1 000, 1 ≀ k ≀ 1 000) β€” the number of teams, the number of games, and the number of stadiums. The second line contains n integers w_1, w_2, …, w_n (1 ≀ w_i ≀ 1 000) β€” the amount of money MFO will earn for each game of the i-th game. Each of the following m lines contains two integers a_i and b_i (1 ≀ a_i, b_i ≀ n, a_i β‰  b_i) β€” the teams that can play the i-th game. It is guaranteed that each pair of teams can play at most one game. Output For each game in the same order, print t_i (1 ≀ t_i ≀ k) β€” the number of the stadium, in which a_i and b_i will play the game. If the i-th game should not be played, t_i should be equal to 0. If there are multiple answers, print any. Example Input 7 11 3 4 7 8 10 10 9 3 6 2 6 1 7 6 4 3 4 6 3 1 5 3 7 5 7 3 4 2 1 4 Output 3 2 1 1 3 1 2 1 2 3 2 Note One of possible solutions to the example is shown below: <image> Submitted Solution: ``` def football(tgs, total_money_game, game): played = [] stadion_played = [] same_stadion = [] stadion_r = tgs[2] s_stadion = 1 stadion = [] for i in range(0, tgs[1]): if game[i] not in played: played.append(game[i]) for j in range(tgs[2],0,-1): if j not in stadion_played: stadion_played.append(j) stadion.append(j) break else: if len(stadion_played) == tgs[2]: if same_stadion.count(s_stadion) > 1: same_stadion = [] s_stadion += 1 if stadion_r == 0: stadion_r = 3 stadion_played.remove(stadion_r) stadion_played.remove(s_stadion) stadion_played.append(s_stadion) stadion.append(s_stadion) same_stadion.append(s_stadion) if stadion_r >= 1: stadion_r -= 1 else: stadion_r = tgs[2] break return stadion tgs = [7, 11, 3] total_money_game = [4, 7, 8, 10, 10, 9, 3] game = [[6, 2],[6, 1],[7, 6],[4, 3],[4, 6],[3, 1],[5, 3],[7, 5],[7, 3],[4, 2],[1, 4]] stadions = football(tgs, total_money_game, game) ```
instruction
0
7,668
17
15,336
No
output
1
7,668
17
15,337
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n football teams in the world. The Main Football Organization (MFO) wants to host at most m games. MFO wants the i-th game to be played between the teams a_i and b_i in one of the k stadiums. Let s_{ij} be the numbers of games the i-th team played in the j-th stadium. MFO does not want a team to have much more games in one stadium than in the others. Therefore, for each team i, the absolute difference between the maximum and minimum among s_{i1}, s_{i2}, …, s_{ik} should not exceed 2. Each team has w_i β€” the amount of money MFO will earn for each game of the i-th team. If the i-th team plays l games, MFO will earn w_i β‹… l. MFO needs to find what games in what stadiums they need to host in order to earn as much money as possible, not violating the rule they set. However, this problem is too complicated for MFO. Therefore, they are asking you to help them. Input The first line contains three integers n, m, k (3 ≀ n ≀ 100, 0 ≀ m ≀ 1 000, 1 ≀ k ≀ 1 000) β€” the number of teams, the number of games, and the number of stadiums. The second line contains n integers w_1, w_2, …, w_n (1 ≀ w_i ≀ 1 000) β€” the amount of money MFO will earn for each game of the i-th game. Each of the following m lines contains two integers a_i and b_i (1 ≀ a_i, b_i ≀ n, a_i β‰  b_i) β€” the teams that can play the i-th game. It is guaranteed that each pair of teams can play at most one game. Output For each game in the same order, print t_i (1 ≀ t_i ≀ k) β€” the number of the stadium, in which a_i and b_i will play the game. If the i-th game should not be played, t_i should be equal to 0. If there are multiple answers, print any. Example Input 7 11 3 4 7 8 10 10 9 3 6 2 6 1 7 6 4 3 4 6 3 1 5 3 7 5 7 3 4 2 1 4 Output 3 2 1 1 3 1 2 1 2 3 2 Note One of possible solutions to the example is shown below: <image> Submitted Solution: ``` import operator import collections import sys #User enters file line of input as n m k which gets split into the different variables n, m, k = input().split(' ') #input("Enter number of teams, matches and stadiums: ").split(' ') #User enters second line of input as value1 value2 value3......valuen which gets split as an array money = input().split(' ') # input("Enter amount of money earned per team in the order of the teams: ").split(' ') #Defining an empty array to get the list of matches played between the teams. matches_list = [] if int(m) == 0: #print("Sorry. No matches this year :(") sys.exit(0) for i in range(int(m)): #User enters team input as team1 team2 which gets split into a tuple which is further appended into the "matches_list" #team1, team2 = input(f"Enter teams that play match {str(i+1)}: ").split(' ') team1, team2 = input().split(' ') #input("Enter teams that play match: ").split(' ') #team1, team2 = input(str(i+1)) matches_list.append((int(team1), int(team2))) #It is guaranteed that each pair of teams can play at most one game hence not checking if input is unique #Generating stadium numbers as an array stadiums = [i for i in range(1, int(k)+1)] #Sorting the matches played in the order of most valuable to least valuable matches based on the amount earned from the induvidual teams. #Doing this will ensure that the matches with the most earning potential will not be left out in case that particular team cannot play all the given matches because of the "not exceeds 2" rule. matches_on_revenue = {} for match in matches_list: revenue = int(money[match[0]-1]) + int(money[match[1]-1]) matches_on_revenue[match] = revenue matches_on_revenue = sorted(matches_on_revenue.items(), key=operator.itemgetter(1), reverse=True) #Making a note of matches played per stadium so far, number of times a team has played at a stadium and stadium assigned for each match. #Initial values would be 0 or empty and will be updated as we loop through each match while assigning stadiums matches_per_stadium = {i : 0 for i in stadiums} teams_at_stadium = {i : [] for i in stadiums} stadium_for_match = {i[0] : 0 for i in matches_on_revenue} #Create a function which assigns stadiums for each match. The dictionary "stadium_for_match" will be passed to this fucntion def assign_stadium(stadium_for_match): #looping through each match in the dictionary in the order of most valuable to least valuable match. Using Python 3.7 so expecting the order of the dictionary to be preserved. for key, value in stadium_for_match.items(): #Assiging variable n to 0 as stadium has not yet been assigned n = 0 #If a stadium is not yet assigned for a particular match, the fucntion will proceed with the logic for that match else it will skip to next match if not value: try: #Try to fetch a stadium where no matches have been played so far. The "matches per stadium" dictionary comes in handy for this stadium_no = list(matches_per_stadium.keys())[list(matches_per_stadium.values()).index(0)] #if stadium available, setting n to 1 as stadium has been found n=1 except: #if no stadium has 0 matches played, sort the stadiums in the order of least to highest matches played and loop through each stadium stadiums_by_matches = sorted(matches_per_stadium.items(), key=operator.itemgetter(1)) for stadium_by_match in stadiums_by_matches: #Get the stadium number stadium_no = stadium_by_match[0] #For that stadium, find the team that has played the lowest number of matches and get the value of how many matches played by that team. # Ignore the matches played by the teams that are present in the current match because even if we add them, it will be a plus one on both ends and so the difference will still be the same least_common = [i for i in collections.Counter(teams_at_stadium[stadium_no]).most_common() if i[0] != key[0] and i[0] != key[1]][-1][1] #Check the following conditions # 1a) If in current match, team1 has played a match in this stadium. # 1b) If yes, whether the difference between number of matches played by team1 and the number of matches played by the team that has played the lowest in this stadium is less than 2. # 2a) If in current match, team2 has played a match in this stadium. # 2b) If yes, whether the difference between number of matches played by team2 and the number of matches played by the team that has played the lowest in this stadium is less than 2. if ((teams_at_stadium[stadium_no].count(key[0]) == 0) or (abs(teams_at_stadium[stadium_no].count(key[0]) - least_common) < 2)) and ((teams_at_stadium[stadium_no].count(key[1]) == 0) or (abs(teams_at_stadium[stadium_no].count(key[1]) - least_common) < 2) ): #If the above conditions are satisfied, pick this stadium and break the loop. Else move on to the next stadium. n=1 break # If a stadium is found, assign it to the match. # Increment the value of this stadium in the "matches_per_stadium" dictionary by 1. # Add the team numbers in the match to the teams_at_stadium list of this stadium again. if n: stadium_for_match[key] = stadium_no matches_per_stadium[stadium_no] = matches_per_stadium[stadium_no] + 1 teams_at_stadium[stadium_no].append(key[0]) teams_at_stadium[stadium_no].append(key[1]) #If no stadium is found for this match the value will remain 0. #Move to the next match. #Return the final dictionary and also if there were any stadiums found for any matches return stadium_for_match, n #Initially assuming there were stadiums found for matches n = 1 while n: #Call the assign stadium function till there were no changes made to any matches. #The reason for this instead of a single function call is: #Lets say a match was assigned value 0 because it could not fit into any stadium due to the "exceeds 2 rule" #After iterating thorugh the entire dictionary, it may be so that this difference had come down from 2. In those cases, there would be a stadium avalible for a match which was previously not available. stadium_for_match, n = assign_stadium(stadium_for_match) #Once the stadiums are finalized, print the output stadium numbers in the same order as the matches provided in the input. for i in matches_list: print(stadium_for_match[i]) ```
instruction
0
7,669
17
15,338
No
output
1
7,669
17
15,339
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n football teams in the world. The Main Football Organization (MFO) wants to host at most m games. MFO wants the i-th game to be played between the teams a_i and b_i in one of the k stadiums. Let s_{ij} be the numbers of games the i-th team played in the j-th stadium. MFO does not want a team to have much more games in one stadium than in the others. Therefore, for each team i, the absolute difference between the maximum and minimum among s_{i1}, s_{i2}, …, s_{ik} should not exceed 2. Each team has w_i β€” the amount of money MFO will earn for each game of the i-th team. If the i-th team plays l games, MFO will earn w_i β‹… l. MFO needs to find what games in what stadiums they need to host in order to earn as much money as possible, not violating the rule they set. However, this problem is too complicated for MFO. Therefore, they are asking you to help them. Input The first line contains three integers n, m, k (3 ≀ n ≀ 100, 0 ≀ m ≀ 1 000, 1 ≀ k ≀ 1 000) β€” the number of teams, the number of games, and the number of stadiums. The second line contains n integers w_1, w_2, …, w_n (1 ≀ w_i ≀ 1 000) β€” the amount of money MFO will earn for each game of the i-th game. Each of the following m lines contains two integers a_i and b_i (1 ≀ a_i, b_i ≀ n, a_i β‰  b_i) β€” the teams that can play the i-th game. It is guaranteed that each pair of teams can play at most one game. Output For each game in the same order, print t_i (1 ≀ t_i ≀ k) β€” the number of the stadium, in which a_i and b_i will play the game. If the i-th game should not be played, t_i should be equal to 0. If there are multiple answers, print any. Example Input 7 11 3 4 7 8 10 10 9 3 6 2 6 1 7 6 4 3 4 6 3 1 5 3 7 5 7 3 4 2 1 4 Output 3 2 1 1 3 1 2 1 2 3 2 Note One of possible solutions to the example is shown below: <image> Submitted Solution: ``` s = input() if '0' * 7 in s or '1' * 7 in s: print('YES') else: print('NO') ```
instruction
0
7,670
17
15,340
No
output
1
7,670
17
15,341
Provide a correct Python 3 solution for this coding contest problem. B: Dansunau www --Dance Now!- story Last lab life! Daigakuin! !! Dosanko Snow has won 9th place in the event "Master Idol World", which can be said to be the outpost of the biggest competition "Lab Life" where master idols compete. The sharp dance is ridiculed as "9th place dance", and the whole body's deciding pose is also ridiculed as "9th place stance", which causes deep emotional wounds. In the upcoming Lab Life Preliminary Qualifying, we can never take 9th place ... Dosanko Snow, who renewed his determination, refined his special skill "self-control" and headed for the battlefield. .. problem A tournament "Lab Life" will be held in which N groups of units compete. In this tournament, the three divisions of Smile Pure Cool will be played separately, and the overall ranking will be decided in descending order of the total points scored in each game. The ranking of the smile category is determined in descending order of the smile value of each unit. Similarly, in the pure / cool category, the ranking is determined in descending order of pure / cool value. The score setting according to the ranking is common to all divisions, and the unit ranked i in a division gets r_i points in that division. Here, if there are a plurality of units having the same value as the unit with the rank i, they are regarded as the same rate i rank, and the points r_i are equally obtained. More specifically, when k units are in the same ratio i position, k units get equal points r_i, and no unit gets points from r_ {i + 1} to r_ {i + k-1}. Also, the next largest unit (s) gets the score r_ {i + k}. As a specific example, consider a case where there are five units with smile values ​​of 1, 3, 2, 3, and 2, and 10, 8, 6, 4, and 2 points are obtained in descending order of rank. At this time, the 2nd and 4th units will get 10 points, the 3rd and 5th units will get 6 points, and the 1st unit will get 2 points. Unit Dosanko Snow, who participates in the Lab Life Preliminary Qualifying, thinks that "Lab Life is not a play", so he entered the tournament first and became the first unit. However, when we obtained information on the smile value, pure value, and cool value (hereinafter referred to as 3 values) of all N groups participating in the tournament, we found that their overall ranking was (equal rate) 9th. Dosanko Snow can raise any one of the three values ​​by the special skill "Self Control", but if you raise it too much, you will get tired and it will affect the main battle, so you want to make the rise value as small as possible. Dosanko Snow wants to get out of 9th place anyway, so when you raise any one of the 3 values ​​by self-control so that it will be 8th or higher at the same rate, find the minimum value that needs to be raised. Input format The input is given in the following format. N r_1 ... r_N s_1 p_1 c_1 ... s_N p_N c_N The first line is given the integer N, which represents the number of units, in one line. The second line that follows is given N integers separated by blanks. The i (1 \ leq i \ leq N) th integer represents the score r_i that can be obtained when the ranking is i in each division. Of the following Nth line, the jth line is given three integers s_j, p_j, c_j. These represent the smile value s_j, pure value p_j, and cool value c_j of the jth unit, respectively. Dosanko Snow is the first unit. Constraint * 9 \ leq N \ leq 100 * 100 \ geq r_1> ...> r_N \ geq 1 * 1 \ leq s_j, p_j, c_j \ leq 100 (1 \ leq j \ leq N) * Before self-control, Dosanko Snow was 9th (sometimes 9th, but never more than 8th) Output format By increasing any of the three values ​​by x by self-control, output the minimum x that makes Dosanko Snow 8th or higher at the same rate on one line. However, if self-control does not raise the ranking no matter how much you raise it, output "Saiko". Input example 1 9 9 8 7 6 5 4 3 2 1 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 Output example 1 2 For example, if you raise the smile value by 2 by self-control, the rankings in each division of Dosanko Snow will be 7th, 9th, and 9th, respectively, and you will get 3 + 1 + 1 = 5 points. On the other hand, the ranking of the second unit in each division is 9th, 8th, and 8th, respectively, and 1 + 2 + 2 = 5 points are obtained. Since the other units get 6 points or more, these two units will be ranked 8th at the same rate, satisfying the conditions. Input example 2 9 9 8 7 6 5 4 3 2 1 1 1 1 2 6 9 6 9 2 9 2 6 3 5 8 5 8 3 8 3 5 4 7 4 7 4 7 Output example 2 Saiko No matter how much you raise the value, Dosanko Snow can only get up to 11 points, but other units can always get 14 points or more, so Dosanko Snow is immovable in 9th place. Example Input 9 9 8 7 6 5 4 3 2 1 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 Output 2
instruction
0
8,357
17
16,714
"Correct Solution: ``` import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline n = int(input()) R = list(map(int,input().split())) SPC = [] S = [] P = [] C = [] ans = 10**5 for i in range(n): s,p,c = map(int,input().split()) S.append(s) P.append(p) C.append(c) SPC.append([s,p,c]) you = list(SPC[0]) for delta in range(1,102-you[0]): S[0] = you[0] + delta SPC[0][0] = S[0] Ssort = sorted(S,reverse = True) Psort = sorted(P,reverse = True) Csort = sorted(C,reverse = True) pointS = {} pointP = {} pointC = {} for r,s,p,c in zip(R,Ssort,Psort,Csort): if s not in pointS:pointS[s] = r if p not in pointP:pointP[p] = r if c not in pointC:pointC[c] = r point = [pointS[s]+pointP[p]+pointC[c] for s,p,c in SPC] if sorted(point,reverse = True).index(point[0]) != 8: ans = min(ans,delta) break S[0] = you[0] SPC[0] = you.copy() for delta in range(1,102-you[1]): P[0] = you[1] + delta SPC[0][1] = P[0] Ssort = sorted(S,reverse = True) Psort = sorted(P,reverse = True) Csort = sorted(C,reverse = True) pointS = {} pointP = {} pointC = {} for r,s,p,c in zip(R,Ssort,Psort,Csort): if s not in pointS:pointS[s] = r if p not in pointP:pointP[p] = r if c not in pointC:pointC[c] = r point = [pointS[s]+pointP[p]+pointC[c] for s,p,c in SPC] if sorted(point,reverse = True).index(point[0]) != 8: ans = min(ans,delta) break P[0] = you[1] SPC[0] = you.copy() for delta in range(1,102-you[2]): C[0] = you[2] + delta SPC[0][2] = C[0] Ssort = sorted(S,reverse = True) Psort = sorted(P,reverse = True) Csort = sorted(C,reverse = True) pointS = {} pointP = {} pointC = {} for r,s,p,c in zip(R,Ssort,Psort,Csort): if s not in pointS:pointS[s] = r if p not in pointP:pointP[p] = r if c not in pointC:pointC[c] = r point = [pointS[s]+pointP[p]+pointC[c] for s,p,c in SPC] if sorted(point,reverse = True).index(point[0]) != 8: ans = min(ans,delta) break print(ans if ans != 10**5 else 'Saiko') ```
output
1
8,357
17
16,715
Provide a correct Python 3 solution for this coding contest problem. In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day. * Each student will take one candy in the order of student number. * If candy remains after one round, continue to take candy in order from the person with the first student number. * The person who picks up the last candy will be the student who keeps the "class flag". There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag". Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag". Input Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≀ a ≀ 10000) representing the number of candies is given on one line. Process until the end of input (EOF). The number of datasets does not exceed 20. Output For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line. Example Input 50 5576 5577 5578 Output 3C11 3C38 3C39 3C01
instruction
0
8,971
17
17,942
"Correct Solution: ``` while 1: try: n = int(input()) except: break if n % 39 == 0: ans = 39 else: ans = n % 39 print("3C" + str(ans).zfill(2)) ```
output
1
8,971
17
17,943
Provide a correct Python 3 solution for this coding contest problem. In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day. * Each student will take one candy in the order of student number. * If candy remains after one round, continue to take candy in order from the person with the first student number. * The person who picks up the last candy will be the student who keeps the "class flag". There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag". Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag". Input Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≀ a ≀ 10000) representing the number of candies is given on one line. Process until the end of input (EOF). The number of datasets does not exceed 20. Output For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line. Example Input 50 5576 5577 5578 Output 3C11 3C38 3C39 3C01
instruction
0
8,972
17
17,944
"Correct Solution: ``` try: while True: ame = int(input()) num1 = ame % 39 if num1 == 0: num1 = 39 if num1 < 10: print("3C0" + str(num1)) else: print("3C" + str(num1)) except EOFError as e: num = 0 ```
output
1
8,972
17
17,945
Provide a correct Python 3 solution for this coding contest problem. In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day. * Each student will take one candy in the order of student number. * If candy remains after one round, continue to take candy in order from the person with the first student number. * The person who picks up the last candy will be the student who keeps the "class flag". There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag". Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag". Input Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≀ a ≀ 10000) representing the number of candies is given on one line. Process until the end of input (EOF). The number of datasets does not exceed 20. Output For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line. Example Input 50 5576 5577 5578 Output 3C11 3C38 3C39 3C01
instruction
0
8,973
17
17,946
"Correct Solution: ``` while True: try: a = int(input()) except:break if a%39 == 0: print("3C39") else: b = a // 39 c = a - 39 * b if c < 10: print("3C0",c,sep='') else: print("3C",c,sep='') ```
output
1
8,973
17
17,947
Provide a correct Python 3 solution for this coding contest problem. In Group C of the 3rd year, we decided to use the "class flag" used at the sports festival on November 10, 2007 at future class reunions. So, in order to decide which students to keep the "class flag", I decided to play the following game using a large amount of candy that the teacher gave me the other day. * Each student will take one candy in the order of student number. * If candy remains after one round, continue to take candy in order from the person with the first student number. * The person who picks up the last candy will be the student who keeps the "class flag". There are 39 students in the 3rd grade C class. Their student numbers are 3C01 to 3C39. For example, if you have 50 candies and everyone in the class finishes taking the first candy, you will have 11 candies left. If you take it again in student number order, the last one will be taken by the 3C11 student. That is, the 3C11 student is the student who keeps the "class flag". Create a program that takes the number of candies as input and outputs the student number of the student who stores the "class flag". Input Multiple test cases are given. Each test case is given in the following format. For each test case, an integer a (1 ≀ a ≀ 10000) representing the number of candies is given on one line. Process until the end of input (EOF). The number of datasets does not exceed 20. Output For each test case, output the student number (half-width alphanumeric characters) of the student who stores the "class flag" on one line. Example Input 50 5576 5577 5578 Output 3C11 3C38 3C39 3C01
instruction
0
8,974
17
17,948
"Correct Solution: ``` while True: try: a = int(input()) except: break a = str(a%39) if a == "0": a = "39" elif len(a) == 1: a = "0"+a print("3C"+a) ```
output
1
8,974
17
17,949