message stringlengths 2 22.8k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 16 109k | cluster float64 1 1 | __index_level_0__ int64 32 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations:
* d1 is the distance between the 1-st and the 2-nd station;
* d2 is the distance between the 2-nd and the 3-rd station;
...
* dn - 1 is the distance between the n - 1-th and the n-th station;
* dn is the distance between the n-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t.
Input
The first line contains integer n (3 β€ n β€ 100) β the number of stations on the circle line. The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1 β€ s, t β€ n) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces.
Output
Print a single number β the length of the shortest path between stations number s and t.
Examples
Input
4
2 3 4 9
1 3
Output
5
Input
4
5 8 2 100
4 1
Output
15
Input
3
1 1 1
3 1
Output
1
Input
3
31 41 59
1 1
Output
0
Note
In the first sample the length of path 1 β 2 β 3 equals 5, the length of path 1 β 4 β 3 equals 13.
In the second sample the length of path 4 β 1 is 100, the length of path 4 β 3 β 2 β 1 is 15.
In the third sample the length of path 3 β 1 is 1, the length of path 3 β 2 β 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | instruction | 0 | 38,971 | 1 | 77,942 |
Tags: implementation
Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
x,y=map(int,input().split())
x,y=x-1,y-1
d=[]
for i in range(n-1):
xx=l[i]
d.append(xx)
if(x==y):
print(0)
else:
s,c=0,0
if(x<y):
for i in range(x,y):
s=s+l[i]
for i in range(y,n):
c=c+l[i]
for i in range(0,x):
c=c+l[i]
print(min(s,c))
else:
for i in range(x-1,y-1,-1):
s=s+l[i]
for i in range(x,n):
c=c+l[i]
for i in range(0,y):
c=c+l[i]
print(min(s,c))
``` | output | 1 | 38,971 | 1 | 77,943 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations:
* d1 is the distance between the 1-st and the 2-nd station;
* d2 is the distance between the 2-nd and the 3-rd station;
...
* dn - 1 is the distance between the n - 1-th and the n-th station;
* dn is the distance between the n-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t.
Input
The first line contains integer n (3 β€ n β€ 100) β the number of stations on the circle line. The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1 β€ s, t β€ n) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces.
Output
Print a single number β the length of the shortest path between stations number s and t.
Examples
Input
4
2 3 4 9
1 3
Output
5
Input
4
5 8 2 100
4 1
Output
15
Input
3
1 1 1
3 1
Output
1
Input
3
31 41 59
1 1
Output
0
Note
In the first sample the length of path 1 β 2 β 3 equals 5, the length of path 1 β 4 β 3 equals 13.
In the second sample the length of path 4 β 1 is 100, the length of path 4 β 3 β 2 β 1 is 15.
In the third sample the length of path 3 β 1 is 1, the length of path 3 β 2 β 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | instruction | 0 | 38,972 | 1 | 77,944 |
Tags: implementation
Correct Solution:
```
n = int(input())
arr = list (map (int, input().split()))
s,t = map (int, input().split())
s -= 1; t -= 1
if s > t: s, t = t, s
print (min (sum (x for x in arr[s:t]), sum (arr) - sum (x for x in arr[s:t])))
``` | output | 1 | 38,972 | 1 | 77,945 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations:
* d1 is the distance between the 1-st and the 2-nd station;
* d2 is the distance between the 2-nd and the 3-rd station;
...
* dn - 1 is the distance between the n - 1-th and the n-th station;
* dn is the distance between the n-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t.
Input
The first line contains integer n (3 β€ n β€ 100) β the number of stations on the circle line. The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1 β€ s, t β€ n) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces.
Output
Print a single number β the length of the shortest path between stations number s and t.
Examples
Input
4
2 3 4 9
1 3
Output
5
Input
4
5 8 2 100
4 1
Output
15
Input
3
1 1 1
3 1
Output
1
Input
3
31 41 59
1 1
Output
0
Note
In the first sample the length of path 1 β 2 β 3 equals 5, the length of path 1 β 4 β 3 equals 13.
In the second sample the length of path 4 β 1 is 100, the length of path 4 β 3 β 2 β 1 is 15.
In the third sample the length of path 3 β 1 is 1, the length of path 3 β 2 β 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
Submitted Solution:
```
def calc_shortest(D, s1, s2):
#D[1:3] = D[1]+D[2] = d_2+d_3 = distance between Station 2 and Station 4
if s1 == s2:
return 0
elif s1 < s2:
path1 = sum(D[s1-1:s2-1])
else:
path1 = sum(D[s2-1:s1-1])
path2 = sum(D)-path1
if path1 < path2:
return path1
else:
return path2
N = [int(i) for i in input().strip().split()][0]
D = [int(i) for i in input().strip().split()]
s1, s2 = [int(i) for i in input().strip().split()]
print(calc_shortest(D, s1, s2))
exit(0)
``` | instruction | 0 | 38,973 | 1 | 77,946 |
Yes | output | 1 | 38,973 | 1 | 77,947 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations:
* d1 is the distance between the 1-st and the 2-nd station;
* d2 is the distance between the 2-nd and the 3-rd station;
...
* dn - 1 is the distance between the n - 1-th and the n-th station;
* dn is the distance between the n-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t.
Input
The first line contains integer n (3 β€ n β€ 100) β the number of stations on the circle line. The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1 β€ s, t β€ n) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces.
Output
Print a single number β the length of the shortest path between stations number s and t.
Examples
Input
4
2 3 4 9
1 3
Output
5
Input
4
5 8 2 100
4 1
Output
15
Input
3
1 1 1
3 1
Output
1
Input
3
31 41 59
1 1
Output
0
Note
In the first sample the length of path 1 β 2 β 3 equals 5, the length of path 1 β 4 β 3 equals 13.
In the second sample the length of path 4 β 1 is 100, the length of path 4 β 3 β 2 β 1 is 15.
In the third sample the length of path 3 β 1 is 1, the length of path 3 β 2 β 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
Submitted Solution:
```
n= int(input())
l=[]
l.extend(map(int,input().split()))
f , e = (map(int,input().split()))
sum1=sum2=0
if e>f:
max=e
min=f
elif e<f:
max=f
min=e
if e==f:
print(0)
else:
for i in range(min,max):
sum1+=l[i-1]
for i in range(max-1,len(l)):
sum2+=l[i]
if min-1>0:
for j in range(0,min-1):
sum2+=l[j]
if sum1>sum2:
print(sum2)
else:
print(sum1)
``` | instruction | 0 | 38,974 | 1 | 77,948 |
Yes | output | 1 | 38,974 | 1 | 77,949 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations:
* d1 is the distance between the 1-st and the 2-nd station;
* d2 is the distance between the 2-nd and the 3-rd station;
...
* dn - 1 is the distance between the n - 1-th and the n-th station;
* dn is the distance between the n-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t.
Input
The first line contains integer n (3 β€ n β€ 100) β the number of stations on the circle line. The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1 β€ s, t β€ n) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces.
Output
Print a single number β the length of the shortest path between stations number s and t.
Examples
Input
4
2 3 4 9
1 3
Output
5
Input
4
5 8 2 100
4 1
Output
15
Input
3
1 1 1
3 1
Output
1
Input
3
31 41 59
1 1
Output
0
Note
In the first sample the length of path 1 β 2 β 3 equals 5, the length of path 1 β 4 β 3 equals 13.
In the second sample the length of path 4 β 1 is 100, the length of path 4 β 3 β 2 β 1 is 15.
In the third sample the length of path 3 β 1 is 1, the length of path 3 β 2 β 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
Submitted Solution:
```
# coding: utf-8
n = int(input())
d = [int(i) for i in input().split()]
s, t = [int(i) for i in input().split()]
if s > t:
s, t = t, s
circu = sum(d)
len1 = sum(d[s-1:t-1])
len2 = circu-len1
print(min(len1,len2))
``` | instruction | 0 | 38,975 | 1 | 77,950 |
Yes | output | 1 | 38,975 | 1 | 77,951 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations:
* d1 is the distance between the 1-st and the 2-nd station;
* d2 is the distance between the 2-nd and the 3-rd station;
...
* dn - 1 is the distance between the n - 1-th and the n-th station;
* dn is the distance between the n-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t.
Input
The first line contains integer n (3 β€ n β€ 100) β the number of stations on the circle line. The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1 β€ s, t β€ n) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces.
Output
Print a single number β the length of the shortest path between stations number s and t.
Examples
Input
4
2 3 4 9
1 3
Output
5
Input
4
5 8 2 100
4 1
Output
15
Input
3
1 1 1
3 1
Output
1
Input
3
31 41 59
1 1
Output
0
Note
In the first sample the length of path 1 β 2 β 3 equals 5, the length of path 1 β 4 β 3 equals 13.
In the second sample the length of path 4 β 1 is 100, the length of path 4 β 3 β 2 β 1 is 15.
In the third sample the length of path 3 β 1 is 1, the length of path 3 β 2 β 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
Submitted Solution:
```
n=int(input())
A = list(map(int,input().split()))
s,e=map(int,input().split())
s-=1
e-=1
d1 = sum(A[min(e,s):max(e,s)])
d2 = sum(A[max(e,s):]) + sum(A[:min(s,e)])
print(min(d1,d2))
``` | instruction | 0 | 38,976 | 1 | 77,952 |
Yes | output | 1 | 38,976 | 1 | 77,953 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations:
* d1 is the distance between the 1-st and the 2-nd station;
* d2 is the distance between the 2-nd and the 3-rd station;
...
* dn - 1 is the distance between the n - 1-th and the n-th station;
* dn is the distance between the n-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t.
Input
The first line contains integer n (3 β€ n β€ 100) β the number of stations on the circle line. The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1 β€ s, t β€ n) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces.
Output
Print a single number β the length of the shortest path between stations number s and t.
Examples
Input
4
2 3 4 9
1 3
Output
5
Input
4
5 8 2 100
4 1
Output
15
Input
3
1 1 1
3 1
Output
1
Input
3
31 41 59
1 1
Output
0
Note
In the first sample the length of path 1 β 2 β 3 equals 5, the length of path 1 β 4 β 3 equals 13.
In the second sample the length of path 4 β 1 is 100, the length of path 4 β 3 β 2 β 1 is 15.
In the third sample the length of path 3 β 1 is 1, the length of path 3 β 2 β 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
Submitted Solution:
```
a = int(input())
d = list(map(int, input().split())) * 2
s, t = map(int, input().split(' '))
if s == t:
ans1 = 0
elif s > t:
ans1 = sum(d[t-1:s-1])
ans2 = sum(d[s-1:(a+t-1)])
elif s < t:
ans1 = sum(d[s-1:t-1])
ans2 = sum(d[t-1:(a+s-1)])
print(ans1, ans2)
``` | instruction | 0 | 38,977 | 1 | 77,954 |
No | output | 1 | 38,977 | 1 | 77,955 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations:
* d1 is the distance between the 1-st and the 2-nd station;
* d2 is the distance between the 2-nd and the 3-rd station;
...
* dn - 1 is the distance between the n - 1-th and the n-th station;
* dn is the distance between the n-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t.
Input
The first line contains integer n (3 β€ n β€ 100) β the number of stations on the circle line. The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1 β€ s, t β€ n) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces.
Output
Print a single number β the length of the shortest path between stations number s and t.
Examples
Input
4
2 3 4 9
1 3
Output
5
Input
4
5 8 2 100
4 1
Output
15
Input
3
1 1 1
3 1
Output
1
Input
3
31 41 59
1 1
Output
0
Note
In the first sample the length of path 1 β 2 β 3 equals 5, the length of path 1 β 4 β 3 equals 13.
In the second sample the length of path 4 β 1 is 100, the length of path 4 β 3 β 2 β 1 is 15.
In the third sample the length of path 3 β 1 is 1, the length of path 3 β 2 β 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
Submitted Solution:
```
n = int(input())
d = [int(x) for x in input().split()]
a, b = [int(x) for x in input().split()]
a, b = min(a, b), max(a, b)
a -= 1
b -= 1
min(sum(d[a:b]), sum(d[:a] + d[b:]))
``` | instruction | 0 | 38,978 | 1 | 77,956 |
No | output | 1 | 38,978 | 1 | 77,957 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations:
* d1 is the distance between the 1-st and the 2-nd station;
* d2 is the distance between the 2-nd and the 3-rd station;
...
* dn - 1 is the distance between the n - 1-th and the n-th station;
* dn is the distance between the n-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t.
Input
The first line contains integer n (3 β€ n β€ 100) β the number of stations on the circle line. The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1 β€ s, t β€ n) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces.
Output
Print a single number β the length of the shortest path between stations number s and t.
Examples
Input
4
2 3 4 9
1 3
Output
5
Input
4
5 8 2 100
4 1
Output
15
Input
3
1 1 1
3 1
Output
1
Input
3
31 41 59
1 1
Output
0
Note
In the first sample the length of path 1 β 2 β 3 equals 5, the length of path 1 β 4 β 3 equals 13.
In the second sample the length of path 4 β 1 is 100, the length of path 4 β 3 β 2 β 1 is 15.
In the third sample the length of path 3 β 1 is 1, the length of path 3 β 2 β 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
Submitted Solution:
```
n=int(input())
l=list(map(int, input().split()))
s,t=map(int, input().split())
sum1=sum2=0
r=abs(s-t)
for i in range(r):
sum1+=l[i]
#print(sum1)
for i in range(n-(r)):
sum2+=l[n-i-1]
#print(sum2)
print(min(sum1,sum2))
``` | instruction | 0 | 38,979 | 1 | 77,958 |
No | output | 1 | 38,979 | 1 | 77,959 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations:
* d1 is the distance between the 1-st and the 2-nd station;
* d2 is the distance between the 2-nd and the 3-rd station;
...
* dn - 1 is the distance between the n - 1-th and the n-th station;
* dn is the distance between the n-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t.
Input
The first line contains integer n (3 β€ n β€ 100) β the number of stations on the circle line. The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 100) β the distances between pairs of neighboring stations. The third line contains two integers s and t (1 β€ s, t β€ n) β the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces.
Output
Print a single number β the length of the shortest path between stations number s and t.
Examples
Input
4
2 3 4 9
1 3
Output
5
Input
4
5 8 2 100
4 1
Output
15
Input
3
1 1 1
3 1
Output
1
Input
3
31 41 59
1 1
Output
0
Note
In the first sample the length of path 1 β 2 β 3 equals 5, the length of path 1 β 4 β 3 equals 13.
In the second sample the length of path 4 β 1 is 100, the length of path 4 β 3 β 2 β 1 is 15.
In the third sample the length of path 3 β 1 is 1, the length of path 3 β 2 β 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.
Submitted Solution:
```
#Amirhossein Alimirzaei
#@HajLorenzo
input()
_d=list(map(int,input().split()))
_=list(map(int,input().split()))
_s1=0
_s2=0
if _[0]>_[1]:
_s1 = sum(_d[_[0] - 1:len(_d)])
if _[1] > 1:
_s1 += sum(_d[0:_[1]-1])
_s2=sum(_d[_[1]-1:_[0]-1])
else:
_s1=sum(_d[_[0]-1:_[1]-1])
_s2=sum(_d[_[1]-1:len(_d)])
if _[0]>1:
_s2=sum(_d[0:_[0]])
print(min(_s1,_s2))
``` | instruction | 0 | 38,980 | 1 | 77,960 |
No | output | 1 | 38,980 | 1 | 77,961 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland is going through tough times β the dirt price has dropped and that is a blow to the country's economy. Everybody knows that Berland is the top world dirt exporter!
The President of Berland was forced to leave only k of the currently existing n subway stations.
The subway stations are located on a straight line one after another, the trains consecutively visit the stations as they move. You can assume that the stations are on the Ox axis, the i-th station is at point with coordinate xi. In such case the distance between stations i and j is calculated by a simple formula |xi - xj|.
Currently, the Ministry of Transport is choosing which stations to close and which ones to leave. Obviously, the residents of the capital won't be too enthusiastic about the innovation, so it was decided to show the best side to the people. The Ministry of Transport wants to choose such k stations that minimize the average commute time in the subway!
Assuming that the train speed is constant (it is a fixed value), the average commute time in the subway is calculated as the sum of pairwise distances between stations, divided by the number of pairs (that is <image>) and divided by the speed of the train.
Help the Minister of Transport to solve this difficult problem. Write a program that, given the location of the stations selects such k stations that the average commute time in the subway is minimized.
Input
The first line of the input contains integer n (3 β€ n β€ 3Β·105) β the number of the stations before the innovation. The second line contains the coordinates of the stations x1, x2, ..., xn ( - 108 β€ xi β€ 108). The third line contains integer k (2 β€ k β€ n - 1) β the number of stations after the innovation.
The station coordinates are distinct and not necessarily sorted.
Output
Print a sequence of k distinct integers t1, t2, ..., tk (1 β€ tj β€ n) β the numbers of the stations that should be left after the innovation in arbitrary order. Assume that the stations are numbered 1 through n in the order they are given in the input. The number of stations you print must have the minimum possible average commute time among all possible ways to choose k stations. If there are multiple such ways, you are allowed to print any of them.
Examples
Input
3
1 100 101
2
Output
2 3
Note
In the sample testcase the optimal answer is to destroy the first station (with x = 1). The average commute time will be equal to 1 in this way. | instruction | 0 | 39,005 | 1 | 78,010 |
Tags: greedy, math, two pointers
Correct Solution:
```
from sys import stdin
n = int(stdin.readline())
a = [int(x) for x in stdin.readline().split()]
a = sorted([(a[x],str(x+1)) for x in range(n)])
k = int(stdin.readline())
sums = [0]
for x in a:
sums.append(sums[-1]+x[0])
total = 0
s = 0
for x in range(k):
total += a[x][0]*x-s
s += a[x][0]
low = total
lowInd = 0
#print(total)
for x in range(n-k):
s -= a[x][0]
total -= s-a[x][0]*(k-1)
total += a[x+k][0]*(k-1)-s
s += a[x+k][0]
if total < low:
low = total
lowInd = x+1
out = []
for x in range(lowInd,lowInd+k):
out.append(a[x][1])
print(' '.join(out))
``` | output | 1 | 39,005 | 1 | 78,011 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland is going through tough times β the dirt price has dropped and that is a blow to the country's economy. Everybody knows that Berland is the top world dirt exporter!
The President of Berland was forced to leave only k of the currently existing n subway stations.
The subway stations are located on a straight line one after another, the trains consecutively visit the stations as they move. You can assume that the stations are on the Ox axis, the i-th station is at point with coordinate xi. In such case the distance between stations i and j is calculated by a simple formula |xi - xj|.
Currently, the Ministry of Transport is choosing which stations to close and which ones to leave. Obviously, the residents of the capital won't be too enthusiastic about the innovation, so it was decided to show the best side to the people. The Ministry of Transport wants to choose such k stations that minimize the average commute time in the subway!
Assuming that the train speed is constant (it is a fixed value), the average commute time in the subway is calculated as the sum of pairwise distances between stations, divided by the number of pairs (that is <image>) and divided by the speed of the train.
Help the Minister of Transport to solve this difficult problem. Write a program that, given the location of the stations selects such k stations that the average commute time in the subway is minimized.
Input
The first line of the input contains integer n (3 β€ n β€ 3Β·105) β the number of the stations before the innovation. The second line contains the coordinates of the stations x1, x2, ..., xn ( - 108 β€ xi β€ 108). The third line contains integer k (2 β€ k β€ n - 1) β the number of stations after the innovation.
The station coordinates are distinct and not necessarily sorted.
Output
Print a sequence of k distinct integers t1, t2, ..., tk (1 β€ tj β€ n) β the numbers of the stations that should be left after the innovation in arbitrary order. Assume that the stations are numbered 1 through n in the order they are given in the input. The number of stations you print must have the minimum possible average commute time among all possible ways to choose k stations. If there are multiple such ways, you are allowed to print any of them.
Examples
Input
3
1 100 101
2
Output
2 3
Note
In the sample testcase the optimal answer is to destroy the first station (with x = 1). The average commute time will be equal to 1 in this way.
Submitted Solution:
```
from itertools import accumulate
n = int(input())
a = [int(x) for x in input().split()]
a.insert(0,0)
k = int(input())
b = sorted(enumerate(a), key= lambda x:x[1])
cum = [0,b[1][1]]
for i in range(2,n+1):
cum.append(cum[i-1]+b[i][1])
#print(a,b,cum)
x = 0
for i in range(1,k+1):
x+= a[i]*(i-1 ) - cum[i-1]
#print(x)
i, j = 1, k
min_i = -1
min_j = -1
sumi = x
while j < n:
sum_i1 = x - (cum[k]-cum[i] + ((k-1)*b[i][1])) + ((k-1)*b[j+1][1] - (cum[j+1]-cum[i]))
#print(sum_i1)
if sum_i1<sumi:
sumi = sum_i1
min_i = i+1
min_j = j+1
i+=1
j+=1
print(min_i,min_j)
``` | instruction | 0 | 39,006 | 1 | 78,012 |
No | output | 1 | 39,006 | 1 | 78,013 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland is going through tough times β the dirt price has dropped and that is a blow to the country's economy. Everybody knows that Berland is the top world dirt exporter!
The President of Berland was forced to leave only k of the currently existing n subway stations.
The subway stations are located on a straight line one after another, the trains consecutively visit the stations as they move. You can assume that the stations are on the Ox axis, the i-th station is at point with coordinate xi. In such case the distance between stations i and j is calculated by a simple formula |xi - xj|.
Currently, the Ministry of Transport is choosing which stations to close and which ones to leave. Obviously, the residents of the capital won't be too enthusiastic about the innovation, so it was decided to show the best side to the people. The Ministry of Transport wants to choose such k stations that minimize the average commute time in the subway!
Assuming that the train speed is constant (it is a fixed value), the average commute time in the subway is calculated as the sum of pairwise distances between stations, divided by the number of pairs (that is <image>) and divided by the speed of the train.
Help the Minister of Transport to solve this difficult problem. Write a program that, given the location of the stations selects such k stations that the average commute time in the subway is minimized.
Input
The first line of the input contains integer n (3 β€ n β€ 3Β·105) β the number of the stations before the innovation. The second line contains the coordinates of the stations x1, x2, ..., xn ( - 108 β€ xi β€ 108). The third line contains integer k (2 β€ k β€ n - 1) β the number of stations after the innovation.
The station coordinates are distinct and not necessarily sorted.
Output
Print a sequence of k distinct integers t1, t2, ..., tk (1 β€ tj β€ n) β the numbers of the stations that should be left after the innovation in arbitrary order. Assume that the stations are numbered 1 through n in the order they are given in the input. The number of stations you print must have the minimum possible average commute time among all possible ways to choose k stations. If there are multiple such ways, you are allowed to print any of them.
Examples
Input
3
1 100 101
2
Output
2 3
Note
In the sample testcase the optimal answer is to destroy the first station (with x = 1). The average commute time will be equal to 1 in this way.
Submitted Solution:
```
n = int(input())
temp = list(map(int,input().split(" ")))
m = int(input())
fi = []
for i in range(len(temp)):
fi.append([temp[i],i+1])
fi.sort(key = lambda x:x[0])
#print(fi)
dis = []
for i in range(n-1):
dis.append(abs(fi[i+1][0]-fi[i][0]))
#print(dis)
m-=1
min = 10000000000
ind = 0
for i in range(len(dis)-m+1):
er = m
tot = 0
if(m%2==0):
for j in range(i,(i+int(m/2))):
#print(er , "er")
tot += er*(dis[j]+dis[2*i+m-1-j])
er = er + m-(2*(j-i+1))
if(tot<min):
min = tot
ind = i
else:
for j in range(i,(i+int(m/2))):
#print(er , "er")
tot += er*(dis[j]+dis[2*i+m-1-j])
#print(tot," - " ,dis[j]+dis[2*i+m-1-j])
er = er + m-(2*(j-i+1))
#print("er",er)
tot += er*dis[i+int(m/2)]
if(tot<min):
min = tot
ind = i
#print(tot)
final = []
for i in range(m+1):
final.append(fi[i+ind][1])
final.sort()
for i in final:
print(i,end=" ")
``` | instruction | 0 | 39,007 | 1 | 78,014 |
No | output | 1 | 39,007 | 1 | 78,015 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland is going through tough times β the dirt price has dropped and that is a blow to the country's economy. Everybody knows that Berland is the top world dirt exporter!
The President of Berland was forced to leave only k of the currently existing n subway stations.
The subway stations are located on a straight line one after another, the trains consecutively visit the stations as they move. You can assume that the stations are on the Ox axis, the i-th station is at point with coordinate xi. In such case the distance between stations i and j is calculated by a simple formula |xi - xj|.
Currently, the Ministry of Transport is choosing which stations to close and which ones to leave. Obviously, the residents of the capital won't be too enthusiastic about the innovation, so it was decided to show the best side to the people. The Ministry of Transport wants to choose such k stations that minimize the average commute time in the subway!
Assuming that the train speed is constant (it is a fixed value), the average commute time in the subway is calculated as the sum of pairwise distances between stations, divided by the number of pairs (that is <image>) and divided by the speed of the train.
Help the Minister of Transport to solve this difficult problem. Write a program that, given the location of the stations selects such k stations that the average commute time in the subway is minimized.
Input
The first line of the input contains integer n (3 β€ n β€ 3Β·105) β the number of the stations before the innovation. The second line contains the coordinates of the stations x1, x2, ..., xn ( - 108 β€ xi β€ 108). The third line contains integer k (2 β€ k β€ n - 1) β the number of stations after the innovation.
The station coordinates are distinct and not necessarily sorted.
Output
Print a sequence of k distinct integers t1, t2, ..., tk (1 β€ tj β€ n) β the numbers of the stations that should be left after the innovation in arbitrary order. Assume that the stations are numbered 1 through n in the order they are given in the input. The number of stations you print must have the minimum possible average commute time among all possible ways to choose k stations. If there are multiple such ways, you are allowed to print any of them.
Examples
Input
3
1 100 101
2
Output
2 3
Note
In the sample testcase the optimal answer is to destroy the first station (with x = 1). The average commute time will be equal to 1 in this way.
Submitted Solution:
```
from itertools import accumulate
n = int(input())
a = [int(x) for x in input().split()]
a.insert(0,-float("inf"))
k = int(input())
b = sorted(enumerate(a), key= lambda x:x[1])
cum = [0,a[1]]
for i in range(2,n+1):
cum.append(cum[i-1]+b[i][1])
#print(a,b,cum)
x = 0
for i in range(1,k+1):
x += b[i][1]*(k-i) + cum[k]-cum[i]
#print(x,"bbb")
i, j = 1, k
min_i = 1
min_j = k
sum_i1 = x
for i in range(k+1,n+1):
#sum_i1 = sum_i1 - (cum[j]-cum[i] + ((k-1)*a[i])) + ( (k-1)*a[j+1] - (cum[j]-cum[i]) )
sum_i1 += (k-1) * b[i][1] - (cum[i-1]-cum[i-k])
sum_i1 -= (cum[i-1]-cum[i-k]) - ((k-1) * b[i-k][-1])
#print(sum_i1)
if sum_i1<x:
x = sum_i1
min_i = i
#print(b)
#print(min_i,min_j)
ans = [b[i][0] for i in range(min_i-k+1,min_i+1)]
print(*ans)
``` | instruction | 0 | 39,008 | 1 | 78,016 |
No | output | 1 | 39,008 | 1 | 78,017 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland is going through tough times β the dirt price has dropped and that is a blow to the country's economy. Everybody knows that Berland is the top world dirt exporter!
The President of Berland was forced to leave only k of the currently existing n subway stations.
The subway stations are located on a straight line one after another, the trains consecutively visit the stations as they move. You can assume that the stations are on the Ox axis, the i-th station is at point with coordinate xi. In such case the distance between stations i and j is calculated by a simple formula |xi - xj|.
Currently, the Ministry of Transport is choosing which stations to close and which ones to leave. Obviously, the residents of the capital won't be too enthusiastic about the innovation, so it was decided to show the best side to the people. The Ministry of Transport wants to choose such k stations that minimize the average commute time in the subway!
Assuming that the train speed is constant (it is a fixed value), the average commute time in the subway is calculated as the sum of pairwise distances between stations, divided by the number of pairs (that is <image>) and divided by the speed of the train.
Help the Minister of Transport to solve this difficult problem. Write a program that, given the location of the stations selects such k stations that the average commute time in the subway is minimized.
Input
The first line of the input contains integer n (3 β€ n β€ 3Β·105) β the number of the stations before the innovation. The second line contains the coordinates of the stations x1, x2, ..., xn ( - 108 β€ xi β€ 108). The third line contains integer k (2 β€ k β€ n - 1) β the number of stations after the innovation.
The station coordinates are distinct and not necessarily sorted.
Output
Print a sequence of k distinct integers t1, t2, ..., tk (1 β€ tj β€ n) β the numbers of the stations that should be left after the innovation in arbitrary order. Assume that the stations are numbered 1 through n in the order they are given in the input. The number of stations you print must have the minimum possible average commute time among all possible ways to choose k stations. If there are multiple such ways, you are allowed to print any of them.
Examples
Input
3
1 100 101
2
Output
2 3
Note
In the sample testcase the optimal answer is to destroy the first station (with x = 1). The average commute time will be equal to 1 in this way.
Submitted Solution:
```
from itertools import accumulate
n = int(input())
a = [int(x) for x in input().split()]
a.insert(0,-float("inf"))
k = int(input())
b = sorted(enumerate(a), key= lambda x:x[1])
cum = [0,b[1][1]]
for i in range(2,n+1):
cum.append(cum[i-1]+b[i][1])
#print(a,b,cum)
x = 0
for i in range(1,k+1):
x += a[i]*(i-1 ) - cum[i-1]
#print(x,"bbb")
i, j = 1, k
min_i = 1
min_j = k
sum_i1 = x
while i+k <= n:
#sum_i1 = sum_i1 - (cum[j]-cum[i] + ((k-1)*a[i])) + ( (k-1)*a[j+1] - (cum[j]-cum[i]) )
sum_i1 += (k-1) * a[j+1] - (cum[j]-cum[i])
sum_i1 -= (cum[j]-cum[i]) - ((k-1) * a[i])
#print(sum_i1)
if sum_i1<x:
x = sum_i1
min_i = i+1
min_j = j+1
i+=1
j+=1
#print(b)
#print(min_i,min_j)
ans = [b[i][0] for i in range(min_i,min_j+1)]
print(*ans)
``` | instruction | 0 | 39,009 | 1 | 78,018 |
No | output | 1 | 39,009 | 1 | 78,019 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently Duff has been a soldier in the army. Malek is her commander.
Their country, Andarz Gu has n cities (numbered from 1 to n) and n - 1 bidirectional roads. Each road connects two different cities. There exist a unique path between any two cities.
There are also m people living in Andarz Gu (numbered from 1 to m). Each person has and ID number. ID number of i - th person is i and he/she lives in city number ci. Note that there may be more than one person in a city, also there may be no people living in the city.
<image>
Malek loves to order. That's why he asks Duff to answer to q queries. In each query, he gives her numbers v, u and a.
To answer a query:
Assume there are x people living in the cities lying on the path from city v to city u. Assume these people's IDs are p1, p2, ..., px in increasing order.
If k = min(x, a), then Duff should tell Malek numbers k, p1, p2, ..., pk in this order. In the other words, Malek wants to know a minimums on that path (or less, if there are less than a people).
Duff is very busy at the moment, so she asked you to help her and answer the queries.
Input
The first line of input contains three integers, n, m and q (1 β€ n, m, q β€ 105).
The next n - 1 lines contain the roads. Each line contains two integers v and u, endpoints of a road (1 β€ v, u β€ n, v β u).
Next line contains m integers c1, c2, ..., cm separated by spaces (1 β€ ci β€ n for each 1 β€ i β€ m).
Next q lines contain the queries. Each of them contains three integers, v, u and a (1 β€ v, u β€ n and 1 β€ a β€ 10).
Output
For each query, print numbers k, p1, p2, ..., pk separated by spaces in one line.
Examples
Input
5 4 5
1 3
1 2
1 4
4 5
2 1 4 3
4 5 6
1 5 2
5 5 10
2 3 3
5 3 1
Output
1 3
2 2 3
0
3 1 2 4
1 2
Note
Graph of Andarz Gu in the sample case is as follows (ID of people in each city are written next to them):
<image>
Submitted Solution:
```
from sys import stdin,stdout
import math,sys
sys.setrecursionlimit(2*(10**5))
n,m,q=stdin.readline().strip().split(' ');n,m,q=int(n),int(m),int(q)
base2depth=int(math.log(n,2))
adj =[[] for i in range(n)]
cities=[[] for i in range(n)]
height=[-1 for i in range(n)]
p =[[-1 for j in range(base2depth)] for i in range(n+1)]
topten=[[[] for j in range(base2depth)] for i in range(n+1)]
for i in range(n-1):
v,u=stdin.readline().strip().split(' ');v,u=int(v),int(u)
adj[v-1].append(u-1);adj[u-1].append(v-1)
cit=list(map(int,stdin.readline().strip().split(' ')))
for i in range(len(cit)):
cities[cit[i]-1].append(i+1);
cities[cit[i]-1]=sorted(cities[cit[i]-1])[:10]
def dfs(currentnode,parentnode,h):
global adj,p,height,topten
height[currentnode]=h
if parentnode!=-1:
topten[currentnode][0]=cities[parentnode]
p[currentnode][0]=parentnode
for i in adj[currentnode]:
if i!=parentnode:
dfs(i,currentnode,h+1)
if n>1:
dfs(0,-1,0)
for j in range(1,base2depth):
for i in range(n):
if p[i][j-1]!=-1:
p[i][j]=p[p[i][j-1]][j-1];
topten[i][j]=sorted(topten[i][j-1]+topten[p[i][j-1]][j-1])[:10]
# for i in range(len(p)):
# print(p[i],' p[{0}]'.format(i))
# print('')
# for i in range(len(topten)):
# print(topten[i],' topten[{0}]'.format(i))
def mainstuff(v,u,a):
v,u=v-1,u-1
if height[v]<height[u]:
v,u=u,v
# V is always higher
diff = height[v]-height[u]
if diff==0:
if u!=v:
ansarr=cities[v]+cities[u]
for i in range(base2depth-1,-1,-1):
if p[u][i] != p[v][i]:
ansarr=sorted(ansarr+topten[v][i]+topten[u][i])[:a]
u=p[u][i]
v=p[v][i]
ansarr=sorted(ansarr+cities[p[u][0]])[:a]
else:
ansarr=cities[u][:a]
else:
ansarr=cities[v][:a]
#print(ansarr)
for i in range(0,base2depth):
if (diff>>i)&1:
#print(v,ansarr,"ohh")
ansarr=sorted(ansarr+topten[v][i])[:a]
v=p[v][i]
#print(ansarr)
if u!=v:
ansarr=sorted(ansarr+cities[u])[:a]
for i in range(base2depth-1,-1,-1):
if p[u][i] != p[v][i]:
ansarr=sorted(ansarr+topten[v][i]+topten[u][i])[:a]
u=p[u][i]
v=p[v][i]
ansarr=sorted(ansarr+cities[p[u][0]])[:a]
stdout.write(str(len(ansarr))+' ');
for i in range(len(ansarr)):
stdout.write(str(ansarr[i])+' ')
stdout.write('\n')
for _ in range(q):
v,u,a=map(int,stdin.readline().strip().split(' '))
mainstuff(v,u,a)
``` | instruction | 0 | 39,111 | 1 | 78,222 |
No | output | 1 | 39,111 | 1 | 78,223 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX β beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 β 2 β ... β n β 1. Formally, for every 1 β€ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 β€ i β€ n, i β x, there is a road between cities x and i.
5. There is at most one road between any two cities.
6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ciΒ·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products caΒ·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 β€ n β€ 100 000, 1 β€ k β€ n) β the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 β€ ci β€ 10 000) β beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 β€ idi β€ n) β indices of capital cities. Indices are given in ascending order.
Output
Print the only integer β summary price of passing each of the roads in XXX.
Examples
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Note
This image describes first sample case:
<image>
It is easy to see that summary price is equal to 17.
This image describes second sample case:
<image>
It is easy to see that summary price is equal to 71. | instruction | 0 | 39,164 | 1 | 78,328 |
Tags: implementation, math
Correct Solution:
```
n, k = map(int, input().split())
c = list(map(int, input().split()))
d = set(map(int, input().split()))
s = 0
s0 = sum(c)
for i in d:
s0 -= c[i - 1]
s += c[i - 1] * s0
for i in range(n):
if i + 1 not in d and (i + 1) % n + 1 not in d:
s += c[i] * c[(i + 1) % n]
print(s)
``` | output | 1 | 39,164 | 1 | 78,329 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX β beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 β 2 β ... β n β 1. Formally, for every 1 β€ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 β€ i β€ n, i β x, there is a road between cities x and i.
5. There is at most one road between any two cities.
6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ciΒ·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products caΒ·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 β€ n β€ 100 000, 1 β€ k β€ n) β the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 β€ ci β€ 10 000) β beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 β€ idi β€ n) β indices of capital cities. Indices are given in ascending order.
Output
Print the only integer β summary price of passing each of the roads in XXX.
Examples
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Note
This image describes first sample case:
<image>
It is easy to see that summary price is equal to 17.
This image describes second sample case:
<image>
It is easy to see that summary price is equal to 71. | instruction | 0 | 39,165 | 1 | 78,330 |
Tags: implementation, math
Correct Solution:
```
n, k = map(int, input().split())
c = list(map(int, input().split()))
v = set(map(int, input().split()))
sum_beuty = sum(c)
ans = 0
for i in v:
sum_beuty -= c[i - 1]
ans += c[i - 1] * (sum_beuty)
c[i - 1] = 0
for i in range(n):
ans += c[i] * c[(i + 1) % n]
print(ans)
``` | output | 1 | 39,165 | 1 | 78,331 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX β beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 β 2 β ... β n β 1. Formally, for every 1 β€ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 β€ i β€ n, i β x, there is a road between cities x and i.
5. There is at most one road between any two cities.
6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ciΒ·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products caΒ·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 β€ n β€ 100 000, 1 β€ k β€ n) β the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 β€ ci β€ 10 000) β beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 β€ idi β€ n) β indices of capital cities. Indices are given in ascending order.
Output
Print the only integer β summary price of passing each of the roads in XXX.
Examples
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Note
This image describes first sample case:
<image>
It is easy to see that summary price is equal to 17.
This image describes second sample case:
<image>
It is easy to see that summary price is equal to 71. | instruction | 0 | 39,166 | 1 | 78,332 |
Tags: implementation, math
Correct Solution:
```
n,k=map(int,input().split())
c=list(map(int,input().split()))
s=set(map(int,input().split()))
sust=sum(c)
su=0
for i in s:
sust-=c[i-1]
su+=c[i-1]*sust
for i in range(n):
if (i+1 not in s) and ((i+1)%n+1 not in s):
su+=c[i]*c[(i+1)%n]
print(su)
``` | output | 1 | 39,166 | 1 | 78,333 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX β beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 β 2 β ... β n β 1. Formally, for every 1 β€ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 β€ i β€ n, i β x, there is a road between cities x and i.
5. There is at most one road between any two cities.
6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ciΒ·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products caΒ·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 β€ n β€ 100 000, 1 β€ k β€ n) β the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 β€ ci β€ 10 000) β beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 β€ idi β€ n) β indices of capital cities. Indices are given in ascending order.
Output
Print the only integer β summary price of passing each of the roads in XXX.
Examples
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Note
This image describes first sample case:
<image>
It is easy to see that summary price is equal to 17.
This image describes second sample case:
<image>
It is easy to see that summary price is equal to 71. | instruction | 0 | 39,167 | 1 | 78,334 |
Tags: implementation, math
Correct Solution:
```
#!/usr/bin/env python
#-*-coding:utf-8 -*-
n,k=map(int,input().split())
W=tuple(map(int,input().split()))
F=n*[True]
s=0
k=sum(W)
for c in map(int,input().split()):
F[c-1]=False
w=W[c-1]
k-=w
s+=w*k
for i in range(n):
j=(1+i)%n
if F[i] and F[j]:s+=W[i]*W[j]
print(s)
``` | output | 1 | 39,167 | 1 | 78,335 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX β beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 β 2 β ... β n β 1. Formally, for every 1 β€ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 β€ i β€ n, i β x, there is a road between cities x and i.
5. There is at most one road between any two cities.
6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ciΒ·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products caΒ·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 β€ n β€ 100 000, 1 β€ k β€ n) β the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 β€ ci β€ 10 000) β beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 β€ idi β€ n) β indices of capital cities. Indices are given in ascending order.
Output
Print the only integer β summary price of passing each of the roads in XXX.
Examples
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Note
This image describes first sample case:
<image>
It is easy to see that summary price is equal to 17.
This image describes second sample case:
<image>
It is easy to see that summary price is equal to 71. | instruction | 0 | 39,168 | 1 | 78,336 |
Tags: implementation, math
Correct Solution:
```
n, k = map(int, input().split())
cost = list(map(int, input().split()))
capital = set(map(int, input().split()))
ans = 0
for i in range(1, n):
g = set()
if i not in capital:
if i == 1:
g = set([i + 1, n]) - capital
temp = [cost[i - 1] for i in g]
ans += cost[i - 1] * sum(temp)
else:
g = set([i + 1]) - capital
temp = [cost[i - 1] for i in g]
ans += cost[i - 1] * sum(temp)
b = sum(cost)
for i in capital:
b -= cost[i - 1]
ans += cost[i - 1] * b
print(ans)
``` | output | 1 | 39,168 | 1 | 78,337 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX β beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 β 2 β ... β n β 1. Formally, for every 1 β€ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 β€ i β€ n, i β x, there is a road between cities x and i.
5. There is at most one road between any two cities.
6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ciΒ·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products caΒ·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 β€ n β€ 100 000, 1 β€ k β€ n) β the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 β€ ci β€ 10 000) β beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 β€ idi β€ n) β indices of capital cities. Indices are given in ascending order.
Output
Print the only integer β summary price of passing each of the roads in XXX.
Examples
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Note
This image describes first sample case:
<image>
It is easy to see that summary price is equal to 17.
This image describes second sample case:
<image>
It is easy to see that summary price is equal to 71. | instruction | 0 | 39,169 | 1 | 78,338 |
Tags: implementation, math
Correct Solution:
```
n, k = map(int, input().split())
prices = list(map(int, input().split()))
st = list(map(int, input().split()))
for i in range(k):
st[i] -= 1
ans = 0
used = 0
useds = set()
s = sum(prices)
for i in range(n):
ans += prices[i] * prices[i - 1]
for i in range(k):
ans += s * prices[st[i]] - prices[st[i]] * used
ans -= prices[st[i]] * (prices[st[i]] + prices[st[i] - 1] + prices[(st[i] + 1) % n])
if (st[i] - 1) % n in useds:
ans += prices[st[i]] * prices[st[i] - 1]
if (st[i] + 1) % n in useds:
ans += prices[st[i]] * prices[(st[i] + 1) % n]
used += prices[st[i]]
useds.add(st[i])
print(ans)
``` | output | 1 | 39,169 | 1 | 78,339 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX β beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 β 2 β ... β n β 1. Formally, for every 1 β€ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 β€ i β€ n, i β x, there is a road between cities x and i.
5. There is at most one road between any two cities.
6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ciΒ·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products caΒ·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 β€ n β€ 100 000, 1 β€ k β€ n) β the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 β€ ci β€ 10 000) β beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 β€ idi β€ n) β indices of capital cities. Indices are given in ascending order.
Output
Print the only integer β summary price of passing each of the roads in XXX.
Examples
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Note
This image describes first sample case:
<image>
It is easy to see that summary price is equal to 17.
This image describes second sample case:
<image>
It is easy to see that summary price is equal to 71. | instruction | 0 | 39,170 | 1 | 78,340 |
Tags: implementation, math
Correct Solution:
```
n, k = map(int, input().split())
l = list(map(int, input().split()))
cit = list(map(int, input().split()))
'''
# a good approach but not sufficient for the time limit
ans = 0
ans_set = set()
for i in range(n - 1):
ans_set.add((i, i + 1))
ans_set.add((0, n - 1))
for i in range(k):
bfc = cit[i] - 1
for ii in range(n):
if ii == bfc:
continue
else:
ans_set.add((min(bfc, ii), max(bfc, ii)))
for i in ans_set:
ii, jj = i
ans += l[ii] * l[jj]
print(ans)
'''
ans = 0
sum_ = sum(l)
for i in range(k):
sum_ -= l[cit[i] - 1]
ans += sum_ * l[cit[i] - 1]
cit = set(cit)
for i in range(n - 1):
if (i + 1) not in cit and (i + 2) not in cit:
ans += l[i] * l[i + 1]
if 1 not in cit and n not in cit:
ans += l[0] * l[-1]
print(ans)
``` | output | 1 | 39,170 | 1 | 78,341 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX β beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 β 2 β ... β n β 1. Formally, for every 1 β€ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 β€ i β€ n, i β x, there is a road between cities x and i.
5. There is at most one road between any two cities.
6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ciΒ·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products caΒ·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 β€ n β€ 100 000, 1 β€ k β€ n) β the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 β€ ci β€ 10 000) β beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 β€ idi β€ n) β indices of capital cities. Indices are given in ascending order.
Output
Print the only integer β summary price of passing each of the roads in XXX.
Examples
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Note
This image describes first sample case:
<image>
It is easy to see that summary price is equal to 17.
This image describes second sample case:
<image>
It is easy to see that summary price is equal to 71. | instruction | 0 | 39,171 | 1 | 78,342 |
Tags: implementation, math
Correct Solution:
```
n, m = map(int,input().split())
cost = list(map(int,input().split()))
iscapi = [False]*n
capi = list(map(lambda x:int(x)-1,input().split()))
#print(capi)
for i in capi:
iscapi[i] = True
tot = 0
sumi = 0
for i in range(0,n):
if not iscapi[i] and not iscapi[(i+1)%n]:
tot += cost[i]*cost[(i+1)%n]
#print(tot)
price = [cost[i] for i in capi]
#print(price)
for i in range(m-2,-1,-1):
price[i] += price[i+1]
#print(price)
for i in range(m-1):
tot += cost[capi[i]]*price[i+1]
#print(tot)
for i in range(n):
if not iscapi[i]:
sumi += cost[i]
#print(sumi)
for i in capi:
tot += cost[i]*sumi
print(tot)
``` | output | 1 | 39,171 | 1 | 78,343 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX β beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 β 2 β ... β n β 1. Formally, for every 1 β€ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 β€ i β€ n, i β x, there is a road between cities x and i.
5. There is at most one road between any two cities.
6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ciΒ·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products caΒ·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 β€ n β€ 100 000, 1 β€ k β€ n) β the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 β€ ci β€ 10 000) β beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 β€ idi β€ n) β indices of capital cities. Indices are given in ascending order.
Output
Print the only integer β summary price of passing each of the roads in XXX.
Examples
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Note
This image describes first sample case:
<image>
It is easy to see that summary price is equal to 17.
This image describes second sample case:
<image>
It is easy to see that summary price is equal to 71.
Submitted Solution:
```
n, k = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
s = sum(c)
m = 0
for i in range(k):
d[i] -= 1
s -= c[d[i]]
m += c[d[i]] * s
c[d[i]] = 0
for i in range(n):
m += c[i] * c[(i + 1) % n]
print(m)
``` | instruction | 0 | 39,172 | 1 | 78,344 |
Yes | output | 1 | 39,172 | 1 | 78,345 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX β beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 β 2 β ... β n β 1. Formally, for every 1 β€ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 β€ i β€ n, i β x, there is a road between cities x and i.
5. There is at most one road between any two cities.
6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ciΒ·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products caΒ·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 β€ n β€ 100 000, 1 β€ k β€ n) β the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 β€ ci β€ 10 000) β beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 β€ idi β€ n) β indices of capital cities. Indices are given in ascending order.
Output
Print the only integer β summary price of passing each of the roads in XXX.
Examples
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Note
This image describes first sample case:
<image>
It is easy to see that summary price is equal to 17.
This image describes second sample case:
<image>
It is easy to see that summary price is equal to 71.
Submitted Solution:
```
n, k = map(int,input().split())
A = list(map(int,input().split()))
cap = set(map(int,input().split()))
price = res = 0
for i in range(len(A)):
if (i+1) not in cap and ((i+1)%n)+1 not in cap:
price = A[i]*A[(i+1)%n]
res += price
price = sum(A)
for i in cap:
price -= A[i-1]
res += price*A[i-1]
print(res)
# price += A[0]*A[n-1]
# print(price)
# # L = list(map(int, input().split()))
``` | instruction | 0 | 39,173 | 1 | 78,346 |
Yes | output | 1 | 39,173 | 1 | 78,347 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX β beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 β 2 β ... β n β 1. Formally, for every 1 β€ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 β€ i β€ n, i β x, there is a road between cities x and i.
5. There is at most one road between any two cities.
6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ciΒ·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products caΒ·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 β€ n β€ 100 000, 1 β€ k β€ n) β the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 β€ ci β€ 10 000) β beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 β€ idi β€ n) β indices of capital cities. Indices are given in ascending order.
Output
Print the only integer β summary price of passing each of the roads in XXX.
Examples
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Note
This image describes first sample case:
<image>
It is easy to see that summary price is equal to 17.
This image describes second sample case:
<image>
It is easy to see that summary price is equal to 71.
Submitted Solution:
```
n,k=map(int,input().split())
l=list(map(int,input().split()))
ls=list(map(int,input().split()))
ans=0
su=sum(l)
for x in ls:
su-=l[x-1]
ans+=l[x-1]*(su)
l[x-1]=0
for i in range(n):
if i==n-1:
ans+=l[i]*l[0]
else:
ans+=l[i]*l[i+1]
print(ans)
``` | instruction | 0 | 39,174 | 1 | 78,348 |
Yes | output | 1 | 39,174 | 1 | 78,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX β beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 β 2 β ... β n β 1. Formally, for every 1 β€ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 β€ i β€ n, i β x, there is a road between cities x and i.
5. There is at most one road between any two cities.
6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ciΒ·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products caΒ·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 β€ n β€ 100 000, 1 β€ k β€ n) β the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 β€ ci β€ 10 000) β beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 β€ idi β€ n) β indices of capital cities. Indices are given in ascending order.
Output
Print the only integer β summary price of passing each of the roads in XXX.
Examples
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Note
This image describes first sample case:
<image>
It is easy to see that summary price is equal to 17.
This image describes second sample case:
<image>
It is easy to see that summary price is equal to 71.
Submitted Solution:
```
import math
N, K = [int(x) for x in input().split()]
res = 0
sum = 0
arr = [int(x) for x in input().split()]
arrK = [int(x) - 1 for x in input().split()]
for i in range(0, N):
res += arr[i] * arr[i - 1]
sum += arr[i]
dictU = {}
used = 0
for i in arrK:
cur = i
if cur == 0:
pre = N-1
else:
pre = cur - 1
if cur == N-1:
next = 0
else:
next = cur + 1
tmp = 0
if pre in dictU:
tmp += arr[pre]
if next in dictU:
tmp += arr[next]
test = arr[cur] * (sum - arr[cur] - arr[pre] - arr[next] - used + tmp)
res += test
dictU[cur] = True
#print(res, test, cur)
used += arr[cur]
print(res)
``` | instruction | 0 | 39,175 | 1 | 78,350 |
Yes | output | 1 | 39,175 | 1 | 78,351 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX β beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 β 2 β ... β n β 1. Formally, for every 1 β€ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 β€ i β€ n, i β x, there is a road between cities x and i.
5. There is at most one road between any two cities.
6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ciΒ·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products caΒ·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 β€ n β€ 100 000, 1 β€ k β€ n) β the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 β€ ci β€ 10 000) β beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 β€ idi β€ n) β indices of capital cities. Indices are given in ascending order.
Output
Print the only integer β summary price of passing each of the roads in XXX.
Examples
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Note
This image describes first sample case:
<image>
It is easy to see that summary price is equal to 17.
This image describes second sample case:
<image>
It is easy to see that summary price is equal to 71.
Submitted Solution:
```
n, k = map(int, input().split())
C = [0] + list(map(int, input().split()))
K = list(map(int, input().split()))
W = [set() for i in range(n + 1)]
summa = C[1] * C[-1]
W[1].add(n)
W[n].add(1)
for i in range(1, n):
if i not in W[i + 1] and (i + 1) not in W[i] :
W[i].add(i + 1)
W[i + 1].add(i )
summa += C[i] * C[i + 1]
for elem in K:
if i not in W[elem] and elem not in W[i] and elem != i:
W[elem].add(i)
W[i].add(elem )
summa += C[i] * C[elem]
print(summa)
``` | instruction | 0 | 39,176 | 1 | 78,352 |
No | output | 1 | 39,176 | 1 | 78,353 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX β beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 β 2 β ... β n β 1. Formally, for every 1 β€ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 β€ i β€ n, i β x, there is a road between cities x and i.
5. There is at most one road between any two cities.
6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ciΒ·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products caΒ·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 β€ n β€ 100 000, 1 β€ k β€ n) β the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 β€ ci β€ 10 000) β beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 β€ idi β€ n) β indices of capital cities. Indices are given in ascending order.
Output
Print the only integer β summary price of passing each of the roads in XXX.
Examples
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Note
This image describes first sample case:
<image>
It is easy to see that summary price is equal to 17.
This image describes second sample case:
<image>
It is easy to see that summary price is equal to 71.
Submitted Solution:
```
n, k = (int(x) for x in input().split(' '))
cs = [int(x) for x in input().split(' ')]
capitals = [int(x) - 1 for x in input().split(' ')]
cap_set = set(capitals)
price = 0
for i in range(n - 1):
price += cs[i]*cs[i + 1]
price += cs[n - 1]*cs[0]
c_sum = sum(cs)
cap_c_sum = sum((cs[i] for i in capitals))
for i in capitals:
if i != 0:
left = i - 1
else:
left = n - 1
if i != n - 1:
right = i + 1
else:
right = 0
if left in cap_set:
cleft = 0
else:
cleft = cs[left]
if right in cap_set:
cright = 0
else:
cright = cs[right]
price += cs[i]*(c_sum - cap_c_sum - cleft - cright)
for i in capitals:
cap_c_sum -= cs[i]
if i != n - 1:
if i + 1 in cap_set:
price -= cs[i]*(cap_c_sum - cs[i + 1])
else:
price -= cs[i]*cap_c_sum
print(price)
``` | instruction | 0 | 39,177 | 1 | 78,354 |
No | output | 1 | 39,177 | 1 | 78,355 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX β beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 β 2 β ... β n β 1. Formally, for every 1 β€ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 β€ i β€ n, i β x, there is a road between cities x and i.
5. There is at most one road between any two cities.
6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ciΒ·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products caΒ·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 β€ n β€ 100 000, 1 β€ k β€ n) β the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 β€ ci β€ 10 000) β beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 β€ idi β€ n) β indices of capital cities. Indices are given in ascending order.
Output
Print the only integer β summary price of passing each of the roads in XXX.
Examples
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Note
This image describes first sample case:
<image>
It is easy to see that summary price is equal to 17.
This image describes second sample case:
<image>
It is easy to see that summary price is equal to 71.
Submitted Solution:
```
from sys import stdin
n, k = map(int, input().split())
our = list(map(int, input().split()))
cap = set(map(int, input().split()))
res = int()
sum_b = sum(our)
for elem in cap:
sum_b -= our[elem - 1]
res += sum_b * our[elem - 1]
for i in range(len(our)):
if (i+1) not in cap and (i+1) % 4 + 1 not in cap:
res += our[i] * our[(i + 1) % n]
print(res)
``` | instruction | 0 | 39,178 | 1 | 78,356 |
No | output | 1 | 39,178 | 1 | 78,357 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX β beautiful, but little-known northern country.
Here are some interesting facts about XXX:
1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 β 2 β ... β n β 1. Formally, for every 1 β€ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 β€ i β€ n, i β x, there is a road between cities x and i.
5. There is at most one road between any two cities.
6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ciΒ·cj.
Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products caΒ·cb. Will you help her?
Input
The first line of the input contains two integers n and k (3 β€ n β€ 100 000, 1 β€ k β€ n) β the number of cities in XXX and the number of capital cities among them.
The second line of the input contains n integers c1, c2, ..., cn (1 β€ ci β€ 10 000) β beauty values of the cities.
The third line of the input contains k distinct integers id1, id2, ..., idk (1 β€ idi β€ n) β indices of capital cities. Indices are given in ascending order.
Output
Print the only integer β summary price of passing each of the roads in XXX.
Examples
Input
4 1
2 3 1 2
3
Output
17
Input
5 2
3 5 2 2 4
1 4
Output
71
Note
This image describes first sample case:
<image>
It is easy to see that summary price is equal to 17.
This image describes second sample case:
<image>
It is easy to see that summary price is equal to 71.
Submitted Solution:
```
n, k = [int(x) for x in input().split(' ')]
ci = [int(x) for x in input().split(' ')]
id = [int(x) for x in input().split(' ')]
s = sum(ci)
ci = [ci[n-1]] + ci + [ci[0]]
c = 0
for i in range(1,n+1):
c += ci[i] * ci[i+1]
for kk in id:
c += (s-ci[kk]-ci[kk+1]-ci[kk-1]) * ci[kk]
for i in range(k):
ii = id[i]
for j in range(i+1, k):
jj = id[j]
if abs(ii - jj) == 1: continue
c -= ci[ii] * ci[jj]
print(c)
``` | instruction | 0 | 39,179 | 1 | 78,358 |
No | output | 1 | 39,179 | 1 | 78,359 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.
Input
The first line contains three integers r, g and b (0 β€ r, g, b β€ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.
Output
Print a single number β the minimal time the students need for the whole group to ascend to the top of the mountain.
Examples
Input
1 3 2
Output
34
Input
3 2 1
Output
33
Note
Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes. | instruction | 0 | 39,307 | 1 | 78,614 |
Tags: greedy, math
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Sun May 16 11:57:20 2021
@author: artur
"""
colors = list(map(int,input().split()))
red = colors[0]
blue = colors[1]
green = colors[2]
time = 29
# and ((blue > 0) or (green > 0)):
while (red > 0) or (blue > 0) or (green > 0):
if (red > 0) :
#and ((blue > 0) or (green > 0)):
red -= 2
time += 1
# elif (red > 0) and ((blue <= 0) or (green <= 0)):
# if red-2 > 1:
# while red-2 > 1:
# red -= 2
# time += 3
# else:
# red -= 2
# time += 1
elif (red <= 0) and ((blue > 0) or (green > 0)):
time += 1
if (blue > 0):
#and ((green > 0) or (red > 0)):
blue -= 2
time += 1
# elif (blue > 0) and ((green <= 0) or (red <= 0)):
# if blue-2 > 1:
# while blue-2 > 1:
# blue -= 2
# time += 3
# else:
# blue -= 2
# time += 1
elif (blue <= 0) and ((green > 0) or (red > 0)):
time += 1
if (green > 0):
#and ((red > 0) or (blue > 0)):
green -= 2
time += 1
# elif (green > 0) and ((red <= 0) or (blue <= 0)):
# if green-2 > 1:
# while green-2 > 1:
# green -= 2
# time += 3
# else:
# green -= 2
# time += 1
elif (green <= 0) and ((red > 0) or (blue > 0)):
time += 1
print(time)
``` | output | 1 | 39,307 | 1 | 78,615 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.
Input
The first line contains three integers r, g and b (0 β€ r, g, b β€ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.
Output
Print a single number β the minimal time the students need for the whole group to ascend to the top of the mountain.
Examples
Input
1 3 2
Output
34
Input
3 2 1
Output
33
Note
Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes. | instruction | 0 | 39,308 | 1 | 78,616 |
Tags: greedy, math
Correct Solution:
```
a=list(map(int,input().split()))
a=list(map(lambda a:a//2+ 1*(a%2!=0),a))
print(max(((a[i]-1)*3)+1+i for i in range(3))+29)
``` | output | 1 | 39,308 | 1 | 78,617 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.
Input
The first line contains three integers r, g and b (0 β€ r, g, b β€ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.
Output
Print a single number β the minimal time the students need for the whole group to ascend to the top of the mountain.
Examples
Input
1 3 2
Output
34
Input
3 2 1
Output
33
Note
Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes. | instruction | 0 | 39,309 | 1 | 78,618 |
Tags: greedy, math
Correct Solution:
```
r,g,b=map(int,input().split())
kr,kg,kb=r//2+r%2,g//2+g%2,b//2+b%2
print(max((kr-1)*3+30,(kg-1)*3+31,(kb-1)*3+32))
``` | output | 1 | 39,309 | 1 | 78,619 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.
Input
The first line contains three integers r, g and b (0 β€ r, g, b β€ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.
Output
Print a single number β the minimal time the students need for the whole group to ascend to the top of the mountain.
Examples
Input
1 3 2
Output
34
Input
3 2 1
Output
33
Note
Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes. | instruction | 0 | 39,310 | 1 | 78,620 |
Tags: greedy, math
Correct Solution:
```
r, g, b = map(int, input().split())
a = 0
r = ((r//2) + (r%2) - 1) * 3 + 1
g = ((g//2) + (g%2) - 1) * 3 + 2
b = ((b//2) + (b%2) - 1) * 3 + 3
a = max(r, max(g,b)) + 29
print(a)
``` | output | 1 | 39,310 | 1 | 78,621 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.
Input
The first line contains three integers r, g and b (0 β€ r, g, b β€ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.
Output
Print a single number β the minimal time the students need for the whole group to ascend to the top of the mountain.
Examples
Input
1 3 2
Output
34
Input
3 2 1
Output
33
Note
Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes. | instruction | 0 | 39,311 | 1 | 78,622 |
Tags: greedy, math
Correct Solution:
```
R, G, B = map(int, input().split())
ans = 30
if R % 2 == 0:
x1 = R // 2
else:
x1 = R // 2 + 1
if G % 2 == 0:
x2 = G // 2
else:
x2 = G // 2 + 1
if B % 2 == 0:
x3 = B // 2
else:
x3 = B // 2 + 1
if x3 == max([x1,x2,x3]):
ans += x3 * 3 - 1
elif x2 == max([x1, x2, x3]):
ans += x2 * 3 - 2
else:
ans += x1 * 3 - 3
print(ans)
``` | output | 1 | 39,311 | 1 | 78,623 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.
Input
The first line contains three integers r, g and b (0 β€ r, g, b β€ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.
Output
Print a single number β the minimal time the students need for the whole group to ascend to the top of the mountain.
Examples
Input
1 3 2
Output
34
Input
3 2 1
Output
33
Note
Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes. | instruction | 0 | 39,312 | 1 | 78,624 |
Tags: greedy, math
Correct Solution:
```
r,g,b = map(int,input().split())
def f1(r):
if r%2 == 0:
x=3*(r/2-1)
else:
x=3*int(r//2)
return x
print(int(max(f1(r),f1(g)+1,f1(b)+2) + 30))
``` | output | 1 | 39,312 | 1 | 78,625 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.
Input
The first line contains three integers r, g and b (0 β€ r, g, b β€ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.
Output
Print a single number β the minimal time the students need for the whole group to ascend to the top of the mountain.
Examples
Input
1 3 2
Output
34
Input
3 2 1
Output
33
Note
Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes. | instruction | 0 | 39,313 | 1 | 78,626 |
Tags: greedy, math
Correct Solution:
```
r,g,b=list(map(int,input().split()))
r=r//2+r%2
g=g//2+g%2
b=b//2+b%2
r=(r-1)*3+30
g=(g-1)*3+31
b=(b-1)*3+32
print(max(r,b,g))
``` | output | 1 | 39,313 | 1 | 78,627 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.
Input
The first line contains three integers r, g and b (0 β€ r, g, b β€ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.
Output
Print a single number β the minimal time the students need for the whole group to ascend to the top of the mountain.
Examples
Input
1 3 2
Output
34
Input
3 2 1
Output
33
Note
Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes. | instruction | 0 | 39,314 | 1 | 78,628 |
Tags: greedy, math
Correct Solution:
```
import sys
import math
import bisect
import itertools
import random
import re
def main():
r, g, b = map(int, input().split())
max_val = 0
if r:
val = ((r + 1) // 2 - 1) * 3 + 30
max_val = max(max_val, val)
if g:
val = ((g + 1) // 2 - 1) * 3 + 1 + 30
max_val = max(max_val, val)
if b:
val = ((b + 1) // 2 - 1) * 3 + 2 + 30
max_val = max(max_val, val)
print(max_val)
if __name__ == "__main__":
main()
``` | output | 1 | 39,314 | 1 | 78,629 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.
Input
The first line contains three integers r, g and b (0 β€ r, g, b β€ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.
Output
Print a single number β the minimal time the students need for the whole group to ascend to the top of the mountain.
Examples
Input
1 3 2
Output
34
Input
3 2 1
Output
33
Note
Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes.
Submitted Solution:
```
import sys,math
order = list(map(int,sys.stdin.readline().split()))
m = -1
seq = 0
for i in range(3):
temp = math.ceil(order[i]/2)-1
if m<=temp:
m = temp
seq = i
print(30+m*3+seq)
``` | instruction | 0 | 39,315 | 1 | 78,630 |
Yes | output | 1 | 39,315 | 1 | 78,631 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.
Input
The first line contains three integers r, g and b (0 β€ r, g, b β€ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.
Output
Print a single number β the minimal time the students need for the whole group to ascend to the top of the mountain.
Examples
Input
1 3 2
Output
34
Input
3 2 1
Output
33
Note
Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes.
Submitted Solution:
```
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
r, g, b = map(int, input().split())
ans = max(
(((r + 1) // 2) - 1) * 3,
(((g + 1) // 2) - 1) * 3 + 1 if g else 0,
(((b + 1) // 2) - 1) * 3 + 2 if b else 0
) + 30
print(ans)
``` | instruction | 0 | 39,316 | 1 | 78,632 |
Yes | output | 1 | 39,316 | 1 | 78,633 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.
Input
The first line contains three integers r, g and b (0 β€ r, g, b β€ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.
Output
Print a single number β the minimal time the students need for the whole group to ascend to the top of the mountain.
Examples
Input
1 3 2
Output
34
Input
3 2 1
Output
33
Note
Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes.
Submitted Solution:
```
cablecars = [(int(color) + 1) // 2 for color in input().split(' ')]
cars_needed = max(cablecars)
position = 2 - cablecars[::-1].index(cars_needed)
print(position + (cars_needed - 1) * 3 + 30)
``` | instruction | 0 | 39,317 | 1 | 78,634 |
Yes | output | 1 | 39,317 | 1 | 78,635 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.
Input
The first line contains three integers r, g and b (0 β€ r, g, b β€ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.
Output
Print a single number β the minimal time the students need for the whole group to ascend to the top of the mountain.
Examples
Input
1 3 2
Output
34
Input
3 2 1
Output
33
Note
Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes.
Submitted Solution:
```
import math
m = 0
p = 0
for pos, i in enumerate(map(int, input().split())):
if math.ceil(i/2) >= m:
m = math.ceil(i/2)
p = pos
print((m-1)*3 + p + 30)
``` | instruction | 0 | 39,318 | 1 | 78,636 |
Yes | output | 1 | 39,318 | 1 | 78,637 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.
Input
The first line contains three integers r, g and b (0 β€ r, g, b β€ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.
Output
Print a single number β the minimal time the students need for the whole group to ascend to the top of the mountain.
Examples
Input
1 3 2
Output
34
Input
3 2 1
Output
33
Note
Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes.
Submitted Solution:
```
import math
r,g,b=map(int,input().split())
r,g,b=math.ceil(r/2),math.ceil(g/2),math.ceil(b/2)
large=max(r,g,b)
if(large==0):
print("0")
elif(large==b and b>0):
print(32+3*(b-1))
elif(large==g and g>0):
print(32+2*(g-1))
else:
print(r+31)
``` | instruction | 0 | 39,319 | 1 | 78,638 |
No | output | 1 | 39,319 | 1 | 78,639 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.
Input
The first line contains three integers r, g and b (0 β€ r, g, b β€ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.
Output
Print a single number β the minimal time the students need for the whole group to ascend to the top of the mountain.
Examples
Input
1 3 2
Output
34
Input
3 2 1
Output
33
Note
Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes.
Submitted Solution:
```
r, g, b = map(int, input().split())
if max(r,g,b) == b:
print(29 + 3 * (b//2 + b % 2))
elif max(r,g,b) == g:
print(28 + 3 * (g//2 + g % 2))
else:
print(27 + 3 * (r//2 + r % 2))
``` | instruction | 0 | 39,320 | 1 | 78,640 |
No | output | 1 | 39,320 | 1 | 78,641 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.
Input
The first line contains three integers r, g and b (0 β€ r, g, b β€ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.
Output
Print a single number β the minimal time the students need for the whole group to ascend to the top of the mountain.
Examples
Input
1 3 2
Output
34
Input
3 2 1
Output
33
Note
Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes.
Submitted Solution:
```
r,g,b=map(int,input().split())
ans=30+3*((r+1)/2-1)
if g:
ans=max (ans, 31 + 3*((g+1)/2-1))
if b:
ans = max (ans, 32 + 3*((b+1)/2-1))
print(ans)
``` | instruction | 0 | 39,321 | 1 | 78,642 |
No | output | 1 | 39,321 | 1 | 78,643 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.
The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.
All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,
The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.
Input
The first line contains three integers r, g and b (0 β€ r, g, b β€ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.
Output
Print a single number β the minimal time the students need for the whole group to ascend to the top of the mountain.
Examples
Input
1 3 2
Output
34
Input
3 2 1
Output
33
Note
Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.
At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.
At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.
At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.
Thus, all the students are on the top, overall the ascension took exactly 34 minutes.
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Sun May 16 11:57:20 2021
@author: artur
"""
colors = list(map(int,input().split()))
red = colors[0]
blue = colors[1]
green = colors[2]
time = 29
# and ((blue > 0) or (green > 0)):
while (red > 0) or (blue > 0) or (green > 0):
if (red > 0) and ((blue > 0) or (green > 0)):
red -= 2
time += 1
elif (red > 0) and ((blue <= 0) or (green <= 0)):
if red-2 > 1:
while red-2 > 1:
red -= 2
time += 3
else:
red -= 2
time += 1
elif (red < 0) and ((blue > 0) or (green > 0)):
time += 1
if (blue > 0) and ((green > 0) or (red > 0)):
blue -= 2
time += 1
elif (blue > 0) and ((green <= 0) or (red <= 0)):
if blue-2 > 1:
while blue-2 > 1:
blue -= 2
time += 3
else:
blue -= 2
time += 1
elif (blue < 0) and ((green > 0) or (red > 0)):
time += 1
if (green > 0) and ((red > 0) or (blue > 0)):
green -= 2
time += 1
elif (green > 0) and ((red <= 0) or (blue <= 0)):
if green-2 > 1:
while green-2 > 1:
green -= 2
time += 3
else:
green -= 2
time += 1
elif (green < 0) and ((red > 0) or (blue > 0)):
time += 1
``` | instruction | 0 | 39,322 | 1 | 78,644 |
No | output | 1 | 39,322 | 1 | 78,645 |
Provide a correct Python 3 solution for this coding contest problem.
There are trains with 26 cars or less. Each vehicle has an identification code from lowercase a to z. No vehicle has the same symbol. However, the order in which the vehicles are connected is arbitrary. The conductor patrols the train. The conductor patrolls back and forth in the train, so he may pass through the same vehicle many times. However, all vehicles shall be patrolled at least once. In addition, the vehicle that starts the patrol and the vehicle that finishes the patrol is not necessarily the vehicle at the end of the train.
There is a patrol record of all the trains on which an Aru Shashou is on board. Create a program that outputs the formation of each train that can be seen from it from the lead car. The patrol record corresponds to one train per line. Each line consists of a string of lowercase letters separated by <-or->. <-Represents a move to a vehicle in front, and-> represents a move to a vehicle behind.
For example, a-> b <-a <-c means that vehicle a has moved to the vehicle behind b, b has moved to a ahead, and a has moved to c ahead. In this case, the train formation will be cab from the first car.
Input
The number of patrol records n (n β€ 50) is given to the first line, and the character string si (half-width character string up to 1024 characters) representing the patrol record i is given to the following n lines.
Output
For patrol record i, output the character string indicating the formation of the train from the first car on the i-line.
Examples
Input
4
a->e->c->b->d
b
Output
aecbd
edacb
bacde
bcdae
Input
4
a->e->c->b->d
b<-c<-a<-d<-e
b->a->c<-a->c->d<-c<-a<-b->a->c->d->e<-d
a->e<-a<-d->a->e<-a<-d<-c->d->a<-d<-c<-b->c->d<-c
Output
aecbd
edacb
bacde
bcdae | instruction | 0 | 39,520 | 1 | 79,040 |
"Correct Solution:
```
inputCount = int(input())
for _ in range(inputCount):
inputContent = input()
trainOrder = [item for item in inputContent if str.isalpha(item)]
directOrder = [item for item in inputContent if item == "<" or item == ">"]
trainList = []
trainList.append(trainOrder[0])
listIndex = 1
trainLength = 1
for train, direct in zip(trainOrder[1:], directOrder):
if listIndex == 1 and direct == "<":
trainList.insert(0, train)
trainLength += 1
elif listIndex == trainLength and direct == ">":
trainList.append(train)
listIndex += 1
trainLength += 1
elif direct == "<":
listIndex -= 1
elif direct == ">":
listIndex += 1
output = "".join(trainList)
print(output)
``` | output | 1 | 39,520 | 1 | 79,041 |
Provide a correct Python 3 solution for this coding contest problem.
There are trains with 26 cars or less. Each vehicle has an identification code from lowercase a to z. No vehicle has the same symbol. However, the order in which the vehicles are connected is arbitrary. The conductor patrols the train. The conductor patrolls back and forth in the train, so he may pass through the same vehicle many times. However, all vehicles shall be patrolled at least once. In addition, the vehicle that starts the patrol and the vehicle that finishes the patrol is not necessarily the vehicle at the end of the train.
There is a patrol record of all the trains on which an Aru Shashou is on board. Create a program that outputs the formation of each train that can be seen from it from the lead car. The patrol record corresponds to one train per line. Each line consists of a string of lowercase letters separated by <-or->. <-Represents a move to a vehicle in front, and-> represents a move to a vehicle behind.
For example, a-> b <-a <-c means that vehicle a has moved to the vehicle behind b, b has moved to a ahead, and a has moved to c ahead. In this case, the train formation will be cab from the first car.
Input
The number of patrol records n (n β€ 50) is given to the first line, and the character string si (half-width character string up to 1024 characters) representing the patrol record i is given to the following n lines.
Output
For patrol record i, output the character string indicating the formation of the train from the first car on the i-line.
Examples
Input
4
a->e->c->b->d
b
Output
aecbd
edacb
bacde
bcdae
Input
4
a->e->c->b->d
b<-c<-a<-d<-e
b->a->c<-a->c->d<-c<-a<-b->a->c->d->e<-d
a->e<-a<-d->a->e<-a<-d<-c->d->a<-d<-c<-b->c->d<-c
Output
aecbd
edacb
bacde
bcdae | instruction | 0 | 39,521 | 1 | 79,042 |
"Correct Solution:
```
n = int(input())
for i in range(n):
Tr = list(input())
cou = 0
ans = [Tr[cou]]
while len(Tr) -1 > cou:
if Tr[cou + 1] == "-":
if Tr[cou + 3] in ans:
cou += 3
continue
else:
ans = ans + [Tr[cou + 3]]
else:
if Tr[cou + 3] in ans:
cou += 3
continue
else:
ans = [Tr[cou + 3]] + ans
cou += 3
a_s = ""
for i in range(len(ans)):
a_s = a_s + ans[i]
print(a_s)
``` | output | 1 | 39,521 | 1 | 79,043 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.