message stringlengths 2 65.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 0 108k | cluster float64 14 14 | __index_level_0__ int64 0 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
β This is not playing but duty as allies of justice, Nii-chan!
β Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters β Karen and Tsukihi β is heading for somewhere they've never reached β water-surrounded islands!
There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist of a, b and c distinct islands respectively.
Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length 1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3, apparently in order to prevent oddities from spreading quickly inside a cluster.
The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo 998 244 353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other.
Input
The first and only line of input contains three space-separated integers a, b and c (1 β€ a, b, c β€ 5 000) β the number of islands in the red, blue and purple clusters, respectively.
Output
Output one line containing an integer β the number of different ways to build bridges, modulo 998 244 353.
Examples
Input
1 1 1
Output
8
Input
1 2 2
Output
63
Input
1 3 5
Output
3264
Input
6 2 9
Output
813023575
Note
In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 23 = 8.
In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively.
<image> | instruction | 0 | 23,464 | 14 | 46,928 |
Tags: combinatorics, dp, math
Correct Solution:
```
def ncr(n,r):
return (fact[n]*pow((fact[n-r]*fact[r])%mod,mod-2,mod))%mod
def calc(a,b):
count=1
count+=(a*b)
for i in range(2,min(a,b)+1):
# print (ncr(a,i))
count=(count+(ncr(a,i)*ncr(b,i)*fact[i]))%mod
return count
mod=998244353
fact=[1,1]
for i in range(2,5001):
fact.append((fact[-1]*i)%mod)
a,b,c=map(int,input().split())
x1=calc(a,b)
x2=calc(b,c)
x3=calc(a,c)
# print (x1,x2,x3)
print ((x1*x2*x3)%mod)
``` | output | 1 | 23,464 | 14 | 46,929 |
Provide tags and a correct Python 3 solution for this coding contest problem.
β This is not playing but duty as allies of justice, Nii-chan!
β Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters β Karen and Tsukihi β is heading for somewhere they've never reached β water-surrounded islands!
There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist of a, b and c distinct islands respectively.
Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length 1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3, apparently in order to prevent oddities from spreading quickly inside a cluster.
The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo 998 244 353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other.
Input
The first and only line of input contains three space-separated integers a, b and c (1 β€ a, b, c β€ 5 000) β the number of islands in the red, blue and purple clusters, respectively.
Output
Output one line containing an integer β the number of different ways to build bridges, modulo 998 244 353.
Examples
Input
1 1 1
Output
8
Input
1 2 2
Output
63
Input
1 3 5
Output
3264
Input
6 2 9
Output
813023575
Note
In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 23 = 8.
In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively.
<image> | instruction | 0 | 23,465 | 14 | 46,930 |
Tags: combinatorics, dp, math
Correct Solution:
```
def calcop(a,b):
t=1
p=1
for i in range(0,min(a,b)):
p *= (a-i)*(b-i)
p //= i+1
t+=p
return t
a,b,c = map(int,input().split())
f = 998244353
ans = calcop(a,b)*calcop(b,c)*calcop(c,a)%f
print(ans)
``` | output | 1 | 23,465 | 14 | 46,931 |
Provide tags and a correct Python 3 solution for this coding contest problem.
β This is not playing but duty as allies of justice, Nii-chan!
β Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters β Karen and Tsukihi β is heading for somewhere they've never reached β water-surrounded islands!
There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist of a, b and c distinct islands respectively.
Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length 1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3, apparently in order to prevent oddities from spreading quickly inside a cluster.
The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo 998 244 353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other.
Input
The first and only line of input contains three space-separated integers a, b and c (1 β€ a, b, c β€ 5 000) β the number of islands in the red, blue and purple clusters, respectively.
Output
Output one line containing an integer β the number of different ways to build bridges, modulo 998 244 353.
Examples
Input
1 1 1
Output
8
Input
1 2 2
Output
63
Input
1 3 5
Output
3264
Input
6 2 9
Output
813023575
Note
In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 23 = 8.
In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively.
<image> | instruction | 0 | 23,466 | 14 | 46,932 |
Tags: combinatorics, dp, math
Correct Solution:
```
mod = 998244353
f = [1]
for i in range(1, 5010):
f += [f[i - 1] * i % mod]
def powmod(n, k):
if k == 0:
return 1
res = powmod(n, k // 2)
res *= res
res %= mod
if k % 2:
res *= n
res %= mod
return res
def inv(n):
return powmod(n, mod - 2)
def c(n, k):
return f[n] * inv(f[n - k]) % mod * inv(f[k]) % mod
def match(a, b):
res = 0
for i in range(min(a, b) + 1):
res += c(a, i) * c(b, i) * f[i] % mod
res %= mod
return res
n,m,k = list(map(int, input().split()))
print(match(n, m) * match(n, k) * match(m, k) % mod)
``` | output | 1 | 23,466 | 14 | 46,933 |
Provide tags and a correct Python 3 solution for this coding contest problem.
β This is not playing but duty as allies of justice, Nii-chan!
β Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters β Karen and Tsukihi β is heading for somewhere they've never reached β water-surrounded islands!
There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist of a, b and c distinct islands respectively.
Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length 1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3, apparently in order to prevent oddities from spreading quickly inside a cluster.
The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo 998 244 353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other.
Input
The first and only line of input contains three space-separated integers a, b and c (1 β€ a, b, c β€ 5 000) β the number of islands in the red, blue and purple clusters, respectively.
Output
Output one line containing an integer β the number of different ways to build bridges, modulo 998 244 353.
Examples
Input
1 1 1
Output
8
Input
1 2 2
Output
63
Input
1 3 5
Output
3264
Input
6 2 9
Output
813023575
Note
In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 23 = 8.
In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively.
<image> | instruction | 0 | 23,467 | 14 | 46,934 |
Tags: combinatorics, dp, math
Correct Solution:
```
import math
def fpow(x, y, p):
if y < 0:
return 1 / fpow(x, -y, p)
elif y == 0:
return 1
elif y % 2 == 0:
return fpow((x * x) % p, y // 2, p)
else:
return ((x % p) * fpow(x % p, y - 1, p)) % p
def c(n, k):
global fact
return (fact[n] * fpow((fact[k] * fact[n - k]), mod - 2, mod) % mod)
mod = 998244353
fact = [1] * 5005
for i in range(1, 5005):
fact[i] = fact[i - 1] * i % mod
r, g, p = map(int, input().split())
pr = 1
su = 0
for k in range(0, min(r, g) + 1):
su += c(r, k) * c(g, k) * fact[k]
pr *= su
su = 0
for k in range(0, min(p, g) + 1):
su += c(p, k) * c(g, k) * fact[k]
pr *= su
su = 0
for k in range(0, min(r, p) + 1):
su += c(r, k) * c(p, k) * fact[k]
pr *= su
print(pr % mod)
``` | output | 1 | 23,467 | 14 | 46,935 |
Provide tags and a correct Python 3 solution for this coding contest problem.
β This is not playing but duty as allies of justice, Nii-chan!
β Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters β Karen and Tsukihi β is heading for somewhere they've never reached β water-surrounded islands!
There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist of a, b and c distinct islands respectively.
Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length 1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3, apparently in order to prevent oddities from spreading quickly inside a cluster.
The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo 998 244 353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other.
Input
The first and only line of input contains three space-separated integers a, b and c (1 β€ a, b, c β€ 5 000) β the number of islands in the red, blue and purple clusters, respectively.
Output
Output one line containing an integer β the number of different ways to build bridges, modulo 998 244 353.
Examples
Input
1 1 1
Output
8
Input
1 2 2
Output
63
Input
1 3 5
Output
3264
Input
6 2 9
Output
813023575
Note
In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 23 = 8.
In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively.
<image> | instruction | 0 | 23,468 | 14 | 46,936 |
Tags: combinatorics, dp, math
Correct Solution:
```
import math
f = 998244353
def matchings(a,b):
m = max(a,b)
n = min(a,b)
t = 1
p = 1
for i in range(0,n):
p *= (n-i)*(m-i)
p //= i+1
t += p
t = t % f
return(t)
inputs = [int(x) for x in input().split(" ")]
k = matchings(inputs[0],inputs[1])*matchings(inputs[0],inputs[2])*matchings(inputs[2],inputs[1]) % f
print(k)
``` | output | 1 | 23,468 | 14 | 46,937 |
Provide tags and a correct Python 3 solution for this coding contest problem.
β This is not playing but duty as allies of justice, Nii-chan!
β Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters β Karen and Tsukihi β is heading for somewhere they've never reached β water-surrounded islands!
There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist of a, b and c distinct islands respectively.
Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length 1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3, apparently in order to prevent oddities from spreading quickly inside a cluster.
The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo 998 244 353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other.
Input
The first and only line of input contains three space-separated integers a, b and c (1 β€ a, b, c β€ 5 000) β the number of islands in the red, blue and purple clusters, respectively.
Output
Output one line containing an integer β the number of different ways to build bridges, modulo 998 244 353.
Examples
Input
1 1 1
Output
8
Input
1 2 2
Output
63
Input
1 3 5
Output
3264
Input
6 2 9
Output
813023575
Note
In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 23 = 8.
In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively.
<image> | instruction | 0 | 23,469 | 14 | 46,938 |
Tags: combinatorics, dp, math
Correct Solution:
```
a, b, c = map(int, input().split())
d = 998244353
def f(x, y):
s, t = 0, 1
for i in range(min(x, y) + 1):
s = (s + t) % d
t = t * (x - i) * (y - i) * pow(i + 1, d - 2, d) % d
return s
print(f(a, b) * f(a, c) * f(b, c) % d)
``` | output | 1 | 23,469 | 14 | 46,939 |
Provide tags and a correct Python 3 solution for this coding contest problem.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?
Input
The only line contains four integers k, n, s, p (1 β€ k, n, s, p β€ 10^4) β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output
Print a single integer β the minimum number of packs they should buy.
Examples
Input
5 3 2 3
Output
4
Input
5 3 100 1
Output
5
Note
In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | instruction | 0 | 23,526 | 14 | 47,052 |
Tags: math
Correct Solution:
```
k,n,s,p = map(int,input().split())
t = n // s + bool(n % s)
print(k * t // p + bool(k * t % p))
``` | output | 1 | 23,526 | 14 | 47,053 |
Provide tags and a correct Python 3 solution for this coding contest problem.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?
Input
The only line contains four integers k, n, s, p (1 β€ k, n, s, p β€ 10^4) β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output
Print a single integer β the minimum number of packs they should buy.
Examples
Input
5 3 2 3
Output
4
Input
5 3 100 1
Output
5
Note
In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | instruction | 0 | 23,527 | 14 | 47,054 |
Tags: math
Correct Solution:
```
[k, n, s, p] = [int(x) for x in input().split(' ')]
ndivs = n // s + (0 if n % s == 0 else 1)
packs = k * ndivs // p + (0 if k * ndivs % p == 0 else 1)
print(packs)
``` | output | 1 | 23,527 | 14 | 47,055 |
Provide tags and a correct Python 3 solution for this coding contest problem.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?
Input
The only line contains four integers k, n, s, p (1 β€ k, n, s, p β€ 10^4) β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output
Print a single integer β the minimum number of packs they should buy.
Examples
Input
5 3 2 3
Output
4
Input
5 3 100 1
Output
5
Note
In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | instruction | 0 | 23,528 | 14 | 47,056 |
Tags: math
Correct Solution:
```
def problem():
k,n,s,p = map(int,input().split(' '))
r = k
if n>s:
if n%s:
r *= n//s+1
else:
r *= n//s
else:
r *= 1
if r>p:
if r%p:
solution = r//p+1
else:
solution = r//p
else:
solution = 1
return solution
solution = problem()
print(solution)
``` | output | 1 | 23,528 | 14 | 47,057 |
Provide tags and a correct Python 3 solution for this coding contest problem.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?
Input
The only line contains four integers k, n, s, p (1 β€ k, n, s, p β€ 10^4) β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output
Print a single integer β the minimum number of packs they should buy.
Examples
Input
5 3 2 3
Output
4
Input
5 3 100 1
Output
5
Note
In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | instruction | 0 | 23,529 | 14 | 47,058 |
Tags: math
Correct Solution:
```
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()
def main():
a,b,c,d=LI()
x=(b+c-1)//c
y=x*a
return (y+d-1)//d
# main()
print(main())
``` | output | 1 | 23,529 | 14 | 47,059 |
Provide tags and a correct Python 3 solution for this coding contest problem.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?
Input
The only line contains four integers k, n, s, p (1 β€ k, n, s, p β€ 10^4) β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output
Print a single integer β the minimum number of packs they should buy.
Examples
Input
5 3 2 3
Output
4
Input
5 3 100 1
Output
5
Note
In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | instruction | 0 | 23,530 | 14 | 47,060 |
Tags: math
Correct Solution:
```
import math
k,n,s,p=list(map(int,input().split()))
c=n/s
c=math.ceil(c)
c=c*k
c=c/p
c=math.ceil(c)
print(int(c))
``` | output | 1 | 23,530 | 14 | 47,061 |
Provide tags and a correct Python 3 solution for this coding contest problem.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?
Input
The only line contains four integers k, n, s, p (1 β€ k, n, s, p β€ 10^4) β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output
Print a single integer β the minimum number of packs they should buy.
Examples
Input
5 3 2 3
Output
4
Input
5 3 100 1
Output
5
Note
In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | instruction | 0 | 23,531 | 14 | 47,062 |
Tags: math
Correct Solution:
```
from math import ceil
(k, n, s, p) = [int(r) for r in input().split()]
total_sheets = k * ceil(n / s)
print(ceil(total_sheets / p))
``` | output | 1 | 23,531 | 14 | 47,063 |
Provide tags and a correct Python 3 solution for this coding contest problem.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?
Input
The only line contains four integers k, n, s, p (1 β€ k, n, s, p β€ 10^4) β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output
Print a single integer β the minimum number of packs they should buy.
Examples
Input
5 3 2 3
Output
4
Input
5 3 100 1
Output
5
Note
In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | instruction | 0 | 23,532 | 14 | 47,064 |
Tags: math
Correct Solution:
```
k, n, s, p=input().split()
k=int(k)
n=int(n)
s=int(s)
p=int(p)
if n%s!=0 :
packs=(int(n/s)+1)*k
if packs%p!=0 :
packs=int(((int(n/s)+1)*k)/p)+1
else :
packs=int(((int(n/s)+1)*k)/p)
else :
packs=((n/s)*k)
if packs%p!=0 :
packs=int(((n/s)*k)/p)+1
else :
packs=int(((n/s)*k)/p)
print(packs)
``` | output | 1 | 23,532 | 14 | 47,065 |
Provide tags and a correct Python 3 solution for this coding contest problem.
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each person should have enough sheets to make n airplanes. How many packs should they buy?
Input
The only line contains four integers k, n, s, p (1 β€ k, n, s, p β€ 10^4) β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Output
Print a single integer β the minimum number of packs they should buy.
Examples
Input
5 3 2 3
Output
4
Input
5 3 100 1
Output
5
Note
In the first sample they have to buy 4 packs of paper: there will be 12 sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | instruction | 0 | 23,533 | 14 | 47,066 |
Tags: math
Correct Solution:
```
k, n, s, p=map(float,input().split(' '))
print(int(((n+s-1)//s*k+p-1)//p))
``` | output | 1 | 23,533 | 14 | 47,067 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers [1, 5, 4, 1, 3] are written, and Sonya gives the number 1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (p_i, q_i) and (p_j, q_j) are different if p_iβ p_j or q_iβ q_j.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input
The first line contains a single integer n (1β€ nβ€ 10^5) β the number of numbers in a row.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_iβ€ 10^5) β the numbers in a row.
Output
Print one number β the number of possible pairs that Sonya can give to robots so that they will not meet.
Examples
Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7
Note
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4).
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2). | instruction | 0 | 23,831 | 14 | 47,662 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
row = [int(i) for i in input().strip().split()]
q_set = set([])
q_possibilities = []
for i in range(-1, -len(row), -1):
q_set.add(row[i])
q_possibilities.append(len(q_set))
q_possibilities.append(0)
q_possibilities.reverse()
p_set = set([])
my_sum = 0
for i in range(len(row)-1):
if row[i] not in p_set:
p_set.add(row[i])
my_sum = my_sum + q_possibilities[i+1]
print(my_sum)
``` | output | 1 | 23,831 | 14 | 47,663 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers [1, 5, 4, 1, 3] are written, and Sonya gives the number 1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (p_i, q_i) and (p_j, q_j) are different if p_iβ p_j or q_iβ q_j.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input
The first line contains a single integer n (1β€ nβ€ 10^5) β the number of numbers in a row.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_iβ€ 10^5) β the numbers in a row.
Output
Print one number β the number of possible pairs that Sonya can give to robots so that they will not meet.
Examples
Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7
Note
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4).
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2). | instruction | 0 | 23,832 | 14 | 47,664 |
Tags: constructive algorithms, implementation
Correct Solution:
```
"""
http://codeforces.com/problemset/problem/1004/C
"""
input()
arr = map(int, input().split())
hash_ = {}
cnt = 0
for x in arr:
if x not in hash_:
cnt += len(hash_)
hash_[x] = len(hash_)
else:
cnt += len(hash_) - hash_[x]
hash_[x] += len(hash_) - hash_[x]
print(cnt)
``` | output | 1 | 23,832 | 14 | 47,665 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers [1, 5, 4, 1, 3] are written, and Sonya gives the number 1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (p_i, q_i) and (p_j, q_j) are different if p_iβ p_j or q_iβ q_j.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input
The first line contains a single integer n (1β€ nβ€ 10^5) β the number of numbers in a row.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_iβ€ 10^5) β the numbers in a row.
Output
Print one number β the number of possible pairs that Sonya can give to robots so that they will not meet.
Examples
Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7
Note
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4).
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2). | instruction | 0 | 23,833 | 14 | 47,666 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
a = input().split()
cou = [0 for i in range(100005)]
vis = [False for i in range(100005)]
st = set()
for i in range(n):
a[i] = int(a[i])
cou[a[i]] += 1
st.add(a[i])
ans = 0
for i in range(n):
cou[a[i]] -= 1
if cou[a[i]] == 0:
st.remove(a[i])
if vis[a[i]] == False:
vis[a[i]] = True
ans += len(st)
print(ans)
``` | output | 1 | 23,833 | 14 | 47,667 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers [1, 5, 4, 1, 3] are written, and Sonya gives the number 1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (p_i, q_i) and (p_j, q_j) are different if p_iβ p_j or q_iβ q_j.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input
The first line contains a single integer n (1β€ nβ€ 10^5) β the number of numbers in a row.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_iβ€ 10^5) β the numbers in a row.
Output
Print one number β the number of possible pairs that Sonya can give to robots so that they will not meet.
Examples
Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7
Note
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4).
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2). | instruction | 0 | 23,834 | 14 | 47,668 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n=int(input())
s=list(map(int,input().split()))
dic={}
for i in s:
dic[i]=len(dic)
print(sum(dic.values()))
``` | output | 1 | 23,834 | 14 | 47,669 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers [1, 5, 4, 1, 3] are written, and Sonya gives the number 1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (p_i, q_i) and (p_j, q_j) are different if p_iβ p_j or q_iβ q_j.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input
The first line contains a single integer n (1β€ nβ€ 10^5) β the number of numbers in a row.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_iβ€ 10^5) β the numbers in a row.
Output
Print one number β the number of possible pairs that Sonya can give to robots so that they will not meet.
Examples
Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7
Note
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4).
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2). | instruction | 0 | 23,835 | 14 | 47,670 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
right = list()
s = set()
for el in a[::-1]:
s.add(el)
right.append(len(s))
right = right[::-1]
s = set()
ans = 0
for i, el in enumerate(a[:-1]):
if el not in s:
ans += right[i + 1]
s.add(el)
print(ans)
``` | output | 1 | 23,835 | 14 | 47,671 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers [1, 5, 4, 1, 3] are written, and Sonya gives the number 1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (p_i, q_i) and (p_j, q_j) are different if p_iβ p_j or q_iβ q_j.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input
The first line contains a single integer n (1β€ nβ€ 10^5) β the number of numbers in a row.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_iβ€ 10^5) β the numbers in a row.
Output
Print one number β the number of possible pairs that Sonya can give to robots so that they will not meet.
Examples
Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7
Note
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4).
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2). | instruction | 0 | 23,836 | 14 | 47,672 |
Tags: constructive algorithms, implementation
Correct Solution:
```
from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]
sum = 0
d = Counter(a)
la = set()
sa = set(a)
for i in range(n):
d[a[i]] -= 1
if d[a[i]] == 0:
sa.remove(a[i])
if a[i] in la:
continue
la.add(a[i])
sum += len(sa)
print(sum)
``` | output | 1 | 23,836 | 14 | 47,673 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers [1, 5, 4, 1, 3] are written, and Sonya gives the number 1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (p_i, q_i) and (p_j, q_j) are different if p_iβ p_j or q_iβ q_j.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input
The first line contains a single integer n (1β€ nβ€ 10^5) β the number of numbers in a row.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_iβ€ 10^5) β the numbers in a row.
Output
Print one number β the number of possible pairs that Sonya can give to robots so that they will not meet.
Examples
Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7
Note
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4).
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2). | instruction | 0 | 23,837 | 14 | 47,674 |
Tags: constructive algorithms, implementation
Correct Solution:
```
import sys,os,io
import math,bisect,operator
inf,mod = float('inf'),10**9+7
# sys.setrecursionlimit(10 ** 6)
from itertools import groupby,accumulate
from heapq import heapify,heappop,heappush
from collections import deque,Counter,defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
Neo = lambda : list(map(int,input().split()))
# test, = Neo()
n, = Neo()
A = Neo()
B = [0]*(n+1)
s = set()
for i in range(n-1,-1,-1):
if A[i] not in s:
B[i] += 1+B[i+1]
else:
B[i] = B[i+1]
s.add(A[i])
s = set()
Ans = 0
for i in range(n):
if A[i] not in s:
Ans += B[i+1]
s.add(A[i])
print(Ans)
``` | output | 1 | 23,837 | 14 | 47,675 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers [1, 5, 4, 1, 3] are written, and Sonya gives the number 1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (p_i, q_i) and (p_j, q_j) are different if p_iβ p_j or q_iβ q_j.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input
The first line contains a single integer n (1β€ nβ€ 10^5) β the number of numbers in a row.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_iβ€ 10^5) β the numbers in a row.
Output
Print one number β the number of possible pairs that Sonya can give to robots so that they will not meet.
Examples
Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7
Note
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4).
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2). | instruction | 0 | 23,838 | 14 | 47,676 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
a = input().split(' ')
d = {}
t = {}
amount = 0
for i in range(n):
a[i] = int(a[i])
elem = a[i]
if elem not in d.keys():
d[elem] = 1
t[elem] = 1
amount += 1
else:
d[elem] += 1
t[elem] += 1
pairs = 0
for i in range(n-1):
if d[a[i]] == t[a[i]]:
d[a[i]] -= 1
if d[a[i]] == 0:
amount -= 1
pairs += amount
else:
d[a[i]] -= 1
if d[a[i]] == 0:
amount -= 1
print(pairs)
``` | output | 1 | 23,838 | 14 | 47,677 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers [1, 5, 4, 1, 3] are written, and Sonya gives the number 1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (p_i, q_i) and (p_j, q_j) are different if p_iβ p_j or q_iβ q_j.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input
The first line contains a single integer n (1β€ nβ€ 10^5) β the number of numbers in a row.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_iβ€ 10^5) β the numbers in a row.
Output
Print one number β the number of possible pairs that Sonya can give to robots so that they will not meet.
Examples
Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7
Note
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4).
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2).
Submitted Solution:
```
n = int(input())
row = [int(i) for i in input().strip().split()]
q_set = set()
q_possibilities = []
for i in range(-1, -n, -1):
q_set.add(row[i])
q_possibilities.append(len(q_set))
q_possibilities.append(0)
q_possibilities.reverse()
p_set = set()
my_sum = 0
for i in range(n - 1):
if row[i] not in p_set:
p_set.add(row[i])
my_sum = my_sum + q_possibilities[i + 1]
print(my_sum)
``` | instruction | 0 | 23,839 | 14 | 47,678 |
Yes | output | 1 | 23,839 | 14 | 47,679 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers [1, 5, 4, 1, 3] are written, and Sonya gives the number 1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (p_i, q_i) and (p_j, q_j) are different if p_iβ p_j or q_iβ q_j.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input
The first line contains a single integer n (1β€ nβ€ 10^5) β the number of numbers in a row.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_iβ€ 10^5) β the numbers in a row.
Output
Print one number β the number of possible pairs that Sonya can give to robots so that they will not meet.
Examples
Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7
Note
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4).
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2).
Submitted Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
b = [0] * n
s = set()
for i in range(n - 1, -1, -1):
if a[i] not in s:
s.add(a[i])
b[i] = 1
r = 0
s = set()
for i in range(n):
if b[i]:
r += len(s)
s.add(a[i])
print(r)
``` | instruction | 0 | 23,840 | 14 | 47,680 |
Yes | output | 1 | 23,840 | 14 | 47,681 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers [1, 5, 4, 1, 3] are written, and Sonya gives the number 1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (p_i, q_i) and (p_j, q_j) are different if p_iβ p_j or q_iβ q_j.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input
The first line contains a single integer n (1β€ nβ€ 10^5) β the number of numbers in a row.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_iβ€ 10^5) β the numbers in a row.
Output
Print one number β the number of possible pairs that Sonya can give to robots so that they will not meet.
Examples
Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7
Note
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4).
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2).
Submitted Solution:
```
n = int(input())
l = [int(el) for el in input().split()]
col = 0
a = [0] * 100001
s = set()
for i in range(n):
if a[l[i]] == 0:
col += len(s)
a[l[i]] += len(s)
s.add(l[i])
else:
col += len(s) - a[l[i]]
a[l[i]] = len(s)
s.add(l[i])
print(col)
``` | instruction | 0 | 23,841 | 14 | 47,682 |
Yes | output | 1 | 23,841 | 14 | 47,683 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers [1, 5, 4, 1, 3] are written, and Sonya gives the number 1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (p_i, q_i) and (p_j, q_j) are different if p_iβ p_j or q_iβ q_j.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input
The first line contains a single integer n (1β€ nβ€ 10^5) β the number of numbers in a row.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_iβ€ 10^5) β the numbers in a row.
Output
Print one number β the number of possible pairs that Sonya can give to robots so that they will not meet.
Examples
Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7
Note
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4).
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2).
Submitted Solution:
```
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
from functools import lru_cache
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
#def input(): return sys.stdin.readline().strip()m
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
aj = lambda: list(map(int, input().split()))
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c): print(["NO","YES"][c])
def y(c): print(["no","yes"][c])
def Yy(c): print(["No","Yes"][c])
n, = aj()
A = aj()
g = [i for i in A]
s = set()
suf= []
c = 0;mark = {}
for i in range(len(g)-1,-1,-1):
if g[i] not in s:
c += 1
#mark[g[i]] = i
s.add(g[i])
suf.append(c)
suf = suf[::-1]
#rint(g)
ans = 0
ok = set()
for i in range(len(g)-1):
if g[i] not in ok:
ok.add(g[i])
ans += suf[i+1]
#rint(i,g[i],ans)
print(ans)
``` | instruction | 0 | 23,842 | 14 | 47,684 |
Yes | output | 1 | 23,842 | 14 | 47,685 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers [1, 5, 4, 1, 3] are written, and Sonya gives the number 1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (p_i, q_i) and (p_j, q_j) are different if p_iβ p_j or q_iβ q_j.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input
The first line contains a single integer n (1β€ nβ€ 10^5) β the number of numbers in a row.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_iβ€ 10^5) β the numbers in a row.
Output
Print one number β the number of possible pairs that Sonya can give to robots so that they will not meet.
Examples
Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7
Note
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4).
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2).
Submitted Solution:
```
noe = int(input())
arr = [int(x) for x in input().split()]
cnt = [0] * int(2e5)
g=noe-1
for x in arr:
cnt[x] = len(set(arr[:g]))
g-=1
#print(cnt[:10], cur)
print(sum(cnt))
``` | instruction | 0 | 23,843 | 14 | 47,686 |
No | output | 1 | 23,843 | 14 | 47,687 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers [1, 5, 4, 1, 3] are written, and Sonya gives the number 1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (p_i, q_i) and (p_j, q_j) are different if p_iβ p_j or q_iβ q_j.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input
The first line contains a single integer n (1β€ nβ€ 10^5) β the number of numbers in a row.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_iβ€ 10^5) β the numbers in a row.
Output
Print one number β the number of possible pairs that Sonya can give to robots so that they will not meet.
Examples
Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7
Note
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4).
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2).
Submitted Solution:
```
cnt = int(input())
data = [int(x) for x in input().split()]
#data = [13036,23902,71466,9482,98728,78471,22915,2470,5999,53211,25994,3996,11349,30511,56448,17277,78308,18316,42069,38636,63127,26256,63985,57249,58305,64366,17839,28518,18980,95945,36316,6076,69530,96509,6940,6039,56048,41847,82118,41054,49670,95896,45891,74636,90736,75413,27251,87730,68344,66202,71879,51666,8985,42722,49000,43845,44614,4961,64751,97655,79361,80091,12747,20934,9188,74058,93662,8454,79516,91323,42656,33567,44392,58833,93051,86157,10398,79297,33197,13472,59847,34005,84201,20634,9790,71913]
#data = [1, 3, 5, 7, 3, 10,7,4]
#print(data)
totalSolutions = 0
tset1 = set([])
data2 = []
aug = data[:]
aug[-1] = 1
for x in range(-2,-len(data)-1,-1):
if data[x] not in tset1:
tset1.add(data[x])
aug[x] = aug[x+1] +1
else:
aug[x] = aug[x+1]
#print(aug)
for i in set(data[:]):
j = data.index(i)
if (j < len(data)-1):
totalSolutions += aug[j+1]
print(totalSolutions)
``` | instruction | 0 | 23,844 | 14 | 47,688 |
No | output | 1 | 23,844 | 14 | 47,689 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers [1, 5, 4, 1, 3] are written, and Sonya gives the number 1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (p_i, q_i) and (p_j, q_j) are different if p_iβ p_j or q_iβ q_j.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input
The first line contains a single integer n (1β€ nβ€ 10^5) β the number of numbers in a row.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_iβ€ 10^5) β the numbers in a row.
Output
Print one number β the number of possible pairs that Sonya can give to robots so that they will not meet.
Examples
Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7
Note
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4).
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2).
Submitted Solution:
```
readints=lambda:map(int, input().strip('\n').split())
n=int(input())
nums=list(readints())
cnt=[0]*n
used={} # elem to left-most index
i=n-1
while i>=0:
x=nums[i]
df=0
if x in used:
for j in used[x]:
df+=cnt[j]
cnt[i]=len(used)-df
if x not in used: used[x]=[]
used[x].append(i)
i-=1
print(cnt)
print(sum(cnt))
``` | instruction | 0 | 23,845 | 14 | 47,690 |
No | output | 1 | 23,845 | 14 | 47,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers [1, 5, 4, 1, 3] are written, and Sonya gives the number 1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (p_i, q_i) and (p_j, q_j) are different if p_iβ p_j or q_iβ q_j.
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Input
The first line contains a single integer n (1β€ nβ€ 10^5) β the number of numbers in a row.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_iβ€ 10^5) β the numbers in a row.
Output
Print one number β the number of possible pairs that Sonya can give to robots so that they will not meet.
Examples
Input
5
1 5 4 1 3
Output
9
Input
7
1 2 1 1 1 3 2
Output
7
Note
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4).
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2).
Submitted Solution:
```
from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]
d = Counter(a)
la = set(a)
sum = 0
for i in range(n):
d[a[i]] -= 1
if d[a[i]] == 0:
la.remove(a[i])
sum += len(la)
print(sum)
``` | instruction | 0 | 23,846 | 14 | 47,692 |
No | output | 1 | 23,846 | 14 | 47,693 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule.
A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number β the number of bonds the atom must form with other atoms. An atom can form one or multiple bonds with any other atom, but it cannot form a bond with itself. The number of bonds of an atom in the molecule must be equal to its valence number.
<image>
Mike knows valence numbers of the three atoms. Find a molecule that can be built from these atoms according to the stated rules, or determine that it is impossible.
Input
The single line of the input contains three space-separated integers a, b and c (1 β€ a, b, c β€ 106) β the valence numbers of the given atoms.
Output
If such a molecule can be built, print three space-separated integers β the number of bonds between the 1-st and the 2-nd, the 2-nd and the 3-rd, the 3-rd and the 1-st atoms, correspondingly. If there are multiple solutions, output any of them. If there is no solution, print "Impossible" (without the quotes).
Examples
Input
1 1 2
Output
0 1 1
Input
3 4 5
Output
1 3 2
Input
4 1 1
Output
Impossible
Note
The first sample corresponds to the first figure. There are no bonds between atoms 1 and 2 in this case.
The second sample corresponds to the second figure. There is one or more bonds between each pair of atoms.
The third sample corresponds to the third figure. There is no solution, because an atom cannot form bonds with itself.
The configuration in the fourth figure is impossible as each atom must have at least one atomic bond. | instruction | 0 | 24,152 | 14 | 48,304 |
Tags: brute force, graphs, math
Correct Solution:
```
a, b, c = map(int, input().split())
for i in range(max([a, b, c])):
ab = i
bc = b - ab
ca = c - bc
if (bc > 0 or ca > 0) and (bc >= 0 and ca >= 0):
if (ab + ca == a):
print (ab, bc, ca)
exit()
print ('Impossible')
``` | output | 1 | 24,152 | 14 | 48,305 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor.
At each cycle each core of the processor gets one instruction: either do nothing, or the number of the memory cell (the core will write an information to the cell). After receiving the command, the core executes it immediately. Sometimes it happens that at one cycle, multiple cores try to write the information into a single cell. Unfortunately, the developers did not foresee the possibility of resolving conflicts between cores, so in this case there is a deadlock: all these cores and the corresponding memory cell are locked forever. Each of the locked cores ignores all further commands, and no core in the future will be able to record an information into the locked cell. If any of the cores tries to write an information into some locked cell, it is immediately locked.
The development team wants to explore the deadlock situation. Therefore, they need a program that will simulate the processor for a given set of instructions for each core within m cycles . You're lucky, this interesting work is entrusted to you. According to the instructions, during the m cycles define for each core the number of the cycle, during which it will become locked. It is believed that initially all cores and all memory cells are not locked.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 100). Then follow n lines describing instructions. The i-th line contains m integers: xi1, xi2, ..., xim (0 β€ xij β€ k), where xij is the instruction that must be executed by the i-th core at the j-th cycle. If xij equals 0, then the corresponding instruction is Β«do nothingΒ». But if xij is a number from 1 to k, then the corresponding instruction is Β«write information to the memory cell number xijΒ».
We assume that the cores are numbered from 1 to n, the work cycles are numbered from 1 to m and the memory cells are numbered from 1 to k.
Output
Print n lines. In the i-th line print integer ti. This number should be equal to 0 if the i-th core won't be locked, or it should be equal to the number of the cycle when this core will be locked.
Examples
Input
4 3 5
1 0 0
1 0 2
2 3 1
3 2 0
Output
1
1
3
0
Input
3 2 2
1 2
1 2
2 2
Output
1
1
0
Input
1 1 1
0
Output
0 | instruction | 0 | 24,168 | 14 | 48,336 |
Tags: implementation
Correct Solution:
```
n, m, k = map(int, input().split())
ans = [0 for i in range(n)]
lock = [False for i in range(k)]
deadlock = lock[:]
insset = [[0 for i in range(n)] for i in range(m)]
for i in range(n):
ins = list(map(int, input().split()))
for j in range(m):
insset[j][i] = ins[j]
for r in range(m):
ins = insset[r]
for i, el in enumerate(ins):
if el == 0 or ans[i]:
continue
if lock[el-1]:
deadlock[el-1] = True
else:
lock[el-1] = True
for i in range(n):
if ins[i] == 0 or ans[i]:
continue
if deadlock[ins[i]-1]:
ans[i] = r+1
lock = [False for i in range(k)]
for el in ans:
print(el)
``` | output | 1 | 24,168 | 14 | 48,337 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor.
At each cycle each core of the processor gets one instruction: either do nothing, or the number of the memory cell (the core will write an information to the cell). After receiving the command, the core executes it immediately. Sometimes it happens that at one cycle, multiple cores try to write the information into a single cell. Unfortunately, the developers did not foresee the possibility of resolving conflicts between cores, so in this case there is a deadlock: all these cores and the corresponding memory cell are locked forever. Each of the locked cores ignores all further commands, and no core in the future will be able to record an information into the locked cell. If any of the cores tries to write an information into some locked cell, it is immediately locked.
The development team wants to explore the deadlock situation. Therefore, they need a program that will simulate the processor for a given set of instructions for each core within m cycles . You're lucky, this interesting work is entrusted to you. According to the instructions, during the m cycles define for each core the number of the cycle, during which it will become locked. It is believed that initially all cores and all memory cells are not locked.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 100). Then follow n lines describing instructions. The i-th line contains m integers: xi1, xi2, ..., xim (0 β€ xij β€ k), where xij is the instruction that must be executed by the i-th core at the j-th cycle. If xij equals 0, then the corresponding instruction is Β«do nothingΒ». But if xij is a number from 1 to k, then the corresponding instruction is Β«write information to the memory cell number xijΒ».
We assume that the cores are numbered from 1 to n, the work cycles are numbered from 1 to m and the memory cells are numbered from 1 to k.
Output
Print n lines. In the i-th line print integer ti. This number should be equal to 0 if the i-th core won't be locked, or it should be equal to the number of the cycle when this core will be locked.
Examples
Input
4 3 5
1 0 0
1 0 2
2 3 1
3 2 0
Output
1
1
3
0
Input
3 2 2
1 2
1 2
2 2
Output
1
1
0
Input
1 1 1
0
Output
0 | instruction | 0 | 24,169 | 14 | 48,338 |
Tags: implementation
Correct Solution:
```
import sys
n, m, k = [int(i) for i in sys.stdin.readline().split(' ')]
mem = set()
cpu = {}
x = [0] * n
for i in range(n):
x[i] = [int(j) for j in sys.stdin.readline().split(' ')]
for i in range(m):
dead = set([i for i in range(n)])
dead -= cpu.keys()
dead = [j for j in dead if x[j][i] > 0 and any(k != j and x[j][i] == x[k][i] for k in dead)]
for j in dead:
if not j in cpu.keys():
cpu[j] = i
mem.add(x[j][i])
add = [j for j in range(n) if x[j][i] in mem]
for j in add:
if not j in cpu.keys():
cpu[j] = i
for i in range(n):
if i in cpu.keys():
print(cpu[i] + 1)
else:
print(0)
``` | output | 1 | 24,169 | 14 | 48,339 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor.
At each cycle each core of the processor gets one instruction: either do nothing, or the number of the memory cell (the core will write an information to the cell). After receiving the command, the core executes it immediately. Sometimes it happens that at one cycle, multiple cores try to write the information into a single cell. Unfortunately, the developers did not foresee the possibility of resolving conflicts between cores, so in this case there is a deadlock: all these cores and the corresponding memory cell are locked forever. Each of the locked cores ignores all further commands, and no core in the future will be able to record an information into the locked cell. If any of the cores tries to write an information into some locked cell, it is immediately locked.
The development team wants to explore the deadlock situation. Therefore, they need a program that will simulate the processor for a given set of instructions for each core within m cycles . You're lucky, this interesting work is entrusted to you. According to the instructions, during the m cycles define for each core the number of the cycle, during which it will become locked. It is believed that initially all cores and all memory cells are not locked.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 100). Then follow n lines describing instructions. The i-th line contains m integers: xi1, xi2, ..., xim (0 β€ xij β€ k), where xij is the instruction that must be executed by the i-th core at the j-th cycle. If xij equals 0, then the corresponding instruction is Β«do nothingΒ». But if xij is a number from 1 to k, then the corresponding instruction is Β«write information to the memory cell number xijΒ».
We assume that the cores are numbered from 1 to n, the work cycles are numbered from 1 to m and the memory cells are numbered from 1 to k.
Output
Print n lines. In the i-th line print integer ti. This number should be equal to 0 if the i-th core won't be locked, or it should be equal to the number of the cycle when this core will be locked.
Examples
Input
4 3 5
1 0 0
1 0 2
2 3 1
3 2 0
Output
1
1
3
0
Input
3 2 2
1 2
1 2
2 2
Output
1
1
0
Input
1 1 1
0
Output
0 | instruction | 0 | 24,170 | 14 | 48,340 |
Tags: implementation
Correct Solution:
```
from collections import defaultdict
n, m, k = [int(i) for i in input().split()]
cell = [0 for i in range(k+1)]
core = [0 for i in range(n+1)]
# if core is positive, it has been locked, same if a cell is positive
# core would access the cell
# n is the number of cores
# m is the number of cycle
# k is the number of cells
A = [[int(i) for i in input().split()] for j in range(n)] # reading in the n lines
A = [[0] + [row[i] for row in A] for i in range(len(A[0]))] # now i have tranpose it
# append 0 at the start
# now A is of size m+1 by n
# each row is a timestep
for t in range(m):
cell_visited = defaultdict(set)
for i in range(1, n+1): # go through each core
if A[t][i] > 0 and core[i] == 0: # instruction to do something and the core is not locked
if cell[A[t][i]] > 0: # the cell is locked, lock the core if it's not locked
core[i] = t + 1
elif cell[A[t][i]] == 0: # the cell is not locked
cell_visited[A[t][i]].add(i)
for i in cell_visited: #i is the index of the cell
if len(cell_visited[i]) > 1:
cell[i] = 1 # lock the cell
for j in cell_visited[i]:
core[j] = t + 1
for i in range(1, n+1):
print(core[i])
``` | output | 1 | 24,170 | 14 | 48,341 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor.
At each cycle each core of the processor gets one instruction: either do nothing, or the number of the memory cell (the core will write an information to the cell). After receiving the command, the core executes it immediately. Sometimes it happens that at one cycle, multiple cores try to write the information into a single cell. Unfortunately, the developers did not foresee the possibility of resolving conflicts between cores, so in this case there is a deadlock: all these cores and the corresponding memory cell are locked forever. Each of the locked cores ignores all further commands, and no core in the future will be able to record an information into the locked cell. If any of the cores tries to write an information into some locked cell, it is immediately locked.
The development team wants to explore the deadlock situation. Therefore, they need a program that will simulate the processor for a given set of instructions for each core within m cycles . You're lucky, this interesting work is entrusted to you. According to the instructions, during the m cycles define for each core the number of the cycle, during which it will become locked. It is believed that initially all cores and all memory cells are not locked.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 100). Then follow n lines describing instructions. The i-th line contains m integers: xi1, xi2, ..., xim (0 β€ xij β€ k), where xij is the instruction that must be executed by the i-th core at the j-th cycle. If xij equals 0, then the corresponding instruction is Β«do nothingΒ». But if xij is a number from 1 to k, then the corresponding instruction is Β«write information to the memory cell number xijΒ».
We assume that the cores are numbered from 1 to n, the work cycles are numbered from 1 to m and the memory cells are numbered from 1 to k.
Output
Print n lines. In the i-th line print integer ti. This number should be equal to 0 if the i-th core won't be locked, or it should be equal to the number of the cycle when this core will be locked.
Examples
Input
4 3 5
1 0 0
1 0 2
2 3 1
3 2 0
Output
1
1
3
0
Input
3 2 2
1 2
1 2
2 2
Output
1
1
0
Input
1 1 1
0
Output
0 | instruction | 0 | 24,171 | 14 | 48,342 |
Tags: implementation
Correct Solution:
```
def adds(memtoproc,mem,proc):
if mem in memtoproc:
memtoproc[mem].append(proc)
else:
memtoproc[mem]=[proc]
def corr(arr,n,m):
brokemems=set()
stopprocs=[0]*n
for c in range(m):
memtoproc=dict()
usemems=set()
locmems=set()
for d in range(n):
if not arr[d][c] or stopprocs[d]:
continue
adds(memtoproc,arr[d][c],d)
if arr[d][c] in usemems:
locmems.add(arr[d][c])
usemems.add(arr[d][c])
if arr[d][c] in brokemems:
if not stopprocs[d]:
stopprocs[d]=c+1
for d in locmems:
brokemems.add(d)
procs=memtoproc[d]
for x in procs:
if not stopprocs[x]:
stopprocs[x]=c+1
return stopprocs
n,m,k=map(int,input().split(' '))
arr=[]
for c in range(n):
arr.append(tuple(map(int,input().split(' '))))
procs=corr(arr,n,m)
for c in procs:
print(c)
``` | output | 1 | 24,171 | 14 | 48,343 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor.
At each cycle each core of the processor gets one instruction: either do nothing, or the number of the memory cell (the core will write an information to the cell). After receiving the command, the core executes it immediately. Sometimes it happens that at one cycle, multiple cores try to write the information into a single cell. Unfortunately, the developers did not foresee the possibility of resolving conflicts between cores, so in this case there is a deadlock: all these cores and the corresponding memory cell are locked forever. Each of the locked cores ignores all further commands, and no core in the future will be able to record an information into the locked cell. If any of the cores tries to write an information into some locked cell, it is immediately locked.
The development team wants to explore the deadlock situation. Therefore, they need a program that will simulate the processor for a given set of instructions for each core within m cycles . You're lucky, this interesting work is entrusted to you. According to the instructions, during the m cycles define for each core the number of the cycle, during which it will become locked. It is believed that initially all cores and all memory cells are not locked.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 100). Then follow n lines describing instructions. The i-th line contains m integers: xi1, xi2, ..., xim (0 β€ xij β€ k), where xij is the instruction that must be executed by the i-th core at the j-th cycle. If xij equals 0, then the corresponding instruction is Β«do nothingΒ». But if xij is a number from 1 to k, then the corresponding instruction is Β«write information to the memory cell number xijΒ».
We assume that the cores are numbered from 1 to n, the work cycles are numbered from 1 to m and the memory cells are numbered from 1 to k.
Output
Print n lines. In the i-th line print integer ti. This number should be equal to 0 if the i-th core won't be locked, or it should be equal to the number of the cycle when this core will be locked.
Examples
Input
4 3 5
1 0 0
1 0 2
2 3 1
3 2 0
Output
1
1
3
0
Input
3 2 2
1 2
1 2
2 2
Output
1
1
0
Input
1 1 1
0
Output
0 | instruction | 0 | 24,172 | 14 | 48,344 |
Tags: implementation
Correct Solution:
```
n,m,k=map(int,input('').split())
x={}
out=[]
memory=[]
for i in range(n):
x[i]=list(map(int, input('').split()))
out+=[(0)]
for j in range(m):
for i in range(n):
k=x[i][j]
if k!=0:
for q in range(n):
if i!=q and out[i]==0:
for p in memory:
if p==k:
out[i]=j+1
break
if k==x[q][j] and out[q]==0:
out[i]=j+1
out[q]=j+1
memory+=[(k)]
for i in range(n):
print (out[i])
``` | output | 1 | 24,172 | 14 | 48,345 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor.
At each cycle each core of the processor gets one instruction: either do nothing, or the number of the memory cell (the core will write an information to the cell). After receiving the command, the core executes it immediately. Sometimes it happens that at one cycle, multiple cores try to write the information into a single cell. Unfortunately, the developers did not foresee the possibility of resolving conflicts between cores, so in this case there is a deadlock: all these cores and the corresponding memory cell are locked forever. Each of the locked cores ignores all further commands, and no core in the future will be able to record an information into the locked cell. If any of the cores tries to write an information into some locked cell, it is immediately locked.
The development team wants to explore the deadlock situation. Therefore, they need a program that will simulate the processor for a given set of instructions for each core within m cycles . You're lucky, this interesting work is entrusted to you. According to the instructions, during the m cycles define for each core the number of the cycle, during which it will become locked. It is believed that initially all cores and all memory cells are not locked.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 100). Then follow n lines describing instructions. The i-th line contains m integers: xi1, xi2, ..., xim (0 β€ xij β€ k), where xij is the instruction that must be executed by the i-th core at the j-th cycle. If xij equals 0, then the corresponding instruction is Β«do nothingΒ». But if xij is a number from 1 to k, then the corresponding instruction is Β«write information to the memory cell number xijΒ».
We assume that the cores are numbered from 1 to n, the work cycles are numbered from 1 to m and the memory cells are numbered from 1 to k.
Output
Print n lines. In the i-th line print integer ti. This number should be equal to 0 if the i-th core won't be locked, or it should be equal to the number of the cycle when this core will be locked.
Examples
Input
4 3 5
1 0 0
1 0 2
2 3 1
3 2 0
Output
1
1
3
0
Input
3 2 2
1 2
1 2
2 2
Output
1
1
0
Input
1 1 1
0
Output
0 | instruction | 0 | 24,173 | 14 | 48,346 |
Tags: implementation
Correct Solution:
```
from collections import Counter
n, m, k = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
v, l = [0] * n, [False] * k
for j in range(m):
c = Counter(a[i][j] for i in range(n))
for i in range(n):
if not v[i] and a[i][j] and (l[a[i][j] - 1] or c[a[i][j]] > 1):
v[i] = j + 1
l[a[i][j] - 1] = True
a[i] = [0] * m
print(*v, sep='\n')
# Made By Mostafa_Khaled
``` | output | 1 | 24,173 | 14 | 48,347 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor.
At each cycle each core of the processor gets one instruction: either do nothing, or the number of the memory cell (the core will write an information to the cell). After receiving the command, the core executes it immediately. Sometimes it happens that at one cycle, multiple cores try to write the information into a single cell. Unfortunately, the developers did not foresee the possibility of resolving conflicts between cores, so in this case there is a deadlock: all these cores and the corresponding memory cell are locked forever. Each of the locked cores ignores all further commands, and no core in the future will be able to record an information into the locked cell. If any of the cores tries to write an information into some locked cell, it is immediately locked.
The development team wants to explore the deadlock situation. Therefore, they need a program that will simulate the processor for a given set of instructions for each core within m cycles . You're lucky, this interesting work is entrusted to you. According to the instructions, during the m cycles define for each core the number of the cycle, during which it will become locked. It is believed that initially all cores and all memory cells are not locked.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 100). Then follow n lines describing instructions. The i-th line contains m integers: xi1, xi2, ..., xim (0 β€ xij β€ k), where xij is the instruction that must be executed by the i-th core at the j-th cycle. If xij equals 0, then the corresponding instruction is Β«do nothingΒ». But if xij is a number from 1 to k, then the corresponding instruction is Β«write information to the memory cell number xijΒ».
We assume that the cores are numbered from 1 to n, the work cycles are numbered from 1 to m and the memory cells are numbered from 1 to k.
Output
Print n lines. In the i-th line print integer ti. This number should be equal to 0 if the i-th core won't be locked, or it should be equal to the number of the cycle when this core will be locked.
Examples
Input
4 3 5
1 0 0
1 0 2
2 3 1
3 2 0
Output
1
1
3
0
Input
3 2 2
1 2
1 2
2 2
Output
1
1
0
Input
1 1 1
0
Output
0 | instruction | 0 | 24,174 | 14 | 48,348 |
Tags: implementation
Correct Solution:
```
n, m, k = map(int, input().split())
cycles = [[] for x in range(m)]
for x in range(n):
temp = list(map(int, input().split()))
for i in range(m):
cycles[i].append(temp[i])
active_cores, active_memory = [0] * n, [0] * (k + 1)
for i in range(m):
temp = {}
for j in range(n):
if not active_cores[j]:
temp[cycles[i][j]] = temp.get(cycles[i][j], []) + [j]
for j in range(n):
if (cycles[i][j]) and (not active_cores[j]) and (len(temp[cycles[i][j]]) > 1 or active_memory[cycles[i][j]]):
active_cores[j] = active_memory[cycles[i][j]] = i + 1
print(*active_cores, sep = '\n')
``` | output | 1 | 24,174 | 14 | 48,349 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor.
At each cycle each core of the processor gets one instruction: either do nothing, or the number of the memory cell (the core will write an information to the cell). After receiving the command, the core executes it immediately. Sometimes it happens that at one cycle, multiple cores try to write the information into a single cell. Unfortunately, the developers did not foresee the possibility of resolving conflicts between cores, so in this case there is a deadlock: all these cores and the corresponding memory cell are locked forever. Each of the locked cores ignores all further commands, and no core in the future will be able to record an information into the locked cell. If any of the cores tries to write an information into some locked cell, it is immediately locked.
The development team wants to explore the deadlock situation. Therefore, they need a program that will simulate the processor for a given set of instructions for each core within m cycles . You're lucky, this interesting work is entrusted to you. According to the instructions, during the m cycles define for each core the number of the cycle, during which it will become locked. It is believed that initially all cores and all memory cells are not locked.
Input
The first line contains three integers n, m, k (1 β€ n, m, k β€ 100). Then follow n lines describing instructions. The i-th line contains m integers: xi1, xi2, ..., xim (0 β€ xij β€ k), where xij is the instruction that must be executed by the i-th core at the j-th cycle. If xij equals 0, then the corresponding instruction is Β«do nothingΒ». But if xij is a number from 1 to k, then the corresponding instruction is Β«write information to the memory cell number xijΒ».
We assume that the cores are numbered from 1 to n, the work cycles are numbered from 1 to m and the memory cells are numbered from 1 to k.
Output
Print n lines. In the i-th line print integer ti. This number should be equal to 0 if the i-th core won't be locked, or it should be equal to the number of the cycle when this core will be locked.
Examples
Input
4 3 5
1 0 0
1 0 2
2 3 1
3 2 0
Output
1
1
3
0
Input
3 2 2
1 2
1 2
2 2
Output
1
1
0
Input
1 1 1
0
Output
0 | instruction | 0 | 24,175 | 14 | 48,350 |
Tags: implementation
Correct Solution:
```
__author__ = 'Lipen'
def main():
n, m, k = map(int, input().split())
data = []
when = [0]*n
blockedcells = set()
blockedcores = set()
for _ in range(n):
data.append(list(map(int, input().split())))
for j in range(m):
operation = []
for _ in range(k):
operation.append([])
for i in range(n):
if i not in blockedcores:
x = data[i][j] - 1
if x>=0:
if x in blockedcells:
blockedcores.add(i)
when[i] = j+1
elif len(operation[x]) > 0:
blockedcells.add(x)
for core in operation[x]:
blockedcores.add(core)
when[core] = j+1
blockedcores.add(i)
when[i] = j+1
operation[x].append(i)
for i in when:
print(i)
main()
``` | output | 1 | 24,175 | 14 | 48,351 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sΡhedule for the event. For some reasons you must follow the conditions:
* The duration of the event must be no more than d minutes;
* Devu must complete all his songs;
* With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
Input
The first line contains two space separated integers n, d (1 β€ n β€ 100; 1 β€ d β€ 10000). The second line contains n space-separated integers: t1, t2, ..., tn (1 β€ ti β€ 100).
Output
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
Examples
Input
3 30
2 2 1
Output
5
Input
3 20
2 1 1
Output
-1
Note
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
* First Churu cracks a joke in 5 minutes.
* Then Devu performs the first song for 2 minutes.
* Then Churu cracks 2 jokes in 10 minutes.
* Now Devu performs second song for 2 minutes.
* Then Churu cracks 2 jokes in 10 minutes.
* Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | instruction | 0 | 24,184 | 14 | 48,368 |
Tags: greedy, implementation
Correct Solution:
```
n,d=input().split()
n=int(n)
d=int(d)
arr = input()
l = list(map(int,arr.split(' ')))
s=0
for i in range(0,n):
s=s+l[i]
s=s+ (n-1)*10
if(s>d):
print(-1)
else:
ans=(n-1)*2 + (d-s)//5
print(ans)
``` | output | 1 | 24,184 | 14 | 48,369 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sΡhedule for the event. For some reasons you must follow the conditions:
* The duration of the event must be no more than d minutes;
* Devu must complete all his songs;
* With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
Input
The first line contains two space separated integers n, d (1 β€ n β€ 100; 1 β€ d β€ 10000). The second line contains n space-separated integers: t1, t2, ..., tn (1 β€ ti β€ 100).
Output
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
Examples
Input
3 30
2 2 1
Output
5
Input
3 20
2 1 1
Output
-1
Note
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
* First Churu cracks a joke in 5 minutes.
* Then Devu performs the first song for 2 minutes.
* Then Churu cracks 2 jokes in 10 minutes.
* Now Devu performs second song for 2 minutes.
* Then Churu cracks 2 jokes in 10 minutes.
* Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | instruction | 0 | 24,185 | 14 | 48,370 |
Tags: greedy, implementation
Correct Solution:
```
n,d=map(int,input().split(" "))
a=0
for k in input().split(" "):
a+=int(k)
if(a+10*(n-1)<=d):
print((d-a)//5)
else:
print(-1)
``` | output | 1 | 24,185 | 14 | 48,371 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sΡhedule for the event. For some reasons you must follow the conditions:
* The duration of the event must be no more than d minutes;
* Devu must complete all his songs;
* With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
Input
The first line contains two space separated integers n, d (1 β€ n β€ 100; 1 β€ d β€ 10000). The second line contains n space-separated integers: t1, t2, ..., tn (1 β€ ti β€ 100).
Output
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
Examples
Input
3 30
2 2 1
Output
5
Input
3 20
2 1 1
Output
-1
Note
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
* First Churu cracks a joke in 5 minutes.
* Then Devu performs the first song for 2 minutes.
* Then Churu cracks 2 jokes in 10 minutes.
* Now Devu performs second song for 2 minutes.
* Then Churu cracks 2 jokes in 10 minutes.
* Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | instruction | 0 | 24,186 | 14 | 48,372 |
Tags: greedy, implementation
Correct Solution:
```
n, d = map(int, input().split())
sp = list(map(int, input().split()))
if sum(sp) + (n-1)*10 <= d:
d -= (sum(sp)+(n-1)*10)
k = (n-1)*2
k += d // 5
print(k)
else:
print(-1)
``` | output | 1 | 24,186 | 14 | 48,373 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sΡhedule for the event. For some reasons you must follow the conditions:
* The duration of the event must be no more than d minutes;
* Devu must complete all his songs;
* With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
Input
The first line contains two space separated integers n, d (1 β€ n β€ 100; 1 β€ d β€ 10000). The second line contains n space-separated integers: t1, t2, ..., tn (1 β€ ti β€ 100).
Output
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
Examples
Input
3 30
2 2 1
Output
5
Input
3 20
2 1 1
Output
-1
Note
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
* First Churu cracks a joke in 5 minutes.
* Then Devu performs the first song for 2 minutes.
* Then Churu cracks 2 jokes in 10 minutes.
* Now Devu performs second song for 2 minutes.
* Then Churu cracks 2 jokes in 10 minutes.
* Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | instruction | 0 | 24,187 | 14 | 48,374 |
Tags: greedy, implementation
Correct Solution:
```
n,d=map(int,input().split())
arr=list(map(int,input().split()))
tot=sum(arr)
tottime=tot+(n-1)*10
if d<tottime:
print(-1)
else:
print((d-tot)//5)
``` | output | 1 | 24,187 | 14 | 48,375 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sΡhedule for the event. For some reasons you must follow the conditions:
* The duration of the event must be no more than d minutes;
* Devu must complete all his songs;
* With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
Input
The first line contains two space separated integers n, d (1 β€ n β€ 100; 1 β€ d β€ 10000). The second line contains n space-separated integers: t1, t2, ..., tn (1 β€ ti β€ 100).
Output
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
Examples
Input
3 30
2 2 1
Output
5
Input
3 20
2 1 1
Output
-1
Note
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
* First Churu cracks a joke in 5 minutes.
* Then Devu performs the first song for 2 minutes.
* Then Churu cracks 2 jokes in 10 minutes.
* Now Devu performs second song for 2 minutes.
* Then Churu cracks 2 jokes in 10 minutes.
* Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | instruction | 0 | 24,188 | 14 | 48,376 |
Tags: greedy, implementation
Correct Solution:
```
import math
a = [int(x) for x in input().split()]
n = a[0]
d = a[1]
t = [int(x) for x in input().split()]
k = sum(t) + 10*(n-1)
if (k > d):
print('-1')
else:
print(2*(n-1)+ math.floor((d-k)/5))
``` | output | 1 | 24,188 | 14 | 48,377 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sΡhedule for the event. For some reasons you must follow the conditions:
* The duration of the event must be no more than d minutes;
* Devu must complete all his songs;
* With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
Input
The first line contains two space separated integers n, d (1 β€ n β€ 100; 1 β€ d β€ 10000). The second line contains n space-separated integers: t1, t2, ..., tn (1 β€ ti β€ 100).
Output
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
Examples
Input
3 30
2 2 1
Output
5
Input
3 20
2 1 1
Output
-1
Note
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
* First Churu cracks a joke in 5 minutes.
* Then Devu performs the first song for 2 minutes.
* Then Churu cracks 2 jokes in 10 minutes.
* Now Devu performs second song for 2 minutes.
* Then Churu cracks 2 jokes in 10 minutes.
* Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | instruction | 0 | 24,189 | 14 | 48,378 |
Tags: greedy, implementation
Correct Solution:
```
n,d=map(int,input().split())
a = sum(list(map(int,input().split())))
if ((n-1)*10+a>d):
print(-1)
exit()
else:
print((d-a)//5)
``` | output | 1 | 24,189 | 14 | 48,379 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sΡhedule for the event. For some reasons you must follow the conditions:
* The duration of the event must be no more than d minutes;
* Devu must complete all his songs;
* With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
Input
The first line contains two space separated integers n, d (1 β€ n β€ 100; 1 β€ d β€ 10000). The second line contains n space-separated integers: t1, t2, ..., tn (1 β€ ti β€ 100).
Output
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
Examples
Input
3 30
2 2 1
Output
5
Input
3 20
2 1 1
Output
-1
Note
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
* First Churu cracks a joke in 5 minutes.
* Then Devu performs the first song for 2 minutes.
* Then Churu cracks 2 jokes in 10 minutes.
* Now Devu performs second song for 2 minutes.
* Then Churu cracks 2 jokes in 10 minutes.
* Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | instruction | 0 | 24,190 | 14 | 48,380 |
Tags: greedy, implementation
Correct Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 14 13:18:46 2020
@author: yash
"""
"""
__ __ _
| \/ (_)_ __ ___ _ __
| |\/| | | '__/ _ \| '_ \
| | | | | | | (_) | | | |
|_| |_|_|_| \___/|_| |_|
"""
"""
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββπ₯βββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββ ββ ββ ββ ββ ββ ββ ββ ββ ββ ββ ββ ββ ββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββπ₯ββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
"""
"""
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@#@@#@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@##@M@M # #@@@M@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@#@@ @@@@@@M@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@### #@@B@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@B@@#@@@@@#M@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@##@@M@#@@##@##@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#M@@@@@##@M@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@##@@@@@@#@##@#@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@# @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@ #
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#@@#@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @# @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @# @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#@@#@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@ #
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@# @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ @@#@@#@@@@@@@@@@@@@@@@@#@@#@#@@@@@@@@@@@@@@@@@@@@@#@#@@@@@@@@@@@@@@@@@@@@@@@@@
@ #@@@@@@@@@@@@@@@@@@@@#@@@@@@#@@@@@@@@@@@@@@@@@#@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ @@#@#@@@@@@@@@@@@@@@@@@#@####@@@@@@@@@@@@@@@@@M@#@@#@#@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@#@#M@@@M@@@@@@@@@@@@@@@@@@@M@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#@M@#@#@@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@@@@@@M@@M@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@#@@#@@@@@@@@@@@@@@@@@@@@M@M@#@@@@@@@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@@@@@@
@@#@@#@@@@@@@@@@@@@@@@@@@@@@@M@ @M@@#@@@@@@@@@@@@@@@@@@@@@@@@@
@#@@@@@#@@@@@@@@@@@@@@@@@@@#@@ @@@@M@@@@@@@@@@@@@@@@@@@@@@@@
@@@#@@@##@@@#@@@@@#@@@@@##@@@@ #@#@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@####@@####@@@@#@@@@M@@@#@@# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@#@ @#@@#@@@ #@ @ #@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@# @@#@@ #@@#@@@@@@@@@@@@@@@@@@@@@@@@@
##@#@@ #M @# @@ @@M @@@@@@@@@@@@@@@@@@@@@@@@
@#@@@M #@ #@ # @@ @@@@@@@@@@@@@@@@@@@@@@@@
@@ @@#@@ ## @##@@ @@@@@@@@@@@@@@@@@@@@@@@@
@# @@M@ @@ @@@@@@@@@@@@@@@@@@@@@@@@
@@@##@@@ @@@@ @@@ @@ #@#@@#@@@@@@@@@@@@@@@@@
@@@@###@@###@@@@#@#@@@@#@@@ M@ #@ @ B @@@#@@@@@@@@@@@@@@@@@@@
@M@@@@@MM@@@@@M@@#@##@@@#@@M@B @# M@ @# #@ #@@#@@@@@@@@@@@@@@@@@@@
@#@#@@M@@M@@#@#@#@#@@#@#@#@@@@ @# @@ # @M @#@@@@@@@@@@@@@@@@@@@@@
@@@ @@@@#@##@ #@# @M # @ @ @@@@@#@@@@@@@@@@@@@@@@@
@@ @@ @#@@#@@#M #@@@@#@@@@@@@@@@@@@@@@@
M@# #@ @@@@##@@ @M@#M@@@#@@@@@@@@@@@@@@@@
@@@@ @@ @@@#@@@#@#@@@@@@@@@@@@@@@@
@# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@M@H@@ @# @#@@@@#@@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@#@#@##@M@@@M@ @M#@@@@@#@@#@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#M@@@##@@@@@@@@M@@@@#@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@#@@@@@M@#@M@@B#M@@M@###@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
###@@@@@@@@@# @#@@@@@@@#@@@#@##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@#@@M@@@#@@#@#@@@@@@#@@@#@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@M@#@#
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@@@#
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@#@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@##
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#@M
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@###@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@#@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
"""
"""
/ \ //\
|\___/| / \// \\
/0 0 \__ / // | \ \
/ / \/_/ // | \ \
@_^_@'/ \/_ // | \ \
//_^_/ \/_ // | \ \
( //) | \/// | \ \
( / /) _|_ / ) // | \ _\
( // /) '/,_ _ _/ ( ; -. | _ _\.-~ .-~~~^-.
(( / / )) ,-{ _ `-.|.-~-. .~ `.
(( // / )) '/\ / ~-. _ .-~ .-~^-. \
(( /// )) `. { } / \ \
(( / )) .----~-.\ \-' .~ \ `. \^-.
///.----..> \ _ -~ `. ^-` ^-_
///-._ _ _ _ _ _ _}^ - - - - ~ ~-- ,.-~
/.-~
"""
"""
____ _ _____
/ ___|___ __| | ___| ___|__ _ __ ___ ___ ___
| | / _ \ / _` |/ _ \ |_ / _ \| '__/ __/ _ \/ __|
| |__| (_) | (_| | __/ _| (_) | | | (_| __/\__ \
\____\___/ \__,_|\___|_| \___/|_| \___\___||___/
"""
"""
βββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
"""
"""βββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
"""
"""
# Codeforces Round #186 (Div. 2), problem: (A) Ilya and Bank Account
n = int(input())
if n > 0:
print(n)
else:
s = str(n)
if s[len(s)-1] < s[len(s)-2] and s[len(s)-2] != '0':
print(int(s[:len(s)-2] + s[len(s)-1:]))
elif s[len(s)-1] > s[len(s)-2] and s[len(s)-1] != '0':
print(int(s[:len(s)-1]))
else:
print(int(s[:len(s)-1]))
"""
"""
# Codeforces Round #261 (Div. 2), problem: (A) Pashmak and Garden,
x1, y1, x2, y2=map(int,input().split())
l=abs(x1-x2)
m=abs(y1-y2)
if x1==x2:
print(x1+m,y1,x2+m,y2)
elif y1==y2:
print(x1,y1+l,x2,y2+l)
elif l!=m:
print(-1)
else:
print(x1,y2,x2,y1)
"""
"""
# Codeforces Round #142 (Div. 2), problem: (A) Dragons
def solve():
s, n = map(int, input().split())
sets = []
for _ in range(n):
ith, bonus = map(int, input().split())
sets.append([ith, bonus])
sets.sort(key=lambda x: x[0])
for i in sets:
if i[0] < s:
s += i[1]
else:
return "NO"
return "YES"
print(solve())
"""
"""
# Codeforces Round #690 (Div. 3)
# (A) Favorite Sequence-
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
ans = []
k = n//2
start = 0
end = len(l)-1
while start <= end:
if start != end:
ans.append(l[start])
ans.append(l[end])
else:
ans.append(l[end])
start += 1
end -= 1
for i in ans:
print(i, end=" ")
print()
# B) Last Year's Substring-
for _ in range(int(input())):
n = int(input())
s = input()
if s[0]+s[1] == '20' and s[-2]+s[-1] == '20':
print("YES")
elif s[0] == '2' and s[-3]+s[-2]+s[-1] == '020':
print("YES")
elif s[0]+s[1]+s[2] == '202' and s[-1] == '0':
print("YES")
elif s[0]+s[1]+s[2]+s[3] == '2020':
print("YES")
elif s[-4]+s[-3]+s[-2]+s[-1] == '2020':
print("YES")
else:
print("NO")
"""
n, d = map(int, input().split())
l = list(map(int, input().split()))
if (sum(l) + (n-1)*10) > d:
print(-1)
else:
print((d-sum(l))//5)
``` | output | 1 | 24,190 | 14 | 48,381 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sΡhedule for the event. For some reasons you must follow the conditions:
* The duration of the event must be no more than d minutes;
* Devu must complete all his songs;
* With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
Input
The first line contains two space separated integers n, d (1 β€ n β€ 100; 1 β€ d β€ 10000). The second line contains n space-separated integers: t1, t2, ..., tn (1 β€ ti β€ 100).
Output
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
Examples
Input
3 30
2 2 1
Output
5
Input
3 20
2 1 1
Output
-1
Note
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
* First Churu cracks a joke in 5 minutes.
* Then Devu performs the first song for 2 minutes.
* Then Churu cracks 2 jokes in 10 minutes.
* Now Devu performs second song for 2 minutes.
* Then Churu cracks 2 jokes in 10 minutes.
* Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | instruction | 0 | 24,191 | 14 | 48,382 |
Tags: greedy, implementation
Correct Solution:
```
inp = list(map(int,input().split(" ")))
div=inp[0]
k=inp[1]
jokes=0
songs= list(map(int,input().split(" ")))
if((len(songs)-1)*10+sum(songs)>k):
print("-1")
else:
time_rem=k-(sum(songs))
jokes=time_rem//5
print(int(jokes))
``` | output | 1 | 24,191 | 14 | 48,383 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of a thimbles per day after the k days are complete.
Initially, no orders are pending. The factory receives updates of the form di, ai, indicating that ai new orders have been placed for the di-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes.
As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day pi. Help the owner answer his questions.
Input
The first line contains five integers n, k, a, b, and q (1 β€ k β€ n β€ 200 000, 1 β€ b < a β€ 10 000, 1 β€ q β€ 200 000) β the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively.
The next q lines contain the descriptions of the queries. Each query is of one of the following two forms:
* 1 di ai (1 β€ di β€ n, 1 β€ ai β€ 10 000), representing an update of ai orders on day di, or
* 2 pi (1 β€ pi β€ n - k + 1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day pi?
It's guaranteed that the input will contain at least one query of the second type.
Output
For each query of the second type, print a line containing a single integer β the maximum number of orders that the factory can fill over all n days.
Examples
Input
5 2 2 1 8
1 1 2
1 5 3
1 2 1
2 2
1 4 2
1 3 2
2 1
2 3
Output
3
6
4
Input
5 4 10 1 6
1 1 5
1 5 5
1 3 2
1 5 2
2 1
2 2
Output
7
1
Note
Consider the first sample.
We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days.
For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for that day, and 2 orders for day 5 since we are limited to our production capacity, for a total of 3 orders filled.
For the third question, we are able to fill 1 order on day 1, 1 order on day 2, and 2 orders on day 5, for a total of 4 orders.
Submitted Solution:
```
import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def add(a,x,v):
while x<len(a):
a[x] += v
x |= x+1
def get(a,x):
r = 0
while x>=0:
r += a[x]
x = (x&(x+1))-1
return r
n, k, a, b, q = mints()
h1 = [0]*n
h2 = [0]*n
z = [0]*n
for i in range(q):
t = tuple(mints())
if t[0] == 1:
p = z[t[1]-1]
pp = p + t[2]
add(h1, t[1]-1, min(a,pp)-min(a,p))
add(h2, t[1]-1, min(b,pp)-min(b,p))
else:
print(get(h2,t[1]-2)+get(h1,n-1)-get(h1,t[1]+k-2))
``` | instruction | 0 | 24,297 | 14 | 48,594 |
No | output | 1 | 24,297 | 14 | 48,595 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 β€ i β€ n - 1), such that ai + 1 > ai.
Input
The first line of the input contains integer n (1 β€ n β€ 1000) β the number of painting.
The second line contains the sequence a1, a2, ..., an (1 β€ ai β€ 1000), where ai means the beauty of the i-th painting.
Output
Print one integer β the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | instruction | 0 | 24,298 | 14 | 48,596 |
Tags: greedy, sortings
Correct Solution:
```
n = int(input())
l = list(map(int, input().split()))
d = {}
for i in l:
if i not in d:
d[i] = 1
else:
d[i] += 1
m = max(d.values())
print(n - m)
``` | output | 1 | 24,298 | 14 | 48,597 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 β€ i β€ n - 1), such that ai + 1 > ai.
Input
The first line of the input contains integer n (1 β€ n β€ 1000) β the number of painting.
The second line contains the sequence a1, a2, ..., an (1 β€ ai β€ 1000), where ai means the beauty of the i-th painting.
Output
Print one integer β the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200. | instruction | 0 | 24,299 | 14 | 48,598 |
Tags: greedy, sortings
Correct Solution:
```
size = 1001
n = int(input())
a = [0] * size
ans = 0
num = map(int, input().split())
for b in num:
a[b] += 1
while a.count(0) != size:
cnt = 0
for i in range(size):
if a[i]:
cnt += 1
a[i] -= 1
ans += cnt - 1
print(ans)
``` | output | 1 | 24,299 | 14 | 48,599 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.