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. On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it. Constraints * S is a string of length 10. * The first eight characters in S are `2017/01/`. * The last two characters in S are digits and represent an integer between 1 and 31 (inclusive). Input Input is given from Standard Input in the following format: S Output Replace the first four characters in S with `2018` and print it. Examples Input 2017/01/07 Output 2018/01/07 Input 2017/01/31 Output 2018/01/31
instruction
0
47,791
4
95,582
"Correct Solution: ``` print(f"{2018}{input()[4:]}") ```
output
1
47,791
4
95,583
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it. Constraints * S is a string of length 10. * The first eight characters in S are `2017/01/`. * The last two characters in S are digits and represent an integer between 1 and 31 (inclusive). Input Input is given from Standard Input in the following format: S Output Replace the first four characters in S with `2018` and print it. Examples Input 2017/01/07 Output 2018/01/07 Input 2017/01/31 Output 2018/01/31 Submitted Solution: ``` s = input() ss = "2018"+s[4:] print(ss) ```
instruction
0
47,792
4
95,584
Yes
output
1
47,792
4
95,585
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it. Constraints * S is a string of length 10. * The first eight characters in S are `2017/01/`. * The last two characters in S are digits and represent an integer between 1 and 31 (inclusive). Input Input is given from Standard Input in the following format: S Output Replace the first four characters in S with `2018` and print it. Examples Input 2017/01/07 Output 2018/01/07 Input 2017/01/31 Output 2018/01/31 Submitted Solution: ``` a=input() print(a.replace("7","8",1)) ```
instruction
0
47,793
4
95,586
Yes
output
1
47,793
4
95,587
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it. Constraints * S is a string of length 10. * The first eight characters in S are `2017/01/`. * The last two characters in S are digits and represent an integer between 1 and 31 (inclusive). Input Input is given from Standard Input in the following format: S Output Replace the first four characters in S with `2018` and print it. Examples Input 2017/01/07 Output 2018/01/07 Input 2017/01/31 Output 2018/01/31 Submitted Solution: ``` s=input() print('2018{}'.format(s[4:])) ```
instruction
0
47,794
4
95,588
Yes
output
1
47,794
4
95,589
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it. Constraints * S is a string of length 10. * The first eight characters in S are `2017/01/`. * The last two characters in S are digits and represent an integer between 1 and 31 (inclusive). Input Input is given from Standard Input in the following format: S Output Replace the first four characters in S with `2018` and print it. Examples Input 2017/01/07 Output 2018/01/07 Input 2017/01/31 Output 2018/01/31 Submitted Solution: ``` N, Y = map(int, input().split()) for i in range(N+1): for j in range(N+1-i): if 10000*i + 5000*j + 1000*(N-i-j) == Y: print(i, j, N-i-j) break else: print("-1 -1 -1") ```
instruction
0
47,796
4
95,592
No
output
1
47,796
4
95,593
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it. Constraints * S is a string of length 10. * The first eight characters in S are `2017/01/`. * The last two characters in S are digits and represent an integer between 1 and 31 (inclusive). Input Input is given from Standard Input in the following format: S Output Replace the first four characters in S with `2018` and print it. Examples Input 2017/01/07 Output 2018/01/07 Input 2017/01/31 Output 2018/01/31 Submitted Solution: ``` n, y = map(int, input().split()) noguchi = 1000 higuchi = 5000 yukichi = 10000 ans = '-1 -1 -1' for i in range(n+1): for j in range(n+1-i): k = n - (i+j) yen = noguchi * i + higuchi * j + yukichi * k if yen == y: ans = '{0} {1} {2}'.format(k,j,i) break print(ans) ```
instruction
0
47,797
4
95,594
No
output
1
47,797
4
95,595
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it. Constraints * S is a string of length 10. * The first eight characters in S are `2017/01/`. * The last two characters in S are digits and represent an integer between 1 and 31 (inclusive). Input Input is given from Standard Input in the following format: S Output Replace the first four characters in S with `2018` and print it. Examples Input 2017/01/07 Output 2018/01/07 Input 2017/01/31 Output 2018/01/31 Submitted Solution: ``` N = list(input()) N[0] = "2" N[1] = "0" N[2] = "1" N[3] = "8" print(N) date = ''.join(N) print(date) ```
instruction
0
47,799
4
95,598
No
output
1
47,799
4
95,599
Provide tags and a correct Python 3 solution for this coding contest problem. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive. Calculate the number of minutes they will be able to spend together. Input The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Print one integer — the number of minutes Sonya and Filya will be able to spend together. Examples Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 Note In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
instruction
0
48,418
4
96,836
Tags: implementation, math Correct Solution: ``` a,b,c,d,k=map(int,input().split()) l=max(a,c) r=min(b,d) if r<l: print(0) elif l<=k<=r and a<=k<=b: print (r-l) else : print (r-l+1) ```
output
1
48,418
4
96,837
Provide tags and a correct Python 3 solution for this coding contest problem. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive. Calculate the number of minutes they will be able to spend together. Input The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Print one integer — the number of minutes Sonya and Filya will be able to spend together. Examples Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 Note In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
instruction
0
48,419
4
96,838
Tags: implementation, math Correct Solution: ``` i1,s1,i2,s2,k=map(int,input().split()) if i2<=s1 and i2>=i1 and s2>=s1: if k>=i2 and k <=s1 : print(s1-i2) else: print(s1-i2+1) elif i2>=i1 and i2<=s1 and s2<=s1: if k>=i2 and k <=s2 : print(s2-i2) else: print(s2-i2+1) elif i1<=s2 and i1>=i2 and s1>=s2: if k>=i1 and k <=s2 : print(s2-i1) else: print(s2-i1+1) elif i1<=s2 and i1>=i2 and s1<=s2: if k>=i1 and k <=s1 : print(s1-i1) else: print(s1-i1+1) else: print(0) ```
output
1
48,419
4
96,839
Provide tags and a correct Python 3 solution for this coding contest problem. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive. Calculate the number of minutes they will be able to spend together. Input The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Print one integer — the number of minutes Sonya and Filya will be able to spend together. Examples Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 Note In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
instruction
0
48,420
4
96,840
Tags: implementation, math Correct Solution: ``` inp = list(map(int, input().split())) l = max(inp[0], inp[2]) r = min(inp[1], inp[3]) res = max(r - l + 1, 0) print(res - (l <= inp[4] <= r)) ```
output
1
48,420
4
96,841
Provide tags and a correct Python 3 solution for this coding contest problem. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive. Calculate the number of minutes they will be able to spend together. Input The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Print one integer — the number of minutes Sonya and Filya will be able to spend together. Examples Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 Note In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
instruction
0
48,421
4
96,842
Tags: implementation, math Correct Solution: ``` i = input().split() start = max(int(i[0]), int(i[2])) end = min(int(i[1]), int(i[3])) res = end - start + 1 if start <= int(i[4]) <= end: res -= 1 if res < 0: res = 0 print(res) ```
output
1
48,421
4
96,843
Provide tags and a correct Python 3 solution for this coding contest problem. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive. Calculate the number of minutes they will be able to spend together. Input The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Print one integer — the number of minutes Sonya and Filya will be able to spend together. Examples Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 Note In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
instruction
0
48,422
4
96,844
Tags: implementation, math Correct Solution: ``` #aditya76 import math l1,r1,l2,r2,k=map(int,input().split()) nach=max(l1,l2) kon=min(r1,r2) if nach>kon: print(0) elif nach<=k<=kon: print(kon-nach) else: print(kon-nach+1) ```
output
1
48,422
4
96,845
Provide tags and a correct Python 3 solution for this coding contest problem. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive. Calculate the number of minutes they will be able to spend together. Input The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Print one integer — the number of minutes Sonya and Filya will be able to spend together. Examples Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 Note In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
instruction
0
48,423
4
96,846
Tags: implementation, math Correct Solution: ``` l1, r1, l2, r2, k = map(int,input().split()) maxd = 0 if l1 <= l2 <= r2 <= r1 or l2 <= l1 <= r1 <= r2: if r2 <= r1: if l2 <= k <= r2: maxd = r2 - l2 else: maxd = r2 - l2 + 1 else: if l1<=k<=r1: maxd = r1 - l1 else: maxd = r1 - l1 + 1 print(maxd) elif l1 <= l2 <= r1 <= r2 or l2 <= l1 <= r2 <= r1: if r1 <= r2: if l2<=k<=r1: maxd = r1 - l2 else: maxd = r1 - l2 + 1 else: if l1<=k<=r2: maxd = r2 - l1 else: maxd = r2 - l1 + 1 print(maxd) else: print(maxd) ```
output
1
48,423
4
96,847
Provide tags and a correct Python 3 solution for this coding contest problem. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive. Calculate the number of minutes they will be able to spend together. Input The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Print one integer — the number of minutes Sonya and Filya will be able to spend together. Examples Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 Note In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
instruction
0
48,424
4
96,848
Tags: implementation, math Correct Solution: ``` l1,r1,l2,r2,k=(int(z) for z in input().split()) L=max(l1,l2) R=min(r1,r2) ans=0 if L<=k<=R: ans-=1 print(max(ans+R-L+1,0)) ```
output
1
48,424
4
96,849
Provide tags and a correct Python 3 solution for this coding contest problem. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive. Calculate the number of minutes they will be able to spend together. Input The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Print one integer — the number of minutes Sonya and Filya will be able to spend together. Examples Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 Note In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
instruction
0
48,425
4
96,850
Tags: implementation, math Correct Solution: ``` l1, r1, l2, r2, k = map(int, input().split()) l = max(l1, l2) r = min(r1, r2) ans = max(r - l + 1, 0) if k >= l and k <= r: ans -= 1 print(ans) ```
output
1
48,425
4
96,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive. Calculate the number of minutes they will be able to spend together. Input The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Print one integer — the number of minutes Sonya and Filya will be able to spend together. Examples Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 Note In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. Submitted Solution: ``` l1, r1, l2, r2, k = [int(num) for num in input().split()] range = [max([l1, l2]), min(r1, r2)] numMinutes = range[1] - range[0] + 1 if k >= range[0] and k <= range[1]: numMinutes -= 1 if numMinutes > 0: print(numMinutes) else: print(0) ```
instruction
0
48,426
4
96,852
Yes
output
1
48,426
4
96,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive. Calculate the number of minutes they will be able to spend together. Input The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Print one integer — the number of minutes Sonya and Filya will be able to spend together. Examples Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 Note In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. Submitted Solution: ``` l1,r1,l2,r2,k = (int(i) for i in input().split()) l = max(l1,l2) r = min(r1,r2) if r < l: print(0) else: ans = r-l if k >= l and k <= r: print(ans) else: print(ans+1) ```
instruction
0
48,427
4
96,854
Yes
output
1
48,427
4
96,855
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive. Calculate the number of minutes they will be able to spend together. Input The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Print one integer — the number of minutes Sonya and Filya will be able to spend together. Examples Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 Note In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. Submitted Solution: ``` l1, r1, l2, r2, k = map(int, input().split()) begin, end = max(l1, l2), min(r1, r2) print(max(end - begin + (begin > k or k > end), 0)) ```
instruction
0
48,428
4
96,856
Yes
output
1
48,428
4
96,857
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive. Calculate the number of minutes they will be able to spend together. Input The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Print one integer — the number of minutes Sonya and Filya will be able to spend together. Examples Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 Note In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. Submitted Solution: ``` a,b,c,d,k = map(int,input().split()) mx = max(a,c) mn = min(b,d) ans = mn - mx + 1 if mx<=k<=mn: ans-=1 print(max(ans,0)) ```
instruction
0
48,429
4
96,858
Yes
output
1
48,429
4
96,859
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive. Calculate the number of minutes they will be able to spend together. Input The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Print one integer — the number of minutes Sonya and Filya will be able to spend together. Examples Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 Note In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. Submitted Solution: ``` l1, r1, l2, r2, k = list(map(int,input().split())) s1 = max(l1, l2) s2 = min(r1, r2) ans = (s2 - s1) + 1 if s1 < k < s2: ans -= 1 print(ans) ```
instruction
0
48,430
4
96,860
No
output
1
48,430
4
96,861
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive. Calculate the number of minutes they will be able to spend together. Input The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Print one integer — the number of minutes Sonya and Filya will be able to spend together. Examples Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 Note In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. Submitted Solution: ``` l1,r1,l2,r2,k=map(int,input().split()) if l1<=l2: if r1>=l2: if l2<=k<=r1: print(-l2+r1) else: print(-l2+r1+1) else: print(0) else: if r2>=l1: if l1<=k<=r2: print(-l1+r2) else: print(-l1+r2+1) else: print(0) ```
instruction
0
48,431
4
96,862
No
output
1
48,431
4
96,863
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive. Calculate the number of minutes they will be able to spend together. Input The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Print one integer — the number of minutes Sonya and Filya will be able to spend together. Examples Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 Note In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. Submitted Solution: ``` l1,r1,l2,r2,k=map(int,input().split()) s=max(l1,l2) e=min(r1,r2) re=(e-s) if k<=e and k>=s: #print("hi") print(re) else: print(re+1) ```
instruction
0
48,432
4
96,864
No
output
1
48,432
4
96,865
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive. Calculate the number of minutes they will be able to spend together. Input The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. Output Print one integer — the number of minutes Sonya and Filya will be able to spend together. Examples Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 Note In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. Submitted Solution: ``` l1, r1, l2, r2, k = list(map(int,input().split())) ans = l2 - r1 +1 if k >= r1 and k <= l2 : ans = ans -1 print(ans) ```
instruction
0
48,433
4
96,866
No
output
1
48,433
4
96,867
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n TV shows you want to watch. Suppose the whole time is split into equal parts called "minutes". The i-th of the shows is going from l_i-th to r_i-th minute, both ends inclusive. You need a TV to watch a TV show and you can't watch two TV shows which air at the same time on the same TV, so it is possible you will need multiple TVs in some minutes. For example, if segments [l_i, r_i] and [l_j, r_j] intersect, then shows i and j can't be watched simultaneously on one TV. Once you start watching a show on some TV it is not possible to "move" it to another TV (since it would be too distracting), or to watch another show on the same TV until this show ends. There is a TV Rental shop near you. It rents a TV for x rupees, and charges y (y < x) rupees for every extra minute you keep the TV. So in order to rent a TV for minutes [a; b] you will need to pay x + y ⋅ (b - a). You can assume, that taking and returning of the TV doesn't take any time and doesn't distract from watching other TV shows. Find the minimum possible cost to view all shows. Since this value could be too large, print it modulo 10^9 + 7. Input The first line contains integers n, x and y (1 ≤ n ≤ 10^5, 1 ≤ y < x ≤ 10^9) — the number of TV shows, the cost to rent a TV for the first minute and the cost to rent a TV for every subsequent minute. Each of the next n lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^9) denoting the start and the end minute of the i-th TV show. Output Print exactly one integer — the minimum cost to view all the shows taken modulo 10^9 + 7. Examples Input 5 4 3 1 2 4 10 2 4 10 11 5 9 Output 60 Input 6 3 2 8 20 6 22 4 15 20 28 17 25 20 27 Output 142 Input 2 1000000000 2 1 2 2 3 Output 999999997 Note In the first example, the optimal strategy would be to rent 3 TVs to watch: * Show [1, 2] on the first TV, * Show [4, 10] on the second TV, * Shows [2, 4], [5, 9], [10, 11] on the third TV. This way the cost for the first TV is 4 + 3 ⋅ (2 - 1) = 7, for the second is 4 + 3 ⋅ (10 - 4) = 22 and for the third is 4 + 3 ⋅ (11 - 2) = 31, which gives 60 int total. In the second example, it is optimal watch each show on a new TV. In third example, it is optimal to watch both shows on a new TV. Note that the answer is to be printed modulo 10^9 + 7. Submitted Solution: ``` from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import heappush,heappop import math from collections import * from functools import reduce,cmp_to_key,lru_cache import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # import sys # input = sys.stdin.readline M = mod = 10**9 + 7 def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))) def inv_mod(n):return pow(n, mod - 2, mod) def li():return [int(i) for i in input().rstrip().split()] def st():return str(input().rstrip())[2:-1] def val():return int(input().rstrip()) def li2():return [str(i)[2:-1] for i in input().rstrip().split()] def li3():return [int(i) for i in st()] n, x, y = li() l = [] for i in range(n):l.append(li()) l.sort() he = [] ans = 0 for i in range(n): curtime = l[i][0] if len(he): item = heappop(he) if item < curtime: heappush(he,l[i][1]) if (curtime - item) * y > x: ans += x + y * (l[i][1] - l[i][0]) else: ans += y * (l[i][1] - item) else: heappush(he,item) ans += x + y * (l[i][1] - l[i][0]) heappush(he,l[i][1]) ans = ans%mod else: ans += x + y * (l[i][1] - l[i][0]) heappush(he,l[i][1]) print(ans) ```
instruction
0
48,852
4
97,704
No
output
1
48,852
4
97,705
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n TV shows you want to watch. Suppose the whole time is split into equal parts called "minutes". The i-th of the shows is going from l_i-th to r_i-th minute, both ends inclusive. You need a TV to watch a TV show and you can't watch two TV shows which air at the same time on the same TV, so it is possible you will need multiple TVs in some minutes. For example, if segments [l_i, r_i] and [l_j, r_j] intersect, then shows i and j can't be watched simultaneously on one TV. Once you start watching a show on some TV it is not possible to "move" it to another TV (since it would be too distracting), or to watch another show on the same TV until this show ends. There is a TV Rental shop near you. It rents a TV for x rupees, and charges y (y < x) rupees for every extra minute you keep the TV. So in order to rent a TV for minutes [a; b] you will need to pay x + y ⋅ (b - a). You can assume, that taking and returning of the TV doesn't take any time and doesn't distract from watching other TV shows. Find the minimum possible cost to view all shows. Since this value could be too large, print it modulo 10^9 + 7. Input The first line contains integers n, x and y (1 ≤ n ≤ 10^5, 1 ≤ y < x ≤ 10^9) — the number of TV shows, the cost to rent a TV for the first minute and the cost to rent a TV for every subsequent minute. Each of the next n lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^9) denoting the start and the end minute of the i-th TV show. Output Print exactly one integer — the minimum cost to view all the shows taken modulo 10^9 + 7. Examples Input 5 4 3 1 2 4 10 2 4 10 11 5 9 Output 60 Input 6 3 2 8 20 6 22 4 15 20 28 17 25 20 27 Output 142 Input 2 1000000000 2 1 2 2 3 Output 999999997 Note In the first example, the optimal strategy would be to rent 3 TVs to watch: * Show [1, 2] on the first TV, * Show [4, 10] on the second TV, * Shows [2, 4], [5, 9], [10, 11] on the third TV. This way the cost for the first TV is 4 + 3 ⋅ (2 - 1) = 7, for the second is 4 + 3 ⋅ (10 - 4) = 22 and for the third is 4 + 3 ⋅ (11 - 2) = 31, which gives 60 int total. In the second example, it is optimal watch each show on a new TV. In third example, it is optimal to watch both shows on a new TV. Note that the answer is to be printed modulo 10^9 + 7. Submitted Solution: ``` import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ########################################################## #q.sort(key=lambda x:((x[1]-x[0]),-x[0])) #from collections import Counter #from fractions import Fraction #s=iter(input()) # for _ in range(int(input())): #from collections import deque # n=int(input()) # n,k=map(int,input().split()) # arr=list(map(int,input().split())) #ls=list(map(int,input().split())) #for in range(m): from bisect import bisect_right n, x, y = map(int, input().split(' ')) s=[0]*n e=[0]*n v=[0]*n c=0 for i in range(n): s[i],e[i]=map(int, input().split(' ')) c+=x+(e[i]-s[i])*y s.sort() e.sort() for i in range(n-1,-1,-1): k=bisect_right(s,e[i]) while (k < n) and (v[k]==1) and ((s[k]-e[i]) * y < x ): k+=1 if k==n: continue if (s[k]-e[i])*y<x: c+=(s[k]-e[i])*y-x v[i]=1 print(c%(10**9+7)) ```
instruction
0
48,853
4
97,706
No
output
1
48,853
4
97,707
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n TV shows you want to watch. Suppose the whole time is split into equal parts called "minutes". The i-th of the shows is going from l_i-th to r_i-th minute, both ends inclusive. You need a TV to watch a TV show and you can't watch two TV shows which air at the same time on the same TV, so it is possible you will need multiple TVs in some minutes. For example, if segments [l_i, r_i] and [l_j, r_j] intersect, then shows i and j can't be watched simultaneously on one TV. Once you start watching a show on some TV it is not possible to "move" it to another TV (since it would be too distracting), or to watch another show on the same TV until this show ends. There is a TV Rental shop near you. It rents a TV for x rupees, and charges y (y < x) rupees for every extra minute you keep the TV. So in order to rent a TV for minutes [a; b] you will need to pay x + y ⋅ (b - a). You can assume, that taking and returning of the TV doesn't take any time and doesn't distract from watching other TV shows. Find the minimum possible cost to view all shows. Since this value could be too large, print it modulo 10^9 + 7. Input The first line contains integers n, x and y (1 ≤ n ≤ 10^5, 1 ≤ y < x ≤ 10^9) — the number of TV shows, the cost to rent a TV for the first minute and the cost to rent a TV for every subsequent minute. Each of the next n lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^9) denoting the start and the end minute of the i-th TV show. Output Print exactly one integer — the minimum cost to view all the shows taken modulo 10^9 + 7. Examples Input 5 4 3 1 2 4 10 2 4 10 11 5 9 Output 60 Input 6 3 2 8 20 6 22 4 15 20 28 17 25 20 27 Output 142 Input 2 1000000000 2 1 2 2 3 Output 999999997 Note In the first example, the optimal strategy would be to rent 3 TVs to watch: * Show [1, 2] on the first TV, * Show [4, 10] on the second TV, * Shows [2, 4], [5, 9], [10, 11] on the third TV. This way the cost for the first TV is 4 + 3 ⋅ (2 - 1) = 7, for the second is 4 + 3 ⋅ (10 - 4) = 22 and for the third is 4 + 3 ⋅ (11 - 2) = 31, which gives 60 int total. In the second example, it is optimal watch each show on a new TV. In third example, it is optimal to watch both shows on a new TV. Note that the answer is to be printed modulo 10^9 + 7. Submitted Solution: ``` import sys import operator class Show: l, r = None, None tv_id = None def __init__(self, l, r): self.l = l self.r = r def __str__(self): return 'Show: {} {}'.format(self.l, self.r) class Tv: l, r = None, None def __init__(self, l, r): self.l = l self.r = r def update_r(self, new_r): self.r = new_r def update_l(self, new_l): self.l = new_l def cost(self): return x + y * (self.r - self.l) def __str__(self): return 'TV: {} {}'.format(self.l, self.r) n, x, y = [int(x) for x in sys.stdin.readline().split(' ')] shows = [] for i in range(n): shows.append([int(x) for x in sys.stdin.readline().strip().split(" ")]) ordered_shows = list(map(lambda x: Show(x[0], x[1]), sorted(shows, key=operator.itemgetter(0, 1)))) tvs = [] for show in ordered_shows: for tv_id in range(len(tvs)): tv = tvs[tv_id] if tv.l == show.r + 1: tvs[tv_id].update_l(show.l) show.tv_id = tv_id elif tv.r == show.l - 1: tvs[tv_id].update_r(show.r) show.tv_id = tv_id if show.tv_id is None: show.tv_id = len(tvs) tvs.append(Tv(show.l, show.r)) total = 0 for tv in tvs: total += tv.cost() if total > 10**9+7: total %= 10**9+7 print(total) ```
instruction
0
48,854
4
97,708
No
output
1
48,854
4
97,709
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n TV shows you want to watch. Suppose the whole time is split into equal parts called "minutes". The i-th of the shows is going from l_i-th to r_i-th minute, both ends inclusive. You need a TV to watch a TV show and you can't watch two TV shows which air at the same time on the same TV, so it is possible you will need multiple TVs in some minutes. For example, if segments [l_i, r_i] and [l_j, r_j] intersect, then shows i and j can't be watched simultaneously on one TV. Once you start watching a show on some TV it is not possible to "move" it to another TV (since it would be too distracting), or to watch another show on the same TV until this show ends. There is a TV Rental shop near you. It rents a TV for x rupees, and charges y (y < x) rupees for every extra minute you keep the TV. So in order to rent a TV for minutes [a; b] you will need to pay x + y ⋅ (b - a). You can assume, that taking and returning of the TV doesn't take any time and doesn't distract from watching other TV shows. Find the minimum possible cost to view all shows. Since this value could be too large, print it modulo 10^9 + 7. Input The first line contains integers n, x and y (1 ≤ n ≤ 10^5, 1 ≤ y < x ≤ 10^9) — the number of TV shows, the cost to rent a TV for the first minute and the cost to rent a TV for every subsequent minute. Each of the next n lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^9) denoting the start and the end minute of the i-th TV show. Output Print exactly one integer — the minimum cost to view all the shows taken modulo 10^9 + 7. Examples Input 5 4 3 1 2 4 10 2 4 10 11 5 9 Output 60 Input 6 3 2 8 20 6 22 4 15 20 28 17 25 20 27 Output 142 Input 2 1000000000 2 1 2 2 3 Output 999999997 Note In the first example, the optimal strategy would be to rent 3 TVs to watch: * Show [1, 2] on the first TV, * Show [4, 10] on the second TV, * Shows [2, 4], [5, 9], [10, 11] on the third TV. This way the cost for the first TV is 4 + 3 ⋅ (2 - 1) = 7, for the second is 4 + 3 ⋅ (10 - 4) = 22 and for the third is 4 + 3 ⋅ (11 - 2) = 31, which gives 60 int total. In the second example, it is optimal watch each show on a new TV. In third example, it is optimal to watch both shows on a new TV. Note that the answer is to be printed modulo 10^9 + 7. Submitted Solution: ``` import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ########################################################## #q.sort(key=lambda x:((x[1]-x[0]),-x[0])) #from collections import Counter #from fractions import Fraction #s=iter(input()) # for _ in range(int(input())): #from collections import deque # n=int(input()) # n,k=map(int,input().split()) # arr=list(map(int,input().split())) #ls=list(map(int,input().split())) #for in range(m): from bisect import bisect_right n, x, y = map(int, input().split(' ')) s=[0]*n e=[0]*n c=0 for i in range(n): s[i],e[i]=map(int, input().split(' ')) c+=x+(e[i]-s[i])*y s.sort() e.sort() for i in range(n): k=bisect_right(s,e[i]) if k==n: break if (s[k]-e[i])*y<x: c+=(s[k]-e[i])*y-x print(c%(10**9+7)) ```
instruction
0
48,855
4
97,710
No
output
1
48,855
4
97,711
Provide tags and a correct Python 3 solution for this coding contest problem. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times.
instruction
0
48,985
4
97,970
Tags: binary search, brute force, greedy, implementation, two pointers Correct Solution: ``` """T=int(input()) for _ in range(0,T): n=int(input()) a,b=map(int,input().split()) s=input() s=[int(x) for x in input().split()] for i in range(0,len(s)): a,b=map(int,input().split())""" """n,x=map(int,input().split()) s=[int(x) for x in input().split()] s=s+s con=[] pre=[0] ct=[0] for i in range(0,len(s)): tt=(s[i]*(s[i]+1))//2 con.append(tt) for i in range(0,len(con)): pre.append(pre[i]+con[i]) ct.append(ct[i]+s[i]) pre=pre+[pre[-1]+10000] print(s) print('con',con) print(pre) print(ct) ans=x for i in range(0,len(pre)-1): trg=pre[i]+x low=i+1 high=len(pre)-1 temp=i+1 while(low<=high): mid=(low+high)>>1 if(pre[mid]<=trg): low=mid+1 else: temp=mid high=mid-1 print('kbckjdc',i,pre[i],temp) c=(pre[temp-1]-pre[i]) dd=ct[temp-1]-ct[i] print('cccccc',c) diff=x-dd print('difffffff',diff) if(diff>0): if(temp-1==i): ele1=s[i%n] c+=((ele1*(ele1+1))//2) h=ele1-diff c-=((h*(h+1))//2) else: ele1=s[i%n] ele2=s[(temp-1)%n] print(ele1,ele2) h=min(ele1-1,ele2-diff) c-=((h*(h+1))//2) h2=diff+h c+=((h2*(h2+1))//2) c-=((diff*(diff+1))//2) ans=max(ans,c) print(ans)""" """T=int(input()) for _ in range(0,T): n=int(input()) a,b=map(int,input().split()) s=input() s=[int(x) for x in input().split()] for i in range(0,len(s)): a,b=map(int,input().split())""" n,x=map(int,input().split()) s=[int(x) for x in input().split()] s=s+s con=[] pre=[0] ct=[0] for i in range(0,len(s)): tt=(s[i]*(s[i]+1))//2 con.append(tt) for i in range(0,len(con)): pre.append(pre[i]+con[i]) ct.append(ct[i]+s[i]) pre=pre+[pre[-1]+10000] ct=ct+[ct[-1]+10000] #print(s) #print('con',con) #print(pre) #print(ct) ans=x for i in range(0,len(ct)-1): trg=ct[i]+x low=i+1 high=len(ct)-1 temp=i+1 while(low<=high): mid=(low+high)>>1 if(ct[mid]<=trg): low=mid+1 else: temp=mid high=mid-1 #print('kbckjdc',i,ct[i],temp) c=(pre[temp-1]-pre[i]) dd=ct[temp-1]-ct[i] #print('cccccc',c) diff=x-dd #print('difffffff',diff) if(diff>=0): if(temp-1==i): ele1=s[i%n] c+=((ele1*(ele1+1))//2) h=ele1-diff c-=((h*(h+1))//2) else: ele1=s[i%n] ele2=s[(temp-1)%n] #print(ele1,ele2) h=min(ele1-1,ele2-diff) c-=((h*(h+1))//2) h2=diff+h c+=((h2*(h2+1))//2) #c-=((diff*(diff+1))//2) ans=max(ans,c) print(ans) ```
output
1
48,985
4
97,971
Provide tags and a correct Python 3 solution for this coding contest problem. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times.
instruction
0
48,986
4
97,972
Tags: binary search, brute force, greedy, implementation, two pointers Correct Solution: ``` n,x=map(int,input().split()) d=list(map(int,input().split()))*3 d.reverse e=[i*(i+1)//2 for i in d] def f(a,b): c=a-b return (a*(a+1))//2 - (c*(c+1))//2 ss=0 ee=0 whole=d[ee] tsol=e[ee] while(True): ee+=1 if whole+d[ee]>x: ee-=1 break whole+=d[ee] tsol+=e[ee] tend=f(d[ee+1],x-whole) tsol+=tend sol=tsol while(ss<n): whole-=d[ss] tsol-=e[ss]+tend ss+=1 while(True): ee+=1 if whole+d[ee]>x: ee-=1 break whole+=d[ee] tsol+=e[ee] tend=f(d[ee+1],x-whole) tsol+=tend sol=max(tsol,sol) print(sol) ```
output
1
48,986
4
97,973
Provide tags and a correct Python 3 solution for this coding contest problem. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times.
instruction
0
48,987
4
97,974
Tags: binary search, brute force, greedy, implementation, two pointers Correct Solution: ``` n, x = tuple(map(int, input().split())) arr = list(map(int, input().split())) arr += arr[::] arr2 = [i * (i + 1) // 2 for i in arr] ans = 0 for now_month in range(n, n * 2): if now_month == n: last_month = now_month count_obnim = 0 count_days = 0 while count_days + arr[last_month] <= x: count_days += arr[last_month] count_obnim += arr2[last_month] last_month -= 1 dop_days = x - count_days nodop_days = arr[last_month] - dop_days dop_obnim = arr2[last_month] - nodop_days * (nodop_days + 1) // 2 count_days += dop_days count_obnim += dop_obnim else: count_days += arr[now_month] count_days -= dop_days count_obnim += arr2[now_month] count_obnim -= dop_obnim while count_days > x: count_days -= arr[last_month + 1] count_obnim -= arr2[last_month + 1] last_month += 1 dop_days = x - count_days nodop_days = arr[last_month] - dop_days dop_obnim = arr2[last_month] - nodop_days * (nodop_days + 1) // 2 count_days += dop_days count_obnim += dop_obnim ans = max(ans, count_obnim) print(ans) ```
output
1
48,987
4
97,975
Provide tags and a correct Python 3 solution for this coding contest problem. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times.
instruction
0
48,988
4
97,976
Tags: binary search, brute force, greedy, implementation, two pointers Correct Solution: ``` n,x=map(int,input().split()) l=list(map(int,input().split())) l*=2 num=0 ans=0 val=0 j=0 for i in range(n): while num<x: num+=l[j] val+=(l[j]*(l[j]+1)//2) j+=1 if j==n: j=0 ans=max(ans,val-(num-x)*(num-x+1)//2) num-=l[i] val-=l[i]*(l[i]+1)//2 print(ans) ```
output
1
48,988
4
97,977
Provide tags and a correct Python 3 solution for this coding contest problem. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times.
instruction
0
48,989
4
97,978
Tags: binary search, brute force, greedy, implementation, two pointers Correct Solution: ``` # from functools import lru_cache from sys import stdin, stdout import sys from math import * # sys.setrecursionlimit(10**6) input = stdin.readline # print = stdout.write # @lru_cache() n,m=map(int,input().split()) ar=list(map(int,input().split())) ar=ar+ar d=[0] h=[0] for i in range(2*n): d.append(d[-1]+ar[i]) h.append(h[-1]+(ar[i]*(ar[i]+1))//2) # print(d) # print(h) ans=0 for i in range(1,2*n+1): if(d[i]>=m): req=d[i]-m l=0 r=i+1 ind=0 while(l<=r): mid=(l+r)//2 if(d[mid]<req): l=mid+1 else: ind=mid r=mid-1 if(ind==0 or d[i]-d[ind]==m): ans=max(ans,h[i]-h[ind]) # print(ind,i) else: rslt=h[i]-h[ind] req = m-(d[i]-d[ind]) temp = (ar[ind-1]*(ar[ind-1]+1))//2-((ar[ind-1]-req)*(ar[ind-1]-req+1))//2 ans=max(ans,rslt+temp) print(ans) ```
output
1
48,989
4
97,979
Provide tags and a correct Python 3 solution for this coding contest problem. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times.
instruction
0
48,990
4
97,980
Tags: binary search, brute force, greedy, implementation, two pointers Correct Solution: ``` import bisect n,days=map(int, input().strip().split()) arr=list(map(int, input().strip().split())); arr=arr+arr; pre1=[0]; pre2=[0]; res=0; for i in range(2*n): pre1.append(pre1[-1]+arr[i]); pre2.append(pre2[-1]+(arr[i]*(arr[i]+1))//2); for i in range(2*n,n,-1): l=1 r=i ans=i while(l<=r): mid=l+(r-l)//2 if(pre1[i]-pre1[mid]<days): ans=mid r=mid-1 else: l=mid+1 tot=pre1[i]-pre1[ans-1]-days temp=(pre2[i]-pre2[ans-1])-((tot)*(tot+1)//2) res=max(res,temp) print(res) ```
output
1
48,990
4
97,981
Provide tags and a correct Python 3 solution for this coding contest problem. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times.
instruction
0
48,991
4
97,982
Tags: binary search, brute force, greedy, implementation, two pointers Correct Solution: ``` n,x = map(int,input().split()) arr = list(map(int,input().split())) arr += arr prefix = [] prefix1 = [] Sum = 0 for i in arr: Sum += i prefix.append(Sum) Sum = 0 for j in arr: Sum += (j*(j+1))//2 prefix1.append(Sum) ans = 0 for i in range(n*2): A = prefix[i]-x if (A<=0): ans = prefix1[i] else: if (arr[i]>=x): jj = prefix1[i]-((arr[i]-x)*(arr[i]-x+1))//2 if (i-1>=0): jj -= prefix1[i-1] ans = max(ans,jj) # break else: l = 0 r = i Ans = i while(l<=r): mid = (l+r)//2 if (prefix[mid]<=A): Ans = mid l = mid+1 else: r = mid-1 # print(i,Ans) B = prefix[i]-prefix[Ans]-x ans = max(ans,prefix1[i]-prefix1[Ans]-(B*(B+1))//2) print(ans) ```
output
1
48,991
4
97,983
Provide tags and a correct Python 3 solution for this coding contest problem. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times.
instruction
0
48,992
4
97,984
Tags: binary search, brute force, greedy, implementation, two pointers Correct Solution: ``` import sys, math,os from io import BytesIO, IOBase from bisect import bisect_left as bl, bisect_right as br, insort #from heapq import heapify, heappush, heappop from collections import defaultdict as dd, deque, Counter #from itertools import permutations,combinations def data(): return sys.stdin.readline().strip() def mdata(): return list(map(int, data().split())) def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n') def out(var) : sys.stdout.write(str(var)+'\n') sys.setrecursionlimit(100000) INF = float('inf') mod = int(1e9)+7 def main(): n,x=mdata() d=mdata() cnt1=0 cnt2=0 m=0 ind=2*n-1 i=2*n-1 d+=d while i>-1: if d[i]>=x-cnt1: cnt2+=(d[i]*d[i]+d[i])//2-((d[i]-x+cnt1)*(d[i]-x+cnt1+1))//2 m=max(cnt2,m) if ind!=i: cnt2-=(d[ind]*d[ind]+d[ind])//2+(d[i]*d[i]+d[i])//2-((d[i]-x+cnt1)*(d[i]-x+cnt1+1))//2 cnt1 -= d[ind] i+=1 else: cnt2-=(d[i]*d[i]+d[i])//2-((d[i]-x+cnt1)*(d[i]-x+cnt1+1))//2 if cnt2 < 0: break ind-=1 else: cnt1 += d[i] cnt2+=(d[i]*d[i]+d[i])//2 i-=1 out(m) if __name__ == '__main__': main() ```
output
1
48,992
4
97,985
Provide tags and a correct Python 2 solution for this coding contest problem. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times.
instruction
0
48,993
4
97,986
Tags: binary search, brute force, greedy, implementation, two pointers Correct Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations raw_input = stdin.readline pr = stdout.write mod=10**9+7 def ni(): return int(raw_input()) def li(): return map(int,raw_input().split()) def pn(n): stdout.write(str(n)+'\n') def pa(arr): pr(' '.join(map(str,arr))+'\n') # fast read function for total integer input def inp(): # this function returns whole input of # space/line seperated integers # Use Ctrl+D to flush stdin. return map(int,stdin.read().split()) range = xrange # not for python 3.0+ # main code def gs(n,m): return ((n*(n+1))/2)-((m*(m+1))/2) n,x=li() l=li() l*=2 dp=[0]*(2*n+1) dp1=[0]*(2*n+1) for i in range(1,2*n+1): dp[i]=dp[i-1]+l[i-1] dp1[i]=dp1[i-1]+((l[i-1]*(l[i-1]+1))/2) l1,r1=1,n ans=0 while l1<=n: l2=l1 r2=r1 while l2<=r2: #print l1,r1,l2,r2 mid=(l2+r2)/2 if dp[r1]-dp[mid-1]<=x: ans=max(ans,dp1[r1]-dp1[mid-1]) r2=mid-1 else: if dp[r1]-dp[mid]<=x: temp=x-(dp[r1]-dp[mid]) #print temp,l[mid-1],l[mid-1]-temp ans=max(ans,dp1[r1]-dp1[mid]+gs(l[mid-1],l[mid-1]-temp)) #r2=mid-1 break else: l2=mid+1 l1+=1 r1+=1 pn(ans) ```
output
1
48,993
4
97,987
Provide tags and a correct Python 2 solution for this coding contest problem. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times.
instruction
0
48,994
4
97,988
Tags: binary search, brute force, greedy, implementation, two pointers Correct Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations raw_input = stdin.readline pr = stdout.write mod=10**9+7 def ni(): return int(raw_input()) def li(): return map(int,raw_input().split()) def pn(n): stdout.write(str(n)+'\n') def pa(arr): pr(' '.join(map(str,arr))+'\n') # fast read function for total integer input def inp(): # this function returns whole input of # space/line seperated integers # Use Ctrl+D to flush stdin. return map(int,stdin.read().split()) range = xrange # not for python 3.0+ # main code def gs(n,m): return ((n*(n+1))/2)-((m*(m+1))/2) n,x=li() l=li() l*=2 dp=[0]*(2*n+1) dp1=[0]*(2*n+1) for i in range(1,2*n+1): dp[i]=dp[i-1]+l[i-1] dp1[i]=dp1[i-1]+((l[i-1]*(l[i-1]+1))/2) l1,r1=1,n ans=0 while l1<=n: l2=l1 r2=r1 while l2<=r2: #print l1,r1,l2,r2 mid=(l2+r2)/2 if dp[r1]-dp[mid-1]<=x: ans=max(ans,dp1[r1]-dp1[mid-1]) r2=mid-1 else: if dp[r1]-dp[mid]<=x: temp=x-(dp[r1]-dp[mid]) #print temp,l[mid-1],l[mid-1]-temp ans=max(ans,dp1[r1]-dp1[mid]+gs(l[mid-1],l[mid-1]-temp)) r2=mid-1 #break else: l2=mid+1 l1+=1 r1+=1 pn(ans) ```
output
1
48,994
4
97,989
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times. Submitted Solution: ``` from bisect import * from collections import * from math import gcd,ceil,sqrt,floor,inf from heapq import * from itertools import * from operator import add,mul,sub,xor,truediv,floordiv from functools import * #------------------------------------------------------------------------ import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #------------------------------------------------------------------------ def RL(): return map(int, sys.stdin.readline().rstrip().split()) def RLL(): return list(map(int, sys.stdin.readline().rstrip().split())) def N(): return int(input()) #------------------------------------------------------------------------ from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc farr=[1] ifa=[] def fact(x,mod=0): if mod: while x>=len(farr): farr.append(farr[-1]*len(farr)%mod) else: while x>=len(farr): farr.append(farr[-1]*len(farr)) return farr[x] def ifact(x,mod): global ifa ifa.append(pow(farr[-1],mod-2,mod)) for i in range(x,0,-1): ifa.append(ifa[-1]*i%mod) ifa=ifa[::-1] def per(i,j,mod=0): if i<j: return 0 if not mod: return fact(i)//fact(i-j) return farr[i]*ifa[i-j]%mod def com(i,j,mod=0): if i<j: return 0 if not mod: return per(i,j)//fact(j) return per(i,j,mod)*ifa[j]%mod def catalan(n): return com(2*n,n)//(n+1) def isprime(n): for i in range(2,int(n**0.5)+1): if n%i==0: return False return True def lowbit(n): return n&-n def inverse(a,m): a%=m if a<=1: return a return ((1-inverse(m,a)*m)//a)%m class BIT: def __init__(self,arr): self.arr=arr self.n=len(arr)-1 def update(self,x,v): while x<=self.n: self.arr[x]+=v x+=x&-x def query(self,x): ans=0 while x: ans+=self.arr[x] x&=x-1 return ans ''' class SMT: def __init__(self,arr): self.n=len(arr)-1 self.arr=[0]*(self.n<<2) self.lazy=[0]*(self.n<<2) def Build(l,r,rt): if l==r: self.arr[rt]=arr[l] return m=(l+r)>>1 Build(l,m,rt<<1) Build(m+1,r,rt<<1|1) self.pushup(rt) Build(1,self.n,1) def pushup(self,rt): self.arr[rt]=self.arr[rt<<1]+self.arr[rt<<1|1] def pushdown(self,rt,ln,rn):#lr,rn表区间数字数 if self.lazy[rt]: self.lazy[rt<<1]+=self.lazy[rt] self.lazy[rt<<1|1]+=self.lazy[rt] self.arr[rt<<1]+=self.lazy[rt]*ln self.arr[rt<<1|1]+=self.lazy[rt]*rn self.lazy[rt]=0 def update(self,L,R,c,l=1,r=None,rt=1):#L,R表示操作区间 if r==None: r=self.n if L<=l and r<=R: self.arr[rt]+=c*(r-l+1) self.lazy[rt]+=c return m=(l+r)>>1 self.pushdown(rt,m-l+1,r-m) if L<=m: self.update(L,R,c,l,m,rt<<1) if R>m: self.update(L,R,c,m+1,r,rt<<1|1) self.pushup(rt) def query(self,L,R,l=1,r=None,rt=1): if r==None: r=self.n #print(L,R,l,r,rt) if L<=l and R>=r: return self.arr[rt] m=(l+r)>>1 self.pushdown(rt,m-l+1,r-m) ans=0 if L<=m: ans+=self.query(L,R,l,m,rt<<1) if R>m: ans+=self.query(L,R,m+1,r,rt<<1|1) return ans ''' class DSU:#容量+路径压缩 def __init__(self,n): self.c=[-1]*n def same(self,x,y): return self.find(x)==self.find(y) def find(self,x): if self.c[x]<0: return x self.c[x]=self.find(self.c[x]) return self.c[x] def union(self,u,v): u,v=self.find(u),self.find(v) if u==v: return False if self.c[u]<self.c[v]: u,v=v,u self.c[u]+=self.c[v] self.c[v]=u return True def size(self,x): return -self.c[self.find(x)] class UFS:#秩+路径 def __init__(self,n): self.parent=[i for i in range(n)] self.ranks=[0]*n def find(self,x): if x!=self.parent[x]: self.parent[x]=self.find(self.parent[x]) return self.parent[x] def union(self,u,v): pu,pv=self.find(u),self.find(v) if pu==pv: return False if self.ranks[pu]>=self.ranks[pv]: self.parent[pv]=pu if self.ranks[pv]==self.ranks[pu]: self.ranks[pu]+=1 else: self.parent[pu]=pv def Prime(n): c=0 prime=[] flag=[0]*(n+1) for i in range(2,n+1): if not flag[i]: prime.append(i) c+=1 for j in range(c): if i*prime[j]>n: break flag[i*prime[j]]=prime[j] if i%prime[j]==0: break #print(flag) return flag def dij(s,graph): d={} d[s]=0 heap=[(0,s)] seen=set() while heap: dis,u=heappop(heap) if u in seen: continue for v in graph[u]: if v not in d or d[v]>d[u]+graph[u][v]: d[v]=d[u]+graph[u][v] heappush(heap,(d[v],v)) return d def GP(it): return [[ch,len(list(g))] for ch,g in groupby(it)] class DLN: def __init__(self,val): self.val=val self.pre=None self.next=None def nb(i,j): for ni,nj in [[i+1,j],[i-1,j],[i,j-1],[i,j+1]]: if 0<=ni<n and 0<=nj<m: yield ni,nj @bootstrap def gdfs(r,p): if len(g[r])==1 and p!=-1: yield None for ch in g[r]: if ch!=p: yield gdfs(ch,r) yield None t=1 for i in range(t): n,x=RL() d=RLL() d=d+d pred=[0] preh=[0] for i in range(2*n): pred.append(d[i]+pred[-1]) preh.append(d[i]*(d[i]+1)//2+preh[-1]) ans=0 for i in range(2*n): if pred[i+1]>=x: l=0 r=i while l<r: mid=(l+r+1)//2 if pred[i+1]-pred[mid]>=x: l=mid else: r=mid-1 tmp=preh[i+1]-preh[l] mis=pred[i+1]-pred[l]-x tmp-=mis*(mis+1)//2 ans=max(ans,tmp) print(ans) ''' sys.setrecursionlimit(200000) import threading threading.stack_size(10**8) t=threading.Thread(target=main) t.start() t.join() ''' ''' sys.setrecursionlimit(200000) import threading threading.stack_size(10**8) t=threading.Thread(target=main) t.start() t.join() ''' ```
instruction
0
48,995
4
97,990
Yes
output
1
48,995
4
97,991
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times. Submitted Solution: ``` from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import heappush,heappop import math from collections import * from functools import reduce,cmp_to_key,lru_cache from itertools import accumulate import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # import sys # input = sys.stdin.readline M = mod = 10**9 + 7 def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))) def inv_mod(n):return pow(n, mod - 2, mod) def li():return [int(i) for i in input().rstrip().split()] def st():return str(input().rstrip())[2:-1] def val():return int(input().rstrip()) def li2():return [str(i)[2:-1] for i in input().rstrip().split()] def li3():return [int(i) for i in st()] n, x = li() l = li() l = l + l startindices = [0 for i in l] i = j = ans = curr = days = 0 while j < 2*n: if days + l[j] <= x: days += l[j] curr += (l[j] * (l[j] + 1))//2 else: while l[j] + days - (l[i] - startindices[i] ) > x: left = startindices[i] days -= l[i] - left curr -= (l[i] * (l[i] + 1))//2 - (left * (left + 1))//2 i += 1 deletetill = l[j] + days - x left = startindices[i] curr -= (left + deletetill) *( left + deletetill + 1)//2 - (left * (left + 1))//2 startindices[i] += deletetill days = x curr += l[j] * (l[j] + 1)//2 ans = max(ans,curr) j += 1 print(ans) ```
instruction
0
48,996
4
97,992
Yes
output
1
48,996
4
97,993
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times. Submitted Solution: ``` n,x = map(int,input().split()) arr = list(map(int,input().split())) i=j=su=hu=an=0 su += arr[j%n] hu += su*(su+1)//2 while i != n: while su < x: j += 1 su += arr[j%n] hu += arr[j%n]*(arr[j%n]+1)//2 if arr[i]>su-x: hu1 = hu y = su-x hu1 -= y*(y+1)//2 an = max(hu1,an) su -= arr[i] hu -= arr[i]*(arr[i]+1)//2 i += 1 print(an) ```
instruction
0
48,997
4
97,994
Yes
output
1
48,997
4
97,995
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times. Submitted Solution: ``` from sys import stdin, gettrace if not gettrace(): def input(): return next(stdin)[:-1] # def input(): # return stdin.buffer.readline() def main(): n,x = map(int, input().split()) dd = [int(a) for a in input().split()] ddh = [] ddd = [0] for i in range(n): ddh.append((dd[i]*(dd[i]+1))//2) for i in range(2*n): ddd.append(dd[i%n]+ddd[-1]) best = 0 hugs = 0 l = 1 r = 1 while ddd[r] < x: hugs += ddh[(r-1)%n] r += 1 while r < n*2: hugs += ddh[(r-1)%n] firstday = ddd[r] - x while firstday >= ddd[l]: hugs -= ddh[(l-1)%n] l += 1 lostdays = dd[(l-1)%n] - (ddd[l] - firstday) h = hugs - (lostdays*(lostdays+1))//2 best = max(best, h) r+=1 print(best) if __name__ == "__main__": main() ```
instruction
0
48,998
4
97,996
Yes
output
1
48,998
4
97,997
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times. Submitted Solution: ``` import sys def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def MI(): return map(int, sys.stdin.readline().split()) def SI(): return sys.stdin.readline().strip() n,x = MI() d = LI() l = [0] for i in range(1,10**6+1): l.append(l[-1]+i) m = max(d) if x<=m: print(l[m]-l[m-x]) else: count = l[m] x-=m tt = [] for i in range(n): if d[i] == m: tt.append(i) ans = 0 for i in (tt): cl = count cr = count le = i-1 r = (i+1)%n while(x>d[le]): cl+=l[d[le]] x-=d[le] le-=1 if le<0: le+=n cl+=l[d[le]]-l[d[le]-x] while(x>d[r]): cl+=l[d[r]] x-=d[r] r+=1 if r>=n: r-=n cr+=l[x] ans = max(cl,cr) print(ans) ```
instruction
0
48,999
4
97,998
No
output
1
48,999
4
97,999
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times. Submitted Solution: ``` n, x=map(int, input().split()) d=list(map(int, input().split())) td=d+d s=[0]*len(td) s[0]=int((d[0]+1)*d[0]/2) for i in range(1, len(td)): s[i]=int((td[i]+1)*td[i]/2) td[i]+=td[i-1] res=0 key=0 val=0 for i in range(1, len(td)): val+=s[i] while td[i]-td[key+1]>=x: val-=s[key+1] key+=1 cnt=td[i]-td[key]-x if cnt<0: cnt=0 res=max(res, int(val-cnt*(cnt+1)/2)) #print("%s %s %s --- %s" %(val, key, cnt, res)) print(res) ```
instruction
0
49,000
4
98,000
No
output
1
49,000
4
98,001
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times. Submitted Solution: ``` import os import sys if os.path.exists('/mnt/c/Users/Square/square/codeforces'): f = iter(open('D.txt').readlines()) def input(): return next(f) # input = lambda: sys.stdin.readline().strip() else: input = lambda: sys.stdin.readline().strip() fprint = lambda *args: print(*args, flush=True) n, x = map(int, input().split()) A = list(map(int, input().split())) A = A + A def f(x): return (x*(x+1))//2 S = [A[0]] H = [f(A[0])] for i in A[1:]: S.append(S[-1] + i) H.append(H[-1] + f(i)) n = len(A) res1 = 0 pos2 = 0 for pos1, a in enumerate(A[:-1]): while pos2 < n and S[pos2] - S[pos1] < x - 1: pos2 += 1 I = S[pos2-1] - S[pos1] t = x - 1 - I if pos2 >= n or t > S[pos2]: break dH = H[pos2-1]-H[pos1] # print('pos1 =', pos1, 'pos2 =', pos2, 't =', t, 'I =', I, 'dH =', dH, 'res =', a + dH + f(t)) res1 = max(a + dH + f(t), res1) # print(S) res2 = 0 pos1 = 0 for pos2, a in list(enumerate(A)): while S[pos2] - S[pos1] > x: pos1 += 1 I = S[pos2] - S[pos1] t = x - I dH = H[pos2]-H[pos1] # print('pos1 =', pos1, 'pos2 =', pos2, 't =', t, 'A[pos1] =', A[pos1], 'I =', I, 'dH =', dH, 'res =', dH + f(A[pos1]) - f(A[pos1] - t)) if t > A[pos1]: continue res2 = max(dH + f(A[pos1]) - f(A[pos1] - t), res2) res = max(res1, res2) print(res) ```
instruction
0
49,001
4
98,002
No
output
1
49,001
4
98,003
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly x days and that's the exact number of days you will spend visiting your friend. You will spend exactly x consecutive (successive) days visiting Coronavirus-chan. They use a very unusual calendar in Naha: there are n months in a year, i-th month lasts exactly d_i days. Days in the i-th month are numbered from 1 to d_i. There are no leap years in Naha. The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get j hugs if you visit Coronavirus-chan on the j-th day of the month. You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). Please note that your trip should not necessarily begin and end in the same year. Input The first line of input contains two integers n and x (1 ≤ n ≤ 2 ⋅ 10^5) — the number of months in the year and the number of days you can spend with your friend. The second line contains n integers d_1, d_2, …, d_n, d_i is the number of days in the i-th month (1 ≤ d_i ≤ 10^6). It is guaranteed that 1 ≤ x ≤ d_1 + d_2 + … + d_n. Output Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life. Examples Input 3 2 1 3 1 Output 5 Input 3 6 3 3 3 Output 12 Input 5 6 4 2 3 1 3 Output 15 Note In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) \{1,1,2,3,1\}. Coronavirus-chan will hug you the most if you come on the third day of the year: 2+3=5 hugs. In the second test case, the numbers of the days are \{1,2,3,1,2,3,1,2,3\}. You will get the most hugs if you arrive on the third day of the year: 3+1+2+3+1+2=12 hugs. In the third test case, the numbers of the days are \{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you 2+3+1+2+3+4=15 times. Submitted Solution: ``` n,x = map(int, input().split()) a= list(map(int, input().split())) ar = [i for j in a for i in range(1,j+1) ] #print(ar) ans=-1 if len(ar)-x == 0: print(sum(ar)) exit() for i in range(0,len(ar)-x): s=0 s = sum(ar[i:i+x]) if s>=ans: ans = s k = ar[len(ar)-x+1:] + ar[:x-1] for i in range(0,len(k)-x): s=0 s = sum(k[i:i+x]) if s>=ans: ans = s print(ans) ```
instruction
0
49,002
4
98,004
No
output
1
49,002
4
98,005
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation! Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all. Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived. According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left. Input The only line contains three integers b, d and s (0 ≤ b, d, s ≤ 1018, b + d + s ≥ 1) — the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium. Output Print single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation. Examples Input 3 2 1 Output 1 Input 1 0 0 Output 0 Input 1 1 1 Output 0 Input 1000000000000000000 0 1000000000000000000 Output 999999999999999999 Note In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day. In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal. In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.
instruction
0
49,318
4
98,636
Tags: binary search, constructive algorithms, greedy, implementation, math Correct Solution: ``` b, d, s = map(int, input().split()) days = max(b, d, s) print(max(0, max(days - b - 1, 0)+ max(days - d - 1, 0)+ max(days - s - 1, 0))) ```
output
1
49,318
4
98,637
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation! Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all. Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived. According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left. Input The only line contains three integers b, d and s (0 ≤ b, d, s ≤ 1018, b + d + s ≥ 1) — the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium. Output Print single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation. Examples Input 3 2 1 Output 1 Input 1 0 0 Output 0 Input 1 1 1 Output 0 Input 1000000000000000000 0 1000000000000000000 Output 999999999999999999 Note In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day. In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal. In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.
instruction
0
49,319
4
98,638
Tags: binary search, constructive algorithms, greedy, implementation, math Correct Solution: ``` b, d, s = map(int, input().split()) def avg(x, y, z): A = [x, y, z] A.sort() return A[1] print(max(max(b, d, s) - min(b, d, s) - 1, 0) + max(max(b, d, s) - avg(b, d, s) - 1, 0)) ```
output
1
49,319
4
98,639
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation! Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all. Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived. According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left. Input The only line contains three integers b, d and s (0 ≤ b, d, s ≤ 1018, b + d + s ≥ 1) — the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium. Output Print single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation. Examples Input 3 2 1 Output 1 Input 1 0 0 Output 0 Input 1 1 1 Output 0 Input 1000000000000000000 0 1000000000000000000 Output 999999999999999999 Note In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day. In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal. In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.
instruction
0
49,320
4
98,640
Tags: binary search, constructive algorithms, greedy, implementation, math Correct Solution: ``` from sys import stdin b, d, s = map(int, stdin.readline().split()) def calculate(last_meal, b, d, s): if last_meal == 'b': if b > d and b > s: return (b - d - 1) + (b - s - 1) else: new_b = max(d, s) + 1 return (new_b - d - 1) + (new_b - s - 1) + new_b - b elif last_meal == 'd': days = max(b, d, s + 1) return days - b + days - d + days - 1 - s else: days = max(b, d, s) return days - b + days - d + days - s print(min(calculate(l, *days) for l in ('b', 'd', 's') for days in ((b, d, s), (d, s, b), (s, b, d)))) ```
output
1
49,320
4
98,641
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation! Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all. Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived. According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left. Input The only line contains three integers b, d and s (0 ≤ b, d, s ≤ 1018, b + d + s ≥ 1) — the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium. Output Print single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation. Examples Input 3 2 1 Output 1 Input 1 0 0 Output 0 Input 1 1 1 Output 0 Input 1000000000000000000 0 1000000000000000000 Output 999999999999999999 Note In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day. In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal. In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.
instruction
0
49,321
4
98,642
Tags: binary search, constructive algorithms, greedy, implementation, math Correct Solution: ``` con = list(map(int, input().split())) k = 0 con.sort() for i in range(2): if (con[2] - 1) > con[i]: k += ((con[2] - 1) - con[i]) print(k) ```
output
1
49,321
4
98,643
Provide tags and a correct Python 3 solution for this coding contest problem. Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation! Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all. Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived. According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left. Input The only line contains three integers b, d and s (0 ≤ b, d, s ≤ 1018, b + d + s ≥ 1) — the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium. Output Print single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation. Examples Input 3 2 1 Output 1 Input 1 0 0 Output 0 Input 1 1 1 Output 0 Input 1000000000000000000 0 1000000000000000000 Output 999999999999999999 Note In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day. In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal. In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.
instruction
0
49,322
4
98,644
Tags: binary search, constructive algorithms, greedy, implementation, math Correct Solution: ``` t = list(map(int,input().split())) a= max(t) b= min(t) if a-b<=1: print(0) else: t.sort() ans=(a-b-1) if t[1]+1<t[-1]: ans+= t[-1]-t[1]-1 print(ans) ```
output
1
49,322
4
98,645