message
stringlengths
2
22.7k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
145
109k
cluster
float64
9
9
__index_level_0__
int64
290
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the n drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink. Input The first input line contains a single integer n (1 ≀ n ≀ 100) β€” the number of orange-containing drinks in Vasya's fridge. The second line contains n integers pi (0 ≀ pi ≀ 100) β€” the volume fraction of orange juice in the i-th drink, in percent. The numbers are separated by a space. Output Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10 - 4. Examples Input 3 50 50 100 Output 66.666666666667 Input 4 0 25 50 75 Output 37.500000000000 Note Note to the first sample: let's assume that Vasya takes x milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <image> milliliters. The total cocktail's volume equals 3Β·x milliliters, so the volume fraction of the juice in the cocktail equals <image>, that is, 66.(6) percent. Submitted Solution: ``` num_of_drinks = input() drinks = [*map(int, input().split())] concentration = sum(drinks) / (100 * len(drinks)) * 100 print(concentration) ```
instruction
0
44,101
9
88,202
Yes
output
1
44,101
9
88,203
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the n drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink. Input The first input line contains a single integer n (1 ≀ n ≀ 100) β€” the number of orange-containing drinks in Vasya's fridge. The second line contains n integers pi (0 ≀ pi ≀ 100) β€” the volume fraction of orange juice in the i-th drink, in percent. The numbers are separated by a space. Output Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10 - 4. Examples Input 3 50 50 100 Output 66.666666666667 Input 4 0 25 50 75 Output 37.500000000000 Note Note to the first sample: let's assume that Vasya takes x milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <image> milliliters. The total cocktail's volume equals 3Β·x milliliters, so the volume fraction of the juice in the cocktail equals <image>, that is, 66.(6) percent. Submitted Solution: ``` n = int(input()) l = list(map(int,input().split())) s = sum(l) print(1/n*(s)) ```
instruction
0
44,102
9
88,204
Yes
output
1
44,102
9
88,205
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the n drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink. Input The first input line contains a single integer n (1 ≀ n ≀ 100) β€” the number of orange-containing drinks in Vasya's fridge. The second line contains n integers pi (0 ≀ pi ≀ 100) β€” the volume fraction of orange juice in the i-th drink, in percent. The numbers are separated by a space. Output Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10 - 4. Examples Input 3 50 50 100 Output 66.666666666667 Input 4 0 25 50 75 Output 37.500000000000 Note Note to the first sample: let's assume that Vasya takes x milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <image> milliliters. The total cocktail's volume equals 3Β·x milliliters, so the volume fraction of the juice in the cocktail equals <image>, that is, 66.(6) percent. Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Fri Aug 7 20:28:41 2020 @author: alber """ x = int(input()) bebidas = list(map(int,input().split())) print(sum(bebidas)/len(bebidas)) ```
instruction
0
44,103
9
88,206
Yes
output
1
44,103
9
88,207
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the n drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink. Input The first input line contains a single integer n (1 ≀ n ≀ 100) β€” the number of orange-containing drinks in Vasya's fridge. The second line contains n integers pi (0 ≀ pi ≀ 100) β€” the volume fraction of orange juice in the i-th drink, in percent. The numbers are separated by a space. Output Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10 - 4. Examples Input 3 50 50 100 Output 66.666666666667 Input 4 0 25 50 75 Output 37.500000000000 Note Note to the first sample: let's assume that Vasya takes x milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <image> milliliters. The total cocktail's volume equals 3Β·x milliliters, so the volume fraction of the juice in the cocktail equals <image>, that is, 66.(6) percent. Submitted Solution: ``` n = input() n = int(n) p = input().split() result = 0.0 for i in p: result+=(2/n)*(int(i)/100) print(result*100) ```
instruction
0
44,104
9
88,208
No
output
1
44,104
9
88,209
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the n drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink. Input The first input line contains a single integer n (1 ≀ n ≀ 100) β€” the number of orange-containing drinks in Vasya's fridge. The second line contains n integers pi (0 ≀ pi ≀ 100) β€” the volume fraction of orange juice in the i-th drink, in percent. The numbers are separated by a space. Output Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10 - 4. Examples Input 3 50 50 100 Output 66.666666666667 Input 4 0 25 50 75 Output 37.500000000000 Note Note to the first sample: let's assume that Vasya takes x milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <image> milliliters. The total cocktail's volume equals 3Β·x milliliters, so the volume fraction of the juice in the cocktail equals <image>, that is, 66.(6) percent. Submitted Solution: ``` n=int(input()) l=list(map(int,input().split(' '))) s=0 for i in range(n): s+=(l[i]/100) d=s/n print(d) ```
instruction
0
44,105
9
88,210
No
output
1
44,105
9
88,211
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the n drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink. Input The first input line contains a single integer n (1 ≀ n ≀ 100) β€” the number of orange-containing drinks in Vasya's fridge. The second line contains n integers pi (0 ≀ pi ≀ 100) β€” the volume fraction of orange juice in the i-th drink, in percent. The numbers are separated by a space. Output Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10 - 4. Examples Input 3 50 50 100 Output 66.666666666667 Input 4 0 25 50 75 Output 37.500000000000 Note Note to the first sample: let's assume that Vasya takes x milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <image> milliliters. The total cocktail's volume equals 3Β·x milliliters, so the volume fraction of the juice in the cocktail equals <image>, that is, 66.(6) percent. Submitted Solution: ``` print(1/(100*int(input())) * sum([int(i) for i in input().split()])) ```
instruction
0
44,106
9
88,212
No
output
1
44,106
9
88,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the n drinks and mixed them. Then he wondered, how much orange juice the cocktail has. Find the volume fraction of orange juice in the final drink. Input The first input line contains a single integer n (1 ≀ n ≀ 100) β€” the number of orange-containing drinks in Vasya's fridge. The second line contains n integers pi (0 ≀ pi ≀ 100) β€” the volume fraction of orange juice in the i-th drink, in percent. The numbers are separated by a space. Output Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10 - 4. Examples Input 3 50 50 100 Output 66.666666666667 Input 4 0 25 50 75 Output 37.500000000000 Note Note to the first sample: let's assume that Vasya takes x milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <image> milliliters. The total cocktail's volume equals 3Β·x milliliters, so the volume fraction of the juice in the cocktail equals <image>, that is, 66.(6) percent. Submitted Solution: ``` k = int(input()) a = sum(i/100 for i in map(int,input().split())) print(round(a/k,5)) ```
instruction
0
44,107
9
88,214
No
output
1
44,107
9
88,215
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Inna loves sweets very much. She has n closed present boxes lines up in a row in front of her. Each of these boxes contains either a candy (Dima's work) or nothing (Sereja's work). Let's assume that the boxes are numbered from 1 to n, from left to right. As the boxes are closed, Inna doesn't know which boxes contain candies and which boxes contain nothing. Inna chose number k and asked w questions to Dima to find that out. Each question is characterised by two integers li, ri (1 ≀ li ≀ ri ≀ n; r - l + 1 is divisible by k), the i-th question is: "Dima, is that true that among the boxes with numbers from li to ri, inclusive, the candies lie only in boxes with numbers li + k - 1, li + 2k - 1, li + 3k - 1, ..., ri?" Dima hates to say "no" to Inna. That's why he wonders, what number of actions he will have to make for each question to make the answer to the question positive. In one action, Dima can either secretly take the candy from any box or put a candy to any box (Dima has infinitely many candies). Help Dima count the number of actions for each Inna's question. Please note that Dima doesn't change the array during Inna's questions. That's why when you calculate the number of operations for the current question, please assume that the sequence of boxes didn't change. Input The first line of the input contains three integers n, k and w (1 ≀ k ≀ min(n, 10), 1 ≀ n, w ≀ 105). The second line contains n characters. If the i-th box contains a candy, the i-th character of the line equals 1, otherwise it equals 0. Each of the following w lines contains two integers li and ri (1 ≀ li ≀ ri ≀ n) β€” the description of the i-th question. It is guaranteed that ri - li + 1 is divisible by k. Output For each question, print a single number on a single line β€” the minimum number of operations Dima needs to make the answer to the question positive. Examples Input 10 3 3 1010100011 1 3 1 6 4 9 Output 1 3 2 Note For the first question, you need to take a candy from the first box to make the answer positive. So the answer is 1. For the second question, you need to take a candy from the first box, take a candy from the fifth box and put a candy to the sixth box. The answer is 3. For the third question, you need to take a candy from the fifth box and put it to the sixth box. The answer is 2. Submitted Solution: ``` inps=[int(a) for a in input().split()][:3] n,k,w=inps[0],inps[1],inps[2] ls=list() char=str(input()) ans=list() f=list() for i in range(w): ls.append([int(a) for a in input().split()]) for i in range(n): if (i+1)%k==0: ans.append(1) else: ans.append(0) for j in range(min(w,2000)): ctr=0 ls1=ls[j] for i in range(ls1[0]-1,ls1[1]): if int(ans[i])!=int(char[i]): ctr+=1 print(ctr) ```
instruction
0
44,173
9
88,346
No
output
1
44,173
9
88,347
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Inna loves sweets very much. She has n closed present boxes lines up in a row in front of her. Each of these boxes contains either a candy (Dima's work) or nothing (Sereja's work). Let's assume that the boxes are numbered from 1 to n, from left to right. As the boxes are closed, Inna doesn't know which boxes contain candies and which boxes contain nothing. Inna chose number k and asked w questions to Dima to find that out. Each question is characterised by two integers li, ri (1 ≀ li ≀ ri ≀ n; r - l + 1 is divisible by k), the i-th question is: "Dima, is that true that among the boxes with numbers from li to ri, inclusive, the candies lie only in boxes with numbers li + k - 1, li + 2k - 1, li + 3k - 1, ..., ri?" Dima hates to say "no" to Inna. That's why he wonders, what number of actions he will have to make for each question to make the answer to the question positive. In one action, Dima can either secretly take the candy from any box or put a candy to any box (Dima has infinitely many candies). Help Dima count the number of actions for each Inna's question. Please note that Dima doesn't change the array during Inna's questions. That's why when you calculate the number of operations for the current question, please assume that the sequence of boxes didn't change. Input The first line of the input contains three integers n, k and w (1 ≀ k ≀ min(n, 10), 1 ≀ n, w ≀ 105). The second line contains n characters. If the i-th box contains a candy, the i-th character of the line equals 1, otherwise it equals 0. Each of the following w lines contains two integers li and ri (1 ≀ li ≀ ri ≀ n) β€” the description of the i-th question. It is guaranteed that ri - li + 1 is divisible by k. Output For each question, print a single number on a single line β€” the minimum number of operations Dima needs to make the answer to the question positive. Examples Input 10 3 3 1010100011 1 3 1 6 4 9 Output 1 3 2 Note For the first question, you need to take a candy from the first box to make the answer positive. So the answer is 1. For the second question, you need to take a candy from the first box, take a candy from the fifth box and put a candy to the sixth box. The answer is 3. For the third question, you need to take a candy from the fifth box and put it to the sixth box. The answer is 2. Submitted Solution: ``` inps=[int(a) for a in input().split()][:3] n,k,w=inps[0],inps[1],inps[2] ls=list() char=str(input()) ans=list() f=list() for i in range(w): ls.append([int(a) for a in input().split()]) for i in range(n): if (i+1)%k==0: ans.append(1) else: ans.append(0) for j in range(min(w,2000)): ctr=0 ls1=ls[j] for i in range(ls1[0]-1,ls1[1]): if int(ans[i])!=int(char[i]): ctr+=1 #print(ctr) print(ls[2]) ```
instruction
0
44,174
9
88,348
No
output
1
44,174
9
88,349
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Inna loves sweets very much. She has n closed present boxes lines up in a row in front of her. Each of these boxes contains either a candy (Dima's work) or nothing (Sereja's work). Let's assume that the boxes are numbered from 1 to n, from left to right. As the boxes are closed, Inna doesn't know which boxes contain candies and which boxes contain nothing. Inna chose number k and asked w questions to Dima to find that out. Each question is characterised by two integers li, ri (1 ≀ li ≀ ri ≀ n; r - l + 1 is divisible by k), the i-th question is: "Dima, is that true that among the boxes with numbers from li to ri, inclusive, the candies lie only in boxes with numbers li + k - 1, li + 2k - 1, li + 3k - 1, ..., ri?" Dima hates to say "no" to Inna. That's why he wonders, what number of actions he will have to make for each question to make the answer to the question positive. In one action, Dima can either secretly take the candy from any box or put a candy to any box (Dima has infinitely many candies). Help Dima count the number of actions for each Inna's question. Please note that Dima doesn't change the array during Inna's questions. That's why when you calculate the number of operations for the current question, please assume that the sequence of boxes didn't change. Input The first line of the input contains three integers n, k and w (1 ≀ k ≀ min(n, 10), 1 ≀ n, w ≀ 105). The second line contains n characters. If the i-th box contains a candy, the i-th character of the line equals 1, otherwise it equals 0. Each of the following w lines contains two integers li and ri (1 ≀ li ≀ ri ≀ n) β€” the description of the i-th question. It is guaranteed that ri - li + 1 is divisible by k. Output For each question, print a single number on a single line β€” the minimum number of operations Dima needs to make the answer to the question positive. Examples Input 10 3 3 1010100011 1 3 1 6 4 9 Output 1 3 2 Note For the first question, you need to take a candy from the first box to make the answer positive. So the answer is 1. For the second question, you need to take a candy from the first box, take a candy from the fifth box and put a candy to the sixth box. The answer is 3. For the third question, you need to take a candy from the fifth box and put it to the sixth box. The answer is 2. Submitted Solution: ``` n, k, w=list(map(int,input().split())) A=input() Ans=[0] count = 0 for val in A: if val == '1': count += 1 Ans.append(count) #print(Ans) for _ in range(w): A,B=list(map(int,input().split())) print(Ans[B]-Ans[A-1]) ```
instruction
0
44,175
9
88,350
No
output
1
44,175
9
88,351
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Inna loves sweets very much. She has n closed present boxes lines up in a row in front of her. Each of these boxes contains either a candy (Dima's work) or nothing (Sereja's work). Let's assume that the boxes are numbered from 1 to n, from left to right. As the boxes are closed, Inna doesn't know which boxes contain candies and which boxes contain nothing. Inna chose number k and asked w questions to Dima to find that out. Each question is characterised by two integers li, ri (1 ≀ li ≀ ri ≀ n; r - l + 1 is divisible by k), the i-th question is: "Dima, is that true that among the boxes with numbers from li to ri, inclusive, the candies lie only in boxes with numbers li + k - 1, li + 2k - 1, li + 3k - 1, ..., ri?" Dima hates to say "no" to Inna. That's why he wonders, what number of actions he will have to make for each question to make the answer to the question positive. In one action, Dima can either secretly take the candy from any box or put a candy to any box (Dima has infinitely many candies). Help Dima count the number of actions for each Inna's question. Please note that Dima doesn't change the array during Inna's questions. That's why when you calculate the number of operations for the current question, please assume that the sequence of boxes didn't change. Input The first line of the input contains three integers n, k and w (1 ≀ k ≀ min(n, 10), 1 ≀ n, w ≀ 105). The second line contains n characters. If the i-th box contains a candy, the i-th character of the line equals 1, otherwise it equals 0. Each of the following w lines contains two integers li and ri (1 ≀ li ≀ ri ≀ n) β€” the description of the i-th question. It is guaranteed that ri - li + 1 is divisible by k. Output For each question, print a single number on a single line β€” the minimum number of operations Dima needs to make the answer to the question positive. Examples Input 10 3 3 1010100011 1 3 1 6 4 9 Output 1 3 2 Note For the first question, you need to take a candy from the first box to make the answer positive. So the answer is 1. For the second question, you need to take a candy from the first box, take a candy from the fifth box and put a candy to the sixth box. The answer is 3. For the third question, you need to take a candy from the fifth box and put it to the sixth box. The answer is 2. Submitted Solution: ``` str1 = input() n = int(str1.split(" ")[0]) k = int(str1.split(" ")[1]) w = int(str1.split(" ")[2]) boxes = input() for _ in range(w): actions = 0 question = input() l = int(question.split(" ")[0]) r = int(question.split(" ")[1]) boxes_part = boxes[l-1:r-1] boxes_needed = "" for i in range(l-r+1): if (i+1)%k == 0: boxes_needed += "1" else: boxes_needed += "0" for a_char, b_char in zip(boxes_part, boxes_needed): if a_char != b_char: actions += 1 print(actions) ```
instruction
0
44,176
9
88,352
No
output
1
44,176
9
88,353
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples Input 5 2 9 8 2 7 Output 2 3
instruction
0
44,285
9
88,570
Tags: greedy, two pointers Correct Solution: ``` n = int(input()) l = list(map(int, input().split())) Ap, Ae = 0, 0 Bp = ( n - 1 ) if Bp != 0: while (Bp-Ap)>0 : Ae += 1 while (l[Ap] > l[Bp]) : l[Ap] = l[Ap] - l[Bp] Bp -= 1 if Bp != Ap and l[Ap]!= 0 : l[Bp] -= l[Ap] Ap += 1 else : Ae = 1 print (Ae, n-Ae) ```
output
1
44,285
9
88,571
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples Input 5 2 9 8 2 7 Output 2 3
instruction
0
44,286
9
88,572
Tags: greedy, two pointers Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) i=1 j=n-2 a,b=l[0],l[-1] a1=1 b1=1 while i<=j: if a<=b: a+=l[i] i+=1 a1+=1 elif b<a: b+=l[j] b1+=1 j-=1 print(a1,n-a1) ```
output
1
44,286
9
88,573
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples Input 5 2 9 8 2 7 Output 2 3
instruction
0
44,287
9
88,574
Tags: greedy, two pointers Correct Solution: ``` n = int(input()) t = list(map(int, input().split())) taken = [0]*n i = 0 j = n - 1 a, b = 0, 0 while i <= j: if not taken[i]: taken[i] = 1 a += 1 if not taken[j]: taken[j] = 1 b += 1 if i == j: break time = min(t[i], t[j]) t[i] -= time t[j] -= time if t[i] == 0: i += 1 if t[j] == 0: j -= 1 print(a, b) ```
output
1
44,287
9
88,575
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples Input 5 2 9 8 2 7 Output 2 3
instruction
0
44,288
9
88,576
Tags: greedy, two pointers Correct Solution: ``` #http://codeforces.com/contest/6/problem/C ''' Comment ''' if __name__ == "__main__": n = int(input()) bars = list(map(int, input().split())) ali = bob = 0; j = n i = -1 while j - i > 1: if ali <= bob: i += 1 ali += bars[i] else: j -= 1 bob += bars[j] print(i + 1, n - j) ```
output
1
44,288
9
88,577
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples Input 5 2 9 8 2 7 Output 2 3
instruction
0
44,289
9
88,578
Tags: greedy, two pointers Correct Solution: ``` from collections import deque,defaultdict,Counter,OrderedDict n = int(input()) arr = deque(map(int,input().split())) if n==1: print(' '.join(['1','0'])) else: a=arr.popleft() b=arr.pop() alice,bob = 1,1 while arr: while arr and a<=b: a+=arr.popleft() alice+=1 while arr and b<a: b+=arr.pop() bob+=1 print(' '.join([str(alice),str(bob)])) ```
output
1
44,289
9
88,579
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples Input 5 2 9 8 2 7 Output 2 3
instruction
0
44,290
9
88,580
Tags: greedy, two pointers Correct Solution: ``` n = int(input()) t = list(map(int,input().split())) a = 0 b = 0 i = 0 j = n-1 while (i<j): if (t[i]==t[j]) : t[i] = 0 t[j] = 0 i += 1 j -= 1 a += 1 b += 1 elif (t[i]>t[j]) : t[i] -= t[j] t[j] = 0 b += 1 j -= 1 if (i==j) : t[i] = 0 a += 1 else: t[j] -= t[i] t[i] = 0 a += 1 i += 1 if (i==j): t[j] = 0 b += 1 if (i==j and t[i]!=0): a += 1 print(a,b) ```
output
1
44,290
9
88,581
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples Input 5 2 9 8 2 7 Output 2 3
instruction
0
44,291
9
88,582
Tags: greedy, two pointers Correct Solution: ``` # -*- coding: utf-8 -*- """ Created on Fri Mar 6 15:55:41 2020 @author: akprasad C. Alice, Bob and Chocolate time limit per test2 seconds memory limit per test64 megabytes inputstandard input outputstandard output Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples input 5 2 9 8 2 7 output 2 3 """ if __name__ == '__main__': n = int(input()) times = [int(x) for x in input().split()] if len(times) == 1: print("1 0") elif len(times) == 2: print("1 1") else: half = sum(times) / 2 alice_time, bob_time = times[0], times[-1] for i in range(1, len(times) -1): # iterate over all but the extreme two elements if alice_time <= half and alice_time + times[i] >= half: bob_time = sum(times[i + 1:]) if bob_time < alice_time: print("{} {}".format(i, len(times) - i)) else: print("{} {}".format(i + 1, len(times) - i - 1)) break alice_time += times[i] ```
output
1
44,291
9
88,583
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples Input 5 2 9 8 2 7 Output 2 3
instruction
0
44,292
9
88,584
Tags: greedy, two pointers Correct Solution: ``` n=int(input()) times=[int(k) for k in input().split(" ")] bob, alice= 0, 0 alice_time, bob_time = 0, sum(times) for i in range(n): temp = times[i] bob_time -= temp if alice_time <= bob_time: alice += 1 else: bob += 1 alice_time += temp print(alice, bob) ```
output
1
44,292
9
88,585
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples Input 5 2 9 8 2 7 Output 2 3 Submitted Solution: ``` n=int(input()) l=list(map(int,input().split())) a=b=i=0 j=n-1 while(i<=j): if(a<=b): a+=l[i] i+=1 else: b+=l[j] j-=1 print(i,n-i) ```
instruction
0
44,293
9
88,586
Yes
output
1
44,293
9
88,587
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples Input 5 2 9 8 2 7 Output 2 3 Submitted Solution: ``` #-*- coding:utf-8 -*- #!/usr/bin/python3 n = int(input()) a = list(map(int, input().split())) ta = tb = 0 na = 0 nb = n - 1 while na <= nb: if ta <= tb: ta += a[na] na += 1 else: tb += a[nb] nb -= 1 print(na, n - na) ```
instruction
0
44,294
9
88,588
Yes
output
1
44,294
9
88,589
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples Input 5 2 9 8 2 7 Output 2 3 Submitted Solution: ``` n=int(input()) x=[int(i) for i in input().split()] a=0 at=0 b=0 bt=0 k1=0 k2=n-1 for j in range(n): if at>bt: b+=1 bt+=x[k2] k2-=1 else: a+=1 at+=x[k1] k1+=1 #print(at,bt,a,b) print(a,b) ```
instruction
0
44,295
9
88,590
Yes
output
1
44,295
9
88,591
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples Input 5 2 9 8 2 7 Output 2 3 Submitted Solution: ``` n = int(input()) chocolate = list(map(int, input().split())) t_alice = t_bob = 0 i, j = 0, n - 1 while i <= j: if t_alice + chocolate[i] <= t_bob + chocolate[j]: t_alice += chocolate[i] i += 1 else: t_bob += chocolate[j] j -= 1 print(i, n - i) ```
instruction
0
44,296
9
88,592
Yes
output
1
44,296
9
88,593
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples Input 5 2 9 8 2 7 Output 2 3 Submitted Solution: ``` n=int(input()) s=list(map(int,input().split(" "))) m=s[::-1] i,j=0,n-1 a,b=0,0 while i<=j: if a<=b:a+=s[i];i+=1 else:b+=m[i];j-=1 print(i,n-i) ```
instruction
0
44,297
9
88,594
No
output
1
44,297
9
88,595
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples Input 5 2 9 8 2 7 Output 2 3 Submitted Solution: ``` n = int(input()) chocolates = list(map(int, input().split())) left = 0 right = n-1 sumL = 0 sumR = 0 while left<=right : if sumL<=sumR : sumL+=chocolates[left] left+=1 if sumL>sumR : sumR+=chocolates[right] right+= -1 ```
instruction
0
44,298
9
88,596
No
output
1
44,298
9
88,597
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples Input 5 2 9 8 2 7 Output 2 3 Submitted Solution: ``` n = int(input()) c = [int(x) for x in input().split()] x=0 y=0 a=0 b=n-1 while (a<b): if (x+c[a] <= y+c[b]): x+=c[a] a+=1 else: y+=c[b] b-=1 print(a,n-a) ```
instruction
0
44,299
9
88,598
No
output
1
44,299
9
88,599
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob β€” from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? Input The first line contains one integer n (1 ≀ n ≀ 105) β€” the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn (1 ≀ ti ≀ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right). Output Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob. Examples Input 5 2 9 8 2 7 Output 2 3 Submitted Solution: ``` #n=input() #a=list(map(int,input().split())) n,a=5,[2,9,8,2,7] ls=rs=0 l,r=-1,n while l<r: if ls<=rs: l+=1 ls+=a[l] else: r-=1 rs+=a[r] print(ls,rs,l,r) print(l+1,n-l-1) ```
instruction
0
44,300
9
88,600
No
output
1
44,300
9
88,601
Provide tags and a correct Python 3 solution for this coding contest problem. At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy. Input Single line of input data contains two space-separated integers a, b (1 ≀ a, b ≀ 109) β€” number of Vladik and Valera candies respectively. Output Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. Examples Input 1 1 Output Valera Input 7 6 Output Vladik Note Illustration for first test case: <image> Illustration for second test case: <image>
instruction
0
44,332
9
88,664
Tags: brute force, implementation Correct Solution: ``` a, b = map(int, input().strip().split()) x = 1 while (a >= 0 and b >= 0): a -= x x += 1 b -= x x += 1 if (a < 0): print('Vladik') else: print('Valera') ```
output
1
44,332
9
88,665
Provide tags and a correct Python 3 solution for this coding contest problem. At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy. Input Single line of input data contains two space-separated integers a, b (1 ≀ a, b ≀ 109) β€” number of Vladik and Valera candies respectively. Output Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. Examples Input 1 1 Output Valera Input 7 6 Output Vladik Note Illustration for first test case: <image> Illustration for second test case: <image>
instruction
0
44,334
9
88,668
Tags: brute force, implementation Correct Solution: ``` vl,va=list(map(int,input().strip().split())) for i in range(vl+va): if i%2==0: vl=vl-(i+1) if vl<0: print("Vladik") break else: va=va-(i+1) if va<0: print("Valera") break ```
output
1
44,334
9
88,669
Provide tags and a correct Python 3 solution for this coding contest problem. At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy. Input Single line of input data contains two space-separated integers a, b (1 ≀ a, b ≀ 109) β€” number of Vladik and Valera candies respectively. Output Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. Examples Input 1 1 Output Valera Input 7 6 Output Vladik Note Illustration for first test case: <image> Illustration for second test case: <image>
instruction
0
44,335
9
88,670
Tags: brute force, implementation Correct Solution: ``` a,b=map(int,input().split()) t=1 c=1 while c==1 : a=a-t if a<0 : print('Vladik') break t=t+1 b=b-t if b<0 : print('Valera') break t=t+1 ```
output
1
44,335
9
88,671
Provide tags and a correct Python 3 solution for this coding contest problem. At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy. Input Single line of input data contains two space-separated integers a, b (1 ≀ a, b ≀ 109) β€” number of Vladik and Valera candies respectively. Output Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. Examples Input 1 1 Output Valera Input 7 6 Output Vladik Note Illustration for first test case: <image> Illustration for second test case: <image>
instruction
0
44,336
9
88,672
Tags: brute force, implementation Correct Solution: ``` a,b=map(int,input().split()) i=1 while True: if i%2: if a<i: print('Vladik'); break a-=i else: if b<i: print('Valera'); break b-=i i+=1 ```
output
1
44,336
9
88,673
Provide tags and a correct Python 3 solution for this coding contest problem. At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy. Input Single line of input data contains two space-separated integers a, b (1 ≀ a, b ≀ 109) β€” number of Vladik and Valera candies respectively. Output Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. Examples Input 1 1 Output Valera Input 7 6 Output Vladik Note Illustration for first test case: <image> Illustration for second test case: <image>
instruction
0
44,337
9
88,674
Tags: brute force, implementation Correct Solution: ``` a, b = [int(x) for x in input().split(' ')] turn = True c = 1 while(True): if(turn): if(a - c >= 0): a -= c turn = False else: print('Vladik') break else: if(b - c >= 0): b -= c turn = True else: print('Valera') break c += 1 ```
output
1
44,337
9
88,675
Provide tags and a correct Python 3 solution for this coding contest problem. At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy. Input Single line of input data contains two space-separated integers a, b (1 ≀ a, b ≀ 109) β€” number of Vladik and Valera candies respectively. Output Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. Examples Input 1 1 Output Valera Input 7 6 Output Vladik Note Illustration for first test case: <image> Illustration for second test case: <image>
instruction
0
44,338
9
88,676
Tags: brute force, implementation Correct Solution: ``` x=1 step=1 a,b=map(int,input().split()) while True: if step==1: if x>a: break a-=x x+=1 step=0 else: if x>b: break b-=x x+=1 step=1 if step==1: print("Vladik") else: print("Valera") ```
output
1
44,338
9
88,677
Provide tags and a correct Python 3 solution for this coding contest problem. At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy. Input Single line of input data contains two space-separated integers a, b (1 ≀ a, b ≀ 109) β€” number of Vladik and Valera candies respectively. Output Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. Examples Input 1 1 Output Valera Input 7 6 Output Vladik Note Illustration for first test case: <image> Illustration for second test case: <image>
instruction
0
44,339
9
88,678
Tags: brute force, implementation Correct Solution: ``` a, b = map(int, input().split()) N = 100005 rec = [0] * N rec[1] = 1 rec[2] = 2 for i in range(3, N): rec[i] = rec[i - 2] + i for i in range(1, 100005): if i % 2 != 0: if a - rec[i] < 0: print('Vladik') exit() else: if b - rec[i] < 0: print('Valera') exit() ```
output
1
44,339
9
88,679
Provide tags and a correct Python 3 solution for this coding contest problem. A company of n friends wants to order exactly two pizzas. It is known that in total there are 9 pizza ingredients in nature, which are denoted by integers from 1 to 9. Each of the n friends has one or more favorite ingredients: the i-th of friends has the number of favorite ingredients equal to f_i (1 ≀ f_i ≀ 9) and your favorite ingredients form the sequence b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). The website of CodePizza restaurant has exactly m (m β‰₯ 2) pizzas. Each pizza is characterized by a set of r_j ingredients a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ r_j ≀ 9, 1 ≀ a_{jt} ≀ 9) , which are included in it, and its price is c_j. Help your friends choose exactly two pizzas in such a way as to please the maximum number of people in the company. It is known that a person is pleased with the choice if each of his/her favorite ingredients is in at least one ordered pizza. If there are several ways to choose two pizzas so as to please the maximum number of friends, then choose the one that minimizes the total price of two pizzas. Input The first line of the input contains two integers n and m (1 ≀ n ≀ 10^5, 2 ≀ m ≀ 10^5) β€” the number of friends in the company and the number of pizzas, respectively. Next, the n lines contain descriptions of favorite ingredients of the friends: the i-th of them contains the number of favorite ingredients f_i (1 ≀ f_i ≀ 9) and a sequence of distinct integers b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). Next, the m lines contain pizza descriptions: the j-th of them contains the integer price of the pizza c_j (1 ≀ c_j ≀ 10^9), the number of ingredients r_j (1 ≀ r_j ≀ 9) and the ingredients themselves as a sequence of distinct integers a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ a_{jt} ≀ 9). Output Output two integers j_1 and j_2 (1 ≀ j_1,j_2 ≀ m, j_1 β‰  j_2) denoting the indices of two pizzas in the required set. If there are several solutions, output any of them. Pizza indices can be printed in any order. Examples Input 3 4 2 6 7 4 2 3 9 5 3 2 3 9 100 1 7 400 3 3 2 5 100 2 9 2 500 3 2 9 5 Output 2 3 Input 4 3 1 1 1 2 1 3 1 4 10 4 1 2 3 4 20 4 1 2 3 4 30 4 1 2 3 4 Output 1 2 Input 1 5 9 9 8 7 6 5 4 3 2 1 3 4 1 2 3 4 1 4 5 6 7 8 4 4 1 3 5 7 1 4 2 4 6 8 5 4 1 9 2 8 Output 2 4
instruction
0
44,668
9
89,336
Tags: bitmasks, brute force Correct Solution: ``` import sys def popcount(i): assert 0 <= i < 0x100000000 i = i - ((i >> 1) & 0x55555555) i = (i & 0x33333333) + ((i >> 2) & 0x33333333) return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24 N, M = map(int, sys.stdin.readline().split()) table = [0]*(2**9) for _ in range(N): S = tuple(map(int, sys.stdin.readline().split())) table[sum(2**(a-1) for a in S[1:])] += 1 dp = [0]*(2**9) for s in range(2**9): ppc = popcount(s) res = table[s] t = s&(s-1) for _ in range(2**ppc - 1): res += table[t] t = (t-1)&s dp[s] = res table = [False]*(2**9) cost = [[] for _ in range(2**9)] idx = [[] for _ in range(2**9)] for i in range(M): T = tuple(map(int, sys.stdin.readline().split())) x = sum(2**(a-1) for a in T[2:]) table[x] = True cost[x].append(T[0]) idx[x].append(i+1) minidx = [cost[x].index(min(cost[x])) if cost[x] else -1 for x in range(2**9)] mincost = [10**10]*(2**9) mincostidx = [(0, 0) for _ in range(2**9)] reachable = [False]*(2**9) for i in range(2**9): if not table[i]: continue for j in range(2**9): if not table[j]: continue reachable[i|j] = True if i != j: mi = min(cost[i]) mj = min(cost[j]) if mincost[i|j] > mi + mj: mincost[i|j] = mi + mj mincostidx[i|j] = (idx[i][minidx[i]], idx[j][minidx[j]]) ctr = -1 candi = [] for i in range(2**9): if not reachable[i]: continue if ctr > dp[i]: continue elif ctr == dp[i]: candi.append(i) else: ctr = dp[i] candi = [i] ans = 10**11 Ans = (-1, -1) for c in candi: if table[c] and len(cost[c]) > 1: D = cost[c][:] res = min(D) a = D.index(res) D.remove(res) r = min(D) b = D.index(r) if cost[c][b] != r: b += 1 if a == b: b += 1 res += r if ans > res: ans = res Ans = (idx[c][a], idx[c][b]) if ans > mincost[c]: ans = mincost[c] Ans = mincostidx[c] print(*Ans) ```
output
1
44,668
9
89,337
Provide tags and a correct Python 3 solution for this coding contest problem. A company of n friends wants to order exactly two pizzas. It is known that in total there are 9 pizza ingredients in nature, which are denoted by integers from 1 to 9. Each of the n friends has one or more favorite ingredients: the i-th of friends has the number of favorite ingredients equal to f_i (1 ≀ f_i ≀ 9) and your favorite ingredients form the sequence b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). The website of CodePizza restaurant has exactly m (m β‰₯ 2) pizzas. Each pizza is characterized by a set of r_j ingredients a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ r_j ≀ 9, 1 ≀ a_{jt} ≀ 9) , which are included in it, and its price is c_j. Help your friends choose exactly two pizzas in such a way as to please the maximum number of people in the company. It is known that a person is pleased with the choice if each of his/her favorite ingredients is in at least one ordered pizza. If there are several ways to choose two pizzas so as to please the maximum number of friends, then choose the one that minimizes the total price of two pizzas. Input The first line of the input contains two integers n and m (1 ≀ n ≀ 10^5, 2 ≀ m ≀ 10^5) β€” the number of friends in the company and the number of pizzas, respectively. Next, the n lines contain descriptions of favorite ingredients of the friends: the i-th of them contains the number of favorite ingredients f_i (1 ≀ f_i ≀ 9) and a sequence of distinct integers b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). Next, the m lines contain pizza descriptions: the j-th of them contains the integer price of the pizza c_j (1 ≀ c_j ≀ 10^9), the number of ingredients r_j (1 ≀ r_j ≀ 9) and the ingredients themselves as a sequence of distinct integers a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ a_{jt} ≀ 9). Output Output two integers j_1 and j_2 (1 ≀ j_1,j_2 ≀ m, j_1 β‰  j_2) denoting the indices of two pizzas in the required set. If there are several solutions, output any of them. Pizza indices can be printed in any order. Examples Input 3 4 2 6 7 4 2 3 9 5 3 2 3 9 100 1 7 400 3 3 2 5 100 2 9 2 500 3 2 9 5 Output 2 3 Input 4 3 1 1 1 2 1 3 1 4 10 4 1 2 3 4 20 4 1 2 3 4 30 4 1 2 3 4 Output 1 2 Input 1 5 9 9 8 7 6 5 4 3 2 1 3 4 1 2 3 4 1 4 5 6 7 8 4 4 1 3 5 7 1 4 2 4 6 8 5 4 1 9 2 8 Output 2 4
instruction
0
44,669
9
89,338
Tags: bitmasks, brute force Correct Solution: ``` import sys import math input=sys.stdin.readline #sys.setrecursionlimit(1000000) #I=lambda : list(map(int,input().split())) ma =int(10000000000000000) n,m=map(int,input().split()) a=[ma]*(515);a1=[ma]*(515);fr=[0]*(515);pos=[0]*(515) for i in range(n): b=list(map(int,input().split())) x=int(0) for j in range(1,b[0]+1): b[j]-=1 x|=(1<<b[j]) fr[x]+=1 min1=int(ma) max1=int(0) ind,ind1=int(),int() for i in range(m): b=list(map(int,input().split())) x=int(0) for j in range(2,b[1]+2): b[j]-=1 x|=(1<<b[j]) if a[x]!=ma: if fr[x]>max1: max1=fr[x] min1=a[x]+b[0] ind=pos[x] ind1=i+1 elif fr[x]==max1: if b[0]+a[x]<min1: min1=b[0]+a[x] ind=pos[x] ind1=i+1 if a[x]>b[0]: a[x]=b[0] pos[x]=i+1 for i in range(1,512): for j in range(1,512): if i==j or a[i]==ma or a[j]==ma: continue k=i|j cnt=int(0) while k>0: cnt+=fr[k] k=(k-1)&(i|j) if cnt>max1: ind=pos[i] ind1=pos[j] max1=cnt min1=a[i]+a[j] if cnt==max1: if a[i]+a[j]<min1: ind=pos[i] ind1=pos[j] min1=min(min1,a[i]+a[j]) print(ind,ind1,sep=" ") ```
output
1
44,669
9
89,339
Provide tags and a correct Python 3 solution for this coding contest problem. A company of n friends wants to order exactly two pizzas. It is known that in total there are 9 pizza ingredients in nature, which are denoted by integers from 1 to 9. Each of the n friends has one or more favorite ingredients: the i-th of friends has the number of favorite ingredients equal to f_i (1 ≀ f_i ≀ 9) and your favorite ingredients form the sequence b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). The website of CodePizza restaurant has exactly m (m β‰₯ 2) pizzas. Each pizza is characterized by a set of r_j ingredients a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ r_j ≀ 9, 1 ≀ a_{jt} ≀ 9) , which are included in it, and its price is c_j. Help your friends choose exactly two pizzas in such a way as to please the maximum number of people in the company. It is known that a person is pleased with the choice if each of his/her favorite ingredients is in at least one ordered pizza. If there are several ways to choose two pizzas so as to please the maximum number of friends, then choose the one that minimizes the total price of two pizzas. Input The first line of the input contains two integers n and m (1 ≀ n ≀ 10^5, 2 ≀ m ≀ 10^5) β€” the number of friends in the company and the number of pizzas, respectively. Next, the n lines contain descriptions of favorite ingredients of the friends: the i-th of them contains the number of favorite ingredients f_i (1 ≀ f_i ≀ 9) and a sequence of distinct integers b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). Next, the m lines contain pizza descriptions: the j-th of them contains the integer price of the pizza c_j (1 ≀ c_j ≀ 10^9), the number of ingredients r_j (1 ≀ r_j ≀ 9) and the ingredients themselves as a sequence of distinct integers a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ a_{jt} ≀ 9). Output Output two integers j_1 and j_2 (1 ≀ j_1,j_2 ≀ m, j_1 β‰  j_2) denoting the indices of two pizzas in the required set. If there are several solutions, output any of them. Pizza indices can be printed in any order. Examples Input 3 4 2 6 7 4 2 3 9 5 3 2 3 9 100 1 7 400 3 3 2 5 100 2 9 2 500 3 2 9 5 Output 2 3 Input 4 3 1 1 1 2 1 3 1 4 10 4 1 2 3 4 20 4 1 2 3 4 30 4 1 2 3 4 Output 1 2 Input 1 5 9 9 8 7 6 5 4 3 2 1 3 4 1 2 3 4 1 4 5 6 7 8 4 4 1 3 5 7 1 4 2 4 6 8 5 4 1 9 2 8 Output 2 4
instruction
0
44,670
9
89,340
Tags: bitmasks, brute force Correct Solution: ``` from sys import stdin, stdout import itertools n, m = map(int, stdin.readline().split()) friends = [0]*512 exists = [0]*512 costs_min = [0]*512 costs_2 = [0]*512 index_min = [0]*512 index_2 = [0]*512 count_friends = [0]*512 def top_to_idx(top): ans = 0 for t in top: ans += 1 << (t-1) return ans def idx_to_top(idx): ans = [] for i in range(9): if idx & (1 << i): ans.append(i+1) return ans for i in range(n): top = list(map(int, stdin.readline().split()))[1:] friends[top_to_idx(top)] += 1 #print(friends) def subset(i, j): for s in range(9): if i & (1 << s) and not (j & (1 << s)): return False return True for i in range(512): for j in range(512): if subset(j, i): count_friends[i] += friends[j] #print(count_friends) for i in range(m): pizza = list(map(int, stdin.readline().split())) top_idx = top_to_idx(pizza[2:]) cost = pizza[0] exists[top_idx] = True if costs_min[top_idx] == 0 or cost < costs_min[top_idx]: costs_2[top_idx] = costs_min[top_idx] index_2[top_idx] = index_min[top_idx] costs_min[top_idx] = cost index_min[top_idx] = i+1 elif costs_2[top_idx] == 0 or cost < costs_2[top_idx]: costs_2[top_idx] = cost index_2[top_idx] = i+1 best_matches = -1 best_cost = -1 best = None for p1 in range(512): for p2 in range(p1, 512): if not exists[p1] or not exists[p2]: continue if p1 == p2 and index_2[p1] == 0: continue p = p1 | p2 # print(idx_to_top(p1 | p2)) matches = count_friends[p] # print(matches) cost = costs_min[p1] + costs_min[p2] if p1 != p2 else costs_min[p1] + costs_2[p2] if best_matches == -1 or matches > best_matches or (matches == best_matches and cost < best_cost): best = (index_min[p1], index_min[p2]) if p1 != p2 else (index_min[p1], index_2[p2]) best_matches = matches best_cost = cost #print(best_matches) #print(best_cost) print(best[0], best[1]) ```
output
1
44,670
9
89,341
Provide tags and a correct Python 3 solution for this coding contest problem. A company of n friends wants to order exactly two pizzas. It is known that in total there are 9 pizza ingredients in nature, which are denoted by integers from 1 to 9. Each of the n friends has one or more favorite ingredients: the i-th of friends has the number of favorite ingredients equal to f_i (1 ≀ f_i ≀ 9) and your favorite ingredients form the sequence b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). The website of CodePizza restaurant has exactly m (m β‰₯ 2) pizzas. Each pizza is characterized by a set of r_j ingredients a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ r_j ≀ 9, 1 ≀ a_{jt} ≀ 9) , which are included in it, and its price is c_j. Help your friends choose exactly two pizzas in such a way as to please the maximum number of people in the company. It is known that a person is pleased with the choice if each of his/her favorite ingredients is in at least one ordered pizza. If there are several ways to choose two pizzas so as to please the maximum number of friends, then choose the one that minimizes the total price of two pizzas. Input The first line of the input contains two integers n and m (1 ≀ n ≀ 10^5, 2 ≀ m ≀ 10^5) β€” the number of friends in the company and the number of pizzas, respectively. Next, the n lines contain descriptions of favorite ingredients of the friends: the i-th of them contains the number of favorite ingredients f_i (1 ≀ f_i ≀ 9) and a sequence of distinct integers b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). Next, the m lines contain pizza descriptions: the j-th of them contains the integer price of the pizza c_j (1 ≀ c_j ≀ 10^9), the number of ingredients r_j (1 ≀ r_j ≀ 9) and the ingredients themselves as a sequence of distinct integers a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ a_{jt} ≀ 9). Output Output two integers j_1 and j_2 (1 ≀ j_1,j_2 ≀ m, j_1 β‰  j_2) denoting the indices of two pizzas in the required set. If there are several solutions, output any of them. Pizza indices can be printed in any order. Examples Input 3 4 2 6 7 4 2 3 9 5 3 2 3 9 100 1 7 400 3 3 2 5 100 2 9 2 500 3 2 9 5 Output 2 3 Input 4 3 1 1 1 2 1 3 1 4 10 4 1 2 3 4 20 4 1 2 3 4 30 4 1 2 3 4 Output 1 2 Input 1 5 9 9 8 7 6 5 4 3 2 1 3 4 1 2 3 4 1 4 5 6 7 8 4 4 1 3 5 7 1 4 2 4 6 8 5 4 1 9 2 8 Output 2 4
instruction
0
44,671
9
89,342
Tags: bitmasks, brute force Correct Solution: ``` import sys import math #input=sys.stdin.readline #sys.setrecursionlimit(1000000) I=lambda : list(map(int,input().split())) ma =int(10000000000000000) n,m=map(int,input().split()) a=[ma]*(515);a1=[ma]*(515);fr=[0]*(515);pos=[0]*(515) for i in range(n): b=I() x=int(0) for j in range(1,b[0]+1): b[j]-=1 x|=(1<<b[j]) fr[x]+=1 min1=int(ma) max1=int(0) ind,ind1=int(),int() for i in range(m): b=I() x=int(0) for j in range(2,b[1]+2): b[j]-=1 x|=(1<<b[j]) if a[x]!=ma: if fr[x]>max1: max1=fr[x] min1=a[x]+b[0] ind=pos[x] ind1=i+1 elif fr[x]==max1: if b[0]+a[x]<min1: min1=b[0]+a[x] ind=pos[x] ind1=i+1 if a[x]>b[0]: a[x]=b[0] pos[x]=i+1 for i in range(1,512): for j in range(1,512): if i==j or a[i]==ma or a[j]==ma: continue k=i|j cnt=int(0) while k>0: cnt+=fr[k] k=(k-1)&(i|j) if cnt>max1: ind=pos[i] ind1=pos[j] max1=cnt min1=a[i]+a[j] if cnt==max1: if a[i]+a[j]<min1: ind=pos[i] ind1=pos[j] min1=min(min1,a[i]+a[j]) print(ind,ind1,sep=" ") ```
output
1
44,671
9
89,343
Provide tags and a correct Python 3 solution for this coding contest problem. A company of n friends wants to order exactly two pizzas. It is known that in total there are 9 pizza ingredients in nature, which are denoted by integers from 1 to 9. Each of the n friends has one or more favorite ingredients: the i-th of friends has the number of favorite ingredients equal to f_i (1 ≀ f_i ≀ 9) and your favorite ingredients form the sequence b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). The website of CodePizza restaurant has exactly m (m β‰₯ 2) pizzas. Each pizza is characterized by a set of r_j ingredients a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ r_j ≀ 9, 1 ≀ a_{jt} ≀ 9) , which are included in it, and its price is c_j. Help your friends choose exactly two pizzas in such a way as to please the maximum number of people in the company. It is known that a person is pleased with the choice if each of his/her favorite ingredients is in at least one ordered pizza. If there are several ways to choose two pizzas so as to please the maximum number of friends, then choose the one that minimizes the total price of two pizzas. Input The first line of the input contains two integers n and m (1 ≀ n ≀ 10^5, 2 ≀ m ≀ 10^5) β€” the number of friends in the company and the number of pizzas, respectively. Next, the n lines contain descriptions of favorite ingredients of the friends: the i-th of them contains the number of favorite ingredients f_i (1 ≀ f_i ≀ 9) and a sequence of distinct integers b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). Next, the m lines contain pizza descriptions: the j-th of them contains the integer price of the pizza c_j (1 ≀ c_j ≀ 10^9), the number of ingredients r_j (1 ≀ r_j ≀ 9) and the ingredients themselves as a sequence of distinct integers a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ a_{jt} ≀ 9). Output Output two integers j_1 and j_2 (1 ≀ j_1,j_2 ≀ m, j_1 β‰  j_2) denoting the indices of two pizzas in the required set. If there are several solutions, output any of them. Pizza indices can be printed in any order. Examples Input 3 4 2 6 7 4 2 3 9 5 3 2 3 9 100 1 7 400 3 3 2 5 100 2 9 2 500 3 2 9 5 Output 2 3 Input 4 3 1 1 1 2 1 3 1 4 10 4 1 2 3 4 20 4 1 2 3 4 30 4 1 2 3 4 Output 1 2 Input 1 5 9 9 8 7 6 5 4 3 2 1 3 4 1 2 3 4 1 4 5 6 7 8 4 4 1 3 5 7 1 4 2 4 6 8 5 4 1 9 2 8 Output 2 4
instruction
0
44,672
9
89,344
Tags: bitmasks, brute force Correct Solution: ``` import sys import math input=sys.stdin.readline #sys.setrecursionlimit(1000000) I=lambda : list(map(int,input().split())) ma =int(10000000000000000) n,m=map(int,input().split()) a=[ma]*(515);a1=[ma]*(515);fr=[0]*(515);pos=[0]*(515) for i in range(n): b=I() x=int(0) for j in range(1,b[0]+1): b[j]-=1 x|=(1<<b[j]) fr[x]+=1 min1=int(ma) max1=int(0) ind,ind1=int(),int() for i in range(m): b=I() x=int(0) for j in range(2,b[1]+2): b[j]-=1 x|=(1<<b[j]) if a[x]!=ma: if fr[x]>max1: max1=fr[x] min1=a[x]+b[0] ind=pos[x] ind1=i+1 elif fr[x]==max1: if b[0]+a[x]<min1: min1=b[0]+a[x] ind=pos[x] ind1=i+1 if a[x]>b[0]: a[x]=b[0] pos[x]=i+1 for i in range(1,512): for j in range(1,512): if i==j or a[i]==ma or a[j]==ma: continue k=i|j cnt=int(0) while k>0: cnt+=fr[k] k=(k-1)&(i|j) if cnt>max1: ind=pos[i] ind1=pos[j] max1=cnt min1=a[i]+a[j] if cnt==max1: if a[i]+a[j]<min1: ind=pos[i] ind1=pos[j] min1=min(min1,a[i]+a[j]) print(ind,ind1,sep=" ") ```
output
1
44,672
9
89,345
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A company of n friends wants to order exactly two pizzas. It is known that in total there are 9 pizza ingredients in nature, which are denoted by integers from 1 to 9. Each of the n friends has one or more favorite ingredients: the i-th of friends has the number of favorite ingredients equal to f_i (1 ≀ f_i ≀ 9) and your favorite ingredients form the sequence b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). The website of CodePizza restaurant has exactly m (m β‰₯ 2) pizzas. Each pizza is characterized by a set of r_j ingredients a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ r_j ≀ 9, 1 ≀ a_{jt} ≀ 9) , which are included in it, and its price is c_j. Help your friends choose exactly two pizzas in such a way as to please the maximum number of people in the company. It is known that a person is pleased with the choice if each of his/her favorite ingredients is in at least one ordered pizza. If there are several ways to choose two pizzas so as to please the maximum number of friends, then choose the one that minimizes the total price of two pizzas. Input The first line of the input contains two integers n and m (1 ≀ n ≀ 10^5, 2 ≀ m ≀ 10^5) β€” the number of friends in the company and the number of pizzas, respectively. Next, the n lines contain descriptions of favorite ingredients of the friends: the i-th of them contains the number of favorite ingredients f_i (1 ≀ f_i ≀ 9) and a sequence of distinct integers b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). Next, the m lines contain pizza descriptions: the j-th of them contains the integer price of the pizza c_j (1 ≀ c_j ≀ 10^9), the number of ingredients r_j (1 ≀ r_j ≀ 9) and the ingredients themselves as a sequence of distinct integers a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ a_{jt} ≀ 9). Output Output two integers j_1 and j_2 (1 ≀ j_1,j_2 ≀ m, j_1 β‰  j_2) denoting the indices of two pizzas in the required set. If there are several solutions, output any of them. Pizza indices can be printed in any order. Examples Input 3 4 2 6 7 4 2 3 9 5 3 2 3 9 100 1 7 400 3 3 2 5 100 2 9 2 500 3 2 9 5 Output 2 3 Input 4 3 1 1 1 2 1 3 1 4 10 4 1 2 3 4 20 4 1 2 3 4 30 4 1 2 3 4 Output 1 2 Input 1 5 9 9 8 7 6 5 4 3 2 1 3 4 1 2 3 4 1 4 5 6 7 8 4 4 1 3 5 7 1 4 2 4 6 8 5 4 1 9 2 8 Output 2 4 Submitted Solution: ``` from sys import stdin a,b = map(int,input().split()) if a == b == 100000 and input()!='6 4 2 9 8 5 6': print(68727,94262) exit() elif a == b == 100000 and input() == '1 8': print(6,60) elif a == b == 100000: print(1,4) exit() qw = [set() for i in range(9)] for i in range(a): for u in stdin.readline().split()[1:]: qw[int(u)-1].add(i) er = [[10**9+1,10**9+2,0,0] for i in range(2**9)] t = [2**i for i in range(9)] for i in range(1,b+1): arr = [0 for i in range(9)] lk = stdin.readline().split() c = int(lk[0]) for u in lk[2:]: arr[int(u)-1] = 1 ind = 0 for l,u in enumerate(arr): ind += u * t[8-l] if c < er[ind][0]: er[ind] = [c,er[ind][0],i,er[ind][2]] elif c < er[ind][1]: er[ind][1] = c er[ind][3] = i maxx = -1 minn = 3*10**9 vivod = [] for i in range(1,2**9): for i1 in range(i+1,2**9): rt = i | i1 if er[i][0] != 10**9+1 and er[i1][0] != 10**9+1: j = 8 d = set() m = [] rt <<= 1 while rt > 1: rt >>= 1 if rt%2==0: m.append(j) j-=1 continue d.update(qw[j]) j-=1 for o in m: d.difference_update(qw[o]) for o in range(j+1): d.difference_update(qw[o]) l = er[i1][0] + er[i][0] if len(d) > maxx: maxx = len(d) minn = l vivod = [er[i][2],er[i1][2]] elif l < minn and len(d) == maxx: minn = l vivod = [er[i][2],er[i1][2]] for i in range(1,2**9): if er[i][1] != 10**9+1 and er[i][0] != 10**9+1: rt = i j = 8 d = set() m = [] rt <<= 1 while rt > 1: rt >>= 1 if rt%2==0: m.append(j) j-=1 continue d.update(qw[j]) j-=1 for o in m: d.difference_update(qw[o]) l = er[i1][0] + er[i][0] if len(d) > maxx: maxx = len(d) minn = l vivod = [er[i][2],er[i][3]] elif l < minn and len(d) == maxx: minn = l vivod = [er[i][2],er[i][3]] print(*vivod) ```
instruction
0
44,673
9
89,346
No
output
1
44,673
9
89,347
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A company of n friends wants to order exactly two pizzas. It is known that in total there are 9 pizza ingredients in nature, which are denoted by integers from 1 to 9. Each of the n friends has one or more favorite ingredients: the i-th of friends has the number of favorite ingredients equal to f_i (1 ≀ f_i ≀ 9) and your favorite ingredients form the sequence b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). The website of CodePizza restaurant has exactly m (m β‰₯ 2) pizzas. Each pizza is characterized by a set of r_j ingredients a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ r_j ≀ 9, 1 ≀ a_{jt} ≀ 9) , which are included in it, and its price is c_j. Help your friends choose exactly two pizzas in such a way as to please the maximum number of people in the company. It is known that a person is pleased with the choice if each of his/her favorite ingredients is in at least one ordered pizza. If there are several ways to choose two pizzas so as to please the maximum number of friends, then choose the one that minimizes the total price of two pizzas. Input The first line of the input contains two integers n and m (1 ≀ n ≀ 10^5, 2 ≀ m ≀ 10^5) β€” the number of friends in the company and the number of pizzas, respectively. Next, the n lines contain descriptions of favorite ingredients of the friends: the i-th of them contains the number of favorite ingredients f_i (1 ≀ f_i ≀ 9) and a sequence of distinct integers b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). Next, the m lines contain pizza descriptions: the j-th of them contains the integer price of the pizza c_j (1 ≀ c_j ≀ 10^9), the number of ingredients r_j (1 ≀ r_j ≀ 9) and the ingredients themselves as a sequence of distinct integers a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ a_{jt} ≀ 9). Output Output two integers j_1 and j_2 (1 ≀ j_1,j_2 ≀ m, j_1 β‰  j_2) denoting the indices of two pizzas in the required set. If there are several solutions, output any of them. Pizza indices can be printed in any order. Examples Input 3 4 2 6 7 4 2 3 9 5 3 2 3 9 100 1 7 400 3 3 2 5 100 2 9 2 500 3 2 9 5 Output 2 3 Input 4 3 1 1 1 2 1 3 1 4 10 4 1 2 3 4 20 4 1 2 3 4 30 4 1 2 3 4 Output 1 2 Input 1 5 9 9 8 7 6 5 4 3 2 1 3 4 1 2 3 4 1 4 5 6 7 8 4 4 1 3 5 7 1 4 2 4 6 8 5 4 1 9 2 8 Output 2 4 Submitted Solution: ``` print("2 3") ```
instruction
0
44,674
9
89,348
No
output
1
44,674
9
89,349
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A company of n friends wants to order exactly two pizzas. It is known that in total there are 9 pizza ingredients in nature, which are denoted by integers from 1 to 9. Each of the n friends has one or more favorite ingredients: the i-th of friends has the number of favorite ingredients equal to f_i (1 ≀ f_i ≀ 9) and your favorite ingredients form the sequence b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). The website of CodePizza restaurant has exactly m (m β‰₯ 2) pizzas. Each pizza is characterized by a set of r_j ingredients a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ r_j ≀ 9, 1 ≀ a_{jt} ≀ 9) , which are included in it, and its price is c_j. Help your friends choose exactly two pizzas in such a way as to please the maximum number of people in the company. It is known that a person is pleased with the choice if each of his/her favorite ingredients is in at least one ordered pizza. If there are several ways to choose two pizzas so as to please the maximum number of friends, then choose the one that minimizes the total price of two pizzas. Input The first line of the input contains two integers n and m (1 ≀ n ≀ 10^5, 2 ≀ m ≀ 10^5) β€” the number of friends in the company and the number of pizzas, respectively. Next, the n lines contain descriptions of favorite ingredients of the friends: the i-th of them contains the number of favorite ingredients f_i (1 ≀ f_i ≀ 9) and a sequence of distinct integers b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). Next, the m lines contain pizza descriptions: the j-th of them contains the integer price of the pizza c_j (1 ≀ c_j ≀ 10^9), the number of ingredients r_j (1 ≀ r_j ≀ 9) and the ingredients themselves as a sequence of distinct integers a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ a_{jt} ≀ 9). Output Output two integers j_1 and j_2 (1 ≀ j_1,j_2 ≀ m, j_1 β‰  j_2) denoting the indices of two pizzas in the required set. If there are several solutions, output any of them. Pizza indices can be printed in any order. Examples Input 3 4 2 6 7 4 2 3 9 5 3 2 3 9 100 1 7 400 3 3 2 5 100 2 9 2 500 3 2 9 5 Output 2 3 Input 4 3 1 1 1 2 1 3 1 4 10 4 1 2 3 4 20 4 1 2 3 4 30 4 1 2 3 4 Output 1 2 Input 1 5 9 9 8 7 6 5 4 3 2 1 3 4 1 2 3 4 1 4 5 6 7 8 4 4 1 3 5 7 1 4 2 4 6 8 5 4 1 9 2 8 Output 2 4 Submitted Solution: ``` from sys import stdin a,b = map(int,input().split()) if a == b == 100000: print(68727,94262) exit() qw = [set() for i in range(9)] for i in range(a): for u in stdin.readline().split()[1:]: qw[int(u)-1].add(i) er = [[10**9+1,10**9+2,0,0] for i in range(2**9)] t = [2**i for i in range(9)] for i in range(1,b+1): arr = [0 for i in range(9)] lk = stdin.readline().split() c = int(lk[0]) for u in lk[2:]: arr[int(u)-1] = 1 ind = 0 for l,u in enumerate(arr): ind += u * t[8-l] if c < er[ind][0]: er[ind] = [c,er[ind][0],i,er[ind][2]] elif c < er[ind][1]: er[ind][1] = c er[ind][3] = i maxx = -1 minn = 3*10**9 vivod = [] i = 22 i1 = 258 for i in range(2**9-1): for i1 in range(i+1,2**9-1): rt = i | i1 if er[i][0] != 10**9+1 and er[i1][0] != 10**9+1: j = 8 d = set() m = [] rt <<= 1 while rt > 1: rt >>= 1 if rt%2==0: m.append(j) j-=1 continue d.update(qw[j]) j-=1 for o in m: d.difference_update(qw[o]) l = er[i1][0] + er[i][0] if len(d) > maxx: maxx = len(d) minn = l vivod = [er[i][2],er[i1][2]] elif l < minn and len(d) == maxx: minn = l vivod = [er[i][2],er[i1][2]] for i in range(2**9-1): if er[i] != [10**9+1,10**9+2,0,0]: rt = i j = 8 d = set() m = [] rt <<= 1 while rt > 1: rt >>= 1 if rt%2==0: m.append(j) j-=1 continue d.update(qw[j]) j-=1 for o in m: d.difference_update(qw[o]) l = er[i1][0] + er[i][0] if len(d) > maxx: maxx = len(d) minn = l vivod = [er[i][2],er[i][3]] elif l < minn and len(d) == maxx: minn = l vivod = [er[i][2],er[i][3]] print(*vivod) ```
instruction
0
44,675
9
89,350
No
output
1
44,675
9
89,351
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A company of n friends wants to order exactly two pizzas. It is known that in total there are 9 pizza ingredients in nature, which are denoted by integers from 1 to 9. Each of the n friends has one or more favorite ingredients: the i-th of friends has the number of favorite ingredients equal to f_i (1 ≀ f_i ≀ 9) and your favorite ingredients form the sequence b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). The website of CodePizza restaurant has exactly m (m β‰₯ 2) pizzas. Each pizza is characterized by a set of r_j ingredients a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ r_j ≀ 9, 1 ≀ a_{jt} ≀ 9) , which are included in it, and its price is c_j. Help your friends choose exactly two pizzas in such a way as to please the maximum number of people in the company. It is known that a person is pleased with the choice if each of his/her favorite ingredients is in at least one ordered pizza. If there are several ways to choose two pizzas so as to please the maximum number of friends, then choose the one that minimizes the total price of two pizzas. Input The first line of the input contains two integers n and m (1 ≀ n ≀ 10^5, 2 ≀ m ≀ 10^5) β€” the number of friends in the company and the number of pizzas, respectively. Next, the n lines contain descriptions of favorite ingredients of the friends: the i-th of them contains the number of favorite ingredients f_i (1 ≀ f_i ≀ 9) and a sequence of distinct integers b_{i1}, b_{i2}, ..., b_{if_i} (1 ≀ b_{it} ≀ 9). Next, the m lines contain pizza descriptions: the j-th of them contains the integer price of the pizza c_j (1 ≀ c_j ≀ 10^9), the number of ingredients r_j (1 ≀ r_j ≀ 9) and the ingredients themselves as a sequence of distinct integers a_{j1}, a_{j2}, ..., a_{jr_j} (1 ≀ a_{jt} ≀ 9). Output Output two integers j_1 and j_2 (1 ≀ j_1,j_2 ≀ m, j_1 β‰  j_2) denoting the indices of two pizzas in the required set. If there are several solutions, output any of them. Pizza indices can be printed in any order. Examples Input 3 4 2 6 7 4 2 3 9 5 3 2 3 9 100 1 7 400 3 3 2 5 100 2 9 2 500 3 2 9 5 Output 2 3 Input 4 3 1 1 1 2 1 3 1 4 10 4 1 2 3 4 20 4 1 2 3 4 30 4 1 2 3 4 Output 1 2 Input 1 5 9 9 8 7 6 5 4 3 2 1 3 4 1 2 3 4 1 4 5 6 7 8 4 4 1 3 5 7 1 4 2 4 6 8 5 4 1 9 2 8 Output 2 4 Submitted Solution: ``` print("") ```
instruction
0
44,676
9
89,352
No
output
1
44,676
9
89,353
Provide tags and a correct Python 3 solution for this coding contest problem. After a successful year of milk production, Farmer John is rewarding his cows with their favorite treat: tasty grass! On the field, there is a row of n units of grass, each with a sweetness s_i. Farmer John has m cows, each with a favorite sweetness f_i and a hunger value h_i. He would like to pick two disjoint subsets of cows to line up on the left and right side of the grass row. There is no restriction on how many cows must be on either side. The cows will be treated in the following manner: * The cows from the left and right side will take turns feeding in an order decided by Farmer John. * When a cow feeds, it walks towards the other end without changing direction and eats grass of its favorite sweetness until it eats h_i units. * The moment a cow eats h_i units, it will fall asleep there, preventing further cows from passing it from both directions. * If it encounters another sleeping cow or reaches the end of the grass row, it will get upset. Farmer John absolutely does not want any cows to get upset. Note that grass does not grow back. Also, to prevent cows from getting upset, not every cow has to feed since FJ can choose a subset of them. Surprisingly, FJ has determined that sleeping cows are the most satisfied. If FJ orders optimally, what is the maximum number of sleeping cows that can result, and how many ways can FJ choose the subset of cows on the left and right side to achieve that maximum number of sleeping cows (modulo 10^9+7)? The order in which FJ sends the cows does not matter as long as no cows get upset. Input The first line contains two integers n and m (1 ≀ n ≀ 5000, 1 ≀ m ≀ 5000) β€” the number of units of grass and the number of cows. The second line contains n integers s_1, s_2, …, s_n (1 ≀ s_i ≀ n) β€” the sweetness values of the grass. The i-th of the following m lines contains two integers f_i and h_i (1 ≀ f_i, h_i ≀ n) β€” the favorite sweetness and hunger value of the i-th cow. No two cows have the same hunger and favorite sweetness simultaneously. Output Output two integers β€” the maximum number of sleeping cows that can result and the number of ways modulo 10^9+7. Examples Input 5 2 1 1 1 1 1 1 2 1 3 Output 2 2 Input 5 2 1 1 1 1 1 1 2 1 4 Output 1 4 Input 3 2 2 3 2 3 1 2 1 Output 2 4 Input 5 1 1 1 1 1 1 2 5 Output 0 1 Note In the first example, FJ can line up the cows as follows to achieve 2 sleeping cows: * Cow 1 is lined up on the left side and cow 2 is lined up on the right side. * Cow 2 is lined up on the left side and cow 1 is lined up on the right side. In the second example, FJ can line up the cows as follows to achieve 1 sleeping cow: * Cow 1 is lined up on the left side. * Cow 2 is lined up on the left side. * Cow 1 is lined up on the right side. * Cow 2 is lined up on the right side. In the third example, FJ can line up the cows as follows to achieve 2 sleeping cows: * Cow 1 and 2 are lined up on the left side. * Cow 1 and 2 are lined up on the right side. * Cow 1 is lined up on the left side and cow 2 is lined up on the right side. * Cow 1 is lined up on the right side and cow 2 is lined up on the left side. In the fourth example, FJ cannot end up with any sleeping cows, so there will be no cows lined up on either side.
instruction
0
44,728
9
89,456
Tags: binary search, combinatorics, dp, greedy, implementation, math Correct Solution: ``` import sys input = sys.stdin.readline from itertools import accumulate mod=10**9+7 n,m=map(int,input().split()) G=list(map(int,input().split())) CP=[[0]*(n+1) for i in range(n+1)] for i in range(m): f,e=map(int,input().split()) CP[f][e]+=1 SUMCP=[] for i in range(n+1): SUMCP.append(list(accumulate(CP[i]))) SUM=[0]*(n+1) LAST=[] for g in G: LAST.append(g) SUM[g]+=1 MAX=0 ANS=0 PLUS=1 for j in range(n+1): if SUM[j]>0 and SUMCP[j][SUM[j]]>0: PLUS=PLUS*SUMCP[j][SUM[j]]%mod MAX+=1 ANS=PLUS MAX0=MAX def PLUSVALUE(j): PLUS=1 MAXC=0 if cr[j]>=num_g: if SUMCP[j][cr[j]]>1: MAXC+=1 PLUS=PLUS*(SUMCP[j][cr[j]]-1)%mod else: if SUMCP[j][cr[j]]>=1: MAXC+=1 PLUS=PLUS*SUMCP[j][cr[j]]%mod return PLUS,MAXC def OPLUSVALUE(j): PLUS=1 MAXC=0 x,y=LEFT[j],cr[j] if x>y: x,y=y,x if SUMCP[j][x]==SUMCP[j][y]==1: MAXC+=1 PLUS=PLUS*2%mod else: if SUMCP[j][x]>=1: MAXC+=2 PLUS=PLUS*SUMCP[j][x]*(SUMCP[j][y]-1)%mod elif SUMCP[j][y]>=1: MAXC+=1 PLUS=PLUS*SUMCP[j][y]%mod return PLUS,MAXC LEFT=[0]*(n+1) g=LAST[0] LEFT[g]+=1 num_g=LEFT[g] PLUS=CP[g][num_g] OPLUS=1 if CP[g][num_g]==0: flag=0 MAXC=0 else: flag=1 MAXC=1 cr=SUM cr[g]-=1 for j in range(n+1): if j==g: v,p_m=PLUSVALUE(g) PLUS=PLUS*v%mod MAXC+=p_m else: v,m=OPLUSVALUE(j) OPLUS=OPLUS*v%mod MAXC+=m if MAXC>MAX and flag==1: MAX=MAXC ANS=PLUS*OPLUS%mod elif MAXC==MAX and flag==1: ANS+=PLUS*OPLUS%mod if flag==1: MAXC-=1+p_m else: MAXC-=p_m for i in range(1,n): #print("!",i,MAX,MAXC,ANS) g=LAST[i] past_g=LAST[i-1] v0,m0=OPLUSVALUE(past_g) v2,m2=OPLUSVALUE(g) OPLUS=OPLUS*v0*pow(v2,mod-2,mod)%mod MAXC+=m0-m2 LEFT[g]+=1 num_g=LEFT[g] cr[g]-=1 #print(LEFT,cr,MAXC,PLUS,OPLUS) if CP[g][num_g]==0: continue else: PLUS=CP[g][num_g] MAXC+=1 v,p_m=PLUSVALUE(g) PLUS=PLUS*v%mod MAXC+=p_m if MAXC>MAX: MAX=MAXC ANS=PLUS*OPLUS%mod elif MAXC==MAX: ANS+=PLUS*OPLUS%mod #print(LEFT,cr,MAXC,PLUS,OPLUS) MAXC-=1+p_m print(MAX,ANS%mod) ```
output
1
44,728
9
89,457
Provide tags and a correct Python 3 solution for this coding contest problem. After a successful year of milk production, Farmer John is rewarding his cows with their favorite treat: tasty grass! On the field, there is a row of n units of grass, each with a sweetness s_i. Farmer John has m cows, each with a favorite sweetness f_i and a hunger value h_i. He would like to pick two disjoint subsets of cows to line up on the left and right side of the grass row. There is no restriction on how many cows must be on either side. The cows will be treated in the following manner: * The cows from the left and right side will take turns feeding in an order decided by Farmer John. * When a cow feeds, it walks towards the other end without changing direction and eats grass of its favorite sweetness until it eats h_i units. * The moment a cow eats h_i units, it will fall asleep there, preventing further cows from passing it from both directions. * If it encounters another sleeping cow or reaches the end of the grass row, it will get upset. Farmer John absolutely does not want any cows to get upset. Note that grass does not grow back. Also, to prevent cows from getting upset, not every cow has to feed since FJ can choose a subset of them. Surprisingly, FJ has determined that sleeping cows are the most satisfied. If FJ orders optimally, what is the maximum number of sleeping cows that can result, and how many ways can FJ choose the subset of cows on the left and right side to achieve that maximum number of sleeping cows (modulo 10^9+7)? The order in which FJ sends the cows does not matter as long as no cows get upset. Input The first line contains two integers n and m (1 ≀ n ≀ 5000, 1 ≀ m ≀ 5000) β€” the number of units of grass and the number of cows. The second line contains n integers s_1, s_2, …, s_n (1 ≀ s_i ≀ n) β€” the sweetness values of the grass. The i-th of the following m lines contains two integers f_i and h_i (1 ≀ f_i, h_i ≀ n) β€” the favorite sweetness and hunger value of the i-th cow. No two cows have the same hunger and favorite sweetness simultaneously. Output Output two integers β€” the maximum number of sleeping cows that can result and the number of ways modulo 10^9+7. Examples Input 5 2 1 1 1 1 1 1 2 1 3 Output 2 2 Input 5 2 1 1 1 1 1 1 2 1 4 Output 1 4 Input 3 2 2 3 2 3 1 2 1 Output 2 4 Input 5 1 1 1 1 1 1 2 5 Output 0 1 Note In the first example, FJ can line up the cows as follows to achieve 2 sleeping cows: * Cow 1 is lined up on the left side and cow 2 is lined up on the right side. * Cow 2 is lined up on the left side and cow 1 is lined up on the right side. In the second example, FJ can line up the cows as follows to achieve 1 sleeping cow: * Cow 1 is lined up on the left side. * Cow 2 is lined up on the left side. * Cow 1 is lined up on the right side. * Cow 2 is lined up on the right side. In the third example, FJ can line up the cows as follows to achieve 2 sleeping cows: * Cow 1 and 2 are lined up on the left side. * Cow 1 and 2 are lined up on the right side. * Cow 1 is lined up on the left side and cow 2 is lined up on the right side. * Cow 1 is lined up on the right side and cow 2 is lined up on the left side. In the fourth example, FJ cannot end up with any sleeping cows, so there will be no cows lined up on either side.
instruction
0
44,729
9
89,458
Tags: binary search, combinatorics, dp, greedy, implementation, math Correct Solution: ``` from sys import stdin, stdout import bisect at_dist = [] mx = [] cow = [] sums = [] m = [] res_p = 0 res_r = 1 def modInverse(a, m) : return power(a, m - 2, m) # To compute x^y under modulo m def power(x, y, m) : if (y == 0) : return 1 p = power(x, y // 2, m) % m p = (p * p) % m if(y % 2 == 0) : return p else : return ((x * p) % m) # Function to return gcd of a and b def gcd(a, b) : if (a == 0) : return b return gcd(b % a, a) def update(p, r): global res_p global res_r if p > res_p: res_p = p res_r = r elif p == res_p: res_r += r res_r = int(res_r % 1000000007) def set_way(f): right = bisect.bisect_right(cow[f],at_dist[f]) left = bisect.bisect_right(cow[f], mx[f] - at_dist[f]) mn = min(left, right) mul = right*left - mn plus = left + right if mul > 0: sums[f] = 2 m[f] = mul elif plus > 0: sums[f] = 1 m[f] = plus else: sums[f] = 0 m[f] = 1 def do_up(f): right = at_dist[f] b = bisect.bisect_right(cow[f],at_dist[f]) left = mx[f] - at_dist[f] if right >= left: b-=1 if b > 0: sums[f] = 2 m[f] = b else: sums[f] = 1 m[f] = 1 def main(): global res_p global res_r global mx n,M = list(map(int, stdin.readline().split())) grass = list(map(int, stdin.readline().split())) for i in range(n+1): at_dist.append(0) sums.append(0) m.append(0) cow.append([]) for i,x in enumerate(grass): at_dist[x] += 1 mx = list(at_dist) for _ in range(M): f,h = list(map(int, stdin.readline().split())) cow[f].append(h) for i in range(1,n+1): cow[i].sort() set_way(i) res_p += sums[i] res_r *= m[i] t_p = res_p t_r = res_r for i in range(n): f = grass[i] t_p -= sums[f] t_r = int(t_r* modInverse(m[f], 1000000007) % 1000000007) at_dist[f] -=1 left = mx[f] - at_dist[f] ii = bisect.bisect_left(cow[f], left) if ii < len(cow[f]) and cow[f][ii] == left: do_up(f) temp_p = t_p + sums[f] temp_r = t_r * m[f] update(temp_p, temp_r) set_way(f) t_p += sums[grass[i]] t_r = (t_r * m[grass[i]]) % 1000000007 stdout.write(str(res_p) + " " + str(int(res_r % 1000000007))) main() ```
output
1
44,729
9
89,459
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After a successful year of milk production, Farmer John is rewarding his cows with their favorite treat: tasty grass! On the field, there is a row of n units of grass, each with a sweetness s_i. Farmer John has m cows, each with a favorite sweetness f_i and a hunger value h_i. He would like to pick two disjoint subsets of cows to line up on the left and right side of the grass row. There is no restriction on how many cows must be on either side. The cows will be treated in the following manner: * The cows from the left and right side will take turns feeding in an order decided by Farmer John. * When a cow feeds, it walks towards the other end without changing direction and eats grass of its favorite sweetness until it eats h_i units. * The moment a cow eats h_i units, it will fall asleep there, preventing further cows from passing it from both directions. * If it encounters another sleeping cow or reaches the end of the grass row, it will get upset. Farmer John absolutely does not want any cows to get upset. Note that grass does not grow back. Also, to prevent cows from getting upset, not every cow has to feed since FJ can choose a subset of them. Surprisingly, FJ has determined that sleeping cows are the most satisfied. If FJ orders optimally, what is the maximum number of sleeping cows that can result, and how many ways can FJ choose the subset of cows on the left and right side to achieve that maximum number of sleeping cows (modulo 10^9+7)? The order in which FJ sends the cows does not matter as long as no cows get upset. Input The first line contains two integers n and m (1 ≀ n ≀ 5000, 1 ≀ m ≀ 5000) β€” the number of units of grass and the number of cows. The second line contains n integers s_1, s_2, …, s_n (1 ≀ s_i ≀ n) β€” the sweetness values of the grass. The i-th of the following m lines contains two integers f_i and h_i (1 ≀ f_i, h_i ≀ n) β€” the favorite sweetness and hunger value of the i-th cow. No two cows have the same hunger and favorite sweetness simultaneously. Output Output two integers β€” the maximum number of sleeping cows that can result and the number of ways modulo 10^9+7. Examples Input 5 2 1 1 1 1 1 1 2 1 3 Output 2 2 Input 5 2 1 1 1 1 1 1 2 1 4 Output 1 4 Input 3 2 2 3 2 3 1 2 1 Output 2 4 Input 5 1 1 1 1 1 1 2 5 Output 0 1 Note In the first example, FJ can line up the cows as follows to achieve 2 sleeping cows: * Cow 1 is lined up on the left side and cow 2 is lined up on the right side. * Cow 2 is lined up on the left side and cow 1 is lined up on the right side. In the second example, FJ can line up the cows as follows to achieve 1 sleeping cow: * Cow 1 is lined up on the left side. * Cow 2 is lined up on the left side. * Cow 1 is lined up on the right side. * Cow 2 is lined up on the right side. In the third example, FJ can line up the cows as follows to achieve 2 sleeping cows: * Cow 1 and 2 are lined up on the left side. * Cow 1 and 2 are lined up on the right side. * Cow 1 is lined up on the left side and cow 2 is lined up on the right side. * Cow 1 is lined up on the right side and cow 2 is lined up on the left side. In the fourth example, FJ cannot end up with any sleeping cows, so there will be no cows lined up on either side. Submitted Solution: ``` from sys import stdin, stdout import bisect at_dist = [] cow = [] def main(): n,m = list(map(int, stdin.readline().split())) grass = list(map(int, stdin.readline().split())) for i in range(n+1): at_dist.append([]) cow.append([]) for i,x in enumerate(grass): at_dist[x].append(i+1) for _ in range(m): f,h = list(map(int, stdin.readline().split())) cow[f].append(h) res = 1 sum = 0 for f in range(n+1): if cow[f]: cow[f].sort() if len(cow[f]) == 1 and cow[f][0] <= len(at_dist[f]): res *= 2 res %= 1000000007 sum += 1 continue elif len(cow[f]) == 1: continue mx = bisect.bisect_right(cow[f], len(at_dist[f])) if cow[f][0] + cow[f][1] > len(at_dist[f]): res *= 2*mx res %= 1000000007 sum += 1 continue right = mx-1 left = 0 temp_res = 0 while right > left: while right > left and cow[f][right] + cow[f][left] > len(at_dist[f]): right -= 1 while right > left and cow[f][right] + cow[f][left] <= len(at_dist[f]): left += 1 left -= 1 temp_res += (left+1) temp_res %= 1000000007 right -= 1 temp_res += right sum += 2 res *= (temp_res * 2) res %= 1000000007 stdout.write(str(sum) + " " + str(res)) main() ```
instruction
0
44,730
9
89,460
No
output
1
44,730
9
89,461
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After a successful year of milk production, Farmer John is rewarding his cows with their favorite treat: tasty grass! On the field, there is a row of n units of grass, each with a sweetness s_i. Farmer John has m cows, each with a favorite sweetness f_i and a hunger value h_i. He would like to pick two disjoint subsets of cows to line up on the left and right side of the grass row. There is no restriction on how many cows must be on either side. The cows will be treated in the following manner: * The cows from the left and right side will take turns feeding in an order decided by Farmer John. * When a cow feeds, it walks towards the other end without changing direction and eats grass of its favorite sweetness until it eats h_i units. * The moment a cow eats h_i units, it will fall asleep there, preventing further cows from passing it from both directions. * If it encounters another sleeping cow or reaches the end of the grass row, it will get upset. Farmer John absolutely does not want any cows to get upset. Note that grass does not grow back. Also, to prevent cows from getting upset, not every cow has to feed since FJ can choose a subset of them. Surprisingly, FJ has determined that sleeping cows are the most satisfied. If FJ orders optimally, what is the maximum number of sleeping cows that can result, and how many ways can FJ choose the subset of cows on the left and right side to achieve that maximum number of sleeping cows (modulo 10^9+7)? The order in which FJ sends the cows does not matter as long as no cows get upset. Input The first line contains two integers n and m (1 ≀ n ≀ 5000, 1 ≀ m ≀ 5000) β€” the number of units of grass and the number of cows. The second line contains n integers s_1, s_2, …, s_n (1 ≀ s_i ≀ n) β€” the sweetness values of the grass. The i-th of the following m lines contains two integers f_i and h_i (1 ≀ f_i, h_i ≀ n) β€” the favorite sweetness and hunger value of the i-th cow. No two cows have the same hunger and favorite sweetness simultaneously. Output Output two integers β€” the maximum number of sleeping cows that can result and the number of ways modulo 10^9+7. Examples Input 5 2 1 1 1 1 1 1 2 1 3 Output 2 2 Input 5 2 1 1 1 1 1 1 2 1 4 Output 1 4 Input 3 2 2 3 2 3 1 2 1 Output 2 4 Input 5 1 1 1 1 1 1 2 5 Output 0 1 Note In the first example, FJ can line up the cows as follows to achieve 2 sleeping cows: * Cow 1 is lined up on the left side and cow 2 is lined up on the right side. * Cow 2 is lined up on the left side and cow 1 is lined up on the right side. In the second example, FJ can line up the cows as follows to achieve 1 sleeping cow: * Cow 1 is lined up on the left side. * Cow 2 is lined up on the left side. * Cow 1 is lined up on the right side. * Cow 2 is lined up on the right side. In the third example, FJ can line up the cows as follows to achieve 2 sleeping cows: * Cow 1 and 2 are lined up on the left side. * Cow 1 and 2 are lined up on the right side. * Cow 1 is lined up on the left side and cow 2 is lined up on the right side. * Cow 1 is lined up on the right side and cow 2 is lined up on the left side. In the fourth example, FJ cannot end up with any sleeping cows, so there will be no cows lined up on either side. Submitted Solution: ``` n, m = map(int, input().strip().split()) s = list(map(int, input().strip().split())) v = [0] * n for i in s: v[i-1] += 1 c = [[] for i in range(n)] for i in range(m): f, h = map(int, input().strip().split()) c[f-1].append(h) u = [0] * n r = t = p = 0 for k in range(n): c[k].sort() i, j = 0, len(c[k]) - 1 while i < j: while i < j and c[k][i] + c[k][j] > v[k]: j -= 1 if i < j: u[k] += j-i i += 1 if u[k]: r += 2; p += 1 else: for i in c[k]: if i <= v[k]: u[k] += 1 if u[k]: r += 1; p += 1 print(r) a = pow(2, p, 1000000007) for i in u: if i: a *= i print(a % 1000000007) ```
instruction
0
44,731
9
89,462
No
output
1
44,731
9
89,463
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After a successful year of milk production, Farmer John is rewarding his cows with their favorite treat: tasty grass! On the field, there is a row of n units of grass, each with a sweetness s_i. Farmer John has m cows, each with a favorite sweetness f_i and a hunger value h_i. He would like to pick two disjoint subsets of cows to line up on the left and right side of the grass row. There is no restriction on how many cows must be on either side. The cows will be treated in the following manner: * The cows from the left and right side will take turns feeding in an order decided by Farmer John. * When a cow feeds, it walks towards the other end without changing direction and eats grass of its favorite sweetness until it eats h_i units. * The moment a cow eats h_i units, it will fall asleep there, preventing further cows from passing it from both directions. * If it encounters another sleeping cow or reaches the end of the grass row, it will get upset. Farmer John absolutely does not want any cows to get upset. Note that grass does not grow back. Also, to prevent cows from getting upset, not every cow has to feed since FJ can choose a subset of them. Surprisingly, FJ has determined that sleeping cows are the most satisfied. If FJ orders optimally, what is the maximum number of sleeping cows that can result, and how many ways can FJ choose the subset of cows on the left and right side to achieve that maximum number of sleeping cows (modulo 10^9+7)? The order in which FJ sends the cows does not matter as long as no cows get upset. Input The first line contains two integers n and m (1 ≀ n ≀ 5000, 1 ≀ m ≀ 5000) β€” the number of units of grass and the number of cows. The second line contains n integers s_1, s_2, …, s_n (1 ≀ s_i ≀ n) β€” the sweetness values of the grass. The i-th of the following m lines contains two integers f_i and h_i (1 ≀ f_i, h_i ≀ n) β€” the favorite sweetness and hunger value of the i-th cow. No two cows have the same hunger and favorite sweetness simultaneously. Output Output two integers β€” the maximum number of sleeping cows that can result and the number of ways modulo 10^9+7. Examples Input 5 2 1 1 1 1 1 1 2 1 3 Output 2 2 Input 5 2 1 1 1 1 1 1 2 1 4 Output 1 4 Input 3 2 2 3 2 3 1 2 1 Output 2 4 Input 5 1 1 1 1 1 1 2 5 Output 0 1 Note In the first example, FJ can line up the cows as follows to achieve 2 sleeping cows: * Cow 1 is lined up on the left side and cow 2 is lined up on the right side. * Cow 2 is lined up on the left side and cow 1 is lined up on the right side. In the second example, FJ can line up the cows as follows to achieve 1 sleeping cow: * Cow 1 is lined up on the left side. * Cow 2 is lined up on the left side. * Cow 1 is lined up on the right side. * Cow 2 is lined up on the right side. In the third example, FJ can line up the cows as follows to achieve 2 sleeping cows: * Cow 1 and 2 are lined up on the left side. * Cow 1 and 2 are lined up on the right side. * Cow 1 is lined up on the left side and cow 2 is lined up on the right side. * Cow 1 is lined up on the right side and cow 2 is lined up on the left side. In the fourth example, FJ cannot end up with any sleeping cows, so there will be no cows lined up on either side. Submitted Solution: ``` import sys input = sys.stdin.readline from itertools import accumulate mod=10**9+7 n,m=map(int,input().split()) G=list(map(int,input().split())) CP=[[0]*(n+1) for i in range(n+1)] for i in range(m): f,e=map(int,input().split()) CP[f][e]+=1 SUMCP=[] for i in range(n+1): SUMCP.append(list(accumulate(CP[i]))) SUM=[0]*(n+1) LAST=[] for g in G: LAST.append(g) SUM[g]+=1 MAX=0 ANS=0 PLUS=1 for j in range(n+1): if SUM[j]>0 and SUMCP[j][SUM[j]]>0: PLUS=PLUS*SUMCP[j][SUM[j]]%mod MAX+=1 ANS=PLUS MAX0=MAX def PLUSVALUE(j): PLUS=1 MAXC=0 if cr[j]>=num_g: if SUMCP[j][cr[j]]>1: MAXC+=1 PLUS=PLUS*(SUMCP[j][cr[j]]-1)%mod else: if SUMCP[j][cr[j]]>=1: MAXC+=1 PLUS=PLUS*SUMCP[j][cr[j]]%mod return PLUS,MAXC def OPLUSVALUE(j): PLUS=1 MAXC=0 x,y=LEFT[j],cr[j] if x>y: x,y=y,x if SUMCP[j][x]==SUMCP[j][y]==1: MAXC+=1 PLUS=PLUS*2%mod else: if SUMCP[j][x]>=1: MAXC+=2 PLUS=PLUS*SUMCP[j][x]*(SUMCP[j][y]-1)%mod elif SUMCP[j][y]>=1: MAXC+=1 PLUS=PLUS*SUMCP[j][y]%mod return PLUS,MAXC LEFT=[0]*(n+1) g=LAST[0] LEFT[g]+=1 num_g=LEFT[g] PLUS=CP[g][num_g] OPLUS=1 if CP[g][num_g]==0: flag=0 MAXC=0 else: flag=1 MAXC=1 cr=SUM cr[g]-=1 for j in range(n+1): if j==g: v,p_m=PLUSVALUE(g) PLUS=PLUS*v%mod MAXC+=m else: v,m=OPLUSVALUE(j) OPLUS=OPLUS*v%mod MAXC+=m if MAXC>MAX and flag==1: MAX=MAXC ANS=PLUS*OPLUS%mod MAXC-=1+p_m elif MAXC==MAX and flag==1: ANS+=PLUS*OPLUS%mod MAXC-=1+p_m for i in range(1,n): #print("!",i,MAX,MAXC,ANS) g=LAST[i] past_g=LAST[i-1] v0,m0=OPLUSVALUE(past_g) v2,m2=OPLUSVALUE(g) OPLUS=OPLUS*v0*pow(v2,mod-2,mod)%mod MAXC+=m0-m2 LEFT[g]+=1 num_g=LEFT[g] cr[g]-=1 #print(LEFT,cr,MAXC,PLUS,OPLUS) if CP[g][num_g]==0: continue else: PLUS=CP[g][num_g] MAXC+=1 v,p_m=PLUSVALUE(g) PLUS=PLUS*v%mod MAXC+=p_m if MAXC>MAX: MAX=MAXC ANS=PLUS*OPLUS%mod elif MAXC==MAX: ANS+=PLUS*OPLUS%mod #print(LEFT,cr,MAXC,PLUS,OPLUS) MAXC-=1+p_m print(MAX,ANS%mod) ```
instruction
0
44,732
9
89,464
No
output
1
44,732
9
89,465
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After a successful year of milk production, Farmer John is rewarding his cows with their favorite treat: tasty grass! On the field, there is a row of n units of grass, each with a sweetness s_i. Farmer John has m cows, each with a favorite sweetness f_i and a hunger value h_i. He would like to pick two disjoint subsets of cows to line up on the left and right side of the grass row. There is no restriction on how many cows must be on either side. The cows will be treated in the following manner: * The cows from the left and right side will take turns feeding in an order decided by Farmer John. * When a cow feeds, it walks towards the other end without changing direction and eats grass of its favorite sweetness until it eats h_i units. * The moment a cow eats h_i units, it will fall asleep there, preventing further cows from passing it from both directions. * If it encounters another sleeping cow or reaches the end of the grass row, it will get upset. Farmer John absolutely does not want any cows to get upset. Note that grass does not grow back. Also, to prevent cows from getting upset, not every cow has to feed since FJ can choose a subset of them. Surprisingly, FJ has determined that sleeping cows are the most satisfied. If FJ orders optimally, what is the maximum number of sleeping cows that can result, and how many ways can FJ choose the subset of cows on the left and right side to achieve that maximum number of sleeping cows (modulo 10^9+7)? The order in which FJ sends the cows does not matter as long as no cows get upset. Input The first line contains two integers n and m (1 ≀ n ≀ 5000, 1 ≀ m ≀ 5000) β€” the number of units of grass and the number of cows. The second line contains n integers s_1, s_2, …, s_n (1 ≀ s_i ≀ n) β€” the sweetness values of the grass. The i-th of the following m lines contains two integers f_i and h_i (1 ≀ f_i, h_i ≀ n) β€” the favorite sweetness and hunger value of the i-th cow. No two cows have the same hunger and favorite sweetness simultaneously. Output Output two integers β€” the maximum number of sleeping cows that can result and the number of ways modulo 10^9+7. Examples Input 5 2 1 1 1 1 1 1 2 1 3 Output 2 2 Input 5 2 1 1 1 1 1 1 2 1 4 Output 1 4 Input 3 2 2 3 2 3 1 2 1 Output 2 4 Input 5 1 1 1 1 1 1 2 5 Output 0 1 Note In the first example, FJ can line up the cows as follows to achieve 2 sleeping cows: * Cow 1 is lined up on the left side and cow 2 is lined up on the right side. * Cow 2 is lined up on the left side and cow 1 is lined up on the right side. In the second example, FJ can line up the cows as follows to achieve 1 sleeping cow: * Cow 1 is lined up on the left side. * Cow 2 is lined up on the left side. * Cow 1 is lined up on the right side. * Cow 2 is lined up on the right side. In the third example, FJ can line up the cows as follows to achieve 2 sleeping cows: * Cow 1 and 2 are lined up on the left side. * Cow 1 and 2 are lined up on the right side. * Cow 1 is lined up on the left side and cow 2 is lined up on the right side. * Cow 1 is lined up on the right side and cow 2 is lined up on the left side. In the fourth example, FJ cannot end up with any sleeping cows, so there will be no cows lined up on either side. Submitted Solution: ``` import sys from collections import Counter, defaultdict def fact(n): ret = 1 for i in range(1, n + 1): ret *= i return ret def solve(N, M, A, FH): counts = Counter(A) cowByKey = defaultdict(list) for f, h in FH: cowByKey[f].append(h) MOD = (10 ** 9) + 7 totCount = 0 tot = 0 for k, v in cowByKey.items(): v = sorted(v) cum = 0 count = 0 for x in v: if cum + x > counts[k]: break cum += x count += 1 if counts[k] - cum == 0: ways = 2 else: ways = 4 totCount += count if tot == 0: tot = ways % MOD else: tot = (tot * ways) % MOD return str(totCount) + " " + str(tot % MOD) if __name__ == "__main__": input = sys.stdin.readline N, M = map(int, input().split()) A = [int(x) for x in input().split()] FH = [] for i in range(M): FH.append([int(x) for x in input().split()]) ans = solve(N, M, A, FH) print(ans) ```
instruction
0
44,733
9
89,466
No
output
1
44,733
9
89,467
Provide tags and a correct Python 3 solution for this coding contest problem. When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were n dishes. Kefa knows that he needs exactly m dishes. But at that, he doesn't want to order the same dish twice to taste as many dishes as possible. Kefa knows that the i-th dish gives him ai units of satisfaction. But some dishes do not go well together and some dishes go very well together. Kefa set to himself k rules of eating food of the following type β€” if he eats dish x exactly before dish y (there should be no other dishes between x and y), then his satisfaction level raises by c. Of course, our parrot wants to get some maximal possible satisfaction from going to the restaurant. Help him in this hard task! Input The first line of the input contains three space-separated numbers, n, m and k (1 ≀ m ≀ n ≀ 18, 0 ≀ k ≀ n * (n - 1)) β€” the number of dishes on the menu, the number of portions Kefa needs to eat to get full and the number of eating rules. The second line contains n space-separated numbers ai, (0 ≀ ai ≀ 109) β€” the satisfaction he gets from the i-th dish. Next k lines contain the rules. The i-th rule is described by the three numbers xi, yi and ci (1 ≀ xi, yi ≀ n, 0 ≀ ci ≀ 109). That means that if you eat dish xi right before dish yi, then the Kefa's satisfaction increases by ci. It is guaranteed that there are no such pairs of indexes i and j (1 ≀ i < j ≀ k), that xi = xj and yi = yj. Output In the single line of the output print the maximum satisfaction that Kefa can get from going to the restaurant. Examples Input 2 2 1 1 1 2 1 1 Output 3 Input 4 3 2 1 2 3 4 2 1 5 3 4 2 Output 12 Note In the first sample it is best to first eat the second dish, then the first one. Then we get one unit of satisfaction for each dish and plus one more for the rule. In the second test the fitting sequences of choice are 4 2 1 or 2 1 4. In both cases we get satisfaction 7 for dishes and also, if we fulfill rule 1, we get an additional satisfaction 5.
instruction
0
45,763
9
91,526
Tags: bitmasks, dp Correct Solution: ``` import sys from array import array # noqa: F401 import typing as Tp # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') def output(*args): sys.stdout.buffer.write( ('\n'.join(map(str, args)) + '\n').encode('utf-8') ) def main(): n, m, k = map(int, input().split()) a = list(map(float, input().split())) add = [[0] * n for _ in range(n + 1)] for xi, yi, ci in (map(int, input().split()) for _ in range(k)): add[xi - 1][yi - 1] = float(ci) minf = float('-inf') dp = [[minf] * (2**n) for _ in range(n + 1)] dp[n][0] = 0.0 for bitset in range(2**n): if bin(bitset).count('1') >= m: continue for i in range(n + 1): if dp[i][bitset] == minf: continue for j in range(n): if (1 << j) & bitset: continue dp[j][bitset | (1 << j)] = max( dp[j][bitset | (1 << j)], dp[i][bitset] + a[j] + add[i][j] ) print(int(max(max(_dp) for _dp in dp) + 1e-7)) if __name__ == '__main__': main() ```
output
1
45,763
9
91,527