message stringlengths 2 43.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 853 107k | cluster float64 24 24 | __index_level_0__ int64 1.71k 214k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1 to n in order they came.
The i-th request is characterized by two values: si — the day when a client wants to start the repair of his car, di — duration (in days) to repair the car. The days are enumerated from 1, the first day is tomorrow, the second day is the day after tomorrow and so on.
Polycarp is making schedule by processing requests in the order from the first to the n-th request. He schedules the i-th request as follows:
* If the car repair shop is idle for di days starting from si (si, si + 1, ..., si + di - 1), then these days are used to repair a car of the i-th client.
* Otherwise, Polycarp finds the first day x (from 1 and further) that there are di subsequent days when no repair is scheduled starting from x. In other words he chooses the smallest positive x that all days x, x + 1, ..., x + di - 1 are not scheduled for repair of any car. So, the car of the i-th client will be repaired in the range [x, x + di - 1]. It is possible that the day x when repair is scheduled to start will be less than si.
Given n requests, you are asked to help Polycarp schedule all of them according to the rules above.
Input
The first line contains integer n (1 ≤ n ≤ 200) — the number of requests from clients.
The following n lines contain requests, one request per line. The i-th request is given as the pair of integers si, di (1 ≤ si ≤ 109, 1 ≤ di ≤ 5·106), where si is the preferred time to start repairing the i-th car, di is the number of days to repair the i-th car.
The requests should be processed in the order they are given in the input.
Output
Print n lines. The i-th line should contain two integers — the start day to repair the i-th car and the finish day to repair the i-th car.
Examples
Input
3
9 2
7 3
2 4
Output
9 10
1 3
4 7
Input
4
1000000000 1000000
1000000000 1000000
100000000 1000000
1000000000 1000000
Output
1000000000 1000999999
1 1000000
100000000 100999999
1000001 2000000
Submitted Solution:
```
from bisect import bisect_left, insort_left
a = []
n = int(input())
for _ in range(n):
#print(a)
s, d = map(int, input().split())
if len(a) == 0:
a.append((s, s + d - 1))
print(s, s+d - 1)
continue
p = bisect_left(a, (s, s + d - 1))
#print('p', p)
ok = True
if p > 0 and a[p-1][1] >= s:
ok = False
if p < len(a) and a[p][0] <= s + d - 1:
ok = False
if ok:
insort_left(a, (s, s + d - 1))
print(s, s + d - 1)
else:
ok = False
for i in range(len(a)):
if i == 0:
if a[0][0] > d:
a = [(1, d)] + a
print(1,d)
ok = True
break
else:
if a[i - 1][1] + d < a[i][0]:
insort_left(a, (a[i - 1][1] + 1, a[i - 1][1] + d))
print(a[i - 1][1] + 1, a[i - 1][1] + d)
ok = True
break
if not ok:
insort_left(a, (a[-1][1] + 1, a[-1][1] + d))
print(a[-1][1] + 1, a[-1][1] + d)
#print(a)
``` | instruction | 0 | 72,965 | 24 | 145,930 |
No | output | 1 | 72,965 | 24 | 145,931 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total. | instruction | 0 | 73,015 | 24 | 146,030 |
Tags: brute force, greedy
Correct Solution:
```
n,k,m = map(int, input().split())
t = sorted(map(int, input().split()), key=int)
s = sum(t)
ans = 0
for i in range(n+1):
curr_ans = i*(k+1)
tot = m - i*s
if tot < 0:
break
for x in t:
c = min(n-i, tot//x)
if not c:
break
tot -= c*x
curr_ans += c
ans = max(ans, curr_ans)
print(ans)
``` | output | 1 | 73,015 | 24 | 146,031 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total. | instruction | 0 | 73,016 | 24 | 146,032 |
Tags: brute force, greedy
Correct Solution:
```
n, k, M = map(int, input().split())
t = list(map(int, input().split()))
sumt = sum(t)
score = 0
t.sort()
for i in range(n + 1):
m = M - sumt * i
if m < 0:
break
r = i * (k + 1)
for x in t:
resheno = min((n - i), m // x)
r += resheno
m -= resheno * x
score = max(score, r)
print(score)
``` | output | 1 | 73,016 | 24 | 146,033 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total. | instruction | 0 | 73,017 | 24 | 146,034 |
Tags: brute force, greedy
Correct Solution:
```
n, k, m = list(map(int, input().split()))
t = sorted(map(int, input().split()))
st = sum(t)
res = 0
for x in range(min(m//st,n)+1):
rem = m - x*st
r = x*(k+1)
for i in range(k):
div = min(rem//t[i], n-x)
rem -= div*t[i]
r += div
res = max(res, r)
print(res)
``` | output | 1 | 73,017 | 24 | 146,035 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total. | instruction | 0 | 73,018 | 24 | 146,036 |
Tags: brute force, greedy
Correct Solution:
```
n, k, M = map(int, input().split())
t = sorted(map(int, input().split()))
def calc(x):
tot = x * sum(t)
if tot > M:
return 0
tans = x * (k + 1)
for i in range(k - 1):
if t[i] * (n - x) + tot <= M:
tot += t[i] * (n - x)
tans += n - x
else:
tans += (M - tot) // t[i]
break
return tans
print(max([calc(x) for x in range(n + 1)]))
``` | output | 1 | 73,018 | 24 | 146,037 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total. | instruction | 0 | 73,019 | 24 | 146,038 |
Tags: brute force, greedy
Correct Solution:
```
n,k,m=map(int,input().split())
t=list(map(int,input().split()))
t.sort()
s=[]
for i in range(min(m//sum(t)+1,n)):
y=m
x=i*(k+1)
y-=i*sum(t)
f=n-i
for j in range(k-1):
x+=min(f,y//t[j])
y-=min(f,y//t[j])*t[j]
x+=2*(min(f,y//t[k-1]))
y-=min(f,y//t[k-1])*t[k-1]
s.append(x)
print(max(s))
``` | output | 1 | 73,019 | 24 | 146,039 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total. | instruction | 0 | 73,020 | 24 | 146,040 |
Tags: brute force, greedy
Correct Solution:
```
n, k, m = list(map(int, input().split()))
t = sorted(map(int, input().split()))
res = 0
for i in range(n+1):
rt = m-i*sum(t)
r = i*(k+1)
if (rt < 0): break
for j in range(k):
div = min(rt//t[j], n-i)
rt -= div*t[j]
r += div
res = max(res, r)
print(res)
``` | output | 1 | 73,020 | 24 | 146,041 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total. | instruction | 0 | 73,021 | 24 | 146,042 |
Tags: brute force, greedy
Correct Solution:
```
from itertools import accumulate
from bisect import *
n, k, m = list(map(int, input().split()))
t = sorted(map(int, input().split()))
res = 0
for x in range(min(n, m//sum(t))+1):
mm = m-x*sum(t); r = x*(k+1)
for i, ti in enumerate(t):
for _ in range(n-x):
if mm>=ti:
mm -= ti
r += 1 if i < k-1 else 2
res = max(res, r)
print(res)
``` | output | 1 | 73,021 | 24 | 146,043 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total. | instruction | 0 | 73,022 | 24 | 146,044 |
Tags: brute force, greedy
Correct Solution:
```
def main():
n, k, m = map(int, input().split(' '))
time = list(map(int, input().split(' ')))
time = sorted(time)
ans = 0
for i in range(n+1):
remain_time = m - i*sum(time)
if remain_time < 0:
break
value = (k+1) * i
for j in range(k):
for take in range(n-i):
if remain_time >= time[j]:
value = value + 1
remain_time = remain_time - time[j]
ans = max(ans, value)
print(ans)
if __name__ == "__main__":
main()
``` | output | 1 | 73,022 | 24 | 146,045 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.
Submitted Solution:
```
n, k, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
s = sum(a)
ans = 0
for i in range(n + 1):
t = s * i
cur = (k + 1) * i
if t > m:
break
t = m - t
for j in range(k):
x = min(t // a[j], n - i)
t -= (x * a[j])
cur += x
ans = max(ans, cur)
print(ans)
``` | instruction | 0 | 73,023 | 24 | 146,046 |
Yes | output | 1 | 73,023 | 24 | 146,047 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.
Submitted Solution:
```
n, k, m = list(map(int, input().split()))
t = sorted(map(int, input().split()))
res = 0
for x in range(min(m//sum(t),n)+1):
rem = m - x*sum(t)
r = x*(k+1)
for i in range(k):
div = min(rem//t[i], n-x)
rem -= div*t[i]
r += div
res = max(res, r)
print(res)
``` | instruction | 0 | 73,024 | 24 | 146,048 |
Yes | output | 1 | 73,024 | 24 | 146,049 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.
Submitted Solution:
```
f = lambda: map(int, input().split())
n, k, m = f()
p = sorted(f())
x = 0
s = sum(p)
for j in range(n + 1):
t = m - j * s
if t < 0: break
y = k * j + j
for i in p:
d = min(n - j, t // i)
y += d
t -= d * i
x = max(x, y)
print(x)
# Made By Mostafa_Khaled
``` | instruction | 0 | 73,025 | 24 | 146,050 |
Yes | output | 1 | 73,025 | 24 | 146,051 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.
Submitted Solution:
```
n,k,m = list(map(int, input().split()))
t = sorted(map(int, input().split()))
st = sum(t)
res = 0
for x in range(min(m//st, n)+1):
rem = m-x*st
r = x*(k+1)
for i in range(k):
y = min(rem//t[i], n-x)
rem -= t[i]*y
r += y
res = max(res, r)
print(res)
``` | instruction | 0 | 73,026 | 24 | 146,052 |
Yes | output | 1 | 73,026 | 24 | 146,053 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.
Submitted Solution:
```
n,k,M = [int(e) for e in input().split()]
t = [int(e) for e in input().split()]
score = 0
fin = 0
for i in range(len(t)):
for j in range(n):
if M >= t[i]:
score += 1
M -= t[i]
if i==len(t)-1:
score += 1
else :
fin = 1
break
if fin == 1:
break
print(score)
``` | instruction | 0 | 73,027 | 24 | 146,054 |
No | output | 1 | 73,027 | 24 | 146,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.
Submitted Solution:
```
t, s, time = input().split()
t, s, time = int(t), int(s), int(time)
subtasks = list(map(int, input().split()))
subtasks.sort(reverse=True)
score = 0
solved = 0
while time > 0:
taken = subtasks.pop()
solved += 1
if time >= taken * t:
time -= taken * t
score += t
last = t
else:
k = (time // taken)
score += k
last = k
time -= k * taken
break
if solved == s:
score += last
print(score)
``` | instruction | 0 | 73,028 | 24 | 146,056 |
No | output | 1 | 73,028 | 24 | 146,057 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.
Submitted Solution:
```
n,k,m=map(int,input().split())
lst=list(map(int,input().split()))
lst.sort()
s=sum(lst)
ans=ans2=c=0
g=m
h=n
if(s<=m):
t=m//s
if t>n:
ans2=(k+1)*n
g=0
else:
ans2=(k+1)*t
g=g-s*t
h=n-t
#print(ans2)
while 1:
if c>=k:
ans+=p
break
t=m//lst[c]
if t<=0:
break
if(t>n):
#print("if")
m=m-n*lst[c];
ans+=n
p=n
else:
m=m-t*lst[c]
#print("else")
ans+=t
p=t
c+=1
#print(p)
#print("sdsd",m,t,ans)
m=g
c=0
n=h
while 1:
if c>=k:
break
t=m//lst[c]
if t<=0:
break
if(t>n):
#print("if2")
m=m-n*lst[c];
ans2+=n
else:
m=m-t*lst[c]
#print("else2")
ans2+=t
c+=1
#print(m,t,ans2)
print(max(ans,ans2))
``` | instruction | 0 | 73,029 | 24 | 146,058 |
No | output | 1 | 73,029 | 24 | 146,059 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
Input
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109).
The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.
Output
Print the maximum amount of points Polycarp can earn in M minutes.
Examples
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
Note
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.
Submitted Solution:
```
n,k,m=map(int,input().split())
lst=list(map(int,input().split()))
lst.sort()
s=sum(lst)
ans=ans2=c=0
g=m
h=n
if(s<=m):
t=m//s
if t>n:
ans2=(k+1)*n
g=0
else:
ans2=(k+1)*t
g=g-s*t
h=n-t
#print(ans2)
while 1:
if c>=k:
ans+=t
break
t=m//lst[c]
if t<=0:
break
if(t>n):
#print("if")
m=m-n*lst[c];
ans+=n
else:
m=m-t*lst[c]
#print("else")
ans+=t
c+=1
#print(t)
#print("sdsd",m,t,ans)
m=g
c=0
n=h
while 1:
if c>=k:
break
t=m//lst[c]
if t<=0:
break
if(t>n):
#print("if2")
m=m-n*lst[c];
ans2+=n
else:
m=m-t*lst[c]
#print("else2")
ans2+=t
c+=1
#print(m,t,ans2)
print(max(ans,ans2))
``` | instruction | 0 | 73,030 | 24 | 146,060 |
No | output | 1 | 73,030 | 24 | 146,061 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
* he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
* he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
* he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
* and so on for each position until the end of s.
For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
Input
ncteho
Output
techno
Input
erfdcoeocs
Output
codeforces
Input
z
Output
z | instruction | 0 | 73,335 | 24 | 146,670 |
Tags: implementation, strings
Correct Solution:
```
word = input()
k = len(word) // 2
if 2 * k == len(word):
k = k - 1
s1 = word[:k][::-1]
s2 = word[k + 1:]
l, r = 0, 0
drow = word[k]
for i in range(1, len(word)):
if i % 2 == 1:
drow += s2[r]
r += 1
else:
drow += s1[l]
l += 1
print(drow)
``` | output | 1 | 73,335 | 24 | 146,671 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
* he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
* he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
* he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
* and so on for each position until the end of s.
For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
Input
ncteho
Output
techno
Input
erfdcoeocs
Output
codeforces
Input
z
Output
z | instruction | 0 | 73,336 | 24 | 146,672 |
Tags: implementation, strings
Correct Solution:
```
import string
s = input()
ss = ""
if (len(s) & 1):
for i in range(len(s) // 2):
ss = s[len(s) - i - 1] + s[i] + ss
ss = s[len(s) // 2] + ss
else:
for i in range(len(s) // 2):
ss = s[i] + s[len(s) - i - 1] + ss
print(ss)
``` | output | 1 | 73,336 | 24 | 146,673 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
* he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
* he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
* he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
* and so on for each position until the end of s.
For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
Input
ncteho
Output
techno
Input
erfdcoeocs
Output
codeforces
Input
z
Output
z | instruction | 0 | 73,337 | 24 | 146,674 |
Tags: implementation, strings
Correct Solution:
```
s=input()
s_new=""
k=len(s)
if k%2!=0:
for i in range(k//2):
s_new+=s[i]
s_new+=s[k-i-1]
s_new+=s[k//2]
elif k%2==0:
for i in range(k//2):
s_new += s[k-1 - i]
s_new+=s[i]
s_new=s_new[::-1]
print(s_new)
``` | output | 1 | 73,337 | 24 | 146,675 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
* he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
* he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
* he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
* and so on for each position until the end of s.
For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
Input
ncteho
Output
techno
Input
erfdcoeocs
Output
codeforces
Input
z
Output
z | instruction | 0 | 73,338 | 24 | 146,676 |
Tags: implementation, strings
Correct Solution:
```
from collections import deque as dd
x=dd(input())
a=[]
if len(x)%2==1:
a.append(x.popleft())
while x:
a.append(x.pop())
a.append(x.popleft())
a.reverse()
print(''.join([str(i) for i in a]))
``` | output | 1 | 73,338 | 24 | 146,677 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
* he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
* he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
* he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
* and so on for each position until the end of s.
For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
Input
ncteho
Output
techno
Input
erfdcoeocs
Output
codeforces
Input
z
Output
z | instruction | 0 | 73,339 | 24 | 146,678 |
Tags: implementation, strings
Correct Solution:
```
s = list(input())
if len(s) < 3:
print(*s,sep="")
else:
if len(s) % 2 == 0:
mid = len(s)//2
else:
mid = (len(s)//2)+1
l1=[]
l1.append(s[mid-1])
l2 = s[:mid-1]
l3 = s[mid:]
a = 0
for i in range(1,(len(s))//2):
l1.append(l3[i-1])
l1.append(l2[-i])
a+=1
if a!= len(l3):
l1.append(l3[-1])
if a != len(l2):
l1.append(l2[0])
print(*l1,sep="")
``` | output | 1 | 73,339 | 24 | 146,679 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
* he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
* he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
* he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
* and so on for each position until the end of s.
For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
Input
ncteho
Output
techno
Input
erfdcoeocs
Output
codeforces
Input
z
Output
z | instruction | 0 | 73,340 | 24 | 146,680 |
Tags: implementation, strings
Correct Solution:
```
String = str(input())
List= []
m =1
if len(String)%2 == 0:
List.append(String[len(String)//2 -1])
for i in range(len(String)-1):
if len(List)%2 == 1:
List.append(String[len(String)//2-1+m])
else:
List.append(String[len(String)//2-1-m])
m+=1
else:
List.append(String[len(String)//2])
for j in range(len(String)-1):
if len(List)%2 == 1:
List.append(String[len(String)//2+m])
else:
List.append(String[len(String)//2-m])
m+=1
print("".join(List))
``` | output | 1 | 73,340 | 24 | 146,681 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
* he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
* he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
* he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
* and so on for each position until the end of s.
For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
Input
ncteho
Output
techno
Input
erfdcoeocs
Output
codeforces
Input
z
Output
z | instruction | 0 | 73,341 | 24 | 146,682 |
Tags: implementation, strings
Correct Solution:
```
def pravo_levo():
from itertools import zip_longest
s = input()
n = len(s)
m = (n+1)//2
odd = list(s[:m])[::-1]
even = list(s[m:])
res = list(zip_longest(odd, even))
ans = ''
for j in res:
for i in j:
if i is not None:
ans += i
return ans
print(pravo_levo())
``` | output | 1 | 73,341 | 24 | 146,683 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
* he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
* he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
* he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
* and so on for each position until the end of s.
For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
Input
ncteho
Output
techno
Input
erfdcoeocs
Output
codeforces
Input
z
Output
z | instruction | 0 | 73,342 | 24 | 146,684 |
Tags: implementation, strings
Correct Solution:
```
s = input()
if len(s) % 2 == 0:
ans = s[len(s) // 2 - 1]
start = len(s) // 2 - 1
else:
ans = s[len(s) // 2]
start = len(s) // 2
for i in range(1, (len(s) - 1) // 2 + 1):
ans += s[start + i] + s[start - i]
if len(s) % 2 == 0:
ans += s[-1]
print(ans)
``` | output | 1 | 73,342 | 24 | 146,685 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
* he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
* he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
* he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
* and so on for each position until the end of s.
For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
Input
ncteho
Output
techno
Input
erfdcoeocs
Output
codeforces
Input
z
Output
z
Submitted Solution:
```
s = input()
n = len(s)
i = (n-1)//2
ans = [s[i]]
for j in range(1, n//2+1):
if i+j < n:
ans.append(s[i+j])
if i-j > -1:
ans.append(s[i-j])
print(''.join(ans))
``` | instruction | 0 | 73,343 | 24 | 146,686 |
Yes | output | 1 | 73,343 | 24 | 146,687 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
* he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
* he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
* he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
* and so on for each position until the end of s.
For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
Input
ncteho
Output
techno
Input
erfdcoeocs
Output
codeforces
Input
z
Output
z
Submitted Solution:
```
s = input()
if len(s) % 2 == 0:
i = len(s) // 2 - 1
j = len(s) // 2
while i >= 0:
print(s[i] + s[j], end = '')
i -= 1
j += 1
else:
i = len(s) // 2 - 1
j = len(s) // 2 + 1
print(s[len(s) // 2], end = '')
while i >= 0:
print(s[j] + s[i], end = '')
i -= 1
j += 1
``` | instruction | 0 | 73,344 | 24 | 146,688 |
Yes | output | 1 | 73,344 | 24 | 146,689 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
* he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
* he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
* he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
* and so on for each position until the end of s.
For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
Input
ncteho
Output
techno
Input
erfdcoeocs
Output
codeforces
Input
z
Output
z
Submitted Solution:
```
n=input()
s=""
w=""
if len(n)&1:
f=0
for i in range(len(n)//2):
f=1
s+=n[i]
s+=n[len(n)-i-1]
if f==0:
print(n)
else:
print((s+n[len(n)//2])[::-1])
else:
for i in range(len(n)//2):
s+=n[len(n)-i-1]
s+=n[i]
print(s[::-1])
``` | instruction | 0 | 73,345 | 24 | 146,690 |
Yes | output | 1 | 73,345 | 24 | 146,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
* he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
* he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
* he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
* and so on for each position until the end of s.
For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
Input
ncteho
Output
techno
Input
erfdcoeocs
Output
codeforces
Input
z
Output
z
Submitted Solution:
```
s = input()
news = ""
f = ""
if len(s) % 2 == 0:
for i in range(int(len(s) / 2)):
news = news + s[-1] + s[0]
s = s[1:-1]
else:
for i in range(int(len(s) / 2)):
news = news + s[0] + s[-1]
s = s[1:-1]
news = news + s[0]
for char in reversed( news ):
f = f + char
print(f)
``` | instruction | 0 | 73,346 | 24 | 146,692 |
Yes | output | 1 | 73,346 | 24 | 146,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
* he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
* he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
* he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
* and so on for each position until the end of s.
For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
Input
ncteho
Output
techno
Input
erfdcoeocs
Output
codeforces
Input
z
Output
z
Submitted Solution:
```
t = input()
s=''
if len(s) % 2 == 1:
i = len(t) // 2
k = 0
for j in range(len(t)):
if k == 1:
i += j
k = 0
else:
i -= j
k = 1
s+=t[i]
else:
i = len(t) // 2 - 1
k = 0
for j in range(len(t)):
if k == 1:
i += j
k = 0
else:
i -= j
k = 1
s+=t[i]
print(s)
``` | instruction | 0 | 73,347 | 24 | 146,694 |
No | output | 1 | 73,347 | 24 | 146,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
* he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
* he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
* he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
* and so on for each position until the end of s.
For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
Input
ncteho
Output
techno
Input
erfdcoeocs
Output
codeforces
Input
z
Output
z
Submitted Solution:
```
a = str(input())
l = []
if len(a) == 1:
print(a)
exit()
for i in range((len(a)+1)//2):
l.append(a[len(a) - i - 1])
if len(a) - i - 1 != i:
l.append(a[i])
l = reversed(l)
s = ''.join(l)
print(s)
``` | instruction | 0 | 73,348 | 24 | 146,696 |
No | output | 1 | 73,348 | 24 | 146,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
* he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
* he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
* he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
* and so on for each position until the end of s.
For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
Input
ncteho
Output
techno
Input
erfdcoeocs
Output
codeforces
Input
z
Output
z
Submitted Solution:
```
import math
def cypher(a):
if len(a) == 1:
print(a)
return
s1 = ''
mid = math.ceil(len(a)/2)
print(mid)
if len(a) == 3:
s1+= (a[mid] + a[mid+1] + a[mid-1])
print(s1)
return
for i in range(1,len(a)):
if mid - i >= 0:
s1 += a[mid-i]
if mid + i <= len(a):
s1 +=a[(mid-1)+i]
print(s1)
c = input().strip()
# c = 'qwertyuioasdfghjklrtyuiodfghjklqwertyuioasdfssddxb'
cypher(c)
``` | instruction | 0 | 73,349 | 24 | 146,698 |
No | output | 1 | 73,349 | 24 | 146,699 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:
* he writes down s_1,
* he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
* he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
* he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
* he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
* and so on for each position until the end of s.
For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
Input
ncteho
Output
techno
Input
erfdcoeocs
Output
codeforces
Input
z
Output
z
Submitted Solution:
```
n=input()
n=list(n)
k=['0']*len(n)
h=-1
for i in n:
if abs(h)<len(n):
k[h]=i
h-=2
for i in k:
if i in n:
n.remove(i)
k[0]=''
k.append('0')
k=k[1:]
y=0
for i in range(len(k)):
if k[i]=='0':
k[i]=n[y]
y+=1
for i in k:
print(i,end='')
``` | instruction | 0 | 73,350 | 24 | 146,700 |
No | output | 1 | 73,350 | 24 | 146,701 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
Note
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | instruction | 0 | 73,506 | 24 | 147,012 |
Tags: sortings
Correct Solution:
```
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
ilelec = lambda: map(int1,input().split())
alelec = lambda: list(map(int1, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c): print(["NO","YES"][c])
def y(c): print(["no","yes"][c])
def Yy(c): print(["No","Yes"][c])
G = []
for _ in range(int(input())):
u,v = ilele()
G.append((u,v))
G.sort()
count = 0
l,r = G[0]
for i in range(1,len(G)):
if l < G[i][0] and G[i][1] < r:
count += 1
if G[i][1] > r:
l,r = G[i]
print(count)
``` | output | 1 | 73,506 | 24 | 147,013 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
Note
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | instruction | 0 | 73,507 | 24 | 147,014 |
Tags: sortings
Correct Solution:
```
a = []
for _ in range(int(input())): a.append(list(map(int, input().split())))
m, s = -1, 0
for i, j in sorted(a):
if j > m:
m = j
else:
s+=1
print(s)
``` | output | 1 | 73,507 | 24 | 147,015 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
Note
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | instruction | 0 | 73,508 | 24 | 147,016 |
Tags: sortings
Correct Solution:
```
n=int(input())
arr=[]
for _ in range(n):
a,b=[int(x) for x in input().split()]
arr.append([a,b])
arr.sort()
maxi=arr[0][1]
ans=0
for i in range(1,n):
maxi=max(maxi,arr[i][1])
if maxi>arr[i][1]:
ans+=1
print(ans)
``` | output | 1 | 73,508 | 24 | 147,017 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
Note
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | instruction | 0 | 73,509 | 24 | 147,018 |
Tags: sortings
Correct Solution:
```
def main(inp):
n = int(inp())
events = [split_inp_int(inp) for __ in range(n)]
events.sort()
st = [events[0]]
total = 0
for start, end in events[1:]:
if not st:
st.append((start, end))
continue
top_s, top_e = st[-1]
if top_s == start:
continue
while st and end >= st[-1][1]:
st.pop()
total += 1 if st else 0
st.append((start, end))
print(total)
def split_inp_int(inp):
return list(map(int, inp().split()))
def use_fast_io():
import sys
class InputStorage:
def __init__(self, lines):
lines.reverse()
self.lines = lines
def input_func(self):
if self.lines:
return self.lines.pop()
else:
return ""
input_storage_obj = InputStorage(sys.stdin.readlines())
return input_storage_obj.input_func
from collections import Counter, defaultdict
from functools import reduce
import operator
import math
def product(arr_):
return reduce(operator.mul, arr_, 1)
if __name__ == "__main__":
main(use_fast_io())
``` | output | 1 | 73,509 | 24 | 147,019 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
Note
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | instruction | 0 | 73,510 | 24 | 147,020 |
Tags: sortings
Correct Solution:
```
t = [tuple(map(int, input().split())) for i in range(int(input()))]
t.sort()
c, s = 0, 0
for a, b in t:
if b < c:
s += 1
if b > c:
c = b
print(s)
``` | output | 1 | 73,510 | 24 | 147,021 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
Note
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | instruction | 0 | 73,511 | 24 | 147,022 |
Tags: sortings
Correct Solution:
```
n = int(input())
x = []
for i in range(n):
x.append(list(map(int, input().split())))
x.sort(key=lambda x: x[0])
maxend = 0
ans = 0
for a, b in x:
if (b < maxend):
ans += 1
else:
maxend = b
print(ans)
``` | output | 1 | 73,511 | 24 | 147,023 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
Note
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | instruction | 0 | 73,512 | 24 | 147,024 |
Tags: sortings
Correct Solution:
```
import time,math as mt,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
return int(stdin.readline())
def IO(): # to take string input
return stdin.readline()
def IP(): # to take tuple as input
return map(int,stdin.readline().split())
def L(): # to take list as input
return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
if a==0:
return b
elif b==0:
return a
if a>b:
return gcd(a%b,b)
else:
return gcd(a,b%a)
def readTree(): # to read tree
v=int(input())
adj=[set() for i in range(v+1)]
for i in range(v-1):
u1,u2=In()
adj[u1].add(u2)
adj[u2].add(u1)
return adj,v
def bfs(adj,v): # a schema of bfs
visited=[False]*(v+1)
q=deque()
while q:
pass
def sieve():
li=[True]*1000001
li[0],li[1]=False,False
for i in range(2,len(li),1):
if li[i]==True:
for j in range(i*i,len(li),i):
li[j]=False
prime=[]
for i in range(1000001):
if li[i]==True:
prime.append(i)
return prime
def setBit(n):
count=0
while n!=0:
n=n&(n-1)
count+=1
return count
mx=10**7
spf=[mx]*(mx+1)
def SPF():
spf[1]=1
for i in range(2,mx+1):
if spf[i]==mx:
spf[i]=i
for j in range(i*i,mx+1,i):
if i<spf[j]:
spf[j]=i
return
#####################################################################################
mod=10**9+7
def solve():
n=II()
li=[]
for i in range(n):
temp=L()
li.append(temp)
li.sort(key=lambda x:x[0])
l,r=li[0][0],li[0][1]
inside=0
for i in range(1,n):
nl,nr=li[i][0],li[i][1]
if nl>l and nr>r:
l,r=nl,nr
elif nl>l and nl<r:
inside+=1
P(inside)
#t=II()
#for i in range(t):
solve()
#######
#
#
####### # # # #### # # #
# # # # # # # # # # #
# #### # # #### #### # #
###### # # #### # # # # #
``` | output | 1 | 73,512 | 24 | 147,025 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
Note
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0. | instruction | 0 | 73,513 | 24 | 147,026 |
Tags: sortings
Correct Solution:
```
l=list(tuple(map(int,input().split())) for _ in range(int(input())))
l.sort(key=lambda x:(x[0],-x[1]))
a,b,cnt=l[0][0],l[0][1],0
for i in l:
if(i[0]>a and i[1]<b):
cnt+=1
else:
a,b=i[0],i[1]
print(cnt)
``` | output | 1 | 73,513 | 24 | 147,027 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
Note
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0.
Submitted Solution:
```
import sys
from math import log2,floor,ceil,sqrt,gcd
import bisect
# from collections import deque
sys.setrecursionlimit(10**5)
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 1000000007
n =int(ri())
lis = []
for i in range(n):
temp = Ri()
lis.append(temp)
lis.sort(key = lambda x : x[0])
cnt = 0
right = lis[0][1]
for i in range(1,len(lis)):
if lis[i][1] < right:
cnt+=1
else:
right= lis[i][1]
print(cnt)
``` | instruction | 0 | 73,514 | 24 | 147,028 |
Yes | output | 1 | 73,514 | 24 | 147,029 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
Note
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0.
Submitted Solution:
```
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
# from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
# import numpy as np
starttime = time.time()
# import numpy as np
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
try:
# sys.setrecursionlimit(int(pow(10,5)))
sys.stdin = open("input.txt", "r")
# sys.stdout = open("../output.txt", "w")
except:
pass
n=L()[0]
A=[L() for i in range(n)]
A.sort()
stk=[A[0]]
for i in range(1,n):
s,e=A[i]
if stk[-1][0]<s and e<stk[-1][1]:
continue
else:
stk.append([s,e])
print(n-len(stk))
endtime = time.time()
# print(f"Runtime of the program is {endtime - starttime}")
``` | instruction | 0 | 73,515 | 24 | 147,030 |
Yes | output | 1 | 73,515 | 24 | 147,031 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
Note
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0.
Submitted Solution:
```
import sys
input=sys.stdin.buffer.readline
I=lambda:list(map(int,input().split()))
n,=I()
ar=[]
for i in range(n):
ar.append(I())
ar.sort()
cur=ar[0][1]
ans=0
for i in range(1,n):
if ar[i][1]<cur:
ans+=1
else:
cur=ar[i][1]
print(ans)
``` | instruction | 0 | 73,516 | 24 | 147,032 |
Yes | output | 1 | 73,516 | 24 | 147,033 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
Note
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0.
Submitted Solution:
```
n = int(input())
I = lambda :map(int,input().split())
li = []
for _ in range (n) :
x, y = I()
li.append((x,y))
li.sort()
#print(li)
x , y = li[0]
minn = x
maxx = y
ans = 0
for _ in range (1,n) :
x , y = li[_]
#print(x,y)
if maxx > y :
ans+=1
maxx = max(maxx,y)
print(ans)
``` | instruction | 0 | 73,517 | 24 | 147,034 |
Yes | output | 1 | 73,517 | 24 | 147,035 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
Note
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0.
Submitted Solution:
```
n = int(input())
arr = []
s_arr = []
e_arr = []
for i in range(n):
a, b = input().split(" ")
s_arr.append((int(a), i))
e_arr.append((int(b), i))
if len(s_arr) <= 1:
print(0)
else:
s_s_arr = sorted(s_arr, key= lambda x: x[0])
s_e_arr = sorted(e_arr, key= lambda x: x[0], reverse=True)
r_c_m = dict()
prev = s_s_arr[0]
r_c_m[s_s_arr[0][1]] = [0, 0]
for i in range(1, len(s_s_arr)):
if s_s_arr[i][0] > prev[0]:
r_c_m[s_s_arr[i][1]] = [1, 0]
prev = s_e_arr[0]
r_c_m[s_e_arr[0][1]][1] = 0
for i in range(1, len(s_e_arr)):
if s_e_arr[i][0] < prev[0]:
r_c_m[s_e_arr[i][1]][1] = 1
r_c = 0
for item in r_c_m:
if r_c_m[item][0] == 1 and r_c_m[item][1] == 1:
r_c = r_c + 1
print(r_c)
``` | instruction | 0 | 73,518 | 24 | 147,036 |
No | output | 1 | 73,518 | 24 | 147,037 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
Note
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0.
Submitted Solution:
```
n = int(input())
arr = []
s_arr = []
e_arr = []
for i in range(n):
a, b = input().split(" ")
s_arr.append((a, i))
e_arr.append((b, i))
if len(s_arr) <= 1:
print(0)
else:
s_s_arr = sorted(s_arr, key= lambda x: x[0])
s_e_arr = sorted(e_arr, key= lambda x: x[0], reverse=True)
r_c_m = dict()
prev = s_s_arr[0]
r_c_m[s_s_arr[0][1]] = [0, 0]
for i in range(1, len(s_s_arr)):
if s_s_arr[i][0] > prev[0]:
r_c_m[s_s_arr[i][1]] = [1, 0]
prev = s_e_arr[0]
r_c_m[s_e_arr[0][1]][1] = 0
for i in range(1, len(s_e_arr)):
if s_e_arr[i][0] < prev[0]:
r_c_m[s_e_arr[i][1]][1] = 1
r_c = 0
for item in r_c_m:
if r_c_m[item][0] == 1 and r_c_m[item][1] == 1:
r_c = r_c + 1
print(r_c)
``` | instruction | 0 | 73,519 | 24 | 147,038 |
No | output | 1 | 73,519 | 24 | 147,039 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
Note
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0.
Submitted Solution:
```
# Getting Problem-Data from Codeforces.
eventCount,pairs = int(input()),[]
for i in range(eventCount):
newPair = tuple(map(int,input().split(' ')))
pairs.append(newPair)
# Sorting Pairs by first componenet.
from operator import itemgetter
pairs.sort(key=itemgetter(0))
print(pairs)
# Method to detemine if event-a contains event-b.
def isIncluded(a,b):
return a[0]<b[0] and b[1]<a[1]
# Algorithm.
prev,count = pairs[0],0
for j in range(1,eventCount):
if isIncluded(prev,pairs[j]):
count = count+1
prev = pairs[j]
print(count)
``` | instruction | 0 | 73,520 | 24 | 147,040 |
No | output | 1 | 73,520 | 24 | 147,041 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
Note
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0.
Submitted Solution:
```
n = int(input())
ys = []
xs = []
cnt = 0
for m in range(n):
lst = list(input().split())
xs.append(int(lst[0]))
ys.append(int(lst[1]))
sortedys = [x for _,x in sorted(zip(xs, ys))]
ymax = int(ys[0])
for i in sortedys:
if i < ymax:
cnt +=1
ymax = max(ymax, i)
print(cnt)
``` | instruction | 0 | 73,521 | 24 | 147,042 |
No | output | 1 | 73,521 | 24 | 147,043 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The progress is not standing still in Berland. Recently all garbage containers in Bertown, the capital of Berland, were replaced by differentiated recycling bins, each accepting some category of waste. While this will definitely improve the ecological situation, for some citizens it's difficult to get used to the habit of sorting waste.
Monocarp is one of those citizens who tries to get used to waste sorting. Today he has to take out the trash from his house. There are three containers near the Monocarp's house, the first one accepts paper waste, the second one accepts plastic waste, and the third one — all other types of waste. It is possible to fit c_1 items into the first container, c_2 items into the second container and c_3 items into the third container.
Monocarp has a lot of items to throw into containers. Some are made of paper, so Monocarp has to put them into the first container (he has a_1 such items), some are made of plastic, so he has to put them into the second container (he has a_2 such items), and some are neither paper nor plastic — so Monocarp has to put them into the third container (he has a_3 such items).
Unfortunately, there are also two categories of items that Monocarp is unsure of: he has a_4 items which are partially made of paper, so he will put each of these items either into the first container or into the third container. Similarly, he has a_5 items partially made of plastic, so he has to put each of them either into the second container or into the third container. Obviously, this choice is made separately for each item — for example, Monocarp can throw several partially-plastic items into the second container, and all other partially-plastic items — into the third one.
Now Monocarp wonders: is it possible to put each item into some container so that the first container will hold no more than c_1 items, the second one — no more than c_2 items, and the third one — no more than c_3 items?
Input
The first line contains one integer t (1 ≤ t ≤ 3 ⋅ 10^4) — the number of test cases.
Each test case consists of two lines. The first line of each test case contains three integers c_1, c_2, c_3 (0 ≤ c_1, c_2, c_3 ≤ 10^8) — the capacities of the containers.
The second line of each test case contains five integers a_1, a_2, a_3, a_4, a_5 (0 ≤ a_i ≤ 10^8), where a_i is the number of items of the i-th category Monocarp has to throw out (i = 1 is paper waste, i = 2 is plastic waste, i = 3 is general waste, i = 4 is partially-paper waste, i = 5 is partially-plastic waste).
Output
For each test case, print either YES if it is possible to fit all items into containers, or NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
7
1 2 3
1 2 3 0 0
2 2 3
1 2 3 1 0
2 2 3
1 2 3 0 1
1 2 5
1 2 3 1 1
0 0 0
0 0 0 0 0
0 0 4
1 0 0 0 0
13 37 42
0 0 0 40 47
Output
YES
YES
NO
YES
YES
NO
YES
Note
Explanations for the example test cases:
1. Monocarp can put 1 item of paper waste into the first container, 2 items of plastic waste into the second container, and 3 items of general waste into the third container;
2. Monocarp can put 1 item of paper waste and 1 item of partially-paper waste into the first container, 2 items of plastic waste into the second container, and 3 items of general waste into the third container;
3. there is no answer since either the second container should contain 3 items, or the third container should contain 4 items;
4. Monocarp can put 1 item of paper waste into the first container, 2 items of plastic waste into the second container, and 3 items of general waste, 1 item of partially-paper waste and 1 item of partially-plastic waste into the third container;
5. there is no waste at all, so all containers can be left empty;
6. there's no answer since it's impossible to put a paper item into the third container;
7. Monocarp can put 10 items of partially-paper waste into the first container, 37 items of partially-plastic waste into the second container, and 30 items of partially-paper waste and 10 items of partially-plastic waste into the third container. | instruction | 0 | 73,544 | 24 | 147,088 |
Tags: greedy, implementation
Correct Solution:
```
for _ in range(int(input())):
cap = list(map(int, input().split()))
val = list(map(int, input().split()))
sig = 0
for i in range(3):
if(cap[i] < val[i]):
print('NO')
sig = 1
break
if(sig == 1):
continue
r1 = cap[0]-val[0]
r2 = cap[1]-val[1]
r1 = val[3] - r1
r2 = val[4] - r2
if(r1 <0):
r1 = 0
if(r2 < 0):
r2 = 0
if(cap[2] - val[2] - (r1+r2) < 0 ):
print('NO')
continue
print('YES')
``` | output | 1 | 73,544 | 24 | 147,089 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.