message stringlengths 2 30.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 237 109k | cluster float64 10 10 | __index_level_0__ int64 474 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
You want to make change for $ n $ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and / or 25 cents coins respectively, find the minimum number of coins you need.
Constraints
* $ 1 \ le n \ le 10 ^ 9 $
Input
$ n $
The integer $ n $ is given in a line.
output
Print the minimum number of coins you need in a line.
Examples
Input
100
Output
4
Input
54321
Output
2175 | instruction | 0 | 36,821 | 10 | 73,642 |
"Correct Solution:
```
def Main():
n = int(input())
count = 0
cents = [25, 10, 5, 1]
for c in cents:
q, mod = divmod(n, c)
count += q
n -= c*q
print(count)
Main()
``` | output | 1 | 36,821 | 10 | 73,643 |
Provide a correct Python 3 solution for this coding contest problem.
You want to make change for $ n $ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and / or 25 cents coins respectively, find the minimum number of coins you need.
Constraints
* $ 1 \ le n \ le 10 ^ 9 $
Input
$ n $
The integer $ n $ is given in a line.
output
Print the minimum number of coins you need in a line.
Examples
Input
100
Output
4
Input
54321
Output
2175 | instruction | 0 | 36,822 | 10 | 73,644 |
"Correct Solution:
```
n = int(input())
ans = 0
for x in (25, 10, 5, 1):
ans += n // x
n %= x
print(ans)
``` | output | 1 | 36,822 | 10 | 73,645 |
Provide a correct Python 3 solution for this coding contest problem.
You want to make change for $ n $ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and / or 25 cents coins respectively, find the minimum number of coins you need.
Constraints
* $ 1 \ le n \ le 10 ^ 9 $
Input
$ n $
The integer $ n $ is given in a line.
output
Print the minimum number of coins you need in a line.
Examples
Input
100
Output
4
Input
54321
Output
2175 | instruction | 0 | 36,823 | 10 | 73,646 |
"Correct Solution:
```
coins = [25,10,5,1]
n = int(input())
ans = 0
for coin in coins:
if n == 0:
break
else:
ans += int(n/coin)
n = n % coin
print(ans)
``` | output | 1 | 36,823 | 10 | 73,647 |
Provide a correct Python 3 solution for this coding contest problem.
You want to make change for $ n $ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and / or 25 cents coins respectively, find the minimum number of coins you need.
Constraints
* $ 1 \ le n \ le 10 ^ 9 $
Input
$ n $
The integer $ n $ is given in a line.
output
Print the minimum number of coins you need in a line.
Examples
Input
100
Output
4
Input
54321
Output
2175 | instruction | 0 | 36,824 | 10 | 73,648 |
"Correct Solution:
```
import sys
n = int(sys.stdin.readline())
k = 0
for c in [25, 10, 5]:
k += n // c
n %= c
print(k+n)
``` | output | 1 | 36,824 | 10 | 73,649 |
Provide a correct Python 3 solution for this coding contest problem.
You want to make change for $ n $ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and / or 25 cents coins respectively, find the minimum number of coins you need.
Constraints
* $ 1 \ le n \ le 10 ^ 9 $
Input
$ n $
The integer $ n $ is given in a line.
output
Print the minimum number of coins you need in a line.
Examples
Input
100
Output
4
Input
54321
Output
2175 | instruction | 0 | 36,825 | 10 | 73,650 |
"Correct Solution:
```
n=int(input())
cnt=n
ans=0
cnt25=divmod(cnt,25)
ans+=cnt25[0]
cnt=cnt25[1]
cnt10=divmod(cnt,10)
ans+=cnt10[0]
cnt=cnt10[1]
cnt5=divmod(cnt,5)
ans+=cnt5[0]
cnt=cnt5[1]
cnt1=divmod(cnt,1)
ans+=cnt1[0]
print(ans)
``` | output | 1 | 36,825 | 10 | 73,651 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You want to make change for $ n $ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and / or 25 cents coins respectively, find the minimum number of coins you need.
Constraints
* $ 1 \ le n \ le 10 ^ 9 $
Input
$ n $
The integer $ n $ is given in a line.
output
Print the minimum number of coins you need in a line.
Examples
Input
100
Output
4
Input
54321
Output
2175
Submitted Solution:
```
import sys, collections
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()
def resolve():
n = I()
ans = 0
for i in (25, 10, 5, 1):
ans += n // i
n %= i
print(ans)
if __name__ == '__main__':
resolve()
``` | instruction | 0 | 36,826 | 10 | 73,652 |
Yes | output | 1 | 36,826 | 10 | 73,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You want to make change for $ n $ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and / or 25 cents coins respectively, find the minimum number of coins you need.
Constraints
* $ 1 \ le n \ le 10 ^ 9 $
Input
$ n $
The integer $ n $ is given in a line.
output
Print the minimum number of coins you need in a line.
Examples
Input
100
Output
4
Input
54321
Output
2175
Submitted Solution:
```
n = int(input())
many = [25, 10, 5, 1]
cnt = 0
for i in many:
cnt += n//i
n = n%i
print(cnt)
``` | instruction | 0 | 36,827 | 10 | 73,654 |
Yes | output | 1 | 36,827 | 10 | 73,655 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You want to make change for $ n $ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and / or 25 cents coins respectively, find the minimum number of coins you need.
Constraints
* $ 1 \ le n \ le 10 ^ 9 $
Input
$ n $
The integer $ n $ is given in a line.
output
Print the minimum number of coins you need in a line.
Examples
Input
100
Output
4
Input
54321
Output
2175
Submitted Solution:
```
def main():
n = int(input())
C = [25,10,5,1]
ans = 0
for i in range(4):
ans += n // C[i]
n %= C[i]
print(ans)
if __name__ == "__main__":
main()
``` | instruction | 0 | 36,828 | 10 | 73,656 |
Yes | output | 1 | 36,828 | 10 | 73,657 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You want to make change for $ n $ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and / or 25 cents coins respectively, find the minimum number of coins you need.
Constraints
* $ 1 \ le n \ le 10 ^ 9 $
Input
$ n $
The integer $ n $ is given in a line.
output
Print the minimum number of coins you need in a line.
Examples
Input
100
Output
4
Input
54321
Output
2175
Submitted Solution:
```
m = int(input()) #money
c =0 #count coin
tc = 0 #temp coin
if m>=25:
c = m//25
m = m-(25*c)
if m>=10:
tc = m//10
m = m-(10*tc)
c += tc
if m>=5:
tc = m//5
m = m-(5*tc)
c += tc
if m>=0:
tc = m//1
m = m-(1*tc)
c += tc
print(c)
``` | instruction | 0 | 36,829 | 10 | 73,658 |
Yes | output | 1 | 36,829 | 10 | 73,659 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:
1. Take the leftmost item with the left hand and spend wi · l energy units (wi is a weight of the leftmost item, l is some parameter). If the previous action was the same (left-hand), then the robot spends extra Ql energy units;
2. Take the rightmost item with the right hand and spend wj · r energy units (wj is a weight of the rightmost item, r is some parameter). If the previous action was the same (right-hand), then the robot spends extra Qr energy units;
Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
Input
The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104).
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100).
Output
In the single line print a single number — the answer to the problem.
Examples
Input
3 4 4 19 1
42 3 99
Output
576
Input
4 7 2 3 9
1 2 3 4
Output
34
Note
Consider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.
The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units. | instruction | 0 | 37,996 | 10 | 75,992 |
Tags: brute force, greedy, math
Correct Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
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")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=998244353
EPS=1e-6
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
n,l,r,ql,qr=value()
w=array()
ans=inf
tot=sum(w)
cur=w[0]
for i in range(1,n):
tans=cur*l+(tot-cur)*r
lefts=i
rights=n-i
if(lefts>rights+1):
extra=lefts-rights-1
tans+=extra*ql
if(rights>lefts+1):
extra=rights-lefts-1
tans+=extra*qr
# print(tans,lefts,rights)
ans=min(ans,tans)
cur+=w[i]
ans=min(ans,tot*l+n*ql-ql,tot*r+n*qr-qr)
print(ans)
``` | output | 1 | 37,996 | 10 | 75,993 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:
1. Take the leftmost item with the left hand and spend wi · l energy units (wi is a weight of the leftmost item, l is some parameter). If the previous action was the same (left-hand), then the robot spends extra Ql energy units;
2. Take the rightmost item with the right hand and spend wj · r energy units (wj is a weight of the rightmost item, r is some parameter). If the previous action was the same (right-hand), then the robot spends extra Qr energy units;
Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
Input
The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104).
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100).
Output
In the single line print a single number — the answer to the problem.
Examples
Input
3 4 4 19 1
42 3 99
Output
576
Input
4 7 2 3 9
1 2 3 4
Output
34
Note
Consider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.
The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units. | instruction | 0 | 37,997 | 10 | 75,994 |
Tags: brute force, greedy, math
Correct Solution:
```
## necessary imports
import sys
input = sys.stdin.readline
from math import ceil, floor, factorial;
# swap_array function
def swaparr(arr, a,b):
temp = arr[a];
arr[a] = arr[b];
arr[b] = temp
## gcd function
def gcd(a,b):
if a == 0:
return b
return gcd(b%a, a)
## nCr function efficient using Binomial Cofficient
def nCr(n, k):
if(k > n - k):
k = n - k
res = 1
for i in range(k):
res = res * (n - i)
res = res / (i + 1)
return int(res)
## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0):
hi = len(a)
while lo < hi:
mid = (lo+hi)//2
if a[mid] < x:
lo = mid+1
else:
hi = mid
return lo
## prime factorization
def primefs(n):
## if n == 1 ## calculating primes
primes = {}
while(n%2 == 0):
primes[2] = primes.get(2, 0) + 1
n = n//2
for i in range(3, int(n**0.5)+2, 2):
while(n%i == 0):
primes[i] = primes.get(i, 0) + 1
n = n//i
if n > 2:
primes[n] = primes.get(n, 0) + 1
## prime factoriazation of n is stored in dictionary
## primes and can be accesed. O(sqrt n)
return primes
## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
res = 1
x = x % p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) :
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
temp = a
a = b
b = temp
return a,b
# find function with path compression included (recursive)
# def find(x, link):
# if link[x] == x:
# return x
# link[x] = find(link[x], link);
# return link[x];
# find function with path compression (ITERATIVE)
def find(x, link):
p = x;
while( p != link[p]):
p = link[p];
while( x != p):
nex = link[x];
link[x] = p;
x = nex;
return p;
# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
x = find(x, link)
y = find(y, link)
if size[x] < size[y]:
x,y = swap(x,y)
if x != y:
size[x] += size[y]
link[y] = x
## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return prime
#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e6 + 5)
def spf_sieve():
spf[1] = 1;
for i in range(2, MAXN):
spf[i] = i;
for i in range(4, MAXN, 2):
spf[i] = 2;
for i in range(3, ceil(MAXN ** 0.5), 2):
if spf[i] == i:
for j in range(i*i, MAXN, i):
if spf[j] == j:
spf[j] = i;
## function for storing smallest prime factors (spf) in the array
################## un-comment below 2 lines when using factorization #################
# spf = [0 for i in range(MAXN)]
# spf_sieve()
def factoriazation(x):
ret = {};
while x != 1:
ret[spf[x]] = ret.get(spf[x], 0) + 1;
x = x//spf[x]
return ret
## this function is useful for multiple queries only, o/w use
## primefs function above. complexity O(log n)
## taking integer array input
def int_array():
return list(map(int, input().strip().split()))
## taking string array input
def str_array():
return input().strip().split();
#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');
################### ---------------- TEMPLATE ENDS HERE ---------------- ###################
n, l, r, ql, qr = int_array();
a = [0] + int_array();
for i in range(1, n+1):
a[i] += a[i-1];
s = a[n]; ans = INF;
for i in range(n+1):
x = a[i] * l + (s - a[i]) * r;
if i > n - i:
x += ((2 * i) - n - 1) * ql;
if n - i > i:
x += (n - (2 * i) - 1) * qr;
ans = min(x, ans);
print(ans);
``` | output | 1 | 37,997 | 10 | 75,995 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:
1. Take the leftmost item with the left hand and spend wi · l energy units (wi is a weight of the leftmost item, l is some parameter). If the previous action was the same (left-hand), then the robot spends extra Ql energy units;
2. Take the rightmost item with the right hand and spend wj · r energy units (wj is a weight of the rightmost item, r is some parameter). If the previous action was the same (right-hand), then the robot spends extra Qr energy units;
Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
Input
The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104).
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100).
Output
In the single line print a single number — the answer to the problem.
Examples
Input
3 4 4 19 1
42 3 99
Output
576
Input
4 7 2 3 9
1 2 3 4
Output
34
Note
Consider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.
The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units. | instruction | 0 | 37,998 | 10 | 75,996 |
Tags: brute force, greedy, math
Correct Solution:
```
from sys import stdin
from itertools import accumulate
def arr_sum(arr):
return list(accumulate(arr, lambda x, y: x + y))
rints = lambda: [int(x) for x in stdin.readline().split()]
n, l, r, ql, qr = rints()
w, ans = [0] + rints(), float('inf')
mem = arr_sum(w)
for i in range(n + 1):
s1, s2 = mem[i] - mem[0], mem[-1] - mem[i]
tem = l * s1 + r * s2
if (n - i - i - 1) > 0:
tem += (n - i - i - 1) * qr
elif (i - (n - i) - 1) > 0:
tem += (i - (n - i) - 1) * ql
ans = min(ans, tem)
print(ans)
``` | output | 1 | 37,998 | 10 | 75,997 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:
1. Take the leftmost item with the left hand and spend wi · l energy units (wi is a weight of the leftmost item, l is some parameter). If the previous action was the same (left-hand), then the robot spends extra Ql energy units;
2. Take the rightmost item with the right hand and spend wj · r energy units (wj is a weight of the rightmost item, r is some parameter). If the previous action was the same (right-hand), then the robot spends extra Qr energy units;
Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
Input
The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104).
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100).
Output
In the single line print a single number — the answer to the problem.
Examples
Input
3 4 4 19 1
42 3 99
Output
576
Input
4 7 2 3 9
1 2 3 4
Output
34
Note
Consider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.
The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units. | instruction | 0 | 37,999 | 10 | 75,998 |
Tags: brute force, greedy, math
Correct Solution:
```
n, l, r, ql, qr = map(int, input().split())
w = [0] + list(map(int, input().split()))
for i in range(1, n + 1):
w[i] += w[i - 1]
s = w[n]
print(min(l * w[i] + r * (s - w[i]) + ql * max(0, 2 * i - n - 1) + qr * max(0, n - 2 * i - 1) for i in range(n + 1)))
# Made By Mostafa_Khaled
``` | output | 1 | 37,999 | 10 | 75,999 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:
1. Take the leftmost item with the left hand and spend wi · l energy units (wi is a weight of the leftmost item, l is some parameter). If the previous action was the same (left-hand), then the robot spends extra Ql energy units;
2. Take the rightmost item with the right hand and spend wj · r energy units (wj is a weight of the rightmost item, r is some parameter). If the previous action was the same (right-hand), then the robot spends extra Qr energy units;
Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
Input
The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104).
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100).
Output
In the single line print a single number — the answer to the problem.
Examples
Input
3 4 4 19 1
42 3 99
Output
576
Input
4 7 2 3 9
1 2 3 4
Output
34
Note
Consider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.
The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units. | instruction | 0 | 38,000 | 10 | 76,000 |
Tags: brute force, greedy, math
Correct Solution:
```
import sys
n,L,r,QL,QR=map(int,sys.stdin.readline().split())
W=list(map(int,sys.stdin.readline().split()))
minn=10**10
SumsL=[0]*n
SumsR=[0]*n
s=0
for i in range(n):
s+=W[i]
SumsL[i]=s
for i in range(n-1):
ans=L*SumsL[i]+r*(s-SumsL[i])
if(n-(i+1)>i+1):
ans+=(abs(n-(i+1)-(i+1))-1)*QR
elif(i+1>n-(i+1)):
ans+=(abs(n-(i+1)-(i+1))-1)*QL
if(ans<minn):
minn=ans
if(s*L+(QL*(n-1)) < minn):
minn=s*L+(QL*(n-1))
if(s*r+(QR*(n-1)) < minn):
minn=s*r+(QR*(n-1))
print(minn)
``` | output | 1 | 38,000 | 10 | 76,001 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:
1. Take the leftmost item with the left hand and spend wi · l energy units (wi is a weight of the leftmost item, l is some parameter). If the previous action was the same (left-hand), then the robot spends extra Ql energy units;
2. Take the rightmost item with the right hand and spend wj · r energy units (wj is a weight of the rightmost item, r is some parameter). If the previous action was the same (right-hand), then the robot spends extra Qr energy units;
Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
Input
The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104).
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100).
Output
In the single line print a single number — the answer to the problem.
Examples
Input
3 4 4 19 1
42 3 99
Output
576
Input
4 7 2 3 9
1 2 3 4
Output
34
Note
Consider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.
The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units. | instruction | 0 | 38,001 | 10 | 76,002 |
Tags: brute force, greedy, math
Correct Solution:
```
path = list(map(int, input().split()))
n, L, R, QL, QR = path[0], path[1], path[2], path[3], path[4]
w = list(map(int, input().split()))
sumpref = [0]
for i in range(1, n + 1) :
sumpref.append(w[i - 1] + sumpref[i - 1])
answer = QR * (n - 1) + sumpref[n] * R
for i in range(1, n + 1) :
energy = L * sumpref[i] + R * (sumpref[n] - sumpref[i])
if i > (n - i) :
energy += (i - (n - i) - 1) * QL
elif (n - i) > i :
energy += ((n - i) - i - 1) * QR
if answer > energy:
answer = energy
print(answer)
``` | output | 1 | 38,001 | 10 | 76,003 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:
1. Take the leftmost item with the left hand and spend wi · l energy units (wi is a weight of the leftmost item, l is some parameter). If the previous action was the same (left-hand), then the robot spends extra Ql energy units;
2. Take the rightmost item with the right hand and spend wj · r energy units (wj is a weight of the rightmost item, r is some parameter). If the previous action was the same (right-hand), then the robot spends extra Qr energy units;
Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
Input
The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104).
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100).
Output
In the single line print a single number — the answer to the problem.
Examples
Input
3 4 4 19 1
42 3 99
Output
576
Input
4 7 2 3 9
1 2 3 4
Output
34
Note
Consider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.
The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units.
Submitted Solution:
```
## necessary imports
import sys
input = sys.stdin.readline
from math import ceil, floor, factorial;
# swap_array function
def swaparr(arr, a,b):
temp = arr[a];
arr[a] = arr[b];
arr[b] = temp
## gcd function
def gcd(a,b):
if a == 0:
return b
return gcd(b%a, a)
## nCr function efficient using Binomial Cofficient
def nCr(n, k):
if(k > n - k):
k = n - k
res = 1
for i in range(k):
res = res * (n - i)
res = res / (i + 1)
return int(res)
## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0):
hi = len(a)
while lo < hi:
mid = (lo+hi)//2
if a[mid] < x:
lo = mid+1
else:
hi = mid
return lo
## prime factorization
def primefs(n):
## if n == 1 ## calculating primes
primes = {}
while(n%2 == 0):
primes[2] = primes.get(2, 0) + 1
n = n//2
for i in range(3, int(n**0.5)+2, 2):
while(n%i == 0):
primes[i] = primes.get(i, 0) + 1
n = n//i
if n > 2:
primes[n] = primes.get(n, 0) + 1
## prime factoriazation of n is stored in dictionary
## primes and can be accesed. O(sqrt n)
return primes
## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
res = 1
x = x % p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) :
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
temp = a
a = b
b = temp
return a,b
# find function with path compression included (recursive)
# def find(x, link):
# if link[x] == x:
# return x
# link[x] = find(link[x], link);
# return link[x];
# find function with path compression (ITERATIVE)
def find(x, link):
p = x;
while( p != link[p]):
p = link[p];
while( x != p):
nex = link[x];
link[x] = p;
x = nex;
return p;
# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
x = find(x, link)
y = find(y, link)
if size[x] < size[y]:
x,y = swap(x,y)
if x != y:
size[x] += size[y]
link[y] = x
## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return prime
#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e6 + 5)
def spf_sieve():
spf[1] = 1;
for i in range(2, MAXN):
spf[i] = i;
for i in range(4, MAXN, 2):
spf[i] = 2;
for i in range(3, ceil(MAXN ** 0.5), 2):
if spf[i] == i:
for j in range(i*i, MAXN, i):
if spf[j] == j:
spf[j] = i;
## function for storing smallest prime factors (spf) in the array
################## un-comment below 2 lines when using factorization #################
# spf = [0 for i in range(MAXN)]
# spf_sieve()
def factoriazation(x):
ret = {};
while x != 1:
ret[spf[x]] = ret.get(spf[x], 0) + 1;
x = x//spf[x]
return ret
## this function is useful for multiple queries only, o/w use
## primefs function above. complexity O(log n)
## taking integer array input
def int_array():
return list(map(int, input().strip().split()))
## taking string array input
def str_array():
return input().strip().split();
#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');
################### ---------------- TEMPLATE ENDS HERE ---------------- ###################
n, l, r, ql, qr = int_array(); a = int_array();
if l == r:
ans = sum(a) * l;
elif l < r:
i = 0; j = n-1; ans = 0; left = 0;
while(i <= j):
if not left:
ans += a[i] * l; i += 1;
left = 1;
else:
x = a[j] * r; y = a[i] * l + ql;
if x <= y:
ans += x; j -= 1;
left = 0;
else:
ans += a[i] * l + ql; i += 1;
left = 1;
else:
i = 0; j = n-1; ans = 0; right = 0;
while(i <= j):
if not right:
ans += a[j] * r; j -= 1;
right = 1;
else:
y = a[j] * r + qr; x = a[i] * l;
if x <= y:
ans += x; i += 1;
right = 0;
else:
ans += a[j] * r + qr; j -= 1;
right = 1;
print(ans);
``` | instruction | 0 | 38,002 | 10 | 76,004 |
No | output | 1 | 38,002 | 10 | 76,005 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:
1. Take the leftmost item with the left hand and spend wi · l energy units (wi is a weight of the leftmost item, l is some parameter). If the previous action was the same (left-hand), then the robot spends extra Ql energy units;
2. Take the rightmost item with the right hand and spend wj · r energy units (wj is a weight of the rightmost item, r is some parameter). If the previous action was the same (right-hand), then the robot spends extra Qr energy units;
Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
Input
The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104).
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100).
Output
In the single line print a single number — the answer to the problem.
Examples
Input
3 4 4 19 1
42 3 99
Output
576
Input
4 7 2 3 9
1 2 3 4
Output
34
Note
Consider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.
The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units.
Submitted Solution:
```
## necessary imports
import sys
input = sys.stdin.readline
from math import ceil, floor, factorial;
# swap_array function
def swaparr(arr, a,b):
temp = arr[a];
arr[a] = arr[b];
arr[b] = temp
## gcd function
def gcd(a,b):
if a == 0:
return b
return gcd(b%a, a)
## nCr function efficient using Binomial Cofficient
def nCr(n, k):
if(k > n - k):
k = n - k
res = 1
for i in range(k):
res = res * (n - i)
res = res / (i + 1)
return int(res)
## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0):
hi = len(a)
while lo < hi:
mid = (lo+hi)//2
if a[mid] < x:
lo = mid+1
else:
hi = mid
return lo
## prime factorization
def primefs(n):
## if n == 1 ## calculating primes
primes = {}
while(n%2 == 0):
primes[2] = primes.get(2, 0) + 1
n = n//2
for i in range(3, int(n**0.5)+2, 2):
while(n%i == 0):
primes[i] = primes.get(i, 0) + 1
n = n//i
if n > 2:
primes[n] = primes.get(n, 0) + 1
## prime factoriazation of n is stored in dictionary
## primes and can be accesed. O(sqrt n)
return primes
## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
res = 1
x = x % p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) :
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
temp = a
a = b
b = temp
return a,b
# find function with path compression included (recursive)
# def find(x, link):
# if link[x] == x:
# return x
# link[x] = find(link[x], link);
# return link[x];
# find function with path compression (ITERATIVE)
def find(x, link):
p = x;
while( p != link[p]):
p = link[p];
while( x != p):
nex = link[x];
link[x] = p;
x = nex;
return p;
# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
x = find(x, link)
y = find(y, link)
if size[x] < size[y]:
x,y = swap(x,y)
if x != y:
size[x] += size[y]
link[y] = x
## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return prime
#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e6 + 5)
def spf_sieve():
spf[1] = 1;
for i in range(2, MAXN):
spf[i] = i;
for i in range(4, MAXN, 2):
spf[i] = 2;
for i in range(3, ceil(MAXN ** 0.5), 2):
if spf[i] == i:
for j in range(i*i, MAXN, i):
if spf[j] == j:
spf[j] = i;
## function for storing smallest prime factors (spf) in the array
################## un-comment below 2 lines when using factorization #################
# spf = [0 for i in range(MAXN)]
# spf_sieve()
def factoriazation(x):
ret = {};
while x != 1:
ret[spf[x]] = ret.get(spf[x], 0) + 1;
x = x//spf[x]
return ret
## this function is useful for multiple queries only, o/w use
## primefs function above. complexity O(log n)
## taking integer array input
def int_array():
return list(map(int, input().strip().split()))
## taking string array input
def str_array():
return input().strip().split();
#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');
################### ---------------- TEMPLATE ENDS HERE ---------------- ###################
n, l, r, ql, qr = int_array(); a = int_array();
if l == r:
ans = sum(a) * l;
elif l < r:
i = 0; j = n-1; ans = 0; left = 0;
while(i <= j):
if not left:
ans += a[i] * l; i += 1;
left = 1;
else:
x = a[j] * r; y = a[i] * l + ql;
if x <= y:
ans += x; j -= 1;
left = 0;
else:
ans += a[i] * l + ql; i += 1;
left = 1;
else:
i = 0; j = n-1; ans = 0; right = 0;
while(i <= j):
if not right:
ans += a[j] * r; j -= 1;
right = 1;
else:
y = a[j] * r + qr; x = a[i] * l;
if x <= y:
ans += x; i += 1;
right = 0;
else:
ans += a[j] * r + qr; j -= 1;
right = 1;
if n % 2 != 0:
kk = sum(a[:n//2])*l + a[n//2]*min(l, r) + sum(a[(n//2) + 1:])*r;
else:
kk = sum(a[:n//2]) * l + sum(a[n//2 : ])*r;
ans = min(ans, kk);
print(ans);
``` | instruction | 0 | 38,003 | 10 | 76,006 |
No | output | 1 | 38,003 | 10 | 76,007 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:
1. Take the leftmost item with the left hand and spend wi · l energy units (wi is a weight of the leftmost item, l is some parameter). If the previous action was the same (left-hand), then the robot spends extra Ql energy units;
2. Take the rightmost item with the right hand and spend wj · r energy units (wj is a weight of the rightmost item, r is some parameter). If the previous action was the same (right-hand), then the robot spends extra Qr energy units;
Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
Input
The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104).
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100).
Output
In the single line print a single number — the answer to the problem.
Examples
Input
3 4 4 19 1
42 3 99
Output
576
Input
4 7 2 3 9
1 2 3 4
Output
34
Note
Consider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.
The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units.
Submitted Solution:
```
import sys
n,L,r,QL,QR=map(int,sys.stdin.readline().split())
W=list(map(int,sys.stdin.readline().split()))
minn=10**10
SumsL=[0]*n
SumsR=[0]*n
s=0
for i in range(n):
s+=W[i]
SumsL[i]=s
for i in range(n-1):
ans=L*SumsL[i-1]+r*(s-SumsL[i-1])
if(n-i>i):
ans+=(abs(n-i-i)-1)*QR
elif(i>n-i):
ans+=(abs(n-i-i)-1)*QL
if(ans<minn):
minn=ans
if(s*L+(QL*(n-1)) < minn):
minn=s*L+(QL*(n-1))
if(s*r+(QR*(n-1)) < minn):
minn=s*r+(QR*(n-1))
print(minn)
``` | instruction | 0 | 38,004 | 10 | 76,008 |
No | output | 1 | 38,004 | 10 | 76,009 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:
1. Take the leftmost item with the left hand and spend wi · l energy units (wi is a weight of the leftmost item, l is some parameter). If the previous action was the same (left-hand), then the robot spends extra Ql energy units;
2. Take the rightmost item with the right hand and spend wj · r energy units (wj is a weight of the rightmost item, r is some parameter). If the previous action was the same (right-hand), then the robot spends extra Qr energy units;
Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
Input
The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104).
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100).
Output
In the single line print a single number — the answer to the problem.
Examples
Input
3 4 4 19 1
42 3 99
Output
576
Input
4 7 2 3 9
1 2 3 4
Output
34
Note
Consider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.
The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units.
Submitted Solution:
```
import sys
n,L,r,QL,QR=map(int,sys.stdin.readline().split())
W=list(map(int,sys.stdin.readline().split()))
minn=10**10
SumsL=[0]*n
SumsR=[0]*n
s=0
for i in range(n):
s+=W[i]
SumsL[i]=s
for i in range(n-1):
ans=L*SumsL[i-1]+r*(s-SumsL[i-1])
if(n-i>i):
ans+=(abs(n-i-i)-1)*QR
elif(i>n-i):
ans+=(abs(n-i-i)-1)*QL
if(ans<minn):
minn=ans
if(s*L+(QL*(n-1)) < minn):
print("L")
minn=s*L+(QL*(n-1))
if(s*r+(QR*(n-1)) < minn):
print("r")
minn=s*r+(QR*(n-1))
print(minn)
``` | instruction | 0 | 38,005 | 10 | 76,010 |
No | output | 1 | 38,005 | 10 | 76,011 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13 | instruction | 0 | 38,086 | 10 | 76,172 |
Tags: brute force, implementation, math
Correct Solution:
```
k,n,w=map(int,input().split(" "))
a=0
for i in range(1,w+1):
a=a+(i*k)
if(a>n):
a=a-n
else:
a=0
print(a)
``` | output | 1 | 38,086 | 10 | 76,173 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13 | instruction | 0 | 38,087 | 10 | 76,174 |
Tags: brute force, implementation, math
Correct Solution:
```
k,n,w=map(int,input().split());s=0
for i in range(w):
s+=(i+1)*k
print( s-n if s > n else 0)
``` | output | 1 | 38,087 | 10 | 76,175 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13 | instruction | 0 | 38,088 | 10 | 76,176 |
Tags: brute force, implementation, math
Correct Solution:
```
k, n, w =[int(i) for i in input().split()]
t = (w + 1)* k * w //2
if t > n:
print(t - n)
else:
print(0)
``` | output | 1 | 38,088 | 10 | 76,177 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13 | instruction | 0 | 38,089 | 10 | 76,178 |
Tags: brute force, implementation, math
Correct Solution:
```
a = input()
k, n, w = a.split()
k = int(k)
n = int(n)
w = int(w)
f = 0
for i in range(w+1):
f = k * i + f
if f-n<0:
print(0)
else:
print(f-n)
``` | output | 1 | 38,089 | 10 | 76,179 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13 | instruction | 0 | 38,090 | 10 | 76,180 |
Tags: brute force, implementation, math
Correct Solution:
```
n = list(map(int,input().split()))
s = 0
for f in range(n[2]+1) :
s+= f * n[0]
if s -n[1] > 0 :
print ( s - n[1] )
else :
print(0)
``` | output | 1 | 38,090 | 10 | 76,181 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13 | instruction | 0 | 38,091 | 10 | 76,182 |
Tags: brute force, implementation, math
Correct Solution:
```
k, n, w = [int(x) for x in input().split()]
l = k * w * (w + 1) // 2 - n
print(l if l >= 0 else 0)
``` | output | 1 | 38,091 | 10 | 76,183 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13 | instruction | 0 | 38,092 | 10 | 76,184 |
Tags: brute force, implementation, math
Correct Solution:
```
k,n,w=[int(i) for i in input().split()]
c=0
for i in range(1,w+1):
c=c+(i*k)
if(c<=n):
print("0")
else:
print((c-n))
``` | output | 1 | 38,092 | 10 | 76,185 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13 | instruction | 0 | 38,093 | 10 | 76,186 |
Tags: brute force, implementation, math
Correct Solution:
```
k,n,w=map(int,input().split())
a=1
b=0
c=0
for i in range(w):
b=k*a
a+=1
c=c+b
d=c-n
if d>0:
print(d)
else:
print(0)
``` | output | 1 | 38,093 | 10 | 76,187 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13
Submitted Solution:
```
def solve():
K,N,W = [int(s) for s in input().split()]
return max(0,K*W*(W+1)//2 - N)
ans = solve()
print(ans)
``` | instruction | 0 | 38,094 | 10 | 76,188 |
Yes | output | 1 | 38,094 | 10 | 76,189 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13
Submitted Solution:
```
k, n, w = map(int, input().split())
print(max(((w * (w + 1) // 2) * k - n), 0))
``` | instruction | 0 | 38,095 | 10 | 76,190 |
Yes | output | 1 | 38,095 | 10 | 76,191 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13
Submitted Solution:
```
k,n,w=[int(x)for x in input().split()]
a=int(w*(w+1)*k/2-n)
if a>0:
print(a)
else:
print(0)
``` | instruction | 0 | 38,096 | 10 | 76,192 |
Yes | output | 1 | 38,096 | 10 | 76,193 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13
Submitted Solution:
```
def main():
k,n,w = map(int,input().split())
total_cost = k*w*(w+1)
total_cost = total_cost//2
money_he_has = n
money_borrowed = total_cost - money_he_has
if(money_borrowed < 0):
print(0)
else:
print(money_borrowed)
main()
``` | instruction | 0 | 38,097 | 10 | 76,194 |
Yes | output | 1 | 38,097 | 10 | 76,195 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13
Submitted Solution:
```
k, n, w = map(int, input().split())
for i in range(w):
n -= k
k *= i
print(abs(n-1))
``` | instruction | 0 | 38,098 | 10 | 76,196 |
No | output | 1 | 38,098 | 10 | 76,197 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13
Submitted Solution:
```
k, n, w = map(int,input().split())
print((w * (w+1) // 2) * k - n)
``` | instruction | 0 | 38,099 | 10 | 76,198 |
No | output | 1 | 38,099 | 10 | 76,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13
Submitted Solution:
```
print((lambda k:(2*k[0]+k[0]*(k[2]-1))*k[2]//2-k[1])(list(map(int,input().split()))))
``` | instruction | 0 | 38,100 | 10 | 76,200 |
No | output | 1 | 38,100 | 10 | 76,201 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13
Submitted Solution:
```
insert=input()
x=insert.split()
banana_price=int(x[0])
money=int(x[1])
banana_he_wants=int(x[2])
sum=0
for each in range(banana_he_wants):
n=(each+1)*banana_price
sum+=n
if sum > money:
print(sum-money)
else:
print()
``` | instruction | 0 | 38,101 | 10 | 76,202 |
No | output | 1 | 38,101 | 10 | 76,203 |
Provide a correct Python 3 solution for this coding contest problem.
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
* Move: When at town i (i < N), move to town i + 1.
* Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* A_i are distinct.
* 2 ≦ T ≦ 10^9
* In the initial state, Takahashi's expected profit is at least 1 yen.
Input
The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N
Output
Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.
Examples
Input
3 2
100 50 200
Output
1
Input
5 8
50 30 40 10 20
Output
2
Input
10 100
7 10 4 5 9 3 6 8 2 1
Output
2 | instruction | 0 | 38,461 | 10 | 76,922 |
"Correct Solution:
```
n,t=map(int,input().split())
ar=list(map(int,input().split()))
mn=float('inf')
mdif,mxc=-float('inf'),0
for e in ar:
if(e-mn>mdif):
mdif=e-mn
mxc=1
elif(e-mn==mdif):
mxc+=1
mn=min(mn,e)
print(mxc)
``` | output | 1 | 38,461 | 10 | 76,923 |
Provide a correct Python 3 solution for this coding contest problem.
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
* Move: When at town i (i < N), move to town i + 1.
* Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* A_i are distinct.
* 2 ≦ T ≦ 10^9
* In the initial state, Takahashi's expected profit is at least 1 yen.
Input
The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N
Output
Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.
Examples
Input
3 2
100 50 200
Output
1
Input
5 8
50 30 40 10 20
Output
2
Input
10 100
7 10 4 5 9 3 6 8 2 1
Output
2 | instruction | 0 | 38,462 | 10 | 76,924 |
"Correct Solution:
```
#!/usr/bin/env python3
N, T = map(int, input().split())
A = list(map(int, input().split()))
d = 0
ans = 1
l = A[0]
for a in A[1:]:
l = min(l, a)
r = a
if r - l == d:
ans += 1
elif r - l > d:
ans = 1
d = r - l
print(ans)
``` | output | 1 | 38,462 | 10 | 76,925 |
Provide a correct Python 3 solution for this coding contest problem.
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
* Move: When at town i (i < N), move to town i + 1.
* Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* A_i are distinct.
* 2 ≦ T ≦ 10^9
* In the initial state, Takahashi's expected profit is at least 1 yen.
Input
The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N
Output
Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.
Examples
Input
3 2
100 50 200
Output
1
Input
5 8
50 30 40 10 20
Output
2
Input
10 100
7 10 4 5 9 3 6 8 2 1
Output
2 | instruction | 0 | 38,463 | 10 | 76,926 |
"Correct Solution:
```
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import division, print_function, absolute_import, unicode_literals
N, T = map(int, input().split())
A = list(map(int, input().split()))
maxA = [0] * N
minA = [0] * N
maxA[N-1] = A[-1]
for i in range(1, N):
maxA[N-i-1] = max(maxA[N-i], A[N-i])
# print(maxA)
max_diff = -10000000000
for i in range(N-1):
max_diff = max(maxA[i] - A[i], max_diff)
# print(max_diff)
cnt = 0
for i in range(N-1):
if maxA[i] - A[i] == max_diff:
cnt += 1
print(cnt)
``` | output | 1 | 38,463 | 10 | 76,927 |
Provide a correct Python 3 solution for this coding contest problem.
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
* Move: When at town i (i < N), move to town i + 1.
* Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* A_i are distinct.
* 2 ≦ T ≦ 10^9
* In the initial state, Takahashi's expected profit is at least 1 yen.
Input
The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N
Output
Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.
Examples
Input
3 2
100 50 200
Output
1
Input
5 8
50 30 40 10 20
Output
2
Input
10 100
7 10 4 5 9 3 6 8 2 1
Output
2 | instruction | 0 | 38,464 | 10 | 76,928 |
"Correct Solution:
```
N, M = map(int, input().split())
A = tuple(map(int, input().split()))
mini = 10**10
bnf = 0
cnt = 1
for i in range(N):
mini = min(mini, A[i])
_bnf = A[i] - mini
if _bnf > bnf:
bnf = _bnf
cnt = 1
elif _bnf == bnf:
cnt += 1
print(cnt)
``` | output | 1 | 38,464 | 10 | 76,929 |
Provide a correct Python 3 solution for this coding contest problem.
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
* Move: When at town i (i < N), move to town i + 1.
* Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* A_i are distinct.
* 2 ≦ T ≦ 10^9
* In the initial state, Takahashi's expected profit is at least 1 yen.
Input
The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N
Output
Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.
Examples
Input
3 2
100 50 200
Output
1
Input
5 8
50 30 40 10 20
Output
2
Input
10 100
7 10 4 5 9 3 6 8 2 1
Output
2 | instruction | 0 | 38,465 | 10 | 76,930 |
"Correct Solution:
```
# f = open('input', 'r')
# n, t = map(int, f.readline().split())
# A = list(map(int, f.readline().split()))
n, t = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
max_diff = 0
min_a = A[0]
for a in A:
min_a = min(min_a, a)
if (a - min_a) == max_diff:
ans += 1
elif (a - min_a) > max_diff:
ans = 1
max_diff = (a - min_a)
print(ans)
``` | output | 1 | 38,465 | 10 | 76,931 |
Provide a correct Python 3 solution for this coding contest problem.
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
* Move: When at town i (i < N), move to town i + 1.
* Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* A_i are distinct.
* 2 ≦ T ≦ 10^9
* In the initial state, Takahashi's expected profit is at least 1 yen.
Input
The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N
Output
Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.
Examples
Input
3 2
100 50 200
Output
1
Input
5 8
50 30 40 10 20
Output
2
Input
10 100
7 10 4 5 9 3 6 8 2 1
Output
2 | instruction | 0 | 38,466 | 10 | 76,932 |
"Correct Solution:
```
N,T = map(int,input().split())
A = list(map(int,input().split()))
cummax = [A[-1]]
for a in reversed(A[:-1]):
cummax.append(max(cummax[-1], a))
cummax.reverse()
maxgain = n = 0
for buy,sell in zip(A,cummax):
gain = sell - buy
if gain > maxgain:
maxgain = gain
n = 1
elif gain == maxgain:
n += 1
print(n)
``` | output | 1 | 38,466 | 10 | 76,933 |
Provide a correct Python 3 solution for this coding contest problem.
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
* Move: When at town i (i < N), move to town i + 1.
* Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* A_i are distinct.
* 2 ≦ T ≦ 10^9
* In the initial state, Takahashi's expected profit is at least 1 yen.
Input
The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N
Output
Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.
Examples
Input
3 2
100 50 200
Output
1
Input
5 8
50 30 40 10 20
Output
2
Input
10 100
7 10 4 5 9 3 6 8 2 1
Output
2 | instruction | 0 | 38,467 | 10 | 76,934 |
"Correct Solution:
```
def main():
buf = input()
buflist = buf.split()
N = int(buflist[0])
T = int(buflist[1])
buf = input()
buflist = buf.split()
A = list(map(int, buflist))
min_price = A[0]
max_price_diff = 0
max_diff_count = 0
for i in range(1, N):
if A[i] < min_price:
min_price = A[i]
elif A[i] - min_price > max_price_diff:
max_price_diff = A[i] - min_price
max_diff_count = 1
elif A[i] - min_price == max_price_diff:
max_diff_count += 1
print(max_diff_count)
if __name__ == '__main__':
main()
``` | output | 1 | 38,467 | 10 | 76,935 |
Provide a correct Python 3 solution for this coding contest problem.
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
* Move: When at town i (i < N), move to town i + 1.
* Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* A_i are distinct.
* 2 ≦ T ≦ 10^9
* In the initial state, Takahashi's expected profit is at least 1 yen.
Input
The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N
Output
Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.
Examples
Input
3 2
100 50 200
Output
1
Input
5 8
50 30 40 10 20
Output
2
Input
10 100
7 10 4 5 9 3 6 8 2 1
Output
2 | instruction | 0 | 38,468 | 10 | 76,936 |
"Correct Solution:
```
from collections import Counter
N, T = map(int, input().split())
As = list(map(int, input().split()))
T //= 2
profits = [0] * (N - 1)
minA = As[0]
for i, A in enumerate(As[1:]):
profits[i] = T * (A - minA)
minA = min(minA, A)
cnts = Counter(profits)
print(cnts[max(cnts.keys())])
``` | output | 1 | 38,468 | 10 | 76,937 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
* Move: When at town i (i < N), move to town i + 1.
* Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* A_i are distinct.
* 2 ≦ T ≦ 10^9
* In the initial state, Takahashi's expected profit is at least 1 yen.
Input
The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N
Output
Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.
Examples
Input
3 2
100 50 200
Output
1
Input
5 8
50 30 40 10 20
Output
2
Input
10 100
7 10 4 5 9 3 6 8 2 1
Output
2
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7
def f():
n,t = list(map(int,input().split()))
a = list(map(int,input().split()))
m = 0
mc = inf
r = 0
for c in a:
if mc > c:
mc = c
continue
if c - mc > m:
m = c - mc
r = 1
continue
if c - mc == m:
r += 1
return r
print(f())
``` | instruction | 0 | 38,469 | 10 | 76,938 |
Yes | output | 1 | 38,469 | 10 | 76,939 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
* Move: When at town i (i < N), move to town i + 1.
* Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* A_i are distinct.
* 2 ≦ T ≦ 10^9
* In the initial state, Takahashi's expected profit is at least 1 yen.
Input
The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N
Output
Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.
Examples
Input
3 2
100 50 200
Output
1
Input
5 8
50 30 40 10 20
Output
2
Input
10 100
7 10 4 5 9 3 6 8 2 1
Output
2
Submitted Solution:
```
N, T = map(int, input().split())
a = [int(i) for i in input().split()]
b = [a[0]]
m = b[0]
for i in range(1,N):
if m > a[i]:
m = a[i]
b.append(m)
c = [a[i] - b[i] for i in range(N)]
print(c.count(max(c)))
``` | instruction | 0 | 38,470 | 10 | 76,940 |
Yes | output | 1 | 38,470 | 10 | 76,941 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
* Move: When at town i (i < N), move to town i + 1.
* Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* A_i are distinct.
* 2 ≦ T ≦ 10^9
* In the initial state, Takahashi's expected profit is at least 1 yen.
Input
The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N
Output
Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.
Examples
Input
3 2
100 50 200
Output
1
Input
5 8
50 30 40 10 20
Output
2
Input
10 100
7 10 4 5 9 3 6 8 2 1
Output
2
Submitted Solution:
```
import sys
from bisect import bisect_left as bl
input = sys.stdin.readline
N, T = map(int, input().split())
a = list(map(int, input().split()))
cm = [float("inf")] * (N + 1)
cmx = [0] * (N + 1)
for i in range(N):
cm[i + 1] = min(cm[i], a[i])
cmx[N - 1 - i] = max(cmx[N - i], a[N - 1 - i])
res = 0
x = 0
for i in range(N + 1):
x = max(cmx[i] - cm[i], x)
for i in range(N):
if cmx[i] - a[i] == x:
res += 1
print(res)
``` | instruction | 0 | 38,471 | 10 | 76,942 |
Yes | output | 1 | 38,471 | 10 | 76,943 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
* Move: When at town i (i < N), move to town i + 1.
* Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* A_i are distinct.
* 2 ≦ T ≦ 10^9
* In the initial state, Takahashi's expected profit is at least 1 yen.
Input
The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N
Output
Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.
Examples
Input
3 2
100 50 200
Output
1
Input
5 8
50 30 40 10 20
Output
2
Input
10 100
7 10 4 5 9 3 6 8 2 1
Output
2
Submitted Solution:
```
from itertools import*;_,a=open(0);*a,=map(int,a.split());c=[x-y for x,y in zip(a,accumulate(a,min))];print(c.count(max(c)))
``` | instruction | 0 | 38,472 | 10 | 76,944 |
Yes | output | 1 | 38,472 | 10 | 76,945 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
* Move: When at town i (i < N), move to town i + 1.
* Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* A_i are distinct.
* 2 ≦ T ≦ 10^9
* In the initial state, Takahashi's expected profit is at least 1 yen.
Input
The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N
Output
Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.
Examples
Input
3 2
100 50 200
Output
1
Input
5 8
50 30 40 10 20
Output
2
Input
10 100
7 10 4 5 9 3 6 8 2 1
Output
2
Submitted Solution:
```
import collections
input()
a = [int(x) for x in input().split()]
print(max(collections.Counter([max(a[i + 1:]) - x for i, x in enumerate(a[:-1])]).items())[1])
``` | instruction | 0 | 38,473 | 10 | 76,946 |
No | output | 1 | 38,473 | 10 | 76,947 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
* Move: When at town i (i < N), move to town i + 1.
* Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* A_i are distinct.
* 2 ≦ T ≦ 10^9
* In the initial state, Takahashi's expected profit is at least 1 yen.
Input
The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N
Output
Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.
Examples
Input
3 2
100 50 200
Output
1
Input
5 8
50 30 40 10 20
Output
2
Input
10 100
7 10 4 5 9 3 6 8 2 1
Output
2
Submitted Solution:
```
N, T = map(int, input().split())
*A, = map(int, input().split())
max_price = A[N-1]
max_prof = 0
count = 0
for a in reversed(A[:N-1]):
prof = max_price - a
if prof < 0: max_price = a
elif prof == max_prof: count += 1
elif prof > max_prof: max_prof = prof; count = 1;
print(min(count, T//2))
``` | instruction | 0 | 38,474 | 10 | 76,948 |
No | output | 1 | 38,474 | 10 | 76,949 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
* Move: When at town i (i < N), move to town i + 1.
* Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change A_i into another arbitrary non-negative integer A_i' for any town i, any number of times. The cost of performing this operation is |A_i - A_i'|. After performing this operation, different towns may have equal values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
Constraints
* 1 ≦ N ≦ 10^5
* 1 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)
* A_i are distinct.
* 2 ≦ T ≦ 10^9
* In the initial state, Takahashi's expected profit is at least 1 yen.
Input
The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N
Output
Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.
Examples
Input
3 2
100 50 200
Output
1
Input
5 8
50 30 40 10 20
Output
2
Input
10 100
7 10 4 5 9 3 6 8 2 1
Output
2
Submitted Solution:
```
n, t = map(int, input().split())
a = list(map(int, input().split()))
mi = a[0]
ma = a[0]
ans = 0
dif = 0
temp1 = 0
temp3 = 0
for i in range(1, n):
if a[i]>ma:
ma=a[i]
elif a[i]==ma:
temp1+=1
elif a[i]==mi:
temp3+=1
elif a[i]<mi:
temp2 = ma-mi
mi=a[i]
ma=0
if temp2>dif:
dif = temp2
ans = 1+min(temp1, temp3)
temp1=0
temp3=0
elif temp2==dif:
ans += 1+min(temp1, temp3)
temp1 = 0
temp3=0
else:
temp1 = 0
temp3=0
#print("ma " + str(ma) )
#print("mi " + str(mi) )
#print("temp1 " + str(temp1))
#print("ans " + str(ans))
#print("dif " + str(dif))
#print(" ")
temp2 = ma-mi
if temp2>dif:
dif = temp2
ans = 1+min(temp3,temp1)
temp1=0
elif temp2==dif:
ans += 1+min(temp1, temp3)
temp1 = 0
else:
temp1 = 0
print(ans)
``` | instruction | 0 | 38,475 | 10 | 76,950 |
No | output | 1 | 38,475 | 10 | 76,951 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.