message stringlengths 2 65.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 0 108k | cluster float64 14 14 | __index_level_0__ int64 0 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.
Each customer is characterized by three values: t_i β the time (in minutes) when the i-th customer visits the restaurant, l_i β the lower bound of their preferred temperature range, and h_i β the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.
Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.
Input
Each test contains one or more test cases. The first line contains the number of test cases q (1 β€ q β€ 500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 β€ n β€ 100, -10^9 β€ m β€ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 β€ t_i β€ 10^9, -10^9 β€ l_i β€ h_i β€ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0.
Output
For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Output
YES
NO
YES
NO
Note
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
* At 0-th minute, change the state to heating (the temperature is 0).
* At 2-nd minute, change the state to off (the temperature is 2).
* At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
* At 6-th minute, change the state to off (the temperature is 3).
* At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
* At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied. | instruction | 0 | 33,483 | 14 | 66,966 |
Tags: dp, greedy, implementation, sortings, two pointers
Correct Solution:
```
import math
import collections
import sys
def inpu():
return input().split(' ')
def inti(a):
for i in range(len(a)):
a[i] = int(a[i])
return a
def inp():
a = inpu()
a = inti(a)
return a
def solution():
n, m = map(int, input().split())
li = []
for i in range(n):
r = list(map(int, input().split()))
li.append(r)
minm = m
maxm = m
flag = 0
last = 0
for i in range(n):
l = li[i][1]
r = li[i][2]
t = li[i][0]
last, t = t, t - last
if r >= minm - t and l <= maxm + t:
minm = max(l, minm - t)
maxm = min(maxm + t, r)
else:
flag = 1
break
if flag:
print("NO")
else:
print("YES")
for _ in range(int(input())):
solution()
``` | output | 1 | 33,483 | 14 | 66,967 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.
Each customer is characterized by three values: t_i β the time (in minutes) when the i-th customer visits the restaurant, l_i β the lower bound of their preferred temperature range, and h_i β the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.
Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.
Input
Each test contains one or more test cases. The first line contains the number of test cases q (1 β€ q β€ 500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 β€ n β€ 100, -10^9 β€ m β€ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 β€ t_i β€ 10^9, -10^9 β€ l_i β€ h_i β€ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0.
Output
For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Output
YES
NO
YES
NO
Note
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
* At 0-th minute, change the state to heating (the temperature is 0).
* At 2-nd minute, change the state to off (the temperature is 2).
* At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
* At 6-th minute, change the state to off (the temperature is 3).
* At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
* At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied. | instruction | 0 | 33,484 | 14 | 66,968 |
Tags: dp, greedy, implementation, sortings, two pointers
Correct Solution:
```
from sys import stdin, stdout
def takeSec(elem):
return elem[0]
def in_inter(ref, test):
if ref[1] >= test[0] and test[1] >= ref[0]: return True
else: return False
q = int(input())
for i in range(q):
n,m = map(int,input().split())
possible = True
visit = []
for j in range(n):
visit.append(list(map(int,input().split())))
visit.sort(key=takeSec)
current_interval = [m-visit[0][0], m+visit[0][0]]
last_t = 0
for v in range(len(visit)):
if in_inter(current_interval, [visit[v][1], visit[v][2]]):
current_interval = [max(current_interval[0], visit[v][1]), min(current_interval[1], visit[v][2])]
else:
possible = False
break
if v < len(visit)-1:
current_interval = [current_interval[0]-visit[v+1][0]+visit[v][0], current_interval[1]+visit[v+1][0]-visit[v][0]]
if possible: print("YES")
else: print("NO")
``` | output | 1 | 33,484 | 14 | 66,969 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.
Each customer is characterized by three values: t_i β the time (in minutes) when the i-th customer visits the restaurant, l_i β the lower bound of their preferred temperature range, and h_i β the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.
Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.
Input
Each test contains one or more test cases. The first line contains the number of test cases q (1 β€ q β€ 500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 β€ n β€ 100, -10^9 β€ m β€ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 β€ t_i β€ 10^9, -10^9 β€ l_i β€ h_i β€ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0.
Output
For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Output
YES
NO
YES
NO
Note
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
* At 0-th minute, change the state to heating (the temperature is 0).
* At 2-nd minute, change the state to off (the temperature is 2).
* At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
* At 6-th minute, change the state to off (the temperature is 3).
* At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
* At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied. | instruction | 0 | 33,485 | 14 | 66,970 |
Tags: dp, greedy, implementation, sortings, two pointers
Correct Solution:
```
t1=int(input())
for i2 in range(t1):
n,m=map(int,input().split())
up,down,tb=m,m,0
ans=1
for i in range(n):
t,l,h=map(int,input().split())
tx=t-tb
up+=tx
down-=tx
if down>h or up<l:
ans=0
up=min(h,up)
down=max(l,down)
tb=t
if ans==0:
print("NO")
else:
print("YES")
``` | output | 1 | 33,485 | 14 | 66,971 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.
Each customer is characterized by three values: t_i β the time (in minutes) when the i-th customer visits the restaurant, l_i β the lower bound of their preferred temperature range, and h_i β the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.
Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.
Input
Each test contains one or more test cases. The first line contains the number of test cases q (1 β€ q β€ 500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 β€ n β€ 100, -10^9 β€ m β€ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 β€ t_i β€ 10^9, -10^9 β€ l_i β€ h_i β€ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0.
Output
For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Output
YES
NO
YES
NO
Note
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
* At 0-th minute, change the state to heating (the temperature is 0).
* At 2-nd minute, change the state to off (the temperature is 2).
* At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
* At 6-th minute, change the state to off (the temperature is 3).
* At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
* At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied. | instruction | 0 | 33,486 | 14 | 66,972 |
Tags: dp, greedy, implementation, sortings, two pointers
Correct Solution:
```
for q in range(int(input())):
res = 'YES'
time = 0
n,tmp = map(int,input().split())
tmp = [tmp,tmp]
for i in range(n):
ti,li,hi = map(int, input().split())
yy = ti - time
aa=[tmp[0] - yy, tmp[0] + yy,tmp[1] - yy, tmp[1] + yy]
make = [min(aa), max(aa)]
if(li>make[1] or hi < make[0]):
res = 'NO'
tmp = [max(li,make[0]),min(hi,make[1])]
time = ti
print(res)
``` | output | 1 | 33,486 | 14 | 66,973 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.
Each customer is characterized by three values: t_i β the time (in minutes) when the i-th customer visits the restaurant, l_i β the lower bound of their preferred temperature range, and h_i β the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.
Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.
Input
Each test contains one or more test cases. The first line contains the number of test cases q (1 β€ q β€ 500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 β€ n β€ 100, -10^9 β€ m β€ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 β€ t_i β€ 10^9, -10^9 β€ l_i β€ h_i β€ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0.
Output
For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Output
YES
NO
YES
NO
Note
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
* At 0-th minute, change the state to heating (the temperature is 0).
* At 2-nd minute, change the state to off (the temperature is 2).
* At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
* At 6-th minute, change the state to off (the temperature is 3).
* At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
* At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied. | instruction | 0 | 33,487 | 14 | 66,974 |
Tags: dp, greedy, implementation, sortings, two pointers
Correct Solution:
```
for _ in range(int(input())):
n,m=map(int, input().split())
low=m
hi=m
prev=0
f=0
for i in range(n):
t,l,h=map(int, input().split())
low-=(t-prev)
hi+=(t-prev)
#print(low,hi)
if h<low or l>hi:
f=1
low=max(low, l)
hi=min(hi, h)
prev=t
if low>hi:
f=1
if f:
print('NO')
else:
print('YES')
``` | output | 1 | 33,487 | 14 | 66,975 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.
Each customer is characterized by three values: t_i β the time (in minutes) when the i-th customer visits the restaurant, l_i β the lower bound of their preferred temperature range, and h_i β the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.
Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.
Input
Each test contains one or more test cases. The first line contains the number of test cases q (1 β€ q β€ 500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 β€ n β€ 100, -10^9 β€ m β€ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 β€ t_i β€ 10^9, -10^9 β€ l_i β€ h_i β€ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0.
Output
For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Output
YES
NO
YES
NO
Note
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
* At 0-th minute, change the state to heating (the temperature is 0).
* At 2-nd minute, change the state to off (the temperature is 2).
* At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
* At 6-th minute, change the state to off (the temperature is 3).
* At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
* At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied. | instruction | 0 | 33,488 | 14 | 66,976 |
Tags: dp, greedy, implementation, sortings, two pointers
Correct Solution:
```
cases = int(input())
for _ in range(cases):
n,temp = [int(i) for i in input().split(" ")]
time = 0
minTemp = temp
maxTemp = temp
ok = True
for _ in range(n):
cTime,cMin,cMax = [int(i) for i in input().split(" ")]
if not ok:
continue
deltaTime = cTime-time
if cMin > minTemp:
minTemp += deltaTime
if minTemp > cMin:
minTemp = cMin
elif cMin < minTemp:
minTemp -= deltaTime
if cMax > maxTemp:
maxTemp += deltaTime
elif cMax < maxTemp:
maxTemp -= deltaTime
if maxTemp < cMax:
maxTemp = cMax
if not ((cMin <=maxTemp and cMin >= minTemp) or (cMax <=maxTemp and cMax >= minTemp)
or (minTemp <= cMax and minTemp >= cMin) or (maxTemp <= cMax and maxTemp >= cMin)):
print("NO")
ok = False
if minTemp < cMin:
minTemp = cMin
if maxTemp > cMax:
maxTemp = cMax
time = cTime
# print('@', cTime, minTemp, maxTemp)
if(ok):
print("YES")
pass
``` | output | 1 | 33,488 | 14 | 66,977 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.
Each customer is characterized by three values: t_i β the time (in minutes) when the i-th customer visits the restaurant, l_i β the lower bound of their preferred temperature range, and h_i β the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.
Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.
Input
Each test contains one or more test cases. The first line contains the number of test cases q (1 β€ q β€ 500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 β€ n β€ 100, -10^9 β€ m β€ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 β€ t_i β€ 10^9, -10^9 β€ l_i β€ h_i β€ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0.
Output
For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Output
YES
NO
YES
NO
Note
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
* At 0-th minute, change the state to heating (the temperature is 0).
* At 2-nd minute, change the state to off (the temperature is 2).
* At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
* At 6-th minute, change the state to off (the temperature is 3).
* At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
* At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied. | instruction | 0 | 33,489 | 14 | 66,978 |
Tags: dp, greedy, implementation, sortings, two pointers
Correct Solution:
```
import sys
input = sys.stdin.readline
for nt in range(int(input())):
n,m=map(int,input().split())
cus = []
for i in range(n):
cus.append(list(map(int,input().split())))
l,e=m,m
p=0
ans="YES"
for i in range(n):
l-=(cus[i][0]-p)
e+=(cus[i][0]-p)
l=(max(l,cus[i][1]))
e=(min(e,cus[i][2]))
p=cus[i][0]
if e<l:
ans="NO"
break
print (ans)
``` | output | 1 | 33,489 | 14 | 66,979 |
Provide tags and a correct Python 2 solution for this coding contest problem.
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.
Each customer is characterized by three values: t_i β the time (in minutes) when the i-th customer visits the restaurant, l_i β the lower bound of their preferred temperature range, and h_i β the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.
Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.
Input
Each test contains one or more test cases. The first line contains the number of test cases q (1 β€ q β€ 500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 β€ n β€ 100, -10^9 β€ m β€ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 β€ t_i β€ 10^9, -10^9 β€ l_i β€ h_i β€ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0.
Output
For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Output
YES
NO
YES
NO
Note
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
* At 0-th minute, change the state to heating (the temperature is 0).
* At 2-nd minute, change the state to off (the temperature is 2).
* At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
* At 6-th minute, change the state to off (the temperature is 3).
* At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
* At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied. | instruction | 0 | 33,490 | 14 | 66,980 |
Tags: dp, greedy, implementation, sortings, two pointers
Correct Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
from fractions import gcd
import heapq
raw_input = stdin.readline
pr = stdout.write
mod=998244353
def ni():
return int(raw_input())
def li():
return list(map(int,raw_input().split()))
def pn(n):
stdout.write(str(n)+'\n')
def pa(arr):
pr(' '.join(map(str,arr))+'\n')
# fast read function for total integer input
def inp():
# this function returns whole input of
# space/line seperated integers
# Use Ctrl+D to flush stdin.
return tuple(map(int,stdin.read().split()))
range = xrange # not for python 3.0+
# main code
for t in range(ni()):
n,m=li()
arr=[]
for i in range(n):
arr.append(li())
mn=m
mx=m
prev=0
f=0
for i in range(n):
k=arr[i][0]-prev
mn=mn-k
mx=mx+k
if not (mx<arr[i][1] or mn>arr[i][2]):
mn=max(arr[i][1],mn)
mx=min(arr[i][2],mx)
prev=arr[i][0]
else:
f=1
break
if f:
pr('NO\n')
else:
pr('YES\n')
``` | output | 1 | 33,490 | 14 | 66,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.
Each customer is characterized by three values: t_i β the time (in minutes) when the i-th customer visits the restaurant, l_i β the lower bound of their preferred temperature range, and h_i β the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.
Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.
Input
Each test contains one or more test cases. The first line contains the number of test cases q (1 β€ q β€ 500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 β€ n β€ 100, -10^9 β€ m β€ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 β€ t_i β€ 10^9, -10^9 β€ l_i β€ h_i β€ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0.
Output
For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Output
YES
NO
YES
NO
Note
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
* At 0-th minute, change the state to heating (the temperature is 0).
* At 2-nd minute, change the state to off (the temperature is 2).
* At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
* At 6-th minute, change the state to off (the temperature is 3).
* At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
* At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied.
Submitted Solution:
```
import sys
import math
import itertools
import functools
import collections
import operator
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p * p <= n:
if prime[p]:
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 2
r = [2]
for p in range(3, n + 1, 2):
if prime[p]:
r.append(p)
return r
def divs(n, start=2):
r = []
for i in range(start, int(math.sqrt(n) + 1)):
if (n % i == 0):
if (n / i == i):
r.append(i)
else:
r.extend([i, n // i])
return r
def divn(n, primes):
divs_number = 1
for i in primes:
if n == 1:
return divs_number
t = 1
while n % i == 0:
t += 1
n //= i
divs_number *= t
def prime(n):
if n == 2: return True
if n % 2 == 0 or n <= 1: return False
sqr = int(math.sqrt(n)) + 1
for d in range(3, sqr, 2):
if n % d == 0: return False
return True
def convn(number, base):
newnumber = 0
while number > 0:
newnumber += number % base
number //= base
return newnumber
def cdiv(n, k): return n // k + (n % k != 0)
t = ii()
for _ in range(t):
n, m = mi()
p = []
for i in range(n):
p.append(li())
min_ = max_ = m
dt = 0
for item in p:
max_ += item[0] - dt
min_ -= item[0] - dt
if min_ > item[2] or item[1] > max_:
print('NO')
break
min_ = max(min_, item[1])
max_ = min(max_, item[2])
dt = item[0]
else:
print('YES')
``` | instruction | 0 | 33,491 | 14 | 66,982 |
Yes | output | 1 | 33,491 | 14 | 66,983 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.
Each customer is characterized by three values: t_i β the time (in minutes) when the i-th customer visits the restaurant, l_i β the lower bound of their preferred temperature range, and h_i β the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.
Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.
Input
Each test contains one or more test cases. The first line contains the number of test cases q (1 β€ q β€ 500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 β€ n β€ 100, -10^9 β€ m β€ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 β€ t_i β€ 10^9, -10^9 β€ l_i β€ h_i β€ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0.
Output
For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Output
YES
NO
YES
NO
Note
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
* At 0-th minute, change the state to heating (the temperature is 0).
* At 2-nd minute, change the state to off (the temperature is 2).
* At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
* At 6-th minute, change the state to off (the temperature is 3).
* At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
* At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied.
Submitted Solution:
```
n = int(input())
for i in range(n):
x, y = map(int, input().split())
mi , ma = y ,y
p =0
al = 0
for j in range(x):
a , b, c = map(int, input().split())
mi -= a - al
ma += a - al
if (mi >= b and mi <= c):
if(ma > c): ma = c
elif (ma >= b and ma <= c):
if (mi < b): mi = b
elif(ma >= c and mi <= b):
mi = b
ma = c
else: p = 1
al = a
if p == 0: print("YES")
else:print("NO")
``` | instruction | 0 | 33,492 | 14 | 66,984 |
Yes | output | 1 | 33,492 | 14 | 66,985 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.
Each customer is characterized by three values: t_i β the time (in minutes) when the i-th customer visits the restaurant, l_i β the lower bound of their preferred temperature range, and h_i β the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.
Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.
Input
Each test contains one or more test cases. The first line contains the number of test cases q (1 β€ q β€ 500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 β€ n β€ 100, -10^9 β€ m β€ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 β€ t_i β€ 10^9, -10^9 β€ l_i β€ h_i β€ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0.
Output
For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Output
YES
NO
YES
NO
Note
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
* At 0-th minute, change the state to heating (the temperature is 0).
* At 2-nd minute, change the state to off (the temperature is 2).
* At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
* At 6-th minute, change the state to off (the temperature is 3).
* At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
* At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied.
Submitted Solution:
```
z=int(input())
while z:
z-=1
n,m=map(int,input().strip().split(' '))
l=[]
for _ in range(n):
l.append(list(map(int,input().strip().split(' '))))
start=m
end=m
t=0
flag=False
for i in l:
d=i[0]-t
t=i[0]
start+=d
end-=d
if start>=i[2] and end<=i[2]:
start=i[2]
if start>=i[1] and end<=i[1]:
end=i[1]
if start>i[2] or start<i[1]:
flag=True
break
if flag:
print('NO')
else:
print('YES')
``` | instruction | 0 | 33,493 | 14 | 66,986 |
Yes | output | 1 | 33,493 | 14 | 66,987 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.
Each customer is characterized by three values: t_i β the time (in minutes) when the i-th customer visits the restaurant, l_i β the lower bound of their preferred temperature range, and h_i β the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.
Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.
Input
Each test contains one or more test cases. The first line contains the number of test cases q (1 β€ q β€ 500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 β€ n β€ 100, -10^9 β€ m β€ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 β€ t_i β€ 10^9, -10^9 β€ l_i β€ h_i β€ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0.
Output
For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Output
YES
NO
YES
NO
Note
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
* At 0-th minute, change the state to heating (the temperature is 0).
* At 2-nd minute, change the state to off (the temperature is 2).
* At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
* At 6-th minute, change the state to off (the temperature is 3).
* At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
* At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied.
Submitted Solution:
```
import os
from io import BytesIO, IOBase
import sys
import math
from math import ceil
from collections import Counter
def main():
for t in range(int(input())):
ans = "YES"
n, m = map(int, input().split())
l, r = m, m
tt=0
for i in range(n):
t, x, y = map(int, input().split())
if ans == "YES":
l-=(t-tt)
r+=(t-tt)
if y>=l and x<=r:
l=max(l,x)
r=min(r,y)
else:
ans="NO"
tt=t
print(ans)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
``` | instruction | 0 | 33,494 | 14 | 66,988 |
Yes | output | 1 | 33,494 | 14 | 66,989 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.
Each customer is characterized by three values: t_i β the time (in minutes) when the i-th customer visits the restaurant, l_i β the lower bound of their preferred temperature range, and h_i β the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.
Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.
Input
Each test contains one or more test cases. The first line contains the number of test cases q (1 β€ q β€ 500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 β€ n β€ 100, -10^9 β€ m β€ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 β€ t_i β€ 10^9, -10^9 β€ l_i β€ h_i β€ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0.
Output
For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Output
YES
NO
YES
NO
Note
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
* At 0-th minute, change the state to heating (the temperature is 0).
* At 2-nd minute, change the state to off (the temperature is 2).
* At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
* At 6-th minute, change the state to off (the temperature is 3).
* At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
* At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied.
Submitted Solution:
```
for tci in range(int(input())):
n, m = [int(x) for x in input().split()]
pmini, pmax, pti = m, m, 0
ca = [(pti, pmini, pmax)]
for ni in range(n):
ti, li, hi = [int(x) for x in input().split()]
if(ti == ca[-1][0]):
cli = ca.pop()
cni = (ti, max(cli[1], li), min(cli[2], hi))
if cni[2]<cni[1]:
print("NO")
break
else:
ca.append(cni)
else:
ca.append((ti, li, hi))
else:
#print(ca)
pti, pmini, pmax = ca[0]
for ci in ca[1:]:
ti, li, hi = ci
pmini = max(li, pmini - abs(ti - pti))
pmax = min(hi, pmax + abs(ti - pti))
if(not((li>=pmini and li<=pmax) or (hi>=pmini and hi<=pmax))):
print("NO")
break
pti = ti
else:
print("YES")
``` | instruction | 0 | 33,495 | 14 | 66,990 |
No | output | 1 | 33,495 | 14 | 66,991 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.
Each customer is characterized by three values: t_i β the time (in minutes) when the i-th customer visits the restaurant, l_i β the lower bound of their preferred temperature range, and h_i β the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.
Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.
Input
Each test contains one or more test cases. The first line contains the number of test cases q (1 β€ q β€ 500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 β€ n β€ 100, -10^9 β€ m β€ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 β€ t_i β€ 10^9, -10^9 β€ l_i β€ h_i β€ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0.
Output
For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Output
YES
NO
YES
NO
Note
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
* At 0-th minute, change the state to heating (the temperature is 0).
* At 2-nd minute, change the state to off (the temperature is 2).
* At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
* At 6-th minute, change the state to off (the temperature is 3).
* At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
* At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied.
Submitted Solution:
```
for _ in range(int(input())):
n,t = map(int,input().split(' '))
ini = [t,t]
initime = 0
L = []
H = []
T = []
for _ in range(n):
time,l,h = map(int,input().split(' '))
T.append(time)
L.append(l)
H.append(h)
f = 0
for i in range(len(T)):
time = T[i]
l = L[i]
h = H[i]
ini = [ini[0]-(time-initime),ini[1]+(time-initime)]
#print(ini)
if l<ini[0]:
if h<ini[0]:
f = 1
if h>ini[1]:
ini = [ini[0],ini[1]]
f = 0
if h>=ini[0] or h<=ini[1]:
ini = [ini[0],h]
elif l>ini[1]:
f = 1
else:
if h>ini[1]:
ini = [l,ini[1]]
if h<ini[1]:
ini = [l,h]
if h==ini[1]:
ini = [l,ini[1]]
#print(ini)
initime = time
if f == 1:
break
if f==1:
print('No')
else:
print('Yes')
``` | instruction | 0 | 33,496 | 14 | 66,992 |
No | output | 1 | 33,496 | 14 | 66,993 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.
Each customer is characterized by three values: t_i β the time (in minutes) when the i-th customer visits the restaurant, l_i β the lower bound of their preferred temperature range, and h_i β the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.
Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.
Input
Each test contains one or more test cases. The first line contains the number of test cases q (1 β€ q β€ 500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 β€ n β€ 100, -10^9 β€ m β€ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 β€ t_i β€ 10^9, -10^9 β€ l_i β€ h_i β€ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0.
Output
For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Output
YES
NO
YES
NO
Note
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
* At 0-th minute, change the state to heating (the temperature is 0).
* At 2-nd minute, change the state to off (the temperature is 2).
* At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
* At 6-th minute, change the state to off (the temperature is 3).
* At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
* At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied.
Submitted Solution:
```
import sys, math
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
def getInts():
return [int(s) for s in input().split()]
def getInt():
return int(input())
def getStrs():
return [s for s in input().split()]
def getStr():
return input()
def listStr():
return list(input())
import collections as col
import math
def solve(t0):
#store the allowed ranges
#if allowed ranges have min > max, fail
#update the ranges based on what's possible
N, M = getInts()
if T == 500 and N == 13 and t == 0:
t0 = 1
if t0 == 1 and t > 49:
print(N,M)
for n in range(N):
print(*(getInts()))
return "NO", t0
elif t0 == 1:
for n in range(N):
X = getInts()
return "NO", t0
minutes = col.defaultdict(lambda: col.defaultdict(int))
for n in range(N):
time, low, high = getInts()
if time not in minutes:
minutes[time]['Low'] = low
minutes[time]['High'] = high
else:
curr_low, curr_high = minutes[time]['Low'], minutes[time]['High']
low, high = max(curr_low,low),min(curr_high,high)
if high < low:
print("NO")
return "NO", t0
minutes[time]['Low'] = low
minutes[time]['High'] = high
A = []
for time in minutes:
if 'Low' in minutes[time] and 'High' in minutes[time]:
A.append((time,minutes[time]['Low'],minutes[time]['High']))
A.sort(reverse=True)
curr_time = 0
curr_high = M
curr_low = M
while A:
time, low, high = A.pop()
curr_low = max(low,curr_low-(time-curr_time))
curr_high = min(high,curr_high+(time-curr_time))
if curr_high < curr_low:
print("NO")
return "NO", t0
curr_time = time
print("YES")
return "YES", t0
t0 = 0
T = getInt()
for t in range(T):
ans, t0 = solve(t0)
``` | instruction | 0 | 33,497 | 14 | 66,994 |
No | output | 1 | 33,497 | 14 | 66,995 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.
Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.
The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.
Each customer is characterized by three values: t_i β the time (in minutes) when the i-th customer visits the restaurant, l_i β the lower bound of their preferred temperature range, and h_i β the upper bound of their preferred temperature range.
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.
Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.
Input
Each test contains one or more test cases. The first line contains the number of test cases q (1 β€ q β€ 500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1 β€ n β€ 100, -10^9 β€ m β€ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 β€ t_i β€ 10^9, -10^9 β€ l_i β€ h_i β€ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.
The customers are given in non-decreasing order of their visit time, and the current time is 0.
Output
For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0
Output
YES
NO
YES
NO
Note
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
* At 0-th minute, change the state to heating (the temperature is 0).
* At 2-nd minute, change the state to off (the temperature is 2).
* At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
* At 6-th minute, change the state to off (the temperature is 3).
* At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
* At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied.
Submitted Solution:
```
Q = int(input())
for q in range(Q):
n, m = input().split()
n, m = int(n), int(m)
line = []
for i in range(n):
t, l, h = input().split()
t, l, h = int(t), int(l), int(h)
line.append([t, l, h])
# line = sorted(line)
# print(line)
lb, ub = m-line[0][0], m+line[0][0]
lb, ub = max(lb, line[0][1]), min(ub, line[0][2])
for i in range(1, n):
d = line[i][0] - line[i-1][0]
l, h = line[i][1], line[i][2]
if l < ub+d:
break
elif lb-d > h:
break
else:
lb, ub = max(l, lb-d), min(h, ub+d)
# print(lb, ub)
if lb <= ub:
print("YES")
else:
print("NO")
``` | instruction | 0 | 33,498 | 14 | 66,996 |
No | output | 1 | 33,498 | 14 | 66,997 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 β€ i < j β€ n, 1 β€ k β€ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".
You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
Input
The first input line contains two integers n and m (1 β€ n, m β€ 100) β the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
Output
Print the single number β the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
Examples
Input
2 3
AAB
BAA
Output
4
Input
4 5
ABABA
BCGDG
AAAAA
YABSA
Output
216
Note
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB". | instruction | 0 | 33,613 | 14 | 67,226 |
Tags: combinatorics
Correct Solution:
```
x,y= map(int,input().split())
a=[]
for i in range(0,x):
p=input()
a.append(p)
ans=1
b=[]
for i in range (0,y):
for j in range(0,x):
b.append(a[j][i])
c=set(b)
ans*=len(c)
ans%=1000000007
b=[]
print(ans)
``` | output | 1 | 33,613 | 14 | 67,227 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 β€ i < j β€ n, 1 β€ k β€ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".
You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
Input
The first input line contains two integers n and m (1 β€ n, m β€ 100) β the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
Output
Print the single number β the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
Examples
Input
2 3
AAB
BAA
Output
4
Input
4 5
ABABA
BCGDG
AAAAA
YABSA
Output
216
Note
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB". | instruction | 0 | 33,614 | 14 | 67,228 |
Tags: combinatorics
Correct Solution:
```
n,m=map(int,input().split())
ans=[set() for i in range(m)]
for i in range(n):
a=input()
for j in range(m):
ans[j].add(a[j])
ans1=1
#print(ans)
for i in range(len(ans)):
#print(len(ans[i]))
ans1=(ans1*len(ans[i]))%(10**9+7)
print(ans1%(10**9+7))
``` | output | 1 | 33,614 | 14 | 67,229 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 β€ i < j β€ n, 1 β€ k β€ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".
You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
Input
The first input line contains two integers n and m (1 β€ n, m β€ 100) β the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
Output
Print the single number β the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
Examples
Input
2 3
AAB
BAA
Output
4
Input
4 5
ABABA
BCGDG
AAAAA
YABSA
Output
216
Note
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB". | instruction | 0 | 33,615 | 14 | 67,230 |
Tags: combinatorics
Correct Solution:
```
mod = 1000000007
resp = 1
entrada = input().split(' ')
quant = int(entrada[0])
tamanho = int(entrada[1])
aux =['']*tamanho
for i in range(quant):
s = input()
for j in range(tamanho):
if(s[j] not in aux[j]):
aux[j] += s[j]
for k in aux:
resp = (resp * len(k)) % mod
print(resp)
``` | output | 1 | 33,615 | 14 | 67,231 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 β€ i < j β€ n, 1 β€ k β€ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".
You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
Input
The first input line contains two integers n and m (1 β€ n, m β€ 100) β the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
Output
Print the single number β the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
Examples
Input
2 3
AAB
BAA
Output
4
Input
4 5
ABABA
BCGDG
AAAAA
YABSA
Output
216
Note
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB". | instruction | 0 | 33,616 | 14 | 67,232 |
Tags: combinatorics
Correct Solution:
```
def multiplicacaoModular(a, b, mod):
return ((a % mod) * (b % mod)) % mod
# ----------------> MAIN <--------------------
qtdNames, tamanho = input().split()
qtdNames = int(qtdNames)
tamanho = int(tamanho)
mod = 1000000007
colunas = {}
for i in range(tamanho):
colunas[i + 1] = set()
for i in range(qtdNames):
name = input()
for j in range(1, tamanho + 1):
colunas[j].add(name[j - 1])
total = 1
for key in colunas:
total = multiplicacaoModular(total, len(colunas[key]), mod)
print(total)
``` | output | 1 | 33,616 | 14 | 67,233 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 β€ i < j β€ n, 1 β€ k β€ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".
You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
Input
The first input line contains two integers n and m (1 β€ n, m β€ 100) β the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
Output
Print the single number β the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
Examples
Input
2 3
AAB
BAA
Output
4
Input
4 5
ABABA
BCGDG
AAAAA
YABSA
Output
216
Note
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB". | instruction | 0 | 33,617 | 14 | 67,234 |
Tags: combinatorics
Correct Solution:
```
###################################################################
# ."-,.__
# `. `. ,
# .--' .._,'"-' `.
# . .' `'
# `. / ,'
# ` '--. ,-"'
# `"` | \
# -. \, |
# `--Y.' ___.
# \ L._, \
# _., `. < <\ _
# ,' ' `, `. | \ ( `
# ../, `. ` | .\`. \ \_
# ,' ,.. . _.,' ||\l ) '".
# , ,' \ ,'.-.`-._,' | . _._`.
# ,' / \ \ `' ' `--/ | \ / / ..\
# .' / \ . |\__ - _ ,'` ` / / `.`.
# | ' .. `-...-" | `-' / / . `.
# | / |L__ | | / / `. `.
# , / . . | | / / ` `
# / / ,. ,`._ `-_ | | _ ,-' / ` \
# / . \"`_/. `-_ \_,. ,' +-' `-' _, ..,-. \`.
# . ' .-f ,' ` '. \__.---' _ .' ' \ \
# ' / `.' l .' / \.. ,_|/ `. ,'` L`
# |' _.-""` `. \ _,' ` \ `.___`.'"`-. , | | | \
# || ,' `. `. ' _,...._ ` | `/ ' | ' .|
# || ,' `. ;.,.---' ,' `. `.. `-' .-' /_ .' ;_ ||
# || ' V / / ` | ` ,' ,' '. ! `. ||
# ||/ _,-------7 ' . | `-' l / `||
# . | ,' .- ,' || | .-. `. .' ||
# `' ,' `".' | | `. '. -.' `'
# / ,' | |,' \-.._,.'/'
# . / . . \ .''
# .`. | `. / :_,'.'
# \ `...\ _ ,'-. .' /_.-'
# `-.__ `, `' . _.>----''. _ __ /
# .' /"' | "' '_
# /_|.-'\ ,". '.'`__'-( \
# / ,"'"\,' `/ `-.|"
###################################################################
from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353
def inp(): return stdin.readline().strip()
def iinp(): return int(inp())
def out(var, end="\n"): stdout.write(str(var)+"\n")
def outa(*var, end="\n"): stdout.write(' '.join(map(str, var)) + end)
def lmp(): return list(mp())
def mp(): return map(int, inp().split())
def smp(): return map(str, inp().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(m, val) for j in range(n)]
def remadd(x, y): return 1 if x%y else 0
def ceil(a,b): return (a+b-1)//b
def isprime(x):
if x<=1: return False
if x in (2, 3): return True
if x%2 == 0: return False
for i in range(3, int(sqrt(x))+1, 2):
if x%i == 0: return False
return True
n, m = mp()
ml = []
for i in range(n):
s = inp()
ml.append(s)
ans = 1
for i in range(m):
s = set()
for j in range(n):
s.add(ml[j][i])
ans = (ans*len(s))%mod
print(ans)
``` | output | 1 | 33,617 | 14 | 67,235 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 β€ i < j β€ n, 1 β€ k β€ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".
You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
Input
The first input line contains two integers n and m (1 β€ n, m β€ 100) β the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
Output
Print the single number β the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
Examples
Input
2 3
AAB
BAA
Output
4
Input
4 5
ABABA
BCGDG
AAAAA
YABSA
Output
216
Note
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB". | instruction | 0 | 33,618 | 14 | 67,236 |
Tags: combinatorics
Correct Solution:
```
n,m=list(map(int,input().split()))
arr=[input() for _ in range(n)]
mod=10**9 +7
ans=1
for i in range(m):
li=[]
for j in range(n):
li.append(arr[j][i])
ans=((ans%mod )*(len(set(li))%mod))%mod
print(ans)
``` | output | 1 | 33,618 | 14 | 67,237 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 β€ i < j β€ n, 1 β€ k β€ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".
You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
Input
The first input line contains two integers n and m (1 β€ n, m β€ 100) β the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
Output
Print the single number β the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
Examples
Input
2 3
AAB
BAA
Output
4
Input
4 5
ABABA
BCGDG
AAAAA
YABSA
Output
216
Note
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
Submitted Solution:
```
mod = 10 ** 9 + 7
def add(x, y):
global mod
return (x + y) % mod
def sub(x, y):
global mod
return ((x - y) % mod + mod) % mod
def mul(x, y):
global mod
return (x * y) % mod
def binpow(x, y):
global mod
if y == 0:
return 1
elif y % 2 == 0:
z = binpow(x, y // 2)
return mul(z, z)
else:
return mul(binpow(x, y - 1), x)
def divide(x, y):
global mod
return mul(x, binpow(y, mod - 2))
n, m = map(int, input().split())
s = []
for i in range(n):
s.append(input())
ans = 1
for i in range(m):
t = set()
for j in range(n):
t.add(s[j][i])
ans = mul(ans, len(t))
print(ans)
``` | instruction | 0 | 33,621 | 14 | 67,242 |
Yes | output | 1 | 33,621 | 14 | 67,243 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 β€ i < j β€ n, 1 β€ k β€ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".
You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
Input
The first input line contains two integers n and m (1 β€ n, m β€ 100) β the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
Output
Print the single number β the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
Examples
Input
2 3
AAB
BAA
Output
4
Input
4 5
ABABA
BCGDG
AAAAA
YABSA
Output
216
Note
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
Submitted Solution:
```
n,m=list(map(int,input().split()))
a=[]
for _ in range(n):
s=input()
a.append(s)
ans=1
for i in range(m):
tr=[0]*26
cnt=0
for j in range(n):
if(tr[ord(a[j][i])-ord("A")]==0):
tr[ord(a[j][i])-ord("A")]=1
cnt+=1
ans*=cnt
ans%=1000000007
print(ans%1000000007)
``` | instruction | 0 | 33,622 | 14 | 67,244 |
Yes | output | 1 | 33,622 | 14 | 67,245 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 β€ i < j β€ n, 1 β€ k β€ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".
You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
Input
The first input line contains two integers n and m (1 β€ n, m β€ 100) β the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
Output
Print the single number β the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
Examples
Input
2 3
AAB
BAA
Output
4
Input
4 5
ABABA
BCGDG
AAAAA
YABSA
Output
216
Note
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
Submitted Solution:
```
n, m = map(int, input().split())
a = []
mod = 10**9+7
for _ in range(n):
a.append(input())
ans = 0
d = [set() for _ in range(m)]
for i in range(n):
for j in range(m):
d[j].add(a[i][j])
ans = 1
for i in range(m):
ans = (ans*len(d[i]))%mod
print(ans)
``` | instruction | 0 | 33,623 | 14 | 67,246 |
Yes | output | 1 | 33,623 | 14 | 67,247 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 β€ i < j β€ n, 1 β€ k β€ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".
You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
Input
The first input line contains two integers n and m (1 β€ n, m β€ 100) β the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
Output
Print the single number β the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
Examples
Input
2 3
AAB
BAA
Output
4
Input
4 5
ABABA
BCGDG
AAAAA
YABSA
Output
216
Note
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
Submitted Solution:
```
a,b=map(int,input().split())
ans=[]
total=1
pri=pow(10,9)+7
from collections import *
for i in range(a):
x=input()
ans.append(x)
for i in range(b):
al=defaultdict(int)
c1=0
for j in range(len(ans)):
if(al[ans[j][i]]==0):
al[ans[j][i]]+=1
c1+=1
total=total*c1
total%=pri
print(total)
``` | instruction | 0 | 33,624 | 14 | 67,248 |
Yes | output | 1 | 33,624 | 14 | 67,249 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 β€ i < j β€ n, 1 β€ k β€ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".
You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
Input
The first input line contains two integers n and m (1 β€ n, m β€ 100) β the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
Output
Print the single number β the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
Examples
Input
2 3
AAB
BAA
Output
4
Input
4 5
ABABA
BCGDG
AAAAA
YABSA
Output
216
Note
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
Submitted Solution:
```
x,y= map(int,input().split())
a=[]
for i in range(0,x):
p=input()
a.append(p)
ans=1
b=[]
for i in range (0,y):
for j in range(0,x):
b.append(a[j][i])
c=set(b)
ans*=len(c)
b=[]
print(ans)
``` | instruction | 0 | 33,625 | 14 | 67,250 |
No | output | 1 | 33,625 | 14 | 67,251 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 β€ i < j β€ n, 1 β€ k β€ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".
You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
Input
The first input line contains two integers n and m (1 β€ n, m β€ 100) β the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
Output
Print the single number β the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
Examples
Input
2 3
AAB
BAA
Output
4
Input
4 5
ABABA
BCGDG
AAAAA
YABSA
Output
216
Note
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
Submitted Solution:
```
n, m = [int(x) for x in input().split()]
lista = []
cont = 1
s = set()
for e in range(n):
temp = []
entrada = input()
lista.append(entrada)
for j in range(m):
s = set()
for i in range(n):
s.add(lista[i][j])
print(s)
cont *= len(s)
print(cont)
``` | instruction | 0 | 33,626 | 14 | 67,252 |
No | output | 1 | 33,626 | 14 | 67,253 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 β€ i < j β€ n, 1 β€ k β€ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD".
You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).
Input
The first input line contains two integers n and m (1 β€ n, m β€ 100) β the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.
Output
Print the single number β the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).
Examples
Input
2 3
AAB
BAA
Output
4
Input
4 5
ABABA
BCGDG
AAAAA
YABSA
Output
216
Note
In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB".
Submitted Solution:
```
n,m=map(int,input().split())
ar=[]
for i in range (n):
ar.append(input())
s=1
for i in range (m):
w=[]
for j in range (n):
w.append(ar[j][i])
s*=len(list(set(w)))
print (s)
``` | instruction | 0 | 33,628 | 14 | 67,256 |
No | output | 1 | 33,628 | 14 | 67,257 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2 | instruction | 0 | 33,630 | 14 | 67,260 |
Tags: greedy, sortings
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 9 21:10:35 2020
@author: mahedi
"""
R=lambda:list(map(int,input().split()))
n,d=R()
a,b=R()
lst1=[]
lst2=[]
lst3=[]
sum=0
cnt=1
for i in range(0,n):
x,y=R()
p=(x*a)+(y*b)
lst1.append(p)
lst2.append(i)
iteams=list(zip(lst1,lst2))
iteams.sort()
for i in range(0,n):
sum=sum+iteams[i][0]
if sum<=d:
lst3.append(iteams[i][1]+1)
cnt=cnt+1
print(len(lst3))
print(*lst3)
``` | output | 1 | 33,630 | 14 | 67,261 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2 | instruction | 0 | 33,631 | 14 | 67,262 |
Tags: greedy, sortings
Correct Solution:
```
n , d = map(int,input().split())
lis=[]
aa=[]
m1,m2=map(int,input().split())
for i in range(n):
a,b=map(int,input().split())
lis.append([m1*a+m2*b,i+1])
lis.sort()
ans=0
for i in range(n):
if lis[i][0]+ans<=d:
ans+=lis[i][0]
aa.append(lis[i][1])
print(len(aa))
print(*aa)
``` | output | 1 | 33,631 | 14 | 67,263 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2 | instruction | 0 | 33,632 | 14 | 67,264 |
Tags: greedy, sortings
Correct Solution:
```
n,d=map(int,input().split())
a,b=map(int,input().split())
s=[None]*n
for i in range(n):
x,y=map(int,input().split())
s[i]=(a*x+b*y,i+1)
s.sort()
res=[]
for i in range(n):
if d-s[i][0] >= 0:
res.append(s[i][1])
d-=s[i][0]
else:
break
print (str(len(res))+"\n" + " ".join(map(str,res)))
``` | output | 1 | 33,632 | 14 | 67,265 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2 | instruction | 0 | 33,633 | 14 | 67,266 |
Tags: greedy, sortings
Correct Solution:
```
n, d = map(int,input().split())
a, b = map(int,input().split())
l = []
for i in range(1,n+1):
a1, b1 = map(int,input().split())
l.append([a1*a + b1*b, i])
l.sort()
temp = d
ans = []
for i in l:
if i[0] <= temp:
ans.append(i[1])
temp -= i[0]
else:
break
print(len(ans))
print (*ans)
``` | output | 1 | 33,633 | 14 | 67,267 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2 | instruction | 0 | 33,634 | 14 | 67,268 |
Tags: greedy, sortings
Correct Solution:
```
import sys
input=sys.stdin.buffer.readline
import os
from math import*
n,d=map(int,input().split())
a,b=map(int,input().split())
price=[]
for i in range(n):
x,y=map(int,input().split())
price.append([x*a+y*b,i+1])
price.sort()
#print(price)
ans=[]
s=0
i=0
while i<n:
s+=price[i][0]
if s<=d:
ans.append(price[i][1])
else:
break
i+=1
print(len(ans))
for x in ans:
print(x,end=' ')
``` | output | 1 | 33,634 | 14 | 67,269 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2 | instruction | 0 | 33,635 | 14 | 67,270 |
Tags: greedy, sortings
Correct Solution:
```
# Input
n, d = map(int, input().split())
a, b = map(int, input().split())
clients = []
for i in range(n):
x_i, y_i = map(int, input().split())
clients.append({'number': i + 1,
'size': x_i * a + y_i * b})
# Solve
clients = sorted(clients, key=lambda x: x['size'])
sum = 0
cnt = len(clients)
for i in range(len(clients)):
sum += clients[i]['size']
if sum > d:
cnt = i
break
# Output
print(cnt)
for i in range(cnt):
print(clients[i]['number'], end=" ")
``` | output | 1 | 33,635 | 14 | 67,271 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2 | instruction | 0 | 33,636 | 14 | 67,272 |
Tags: greedy, sortings
Correct Solution:
```
I=lambda:map(int,input().split())
R=range
n,d=I()
a,b=I()
m=[]
v=[]
for i in R(n):x,y=I();v+=[x*a+y*b];m+=[i]
m=sorted(m,key=lambda x:v[x])
for i in R(n):
if v[m[i]]>d:n=i;break
d-=v[m[i]]
print(n)
for i in R(n):print(m[i]+1,end=' ')
``` | output | 1 | 33,636 | 14 | 67,273 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2 | instruction | 0 | 33,637 | 14 | 67,274 |
Tags: greedy, sortings
Correct Solution:
```
##############--->>>>> Deepcoder Amit Kumar Bhuyan <<<<<---##############
"""
Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().strip().split(" "))
def msi(): return map(str,input().strip().split(" "))
def li(): return list(mi())
def dmain():
sys.setrecursionlimit(1000000)
threading.stack_size(1024000)
thread = threading.Thread(target=main)
thread.start()
#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
#from math import log,sqrt,factorial,cos,tan,sin,radians
#from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
#from decimal import *
#import threading
#from itertools import permutations
#Copy 2D list m = [x[:] for x in mark] .. Avoid Using Deepcopy
import sys
input = sys.stdin.readline
scanner = lambda: int(input())
string = lambda: input().rstrip()
get_list = lambda: list(read())
read = lambda: map(int, input().split())
get_float = lambda: map(float, input().split())
# from bisect import bisect_left as lower_bound;
# from bisect import bisect_right as upper_bound;
# from math import ceil, factorial;
def ceil(x):
if x != int(x):
x = int(x) + 1
return x
def factorial(x, m):
val = 1
while x>0:
val = (val * x) % m
x -= 1
return val
def fact(x):
val = 1
while x > 0:
val *= x
x -= 1
return val
# swap_array function
def swaparr(arr, a,b):
temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
## gcd function
def gcd(a,b):
if b == 0:
return a;
return gcd(b, a % b);
## lcm function
def lcm(a, b):
return (a * b) // math.gcd(a, b)
def is_integer(n):
return math.ceil(n) == math.floor(n)
## nCr function efficient using Binomial Cofficient
def nCr(n, k):
if k > n:
return 0
if(k > n - k):
k = n - k
res = 1
for i in range(k):
res = res * (n - i)
res = res / (i + 1)
return int(res)
## upper bound function code -- such that e in a[:i] e < x;
## prime factorization
def primefs(n):
## if n == 1 ## calculating primes
primes = {}
while(n%2 == 0 and n > 0):
primes[2] = primes.get(2, 0) + 1
n = n//2
for i in range(3, int(n**0.5)+2, 2):
while(n%i == 0 and n > 0):
primes[i] = primes.get(i, 0) + 1
n = n//i
if n > 2:
primes[n] = primes.get(n, 0) + 1
## prime factoriazation of n is stored in dictionary
## primes and can be accesed. O(sqrt n)
return primes
## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
res = 1
x = x % p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) :
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
temp = a
a = b
b = temp
return a,b;
# find function with path compression included (recursive)
# def find(x, link):
# if link[x] == x:
# return x
# link[x] = find(link[x], link);
# return link[x];
# find function with path compression (ITERATIVE)
def find(x, link):
p = x;
while( p != link[p]):
p = link[p];
while( x != p):
nex = link[x];
link[x] = p;
x = nex;
return p;
# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
x = find(x, link)
y = find(y, link)
if size[x] < size[y]:
x,y = swap(x,y)
if x != y:
size[x] += size[y]
link[y] = x
## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
prime = [True for i in range(n+1)]
prime[0], prime[1] = False, False
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return prime
# Euler's Toitent Function phi
def phi(n) :
result = n
p = 2
while(p * p<= n) :
if (n % p == 0) :
while (n % p == 0) :
n = n // p
result = result * (1.0 - (1.0 / (float) (p)))
p = p + 1
if (n > 1) :
result = result * (1.0 - (1.0 / (float)(n)))
return (int)(result)
def is_prime(n):
if n == 0:
return False
if n == 1:
return True
for i in range(2, int(n ** (1 / 2)) + 1):
if not n % i:
return False
return True
def next_prime(n, primes):
while primes[n] != True:
n += 1
return n
#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
spf[1] = 1;
for i in range(2, MAXN):
spf[i] = i;
for i in range(4, MAXN, 2):
spf[i] = 2;
for i in range(3, ceil(MAXN ** 0.5), 2):
if spf[i] == i:
for j in range(i*i, MAXN, i):
if spf[j] == j:
spf[j] = i;
## function for storing smallest prime factors (spf) in the array
################## un-comment below 2 lines when using factorization #################
spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
res = []
for i in range(2, int(x ** 0.5) + 1):
while x % i == 0:
res.append(i)
x //= i
if x != 1:
res.append(x)
return res
## this function is useful for multiple queries only, o/w use
## primefs function above. complexity O(log n)
def factors(n):
res = []
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
res.append(i)
res.append(n // i)
return list(set(res))
## taking integer array input
def int_array():
return list(map(int, input().strip().split()));
def float_array():
return list(map(float, input().strip().split()));
## taking string array input
def str_array():
return input().strip().split();
def binary_search(low, high, w, h, n):
while low < high:
mid = low + (high - low) // 2
# print(low, mid, high)
if check(mid, w, h, n):
low = mid + 1
else:
high = mid
return low
## for checking any conditions
def check(beauty, s, n, count):
pass
#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');
alphs = "abcdefghijklmnopqrstuvwxyz"
################### ---------------- TEMPLATE ENDS HERE ---------------- ###################
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect
# import numpy as np
def solve():
n, d = read()
a, b = read()
clients = []
for i in range(n):
x, y = read()
summ = x * a + y * b
clients.append([summ, x, y, i + 1])
clients.sort()
totalphotos = 0
ans = []
for photos in clients:
ind = photos[3]
if totalphotos + photos[0] > d:
break
ans.append(ind)
totalphotos += photos[0]
print(len(ans))
print(*ans)
# region fastio
# template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
#read()
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
for i in range(1):
solve()
#dmain()
# Comment Read()
# fin_time = datetime.now()
# print("Execution time (for loop): ", (fin_time-init_time))
``` | output | 1 | 33,637 | 14 | 67,275 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2
Submitted Solution:
```
n,d=[int(i) for i in input().split()]
a,b=[int(i) for i in input().split()]
arr,res=[],[]
for j in range(n):
x,y=[int(i) for i in input().split()]
arr.append([(x*a+y*b),j])
arr.sort()
sum=0
for i in range(n):
sum=sum+arr[i][0]
if sum>d:
break
res.append(arr[i][1]+1)
print(len(res))
for i in res:
print(i,end=' ')
print('')
``` | instruction | 0 | 33,638 | 14 | 67,276 |
Yes | output | 1 | 33,638 | 14 | 67,277 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2
Submitted Solution:
```
R=lambda:map(int,input().split())
n,d=R()
a,b=R()
def get():
x,y=R()
return a*x+b*y
s=sorted([(get(),i) for i in range(1,n+1)])
#print(s)
ans=[]
for i in range(n):
if d>=s[i][0]:
ans+=[s[i][1]]
d-=s[i][0]
else:
break
print(len(ans))
print(*ans)
``` | instruction | 0 | 33,639 | 14 | 67,278 |
Yes | output | 1 | 33,639 | 14 | 67,279 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2
Submitted Solution:
```
n,d=map(int,input().split())
a,b=map(int,input().split())
ans=[]
for i in range(n):
x,y=map(int,input().split())
ans.append([x*a+y*b,i+1])
ans.sort()
nans=[]
for i in range(len(ans)):
if d>=ans[i][0]:
nans.append(ans[i][1])
d=d-ans[i][0]
else:
break
print(len(nans))
print(*nans)
``` | instruction | 0 | 33,640 | 14 | 67,280 |
Yes | output | 1 | 33,640 | 14 | 67,281 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2
Submitted Solution:
```
import sys
import math
import collections
import heapq
import decimal
input=sys.stdin.readline
n,d=(int(i) for i in input().split())
a,b=(int(i) for i in input().split())
l=[]
for i in range(n):
x,y=(int(i) for i in input().split())
l.append(x*a+y*b)
d1={}
for i in range(n):
if(l[i] in d1):
d1[l[i]].append(i+1)
else:
d1[l[i]]=[i+1]
c=0
s1=0
ans=[]
s=set(l)
l1=sorted(list(s))
for i in l1:
if(s1+i>d):
break
else:
for j in d1[i]:
if(s1+i<=d):
s1+=i
c+=1
ans.append(j)
else:
break
print(c)
print(*ans)
``` | instruction | 0 | 33,641 | 14 | 67,282 |
Yes | output | 1 | 33,641 | 14 | 67,283 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2
Submitted Solution:
```
n , d = map(int,input().split())
lis=[]
c1=c2=0
m1,m2=map(int,input().split())
for i in range(n):
a,b=map(int,input().split())
lis.append([a,b,i+1])
lis.sort()
ans1=ans2=0
aa1=[]
a2=[]
for i in range(n):
k=m1*lis[i][0] +m2*lis[i][1]
if ans1+k<=d:
ans1+=k
aa1.append(lis[i][2])
lis=sorted(lis,key=lambda x: x[1])
for i in range(n):
k=m1*lis[i][0] +m2*lis[i][1]
if ans2+k<=d:
ans2+=k
a2.append(lis[i][2])
if len(aa1)>len(a2):
print(len(a2))
print(*a2)
else:
print(len(aa1))
print(*aa1)
``` | instruction | 0 | 33,642 | 14 | 67,284 |
No | output | 1 | 33,642 | 14 | 67,285 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2
Submitted Solution:
```
def manager(A,maxmem, lmem, hmem):
print(maxmem)
memory = [0 for x in range(len(A))]
for i in range(len(A)):
memory[i] = A[i][0]*lmem + A[i][1]*hmem
L = [int(x) for x in range(len(memory))]
k = bubbleSort(memory, L)
total = 0
ind = 0
for i in range(len(k[0])):
if(total+k[0][i]<=maxmem):
total = total+k[0][i]
else:
ind = i
break
print(ind)
for i in range(ind):
print(L[i]+1, end = ' ')
def bubbleSort(alist, L):
for passnum in range(len(alist)-1,0,-1):
for i in range(passnum):
if alist[i]>alist[i+1]:
temp = alist[i]
temp1 = L[i]
alist[i] = alist[i+1]
L[i] = L[i+1]
alist[i+1] = temp
L[i+1] = temp1
return alist,L
mem = [int(x) for x in input().split()]
indmem = [int(x) for x in input().split()]
A = []
for i in range(mem[0]):
a = [int(x) for x in input().split()]
A.append(a)
manager(A,mem[1],indmem[0],indmem[1])
``` | instruction | 0 | 33,643 | 14 | 67,286 |
No | output | 1 | 33,643 | 14 | 67,287 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2
Submitted Solution:
```
import sys
import math
n, z = [int(x) for x in (sys.stdin.readline()).split()]
a, b = [int(x) for x in (sys.stdin.readline()).split()]
d = dict()
for i in range(n):
x, y = [int(x) for x in (sys.stdin.readline()).split()]
if y in d:
d[y].append((x, i + 1))
else:
d[y] = [(x, i + 1)]
k = list(d.keys())
k.sort()
res = 0
v = []
for i in k:
d[i].sort(key = lambda x: x[0])
for j in d[i]:
if(z - (i * b + j[0] * a) >= 0):
res += 1
v.append(str(j[1]))
z -= (i * b + j[0] * a)
print(res)
print(" ".join(v))
``` | instruction | 0 | 33,644 | 14 | 67,288 |
No | output | 1 | 33,644 | 14 | 67,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.
The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.
Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.
Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.
Input
The first line contains two integers n and d (1 β€ n β€ 105, 1 β€ d β€ 109) β the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 β€ a β€ b β€ 104) β the size of one low quality photo and of one high quality photo, correspondingly.
Next n lines describe the clients. The i-th line contains two integers xi and yi (0 β€ xi, yi β€ 105) β the number of low quality photos and high quality photos the i-th client wants, correspondingly.
All numbers on all lines are separated by single spaces.
Output
On the first line print the answer to the problem β the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.
Examples
Input
3 10
2 3
1 4
2 1
1 0
Output
2
3 2
Input
3 6
6 6
1 1
1 0
1 0
Output
1
2
Submitted Solution:
```
class Pair:
def __init__(self,sumOfNumber,index):
self.sumOfNumber=sumOfNumber
self.index=index
def __lt__(self, other):
return self.sumOfNumber < other.sumOfNumber
n,d=map(int,input().split())
a,b=map(int,input().split())
s=[None]*n
for i in range(n):
x,y=map(int,input().split())
cur=Pair(0,0)
cur.sumOfNumber=(a*x)+(b*y)
cur.index=i+1
s[i]=cur
s.sort()
cur=0
res=[]
while cur<n and d-s[cur].sumOfNumber >= 0:
d-=s[cur].sumOfNumber
cur+=1
res.append(s[cur].index)
print (str(len(res))+"\n" + " ".join(map(str,res)))
``` | instruction | 0 | 33,645 | 14 | 67,290 |
No | output | 1 | 33,645 | 14 | 67,291 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar.
Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating).
Input
The first line contains two integers n and m (2 β€ n, m β€ 100) β the number of employees and the number of languages.
Then n lines follow β each employee's language list. At the beginning of the i-th line is integer ki (0 β€ ki β€ m) β the number of languages the i-th employee knows. Next, the i-th line contains ki integers β aij (1 β€ aij β€ m) β the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages.
The numbers in the lines are separated by single spaces.
Output
Print a single integer β the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
Examples
Input
5 5
1 2
2 2 3
2 3 4
2 4 5
1 5
Output
0
Input
8 7
0
3 1 2 3
1 1
2 5 4
2 6 7
1 3
2 7 4
1 1
Output
2
Input
2 2
1 2
0
Output
1
Note
In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | instruction | 0 | 33,662 | 14 | 67,324 |
Tags: dfs and similar, dsu
Correct Solution:
```
import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline
def dfs(i, grp):
if vis[i]:
return
vis[i] = grp
langs = employees[i]
for lang in langs:
for emp in langs_d[lang]:
dfs(emp, grp)
n, m = map(int, input().split())
employees = []
langs_d = {}
for i in range(n):
langs = list(map(int, input().split()))[1:]
employees.append(langs)
for lang in langs:
if lang in langs_d:
langs_d[lang].append(i)
else:
langs_d[lang] = [i]
if not langs_d.keys():
print(n)
exit()
vis = [0]*n
grp = 1
for i in range(n):
if vis[i]:
continue
dfs(i, grp)
grp += 1
print(max(vis)-1)
``` | output | 1 | 33,662 | 14 | 67,325 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar.
Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating).
Input
The first line contains two integers n and m (2 β€ n, m β€ 100) β the number of employees and the number of languages.
Then n lines follow β each employee's language list. At the beginning of the i-th line is integer ki (0 β€ ki β€ m) β the number of languages the i-th employee knows. Next, the i-th line contains ki integers β aij (1 β€ aij β€ m) β the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages.
The numbers in the lines are separated by single spaces.
Output
Print a single integer β the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
Examples
Input
5 5
1 2
2 2 3
2 3 4
2 4 5
1 5
Output
0
Input
8 7
0
3 1 2 3
1 1
2 5 4
2 6 7
1 3
2 7 4
1 1
Output
2
Input
2 2
1 2
0
Output
1
Note
In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | instruction | 0 | 33,663 | 14 | 67,326 |
Tags: dfs and similar, dsu
Correct Solution:
```
n, m = [int(x) for x in input().split()]
lang = dict()
for i in range(1, m + 1):
lang[i] = []
g = dict()
color = dict()
for i in range(1, n + 1):
g[i] = []
color[i] = 0
for i in range(1, n + 1):
inp = [int(x) for x in input().split()]
for j in range(inp[0]):
lang[inp[j + 1]].append(i)
for x in lang.values():
for i in range(len(x) - 1):
g[x[i]].append(x[i + 1])
g[x[i + 1]].append(x[i])
# check for special case: all people haven't learned a language yet
all_zero_lang = True
for i in range(1, m + 1):
if lang[i]:
all_zero_lang = False
break
if all_zero_lang:
print(n)
else:
cntr = -1
q = [i for i in range(1, n + 1)]
while q:
u = q.pop(0)
if color[u] == 0:
cntr += 1
# bfs
color[u] = 1
queue = [u]
while queue:
w = queue.pop(0)
for x in g[w]:
if color[x] == 0:
color[x] = 1
queue.append(x)
print(cntr)
``` | output | 1 | 33,663 | 14 | 67,327 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar.
Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating).
Input
The first line contains two integers n and m (2 β€ n, m β€ 100) β the number of employees and the number of languages.
Then n lines follow β each employee's language list. At the beginning of the i-th line is integer ki (0 β€ ki β€ m) β the number of languages the i-th employee knows. Next, the i-th line contains ki integers β aij (1 β€ aij β€ m) β the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages.
The numbers in the lines are separated by single spaces.
Output
Print a single integer β the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
Examples
Input
5 5
1 2
2 2 3
2 3 4
2 4 5
1 5
Output
0
Input
8 7
0
3 1 2 3
1 1
2 5 4
2 6 7
1 3
2 7 4
1 1
Output
2
Input
2 2
1 2
0
Output
1
Note
In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | instruction | 0 | 33,664 | 14 | 67,328 |
Tags: dfs and similar, dsu
Correct Solution:
```
# cook your dish here
import sys
sys.setrecursionlimit(10**6)
def find(i,parent):
if parent[i]==i:
return i
else:
parent[i]=find(parent[i],parent)
return parent[i]
def union(a,b,parent,size):
xa=find(a,parent)
xb=find(b,parent)
if size[xa]>size[xb]:
parent[xb]=xa
size[xa]+=size[xb]
else:
parent[xa]=xb
size[xb]+=size[xa]
ans=0
n,m=list(map(int,input().split()))
parent=[]
for i in range(m+1):
parent.append(i)
visited=[0]*(m+1)
size=[1]*(m+1)
for i in range(n):
l=list(map(int,input().split()))
if l[0]==0:
ans=ans+1
else:
x=l[1]
visited[x]=1
for j in range(2,len(l)):
visited[l[j]]=1
union(x,l[j],parent,size)
f=-1
for i in range(1,m+1):
if parent[i]==i and visited[i]==1:
f=f+1
if f!=-1:
ans=ans+f
print(ans)
``` | output | 1 | 33,664 | 14 | 67,329 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar.
Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating).
Input
The first line contains two integers n and m (2 β€ n, m β€ 100) β the number of employees and the number of languages.
Then n lines follow β each employee's language list. At the beginning of the i-th line is integer ki (0 β€ ki β€ m) β the number of languages the i-th employee knows. Next, the i-th line contains ki integers β aij (1 β€ aij β€ m) β the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages.
The numbers in the lines are separated by single spaces.
Output
Print a single integer β the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
Examples
Input
5 5
1 2
2 2 3
2 3 4
2 4 5
1 5
Output
0
Input
8 7
0
3 1 2 3
1 1
2 5 4
2 6 7
1 3
2 7 4
1 1
Output
2
Input
2 2
1 2
0
Output
1
Note
In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | instruction | 0 | 33,665 | 14 | 67,330 |
Tags: dfs and similar, dsu
Correct Solution:
```
## necessary imports
import sys
input = sys.stdin.readline
from math import log2, log, ceil
# swap_array function
def swaparr(arr, a,b):
temp = arr[a];
arr[a] = arr[b];
arr[b] = temp
## gcd function
def gcd(a,b):
if a == 0:
return b
return gcd(b%a, a)
## nCr function efficient using Binomial Cofficient
def nCr(n, k):
if(k > n - k):
k = n - k
res = 1
for i in range(k):
res = res * (n - i)
res = res / (i + 1)
return res
## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0):
hi = len(a)
while lo < hi:
mid = (lo+hi)//2
if a[mid] < x:
lo = mid+1
else:
hi = mid
return lo
## prime factorization
def primefs(n):
## if n == 1 ## calculating primes
primes = {}
while(n%2 == 0):
primes[2] = primes.get(2, 0) + 1
n = n//2
for i in range(3, int(n**0.5)+2, 2):
while(n%i == 0):
primes[i] = primes.get(i, 0) + 1
n = n//i
if n > 2:
primes[n] = primes.get(n, 0) + 1
## prime factoriazation of n is stored in dictionary
## primes and can be accesed. O(sqrt n)
return primes
## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
res = 1
x = x % p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) :
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
temp = a
a = b
b = temp
return a,b
# find function with path compression included (recursive)
# def find(x, link):
# if link[x] == x:
# return x
# link[x] = find(link[x], link);
# return link[x];
# find function with path compression (ITERATIVE)
def find(x, link):
p = x;
while( p != link[p]):
p = link[p];
while( x != p):
nex = link[x];
link[x] = p;
x = nex;
return p;
# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
x = find(x, link)
y = find(y, link)
if size[x] < size[y]:
x,y = swap(x,y)
if x != y:
size[x] += size[y]
link[y] = x
## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return prime
#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e6 + 5)
def spf_sieve():
spf[1] = 1;
for i in range(2, MAXN):
spf[i] = i;
for i in range(4, MAXN, 2):
spf[i] = 2;
for i in range(3, ceil(MAXN ** 0.5), 2):
if spf[i] == i:
for j in range(i*i, MAXN, i):
if spf[j] == j:
spf[j] = i;
## function for storing smallest prime factors (spf) in the array
################## un-comment below 2 lines when using factorization #################
# spf = [0 for i in range(MAXN)]
# spf_sieve()
def factoriazation(x):
ret = {};
while x != 1:
ret[spf[x]] = ret.get(spf[x], 0) + 1;
x = x//spf[x]
return ret
## this function is useful for multiple queries only, o/w use
## primefs function above. complexity O(log n)
## taking integer array input
def int_array():
return list(map(int, input().strip().split()))
## taking string array input
def str_array():
return input().strip().split();
#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');
################### ---------------- TEMPLATE ENDS HERE ---------------- ###################
n, m = int_array();
link = [i for i in range(m)]; size = [1]*m; ans = 0;
parent = []; used = set();
for _ in range(n):
a = int_array(); c = a[0]; a = a[1:];
for i in a:
used.add(i-1);
if c == 0:
ans += 1;
elif c == 1:
parent.append(a[-1] - 1);
else:
for i in range(c-1):
union(a[i]-1, a[i+1]-1, link, size);
parent.append(a[-1] - 1);
for i in range(len(parent)):
parent[i] = find(link[parent[i]], link);
#### ----------------- finding most common parent ------------------- ####
pset = set(parent); mset = used.intersection(pset);
mikasa = len(mset)-1 if len(mset) > 0 else 0;
print(ans + mikasa);
``` | output | 1 | 33,665 | 14 | 67,331 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar.
Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating).
Input
The first line contains two integers n and m (2 β€ n, m β€ 100) β the number of employees and the number of languages.
Then n lines follow β each employee's language list. At the beginning of the i-th line is integer ki (0 β€ ki β€ m) β the number of languages the i-th employee knows. Next, the i-th line contains ki integers β aij (1 β€ aij β€ m) β the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages.
The numbers in the lines are separated by single spaces.
Output
Print a single integer β the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
Examples
Input
5 5
1 2
2 2 3
2 3 4
2 4 5
1 5
Output
0
Input
8 7
0
3 1 2 3
1 1
2 5 4
2 6 7
1 3
2 7 4
1 1
Output
2
Input
2 2
1 2
0
Output
1
Note
In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2. | instruction | 0 | 33,666 | 14 | 67,332 |
Tags: dfs and similar, dsu
Correct Solution:
```
#!/usr/bin/env python3
from sys import stdin
def find(par, a):
if par[a] is not a:
par[a] = find(par, par[a])
return par[a]
def merge(par, rnk, a, b):
a = find(par, a)
b = find(par, b)
if a == b:
return
if rnk[a] < rnk[b]:
par[a] = b
else:
par[b] = a
if rnk[a] == rnk[b]:
rnk[b] += 1
def solve(tc):
n, m = map(int, stdin.readline().split())
employee = [[False for i in range(m+1)] for j in range(n)]
illiteracy = [False for i in range(n)]
cntIlliteracy = 0
for i in range(n):
seq = list(map(int, stdin.readline().split()))
if seq[0] == 0:
illiteracy[i] = True
cntIlliteracy += 1
for j in range(seq[0]):
employee[i][seq[j+1]] = True
comp = list(range(n))
rnk = [0 for i in range(n)]
for i in range(n):
if illiteracy[i]:
continue
for j in range(i+1, n):
if illiteracy[j]:
continue
ok = False
for k in range(m+1):
if employee[i][k] and employee[j][k]:
ok = True
break
if ok:
merge(comp, rnk, i, j)
group = set()
for i in range(n):
if not illiteracy[i]:
group.add(find(comp, i))
print((len(group)-1 if len(group) > 1 else 0)+cntIlliteracy)
tcs = 1
for tc in range(tcs):
solve(tc)
``` | output | 1 | 33,666 | 14 | 67,333 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.