text
stringlengths
198
433k
conversation_id
int64
0
109k
Provide tags and a correct Python 3 solution for this coding contest problem. You like playing chess tournaments online. In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game"). The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game. After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug. Compute the maximum score you can get by cheating in the optimal way. Input Each test contains multiple test cases. The first line contains an integer t (1≀ t ≀ 20,000) β€” the number of test cases. The description of the test cases follows. The first line of each testcase contains two integers n, k (1≀ n≀ 100,000, 0≀ k≀ n) – the number of games played and the number of outcomes that you can change. The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then s_i= W, if you have lost the i-th game then s_i= L. It is guaranteed that the sum of n over all testcases does not exceed 200,000. Output For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way. Example Input 8 5 2 WLWLL 6 5 LLLWWL 7 1 LWLWLWL 15 5 WWWLLLWWWLLLWWW 40 7 LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL 1 0 L 1 1 L 6 1 WLLWLW Output 7 11 6 26 46 0 1 6 Note Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game). An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game. Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game). An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11 = 1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games. Tags: greedy, implementation, sortings Correct Solution: ``` def score(a,n): score = 0 if a[0]=='L' else 1 for i in range(1,n): if a[i]==a[i-1] =='W': score+=2 elif a[i]=='W': score+=1 return score t = int(input()) for _ in range(t): n,k = map(int,input().split()) s = input() mylist = [] x = 0 while(x<n and s[x]=='L'): x+=1 count = 0 while(x<n): if(s[x]=='W'): if count!=0: mylist.append(count) count=0 else: count+=1 x+=1 mylist.sort() ans = 0 for i in mylist: k-=i if k==0: ans+= 2*i + 1 break elif k>0: ans+=2*i+1 else: ans+=2*i break counter = 0 while(counter<n and s[counter]=='L'): counter+=1 scounter = 0 while( scounter<n and s[n-1-scounter]=='L' ): scounter+=1 ans+=score(s,n) if ans==0 and k>0: ans-=1 if k<=(scounter+counter): ans+=2*k else: ans+=2*(scounter+counter) # print("ans",ans) print(ans) ```
6,800
Provide tags and a correct Python 3 solution for this coding contest problem. You like playing chess tournaments online. In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game"). The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game. After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug. Compute the maximum score you can get by cheating in the optimal way. Input Each test contains multiple test cases. The first line contains an integer t (1≀ t ≀ 20,000) β€” the number of test cases. The description of the test cases follows. The first line of each testcase contains two integers n, k (1≀ n≀ 100,000, 0≀ k≀ n) – the number of games played and the number of outcomes that you can change. The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then s_i= W, if you have lost the i-th game then s_i= L. It is guaranteed that the sum of n over all testcases does not exceed 200,000. Output For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way. Example Input 8 5 2 WLWLL 6 5 LLLWWL 7 1 LWLWLWL 15 5 WWWLLLWWWLLLWWW 40 7 LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL 1 0 L 1 1 L 6 1 WLLWLW Output 7 11 6 26 46 0 1 6 Note Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game). An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game. Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game). An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11 = 1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games. Tags: greedy, implementation, sortings Correct Solution: ``` t = int(input()) for it in range(0, t): n, k = tuple(list(map(int, input().split(' ')))) results = [char for char in input()] initial_score = 0 loss_amount = 0 for i in range(0, len(results)): if i > 0 and results[i] == 'W' and results[i - 1] == 'W': initial_score += 1 if results[i] == 'L': loss_amount += 1 k = min(k, loss_amount) initial_score += (n - loss_amount) streak_increase_added_score = 2 * k if loss_amount == n and streak_increase_added_score > 0: streak_increase_added_score -= 1 streak_diffs = [] current_streak_diff = 0 streak_found = 0 for i in range(0, n): if results[i] == 'W': streak_found = True if current_streak_diff != 0: streak_diffs.append(current_streak_diff) current_streak_diff = 0 if results[i] == 'L' and streak_found: current_streak_diff += 1 sorted_streak_diffs = sorted(streak_diffs) disjoint_streak_decrease_added_score = 0 for i in range(0, len(sorted_streak_diffs)): if k >= sorted_streak_diffs[i]: disjoint_streak_decrease_added_score += 1 k -= sorted_streak_diffs[i] else: break final_score = (initial_score + streak_increase_added_score + disjoint_streak_decrease_added_score) print(final_score) ```
6,801
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You like playing chess tournaments online. In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game"). The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game. After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug. Compute the maximum score you can get by cheating in the optimal way. Input Each test contains multiple test cases. The first line contains an integer t (1≀ t ≀ 20,000) β€” the number of test cases. The description of the test cases follows. The first line of each testcase contains two integers n, k (1≀ n≀ 100,000, 0≀ k≀ n) – the number of games played and the number of outcomes that you can change. The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then s_i= W, if you have lost the i-th game then s_i= L. It is guaranteed that the sum of n over all testcases does not exceed 200,000. Output For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way. Example Input 8 5 2 WLWLL 6 5 LLLWWL 7 1 LWLWLWL 15 5 WWWLLLWWWLLLWWW 40 7 LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL 1 0 L 1 1 L 6 1 WLLWLW Output 7 11 6 26 46 0 1 6 Note Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game). An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game. Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game). An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11 = 1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games. Submitted Solution: ``` import sys input=sys.stdin.readline t=int(input()) for i in range(t): n,k=map(int,input().split()) state=input() state=[i for i in state] ans,prev=0,0 store=[] if state[0]=='W': rang=[-1] else: rang=[] for i in range(len(state)): if state[i]=='W': if len(rang)==1: if rang[0]==i-1: rang=[i] else: store.append((i-rang[0]-1,rang[0]+1,i)) rang=[i] else: rang=[i] last=(rang[0] if rang else 0) store.sort() if k>0: for i in store: for j in range(i[1],i[2]): state[j]='W' k-=1 if k==0: break if k==0: break if k>0: for i in range(last+1,len(state)): if state[i]=='L' : state[i]='W' k-=1 if k==0: break if k>0: for i in range(len(state)-1,-1,-1): if state[i]=='L' : state[i]='W' k-=1 if k==0: break if state[0]=='W': ans=1 else: ans=0 for i in range(1,len(state)): if state[i]=='W': if state[i-1]=='W': ans+=2 else: ans+=1 sys.stdout.write(str(ans)+'\n') ``` Yes
6,802
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You like playing chess tournaments online. In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game"). The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game. After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug. Compute the maximum score you can get by cheating in the optimal way. Input Each test contains multiple test cases. The first line contains an integer t (1≀ t ≀ 20,000) β€” the number of test cases. The description of the test cases follows. The first line of each testcase contains two integers n, k (1≀ n≀ 100,000, 0≀ k≀ n) – the number of games played and the number of outcomes that you can change. The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then s_i= W, if you have lost the i-th game then s_i= L. It is guaranteed that the sum of n over all testcases does not exceed 200,000. Output For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way. Example Input 8 5 2 WLWLL 6 5 LLLWWL 7 1 LWLWLWL 15 5 WWWLLLWWWLLLWWW 40 7 LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL 1 0 L 1 1 L 6 1 WLLWLW Output 7 11 6 26 46 0 1 6 Note Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game). An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game. Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game). An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11 = 1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games. Submitted Solution: ``` def solve(): n, k = map(int, input().split()) A = input() segs = [] s, t = 0, 0 while s < n and A[s] == 'L': s += 1 head = (0, s) nn = n while nn >= 1 and A[nn - 1] == 'L': nn -= 1 tail = (nn, n) while s < nn: if A[s] == 'W': s += 1 continue t = s while t < nn and A[t] == 'L': t += 1 segs.append((s, t)) s = t segs.sort(key=lambda x: x[1] - x[0]) B = list(A) for (s, t) in segs: if k <= 0: break w = min(t - s, k) B[s:s+w] = 'W' * w k -= w if k > 0 and tail[0] != n: s, t = tail w = min(t - s, k) B[s:s+w] = 'W' * w k -= w if k > 0 and head[1] > 0: s, t = head w = min(t - s, k) B[t - w: t] = 'W' * w k -= w score = 0 for i in range(n): if i >= 1 and B[i - 1] == 'W' and B[i] == 'W': score += 2 continue if B[i] == 'W': score += 1 continue return score TC = int(input()) for _ in range(TC): print(solve()) ``` Yes
6,803
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You like playing chess tournaments online. In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game"). The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game. After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug. Compute the maximum score you can get by cheating in the optimal way. Input Each test contains multiple test cases. The first line contains an integer t (1≀ t ≀ 20,000) β€” the number of test cases. The description of the test cases follows. The first line of each testcase contains two integers n, k (1≀ n≀ 100,000, 0≀ k≀ n) – the number of games played and the number of outcomes that you can change. The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then s_i= W, if you have lost the i-th game then s_i= L. It is guaranteed that the sum of n over all testcases does not exceed 200,000. Output For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way. Example Input 8 5 2 WLWLL 6 5 LLLWWL 7 1 LWLWLWL 15 5 WWWLLLWWWLLLWWW 40 7 LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL 1 0 L 1 1 L 6 1 WLLWLW Output 7 11 6 26 46 0 1 6 Note Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game). An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game. Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game). An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11 = 1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games. Submitted Solution: ``` for i in range(int(input())): n, k = map(int, input().split()) s = input() wins = s.count('W') + k if wins >= n: print(2 * n - 1) else: streaks = int(s[0] == 'W') + s.count('LW') or int(wins > 0) gaps = s.strip('L').replace('W', ' ').strip().split() for g in sorted(map(len, gaps)): if g > k: break k -= g streaks -= 1 print(wins * 2 - streaks) ``` Yes
6,804
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You like playing chess tournaments online. In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game"). The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game. After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug. Compute the maximum score you can get by cheating in the optimal way. Input Each test contains multiple test cases. The first line contains an integer t (1≀ t ≀ 20,000) β€” the number of test cases. The description of the test cases follows. The first line of each testcase contains two integers n, k (1≀ n≀ 100,000, 0≀ k≀ n) – the number of games played and the number of outcomes that you can change. The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then s_i= W, if you have lost the i-th game then s_i= L. It is guaranteed that the sum of n over all testcases does not exceed 200,000. Output For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way. Example Input 8 5 2 WLWLL 6 5 LLLWWL 7 1 LWLWLWL 15 5 WWWLLLWWWLLLWWW 40 7 LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL 1 0 L 1 1 L 6 1 WLLWLW Output 7 11 6 26 46 0 1 6 Note Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game). An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game. Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game). An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11 = 1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games. Submitted Solution: ``` from itertools import groupby for _ in range(int(input())): n, k = map(int, input().split()) s = input() if k >= s.count('L'): print(n * 2 - 1) else: s = s.strip("L") group = [] for i, g in groupby(s): if i == 'L': group.append(len(list(g))) group.sort() i, m = 0, len(group) r = k while i < m and r >= group[i]: r -= group[i] i += 1 ans = (s.count('W') + k) * 2 - (m + 1 - i) print(max(0, ans)) ``` Yes
6,805
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You like playing chess tournaments online. In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game"). The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game. After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug. Compute the maximum score you can get by cheating in the optimal way. Input Each test contains multiple test cases. The first line contains an integer t (1≀ t ≀ 20,000) β€” the number of test cases. The description of the test cases follows. The first line of each testcase contains two integers n, k (1≀ n≀ 100,000, 0≀ k≀ n) – the number of games played and the number of outcomes that you can change. The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then s_i= W, if you have lost the i-th game then s_i= L. It is guaranteed that the sum of n over all testcases does not exceed 200,000. Output For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way. Example Input 8 5 2 WLWLL 6 5 LLLWWL 7 1 LWLWLWL 15 5 WWWLLLWWWLLLWWW 40 7 LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL 1 0 L 1 1 L 6 1 WLLWLW Output 7 11 6 26 46 0 1 6 Note Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game). An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game. Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game). An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11 = 1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games. Submitted Solution: ``` import os import sys from io import BytesIO, IOBase import math from itertools import permutations from decimal import * getcontext().prec = 25 MOD = pow(10, 9) + 7 BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # n, k = map(int, input().split(" ")) # l = list(map(int, input().split(" "))) for _ in range(int(input())): n, k = map(int, input().split(" ")) l = input() if n == k: print(2 * k - 1) else: t = 0 z = [] w = False le = pre = 0 for i in range(n): if l[i] == "L": pre += 1 else: break start = max(1, pre) if l[0]=="W": t+=1 for i in range(start, n): if l[i] == "W": w=True if le: z.append(le) le = 0 if l[i - 1] == "W": t += 2 else: t += 1 if l[i] == "L": le += 1 extra = le z.sort() if k == 0: print(t) elif not extra and not z: if not w: print(2*k -1) else: print(2*k+1) elif not z: t += 2 * (min(pre, k)) k = max(0, k - pre) t += 2 * (min(k, extra)) print(t) elif z: for i in range(len(z)): if z[i] <= k: k -= z[i] t += 2 * z[i] + 1 else: t += 2 * k k = 0 break if k: t += 2 * (min(pre, k)) k = max(0, k - pre) t += 2 * (min(k, extra)) print(t) ``` No
6,806
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You like playing chess tournaments online. In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game"). The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game. After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug. Compute the maximum score you can get by cheating in the optimal way. Input Each test contains multiple test cases. The first line contains an integer t (1≀ t ≀ 20,000) β€” the number of test cases. The description of the test cases follows. The first line of each testcase contains two integers n, k (1≀ n≀ 100,000, 0≀ k≀ n) – the number of games played and the number of outcomes that you can change. The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then s_i= W, if you have lost the i-th game then s_i= L. It is guaranteed that the sum of n over all testcases does not exceed 200,000. Output For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way. Example Input 8 5 2 WLWLL 6 5 LLLWWL 7 1 LWLWLWL 15 5 WWWLLLWWWLLLWWW 40 7 LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL 1 0 L 1 1 L 6 1 WLLWLW Output 7 11 6 26 46 0 1 6 Note Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game). An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game. Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game). An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11 = 1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games. Submitted Solution: ``` test_cases = int(input()) for i in range(0, test_cases): stats = [int(x) for x in input().split()] record = str(input()) g = stats[0] c = stats[1] score = 0 des = [] #irability indices = {} # of desirable locations indices[1] = [] indices[2] = [] indices[3] = [] for i in range(0, g): if record[i] == "W": des.append(0) score += 1 if i != 0 and record[i - 1] == "W": score += 1 else: d = 1 if i != 0 and record[i - 1] == "W": d += 1 if i != g - 1 and record[i + 1] == "W": d += 1 des.append(d) indices[d].append(i) for choice in range(0, c): # arbitrarily pick first top desirable index d = 3 while d > 0: if bool(indices[d]): break d -= 1 #des == 0: perfect game lol if d == 0: break ind = indices[d][0] # flip it! score += d des[ind] = 0 indices[d].remove(ind) if ind != 0 and des[ind - 1] > 0: indices[des[ind - 1] + 1].append(ind - 1) indices[des[ind - 1]].remove(ind - 1) des[ind - 1] += 1 if ind != g - 1 and des[ind + 1] > 0: indices[des[ind + 1] + 1].append(ind + 1) indices[des[ind + 1]].remove(ind + 1) des[ind + 1] += 1 print(score) ``` No
6,807
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You like playing chess tournaments online. In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game"). The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game. After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug. Compute the maximum score you can get by cheating in the optimal way. Input Each test contains multiple test cases. The first line contains an integer t (1≀ t ≀ 20,000) β€” the number of test cases. The description of the test cases follows. The first line of each testcase contains two integers n, k (1≀ n≀ 100,000, 0≀ k≀ n) – the number of games played and the number of outcomes that you can change. The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then s_i= W, if you have lost the i-th game then s_i= L. It is guaranteed that the sum of n over all testcases does not exceed 200,000. Output For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way. Example Input 8 5 2 WLWLL 6 5 LLLWWL 7 1 LWLWLWL 15 5 WWWLLLWWWLLLWWW 40 7 LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL 1 0 L 1 1 L 6 1 WLLWLW Output 7 11 6 26 46 0 1 6 Note Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game). An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game. Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game). An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11 = 1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games. Submitted Solution: ``` #!/usr/bin/env python import os import sys from io import BytesIO, IOBase #from bisect import bisect_left as bl #c++ lowerbound bl(array,element) #from bisect import bisect_right as br #c++ upperbound br(array,element) from functools import cmp_to_key def main(): for _ in range(int(input())): n,k=map(int,input().split(" ")) a=list(input()) start=-1 end=-1 temp=[] for x in range(n): if a[x]=='L': end+=1 else: if start!=end: temp.append([end-start,[start+1,end]]) start=x end=x if start!=end: temp.append([end-start,[start+1,end]]) #print(temp) def boss(a,b): if a[0]>b[0]: return 1 elif a[0]<b[0]: return -1 else: if a[1][0]==0 or a[1][1]==n-1: return 1 else: return -1 temp.sort(key=cmp_to_key(boss)) for x in temp: if k<=0: break for z in range(x[1][0],x[1][1]+1): a[z]='W' k-=1 if k<=0: break if k<=0: break ans=0 chk=-1 #print(a,temp) for x in range(n): if a[x]=='W': if chk==-1: ans+=1 chk=0 else: ans+=2 else: chk=-1 print(ans) #-----------------------------BOSS-------------------------------------! # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() ``` No
6,808
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You like playing chess tournaments online. In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 point. If you win the very first game of the tournament you get 1 point (since there is not a "previous game"). The outcomes of the n games are represented by a string s of length n: the i-th character of s is W if you have won the i-th game, while it is L if you have lost the i-th game. After the tournament, you notice a bug on the website that allows you to change the outcome of at most k of your games (meaning that at most k times you can change some symbol L to W, or W to L). Since your only goal is to improve your chess rating, you decide to cheat and use the bug. Compute the maximum score you can get by cheating in the optimal way. Input Each test contains multiple test cases. The first line contains an integer t (1≀ t ≀ 20,000) β€” the number of test cases. The description of the test cases follows. The first line of each testcase contains two integers n, k (1≀ n≀ 100,000, 0≀ k≀ n) – the number of games played and the number of outcomes that you can change. The second line contains a string s of length n containing only the characters W and L. If you have won the i-th game then s_i= W, if you have lost the i-th game then s_i= L. It is guaranteed that the sum of n over all testcases does not exceed 200,000. Output For each testcase, print a single integer – the maximum score you can get by cheating in the optimal way. Example Input 8 5 2 WLWLL 6 5 LLLWWL 7 1 LWLWLWL 15 5 WWWLLLWWWLLLWWW 40 7 LLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL 1 0 L 1 1 L 6 1 WLLWLW Output 7 11 6 26 46 0 1 6 Note Explanation of the first testcase. Before changing any outcome, the score is 2. Indeed, you won the first game, so you got 1 point, and you won also the third, so you got another 1 point (and not 2 because you lost the second game). An optimal way to cheat is to change the outcomes of the second and fourth game. Doing so, you end up winning the first four games (the string of the outcomes becomes WWWWL). Hence, the new score is 7=1+2+2+2: 1 point for the first game and 2 points for the second, third and fourth game. Explanation of the second testcase. Before changing any outcome, the score is 3. Indeed, you won the fourth game, so you got 1 point, and you won also the fifth game, so you got 2 more points (since you won also the previous game). An optimal way to cheat is to change the outcomes of the first, second, third and sixth game. Doing so, you end up winning all games (the string of the outcomes becomes WWWWWW). Hence, the new score is 11 = 1+2+2+2+2+2: 1 point for the first game and 2 points for all the other games. Submitted Solution: ``` #include <CodeforcesSolutions.h> #include <ONLINE_JUDGE <solution.cf(contestID = "1427",questionID = "A",method = "GET")>.h> """ Author : thekushalghosh Team : CodeDiggers I prefer Python language over the C++ language :p :D Visit my website : thekushalghosh.github.io """ import sys,math,cmath,time,collections start_time = time.time() ########################################################################## ################# ---- THE ACTUAL CODE STARTS BELOW ---- ################# def solve(): n,k = invr() s = list(insr()) if "W" not in s: if k == 0: c = 0 else: c = (2 * min(k,len(s))) - 1 else: i = s.index("W") while i < len(s): if k > 0 and s[i] == "L": s[i] = "W" k = k - 1 i = i + 1 i = s.index("W") while i >= 0: if k > 0 and s[i] == "L": s[i] = "W" k = k - 1 i = i - 1 c = 0 for i in range(len(s)): if s[i] == "W": if i != 0 and s[i - 1] == "W": c = c + 2 else: c = c + 1 print(c) ################## ---- THE ACTUAL CODE ENDS ABOVE ---- ################## ########################################################################## def main(): global tt if not ONLINE_JUDGE: sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") t = 1 t = inp() for tt in range(1,t + 1): solve() if not ONLINE_JUDGE: print("Time Elapsed :",time.time() - start_time,"seconds") sys.stdout.close() #---------------------- USER DEFINED INPUT FUNCTIONS ----------------------# def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): return(input().strip()) def invr(): return(map(int,input().split())) #------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------# def counter(a): q = [0] * max(a) for i in range(len(a)): q[a[i] - 1] = q[a[i] - 1] + 1 return(q) def counter_elements(a): q = dict() for i in range(len(a)): if a[i] not in q: q[a[i]] = 0 q[a[i]] = q[a[i]] + 1 return(q) def string_counter(a): q = [0] * 26 for i in range(len(a)): q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1 return(q) def factorial(n,m = 1000000007): q = 1 for i in range(n): q = (q * (i + 1)) % m return(q) def factors(n): q = [] for i in range(1,int(n ** 0.5) + 1): if n % i == 0: q.append(i); q.append(n // i) return(list(sorted(list(set(q))))) def prime_factors(n): q = [] while n % 2 == 0: q.append(2); n = n // 2 for i in range(3,int(n ** 0.5) + 1,2): while n % i == 0: q.append(i); n = n // i if n > 2: q.append(n) return(list(sorted(q))) def transpose(a): n,m = len(a),len(a[0]) b = [[0] * n for i in range(m)] for i in range(m): for j in range(n): b[i][j] = a[j][i] return(b) def power_two(x): return (x and (not(x & (x - 1)))) def ceil(a, b): return -(-a // b) def seive(n): a = [1] prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p ** 2,n + 1, p): prime[i] = False p = p + 1 for p in range(2,n + 1): if prime[p]: a.append(p) return(a) #-----------------------------------------------------------------------# ONLINE_JUDGE = __debug__ if ONLINE_JUDGE: #import io,os #input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline input = sys.stdin.readline main() ``` No
6,809
Provide tags and a correct Python 3 solution for this coding contest problem. You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all balls with Manhattan distance at most k from ball i move to the position of ball i. Many balls may have the same coordinate after an operation. More formally, for all balls j such that |x_i - x_j| + |y_i - y_j| ≀ k, we assign x_j:=x_i and y_j:=y_i. <image> An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls. Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains two integers n, k (2 ≀ n ≀ 100, 0 ≀ k ≀ 10^6) β€” the number of balls and the attract power of all balls, respectively. The following n lines describe the balls' coordinates. The i-th of these lines contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^5) β€” the coordinates of the i-th ball. It is guaranteed that all points are distinct. Output For each test case print a single integer β€” the minimum number of operations to move all balls to the same position, or -1 if it is impossible. Example Input 3 3 2 0 0 3 3 1 1 3 3 6 7 8 8 6 9 4 1 0 0 0 1 0 2 0 3 Output -1 1 -1 Note In the first test case, there are three balls at (0, 0), (3, 3), and (1, 1) and the attract power is 2. It is possible to move two balls together with one operation, but not all three balls together with any number of operations. In the second test case, there are three balls at (6, 7), (8, 8), and (6, 9) and the attract power is 3. If we charge any ball, the other two will move to the same position, so we only require one operation. In the third test case, there are four balls at (0, 0), (0, 1), (0, 2), and (0, 3), and the attract power is 1. We can show that it is impossible to move all balls to the same position with a sequence of operations. Tags: brute force, geometry, greedy Correct Solution: ``` t=int(input()) for _ in range(t): n,k=map(int,input().split()) xs=[] ys=[] for ii in range(n): x,y=map(int,input().split()) xs.append(x) ys.append(y) #print(xs) #print(ys) done=False for i in range(n): max_k=-1 for j in range(n): max_k = max(max_k, abs(xs[i]-xs[j]) + abs(ys[i]-ys[j])) if max_k<=k: print(1) done=True break if not done: print(-1) ```
6,810
Provide tags and a correct Python 3 solution for this coding contest problem. You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all balls with Manhattan distance at most k from ball i move to the position of ball i. Many balls may have the same coordinate after an operation. More formally, for all balls j such that |x_i - x_j| + |y_i - y_j| ≀ k, we assign x_j:=x_i and y_j:=y_i. <image> An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls. Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains two integers n, k (2 ≀ n ≀ 100, 0 ≀ k ≀ 10^6) β€” the number of balls and the attract power of all balls, respectively. The following n lines describe the balls' coordinates. The i-th of these lines contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^5) β€” the coordinates of the i-th ball. It is guaranteed that all points are distinct. Output For each test case print a single integer β€” the minimum number of operations to move all balls to the same position, or -1 if it is impossible. Example Input 3 3 2 0 0 3 3 1 1 3 3 6 7 8 8 6 9 4 1 0 0 0 1 0 2 0 3 Output -1 1 -1 Note In the first test case, there are three balls at (0, 0), (3, 3), and (1, 1) and the attract power is 2. It is possible to move two balls together with one operation, but not all three balls together with any number of operations. In the second test case, there are three balls at (6, 7), (8, 8), and (6, 9) and the attract power is 3. If we charge any ball, the other two will move to the same position, so we only require one operation. In the third test case, there are four balls at (0, 0), (0, 1), (0, 2), and (0, 3), and the attract power is 1. We can show that it is impossible to move all balls to the same position with a sequence of operations. Tags: brute force, geometry, greedy Correct Solution: ``` import math for _ in range(int(input())): n,k=map(int,input().split()) l=[] for __ in range(n): x,y=map(int,input().split()) l.append([x,y]) c=0 cc=0 #print(l,len(l),n) for i in range(n): c=0 for j in range(n): if i!=j and ((abs(l[i][0]-l[j][0])+abs(l[i][1]-l[j][1])))<=k: c+=1 #print(i,j,((abs(l[i][0]-l[j][0])**2+abs(l[i][1]-l[j][1])**2)),k) if c==n-1: print(1) cc=1 break if cc!=1: print(-1) ```
6,811
Provide tags and a correct Python 3 solution for this coding contest problem. You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all balls with Manhattan distance at most k from ball i move to the position of ball i. Many balls may have the same coordinate after an operation. More formally, for all balls j such that |x_i - x_j| + |y_i - y_j| ≀ k, we assign x_j:=x_i and y_j:=y_i. <image> An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls. Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains two integers n, k (2 ≀ n ≀ 100, 0 ≀ k ≀ 10^6) β€” the number of balls and the attract power of all balls, respectively. The following n lines describe the balls' coordinates. The i-th of these lines contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^5) β€” the coordinates of the i-th ball. It is guaranteed that all points are distinct. Output For each test case print a single integer β€” the minimum number of operations to move all balls to the same position, or -1 if it is impossible. Example Input 3 3 2 0 0 3 3 1 1 3 3 6 7 8 8 6 9 4 1 0 0 0 1 0 2 0 3 Output -1 1 -1 Note In the first test case, there are three balls at (0, 0), (3, 3), and (1, 1) and the attract power is 2. It is possible to move two balls together with one operation, but not all three balls together with any number of operations. In the second test case, there are three balls at (6, 7), (8, 8), and (6, 9) and the attract power is 3. If we charge any ball, the other two will move to the same position, so we only require one operation. In the third test case, there are four balls at (0, 0), (0, 1), (0, 2), and (0, 3), and the attract power is 1. We can show that it is impossible to move all balls to the same position with a sequence of operations. Tags: brute force, geometry, greedy Correct Solution: ``` t = int(input()) for i in range(t): n,k = map(int,input().split()) L = [] for j in range(n): x,y = map(int,input().split()) L.append([x,y]) mn = 0 ok = False for i in range(n): mn = 0 for j in range(n): if i!= j: x = abs(L[i][0]-L[j][0]) + abs(L[i][1] - L[j][1]) mn = max(mn,x) if mn<=k: ok = True if ok == False: print(-1) else: print(1) ```
6,812
Provide tags and a correct Python 3 solution for this coding contest problem. You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all balls with Manhattan distance at most k from ball i move to the position of ball i. Many balls may have the same coordinate after an operation. More formally, for all balls j such that |x_i - x_j| + |y_i - y_j| ≀ k, we assign x_j:=x_i and y_j:=y_i. <image> An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls. Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains two integers n, k (2 ≀ n ≀ 100, 0 ≀ k ≀ 10^6) β€” the number of balls and the attract power of all balls, respectively. The following n lines describe the balls' coordinates. The i-th of these lines contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^5) β€” the coordinates of the i-th ball. It is guaranteed that all points are distinct. Output For each test case print a single integer β€” the minimum number of operations to move all balls to the same position, or -1 if it is impossible. Example Input 3 3 2 0 0 3 3 1 1 3 3 6 7 8 8 6 9 4 1 0 0 0 1 0 2 0 3 Output -1 1 -1 Note In the first test case, there are three balls at (0, 0), (3, 3), and (1, 1) and the attract power is 2. It is possible to move two balls together with one operation, but not all three balls together with any number of operations. In the second test case, there are three balls at (6, 7), (8, 8), and (6, 9) and the attract power is 3. If we charge any ball, the other two will move to the same position, so we only require one operation. In the third test case, there are four balls at (0, 0), (0, 1), (0, 2), and (0, 3), and the attract power is 1. We can show that it is impossible to move all balls to the same position with a sequence of operations. Tags: brute force, geometry, greedy Correct Solution: ``` import io import os from collections import Counter, defaultdict, deque def solve(N, K, balls): for x1, y1 in balls: bad = False for x2, y2 in balls: if x1 == x2 and y1 == y2: continue if abs(x1 - x2) + abs(y1 - y2) > K: bad = True break if not bad: return 1 return -1 if __name__ == "__main__": input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline TC = int(input()) for tc in range(1, TC + 1): N, K = [int(x) for x in input().split()] balls = [[int(x) for x in input().split()] for i in range(N)] ans = solve(N, K, balls) print(ans) ```
6,813
Provide tags and a correct Python 3 solution for this coding contest problem. You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all balls with Manhattan distance at most k from ball i move to the position of ball i. Many balls may have the same coordinate after an operation. More formally, for all balls j such that |x_i - x_j| + |y_i - y_j| ≀ k, we assign x_j:=x_i and y_j:=y_i. <image> An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls. Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains two integers n, k (2 ≀ n ≀ 100, 0 ≀ k ≀ 10^6) β€” the number of balls and the attract power of all balls, respectively. The following n lines describe the balls' coordinates. The i-th of these lines contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^5) β€” the coordinates of the i-th ball. It is guaranteed that all points are distinct. Output For each test case print a single integer β€” the minimum number of operations to move all balls to the same position, or -1 if it is impossible. Example Input 3 3 2 0 0 3 3 1 1 3 3 6 7 8 8 6 9 4 1 0 0 0 1 0 2 0 3 Output -1 1 -1 Note In the first test case, there are three balls at (0, 0), (3, 3), and (1, 1) and the attract power is 2. It is possible to move two balls together with one operation, but not all three balls together with any number of operations. In the second test case, there are three balls at (6, 7), (8, 8), and (6, 9) and the attract power is 3. If we charge any ball, the other two will move to the same position, so we only require one operation. In the third test case, there are four balls at (0, 0), (0, 1), (0, 2), and (0, 3), and the attract power is 1. We can show that it is impossible to move all balls to the same position with a sequence of operations. Tags: brute force, geometry, greedy Correct Solution: ``` import sys import os from io import BytesIO, IOBase #Fast IO Region BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") T = int(input()) for _ in range(T): n, k = map(int, input().split()) arr = [] for i in range(n): x, y = map(int, input().split()) arr.append((x,y)) ok = False for i in range(n): cx, cy = arr[i] for j in range(n): if abs(cx - arr[j][0]) + abs(cy - arr[j][1]) > k: break else: ok = True break if ok: print(1) continue print(-1) ```
6,814
Provide tags and a correct Python 3 solution for this coding contest problem. You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all balls with Manhattan distance at most k from ball i move to the position of ball i. Many balls may have the same coordinate after an operation. More formally, for all balls j such that |x_i - x_j| + |y_i - y_j| ≀ k, we assign x_j:=x_i and y_j:=y_i. <image> An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls. Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains two integers n, k (2 ≀ n ≀ 100, 0 ≀ k ≀ 10^6) β€” the number of balls and the attract power of all balls, respectively. The following n lines describe the balls' coordinates. The i-th of these lines contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^5) β€” the coordinates of the i-th ball. It is guaranteed that all points are distinct. Output For each test case print a single integer β€” the minimum number of operations to move all balls to the same position, or -1 if it is impossible. Example Input 3 3 2 0 0 3 3 1 1 3 3 6 7 8 8 6 9 4 1 0 0 0 1 0 2 0 3 Output -1 1 -1 Note In the first test case, there are three balls at (0, 0), (3, 3), and (1, 1) and the attract power is 2. It is possible to move two balls together with one operation, but not all three balls together with any number of operations. In the second test case, there are three balls at (6, 7), (8, 8), and (6, 9) and the attract power is 3. If we charge any ball, the other two will move to the same position, so we only require one operation. In the third test case, there are four balls at (0, 0), (0, 1), (0, 2), and (0, 3), and the attract power is 1. We can show that it is impossible to move all balls to the same position with a sequence of operations. Tags: brute force, geometry, greedy Correct Solution: ``` t=int(input()) for s in range(t): n,k=map(int,input().split()) l=[] for i in range(n): x,y=map(int,input().split()) l.append([x,y]) flag=0 for i in range(0,n): c=0 for j in range(0,n): if(abs(l[i][0]-l[j][0]) + abs(l[i][1]-l[j][1])>k): break c=c+1 if(c==n): flag=1 print(1) break if(flag==0): print(-1) ```
6,815
Provide tags and a correct Python 3 solution for this coding contest problem. You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all balls with Manhattan distance at most k from ball i move to the position of ball i. Many balls may have the same coordinate after an operation. More formally, for all balls j such that |x_i - x_j| + |y_i - y_j| ≀ k, we assign x_j:=x_i and y_j:=y_i. <image> An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls. Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains two integers n, k (2 ≀ n ≀ 100, 0 ≀ k ≀ 10^6) β€” the number of balls and the attract power of all balls, respectively. The following n lines describe the balls' coordinates. The i-th of these lines contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^5) β€” the coordinates of the i-th ball. It is guaranteed that all points are distinct. Output For each test case print a single integer β€” the minimum number of operations to move all balls to the same position, or -1 if it is impossible. Example Input 3 3 2 0 0 3 3 1 1 3 3 6 7 8 8 6 9 4 1 0 0 0 1 0 2 0 3 Output -1 1 -1 Note In the first test case, there are three balls at (0, 0), (3, 3), and (1, 1) and the attract power is 2. It is possible to move two balls together with one operation, but not all three balls together with any number of operations. In the second test case, there are three balls at (6, 7), (8, 8), and (6, 9) and the attract power is 3. If we charge any ball, the other two will move to the same position, so we only require one operation. In the third test case, there are four balls at (0, 0), (0, 1), (0, 2), and (0, 3), and the attract power is 1. We can show that it is impossible to move all balls to the same position with a sequence of operations. Tags: brute force, geometry, greedy Correct Solution: ``` from os import path import sys # mod = int(1e9 + 7) # import re # can use multiple splits from math import ceil, floor,gcd,log from collections import defaultdict , Counter # from bisect import bisect_left, bisect_right #popping from the end is less taxing,since you don't have to shift any elements maxx = float('inf') if (path.exists('input.txt')): #------------------Sublime--------------------------------------# sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w'); I = lambda :int(sys.stdin.buffer.readline()) tup= lambda : map(int , sys.stdin.buffer.readline().split()) lint = lambda :[int(x) for x in sys.stdin.buffer.readline().split()] S = lambda: sys.stdin.readline().replace('\n', '').strip() # def grid(r, c): return [lint() for i in range(r)] # def debug(*args, c=6): print('\033[3{}m'.format(c), *args, '\033[0m', file=sys.stderr) stpr = lambda x : sys.stdout.write(f'{x}' + '\n') star = lambda x: print(' '.join(map(str, x))) else: #------------------PYPY FAst I/o--------------------------------# I = lambda :int(sys.stdin.buffer.readline()) tup= lambda : map(int , sys.stdin.buffer.readline().split()) lint = lambda :[int(x) for x in sys.stdin.buffer.readline().split()] S = lambda: sys.stdin.readline().replace('\n', '').strip() # def grid(r, c): return [lint() for i in range(r)] stpr = lambda x : sys.stdout.write(f'{x}' + '\n') star = lambda x: print(' '.join(map(str, x))) # input = sys.stdin.readline for _ in range(I()): n , k = tup() a=[] for i in range(n): b ,c = tup() a.append((b,c)) ans = maxx for i in range(n): se = set() f = 1 for j in range(n): if i != j : ana = abs(a[i][0] - a[j][0]) + abs(a[i][1] - a[j][1]) if ana <= k: se.add(ana) else: f =0 break if f: ans= min(ans ,len(se)) se.clear() else: se.clear() if ans == maxx: print(-1) else:print(1) ```
6,816
Provide tags and a correct Python 3 solution for this coding contest problem. You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all balls with Manhattan distance at most k from ball i move to the position of ball i. Many balls may have the same coordinate after an operation. More formally, for all balls j such that |x_i - x_j| + |y_i - y_j| ≀ k, we assign x_j:=x_i and y_j:=y_i. <image> An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls. Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains two integers n, k (2 ≀ n ≀ 100, 0 ≀ k ≀ 10^6) β€” the number of balls and the attract power of all balls, respectively. The following n lines describe the balls' coordinates. The i-th of these lines contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^5) β€” the coordinates of the i-th ball. It is guaranteed that all points are distinct. Output For each test case print a single integer β€” the minimum number of operations to move all balls to the same position, or -1 if it is impossible. Example Input 3 3 2 0 0 3 3 1 1 3 3 6 7 8 8 6 9 4 1 0 0 0 1 0 2 0 3 Output -1 1 -1 Note In the first test case, there are three balls at (0, 0), (3, 3), and (1, 1) and the attract power is 2. It is possible to move two balls together with one operation, but not all three balls together with any number of operations. In the second test case, there are three balls at (6, 7), (8, 8), and (6, 9) and the attract power is 3. If we charge any ball, the other two will move to the same position, so we only require one operation. In the third test case, there are four balls at (0, 0), (0, 1), (0, 2), and (0, 3), and the attract power is 1. We can show that it is impossible to move all balls to the same position with a sequence of operations. Tags: brute force, geometry, greedy Correct Solution: ``` t= int(input()) for _ in range(t): n, k = map(int, input().split()) XY = [] for i in range(n): x,y = map(int, input().split()) XY.append((x, y)) flag = False for i in range(n): xi, yi = XY[i] for j in range(n): xj, yj = XY[j] if abs(xi-xj)+abs(yi-yj)>k: break else: flag = True break if flag: print(1) else: print(-1) ```
6,817
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all balls with Manhattan distance at most k from ball i move to the position of ball i. Many balls may have the same coordinate after an operation. More formally, for all balls j such that |x_i - x_j| + |y_i - y_j| ≀ k, we assign x_j:=x_i and y_j:=y_i. <image> An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls. Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains two integers n, k (2 ≀ n ≀ 100, 0 ≀ k ≀ 10^6) β€” the number of balls and the attract power of all balls, respectively. The following n lines describe the balls' coordinates. The i-th of these lines contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^5) β€” the coordinates of the i-th ball. It is guaranteed that all points are distinct. Output For each test case print a single integer β€” the minimum number of operations to move all balls to the same position, or -1 if it is impossible. Example Input 3 3 2 0 0 3 3 1 1 3 3 6 7 8 8 6 9 4 1 0 0 0 1 0 2 0 3 Output -1 1 -1 Note In the first test case, there are three balls at (0, 0), (3, 3), and (1, 1) and the attract power is 2. It is possible to move two balls together with one operation, but not all three balls together with any number of operations. In the second test case, there are three balls at (6, 7), (8, 8), and (6, 9) and the attract power is 3. If we charge any ball, the other two will move to the same position, so we only require one operation. In the third test case, there are four balls at (0, 0), (0, 1), (0, 2), and (0, 3), and the attract power is 1. We can show that it is impossible to move all balls to the same position with a sequence of operations. Submitted Solution: ``` rn=lambda:int(input()) rl=lambda:list(map(int,input().split())) rns=lambda:map(int,input().split()) rs=lambda:input() yn=lambda x:print('Yes') if x else print('No') YN=lambda x:print('YES') if x else print('NO') for _ in range(rn()): n,k=rns() points=[] ans=-1 for i in range(n): points.append(rl()) for i in range(n): b=[] for j in range(n): if i!=j: b.append(abs(points[i][0]-points[j][0])+abs(points[i][1]-points[j][1])) if all([i<=k for i in b]): ans=1 break print(ans) ``` Yes
6,818
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all balls with Manhattan distance at most k from ball i move to the position of ball i. Many balls may have the same coordinate after an operation. More formally, for all balls j such that |x_i - x_j| + |y_i - y_j| ≀ k, we assign x_j:=x_i and y_j:=y_i. <image> An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls. Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains two integers n, k (2 ≀ n ≀ 100, 0 ≀ k ≀ 10^6) β€” the number of balls and the attract power of all balls, respectively. The following n lines describe the balls' coordinates. The i-th of these lines contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^5) β€” the coordinates of the i-th ball. It is guaranteed that all points are distinct. Output For each test case print a single integer β€” the minimum number of operations to move all balls to the same position, or -1 if it is impossible. Example Input 3 3 2 0 0 3 3 1 1 3 3 6 7 8 8 6 9 4 1 0 0 0 1 0 2 0 3 Output -1 1 -1 Note In the first test case, there are three balls at (0, 0), (3, 3), and (1, 1) and the attract power is 2. It is possible to move two balls together with one operation, but not all three balls together with any number of operations. In the second test case, there are three balls at (6, 7), (8, 8), and (6, 9) and the attract power is 3. If we charge any ball, the other two will move to the same position, so we only require one operation. In the third test case, there are four balls at (0, 0), (0, 1), (0, 2), and (0, 3), and the attract power is 1. We can show that it is impossible to move all balls to the same position with a sequence of operations. Submitted Solution: ``` # cook your dish here remaing_test_cases = int(input()) while remaing_test_cases > 0: points_count,K = map(int,input().split()) points = [] for i in range(points_count): x,y = map(int,input().split()) points.append([x,y]) flag = 0 for i in range(points_count): count_power = 0 for j in range(points_count): if (abs(points[i][0] - points[j][0]) + abs(points[i][1] - points[j][1])) <= K: count_power = count_power + 1 if count_power == points_count: print(1) flag = 1 break if flag == 0: print(-1) remaing_test_cases = remaing_test_cases - 1 ``` Yes
6,819
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all balls with Manhattan distance at most k from ball i move to the position of ball i. Many balls may have the same coordinate after an operation. More formally, for all balls j such that |x_i - x_j| + |y_i - y_j| ≀ k, we assign x_j:=x_i and y_j:=y_i. <image> An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls. Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains two integers n, k (2 ≀ n ≀ 100, 0 ≀ k ≀ 10^6) β€” the number of balls and the attract power of all balls, respectively. The following n lines describe the balls' coordinates. The i-th of these lines contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^5) β€” the coordinates of the i-th ball. It is guaranteed that all points are distinct. Output For each test case print a single integer β€” the minimum number of operations to move all balls to the same position, or -1 if it is impossible. Example Input 3 3 2 0 0 3 3 1 1 3 3 6 7 8 8 6 9 4 1 0 0 0 1 0 2 0 3 Output -1 1 -1 Note In the first test case, there are three balls at (0, 0), (3, 3), and (1, 1) and the attract power is 2. It is possible to move two balls together with one operation, but not all three balls together with any number of operations. In the second test case, there are three balls at (6, 7), (8, 8), and (6, 9) and the attract power is 3. If we charge any ball, the other two will move to the same position, so we only require one operation. In the third test case, there are four balls at (0, 0), (0, 1), (0, 2), and (0, 3), and the attract power is 1. We can show that it is impossible to move all balls to the same position with a sequence of operations. Submitted Solution: ``` for i in range(int(input())): n,k=map(int,input().split());l=[];t=-1 for i in range(n):x,y=map(int,input().split());l.append([x,y]) for i in l: q=0 for j in l: if abs(i[1]-j[1])+abs(i[0]-j[0])<=k:q+=1 else:break if q==n:t=1 print(t) ``` Yes
6,820
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all balls with Manhattan distance at most k from ball i move to the position of ball i. Many balls may have the same coordinate after an operation. More formally, for all balls j such that |x_i - x_j| + |y_i - y_j| ≀ k, we assign x_j:=x_i and y_j:=y_i. <image> An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls. Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains two integers n, k (2 ≀ n ≀ 100, 0 ≀ k ≀ 10^6) β€” the number of balls and the attract power of all balls, respectively. The following n lines describe the balls' coordinates. The i-th of these lines contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^5) β€” the coordinates of the i-th ball. It is guaranteed that all points are distinct. Output For each test case print a single integer β€” the minimum number of operations to move all balls to the same position, or -1 if it is impossible. Example Input 3 3 2 0 0 3 3 1 1 3 3 6 7 8 8 6 9 4 1 0 0 0 1 0 2 0 3 Output -1 1 -1 Note In the first test case, there are three balls at (0, 0), (3, 3), and (1, 1) and the attract power is 2. It is possible to move two balls together with one operation, but not all three balls together with any number of operations. In the second test case, there are three balls at (6, 7), (8, 8), and (6, 9) and the attract power is 3. If we charge any ball, the other two will move to the same position, so we only require one operation. In the third test case, there are four balls at (0, 0), (0, 1), (0, 2), and (0, 3), and the attract power is 1. We can show that it is impossible to move all balls to the same position with a sequence of operations. Submitted Solution: ``` n_tests = int(input()) for test in range(n_tests): [n, k] = input().split(' ') k = int(k) d = [] n = int(n) for i in range(n): p = input().split(' ') p = [int(w) for w in p] d.append(p) md = [] t = False for i in range(n): q = d[i] a = 0 for j in range(n): s = abs(q[0] - d[j][0]) + abs(q[1] - d[j][1]) if s <= k: a += 1 if a == n: t = True break if t: print(1) else: print(-1) ``` Yes
6,821
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all balls with Manhattan distance at most k from ball i move to the position of ball i. Many balls may have the same coordinate after an operation. More formally, for all balls j such that |x_i - x_j| + |y_i - y_j| ≀ k, we assign x_j:=x_i and y_j:=y_i. <image> An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls. Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains two integers n, k (2 ≀ n ≀ 100, 0 ≀ k ≀ 10^6) β€” the number of balls and the attract power of all balls, respectively. The following n lines describe the balls' coordinates. The i-th of these lines contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^5) β€” the coordinates of the i-th ball. It is guaranteed that all points are distinct. Output For each test case print a single integer β€” the minimum number of operations to move all balls to the same position, or -1 if it is impossible. Example Input 3 3 2 0 0 3 3 1 1 3 3 6 7 8 8 6 9 4 1 0 0 0 1 0 2 0 3 Output -1 1 -1 Note In the first test case, there are three balls at (0, 0), (3, 3), and (1, 1) and the attract power is 2. It is possible to move two balls together with one operation, but not all three balls together with any number of operations. In the second test case, there are three balls at (6, 7), (8, 8), and (6, 9) and the attract power is 3. If we charge any ball, the other two will move to the same position, so we only require one operation. In the third test case, there are four balls at (0, 0), (0, 1), (0, 2), and (0, 3), and the attract power is 1. We can show that it is impossible to move all balls to the same position with a sequence of operations. Submitted Solution: ``` # Competitive Programming Template --> Ankit Josh import os from math import factorial,sqrt,ceil,floor,log from itertools import groupby import sys from io import BytesIO, IOBase def inp(): return sys.stdin.readline().strip() def IIX(): return (int(x) for x in sys.stdin.readline().split()) def II(): return (int(inp())) def LI(): return list(map(int, inp().split())) def LS(): return list(map(str, inp().split())) def L(x):return list(x) def out(var): return sys.stdout.write(str(var)) #Graph using Ajdacency List class GraphAL: def __init__(self,Nodes,isDirected=False): self.nodes=[x for x in range(1,Nodes+1) ] self.adj_list={} self.isDirected=isDirected for node in self.nodes: self.adj_list[node]=[] def add_edge(self,x,y): self.adj_list[x].append(y) if self.isDirected==False: self.adj_list[y].append(x) def return_graph(self): return(self.adj_list) #Graph using Ajdacency Matrix class GraphAM: def __init__(self,Nodes,isDirected=False): self.adj_matrix=[ [0]*(Nodes+1) for x in range(Nodes+2)] self.isDirected=isDirected def add_edge(self,x,y): if self.isDirected: self.adj_matrix[x][y]=1 elif self.isDirected==False: self.adj_matrix[x][y]=1 self.adj_matrix[y][x]=1 def delete_edge(self,x,y): if self.isDirected: self.adj_matrix[x][y]=0 if self.isDirected==False: self.adj_matrix[x][y]=0 self.adj_matrix[y][x]=0 def degree(self,x): l=self.adj_matrix[x] return l.count(1) def return_graph(self): return self.adj_matrix ''' nodes=II() edges=II() graph=GraphAL(nodes) #Add 'True' to the Graph method, for directed graph connections=[] for i in range(edges): l=LI() connections.append(l) for connect in connections: graph.add_edge(connect[0],connect[1]) grp=graph.return_graph() ''' def primeFact(n): hashMap={} for i in range(2,int(sqrt(n))+1): if n % i==0: hashMap[i]=0 while n % i==0: hashMap[i]+=1 n/=i if n>1: hashMap[n]=1 return hashMap #Code goes here def solve(): #Start coding n,k=IIX() c=[] for _ in range(n): x,y=IIX() c.append([x,y]) xmin=float("inf") xmax=0 for x in c: xmin=min(xmin,x[0]) xmax=max(xmax,x[0]) ymin=float("inf") ymax=0 for x in c: ymin=min(ymin,x[1]) ymax=max(ymax,x[1]) diffx=abs(xmax-xmin);diffy=abs(ymax-ymin) if diffx>k or diffy>k: print(-1) return else: print(1) return return # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": try: t=II() for _ in range(t): solve() except EOFError as e: out('') except RuntimeError as r: out('') ``` No
6,822
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all balls with Manhattan distance at most k from ball i move to the position of ball i. Many balls may have the same coordinate after an operation. More formally, for all balls j such that |x_i - x_j| + |y_i - y_j| ≀ k, we assign x_j:=x_i and y_j:=y_i. <image> An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls. Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains two integers n, k (2 ≀ n ≀ 100, 0 ≀ k ≀ 10^6) β€” the number of balls and the attract power of all balls, respectively. The following n lines describe the balls' coordinates. The i-th of these lines contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^5) β€” the coordinates of the i-th ball. It is guaranteed that all points are distinct. Output For each test case print a single integer β€” the minimum number of operations to move all balls to the same position, or -1 if it is impossible. Example Input 3 3 2 0 0 3 3 1 1 3 3 6 7 8 8 6 9 4 1 0 0 0 1 0 2 0 3 Output -1 1 -1 Note In the first test case, there are three balls at (0, 0), (3, 3), and (1, 1) and the attract power is 2. It is possible to move two balls together with one operation, but not all three balls together with any number of operations. In the second test case, there are three balls at (6, 7), (8, 8), and (6, 9) and the attract power is 3. If we charge any ball, the other two will move to the same position, so we only require one operation. In the third test case, there are four balls at (0, 0), (0, 1), (0, 2), and (0, 3), and the attract power is 1. We can show that it is impossible to move all balls to the same position with a sequence of operations. Submitted Solution: ``` def solve(points, k, n): for i in range(1, n): if abs(points[i][0] - points[0][0]) + abs(points[i][1] - points[0][1]) > k: return -1 return 1 for _ in range(int(input())): n, k = map(int, input().split()) points = [] for i in range(n): x, y = map(int, input().split()) points.append([x, y]) print(solve(points, k, n)) ``` No
6,823
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all balls with Manhattan distance at most k from ball i move to the position of ball i. Many balls may have the same coordinate after an operation. More formally, for all balls j such that |x_i - x_j| + |y_i - y_j| ≀ k, we assign x_j:=x_i and y_j:=y_i. <image> An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls. Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains two integers n, k (2 ≀ n ≀ 100, 0 ≀ k ≀ 10^6) β€” the number of balls and the attract power of all balls, respectively. The following n lines describe the balls' coordinates. The i-th of these lines contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^5) β€” the coordinates of the i-th ball. It is guaranteed that all points are distinct. Output For each test case print a single integer β€” the minimum number of operations to move all balls to the same position, or -1 if it is impossible. Example Input 3 3 2 0 0 3 3 1 1 3 3 6 7 8 8 6 9 4 1 0 0 0 1 0 2 0 3 Output -1 1 -1 Note In the first test case, there are three balls at (0, 0), (3, 3), and (1, 1) and the attract power is 2. It is possible to move two balls together with one operation, but not all three balls together with any number of operations. In the second test case, there are three balls at (6, 7), (8, 8), and (6, 9) and the attract power is 3. If we charge any ball, the other two will move to the same position, so we only require one operation. In the third test case, there are four balls at (0, 0), (0, 1), (0, 2), and (0, 3), and the attract power is 1. We can show that it is impossible to move all balls to the same position with a sequence of operations. Submitted Solution: ``` def dis(x,y,x1,y1): return abs(x-x1) + abs(y-y1) for _ in range(int(input())): n,k = map(int,input().split()) li = [] for i in range(n): p = list(map(int,input().split())) li.append(p) li = sorted(li,key=lambda x:x[1]) flag = False count = 0 for i in range(n): for j in range(i,n): val = dis(li[i][0],li[i][1],li[j][0],li[j][1]) if val == 0: count += 1 if val > k: flag = True break if flag: print(-1) else: if count == ((n)*(n+1))//2: print(0) else: print(1) ``` No
6,824
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls. In one operation, you can select a ball i to charge it. Once charged, all balls with Manhattan distance at most k from ball i move to the position of ball i. Many balls may have the same coordinate after an operation. More formally, for all balls j such that |x_i - x_j| + |y_i - y_j| ≀ k, we assign x_j:=x_i and y_j:=y_i. <image> An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls. Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible. Input The first line contains a single integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains two integers n, k (2 ≀ n ≀ 100, 0 ≀ k ≀ 10^6) β€” the number of balls and the attract power of all balls, respectively. The following n lines describe the balls' coordinates. The i-th of these lines contains two integers x_i, y_i (0 ≀ x_i, y_i ≀ 10^5) β€” the coordinates of the i-th ball. It is guaranteed that all points are distinct. Output For each test case print a single integer β€” the minimum number of operations to move all balls to the same position, or -1 if it is impossible. Example Input 3 3 2 0 0 3 3 1 1 3 3 6 7 8 8 6 9 4 1 0 0 0 1 0 2 0 3 Output -1 1 -1 Note In the first test case, there are three balls at (0, 0), (3, 3), and (1, 1) and the attract power is 2. It is possible to move two balls together with one operation, but not all three balls together with any number of operations. In the second test case, there are three balls at (6, 7), (8, 8), and (6, 9) and the attract power is 3. If we charge any ball, the other two will move to the same position, so we only require one operation. In the third test case, there are four balls at (0, 0), (0, 1), (0, 2), and (0, 3), and the attract power is 1. We can show that it is impossible to move all balls to the same position with a sequence of operations. Submitted Solution: ``` for i in range(int(input())): n,k=map(int,input().split()) l=[] for i in range(n): x,y=map(int,input().split()) l.append([x,y]) c=0 q=0 for i in range(n): if c==n: q+=1 print(1) break c=0 for j in range(n): if abs(l[i][0]-l[j][0])+abs(l[i][1]-l[j][1])<=k: c+=1 if q==0: print(-1) ``` No
6,825
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider a road consisting of several rows. Each row is divided into several rectangular tiles, and all tiles in the same row are equal. The first row contains exactly one rectangular tile. Look at the picture below which shows how the tiles are arranged. The road is constructed as follows: * the first row consists of 1 tile; * then a_1 rows follow; each of these rows contains 1 tile greater than the previous row; * then b_1 rows follow; each of these rows contains 1 tile less than the previous row; * then a_2 rows follow; each of these rows contains 1 tile greater than the previous row; * then b_2 rows follow; each of these rows contains 1 tile less than the previous row; * ... * then a_n rows follow; each of these rows contains 1 tile greater than the previous row; * then b_n rows follow; each of these rows contains 1 tile less than the previous row. <image> An example of the road with n = 2, a_1 = 4, b_1 = 2, a_2 = 2, b_2 = 3. Rows are arranged from left to right. You start from the only tile in the first row and want to reach the last row (any tile of it). From your current tile, you can move to any tile in the next row which touches your current tile. Calculate the number of different paths from the first row to the last row. Since it can be large, print it modulo 998244353. Input The first line contains one integer n (1 ≀ n ≀ 1000). Then n lines follow. The i-th of them contains two integers a_i and b_i (1 ≀ a_i, b_i ≀ 10^5; |a_i - b_i| ≀ 5). Additional constraint on the input: the sequence of a_i and b_i never results in a row with non-positive number of tiles. Output Print one integer β€” the number of paths from the first row to the last row, taken modulo 998244353. Examples Input 2 4 2 2 3 Output 850 Input 3 4 1 2 3 3 1 Output 10150 Input 8 328 323 867 868 715 718 721 722 439 435 868 870 834 834 797 796 Output 759099319 Submitted Solution: ``` print('dtl3') ``` No
6,826
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider a road consisting of several rows. Each row is divided into several rectangular tiles, and all tiles in the same row are equal. The first row contains exactly one rectangular tile. Look at the picture below which shows how the tiles are arranged. The road is constructed as follows: * the first row consists of 1 tile; * then a_1 rows follow; each of these rows contains 1 tile greater than the previous row; * then b_1 rows follow; each of these rows contains 1 tile less than the previous row; * then a_2 rows follow; each of these rows contains 1 tile greater than the previous row; * then b_2 rows follow; each of these rows contains 1 tile less than the previous row; * ... * then a_n rows follow; each of these rows contains 1 tile greater than the previous row; * then b_n rows follow; each of these rows contains 1 tile less than the previous row. <image> An example of the road with n = 2, a_1 = 4, b_1 = 2, a_2 = 2, b_2 = 3. Rows are arranged from left to right. You start from the only tile in the first row and want to reach the last row (any tile of it). From your current tile, you can move to any tile in the next row which touches your current tile. Calculate the number of different paths from the first row to the last row. Since it can be large, print it modulo 998244353. Input The first line contains one integer n (1 ≀ n ≀ 1000). Then n lines follow. The i-th of them contains two integers a_i and b_i (1 ≀ a_i, b_i ≀ 10^5; |a_i - b_i| ≀ 5). Additional constraint on the input: the sequence of a_i and b_i never results in a row with non-positive number of tiles. Output Print one integer β€” the number of paths from the first row to the last row, taken modulo 998244353. Examples Input 2 4 2 2 3 Output 850 Input 3 4 1 2 3 3 1 Output 10150 Input 8 328 323 867 868 715 718 721 722 439 435 868 870 834 834 797 796 Output 759099319 Submitted Solution: ``` print('dtl1') ``` No
6,827
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider a road consisting of several rows. Each row is divided into several rectangular tiles, and all tiles in the same row are equal. The first row contains exactly one rectangular tile. Look at the picture below which shows how the tiles are arranged. The road is constructed as follows: * the first row consists of 1 tile; * then a_1 rows follow; each of these rows contains 1 tile greater than the previous row; * then b_1 rows follow; each of these rows contains 1 tile less than the previous row; * then a_2 rows follow; each of these rows contains 1 tile greater than the previous row; * then b_2 rows follow; each of these rows contains 1 tile less than the previous row; * ... * then a_n rows follow; each of these rows contains 1 tile greater than the previous row; * then b_n rows follow; each of these rows contains 1 tile less than the previous row. <image> An example of the road with n = 2, a_1 = 4, b_1 = 2, a_2 = 2, b_2 = 3. Rows are arranged from left to right. You start from the only tile in the first row and want to reach the last row (any tile of it). From your current tile, you can move to any tile in the next row which touches your current tile. Calculate the number of different paths from the first row to the last row. Since it can be large, print it modulo 998244353. Input The first line contains one integer n (1 ≀ n ≀ 1000). Then n lines follow. The i-th of them contains two integers a_i and b_i (1 ≀ a_i, b_i ≀ 10^5; |a_i - b_i| ≀ 5). Additional constraint on the input: the sequence of a_i and b_i never results in a row with non-positive number of tiles. Output Print one integer β€” the number of paths from the first row to the last row, taken modulo 998244353. Examples Input 2 4 2 2 3 Output 850 Input 3 4 1 2 3 3 1 Output 10150 Input 8 328 323 867 868 715 718 721 722 439 435 868 870 834 834 797 796 Output 759099319 Submitted Solution: ``` print('quypnquypn1231211111112121') ``` No
6,828
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider a road consisting of several rows. Each row is divided into several rectangular tiles, and all tiles in the same row are equal. The first row contains exactly one rectangular tile. Look at the picture below which shows how the tiles are arranged. The road is constructed as follows: * the first row consists of 1 tile; * then a_1 rows follow; each of these rows contains 1 tile greater than the previous row; * then b_1 rows follow; each of these rows contains 1 tile less than the previous row; * then a_2 rows follow; each of these rows contains 1 tile greater than the previous row; * then b_2 rows follow; each of these rows contains 1 tile less than the previous row; * ... * then a_n rows follow; each of these rows contains 1 tile greater than the previous row; * then b_n rows follow; each of these rows contains 1 tile less than the previous row. <image> An example of the road with n = 2, a_1 = 4, b_1 = 2, a_2 = 2, b_2 = 3. Rows are arranged from left to right. You start from the only tile in the first row and want to reach the last row (any tile of it). From your current tile, you can move to any tile in the next row which touches your current tile. Calculate the number of different paths from the first row to the last row. Since it can be large, print it modulo 998244353. Input The first line contains one integer n (1 ≀ n ≀ 1000). Then n lines follow. The i-th of them contains two integers a_i and b_i (1 ≀ a_i, b_i ≀ 10^5; |a_i - b_i| ≀ 5). Additional constraint on the input: the sequence of a_i and b_i never results in a row with non-positive number of tiles. Output Print one integer β€” the number of paths from the first row to the last row, taken modulo 998244353. Examples Input 2 4 2 2 3 Output 850 Input 3 4 1 2 3 3 1 Output 10150 Input 8 328 323 867 868 715 718 721 722 439 435 868 870 834 834 797 796 Output 759099319 Submitted Solution: ``` print('dtl4') ``` No
6,829
Provide tags and a correct Python 3 solution for this coding contest problem. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Tags: implementation Correct Solution: ``` def s(): a = [[ord(i)-48 if ord(i) < 60 else ord(i)-55 for i in i]for i in input().split(':')] r = [i for i in range(max(max(a[0]),max(a[1]))+1,61) if sum(list(i**l[0]*l[1] for l in enumerate(reversed(a[0]))))<24 and sum(list(i**l[0]*l[1] for l in enumerate(reversed(a[1]))))<60] if len(r) == 0: print(0) elif r[-1] == 60: print(-1) else: print(*r) s() ```
6,830
Provide tags and a correct Python 3 solution for this coding contest problem. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Tags: implementation Correct Solution: ``` def val(c): if 'A' <= c <='Z': return ord(c) - 65 + 10 else: return int(c) def calc(h, b): ans = 0 i = 0 for c in h[::-1]: v = val(c) ans += int(v) * (b**i) i += 1 return ans h, m = [x for x in input().split(":")] min_base = -1 for c in h: min_base = max(min_base, val(c)+1) for c in m: min_base = max(min_base, val(c)+1) # print(min_base) answers = [] while True: hour = calc(h, min_base) min = calc(m, min_base) if hour > 23 or min > 59 or min_base > 60: break else: answers.append(min_base) min_base+= 1 if len(answers) == 0: print(0) elif min_base > 60: print(-1) else: print(*answers) ```
6,831
Provide tags and a correct Python 3 solution for this coding contest problem. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Tags: implementation Correct Solution: ``` #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #-------------------game starts now---------------------------------------------------- a, b = input().split(':') a = list(a) b = list(b) c = 10 for i in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ': for j in range(len(a)): if a[j] == i: a[j] = c for j in range(len(b)): if b[j] == i: b[j] = c c += 1 a = list(map(int, a)) b = list(map(int, b)) ans = [] for c in range(2, 200): x1 = 0 x2 = 0 for p in range(len(a)): x1 += a[p] * c ** (len(a) - p - 1) for p in range(len(b)): x2 += b[p] * c ** (len(b) - p - 1) if 0 <= x1 <= 23 and 0 <= x2 <= 59 and max(a) < c and max(b) < c: ans.append(c) if len(ans) > 100: print(-1) elif ans: print(*ans) else: print(0) ```
6,832
Provide tags and a correct Python 3 solution for this coding contest problem. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Tags: implementation Correct Solution: ``` #Algorithm : # 1) Split into strings , remove zeros # 2) Start checking for every integer in a range of(2 to 61) # 3) check the numbers and respetively add them ! ################################ #Function to calculate the value #This function is approximately called 60 times by 2 strings ! And it still works def base(t,b): num = 0 p = 1 i = len(t) - 1 v = 0 while i >=0 : if(t[i].isdigit()): v = int(t[i]) else: #Important to convert alphabets to numbers v = ord(t[i]) - 55 #If a value in string is greater than the numeral , then there can't exist such a numeral system if v >= b: return -1 num = num + (v*p) p=p*b i=i-1 return num ################################### #Function to remove leading zeros def remove_zeros(s): i=0 res="" while i < len(s) and s[i] == "0": i=i+1 while i < len(s): res = res + s[i] i=i+1 if res == "": res = "0" return res ##################################### s = input().split(":") num = [] for i in range(2): s[i]=remove_zeros(s[i]) #Important range used for checking for i in range(2,61): a = base(s[0],i) b = base(s[1],i) if a >= 0 and a <= 23 and b >=0 and b <= 59: num.append(i) if len(num) == 0: print(0) elif 60 in num : # As 60 cannot come it is possible only when there are only numbers at the 0th place print(-1) else: for x in num: print(x) ```
6,833
Provide tags and a correct Python 3 solution for this coding contest problem. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Tags: implementation Correct Solution: ``` from sys import setrecursionlimit, exit, stdin from math import ceil, floor, acos, pi from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd from functools import reduce import itertools setrecursionlimit(10**7) RI=lambda x=' ': list(map(int,input().split(x))) RS=lambda x=' ': input().rstrip().split(x) dX= [-1, 1, 0, 0,-1, 1,-1, 1] dY= [ 0, 0,-1, 1, 1,-1,-1, 1] mod=int(1e9+7) eps=1e-6 MAX=1000 ################################################# def to_base(s, b): if not s: return 0 v=int(s[-1], 36) if v>=b: return MAX return v+to_base(s[:-1], b) *b h, m = RS(':') ans=[] for b in range(100): if to_base(h, b) < 24 and to_base(m, b) <60: ans.append(b) if not ans: print(0) elif ans[-1]==99: print(-1) else: print(*ans) ```
6,834
Provide tags and a correct Python 3 solution for this coding contest problem. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Tags: implementation Correct Solution: ``` a,b=input().split(':') z='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' c=[z.find(i) for i in a] d=[z.find(i) for i in b] for i in range(len(c)): if c[i]>0: break c=c[i:] for i in range(len(d)): if d[i]>0: break d=d[i:] if int(a,base=max(*c+[1])+1)>23 or int(b,base=max(*d+[1])+1)>59: print(0) elif len(c)==len(d)==1: print(-1) else: for i in range(max(*d+c)+1,61): e=0 for j in range(len(c)): e+=i**j*c[-1-j] f=0 for j in range(len(d)): f+=i**j*d[-1-j] if 0<=e<=23 and 0<=f<=59: print(i,end=' ') ```
6,835
Provide tags and a correct Python 3 solution for this coding contest problem. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Tags: implementation Correct Solution: ``` def f(x, k): if 1 < k < 37: return int(x, k) s = 0 for i in x: s = s * k s += int(i, 36) return s hours, minutes = input().split(':') i = j = k = max(int(max(hours), 36), int(max(minutes), 36)) + 1 x, y = (f(hours, k) == f(hours, k + 1)), (f(minutes, k) == f(minutes, k + 1)) if x and y: print(-1 if hours[-1] < 'O' else 0) else: if x: i = 61 else: while f(hours, i) < 24: i += 1 if y: j = i else: while j < i and f(minutes, j) < 60: j += 1 print(' '.join(map(str, range(k, j))) if k < j else 0) ```
6,836
Provide tags and a correct Python 3 solution for this coding contest problem. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Tags: implementation Correct Solution: ``` import string import re values={str(d): d for d in range(10) } for ch in string.ascii_uppercase: values[ch] = ord(ch) - 55 def convert(s, i): x=0 for ch in s: d = values[ch] if d>=i: return None x = i*x+d return x match=re.match('0*(\w+):0*(\w+)',input().strip()) a,b=match.groups([1, 2]) ans = [] for i in range(2, 60): h = convert(a, i) m = convert(b, i) if h == None or m == None: continue if h < 24 and m < 60: ans.append(i) if len(ans) == 0: print(0) elif len(a) + len(b) == 2: print(-1) else: print(*ans) ```
6,837
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Submitted Solution: ``` def f(x, k): if 1 < k < 37: return int(x, k) s = 0 for i in x: s = s * k s += int(i, 36) return s a, b = input().split(':') i = j = k = max(int(max(a), 36), int(max(b), 36)) + 1 x, y = (f(a, k) == f(a, k + 1)), (f(b, k) == f(b, k + 1)) if x and y: print(-1 if a[-1] < 'O' else 0) else: if x: i = 61 else: while f(a, i) < 24: i += 1 if y: j = i else: while j < i and f(b, j) < 60: j += 1 print(' '.join(map(str, range(k, j))) if k < j else 0) # Made By Mostafa_Khaled ``` Yes
6,838
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Submitted Solution: ``` time = input() hour = time.split(':')[0] minute = time.split(':')[1] minBase = 0 def charToVal(x): if ord(x) < 58: return ord(x) - 48 else: return ord(x) - 55 for x in hour: if ord(x) < 58: minBase = max(minBase, ord(x) - 47) else: minBase = max(minBase, ord(x) - 54) for x in minute: if ord(x) < 58: minBase = max(minBase, ord(x) - 47) else: minBase = max(minBase, ord(x) - 54) solutions = [] for base in range(minBase, 62): multiple = 1 converted_hour = 0 for x in range(len(hour) - 1, -1, -1): converted_hour += multiple*(charToVal(hour[x])) multiple *= base if converted_hour >= 24: break multiple = 1 converted_minute = 0 for x in range(len(minute) - 1, -1, -1): converted_minute += multiple*(charToVal(minute[x])) multiple *= base if converted_minute >= 60: break solutions.append(base) if 61 in solutions: print(-1) elif len(solutions) == 0: print(0) else: for x in solutions: print(x, end=' ') ``` Yes
6,839
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Submitted Solution: ``` import sys s1,s2 = input().split(":") def convert(n,base): ans = 0 for i in range(len(n)): x = 0 if n[i].isalpha(): x = int(ord(n[i]) - ord('A')+10) else: x = int(n[i]) ans += x*pow(base,len(n)-i-1) return ans work = [] minm = 0 for c in s1+s2: if c.isalpha(): minm = max(minm, ord(c) - ord('A')+10) else: minm = max(minm,int(c)) for base in range(max(minm+1,2),60): if convert(s1,base) < 24 and convert(s2,base) < 60: work.append(base) else: break if len(work) == 0: print(0) elif (len(s1) == 1 or s1[:len(s1)-1] == '0'*(len(s1) -1)) and (len(s2) == 1 or s2[:len(s2)-1] == '0'*(len(s2) -1)): print(-1) else: print(" ".join(map(str,work))) ``` Yes
6,840
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Submitted Solution: ``` '''input 27:0070 ''' def conv(s, base): ans = 0 for index, i in enumerate(reversed(s)): val = int(i, 36) ans += (base**index)*val return ans def valid(base, h, m): hours = conv(h, base) mint = conv(m, base) if(0 <= hours < 24 and 0 <= mint < 60): return True else: return False h, m = input().split(":") hl = sorted(list(h)) ml = sorted(list(m)) hm = hl[-1] mm = ml[-1] if(ord(hm) < ord('A')): minbaseh = ord(hm) - ord('0') + 1 else: minbaseh = 11 + ord(hm) - ord('A') if(ord(mm) < ord('A')): minbasem = ord(mm) - ord('0') + 1 else: minbasem = 11 + ord(mm) - ord('A') minbase = max(minbasem, minbaseh) # print(minbaseh, minbasem, minbase, hm, mm) firstInval = 0 found = False lo = minbase hi = 60 while(lo <= hi): mid = lo + (hi - lo)//2 # print(mid, lo, hi, valid(mid, h, m)) if(not valid(mid, h, m)): firstInval = mid hi = mid-1 found = True else: lo = mid+1 if(not found): print(-1) elif(firstInval == minbase): print(0) else: for i in range(minbase, firstInval): print(i, end = " ") ``` Yes
6,841
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Submitted Solution: ``` time = input() hour = time.split(':')[0] minute = time.split(':')[1] minBase = 0 def charToVal(x): if ord(x) < 58: return ord(x) - 48 else: return ord(x) - 55 for x in hour: if ord(x) < 58: minBase = max(minBase, ord(x) - 47) else: minBase = max(minBase, ord(x) - 54) for x in minute: if ord(x) < 58: minBase = max(minBase, ord(x) - 47) else: minBase = max(minBase, ord(x) - 54) solutions = [] for base in range(minBase, 27): multiple = 1 converted_hour = 0 for x in range(len(hour) - 1, -1, -1): converted_hour += multiple*(charToVal(hour[x])) multiple *= base if converted_hour >= 24: break multiple = 1 converted_minute = 0 for x in range(len(minute) - 1, -1, -1): converted_minute += multiple*(charToVal(minute[x])) multiple *= base if converted_minute >= 60: break solutions.append(base) if 26 in solutions: print(-1) elif len(solutions) == 0: print(0) else: for x in solutions: print(x, end=' ') #make sure it is valid # if it fails, break, return ones that worked #otherwise, next return statement is -1 ``` No
6,842
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Submitted Solution: ``` s = input() a = s[:s.index(":")] b = s[s.index(":")+1:] a2 = '' b2 = '' found = False for i in a: if i!='0': found = True if found: a2+=i found = False for i in b: if i!='0': found = True if found: b2+=i a = a2 b = b2 apos = [] bpos = [] values = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] for i in a: apos.append(values.index(i)) for i in b: bpos.append(values.index(i)) if len(apos)==0: apos.append(0) if len(bpos)==0: bpos.append(0) minradix = max(max(apos), max(bpos)) #print(minradix) results = [] for i in range(minradix+1, 24): aresult = 0 bresult = 0 for j in range(len(apos)): aresult+=apos[j]*(i**(len(apos)-j-1)) for j in range(len(bpos)): bresult+=bpos[j]*(i**(len(bpos)-j-1)) if aresult<=23 and bresult<=59: results.append(i) #print(a, b) if len(a)==1 and len(b)==1 and values.index(a)<=23 and values.index(b)<=59: print(-1) elif len(results)==0: print(0) elif apos==[0] and bpos==[0]: print(-1) else: print(' '.join(list(map(str, results)))) ``` No
6,843
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Submitted Solution: ``` a,b=input().split(':') z='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' c=[z.find(i) for i in a] d=[z.find(i) for i in b] for i in range(len(c)): if c[i]>0: break c=c[i:] for i in range(len(d)): if d[i]>0: break d=d[i:] if int(a,base=max(*c+[2])+1)>23 or int(b,base=max(*d+[2])+1)>59: print(0) elif len(c)==len(d)==1: print(-1) else: for i in range(max(*d+c)+1,61): e=0 for j in range(len(c)): e+=i**j*c[-1-j] f=0 for j in range(len(d)): f+=i**j*d[-1-j] if 0<=e<=23 and 0<=f<=59: print(i,end=' ') ``` No
6,844
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" β€” you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots. Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written. Your task is to print the radixes of all numeral system which can contain the time "a:b". Input The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time). We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. Output Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1. Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. Examples Input 11:20 Output 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Input 2A:13 Output 0 Input 000B:00001 Output -1 Note Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system. Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time. Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. Submitted Solution: ``` s=input().rstrip().split(':') ans=[] for i in range(2,60): try: if int(s[0],i)<=24 and int(s[0],i)>=0 and int(s[1],i)>=0 and int(s[1],i)<=59: ans.append(i) except: pass count=0 i=100 try: if int(s[0],i)<=24 and int(s[0],i)>=0 and int(s[1],i)>=0 and int(s[1],i)<=59: count+=1 except: pass if count==1 or ans[-1]==36: print(-1) elif len(ans)==0: print(0) else: print(*ans) ``` No
6,845
Provide tags and a correct Python 3 solution for this coding contest problem. <image> While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n. For some unknown reason, the number of service variables is always an even number. William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5 000 and after every operation no variable can have an absolute value greater than 10^{18}. William can perform actions of two types for two chosen variables with indices i and j, where i < j: 1. Perform assignment a_i = a_i + a_j 2. Perform assignment a_j = a_j - a_i William wants you to develop a strategy that will get all the internal variables to the desired values. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≀ t ≀ 20). Description of the test cases follows. The first line of each test case contains a single even integer n (2 ≀ n ≀ 10^3), which is the number of internal variables. The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), which are initial values of internal variables. Output For each test case print the answer in the following format: The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k ≀ 5 000 must be satisfied. Each of the next k lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i < j should hold. We can show that an answer always exists. Example Input 2 4 1 1 1 1 4 4 3 1 2 Output 8 2 1 2 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 1 1 2 1 1 2 8 2 1 4 1 2 4 1 2 4 1 2 4 1 3 4 1 1 2 1 1 2 1 1 4 Note For the first sample test case one possible sequence of operations is as follows: 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1] 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1] 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1] 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1] 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0] 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1] 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1] 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows: 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2] 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2] 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2] 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2] 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2] 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2] 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2] 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2] Tags: constructive algorithms Correct Solution: ``` #Fast I/O import sys,os import math # To enable the file I/O i the below 2 lines are uncommented. # read from in.txt if uncommented if os.path.exists('in.txt'): sys.stdin=open('in.txt','r') # will print on Console if file I/O is not activated #if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w') # inputs template from io import BytesIO, IOBase def main(): for _ in range(int(input())): n=int(input()) arr=list(MI()) print(3*n) for i in range(n//2): print(1,2*i+1,2*i+2) print(2,2*i+1,2*i+2) print(2,2*i+1,2*i+2) print(1,2*i+1,2*i+2) print(2,2*i+1,2*i+2) print(2,2*i+1,2*i+2) # Sample Inputs/Output # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #for array of integers def MI():return (map(int,input().split())) # endregion #for fast output, always take string def outP(var): sys.stdout.write(str(var)+'\n') # end of any user-defined functions MOD=10**9+7 mod=998244353 # main functions for execution of the program. if __name__ == '__main__': #This doesn't works here but works wonders when submitted on CodeChef or CodeForces main() ```
6,846
Provide tags and a correct Python 3 solution for this coding contest problem. <image> While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n. For some unknown reason, the number of service variables is always an even number. William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5 000 and after every operation no variable can have an absolute value greater than 10^{18}. William can perform actions of two types for two chosen variables with indices i and j, where i < j: 1. Perform assignment a_i = a_i + a_j 2. Perform assignment a_j = a_j - a_i William wants you to develop a strategy that will get all the internal variables to the desired values. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≀ t ≀ 20). Description of the test cases follows. The first line of each test case contains a single even integer n (2 ≀ n ≀ 10^3), which is the number of internal variables. The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), which are initial values of internal variables. Output For each test case print the answer in the following format: The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k ≀ 5 000 must be satisfied. Each of the next k lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i < j should hold. We can show that an answer always exists. Example Input 2 4 1 1 1 1 4 4 3 1 2 Output 8 2 1 2 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 1 1 2 1 1 2 8 2 1 4 1 2 4 1 2 4 1 2 4 1 3 4 1 1 2 1 1 2 1 1 4 Note For the first sample test case one possible sequence of operations is as follows: 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1] 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1] 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1] 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1] 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0] 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1] 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1] 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows: 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2] 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2] 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2] 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2] 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2] 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2] 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2] 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2] Tags: constructive algorithms Correct Solution: ``` """ ai = ai + aj aj = aj - ai 1 ai + aj, aj 2 ai + aj, -ai 1 aj, -ai 2 aj, -ai-aj 1 -ai, -ai-aj 2 -ai, -aj """ def test(): n = int(input()) arr = list(map(int, input().split())) opts = int(n / 2 * 6) print(opts) for i in range(1, n + 1, 2): for _ in range(3): print(f'1 {i} {i + 1}') print(f'2 {i} {i + 1}') if __name__ == "__main__": num_cases = int(input()) for _ in range(0, num_cases): test() ```
6,847
Provide tags and a correct Python 3 solution for this coding contest problem. <image> While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n. For some unknown reason, the number of service variables is always an even number. William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5 000 and after every operation no variable can have an absolute value greater than 10^{18}. William can perform actions of two types for two chosen variables with indices i and j, where i < j: 1. Perform assignment a_i = a_i + a_j 2. Perform assignment a_j = a_j - a_i William wants you to develop a strategy that will get all the internal variables to the desired values. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≀ t ≀ 20). Description of the test cases follows. The first line of each test case contains a single even integer n (2 ≀ n ≀ 10^3), which is the number of internal variables. The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), which are initial values of internal variables. Output For each test case print the answer in the following format: The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k ≀ 5 000 must be satisfied. Each of the next k lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i < j should hold. We can show that an answer always exists. Example Input 2 4 1 1 1 1 4 4 3 1 2 Output 8 2 1 2 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 1 1 2 1 1 2 8 2 1 4 1 2 4 1 2 4 1 2 4 1 3 4 1 1 2 1 1 2 1 1 4 Note For the first sample test case one possible sequence of operations is as follows: 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1] 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1] 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1] 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1] 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0] 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1] 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1] 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows: 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2] 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2] 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2] 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2] 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2] 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2] 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2] 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2] Tags: constructive algorithms Correct Solution: ``` def fun(ls,n): print(3*n) for i in range(0,n,2): index=i+1 print(1,index,index+1) print(2,index,index+1) print(1,index,index+1) print(1,index,index+1) print(2,index,index+1) print(1,index,index+1) T = int(input()) for _ in range(T): n=int(input()) ls= list(map(int, input().split())) fun(ls,n) # Concept # let num be a,b # apply 1 a+b,b # apply 2 a+b,-a # apply 1 b,-a # apply 1 -a+b,-a # apply 2 -a+b,-b # apply 1 -a,-b # 6 operation for 2 num = 3 operation for one number sototal 3*n operation ```
6,848
Provide tags and a correct Python 3 solution for this coding contest problem. <image> While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n. For some unknown reason, the number of service variables is always an even number. William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5 000 and after every operation no variable can have an absolute value greater than 10^{18}. William can perform actions of two types for two chosen variables with indices i and j, where i < j: 1. Perform assignment a_i = a_i + a_j 2. Perform assignment a_j = a_j - a_i William wants you to develop a strategy that will get all the internal variables to the desired values. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≀ t ≀ 20). Description of the test cases follows. The first line of each test case contains a single even integer n (2 ≀ n ≀ 10^3), which is the number of internal variables. The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), which are initial values of internal variables. Output For each test case print the answer in the following format: The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k ≀ 5 000 must be satisfied. Each of the next k lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i < j should hold. We can show that an answer always exists. Example Input 2 4 1 1 1 1 4 4 3 1 2 Output 8 2 1 2 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 1 1 2 1 1 2 8 2 1 4 1 2 4 1 2 4 1 2 4 1 3 4 1 1 2 1 1 2 1 1 4 Note For the first sample test case one possible sequence of operations is as follows: 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1] 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1] 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1] 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1] 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0] 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1] 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1] 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows: 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2] 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2] 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2] 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2] 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2] 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2] 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2] 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2] Tags: constructive algorithms Correct Solution: ``` t = int(input()) while t: n = int(input()) l = [int(i) for i in input().split()] print(6*(n//2)) i = 0 while i<n: print('2' + " " + str(i+1) + " " + str(i+2)) print('1' + " " + str(i+1) + " " + str(i+2)) print('2' + " " + str(i+1) + " " + str(i+2)) print('1' + " " + str(i+1) + " " + str(i+2)) print('2' + " " + str(i+1) + " " + str(i+2)) print('1' + " " + str(i+1) + " " + str(i+2)) i+=2 t-=1 ```
6,849
Provide tags and a correct Python 3 solution for this coding contest problem. <image> While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n. For some unknown reason, the number of service variables is always an even number. William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5 000 and after every operation no variable can have an absolute value greater than 10^{18}. William can perform actions of two types for two chosen variables with indices i and j, where i < j: 1. Perform assignment a_i = a_i + a_j 2. Perform assignment a_j = a_j - a_i William wants you to develop a strategy that will get all the internal variables to the desired values. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≀ t ≀ 20). Description of the test cases follows. The first line of each test case contains a single even integer n (2 ≀ n ≀ 10^3), which is the number of internal variables. The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), which are initial values of internal variables. Output For each test case print the answer in the following format: The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k ≀ 5 000 must be satisfied. Each of the next k lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i < j should hold. We can show that an answer always exists. Example Input 2 4 1 1 1 1 4 4 3 1 2 Output 8 2 1 2 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 1 1 2 1 1 2 8 2 1 4 1 2 4 1 2 4 1 2 4 1 3 4 1 1 2 1 1 2 1 1 4 Note For the first sample test case one possible sequence of operations is as follows: 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1] 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1] 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1] 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1] 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0] 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1] 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1] 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows: 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2] 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2] 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2] 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2] 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2] 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2] 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2] 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2] Tags: constructive algorithms Correct Solution: ``` import sys import math import bisect from sys import stdin, stdout from math import gcd, floor, sqrt, log from collections import defaultdict as dd from bisect import bisect_left as bl, bisect_right as br from collections import Counter from collections import defaultdict as dd # sys.setrecursionlimit(100000000) flush = lambda: stdout.flush() stdstr = lambda: stdin.readline() stdint = lambda: int(stdin.readline()) stdpr = lambda x: stdout.write(str(x)) stdmap = lambda: map(int, stdstr().split()) stdarr = lambda: list(map(int, stdstr().split())) mod = 1000000007 def f(arr, i, j): arr[i] = arr[i] + arr[j] def s(arr, i, j): arr[j] = arr[j]-arr[i] for _ in range(stdint()): n = stdint() arr = stdarr() res = [] for i in range(0, n, 2): x,y = i+1, i+2 res.append([1, x,y]) # f(arr, x, y) res.append([2, x,y]) # s(arr, x, y) res.append([2, x, y]) # s(arr, x, y) res.append([1,x,y]) # f(arr, x, y) res.append([2,x,y]) # s(arr, x, y) res.append([2,x,y]) # s(arr, x, y) print(len(res)) for i in res: print(*i) ```
6,850
Provide tags and a correct Python 3 solution for this coding contest problem. <image> While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n. For some unknown reason, the number of service variables is always an even number. William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5 000 and after every operation no variable can have an absolute value greater than 10^{18}. William can perform actions of two types for two chosen variables with indices i and j, where i < j: 1. Perform assignment a_i = a_i + a_j 2. Perform assignment a_j = a_j - a_i William wants you to develop a strategy that will get all the internal variables to the desired values. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≀ t ≀ 20). Description of the test cases follows. The first line of each test case contains a single even integer n (2 ≀ n ≀ 10^3), which is the number of internal variables. The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), which are initial values of internal variables. Output For each test case print the answer in the following format: The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k ≀ 5 000 must be satisfied. Each of the next k lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i < j should hold. We can show that an answer always exists. Example Input 2 4 1 1 1 1 4 4 3 1 2 Output 8 2 1 2 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 1 1 2 1 1 2 8 2 1 4 1 2 4 1 2 4 1 2 4 1 3 4 1 1 2 1 1 2 1 1 4 Note For the first sample test case one possible sequence of operations is as follows: 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1] 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1] 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1] 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1] 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0] 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1] 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1] 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows: 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2] 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2] 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2] 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2] 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2] 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2] 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2] 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2] Tags: constructive algorithms Correct Solution: ``` t = int(input()) while t > 0: t -= 1 n = int(input()) input() print(6 * n // 2) for i in range(0, n, 2): print('2', i + 1, i + 2) print('2', i + 1, i + 2) print('1', i + 1, i + 2) print('2', i + 1, i + 2) print('2', i + 1, i + 2) print('1', i + 1, i + 2) # from copy import copy # # b = [2, 3] # for mask in range(64): # a = copy(b) # for i in range(6): # if mask >> i & 1: # a[0] += a[1] # else: # a[1] -= a[0] # # print(a) # if a == [-2, -3]: # print(mask) ```
6,851
Provide tags and a correct Python 3 solution for this coding contest problem. <image> While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n. For some unknown reason, the number of service variables is always an even number. William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5 000 and after every operation no variable can have an absolute value greater than 10^{18}. William can perform actions of two types for two chosen variables with indices i and j, where i < j: 1. Perform assignment a_i = a_i + a_j 2. Perform assignment a_j = a_j - a_i William wants you to develop a strategy that will get all the internal variables to the desired values. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≀ t ≀ 20). Description of the test cases follows. The first line of each test case contains a single even integer n (2 ≀ n ≀ 10^3), which is the number of internal variables. The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), which are initial values of internal variables. Output For each test case print the answer in the following format: The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k ≀ 5 000 must be satisfied. Each of the next k lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i < j should hold. We can show that an answer always exists. Example Input 2 4 1 1 1 1 4 4 3 1 2 Output 8 2 1 2 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 1 1 2 1 1 2 8 2 1 4 1 2 4 1 2 4 1 2 4 1 3 4 1 1 2 1 1 2 1 1 4 Note For the first sample test case one possible sequence of operations is as follows: 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1] 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1] 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1] 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1] 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0] 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1] 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1] 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows: 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2] 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2] 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2] 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2] 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2] 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2] 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2] 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2] Tags: constructive algorithms Correct Solution: ``` import os import sys from io import BytesIO, IOBase from collections import Counter import math as mt BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) def gcd(a, b): if a == 0: return b return gcd(b % a, a) def lcm(a, b): return (a * b) / gcd(a, b) mod = int(1e9) + 7 def power(k, n): if n == 0: return 1 if n % 2: return (power(k, n - 1) * k) % mod t = power(k, n // 2) return (t * t) % mod def totalPrimeFactors(n): count = 0 if (n % 2) == 0: count += 1 while (n % 2) == 0: n //= 2 i = 3 while i * i <= n: if (n % i) == 0: count += 1 while (n % i) == 0: n //= i i += 2 if n > 2: count += 1 return count # #MAXN = int(1e7 + 1) # # spf = [0 for i in range(MAXN)] # # # def sieve(): # spf[1] = 1 # for i in range(2, MAXN): # spf[i] = i # for i in range(4, MAXN, 2): # spf[i] = 2 # # for i in range(3, mt.ceil(mt.sqrt(MAXN))): # if (spf[i] == i): # for j in range(i * i, MAXN, i): # if (spf[j] == j): # spf[j] = i # # # def getFactorization(x): # ret = 0 # while (x != 1): # k = spf[x] # ret += 1 # # ret.add(spf[x]) # while x % k == 0: # x //= k # # return ret # Driver code # precalculating Smallest Prime Factor # sieve() def main(): for _ in range(int(input())): n=int(input()) a=list(map(int, input().split())) ans=[] for i in range(0, n, 2): ans.append([1, i, i+1]) ans.append([2, i, i+1]) ans.append([2, i, i+1]) ans.append([1, i, i + 1]) ans.append([2, i, i + 1]) ans.append([2, i, i + 1]) print(len(ans)) for i in ans: print(i[0], i[1]+1, i[2]+1) return if __name__ == "__main__": main() ```
6,852
Provide tags and a correct Python 3 solution for this coding contest problem. <image> While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n. For some unknown reason, the number of service variables is always an even number. William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5 000 and after every operation no variable can have an absolute value greater than 10^{18}. William can perform actions of two types for two chosen variables with indices i and j, where i < j: 1. Perform assignment a_i = a_i + a_j 2. Perform assignment a_j = a_j - a_i William wants you to develop a strategy that will get all the internal variables to the desired values. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≀ t ≀ 20). Description of the test cases follows. The first line of each test case contains a single even integer n (2 ≀ n ≀ 10^3), which is the number of internal variables. The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), which are initial values of internal variables. Output For each test case print the answer in the following format: The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k ≀ 5 000 must be satisfied. Each of the next k lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i < j should hold. We can show that an answer always exists. Example Input 2 4 1 1 1 1 4 4 3 1 2 Output 8 2 1 2 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 1 1 2 1 1 2 8 2 1 4 1 2 4 1 2 4 1 2 4 1 3 4 1 1 2 1 1 2 1 1 4 Note For the first sample test case one possible sequence of operations is as follows: 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1] 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1] 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1] 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1] 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0] 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1] 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1] 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows: 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2] 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2] 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2] 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2] 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2] 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2] 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2] 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2] Tags: constructive algorithms Correct Solution: ``` a=int(input()) import sys input=sys.stdin.readline for i in range(a): n=int(input()) z=list(map(int,input().split())) print(3*len(z)) for i in range(0,len(z),2): print(1,i+1,i+2) print(2,i+1,i+2) print(1,i+1,i+2) print(2,i+1,i+2) print(1,i+1,i+2) print(2,i+1,i+2) ```
6,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. <image> While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n. For some unknown reason, the number of service variables is always an even number. William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5 000 and after every operation no variable can have an absolute value greater than 10^{18}. William can perform actions of two types for two chosen variables with indices i and j, where i < j: 1. Perform assignment a_i = a_i + a_j 2. Perform assignment a_j = a_j - a_i William wants you to develop a strategy that will get all the internal variables to the desired values. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≀ t ≀ 20). Description of the test cases follows. The first line of each test case contains a single even integer n (2 ≀ n ≀ 10^3), which is the number of internal variables. The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), which are initial values of internal variables. Output For each test case print the answer in the following format: The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k ≀ 5 000 must be satisfied. Each of the next k lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i < j should hold. We can show that an answer always exists. Example Input 2 4 1 1 1 1 4 4 3 1 2 Output 8 2 1 2 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 1 1 2 1 1 2 8 2 1 4 1 2 4 1 2 4 1 2 4 1 3 4 1 1 2 1 1 2 1 1 4 Note For the first sample test case one possible sequence of operations is as follows: 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1] 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1] 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1] 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1] 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0] 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1] 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1] 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows: 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2] 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2] 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2] 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2] 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2] 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2] 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2] 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2] Submitted Solution: ``` for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) print(n*3) for i in range(1, n, 2): for j in range(3): print(1, i, i+1) print(2, i, i+1) ###### thanking telegram for solutions ###### '''__________ ____ ___ _____________ __.___ \______ \ | \/ _____/ |/ _| | | _/ | /\_____ \| < | | | | \ | / / \ | \| | |____|_ /______/ /_______ /____|__ \___| ''' ``` Yes
6,854
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. <image> While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n. For some unknown reason, the number of service variables is always an even number. William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5 000 and after every operation no variable can have an absolute value greater than 10^{18}. William can perform actions of two types for two chosen variables with indices i and j, where i < j: 1. Perform assignment a_i = a_i + a_j 2. Perform assignment a_j = a_j - a_i William wants you to develop a strategy that will get all the internal variables to the desired values. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≀ t ≀ 20). Description of the test cases follows. The first line of each test case contains a single even integer n (2 ≀ n ≀ 10^3), which is the number of internal variables. The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), which are initial values of internal variables. Output For each test case print the answer in the following format: The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k ≀ 5 000 must be satisfied. Each of the next k lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i < j should hold. We can show that an answer always exists. Example Input 2 4 1 1 1 1 4 4 3 1 2 Output 8 2 1 2 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 1 1 2 1 1 2 8 2 1 4 1 2 4 1 2 4 1 2 4 1 3 4 1 1 2 1 1 2 1 1 4 Note For the first sample test case one possible sequence of operations is as follows: 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1] 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1] 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1] 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1] 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0] 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1] 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1] 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows: 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2] 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2] 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2] 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2] 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2] 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2] 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2] 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2] Submitted Solution: ``` t=int(input()) def solve(): n=int(input()) arr=list(map(int,input().split())) print(n*3) for i in range(1,n+1,2): print(2,i,i+1) print(1,i,i+1) print(2,i,i+1) print(2,i,i+1) print(1,i,i+1) print(2,i,i+1) for i in range(t): solve() ``` Yes
6,855
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. <image> While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n. For some unknown reason, the number of service variables is always an even number. William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5 000 and after every operation no variable can have an absolute value greater than 10^{18}. William can perform actions of two types for two chosen variables with indices i and j, where i < j: 1. Perform assignment a_i = a_i + a_j 2. Perform assignment a_j = a_j - a_i William wants you to develop a strategy that will get all the internal variables to the desired values. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≀ t ≀ 20). Description of the test cases follows. The first line of each test case contains a single even integer n (2 ≀ n ≀ 10^3), which is the number of internal variables. The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), which are initial values of internal variables. Output For each test case print the answer in the following format: The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k ≀ 5 000 must be satisfied. Each of the next k lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i < j should hold. We can show that an answer always exists. Example Input 2 4 1 1 1 1 4 4 3 1 2 Output 8 2 1 2 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 1 1 2 1 1 2 8 2 1 4 1 2 4 1 2 4 1 2 4 1 3 4 1 1 2 1 1 2 1 1 4 Note For the first sample test case one possible sequence of operations is as follows: 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1] 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1] 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1] 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1] 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0] 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1] 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1] 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows: 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2] 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2] 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2] 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2] 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2] 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2] 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2] 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2] Submitted Solution: ``` import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) t = I() for _ in range(t): n = I() A = LI() print(3*n) for i in range(n//2): x = 2*i+1 y = 2*i+2 for a in [1,2,1,1,2,1]: print(a,x,y) ``` Yes
6,856
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. <image> While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n. For some unknown reason, the number of service variables is always an even number. William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5 000 and after every operation no variable can have an absolute value greater than 10^{18}. William can perform actions of two types for two chosen variables with indices i and j, where i < j: 1. Perform assignment a_i = a_i + a_j 2. Perform assignment a_j = a_j - a_i William wants you to develop a strategy that will get all the internal variables to the desired values. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≀ t ≀ 20). Description of the test cases follows. The first line of each test case contains a single even integer n (2 ≀ n ≀ 10^3), which is the number of internal variables. The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), which are initial values of internal variables. Output For each test case print the answer in the following format: The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k ≀ 5 000 must be satisfied. Each of the next k lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i < j should hold. We can show that an answer always exists. Example Input 2 4 1 1 1 1 4 4 3 1 2 Output 8 2 1 2 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 1 1 2 1 1 2 8 2 1 4 1 2 4 1 2 4 1 2 4 1 3 4 1 1 2 1 1 2 1 1 4 Note For the first sample test case one possible sequence of operations is as follows: 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1] 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1] 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1] 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1] 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0] 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1] 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1] 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows: 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2] 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2] 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2] 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2] 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2] 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2] 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2] 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2] Submitted Solution: ``` #!/usr/bin/env python import os import sys from io import BytesIO, IOBase import math from collections import Counter def func(array): print(3 * len(array)) for i in range(0, len(array), 2): for j in range(3): print(f"2 {i+1} {i+2}") print(f"1 {i+1} {i+2}") def main(): num_test = int(parse_input()) result = [] for _ in range(num_test): n = int(parse_input()) array = [int(i) for i in parse_input().split()] func(array) # print("\n".join(map(str, result))) # region fastio # BUFSIZE = 8192 # class FastIO(IOBase): # newlines = 0 # def __init__(self, file): # self._fd = file.fileno() # self.buffer = BytesIO() # self.writable = "x" in file.mode or "r" not in file.mode # self.write = self.buffer.write if self.writable else None # def read(self): # while True: # b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) # if not b: # break # ptr = self.buffer.tell() # self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) # self.newlines = 0 # return self.buffer.read() # def readline(self): # while self.newlines == 0: # b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) # self.newlines = b.count(b"\n") + (not b) # ptr = self.buffer.tell() # self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) # self.newlines -= 1 # return self.buffer.readline() # def flush(self): # if self.writable: # os.write(self._fd, self.buffer.getvalue()) # self.buffer.truncate(0), self.buffer.seek(0) # class IOWrapper(IOBase): # def __init__(self, file): # self.buffer = FastIO(file) # self.flush = self.buffer.flush # self.writable = self.buffer.writable # self.write = lambda s: self.buffer.write(s.encode("ascii")) # self.read = lambda: self.buffer.read().decode("ascii") # self.readline = lambda: self.buffer.readline().decode("ascii") # sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) parse_input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() ``` Yes
6,857
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. <image> While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n. For some unknown reason, the number of service variables is always an even number. William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5 000 and after every operation no variable can have an absolute value greater than 10^{18}. William can perform actions of two types for two chosen variables with indices i and j, where i < j: 1. Perform assignment a_i = a_i + a_j 2. Perform assignment a_j = a_j - a_i William wants you to develop a strategy that will get all the internal variables to the desired values. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≀ t ≀ 20). Description of the test cases follows. The first line of each test case contains a single even integer n (2 ≀ n ≀ 10^3), which is the number of internal variables. The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), which are initial values of internal variables. Output For each test case print the answer in the following format: The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k ≀ 5 000 must be satisfied. Each of the next k lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i < j should hold. We can show that an answer always exists. Example Input 2 4 1 1 1 1 4 4 3 1 2 Output 8 2 1 2 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 1 1 2 1 1 2 8 2 1 4 1 2 4 1 2 4 1 2 4 1 3 4 1 1 2 1 1 2 1 1 4 Note For the first sample test case one possible sequence of operations is as follows: 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1] 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1] 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1] 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1] 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0] 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1] 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1] 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows: 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2] 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2] 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2] 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2] 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2] 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2] 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2] 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2] Submitted Solution: ``` #from _typeshed import SupportsKeysAndGetItem import sys #sys.stdin=open("input.txt","r"); #sys.stdout=open("output.txt","w") ####### GLOBAL ############### MOD=1000000007 no=lambda:print("NO") yes=lambda:print("YES") _1=lambda:print(-1) ari=lambda:[int(_) for _ in input().split()] cin=lambda:int(input()) cis=lambda:input() show=lambda x: print(x) ########### END ######### ###### test_case=1 test_case=int(input()) ###### def ans(): n=cin() a=ari() cnt=0 index=0 temp_arr=[] final_ans=[] for i in range(n): temp_arr.append(a[i]*-1) def help(first,last): nonlocal temp_arr nonlocal a nonlocal final_ans c=0 while True: a[last]=a[last]-a[first] c+=1 final_ans.append((2,first,last)) if a[last]==temp_arr[last] and a[first]==temp_arr[first]: break final_ans.append((1,first,last)) a[first]=a[first]+a[last] c+=1 if a[last]==temp_arr[last] and a[first]==temp_arr[first]: break return c for i in range(0,n,2): cnt+= help(i,i+1) print(cnt) for i in final_ans: j,k,l=i[0],i[1],i[2] print(j,k,l) return for _ in range(test_case): ans() ``` No
6,858
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. <image> While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n. For some unknown reason, the number of service variables is always an even number. William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5 000 and after every operation no variable can have an absolute value greater than 10^{18}. William can perform actions of two types for two chosen variables with indices i and j, where i < j: 1. Perform assignment a_i = a_i + a_j 2. Perform assignment a_j = a_j - a_i William wants you to develop a strategy that will get all the internal variables to the desired values. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≀ t ≀ 20). Description of the test cases follows. The first line of each test case contains a single even integer n (2 ≀ n ≀ 10^3), which is the number of internal variables. The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), which are initial values of internal variables. Output For each test case print the answer in the following format: The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k ≀ 5 000 must be satisfied. Each of the next k lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i < j should hold. We can show that an answer always exists. Example Input 2 4 1 1 1 1 4 4 3 1 2 Output 8 2 1 2 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 1 1 2 1 1 2 8 2 1 4 1 2 4 1 2 4 1 2 4 1 3 4 1 1 2 1 1 2 1 1 4 Note For the first sample test case one possible sequence of operations is as follows: 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1] 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1] 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1] 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1] 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0] 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1] 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1] 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows: 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2] 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2] 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2] 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2] 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2] 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2] 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2] 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2] Submitted Solution: ``` for i in range(int(input())): n=int(input()) li=list(map(int,input().split())) b=[] for j in range(0,n,2): if li[j]<li[j+1]: b.append(8) if li[j]==li[j+1]: b.append(4) if li[j]>li[j+1]: b.append(6) print(sum(b)) for j in range(0,n,2): if li[j]<li[j+1]: print(1, j + 1, j + 2) print(2, j + 1, j + 2) print(1, j + 1, j + 2) print(2, j + 1, j + 2) print(1, j + 1, j + 2) print(2, j + 1, j + 2) print(1, j + 1, j + 2) print(1, j + 1, j + 2) if li[j]==li[j+1]: print(2, j + 1, j + 2) print(2, j + 1, j + 2) print(1, j + 1, j + 2) print(1, j + 1, j + 2) if li[j]>li[j+1]: print(2, j + 1, j + 2) print(1, j + 1, j + 2) print(2, j + 1, j + 2) print(1, j + 1, j + 2) print(2, j + 1, j + 2) print(1, j + 1, j + 2) ``` No
6,859
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. <image> While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n. For some unknown reason, the number of service variables is always an even number. William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5 000 and after every operation no variable can have an absolute value greater than 10^{18}. William can perform actions of two types for two chosen variables with indices i and j, where i < j: 1. Perform assignment a_i = a_i + a_j 2. Perform assignment a_j = a_j - a_i William wants you to develop a strategy that will get all the internal variables to the desired values. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≀ t ≀ 20). Description of the test cases follows. The first line of each test case contains a single even integer n (2 ≀ n ≀ 10^3), which is the number of internal variables. The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), which are initial values of internal variables. Output For each test case print the answer in the following format: The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k ≀ 5 000 must be satisfied. Each of the next k lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i < j should hold. We can show that an answer always exists. Example Input 2 4 1 1 1 1 4 4 3 1 2 Output 8 2 1 2 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 1 1 2 1 1 2 8 2 1 4 1 2 4 1 2 4 1 2 4 1 3 4 1 1 2 1 1 2 1 1 4 Note For the first sample test case one possible sequence of operations is as follows: 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1] 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1] 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1] 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1] 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0] 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1] 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1] 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows: 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2] 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2] 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2] 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2] 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2] 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2] 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2] 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2] Submitted Solution: ``` def solve(): n = int(input()) s = list(map(int,input().split())) for i in range(0,n,2): j = i+1 print(2,i,j) print(1,i,j) print(2,i,j) print(2,i,j) print(1,i,j) print(2,i,j) for nt in range(int(input())): solve() ``` No
6,860
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. <image> While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n. For some unknown reason, the number of service variables is always an even number. William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed 5 000 and after every operation no variable can have an absolute value greater than 10^{18}. William can perform actions of two types for two chosen variables with indices i and j, where i < j: 1. Perform assignment a_i = a_i + a_j 2. Perform assignment a_j = a_j - a_i William wants you to develop a strategy that will get all the internal variables to the desired values. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≀ t ≀ 20). Description of the test cases follows. The first line of each test case contains a single even integer n (2 ≀ n ≀ 10^3), which is the number of internal variables. The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 10^9), which are initial values of internal variables. Output For each test case print the answer in the following format: The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k ≀ 5 000 must be satisfied. Each of the next k lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that i < j should hold. We can show that an answer always exists. Example Input 2 4 1 1 1 1 4 4 3 1 2 Output 8 2 1 2 2 1 2 2 1 3 2 1 3 2 1 4 2 1 4 1 1 2 1 1 2 8 2 1 4 1 2 4 1 2 4 1 2 4 1 3 4 1 1 2 1 1 2 1 1 4 Note For the first sample test case one possible sequence of operations is as follows: 1. "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1] 2. "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1] 3. "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1] 4. "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1] 5. "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0] 6. "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1] 7. "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1] 8. "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows: 1. "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2] 2. "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2] 3. "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2] 4. "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2] 5. "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2] 6. "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2] 7. "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2] 8. "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2] Submitted Solution: ``` for i in range(int(input())): n = int(input()) li = list(map(int,input().split())) for j in range(1,len(li)+1,2): print(1,j,j+1) print(2,j,j+1) print(1,j,j+1) print(1,j,j+1) print(2,j,j+1) print(1,j,j+1) ``` No
6,861
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input The first line contains the single integer n (1 ≀ n ≀ 1000) β€” the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Examples Input 5 100 50 200 150 200 Output 2 Input 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Output 4 Note In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing. Tags: brute force Correct Solution: ``` n=int(input()) a=[int(i) for i in input().split()] ans=0 big=a[0] small=a[0] for i in range(1,n): if a[i]>big: big=a[i] ans+=1 elif a[i]<small: small=a[i] ans+=1 print(ans) ```
6,862
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input The first line contains the single integer n (1 ≀ n ≀ 1000) β€” the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Examples Input 5 100 50 200 150 200 Output 2 Input 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Output 4 Note In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing. Tags: brute force Correct Solution: ``` n = input() arr = list(map(int, input().split())) amazing = 0 for i, a in enumerate(arr): if i == 0: mx = mn = a else: if a > mx: amazing += 1 mx = a if a < mn: amazing += 1 mn = a print(amazing) ```
6,863
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input The first line contains the single integer n (1 ≀ n ≀ 1000) β€” the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Examples Input 5 100 50 200 150 200 Output 2 Input 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Output 4 Note In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing. Tags: brute force Correct Solution: ``` n=int(input()) b=input().split() t=[] m=[] score=0 for i in range(1,n+1): t.append(int(b[i-1])) if len(t)>1: if t[-1]>max(m) or t[-1]<min(m): score=score+1 m.append(int(b[i-1])) else: m.append(int(b[i-1])) else: m.append(int(b[i-1])) print(score) ```
6,864
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input The first line contains the single integer n (1 ≀ n ≀ 1000) β€” the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Examples Input 5 100 50 200 150 200 Output 2 Input 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Output 4 Note In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing. Tags: brute force Correct Solution: ``` n = int(input()) p = list(map(int, input().split())) amazing = 0 for x in range(1, n): if p[x] == p[0]: continue elif p[x] > p[0]: for y in range(1, x): if p[x] <= p[y]: break else: amazing += 1 elif p[x] < p[0]: for y in range(1, x): if p[x] >= p[y]: break else: amazing += 1 print(amazing) ```
6,865
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input The first line contains the single integer n (1 ≀ n ≀ 1000) β€” the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Examples Input 5 100 50 200 150 200 Output 2 Input 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Output 4 Note In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing. Tags: brute force Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) a=l[0] b=l[0] c=0 for i in l: if i>a: c=c+1 a=i for i in l: if i<b: c=c+1 b=i print(c) ```
6,866
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input The first line contains the single integer n (1 ≀ n ≀ 1000) β€” the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Examples Input 5 100 50 200 150 200 Output 2 Input 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Output 4 Note In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing. Tags: brute force Correct Solution: ``` n=int(input()) lst=list(map(int,input().split())) MAX=MIN=lst[0] ans=0 for i in lst[1:]: if i>MAX: MAX=i ans+=1 if i<MIN: MIN=i ans+=1 print(ans) ```
6,867
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input The first line contains the single integer n (1 ≀ n ≀ 1000) β€” the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Examples Input 5 100 50 200 150 200 Output 2 Input 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Output 4 Note In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing. Tags: brute force Correct Solution: ``` a=int(input()) b=list(map(int,input().split())) x=int(1) m=b[0] n=b[0] t=[] t.append(b[0]) k=int(0) while x<a: if b[x]>m or b[x]<n: k=k+1 t.append(b[x]) m=max(t) n=min(t) x=x+1 print(k) ```
6,868
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input The first line contains the single integer n (1 ≀ n ≀ 1000) β€” the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Examples Input 5 100 50 200 150 200 Output 2 Input 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Output 4 Note In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing. Tags: brute force Correct Solution: ``` def main(): n = int(input()) scores = list(map(int , input().split())) m, M, count = scores[0], scores[0], 0 for i in range(1, n): if m < scores[i]: m = scores[i] count += 1 elif M > scores[i]: M = scores[i] count+= 1 print(count) main() ```
6,869
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input The first line contains the single integer n (1 ≀ n ≀ 1000) β€” the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Examples Input 5 100 50 200 150 200 Output 2 Input 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Output 4 Note In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing. Submitted Solution: ``` n=int(input()) l=list(map(int,input().split())) mx=l[0] mn=l[0] c=0 for i in range(1,n): if l[i]>mx: c+=1 mx=l[i] if l[i]<mn: c+=1 mn=l[i] print(c) ``` Yes
6,870
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input The first line contains the single integer n (1 ≀ n ≀ 1000) β€” the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Examples Input 5 100 50 200 150 200 Output 2 Input 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Output 4 Note In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing. Submitted Solution: ``` n = int(input()) contest_scores = list(map(int, input().split())) min_score = max_score = contest_scores[0] result = 0 for k in range(1, len(contest_scores)): tmp_score = contest_scores[k] if tmp_score > max_score: result += 1 if tmp_score < min_score: result += 1 max_score = max(tmp_score, max_score) min_score = min(tmp_score, min_score) print(result) ``` Yes
6,871
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input The first line contains the single integer n (1 ≀ n ≀ 1000) β€” the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Examples Input 5 100 50 200 150 200 Output 2 Input 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Output 4 Note In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing. Submitted Solution: ``` n = int(input()) t = [int(x) for x in input().split()] k = 0 l = t[0] m = t[0] for i in range(1,n): if t[i] > l: k += 1 l = t[i] elif t[i] < m: k += 1 m = t[i] print(k) ``` Yes
6,872
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input The first line contains the single integer n (1 ≀ n ≀ 1000) β€” the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Examples Input 5 100 50 200 150 200 Output 2 Input 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Output 4 Note In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing. Submitted Solution: ``` n = int(input()) max = -1 min = 1e9 ans = 0 for i in map(int, input().split(' ')): if i > max: max = i ans += 1 if i < min: min = i ans += 1 print(ans - 2) ``` Yes
6,873
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input The first line contains the single integer n (1 ≀ n ≀ 1000) β€” the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Examples Input 5 100 50 200 150 200 Output 2 Input 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Output 4 Note In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing. Submitted Solution: ``` lines = '' for i in range(2): lines+=input()+"\n" lines = lines.split('\n') nums = map(int, lines[1].split(" ")) u, q = 0, 0 x = [] for n in nums: if n > q: u += 1 q = n print(u - 1 or 1 if int(lines[0]) > 0 else 0) ``` No
6,874
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input The first line contains the single integer n (1 ≀ n ≀ 1000) β€” the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Examples Input 5 100 50 200 150 200 Output 2 Input 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Output 4 Note In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing. Submitted Solution: ``` def funct(n,l): cnt=0 for i in range(1,n): if(l[i]>l[i-1]): cnt+=1 return cnt n=int(input()) l=list(map(int,input().split())) print(funct(n,l)) ``` No
6,875
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input The first line contains the single integer n (1 ≀ n ≀ 1000) β€” the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Examples Input 5 100 50 200 150 200 Output 2 Input 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Output 4 Note In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing. Submitted Solution: ``` a=int(input()) nume=[] nume=input().split(" ") soma=0 if a<10: for i in nume: soma+=int(i) media=soma/a cont=0 for i in nume: if media<int(i): cont+=1 print(cont-1) else: for i in nume: soma+=int(i) media=soma/a cont=0 for i in nume: if media<int(i): cont+=1 print(cont) ``` No
6,876
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input The first line contains the single integer n (1 ≀ n ≀ 1000) β€” the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Examples Input 5 100 50 200 150 200 Output 2 Input 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Output 4 Note In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing. Submitted Solution: ``` k=int(input()) ls=list(map(int,input().split())) count=0 for i in range(1,k): if ls[i]>ls[i-1]: count+=1 print(count) ``` No
6,877
Provide tags and a correct Python 3 solution for this coding contest problem. To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: * all his friends should also be invited to the party; * the party shouldn't have any people he dislikes; * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≀ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite. Input The first line of input contains an integer n β€” the number of the Beaver's acquaintances. The second line contains an integer k <image> β€” the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> β€” indices of people who form the i-th pair of friends. The next line contains an integer m <image> β€” the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: * 2 ≀ n ≀ 14 The input limitations for getting 100 points are: * 2 ≀ n ≀ 2000 Output Output a single number β€” the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Examples Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Output 3 Note Let's have a look at the example. <image> Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected). Tags: dfs and similar, dsu, graphs Correct Solution: ``` from sys import stdin, stdout def find(node): x = [] while dsu[node] > 0: x.append(node) node = dsu[node] for i in x: dsu[i] = node return node def union(node1, node2): if node1 != node2: if dsu[node1] > dsu[node2]: node1, node2 = node2, node1 dsu[node1] += dsu[node2] dsu[node2] = node1 n = int(stdin.readline().strip()) dsu = [-1]*(n+1) m = int(stdin.readline().strip()) for __ in range(m): a, b = map(int, stdin.readline().strip().split()) union(find(a), find(b)) k = int(stdin.readline().strip()) for __ in range(k): a, b = map(int, stdin.readline().strip().split()) p_a = find(a) p_b = find(b) if p_a == p_b: dsu[p_a] = 0 maxm = 0 for i in range(1, n+1): if dsu[i] < 0: maxm = max(maxm, abs(dsu[i])) stdout.write(f'{maxm}') ```
6,878
Provide tags and a correct Python 3 solution for this coding contest problem. To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: * all his friends should also be invited to the party; * the party shouldn't have any people he dislikes; * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≀ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite. Input The first line of input contains an integer n β€” the number of the Beaver's acquaintances. The second line contains an integer k <image> β€” the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> β€” indices of people who form the i-th pair of friends. The next line contains an integer m <image> β€” the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: * 2 ≀ n ≀ 14 The input limitations for getting 100 points are: * 2 ≀ n ≀ 2000 Output Output a single number β€” the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Examples Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Output 3 Note Let's have a look at the example. <image> Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected). Tags: dfs and similar, dsu, graphs Correct Solution: ``` from sys import setrecursionlimit setrecursionlimit(10 ** 9) def dfs(g, col, st): global used used[st] = col for w in g[st]: if used[w] is False: dfs(g, col, w) n = int(input()) k = int(input()) g = [] used = [False] * n for i in range(n): g.append([]) for i in range(k): x, y = map(int, input().split()) g[x - 1].append(y - 1) g[y - 1].append(x - 1) cur = 0 for i in range(n): if used[i] is False: dfs(g, cur, i) cur += 1 k = int(input()) lst = [0] * n for i in range(k): x, y = map(int, input().split()) x -= 1 y -= 1 if used[x] == used[y]: lst[used[x]] = -1 for i in range(n): if lst[used[i]] != -1: lst[used[i]] += 1 print(max(0, max(lst))) ```
6,879
Provide tags and a correct Python 3 solution for this coding contest problem. To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: * all his friends should also be invited to the party; * the party shouldn't have any people he dislikes; * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≀ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite. Input The first line of input contains an integer n β€” the number of the Beaver's acquaintances. The second line contains an integer k <image> β€” the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> β€” indices of people who form the i-th pair of friends. The next line contains an integer m <image> β€” the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: * 2 ≀ n ≀ 14 The input limitations for getting 100 points are: * 2 ≀ n ≀ 2000 Output Output a single number β€” the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Examples Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Output 3 Note Let's have a look at the example. <image> Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected). Tags: dfs and similar, dsu, graphs Correct Solution: ``` t, p, k = [0] * (int(input()) + 1), {0: []}, 1 for i in range(int(input())): a, b = map(int, input().split()) if t[a] == t[b]: if t[a] == 0: t[a] = t[b] = k p[k] = [a, b] k += 1 else: if t[a] == 0: t[a] = t[b] p[t[b]].append(a) elif t[b] == 0: t[b] = t[a] p[t[a]].append(b) else: x, y = t[b], t[a] for c in p[x]: t[c] = y p[y] += p[x] p[x] = [] for i in range(int(input())): a, b = map(int, input().split()) if t[a] == t[b]: p[t[a]] = [] ans = max(len(p[i]) for i in p) print(ans if ans > 0 else int(0 in t[1:])) ```
6,880
Provide tags and a correct Python 3 solution for this coding contest problem. To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: * all his friends should also be invited to the party; * the party shouldn't have any people he dislikes; * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≀ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite. Input The first line of input contains an integer n β€” the number of the Beaver's acquaintances. The second line contains an integer k <image> β€” the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> β€” indices of people who form the i-th pair of friends. The next line contains an integer m <image> β€” the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: * 2 ≀ n ≀ 14 The input limitations for getting 100 points are: * 2 ≀ n ≀ 2000 Output Output a single number β€” the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Examples Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Output 3 Note Let's have a look at the example. <image> Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected). Tags: dfs and similar, dsu, graphs Correct Solution: ``` class DSNode: def __init__(self, val): self.val = val self.rank = 0 self.parent = self self.correct = True def __str__(self): return str(self.find().val) def find(self): x = self if x != x.parent: x.parent = x.parent.find() return x.parent def union(x, y): x = x.find() y = y.find() if x == y: return if x.rank > y.rank: y.parent = x else: x.parent = y if x.rank == y.rank: y.rank += 1 # Amount of people n = int(input()) # Pairs of friends k = int(input()) P = [DSNode(x) for x in range(n+1)] for i in range(k): u, v = map(int, input().split(' ')) union(P[u], P[v]) # Pairs of people who dislike each other m = int(input()) for i in range(m): u, v = map(int, input().split(' ')) u1, v1 = P[u].find(), P[v].find() if u1 == v1: u1.correct = False max_size = 0 A = [0 for _ in range(n + 1)] for i in range(1, n+1): p = P[i] p = p.find() if p.correct: A[p.val] += 1 print(max(A)) ```
6,881
Provide tags and a correct Python 3 solution for this coding contest problem. To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: * all his friends should also be invited to the party; * the party shouldn't have any people he dislikes; * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≀ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite. Input The first line of input contains an integer n β€” the number of the Beaver's acquaintances. The second line contains an integer k <image> β€” the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> β€” indices of people who form the i-th pair of friends. The next line contains an integer m <image> β€” the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: * 2 ≀ n ≀ 14 The input limitations for getting 100 points are: * 2 ≀ n ≀ 2000 Output Output a single number β€” the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Examples Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Output 3 Note Let's have a look at the example. <image> Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected). Tags: dfs and similar, dsu, graphs Correct Solution: ``` n = int(input()) l = int(input()) likes_list = [[] for i in range(n + 1)] for i in range(l): a, b = map(int, input().split()) likes_list[a].append(b) likes_list[b].append(a) d = int(input()) dislikes_list = [[] for i in range(n + 1)] for i in range(d): a, b = map(int, input().split()) dislikes_list[a].append(b) dislikes_list[b].append(a) v = [False] * (n + 1) groups = {} f_id = [i for i in range(n + 1)] for i in range(1, n + 1): if not v[i]: f = set() s = [i] while len(s) > 0: x = s.pop() f_id[x] = i f.add(x) if v[x]: continue v[x] = True for y in likes_list[x]: s.append(y) groups[i] = f for i in range(1, n + 1): for ds in dislikes_list[i]: groups[f_id[i]].difference_update({ds}.union(groups[f_id[ds]])) ans = 0 for v in groups.values(): ans = max(ans, len(v)) print(ans) ```
6,882
Provide tags and a correct Python 3 solution for this coding contest problem. To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: * all his friends should also be invited to the party; * the party shouldn't have any people he dislikes; * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≀ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite. Input The first line of input contains an integer n β€” the number of the Beaver's acquaintances. The second line contains an integer k <image> β€” the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> β€” indices of people who form the i-th pair of friends. The next line contains an integer m <image> β€” the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: * 2 ≀ n ≀ 14 The input limitations for getting 100 points are: * 2 ≀ n ≀ 2000 Output Output a single number β€” the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Examples Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Output 3 Note Let's have a look at the example. <image> Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected). Tags: dfs and similar, dsu, graphs Correct Solution: ``` # Problem: C1. Party # Contest: Codeforces - ABBYY Cup 2.0 - Easy # URL: https://codeforces.com/contest/177/problem/C1 # Memory Limit: 256 MB # Time Limit: 2000 ms # # KAPOOR'S from sys import stdin, stdout def INI(): return int(stdin.readline()) def INL(): return [int(_) for _ in stdin.readline().split()] def INS(): return stdin.readline() def MOD(): return pow(10,9)+7 def OPS(ans): stdout.write(str(ans)+"\n") def OPL(ans): [stdout.write(str(_)+" ") for _ in ans] stdout.write("\n") rank=[0 for _ in range(2000+1)] par=[_ for _ in range(2000+1)] Size=[1 for _ in range(2000+1)] def findpar(x): if x==par[x]: return x return findpar(par[x]) def union(pu,pv): if rank[pu]<rank[pv]: par[pu]=pv Size[pv]+=Size[pu] elif rank[pv]<rank[pu]: par[pv]=pu Size[pu]+=Size[pv] else: par[pv]=pu rank[pu]+=1 Size[pu]+=Size[pv] if __name__=="__main__": # for _ in range(INI()): t=INI() n=INI() for _ in range(n): u,v=INL() pu=findpar(u) pv=findpar(v) if pu!=pv: union(pu,pv) q=int(input()) for _ in range(q): u,v=INL() pu=findpar(u) pv=findpar(v) if pu==pv: Size[pu]=0 ans=0 for _ in range(1,t+1): ans=max(ans,Size[findpar(_)]) print(ans) ```
6,883
Provide tags and a correct Python 3 solution for this coding contest problem. To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: * all his friends should also be invited to the party; * the party shouldn't have any people he dislikes; * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≀ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite. Input The first line of input contains an integer n β€” the number of the Beaver's acquaintances. The second line contains an integer k <image> β€” the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> β€” indices of people who form the i-th pair of friends. The next line contains an integer m <image> β€” the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: * 2 ≀ n ≀ 14 The input limitations for getting 100 points are: * 2 ≀ n ≀ 2000 Output Output a single number β€” the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Examples Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Output 3 Note Let's have a look at the example. <image> Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected). Tags: dfs and similar, dsu, graphs Correct Solution: ``` def find(a): if parent[a]!=a: parent[a]=find(parent[a]) return parent[a] def union(a,b): u,v=find(a),find(b) if u==v: return if rank[u]>rank[v]: parent[v]=u else: parent[u]=v if rank[u]==rank[v]: rank[v]+=1 n=int(input()) k=int(input()) parent=list(map(int,range(n+1))) rank=[0]*(n+1) ans=[0]*(n+1) count=[0]*(n+1) for i in range(k): u,v=map(int,input().split()) union(u,v) for i in range(len(ans)): ans[find(i)]+=1 for i in range(len(parent)): count[parent[i]]+=1 d={} m=int(input()) for i in range(m): u,v=map(int,input().split()) if parent[u]==parent[v]: d[parent[u]]=False sak=0 for i in range(len(count)): if count[i]!=0 and i not in d and i!=0: sak=max(sak,count[i]) print(sak) ```
6,884
Provide tags and a correct Python 3 solution for this coding contest problem. To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: * all his friends should also be invited to the party; * the party shouldn't have any people he dislikes; * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≀ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite. Input The first line of input contains an integer n β€” the number of the Beaver's acquaintances. The second line contains an integer k <image> β€” the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> β€” indices of people who form the i-th pair of friends. The next line contains an integer m <image> β€” the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: * 2 ≀ n ≀ 14 The input limitations for getting 100 points are: * 2 ≀ n ≀ 2000 Output Output a single number β€” the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Examples Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Output 3 Note Let's have a look at the example. <image> Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected). Tags: dfs and similar, dsu, graphs Correct Solution: ``` n = int(input()) num_likes = int(input()) like = [ [] for u in range(n + 1) ] for i in range(num_likes): u, v = map(int, input().split()) like[u].append(v) like[v].append(u) num_dislikes = int(input()) dislike = [ (n + 1) * [ False ] for u in range(n + 1) ] for i in range(num_dislikes): u, v = map(int, input().split()) dislike[u][v] = True dislike[v][u] = True result = 0 seen = (n + 1) * [ False ] for u in range(1, n + 1): if seen[u]: continue seen[u] = True group = [ u ] queue = [ u ] tail = 0 while tail < len(queue): u = queue[tail] tail += 1 for v in like[u]: if seen[v]: continue seen[v] = True group.append(v) queue.append(v) okay = True for i, u in enumerate(group): for j in range(i + 1, len(group)): v = group[j] if dislike[u][v]: okay = False break if not okay: break if okay: result = max(result, len(group)) print(result) ```
6,885
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: * all his friends should also be invited to the party; * the party shouldn't have any people he dislikes; * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≀ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite. Input The first line of input contains an integer n β€” the number of the Beaver's acquaintances. The second line contains an integer k <image> β€” the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> β€” indices of people who form the i-th pair of friends. The next line contains an integer m <image> β€” the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: * 2 ≀ n ≀ 14 The input limitations for getting 100 points are: * 2 ≀ n ≀ 2000 Output Output a single number β€” the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Examples Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Output 3 Note Let's have a look at the example. <image> Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected). Submitted Solution: ``` def dfs (chain): if chain: for c in chain: if c not in groups: groups.add(c) dfs(graph[c-1]) graph[c-1].clear() graph= [[] for _ in range(int(input()))]; sev = len(graph) groups,inv,ind = set(),{},1 for _ in range(int(input())): u,v = map(int,input().split()) graph[u-1].append(v) for i,g in enumerate(graph): if g: groups.add(i+1) dfs(g); inv[ind] = [p for p in groups] ind+=1; groups.clear() graph = [set() for _ in range(sev)] for f in inv: for k in inv[f]: graph[k-1].add(f) for g in range(sev): if not graph[g]: inv[g+1] = [g+1] for _ in range(int(input())): cat = [x for x in map(int,input().split())] gat = graph[cat[0]-1].intersection(graph[cat[1]-1]) if gat: for s in cat: for l in graph[s-1]: try: inv.pop(l) except KeyError: continue if inv: print(len(max(inv.items(),key = lambda x: len(x[1]))[1])) else: print(0) ``` Yes
6,886
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: * all his friends should also be invited to the party; * the party shouldn't have any people he dislikes; * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≀ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite. Input The first line of input contains an integer n β€” the number of the Beaver's acquaintances. The second line contains an integer k <image> β€” the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> β€” indices of people who form the i-th pair of friends. The next line contains an integer m <image> β€” the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: * 2 ≀ n ≀ 14 The input limitations for getting 100 points are: * 2 ≀ n ≀ 2000 Output Output a single number β€” the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Examples Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Output 3 Note Let's have a look at the example. <image> Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected). Submitted Solution: ``` t, p, k = [0] * (int(input()) + 1), {0: []}, 1 for i in range(int(input())): a, b = map(int, input().split()) if t[a] == t[b]: if t[a] == 0: t[a] = t[b] = k p[k] = [a, b] k += 1 else: if t[a] == 0: t[a] = t[b] p[t[b]].append(a) elif t[b] == 0: t[b] = t[a] p[t[a]].append(b) else: x, y = t[b], t[a] for c in p[x]: t[c] = y p[y] += p[x] p[x] = [] for i in range(int(input())): a, b = map(int, input().split()) if t[a] == t[b]: p[t[a]] = [] ans = max(map(len, p.values())) if ans == 0: ans = int(0 in t[1:]) print(ans) ``` Yes
6,887
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: * all his friends should also be invited to the party; * the party shouldn't have any people he dislikes; * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≀ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite. Input The first line of input contains an integer n β€” the number of the Beaver's acquaintances. The second line contains an integer k <image> β€” the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> β€” indices of people who form the i-th pair of friends. The next line contains an integer m <image> β€” the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: * 2 ≀ n ≀ 14 The input limitations for getting 100 points are: * 2 ≀ n ≀ 2000 Output Output a single number β€” the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Examples Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Output 3 Note Let's have a look at the example. <image> Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected). Submitted Solution: ``` class DisjointSetStructure(): def __init__(self, n): self.A = [[i,0,1] for i in range(n)] self.size = n def getpair(self, i): p = i while self.A[p][0] != p: p = self.A[p][0] j = self.A[i][0] while j != p: self.A[i][0] = p i, j = j, self.A[j][0] return (p, self.A[p][2]) def __getitem__(self, i): return self.getpair(i)[0] def union(self, i, j): u, v = self[i], self[j] if u == v: return self.size -= 1 if self.A[u][1] > self.A[v][1]: self.A[v][0] = u self.A[u][2] += self.A[v][2] else: self.A[u][0] = v self.A[v][2] += self.A[u][2] if self.A[u][1] == self.A[v][1]: self.A[v][1] += 1 def __len__(self): return self.size n = int(input()) k = int(input()) D = DisjointSetStructure(n) for i in range(k): u, v = [int(x) - 1 for x in input().split()] D.union(u, v) l = int(input()) friendly = [True for i in range(n)] for i in range(l): u, v = [int(x) - 1 for x in input().split()] if D[u] == D[v]: friendly[D[u]] = False print(max(D.getpair(i)[1] if friendly[D[i]] else 0 for i in range(n))) ``` Yes
6,888
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: * all his friends should also be invited to the party; * the party shouldn't have any people he dislikes; * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≀ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite. Input The first line of input contains an integer n β€” the number of the Beaver's acquaintances. The second line contains an integer k <image> β€” the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> β€” indices of people who form the i-th pair of friends. The next line contains an integer m <image> β€” the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: * 2 ≀ n ≀ 14 The input limitations for getting 100 points are: * 2 ≀ n ≀ 2000 Output Output a single number β€” the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Examples Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Output 3 Note Let's have a look at the example. <image> Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected). Submitted Solution: ``` from collections import defaultdict def Root(child): while(Parent[child]!=child): child = Parent[child] return child def Union(a,b): root_a = Root(a) root_b = Root(b) if(root_a!=root_b): if(Size[root_a]<Size[root_b]): Parent[root_a] = root_b Size[root_b]+=Size[root_a] else: Parent[root_b] = root_a Size[root_a]+=Size[root_b] return 1 return 0 n = int(input()) Parent = [i for i in range(n)] Size = [1 for i in range(n)] k = int(input()) for i in range(k): u,v = map(int,input().split()) u-=1;v-=1 Union(u,v) m = int(input()) for i in range(m): u,v = map(int,input().split()) root_u = Root(u-1) root_v = Root(v-1) if(root_u==root_v): Size[root_u] = 0 Max = -float('inf') for i in range(n): Max = max(Max,Size[Root(i)]) print(Max) ``` Yes
6,889
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: * all his friends should also be invited to the party; * the party shouldn't have any people he dislikes; * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≀ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite. Input The first line of input contains an integer n β€” the number of the Beaver's acquaintances. The second line contains an integer k <image> β€” the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> β€” indices of people who form the i-th pair of friends. The next line contains an integer m <image> β€” the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: * 2 ≀ n ≀ 14 The input limitations for getting 100 points are: * 2 ≀ n ≀ 2000 Output Output a single number β€” the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Examples Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Output 3 Note Let's have a look at the example. <image> Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected). Submitted Solution: ``` def root(Arr,i): while(Arr[i]!=i): Arr[i]=Arr[Arr[i]] i=Arr[i] return i def Union(Arr,A,B): root_A= root(Arr,A) root_B=root(Arr,B) if size[root_B]<size[root_A]: Arr[root_B]=root_A size[root_A]+=size[root_B] else: Arr[root_A]=root_B size[root_B]+=size[root_A] def Find(A,B): if root(Arr,A)==root(Arr,B): return True return False n=int(input()) Arr=list(range(n)) size=[1]*(n) f=int(input()) for i in range(f): A,B=map(int,input().split()) if not Find(A-1,B-1): Union(Arr,A-1,B-1) e=int(input()) enemy=[[0,0]]*e lst=sorted(size)[::-1] for i in range(e): A,B=map(int,input().split()) enemy[i][0]=A-1 enemy[i][1]=B-1 ans=0 test=0 while(True and ans<n): for i in range(e): a=enemy[i][0] b=enemy[i][1] Root=root(Arr,size.index(lst[ans])) if root(Arr,a)==Root and root(Arr,b)==Root: break if i==e-1: test=1 break if test==1: break ans+=1 #print(size) if ans>e: ans=0 print(lst[ans]) ``` No
6,890
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: * all his friends should also be invited to the party; * the party shouldn't have any people he dislikes; * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≀ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite. Input The first line of input contains an integer n β€” the number of the Beaver's acquaintances. The second line contains an integer k <image> β€” the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> β€” indices of people who form the i-th pair of friends. The next line contains an integer m <image> β€” the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: * 2 ≀ n ≀ 14 The input limitations for getting 100 points are: * 2 ≀ n ≀ 2000 Output Output a single number β€” the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Examples Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Output 3 Note Let's have a look at the example. <image> Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected). Submitted Solution: ``` def root(Arr,i): while(Arr[i]!=i): Arr[i]=Arr[Arr[i]] i=Arr[i] return i def Union(Arr,A,B): root_A= root(Arr,A) root_B=root(Arr,B) if size[root_B]<size[root_A]: Arr[root_B]=root_A size[root_A]+=size[root_B] else: Arr[root_A]=root_B size[root_B]+=size[root_A] def Find(A,B): if root(Arr,A)==root(Arr,B): return True return False n=int(input()) Arr=list(range(n)) size=[1]*(n) f=int(input()) for i in range(f): A,B=map(int,input().split()) if not Find(A-1,B-1): Union(Arr,A-1,B-1) e=int(input()) enemy=[[0,0]]*e lst=sorted(size)[::-1] for i in range(e): A,B=map(int,input().split()) enemy[i][0]=A-1 enemy[i][1]=B-1 ans=0 test=0 if e==0: print(lst[0]) else: while(True and ans<n): for i in range(e): a=enemy[i][0] b=enemy[i][1] Root=root(Arr,size.index(lst[ans])) if root(Arr,a)==Root and root(Arr,b)==Root: break if i==e-1: test=1 break if test==1: break ans+=1 #print(size) if ans>e: print('0') else: print(lst[ans]) ``` No
6,891
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: * all his friends should also be invited to the party; * the party shouldn't have any people he dislikes; * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≀ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite. Input The first line of input contains an integer n β€” the number of the Beaver's acquaintances. The second line contains an integer k <image> β€” the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> β€” indices of people who form the i-th pair of friends. The next line contains an integer m <image> β€” the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: * 2 ≀ n ≀ 14 The input limitations for getting 100 points are: * 2 ≀ n ≀ 2000 Output Output a single number β€” the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Examples Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Output 3 Note Let's have a look at the example. <image> Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected). Submitted Solution: ``` def root(Arr,i): while(Arr[i]!=i): Arr[i]=Arr[Arr[i]] i=Arr[i] return i def Union(Arr,A,B): root_A= root(Arr,A) root_B=root(Arr,B) if size[root_B]<size[root_A]: Arr[root_B]=Arr[root_A] size[root_A]+=size[root_B] else: Arr[root_A]=Arr[root_B] size[root_B]+=size[root_A] def Find(A,B): if root(Arr,A)==root(Arr,B): return True return False n=int(input()) Arr=list(range(n)) size=[1]*(n) lst=[] f=int(input()) for i in range(f): A,B=map(int,input().split()) if not Find(A-1,B-1): Union(Arr,A-1,B-1) e=int(input()) enemy=[] #print(enemy) for x in range(e): a,b=map(int,input().split()) enemy.append([a-1,b-1]) #print(enemy) for i in range(n): if Arr[i]==i: lst.append([size[i],i]) lst=sorted(lst)[::-1] ans=0 test=0 if e==0: print(lst[0][0]) else: for i in range(len(lst)): Root=lst[i][1] test=0 for k in range(e): if root(Arr,enemy[k][0])==Root and root(Arr,enemy[k][1])==Root: test=1 break if test==0: ans=lst[i][0] break #print(enemy) #print(lst) print(ans) ``` No
6,892
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: * all his friends should also be invited to the party; * the party shouldn't have any people he dislikes; * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≀ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite. Input The first line of input contains an integer n β€” the number of the Beaver's acquaintances. The second line contains an integer k <image> β€” the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> β€” indices of people who form the i-th pair of friends. The next line contains an integer m <image> β€” the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: * 2 ≀ n ≀ 14 The input limitations for getting 100 points are: * 2 ≀ n ≀ 2000 Output Output a single number β€” the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Examples Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Output 3 Note Let's have a look at the example. <image> Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected). Submitted Solution: ``` # Problem: C1. Party # Contest: Codeforces - ABBYY Cup 2.0 - Easy # URL: https://codeforces.com/contest/177/problem/C1 # Memory Limit: 256 MB # Time Limit: 2000 ms # # KAPOOR'S from sys import stdin, stdout def INI(): return int(stdin.readline()) def INL(): return [int(_) for _ in stdin.readline().split()] def INS(): return stdin.readline() def MOD(): return pow(10,9)+7 def OPS(ans): stdout.write(str(ans)+"\n") def OPL(ans): [stdout.write(str(_)+" ") for _ in ans] stdout.write("\n") rank=[0 for _ in range(2000+1)] par=[_ for _ in range(2000+1)] Size=[1 for _ in range(2000+1)] def findpar(x): if x==par[x]: return x return findpar(par[x]) def union(pu,pv): if rank[pu]<rank[pv]: par[pu]=pv Size[pv]+=Size[pu] elif rank[pv]<rank[pu]: par[pv]=pu Size[pu]+=Size[pv] else: par[pv]=pu rank[pu]+=1 Size[pu]+=Size[pv] if __name__=="__main__": # for _ in range(INI()): INI() n=INI() for _ in range(n): u,v=INL() pu=findpar(u) pv=findpar(v) if pu!=pv: union(pu,pv) q=int(input()) for _ in range(q): u,v=INL() pu=findpar(u) pv=findpar(v) if pu==pv: par[pu]=0 ans=0 for _ in range(1,n+1): ans=max(ans,Size[findpar(_)]) print(ans) ``` No
6,893
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous. Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions: * climb one area up; * climb one area down; * jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall. If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon. The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" β€” first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on. The level is considered completed if the ninja manages to get out of the canyon. After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question. Input The first line contains two integers n and k (1 ≀ n, k ≀ 105) β€” the height of the canyon and the height of ninja's jump, correspondingly. The second line contains the description of the left wall β€” a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area. The third line describes the right wall in the same format. It is guaranteed that the first area of the left wall is not dangerous. Output Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). Examples Input 7 3 ---X--X -X--XX- Output YES Input 6 2 --X-X- X--XX- Output NO Note In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon. In the second sample there's no way the ninja can get out of the canyon. Tags: shortest paths Correct Solution: ``` f = lambda: [q != '-' for q in input()] n, k = map(int, input().split()) t = [(0, 0, f(), f())] def g(d, s, a, b): if d > n - 1: print('YES') exit() if not (a[d] or s > d): a[d] = 1 t.append((d, s, a, b)) while t: d, s, a, b = t.pop() g(d + 1, s + 1, a, b) g(d - 1, s + 1, a, b) g(d + k, s + 1, b, a) print('NO') ```
6,894
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous. Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions: * climb one area up; * climb one area down; * jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall. If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon. The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" β€” first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on. The level is considered completed if the ninja manages to get out of the canyon. After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question. Input The first line contains two integers n and k (1 ≀ n, k ≀ 105) β€” the height of the canyon and the height of ninja's jump, correspondingly. The second line contains the description of the left wall β€” a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area. The third line describes the right wall in the same format. It is guaranteed that the first area of the left wall is not dangerous. Output Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). Examples Input 7 3 ---X--X -X--XX- Output YES Input 6 2 --X-X- X--XX- Output NO Note In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon. In the second sample there's no way the ninja can get out of the canyon. Tags: shortest paths Correct Solution: ``` # 198B __author__ = 'artyom' n, k = map(int, input().split()) w = [input(), input()] def neighbours(vertex, time): vertices = set() if vertex[1] + 1 >= n or w[vertex[0]][vertex[1] + 1] != 'X': vertices.add((vertex[0], vertex[1] + 1)) if vertex[1] + k >= n or w[1 - vertex[0]][vertex[1] + k] != 'X': vertices.add((1 - vertex[0], vertex[1] + k)) if vertex[1] - 1 > time and w[vertex[0]][vertex[1] - 1] != 'X': vertices.add((vertex[0], vertex[1] - 1)) return vertices def bfs(*start): stack, visited = [(start, 0)], set() while stack: vertex, time = stack.pop(0) if vertex[1] >= n: return 1 if vertex not in visited: visited.add(vertex) for neighbour in neighbours(vertex, time): if neighbour not in visited: stack.append((neighbour, time + 1)) return 0 print('YES' if bfs(0, 0) else 'NO') ```
6,895
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous. Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions: * climb one area up; * climb one area down; * jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall. If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon. The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" β€” first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on. The level is considered completed if the ninja manages to get out of the canyon. After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question. Input The first line contains two integers n and k (1 ≀ n, k ≀ 105) β€” the height of the canyon and the height of ninja's jump, correspondingly. The second line contains the description of the left wall β€” a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area. The third line describes the right wall in the same format. It is guaranteed that the first area of the left wall is not dangerous. Output Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). Examples Input 7 3 ---X--X -X--XX- Output YES Input 6 2 --X-X- X--XX- Output NO Note In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon. In the second sample there's no way the ninja can get out of the canyon. Tags: shortest paths Correct Solution: ``` def bfs(n): visited=[False]*(2*n) queue=[] queue2=[] queue.append(0) queue2.append(0) visited[0]=True flag=True water=0 while queue and flag: s=queue.pop(0) water= queue2.pop(0) for i in graph[s]: if not visited[i]: a=0 #print(water,i) if i>=n: a=i-n else: a=i if a>water: if i==n-1 or i==2*n-1: flag=False else: queue.append(i) queue2.append(water+1) visited[i]=True return not flag n,k=map(int,input().split()) l=input() r=input() graph=[] for i in range(n): graph.append([]) if l[i]=='-': if i+1<n: if l[i+1]=='-': graph[i].append(i+1) if i-1>=0: if l[i-1]=='-': graph[i].append(i-1) if i+k<n: if r[i+k]=='-': graph[i].append(n+i+k) else: graph[i].append(2*n-1) for i in range(n): graph.append([]) if r[i]=='-': if i+1<n: if r[i+1]=='-': graph[n+i].append(n+i+1) if i-1>=0: if r[i-1]=='-': graph[n+i].append(n+i-1) if i+k<n: if l[i+k]=='-': graph[n+i].append(i+k) else: graph[n+i].append(n-1) #print(graph) if n==1: print("YES") elif bfs(n): print("YES") else: print("NO") ```
6,896
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous. Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions: * climb one area up; * climb one area down; * jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall. If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon. The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" β€” first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on. The level is considered completed if the ninja manages to get out of the canyon. After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question. Input The first line contains two integers n and k (1 ≀ n, k ≀ 105) β€” the height of the canyon and the height of ninja's jump, correspondingly. The second line contains the description of the left wall β€” a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area. The third line describes the right wall in the same format. It is guaranteed that the first area of the left wall is not dangerous. Output Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). Examples Input 7 3 ---X--X -X--XX- Output YES Input 6 2 --X-X- X--XX- Output NO Note In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon. In the second sample there's no way the ninja can get out of the canyon. Tags: shortest paths Correct Solution: ``` n, k = map(int, input().split(' ')) l = input() r = input() data = [0, ' '+l, ' '+r] dist = [[1000000]*(10**5+5) for _ in range(3)] visited = [[False]*100005 for _ in range(3)] visited[1][1] = True dist[1][1] = 0 qx = [1] qy = [1] while qx: x = qx.pop() y = qy.pop() if dist[x][y] >= y: continue if x == 1: poss = [[x, y-1], [x, y+1], [x+1, y+k]] if x == 2: poss = [[x, y-1], [x, y+1], [x-1, y+k]] for i in poss: newx = i[0] newy = i[1] if newy > n: print("YES"); quit(); if 1<=newy<=n and not visited[newx][newy] and data[newx][newy] != 'X': visited[newx][newy] = True qx = [newx] + qx qy = [newy] + qy dist[newx][newy] = dist[x][y] + 1 print("NO") ```
6,897
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous. Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions: * climb one area up; * climb one area down; * jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall. If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon. The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" β€” first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on. The level is considered completed if the ninja manages to get out of the canyon. After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question. Input The first line contains two integers n and k (1 ≀ n, k ≀ 105) β€” the height of the canyon and the height of ninja's jump, correspondingly. The second line contains the description of the left wall β€” a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area. The third line describes the right wall in the same format. It is guaranteed that the first area of the left wall is not dangerous. Output Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). Examples Input 7 3 ---X--X -X--XX- Output YES Input 6 2 --X-X- X--XX- Output NO Note In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon. In the second sample there's no way the ninja can get out of the canyon. Tags: shortest paths Correct Solution: ``` n, k = map(int, input().split()) lzid = input() dzid = input() zidovi = [lzid, dzid] q = [[-1, [False,0]]] #[koraci, [zid, visina]] izasao = 0 bio = [[0 for i in range(n+k+100)], [0 for i in range(n+k+100)]] while len(q) != 0: trenutni = q.pop(0) korak = trenutni[0] pozicija = trenutni[1] tren_zid = pozicija[0] tren_visina = pozicija[1] if bio[tren_zid][tren_visina] == 0: bio[tren_zid][tren_visina] = 1 if tren_visina > n-1: print("YES") izasao = 1 break elif tren_visina == n-1 and zidovi[tren_zid][tren_visina] != 'X' and tren_visina > korak: print("YES") izasao = 1 break elif zidovi[tren_zid][tren_visina] != 'X' and tren_visina > korak: q.append([korak+1, [tren_zid, tren_visina-1]]) q.append([korak+1, [tren_zid, tren_visina+1]]) q.append([korak+1, [not(tren_zid), tren_visina+k]]) ## if tren_visina - 1 > korak+1: ## if zidovi[tren_zid][tren_visina-1] != 'X': ## q.append([korak+1, [tren_zid, tren_visina-1]]) ## if tren_visina + 1 > korak: ## if tren_visina + k <= n-1: ## if zidovi[tren_zid][tren_visina+1] != 'X': ## q.append([korak+1, [tren_zid, tren_visina+1]]) ## else: ## print("YES") ## izasao = 1 ## break ## if tren_visina + k > korak: ## if tren_visina + k <= n-1: ## if zidovi[not(tren_zid)][tren_visina+k] != 'X': ## q.append([korak+1, [not(tren_zid), tren_visina+k]]) ## else: ## print("YES") ## izasao = 1 if izasao == 0: print("NO") ```
6,898
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous. Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions: * climb one area up; * climb one area down; * jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall. If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon. The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" β€” first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on. The level is considered completed if the ninja manages to get out of the canyon. After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question. Input The first line contains two integers n and k (1 ≀ n, k ≀ 105) β€” the height of the canyon and the height of ninja's jump, correspondingly. The second line contains the description of the left wall β€” a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area. The third line describes the right wall in the same format. It is guaranteed that the first area of the left wall is not dangerous. Output Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). Examples Input 7 3 ---X--X -X--XX- Output YES Input 6 2 --X-X- X--XX- Output NO Note In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon. In the second sample there's no way the ninja can get out of the canyon. Tags: shortest paths Correct Solution: ``` f = lambda: [q == '-' for q in input()] n, k = map(int, input().split()) l, r = f(), f() u, v = [0], [] def yes(d): if d > n - 1: print('YES') exit() for i in range(n): a, b = [], [] for d in u: if l[d - 1] and d - 1 > i: a.append(d - 1) l[d - 1] = 0 yes(d + 1) if l[d + 1]: a.append(d + 1) l[d + 1] = 0 yes(d + k) if r[d + k]: b.append(d + k) r[d + k] = 0 for d in v: if r[d - 1] and d - 1 > i: b.append(d - 1) r[d - 1] = 0 yes(d + 1) if r[d + 1]: b.append(d + 1) r[d + 1] = 0 yes(d + k) if l[d + k]: a.append(d + k) l[d + k] = 0 u, v = a, b print('NO') ```
6,899