message
stringlengths
2
43.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
853
107k
cluster
float64
24
24
__index_level_0__
int64
1.71k
214k
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y β‰₯ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost. Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β€” the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≀ ti ≀ 2; xi, yi β‰₯ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. Examples Input 2 1 5 5 2 6 4 Output LIVE LIVE Input 3 1 0 10 2 0 10 1 10 0 Output LIVE DEAD Note Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
instruction
0
95,563
24
191,126
Tags: implementation Correct Solution: ``` n=int(input()) sum1=0 sum2=0 z=0 c=0 for i in range(n): t,x,y=map(int,input().split()) if t==1: sum1+=x z+=1 if t==2: sum2+=x c+=1 if sum1>=int(5*z): print("LIVE") else: print("DEAD") if sum2>=int(5*c): print("LIVE") else: print("DEAD") ```
output
1
95,563
24
191,127
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y β‰₯ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost. Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β€” the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≀ ti ≀ 2; xi, yi β‰₯ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. Examples Input 2 1 5 5 2 6 4 Output LIVE LIVE Input 3 1 0 10 2 0 10 1 10 0 Output LIVE DEAD Note Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
instruction
0
95,564
24
191,128
Tags: implementation Correct Solution: ``` x=int(input()) a,b,c,d=0,0,0,0 for i in range(x): t,x,y=map(int,input().split()) if t==1: a+=1 b+=x if t==2: c+=1 d+=x if b>=a*5: print('LIVE') else: print('DEAD') if d>=c*5: print('LIVE') else: print('DEAD') ```
output
1
95,564
24
191,129
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y β‰₯ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost. Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β€” the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≀ ti ≀ 2; xi, yi β‰₯ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. Examples Input 2 1 5 5 2 6 4 Output LIVE LIVE Input 3 1 0 10 2 0 10 1 10 0 Output LIVE DEAD Note Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. Submitted Solution: ``` n = int(input()) s = [[0, 0], [0, 0]] for i in range(n): x = [int(s) for s in input().split(' ')] s[x[0] - 1][0] += x[1] s[x[0] - 1][1] += x[2] for server in s: if server[0] >= server[1]: print('LIVE') else: print('DEAD') ```
instruction
0
95,565
24
191,130
Yes
output
1
95,565
24
191,131
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y β‰₯ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost. Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β€” the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≀ ti ≀ 2; xi, yi β‰₯ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. Examples Input 2 1 5 5 2 6 4 Output LIVE LIVE Input 3 1 0 10 2 0 10 1 10 0 Output LIVE DEAD Note Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. Submitted Solution: ``` n = int(input()) live_a = 0 dead_a = 0 live_b = 0 dead_b = 0 status_a = False status_b = False for i in range(n): x = list(map(int, input().split())) if x[0] == 1: live_a += x[1] dead_a += x[2] else: live_b += x[1] dead_b += x[2] if live_a >= dead_a: status_a = True if live_b >= dead_b: status_b = True print("LIVE" if status_a == True else "DEAD") print("LIVE" if status_b == True else "DEAD") ```
instruction
0
95,566
24
191,132
Yes
output
1
95,566
24
191,133
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y β‰₯ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost. Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β€” the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≀ ti ≀ 2; xi, yi β‰₯ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. Examples Input 2 1 5 5 2 6 4 Output LIVE LIVE Input 3 1 0 10 2 0 10 1 10 0 Output LIVE DEAD Note Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. Submitted Solution: ``` import math t = int(input()) sum1 = 0 sum2 = 0 s1 = 0 s2 = 0 for i in range(t): s, x, y = input().split() if int(s) == 1: sum1 += int(x) s1 += 1 else: sum2 += int(x) s2 += 1 if sum1 >= s1*5: print("LIVE") else: print("DEAD") if sum2 >= s2*5: print("LIVE") else: print("DEAD") ```
instruction
0
95,567
24
191,134
Yes
output
1
95,567
24
191,135
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y β‰₯ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost. Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β€” the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≀ ti ≀ 2; xi, yi β‰₯ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. Examples Input 2 1 5 5 2 6 4 Output LIVE LIVE Input 3 1 0 10 2 0 10 1 10 0 Output LIVE DEAD Note Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. Submitted Solution: ``` x = int(input()) y = [] k = 0 l = 0 s = 0 s1 = 0 for i in range(x): y.append(list(map(int,input().split()))) for i in range(x): if y[i][0] == 1: t = y[i][1] s = s + t k = k + 1 if y[i][0] == 2: g = y[i][1] s1 = s1 + g l = l + 1 if s>=5*k: print("LIVE") if s<5*k: print("DEAD") if s1>=5*l: print("LIVE") if s1<5*l: print("DEAD") ```
instruction
0
95,568
24
191,136
Yes
output
1
95,568
24
191,137
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y β‰₯ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost. Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β€” the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≀ ti ≀ 2; xi, yi β‰₯ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. Examples Input 2 1 5 5 2 6 4 Output LIVE LIVE Input 3 1 0 10 2 0 10 1 10 0 Output LIVE DEAD Note Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. Submitted Solution: ``` n = int(input()) at, bt, al, bl = 0, 0, 0, 0 for _ in range(n): t, x, y = map(int,input().split()) if t == 1: at += x al += y if t == 2: bt += x bl += y if at>=int((al+at)/2): print("LIVE") else: print("DEAD") if bt >= int((al+at)/2): print("LIVE") else: print("DEAD") ```
instruction
0
95,569
24
191,138
No
output
1
95,569
24
191,139
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y β‰₯ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost. Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β€” the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≀ ti ≀ 2; xi, yi β‰₯ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. Examples Input 2 1 5 5 2 6 4 Output LIVE LIVE Input 3 1 0 10 2 0 10 1 10 0 Output LIVE DEAD Note Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. Submitted Solution: ``` n = int(input()) at, bt, al, bl = 0, 0, 0, 0 for _ in range(n): t, x, y = map(int,input().split()) if t == 1: at += x al += y if t == 2: bt += x bl += y if at>=int(al/2): print("LIVE") else: print("DEAD") if bt >= int(bl/2): print("LIVE") else: print("DEAD") ```
instruction
0
95,570
24
191,140
No
output
1
95,570
24
191,141
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y β‰₯ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost. Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β€” the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≀ ti ≀ 2; xi, yi β‰₯ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. Examples Input 2 1 5 5 2 6 4 Output LIVE LIVE Input 3 1 0 10 2 0 10 1 10 0 Output LIVE DEAD Note Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. Submitted Solution: ``` n=int(input()) l=[] m=[] count=0 add=0 for i in range(n): li=list(map(int,input().split())) if li[0]==1: l.append(li) count+=1 else: m.append(li) add+=1 sum1=0 sum2=0 for row in range(count): sum1+=l[row][1] for col in range(add): sum2+=m[col][1] if sum1>=int(count)*5: print("live") else: print("dead") if sum2>=int(add)*5: print("live") else: print("dead") ```
instruction
0
95,571
24
191,142
No
output
1
95,571
24
191,143
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarpus is a system administrator. There are two servers under his strict guidance β€” a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y β‰₯ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost. Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input The first line contains a single integer n (2 ≀ n ≀ 1000) β€” the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β€” the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≀ ti ≀ 2; xi, yi β‰₯ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. Examples Input 2 1 5 5 2 6 4 Output LIVE LIVE Input 3 1 0 10 2 0 10 1 10 0 Output LIVE DEAD Note Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. Submitted Solution: ``` x = int(input()) i1 = 0 i2 = 0 check = 0 for i in range(x): l1 = [int(n) for n in input().split()] check += l1[2] if l1[0] == 1: i1 += l1[1] else: i2 += l1[1] if(i1 >= (check // 2)): print("LIVE") else: print("DEAD") if (i2 >= (check // 2)): print("LIVE") else: print("DEAD") ```
instruction
0
95,572
24
191,144
No
output
1
95,572
24
191,145
Provide tags and a correct Python 3 solution for this coding contest problem. It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>. You should write a program which will calculate average sleep times of Polycarp over all weeks. Input The first line contains two integer numbers n and k (1 ≀ k ≀ n ≀ 2Β·105). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Examples Input 3 2 3 4 7 Output 9.0000000000 Input 1 1 10 Output 10.0000000000 Input 8 2 1 2 4 100000 123 456 789 1 Output 28964.2857142857 Note In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7.
instruction
0
95,764
24
191,528
Tags: data structures, implementation, math Correct Solution: ``` n,k=map(int,input().split()) arr=list(map(int,input().split())) ww=n-k+1 a=[] a.append(0) for i in range(n): a.append(arr[i]) for i in range(1,n+1): a[i]=a[i]+a[i-1] ans=0 for i in range(k,n+1): tmp=a[i]-a[i-k] ans+=(tmp/ww) print(ans) ```
output
1
95,764
24
191,529
Provide tags and a correct Python 3 solution for this coding contest problem. It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>. You should write a program which will calculate average sleep times of Polycarp over all weeks. Input The first line contains two integer numbers n and k (1 ≀ k ≀ n ≀ 2Β·105). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Examples Input 3 2 3 4 7 Output 9.0000000000 Input 1 1 10 Output 10.0000000000 Input 8 2 1 2 4 100000 123 456 789 1 Output 28964.2857142857 Note In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7.
instruction
0
95,765
24
191,530
Tags: data structures, implementation, math Correct Solution: ``` n, k = map(int, input().split()) a = [0] + list(map(int, input().split())) s, v = sum(a[:k]), 0 for i in range(k, n + 1): s += a[i] - a[i - k] v += s print(v / (n - k + 1)) ```
output
1
95,765
24
191,531
Provide tags and a correct Python 3 solution for this coding contest problem. It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>. You should write a program which will calculate average sleep times of Polycarp over all weeks. Input The first line contains two integer numbers n and k (1 ≀ k ≀ n ≀ 2Β·105). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Examples Input 3 2 3 4 7 Output 9.0000000000 Input 1 1 10 Output 10.0000000000 Input 8 2 1 2 4 100000 123 456 789 1 Output 28964.2857142857 Note In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7.
instruction
0
95,766
24
191,532
Tags: data structures, implementation, math Correct Solution: ``` from sys import stdin a,b=map(int,stdin.readline().split()) c=list(map(int,stdin.readline().split())) s=sum(c[:b]);k=s for i in range(1,a-b+1):k=k-c[i-1]+c[i+b-1];s+=k print((s)/(a-b+1)) ```
output
1
95,766
24
191,533
Provide tags and a correct Python 3 solution for this coding contest problem. It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>. You should write a program which will calculate average sleep times of Polycarp over all weeks. Input The first line contains two integer numbers n and k (1 ≀ k ≀ n ≀ 2Β·105). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Examples Input 3 2 3 4 7 Output 9.0000000000 Input 1 1 10 Output 10.0000000000 Input 8 2 1 2 4 100000 123 456 789 1 Output 28964.2857142857 Note In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7.
instruction
0
95,767
24
191,534
Tags: data structures, implementation, math Correct Solution: ``` while True: try: n, k = map(int, input().split(' ')) except: break L = [int(x) for x in input().split(' ')] ans = sum = 0.0 for x in L[:k]: sum += x ans += sum for i in range(k, n): sum = sum - L[i - k] + L[i] ans += sum print('%.10f' % (ans / (n - k + 1))) ```
output
1
95,767
24
191,535
Provide tags and a correct Python 3 solution for this coding contest problem. It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>. You should write a program which will calculate average sleep times of Polycarp over all weeks. Input The first line contains two integer numbers n and k (1 ≀ k ≀ n ≀ 2Β·105). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Examples Input 3 2 3 4 7 Output 9.0000000000 Input 1 1 10 Output 10.0000000000 Input 8 2 1 2 4 100000 123 456 789 1 Output 28964.2857142857 Note In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7.
instruction
0
95,768
24
191,536
Tags: data structures, implementation, math Correct Solution: ``` def solve(n,k,a): s = sum(a[:k]) tot = 0 l = 0 tot += s for r in range(k,n): s = s-a[l]+a[r] tot += s l+=1 return tot/(n-k+1) def main(): n,k = map(int,input().split(' ')) a = [int(x) for x in input().split(' ')] print('{:0.6f}'.format(solve(n,k,a))) if __name__ == "__main__": main() ```
output
1
95,768
24
191,537
Provide tags and a correct Python 3 solution for this coding contest problem. It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>. You should write a program which will calculate average sleep times of Polycarp over all weeks. Input The first line contains two integer numbers n and k (1 ≀ k ≀ n ≀ 2Β·105). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Examples Input 3 2 3 4 7 Output 9.0000000000 Input 1 1 10 Output 10.0000000000 Input 8 2 1 2 4 100000 123 456 789 1 Output 28964.2857142857 Note In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7.
instruction
0
95,769
24
191,538
Tags: data structures, implementation, math Correct Solution: ``` n,k=list(map(int,input().strip().split(' '))) A=list(map(int,input().strip().split(' '))) temp=0 total=0 for i in range(n-k+1): if i==0: temp=sum(A[:k]) total+=temp else: temp-=A[i-1] temp+=A[i+k-1] total+=temp #print(temp) ans=total/(n-k+1) print(ans) ```
output
1
95,769
24
191,539
Provide tags and a correct Python 3 solution for this coding contest problem. It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>. You should write a program which will calculate average sleep times of Polycarp over all weeks. Input The first line contains two integer numbers n and k (1 ≀ k ≀ n ≀ 2Β·105). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Examples Input 3 2 3 4 7 Output 9.0000000000 Input 1 1 10 Output 10.0000000000 Input 8 2 1 2 4 100000 123 456 789 1 Output 28964.2857142857 Note In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7.
instruction
0
95,770
24
191,540
Tags: data structures, implementation, math Correct Solution: ``` import sys input = sys.stdin.readline ''' week = k days ai sleep time on i-th day ''' n, k = map(int, input().split()) a = list(map(int, input().split())) k_sum = sum(a[:k]) tot = k_sum left, right = 0, k while right < n: k_sum -= a[left] k_sum += a[right] tot += k_sum left += 1 right += 1 print(tot / (n-k+1)) ```
output
1
95,770
24
191,541
Provide tags and a correct Python 3 solution for this coding contest problem. It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>. You should write a program which will calculate average sleep times of Polycarp over all weeks. Input The first line contains two integer numbers n and k (1 ≀ k ≀ n ≀ 2Β·105). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Examples Input 3 2 3 4 7 Output 9.0000000000 Input 1 1 10 Output 10.0000000000 Input 8 2 1 2 4 100000 123 456 789 1 Output 28964.2857142857 Note In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7.
instruction
0
95,771
24
191,542
Tags: data structures, implementation, math Correct Solution: ``` n,k = map(int, input().split()) values = list(map(int, input().split())) total = sum(values[:k]) hours = total for i in range(k,n): total += values[i] - values[i-k] hours += total print("%.6f" % (hours/(n-k+1))) ```
output
1
95,771
24
191,543
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>. You should write a program which will calculate average sleep times of Polycarp over all weeks. Input The first line contains two integer numbers n and k (1 ≀ k ≀ n ≀ 2Β·105). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Examples Input 3 2 3 4 7 Output 9.0000000000 Input 1 1 10 Output 10.0000000000 Input 8 2 1 2 4 100000 123 456 789 1 Output 28964.2857142857 Note In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7. Submitted Solution: ``` n,k = map(int,input().split()) a=list(map(int,input().split())) sum=0 for i in range(k): sum+=a[i] total = sum i=1 while(i+k-1 < n): sum-=a[i-1] sum+=a[i+k-1] i+=1 total+=sum print(format(total/(n-k+1),'.6f')) ```
instruction
0
95,772
24
191,544
Yes
output
1
95,772
24
191,545
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>. You should write a program which will calculate average sleep times of Polycarp over all weeks. Input The first line contains two integer numbers n and k (1 ≀ k ≀ n ≀ 2Β·105). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Examples Input 3 2 3 4 7 Output 9.0000000000 Input 1 1 10 Output 10.0000000000 Input 8 2 1 2 4 100000 123 456 789 1 Output 28964.2857142857 Note In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7. Submitted Solution: ``` from itertools import * n,k = [int(x) for x in input().split()] a = list(accumulate([0] + [int(x) for x in input().split()])) print(sum([a[i] - a[i-k] for i in range(k,n+1)]) / (n-k+1)) ```
instruction
0
95,773
24
191,546
Yes
output
1
95,773
24
191,547
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>. You should write a program which will calculate average sleep times of Polycarp over all weeks. Input The first line contains two integer numbers n and k (1 ≀ k ≀ n ≀ 2Β·105). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Examples Input 3 2 3 4 7 Output 9.0000000000 Input 1 1 10 Output 10.0000000000 Input 8 2 1 2 4 100000 123 456 789 1 Output 28964.2857142857 Note In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7. Submitted Solution: ``` n, k = list(map(int, input().split())) a = list(map(int, input().split())) running_sum = [] acc = 0 for i in range(0, k): acc += a[i] running_sum.append(acc) total = running_sum[k - 1] for i in range(k, n): acc += a[i] running_sum.append(acc) total += running_sum[i] - running_sum[i - k] print("%.10f" % (total / (n - k + 1))) ```
instruction
0
95,774
24
191,548
Yes
output
1
95,774
24
191,549
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>. You should write a program which will calculate average sleep times of Polycarp over all weeks. Input The first line contains two integer numbers n and k (1 ≀ k ≀ n ≀ 2Β·105). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Examples Input 3 2 3 4 7 Output 9.0000000000 Input 1 1 10 Output 10.0000000000 Input 8 2 1 2 4 100000 123 456 789 1 Output 28964.2857142857 Note In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7. Submitted Solution: ``` n, k = list(map(int, input().split())) a = list(map(int, input().split())) r, s, x = n-k+1, 0, [] x.append(a[0]) for i in range(1, n+1): x.append(x[i-1] + a[i-1]) for i in range(k, n+1): s += x[i] - x[i-k] print(s/r) ```
instruction
0
95,775
24
191,550
Yes
output
1
95,775
24
191,551
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>. You should write a program which will calculate average sleep times of Polycarp over all weeks. Input The first line contains two integer numbers n and k (1 ≀ k ≀ n ≀ 2Β·105). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Examples Input 3 2 3 4 7 Output 9.0000000000 Input 1 1 10 Output 10.0000000000 Input 8 2 1 2 4 100000 123 456 789 1 Output 28964.2857142857 Note In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7. Submitted Solution: ``` def computeAvg(n, k, a, ans=0.): for i in range(n): ans+=float(min(k,n+k-1,n-i,i+1))*a[i]/1.0/(n-k+1) return float(ans) if __name__ == "__main__": n, k = list(map(int, input().split())) a = list(map(int, input().split())) print(computeAvg(n,k,a)) ```
instruction
0
95,776
24
191,552
No
output
1
95,776
24
191,553
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>. You should write a program which will calculate average sleep times of Polycarp over all weeks. Input The first line contains two integer numbers n and k (1 ≀ k ≀ n ≀ 2Β·105). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Examples Input 3 2 3 4 7 Output 9.0000000000 Input 1 1 10 Output 10.0000000000 Input 8 2 1 2 4 100000 123 456 789 1 Output 28964.2857142857 Note In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7. Submitted Solution: ``` #puoy-tang 3, 808B, 2137, G O O D B O Y O puoy-tang inp = input().split() n, k = int(inp[0]), int(inp[1]) cunt = n-k+1 a = input().split() tsum = 0 hlf = 1 for i in range(0,len(a)): a[i] = int(a[i]) tsum += a[i]*min(hlf, k, cunt) if hlf < len(a)/2: hlf += 1 elif hlf > len(a)/2: hlf -= 1 tsum /= n-k+1 print(tsum) ```
instruction
0
95,777
24
191,554
No
output
1
95,777
24
191,555
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>. You should write a program which will calculate average sleep times of Polycarp over all weeks. Input The first line contains two integer numbers n and k (1 ≀ k ≀ n ≀ 2Β·105). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Examples Input 3 2 3 4 7 Output 9.0000000000 Input 1 1 10 Output 10.0000000000 Input 8 2 1 2 4 100000 123 456 789 1 Output 28964.2857142857 Note In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7. Submitted Solution: ``` x=input() x=x.split() n=input() n=n.split() for i in range(0,len(x)): x[i]=float(int(x[i])) for i in range(0,len(n)): n[i]=float(int(n[i])) no=x[0]-x[1]+1 sum_=float(0); for i in n: sum_+=i sum_*=2 sum_-=n[0] sum_-=n[-1] print(float(sum_)/float(x[0]-x[1]+1)) ```
instruction
0
95,778
24
191,556
No
output
1
95,778
24
191,557
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequence a1, a2, ..., an, where ai is the sleep time on the i-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2, n = 3 and a = [3, 4, 7], then the result is <image>. You should write a program which will calculate average sleep times of Polycarp over all weeks. Input The first line contains two integer numbers n and k (1 ≀ k ≀ n ≀ 2Β·105). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 105). Output Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Examples Input 3 2 3 4 7 Output 9.0000000000 Input 1 1 10 Output 10.0000000000 Input 8 2 1 2 4 100000 123 456 789 1 Output 28964.2857142857 Note In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7. Submitted Solution: ``` from math import floor def truncate(f, n): return floor(f * 10 ** n) / 10 ** n def bounded_sum(l, p1, p2): r = 0 for i in range(p1, p2 + 1): r += l[i] return r def solve(n, k, a): pos = 0 total = 0 for i in range(n - k + 1): total += bounded_sum(a, pos, pos + k - 1) pos += k - 1 return total/(n - k + 1) N, K = [int(i) for i in input().split()] A = [int(i) for i in input().split()] print(truncate(solve(N, K, A), 10)) # 1521408685546 ```
instruction
0
95,779
24
191,558
No
output
1
95,779
24
191,559
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a string s consisting of n lowercase Latin letters. Polycarp wants to remove exactly k characters (k ≀ n) from the string s. Polycarp uses the following algorithm k times: * if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; * if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; * ... * remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly k times, thus removing exactly k characters. Help Polycarp find the resulting string. Input The first line of input contains two integers n and k (1 ≀ k ≀ n ≀ 4 β‹… 10^5) β€” the length of the string and the number of letters Polycarp will remove. The second line contains the string s consisting of n lowercase Latin letters. Output Print the string that will be obtained from s after Polycarp removes exactly k letters using the above algorithm k times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). Examples Input 15 3 cccaabababaccbc Output cccbbabaccbc Input 15 9 cccaabababaccbc Output cccccc Input 1 1 u Output
instruction
0
95,839
24
191,678
Tags: implementation Correct Solution: ``` from collections import Counter N,K = map(int,input().split()) S = input() C = Counter(S) cnt = 0 for i in range(26): c = chr(97+i) if cnt + C[c] >= K: break else: cnt += C[c] S = S.replace(c,"") t = "" for s in S: if s == c and cnt < K: cnt += 1 else: t += s else: S = t print(S) ```
output
1
95,839
24
191,679
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a string s consisting of n lowercase Latin letters. Polycarp wants to remove exactly k characters (k ≀ n) from the string s. Polycarp uses the following algorithm k times: * if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; * if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; * ... * remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly k times, thus removing exactly k characters. Help Polycarp find the resulting string. Input The first line of input contains two integers n and k (1 ≀ k ≀ n ≀ 4 β‹… 10^5) β€” the length of the string and the number of letters Polycarp will remove. The second line contains the string s consisting of n lowercase Latin letters. Output Print the string that will be obtained from s after Polycarp removes exactly k letters using the above algorithm k times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). Examples Input 15 3 cccaabababaccbc Output cccbbabaccbc Input 15 9 cccaabababaccbc Output cccccc Input 1 1 u Output
instruction
0
95,842
24
191,684
Tags: implementation Correct Solution: ``` _, k = map(int, input().split()) s = input() for ch in 'abcdefghijklmnopqrstuvwxyz': x = s.count(ch) if x < k: s = s.replace(ch, '', x) k -= x else: s = s.replace(ch, '', k) break print(s) ```
output
1
95,842
24
191,685
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s consisting of n lowercase Latin letters. Polycarp wants to remove exactly k characters (k ≀ n) from the string s. Polycarp uses the following algorithm k times: * if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; * if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; * ... * remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly k times, thus removing exactly k characters. Help Polycarp find the resulting string. Input The first line of input contains two integers n and k (1 ≀ k ≀ n ≀ 4 β‹… 10^5) β€” the length of the string and the number of letters Polycarp will remove. The second line contains the string s consisting of n lowercase Latin letters. Output Print the string that will be obtained from s after Polycarp removes exactly k letters using the above algorithm k times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). Examples Input 15 3 cccaabababaccbc Output cccbbabaccbc Input 15 9 cccaabababaccbc Output cccccc Input 1 1 u Output Submitted Solution: ``` def fun(s,n,k): occ=[0]*26 for i in s: occ[ord(i)-97]+=1 r=k i=-1 while r>0: i+=1 r-=occ[i] if i==-1: return '' last=occ[i]+r occ[i]=last ans='' for j in s: ch=ord(j)-97 if ch<=i and occ[ch]>0: occ[ch]-=1 else: ans+=j return ans n,k=map(int,input().split()) #n=int(input()) s=input() print(fun(s,n,k)) ```
instruction
0
95,847
24
191,694
Yes
output
1
95,847
24
191,695
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s consisting of n lowercase Latin letters. Polycarp wants to remove exactly k characters (k ≀ n) from the string s. Polycarp uses the following algorithm k times: * if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; * if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; * ... * remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly k times, thus removing exactly k characters. Help Polycarp find the resulting string. Input The first line of input contains two integers n and k (1 ≀ k ≀ n ≀ 4 β‹… 10^5) β€” the length of the string and the number of letters Polycarp will remove. The second line contains the string s consisting of n lowercase Latin letters. Output Print the string that will be obtained from s after Polycarp removes exactly k letters using the above algorithm k times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). Examples Input 15 3 cccaabababaccbc Output cccbbabaccbc Input 15 9 cccaabababaccbc Output cccccc Input 1 1 u Output Submitted Solution: ``` n, k = map(int, input().split()) s = list(input()) # count = Counter(s) update = dict() while k>0: for i in range(26): c = chr(i+97) count = s.count(c) if count < k: update[c] = count k -= count else: update[c] = k k = 0 break # print(update) updated_str = [] for i in s: if i in update and update[i]>0: update[i] -= 1 continue else: updated_str.append(i) print(''.join(updated_str)) ```
instruction
0
95,848
24
191,696
Yes
output
1
95,848
24
191,697
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s consisting of n lowercase Latin letters. Polycarp wants to remove exactly k characters (k ≀ n) from the string s. Polycarp uses the following algorithm k times: * if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; * if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; * ... * remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly k times, thus removing exactly k characters. Help Polycarp find the resulting string. Input The first line of input contains two integers n and k (1 ≀ k ≀ n ≀ 4 β‹… 10^5) β€” the length of the string and the number of letters Polycarp will remove. The second line contains the string s consisting of n lowercase Latin letters. Output Print the string that will be obtained from s after Polycarp removes exactly k letters using the above algorithm k times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). Examples Input 15 3 cccaabababaccbc Output cccbbabaccbc Input 15 9 cccaabababaccbc Output cccccc Input 1 1 u Output Submitted Solution: ``` from collections import defaultdict n , k = [int(x) for x in input().split()] s = input() removed = set() l = defaultdict(list) for ind,i in enumerate(s) : l[i].append(ind) if k >= n : pass else : while k > 0 : for char in sorted(l.keys()) : if k >= len(l[char]) : for ind in l[char] : removed.add(ind) k -= len(l[char]) if k == 0 : break else : for ind in l[char][:k] : removed.add(ind) k = 0 break for ind,i in enumerate(s) : if ind not in removed : print(i , end = '') ```
instruction
0
95,849
24
191,698
Yes
output
1
95,849
24
191,699
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s consisting of n lowercase Latin letters. Polycarp wants to remove exactly k characters (k ≀ n) from the string s. Polycarp uses the following algorithm k times: * if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; * if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; * ... * remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly k times, thus removing exactly k characters. Help Polycarp find the resulting string. Input The first line of input contains two integers n and k (1 ≀ k ≀ n ≀ 4 β‹… 10^5) β€” the length of the string and the number of letters Polycarp will remove. The second line contains the string s consisting of n lowercase Latin letters. Output Print the string that will be obtained from s after Polycarp removes exactly k letters using the above algorithm k times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). Examples Input 15 3 cccaabababaccbc Output cccbbabaccbc Input 15 9 cccaabababaccbc Output cccccc Input 1 1 u Output Submitted Solution: ``` [n,k] = list(map(int,input().split(" "))) s = input() list_s = list(s) #print(list_s) y = [i for i in range(len(list_s))] zipped = list(zip(list_s,y)) #print(zipped) zipped.sort(key = lambda t: t[0]) #print('after',zipped) result = list("*"*n) #print(zipped[0][0],zipped[0][1]) for i in range(k,len(zipped)): result[zipped[i][1]] = zipped[i][0] #print('result',result) final = "" for c in result: if c != '*': final += c print(final) ```
instruction
0
95,850
24
191,700
Yes
output
1
95,850
24
191,701
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a string s consisting of n lowercase Latin letters. Polycarp wants to remove exactly k characters (k ≀ n) from the string s. Polycarp uses the following algorithm k times: * if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; * if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; * ... * remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly k times, thus removing exactly k characters. Help Polycarp find the resulting string. Input The first line of input contains two integers n and k (1 ≀ k ≀ n ≀ 4 β‹… 10^5) β€” the length of the string and the number of letters Polycarp will remove. The second line contains the string s consisting of n lowercase Latin letters. Output Print the string that will be obtained from s after Polycarp removes exactly k letters using the above algorithm k times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). Examples Input 15 3 cccaabababaccbc Output cccbbabaccbc Input 15 9 cccaabababaccbc Output cccccc Input 1 1 u Output Submitted Solution: ``` number_of_testcases = 1 #int(input()) for _ in range(number_of_testcases): len_of_given_str, num_of_letters_to_be_removed = map(int, input().split()) given_str = input() freq_of_alpha = [0 for i in range(26)] for char in given_str: freq_of_alpha[ord(char)-97] += 1 #print(freq_of_alpha) for i in range(26): if freq_of_alpha[i] >= num_of_letters_to_be_removed: freq_of_alpha[i] -= num_of_letters_to_be_removed break else: num_of_letters_to_be_removed -= freq_of_alpha[i] #print(freq_of_alpha) resulting_str = [] for char in range(len_of_given_str-1, -1, -1): char = given_str[char] if freq_of_alpha[ord(char) - 97]: resulting_str.append(char) freq_of_alpha[ord(char) - 97] -= 1 #print(freq_of_alpha) # print(resulting_str) resulting_str.reverse() print("".join(resulting_str)) ```
instruction
0
95,851
24
191,702
No
output
1
95,851
24
191,703
Provide tags and a correct Python 3 solution for this coding contest problem. The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well. So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry. Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another. For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the n-th daughter. For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3], [1, 2], [3, 4], [3], respectively. <image> In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of kingdom 3, leaving daughter 4 nobody to marry to. Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list. Polycarp LXXXIV wants to increase the number of married couples. Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. For your and our convenience you are asked to answer t independent test cases. Input The first line contains a single integer t (1 ≀ t ≀ 10^5) β€” the number of test cases. Then t test cases follow. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of daughters and the number of kingdoms. Each of the next n lines contains the description of each daughter's list. The first integer k (0 ≀ k ≀ n) is the number of entries in the i-th daughter's list. After that k distinct integers follow g_i[1], g_i[2], ..., g_i[k] (1 ≀ g_i[j] ≀ n) β€” the indices of the kingdoms in the list in the increasing order (g_i[1] < g_i[2] < ... < g_i[k]). It's guaranteed that the total number of daughters over all test cases does not exceed 10^5. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 10^5. Output For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β€” the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". Example Input 5 4 2 2 3 2 1 2 2 3 4 1 3 2 0 0 3 3 1 2 3 3 1 2 3 3 1 2 3 1 1 1 4 1 1 1 2 1 3 1 4 Output IMPROVE 4 4 IMPROVE 1 1 OPTIMAL OPTIMAL OPTIMAL Note The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom. In the second test case any new entry will increase the number of marriages from 0 to 1. In the third and the fourth test cases there is no way to add an entry. In the fifth test case there is no way to change the marriages by adding any entry.
instruction
0
97,117
24
194,234
Tags: brute force, graphs, greedy Correct Solution: ``` def main(): for _ in range(int(input())): n=int(input()) visited=[False]*n q=[list(map(int,input().split())) for i in range(n)] t1,x=0,0 for i in range(n): t=-1 if(len(q[i])>1): t=min(q[i][1:],key=lambda x: n+1 if(visited[x-1]) else x) elif(t1==0 and x==0): t1=-1 x=i if(t!=-1 and not visited[t-1]): visited[t-1]=True elif(t1==0 and x==0): t1=-1 x=i if(t1==-1): print("IMPROVE") print(x+1,visited.index(False)+1) else: print("OPTIMAL") main() ```
output
1
97,117
24
194,235
Provide tags and a correct Python 3 solution for this coding contest problem. The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well. So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry. Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another. For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the n-th daughter. For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3], [1, 2], [3, 4], [3], respectively. <image> In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of kingdom 3, leaving daughter 4 nobody to marry to. Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list. Polycarp LXXXIV wants to increase the number of married couples. Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. For your and our convenience you are asked to answer t independent test cases. Input The first line contains a single integer t (1 ≀ t ≀ 10^5) β€” the number of test cases. Then t test cases follow. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of daughters and the number of kingdoms. Each of the next n lines contains the description of each daughter's list. The first integer k (0 ≀ k ≀ n) is the number of entries in the i-th daughter's list. After that k distinct integers follow g_i[1], g_i[2], ..., g_i[k] (1 ≀ g_i[j] ≀ n) β€” the indices of the kingdoms in the list in the increasing order (g_i[1] < g_i[2] < ... < g_i[k]). It's guaranteed that the total number of daughters over all test cases does not exceed 10^5. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 10^5. Output For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β€” the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". Example Input 5 4 2 2 3 2 1 2 2 3 4 1 3 2 0 0 3 3 1 2 3 3 1 2 3 3 1 2 3 1 1 1 4 1 1 1 2 1 3 1 4 Output IMPROVE 4 4 IMPROVE 1 1 OPTIMAL OPTIMAL OPTIMAL Note The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom. In the second test case any new entry will increase the number of marriages from 0 to 1. In the third and the fourth test cases there is no way to add an entry. In the fifth test case there is no way to change the marriages by adding any entry.
instruction
0
97,118
24
194,236
Tags: brute force, graphs, greedy Correct Solution: ``` input = __import__('sys').stdin.readline print = __import__('sys').stdout.write for _ in range(int(input())): n = int(input()) prince = set(range(1, n+1)) princess = set(range(1, n+1)) princess_list = [[] for _ in range(n+1)] for i in range(n): k = list(map(int, input().split()))[1:] princess_list[i+1] = k if k: for j in k: if j in prince: prince.remove(j) princess.remove(i+1) break # print(str(princess) + '\n') # print(str(prince) + '\n') # print(str(princess_list) +'\n') # exit()Y tmp = False for pr1 in princess: for pr2 in prince: if pr2 in princess_list[pr1]: continue else: print (f'IMPROVE\n') print (f'{pr1} {pr2}\n') tmp = True break if tmp: break else: print ('OPTIMAL\n') ```
output
1
97,118
24
194,237
Provide tags and a correct Python 3 solution for this coding contest problem. The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well. So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry. Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another. For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the n-th daughter. For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3], [1, 2], [3, 4], [3], respectively. <image> In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of kingdom 3, leaving daughter 4 nobody to marry to. Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list. Polycarp LXXXIV wants to increase the number of married couples. Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. For your and our convenience you are asked to answer t independent test cases. Input The first line contains a single integer t (1 ≀ t ≀ 10^5) β€” the number of test cases. Then t test cases follow. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of daughters and the number of kingdoms. Each of the next n lines contains the description of each daughter's list. The first integer k (0 ≀ k ≀ n) is the number of entries in the i-th daughter's list. After that k distinct integers follow g_i[1], g_i[2], ..., g_i[k] (1 ≀ g_i[j] ≀ n) β€” the indices of the kingdoms in the list in the increasing order (g_i[1] < g_i[2] < ... < g_i[k]). It's guaranteed that the total number of daughters over all test cases does not exceed 10^5. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 10^5. Output For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β€” the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". Example Input 5 4 2 2 3 2 1 2 2 3 4 1 3 2 0 0 3 3 1 2 3 3 1 2 3 3 1 2 3 1 1 1 4 1 1 1 2 1 3 1 4 Output IMPROVE 4 4 IMPROVE 1 1 OPTIMAL OPTIMAL OPTIMAL Note The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom. In the second test case any new entry will increase the number of marriages from 0 to 1. In the third and the fourth test cases there is no way to add an entry. In the fifth test case there is no way to change the marriages by adding any entry.
instruction
0
97,119
24
194,238
Tags: brute force, graphs, greedy Correct Solution: ``` t = int(input()) for _ in range(t): n = int(input()) # daughters = [False for _ in range(n+1)] # boys = [False for _ in range(n+1)] boys = [False]*(n+1) dul = -1 boys[0] = True chk = True for i in range(n): x = list(map(int, input().split())) for j in range(1, x[0]+1): if boys[x[j]]==False: boys[x[j]]=True break else: if chk==True: dul = i+1 chk = False if dul!=-1: print("IMPROVE") print(dul, boys.index(False)) else: print("OPTIMAL") # print(boys) # lst = [list(map(int, input().split())) for _ in range(n)] ```
output
1
97,119
24
194,239
Provide tags and a correct Python 3 solution for this coding contest problem. The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well. So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry. Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another. For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the n-th daughter. For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3], [1, 2], [3, 4], [3], respectively. <image> In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of kingdom 3, leaving daughter 4 nobody to marry to. Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list. Polycarp LXXXIV wants to increase the number of married couples. Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. For your and our convenience you are asked to answer t independent test cases. Input The first line contains a single integer t (1 ≀ t ≀ 10^5) β€” the number of test cases. Then t test cases follow. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of daughters and the number of kingdoms. Each of the next n lines contains the description of each daughter's list. The first integer k (0 ≀ k ≀ n) is the number of entries in the i-th daughter's list. After that k distinct integers follow g_i[1], g_i[2], ..., g_i[k] (1 ≀ g_i[j] ≀ n) β€” the indices of the kingdoms in the list in the increasing order (g_i[1] < g_i[2] < ... < g_i[k]). It's guaranteed that the total number of daughters over all test cases does not exceed 10^5. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 10^5. Output For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β€” the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". Example Input 5 4 2 2 3 2 1 2 2 3 4 1 3 2 0 0 3 3 1 2 3 3 1 2 3 3 1 2 3 1 1 1 4 1 1 1 2 1 3 1 4 Output IMPROVE 4 4 IMPROVE 1 1 OPTIMAL OPTIMAL OPTIMAL Note The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom. In the second test case any new entry will increase the number of marriages from 0 to 1. In the third and the fourth test cases there is no way to add an entry. In the fifth test case there is no way to change the marriages by adding any entry.
instruction
0
97,120
24
194,240
Tags: brute force, graphs, greedy Correct Solution: ``` for _ in range(int(input())): n = int(input()) dc ={} for i in range(1,n+1): dc[i] = [] prc = [False for i in range(n+1)] pcc = [False for i in range(n+1)] b = [] for i in range(1,n+1): x = [int(o) for o in input().split()] dc[i] = x[1:] count = 0 for i in range(1,n+1): if len(dc[i]) is 0: continue else: temp = dc[i] for boy in temp: if prc[boy] is False: pcc[i] = True prc[boy] = True count += 1 break if count == n: print("OPTIMAL") else: flag = 0 for girl in range(1,n+1): if pcc[girl] is False: for boy in range(1,n+1): if prc[boy] is False and len(dc[girl]) is 0: flag = 1 print("IMPROVE") print(girl,boy) break elif prc[boy] is False and boy not in dc[girl]: flag = 1 print("IMPROVE") print(girl,boy) break if flag is 1: break if flag is 0: print("OPTIMAL") ```
output
1
97,120
24
194,241
Provide tags and a correct Python 3 solution for this coding contest problem. The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well. So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry. Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another. For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the n-th daughter. For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3], [1, 2], [3, 4], [3], respectively. <image> In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of kingdom 3, leaving daughter 4 nobody to marry to. Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list. Polycarp LXXXIV wants to increase the number of married couples. Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. For your and our convenience you are asked to answer t independent test cases. Input The first line contains a single integer t (1 ≀ t ≀ 10^5) β€” the number of test cases. Then t test cases follow. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of daughters and the number of kingdoms. Each of the next n lines contains the description of each daughter's list. The first integer k (0 ≀ k ≀ n) is the number of entries in the i-th daughter's list. After that k distinct integers follow g_i[1], g_i[2], ..., g_i[k] (1 ≀ g_i[j] ≀ n) β€” the indices of the kingdoms in the list in the increasing order (g_i[1] < g_i[2] < ... < g_i[k]). It's guaranteed that the total number of daughters over all test cases does not exceed 10^5. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 10^5. Output For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β€” the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". Example Input 5 4 2 2 3 2 1 2 2 3 4 1 3 2 0 0 3 3 1 2 3 3 1 2 3 3 1 2 3 1 1 1 4 1 1 1 2 1 3 1 4 Output IMPROVE 4 4 IMPROVE 1 1 OPTIMAL OPTIMAL OPTIMAL Note The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom. In the second test case any new entry will increase the number of marriages from 0 to 1. In the third and the fourth test cases there is no way to add an entry. In the fifth test case there is no way to change the marriages by adding any entry.
instruction
0
97,121
24
194,242
Tags: brute force, graphs, greedy Correct Solution: ``` t = int(input()) for _ in range(t): n = int(input()) used = [False for i in range(n)] v = -1 for i in range(n): l = [int(x) - 1 for x in input().split()][1:] for j in l: if not used[j]: used[j] = True break else: v = i if v == -1: print("OPTIMAL") else: u = used.index(False) print("IMPROVE") print((v + 1) ,(u + 1)) ```
output
1
97,121
24
194,243
Provide tags and a correct Python 3 solution for this coding contest problem. The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well. So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry. Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another. For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the n-th daughter. For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3], [1, 2], [3, 4], [3], respectively. <image> In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of kingdom 3, leaving daughter 4 nobody to marry to. Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list. Polycarp LXXXIV wants to increase the number of married couples. Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. For your and our convenience you are asked to answer t independent test cases. Input The first line contains a single integer t (1 ≀ t ≀ 10^5) β€” the number of test cases. Then t test cases follow. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of daughters and the number of kingdoms. Each of the next n lines contains the description of each daughter's list. The first integer k (0 ≀ k ≀ n) is the number of entries in the i-th daughter's list. After that k distinct integers follow g_i[1], g_i[2], ..., g_i[k] (1 ≀ g_i[j] ≀ n) β€” the indices of the kingdoms in the list in the increasing order (g_i[1] < g_i[2] < ... < g_i[k]). It's guaranteed that the total number of daughters over all test cases does not exceed 10^5. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 10^5. Output For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β€” the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". Example Input 5 4 2 2 3 2 1 2 2 3 4 1 3 2 0 0 3 3 1 2 3 3 1 2 3 3 1 2 3 1 1 1 4 1 1 1 2 1 3 1 4 Output IMPROVE 4 4 IMPROVE 1 1 OPTIMAL OPTIMAL OPTIMAL Note The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom. In the second test case any new entry will increase the number of marriages from 0 to 1. In the third and the fourth test cases there is no way to add an entry. In the fifth test case there is no way to change the marriages by adding any entry.
instruction
0
97,122
24
194,244
Tags: brute force, graphs, greedy Correct Solution: ``` def main(): n = int(input()) prince = set() princes = set() for i in range(1, n + 1): prince.add(i) to_change = -1 for i in range(n): lst = list(map(int, input().split())) have = False for k in lst[1:]: if k in prince: have = True prince.remove(k) princes.add(i) break if not have: to_change = i if to_change == -1: print("OPTIMAL") return print("IMPROVE") print(to_change + 1, min(prince)) if __name__ == "__main__": t = int(input()) for i in range(t): main() ```
output
1
97,122
24
194,245
Provide tags and a correct Python 3 solution for this coding contest problem. The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well. So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry. Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another. For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the n-th daughter. For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3], [1, 2], [3, 4], [3], respectively. <image> In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of kingdom 3, leaving daughter 4 nobody to marry to. Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list. Polycarp LXXXIV wants to increase the number of married couples. Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. For your and our convenience you are asked to answer t independent test cases. Input The first line contains a single integer t (1 ≀ t ≀ 10^5) β€” the number of test cases. Then t test cases follow. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of daughters and the number of kingdoms. Each of the next n lines contains the description of each daughter's list. The first integer k (0 ≀ k ≀ n) is the number of entries in the i-th daughter's list. After that k distinct integers follow g_i[1], g_i[2], ..., g_i[k] (1 ≀ g_i[j] ≀ n) β€” the indices of the kingdoms in the list in the increasing order (g_i[1] < g_i[2] < ... < g_i[k]). It's guaranteed that the total number of daughters over all test cases does not exceed 10^5. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 10^5. Output For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β€” the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". Example Input 5 4 2 2 3 2 1 2 2 3 4 1 3 2 0 0 3 3 1 2 3 3 1 2 3 3 1 2 3 1 1 1 4 1 1 1 2 1 3 1 4 Output IMPROVE 4 4 IMPROVE 1 1 OPTIMAL OPTIMAL OPTIMAL Note The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom. In the second test case any new entry will increase the number of marriages from 0 to 1. In the third and the fourth test cases there is no way to add an entry. In the fifth test case there is no way to change the marriages by adding any entry.
instruction
0
97,123
24
194,246
Tags: brute force, graphs, greedy Correct Solution: ``` t=int(input()) for _ in range(t): n=int(input()) l1=[False]*n l2=[False]*n for i in range(n): l=list(map(int,input().split()))[1:] for j in l: if not l2[j-1]: l1[i]=True l2[j-1]=True break f1=0 f2=0 s=" " for i in range(n): if f1==0 and not l1[i]: f1=1 s=str(i+1)+s if f2==0 and not l2[i]: f2=1 s=s+str(i+1) if f1==1 and f2==1: break if f1==1 and f2==1: print("IMPROVE") print(s) else: print("OPTIMAL") ```
output
1
97,123
24
194,247
Provide tags and a correct Python 3 solution for this coding contest problem. The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well. So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry. Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another. For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the n-th daughter. For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3], [1, 2], [3, 4], [3], respectively. <image> In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of kingdom 3, leaving daughter 4 nobody to marry to. Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list. Polycarp LXXXIV wants to increase the number of married couples. Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. For your and our convenience you are asked to answer t independent test cases. Input The first line contains a single integer t (1 ≀ t ≀ 10^5) β€” the number of test cases. Then t test cases follow. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of daughters and the number of kingdoms. Each of the next n lines contains the description of each daughter's list. The first integer k (0 ≀ k ≀ n) is the number of entries in the i-th daughter's list. After that k distinct integers follow g_i[1], g_i[2], ..., g_i[k] (1 ≀ g_i[j] ≀ n) β€” the indices of the kingdoms in the list in the increasing order (g_i[1] < g_i[2] < ... < g_i[k]). It's guaranteed that the total number of daughters over all test cases does not exceed 10^5. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 10^5. Output For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β€” the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". Example Input 5 4 2 2 3 2 1 2 2 3 4 1 3 2 0 0 3 3 1 2 3 3 1 2 3 3 1 2 3 1 1 1 4 1 1 1 2 1 3 1 4 Output IMPROVE 4 4 IMPROVE 1 1 OPTIMAL OPTIMAL OPTIMAL Note The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom. In the second test case any new entry will increase the number of marriages from 0 to 1. In the third and the fourth test cases there is no way to add an entry. In the fifth test case there is no way to change the marriages by adding any entry.
instruction
0
97,124
24
194,248
Tags: brute force, graphs, greedy Correct Solution: ``` import sys input=sys.stdin.readline from math import * t=int(input()) while t>0: t-=1 n=int(input()) f=[0 for i in range(n+1)] l=[] flag=0 for i in range(n): a=[int(x) for x in input().split()] a=a[1:] a.sort() p=0 for j in range(len(a)): if f[a[j]]==0: f[a[j]]=1 p=1 break #print(f,p) if p==0: l.append(i) #print(f) if f[1:].count(0)>=1 and len(l)>0: print("IMPROVE") print(l[0]+1,f[1:].index(0)+1) else: print("OPTIMAL") ```
output
1
97,124
24
194,249
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well. So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry. Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another. For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the n-th daughter. For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3], [1, 2], [3, 4], [3], respectively. <image> In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of kingdom 3, leaving daughter 4 nobody to marry to. Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list. Polycarp LXXXIV wants to increase the number of married couples. Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. For your and our convenience you are asked to answer t independent test cases. Input The first line contains a single integer t (1 ≀ t ≀ 10^5) β€” the number of test cases. Then t test cases follow. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of daughters and the number of kingdoms. Each of the next n lines contains the description of each daughter's list. The first integer k (0 ≀ k ≀ n) is the number of entries in the i-th daughter's list. After that k distinct integers follow g_i[1], g_i[2], ..., g_i[k] (1 ≀ g_i[j] ≀ n) β€” the indices of the kingdoms in the list in the increasing order (g_i[1] < g_i[2] < ... < g_i[k]). It's guaranteed that the total number of daughters over all test cases does not exceed 10^5. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 10^5. Output For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β€” the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". Example Input 5 4 2 2 3 2 1 2 2 3 4 1 3 2 0 0 3 3 1 2 3 3 1 2 3 3 1 2 3 1 1 1 4 1 1 1 2 1 3 1 4 Output IMPROVE 4 4 IMPROVE 1 1 OPTIMAL OPTIMAL OPTIMAL Note The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom. In the second test case any new entry will increase the number of marriages from 0 to 1. In the third and the fourth test cases there is no way to add an entry. In the fifth test case there is no way to change the marriages by adding any entry. Submitted Solution: ``` import bisect import os import io from collections import Counter from collections import defaultdict import math import random import heapq as hq from math import sqrt import sys from functools import reduce from collections import deque import threading # sys.setrecursionlimit(2000000) # input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def tinput(): return input().split() def rinput(): return map(int, tinput()) def rlinput(): return list(rinput()) mod = int(1e9)+7 def factors(n): return set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))) # ---------------------------------------------------- # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') for _ in range(iinput()): n = iinput() val = [] for i in range(n): a = rlinput() a.pop(0) val.append(a) ans1 = -1 visited = [False]*(n+1) for i in range(n): flag = False for j in val[i]: if not visited[j]: visited[j] = True flag = True break if not flag: ans1 = i+1 if ans1 == -1: print('OPTIMAL') else: print('IMPROVE') ans2 = -1 for i in range(1, n+1): if not visited[i]: ans2 = i break print(ans1, ans2) ```
instruction
0
97,125
24
194,250
Yes
output
1
97,125
24
194,251
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well. So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry. Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another. For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the n-th daughter. For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3], [1, 2], [3, 4], [3], respectively. <image> In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of kingdom 3, leaving daughter 4 nobody to marry to. Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list. Polycarp LXXXIV wants to increase the number of married couples. Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. For your and our convenience you are asked to answer t independent test cases. Input The first line contains a single integer t (1 ≀ t ≀ 10^5) β€” the number of test cases. Then t test cases follow. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of daughters and the number of kingdoms. Each of the next n lines contains the description of each daughter's list. The first integer k (0 ≀ k ≀ n) is the number of entries in the i-th daughter's list. After that k distinct integers follow g_i[1], g_i[2], ..., g_i[k] (1 ≀ g_i[j] ≀ n) β€” the indices of the kingdoms in the list in the increasing order (g_i[1] < g_i[2] < ... < g_i[k]). It's guaranteed that the total number of daughters over all test cases does not exceed 10^5. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 10^5. Output For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β€” the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". Example Input 5 4 2 2 3 2 1 2 2 3 4 1 3 2 0 0 3 3 1 2 3 3 1 2 3 3 1 2 3 1 1 1 4 1 1 1 2 1 3 1 4 Output IMPROVE 4 4 IMPROVE 1 1 OPTIMAL OPTIMAL OPTIMAL Note The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom. In the second test case any new entry will increase the number of marriages from 0 to 1. In the third and the fourth test cases there is no way to add an entry. In the fifth test case there is no way to change the marriages by adding any entry. Submitted Solution: ``` t=int(input()) for i in range(t): n=int(input()) arr = [] for j in range(n): a1= input().split(" ") arr.append([]) for c in range(len(a1)): arr[j].append(int(a1[c])) done = set() remain = [] count=0 for k in range(len(arr)): p = arr[k] flag=0 for q in range(1,len(p)): if(p[q] not in done): done.add(p[q]) flag=1 count+=1 break if(flag==0): p.append(k) remain.append(p) if(count==n): print("OPTIMAL") continue prince = list(done) prince.sort() num = -1 for w in range(len(prince)-1): if(prince[w]!=prince[w+1]-1): num = prince[w]+1 break if(num==-1): if(len(prince)>0 and prince[0]>=2): num = 1 else: num = len(prince)+1 add = -1 for z in range(len(remain)): element = remain[z] if(num not in element[1:len(element)-1]): add = element[len(element)-1] break print("IMPROVE") print(str(add+1),num) ```
instruction
0
97,126
24
194,252
Yes
output
1
97,126
24
194,253
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well. So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry. Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another. For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the n-th daughter. For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3], [1, 2], [3, 4], [3], respectively. <image> In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of kingdom 3, leaving daughter 4 nobody to marry to. Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list. Polycarp LXXXIV wants to increase the number of married couples. Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. For your and our convenience you are asked to answer t independent test cases. Input The first line contains a single integer t (1 ≀ t ≀ 10^5) β€” the number of test cases. Then t test cases follow. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of daughters and the number of kingdoms. Each of the next n lines contains the description of each daughter's list. The first integer k (0 ≀ k ≀ n) is the number of entries in the i-th daughter's list. After that k distinct integers follow g_i[1], g_i[2], ..., g_i[k] (1 ≀ g_i[j] ≀ n) β€” the indices of the kingdoms in the list in the increasing order (g_i[1] < g_i[2] < ... < g_i[k]). It's guaranteed that the total number of daughters over all test cases does not exceed 10^5. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 10^5. Output For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β€” the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". Example Input 5 4 2 2 3 2 1 2 2 3 4 1 3 2 0 0 3 3 1 2 3 3 1 2 3 3 1 2 3 1 1 1 4 1 1 1 2 1 3 1 4 Output IMPROVE 4 4 IMPROVE 1 1 OPTIMAL OPTIMAL OPTIMAL Note The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom. In the second test case any new entry will increase the number of marriages from 0 to 1. In the third and the fourth test cases there is no way to add an entry. In the fifth test case there is no way to change the marriages by adding any entry. Submitted Solution: ``` t = int(input()) for j in range(t): n = int(input()) taken_prince = [False for i in range(n)] taken_princess = [False for i in range(n)] for x in range(n): wanted_prince_list = list(map(int, input().split())) for i in wanted_prince_list[1:]: if taken_prince[i-1] == False: taken_prince[i-1] = True taken_princess[x] = True break toprint = "OPTIMAL" for i in range(n): if taken_princess[i]==False: u = taken_prince.index(False) toprint = 'IMPROVE\n' + str(i+1) + ' ' + str(u+1) break print(toprint) ```
instruction
0
97,127
24
194,254
Yes
output
1
97,127
24
194,255
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well. So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry. Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another. For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the n-th daughter. For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3], [1, 2], [3, 4], [3], respectively. <image> In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of kingdom 3, leaving daughter 4 nobody to marry to. Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list. Polycarp LXXXIV wants to increase the number of married couples. Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. For your and our convenience you are asked to answer t independent test cases. Input The first line contains a single integer t (1 ≀ t ≀ 10^5) β€” the number of test cases. Then t test cases follow. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of daughters and the number of kingdoms. Each of the next n lines contains the description of each daughter's list. The first integer k (0 ≀ k ≀ n) is the number of entries in the i-th daughter's list. After that k distinct integers follow g_i[1], g_i[2], ..., g_i[k] (1 ≀ g_i[j] ≀ n) β€” the indices of the kingdoms in the list in the increasing order (g_i[1] < g_i[2] < ... < g_i[k]). It's guaranteed that the total number of daughters over all test cases does not exceed 10^5. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 10^5. Output For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β€” the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". Example Input 5 4 2 2 3 2 1 2 2 3 4 1 3 2 0 0 3 3 1 2 3 3 1 2 3 3 1 2 3 1 1 1 4 1 1 1 2 1 3 1 4 Output IMPROVE 4 4 IMPROVE 1 1 OPTIMAL OPTIMAL OPTIMAL Note The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom. In the second test case any new entry will increase the number of marriages from 0 to 1. In the third and the fourth test cases there is no way to add an entry. In the fifth test case there is no way to change the marriages by adding any entry. Submitted Solution: ``` for _ in range(int(input())): n=int(input()) dic={};m={};boo=True;ans=0 for i in range(n): a=[int(j) for j in input().split()] boo=True for j in a[1:]: if(j not in m.keys()): m[j]=i+1 boo=False break if(boo): ans=i+1 ans2=list(set(x for x in range(1,n+1))-set(m.keys())) if(len(ans2)==0): print('OPTIMAL') else: print('IMPROVE') print(ans,ans2[0]) ```
instruction
0
97,128
24
194,256
Yes
output
1
97,128
24
194,257
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well. So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry. Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another. For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the n-th daughter. For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3], [1, 2], [3, 4], [3], respectively. <image> In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of kingdom 3, leaving daughter 4 nobody to marry to. Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list. Polycarp LXXXIV wants to increase the number of married couples. Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. For your and our convenience you are asked to answer t independent test cases. Input The first line contains a single integer t (1 ≀ t ≀ 10^5) β€” the number of test cases. Then t test cases follow. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of daughters and the number of kingdoms. Each of the next n lines contains the description of each daughter's list. The first integer k (0 ≀ k ≀ n) is the number of entries in the i-th daughter's list. After that k distinct integers follow g_i[1], g_i[2], ..., g_i[k] (1 ≀ g_i[j] ≀ n) β€” the indices of the kingdoms in the list in the increasing order (g_i[1] < g_i[2] < ... < g_i[k]). It's guaranteed that the total number of daughters over all test cases does not exceed 10^5. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 10^5. Output For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β€” the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". Example Input 5 4 2 2 3 2 1 2 2 3 4 1 3 2 0 0 3 3 1 2 3 3 1 2 3 3 1 2 3 1 1 1 4 1 1 1 2 1 3 1 4 Output IMPROVE 4 4 IMPROVE 1 1 OPTIMAL OPTIMAL OPTIMAL Note The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom. In the second test case any new entry will increase the number of marriages from 0 to 1. In the third and the fourth test cases there is no way to add an entry. In the fifth test case there is no way to change the marriages by adding any entry. Submitted Solution: ``` for _ in range(int(input())): dlst = [] n = int(input()) prince = set(range(1, 1+n)) notf = None for i in range(1, n+1): dlst.append([int(x) for x in input().split()]) for val in dlst[-1]: if val in prince: prince.remove(val) break else: notf = i if len(prince) == 0: ans = "OPTIMAL" else: ans = "IMPROVE\n" ans += str(notf) + ' ' + str(prince.pop()) print(ans) ```
instruction
0
97,129
24
194,258
No
output
1
97,129
24
194,259
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well. So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry. Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another. For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the n-th daughter. For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3], [1, 2], [3, 4], [3], respectively. <image> In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of kingdom 3, leaving daughter 4 nobody to marry to. Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list. Polycarp LXXXIV wants to increase the number of married couples. Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. For your and our convenience you are asked to answer t independent test cases. Input The first line contains a single integer t (1 ≀ t ≀ 10^5) β€” the number of test cases. Then t test cases follow. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of daughters and the number of kingdoms. Each of the next n lines contains the description of each daughter's list. The first integer k (0 ≀ k ≀ n) is the number of entries in the i-th daughter's list. After that k distinct integers follow g_i[1], g_i[2], ..., g_i[k] (1 ≀ g_i[j] ≀ n) β€” the indices of the kingdoms in the list in the increasing order (g_i[1] < g_i[2] < ... < g_i[k]). It's guaranteed that the total number of daughters over all test cases does not exceed 10^5. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 10^5. Output For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β€” the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". Example Input 5 4 2 2 3 2 1 2 2 3 4 1 3 2 0 0 3 3 1 2 3 3 1 2 3 3 1 2 3 1 1 1 4 1 1 1 2 1 3 1 4 Output IMPROVE 4 4 IMPROVE 1 1 OPTIMAL OPTIMAL OPTIMAL Note The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom. In the second test case any new entry will increase the number of marriages from 0 to 1. In the third and the fourth test cases there is no way to add an entry. In the fifth test case there is no way to change the marriages by adding any entry. Submitted Solution: ``` import sys for _ in range(int(sys.stdin.readline())): a=[] b=int(sys.stdin.readline()) d=0 for i in range(b): c=sys.stdin.readline() if len(c)==1: a.append(list()) else: a.append(list(map(int,c.split()))) c=[i for i in range(1,b+1)] for i in range(b): for k in range(1,a[i][0]+1): if a[i][k] in c: c.remove(a[i][k]) break elif k == a[i][0]: d=i if len(c)==0: sys.stdout.write('OPTIMAL\n') else: sys.stdout.write('IMPROVE\n') sys.stdout.write('{} {}\n'.format(d+1,c[0])) ```
instruction
0
97,130
24
194,260
No
output
1
97,130
24
194,261
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well. So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry. Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another. For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the n-th daughter. For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3], [1, 2], [3, 4], [3], respectively. <image> In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of kingdom 3, leaving daughter 4 nobody to marry to. Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list. Polycarp LXXXIV wants to increase the number of married couples. Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. For your and our convenience you are asked to answer t independent test cases. Input The first line contains a single integer t (1 ≀ t ≀ 10^5) β€” the number of test cases. Then t test cases follow. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of daughters and the number of kingdoms. Each of the next n lines contains the description of each daughter's list. The first integer k (0 ≀ k ≀ n) is the number of entries in the i-th daughter's list. After that k distinct integers follow g_i[1], g_i[2], ..., g_i[k] (1 ≀ g_i[j] ≀ n) β€” the indices of the kingdoms in the list in the increasing order (g_i[1] < g_i[2] < ... < g_i[k]). It's guaranteed that the total number of daughters over all test cases does not exceed 10^5. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 10^5. Output For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β€” the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". Example Input 5 4 2 2 3 2 1 2 2 3 4 1 3 2 0 0 3 3 1 2 3 3 1 2 3 3 1 2 3 1 1 1 4 1 1 1 2 1 3 1 4 Output IMPROVE 4 4 IMPROVE 1 1 OPTIMAL OPTIMAL OPTIMAL Note The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom. In the second test case any new entry will increase the number of marriages from 0 to 1. In the third and the fourth test cases there is no way to add an entry. In the fifth test case there is no way to change the marriages by adding any entry. Submitted Solution: ``` t = int(input()) for i in range(t): n = int(input()) pr = [0 for j in range(n+1)] dr = [0 for j in range(n+1)] if_good = 0 for j in range(1, n+1): if_good = 0 flag = 0 dr[j] = list(map(int, input().split())) if dr[j][0] == 0: print(dr) print('IMPROVE') for p in range(1, n+1): if pr[p]==0: print(j, p) flag = 1 break if flag == 1: break else: for p in dr[j][1:]: if pr[p]==0: pr[p]=1 flag = 1 if_good = 1 break if (flag == 0): for p in range(1, n+1): if pr[p]==0: print('IMPROVE') print(j, p) flag = 1 break if if_good== 1: print('OPTIMAL') ```
instruction
0
97,131
24
194,262
No
output
1
97,131
24
194,263
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The King of Berland Polycarp LXXXIV has n daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are n other kingdoms as well. So Polycarp LXXXIV has enumerated his daughters from 1 to n and the kingdoms from 1 to n. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry. Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another. For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the n-th daughter. For example, let there be 4 daughters and kingdoms, the lists daughters have are [2, 3], [1, 2], [3, 4], [3], respectively. <image> In that case daughter 1 marries the prince of kingdom 2, daughter 2 marries the prince of kingdom 1, daughter 3 marries the prince of kingdom 3, leaving daughter 4 nobody to marry to. Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list. Polycarp LXXXIV wants to increase the number of married couples. Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. For your and our convenience you are asked to answer t independent test cases. Input The first line contains a single integer t (1 ≀ t ≀ 10^5) β€” the number of test cases. Then t test cases follow. The first line of each test case contains a single integer n (1 ≀ n ≀ 10^5) β€” the number of daughters and the number of kingdoms. Each of the next n lines contains the description of each daughter's list. The first integer k (0 ≀ k ≀ n) is the number of entries in the i-th daughter's list. After that k distinct integers follow g_i[1], g_i[2], ..., g_i[k] (1 ≀ g_i[j] ≀ n) β€” the indices of the kingdoms in the list in the increasing order (g_i[1] < g_i[2] < ... < g_i[k]). It's guaranteed that the total number of daughters over all test cases does not exceed 10^5. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed 10^5. Output For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers β€” the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". Example Input 5 4 2 2 3 2 1 2 2 3 4 1 3 2 0 0 3 3 1 2 3 3 1 2 3 3 1 2 3 1 1 1 4 1 1 1 2 1 3 1 4 Output IMPROVE 4 4 IMPROVE 1 1 OPTIMAL OPTIMAL OPTIMAL Note The first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom. In the second test case any new entry will increase the number of marriages from 0 to 1. In the third and the fourth test cases there is no way to add an entry. In the fifth test case there is no way to change the marriages by adding any entry. Submitted Solution: ``` t=int(input()) while t>0: t-=1 n=int(input()) li=[] for i in range(n): x=map(int,input().split()) li.append(x) a=[] b=[] for i in range(n): for j in li[i]: if j not in a and j!=0: a.append(j) b.append(i+1) break #print(a) #print(b) z=0 for i in range(1,n+1): if i not in b: z=i break for i in range(1,n+1): if i not in a: print('IMPROVE') print(z,i) break elif i==n and i in a: print('OPTIMAL') ```
instruction
0
97,132
24
194,264
No
output
1
97,132
24
194,265
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence ai, will print the minimum number of folders. Input The first line contains integer n (1 ≀ n ≀ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≀ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. Output Print an integer k β€” the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder. If there are multiple ways to sort the reports into k days, print any of them. Examples Input 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Output 3 5 3 3 Input 5 0 -1 100 -1 0 Output 1 5 Note Here goes a way to sort the reports from the first sample into three folders: 1 2 3 -4 -5 | -6 5 -5 | -6 -7 6 In the second sample you can put all five reports in one folder.
instruction
0
97,267
24
194,534
Tags: greedy Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) c,x=0,0 d=[] for i in range(n): if(l[i]<0): c=c+1 x=x+1 if(x==2): d.append(c) x=0 c=0 else: c=c+1 if(d==[]): d.append(c) c=0 if(c>0 and x==0): d[-1]+=c elif(c>0 and x!=0): d.append(c) print(len(d)) print(*d) ```
output
1
97,267
24
194,535