message stringlengths 2 20.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 757 108k | cluster float64 4 4 | __index_level_0__ int64 1.51k 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 ≤ m ≤ 12, 1 ≤ d ≤ 7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Submitted Solution:
```
m,d=map(int,input().split())
x={1:31 , 2:28 , 3:31 , 4:30 , 5:31 , 6:30 ,7:31 , 8:31 , 9:30 ,10:31 , 11:30 , 12:31}
ans=1+(x[m]-(8-d))//7
if (x[m]-(8-d))%7!=0 : ans+=1
print(ans)
``` | instruction | 0 | 105,776 | 4 | 211,552 |
Yes | output | 1 | 105,776 | 4 | 211,553 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 ≤ m ≤ 12, 1 ≤ d ≤ 7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Submitted Solution:
```
m,d = list(map(int, input().split()))
if m == 4 or m == 6 or m == 9 or m == 11:
n = 30
elif m == 2:
n = 28
else:
n = 31
if m == 2 and d == 1:
print(4)
elif n == 30 and d == 7:
print(6)
elif n == 31 and(d == 6 or d == 7):
print(6)
else:
print(5)
``` | instruction | 0 | 105,777 | 4 | 211,554 |
Yes | output | 1 | 105,777 | 4 | 211,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 ≤ m ≤ 12, 1 ≤ d ≤ 7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Submitted Solution:
```
a=input()
s=''
for i in range(0,len(a)):
if a[i]==' ':
mes=int(s)
s=''
continue
else:
s+=a[i]
if(mes==1 or mes==3 or mes==5 or mes==7 or mes==8 or mes==10 or mes==12):
if(int(s)>5):
print(6)
else:
print(5)
elif (mes==4 or mes==6 or mes==9 or mes==11):
if(int(s)>6):
print(6)
else:
print(5)
elif(mes==2):
if(int(s)==1):
print(4)
else:
print(5)
else:
print(5)
``` | instruction | 0 | 105,778 | 4 | 211,556 |
Yes | output | 1 | 105,778 | 4 | 211,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 ≤ m ≤ 12, 1 ≤ d ≤ 7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Submitted Solution:
```
m, d = map(int, input().split())
month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
days = month[m - 1]
answer = 1
days -= 7 - d + 1
if days % 7 == 0:
answer += days // 7
else:
answer += days // 7 + 1
print(answer)
``` | instruction | 0 | 105,779 | 4 | 211,558 |
Yes | output | 1 | 105,779 | 4 | 211,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 ≤ m ≤ 12, 1 ≤ d ≤ 7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Submitted Solution:
```
a,b=map(int,input().split())
month=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
print(-(-(month[a-11]+b-1)//7))
``` | instruction | 0 | 105,780 | 4 | 211,560 |
No | output | 1 | 105,780 | 4 | 211,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 ≤ m ≤ 12, 1 ≤ d ≤ 7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Submitted Solution:
```
m,d=map(int,input().split())
if m==2:
if d==1:
print(4)
else:
print(5)
elif m<8:
if m%2==0 and m!=2:
if d<=6:
print(5)
else:
print(6)
else:
if m%2!=0 and m!=2:
if d<=6:
print(5)
else:
print(6)
else:
if d<=5:
print(5)
else:
print(6)
``` | instruction | 0 | 105,781 | 4 | 211,562 |
No | output | 1 | 105,781 | 4 | 211,563 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 ≤ m ≤ 12, 1 ≤ d ≤ 7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Submitted Solution:
```
a,b=map(int, input().split())
cnt=1
if a<=7:
if a%2==0:
c=8-b
while(c<30):
c+=7
cnt+=1
else:
c=8-b
while(c<31):
c+=7
cnt+=1
else:
if a%2!=0:
c=8-b
while(c<30):
c+=7
cnt+=1
else:
c=8-b
while(c<31):
c+=7
cnt+=1
print(cnt)
``` | instruction | 0 | 105,782 | 4 | 211,564 |
No | output | 1 | 105,782 | 4 | 211,565 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 ≤ m ≤ 12, 1 ≤ d ≤ 7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Submitted Solution:
```
m,d=map(int,input().split())
l0=[1,3,5,7,8,10,12]
l1=[4,6,9,11]
l2=[2]
if(m in l0):
if(d>5):
print(6)
if(d<=5):
print(5)
elif(m in l1):
if(d>6):
print(6)
if(d<=6):
print(5)
elif(m in l2):
print(4)
``` | instruction | 0 | 105,783 | 4 | 211,566 |
No | output | 1 | 105,783 | 4 | 211,567 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results.
Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉.
Will Adilbek be able to provide the generated results in no more than n days?
Input
The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases.
The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs.
Output
Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise.
Example
Input
3
1 1
4 5
5 11
Output
YES
YES
NO
Note
In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n.
In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit.
In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. | instruction | 0 | 106,257 | 4 | 212,514 |
Tags: binary search, brute force, math, ternary search
Correct Solution:
```
from math import ceil
a = int(input())
for i in range(a):
# n - days before deadline, d - days for the program to work
n, d = map(int, input().split())
if d <= n:
print("YES")
else:
counter = 1
current_n_of_days = counter + (ceil(d / (counter + 1)))
previous_result = current_n_of_days + 1
while current_n_of_days <= previous_result:
if current_n_of_days <= n:
print("YES")
break
else:
counter += 1
previous_result = current_n_of_days
current_n_of_days = counter + (ceil(d / (counter + 1)))
else:
print("NO")
``` | output | 1 | 106,257 | 4 | 212,515 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results.
Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉.
Will Adilbek be able to provide the generated results in no more than n days?
Input
The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases.
The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs.
Output
Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise.
Example
Input
3
1 1
4 5
5 11
Output
YES
YES
NO
Note
In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n.
In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit.
In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. | instruction | 0 | 106,258 | 4 | 212,516 |
Tags: binary search, brute force, math, ternary search
Correct Solution:
```
import os,sys
from io import BytesIO, IOBase
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())
import math
for i in range(ii()):
n,d=mi()
if d<=n:
print("YES")
else:
a=math.ceil(d/(n//2+1))
a+=n//2
if a<=n:
print("YES")
else:
print("NO")
``` | output | 1 | 106,258 | 4 | 212,517 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results.
Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉.
Will Adilbek be able to provide the generated results in no more than n days?
Input
The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases.
The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs.
Output
Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise.
Example
Input
3
1 1
4 5
5 11
Output
YES
YES
NO
Note
In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n.
In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit.
In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. | instruction | 0 | 106,259 | 4 | 212,518 |
Tags: binary search, brute force, math, ternary search
Correct Solution:
```
def arr_inp():
return [int(x) for x in stdin.readline().split()]
from sys import stdin
from math import ceil
for i in range(int(input())):
n, d = arr_inp()
if n == d:
print('YES')
else:
a, b, c, mi = 0, d, 2, d
while (b >= a):
b, a = ceil(d / c), a + 1
mi = min(mi, a + b)
c += 1
print('YES' if n >= mi else 'NO')
``` | output | 1 | 106,259 | 4 | 212,519 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results.
Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉.
Will Adilbek be able to provide the generated results in no more than n days?
Input
The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases.
The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs.
Output
Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise.
Example
Input
3
1 1
4 5
5 11
Output
YES
YES
NO
Note
In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n.
In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit.
In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. | instruction | 0 | 106,260 | 4 | 212,520 |
Tags: binary search, brute force, math, ternary search
Correct Solution:
```
import math
#print(math.ceil(4.0))
t = int(input())
for i in range(0, t):
n, d = map(int, input().split())
k = int(math.sqrt(d))
x = d
#print("k=",k)
if n <= k:
x = min(x, int(n + 1 + math.ceil(d / (n + 1))-1) )
# print("x=",x)
if k <= n:
x = min(x, k + 1 + math.ceil(d / (k + 1))- 1)
# print("x=", x)
if k <= n + 1:
x = min(x, k + math.ceil(d / k) -1)
# print("x=", x)
#print("n=",n)
if x <= n:
print("YES")
else:
print("NO")
``` | output | 1 | 106,260 | 4 | 212,521 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results.
Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉.
Will Adilbek be able to provide the generated results in no more than n days?
Input
The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases.
The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs.
Output
Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise.
Example
Input
3
1 1
4 5
5 11
Output
YES
YES
NO
Note
In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n.
In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit.
In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. | instruction | 0 | 106,261 | 4 | 212,522 |
Tags: binary search, brute force, math, ternary search
Correct Solution:
```
import collections
import math
local = False
if local:
file = open("A.txt", "r")
def inp():
if local:
return file.readline().rstrip()
else:
return input().rstrip()
def ints():
return [int(_) for _ in inp().split()]
t = int(inp())
for _ in range(t):
n, d = ints()
if d<=n:
print("YES")
else:
found = False
for i in range(n):
if i+math.ceil(d/(i+1))<=n:
found=True
break
if found:
print("YES")
else:
print("NO")
``` | output | 1 | 106,261 | 4 | 212,523 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results.
Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉.
Will Adilbek be able to provide the generated results in no more than n days?
Input
The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases.
The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs.
Output
Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise.
Example
Input
3
1 1
4 5
5 11
Output
YES
YES
NO
Note
In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n.
In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit.
In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. | instruction | 0 | 106,262 | 4 | 212,524 |
Tags: binary search, brute force, math, ternary search
Correct Solution:
```
import io
import os
from collections import Counter, defaultdict, deque
def solve(N, D):
x = int((D + 0.25) ** 0.5 - 0.5)
for i in range(max(0, x - 10), x + 10):
days = i + D // (i + 1)
if D % (i + 1) != 0:
days += 1
if days <= N:
return "YES"
return "NO"
if __name__ == "__main__":
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
N, D = [int(x) for x in input().split()]
ans = solve(N, D)
print(ans)
``` | output | 1 | 106,262 | 4 | 212,525 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results.
Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉.
Will Adilbek be able to provide the generated results in no more than n days?
Input
The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases.
The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs.
Output
Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise.
Example
Input
3
1 1
4 5
5 11
Output
YES
YES
NO
Note
In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n.
In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit.
In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. | instruction | 0 | 106,263 | 4 | 212,526 |
Tags: binary search, brute force, math, ternary search
Correct Solution:
```
import math
T=int(input())
for iT in range(T):
n,d=[int(i) for i in input().split()]
x=int(math.sqrt(d))-1
temp=x+math.ceil(d/(x+1))
print("YES" if (temp<=n or d==1 )else "NO")
``` | output | 1 | 106,263 | 4 | 212,527 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results.
Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in \left⌈ (d)/(x + 1) \right⌉ days (\left⌈ a \right⌉ is the ceiling function: \left⌈ 2.4 \right⌉ = 3, \left⌈ 2 \right⌉ = 2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x + \left⌈ (d)/(x + 1) \right⌉.
Will Adilbek be able to provide the generated results in no more than n days?
Input
The first line contains a single integer T (1 ≤ T ≤ 50) — the number of test cases.
The next T lines contain test cases – one per line. Each line contains two integers n and d (1 ≤ n ≤ 10^9, 1 ≤ d ≤ 10^9) — the number of days before the deadline and the number of days the program runs.
Output
Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise.
Example
Input
3
1 1
4 5
5 11
Output
YES
YES
NO
Note
In the first test case, Adilbek decides not to optimize the program at all, since d ≤ n.
In the second test case, Adilbek can spend 1 day optimizing the program and it will run \left⌈ 5/2 \right⌉ = 3 days. In total, he will spend 4 days and will fit in the limit.
In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it'll still work \left⌈ (11)/(2+1) \right⌉ = 4 days. | instruction | 0 | 106,264 | 4 | 212,528 |
Tags: binary search, brute force, math, ternary search
Correct Solution:
```
'''input
3
1 1
4 5
5 11
'''
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline
import math
def check(num):
return num + math.ceil(d/(num + 1)) <= n
# main starts
t = int(input().strip())
for _ in range(t):
n, d = list(map(int, input().split()))
x = math.ceil(math.sqrt(d) - 1)
if x + math.ceil(d/(x + 1)) <= n:
print("YES")
elif x - 1 >= 1 and x - 1 + math.ceil(d/x) <= n:
print("YES")
elif x + 1 + math.ceil(d/(x + 2)) <= n:
print("YES")
else:
print("NO")
``` | output | 1 | 106,264 | 4 | 212,529 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Reforms have started in Berland again! At this time, the Parliament is discussing the reform of the calendar. To make the lives of citizens of Berland more varied, it was decided to change the calendar. As more and more people are complaining that "the years fly by...", it was decided that starting from the next year the number of days per year will begin to grow. So the coming year will have exactly a days, the next after coming year will have a + 1 days, the next one will have a + 2 days and so on. This schedule is planned for the coming n years (in the n-th year the length of the year will be equal a + n - 1 day).
No one has yet decided what will become of months. An MP Palevny made the following proposal.
* The calendar for each month is comfortable to be printed on a square sheet of paper. We are proposed to make the number of days in each month be the square of some integer. The number of days per month should be the same for each month of any year, but may be different for different years.
* The number of days in each year must be divisible by the number of days per month in this year. This rule ensures that the number of months in each year is an integer.
* The number of days per month for each year must be chosen so as to save the maximum amount of paper to print the calendars. In other words, the number of days per month should be as much as possible.
These rules provide an unambiguous method for choosing the number of days in each month for any given year length. For example, according to Palevny's proposition, a year that consists of 108 days will have three months, 36 days each. The year that consists of 99 days will have 11 months, 9 days each, and a year of 365 days will have 365 months, one day each.
The proposal provoked heated discussion in the community, the famous mathematician Perelmanov quickly calculated that if the proposal is supported, then in a period of n years, beginning with the year that has a days, the country will spend p sheets of paper to print a set of calendars for these years. Perelmanov's calculations take into account the fact that the set will contain one calendar for each year and each month will be printed on a separate sheet.
Repeat Perelmanov's achievement and print the required number p. You are given positive integers a and n. Perelmanov warns you that your program should not work longer than four seconds at the maximum test.
Input
The only input line contains a pair of integers a, n (1 ≤ a, n ≤ 107; a + n - 1 ≤ 107).
Output
Print the required number p.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
25 3
Output
30
Input
50 5
Output
125
Note
A note to the first sample test. A year of 25 days will consist of one month containing 25 days. A year of 26 days will consist of 26 months, one day each. A year of 27 days will have three months, 9 days each. | instruction | 0 | 107,267 | 4 | 214,534 |
Tags: *special, number theory
Correct Solution:
```
F = {}
def f(k):
if not k in F:
s, i, j = 0, 4, 4
while i <= k:
s += i * f(k // i)
i += j + 1
j += 2
F[k] = (k * (k + 1)) // 2 - s
return F[k]
def g(k):
s, i, j = 0, 4, 4
while i <= k:
s += (i - 1) * f(k // i)
i += j + 1
j += 2
return (k * (k + 1)) // 2 - s
a, n = map(int, input().split())
print(g(a + n - 1) - g(a - 1))
``` | output | 1 | 107,267 | 4 | 214,535 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Reforms have started in Berland again! At this time, the Parliament is discussing the reform of the calendar. To make the lives of citizens of Berland more varied, it was decided to change the calendar. As more and more people are complaining that "the years fly by...", it was decided that starting from the next year the number of days per year will begin to grow. So the coming year will have exactly a days, the next after coming year will have a + 1 days, the next one will have a + 2 days and so on. This schedule is planned for the coming n years (in the n-th year the length of the year will be equal a + n - 1 day).
No one has yet decided what will become of months. An MP Palevny made the following proposal.
* The calendar for each month is comfortable to be printed on a square sheet of paper. We are proposed to make the number of days in each month be the square of some integer. The number of days per month should be the same for each month of any year, but may be different for different years.
* The number of days in each year must be divisible by the number of days per month in this year. This rule ensures that the number of months in each year is an integer.
* The number of days per month for each year must be chosen so as to save the maximum amount of paper to print the calendars. In other words, the number of days per month should be as much as possible.
These rules provide an unambiguous method for choosing the number of days in each month for any given year length. For example, according to Palevny's proposition, a year that consists of 108 days will have three months, 36 days each. The year that consists of 99 days will have 11 months, 9 days each, and a year of 365 days will have 365 months, one day each.
The proposal provoked heated discussion in the community, the famous mathematician Perelmanov quickly calculated that if the proposal is supported, then in a period of n years, beginning with the year that has a days, the country will spend p sheets of paper to print a set of calendars for these years. Perelmanov's calculations take into account the fact that the set will contain one calendar for each year and each month will be printed on a separate sheet.
Repeat Perelmanov's achievement and print the required number p. You are given positive integers a and n. Perelmanov warns you that your program should not work longer than four seconds at the maximum test.
Input
The only input line contains a pair of integers a, n (1 ≤ a, n ≤ 107; a + n - 1 ≤ 107).
Output
Print the required number p.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
25 3
Output
30
Input
50 5
Output
125
Note
A note to the first sample test. A year of 25 days will consist of one month containing 25 days. A year of 26 days will consist of 26 months, one day each. A year of 27 days will have three months, 9 days each.
Submitted Solution:
```
a,n=[int(i) for i in input().split()]
i=1
soma=0
respostas=dict()
while i*i<(a+n):
ii=i*i
j=ii
while j<(a+n):
respostas[j]=ii
j+=ii
i+=1
i=a
while i<a+n:
soma+=i/respostas[i]
i+=1
print(soma)
``` | instruction | 0 | 107,268 | 4 | 214,536 |
No | output | 1 | 107,268 | 4 | 214,537 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.
Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.
Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
Input
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.
Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
Examples
Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0
Note
In first example Vitalya should turn off first alarm clock which rings at minute 3.
In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.
In third example Vitalya should turn off any 6 alarm clocks. | instruction | 0 | 107,546 | 4 | 215,092 |
Tags: greedy
Correct Solution:
```
import sys
import math as mt
import bisect
#input=sys.stdin.readline
#t=int(input())
t=1
def solve():
i,j,ans=0,0,0
ind=[0]*(n)
suma,ex=1,0
j=0
for i in range(n):
if j<n and ind[i]==0:
while j<n:
if l[j]-l[i]+1<=m:
if j-i+1-ex>=k:
diff=(j-i+1-ex)-k+1
for j1 in range(j,j-diff,-1):
#print(j1,diff)
ind[j1]=1
ans+=diff
ex+=diff
else:
if k==1:
ans+=1
break
j+=1
else:
ex-=1
return ans
for _ in range(t):
#n=int(input())
#a=int(input())
#b=int(input())
n,m,k=map(int,input().split())
#x,y,k=map(int,input().split())
#n,h=(map(int,input().split()))
l=list(map(int,input().split()))
#l2=list(map(int,input().split()))
l.sort()
print(solve())
``` | output | 1 | 107,546 | 4 | 215,093 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.
Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.
Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
Input
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.
Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
Examples
Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0
Note
In first example Vitalya should turn off first alarm clock which rings at minute 3.
In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.
In third example Vitalya should turn off any 6 alarm clocks. | instruction | 0 | 107,547 | 4 | 215,094 |
Tags: greedy
Correct Solution:
```
n, m, k = map(int, input().split())
a = map(int, input().split())
a = list(sorted(a))
s = []
r = 0
for x in a:
if len(s) and s[0] < x - m + 1:
del s[0]
if len(s) < k - 1:
s.append(x)
else:
r += 1
print(r)
``` | output | 1 | 107,547 | 4 | 215,095 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.
Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.
Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
Input
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.
Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
Examples
Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0
Note
In first example Vitalya should turn off first alarm clock which rings at minute 3.
In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.
In third example Vitalya should turn off any 6 alarm clocks. | instruction | 0 | 107,548 | 4 | 215,096 |
Tags: greedy
Correct Solution:
```
from sys import stdin, exit, setrecursionlimit
from collections import deque
from string import ascii_lowercase
from itertools import *
from math import *
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()
mod = 10**9+7
n, m, k= mi()
a = lmi()
a.sort()
q = deque()
cnt = 0
for i in range(n):
q.append(i)
while a and a[q[-1]] - a[q[0]] > m-1:
q.popleft()
while len(q) >= k:
q.pop()
cnt += 1
print(cnt)
``` | output | 1 | 107,548 | 4 | 215,097 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.
Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.
Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
Input
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.
Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
Examples
Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0
Note
In first example Vitalya should turn off first alarm clock which rings at minute 3.
In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.
In third example Vitalya should turn off any 6 alarm clocks. | instruction | 0 | 107,549 | 4 | 215,098 |
Tags: greedy
Correct Solution:
```
import sys,os,io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left , bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')
def isPrime(x):
for i in range(2,x):
if i*i>x:
break
if (x%i==0):
return False
return True
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den,
p - 2, p)) % p
def primeFactors(n):
l = []
while n % 2 == 0:
l.append(2)
n = n / 2
for i in range(3,int(math.sqrt(n))+1,2):
while n % i== 0:
l.append(int(i))
n = n / i
if n > 2:
l.append(n)
return list(set(l))
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 # y = y/2
x = (x * x) % p
return res
def SieveOfEratosthenes(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
def countdig(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
def si():
return input()
def prefix_sum(arr):
r = [0] * (len(arr)+1)
for i, el in enumerate(arr):
r[i+1] = r[i] + el
return r
def divideCeil(n,x):
if (n%x==0):
return n//x
return n//x+1
def ii():
return int(input())
def li():
return list(map(int,input().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
def power_set(L):
"""
L is a list.
The function returns the power set, but as a list of lists.
"""
cardinality=len(L)
n=2 ** cardinality
powerset = []
for i in range(n):
a=bin(i)[2:]
subset=[]
for j in range(len(a)):
if a[-j-1]=='1':
subset.append(L[j])
powerset.append(subset)
#the function could stop here closing with
#return powerset
powerset_orderred=[]
for k in range(cardinality+1):
for w in powerset:
if len(w)==k:
powerset_orderred.append(w)
return powerset_orderred
def fastPlrintNextLines(a):
# 12
# 3
# 1
#like this
#a is list of strings
print('\n'.join(map(str,a)))
def sortByFirstAndSecond(A):
A = sorted(A,key = lambda x:x[0])
A = sorted(A,key = lambda x:x[1])
return list(A)
#__________________________TEMPLATE__________________OVER_______________________________________________________
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w")
else:
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = 1
# t = int(input())
for _ in range(t):
n,m,k = li()
a = li()
a.sort()
a1 = []
cnt = 0
for i in range(n):
a1.append(a[i])
if len(a1)>=k and a1[-1]-a1[len(a1)-k]<m:
a1.pop()
cnt+=1
print(cnt)
``` | output | 1 | 107,549 | 4 | 215,099 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.
Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.
Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
Input
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.
Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
Examples
Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0
Note
In first example Vitalya should turn off first alarm clock which rings at minute 3.
In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.
In third example Vitalya should turn off any 6 alarm clocks. | instruction | 0 | 107,550 | 4 | 215,100 |
Tags: greedy
Correct Solution:
```
import sys
input = sys.stdin.readline
from collections import *
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
t = [0]*(10**6+100)
for ai in a:
t[ai] = 1
now = 0
ans = 0
for i in range(10**6+100):
now += t[i]
if i>=m:
now -= t[i-m]
if now==k:
t[i] = 0
now -= 1
ans += 1
print(ans)
``` | output | 1 | 107,550 | 4 | 215,101 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.
Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.
Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
Input
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.
Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
Examples
Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0
Note
In first example Vitalya should turn off first alarm clock which rings at minute 3.
In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.
In third example Vitalya should turn off any 6 alarm clocks. | instruction | 0 | 107,551 | 4 | 215,102 |
Tags: greedy
Correct Solution:
```
n, m, k=[int(x) for x in input().split()]
alarms=[int(x) for x in input().split()]
alarms.sort()
al2=[]
cont=0
for i in range(len(alarms)):
al2.append(alarms[i])
if len(al2)>=k and al2[-1]-al2[len(al2)-k]<m:
al2.pop()
cont+=1
print(cont)
``` | output | 1 | 107,551 | 4 | 215,103 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.
Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.
Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
Input
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.
Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
Examples
Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0
Note
In first example Vitalya should turn off first alarm clock which rings at minute 3.
In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.
In third example Vitalya should turn off any 6 alarm clocks. | instruction | 0 | 107,552 | 4 | 215,104 |
Tags: greedy
Correct Solution:
```
n, m, k = (int(x) for x in input().split())
ns = set((int(x) for x in input().split()))
from collections import deque
span = deque((0 for i in range(m)))
kk = 0
res = 0
mm = -1
while len(ns) > 0:
mm += 1
x = span.popleft()
if x == 1:
kk -= 1
if mm not in ns:
span.append(0)
else:
ns.remove(mm)
y = 1
if kk == k - 1:
res += 1
y = 0
span.append(y)
kk+=y
print(res)
``` | output | 1 | 107,552 | 4 | 215,105 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.
Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.
Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
Input
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.
Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
Examples
Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0
Note
In first example Vitalya should turn off first alarm clock which rings at minute 3.
In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.
In third example Vitalya should turn off any 6 alarm clocks. | instruction | 0 | 107,553 | 4 | 215,106 |
Tags: greedy
Correct Solution:
```
from collections import deque
n,m,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a = sorted(a)
a = deque(a)
first = - 10e7
r = deque([])
s = 0
result = 0
while n > 0:
e = a[0]
c = e - m + 1
while r != deque([]):
if r[0] < c:
r.popleft()
s -= 1
else:
break
if s + 1 >= k:
result += 1
else:
r.append(e)
s += 1
a.popleft()
n -= 1
# print(e, c, s, r, result)
print(result)
``` | output | 1 | 107,553 | 4 | 215,107 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.
Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.
Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
Input
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.
Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
Examples
Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0
Note
In first example Vitalya should turn off first alarm clock which rings at minute 3.
In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.
In third example Vitalya should turn off any 6 alarm clocks.
Submitted Solution:
```
n,m,k = map(int,input().split())
lis = sorted(map(int,input().split()))+[1000000000000000]
j=zer=ans=0
for i in range(n):
if lis[i]==0:
zer-=1
continue
j=max(j,i)
while j<=n and lis[j]-lis[i]<m:
j+=1
if j-i-zer>=k:
a=j-1
ext=j-i-zer-k+1
t=0
while a>=0 and ext>0:
if lis[a]!=0:
lis[a]=0
t+=1
zer+=1
ext-=1
a-=1
ans+=t
if lis[i]==0:
zer-=1
print(ans)
``` | instruction | 0 | 107,554 | 4 | 215,108 |
Yes | output | 1 | 107,554 | 4 | 215,109 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.
Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.
Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
Input
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.
Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
Examples
Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0
Note
In first example Vitalya should turn off first alarm clock which rings at minute 3.
In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.
In third example Vitalya should turn off any 6 alarm clocks.
Submitted Solution:
```
import heapq
import sys
input = sys.stdin.readline
for _ in range(1):
n,m,k = map(int,input().split())
l = list(map(int,input().split()))
if k == 1:
print(n)
continue
l.sort()
h = []
heapq.heapify(h)
ans = 0
for i in l:
if len(h)+1 == k:
if i-h[0]+1 <= m:
ans += 1
continue
while len(h) > 0:
if i - h[0] + 1 > m:
heapq.heappop(h)
else:
break
heapq.heappush(h, i)
else:
heapq.heappush(h,i)
print(ans)
``` | instruction | 0 | 107,555 | 4 | 215,110 |
Yes | output | 1 | 107,555 | 4 | 215,111 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.
Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.
Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
Input
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.
Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
Examples
Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0
Note
In first example Vitalya should turn off first alarm clock which rings at minute 3.
In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.
In third example Vitalya should turn off any 6 alarm clocks.
Submitted Solution:
```
n, m, k = map(int, input().split())
times = list(map(int, input().split()))
times.sort()
ans = 0
start = 0
cnt = 0
j = 0
prohibited = []
for i in range(n):
prohibited += [1]
for i in range(n):
if times[i] < start + m:
cnt += 1
else:
while times[i] >= start + m:
if prohibited[j] == 1:
start = times[j]
if j != 0:
cnt -= 1
j += 1
cnt += 1
if cnt == k:
cnt -= 1
ans += 1
prohibited[i] = 0
if k == 1:
print(n)
else:
print(ans)
``` | instruction | 0 | 107,556 | 4 | 215,112 |
Yes | output | 1 | 107,556 | 4 | 215,113 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.
Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.
Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
Input
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.
Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
Examples
Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0
Note
In first example Vitalya should turn off first alarm clock which rings at minute 3.
In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.
In third example Vitalya should turn off any 6 alarm clocks.
Submitted Solution:
```
n,m,k=map(int,input().split())
cnt=[0]*(10**6+5)
l=[int(i) for i in input().split()]
for i in l:
cnt[i]+=1
sm=0
for i in range(10**6+5):
sm+=cnt[i]
if(i>=m):
sm-=cnt[i-m]
if(sm>=k):
sm-=1
cnt[i]=0
print(n-sum(cnt))
``` | instruction | 0 | 107,557 | 4 | 215,114 |
Yes | output | 1 | 107,557 | 4 | 215,115 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.
Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.
Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
Input
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.
Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
Examples
Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0
Note
In first example Vitalya should turn off first alarm clock which rings at minute 3.
In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.
In third example Vitalya should turn off any 6 alarm clocks.
Submitted Solution:
```
n, m, k = map(int, input().split())
ls = list(map(int, input().split()))
ls.sort()
l = len(ls)
i = 0
j = 1
t = n
if n == 1:
print(1)
elif k == 1:
print(n)
else:
while t != 0:
# print(i, j)
while j != l and ls[j] - ls[i] + 1 <= m:
j += 1
x = j - i
if x - k < 0:
t = 0
else:
t = min(t, x - k +1)
i += 1
if j == l:
break
print(t)
``` | instruction | 0 | 107,558 | 4 | 215,116 |
No | output | 1 | 107,558 | 4 | 215,117 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.
Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.
Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
Input
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.
Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
Examples
Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0
Note
In first example Vitalya should turn off first alarm clock which rings at minute 3.
In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.
In third example Vitalya should turn off any 6 alarm clocks.
Submitted Solution:
```
n,m,k = list(map(int,input().split()))
clock = list(map(int,input().split()))
clock.sort()
unlock = [clock[0]]
count = 0
j = 0
con = 1
for i in range(1,n):
if clock[i] - unlock[j] < m:
if con < k - 1:
con += 1
unlock += [clock[i]]
else:
count += 1
else:
while j == len(unlock) or clock[i] - unlock[j] < m:
j += 1
con -= 1
unlock += [clock[i]]
if j == len(unlock) - 1:
j += 1
print(count)
``` | instruction | 0 | 107,559 | 4 | 215,118 |
No | output | 1 | 107,559 | 4 | 215,119 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.
Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.
Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
Input
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.
Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
Examples
Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0
Note
In first example Vitalya should turn off first alarm clock which rings at minute 3.
In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.
In third example Vitalya should turn off any 6 alarm clocks.
Submitted Solution:
```
from collections import *
al=defaultdict(int)
n,u,k=map(int,input().split())
z=list(map(int,input().split()))
z.sort()
m=z.copy()
if(k==1):
print(len(z))
exit()
al=defaultdict(int)
total=0
point=z[0]+1
for i in range(len(z)):
if(point>=len(z)):
break;
if(i==0):
point=m[k-1]
count=0
for j in range(k-1,len(z)):
if(m[j]-z[i]+1>u):
break;
else:
count+=1
al[j]=1
total+=count
point=j
gap=k
else:
if(al[i]==0):
gap-=1
while(gap<k):
if(al[point]==0):
point+=1
gap+=1
else:
point+=1
count=0
for j in range(point,len(z)):
if(z[j]-z[i]+1>u):
break;
else:
count+=1
al[j]=1
total+=count
point=j
gap=k
else:
continue;
print(total)
``` | instruction | 0 | 107,560 | 4 | 215,120 |
No | output | 1 | 107,560 | 4 | 215,121 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.
Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.
Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.
Input
First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.
Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.
Output
Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.
Examples
Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0
Note
In first example Vitalya should turn off first alarm clock which rings at minute 3.
In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.
In third example Vitalya should turn off any 6 alarm clocks.
Submitted Solution:
```
n, m, k = map(int, input().split())
times = list(map(int, input().split()))
times.sort()
ans = 0
start = 0
cnt = 0
j = 0
for i in range(n):
if times[i] <= start + m:
cnt += 1
if cnt == k:
cnt -= 1
ans += 1
j += 1
else:
while times[i] > start + m:
start = times[j]
j += 1
cnt -= 1
cnt += 1
print(ans)
``` | instruction | 0 | 107,561 | 4 | 215,122 |
No | output | 1 | 107,561 | 4 | 215,123 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.
There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th hour, and last lesson is during j-th hour, then he spends j - i + 1 hours in the university during this day. If there are no lessons during some day, then Ivan stays at home and therefore spends 0 hours in the university.
Ivan doesn't like to spend a lot of time in the university, so he has decided to skip some lessons. He cannot skip more than k lessons during the week. After deciding which lessons he should skip and which he should attend, every day Ivan will enter the university right before the start of the first lesson he does not skip, and leave it after the end of the last lesson he decides to attend. If Ivan skips all lessons during some day, he doesn't go to the university that day at all.
Given n, m, k and Ivan's timetable, can you determine the minimum number of hours he has to spend in the university during one week, if he cannot skip more than k lessons?
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 500, 0 ≤ k ≤ 500) — the number of days in the Berland week, the number of working hours during each day, and the number of lessons Ivan can skip, respectively.
Then n lines follow, i-th line containing a binary string of m characters. If j-th character in i-th line is 1, then Ivan has a lesson on i-th day during j-th hour (if it is 0, there is no such lesson).
Output
Print the minimum number of hours Ivan has to spend in the university during the week if he skips not more than k lessons.
Examples
Input
2 5 1
01001
10110
Output
5
Input
2 5 0
01001
10110
Output
8
Note
In the first example Ivan can skip any of two lessons during the first day, so he spends 1 hour during the first day and 4 hours during the second day.
In the second example Ivan can't skip any lessons, so he spends 4 hours every day. | instruction | 0 | 107,578 | 4 | 215,156 |
Tags: dp
Correct Solution:
```
import sys
n, m, k = map(int, input().split())
table = [input() for _ in range(n)]
dp = [0]*(k+1)
for a in table:
one = []
for i in range(m):
if a[i] == '1':
one.append(i)
if not one:
continue
ni = len(one)
subdp = [10**9] * (ni+1)
subdp[-1] = 0
for i in range(ni):
for j in range(i, ni):
subdp[ni-(j-i+1)] = min(subdp[ni-(j-i+1)], one[j]-one[i]+1)
next_dp = [10**9]*(k+1)
for i in range(k, -1, -1):
for j in range(ni+1):
if i+j > k:
break
next_dp[i+j] = min(next_dp[i+j], dp[i] + subdp[j])
dp = next_dp
print(min(dp))
``` | output | 1 | 107,578 | 4 | 215,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.
There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th hour, and last lesson is during j-th hour, then he spends j - i + 1 hours in the university during this day. If there are no lessons during some day, then Ivan stays at home and therefore spends 0 hours in the university.
Ivan doesn't like to spend a lot of time in the university, so he has decided to skip some lessons. He cannot skip more than k lessons during the week. After deciding which lessons he should skip and which he should attend, every day Ivan will enter the university right before the start of the first lesson he does not skip, and leave it after the end of the last lesson he decides to attend. If Ivan skips all lessons during some day, he doesn't go to the university that day at all.
Given n, m, k and Ivan's timetable, can you determine the minimum number of hours he has to spend in the university during one week, if he cannot skip more than k lessons?
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 500, 0 ≤ k ≤ 500) — the number of days in the Berland week, the number of working hours during each day, and the number of lessons Ivan can skip, respectively.
Then n lines follow, i-th line containing a binary string of m characters. If j-th character in i-th line is 1, then Ivan has a lesson on i-th day during j-th hour (if it is 0, there is no such lesson).
Output
Print the minimum number of hours Ivan has to spend in the university during the week if he skips not more than k lessons.
Examples
Input
2 5 1
01001
10110
Output
5
Input
2 5 0
01001
10110
Output
8
Note
In the first example Ivan can skip any of two lessons during the first day, so he spends 1 hour during the first day and 4 hours during the second day.
In the second example Ivan can't skip any lessons, so he spends 4 hours every day. | instruction | 0 | 107,579 | 4 | 215,158 |
Tags: dp
Correct Solution:
```
R = lambda: map(int, input().split())
n, m, k = R()
cls = [list(i for i, x in enumerate(map(int, input())) if x) for _ in range(n)]
dp = [[n * m] * (k + 1) for i in range(n + 1)]
dp.append([0] * (k + 1))
for i in range(n):
row = cls[i]
c2l = [m + 1] * (m + 1)
c2l[0] = row[-1] - row[0] + 1 if row else 0
c2l[len(row)] = 0
for r in range(len(row)):
for l in range(r + 1):
c2l[len(row) - (r - l + 1)] = min(c2l[len(row) - (r - l + 1)], row[r] - row[l] + 1)
for j in range(k + 1):
for c, l in enumerate(c2l):
if j + c <= k and l < m + 1:
dp[i][j] = min(dp[i][j], dp[i - 1][j + c] + l)
print(min(dp[n - 1]))
``` | output | 1 | 107,579 | 4 | 215,159 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.
There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th hour, and last lesson is during j-th hour, then he spends j - i + 1 hours in the university during this day. If there are no lessons during some day, then Ivan stays at home and therefore spends 0 hours in the university.
Ivan doesn't like to spend a lot of time in the university, so he has decided to skip some lessons. He cannot skip more than k lessons during the week. After deciding which lessons he should skip and which he should attend, every day Ivan will enter the university right before the start of the first lesson he does not skip, and leave it after the end of the last lesson he decides to attend. If Ivan skips all lessons during some day, he doesn't go to the university that day at all.
Given n, m, k and Ivan's timetable, can you determine the minimum number of hours he has to spend in the university during one week, if he cannot skip more than k lessons?
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 500, 0 ≤ k ≤ 500) — the number of days in the Berland week, the number of working hours during each day, and the number of lessons Ivan can skip, respectively.
Then n lines follow, i-th line containing a binary string of m characters. If j-th character in i-th line is 1, then Ivan has a lesson on i-th day during j-th hour (if it is 0, there is no such lesson).
Output
Print the minimum number of hours Ivan has to spend in the university during the week if he skips not more than k lessons.
Examples
Input
2 5 1
01001
10110
Output
5
Input
2 5 0
01001
10110
Output
8
Note
In the first example Ivan can skip any of two lessons during the first day, so he spends 1 hour during the first day and 4 hours during the second day.
In the second example Ivan can't skip any lessons, so he spends 4 hours every day. | instruction | 0 | 107,580 | 4 | 215,160 |
Tags: dp
Correct Solution:
```
def min_sub_array(day, k):
if not day:
return [0] * (k + 1)
n = len(day)
best = [float('inf')] * (n + 1)
best[0] = 0
best[1] = 1
for size in range(2, n + 1):
for i in range(n + 1 - size):
best[size] = min(best[size], day[i + size - 1] - day[i] + 1)
output = [0] * (k + 1)
for i in range(k + 1):
if n - i > 0:
output[i] = best[n - i]
return output
N, M, K = map(int, input().split())
day = [i for i, val in enumerate(input()) if val == '1']
best = min_sub_array(day, K)
for _ in range(N - 1):
day = [i for i, val in enumerate(input()) if val == '1']
new_day_best = min_sub_array(day, K)
new_best = [float('inf')] * (K + 1)
for i in range(K + 1):
for j in range(i + 1):
new_best[i] = min(new_best[i], new_day_best[j] + best[i - j])
best = new_best
print(best[K])
``` | output | 1 | 107,580 | 4 | 215,161 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.
There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th hour, and last lesson is during j-th hour, then he spends j - i + 1 hours in the university during this day. If there are no lessons during some day, then Ivan stays at home and therefore spends 0 hours in the university.
Ivan doesn't like to spend a lot of time in the university, so he has decided to skip some lessons. He cannot skip more than k lessons during the week. After deciding which lessons he should skip and which he should attend, every day Ivan will enter the university right before the start of the first lesson he does not skip, and leave it after the end of the last lesson he decides to attend. If Ivan skips all lessons during some day, he doesn't go to the university that day at all.
Given n, m, k and Ivan's timetable, can you determine the minimum number of hours he has to spend in the university during one week, if he cannot skip more than k lessons?
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 500, 0 ≤ k ≤ 500) — the number of days in the Berland week, the number of working hours during each day, and the number of lessons Ivan can skip, respectively.
Then n lines follow, i-th line containing a binary string of m characters. If j-th character in i-th line is 1, then Ivan has a lesson on i-th day during j-th hour (if it is 0, there is no such lesson).
Output
Print the minimum number of hours Ivan has to spend in the university during the week if he skips not more than k lessons.
Examples
Input
2 5 1
01001
10110
Output
5
Input
2 5 0
01001
10110
Output
8
Note
In the first example Ivan can skip any of two lessons during the first day, so he spends 1 hour during the first day and 4 hours during the second day.
In the second example Ivan can't skip any lessons, so he spends 4 hours every day. | instruction | 0 | 107,581 | 4 | 215,162 |
Tags: dp
Correct Solution:
```
import queue
intput = lambda:map(int, input().split())
N, M, K = intput()
ht = [[] for _ in range(N)]
for _ in range(N):
day = input()
ht[_] = [i for i in range(M) if day[i] == '1']
# req[i][j] -- required hours for day i if j lessons skipped
# dp[i][j] -- required hours up to day i if j lesson skipped
# dp[i+1][j+z] = dp[i][j] + req[i][z]
tc = [1,2,3,8,9]
# just return dp[-1][-1]
req = [[0 for _ in range(M+1)] for __ in range(N)]
dp = [[0 for _ in range(K+1)] for __ in range(N)]
for i in range(N):
# cost to skip j lessons today
for j in range(len(ht[i])):
req[i][j] = ht[i][-1] - ht[i][0] + 1 # default large num
# if start at the first-th lesson
for first in range(j+1):
last = first + len(ht[i])-j-1
cost = ht[i][last]-ht[i][first]+1
if last >= first:
req[i][j] = min(req[i][j], cost)
for i in range(min(len(req[0]), len(dp[0]))):
dp[0][i] = req[0][i]
for i in range(1, N):
# total skipped up to this point
for j in range(K+1):
dp[i][j] = dp[i-1][j] + req[i][0]
# additional skipped for this day -- min of (skips left, curr skips, num lessons)
for z in range(1+min(j, len(ht[i]))):
dp[i][j] = min(dp[i][j], dp[i-1][j-z] + req[i][z])
# print('{}\n{}'.format(req,dp))
print(dp[-1][-1])
``` | output | 1 | 107,581 | 4 | 215,163 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.
There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th hour, and last lesson is during j-th hour, then he spends j - i + 1 hours in the university during this day. If there are no lessons during some day, then Ivan stays at home and therefore spends 0 hours in the university.
Ivan doesn't like to spend a lot of time in the university, so he has decided to skip some lessons. He cannot skip more than k lessons during the week. After deciding which lessons he should skip and which he should attend, every day Ivan will enter the university right before the start of the first lesson he does not skip, and leave it after the end of the last lesson he decides to attend. If Ivan skips all lessons during some day, he doesn't go to the university that day at all.
Given n, m, k and Ivan's timetable, can you determine the minimum number of hours he has to spend in the university during one week, if he cannot skip more than k lessons?
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 500, 0 ≤ k ≤ 500) — the number of days in the Berland week, the number of working hours during each day, and the number of lessons Ivan can skip, respectively.
Then n lines follow, i-th line containing a binary string of m characters. If j-th character in i-th line is 1, then Ivan has a lesson on i-th day during j-th hour (if it is 0, there is no such lesson).
Output
Print the minimum number of hours Ivan has to spend in the university during the week if he skips not more than k lessons.
Examples
Input
2 5 1
01001
10110
Output
5
Input
2 5 0
01001
10110
Output
8
Note
In the first example Ivan can skip any of two lessons during the first day, so he spends 1 hour during the first day and 4 hours during the second day.
In the second example Ivan can't skip any lessons, so he spends 4 hours every day. | instruction | 0 | 107,582 | 4 | 215,164 |
Tags: dp
Correct Solution:
```
import sys
input = sys.stdin.readline
def int_array():
return list(map(int, input().strip().split()))
def float_array():
return list(map(float, input().strip().split()))
def str_array():
return input().strip().split()
from collections import Counter
import math
import bisect
from collections import deque
n,m,lesson=int_array()
dp=[[250005 for i in range(lesson+2)]for j in range(n+1)]
days=[[] for i in range(n)]
for i in range(n):
s=input()
for j in range(m):
if s[j]=="1":
days[i].append(j+1)
m=[[250005 for i in range(lesson+2)]for j in range(n+1)]
for i in range(n):
for j in range(lesson+1):
if j<=len(days[i]):
if j==len(days[i]):
m[i][j]=0
continue
else:
for k in range(0,j+1):
var=days[i][0+k]
var1=days[i][-1*max(1,1+(j-k))]
m[i][j]=min(m[i][j],var1-var+1)
for i in range(lesson+1):
dp[0][i]=m[0][i]
for i in range(1,n):
for j in range(lesson+1):
for k in range(j+1):
dp[i][j]=min(dp[i][j],dp[i-1][j-k]+m[i][k])
#dp[i][j] = min(dp[i][j], dp[i - 1][k]+m[i][j-k])
print(min(dp[n-1]))
``` | output | 1 | 107,582 | 4 | 215,165 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.
There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th hour, and last lesson is during j-th hour, then he spends j - i + 1 hours in the university during this day. If there are no lessons during some day, then Ivan stays at home and therefore spends 0 hours in the university.
Ivan doesn't like to spend a lot of time in the university, so he has decided to skip some lessons. He cannot skip more than k lessons during the week. After deciding which lessons he should skip and which he should attend, every day Ivan will enter the university right before the start of the first lesson he does not skip, and leave it after the end of the last lesson he decides to attend. If Ivan skips all lessons during some day, he doesn't go to the university that day at all.
Given n, m, k and Ivan's timetable, can you determine the minimum number of hours he has to spend in the university during one week, if he cannot skip more than k lessons?
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 500, 0 ≤ k ≤ 500) — the number of days in the Berland week, the number of working hours during each day, and the number of lessons Ivan can skip, respectively.
Then n lines follow, i-th line containing a binary string of m characters. If j-th character in i-th line is 1, then Ivan has a lesson on i-th day during j-th hour (if it is 0, there is no such lesson).
Output
Print the minimum number of hours Ivan has to spend in the university during the week if he skips not more than k lessons.
Examples
Input
2 5 1
01001
10110
Output
5
Input
2 5 0
01001
10110
Output
8
Note
In the first example Ivan can skip any of two lessons during the first day, so he spends 1 hour during the first day and 4 hours during the second day.
In the second example Ivan can't skip any lessons, so he spends 4 hours every day. | instruction | 0 | 107,583 | 4 | 215,166 |
Tags: dp
Correct Solution:
```
n, m, k = input().split(' ')
n = int(n)
m = int(m)
k = int(k)
ind = []
pre = []
for _ in range(n):
s = input()
ind.append([])
for i, c in enumerate(s):
if c == '1':
ind[-1].append(i)
for i in range(n):
pre.append([])
for j in range(k + 1):
pre[i].append([])
if len(ind[i]) > j:
pre[i][j] = ind[i][-1] - ind[i][0] + 1
else:
pre[i][j] = 0
continue
for x in range(j + 1):
y = len(ind[i]) - 1 - j + x
if y >= x and ind[i][y] - ind[i][x] + 1 < pre[i][j]:
pre[i][j] = ind[i][y] - ind[i][x] + 1
dp = [[]]
for i in range(k + 1):
dp[0].append(pre[0][i])
for i in range(1, n):
dp.append([])
for j in range(0, k + 1):
dp[i].append(pre[i][j] + dp[i - 1][0])
for z in range(j + 1):
dp[i][j] = min(dp[i][j], dp[i - 1][z] + pre[i][j - z])
print (dp[n - 1][k])
``` | output | 1 | 107,583 | 4 | 215,167 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.
There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th hour, and last lesson is during j-th hour, then he spends j - i + 1 hours in the university during this day. If there are no lessons during some day, then Ivan stays at home and therefore spends 0 hours in the university.
Ivan doesn't like to spend a lot of time in the university, so he has decided to skip some lessons. He cannot skip more than k lessons during the week. After deciding which lessons he should skip and which he should attend, every day Ivan will enter the university right before the start of the first lesson he does not skip, and leave it after the end of the last lesson he decides to attend. If Ivan skips all lessons during some day, he doesn't go to the university that day at all.
Given n, m, k and Ivan's timetable, can you determine the minimum number of hours he has to spend in the university during one week, if he cannot skip more than k lessons?
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 500, 0 ≤ k ≤ 500) — the number of days in the Berland week, the number of working hours during each day, and the number of lessons Ivan can skip, respectively.
Then n lines follow, i-th line containing a binary string of m characters. If j-th character in i-th line is 1, then Ivan has a lesson on i-th day during j-th hour (if it is 0, there is no such lesson).
Output
Print the minimum number of hours Ivan has to spend in the university during the week if he skips not more than k lessons.
Examples
Input
2 5 1
01001
10110
Output
5
Input
2 5 0
01001
10110
Output
8
Note
In the first example Ivan can skip any of two lessons during the first day, so he spends 1 hour during the first day and 4 hours during the second day.
In the second example Ivan can't skip any lessons, so he spends 4 hours every day. | instruction | 0 | 107,584 | 4 | 215,168 |
Tags: dp
Correct Solution:
```
import math
#import math
#------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now----------------------------------------------------import math
def calc(st,j):
ans=9999999999999999999999
#print(st)
if j>=len(st):
return 0
j=len(st)-j
for i in range(j-1,len(st)):
ans=min(ans,st[i]-st[i-j+1]+1)
return ans
n,m,k=map(int,input().split())
s=[]
for i in range(n):
s.append(input())
inf=99999999999999999999
dp=[[inf for i in range(k+1)]for j in range(n+1)]
for i in range(k+1):
dp[0][i]=0
for i in range(1,n+1):
st=[]
for ik in range(len(s[i-1])):
if s[i-1][ik]=='1':
st.append(ik)
for j in range(k+1):
no=calc(st,j)
#print(no,j)
for t in range(k+1-j):
dp[i][t+j]=min(dp[i][t+j],no+dp[i-1][t])
#print(dp)
print(dp[n][k])
``` | output | 1 | 107,584 | 4 | 215,169 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.
There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th hour, and last lesson is during j-th hour, then he spends j - i + 1 hours in the university during this day. If there are no lessons during some day, then Ivan stays at home and therefore spends 0 hours in the university.
Ivan doesn't like to spend a lot of time in the university, so he has decided to skip some lessons. He cannot skip more than k lessons during the week. After deciding which lessons he should skip and which he should attend, every day Ivan will enter the university right before the start of the first lesson he does not skip, and leave it after the end of the last lesson he decides to attend. If Ivan skips all lessons during some day, he doesn't go to the university that day at all.
Given n, m, k and Ivan's timetable, can you determine the minimum number of hours he has to spend in the university during one week, if he cannot skip more than k lessons?
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 500, 0 ≤ k ≤ 500) — the number of days in the Berland week, the number of working hours during each day, and the number of lessons Ivan can skip, respectively.
Then n lines follow, i-th line containing a binary string of m characters. If j-th character in i-th line is 1, then Ivan has a lesson on i-th day during j-th hour (if it is 0, there is no such lesson).
Output
Print the minimum number of hours Ivan has to spend in the university during the week if he skips not more than k lessons.
Examples
Input
2 5 1
01001
10110
Output
5
Input
2 5 0
01001
10110
Output
8
Note
In the first example Ivan can skip any of two lessons during the first day, so he spends 1 hour during the first day and 4 hours during the second day.
In the second example Ivan can't skip any lessons, so he spends 4 hours every day. | instruction | 0 | 107,585 | 4 | 215,170 |
Tags: dp
Correct Solution:
```
n, m, k = map(int, input().split())
DATA = [input() for i in range(n)]
#dp[n_day][used_cost]
#ans = min(dp[n_day][used_cost] for used_cost in range(k + 1))
#dp[n_day][used_cost] := min(dp[n_day - 1][prev_cost] + cost(pay used_cost - prev_cost in n_day) for prev_cost in range(used_cost + 1))
INF = 1 << 60
dp = [[INF]*(k + 10) for i in range(n + 10)]
dp[0][0] = 0
COST = [[INF]*(k + 10) for i in range(n + 10)]
for i, string in enumerate(DATA):
#COST[i + 1]
stack = []
for j in range(m):
if string[j] == "1":
stack.append(j)
L = len(stack)
for j in range(k + 10):
if j >= L:
COST[i + 1][j] = 0
continue
else:
for pos in range(j + 1):
l = pos
r = pos + L - 1 - j
COST[i+1][j] = min(COST[i+1][j], stack[r] - stack[l] + 1)
for day in range(1, n + 1):
for used_cost in range(k + 1):
dp[day][used_cost] = min(dp[day - 1][prev_cost] + COST[day]
[used_cost - prev_cost] for prev_cost in range(used_cost + 1))
ans = min(dp[n][used_cost] for used_cost in range(k + 1))
print(ans)
``` | output | 1 | 107,585 | 4 | 215,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.
There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th hour, and last lesson is during j-th hour, then he spends j - i + 1 hours in the university during this day. If there are no lessons during some day, then Ivan stays at home and therefore spends 0 hours in the university.
Ivan doesn't like to spend a lot of time in the university, so he has decided to skip some lessons. He cannot skip more than k lessons during the week. After deciding which lessons he should skip and which he should attend, every day Ivan will enter the university right before the start of the first lesson he does not skip, and leave it after the end of the last lesson he decides to attend. If Ivan skips all lessons during some day, he doesn't go to the university that day at all.
Given n, m, k and Ivan's timetable, can you determine the minimum number of hours he has to spend in the university during one week, if he cannot skip more than k lessons?
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 500, 0 ≤ k ≤ 500) — the number of days in the Berland week, the number of working hours during each day, and the number of lessons Ivan can skip, respectively.
Then n lines follow, i-th line containing a binary string of m characters. If j-th character in i-th line is 1, then Ivan has a lesson on i-th day during j-th hour (if it is 0, there is no such lesson).
Output
Print the minimum number of hours Ivan has to spend in the university during the week if he skips not more than k lessons.
Examples
Input
2 5 1
01001
10110
Output
5
Input
2 5 0
01001
10110
Output
8
Note
In the first example Ivan can skip any of two lessons during the first day, so he spends 1 hour during the first day and 4 hours during the second day.
In the second example Ivan can't skip any lessons, so he spends 4 hours every day.
Submitted Solution:
```
from collections import deque
n, m, k = map(int, input().split())
field = []
for i in range(n):
field.append(input())
save = [deque() for i in range(n)]
for i in range(n):
cur = [[0, 0, 0] for i in range(m)]
last = -1
for j in range(m - 1 , -1, -1):
if (field[i][j] == "1"):
if (last == -1):
cur[j][1] = 1
else:
cur[j][1] = last - j
last = j
last = -1
for j in range(m):
if (field[i][j] == "1"):
if (last == -1):
cur[j][0] = 1
else:
cur[j][0] = j - last
last = j
cur[j][2] = j
save[i].append(cur[j])
for cnt in range(k):
mx = [-1, -1, -1]
for i in range(n):
if (len(save[i])):
if (len(save[i]) == 1):
mx = max(mx, [1, i, 0])
else:
mx = max(mx, [save[i][0][1], i, 0], [save[i][-1][0], i, -1])
if (mx[0] == -1):
break
else:
if (mx[2] == 0):
save[mx[1]].popleft()
else:
save[mx[1]].pop()
ans = 0
for i in range(n):
if (len(save[i])):
ans += save[i][-1][2] - save[i][0][2] + 1
print(ans)
``` | instruction | 0 | 107,586 | 4 | 215,172 |
No | output | 1 | 107,586 | 4 | 215,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.
There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th hour, and last lesson is during j-th hour, then he spends j - i + 1 hours in the university during this day. If there are no lessons during some day, then Ivan stays at home and therefore spends 0 hours in the university.
Ivan doesn't like to spend a lot of time in the university, so he has decided to skip some lessons. He cannot skip more than k lessons during the week. After deciding which lessons he should skip and which he should attend, every day Ivan will enter the university right before the start of the first lesson he does not skip, and leave it after the end of the last lesson he decides to attend. If Ivan skips all lessons during some day, he doesn't go to the university that day at all.
Given n, m, k and Ivan's timetable, can you determine the minimum number of hours he has to spend in the university during one week, if he cannot skip more than k lessons?
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 500, 0 ≤ k ≤ 500) — the number of days in the Berland week, the number of working hours during each day, and the number of lessons Ivan can skip, respectively.
Then n lines follow, i-th line containing a binary string of m characters. If j-th character in i-th line is 1, then Ivan has a lesson on i-th day during j-th hour (if it is 0, there is no such lesson).
Output
Print the minimum number of hours Ivan has to spend in the university during the week if he skips not more than k lessons.
Examples
Input
2 5 1
01001
10110
Output
5
Input
2 5 0
01001
10110
Output
8
Note
In the first example Ivan can skip any of two lessons during the first day, so he spends 1 hour during the first day and 4 hours during the second day.
In the second example Ivan can't skip any lessons, so he spends 4 hours every day.
Submitted Solution:
```
n,m,k = map(int,input().split())
a = [0]*n
s = [0]*n
for i in range(n):
a[i] = list(map(int,list(input())))
s[i] = m-a[i][::-1].index(1)-a[i].index(1)
if min(s)<=k:
if min(s)==k:
t = s.index(min(s))
s[t] = 0
a[t] = [0]*m
k = 0
s = 0
for i in range(n):
if 1 in a[i]:
s+=(m-a[i][::-1].index(1)-a[i].index(1))
print (s)
else:
while min(s)<k:
for i in range(n):
if s[i]<k:
k-=s[i]
s[i] = 0
a[i] = [0]*m
s = 0
for i in range(n):
if 1 in a[i]:
s+=(m-a[i][::-1].index(1)-a[i].index(1))
print (s-k)
else:
s = 0
for i in range(n):
if 1 in a[i]:
s+=(m-a[i][::-1].index(1)-a[i].index(1))
print (s-k)
``` | instruction | 0 | 107,587 | 4 | 215,174 |
No | output | 1 | 107,587 | 4 | 215,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.
There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th hour, and last lesson is during j-th hour, then he spends j - i + 1 hours in the university during this day. If there are no lessons during some day, then Ivan stays at home and therefore spends 0 hours in the university.
Ivan doesn't like to spend a lot of time in the university, so he has decided to skip some lessons. He cannot skip more than k lessons during the week. After deciding which lessons he should skip and which he should attend, every day Ivan will enter the university right before the start of the first lesson he does not skip, and leave it after the end of the last lesson he decides to attend. If Ivan skips all lessons during some day, he doesn't go to the university that day at all.
Given n, m, k and Ivan's timetable, can you determine the minimum number of hours he has to spend in the university during one week, if he cannot skip more than k lessons?
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 500, 0 ≤ k ≤ 500) — the number of days in the Berland week, the number of working hours during each day, and the number of lessons Ivan can skip, respectively.
Then n lines follow, i-th line containing a binary string of m characters. If j-th character in i-th line is 1, then Ivan has a lesson on i-th day during j-th hour (if it is 0, there is no such lesson).
Output
Print the minimum number of hours Ivan has to spend in the university during the week if he skips not more than k lessons.
Examples
Input
2 5 1
01001
10110
Output
5
Input
2 5 0
01001
10110
Output
8
Note
In the first example Ivan can skip any of two lessons during the first day, so he spends 1 hour during the first day and 4 hours during the second day.
In the second example Ivan can't skip any lessons, so he spends 4 hours every day.
Submitted Solution:
```
n,m,k=map(int,input().split())
ls=[]
hs=0
for i in range(n):
ls.append([])
c=-1
a=input()
for j in a:
if j=='1':
if c!=-1:
ls[i]+=[c]
hs+=c
c=1
else:
if c!=-1:
c+=1
if c!=-1:
ls[i]+=[1]
hs+=1
for i in range(k):
ma,ima,jma=0,1,1
for j in range(n):
if len(ls[j])==0:
continue
elif len(ls[j])==1 and 1>ma:
ma,jma,ima=1,j,0
elif ls[j][0]>ma:
ma,jma,ima=ls[j][0],j,0
elif ls[j][-2]>ma:
ma,jma,ima=ls[j][-2],j,-1
if ima!=1:
hs-=ma
ls[jma].pop(ima)
else:
1/0
print(hs)
``` | instruction | 0 | 107,588 | 4 | 215,176 |
No | output | 1 | 107,588 | 4 | 215,177 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.
There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th hour, and last lesson is during j-th hour, then he spends j - i + 1 hours in the university during this day. If there are no lessons during some day, then Ivan stays at home and therefore spends 0 hours in the university.
Ivan doesn't like to spend a lot of time in the university, so he has decided to skip some lessons. He cannot skip more than k lessons during the week. After deciding which lessons he should skip and which he should attend, every day Ivan will enter the university right before the start of the first lesson he does not skip, and leave it after the end of the last lesson he decides to attend. If Ivan skips all lessons during some day, he doesn't go to the university that day at all.
Given n, m, k and Ivan's timetable, can you determine the minimum number of hours he has to spend in the university during one week, if he cannot skip more than k lessons?
Input
The first line contains three integers n, m and k (1 ≤ n, m ≤ 500, 0 ≤ k ≤ 500) — the number of days in the Berland week, the number of working hours during each day, and the number of lessons Ivan can skip, respectively.
Then n lines follow, i-th line containing a binary string of m characters. If j-th character in i-th line is 1, then Ivan has a lesson on i-th day during j-th hour (if it is 0, there is no such lesson).
Output
Print the minimum number of hours Ivan has to spend in the university during the week if he skips not more than k lessons.
Examples
Input
2 5 1
01001
10110
Output
5
Input
2 5 0
01001
10110
Output
8
Note
In the first example Ivan can skip any of two lessons during the first day, so he spends 1 hour during the first day and 4 hours during the second day.
In the second example Ivan can't skip any lessons, so he spends 4 hours every day.
Submitted Solution:
```
import sys
import math
from collections import defaultdict
n,m,k=map(int,sys.stdin.readline().split())
s=sys.stdin.readline()[:-1]
dp=[0 for _ in range(k+1)]
days=[]
for i in range(m):
if s[i]=='1':
days.append(i)
x=len(days)
for i in range(min(x,k+1)):
dp[i]=(days[-1]-days[i]+1)
if x<k+1:
last=0
for i in range(x,k+1):
dp[i]=last
#print(dp,'dp',k+1,x)
for _ in range(n-1):
newdp=[1e10 for _ in range(k+1)]
s=sys.stdin.readline()[:-1]
#print(s,'s')
days=[]
for i in range(m):
if s[i]=='1':
days.append(i)
x=len(days)
#last=days[-1]
if x==0:
days=[0]
if x<k+1 and x!=0:
for i in range(x,k+1):
days.append(days[-1])
for i in range(k+1):
if days[-1]!=0:
newdp[i]=dp[i]+days[-1]-days[0]+1
else:
newdp[i]=dp[i]
#print(i,'i',days[-1],'last',days[0],'first',newdp[i])
for j in range(i):
if i-j>=x and days[-1]==0:
newdp[i]=min(newdp[i],dp[j]+0)
else:
#print(i,'i',j,'j')
newdp[i]=min(newdp[i],dp[j]+days[-1]-days[i-j]+1)
dp=[i for i in newdp]
#print(dp,'dp')
print(dp[-1])
``` | instruction | 0 | 107,589 | 4 | 215,178 |
No | output | 1 | 107,589 | 4 | 215,179 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.
Input
The first line contains integer number n (1 ≤ n ≤ 109) — current year in Berland.
Output
Output amount of years from the current year to the next lucky one.
Examples
Input
4
Output
1
Input
201
Output
99
Input
4000
Output
1000
Note
In the first example next lucky year is 5. In the second one — 300. In the third — 5000. | instruction | 0 | 108,314 | 4 | 216,628 |
Tags: implementation
Correct Solution:
```
#!/bin/python3
n = int(input())
if len(str(n)) == 1:
print(1)
else:
c = '{:<0{}d}'.format(1, int(len(str(n))))
c = int(c)
print(((c+n)-(n%c))-n)
``` | output | 1 | 108,314 | 4 | 216,629 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.
Input
The first line contains integer number n (1 ≤ n ≤ 109) — current year in Berland.
Output
Output amount of years from the current year to the next lucky one.
Examples
Input
4
Output
1
Input
201
Output
99
Input
4000
Output
1000
Note
In the first example next lucky year is 5. In the second one — 300. In the third — 5000. | instruction | 0 | 108,315 | 4 | 216,630 |
Tags: implementation
Correct Solution:
```
x = input()
a = 10**(len(x)-1)
if int(x) < 10:
print(1)
else:
print(((a - int(x[1:]))))
``` | output | 1 | 108,315 | 4 | 216,631 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.
Input
The first line contains integer number n (1 ≤ n ≤ 109) — current year in Berland.
Output
Output amount of years from the current year to the next lucky one.
Examples
Input
4
Output
1
Input
201
Output
99
Input
4000
Output
1000
Note
In the first example next lucky year is 5. In the second one — 300. In the third — 5000. | instruction | 0 | 108,316 | 4 | 216,632 |
Tags: implementation
Correct Solution:
```
s=input()
if len(s)==1:print(1)
else:print((10**(len(s)-1))-(int(s[1:])))
``` | output | 1 | 108,316 | 4 | 216,633 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.
Input
The first line contains integer number n (1 ≤ n ≤ 109) — current year in Berland.
Output
Output amount of years from the current year to the next lucky one.
Examples
Input
4
Output
1
Input
201
Output
99
Input
4000
Output
1000
Note
In the first example next lucky year is 5. In the second one — 300. In the third — 5000. | instruction | 0 | 108,317 | 4 | 216,634 |
Tags: implementation
Correct Solution:
```
n = input()
res = str(int(n[0])+1)
for i in range(0, len(n)-1):
res += '0'
print(int(res)-int(n))
``` | output | 1 | 108,317 | 4 | 216,635 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.