message
stringlengths
2
20.1k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
1.95k
109k
cluster
float64
17
17
__index_level_0__
int64
3.91k
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Japan achieved the second straight victory in the national baseball competition WBC !! A baseball tournament was held at Aizu Gakuen High School as baseball became more popular. In this tournament, a round-robin league match will be held and the ranking will be decided in the following ways. 1. The team with the most wins is ranked high 2. If the number of wins is the same, the team with the fewest losses will be ranked higher. Create a program that inputs the results of each team and outputs the team names in order from the top team. If there are teams with the same rank, output them in the order of input. However, the number of teams n is an integer from 2 to 10 and the team name t is a single-byte alphabetic character. , 2 for a draw. Also, the team name shall be unique. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n score1 score2 :: scoren The number of teams n (2 ≀ n ≀ 10) is given on the first line, and the scorei of the i-th team is given on the following n lines. Each grade is given in the following format. t r1 r2 ... rnβˆ’1 The team name t (one-character half-width alphabetic character) and the result ri (0, 1, or 2) for each match of t are given separated by blanks. The number of datasets does not exceed 50. Output For each dataset, the team name is output in order from the top team. Example Input 6 A 1 0 0 2 0 B 0 0 1 1 0 C 1 1 1 1 1 D 1 0 0 1 2 E 2 0 0 0 0 F 1 1 0 2 1 4 g 1 1 1 h 0 1 2 w 0 0 0 b 0 2 1 0 Output E A B D F C w h b g Submitted Solution: ``` def solve(): N = int(input()) if N == 0: return -1 score = [] for i in range(N): s = input().split() win, draw = 0, 0 for j in range(1, len(s)): if s[j] == '1': continue elif s[j] == '0': win += 1 else : draw += 1 score.append((s[0], win, draw)) res = sorted(score, reverse=True, key=lambda x:(x[1], x[2])) for s in res: print(s[0]) while True: if solve() != None: break ```
instruction
0
81,627
17
163,254
Yes
output
1
81,627
17
163,255
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Japan achieved the second straight victory in the national baseball competition WBC !! A baseball tournament was held at Aizu Gakuen High School as baseball became more popular. In this tournament, a round-robin league match will be held and the ranking will be decided in the following ways. 1. The team with the most wins is ranked high 2. If the number of wins is the same, the team with the fewest losses will be ranked higher. Create a program that inputs the results of each team and outputs the team names in order from the top team. If there are teams with the same rank, output them in the order of input. However, the number of teams n is an integer from 2 to 10 and the team name t is a single-byte alphabetic character. , 2 for a draw. Also, the team name shall be unique. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n score1 score2 :: scoren The number of teams n (2 ≀ n ≀ 10) is given on the first line, and the scorei of the i-th team is given on the following n lines. Each grade is given in the following format. t r1 r2 ... rnβˆ’1 The team name t (one-character half-width alphabetic character) and the result ri (0, 1, or 2) for each match of t are given separated by blanks. The number of datasets does not exceed 50. Output For each dataset, the team name is output in order from the top team. Example Input 6 A 1 0 0 2 0 B 0 0 1 1 0 C 1 1 1 1 1 D 1 0 0 1 2 E 2 0 0 0 0 F 1 1 0 2 1 4 g 1 1 1 h 0 1 2 w 0 0 0 b 0 2 1 0 Output E A B D F C w h b g Submitted Solution: ``` while True: num = int(input()) if num==0: break L = [] for i in range(num): n, *k = input().split() L.append( (n, k.count("0"), k.count("1"), i) ) L.sort(key=lambda x:(-x[1],x[2],x[3]) ) for x in L: print(x[0]) ```
instruction
0
81,628
17
163,256
Yes
output
1
81,628
17
163,257
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Japan achieved the second straight victory in the national baseball competition WBC !! A baseball tournament was held at Aizu Gakuen High School as baseball became more popular. In this tournament, a round-robin league match will be held and the ranking will be decided in the following ways. 1. The team with the most wins is ranked high 2. If the number of wins is the same, the team with the fewest losses will be ranked higher. Create a program that inputs the results of each team and outputs the team names in order from the top team. If there are teams with the same rank, output them in the order of input. However, the number of teams n is an integer from 2 to 10 and the team name t is a single-byte alphabetic character. , 2 for a draw. Also, the team name shall be unique. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n score1 score2 :: scoren The number of teams n (2 ≀ n ≀ 10) is given on the first line, and the scorei of the i-th team is given on the following n lines. Each grade is given in the following format. t r1 r2 ... rnβˆ’1 The team name t (one-character half-width alphabetic character) and the result ri (0, 1, or 2) for each match of t are given separated by blanks. The number of datasets does not exceed 50. Output For each dataset, the team name is output in order from the top team. Example Input 6 A 1 0 0 2 0 B 0 0 1 1 0 C 1 1 1 1 1 D 1 0 0 1 2 E 2 0 0 0 0 F 1 1 0 2 1 4 g 1 1 1 h 0 1 2 w 0 0 0 b 0 2 1 0 Output E A B D F C w h b g Submitted Solution: ``` import sys import operator f = sys.stdin while True: n = int(f.readline()) if n == 0: break teams = [f.readline().split() for i in range(n)] teams = [(t[0], -t.count('0'), t.count('1'), i) for i, t in enumerate(teams)] teams.sort(key=operator.itemgetter(1,2,3)) print('\n'.join([t[0] for t in teams])) ```
instruction
0
81,629
17
163,258
Yes
output
1
81,629
17
163,259
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Japan achieved the second straight victory in the national baseball competition WBC !! A baseball tournament was held at Aizu Gakuen High School as baseball became more popular. In this tournament, a round-robin league match will be held and the ranking will be decided in the following ways. 1. The team with the most wins is ranked high 2. If the number of wins is the same, the team with the fewest losses will be ranked higher. Create a program that inputs the results of each team and outputs the team names in order from the top team. If there are teams with the same rank, output them in the order of input. However, the number of teams n is an integer from 2 to 10 and the team name t is a single-byte alphabetic character. , 2 for a draw. Also, the team name shall be unique. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n score1 score2 :: scoren The number of teams n (2 ≀ n ≀ 10) is given on the first line, and the scorei of the i-th team is given on the following n lines. Each grade is given in the following format. t r1 r2 ... rnβˆ’1 The team name t (one-character half-width alphabetic character) and the result ri (0, 1, or 2) for each match of t are given separated by blanks. The number of datasets does not exceed 50. Output For each dataset, the team name is output in order from the top team. Example Input 6 A 1 0 0 2 0 B 0 0 1 1 0 C 1 1 1 1 1 D 1 0 0 1 2 E 2 0 0 0 0 F 1 1 0 2 1 4 g 1 1 1 h 0 1 2 w 0 0 0 b 0 2 1 0 Output E A B D F C w h b g Submitted Solution: ``` import sys f = sys.stdin while True: n = int(f.readline()) if n == 0: break teams = [f.readline().split() for i in range(n)] teams = [(t[0], -t.count('0'), t.count('1'), i) for i, t in enumerate(teams)] teams.sort(key=operator.itemgetter(1,2,3)) print('\n'.join([t[0] for t in teams])) ```
instruction
0
81,630
17
163,260
No
output
1
81,630
17
163,261
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Japan achieved the second straight victory in the national baseball competition WBC !! A baseball tournament was held at Aizu Gakuen High School as baseball became more popular. In this tournament, a round-robin league match will be held and the ranking will be decided in the following ways. 1. The team with the most wins is ranked high 2. If the number of wins is the same, the team with the fewest losses will be ranked higher. Create a program that inputs the results of each team and outputs the team names in order from the top team. If there are teams with the same rank, output them in the order of input. However, the number of teams n is an integer from 2 to 10 and the team name t is a single-byte alphabetic character. , 2 for a draw. Also, the team name shall be unique. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n score1 score2 :: scoren The number of teams n (2 ≀ n ≀ 10) is given on the first line, and the scorei of the i-th team is given on the following n lines. Each grade is given in the following format. t r1 r2 ... rnβˆ’1 The team name t (one-character half-width alphabetic character) and the result ri (0, 1, or 2) for each match of t are given separated by blanks. The number of datasets does not exceed 50. Output For each dataset, the team name is output in order from the top team. Example Input 6 A 1 0 0 2 0 B 0 0 1 1 0 C 1 1 1 1 1 D 1 0 0 1 2 E 2 0 0 0 0 F 1 1 0 2 1 4 g 1 1 1 h 0 1 2 w 0 0 0 b 0 2 1 0 Output E A B D F C w h b g Submitted Solution: ``` while True: n = int(input()) if n == 0: break tmp = [list(input().split()) for _ in range(n)] score = {'0': 2, '1': 0, '2': 1} ans = [] for t in tmp: tmpv = 0 for v in t[1:]: tmpv += score[v] ans.append(t[0] + str(tmpv)) for i in range(len(ans)): for j in range(i+1, len(ans))[::-1]: if ans[j][1] > ans[j-1][1]: ans[j], ans[j-1] = ans[j-1], ans[j] for a in ans: print(a[0]) ```
instruction
0
81,631
17
163,262
No
output
1
81,631
17
163,263
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Japan achieved the second straight victory in the national baseball competition WBC !! A baseball tournament was held at Aizu Gakuen High School as baseball became more popular. In this tournament, a round-robin league match will be held and the ranking will be decided in the following ways. 1. The team with the most wins is ranked high 2. If the number of wins is the same, the team with the fewest losses will be ranked higher. Create a program that inputs the results of each team and outputs the team names in order from the top team. If there are teams with the same rank, output them in the order of input. However, the number of teams n is an integer from 2 to 10 and the team name t is a single-byte alphabetic character. , 2 for a draw. Also, the team name shall be unique. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n score1 score2 :: scoren The number of teams n (2 ≀ n ≀ 10) is given on the first line, and the scorei of the i-th team is given on the following n lines. Each grade is given in the following format. t r1 r2 ... rnβˆ’1 The team name t (one-character half-width alphabetic character) and the result ri (0, 1, or 2) for each match of t are given separated by blanks. The number of datasets does not exceed 50. Output For each dataset, the team name is output in order from the top team. Example Input 6 A 1 0 0 2 0 B 0 0 1 1 0 C 1 1 1 1 1 D 1 0 0 1 2 E 2 0 0 0 0 F 1 1 0 2 1 4 g 1 1 1 h 0 1 2 w 0 0 0 b 0 2 1 0 Output E A B D F C w h b g Submitted Solution: ``` while True: n = int(input()) if n == 0: break tmp = [list(input().split()) for _ in range(n)] score = {'0': 2, '1': 0, '2': 1} ans = [] for t in tmp: tmpv = 0 for v in t[1:]: tmpv += score[v] ans.append(t[0] + str(tmpv)) for i in range(len(ans)): for j in range(i+1, len(ans))[::-1]: if ans[j][1] > ans[j-1][1]: ans[j], ans[j-1] = ans[j-1], ans[j] print('\n'.join(str(a[0]) for a in ans)) ```
instruction
0
81,632
17
163,264
No
output
1
81,632
17
163,265
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Japan achieved the second straight victory in the national baseball competition WBC !! A baseball tournament was held at Aizu Gakuen High School as baseball became more popular. In this tournament, a round-robin league match will be held and the ranking will be decided in the following ways. 1. The team with the most wins is ranked high 2. If the number of wins is the same, the team with the fewest losses will be ranked higher. Create a program that inputs the results of each team and outputs the team names in order from the top team. If there are teams with the same rank, output them in the order of input. However, the number of teams n is an integer from 2 to 10 and the team name t is a single-byte alphabetic character. , 2 for a draw. Also, the team name shall be unique. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n score1 score2 :: scoren The number of teams n (2 ≀ n ≀ 10) is given on the first line, and the scorei of the i-th team is given on the following n lines. Each grade is given in the following format. t r1 r2 ... rnβˆ’1 The team name t (one-character half-width alphabetic character) and the result ri (0, 1, or 2) for each match of t are given separated by blanks. The number of datasets does not exceed 50. Output For each dataset, the team name is output in order from the top team. Example Input 6 A 1 0 0 2 0 B 0 0 1 1 0 C 1 1 1 1 1 D 1 0 0 1 2 E 2 0 0 0 0 F 1 1 0 2 1 4 g 1 1 1 h 0 1 2 w 0 0 0 b 0 2 1 0 Output E A B D F C w h b g Submitted Solution: ``` while True: n = int(input()) if n == 0: break tmp = [list(input().split()) for _ in range(n)] score = {'0': 2, '1': 0, '2': 1} ans = [] for t in tmp: tmpv = 0 for v in t[1:]: tmpv += score[v] ans.append(t[0] + str(tmpv)) for i in range(len(ans)): for j in range(i+1, len(ans))[::-1]: if ans[j][1] > ans[j-1][1]: ans[j], ans[j-1] = ans[j-1], ans[j] print('\n'.join([a[0] for a in ans])) ```
instruction
0
81,633
17
163,266
No
output
1
81,633
17
163,267
Provide tags and a correct Python 3 solution for this coding contest problem. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.
instruction
0
81,737
17
163,474
Tags: combinatorics, dp, math, probabilities Correct Solution: ``` n, m, h = map(int, input().split()) s = list(map(int, input().split())) ans = 1 for i in range(sum(s) - 1, sum(s) - s[h - 1], -1): ans *= (i - n + 1) / i print (1 - ans if sum(s) >= n else -1) ```
output
1
81,737
17
163,475
Provide tags and a correct Python 3 solution for this coding contest problem. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.
instruction
0
81,738
17
163,476
Tags: combinatorics, dp, math, probabilities Correct Solution: ``` # Legends Always Come Up with Solution # Author: Manvir Singh import os from io import BytesIO, IOBase import sys from collections import defaultdict, deque, Counter from bisect import * from math import sqrt, pi, ceil, log, inf from itertools import permutations from copy import deepcopy from heapq import * from sys import setrecursionlimit def main(): n, m, h = map(int, input().split()) a = list(map(int, input().split())) z = sum(a) if n > z: print(-1) else: y = z - a[h - 1] p = 1 z = z - 1 for i in range(n - 1): p = p * (y / z) y -= 1 z -= 1 print(1 - p) # 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") if __name__ == "__main__": main() ```
output
1
81,738
17
163,477
Provide tags and a correct Python 3 solution for this coding contest problem. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.
instruction
0
81,739
17
163,478
Tags: combinatorics, dp, math, probabilities Correct Solution: ``` # by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def main(): n,m,h = map(int,input().split()) s = list(map(int,input().split())) x = sum(s) if x < n: print(-1) else: b,a = [i for i in range(x-s[h-1]+1,x)],[i for i in range(x-n-s[h-1]+2,x-n+1)] ans = 1 for x,y in zip(a,b): ans *= x ans /= y print(1-ans) #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") if __name__ == '__main__': main() ```
output
1
81,739
17
163,479
Provide tags and a correct Python 3 solution for this coding contest problem. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.
instruction
0
81,740
17
163,480
Tags: combinatorics, dp, math, probabilities Correct Solution: ``` def fact(x): ans = 1 for i in range(1, x + 1): ans *= i return ans def C(x, y): return fact(x) // fact(y) // fact(x - y) m, n, h = map(int, input().split()) a = list(map(int, input().split())) s = sum(a) h -= 1 if(s < m): print(-1) elif(s == m): if(a[h] > 1): print(1) else: print(0) else: ans = 1 for i in range(m - 1): ans *= (s - a[h] - i) ans /= (s - 1 - i) print(1 - ans) ```
output
1
81,740
17
163,481
Provide tags and a correct Python 3 solution for this coding contest problem. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.
instruction
0
81,741
17
163,482
Tags: combinatorics, dp, math, probabilities Correct Solution: ``` def nck(n,k): if(n<k): return 0 num=1 den=1 if(k>n-k): return nck(n,n-k) for i in range(k): num=num*(n-i) den=den*(i+1) return num//den l=input().split() n=int(l[0]) m=int(l[1]) h=int(l[2]) l=input().split() li=[int(i) for i in l] poss=sum(li)-1 if(poss<n-1): print(-1) else: ki=li[h-1]-1 print(1-(nck(poss-ki,n-1)/nck(poss,n-1))) ```
output
1
81,741
17
163,483
Provide tags and a correct Python 3 solution for this coding contest problem. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.
instruction
0
81,742
17
163,484
Tags: combinatorics, dp, math, probabilities Correct Solution: ``` #!/usr/bin/env python3 from functools import reduce from operator import mul from fractions import Fraction def nCk(n,k): return int( reduce(mul, (Fraction(n-i, i+1) for i in range(k)), 1) ) def divide(a, b): return float(Fraction(a, b)) def main(): n, _, h = list(map(int, input().split())) s = list(map(int, input().split())) s_sum = sum(s) if s_sum < n: print(-1) else: print(1 - divide(nCk(s_sum - s[h - 1], n - 1), nCk(s_sum - 1, n - 1))) if __name__ == '__main__': main() ```
output
1
81,742
17
163,485
Provide tags and a correct Python 3 solution for this coding contest problem. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.
instruction
0
81,743
17
163,486
Tags: combinatorics, dp, math, probabilities Correct Solution: ``` n, _, h = [int(x) for x in input().split()] s = [int(x) for x in input().split()] h -= 1 n -= 1 s[h] -= 1 st = sum(s) - s[h] if st + s[h] < n: print(-1) elif n == 0: print(0) elif st < n: print(1) elif st == 0: print(0 if s[h] == 0 else 1) else: def cmb(a, b): if b > a: return 0 if b == 0: return 1 import math # print( math.factorial(a), math.factorial(b), math.factorial(a - b), math.factorial(b) * math.factorial(a - b)) return math.factorial(a) // (math.factorial(b) * math.factorial(a - b)) ps = [0] * (n + 1) ca = [0] * (n + 1) cb = [0] * (n + 1) ca[1] = st cb[1] = s[h] ca[0] = 1 cb[0] = 1 for k in range(2, n + 1): ca[k] = ca[k - 1] * (st - k + 1) // k cb[k] = cb[k - 1] * (s[h] - k + 1) // k # print(ca) # print(cb) for k in range(n + 1): ps[k] = ca[n - k] * cb[k] # ps[k] = cmb(st, n - k) * cmb(s[h], k) # print(st - k, n - k, s[h], k, ps[k]) pass pst = sum(ps) print((pst - ps[0]) / pst) ```
output
1
81,743
17
163,487
Provide tags and a correct Python 3 solution for this coding contest problem. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.
instruction
0
81,744
17
163,488
Tags: combinatorics, dp, math, probabilities Correct Solution: ``` import math def binom(k, n): ret = 1 for i in range(0, k): ret = ret * (n-i) // (i+1) return ret [n, m, h] = map(int, input().split()) l = list(map(int, input().split())) t = sum(l) - 1 n = n - 1 l[h-1] = l[h-1] - 1 p = t - l[h-1] if n > t: print("{}".format(-1)) else: print("{}".format(1 - (binom(n, p) / binom(n, t)))) ```
output
1
81,744
17
163,489
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. Submitted Solution: ``` n, m, h = map(int, input().split()) s = list(map(int, input().split())) a = 1 S = sum(s) for i in range(S - s[h - 1] + 1, S): a *= (i - n + 1) / i print (-1 if S < n else 1 - a) ```
instruction
0
81,745
17
163,490
Yes
output
1
81,745
17
163,491
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. Submitted Solution: ``` import math from sys import stdin, stdout def ncr(n, r): if (n < r): return 0 r = min(r, n-r) ans = 1 for i in range(r): ans *= (n-i) ans //= (i+1) return ans n, m, h = map(int , stdin.readline().split()) s = list(map(int, stdin.readline().split())) tot = sum(s) if ( n > tot ): stdout.write(str(-1)) else: players_from_other_dept = tot - s[h-1] players_remaining = tot -1 players_remaining_to_be_sel = n - 1 ans = 1.0 ans -= ncr(players_from_other_dept, players_remaining_to_be_sel)/ncr(players_remaining, players_remaining_to_be_sel) stdout.write("%.8f"%(ans)) ```
instruction
0
81,746
17
163,492
Yes
output
1
81,746
17
163,493
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. Submitted Solution: ``` from math import * # Function to find the nCr def printNcR(n, r): # p holds the value of n*(n-1)*(n-2)..., # k holds the value of r*(r-1)... p = 1 k = 1 # C(n, r) == C(n, n-r), # choosing the smaller value if (n - r < r): r = n - r if (r != 0): while (r): p *= n k *= r # gcd of p, k m = gcd(p, k) # dividing by gcd, to simplify product # division by their gcd saves from # the overflow p //= m k //= m n -= 1 r -= 1 # print(r) # k should be simplified to 1 # as C(n, r) is a natural number # (denominator should be 1 ) else: p = 1 # if our approach is correct p = ans and k =1 return p n,m,h = map(int,(input().split())) a = list(map(int,input().strip().split())) if sum(a)<n: print(-1) elif a[h-1] == 1: print(0) elif sum(a) == n or sum(a)-a[h-1]<n-1 or sum(a)-1<n-1: print(1) else: p = printNcR(sum(a)-a[h-1],n-1)/printNcR(sum(a)-1,n-1) print(1 - p) ```
instruction
0
81,747
17
163,494
Yes
output
1
81,747
17
163,495
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. Submitted Solution: ``` R = lambda: map(int, input().split()) def cnt(n, k): res = 1 for i in range(k): res = res * (n - i) / (k + 1) return res n, m, h = R() h -= 1 ps = list(R()) tot = sum(ps) if tot < n: print(-1) exit(0) if tot <= 1 or n <= 1 or ps[h] <= 1: print(0) exit(0) if tot == n: print(1) exit(0) ac = cnt(tot - 1, n - 1) rem = cnt(tot - ps[h], n - 1) print((ac - rem) / ac) ```
instruction
0
81,748
17
163,496
Yes
output
1
81,748
17
163,497
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. Submitted Solution: ``` # Legends Always Come Up with Solution # Author: Manvir Singh import os from io import BytesIO, IOBase import sys from collections import defaultdict, deque, Counter from bisect import * from math import sqrt, pi, ceil, log, inf from itertools import permutations from copy import deepcopy from heapq import * from sys import setrecursionlimit def main(): n, m, h = map(int, input().split()) a = list(map(int, input().split())) z = sum(a) if n > z: print(-1) elif n == z: print(1) else: y = z - a[h - 1] p = 1 z = z - 1 for i in range(n - 1): p = p * (y / z) y -= 1 z -= 1 print(1 - p) # 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") if __name__ == "__main__": main() ```
instruction
0
81,749
17
163,498
No
output
1
81,749
17
163,499
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. Submitted Solution: ``` def ncr(x,y): m=1 n=1 for i in range(x-y+1,x+1): m*=i for i in range(1,y+1): n*=i return m//n a,b,c=map(int,input().split()) d=[int(d) for d in input().split()] e=0 for i in d: e+=i if(e==a): print("1") elif(e<a): print("-1") else: f=d[c-1]-1 g=e-d[c-1] p=ncr(g,a-2) o=(f*p)/ncr(e-1,a-1) print(o) ```
instruction
0
81,750
17
163,500
No
output
1
81,750
17
163,501
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. Submitted Solution: ``` n, m, h= input().split() a = [] nums = sorted([int(i) for i in input().split() if i.isdigit()]) soma = 0 for x in range(int(m)): soma = soma + nums[x] if(soma < int(n)): print("-1.0") else: temp1 = 1 temp2 = 1 soma1 = soma - 1 soma2 = soma - nums[int(h)] for x in range(int(n) - 1): soma = soma + nums[x] temp2 = temp2 * soma2 / soma1 soma2 = soma2 - 1 soma1 = soma1 - 1 temp1 = 1.0 - temp2 print ('%.6f' % temp1) ```
instruction
0
81,751
17
163,502
No
output
1
81,751
17
163,503
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. Submitted Solution: ``` n, m, h = map(int, input().split()) h -= 1 S = list(map(int, input().split())) def solve(): if sum(S) < n: return -1 if sum(S) - S[h] < n - 1: return 1 num1 = [k for k in range(1, sum(S) - S[h] + 1)] num2 = [k for k in range(1, sum(S) - n + 1)] den1 = [k for k in range(1, sum(S))] den2 = [k for k in range(1, sum(S) - S[h] - n + 2)] num1.sort(reverse=True) num2.sort(reverse=True) den1.sort(reverse=False) den2.sort(reverse=False) ans = 1 for i in range(max(map(len, [num1, num2, den1, den2]))): ans *= num1[i] if i < len(num1) else 1 ans *= num2[i] if i < len(num2) else 1 ans /= den1[i] if i < len(den1) else 1 ans /= den2[i] if i < len(den2) else 1 return 1 - ans print("%.12f\n" % solve()) ```
instruction
0
81,752
17
163,504
No
output
1
81,752
17
163,505
Provide tags and a correct Python 3 solution for this coding contest problem. A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other. There are two possible outcomes of a game: * the game may result in a tie, then both teams get 1 point; * one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points. The score of a team is the number of points it gained during all games that it played. You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well. Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible. Input The first line contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer n (2 ≀ n ≀ 100) β€” the number of teams. Output For each test case, print (n(n - 1))/(2) integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second β€” between team 1 and team 3, then 1 and 4, ..., 1 and n, 2 and 3, 2 and 4, ..., 2 and n, and so on, until the game between the team n - 1 and the team n. The integer corresponding to the game between the team x and the team y should be 1 if x wins, -1 if y wins, or 0 if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score. Example Input 2 2 3 Output 0 1 -1 1 Note In the first test case of the example, both teams get 1 point since the game between them is a tie. In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points).
instruction
0
81,950
17
163,900
Tags: brute force, constructive algorithms, dfs and similar, graphs, greedy, implementation, math Correct Solution: ``` from sys import stdin, gettrace if gettrace(): def inputi(): return input() else: def input(): return next(stdin)[:-1] def inputi(): return stdin.buffer.readline() def solve(): n = int(input()) res = [] for i in range(1,n): for j in range(min((n-1)//2, n-i)): res.append(1) if n%2 == 0 and (n-1)//2 < n-i: res.append(0) for j in range((n-1)//2 - i+1): res.append(-1) print(' '.join(map(str, res))) def main(): t = int(input()) for _ in range(t): solve() if __name__ == "__main__": main() ```
output
1
81,950
17
163,901
Provide tags and a correct Python 3 solution for this coding contest problem. A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other. There are two possible outcomes of a game: * the game may result in a tie, then both teams get 1 point; * one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points. The score of a team is the number of points it gained during all games that it played. You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well. Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible. Input The first line contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer n (2 ≀ n ≀ 100) β€” the number of teams. Output For each test case, print (n(n - 1))/(2) integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second β€” between team 1 and team 3, then 1 and 4, ..., 1 and n, 2 and 3, 2 and 4, ..., 2 and n, and so on, until the game between the team n - 1 and the team n. The integer corresponding to the game between the team x and the team y should be 1 if x wins, -1 if y wins, or 0 if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score. Example Input 2 2 3 Output 0 1 -1 1 Note In the first test case of the example, both teams get 1 point since the game between them is a tie. In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points).
instruction
0
81,951
17
163,902
Tags: brute force, constructive algorithms, dfs and similar, graphs, greedy, implementation, math Correct Solution: ``` #################################################### import os import sys 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") ####################################### for t in range(int(input())): n=int(input()) if n%2: l=[] for i in range((n*(n-1))//2): if i%2: l.append(-1) else: l.append(1) else: l1=[] l=[] for i in range(1,n): for j in range(i+1,n+1): l1.append([i,j]) c=1 d=1 y=1 for i in l1: if i[0]==c and i[1]==c+1: l.append(0) c=i[1]+1 else: if i[0]!=y: y=i[0] d^=1 if d: l.append(1) d^=1 else: l.append(-1) d^=1 print(*l) ```
output
1
81,951
17
163,903
Provide tags and a correct Python 3 solution for this coding contest problem. A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other. There are two possible outcomes of a game: * the game may result in a tie, then both teams get 1 point; * one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points. The score of a team is the number of points it gained during all games that it played. You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well. Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible. Input The first line contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer n (2 ≀ n ≀ 100) β€” the number of teams. Output For each test case, print (n(n - 1))/(2) integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second β€” between team 1 and team 3, then 1 and 4, ..., 1 and n, 2 and 3, 2 and 4, ..., 2 and n, and so on, until the game between the team n - 1 and the team n. The integer corresponding to the game between the team x and the team y should be 1 if x wins, -1 if y wins, or 0 if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score. Example Input 2 2 3 Output 0 1 -1 1 Note In the first test case of the example, both teams get 1 point since the game between them is a tie. In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points).
instruction
0
81,952
17
163,904
Tags: brute force, constructive algorithms, dfs and similar, graphs, greedy, implementation, math Correct Solution: ``` # ANKIT BEHIND import math t=int(input()) for i in range(0,t): n=int(input()) ans=[] if(n%2!=0): for i in range(0,(n*(n-1)//2)): if(i%2==0): ans.append(1) else: ans.append(-1) else: a=n//2 s=0 aa=n-1 index=0 i=1 while(i<=n*(n-1)//2): i=i+1 s=s+1 if(s==a) and (s<aa): ans.append(0) index=index+1 for j in range(s,aa): ans.append(-1) index=index+j i=index+1 aa=aa-1 s=0 elif(s==a) and (s==aa): ans.append(0) i=index+1 break else: ans.append(1) for i in range(0,n*(n-2)//8): ans.append(1) print(*ans) #c=list(map(int,input().split())) #n,k,kk=map(int,input().split()) ```
output
1
81,952
17
163,905
Provide tags and a correct Python 3 solution for this coding contest problem. A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other. There are two possible outcomes of a game: * the game may result in a tie, then both teams get 1 point; * one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points. The score of a team is the number of points it gained during all games that it played. You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well. Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible. Input The first line contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer n (2 ≀ n ≀ 100) β€” the number of teams. Output For each test case, print (n(n - 1))/(2) integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second β€” between team 1 and team 3, then 1 and 4, ..., 1 and n, 2 and 3, 2 and 4, ..., 2 and n, and so on, until the game between the team n - 1 and the team n. The integer corresponding to the game between the team x and the team y should be 1 if x wins, -1 if y wins, or 0 if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score. Example Input 2 2 3 Output 0 1 -1 1 Note In the first test case of the example, both teams get 1 point since the game between them is a tie. In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points).
instruction
0
81,953
17
163,906
Tags: brute force, constructive algorithms, dfs and similar, graphs, greedy, implementation, math Correct Solution: ``` # by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO,IOBase def some_random_function(): """due to the fast IO template, my code gets caught in plag check for no reason. That is why, I am writing random functions""" x = 10 x *= 100 i_dont_know = x why_am_i_writing_this = x*x print(i_dont_know) print(why_am_i_writing_this) def main(): for _ in range(int(input())): n = int(input()) if n&1: aa = [] x,y = n//2,n//2 for i in range(n-1): aa.extend([1]*x) aa.extend([-1]*y) if not y: x -= 1 else: y -= 1 print(*aa) else: aa = [] x,y = (n-1)//2,(n-1)//2 for i in range(n-1): if not i&1: aa.append(0) aa.extend([1]*x+[-1]*y) else: aa.extend([-1]*y+[1]*x) if not i&1: continue x -= 1 y -= 1 print(*aa) # 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") def some_random_function1(): """due to the fast IO template, my code gets caught in plag check for no reason. That is why, I am writing random functions""" x = 10 x *= 100 i_dont_know = x why_am_i_writing_this = x*x print(i_dont_know) print(why_am_i_writing_this) def some_random_function2(): """due to the fast IO template, my code gets caught in plag check for no reason. That is why, I am writing random functions""" x = 10 x *= 100 i_dont_know = x why_am_i_writing_this = x*x print(i_dont_know) print(why_am_i_writing_this) def some_random_function3(): """due to the fast IO template, my code gets caught in plag check for no reason. That is why, I am writing random functions""" x = 10 x *= 100 i_dont_know = x why_am_i_writing_this = x*x print(i_dont_know) print(why_am_i_writing_this) def some_random_function4(): """due to the fast IO template, my code gets caught in plag check for no reason. That is why, I am writing random functions""" x = 10 x *= 100 i_dont_know = x why_am_i_writing_this = x*x print(i_dont_know) print(why_am_i_writing_this) if __name__=='__main__': main() ```
output
1
81,953
17
163,907
Provide tags and a correct Python 3 solution for this coding contest problem. A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other. There are two possible outcomes of a game: * the game may result in a tie, then both teams get 1 point; * one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points. The score of a team is the number of points it gained during all games that it played. You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well. Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible. Input The first line contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer n (2 ≀ n ≀ 100) β€” the number of teams. Output For each test case, print (n(n - 1))/(2) integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second β€” between team 1 and team 3, then 1 and 4, ..., 1 and n, 2 and 3, 2 and 4, ..., 2 and n, and so on, until the game between the team n - 1 and the team n. The integer corresponding to the game between the team x and the team y should be 1 if x wins, -1 if y wins, or 0 if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score. Example Input 2 2 3 Output 0 1 -1 1 Note In the first test case of the example, both teams get 1 point since the game between them is a tie. In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points).
instruction
0
81,954
17
163,908
Tags: brute force, constructive algorithms, dfs and similar, graphs, greedy, implementation, math Correct Solution: ``` from math import ceil,floor,log import sys from heapq import heappush,heappop from collections import Counter,defaultdict,deque input=lambda : sys.stdin.readline().strip() c=lambda x: 10**9 if(x=="?") else int(x) class node: def __init__(self,x,y): self.a=[x,y] def __lt__(self,b): return b.a[0]<self.a[0] def __repr__(self): return str(self.a[0])+" "+str(self.a[1]) def main(): for _ in range(int(input())): n=int(input()) l=[0]*((n*(n-1))//2) t=1 k=0 if(n%2==1): for i in range(n*(n-1)//2): l[i]=t t=-t print(*l) else: t=-1 k=0 l1=[[0]*n for i in range(n)] for i in range(n): for j in range(i+1,n): if(i+1==j and i%2==0): pass else: l1[i][j]=t t=-t l[k]=l1[i][j] k+=1 if(i%2==0): t=1 else: t=-1 print(*l) main() ```
output
1
81,954
17
163,909
Provide tags and a correct Python 3 solution for this coding contest problem. A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other. There are two possible outcomes of a game: * the game may result in a tie, then both teams get 1 point; * one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points. The score of a team is the number of points it gained during all games that it played. You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well. Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible. Input The first line contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer n (2 ≀ n ≀ 100) β€” the number of teams. Output For each test case, print (n(n - 1))/(2) integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second β€” between team 1 and team 3, then 1 and 4, ..., 1 and n, 2 and 3, 2 and 4, ..., 2 and n, and so on, until the game between the team n - 1 and the team n. The integer corresponding to the game between the team x and the team y should be 1 if x wins, -1 if y wins, or 0 if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score. Example Input 2 2 3 Output 0 1 -1 1 Note In the first test case of the example, both teams get 1 point since the game between them is a tie. In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points).
instruction
0
81,955
17
163,910
Tags: brute force, constructive algorithms, dfs and similar, graphs, greedy, implementation, math Correct Solution: ``` for _ in range(int(input())): n=int(input()) x=(n*(n-1))//2 z=[0]*n k=x//n y=[] for i in range(n): for j in range(i+1,n): if z[i]<k: z[i]+=1 y.append(1) elif n%2==0 and z[i]<k+1: z[i]+=1 y.append(0) else: z[j]+=1 y.append(-1) print(*y) ```
output
1
81,955
17
163,911
Provide tags and a correct Python 3 solution for this coding contest problem. A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other. There are two possible outcomes of a game: * the game may result in a tie, then both teams get 1 point; * one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points. The score of a team is the number of points it gained during all games that it played. You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well. Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible. Input The first line contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer n (2 ≀ n ≀ 100) β€” the number of teams. Output For each test case, print (n(n - 1))/(2) integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second β€” between team 1 and team 3, then 1 and 4, ..., 1 and n, 2 and 3, 2 and 4, ..., 2 and n, and so on, until the game between the team n - 1 and the team n. The integer corresponding to the game between the team x and the team y should be 1 if x wins, -1 if y wins, or 0 if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score. Example Input 2 2 3 Output 0 1 -1 1 Note In the first test case of the example, both teams get 1 point since the game between them is a tie. In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points).
instruction
0
81,956
17
163,912
Tags: brute force, constructive algorithms, dfs and similar, graphs, greedy, implementation, math Correct Solution: ``` from sys import stdin, setrecursionlimit, stdout #setrecursionlimit(100000) #use "python" instead of "pypy" to avoid MLE from collections import deque from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin from heapq import heapify, heappop, heappush, heapreplace, heappushpop from bisect import bisect_right, bisect_left def ii(): return int(stdin.readline()) def fi(): return float(stdin.readline()) def mi(): return map(int, stdin.readline().split()) def fmi(): return map(float, stdin.readline().split()) def li(): return list(mi()) def si(): return stdin.readline().rstrip() def lsi(): return list(si()) mod=1000000007 res=['NO', 'YES'] ####################################################################################### ########################### M Y F U N C T I O N S ########################### ####################################################################################### ####################################################################################### ########################### M A I N P R O G R A M ########################### ####################################################################################### test, test_case=0, 1 test_case=ii() #print('>>>>>>>>>>>>>>>>>>>>>>>>>>>') while test<test_case: test+=1 n=ii() tot=(n*(n-1))//2 gap=tot//n f=0 if tot%n: f=1 a=[] for i in range(1, n+1): for j in range(i+1, n+1): g=j-i x=-1 if g<=gap: x=1 elif f and g==gap+1: x=0 a.append(x) print(*a) ```
output
1
81,956
17
163,913
Provide tags and a correct Python 3 solution for this coding contest problem. A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other. There are two possible outcomes of a game: * the game may result in a tie, then both teams get 1 point; * one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points. The score of a team is the number of points it gained during all games that it played. You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well. Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible. Input The first line contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer n (2 ≀ n ≀ 100) β€” the number of teams. Output For each test case, print (n(n - 1))/(2) integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second β€” between team 1 and team 3, then 1 and 4, ..., 1 and n, 2 and 3, 2 and 4, ..., 2 and n, and so on, until the game between the team n - 1 and the team n. The integer corresponding to the game between the team x and the team y should be 1 if x wins, -1 if y wins, or 0 if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score. Example Input 2 2 3 Output 0 1 -1 1 Note In the first test case of the example, both teams get 1 point since the game between them is a tie. In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points).
instruction
0
81,957
17
163,914
Tags: brute force, constructive algorithms, dfs and similar, graphs, greedy, implementation, math Correct Solution: ``` def solve(n): t = [[None for i in range(n)] for j in range(n)] for i in range(n): for j in range(i+1,n): if(j==i+1 and n&1==0 and i&1==0): t[i][j] = 0 t[j][i] = 0 elif(i&1==0): if(j&1==0): t[i][j] = 1 t[j][i] = -1 else: t[i][j] = -1 t[j][i] = 1 else: if(j&1==1): t[i][j] = 1 t[j][i] = -1 else: t[i][j] = -1 t[j][i] = 1 res = [] for i in range(n): for j in range(i+1,n): res.append(t[i][j]) for x in res: print(x,end=" ") print() t = int(input()) for _ in range(t): n = int(input()) solve(n) ```
output
1
81,957
17
163,915
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other. There are two possible outcomes of a game: * the game may result in a tie, then both teams get 1 point; * one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points. The score of a team is the number of points it gained during all games that it played. You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well. Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible. Input The first line contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer n (2 ≀ n ≀ 100) β€” the number of teams. Output For each test case, print (n(n - 1))/(2) integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second β€” between team 1 and team 3, then 1 and 4, ..., 1 and n, 2 and 3, 2 and 4, ..., 2 and n, and so on, until the game between the team n - 1 and the team n. The integer corresponding to the game between the team x and the team y should be 1 if x wins, -1 if y wins, or 0 if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score. Example Input 2 2 3 Output 0 1 -1 1 Note In the first test case of the example, both teams get 1 point since the game between them is a tie. In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points). Submitted Solution: ``` answers = [] def solve(n): final = [] limit = (n*(n-1)) // 2 if n == 2: answers.append([0]) return if n % 2 == 0: wins = (n-1) // 2 loss = (n-1) // 2 draw = 1 for i in range(1, n+1): temp = [] if wins >= 1: temp.append([1]*wins) if draw == 1: temp.append([0]) if loss >= 1: temp.append([-1]*loss) # print(temp) for ele in temp: final.extend(ele[:]) loss -= 1 if loss < 0: wins -= 1 draw = 0 # print(len(final), limit) if len(final) < limit: # print('ll') rem = limit-len(final) for i in range(rem): final.append(1) answers.append(final) else: wins = (n-1) // 2 loss = (n-1) // 2 # count = 0 for i in range(1, n+1): temp = [] if wins >= 1: temp.append([1]*wins) if loss >= 1: temp.append([-1]*loss) # print(temp) for ele in temp: final.extend(ele[:]) loss -= 1 if loss < 0: wins -= 1 answers.append(final) T = int(input()) while T: n = int(input()) solve(n) T -= 1 for ans in answers: print(*ans) ```
instruction
0
81,958
17
163,916
Yes
output
1
81,958
17
163,917
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other. There are two possible outcomes of a game: * the game may result in a tie, then both teams get 1 point; * one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points. The score of a team is the number of points it gained during all games that it played. You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well. Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible. Input The first line contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer n (2 ≀ n ≀ 100) β€” the number of teams. Output For each test case, print (n(n - 1))/(2) integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second β€” between team 1 and team 3, then 1 and 4, ..., 1 and n, 2 and 3, 2 and 4, ..., 2 and n, and so on, until the game between the team n - 1 and the team n. The integer corresponding to the game between the team x and the team y should be 1 if x wins, -1 if y wins, or 0 if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score. Example Input 2 2 3 Output 0 1 -1 1 Note In the first test case of the example, both teams get 1 point since the game between them is a tie. In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points). Submitted Solution: ``` for _ in range(int(input())): n = int(input()) if n%2==1: for i in range(n): for j in range(i+1,n): print(1 if (i+j)%2==1 else -1,end = " ") else: grid = [[0 for i in range(n)]for j in range(n)] for i in range(0,n,2): for j in range(i+2,n,2): grid[i][j] = 1 grid[i][j+1] = -1 grid[i+1][j] = -1 grid[i+1][j+1] = 1 for i in range(n): for j in range(i+1,n): print(grid[i][j],end = " ") print() ```
instruction
0
81,959
17
163,918
Yes
output
1
81,959
17
163,919
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other. There are two possible outcomes of a game: * the game may result in a tie, then both teams get 1 point; * one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points. The score of a team is the number of points it gained during all games that it played. You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well. Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible. Input The first line contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer n (2 ≀ n ≀ 100) β€” the number of teams. Output For each test case, print (n(n - 1))/(2) integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second β€” between team 1 and team 3, then 1 and 4, ..., 1 and n, 2 and 3, 2 and 4, ..., 2 and n, and so on, until the game between the team n - 1 and the team n. The integer corresponding to the game between the team x and the team y should be 1 if x wins, -1 if y wins, or 0 if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score. Example Input 2 2 3 Output 0 1 -1 1 Note In the first test case of the example, both teams get 1 point since the game between them is a tie. In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points). Submitted Solution: ``` t=int(input()) for q in range(t): n=int(input()) z=-1 if n%2==0: for i in range(1,n+1): for j in range(i+1,n+1): if i%2==1 and j==i+1: print(0,end=' ') elif i%2==0 and j==i+1: print(z,end=' ') else: if z==1: z=-1 else: z=1 print(z,end=' ') else: for i in range(1,n+1): for j in range(i+1,n+1): if z==1: z=-1 else: z=1 print(z,end=' ') ```
instruction
0
81,960
17
163,920
Yes
output
1
81,960
17
163,921
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other. There are two possible outcomes of a game: * the game may result in a tie, then both teams get 1 point; * one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points. The score of a team is the number of points it gained during all games that it played. You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well. Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible. Input The first line contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer n (2 ≀ n ≀ 100) β€” the number of teams. Output For each test case, print (n(n - 1))/(2) integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second β€” between team 1 and team 3, then 1 and 4, ..., 1 and n, 2 and 3, 2 and 4, ..., 2 and n, and so on, until the game between the team n - 1 and the team n. The integer corresponding to the game between the team x and the team y should be 1 if x wins, -1 if y wins, or 0 if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score. Example Input 2 2 3 Output 0 1 -1 1 Note In the first test case of the example, both teams get 1 point since the game between them is a tie. In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points). Submitted Solution: ``` def main(): num_cases = int(input()) for case_num in range(1, num_cases + 1): solve(case_num) def solve(case_num): # Code here n = int(input()) result = [[0] * n for _ in range(n)] for i in range(n): for j in range(1, n): if (n % 2 == 0 and j == n // 2): continue if j <= (n - 1) // 2: result[i][(i + j) % n] = 1 else: result[i][(i + j) % n] = -1 # cycle = [0, 1] # right = 2 # left = n - 1 # for i in range(n - 2): # if i % 2 == 0: # cycle.append(right) # right += 1 # else: # cycle.append(left) # left -= 1 # cycle.append(0) # for _ in range(n // 2): # for i, j in zip(cycle[:-1], cycle[1:]): # result[i][j] = 1 # result[j][i] = -1 # new_cycle = [] # for i in cycle: # if i == 0: # new_cycle.append(i) # elif i == n - 1: # new_cycle.append(1) # else: # new_cycle.append(i + 1) # cycle = new_cycle for i in range(n): for j in range(i + 1, n): print(result[i][j], end=' ') print() if __name__ == '__main__': main() ```
instruction
0
81,961
17
163,922
Yes
output
1
81,961
17
163,923
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other. There are two possible outcomes of a game: * the game may result in a tie, then both teams get 1 point; * one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points. The score of a team is the number of points it gained during all games that it played. You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well. Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible. Input The first line contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer n (2 ≀ n ≀ 100) β€” the number of teams. Output For each test case, print (n(n - 1))/(2) integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second β€” between team 1 and team 3, then 1 and 4, ..., 1 and n, 2 and 3, 2 and 4, ..., 2 and n, and so on, until the game between the team n - 1 and the team n. The integer corresponding to the game between the team x and the team y should be 1 if x wins, -1 if y wins, or 0 if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score. Example Input 2 2 3 Output 0 1 -1 1 Note In the first test case of the example, both teams get 1 point since the game between them is a tie. In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points). Submitted Solution: ``` t = int(input()) for _ in range(t): n = int(input()) matches = n-1 maxi = matches//2 arr = [0]*n out=[] for i in range(n): for j in range(i+1,n): if arr[i]<maxi: out.append(1) arr[i]+=1 elif arr[j]<maxi: out.append(-1) arr[j]+=1 else: out.append(0) print(*out) ```
instruction
0
81,962
17
163,924
No
output
1
81,962
17
163,925
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other. There are two possible outcomes of a game: * the game may result in a tie, then both teams get 1 point; * one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points. The score of a team is the number of points it gained during all games that it played. You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well. Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible. Input The first line contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer n (2 ≀ n ≀ 100) β€” the number of teams. Output For each test case, print (n(n - 1))/(2) integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second β€” between team 1 and team 3, then 1 and 4, ..., 1 and n, 2 and 3, 2 and 4, ..., 2 and n, and so on, until the game between the team n - 1 and the team n. The integer corresponding to the game between the team x and the team y should be 1 if x wins, -1 if y wins, or 0 if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score. Example Input 2 2 3 Output 0 1 -1 1 Note In the first test case of the example, both teams get 1 point since the game between them is a tie. In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points). Submitted Solution: ``` for _ in '.'*int(input()): n = int(input()) if n == 2: print(0) continue total = n*(n-1)//2 mw = total//n l = [0 for i in range(n)] #will store the number of wins draws = total%n a = n-1 while a>0: for i in range(a): if l[n-a-1] < mw: print("1", end = " ") l[n-a-1] +=1 else: if draws >0: print("0", end = " ") draws = draws - 1 else: print("-1", end = " ") l[n-a+i] += 1 a = a -1 ```
instruction
0
81,963
17
163,926
No
output
1
81,963
17
163,927
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other. There are two possible outcomes of a game: * the game may result in a tie, then both teams get 1 point; * one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points. The score of a team is the number of points it gained during all games that it played. You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well. Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible. Input The first line contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer n (2 ≀ n ≀ 100) β€” the number of teams. Output For each test case, print (n(n - 1))/(2) integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second β€” between team 1 and team 3, then 1 and 4, ..., 1 and n, 2 and 3, 2 and 4, ..., 2 and n, and so on, until the game between the team n - 1 and the team n. The integer corresponding to the game between the team x and the team y should be 1 if x wins, -1 if y wins, or 0 if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score. Example Input 2 2 3 Output 0 1 -1 1 Note In the first test case of the example, both teams get 1 point since the game between them is a tie. In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points). Submitted Solution: ``` # ------------------- fast io -------------------- import os import sys 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") # ------------------- fast io -------------------- def main(): for j in range(int(input())): n=int(input());games=(n*(n-1))//2 ans=[];count=(n-1)//2 for s in range(n): for i in range(s+1,n): if i<=s+count: ans.append(1) else: if i==s+count+1: ans.append(0) else: ans.append(-1) print(*ans) main() ```
instruction
0
81,964
17
163,928
No
output
1
81,964
17
163,929
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other. There are two possible outcomes of a game: * the game may result in a tie, then both teams get 1 point; * one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points. The score of a team is the number of points it gained during all games that it played. You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well. Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible. Input The first line contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. Then the test cases follow. Each test case is described by one line containing one integer n (2 ≀ n ≀ 100) β€” the number of teams. Output For each test case, print (n(n - 1))/(2) integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second β€” between team 1 and team 3, then 1 and 4, ..., 1 and n, 2 and 3, 2 and 4, ..., 2 and n, and so on, until the game between the team n - 1 and the team n. The integer corresponding to the game between the team x and the team y should be 1 if x wins, -1 if y wins, or 0 if the game results in a tie. All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score. Example Input 2 2 3 Output 0 1 -1 1 Note In the first test case of the example, both teams get 1 point since the game between them is a tie. In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points). Submitted Solution: ``` #input() #int(input()) #[s for s in input().split()] #[int(s) for s in input().split()] #for t in range(t): import math import collections import bisect def arrPrint(a): return " ".join([str(i) for i in a]) def gridPrint(a): return "\n".join([" ".join([str(j) for j in a[i]]) for i in range(len(a))]) def isPalindrome(s): for i in range(len(s)//2): if not s[i] == s[-i-1]: return False return True def solve(n): ans = [] for i in range(1, n + 1): for j in range(n - i): if n%2 == 0 and j == 0: ans.append(0) else: if j % 2 == 0: ans.append(1) else: ans.append(-1) return(arrPrint(ans)) t = int(input()) for t in range(t): n = int(input()) result = solve(n) print(result) ```
instruction
0
81,965
17
163,930
No
output
1
81,965
17
163,931
Provide a correct Python 3 solution for this coding contest problem. In 21XX, an annual programming contest, Japan Algorithmist GrandPrix (JAG) has become one of the most popular mind sports events. JAG is conducted as a knockout tournament. This year, $N$ contestants will compete in JAG. A tournament chart is represented as a string. '[[a-b]-[c-d]]' is an easy example. In this case, there are 4 contestants named a, b, c, and d, and all matches are described as follows: * Match 1 is the match between a and b. * Match 2 is the match between c and d. * Match 3 is the match between [the winner of match 1] and [the winner of match 2]. More precisely, the tournament chart satisfies the following BNF: * <winner> ::= <person> | "[" <winner> "-" <winner> "]" * <person> ::= "a" | "b" | "c" | ... | "z" You, the chairperson of JAG, are planning to announce the results of this year's JAG competition. However, you made a mistake and lost the results of all the matches. Fortunately, you found the tournament chart that was printed before all of the matches of the tournament. Of course, it does not contains results at all. Therefore, you asked every contestant for the number of wins in the tournament, and got $N$ pieces of information in the form of "The contestant $a_i$ won $v_i$ times". Now, your job is to determine whether all of these replies can be true. Input The input consists of a single test case in the format below. $S$ $a_1$ $v_1$ : $a_N$ $v_N$ $S$ represents the tournament chart. $S$ satisfies the above BNF. The following $N$ lines represent the information of the number of wins. The ($i+1$)-th line consists of a lowercase letter $a_i$ and a non-negative integer $v_i$ ($v_i \leq 26$) separated by a space, and this means that the contestant $a_i$ won $v_i$ times. Note that $N$ ($2 \leq N \leq 26$) means that the number of contestants and it can be identified by string $S$. You can assume that each letter $a_i$ is distinct. It is guaranteed that $S$ contains each $a_i$ exactly once and doesn't contain any other lowercase letters. Output Print 'Yes' in one line if replies are all valid for the tournament chart. Otherwise, print 'No' in one line. Examples Input [[m-y]-[a-o]] o 0 a 1 y 2 m 0 Output Yes Input [[r-i]-[m-e]] e 0 r 1 i 1 m 2 Output No
instruction
0
82,526
17
165,052
"Correct Solution: ``` #!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = LS() return l sys.setrecursionlimit(1000000) mod = 1000000007 #A def A(): def parse_winner(s,i): if s[i] == "[": i += 1 w1, i = parse_winner(s,i) i += 1 w2, i = parse_winner(s,i) return calc(w1, w2), i+1 else: p, i = parse_person(s,i) return p, i def parse_person(s,i): return s[i], i+1 def calc(w1,w2): if f[w1] == 0: if f[w2] == 0: return "0" else: f[w2] -= 1 return w2 else: if f[w2] != 0: return "0" else: f[w1] -= 1 return w1 s = S() k = 0 for i in s: if i not in "[-]": k += 1 f = defaultdict(int) f["0"] = 100000 for i in range(k): a,b = input().split() f[a] = int(b) w = parse_winner(s,0)[0] if f[w]: print("No") else: print("Yes") return #B def B(): n,k = LI() s = S() t = S() q = deque() ans = 0 for i in range(n): if s[i] == "B" and t[i] == "W": if q: x = q.popleft() if i-x >= k: ans += 1 while q: q.popleft() q.append(i) if q: ans += 1 for i in range(n): if s[i] == "W" and t[i] == "B": if q: x = q.popleft() if i-x >= k: ans += 1 while q: q.popleft() q.append(i) if q: ans += 1 print(ans) return #C def C(): n = I() s = SR(n) t = S() return #D from operator import mul def D(): def dot(a,b): return sum(map(mul,a,b)) def mul_matrix(a,b,m): tb = tuple(zip(*b)) return [[dot(a_i,b_j)%m for b_j in tb] for a_i in a] def pow_matrix(a,n,m): h = len(a) b = [[1 if i == j else 0 for j in range(h)] for i in range(h)] k = n while k: if (k&1): b = mul_matrix(b,a,m) a = mul_matrix(a,a,m) k >>= 1 return b while 1: n,m,a,b,c,t = LI() if n == 0: break s = LI() s2 = [[s[i] for j in range(1)] for i in range(n)] mat = [[0 for j in range(n)] for i in range(n)] mat[0][0] = b mat[0][1] = c for i in range(1,n-1): mat[i][i-1] = a mat[i][i] = b mat[i][i+1] = c mat[n-1][-2] = a mat[n-1][-1] = b mat = pow_matrix(mat,t,m) mat = mul_matrix(mat,s2,m) for i in mat[:-1]: print(i[0],end = " ") print(mat[-1][0]) return #E def E(): def surface(x,y,z): return ((x == 0)|(x == a-1))+((y == 0)|(y == b-1))+((z == 0)|(z == c-1))+k d = [(1,0,0),(-1,0,0),(0,1,0),(0,-1,0),(0,0,1),(0,0,-1)] a,b,c,n = LI() s = [0 for i in range(7)] k = (a==1)+(b==1)+(c==1) if k == 0: s[1] = 2*(max(0,a-2)*max(0,b-2)+max(0,c-2)*max(0,b-2)+max(0,a-2)*max(0,c-2)) s[2] = 4*(max(0,a-2)+max(0,b-2)+max(0,c-2)) s[3] = 8 elif k == 1: s[2] = max(0,a-2)*max(0,b-2)+max(0,c-2)*max(0,b-2)+max(0,a-2)*max(0,c-2) s[3] = 2*(max(0,a-2)+max(0,b-2)+max(0,c-2)) s[4] = 4 elif k == 2: s[4] = max(0,a-2)+max(0,b-2)+max(0,c-2) s[5] = 2 else: s[6] = 1 f = defaultdict(int) for i in range(n): x,y,z = LI() s[surface(x,y,z)] -= 1 f[(x,y,z)] = -1 for dx,dy,dz in d: if f[(x+dx,y+dy,z+dz)] != -1: f[(x+dx,y+dy,z+dz)] += 1 ans = 0 for i,j in f.items(): if j != -1: x,y,z = i if 0 <= x < a and 0 <= y < b and 0 <= z < c: ans += j+surface(x,y,z) s[surface(x,y,z)] -= 1 for i in range(1,7): ans += i*s[i] print(ans) return #F def F(): return #G def G(): return #H def H(): return #I def I_(): return #J def J(): return #Solve if __name__ == "__main__": A() ```
output
1
82,526
17
165,053
Provide a correct Python 3 solution for this coding contest problem. In 21XX, an annual programming contest, Japan Algorithmist GrandPrix (JAG) has become one of the most popular mind sports events. JAG is conducted as a knockout tournament. This year, $N$ contestants will compete in JAG. A tournament chart is represented as a string. '[[a-b]-[c-d]]' is an easy example. In this case, there are 4 contestants named a, b, c, and d, and all matches are described as follows: * Match 1 is the match between a and b. * Match 2 is the match between c and d. * Match 3 is the match between [the winner of match 1] and [the winner of match 2]. More precisely, the tournament chart satisfies the following BNF: * <winner> ::= <person> | "[" <winner> "-" <winner> "]" * <person> ::= "a" | "b" | "c" | ... | "z" You, the chairperson of JAG, are planning to announce the results of this year's JAG competition. However, you made a mistake and lost the results of all the matches. Fortunately, you found the tournament chart that was printed before all of the matches of the tournament. Of course, it does not contains results at all. Therefore, you asked every contestant for the number of wins in the tournament, and got $N$ pieces of information in the form of "The contestant $a_i$ won $v_i$ times". Now, your job is to determine whether all of these replies can be true. Input The input consists of a single test case in the format below. $S$ $a_1$ $v_1$ : $a_N$ $v_N$ $S$ represents the tournament chart. $S$ satisfies the above BNF. The following $N$ lines represent the information of the number of wins. The ($i+1$)-th line consists of a lowercase letter $a_i$ and a non-negative integer $v_i$ ($v_i \leq 26$) separated by a space, and this means that the contestant $a_i$ won $v_i$ times. Note that $N$ ($2 \leq N \leq 26$) means that the number of contestants and it can be identified by string $S$. You can assume that each letter $a_i$ is distinct. It is guaranteed that $S$ contains each $a_i$ exactly once and doesn't contain any other lowercase letters. Output Print 'Yes' in one line if replies are all valid for the tournament chart. Otherwise, print 'No' in one line. Examples Input [[m-y]-[a-o]] o 0 a 1 y 2 m 0 Output Yes Input [[r-i]-[m-e]] e 0 r 1 i 1 m 2 Output No
instruction
0
82,527
17
165,054
"Correct Solution: ``` import re def main(): s = input() d = {} n = len(re.findall(r'\w', s)) for i in range(n): a, v = input().split() v = int(v) d[a] = v prog = re.compile(r'\[(\w)-(\w)\]') m = prog.search(s) while m is not None: c1, c2 = m.group(1, 2) if d[c1] == d[c2]: print('No') return 0 if d[c1] < d[c2]: d[c2] -= 1 s = prog.sub(c2, s, 1) if d[c1] != 0: print('No') return 0 else: d[c1] -= 1 s = prog.sub(c1, s, 1) if d[c2] != 0: print('No') return 0 m = prog.search(s) if len(s) != 1: print('No') elif [0 for k, v in d.items() if v]: print('No') else: print('Yes') return 0 if __name__ == '__main__': main() ```
output
1
82,527
17
165,055
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A football league has recently begun in Beautiful land. There are n teams participating in the league. Let's enumerate them with integers from 1 to n. There will be played exactly (n(n-1))/(2) matches: each team will play against all other teams exactly once. In each match, there is always a winner and loser and there is no draw. After all matches are played, the organizers will count the number of beautiful triples. Let's call a triple of three teams (A, B, C) beautiful if a team A win against a team B, a team B win against a team C and a team C win against a team A. We look only to a triples of different teams and the order of teams in the triple is important. The beauty of the league is the number of beautiful triples. At the moment, m matches were played and their results are known. What is the maximum beauty of the league that can be, after playing all remaining matches? Also find a possible results for all remaining (n(n-1))/(2) - m matches, so that the league has this maximum beauty. Input The first line contains two integers n, m (3 ≀ n ≀ 50, 0 ≀ m ≀ (n(n-1))/(2)) β€” the number of teams in the football league and the number of matches that were played. Each of m following lines contains two integers u and v (1 ≀ u, v ≀ n, u β‰  v) denoting that the u-th team won against the v-th team. It is guaranteed that each unordered pair of teams appears at most once. Output Print n lines, each line having a string of exactly n characters. Each character must be either 0 or 1. Let a_{ij} be the j-th number in the i-th line. For all 1 ≀ i ≀ n it should be true, that a_{ii} = 0. For all pairs of teams i β‰  j the number a_{ij} indicates the result of the match between the i-th team and the j-th team: * If a_{ij} is 1, the i-th team wins against the j-th team; * Otherwise the j-th team wins against the i-th team; * Also, it should be true, that a_{ij} + a_{ji} = 1. Also note that the results of the m matches that were already played cannot be changed in your league. The beauty of the league in the output should be maximum possible. If there are multiple possible answers with maximum beauty, you can print any of them. Examples Input 3 1 1 2 Output 010 001 100 Input 4 2 1 2 1 3 Output 0110 0001 0100 1010 Note The beauty of league in the first test case is equal to 3 because there exists three beautiful triples: (1, 2, 3), (2, 3, 1), (3, 1, 2). The beauty of league in the second test is equal to 6 because there exists six beautiful triples: (1, 2, 4), (2, 4, 1), (4, 1, 2), (2, 4, 3), (4, 3, 2), (3, 2, 4). Submitted Solution: ``` import sys input = sys.stdin.readline n,m=map(int,input().split()) W=[0]*n WIN=0 ANS=[[-1]*n for i in range(n)] for i in range(n): ANS[i][i]=0 for i in range(m): x,y=map(int,input().split()) x-=1 y-=1 ANS[x][y]=1 ANS[y][x]=0 W[x]+=1 WIN+=1 last=n*(n-1)//2 while WIN<last: WL=sorted([(sc,ind) for ind,sc in enumerate(W)]) flag=0 for _,ind in WL: if -1 in ANS[ind]: for _,indr in WL[::-1]: if ANS[ind][indr]==-1: ANS[ind][indr]=1 ANS[indr][ind]=0 W[ind]+=1 WIN+=1 flag=1 break if flag: break for ans in ANS: print("".join(map(str,ans))) ```
instruction
0
82,708
17
165,416
No
output
1
82,708
17
165,417
Provide tags and a correct Python 3 solution for this coding contest problem. A programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive. Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the i-th student wants to be on the same team with the j-th one, then the j-th student wants to be on the same team with the i-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the i-th student wants to be on the same team with the j-th, then the i-th and the j-th students must be on the same team. Also, it is obvious that each student must be on exactly one team. Help the coach and divide the teams the way he wants. Input The first line of the input contains integers n and m (3 ≀ n ≀ 48, <image>. Then follow m lines, each contains a pair of integers ai, bi (1 ≀ ai < bi ≀ n) β€” the pair ai, bi means that students with numbers ai and bi want to be on the same team. It is guaranteed that n is divisible by 3. It is guaranteed that each pair ai, bi occurs in the input at most once. Output If the required division into teams doesn't exist, print number -1. Otherwise, print <image> lines. In each line print three integers xi, yi, zi (1 ≀ xi, yi, zi ≀ n) β€” the i-th team. If there are multiple answers, you are allowed to print any of them. Examples Input 3 0 Output 3 2 1 Input 6 4 1 2 2 3 3 4 5 6 Output -1 Input 3 3 1 2 2 3 1 3 Output 3 2 1
instruction
0
82,874
17
165,748
Tags: brute force, dfs and similar, graphs Correct Solution: ``` import sys nm = list(map(int, input().split())) done = [] visited = [] for i in range(nm[1]): pair = input().split() if pair[0] not in visited and pair[1] not in visited: done.append([pair[0],pair[1]]) visited.append(pair[0]) visited.append("-") visited.append(pair[1]) elif pair[0] not in visited: temp = visited.index(pair[1]) if temp < len(visited)-1 and visited[temp+1] != "-": if temp < len(visited)-1 and visited[temp+1] == "|": print("-1") sys.exit() visited.insert(temp+1,"-") visited.insert(temp+2,pair[0]) #visited.insert(temp+3,"|") else: if temp < len(visited)-3 and visited[temp+3] == "|": print("-1") sys.exit() visited.insert(temp+4,"-") visited.insert(temp+5,pair[0]) #visited.insert(temp+6,"|") elif pair[1] not in visited: temp = visited.index(pair[0]) if temp <len(visited)-1 and visited[temp+1] != "-": if temp < len(visited)-1 and visited[temp+1] == "|": print("-1") sys.exit() visited.insert(temp+1,"-") visited.insert(temp+2,pair[1]) #visited.insert(temp+3,"|") else: if temp < len(visited)-3 and visited[temp+3] == "|": print("-1") sys.exit() visited.insert(temp+4,"-") visited.insert(temp+5,pair[1]) #visited.insert(temp+6,"|") k = 0 lis = [[] for i in range((int(nm[0])//3)*2)] i = 0 while i<len(visited)-1: if visited[i+1] == "-": lis[k].append(visited[i]) i+=2 else: lis[k].append(visited[i]) k+=1 i+=1 i = 0 while i < len(lis): if lis[i] == []: lis.pop() i-=1 i+=1 if len(visited) > 2: lis[-1].append(visited[-1]) for i in range(nm[0]): flag = False if str(i+1) not in visited: for e in range(len(lis)): if len(lis[e]) < 3: lis[e].append(str(i+1)) flag = True break if not flag: lis.append([str(i+1)]) for i in lis: if len(i) != 3: print(-1) sys.exit() for i in lis: print(i[0],i[1],i[2]) ```
output
1
82,874
17
165,749
Provide tags and a correct Python 3 solution for this coding contest problem. A programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive. Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the i-th student wants to be on the same team with the j-th one, then the j-th student wants to be on the same team with the i-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the i-th student wants to be on the same team with the j-th, then the i-th and the j-th students must be on the same team. Also, it is obvious that each student must be on exactly one team. Help the coach and divide the teams the way he wants. Input The first line of the input contains integers n and m (3 ≀ n ≀ 48, <image>. Then follow m lines, each contains a pair of integers ai, bi (1 ≀ ai < bi ≀ n) β€” the pair ai, bi means that students with numbers ai and bi want to be on the same team. It is guaranteed that n is divisible by 3. It is guaranteed that each pair ai, bi occurs in the input at most once. Output If the required division into teams doesn't exist, print number -1. Otherwise, print <image> lines. In each line print three integers xi, yi, zi (1 ≀ xi, yi, zi ≀ n) β€” the i-th team. If there are multiple answers, you are allowed to print any of them. Examples Input 3 0 Output 3 2 1 Input 6 4 1 2 2 3 3 4 5 6 Output -1 Input 3 3 1 2 2 3 1 3 Output 3 2 1
instruction
0
82,875
17
165,750
Tags: brute force, dfs and similar, graphs Correct Solution: ``` #http://codeforces.com/problemset/problem/300/B from collections import defaultdict from itertools import islice def finding_connected_component(graph, current_student): stack = [current_student] result = [] while stack: student = stack.pop() result.append(student) for connected_student in graph[student]: if not visited[connected_student]: visited[connected_student] = True stack.append(connected_student) return result number_of_students, number_of_pairs = map(int, input().rstrip().split(" ")) graph = defaultdict(list) group = defaultdict(list) visited = [False] * (number_of_students+1) isHavingSolution = True for i in range(number_of_pairs): studentA, studentB = map(int, input().rstrip().split(" ")) graph[studentA].append(studentB) graph[studentB].append(studentA) for index in range(1, len(visited)): if not visited[index]: visited[index] = True list_of_connected_students = finding_connected_component(graph, index) if len(list_of_connected_students) > 3: isHavingSolution = False break else: group[len(list_of_connected_students)].append(list_of_connected_students) if len(group[2]) > len(group[1]) or not isHavingSolution: print(-1) else: while len(group[2]) > 0: current_group_2 = group[2].pop() current_group_1 = group[1].pop() group[3].append(current_group_2 + current_group_1) if len(group[1])%3 != 0: print(-1) else: index = 0 group_whateverleft = [] for element in group[1]: group_whateverleft.append(element[0]) last_group_3 = [group_whateverleft[i:i+3] for i in range(0, len(group_whateverleft), 3)] for element in last_group_3: group[3].append(element) for element in group[3]: element = sorted(element, reverse=True) print(' '.join(map(str, element))) ```
output
1
82,875
17
165,751
Provide tags and a correct Python 3 solution for this coding contest problem. A programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive. Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the i-th student wants to be on the same team with the j-th one, then the j-th student wants to be on the same team with the i-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the i-th student wants to be on the same team with the j-th, then the i-th and the j-th students must be on the same team. Also, it is obvious that each student must be on exactly one team. Help the coach and divide the teams the way he wants. Input The first line of the input contains integers n and m (3 ≀ n ≀ 48, <image>. Then follow m lines, each contains a pair of integers ai, bi (1 ≀ ai < bi ≀ n) β€” the pair ai, bi means that students with numbers ai and bi want to be on the same team. It is guaranteed that n is divisible by 3. It is guaranteed that each pair ai, bi occurs in the input at most once. Output If the required division into teams doesn't exist, print number -1. Otherwise, print <image> lines. In each line print three integers xi, yi, zi (1 ≀ xi, yi, zi ≀ n) β€” the i-th team. If there are multiple answers, you are allowed to print any of them. Examples Input 3 0 Output 3 2 1 Input 6 4 1 2 2 3 3 4 5 6 Output -1 Input 3 3 1 2 2 3 1 3 Output 3 2 1
instruction
0
82,876
17
165,752
Tags: brute force, dfs and similar, graphs Correct Solution: ``` import sys from collections import defaultdict def make_graph(): return defaultdict(make_graph) def return_pair_sets(person, graph, used): if person in used: return [] used[person] = True if person not in graph: return [person] sets = [person] for friend in graph[person]: sets += return_pair_sets(friend, graph, used) return sets values = [int(x) for x in sys.stdin.readline().split()] n_kids, n_pairings = values[0], values[1] graph = make_graph() for i in range(n_pairings): pair_values = [int(x) for x in sys.stdin.readline().split()] first, second = pair_values[0], pair_values[1] if first not in graph: graph[first] = [] if second not in graph: graph[second] = [] graph[first].append(second) graph[second].append(first) used = {} sets_of_three = [] for i in range(1, n_kids+1): if i not in used: group = return_pair_sets(i, graph, used) # print(group) if len(group) < 3: did_insert = False for j in sets_of_three: if len(j) + len(group) == 3: j += group did_insert = True break if not did_insert: sets_of_three.append(group) else: sets_of_three.append(group) ones = [x[0] for x in sets_of_three if len(x) == 1] if len(ones) % 3 != 0: print("-1") sys.exit(0) for i in range(len(ones) // 3): cur_set = [] index = i * 3 cur_set.append(ones[index]) cur_set.append(ones[index+1]) cur_set.append(ones[index+2]) sets_of_three.append(cur_set) for i in sets_of_three: if len(i) != 3 and len(i) != 1: print("-1") sys.exit(0) for i in sets_of_three: if len(i) == 3: sys.stdout.write(str(i[0]) + " " + str(i[1]) + " " + str(i[2]) + "\n") ```
output
1
82,876
17
165,753
Provide tags and a correct Python 3 solution for this coding contest problem. A programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive. Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the i-th student wants to be on the same team with the j-th one, then the j-th student wants to be on the same team with the i-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the i-th student wants to be on the same team with the j-th, then the i-th and the j-th students must be on the same team. Also, it is obvious that each student must be on exactly one team. Help the coach and divide the teams the way he wants. Input The first line of the input contains integers n and m (3 ≀ n ≀ 48, <image>. Then follow m lines, each contains a pair of integers ai, bi (1 ≀ ai < bi ≀ n) β€” the pair ai, bi means that students with numbers ai and bi want to be on the same team. It is guaranteed that n is divisible by 3. It is guaranteed that each pair ai, bi occurs in the input at most once. Output If the required division into teams doesn't exist, print number -1. Otherwise, print <image> lines. In each line print three integers xi, yi, zi (1 ≀ xi, yi, zi ≀ n) β€” the i-th team. If there are multiple answers, you are allowed to print any of them. Examples Input 3 0 Output 3 2 1 Input 6 4 1 2 2 3 3 4 5 6 Output -1 Input 3 3 1 2 2 3 1 3 Output 3 2 1
instruction
0
82,877
17
165,754
Tags: brute force, dfs and similar, graphs Correct Solution: ``` n,m=map(int,input().split()) from collections import defaultdict e=defaultdict(list) f,v=[False]*(n+1),[] def dfs(i,s): s.add(i) f[i]=True for k in e[i]: if not f[k]: dfs(k,s) for j in range(m): a,b=map(int,input().split()) e[a].append(b) e[b].append(a) for i in range(1,n+1): if e[i] and not f[i]: s=set() dfs(i,s) if len(s)>3: print(-1) exit() v.append(list(s)) if len(v)>(n//3): print(-1) exit() while len(v)<(n//3): v.append([]) vi = 0 for i in range(1, n + 1): if not f[i]: while len(v[vi]) == 3: vi += 1 v[vi].append(i) for vi in v: print(vi[0], vi[1], vi[2]) ```
output
1
82,877
17
165,755
Provide tags and a correct Python 3 solution for this coding contest problem. A programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive. Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the i-th student wants to be on the same team with the j-th one, then the j-th student wants to be on the same team with the i-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the i-th student wants to be on the same team with the j-th, then the i-th and the j-th students must be on the same team. Also, it is obvious that each student must be on exactly one team. Help the coach and divide the teams the way he wants. Input The first line of the input contains integers n and m (3 ≀ n ≀ 48, <image>. Then follow m lines, each contains a pair of integers ai, bi (1 ≀ ai < bi ≀ n) β€” the pair ai, bi means that students with numbers ai and bi want to be on the same team. It is guaranteed that n is divisible by 3. It is guaranteed that each pair ai, bi occurs in the input at most once. Output If the required division into teams doesn't exist, print number -1. Otherwise, print <image> lines. In each line print three integers xi, yi, zi (1 ≀ xi, yi, zi ≀ n) β€” the i-th team. If there are multiple answers, you are allowed to print any of them. Examples Input 3 0 Output 3 2 1 Input 6 4 1 2 2 3 3 4 5 6 Output -1 Input 3 3 1 2 2 3 1 3 Output 3 2 1
instruction
0
82,878
17
165,756
Tags: brute force, dfs and similar, graphs Correct Solution: ``` n, m = map(int, input().split()) visited = [False for i in range(n)] g = [[] for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) g[a-1].append(b-1) g[b-1].append(a-1) def dfs(x, s): s.add(x) visited[x] = True for adj in g[x]: if not visited[adj]: dfs(adj, s) groups = [] for i in range(n): if g[i] and not visited[i]: s = set() dfs(i, s) if len(s) > 3: print(-1) exit() groups.append(list(s)) if len(groups) > n//3: print(-1) exit() while len(groups) < n // 3: groups.append([]) current_v = 0 for i in range(n): if not visited[i]: while len(groups[current_v]) == 3: current_v += 1 groups[current_v].append(i) for g in groups: print(" ".join(map(lambda x: str(x+1), g))) ```
output
1
82,878
17
165,757
Provide tags and a correct Python 3 solution for this coding contest problem. A programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive. Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the i-th student wants to be on the same team with the j-th one, then the j-th student wants to be on the same team with the i-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the i-th student wants to be on the same team with the j-th, then the i-th and the j-th students must be on the same team. Also, it is obvious that each student must be on exactly one team. Help the coach and divide the teams the way he wants. Input The first line of the input contains integers n and m (3 ≀ n ≀ 48, <image>. Then follow m lines, each contains a pair of integers ai, bi (1 ≀ ai < bi ≀ n) β€” the pair ai, bi means that students with numbers ai and bi want to be on the same team. It is guaranteed that n is divisible by 3. It is guaranteed that each pair ai, bi occurs in the input at most once. Output If the required division into teams doesn't exist, print number -1. Otherwise, print <image> lines. In each line print three integers xi, yi, zi (1 ≀ xi, yi, zi ≀ n) β€” the i-th team. If there are multiple answers, you are allowed to print any of them. Examples Input 3 0 Output 3 2 1 Input 6 4 1 2 2 3 3 4 5 6 Output -1 Input 3 3 1 2 2 3 1 3 Output 3 2 1
instruction
0
82,879
17
165,758
Tags: brute force, dfs and similar, graphs Correct Solution: ``` n, m = map(int, input().split()) edges = [[*map(int, input().split())] for _ in range(m)] parent = [*range(n)] for i, j in edges: if parent[i - 1] != parent[j - 1]: old, new = parent[i - 1], parent[j - 1] for j in range(n): if parent[j] == old: parent[j] = new d = {} for i in range(n): if parent[i] in d: d[parent[i]].append(i + 1) else: d[parent[i]] = [i + 1] d = [i for i in d.values()] d.sort(key=lambda x: -len(x)) pl = [len(i) for i in d] th, tw, o = [], [], [] for i in d: if len(i) == 3: th.append(i) elif len(i) == 2: tw.append(i) elif len(i) == 1: o.append(i) elif len(i) > 3: print(-1) exit() if len(tw) > len(o): print(-1) exit() for i in th: print(*i) for i, j in zip(tw, o): print(i[0], i[1], j[0]) for i in range(len(tw), len(o), 3): print(o[i][0], o[i + 1][0], o[i + 2][0]) ```
output
1
82,879
17
165,759
Provide tags and a correct Python 3 solution for this coding contest problem. A programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive. Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the i-th student wants to be on the same team with the j-th one, then the j-th student wants to be on the same team with the i-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the i-th student wants to be on the same team with the j-th, then the i-th and the j-th students must be on the same team. Also, it is obvious that each student must be on exactly one team. Help the coach and divide the teams the way he wants. Input The first line of the input contains integers n and m (3 ≀ n ≀ 48, <image>. Then follow m lines, each contains a pair of integers ai, bi (1 ≀ ai < bi ≀ n) β€” the pair ai, bi means that students with numbers ai and bi want to be on the same team. It is guaranteed that n is divisible by 3. It is guaranteed that each pair ai, bi occurs in the input at most once. Output If the required division into teams doesn't exist, print number -1. Otherwise, print <image> lines. In each line print three integers xi, yi, zi (1 ≀ xi, yi, zi ≀ n) β€” the i-th team. If there are multiple answers, you are allowed to print any of them. Examples Input 3 0 Output 3 2 1 Input 6 4 1 2 2 3 3 4 5 6 Output -1 Input 3 3 1 2 2 3 1 3 Output 3 2 1
instruction
0
82,880
17
165,760
Tags: brute force, dfs and similar, graphs Correct Solution: ``` n,m = map(int, input().split()) arr = [i for i in range(n+1)] mem = {} for i in range(m): a,b = map(int, input().split()) if arr[a] in mem: mem[arr[a]].append(arr[b]) arr[b] = arr[a] elif arr[b] in mem: mem[arr[b]].append(arr[a]) arr[a] = arr[b] else: mem[arr[a]] = [arr[a],arr[b]] arr[b] = arr[a] for i in mem.keys(): arr[i] = 0 brr = [] for i in range(1,n+1): if arr[i]==i: brr.append(i) l1 = len(brr) crr = list(mem.values()) l2 = len(crr) for i in range(l2): crr[i] = list(set(crr[i])) flag = 0 for i in crr: if len(i)>3: flag = 1 break elif len(i)==3: continue else: try: i.append(brr[0]) brr = brr[1:] except: flag = 1 break if flag!=1: for i in crr: print(*i) l1 = len(brr) for j in range(0,l1,3): print(brr[j],brr[j+1],brr[j+2]) else: print(-1) ```
output
1
82,880
17
165,761
Provide tags and a correct Python 3 solution for this coding contest problem. A programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive. Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the i-th student wants to be on the same team with the j-th one, then the j-th student wants to be on the same team with the i-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the i-th student wants to be on the same team with the j-th, then the i-th and the j-th students must be on the same team. Also, it is obvious that each student must be on exactly one team. Help the coach and divide the teams the way he wants. Input The first line of the input contains integers n and m (3 ≀ n ≀ 48, <image>. Then follow m lines, each contains a pair of integers ai, bi (1 ≀ ai < bi ≀ n) β€” the pair ai, bi means that students with numbers ai and bi want to be on the same team. It is guaranteed that n is divisible by 3. It is guaranteed that each pair ai, bi occurs in the input at most once. Output If the required division into teams doesn't exist, print number -1. Otherwise, print <image> lines. In each line print three integers xi, yi, zi (1 ≀ xi, yi, zi ≀ n) β€” the i-th team. If there are multiple answers, you are allowed to print any of them. Examples Input 3 0 Output 3 2 1 Input 6 4 1 2 2 3 3 4 5 6 Output -1 Input 3 3 1 2 2 3 1 3 Output 3 2 1
instruction
0
82,881
17
165,762
Tags: brute force, dfs and similar, graphs Correct Solution: ``` import sys,math from collections import deque,defaultdict import operator as op from functools import reduce from itertools import permutations import heapq #sys.setrecursionlimit(10**7) # OneDrive\Documents\codeforces I=sys.stdin.readline alpha="abcdefghijklmnopqrstuvwxyz" mod=10**9 + 7 """ x_move=[-1,0,1,0,-1,1,1,-1] y_move=[0,1,0,-1,1,1,-1,-1] """ def ii(): return int(I().strip()) def li(): return list(map(int,I().strip().split())) def mi(): return map(int,I().strip().split()) def ncr(n, r): r = min(r, n-r) numer = reduce(op.mul, range(n, n-r, -1), 1) denom = reduce(op.mul, range(1, r+1), 1) return numer // denom def ispali(s): i=0 j=len(s)-1 while i<j: if s[i]!=s[j]: return False i+=1 j-=1 return True def isPrime(n): if n<=1: return False elif n<=2: return True else: for i in range(2,int(n**.5)+1): if n%i==0: return False return True def main(): n,m=mi() d=defaultdict(list) for i in range(m): u,v=mi() d[u].append(v) d[v].append(u) vis=[-1]*(n+1) cnt=1 groups=defaultdict(list) def dfs(i): vis[i]=cnt con=1 for child in d[i]: if vis[child]==-1: con+=dfs(child) return con f=0 for i in range(1,n+1): if vis[i]==-1: grup=dfs(i) tmp=[] for j in range(1,n+1): if vis[j]==cnt: tmp.append(j) if grup==3: groups[3].append(tmp) elif grup==2: groups[2].append(tmp) elif grup==1: groups[1].append(tmp) else: f=1 break cnt+=1 # print(groups) if len(groups[2])>len(groups[1]): f=1 else: for i in range(len(groups[2])): groups[3].append(groups[2].pop()+groups[1].pop()) for i in range(len(groups[1])//3): tmp=[] for _ in range(3): tmp+=groups[1].pop() groups[3].append(tmp) if len(groups[1])>0 or len(groups[3])!=n//3: f=1 if f: print(-1) else: for i in groups[3]: print(*i) if __name__ == '__main__': main() ```
output
1
82,881
17
165,763