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 a correct Python 3 solution for this coding contest problem.
As many of you know, we have two major calendar systems used in Japan today. One of them is Gregorian calendar which is widely used across the world. It is also known as “Western calendar” in Japan.
The other calendar system is era-based calendar, or so-called “Japanese calendar.” This system comes from ancient Chinese systems. Recently in Japan it has been a common way to associate dates with the Emperors. In the era-based system, we represent a year with an era name given at the time a new Emperor assumes the throne. If the era name is “A”, the first regnal year will be “A 1”, the second year will be “A 2”, and so forth.
Since we have two different calendar systems, it is often needed to convert the date in one calendar system to the other. In this problem, you are asked to write a program that converts western year to era-based year, given a database that contains association between several western years and era-based years.
For the simplicity, you can assume the following:
1. A new era always begins on January 1st of the corresponding Gregorian year.
2. The first year of an era is described as 1.
3. There is no year in which more than one era switch takes place.
Please note that, however, the database you will see may be incomplete. In other words, some era that existed in the history may be missing from your data. So you will also have to detect the cases where you cannot determine exactly which era the given year belongs to.
Input
The input contains multiple test cases. Each test case has the following format:
N Q
EraName1 EraBasedYear1 WesternYear1
.
.
.
EraNameN EraBasedYearN WesternYearN
Query1 .
.
.
QueryQ
The first line of the input contains two positive integers N and Q (1 ≤ N ≤ 1000, 1 ≤ Q ≤ 1000). N is the number of database entries, and Q is the number of queries.
Each of the following N lines has three components: era name, era-based year number and the corresponding western year (1 ≤ EraBasedYeari ≤ WesternYeari ≤ 109 ). Each of era names consist of at most 16 Roman alphabet characters. Then the last Q lines of the input specifies queries (1 ≤ Queryi ≤ 109 ), each of which is a western year to compute era-based representation.
The end of input is indicated by a line containing two zeros. This line is not part of any dataset and hence should not be processed.
You can assume that all the western year in the input is positive integers, and that there is no two entries that share the same era name.
Output
For each query, output in a line the era name and the era-based year number corresponding to the western year given, separated with a single whitespace. In case you cannot determine the era, output “Unknown” without quotes.
Example
Input
4 3
meiji 10 1877
taisho 6 1917
showa 62 1987
heisei 22 2010
1868
1917
1988
1 1
universalcentury 123 2168
2010
0 0
Output
meiji 1
taisho 6
Unknown
Unknown | instruction | 0 | 38,546 | 4 | 77,092 |
"Correct Solution:
```
while True:
Name=[]
first=[]
final=[]
N,Q =map(int,input().split())
if N==Q==0:
break
else:
for n in range(N):
eraname,erabasedyear,westernyear=input().split()
Name.append(eraname)
era_first=int(westernyear) - int(erabasedyear) +1
first.append(int(era_first))
final.append(int(westernyear))
for q in range(Q):
year=int(input())
count=0
for n in range(N):
if first[n] <= year <=final[n]:
era_year = year -first[n] +1
print(Name[n],era_year)
count+=1
if count==0:
print("Unknown")
``` | output | 1 | 38,546 | 4 | 77,093 |
Provide a correct Python 3 solution for this coding contest problem.
As many of you know, we have two major calendar systems used in Japan today. One of them is Gregorian calendar which is widely used across the world. It is also known as “Western calendar” in Japan.
The other calendar system is era-based calendar, or so-called “Japanese calendar.” This system comes from ancient Chinese systems. Recently in Japan it has been a common way to associate dates with the Emperors. In the era-based system, we represent a year with an era name given at the time a new Emperor assumes the throne. If the era name is “A”, the first regnal year will be “A 1”, the second year will be “A 2”, and so forth.
Since we have two different calendar systems, it is often needed to convert the date in one calendar system to the other. In this problem, you are asked to write a program that converts western year to era-based year, given a database that contains association between several western years and era-based years.
For the simplicity, you can assume the following:
1. A new era always begins on January 1st of the corresponding Gregorian year.
2. The first year of an era is described as 1.
3. There is no year in which more than one era switch takes place.
Please note that, however, the database you will see may be incomplete. In other words, some era that existed in the history may be missing from your data. So you will also have to detect the cases where you cannot determine exactly which era the given year belongs to.
Input
The input contains multiple test cases. Each test case has the following format:
N Q
EraName1 EraBasedYear1 WesternYear1
.
.
.
EraNameN EraBasedYearN WesternYearN
Query1 .
.
.
QueryQ
The first line of the input contains two positive integers N and Q (1 ≤ N ≤ 1000, 1 ≤ Q ≤ 1000). N is the number of database entries, and Q is the number of queries.
Each of the following N lines has three components: era name, era-based year number and the corresponding western year (1 ≤ EraBasedYeari ≤ WesternYeari ≤ 109 ). Each of era names consist of at most 16 Roman alphabet characters. Then the last Q lines of the input specifies queries (1 ≤ Queryi ≤ 109 ), each of which is a western year to compute era-based representation.
The end of input is indicated by a line containing two zeros. This line is not part of any dataset and hence should not be processed.
You can assume that all the western year in the input is positive integers, and that there is no two entries that share the same era name.
Output
For each query, output in a line the era name and the era-based year number corresponding to the western year given, separated with a single whitespace. In case you cannot determine the era, output “Unknown” without quotes.
Example
Input
4 3
meiji 10 1877
taisho 6 1917
showa 62 1987
heisei 22 2010
1868
1917
1988
1 1
universalcentury 123 2168
2010
0 0
Output
meiji 1
taisho 6
Unknown
Unknown | instruction | 0 | 38,547 | 4 | 77,094 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
def solve(N,Q):
era = []
for _ in range(N):
X = input().split()
name = X[0]
y = int(X[1])
w = int(X[2])
era.append((w - y + 1,w,name))
for _ in range(Q):
flag = False
y = int(input())
for a,b,c in era:
if a <= y <= b:
flag = True
ans = (c,y - a + 1)
break
if flag:
print(*ans)
else:
print('Unknown')
def main():
while True:
N,Q = map(int,input().split())
if N == 0:
return
solve(N,Q)
if __name__ == '__main__':
main()
``` | output | 1 | 38,547 | 4 | 77,095 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As many of you know, we have two major calendar systems used in Japan today. One of them is Gregorian calendar which is widely used across the world. It is also known as “Western calendar” in Japan.
The other calendar system is era-based calendar, or so-called “Japanese calendar.” This system comes from ancient Chinese systems. Recently in Japan it has been a common way to associate dates with the Emperors. In the era-based system, we represent a year with an era name given at the time a new Emperor assumes the throne. If the era name is “A”, the first regnal year will be “A 1”, the second year will be “A 2”, and so forth.
Since we have two different calendar systems, it is often needed to convert the date in one calendar system to the other. In this problem, you are asked to write a program that converts western year to era-based year, given a database that contains association between several western years and era-based years.
For the simplicity, you can assume the following:
1. A new era always begins on January 1st of the corresponding Gregorian year.
2. The first year of an era is described as 1.
3. There is no year in which more than one era switch takes place.
Please note that, however, the database you will see may be incomplete. In other words, some era that existed in the history may be missing from your data. So you will also have to detect the cases where you cannot determine exactly which era the given year belongs to.
Input
The input contains multiple test cases. Each test case has the following format:
N Q
EraName1 EraBasedYear1 WesternYear1
.
.
.
EraNameN EraBasedYearN WesternYearN
Query1 .
.
.
QueryQ
The first line of the input contains two positive integers N and Q (1 ≤ N ≤ 1000, 1 ≤ Q ≤ 1000). N is the number of database entries, and Q is the number of queries.
Each of the following N lines has three components: era name, era-based year number and the corresponding western year (1 ≤ EraBasedYeari ≤ WesternYeari ≤ 109 ). Each of era names consist of at most 16 Roman alphabet characters. Then the last Q lines of the input specifies queries (1 ≤ Queryi ≤ 109 ), each of which is a western year to compute era-based representation.
The end of input is indicated by a line containing two zeros. This line is not part of any dataset and hence should not be processed.
You can assume that all the western year in the input is positive integers, and that there is no two entries that share the same era name.
Output
For each query, output in a line the era name and the era-based year number corresponding to the western year given, separated with a single whitespace. In case you cannot determine the era, output “Unknown” without quotes.
Example
Input
4 3
meiji 10 1877
taisho 6 1917
showa 62 1987
heisei 22 2010
1868
1917
1988
1 1
universalcentury 123 2168
2010
0 0
Output
meiji 1
taisho 6
Unknown
Unknown
Submitted Solution:
```
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve(n,e,q):
l = set([i for i in q])
d = defaultdict(lambda : 0)
for i in range(n):
n,j,k = e[i]
j = int(j)
k = int(k)
d[k-j+1] += i+1
d[k+1] -= i+1
l.add(k-j+1)
l.add(k+1)
l = list(l)
l.sort()
for i in range(len(l)-1):
d[l[i+1]] += d[l[i]]
for i in q:
j = d[i]
if j > 0:
print(e[j-1][0],i-int(e[j-1][2])+int(e[j-1][1]))
else:
print("Unknown")
return
#Solve
if __name__ == "__main__":
while 1:
n,Q = LI()
if n == Q == 0:
break
e = [input().split() for i in range(n)]
q = IR(Q)
solve(n,e,q)
``` | instruction | 0 | 38,548 | 4 | 77,096 |
Yes | output | 1 | 38,548 | 4 | 77,097 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As many of you know, we have two major calendar systems used in Japan today. One of them is Gregorian calendar which is widely used across the world. It is also known as “Western calendar” in Japan.
The other calendar system is era-based calendar, or so-called “Japanese calendar.” This system comes from ancient Chinese systems. Recently in Japan it has been a common way to associate dates with the Emperors. In the era-based system, we represent a year with an era name given at the time a new Emperor assumes the throne. If the era name is “A”, the first regnal year will be “A 1”, the second year will be “A 2”, and so forth.
Since we have two different calendar systems, it is often needed to convert the date in one calendar system to the other. In this problem, you are asked to write a program that converts western year to era-based year, given a database that contains association between several western years and era-based years.
For the simplicity, you can assume the following:
1. A new era always begins on January 1st of the corresponding Gregorian year.
2. The first year of an era is described as 1.
3. There is no year in which more than one era switch takes place.
Please note that, however, the database you will see may be incomplete. In other words, some era that existed in the history may be missing from your data. So you will also have to detect the cases where you cannot determine exactly which era the given year belongs to.
Input
The input contains multiple test cases. Each test case has the following format:
N Q
EraName1 EraBasedYear1 WesternYear1
.
.
.
EraNameN EraBasedYearN WesternYearN
Query1 .
.
.
QueryQ
The first line of the input contains two positive integers N and Q (1 ≤ N ≤ 1000, 1 ≤ Q ≤ 1000). N is the number of database entries, and Q is the number of queries.
Each of the following N lines has three components: era name, era-based year number and the corresponding western year (1 ≤ EraBasedYeari ≤ WesternYeari ≤ 109 ). Each of era names consist of at most 16 Roman alphabet characters. Then the last Q lines of the input specifies queries (1 ≤ Queryi ≤ 109 ), each of which is a western year to compute era-based representation.
The end of input is indicated by a line containing two zeros. This line is not part of any dataset and hence should not be processed.
You can assume that all the western year in the input is positive integers, and that there is no two entries that share the same era name.
Output
For each query, output in a line the era name and the era-based year number corresponding to the western year given, separated with a single whitespace. In case you cannot determine the era, output “Unknown” without quotes.
Example
Input
4 3
meiji 10 1877
taisho 6 1917
showa 62 1987
heisei 22 2010
1868
1917
1988
1 1
universalcentury 123 2168
2010
0 0
Output
meiji 1
taisho 6
Unknown
Unknown
Submitted Solution:
```
while True:
N, Q = map(int, input().split())
if not N:
break
a = []
for i in range(N):
x, y, z = input().split()
a.append((int(z), int(z) - int(y), x))
a = list(reversed(sorted(a)))
for i in range(Q):
x = int(input())
for v in a:
if v[0] >= x and v[1] < x:
print(v[2], x - v[1])
break;
else:
print('Unknown')
``` | instruction | 0 | 38,549 | 4 | 77,098 |
Yes | output | 1 | 38,549 | 4 | 77,099 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As many of you know, we have two major calendar systems used in Japan today. One of them is Gregorian calendar which is widely used across the world. It is also known as “Western calendar” in Japan.
The other calendar system is era-based calendar, or so-called “Japanese calendar.” This system comes from ancient Chinese systems. Recently in Japan it has been a common way to associate dates with the Emperors. In the era-based system, we represent a year with an era name given at the time a new Emperor assumes the throne. If the era name is “A”, the first regnal year will be “A 1”, the second year will be “A 2”, and so forth.
Since we have two different calendar systems, it is often needed to convert the date in one calendar system to the other. In this problem, you are asked to write a program that converts western year to era-based year, given a database that contains association between several western years and era-based years.
For the simplicity, you can assume the following:
1. A new era always begins on January 1st of the corresponding Gregorian year.
2. The first year of an era is described as 1.
3. There is no year in which more than one era switch takes place.
Please note that, however, the database you will see may be incomplete. In other words, some era that existed in the history may be missing from your data. So you will also have to detect the cases where you cannot determine exactly which era the given year belongs to.
Input
The input contains multiple test cases. Each test case has the following format:
N Q
EraName1 EraBasedYear1 WesternYear1
.
.
.
EraNameN EraBasedYearN WesternYearN
Query1 .
.
.
QueryQ
The first line of the input contains two positive integers N and Q (1 ≤ N ≤ 1000, 1 ≤ Q ≤ 1000). N is the number of database entries, and Q is the number of queries.
Each of the following N lines has three components: era name, era-based year number and the corresponding western year (1 ≤ EraBasedYeari ≤ WesternYeari ≤ 109 ). Each of era names consist of at most 16 Roman alphabet characters. Then the last Q lines of the input specifies queries (1 ≤ Queryi ≤ 109 ), each of which is a western year to compute era-based representation.
The end of input is indicated by a line containing two zeros. This line is not part of any dataset and hence should not be processed.
You can assume that all the western year in the input is positive integers, and that there is no two entries that share the same era name.
Output
For each query, output in a line the era name and the era-based year number corresponding to the western year given, separated with a single whitespace. In case you cannot determine the era, output “Unknown” without quotes.
Example
Input
4 3
meiji 10 1877
taisho 6 1917
showa 62 1987
heisei 22 2010
1868
1917
1988
1 1
universalcentury 123 2168
2010
0 0
Output
meiji 1
taisho 6
Unknown
Unknown
Submitted Solution:
```
#Time limit exceedsになるので二分探索法を使う
from bisect import bisect_left
while True:
n, q = map(int, input().split())
if n == 0:
break
era = {} # {西暦: ('元号', 年)}
years = []
for _ in range(n):
gengou, wa_year, we_year = input().split()
wa_year = int(wa_year)
we_year = int(we_year)
era[we_year] = (gengou, wa_year)
years.append(we_year)
years_final = sorted(years)
for _ in range(q):
year1 = int(input())
temp = bisect_left(years_final, year1)
if temp >= len(years_final):
print('Unknown')
continue
year2 = years_final[temp]
gengou, span = era[year2]
result = year1 - year2 + span
if result <= 0:
print('Unknown')
else:
print(gengou, result)
``` | instruction | 0 | 38,550 | 4 | 77,100 |
Yes | output | 1 | 38,550 | 4 | 77,101 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As many of you know, we have two major calendar systems used in Japan today. One of them is Gregorian calendar which is widely used across the world. It is also known as “Western calendar” in Japan.
The other calendar system is era-based calendar, or so-called “Japanese calendar.” This system comes from ancient Chinese systems. Recently in Japan it has been a common way to associate dates with the Emperors. In the era-based system, we represent a year with an era name given at the time a new Emperor assumes the throne. If the era name is “A”, the first regnal year will be “A 1”, the second year will be “A 2”, and so forth.
Since we have two different calendar systems, it is often needed to convert the date in one calendar system to the other. In this problem, you are asked to write a program that converts western year to era-based year, given a database that contains association between several western years and era-based years.
For the simplicity, you can assume the following:
1. A new era always begins on January 1st of the corresponding Gregorian year.
2. The first year of an era is described as 1.
3. There is no year in which more than one era switch takes place.
Please note that, however, the database you will see may be incomplete. In other words, some era that existed in the history may be missing from your data. So you will also have to detect the cases where you cannot determine exactly which era the given year belongs to.
Input
The input contains multiple test cases. Each test case has the following format:
N Q
EraName1 EraBasedYear1 WesternYear1
.
.
.
EraNameN EraBasedYearN WesternYearN
Query1 .
.
.
QueryQ
The first line of the input contains two positive integers N and Q (1 ≤ N ≤ 1000, 1 ≤ Q ≤ 1000). N is the number of database entries, and Q is the number of queries.
Each of the following N lines has three components: era name, era-based year number and the corresponding western year (1 ≤ EraBasedYeari ≤ WesternYeari ≤ 109 ). Each of era names consist of at most 16 Roman alphabet characters. Then the last Q lines of the input specifies queries (1 ≤ Queryi ≤ 109 ), each of which is a western year to compute era-based representation.
The end of input is indicated by a line containing two zeros. This line is not part of any dataset and hence should not be processed.
You can assume that all the western year in the input is positive integers, and that there is no two entries that share the same era name.
Output
For each query, output in a line the era name and the era-based year number corresponding to the western year given, separated with a single whitespace. In case you cannot determine the era, output “Unknown” without quotes.
Example
Input
4 3
meiji 10 1877
taisho 6 1917
showa 62 1987
heisei 22 2010
1868
1917
1988
1 1
universalcentury 123 2168
2010
0 0
Output
meiji 1
taisho 6
Unknown
Unknown
Submitted Solution:
```
while True:
n, q = map(int, input().split())
d = {}
if n == 0 and q == 0:
break
for i in range(n):
era, years, now = input().split()
begin = int(now) - int(years) + 1
d[era] = [begin, int(now)]
for i in range(q):
year = int(input())
for e, y in d.items():
if year >= y[0] and year <= y[1]:
print(e, year - y[0] + 1)
break
else:
print('Unknown')
``` | instruction | 0 | 38,551 | 4 | 77,102 |
Yes | output | 1 | 38,551 | 4 | 77,103 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As many of you know, we have two major calendar systems used in Japan today. One of them is Gregorian calendar which is widely used across the world. It is also known as “Western calendar” in Japan.
The other calendar system is era-based calendar, or so-called “Japanese calendar.” This system comes from ancient Chinese systems. Recently in Japan it has been a common way to associate dates with the Emperors. In the era-based system, we represent a year with an era name given at the time a new Emperor assumes the throne. If the era name is “A”, the first regnal year will be “A 1”, the second year will be “A 2”, and so forth.
Since we have two different calendar systems, it is often needed to convert the date in one calendar system to the other. In this problem, you are asked to write a program that converts western year to era-based year, given a database that contains association between several western years and era-based years.
For the simplicity, you can assume the following:
1. A new era always begins on January 1st of the corresponding Gregorian year.
2. The first year of an era is described as 1.
3. There is no year in which more than one era switch takes place.
Please note that, however, the database you will see may be incomplete. In other words, some era that existed in the history may be missing from your data. So you will also have to detect the cases where you cannot determine exactly which era the given year belongs to.
Input
The input contains multiple test cases. Each test case has the following format:
N Q
EraName1 EraBasedYear1 WesternYear1
.
.
.
EraNameN EraBasedYearN WesternYearN
Query1 .
.
.
QueryQ
The first line of the input contains two positive integers N and Q (1 ≤ N ≤ 1000, 1 ≤ Q ≤ 1000). N is the number of database entries, and Q is the number of queries.
Each of the following N lines has three components: era name, era-based year number and the corresponding western year (1 ≤ EraBasedYeari ≤ WesternYeari ≤ 109 ). Each of era names consist of at most 16 Roman alphabet characters. Then the last Q lines of the input specifies queries (1 ≤ Queryi ≤ 109 ), each of which is a western year to compute era-based representation.
The end of input is indicated by a line containing two zeros. This line is not part of any dataset and hence should not be processed.
You can assume that all the western year in the input is positive integers, and that there is no two entries that share the same era name.
Output
For each query, output in a line the era name and the era-based year number corresponding to the western year given, separated with a single whitespace. In case you cannot determine the era, output “Unknown” without quotes.
Example
Input
4 3
meiji 10 1877
taisho 6 1917
showa 62 1987
heisei 22 2010
1868
1917
1988
1 1
universalcentury 123 2168
2010
0 0
Output
meiji 1
taisho 6
Unknown
Unknown
Submitted Solution:
```
inputnum,outputnum = (int(n) for n in input().split(' '))
data = {}
while True:
for i in range(inputnum):
temp = input().split(' ')
data[temp[0]] = [int(temp[2]) - int(temp[1]) + 1,int(temp[2])]
for o in range(outputnum):
targ = int(input())
for k,v in data.items():
if v[0] <= targ <= v[1]:
print(k + ' ' + str(targ-v[0] + 1))
break
else:
print("Unknown")
inputnum,outputnum = (int(n) for n in input().split(' '))
if inputnum == outputnum == 0:
break
``` | instruction | 0 | 38,552 | 4 | 77,104 |
No | output | 1 | 38,552 | 4 | 77,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As many of you know, we have two major calendar systems used in Japan today. One of them is Gregorian calendar which is widely used across the world. It is also known as “Western calendar” in Japan.
The other calendar system is era-based calendar, or so-called “Japanese calendar.” This system comes from ancient Chinese systems. Recently in Japan it has been a common way to associate dates with the Emperors. In the era-based system, we represent a year with an era name given at the time a new Emperor assumes the throne. If the era name is “A”, the first regnal year will be “A 1”, the second year will be “A 2”, and so forth.
Since we have two different calendar systems, it is often needed to convert the date in one calendar system to the other. In this problem, you are asked to write a program that converts western year to era-based year, given a database that contains association between several western years and era-based years.
For the simplicity, you can assume the following:
1. A new era always begins on January 1st of the corresponding Gregorian year.
2. The first year of an era is described as 1.
3. There is no year in which more than one era switch takes place.
Please note that, however, the database you will see may be incomplete. In other words, some era that existed in the history may be missing from your data. So you will also have to detect the cases where you cannot determine exactly which era the given year belongs to.
Input
The input contains multiple test cases. Each test case has the following format:
N Q
EraName1 EraBasedYear1 WesternYear1
.
.
.
EraNameN EraBasedYearN WesternYearN
Query1 .
.
.
QueryQ
The first line of the input contains two positive integers N and Q (1 ≤ N ≤ 1000, 1 ≤ Q ≤ 1000). N is the number of database entries, and Q is the number of queries.
Each of the following N lines has three components: era name, era-based year number and the corresponding western year (1 ≤ EraBasedYeari ≤ WesternYeari ≤ 109 ). Each of era names consist of at most 16 Roman alphabet characters. Then the last Q lines of the input specifies queries (1 ≤ Queryi ≤ 109 ), each of which is a western year to compute era-based representation.
The end of input is indicated by a line containing two zeros. This line is not part of any dataset and hence should not be processed.
You can assume that all the western year in the input is positive integers, and that there is no two entries that share the same era name.
Output
For each query, output in a line the era name and the era-based year number corresponding to the western year given, separated with a single whitespace. In case you cannot determine the era, output “Unknown” without quotes.
Example
Input
4 3
meiji 10 1877
taisho 6 1917
showa 62 1987
heisei 22 2010
1868
1917
1988
1 1
universalcentury 123 2168
2010
0 0
Output
meiji 1
taisho 6
Unknown
Unknown
Submitted Solution:
```
from bisect import bisect_left
while True:
N, Q = map(int, input().split(' '))
if N == 0:
break
era = {} # Like {1877: ('Meiji', 10)}
years = [] # 西暦
for _ in range(N):
name, j, w = input().split(' ')
j, w = int(j), int(w)
era[w] = (name, j)
years.append(w)
years.sort()
for _ in range(Q):
q = int(input())
y = years[bisect_left(years, q)]
name, length = era[y]
if q - y + length <= 0:
print('Unknown')
else:
print(name + ' ' + str(q-y+length))
``` | instruction | 0 | 38,553 | 4 | 77,106 |
No | output | 1 | 38,553 | 4 | 77,107 |
Provide a correct Python 3 solution for this coding contest problem.
We have an analog clock whose three hands (the second hand, the minute hand and the hour hand) rotate quite smoothly. You can measure two angles between the second hand and two other hands.
Write a program to find the time at which "No two hands overlap each other" and "Two angles between the second hand and two other hands are equal" for the first time on or after a given time.
<image>
Figure D.1. Angles between the second hand and two other hands
Clocks are not limited to 12-hour clocks. The hour hand of an H-hour clock goes around once in H hours. The minute hand still goes around once every hour, and the second hand goes around once every minute. At 0:0:0 (midnight), all the hands are at the upright position.
Input
The input consists of multiple datasets. Each of the dataset has four integers H, h, m and s in one line, separated by a space. H means that the clock is an H-hour clock. h, m and s mean hour, minute and second of the specified time, respectively.
You may assume 2 ≤ H ≤ 100, 0 ≤ h < H, 0 ≤ m < 60, and 0 ≤ s < 60.
The end of the input is indicated by a line containing four zeros.
<image>
Figure D.2. Examples of H-hour clock (6-hour clock and 15-hour clock)
Output
Output the time T at which "No two hands overlap each other" and "Two angles between the second hand and two other hands are equal" for the first time on and after the specified time.
For T being ho:mo:so (so seconds past mo minutes past ho o'clock), output four non-negative integers ho, mo, n, and d in one line, separated by a space, where n/d is the irreducible fraction representing so. For integer so including 0, let d be 1.
The time should be expressed in the remainder of H hours. In other words, one second after (H − 1):59:59 is 0:0:0, not H:0:0.
Example
Input
12 0 0 0
12 11 59 59
12 1 56 0
12 1 56 3
12 1 56 34
12 3 9 43
12 3 10 14
12 7 17 58
12 7 18 28
12 7 23 0
12 7 23 31
2 0 38 29
2 0 39 0
2 0 39 30
2 1 6 20
2 1 20 1
2 1 20 31
3 2 15 0
3 2 59 30
4 0 28 48
5 1 5 40
5 1 6 10
5 1 7 41
11 0 55 0
0 0 0 0
Output
0 0 43200 1427
0 0 43200 1427
1 56 4080 1427
1 56 47280 1427
1 57 4860 1427
3 10 18600 1427
3 10 61800 1427
7 18 39240 1427
7 18 82440 1427
7 23 43140 1427
7 24 720 1427
0 38 4680 79
0 39 2340 79
0 40 0 1
1 6 3960 79
1 20 2400 79
1 21 60 79
2 15 0 1
0 0 2700 89
0 28 48 1
1 6 320 33
1 6 40 1
1 8 120 11
0 55 0 1 | instruction | 0 | 39,558 | 4 | 79,116 |
"Correct Solution:
```
import sys
def gcd(m, n):
while n:
m, n = n, m % n
return m
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
f = lambda h, m, s: 3600*h + 60*m + s
H, h, m, s = map(int, readline().split())
if H == 0:
return False
d0 = f(h, m, s)
M = f(H, 0, 0)
res = []
for h0 in range(H):
for m0 in range(60):
p = 3600*h0 + 60*m0 + 60*H*m0; q = 119*H-1
for d in [-3600*H, 0, 3600*H]:
p1 = p + d; q1 = q
g = gcd(p1, q); p1 //= g; q1 //= g
if 0 <= p1 < 60*q1:
if H*(60*m0*q1 + p1) != q1*(3600*h0 + 60*m0) + p1:
res.append((f(h0, m0, 0) + p1/q1, h0, m0, p1, q1))
res.sort(key = lambda x: (x[0] - d0) % M)
_, h, m, p, q = res[0]
write("%d %d %d %d\n" % (h, m, p, q))
return True
while solve():
...
``` | output | 1 | 39,558 | 4 | 79,117 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
Constraints
* 0 \leq A,B \leq 23
* A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the hour of the starting time of the contest in 24-hour time.
Examples
Input
9 12
Output
21
Input
19 0
Output
19
Input
23 2
Output
1 | instruction | 0 | 41,085 | 4 | 82,170 |
"Correct Solution:
```
[A,B]=list(map(int,input().split()))
print((A+B)%24)
``` | output | 1 | 41,085 | 4 | 82,171 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
Constraints
* 0 \leq A,B \leq 23
* A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the hour of the starting time of the contest in 24-hour time.
Examples
Input
9 12
Output
21
Input
19 0
Output
19
Input
23 2
Output
1 | instruction | 0 | 41,086 | 4 | 82,172 |
"Correct Solution:
```
import math
a,b = map(int, input().split())
print(abs(a + b) % 24)
``` | output | 1 | 41,086 | 4 | 82,173 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
Constraints
* 0 \leq A,B \leq 23
* A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the hour of the starting time of the contest in 24-hour time.
Examples
Input
9 12
Output
21
Input
19 0
Output
19
Input
23 2
Output
1 | instruction | 0 | 41,087 | 4 | 82,174 |
"Correct Solution:
```
A, B = list(map(int, input().split()))
T = (A + B) % 24
print(T)
``` | output | 1 | 41,087 | 4 | 82,175 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
Constraints
* 0 \leq A,B \leq 23
* A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the hour of the starting time of the contest in 24-hour time.
Examples
Input
9 12
Output
21
Input
19 0
Output
19
Input
23 2
Output
1 | instruction | 0 | 41,088 | 4 | 82,176 |
"Correct Solution:
```
print(sum([int(i) for i in input().split()]) % 24)
``` | output | 1 | 41,088 | 4 | 82,177 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
Constraints
* 0 \leq A,B \leq 23
* A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the hour of the starting time of the contest in 24-hour time.
Examples
Input
9 12
Output
21
Input
19 0
Output
19
Input
23 2
Output
1 | instruction | 0 | 41,089 | 4 | 82,178 |
"Correct Solution:
```
a, b = map(int, input().split())
A = a+b
B = A%24
print(B)
``` | output | 1 | 41,089 | 4 | 82,179 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
Constraints
* 0 \leq A,B \leq 23
* A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the hour of the starting time of the contest in 24-hour time.
Examples
Input
9 12
Output
21
Input
19 0
Output
19
Input
23 2
Output
1 | instruction | 0 | 41,090 | 4 | 82,180 |
"Correct Solution:
```
a,b = map(int,input().split())
r = (24+a+b)%24
print(r)
``` | output | 1 | 41,090 | 4 | 82,181 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
Constraints
* 0 \leq A,B \leq 23
* A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the hour of the starting time of the contest in 24-hour time.
Examples
Input
9 12
Output
21
Input
19 0
Output
19
Input
23 2
Output
1 | instruction | 0 | 41,091 | 4 | 82,182 |
"Correct Solution:
```
#2019/09/24
A, B = map(int, input().split())
print((A + B) % 24)
``` | output | 1 | 41,091 | 4 | 82,183 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
Constraints
* 0 \leq A,B \leq 23
* A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the hour of the starting time of the contest in 24-hour time.
Examples
Input
9 12
Output
21
Input
19 0
Output
19
Input
23 2
Output
1 | instruction | 0 | 41,092 | 4 | 82,184 |
"Correct Solution:
```
t1,t2 = list(map(int,input().strip().split()))
print((t1+t2)%24)
``` | output | 1 | 41,092 | 4 | 82,185 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
Constraints
* 0 \leq A,B \leq 23
* A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the hour of the starting time of the contest in 24-hour time.
Examples
Input
9 12
Output
21
Input
19 0
Output
19
Input
23 2
Output
1
Submitted Solution:
```
A,B=map(int,input().split(' '))
print(str((A+B)%24))
``` | instruction | 0 | 41,093 | 4 | 82,186 |
Yes | output | 1 | 41,093 | 4 | 82,187 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
Constraints
* 0 \leq A,B \leq 23
* A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the hour of the starting time of the contest in 24-hour time.
Examples
Input
9 12
Output
21
Input
19 0
Output
19
Input
23 2
Output
1
Submitted Solution:
```
print(sum(list(int(i) for i in input().split()))%24)
``` | instruction | 0 | 41,094 | 4 | 82,188 |
Yes | output | 1 | 41,094 | 4 | 82,189 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
Constraints
* 0 \leq A,B \leq 23
* A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the hour of the starting time of the contest in 24-hour time.
Examples
Input
9 12
Output
21
Input
19 0
Output
19
Input
23 2
Output
1
Submitted Solution:
```
a,b = map(int,input().split())
print((a+b) % 24)
``` | instruction | 0 | 41,095 | 4 | 82,190 |
Yes | output | 1 | 41,095 | 4 | 82,191 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
Constraints
* 0 \leq A,B \leq 23
* A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the hour of the starting time of the contest in 24-hour time.
Examples
Input
9 12
Output
21
Input
19 0
Output
19
Input
23 2
Output
1
Submitted Solution:
```
x=sum(list(map(int,input().split())))
if x>=24:
x-=24
print(x)
``` | instruction | 0 | 41,096 | 4 | 82,192 |
Yes | output | 1 | 41,096 | 4 | 82,193 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
Constraints
* 0 \leq A,B \leq 23
* A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the hour of the starting time of the contest in 24-hour time.
Examples
Input
9 12
Output
21
Input
19 0
Output
19
Input
23 2
Output
1
Submitted Solution:
```
a,b = map(int,input().split())
if a + b <= 24:
t = a + b
else:
t = a + b - 24
print(t)
``` | instruction | 0 | 41,097 | 4 | 82,194 |
No | output | 1 | 41,097 | 4 | 82,195 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
Constraints
* 0 \leq A,B \leq 23
* A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the hour of the starting time of the contest in 24-hour time.
Examples
Input
9 12
Output
21
Input
19 0
Output
19
Input
23 2
Output
1
Submitted Solution:
```
import math
def C(n, r):
fact = math.factorial
return fact(n) // fact(r) // fact(n-r)
N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v_sort = sorted(v, reverse=True)
print(sum(v_sort[:A])/A)
a, b = v_sort.count(v_sort[A-1]), v_sort[:A].count(v_sort[A-1])
if v_sort[0] == v_sort[A-1]:
print(sum([C(a, r) for r in range(A, min(B, a)+1)]))
else:
print(C(a, b))
``` | instruction | 0 | 41,098 | 4 | 82,196 |
No | output | 1 | 41,098 | 4 | 82,197 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
Constraints
* 0 \leq A,B \leq 23
* A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the hour of the starting time of the contest in 24-hour time.
Examples
Input
9 12
Output
21
Input
19 0
Output
19
Input
23 2
Output
1
Submitted Solution:
```
n, m = map(int,input().split())
students = [None]*n
points = [None]*m
students[i] = [tuple(map(int, input.split())) for _ in range(n)]
points[i] = [tuple(map(int, input.split())) for _ in range(m)]
ans = []
for s in students:
tmp = []
for p in points:
tmp.append(abs(s[0] - p[0]) + abs(s[1] - p[1]))
ans.append(tmp.index(min(tmp)) + 1)
for i in range(n):
print(ans[i])
``` | instruction | 0 | 41,099 | 4 | 82,198 |
No | output | 1 | 41,099 | 4 | 82,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
Constraints
* 0 \leq A,B \leq 23
* A and B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the hour of the starting time of the contest in 24-hour time.
Examples
Input
9 12
Output
21
Input
19 0
Output
19
Input
23 2
Output
1
Submitted Solution:
```
a = list(map(int, input().split()))
sum = a[0] + a[1]
if(sum <= 24):
print(sum)
else:
print(sum - 24)
``` | instruction | 0 | 41,100 | 4 | 82,200 |
No | output | 1 | 41,100 | 4 | 82,201 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
Output
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
Examples
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
Note
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate. | instruction | 0 | 41,816 | 4 | 83,632 |
Tags: binary search, two pointers
Correct Solution:
```
n = int(input())
a = [int(i) for i in input().split()]
s, f = [int(i) for i in input().split()]
a = a + a
ln = f - s
ans = sum(a[:ln])
mx = ans
h = s
for i in range(n - 1):
ans = ans - a[i] + a[i + ln]
if ans > mx:
ans = mx
k = s + (n - (i + 2) + 1)
if k > n:
k -= n
h = k
elif ans == mx:
k = s + (n - (i + 2) + 1)
if k > n:
k -= n
h = min(h, k)
print(h)
``` | output | 1 | 41,816 | 4 | 83,633 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
Output
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
Examples
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
Note
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate. | instruction | 0 | 41,817 | 4 | 83,634 |
Tags: binary search, two pointers
Correct Solution:
```
n = int(input())
a = [int(i) for i in input().split(' ')]
s, f = [int(i) for i in input().split(' ')]
m = sum(a[i] for i in range(s - 1, f - 1))
current, time = m, 0
for i in range(n):
current = current - a[(s - 1 + i) % n] + a[(f - 1 + i) % n]
if current >= m:
m = current
time = i
print(n - time)
``` | output | 1 | 41,817 | 4 | 83,635 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
Output
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
Examples
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
Note
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate. | instruction | 0 | 41,818 | 4 | 83,636 |
Tags: binary search, two pointers
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
s, f = map(int, input().split())
s -= 1
f -= 1
best_sum = sum(a[s:f])
best_i = 0
cur_sum = best_sum
for i in range(1, n):
cur_sum += a[(s - i + n) % n]
cur_sum -= a[(f - i + n) % n]
if cur_sum > best_sum:
best_sum = cur_sum
best_i = i
print(best_i + 1)
``` | output | 1 | 41,818 | 4 | 83,637 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
Output
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
Examples
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
Note
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate. | instruction | 0 | 41,819 | 4 | 83,638 |
Tags: binary search, two pointers
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 7 23:03:41 2018
@author: Paras Sharma
"""
n=int(input())
l=list(map(int,input().split()))
s,e=list(map(int,input().split()))
t=e-s
curr=sum(l[:t-1])
#print(curr)
newl=[]
for i in range(t-1,n+t-1):
#print(i)
if(i>n-1):
i=i%n
#print(i)
newl.append(curr+l[i])
#print(newl)
curr=curr-l[i-t+1]+l[i]
#print(curr)
maxi=newl.index(max(newl))
#print(maxi)
ind=[]
curmax=max(newl)
for k in range(len(newl)):
if newl[k]==curmax:
ind.append(k+1)
#print(ind)
ans=[]
for l in range(len(ind)):
ans.append(s)
for j in range(ind[l]-1):
if ans[l]<=1:
ans[l]=n
else:
ans[l]-=1
print(min(ans))
'''ans=s
for j in range(maxi):
if ans<=1:
ans=n
else:
ans-=1
print(ans)
'''
``` | output | 1 | 41,819 | 4 | 83,639 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
Output
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
Examples
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
Note
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate. | instruction | 0 | 41,820 | 4 | 83,640 |
Tags: binary search, two pointers
Correct Solution:
```
# cook your dish here
n = int(input())
a = list(map(int, input().split()))
s, f = map(int, input().split())
def conv(i, n, s):
return ( s - (i - 1) ) % n
d = {}
sm = 0
diff = f - s
for i in range(diff):
sm+=a[i]
for i in range(n):
tm = conv(i+1, n, s)
tm = n if tm == 0 else tm
# print(tm)
d[tm] = sm
sm -= a[i]
sm += a[(i+diff)%n]
mx = 0
mxi = 0
for i in range(1, n+1):
if d[i] > mx:
mx = d[i]
mxi = i
# print(d)
print(mxi)
``` | output | 1 | 41,820 | 4 | 83,641 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
Output
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
Examples
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
Note
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate. | instruction | 0 | 41,821 | 4 | 83,642 |
Tags: binary search, two pointers
Correct Solution:
```
n = int(input())
l = list(map(int,input().split()))
s,f = map(int,input().split())
pref = [0]
for i in l:
pref.append(i+pref[-1])
f-=1
maxi = 0
ha = 1
ans = 0
# print(pref)
while ha<=n:
if f>=s:
sumi = pref[f]-pref[s-1]
else:
sumi = pref[f]+pref[n]-pref[s-1]
if sumi>maxi:
ans = ha
maxi = sumi
# print(sumi,s,f)
s-=1
f-=1
s%=n
f%=n
if s == 0:
s = n
if f == 0:
f = n
ha+=1
# print(maxi)
print(ans)
``` | output | 1 | 41,821 | 4 | 83,643 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
Output
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
Examples
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
Note
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate. | instruction | 0 | 41,822 | 4 | 83,644 |
Tags: binary search, two pointers
Correct Solution:
```
n = int(input())
lst = []
for x in input().split():
lst.append(int(x))
s, f = map(int, input().split())
s -= 1
f -= 1
best_sum = sum(lst[s:f])
best_i = 0
cur_sum = best_sum
for i in range(1, n):
cur_sum += lst[(s - i + n) % n]
cur_sum -= lst[(f - i + n) % n]
if cur_sum > best_sum:
best_sum = cur_sum
best_i = i
print(best_i + 1)
``` | output | 1 | 41,822 | 4 | 83,645 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
Output
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
Examples
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
Note
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate. | instruction | 0 | 41,823 | 4 | 83,646 |
Tags: binary search, two pointers
Correct Solution:
```
def main():
n = int(input())
a = [int(x) for x in input().split()]
a += a
s, f = [int(x) for x in input().split()]
dp = [0 for _ in range(2 * n + 1)]
for i in range(2 * n):
dp[i + 1] = dp[i] + a[i]
ans, sum = 0, 0
for i in range(n):
cur_sum = dp[f + n - i - 1] - dp[s + n - i - 1]
if cur_sum > sum:
ans = i
sum = cur_sum
ans += 1
print(ans)
if __name__ == '__main__':
main()
``` | output | 1 | 41,823 | 4 | 83,647 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
Output
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
Examples
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
Note
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
Submitted Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
s,f = [int(x) for x in input().split()]
zones = f-s
currans = 1
currmax = sum(a[s-1 : f-2])
ans=1
maxppl = currmax
fst = s-1
lst = f-2
for currans in range(2, n+1):
currmax += a[fst-1 if fst > 0 else n-1]
currmax -= a[lst]
fst = fst-1 if fst > 0 else n-1
lst = lst - 1 if lst > 0 else n - 1
if currmax > maxppl:
maxppl = currmax
ans = currans
print(ans)
``` | instruction | 0 | 41,824 | 4 | 83,648 |
Yes | output | 1 | 41,824 | 4 | 83,649 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
Output
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
Examples
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
Note
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
Submitted Solution:
```
# C
import copy
N = int(input())
A = list(map(int, input().split()))
s, f = map(int, input().split())
B = copy.deepcopy(A)
C = A + B # Aを二つ連結したリスト
l = f - s
max_list = []
max_number = 0
sumC = [0 for i in range(N)]
sumC[0] = sum(C[0:l])
for i in range(1, N):
sumC[i] = sumC[i-1] + C[i+l-1] - C[i-1]
for i in range(N):
if sumC[i] > max_number:
max_list = [i]
max_number = sumC[i]
elif sumC[i] == max_number:
max_list.append(i)
ans_list = []
for j in max_list:
for i in range(N):
if j + i < N:
if s + i <= N:
A[j + i] = s + i
else:
A[j + i] = s + i - N
else:
if s + i <= N:
A[j + i - N] = s + i
else:
A[j + i - N] = s + i - N
ans_list.append(A[0])
print(min(ans_list))
``` | instruction | 0 | 41,825 | 4 | 83,650 |
Yes | output | 1 | 41,825 | 4 | 83,651 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
Output
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
Examples
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
Note
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
Submitted Solution:
```
zones = int(input())
people = list(map(int, input().split()))
s, f = map(int, input().split())
gap = f - 1 - s
sums = [sum(people[: gap + 1])]
times = []
people += people[: gap + 1]
for i in range(1, zones):
sums.append(sums[i - 1] - people[i - 1] + people[i + gap])
p_max = max(sums)
for i in range(len(sums)):
if sums[i] == p_max:
if s > i:
times.append(s - i)
else:
times.append(zones + s - i)
print(min(times))
``` | instruction | 0 | 41,826 | 4 | 83,652 |
Yes | output | 1 | 41,826 | 4 | 83,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
Output
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
Examples
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
Note
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
Submitted Solution:
```
from sys import stdin as si
from collections import Counter as c
class Solution:
def bazinga(self, n,m, k):
mnp = sum(m[k[0]-1:k[1]-1]) # min number of participants
diff = k[1]-k[0]
mxp,ans = mnp, 0 # maximizing participants
for i in range(1,n):
# print (i,diff, mxp,mnp, sum(m[i: diff+i]))
mxp += m[(k[0]-i-1 + n) % n]
mxp -= m[(k[1]-i-1 + n) % n]
if mxp > mnp:
mnp,ans = mxp, i
return ans +1
if __name__ == '__main__':
#for i in range(int(si.readline().strip())):
n = int(si.readline().strip())
m = list(map(int, si.readline().strip().split()))
k = tuple(map(int, si.readline().strip().split()))
S = Solution()
print(S.bazinga(n, m, k))
'''
http://codeforces.com/contest/939/problem/C
'''
``` | instruction | 0 | 41,827 | 4 | 83,654 |
Yes | output | 1 | 41,827 | 4 | 83,655 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
Output
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
Examples
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
Note
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
Submitted Solution:
```
n = int(input())
a = [0]
a += [int(i) for i in input().split()]
s,f = [int(i) for i in input().split()]
sum = 0
for i in range(1,f - s + 1):sum += a[i]
maxn,ans = sum,1
tmp = f - s - 1
for i in range(2,n + 1):
tmp2 = i + tmp
if(tmp2 > n):tmp2 %= n
sum = sum - a[i - 1] + a[tmp2]
#print(i,sum)
if(sum >= maxn):
ans = i
maxn = sum
if(n == 10000 and a[1] == 3256):
for i in a:
print(i,end = ',')
if ans < s:print(s - ans + 1)
else:print(n + s - ans + 1)
``` | instruction | 0 | 41,828 | 4 | 83,656 |
No | output | 1 | 41,828 | 4 | 83,657 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
Output
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
Examples
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
Note
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split()))
s,t = list(map(int,input().split()))
x = t - s;
i = 0
j = x - 1
ans = 0
cur = 0
p = 1
q = 1
for k in range(i,j + 1):
ans += a[k]
cur = ans
while p != n:
ii = (i + 1) % n
jj = (j + 1) % n
p += 1
cur = cur - a[i] + a[jj]
if cur > ans:
ans = cur
q = p
i = ii
j = jj
ret = (n - q + 1 + s) % n
if (ret == 0): ret = n
print(ret)
``` | instruction | 0 | 41,829 | 4 | 83,658 |
No | output | 1 | 41,829 | 4 | 83,659 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
Output
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
Examples
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
Note
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
Submitted Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
s, f = (int(x) for x in input().split())
a = a + a[:f - s - 1]
max_i = 0
t = s
max = 0
max_t = t
sum = sum(a[0:0 + f - s])
for i in range(n):
if sum > max:
max = sum
max_i = i
max_t = t
if i < (n - 1):
sum += a[i + f - s] - a[i]
t -= 1
if t == 0:
t = n
print(max_t)
``` | instruction | 0 | 41,830 | 4 | 83,660 |
No | output | 1 | 41,830 | 4 | 83,661 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.
Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.
Help platform select such an hour, that the number of people who will participate in the contest is maximum.
Input
The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.
The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).
Output
Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.
Examples
Input
3
1 2 3
1 3
Output
3
Input
5
1 2 3 4 1
1 3
Output
4
Note
In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.
In second example only people from the third and the fourth timezones will participate.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
s, f = list(map(int, input().split()))
d = f-s
msum = 0
sums = []
for x in range(n-d+1):
if (sum(a[x:x+d]) > msum):
msum = sum(a[x:x+d])
sums = [n-x+s,msum]
elif (sum(a[x:x+d]) == msum):
sums.append([n-x+s,msum])
print(min(sums))
``` | instruction | 0 | 41,831 | 4 | 83,662 |
No | output | 1 | 41,831 | 4 | 83,663 |
Provide a correct Python 3 solution for this coding contest problem.
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.
Find the maximum possible total points of happiness that Taro gains.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq a_i, b_i, c_i \leq 10^4
Input
Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N
Output
Print the maximum possible total points of happiness that Taro gains.
Examples
Input
3
10 40 70
20 50 80
30 60 90
Output
210
Input
1
100 10 1
Output
100
Input
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
Output
46 | instruction | 0 | 41,877 | 4 | 83,754 |
"Correct Solution:
```
N = int(input())
ABC = [[int(_) for _ in input().split()] for _ in range(N)]
dp = [0, 0, 0]
for a, b, c in ABC:
dp = [a + max(dp[1:]), b + max([dp[0], dp[2]]), c + max(dp[:2])]
print(max(dp))
``` | output | 1 | 41,877 | 4 | 83,755 |
Provide a correct Python 3 solution for this coding contest problem.
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.
Find the maximum possible total points of happiness that Taro gains.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq a_i, b_i, c_i \leq 10^4
Input
Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N
Output
Print the maximum possible total points of happiness that Taro gains.
Examples
Input
3
10 40 70
20 50 80
30 60 90
Output
210
Input
1
100 10 1
Output
100
Input
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
Output
46 | instruction | 0 | 41,878 | 4 | 83,756 |
"Correct Solution:
```
n, *t = map( int, open( 0 ).read().split() )
# manemane
A, B, C = 0, 0, 0
for i in range( n ):
A, B, C = t[ 3 * i ] + max( B, C ), t[ 3 * i + 1 ] + max( A, C ), t[ 3 * i + 2 ] + max( A, B )
print( max( A, B, C ) )
``` | output | 1 | 41,878 | 4 | 83,757 |
Provide a correct Python 3 solution for this coding contest problem.
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.
Find the maximum possible total points of happiness that Taro gains.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq a_i, b_i, c_i \leq 10^4
Input
Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N
Output
Print the maximum possible total points of happiness that Taro gains.
Examples
Input
3
10 40 70
20 50 80
30 60 90
Output
210
Input
1
100 10 1
Output
100
Input
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
Output
46 | instruction | 0 | 41,879 | 4 | 83,758 |
"Correct Solution:
```
n=int(input())
V=[[0]*3 for i in range(2)]
d=1
e=0
for i in range(n):
a,b,c=map(int,input().split())
V[d][0]=max(V[e][1],V[e][2])+a
V[d][1]=max(V[e][2],V[e][0])+b
V[d][2]=max(V[e][0],V[e][1])+c
d=e
e=(e+1)%2
print(max(V[e][0],V[e][1],V[e][2]))
``` | output | 1 | 41,879 | 4 | 83,759 |
Provide a correct Python 3 solution for this coding contest problem.
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.
Find the maximum possible total points of happiness that Taro gains.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq a_i, b_i, c_i \leq 10^4
Input
Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N
Output
Print the maximum possible total points of happiness that Taro gains.
Examples
Input
3
10 40 70
20 50 80
30 60 90
Output
210
Input
1
100 10 1
Output
100
Input
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
Output
46 | instruction | 0 | 41,880 | 4 | 83,760 |
"Correct Solution:
```
N = int(input())
dp = [0, 0, 0]
for i in range(N):
a, b, c = map(int, input().split())
tmp_a = a + max(dp[1], dp[2])
tmp_b = b + max(dp[0], dp[2])
tmp_c = c + max(dp[0], dp[1])
dp = [tmp_a, tmp_b, tmp_c]
print(max(dp))
``` | output | 1 | 41,880 | 4 | 83,761 |
Provide a correct Python 3 solution for this coding contest problem.
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.
Find the maximum possible total points of happiness that Taro gains.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq a_i, b_i, c_i \leq 10^4
Input
Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N
Output
Print the maximum possible total points of happiness that Taro gains.
Examples
Input
3
10 40 70
20 50 80
30 60 90
Output
210
Input
1
100 10 1
Output
100
Input
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
Output
46 | instruction | 0 | 41,881 | 4 | 83,762 |
"Correct Solution:
```
N = int(input())
wa, wb, wc = [0] * 3
for a, b, c in (map(int, input().split()) for _ in range(N)):
wa, wb, wc = a + max(wb, wc), b + max(wa, wc), c + max(wa, wb)
print(max(wa, wb, wc))
``` | output | 1 | 41,881 | 4 | 83,763 |
Provide a correct Python 3 solution for this coding contest problem.
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.
Find the maximum possible total points of happiness that Taro gains.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq a_i, b_i, c_i \leq 10^4
Input
Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N
Output
Print the maximum possible total points of happiness that Taro gains.
Examples
Input
3
10 40 70
20 50 80
30 60 90
Output
210
Input
1
100 10 1
Output
100
Input
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
Output
46 | instruction | 0 | 41,882 | 4 | 83,764 |
"Correct Solution:
```
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
dp=[[0 for i in range(3)] for j in range(n+1)]
dp[1]=l[0]
for i in range(2,n+1):
for j in range(3):
dp[i][j]=max(dp[i-1][j-1],dp[i-1][j-2])+l[i-1][j]
print(max(dp[-1]))
``` | output | 1 | 41,882 | 4 | 83,765 |
Provide a correct Python 3 solution for this coding contest problem.
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.
Find the maximum possible total points of happiness that Taro gains.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq a_i, b_i, c_i \leq 10^4
Input
Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N
Output
Print the maximum possible total points of happiness that Taro gains.
Examples
Input
3
10 40 70
20 50 80
30 60 90
Output
210
Input
1
100 10 1
Output
100
Input
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
Output
46 | instruction | 0 | 41,883 | 4 | 83,766 |
"Correct Solution:
```
N = int(input())
la, lb, lc = [0] * 3
for i in range(N):
a, b, c = [int(x) for x in input().split()]
aa = a + max(lb, lc)
bb = b + max(lc, la)
cc = c + max(lb, la)
la = aa
lb = bb
lc = cc
print(max(la, lb, lc))
``` | output | 1 | 41,883 | 4 | 83,767 |
Provide a correct Python 3 solution for this coding contest problem.
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.
Find the maximum possible total points of happiness that Taro gains.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq a_i, b_i, c_i \leq 10^4
Input
Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N
Output
Print the maximum possible total points of happiness that Taro gains.
Examples
Input
3
10 40 70
20 50 80
30 60 90
Output
210
Input
1
100 10 1
Output
100
Input
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
Output
46 | instruction | 0 | 41,884 | 4 | 83,768 |
"Correct Solution:
```
N=int(input())
abc=[list(map(int,input().split())) for i in range(N)]
x,y,z = 0,0,0
for a,b,c in abc:
x,y,z = max(y,z)+a,max(x,z)+b,max(x,y)+c
print(max(x,y,z))
``` | output | 1 | 41,884 | 4 | 83,769 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.
The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day:
* A: Swim in the sea. Gain a_i points of happiness.
* B: Catch bugs in the mountains. Gain b_i points of happiness.
* C: Do homework at home. Gain c_i points of happiness.
As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.
Find the maximum possible total points of happiness that Taro gains.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq a_i, b_i, c_i \leq 10^4
Input
Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N
Output
Print the maximum possible total points of happiness that Taro gains.
Examples
Input
3
10 40 70
20 50 80
30 60 90
Output
210
Input
1
100 10 1
Output
100
Input
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
Output
46
Submitted Solution:
```
n = int(input())
A = B = C = 0
for _ in range(n):
a, b, c = map(int, input().split())
A, B, C = max(B, C)+a, max(A, C)+b, max(A, B)+c
print(max(A, B, C))
``` | instruction | 0 | 41,885 | 4 | 83,770 |
Yes | output | 1 | 41,885 | 4 | 83,771 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.