message stringlengths 2 20.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 757 108k | cluster float64 4 4 | __index_level_0__ int64 1.51k 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.
Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.
According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.
Input
The only line contains three integers b, d and s (0 ≤ b, d, s ≤ 1018, b + d + s ≥ 1) — the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.
Output
Print single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation.
Examples
Input
3 2 1
Output
1
Input
1 0 0
Output
0
Input
1 1 1
Output
0
Input
1000000000000000000 0 1000000000000000000
Output
999999999999999999
Note
In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.
In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.
In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal. | instruction | 0 | 49,323 | 4 | 98,646 |
Tags: binary search, constructive algorithms, greedy, implementation, math
Correct Solution:
```
'''input
3 2 1
'''
b, d, s = map(int, input().split())
x = max(b, d, s)
x = x - 1
a = 0
if b < x:
a = a + x - b
if d < x:
a = a + x - d
if s < x:
a = a + x - s
print(a)
``` | output | 1 | 49,323 | 4 | 98,647 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.
Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.
According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.
Input
The only line contains three integers b, d and s (0 ≤ b, d, s ≤ 1018, b + d + s ≥ 1) — the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.
Output
Print single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation.
Examples
Input
3 2 1
Output
1
Input
1 0 0
Output
0
Input
1 1 1
Output
0
Input
1000000000000000000 0 1000000000000000000
Output
999999999999999999
Note
In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.
In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.
In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal. | instruction | 0 | 49,324 | 4 | 98,648 |
Tags: binary search, constructive algorithms, greedy, implementation, math
Correct Solution:
```
read = lambda: map(int, input().split())
b, d, s = read()
A = (0, 0, 0), (1, 0, 0), (1, 1, 0)
B = (0, 0, 0), (0, 0, 1), (0, 1, 1)
ans = float('inf')
for x1, y1, z1 in A:
for x2, y2, z2 in B:
x, y, z = x1 + x2, y1 + y2, z1 + z2
k = max(b - x, d - y, s - z)
cur = (k + x - b) + (k + y - d) + (k + z - s)
ans = min(ans, cur)
print(ans)
``` | output | 1 | 49,324 | 4 | 98,649 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.
Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.
According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.
Input
The only line contains three integers b, d and s (0 ≤ b, d, s ≤ 1018, b + d + s ≥ 1) — the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.
Output
Print single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation.
Examples
Input
3 2 1
Output
1
Input
1 0 0
Output
0
Input
1 1 1
Output
0
Input
1000000000000000000 0 1000000000000000000
Output
999999999999999999
Note
In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.
In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.
In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal. | instruction | 0 | 49,325 | 4 | 98,650 |
Tags: binary search, constructive algorithms, greedy, implementation, math
Correct Solution:
```
b,d,s=map(int,input().split())
ans=0
mx=max(b,d,s)
if(b<mx-1):
ans+=mx-1-b
if(d<mx-1):
ans+=mx-1-d
if(s<mx-1):
ans+=mx-1-s
print(ans)
``` | output | 1 | 49,325 | 4 | 98,651 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of days before the next Sunday.
Examples
Input
SAT
Output
1
Input
SUN
Output
7 | instruction | 0 | 51,948 | 4 | 103,896 |
"Correct Solution:
```
l=["SUN","MON","TUE","WED","THU","FRI","SAT"]
S=input()
r=7-l.index(S)
print(r)
``` | output | 1 | 51,948 | 4 | 103,897 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of days before the next Sunday.
Examples
Input
SAT
Output
1
Input
SUN
Output
7 | instruction | 0 | 51,949 | 4 | 103,898 |
"Correct Solution:
```
print({"SU":7,"MO":6,"TU":5,"WE":4,"TH":3,"FR":2,"SA":1}[input()[:2]])
``` | output | 1 | 51,949 | 4 | 103,899 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of days before the next Sunday.
Examples
Input
SAT
Output
1
Input
SUN
Output
7 | instruction | 0 | 51,950 | 4 | 103,900 |
"Correct Solution:
```
s=["SUN","MON","TUE","WED","THU","FRI","SAT"]
t=input()
print(7-s.index(t))
``` | output | 1 | 51,950 | 4 | 103,901 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of days before the next Sunday.
Examples
Input
SAT
Output
1
Input
SUN
Output
7 | instruction | 0 | 51,951 | 4 | 103,902 |
"Correct Solution:
```
a=input()
wday=["SUN","MON","TUE","WED","THU","FRI","SAT"]
print(7-wday.index(a))
``` | output | 1 | 51,951 | 4 | 103,903 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of days before the next Sunday.
Examples
Input
SAT
Output
1
Input
SUN
Output
7 | instruction | 0 | 51,952 | 4 | 103,904 |
"Correct Solution:
```
S=input()
day=['SUN','MON','TUE','WED','THU','FRI','SAT']
print(7-(day.index(S)))
``` | output | 1 | 51,952 | 4 | 103,905 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of days before the next Sunday.
Examples
Input
SAT
Output
1
Input
SUN
Output
7 | instruction | 0 | 51,953 | 4 | 103,906 |
"Correct Solution:
```
S = {"SUN":7,"MON":6,"TUE":5,"WED":4,"THU":3,"FRI":2,"SAT":1}
print(S[input()])
``` | output | 1 | 51,953 | 4 | 103,907 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of days before the next Sunday.
Examples
Input
SAT
Output
1
Input
SUN
Output
7 | instruction | 0 | 51,954 | 4 | 103,908 |
"Correct Solution:
```
a=['SUN','MON','TUE','WED','THU','FRI','SAT']
print(7-a.index(input()))
``` | output | 1 | 51,954 | 4 | 103,909 |
Provide a correct Python 3 solution for this coding contest problem.
Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of days before the next Sunday.
Examples
Input
SAT
Output
1
Input
SUN
Output
7 | instruction | 0 | 51,955 | 4 | 103,910 |
"Correct Solution:
```
S=input()
print(['','SAT','FRI','THU','WED','TUE','MON','SUN'].index(S))
``` | output | 1 | 51,955 | 4 | 103,911 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of days before the next Sunday.
Examples
Input
SAT
Output
1
Input
SUN
Output
7
Submitted Solution:
```
s = input()
l = ['SAT','FRI','THU','WED','TUE','MON','SUN']
print(l.index(s)+1)
``` | instruction | 0 | 51,956 | 4 | 103,912 |
Yes | output | 1 | 51,956 | 4 | 103,913 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of days before the next Sunday.
Examples
Input
SAT
Output
1
Input
SUN
Output
7
Submitted Solution:
```
S = input()
l = ['SUN','MON','TUE','WED','THU','FRI','SAT']
print(7-l.index(S))
``` | instruction | 0 | 51,957 | 4 | 103,914 |
Yes | output | 1 | 51,957 | 4 | 103,915 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of days before the next Sunday.
Examples
Input
SAT
Output
1
Input
SUN
Output
7
Submitted Solution:
```
S = input()
LD = ['SUN','MON','TUE','WED','THU','FRI','SAT']
print(7-LD.index(S))
``` | instruction | 0 | 51,958 | 4 | 103,916 |
Yes | output | 1 | 51,958 | 4 | 103,917 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of days before the next Sunday.
Examples
Input
SAT
Output
1
Input
SUN
Output
7
Submitted Solution:
```
week = ("SUN","MON","TUE","WED","THU","FRI","SAT")
print(7-week.index(input()))
``` | instruction | 0 | 51,959 | 4 | 103,918 |
Yes | output | 1 | 51,959 | 4 | 103,919 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of days before the next Sunday.
Examples
Input
SAT
Output
1
Input
SUN
Output
7
Submitted Solution:
```
s = input()
A =['SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON','SUN']
for i in range(1, 8):
if A[i] == S:
print(i)
break
``` | instruction | 0 | 51,960 | 4 | 103,920 |
No | output | 1 | 51,960 | 4 | 103,921 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of days before the next Sunday.
Examples
Input
SAT
Output
1
Input
SUN
Output
7
Submitted Solution:
```
dic = {1:'SAT', 2:'FRI', 3:'THU', 4:'WED', 5:'TUE', 6:'MON', 7:'SUN'}
a = input()
if a in dic:
print(dic[a])
``` | instruction | 0 | 51,961 | 4 | 103,922 |
No | output | 1 | 51,961 | 4 | 103,923 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of days before the next Sunday.
Examples
Input
SAT
Output
1
Input
SUN
Output
7
Submitted Solution:
```
D_dict = {}
D_dict['SUN'] = 7
D_dict['MON'] = 6
D_dict['TUE'] = 5
D_dict['WED'] = 4
D_dict['THU'] = 3
D_dict['FRI'] = 2
D_dict['SAT'] = 1
S = input()
D_dict[S]
``` | instruction | 0 | 51,962 | 4 | 103,924 |
No | output | 1 | 51,962 | 4 | 103,925 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given is a string S representing the day of the week today.
S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
Constraints
* S is `SUN`, `MON`, `TUE`, `WED`, `THU`, `FRI`, or `SAT`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the number of days before the next Sunday.
Examples
Input
SAT
Output
1
Input
SUN
Output
7
Submitted Solution:
```
s = input()
l = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
for i in range(7):
if s == l[i]:
print(7%i)
``` | instruction | 0 | 51,963 | 4 | 103,926 |
No | output | 1 | 51,963 | 4 | 103,927 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place!
This contest consists of n problems, and Pasha solves ith problem in ai time units (his solutions are always correct). At any moment of time he can be thinking about a solution to only one of the problems (that is, he cannot be solving two problems at the same time). The time Pasha spends to send his solutions is negligible. Pasha can send any number of solutions at the same moment.
Unfortunately, there are too many participants, and the website is not always working. Pasha received the information that the website will be working only during m time periods, jth period is represented by its starting moment lj and ending moment rj. Of course, Pasha can send his solution only when the website is working. In other words, Pasha can send his solution at some moment T iff there exists a period x such that lx ≤ T ≤ rx.
Pasha wants to know his best possible result. We need to tell him the minimal moment of time by which he is able to have solutions to all problems submitted, if he acts optimally, or say that it's impossible no matter how Pasha solves the problems.
Input
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of problems. The second line contains n integers ai (1 ≤ ai ≤ 105) — the time Pasha needs to solve ith problem.
The third line contains one integer m (0 ≤ m ≤ 1000) — the number of periods of time when the website is working. Next m lines represent these periods. jth line contains two numbers lj and rj (1 ≤ lj < rj ≤ 105) — the starting and the ending moment of jth period.
It is guaranteed that the periods are not intersecting and are given in chronological order, so for every j > 1 the condition lj > rj - 1 is met.
Output
If Pasha can solve and submit all the problems before the end of the contest, print the minimal moment of time by which he can have all the solutions submitted.
Otherwise print "-1" (without brackets).
Examples
Input
2
3 4
2
1 4
7 9
Output
7
Input
1
5
1
1 4
Output
-1
Input
1
5
1
1 5
Output
5
Note
In the first example Pasha can act like this: he solves the second problem in 4 units of time and sends it immediately. Then he spends 3 time units to solve the first problem and sends it 7 time units after the contest starts, because at this moment the website starts working again.
In the second example Pasha invents the solution only after the website stops working for the last time.
In the third example Pasha sends the solution exactly at the end of the first period. | instruction | 0 | 52,739 | 4 | 105,478 |
Tags: implementation
Correct Solution:
```
#!/usr/bin/pypy3
from sys import stdin,stderr
def readInts(): return map(int,stdin.readline().strip().split())
def print_err(*args,**kwargs): print(*args,file=stderr,**kwargs)
def solve(vs):
return None
def run():
n, = readInts()
a = readInts()
m, = readInts()
time_all = sum(a)
printed = False
for _ in range(m):
lj,rj = readInts()
if printed: continue
if time_all <= lj:
print(lj)
printed = True
elif time_all <= rj:
print(time_all)
printed = True
if not printed: print(-1)
run()
``` | output | 1 | 52,739 | 4 | 105,479 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place!
This contest consists of n problems, and Pasha solves ith problem in ai time units (his solutions are always correct). At any moment of time he can be thinking about a solution to only one of the problems (that is, he cannot be solving two problems at the same time). The time Pasha spends to send his solutions is negligible. Pasha can send any number of solutions at the same moment.
Unfortunately, there are too many participants, and the website is not always working. Pasha received the information that the website will be working only during m time periods, jth period is represented by its starting moment lj and ending moment rj. Of course, Pasha can send his solution only when the website is working. In other words, Pasha can send his solution at some moment T iff there exists a period x such that lx ≤ T ≤ rx.
Pasha wants to know his best possible result. We need to tell him the minimal moment of time by which he is able to have solutions to all problems submitted, if he acts optimally, or say that it's impossible no matter how Pasha solves the problems.
Input
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of problems. The second line contains n integers ai (1 ≤ ai ≤ 105) — the time Pasha needs to solve ith problem.
The third line contains one integer m (0 ≤ m ≤ 1000) — the number of periods of time when the website is working. Next m lines represent these periods. jth line contains two numbers lj and rj (1 ≤ lj < rj ≤ 105) — the starting and the ending moment of jth period.
It is guaranteed that the periods are not intersecting and are given in chronological order, so for every j > 1 the condition lj > rj - 1 is met.
Output
If Pasha can solve and submit all the problems before the end of the contest, print the minimal moment of time by which he can have all the solutions submitted.
Otherwise print "-1" (without brackets).
Examples
Input
2
3 4
2
1 4
7 9
Output
7
Input
1
5
1
1 4
Output
-1
Input
1
5
1
1 5
Output
5
Note
In the first example Pasha can act like this: he solves the second problem in 4 units of time and sends it immediately. Then he spends 3 time units to solve the first problem and sends it 7 time units after the contest starts, because at this moment the website starts working again.
In the second example Pasha invents the solution only after the website stops working for the last time.
In the third example Pasha sends the solution exactly at the end of the first period. | instruction | 0 | 52,740 | 4 | 105,480 |
Tags: implementation
Correct Solution:
```
n = int(int(input()))
a = list(map(int,input().split()))
a = sum(a)
m = int(input())
for i in range(m):
x,y = input().split()
x,y = int(x),int(y)
if y >= a:
print(max(a,x))
break
else:
print(-1)
``` | output | 1 | 52,740 | 4 | 105,481 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place!
This contest consists of n problems, and Pasha solves ith problem in ai time units (his solutions are always correct). At any moment of time he can be thinking about a solution to only one of the problems (that is, he cannot be solving two problems at the same time). The time Pasha spends to send his solutions is negligible. Pasha can send any number of solutions at the same moment.
Unfortunately, there are too many participants, and the website is not always working. Pasha received the information that the website will be working only during m time periods, jth period is represented by its starting moment lj and ending moment rj. Of course, Pasha can send his solution only when the website is working. In other words, Pasha can send his solution at some moment T iff there exists a period x such that lx ≤ T ≤ rx.
Pasha wants to know his best possible result. We need to tell him the minimal moment of time by which he is able to have solutions to all problems submitted, if he acts optimally, or say that it's impossible no matter how Pasha solves the problems.
Input
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of problems. The second line contains n integers ai (1 ≤ ai ≤ 105) — the time Pasha needs to solve ith problem.
The third line contains one integer m (0 ≤ m ≤ 1000) — the number of periods of time when the website is working. Next m lines represent these periods. jth line contains two numbers lj and rj (1 ≤ lj < rj ≤ 105) — the starting and the ending moment of jth period.
It is guaranteed that the periods are not intersecting and are given in chronological order, so for every j > 1 the condition lj > rj - 1 is met.
Output
If Pasha can solve and submit all the problems before the end of the contest, print the minimal moment of time by which he can have all the solutions submitted.
Otherwise print "-1" (without brackets).
Examples
Input
2
3 4
2
1 4
7 9
Output
7
Input
1
5
1
1 4
Output
-1
Input
1
5
1
1 5
Output
5
Note
In the first example Pasha can act like this: he solves the second problem in 4 units of time and sends it immediately. Then he spends 3 time units to solve the first problem and sends it 7 time units after the contest starts, because at this moment the website starts working again.
In the second example Pasha invents the solution only after the website stops working for the last time.
In the third example Pasha sends the solution exactly at the end of the first period. | instruction | 0 | 52,741 | 4 | 105,482 |
Tags: implementation
Correct Solution:
```
n = int(input())
t = sum(map(int, input().split()))
m = int(input())
possible = False
best = 1000000000
for i in range(m):
l,r = map(int, input().split())
if l <= t <= r:
possible = True
if l >= t:
best = min(best, l)
if possible:
print(t)
elif best < 1000000000:
print(best)
else:
print(-1)
``` | output | 1 | 52,741 | 4 | 105,483 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place!
This contest consists of n problems, and Pasha solves ith problem in ai time units (his solutions are always correct). At any moment of time he can be thinking about a solution to only one of the problems (that is, he cannot be solving two problems at the same time). The time Pasha spends to send his solutions is negligible. Pasha can send any number of solutions at the same moment.
Unfortunately, there are too many participants, and the website is not always working. Pasha received the information that the website will be working only during m time periods, jth period is represented by its starting moment lj and ending moment rj. Of course, Pasha can send his solution only when the website is working. In other words, Pasha can send his solution at some moment T iff there exists a period x such that lx ≤ T ≤ rx.
Pasha wants to know his best possible result. We need to tell him the minimal moment of time by which he is able to have solutions to all problems submitted, if he acts optimally, or say that it's impossible no matter how Pasha solves the problems.
Input
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of problems. The second line contains n integers ai (1 ≤ ai ≤ 105) — the time Pasha needs to solve ith problem.
The third line contains one integer m (0 ≤ m ≤ 1000) — the number of periods of time when the website is working. Next m lines represent these periods. jth line contains two numbers lj and rj (1 ≤ lj < rj ≤ 105) — the starting and the ending moment of jth period.
It is guaranteed that the periods are not intersecting and are given in chronological order, so for every j > 1 the condition lj > rj - 1 is met.
Output
If Pasha can solve and submit all the problems before the end of the contest, print the minimal moment of time by which he can have all the solutions submitted.
Otherwise print "-1" (without brackets).
Examples
Input
2
3 4
2
1 4
7 9
Output
7
Input
1
5
1
1 4
Output
-1
Input
1
5
1
1 5
Output
5
Note
In the first example Pasha can act like this: he solves the second problem in 4 units of time and sends it immediately. Then he spends 3 time units to solve the first problem and sends it 7 time units after the contest starts, because at this moment the website starts working again.
In the second example Pasha invents the solution only after the website stops working for the last time.
In the third example Pasha sends the solution exactly at the end of the first period. | instruction | 0 | 52,742 | 4 | 105,484 |
Tags: implementation
Correct Solution:
```
n = int(input())
time = [int(x) for x in input().split()]
m = int(input())
periods =[]
for i in range(m):
l, r = (int(x) for x in input().split())
periods.append((l, r))
summ = sum(time)
for l, r in periods:
if l <= summ and r >= summ:
print(summ)
break
elif l >= summ:
print(l)
break
else:
print('-1')
``` | output | 1 | 52,742 | 4 | 105,485 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place!
This contest consists of n problems, and Pasha solves ith problem in ai time units (his solutions are always correct). At any moment of time he can be thinking about a solution to only one of the problems (that is, he cannot be solving two problems at the same time). The time Pasha spends to send his solutions is negligible. Pasha can send any number of solutions at the same moment.
Unfortunately, there are too many participants, and the website is not always working. Pasha received the information that the website will be working only during m time periods, jth period is represented by its starting moment lj and ending moment rj. Of course, Pasha can send his solution only when the website is working. In other words, Pasha can send his solution at some moment T iff there exists a period x such that lx ≤ T ≤ rx.
Pasha wants to know his best possible result. We need to tell him the minimal moment of time by which he is able to have solutions to all problems submitted, if he acts optimally, or say that it's impossible no matter how Pasha solves the problems.
Input
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of problems. The second line contains n integers ai (1 ≤ ai ≤ 105) — the time Pasha needs to solve ith problem.
The third line contains one integer m (0 ≤ m ≤ 1000) — the number of periods of time when the website is working. Next m lines represent these periods. jth line contains two numbers lj and rj (1 ≤ lj < rj ≤ 105) — the starting and the ending moment of jth period.
It is guaranteed that the periods are not intersecting and are given in chronological order, so for every j > 1 the condition lj > rj - 1 is met.
Output
If Pasha can solve and submit all the problems before the end of the contest, print the minimal moment of time by which he can have all the solutions submitted.
Otherwise print "-1" (without brackets).
Examples
Input
2
3 4
2
1 4
7 9
Output
7
Input
1
5
1
1 4
Output
-1
Input
1
5
1
1 5
Output
5
Note
In the first example Pasha can act like this: he solves the second problem in 4 units of time and sends it immediately. Then he spends 3 time units to solve the first problem and sends it 7 time units after the contest starts, because at this moment the website starts working again.
In the second example Pasha invents the solution only after the website stops working for the last time.
In the third example Pasha sends the solution exactly at the end of the first period. | instruction | 0 | 52,743 | 4 | 105,486 |
Tags: implementation
Correct Solution:
```
input()
s = sum(map(int, input().split()))
m = int(input())
ans = -1
for _ in range(m):
l, r = map(int, input().split())
if l >= s:
ans = l
break
if r >= s:
ans = s
break
print(ans)
``` | output | 1 | 52,743 | 4 | 105,487 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place!
This contest consists of n problems, and Pasha solves ith problem in ai time units (his solutions are always correct). At any moment of time he can be thinking about a solution to only one of the problems (that is, he cannot be solving two problems at the same time). The time Pasha spends to send his solutions is negligible. Pasha can send any number of solutions at the same moment.
Unfortunately, there are too many participants, and the website is not always working. Pasha received the information that the website will be working only during m time periods, jth period is represented by its starting moment lj and ending moment rj. Of course, Pasha can send his solution only when the website is working. In other words, Pasha can send his solution at some moment T iff there exists a period x such that lx ≤ T ≤ rx.
Pasha wants to know his best possible result. We need to tell him the minimal moment of time by which he is able to have solutions to all problems submitted, if he acts optimally, or say that it's impossible no matter how Pasha solves the problems.
Input
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of problems. The second line contains n integers ai (1 ≤ ai ≤ 105) — the time Pasha needs to solve ith problem.
The third line contains one integer m (0 ≤ m ≤ 1000) — the number of periods of time when the website is working. Next m lines represent these periods. jth line contains two numbers lj and rj (1 ≤ lj < rj ≤ 105) — the starting and the ending moment of jth period.
It is guaranteed that the periods are not intersecting and are given in chronological order, so for every j > 1 the condition lj > rj - 1 is met.
Output
If Pasha can solve and submit all the problems before the end of the contest, print the minimal moment of time by which he can have all the solutions submitted.
Otherwise print "-1" (without brackets).
Examples
Input
2
3 4
2
1 4
7 9
Output
7
Input
1
5
1
1 4
Output
-1
Input
1
5
1
1 5
Output
5
Note
In the first example Pasha can act like this: he solves the second problem in 4 units of time and sends it immediately. Then he spends 3 time units to solve the first problem and sends it 7 time units after the contest starts, because at this moment the website starts working again.
In the second example Pasha invents the solution only after the website stops working for the last time.
In the third example Pasha sends the solution exactly at the end of the first period. | instruction | 0 | 52,744 | 4 | 105,488 |
Tags: implementation
Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
s=sum(l)
q=int(input())
l=[]
for i in range(q):
l.append(list(map(int,input().split())))
ans= int(1e6)
for i in l:
if s<=i[0]:
ans=min(ans,i[0])
elif i[0]<=s<=i[1]:
ans=min(ans,s)
if ans>100000:
ans=-1
print(ans)
``` | output | 1 | 52,744 | 4 | 105,489 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place!
This contest consists of n problems, and Pasha solves ith problem in ai time units (his solutions are always correct). At any moment of time he can be thinking about a solution to only one of the problems (that is, he cannot be solving two problems at the same time). The time Pasha spends to send his solutions is negligible. Pasha can send any number of solutions at the same moment.
Unfortunately, there are too many participants, and the website is not always working. Pasha received the information that the website will be working only during m time periods, jth period is represented by its starting moment lj and ending moment rj. Of course, Pasha can send his solution only when the website is working. In other words, Pasha can send his solution at some moment T iff there exists a period x such that lx ≤ T ≤ rx.
Pasha wants to know his best possible result. We need to tell him the minimal moment of time by which he is able to have solutions to all problems submitted, if he acts optimally, or say that it's impossible no matter how Pasha solves the problems.
Input
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of problems. The second line contains n integers ai (1 ≤ ai ≤ 105) — the time Pasha needs to solve ith problem.
The third line contains one integer m (0 ≤ m ≤ 1000) — the number of periods of time when the website is working. Next m lines represent these periods. jth line contains two numbers lj and rj (1 ≤ lj < rj ≤ 105) — the starting and the ending moment of jth period.
It is guaranteed that the periods are not intersecting and are given in chronological order, so for every j > 1 the condition lj > rj - 1 is met.
Output
If Pasha can solve and submit all the problems before the end of the contest, print the minimal moment of time by which he can have all the solutions submitted.
Otherwise print "-1" (without brackets).
Examples
Input
2
3 4
2
1 4
7 9
Output
7
Input
1
5
1
1 4
Output
-1
Input
1
5
1
1 5
Output
5
Note
In the first example Pasha can act like this: he solves the second problem in 4 units of time and sends it immediately. Then he spends 3 time units to solve the first problem and sends it 7 time units after the contest starts, because at this moment the website starts working again.
In the second example Pasha invents the solution only after the website stops working for the last time.
In the third example Pasha sends the solution exactly at the end of the first period. | instruction | 0 | 52,745 | 4 | 105,490 |
Tags: implementation
Correct Solution:
```
# cook your dish here
n=input()
l=[int(x) for x in input().split()]
s=sum(l)
m=int(input())
ans=-1
for _ in range(m):
(a,b)=input().split()
(a,b)=(int(a),int(b))
if s<=b and ans==-1:
ans=max(a,s)
print(ans)
``` | output | 1 | 52,745 | 4 | 105,491 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place!
This contest consists of n problems, and Pasha solves ith problem in ai time units (his solutions are always correct). At any moment of time he can be thinking about a solution to only one of the problems (that is, he cannot be solving two problems at the same time). The time Pasha spends to send his solutions is negligible. Pasha can send any number of solutions at the same moment.
Unfortunately, there are too many participants, and the website is not always working. Pasha received the information that the website will be working only during m time periods, jth period is represented by its starting moment lj and ending moment rj. Of course, Pasha can send his solution only when the website is working. In other words, Pasha can send his solution at some moment T iff there exists a period x such that lx ≤ T ≤ rx.
Pasha wants to know his best possible result. We need to tell him the minimal moment of time by which he is able to have solutions to all problems submitted, if he acts optimally, or say that it's impossible no matter how Pasha solves the problems.
Input
The first line contains one integer n (1 ≤ n ≤ 1000) — the number of problems. The second line contains n integers ai (1 ≤ ai ≤ 105) — the time Pasha needs to solve ith problem.
The third line contains one integer m (0 ≤ m ≤ 1000) — the number of periods of time when the website is working. Next m lines represent these periods. jth line contains two numbers lj and rj (1 ≤ lj < rj ≤ 105) — the starting and the ending moment of jth period.
It is guaranteed that the periods are not intersecting and are given in chronological order, so for every j > 1 the condition lj > rj - 1 is met.
Output
If Pasha can solve and submit all the problems before the end of the contest, print the minimal moment of time by which he can have all the solutions submitted.
Otherwise print "-1" (without brackets).
Examples
Input
2
3 4
2
1 4
7 9
Output
7
Input
1
5
1
1 4
Output
-1
Input
1
5
1
1 5
Output
5
Note
In the first example Pasha can act like this: he solves the second problem in 4 units of time and sends it immediately. Then he spends 3 time units to solve the first problem and sends it 7 time units after the contest starts, because at this moment the website starts working again.
In the second example Pasha invents the solution only after the website stops working for the last time.
In the third example Pasha sends the solution exactly at the end of the first period. | instruction | 0 | 52,746 | 4 | 105,492 |
Tags: implementation
Correct Solution:
```
n = int(input())
arr = list(map(int, input().split()))
m = int(input())
moment = []
my = 0
for i in range(m):
a, b = map(int, input().split())
moment.append((a, b))
if b > my:
my = b
moment = sorted(moment)
total = sum(arr)
if total <= my:
for a, b in moment:
if total <= b:
print(str(max(total, a)))
break
else:
print('-1')
``` | output | 1 | 52,746 | 4 | 105,493 |
Provide a correct Python 3 solution for this coding contest problem.
Chokudai loves eating so much. However, his doctor Akensho told him that he was overweight, so he finally decided to lose his weight.
Chokudai made a slimming plan of a $D$-day cycle. It is represented by $D$ integers $w_0, ..., w_{D-1}$. His weight is $S$ on the 0-th day of the plan and he aims to reduce it to $T$ ($S > T$). If his weight on the $i$-th day of the plan is $x$, it will be $x + w_{i\%D}$ on the $(i+1)$-th day. Note that $i\%D$ is the remainder obtained by dividing $i$ by $D$. If his weight successfully gets less than or equal to $T$, he will stop slimming immediately.
If his slimming plan takes too many days or even does not end forever, he should reconsider it.
Determine whether it ends or not, and report how many days it takes if it ends.
Input
The input consists of a single test case formatted as follows.
$S$ $T$ $D$
$w_0 ... w_{D-1}$
The first line consists of three integers $S$, $T$, $D$ ($1 \leq S, T, D \leq 100,000, S > T$). The second line consists of $D$ integers $w_0, ..., w_{D-1}$ ($-100,000 \leq w_i \leq 100,000$ for each $i$).
Output
If Chokudai's slimming plan ends on the $d$-th day, print $d$ in one line. If it never ends, print $-1$.
Examples
Input
65 60 3
-2 3 -4
Output
4
Input
65 60 3
-2 10 -3
Output
-1
Input
100000 1 1
-1
Output
99999
Input
60 59 1
-123
Output
1 | instruction | 0 | 53,894 | 4 | 107,788 |
"Correct Solution:
```
S, T, D = map(int, input().split())
S -= T
*W, = map(int, input().split())
F = sum(W)
if F >= 0:
su = S
for i, w in enumerate(W):
su += w
if su <= 0:
print(i+1)
break
else:
print(-1)
exit(0)
su = 0
mi = 0
for d in W:
su += d
mi = min(mi, su)
k = max((S+mi-F-1) // -F, 0)
S += k*F
for i, w in enumerate(W):
S += w
if S <= 0:
print(i+1+k*D)
break
else:
assert 0
``` | output | 1 | 53,894 | 4 | 107,789 |
Provide a correct Python 3 solution for this coding contest problem.
You will be given a contest schedule for D days. For each d=1,2,\ldots,D, calculate the satisfaction at the end of day d.
Input
Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
t_1
t_2
\vdots
t_D
* The constraints and generation methods for the input part are the same as those for Problem A.
* For each d, t_d is an integer satisfying 1\leq t_d \leq 26, and your program is expected to work correctly for any value that meets the constraints.
Output
Let v_d be the satisfaction at the end of day d. Print D integers v_d to Standard Output in the following format:
v_1
v_2
\vdots
v_D
Output
Let v_d be the satisfaction at the end of day d. Print D integers v_d to Standard Output in the following format:
v_1
v_2
\vdots
v_D
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
1
17
13
14
13
Output
18398
35037
51140
65837
79325 | instruction | 0 | 54,545 | 4 | 109,090 |
"Correct Solution:
```
D = int(input())
c = [int(x) for x in input().split()]
s = []
for i in range(D):
s.append([int(x) for x in input().split()])
ans = 0
nissuu = [0] * 26
for i in range(D):
t = int(input())
for j in range(26):
if j == t-1:
nissuu[j] = 0
else:
nissuu[j] += 1
ans -= c[j]*nissuu[j]
ans += s[i][t-1]
print(ans)
``` | output | 1 | 54,545 | 4 | 109,091 |
Provide a correct Python 3 solution for this coding contest problem.
You will be given a contest schedule for D days. For each d=1,2,\ldots,D, calculate the satisfaction at the end of day d.
Input
Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
t_1
t_2
\vdots
t_D
* The constraints and generation methods for the input part are the same as those for Problem A.
* For each d, t_d is an integer satisfying 1\leq t_d \leq 26, and your program is expected to work correctly for any value that meets the constraints.
Output
Let v_d be the satisfaction at the end of day d. Print D integers v_d to Standard Output in the following format:
v_1
v_2
\vdots
v_D
Output
Let v_d be the satisfaction at the end of day d. Print D integers v_d to Standard Output in the following format:
v_1
v_2
\vdots
v_D
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
1
17
13
14
13
Output
18398
35037
51140
65837
79325 | instruction | 0 | 54,546 | 4 | 109,092 |
"Correct Solution:
```
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
manzoku = 0
last = [-1]*26
for day in range(D):
t = int(input())-1
manzoku += S[day][t]
last[t] = day
for i in range(26):
manzoku -= C[i]*(day-last[i])
print(manzoku)
``` | output | 1 | 54,546 | 4 | 109,093 |
Provide a correct Python 3 solution for this coding contest problem.
You will be given a contest schedule for D days. For each d=1,2,\ldots,D, calculate the satisfaction at the end of day d.
Input
Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
t_1
t_2
\vdots
t_D
* The constraints and generation methods for the input part are the same as those for Problem A.
* For each d, t_d is an integer satisfying 1\leq t_d \leq 26, and your program is expected to work correctly for any value that meets the constraints.
Output
Let v_d be the satisfaction at the end of day d. Print D integers v_d to Standard Output in the following format:
v_1
v_2
\vdots
v_D
Output
Let v_d be the satisfaction at the end of day d. Print D integers v_d to Standard Output in the following format:
v_1
v_2
\vdots
v_D
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
1
17
13
14
13
Output
18398
35037
51140
65837
79325 | instruction | 0 | 54,547 | 4 | 109,094 |
"Correct Solution:
```
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]
MAX = 26
last = [0] * MAX
score = 0
for day, e in enumerate(t, 1):
score += s[day-1][e-1]
last[e-1] = day
for ec, elast in zip(c, last):
score -= ec * (day - elast)
print(score)
``` | output | 1 | 54,547 | 4 | 109,095 |
Provide a correct Python 3 solution for this coding contest problem.
You will be given a contest schedule for D days. For each d=1,2,\ldots,D, calculate the satisfaction at the end of day d.
Input
Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
t_1
t_2
\vdots
t_D
* The constraints and generation methods for the input part are the same as those for Problem A.
* For each d, t_d is an integer satisfying 1\leq t_d \leq 26, and your program is expected to work correctly for any value that meets the constraints.
Output
Let v_d be the satisfaction at the end of day d. Print D integers v_d to Standard Output in the following format:
v_1
v_2
\vdots
v_D
Output
Let v_d be the satisfaction at the end of day d. Print D integers v_d to Standard Output in the following format:
v_1
v_2
\vdots
v_D
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
1
17
13
14
13
Output
18398
35037
51140
65837
79325 | instruction | 0 | 54,548 | 4 | 109,096 |
"Correct Solution:
```
D = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(D):
s.append(list(map(int, input().split())))
t = [(int(input()) - 1) for _ in range(D)]
last = [0] * 26
S = 0
for dd in range(1, D + 1):
S += s[dd - 1][t[dd - 1]]
last[t[dd - 1]] = dd
for i in range(26):
S -= c[i] * (dd - last[i])
print(S)
``` | output | 1 | 54,548 | 4 | 109,097 |
Provide a correct Python 3 solution for this coding contest problem.
You will be given a contest schedule for D days. For each d=1,2,\ldots,D, calculate the satisfaction at the end of day d.
Input
Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
t_1
t_2
\vdots
t_D
* The constraints and generation methods for the input part are the same as those for Problem A.
* For each d, t_d is an integer satisfying 1\leq t_d \leq 26, and your program is expected to work correctly for any value that meets the constraints.
Output
Let v_d be the satisfaction at the end of day d. Print D integers v_d to Standard Output in the following format:
v_1
v_2
\vdots
v_D
Output
Let v_d be the satisfaction at the end of day d. Print D integers v_d to Standard Output in the following format:
v_1
v_2
\vdots
v_D
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
1
17
13
14
13
Output
18398
35037
51140
65837
79325 | instruction | 0 | 54,549 | 4 | 109,098 |
"Correct Solution:
```
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) for _ in range(D)]
v = 0
last = [-1 for _ in range(26)]
for d in range(D):
last[t[d]-1] = d
v += s[d][t[d]-1]
for j in range(26):
v -= c[j]*(d-last[j])
print(v)
``` | output | 1 | 54,549 | 4 | 109,099 |
Provide a correct Python 3 solution for this coding contest problem.
You will be given a contest schedule for D days. For each d=1,2,\ldots,D, calculate the satisfaction at the end of day d.
Input
Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
t_1
t_2
\vdots
t_D
* The constraints and generation methods for the input part are the same as those for Problem A.
* For each d, t_d is an integer satisfying 1\leq t_d \leq 26, and your program is expected to work correctly for any value that meets the constraints.
Output
Let v_d be the satisfaction at the end of day d. Print D integers v_d to Standard Output in the following format:
v_1
v_2
\vdots
v_D
Output
Let v_d be the satisfaction at the end of day d. Print D integers v_d to Standard Output in the following format:
v_1
v_2
\vdots
v_D
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
1
17
13
14
13
Output
18398
35037
51140
65837
79325 | instruction | 0 | 54,550 | 4 | 109,100 |
"Correct Solution:
```
import random
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]
ans = 0
last = [0]*26
for i in range(1,d+1):
#x = 0
x = t[i-1]-1
#x = random.randrange(26)
last[x] = i
ans += s[i-1][x]
for j in range(26):
ans -= c[j]*(i-last[j])
print(ans)
``` | output | 1 | 54,550 | 4 | 109,101 |
Provide a correct Python 3 solution for this coding contest problem.
You will be given a contest schedule for D days. For each d=1,2,\ldots,D, calculate the satisfaction at the end of day d.
Input
Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
t_1
t_2
\vdots
t_D
* The constraints and generation methods for the input part are the same as those for Problem A.
* For each d, t_d is an integer satisfying 1\leq t_d \leq 26, and your program is expected to work correctly for any value that meets the constraints.
Output
Let v_d be the satisfaction at the end of day d. Print D integers v_d to Standard Output in the following format:
v_1
v_2
\vdots
v_D
Output
Let v_d be the satisfaction at the end of day d. Print D integers v_d to Standard Output in the following format:
v_1
v_2
\vdots
v_D
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
1
17
13
14
13
Output
18398
35037
51140
65837
79325 | instruction | 0 | 54,551 | 4 | 109,102 |
"Correct Solution:
```
D=int(input())
*c,=map(int,input().split())
s=[]
for i in range(D):
*x,=map(int,input().split())
s.append(x)
T=[]
for i in range(D):
T.append(int(input()))
last=[-1]*26
v=0
for d in range(D):
v+=s[d][T[d]-1]
last[T[d]-1]=d
for i in range(26):
v-=c[i]*(d-last[i])
print(v)
``` | output | 1 | 54,551 | 4 | 109,103 |
Provide a correct Python 3 solution for this coding contest problem.
You will be given a contest schedule for D days. For each d=1,2,\ldots,D, calculate the satisfaction at the end of day d.
Input
Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.
D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
t_1
t_2
\vdots
t_D
* The constraints and generation methods for the input part are the same as those for Problem A.
* For each d, t_d is an integer satisfying 1\leq t_d \leq 26, and your program is expected to work correctly for any value that meets the constraints.
Output
Let v_d be the satisfaction at the end of day d. Print D integers v_d to Standard Output in the following format:
v_1
v_2
\vdots
v_D
Output
Let v_d be the satisfaction at the end of day d. Print D integers v_d to Standard Output in the following format:
v_1
v_2
\vdots
v_D
Example
Input
5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
1
17
13
14
13
Output
18398
35037
51140
65837
79325 | instruction | 0 | 54,552 | 4 | 109,104 |
"Correct Solution:
```
d = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(d):
s.append(list(map(int, input().split())))
t = []
for _ in range(d):
t.append(int(input())-1)
v = 0
last = [-1]*26
for i in range(d):
v += s[i][t[i]]
last[t[i]] = i
for j in range(26):
v -= c[j]*(i-last[j])
print(v)
``` | output | 1 | 54,552 | 4 | 109,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Aizu Gakuen High School holds a school festival every year. The most popular of these is the haunted house. The most popular reason is that 9 classes do haunted houses instead of 1 or 2 classes. Each one has its own unique haunted house. Therefore, many visitors come from the neighborhood these days.
Therefore, the school festival executive committee decided to unify the admission fee for the haunted house in the school as shown in the table below, and based on this, total the total number of visitors and income for each class.
Admission fee list (admission fee per visitor)
Morning Afternoon
200 yen 300 yen
Enter the number of visitors in the morning and afternoon for each class, and create a program that creates a list of the total number of visitors and income for each class.
Input
The input is given in the following format:
name1 a1 b1
name2 a2 b2
::
name9 a9 b9
The input consists of 9 lines, the class name of the i-th class on the i-line namei (a half-width character string of 1 to 15 characters including numbers and alphabets), the number of visitors in the morning ai (0 ≤ ai ≤ 400) , Afternoon attendance bi (0 ≤ bi ≤ 400) is given.
Output
On the i-line, output the class name of the i-class, the total number of visitors, and the fee income on one line separated by blanks.
Example
Input
1a 132 243
1c 324 183
1f 93 199
2b 372 163
2c 229 293
2e 391 206
3a 118 168
3b 263 293
3d 281 102
Output
1a 375 99300
1c 507 119700
1f 292 78300
2b 535 123300
2c 522 133700
2e 597 140000
3a 286 74000
3b 556 140500
3d 383 86800
Submitted Solution:
```
# Your code here!
classmate = []
morning = []
afternoon = []
for i in range(9):
a,b,c=input().split()
classmate.append(a)
morning.append(int(b))
afternoon.append(int(c))
for i in range(9):
print(classmate[i], morning[i]+afternoon[i],morning[i] * 200 + afternoon[i] * 300)
``` | instruction | 0 | 54,713 | 4 | 109,426 |
Yes | output | 1 | 54,713 | 4 | 109,427 |
Provide a correct Python 3 solution for this coding contest problem.
problem
During this time of winter in Japan, hot days continue in Australia in the Southern Hemisphere. IOI, who lives in Australia, decided to plan what clothes to wear based on the weather forecast for a certain D day. The maximum temperature on day i (1 ≤ i ≤ D) is predicted to be Ti degrees.
IOI has N kinds of clothes, which are numbered from 1 to N. Clothes j (1 ≤ j ≤ N) are suitable for wearing on days when the maximum temperature is above Aj and below Bj. In addition, each clothes has an integer called "flashiness", and the flashiness of clothes j is Cj.
For each of the D days, IOI chooses to wear one of the clothes suitable for wearing when the maximum temperature follows the weather forecast. You may choose the same clothes as many times as you like, or you may choose clothes that are never chosen in D days.
IOI, who wanted to avoid wearing similar clothes in succession, decided to maximize the total absolute value of the difference in the flashiness of the clothes worn on consecutive days. That is, assuming that the clothes xi are selected on the i-day, we want to maximize the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD |. Create a program to find this maximum value.
input
The input consists of 1 + D + N lines.
On the first line, two integers D and N (2 ≤ D ≤ 200, 1 ≤ N ≤ 200) are written with a blank as a delimiter. D is the number of days to plan clothes and N is the number of clothes types IOI has.
One integer Ti (0 ≤ Ti ≤ 60) is written in the i-th line (1 ≤ i ≤ D) of the following D lines. This means that the maximum temperature on day i is forecast to be Ti degrees.
In the jth line (1 ≤ j ≤ N) of the following N lines, three integers Aj, Bj, Cj (0 ≤ Aj ≤ Bj ≤ 60, 0 ≤ Cj ≤ 100) are written. These indicate that clothing j is suitable for wearing on days when the maximum temperature is above Aj and below Bj, and the flashiness is Cj.
It is guaranteed that there will be at least one piece of clothing suitable for wearing when the maximum temperature follows the weather forecast for every D day.
output
Output the total absolute value of the difference in the flashiness of clothes worn on consecutive days, that is, the maximum value of the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD | in one line. ..
Input / output example
Input example 1
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output example 1
80
In the input / output example 1, the candidates for clothes on the first day are clothes 3 and 4, the candidates for clothes on the second day are clothes 2 and clothes 3, and the candidates for clothes on the third day are only clothes 3. is there. Choose clothes 4 on the first day, clothes 2 on the second day, and clothes 3 on the third day. That is, x1 = 4, x2 = 2, x3 = 3. At this time, the absolute value of the difference in the flashiness of the clothes on the first day and the second day is | 40 --90 | = 50, and the absolute value of the difference in the flashiness of the clothes on the second and third days is | 90-60 | = 30. The total is 80, which is the maximum value.
Input example 2
5 2
26
28
32
29
34
30 35 0
25 30 100
Output example 2
300
In Example 2 of input / output, clothes 2 on the first day, clothes 2 on the second day, clothes 1 on the third day, clothes 2 on the fourth day, and clothes 1 on the fifth day. You have to choose. At this time, the required value is | 100 --100 | + | 100 --0 | + | 0 --100 | + | 100 --0 | = 300.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output
80 | instruction | 0 | 54,715 | 4 | 109,430 |
"Correct Solution:
```
INF = 10 ** 20
def main():
d, n = map(int,input().split())
temp = [int(input()) for i in range(d)]
temp.insert(0,0)
alst = []
blst = []
clst = []
for i in range(n):
a,b,c = map(int,input().split())
alst.append(a)
blst.append(b)
clst.append(c)
dp = [[0] * n for i in range(d + 1)]
t1 = temp[1]
for i in range(n):
if not (alst[i] <= t1 <= blst[i]):
dp[1][i] = -INF
for i in range(2, d + 1):
t = temp[i]
predp = dp[i - 1]
for j in range(n):
cj = clst[j]
if alst[j] <= t <= blst[j]:
save = 0
for x in range(n):
cx = clst[x]
if cj >= cx:
v = predp[x] + cj - cx
else:
v = predp[x] - cj + cx
if save < v:
save = v
dp[i][j] = save
print(max(dp[d]))
main()
``` | output | 1 | 54,715 | 4 | 109,431 |
Provide a correct Python 3 solution for this coding contest problem.
problem
During this time of winter in Japan, hot days continue in Australia in the Southern Hemisphere. IOI, who lives in Australia, decided to plan what clothes to wear based on the weather forecast for a certain D day. The maximum temperature on day i (1 ≤ i ≤ D) is predicted to be Ti degrees.
IOI has N kinds of clothes, which are numbered from 1 to N. Clothes j (1 ≤ j ≤ N) are suitable for wearing on days when the maximum temperature is above Aj and below Bj. In addition, each clothes has an integer called "flashiness", and the flashiness of clothes j is Cj.
For each of the D days, IOI chooses to wear one of the clothes suitable for wearing when the maximum temperature follows the weather forecast. You may choose the same clothes as many times as you like, or you may choose clothes that are never chosen in D days.
IOI, who wanted to avoid wearing similar clothes in succession, decided to maximize the total absolute value of the difference in the flashiness of the clothes worn on consecutive days. That is, assuming that the clothes xi are selected on the i-day, we want to maximize the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD |. Create a program to find this maximum value.
input
The input consists of 1 + D + N lines.
On the first line, two integers D and N (2 ≤ D ≤ 200, 1 ≤ N ≤ 200) are written with a blank as a delimiter. D is the number of days to plan clothes and N is the number of clothes types IOI has.
One integer Ti (0 ≤ Ti ≤ 60) is written in the i-th line (1 ≤ i ≤ D) of the following D lines. This means that the maximum temperature on day i is forecast to be Ti degrees.
In the jth line (1 ≤ j ≤ N) of the following N lines, three integers Aj, Bj, Cj (0 ≤ Aj ≤ Bj ≤ 60, 0 ≤ Cj ≤ 100) are written. These indicate that clothing j is suitable for wearing on days when the maximum temperature is above Aj and below Bj, and the flashiness is Cj.
It is guaranteed that there will be at least one piece of clothing suitable for wearing when the maximum temperature follows the weather forecast for every D day.
output
Output the total absolute value of the difference in the flashiness of clothes worn on consecutive days, that is, the maximum value of the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD | in one line. ..
Input / output example
Input example 1
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output example 1
80
In the input / output example 1, the candidates for clothes on the first day are clothes 3 and 4, the candidates for clothes on the second day are clothes 2 and clothes 3, and the candidates for clothes on the third day are only clothes 3. is there. Choose clothes 4 on the first day, clothes 2 on the second day, and clothes 3 on the third day. That is, x1 = 4, x2 = 2, x3 = 3. At this time, the absolute value of the difference in the flashiness of the clothes on the first day and the second day is | 40 --90 | = 50, and the absolute value of the difference in the flashiness of the clothes on the second and third days is | 90-60 | = 30. The total is 80, which is the maximum value.
Input example 2
5 2
26
28
32
29
34
30 35 0
25 30 100
Output example 2
300
In Example 2 of input / output, clothes 2 on the first day, clothes 2 on the second day, clothes 1 on the third day, clothes 2 on the fourth day, and clothes 1 on the fifth day. You have to choose. At this time, the required value is | 100 --100 | + | 100 --0 | + | 0 --100 | + | 100 --0 | = 300.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output
80 | instruction | 0 | 54,716 | 4 | 109,432 |
"Correct Solution:
```
def run():
D, N = map(int, input().split())
d_li = [int(input()) for d in range(D)]
clothe_li = [list(map(int, input().split())) for n in range(N)]
dp = [[0]*N for d in range(D)]
#init
d = d_li[0]
for n, (a, b, c) in enumerate(clothe_li):
if (a <= d) and (d <= b):
dp[0][n] = 1
#loop
for i in range(1, D):
d = d_li[i]
#print(dp)
for pre_n in range(N):
if dp[i-1][pre_n] == 0: continue
for n, (a, b, c) in enumerate(clothe_li):
if (a <= d) and (d <= b):
#print(c)
dp[i][n] = max(dp[i][n],
dp[i-1][pre_n] + abs(clothe_li[pre_n][2] - c))
print(max(dp[-1])-1)
if __name__ == '__main__':
run()
``` | output | 1 | 54,716 | 4 | 109,433 |
Provide a correct Python 3 solution for this coding contest problem.
problem
During this time of winter in Japan, hot days continue in Australia in the Southern Hemisphere. IOI, who lives in Australia, decided to plan what clothes to wear based on the weather forecast for a certain D day. The maximum temperature on day i (1 ≤ i ≤ D) is predicted to be Ti degrees.
IOI has N kinds of clothes, which are numbered from 1 to N. Clothes j (1 ≤ j ≤ N) are suitable for wearing on days when the maximum temperature is above Aj and below Bj. In addition, each clothes has an integer called "flashiness", and the flashiness of clothes j is Cj.
For each of the D days, IOI chooses to wear one of the clothes suitable for wearing when the maximum temperature follows the weather forecast. You may choose the same clothes as many times as you like, or you may choose clothes that are never chosen in D days.
IOI, who wanted to avoid wearing similar clothes in succession, decided to maximize the total absolute value of the difference in the flashiness of the clothes worn on consecutive days. That is, assuming that the clothes xi are selected on the i-day, we want to maximize the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD |. Create a program to find this maximum value.
input
The input consists of 1 + D + N lines.
On the first line, two integers D and N (2 ≤ D ≤ 200, 1 ≤ N ≤ 200) are written with a blank as a delimiter. D is the number of days to plan clothes and N is the number of clothes types IOI has.
One integer Ti (0 ≤ Ti ≤ 60) is written in the i-th line (1 ≤ i ≤ D) of the following D lines. This means that the maximum temperature on day i is forecast to be Ti degrees.
In the jth line (1 ≤ j ≤ N) of the following N lines, three integers Aj, Bj, Cj (0 ≤ Aj ≤ Bj ≤ 60, 0 ≤ Cj ≤ 100) are written. These indicate that clothing j is suitable for wearing on days when the maximum temperature is above Aj and below Bj, and the flashiness is Cj.
It is guaranteed that there will be at least one piece of clothing suitable for wearing when the maximum temperature follows the weather forecast for every D day.
output
Output the total absolute value of the difference in the flashiness of clothes worn on consecutive days, that is, the maximum value of the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD | in one line. ..
Input / output example
Input example 1
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output example 1
80
In the input / output example 1, the candidates for clothes on the first day are clothes 3 and 4, the candidates for clothes on the second day are clothes 2 and clothes 3, and the candidates for clothes on the third day are only clothes 3. is there. Choose clothes 4 on the first day, clothes 2 on the second day, and clothes 3 on the third day. That is, x1 = 4, x2 = 2, x3 = 3. At this time, the absolute value of the difference in the flashiness of the clothes on the first day and the second day is | 40 --90 | = 50, and the absolute value of the difference in the flashiness of the clothes on the second and third days is | 90-60 | = 30. The total is 80, which is the maximum value.
Input example 2
5 2
26
28
32
29
34
30 35 0
25 30 100
Output example 2
300
In Example 2 of input / output, clothes 2 on the first day, clothes 2 on the second day, clothes 1 on the third day, clothes 2 on the fourth day, and clothes 1 on the fifth day. You have to choose. At this time, the required value is | 100 --100 | + | 100 --0 | + | 0 --100 | + | 100 --0 | = 300.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output
80 | instruction | 0 | 54,717 | 4 | 109,434 |
"Correct Solution:
```
INF = 10 ** 20
d, n = map(int,input().split())
temp = [int(input()) for i in range(d)]
temp.insert(0,0)
alst = []
blst = []
clst = []
for i in range(n):
a,b,c = map(int,input().split())
alst.append(a)
blst.append(b)
clst.append(c)
dp = [[0] * n for i in range(d + 1)]
for i in range(n):
if not (alst[i] <= temp[1] <= blst[i]):
dp[1][i] = -INF
for i in range(2, d + 1):
t = temp[i]
for j in range(n):
if alst[j] <= t <= blst[j]:
dp[i][j] = max(dp[i - 1][x] + abs(clst[j] - clst[x]) for x in range(n))
print(max(dp[d]))
``` | output | 1 | 54,717 | 4 | 109,435 |
Provide a correct Python 3 solution for this coding contest problem.
problem
During this time of winter in Japan, hot days continue in Australia in the Southern Hemisphere. IOI, who lives in Australia, decided to plan what clothes to wear based on the weather forecast for a certain D day. The maximum temperature on day i (1 ≤ i ≤ D) is predicted to be Ti degrees.
IOI has N kinds of clothes, which are numbered from 1 to N. Clothes j (1 ≤ j ≤ N) are suitable for wearing on days when the maximum temperature is above Aj and below Bj. In addition, each clothes has an integer called "flashiness", and the flashiness of clothes j is Cj.
For each of the D days, IOI chooses to wear one of the clothes suitable for wearing when the maximum temperature follows the weather forecast. You may choose the same clothes as many times as you like, or you may choose clothes that are never chosen in D days.
IOI, who wanted to avoid wearing similar clothes in succession, decided to maximize the total absolute value of the difference in the flashiness of the clothes worn on consecutive days. That is, assuming that the clothes xi are selected on the i-day, we want to maximize the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD |. Create a program to find this maximum value.
input
The input consists of 1 + D + N lines.
On the first line, two integers D and N (2 ≤ D ≤ 200, 1 ≤ N ≤ 200) are written with a blank as a delimiter. D is the number of days to plan clothes and N is the number of clothes types IOI has.
One integer Ti (0 ≤ Ti ≤ 60) is written in the i-th line (1 ≤ i ≤ D) of the following D lines. This means that the maximum temperature on day i is forecast to be Ti degrees.
In the jth line (1 ≤ j ≤ N) of the following N lines, three integers Aj, Bj, Cj (0 ≤ Aj ≤ Bj ≤ 60, 0 ≤ Cj ≤ 100) are written. These indicate that clothing j is suitable for wearing on days when the maximum temperature is above Aj and below Bj, and the flashiness is Cj.
It is guaranteed that there will be at least one piece of clothing suitable for wearing when the maximum temperature follows the weather forecast for every D day.
output
Output the total absolute value of the difference in the flashiness of clothes worn on consecutive days, that is, the maximum value of the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD | in one line. ..
Input / output example
Input example 1
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output example 1
80
In the input / output example 1, the candidates for clothes on the first day are clothes 3 and 4, the candidates for clothes on the second day are clothes 2 and clothes 3, and the candidates for clothes on the third day are only clothes 3. is there. Choose clothes 4 on the first day, clothes 2 on the second day, and clothes 3 on the third day. That is, x1 = 4, x2 = 2, x3 = 3. At this time, the absolute value of the difference in the flashiness of the clothes on the first day and the second day is | 40 --90 | = 50, and the absolute value of the difference in the flashiness of the clothes on the second and third days is | 90-60 | = 30. The total is 80, which is the maximum value.
Input example 2
5 2
26
28
32
29
34
30 35 0
25 30 100
Output example 2
300
In Example 2 of input / output, clothes 2 on the first day, clothes 2 on the second day, clothes 1 on the third day, clothes 2 on the fourth day, and clothes 1 on the fifth day. You have to choose. At this time, the required value is | 100 --100 | + | 100 --0 | + | 0 --100 | + | 100 --0 | = 300.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output
80 | instruction | 0 | 54,718 | 4 | 109,436 |
"Correct Solution:
```
D,N = map(int,input().split())
temperature = []
for _ in range(D):
temperature.append(int(input()))
temperature.insert(0,0)
clothes = []
for _ in range(N):
a,b,c = map(int,input().split())
clothes.append([a,b,c])
dp = [[0]*N for i in range(D+1)]
t1 = temperature[1]
for i in range(N):
if not (clothes[i][0] <= t1 <= clothes[i][1]):
dp[1][i] = -10**10
for day in range(2,D+1):
temp = temperature[day]
pred = dp[day-1]
for i in range(N):
ci = clothes[i][2]
if clothes[i][0] <= temp <= clothes[i][1]:
max_hadesa = 0
for j in range(N):
cj = clothes[j][2]
if ci >= cj:
tmp = pred[j]+ci-cj
else:
tmp = pred[j]+cj-ci
if max_hadesa<tmp:
max_hadesa = tmp
dp[day][i] = max_hadesa
print(max(dp[D]))
``` | output | 1 | 54,718 | 4 | 109,437 |
Provide a correct Python 3 solution for this coding contest problem.
problem
During this time of winter in Japan, hot days continue in Australia in the Southern Hemisphere. IOI, who lives in Australia, decided to plan what clothes to wear based on the weather forecast for a certain D day. The maximum temperature on day i (1 ≤ i ≤ D) is predicted to be Ti degrees.
IOI has N kinds of clothes, which are numbered from 1 to N. Clothes j (1 ≤ j ≤ N) are suitable for wearing on days when the maximum temperature is above Aj and below Bj. In addition, each clothes has an integer called "flashiness", and the flashiness of clothes j is Cj.
For each of the D days, IOI chooses to wear one of the clothes suitable for wearing when the maximum temperature follows the weather forecast. You may choose the same clothes as many times as you like, or you may choose clothes that are never chosen in D days.
IOI, who wanted to avoid wearing similar clothes in succession, decided to maximize the total absolute value of the difference in the flashiness of the clothes worn on consecutive days. That is, assuming that the clothes xi are selected on the i-day, we want to maximize the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD |. Create a program to find this maximum value.
input
The input consists of 1 + D + N lines.
On the first line, two integers D and N (2 ≤ D ≤ 200, 1 ≤ N ≤ 200) are written with a blank as a delimiter. D is the number of days to plan clothes and N is the number of clothes types IOI has.
One integer Ti (0 ≤ Ti ≤ 60) is written in the i-th line (1 ≤ i ≤ D) of the following D lines. This means that the maximum temperature on day i is forecast to be Ti degrees.
In the jth line (1 ≤ j ≤ N) of the following N lines, three integers Aj, Bj, Cj (0 ≤ Aj ≤ Bj ≤ 60, 0 ≤ Cj ≤ 100) are written. These indicate that clothing j is suitable for wearing on days when the maximum temperature is above Aj and below Bj, and the flashiness is Cj.
It is guaranteed that there will be at least one piece of clothing suitable for wearing when the maximum temperature follows the weather forecast for every D day.
output
Output the total absolute value of the difference in the flashiness of clothes worn on consecutive days, that is, the maximum value of the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD | in one line. ..
Input / output example
Input example 1
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output example 1
80
In the input / output example 1, the candidates for clothes on the first day are clothes 3 and 4, the candidates for clothes on the second day are clothes 2 and clothes 3, and the candidates for clothes on the third day are only clothes 3. is there. Choose clothes 4 on the first day, clothes 2 on the second day, and clothes 3 on the third day. That is, x1 = 4, x2 = 2, x3 = 3. At this time, the absolute value of the difference in the flashiness of the clothes on the first day and the second day is | 40 --90 | = 50, and the absolute value of the difference in the flashiness of the clothes on the second and third days is | 90-60 | = 30. The total is 80, which is the maximum value.
Input example 2
5 2
26
28
32
29
34
30 35 0
25 30 100
Output example 2
300
In Example 2 of input / output, clothes 2 on the first day, clothes 2 on the second day, clothes 1 on the third day, clothes 2 on the fourth day, and clothes 1 on the fifth day. You have to choose. At this time, the required value is | 100 --100 | + | 100 --0 | + | 0 --100 | + | 100 --0 | = 300.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output
80 | instruction | 0 | 54,719 | 4 | 109,438 |
"Correct Solution:
```
D,N = map(int,input().split())
T = [ int(input()) for i in range(D) ]
clothes = []
for _ in range(N):
a,b,c = map(int,input().split())
clothes.append([a,b,c])
# i日目に服jを来た時の、派手さの絶対値
dp = [ [-1]*(N) for _ in range(D+1) ]
dp[0][0] = 0
for j in range(N):
a,b,c = clothes[j]
if a <= T[0] <= b:
dp[1][j] = c
for i in range(2, D+1):
for j in range(N):
a,b,c = clothes[j]
if a <= T[i-1] <= b:
for k in range(N):
if dp[i-1][k] > -1:
prev_c = clothes[k][2]
if i > 2:
dp[i][j] = max(dp[i][j], dp[i-1][k]+abs(prev_c-c))
else:
dp[i][j] = max(dp[i][j], abs(prev_c-c))
print(max(dp[-1]))
``` | output | 1 | 54,719 | 4 | 109,439 |
Provide a correct Python 3 solution for this coding contest problem.
problem
During this time of winter in Japan, hot days continue in Australia in the Southern Hemisphere. IOI, who lives in Australia, decided to plan what clothes to wear based on the weather forecast for a certain D day. The maximum temperature on day i (1 ≤ i ≤ D) is predicted to be Ti degrees.
IOI has N kinds of clothes, which are numbered from 1 to N. Clothes j (1 ≤ j ≤ N) are suitable for wearing on days when the maximum temperature is above Aj and below Bj. In addition, each clothes has an integer called "flashiness", and the flashiness of clothes j is Cj.
For each of the D days, IOI chooses to wear one of the clothes suitable for wearing when the maximum temperature follows the weather forecast. You may choose the same clothes as many times as you like, or you may choose clothes that are never chosen in D days.
IOI, who wanted to avoid wearing similar clothes in succession, decided to maximize the total absolute value of the difference in the flashiness of the clothes worn on consecutive days. That is, assuming that the clothes xi are selected on the i-day, we want to maximize the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD |. Create a program to find this maximum value.
input
The input consists of 1 + D + N lines.
On the first line, two integers D and N (2 ≤ D ≤ 200, 1 ≤ N ≤ 200) are written with a blank as a delimiter. D is the number of days to plan clothes and N is the number of clothes types IOI has.
One integer Ti (0 ≤ Ti ≤ 60) is written in the i-th line (1 ≤ i ≤ D) of the following D lines. This means that the maximum temperature on day i is forecast to be Ti degrees.
In the jth line (1 ≤ j ≤ N) of the following N lines, three integers Aj, Bj, Cj (0 ≤ Aj ≤ Bj ≤ 60, 0 ≤ Cj ≤ 100) are written. These indicate that clothing j is suitable for wearing on days when the maximum temperature is above Aj and below Bj, and the flashiness is Cj.
It is guaranteed that there will be at least one piece of clothing suitable for wearing when the maximum temperature follows the weather forecast for every D day.
output
Output the total absolute value of the difference in the flashiness of clothes worn on consecutive days, that is, the maximum value of the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD | in one line. ..
Input / output example
Input example 1
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output example 1
80
In the input / output example 1, the candidates for clothes on the first day are clothes 3 and 4, the candidates for clothes on the second day are clothes 2 and clothes 3, and the candidates for clothes on the third day are only clothes 3. is there. Choose clothes 4 on the first day, clothes 2 on the second day, and clothes 3 on the third day. That is, x1 = 4, x2 = 2, x3 = 3. At this time, the absolute value of the difference in the flashiness of the clothes on the first day and the second day is | 40 --90 | = 50, and the absolute value of the difference in the flashiness of the clothes on the second and third days is | 90-60 | = 30. The total is 80, which is the maximum value.
Input example 2
5 2
26
28
32
29
34
30 35 0
25 30 100
Output example 2
300
In Example 2 of input / output, clothes 2 on the first day, clothes 2 on the second day, clothes 1 on the third day, clothes 2 on the fourth day, and clothes 1 on the fifth day. You have to choose. At this time, the required value is | 100 --100 | + | 100 --0 | + | 0 --100 | + | 100 --0 | = 300.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output
80 | instruction | 0 | 54,720 | 4 | 109,440 |
"Correct Solution:
```
#D
D,N = map(int,input().split())
T = [int(input()) for i in range(D)]
ABC = [list(map(int,input().split())) for i in range(N)]
can = []
for t in T:
mini = []
for abc in ABC:
a,b,c = abc
if a <= t and t <= b:
mini.append(c)
mini.sort()
can.append([mini[0],mini[-1]])
dp = [[0,0] for i in range(D)]
for i in range(1,D):
o = can[i-1]
m = can[i]
dp[i][0] = max(dp[i-1][0]+abs(o[0]-m[0]),dp[i-1][1]+abs(o[1]-m[0]))
dp[i][1] = max(dp[i-1][0]+abs(o[0]-m[1]),dp[i-1][1]+abs(o[1]-m[1]))
print(max(dp[D-1]))
``` | output | 1 | 54,720 | 4 | 109,441 |
Provide a correct Python 3 solution for this coding contest problem.
problem
During this time of winter in Japan, hot days continue in Australia in the Southern Hemisphere. IOI, who lives in Australia, decided to plan what clothes to wear based on the weather forecast for a certain D day. The maximum temperature on day i (1 ≤ i ≤ D) is predicted to be Ti degrees.
IOI has N kinds of clothes, which are numbered from 1 to N. Clothes j (1 ≤ j ≤ N) are suitable for wearing on days when the maximum temperature is above Aj and below Bj. In addition, each clothes has an integer called "flashiness", and the flashiness of clothes j is Cj.
For each of the D days, IOI chooses to wear one of the clothes suitable for wearing when the maximum temperature follows the weather forecast. You may choose the same clothes as many times as you like, or you may choose clothes that are never chosen in D days.
IOI, who wanted to avoid wearing similar clothes in succession, decided to maximize the total absolute value of the difference in the flashiness of the clothes worn on consecutive days. That is, assuming that the clothes xi are selected on the i-day, we want to maximize the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD |. Create a program to find this maximum value.
input
The input consists of 1 + D + N lines.
On the first line, two integers D and N (2 ≤ D ≤ 200, 1 ≤ N ≤ 200) are written with a blank as a delimiter. D is the number of days to plan clothes and N is the number of clothes types IOI has.
One integer Ti (0 ≤ Ti ≤ 60) is written in the i-th line (1 ≤ i ≤ D) of the following D lines. This means that the maximum temperature on day i is forecast to be Ti degrees.
In the jth line (1 ≤ j ≤ N) of the following N lines, three integers Aj, Bj, Cj (0 ≤ Aj ≤ Bj ≤ 60, 0 ≤ Cj ≤ 100) are written. These indicate that clothing j is suitable for wearing on days when the maximum temperature is above Aj and below Bj, and the flashiness is Cj.
It is guaranteed that there will be at least one piece of clothing suitable for wearing when the maximum temperature follows the weather forecast for every D day.
output
Output the total absolute value of the difference in the flashiness of clothes worn on consecutive days, that is, the maximum value of the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD | in one line. ..
Input / output example
Input example 1
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output example 1
80
In the input / output example 1, the candidates for clothes on the first day are clothes 3 and 4, the candidates for clothes on the second day are clothes 2 and clothes 3, and the candidates for clothes on the third day are only clothes 3. is there. Choose clothes 4 on the first day, clothes 2 on the second day, and clothes 3 on the third day. That is, x1 = 4, x2 = 2, x3 = 3. At this time, the absolute value of the difference in the flashiness of the clothes on the first day and the second day is | 40 --90 | = 50, and the absolute value of the difference in the flashiness of the clothes on the second and third days is | 90-60 | = 30. The total is 80, which is the maximum value.
Input example 2
5 2
26
28
32
29
34
30 35 0
25 30 100
Output example 2
300
In Example 2 of input / output, clothes 2 on the first day, clothes 2 on the second day, clothes 1 on the third day, clothes 2 on the fourth day, and clothes 1 on the fifth day. You have to choose. At this time, the required value is | 100 --100 | + | 100 --0 | + | 0 --100 | + | 100 --0 | = 300.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output
80 | instruction | 0 | 54,721 | 4 | 109,442 |
"Correct Solution:
```
def solve():
from sys import stdin
f_i = stdin
D, N = map(int, f_i.readline().split())
T = tuple(int(f_i.readline()) for i in range(D))
clothes = [tuple(map(int, f_i.readline().split())) for i in range(N)]
clothes.sort(key=lambda x: x[2])
candidate = []
for t in T:
ct = tuple(filter(lambda x: x[0] <= t <= x[1], clothes))
c_min = ct[0][2]
c_max = ct[-1][2]
if c_min == c_max:
candidate.append((c_min,))
else:
candidate.append((c_min, c_max))
dp = [0] * len(candidate[0])
for c1, c2 in zip(candidate, candidate[1:]):
dp = [max(rec + abs(ci - cj) for rec, ci in zip(dp, c1)) for cj in c2]
print(max(dp))
solve()
``` | output | 1 | 54,721 | 4 | 109,443 |
Provide a correct Python 3 solution for this coding contest problem.
problem
During this time of winter in Japan, hot days continue in Australia in the Southern Hemisphere. IOI, who lives in Australia, decided to plan what clothes to wear based on the weather forecast for a certain D day. The maximum temperature on day i (1 ≤ i ≤ D) is predicted to be Ti degrees.
IOI has N kinds of clothes, which are numbered from 1 to N. Clothes j (1 ≤ j ≤ N) are suitable for wearing on days when the maximum temperature is above Aj and below Bj. In addition, each clothes has an integer called "flashiness", and the flashiness of clothes j is Cj.
For each of the D days, IOI chooses to wear one of the clothes suitable for wearing when the maximum temperature follows the weather forecast. You may choose the same clothes as many times as you like, or you may choose clothes that are never chosen in D days.
IOI, who wanted to avoid wearing similar clothes in succession, decided to maximize the total absolute value of the difference in the flashiness of the clothes worn on consecutive days. That is, assuming that the clothes xi are selected on the i-day, we want to maximize the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD |. Create a program to find this maximum value.
input
The input consists of 1 + D + N lines.
On the first line, two integers D and N (2 ≤ D ≤ 200, 1 ≤ N ≤ 200) are written with a blank as a delimiter. D is the number of days to plan clothes and N is the number of clothes types IOI has.
One integer Ti (0 ≤ Ti ≤ 60) is written in the i-th line (1 ≤ i ≤ D) of the following D lines. This means that the maximum temperature on day i is forecast to be Ti degrees.
In the jth line (1 ≤ j ≤ N) of the following N lines, three integers Aj, Bj, Cj (0 ≤ Aj ≤ Bj ≤ 60, 0 ≤ Cj ≤ 100) are written. These indicate that clothing j is suitable for wearing on days when the maximum temperature is above Aj and below Bj, and the flashiness is Cj.
It is guaranteed that there will be at least one piece of clothing suitable for wearing when the maximum temperature follows the weather forecast for every D day.
output
Output the total absolute value of the difference in the flashiness of clothes worn on consecutive days, that is, the maximum value of the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD | in one line. ..
Input / output example
Input example 1
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output example 1
80
In the input / output example 1, the candidates for clothes on the first day are clothes 3 and 4, the candidates for clothes on the second day are clothes 2 and clothes 3, and the candidates for clothes on the third day are only clothes 3. is there. Choose clothes 4 on the first day, clothes 2 on the second day, and clothes 3 on the third day. That is, x1 = 4, x2 = 2, x3 = 3. At this time, the absolute value of the difference in the flashiness of the clothes on the first day and the second day is | 40 --90 | = 50, and the absolute value of the difference in the flashiness of the clothes on the second and third days is | 90-60 | = 30. The total is 80, which is the maximum value.
Input example 2
5 2
26
28
32
29
34
30 35 0
25 30 100
Output example 2
300
In Example 2 of input / output, clothes 2 on the first day, clothes 2 on the second day, clothes 1 on the third day, clothes 2 on the fourth day, and clothes 1 on the fifth day. You have to choose. At this time, the required value is | 100 --100 | + | 100 --0 | + | 0 --100 | + | 100 --0 | = 300.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output
80 | instruction | 0 | 54,722 | 4 | 109,444 |
"Correct Solution:
```
d,n=map(int,input().split())
t=[int(input()) for _ in [0]*d]
abc=[list(map(int,input().split())) for _ in [0]*n]
memo=[-1]*101
t_list=[set() for _ in [0]*61]
for a,b,c in abc:
for j in range(a,b+1):
t_list[j].add(c)
for i in t_list[t[0]]:
memo[i]=0
for i in t[1:]:
memo2=[-1]*101
temp=[j for j in t_list[i]]
for j,k in enumerate(memo):
if k!=-1:
for l in temp:
memo2[l]=max(memo2[l],k+abs(j-l))
memo=memo2
print(max(memo))
``` | output | 1 | 54,722 | 4 | 109,445 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
During this time of winter in Japan, hot days continue in Australia in the Southern Hemisphere. IOI, who lives in Australia, decided to plan what clothes to wear based on the weather forecast for a certain D day. The maximum temperature on day i (1 ≤ i ≤ D) is predicted to be Ti degrees.
IOI has N kinds of clothes, which are numbered from 1 to N. Clothes j (1 ≤ j ≤ N) are suitable for wearing on days when the maximum temperature is above Aj and below Bj. In addition, each clothes has an integer called "flashiness", and the flashiness of clothes j is Cj.
For each of the D days, IOI chooses to wear one of the clothes suitable for wearing when the maximum temperature follows the weather forecast. You may choose the same clothes as many times as you like, or you may choose clothes that are never chosen in D days.
IOI, who wanted to avoid wearing similar clothes in succession, decided to maximize the total absolute value of the difference in the flashiness of the clothes worn on consecutive days. That is, assuming that the clothes xi are selected on the i-day, we want to maximize the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD |. Create a program to find this maximum value.
input
The input consists of 1 + D + N lines.
On the first line, two integers D and N (2 ≤ D ≤ 200, 1 ≤ N ≤ 200) are written with a blank as a delimiter. D is the number of days to plan clothes and N is the number of clothes types IOI has.
One integer Ti (0 ≤ Ti ≤ 60) is written in the i-th line (1 ≤ i ≤ D) of the following D lines. This means that the maximum temperature on day i is forecast to be Ti degrees.
In the jth line (1 ≤ j ≤ N) of the following N lines, three integers Aj, Bj, Cj (0 ≤ Aj ≤ Bj ≤ 60, 0 ≤ Cj ≤ 100) are written. These indicate that clothing j is suitable for wearing on days when the maximum temperature is above Aj and below Bj, and the flashiness is Cj.
It is guaranteed that there will be at least one piece of clothing suitable for wearing when the maximum temperature follows the weather forecast for every D day.
output
Output the total absolute value of the difference in the flashiness of clothes worn on consecutive days, that is, the maximum value of the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD | in one line. ..
Input / output example
Input example 1
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output example 1
80
In the input / output example 1, the candidates for clothes on the first day are clothes 3 and 4, the candidates for clothes on the second day are clothes 2 and clothes 3, and the candidates for clothes on the third day are only clothes 3. is there. Choose clothes 4 on the first day, clothes 2 on the second day, and clothes 3 on the third day. That is, x1 = 4, x2 = 2, x3 = 3. At this time, the absolute value of the difference in the flashiness of the clothes on the first day and the second day is | 40 --90 | = 50, and the absolute value of the difference in the flashiness of the clothes on the second and third days is | 90-60 | = 30. The total is 80, which is the maximum value.
Input example 2
5 2
26
28
32
29
34
30 35 0
25 30 100
Output example 2
300
In Example 2 of input / output, clothes 2 on the first day, clothes 2 on the second day, clothes 1 on the third day, clothes 2 on the fourth day, and clothes 1 on the fifth day. You have to choose. At this time, the required value is | 100 --100 | + | 100 --0 | + | 0 --100 | + | 100 --0 | = 300.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output
80
Submitted Solution:
```
D,N=map(int,input().split())
dp=[[-1]*(N) for i in range(D+1)]
#dp[i][j][k] i日目にjを着たときの最大
d=[]
for i in range(D):
i=int(input())
d.append(i)
J=[]
for j in range(N):
a,b,c=map(int,input().split())
J.append([a,b,c])
t=d[0]
h=[-1]*N
for j in range(N):
a,b,c=J[j]
if t<a or b<t:
continue
h[j]=c
for i in range(2,D+1):
t=d[i-1]
for j in range(N):
a,b,c=J[j]
if t<a or b<t:
continue
for k in range(N):
if i==2:
if h[k]==-1:
continue
dp[i][j]=max(abs(J[k][2]-c),dp[i][j])
if dp[i-1][k]==-1:
continue
dp[i][j]=max(dp[i-1][k]+abs(J[k][2]-c),dp[i][j])
ans=0
for i in range(N):
ans=max(dp[D][i],ans)
print(ans)
``` | instruction | 0 | 54,723 | 4 | 109,446 |
Yes | output | 1 | 54,723 | 4 | 109,447 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
During this time of winter in Japan, hot days continue in Australia in the Southern Hemisphere. IOI, who lives in Australia, decided to plan what clothes to wear based on the weather forecast for a certain D day. The maximum temperature on day i (1 ≤ i ≤ D) is predicted to be Ti degrees.
IOI has N kinds of clothes, which are numbered from 1 to N. Clothes j (1 ≤ j ≤ N) are suitable for wearing on days when the maximum temperature is above Aj and below Bj. In addition, each clothes has an integer called "flashiness", and the flashiness of clothes j is Cj.
For each of the D days, IOI chooses to wear one of the clothes suitable for wearing when the maximum temperature follows the weather forecast. You may choose the same clothes as many times as you like, or you may choose clothes that are never chosen in D days.
IOI, who wanted to avoid wearing similar clothes in succession, decided to maximize the total absolute value of the difference in the flashiness of the clothes worn on consecutive days. That is, assuming that the clothes xi are selected on the i-day, we want to maximize the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD |. Create a program to find this maximum value.
input
The input consists of 1 + D + N lines.
On the first line, two integers D and N (2 ≤ D ≤ 200, 1 ≤ N ≤ 200) are written with a blank as a delimiter. D is the number of days to plan clothes and N is the number of clothes types IOI has.
One integer Ti (0 ≤ Ti ≤ 60) is written in the i-th line (1 ≤ i ≤ D) of the following D lines. This means that the maximum temperature on day i is forecast to be Ti degrees.
In the jth line (1 ≤ j ≤ N) of the following N lines, three integers Aj, Bj, Cj (0 ≤ Aj ≤ Bj ≤ 60, 0 ≤ Cj ≤ 100) are written. These indicate that clothing j is suitable for wearing on days when the maximum temperature is above Aj and below Bj, and the flashiness is Cj.
It is guaranteed that there will be at least one piece of clothing suitable for wearing when the maximum temperature follows the weather forecast for every D day.
output
Output the total absolute value of the difference in the flashiness of clothes worn on consecutive days, that is, the maximum value of the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD | in one line. ..
Input / output example
Input example 1
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output example 1
80
In the input / output example 1, the candidates for clothes on the first day are clothes 3 and 4, the candidates for clothes on the second day are clothes 2 and clothes 3, and the candidates for clothes on the third day are only clothes 3. is there. Choose clothes 4 on the first day, clothes 2 on the second day, and clothes 3 on the third day. That is, x1 = 4, x2 = 2, x3 = 3. At this time, the absolute value of the difference in the flashiness of the clothes on the first day and the second day is | 40 --90 | = 50, and the absolute value of the difference in the flashiness of the clothes on the second and third days is | 90-60 | = 30. The total is 80, which is the maximum value.
Input example 2
5 2
26
28
32
29
34
30 35 0
25 30 100
Output example 2
300
In Example 2 of input / output, clothes 2 on the first day, clothes 2 on the second day, clothes 1 on the third day, clothes 2 on the fourth day, and clothes 1 on the fifth day. You have to choose. At this time, the required value is | 100 --100 | + | 100 --0 | + | 0 --100 | + | 100 --0 | = 300.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output
80
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Hot days
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0579
"""
import sys
def solve(temperatures, clothes):
points = [[] for _ in range(len(temperatures))]
for i, t in enumerate(temperatures):
for c in clothes:
if c[0] <= t <= c[1]:
points[i].append(c[-1])
points[i].sort()
dp = [[min(points[0]), 0], [max(points[0]), 0]]
for p in points[1:]:
dp = [[min(p), max(dp[0][1] + abs(min(p)-dp[0][0]), dp[1][1] + abs(min(p)-dp[1][0]))],
[max(p), max(dp[0][1] + abs(max(p)-dp[0][0]), dp[1][1] + abs(max(p)-dp[1][0]))]]
return max(dp[0][1], dp[1][1])
def main(args):
d, n = map(int, input().split())
temperatures = [int(input()) for _ in range(d)]
clothes = [[int(x) for x in input().split()] for _ in range(n)]
ans = solve(temperatures, clothes)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
``` | instruction | 0 | 54,724 | 4 | 109,448 |
Yes | output | 1 | 54,724 | 4 | 109,449 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
During this time of winter in Japan, hot days continue in Australia in the Southern Hemisphere. IOI, who lives in Australia, decided to plan what clothes to wear based on the weather forecast for a certain D day. The maximum temperature on day i (1 ≤ i ≤ D) is predicted to be Ti degrees.
IOI has N kinds of clothes, which are numbered from 1 to N. Clothes j (1 ≤ j ≤ N) are suitable for wearing on days when the maximum temperature is above Aj and below Bj. In addition, each clothes has an integer called "flashiness", and the flashiness of clothes j is Cj.
For each of the D days, IOI chooses to wear one of the clothes suitable for wearing when the maximum temperature follows the weather forecast. You may choose the same clothes as many times as you like, or you may choose clothes that are never chosen in D days.
IOI, who wanted to avoid wearing similar clothes in succession, decided to maximize the total absolute value of the difference in the flashiness of the clothes worn on consecutive days. That is, assuming that the clothes xi are selected on the i-day, we want to maximize the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD |. Create a program to find this maximum value.
input
The input consists of 1 + D + N lines.
On the first line, two integers D and N (2 ≤ D ≤ 200, 1 ≤ N ≤ 200) are written with a blank as a delimiter. D is the number of days to plan clothes and N is the number of clothes types IOI has.
One integer Ti (0 ≤ Ti ≤ 60) is written in the i-th line (1 ≤ i ≤ D) of the following D lines. This means that the maximum temperature on day i is forecast to be Ti degrees.
In the jth line (1 ≤ j ≤ N) of the following N lines, three integers Aj, Bj, Cj (0 ≤ Aj ≤ Bj ≤ 60, 0 ≤ Cj ≤ 100) are written. These indicate that clothing j is suitable for wearing on days when the maximum temperature is above Aj and below Bj, and the flashiness is Cj.
It is guaranteed that there will be at least one piece of clothing suitable for wearing when the maximum temperature follows the weather forecast for every D day.
output
Output the total absolute value of the difference in the flashiness of clothes worn on consecutive days, that is, the maximum value of the values | Cx1 --Cx2 | + | Cx2 --Cx3 | +… + | CxD-1 --CxD | in one line. ..
Input / output example
Input example 1
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output example 1
80
In the input / output example 1, the candidates for clothes on the first day are clothes 3 and 4, the candidates for clothes on the second day are clothes 2 and clothes 3, and the candidates for clothes on the third day are only clothes 3. is there. Choose clothes 4 on the first day, clothes 2 on the second day, and clothes 3 on the third day. That is, x1 = 4, x2 = 2, x3 = 3. At this time, the absolute value of the difference in the flashiness of the clothes on the first day and the second day is | 40 --90 | = 50, and the absolute value of the difference in the flashiness of the clothes on the second and third days is | 90-60 | = 30. The total is 80, which is the maximum value.
Input example 2
5 2
26
28
32
29
34
30 35 0
25 30 100
Output example 2
300
In Example 2 of input / output, clothes 2 on the first day, clothes 2 on the second day, clothes 1 on the third day, clothes 2 on the fourth day, and clothes 1 on the fifth day. You have to choose. At this time, the required value is | 100 --100 | + | 100 --0 | + | 0 --100 | + | 100 --0 | = 300.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
Output
80
Submitted Solution:
```
INF = 10 ** 20
def main():
d, n = map(int,input().split())
temp = [int(input()) for i in range(d)]
temp.insert(0,0)
alst = []
blst = []
clst = []
for i in range(n):
a,b,c = map(int,input().split())
alst.append(a)
blst.append(b)
clst.append(c)
dp = [[0] * n for i in range(d + 1)]
t1 = temp[1]
for i in range(n):
if not (alst[i] <= t1 <= blst[i]):
dp[1][i] = -INF
for i in range(2, d + 1):
t = temp[i]
predp = dp[i - 1]
for j in range(n):
cj = clst[j]
if alst[j] <= t <= blst[j]:
dp[i][j] = max(predp[x] + (cj - clst[x] if cj >= clst[x] else clst[x] - cj) for x in range(n))
print(max(dp[d]))
main()
``` | instruction | 0 | 54,725 | 4 | 109,450 |
Yes | output | 1 | 54,725 | 4 | 109,451 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The main server of Gomble company received a log of one top-secret process, the name of which can't be revealed. The log was written in the following format: «[date:time]: message», where for each «[date:time]» value existed not more than 10 lines. All the files were encoded in a very complicated manner, and only one programmer — Alex — managed to decode them. The code was so complicated that Alex needed four weeks to decode it. Right after the decoding process was finished, all the files were deleted. But after the files deletion, Alex noticed that he saved the recordings in format «[time]: message». So, information about the dates was lost. However, as the lines were added into the log in chronological order, it's not difficult to say if the recordings could appear during one day or not. It is possible also to find the minimum amount of days during which the log was written.
So, to make up for his mistake Alex has to find the minimum amount of days covered by the log. Note that Alex doesn't have to find the minimum amount of days between the beginning and the end of the logging, he has to find the minimum amount of dates in which records could be done. (See Sample test 2 for further clarifications).
We should remind you that the process made not more than 10 recordings in a minute. Consider that a midnight belongs to coming day.
Input
The first input line contains number n (1 ≤ n ≤ 100). The following n lines contain recordings in format «[time]: message», where time is given in format «hh:mm x.m.». For hh two-digit numbers from 01 to 12 are used, for mm two-digit numbers from 00 to 59 are used, and x is either character «a» or character «p». A message is a non-empty sequence of Latin letters and/or spaces, it doesn't start or end with a space. The length of each message doesn't exceed 20.
Output
Output one number — the minimum amount of days covered by the log.
Examples
Input
5
[05:00 a.m.]: Server is started
[05:00 a.m.]: Rescan initialized
[01:13 p.m.]: Request processed
[01:10 p.m.]: Request processed
[11:40 p.m.]: Rescan completed
Output
2
Input
3
[09:00 a.m.]: User logged in
[08:00 a.m.]: User logged in
[07:00 a.m.]: User logged in
Output
3
Note
Formally the 12-hour time format is described at:
* http://en.wikipedia.org/wiki/12-hour_clock.
The problem authors recommend you to look through these descriptions before you start with the problem. | instruction | 0 | 55,045 | 4 | 110,090 |
Tags: implementation, strings
Correct Solution:
```
def compareTime(t1,t2,):
if abs(t2-ref) < abs(t1-ref):
return True
else:
return False
def getTime(msg):
hh = int(msg[1:3])
mm = int(msg[4:6])
if hh == 12 and msg[7] == 'a':
hh = 00
elif msg[7] == 'p' and hh != 12:
hh = hh+12
return hh*60+mm
n = int(input())
msgs = []
msgs_processed = []
for _ in range(n):
msgs.append(input())
prev_t = -1
repeatCntr = 0
cnt = 1
for i in range(n):
t = getTime(msgs[i])
if t != prev_t:
msgs_processed.append(t)
prev_t = t
#print(t)
repeatCntr = 0
elif t == prev_t:
repeatCntr += 1
if repeatCntr > 9:
cnt+=1
#print(t)
repeatCntr = 0
#else:
#print('IGN',end=" ")
ref = getTime('[00:00 a.m.]')
for i in range(len(msgs_processed)-1):
#print(msgs_processed[i],msgs_processed[i+1])
if compareTime(msgs_processed[i],msgs_processed[i+1]):
cnt=cnt+1
#print('Day Change')
#else:
#print('same day')
print(cnt)
``` | output | 1 | 55,045 | 4 | 110,091 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The main server of Gomble company received a log of one top-secret process, the name of which can't be revealed. The log was written in the following format: «[date:time]: message», where for each «[date:time]» value existed not more than 10 lines. All the files were encoded in a very complicated manner, and only one programmer — Alex — managed to decode them. The code was so complicated that Alex needed four weeks to decode it. Right after the decoding process was finished, all the files were deleted. But after the files deletion, Alex noticed that he saved the recordings in format «[time]: message». So, information about the dates was lost. However, as the lines were added into the log in chronological order, it's not difficult to say if the recordings could appear during one day or not. It is possible also to find the minimum amount of days during which the log was written.
So, to make up for his mistake Alex has to find the minimum amount of days covered by the log. Note that Alex doesn't have to find the minimum amount of days between the beginning and the end of the logging, he has to find the minimum amount of dates in which records could be done. (See Sample test 2 for further clarifications).
We should remind you that the process made not more than 10 recordings in a minute. Consider that a midnight belongs to coming day.
Input
The first input line contains number n (1 ≤ n ≤ 100). The following n lines contain recordings in format «[time]: message», where time is given in format «hh:mm x.m.». For hh two-digit numbers from 01 to 12 are used, for mm two-digit numbers from 00 to 59 are used, and x is either character «a» or character «p». A message is a non-empty sequence of Latin letters and/or spaces, it doesn't start or end with a space. The length of each message doesn't exceed 20.
Output
Output one number — the minimum amount of days covered by the log.
Examples
Input
5
[05:00 a.m.]: Server is started
[05:00 a.m.]: Rescan initialized
[01:13 p.m.]: Request processed
[01:10 p.m.]: Request processed
[11:40 p.m.]: Rescan completed
Output
2
Input
3
[09:00 a.m.]: User logged in
[08:00 a.m.]: User logged in
[07:00 a.m.]: User logged in
Output
3
Note
Formally the 12-hour time format is described at:
* http://en.wikipedia.org/wiki/12-hour_clock.
The problem authors recommend you to look through these descriptions before you start with the problem. | instruction | 0 | 55,046 | 4 | 110,092 |
Tags: implementation, strings
Correct Solution:
```
prev = 24 * 60
days = 0
cnt = 0
for i in range(int(input())):
time = input()[1:8].split()
time[0:1] = list(map(int, time[0].split(":")))
if time[0] == 12:
time[0] = 0
if time[2] == "p":
time[0] += 12
curr = time[0] * 60 + time[1]
if curr < prev:
days += 1
cnt = 1
elif curr == prev:
cnt += 1
if cnt > 10:
cnt -= 10
days += 1
else:
cnt = 1
prev = curr
print(days)
``` | output | 1 | 55,046 | 4 | 110,093 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.